@turmind/halo 1.5.7 → 1.5.8
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.
- package/admin-out/404.html +1 -1
- package/admin-out/_next/static/chunks/989-df2401d289d09a7e.js +1 -0
- package/admin-out/_next/static/chunks/app/page-ed2976abf85a335d.js +1 -0
- package/admin-out/index.html +1 -1
- package/admin-out/index.txt +4 -4
- package/bundled-docs/design/architecture.md +3 -2
- package/bundled-docs/design/canvas-extensions.md +3 -1
- package/bundled-docs/design/express-self.md +16 -7
- package/bundled-docs/design/storage.md +9 -2
- package/bundled-docs/design/ws.md +1 -0
- package/bundled-docs/dev/add-model-provider.md +16 -7
- package/bundled-docs/guide/agents.md +2 -2
- package/bundled-docs/guide/cli.md +10 -1
- package/bundled-docs/requirements/chat.md +2 -2
- package/dist/index.js +1493 -1121
- package/package.json +1 -1
- package/templates/canvas/self.html +162 -10
- package/templates/models/anthropic.yaml +1 -0
- package/templates/models/aws-bedrock-claude-invoke.yaml +1 -0
- package/templates/models/aws-bedrock-mantle.yaml +1 -0
- package/templates/models/aws-bedrock-openai.yaml +1 -0
- package/templates/models/deepseek.yaml +1 -0
- package/templates/models/doubao.yaml +1 -0
- package/templates/models/hunyuan.yaml +1 -0
- package/templates/models/kimi.yaml +1 -0
- package/templates/models/mimo-token-plan-china.yaml +1 -0
- package/templates/models/minimax.yaml +1 -0
- package/templates/models/openai.yaml +1 -0
- package/templates/models/qwen.yaml +1 -0
- package/templates/models/zhipu.yaml +1 -0
- package/templates/skills/extension/SKILL.md +30 -2
- package/templates/skills/extension/config.yaml +2 -2
- package/templates/skills/extension/templates/ext.sh +69 -16
- package/templates/skills/self/SKILL.md +23 -4
- package/admin-out/_next/static/chunks/989-e0faeff1c4a0b0b9.js +0 -1
- package/admin-out/_next/static/chunks/app/page-44f707ea8dad57da.js +0 -1
- /package/admin-out/_next/static/{rTD3zkMvzwtqUwzhz6QJH → T3x-q3QCOgSpfydoH53XD}/_buildManifest.js +0 -0
- /package/admin-out/_next/static/{rTD3zkMvzwtqUwzhz6QJH → T3x-q3QCOgSpfydoH53XD}/_ssgManifest.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{17119:(e,t,r)=>{"use strict";r.d(t,{kj:()=>n.useT,pZ:()=>a.LanguageSelect,s9:()=>n.useI18n});var n=r(19882);r(38115);var a=r(53804);r(24554)},17851:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>oQ});var n,a,s=r(41440),l=r(54604),o=r(2877),i=r(17640),c=r(60252),d=r(56207);function u(e,t){return"".concat(null!=e?e:"","/").concat(t)}function m(e,t){let r=d.wG.__getMonacoInstance();if(r)for(let a of t){var n;null==(n=r.editor.getModel(r.Uri.parse(u(e,a))))||n.dispose()}}let x=1;function p(){return"g".concat(x++)}function h(e){let t=e.groups[e.activeGroupIdx];if(!t)return{tabs:[],activeTab:null};let r=[];for(let n of t.tabs){let t=e.buffers[n];t&&r.push(t)}return{tabs:r,activeTab:t.activeTab}}function f(e,t,r,n){let a=e.buffers[r]?e.buffers:{...e.buffers,[r]:n()},s=e.groups[t],l=s.tabs.includes(r)?s.tabs:[...s.tabs,r];return{buffers:a,groups:e.groups.map((e,n)=>n===t?{...e,tabs:l,activeTab:r}:e)}}function g(e,t){let r={...e,children:e.children&&[...e.children]},n=r,a=0;for(let e of t){if(!n.children)break;let t=n.children.findIndex(t=>t.name===e&&"directory"===t.type);if(-1===t)break;let r={...n.children[t]};r.children&&(r.children=[...r.children]),n.children[t]=r,n=r,a++}return{root:r,node:n,depth:a}}function v(){return(0,c.v)((e,t)=>({buffers:{},groups:[{id:p(),tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modelPathPrefix:null,setModelPathPrefix(r){t().modelPathPrefix!==r&&e({modelPathPrefix:r})},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,n,a,s){e(e=>{let{buffers:l,groups:o}=f(e,e.activeGroupIdx,t,()=>({path:t,content:r,originalContent:r,language:n,mtime:a,size:null==s?void 0:s.size,createdAt:null==s?void 0:s.createdAt})),i={...e,buffers:l,groups:o};return{buffers:l,groups:o,...h(i)}})},openPreview(t,r,n,a){e(e=>{let{buffers:s,groups:l}=f(e,e.activeGroupIdx,t,()=>({path:t,content:"",originalContent:"",language:"",preview:{downloadUrl:r,viewUrl:n,tooLarge:null==a?void 0:a.tooLarge},size:null==a?void 0:a.size,mtime:null==a?void 0:a.mtime,createdAt:null==a?void 0:a.createdAt})),o={...e,buffers:s,groups:l};return{buffers:s,groups:l,...h(o)}})},openFileInGroup(t,r,n,a,s,l){e(e=>{if(t<0||t>=e.groups.length)return e;let{buffers:o,groups:i}=f(e,t,r,()=>({path:r,content:n,originalContent:n,language:a,mtime:s,size:null==l?void 0:l.size,createdAt:null==l?void 0:l.createdAt})),c={...e,buffers:o,groups:i,activeGroupIdx:t};return{buffers:o,groups:i,activeGroupIdx:t,...h(c)}})},closeTab(r){e(e=>{let t=e.groups.map(e=>{if(!e.tabs.includes(r))return e;let t=e.tabs.filter(e=>e!==r),n=e.activeTab;if(n===r){var a;n=null!=(a=t[Math.min(e.tabs.indexOf(r),t.length-1)])?a:null}return{...e,tabs:t,activeTab:n}}),n=t.some(e=>e.tabs.includes(r)),a=n?e.buffers:(()=>{let{[r]:t,...n}=e.buffers;return n})(),s=n?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(r))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(r),t})(),l=t.length>1&&0===t[1].tabs.length?{groups:[t[0]],activeGroupIdx:0}:{groups:t,activeGroupIdx:Math.min(e.activeGroupIdx,t.length-1)},o={...e,buffers:a,modifiedPaths:s,...l};return{buffers:a,modifiedPaths:s,...l,...h(o)}});let n=t();n.buffers[r]||m(n.modelPathPrefix,[r])},closeTabIn(r,n){e(e=>{if(r<0||r>=e.groups.length)return e;let t=e.groups[r];if(!t.tabs.includes(n))return e;let a=t.tabs.filter(e=>e!==n),s=t.activeTab;if(s===n){var l;s=null!=(l=a[Math.min(t.tabs.indexOf(n),a.length-1)])?l:null}let o=e.groups.map((e,t)=>t===r?{...e,tabs:a,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(n)),d=c?e.buffers:(()=>{let{[n]:t,...r}=e.buffers;return r})(),u=c?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(n))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(n),t})(),m={...e,groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u};return{groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u,...h(m)}});let a=t();a.buffers[n]||m(a.modelPathPrefix,[n])},setActiveTab(t,r){e(e=>{let n=null!=r?r:-1;if(n<0){let r=e.groups[e.activeGroupIdx];n=(null==r?void 0:r.tabs.includes(t))?e.activeGroupIdx:e.groups.findIndex(e=>e.tabs.includes(t))}if(n<0||!e.groups[n].tabs.includes(t))return e;let a=e.groups.map((e,r)=>r===n?{...e,activeTab:t}:e),s=n,l={...e,groups:a,activeGroupIdx:s};return{groups:a,activeGroupIdx:s,...h(l)}})},updateContent(t,r){e(e=>{let n=e.buffers[t];if(!n)return e;let a=r!==n.originalContent,s={...e.buffers,[t]:{...n,content:r,modified:a}},l=new Set(e.modifiedPaths);a?l.add(t):l.delete(t);let o={...e,buffers:s,modifiedPaths:l};return{buffers:s,modifiedPaths:l,...h(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,...h(r)}})},splitToRight(t){e(e=>{var r,n;if(e.groups.length>=2)return e;let a=null!=(n=null!=t?t:null==(r=e.groups[e.activeGroupIdx])?void 0:r.activeTab)?n:null;if(!a||!e.buffers[a])return e;let s={id:p(),tabs:[a],activeTab:a},l=[e.groups[0],s],o={...e,groups:l,activeGroupIdx:1};return{groups:l,activeGroupIdx:1,...h(o)}})},closeGroup(r){let n=[];e(e=>{if(e.groups.length<=1||r<0||r>=e.groups.length)return e;let t=e.groups.filter((e,t)=>t!==r),a=new Set;for(let e of t)for(let t of e.tabs)a.add(t);let s={};for(let[t,r]of Object.entries(e.buffers))a.has(t)?s[t]=r:n.push(t);let l=new Set;for(let t of e.modifiedPaths)a.has(t)&&l.add(t);let o=Math.max(0,Math.min(e.activeGroupIdx,t.length-1)),i={...e,groups:t,activeGroupIdx:o,buffers:s,modifiedPaths:l};return{groups:t,activeGroupIdx:o,buffers:s,modifiedPaths:l,...h(i)}}),n.length>0&&m(t().modelPathPrefix,n)},moveTabToGroup(t,r,n,a){e(e=>{if(t===n){if(t<0||t>=e.groups.length)return e;let n=e.groups[t],s=n.tabs.indexOf(r);if(s<0)return e;let l=null==a?n.tabs.length-1:Math.max(0,Math.min(a,n.tabs.length-1));if(s===l)return e;let o=function(e,t,r){let n=[...e],[a]=n.splice(t,1);return n.splice(r,0,a),n}(n.tabs,s,l),i=e.groups.map((e,n)=>n===t?{...e,tabs:o,activeTab:r}:e),c={...e,groups:i};return{groups:i,...h(c)}}if(t<0||t>=e.groups.length||n<0||n>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(n===e.groups.length){if(e.groups.length>=2)return e;c[t]={...s,tabs:l,activeTab:o},c.push({id:p(),tabs:[r],activeTab:r})}else{let e=c[n],i=e.tabs.includes(r)?e.tabs:(()=>{let t=[...e.tabs];return null==a||a>=t.length?t.push(r):t.splice(Math.max(0,a),0,r),t})();c[t]={...s,tabs:l,activeTab:o},c[n]={...e,tabs:i,activeTab:r}}let d=n;0===c[t].tabs.length&&c.length>1&&(c=c.filter((e,r)=>r!==t),d=Math.max(0,Math.min(n>t?n-1:n,c.length-1)));let u={...e,groups:c,activeGroupIdx:d};return{groups:c,activeGroupIdx:d,...h(u)}})},setFileTree(t){e({fileTree:t})},setDirChildren(t,r){e(e=>{if(!e.fileTree)return e;let n=t.split("/").filter(Boolean),{root:a,node:s,depth:l}=g(e.fileTree,n);if(l<n.length)return e;let o=[...r].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name));return s.children=o,s.hasChildren=o.length>0,{fileTree:a}})},markModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let n=new Set(e.modifiedPaths);n.add(t);let a={...e.buffers,[t]:{...r,modified:!0}},s={...e,buffers:a,modifiedPaths:n};return{buffers:a,modifiedPaths:n,...h(s)}})},clearModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let n=new Set(e.modifiedPaths);n.delete(t);let a={...e.buffers,[t]:{...r,modified:!1}},s={...e,buffers:a,modifiedPaths:n};return{buffers:a,modifiedPaths:n,...h(s)}})},markSaved(t,r){e(e=>{let n=e.buffers[t];if(!n)return e;let a=new Set(e.modifiedPaths);a.delete(t);let s={...e.buffers,[t]:{...n,originalContent:n.content,modified:!1,mtime:null!=r?r:n.mtime}},l={...e,buffers:s,modifiedPaths:a};return{buffers:s,modifiedPaths:a,...h(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 n=t.split("/").filter(Boolean);if(0===n.length)return e;let a=n.slice(0,-1),{root:s,node:l,depth:o}=g(e.fileTree,a);if(o<a.length||void 0===l.children)return void 0===l.children&&!0!==l.hasChildren?(l.hasChildren=!0,{fileTree:s}):e;let i=n[n.length-1];if(l.children.some(e=>e.name===i))return e;let c="directory"===r?{name:i,path:t,type:"directory",hasChildren:!1,children:[]}:{name:i,path:t,type:"file"};return l.children.push(c),l.children.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),{fileTree:s}})},removeFileNode(t){e(e=>{if(!e.fileTree)return e;let r=t.split("/").filter(Boolean);if(0===r.length)return e;let n=r.slice(0,-1),{root:a,node:s,depth:l}=g(e.fileTree,n);if(l<n.length||!s.children)return e;let o=r[r.length-1],i=s.children.findIndex(e=>e.name===o);return -1===i?e:(s.children.splice(i,1),{fileTree:a})})},async checkAndRefresh(r,n,a){let s=t().buffers[r];if(!s||s.preview||s.mtime&&n<=s.mtime||s.modified)return!1;let l=await a();return e(e=>{var t,n;let a=e.buffers[r];if(!a||a.modified)return e;let s={...e.buffers,[r]:{...a,content:l.content,originalContent:l.content,mtime:l.modifiedAt,size:null!=(t=l.size)?t:a.size,createdAt:null!=(n=l.createdAt)?n:a.createdAt}},o={...e,buffers:s};return{buffers:s,...h(o)}}),!0}}))}let b=v(),j=(0,l.createContext)(null);function y(e){let{children:t}=e,r=(0,l.useRef)(null);return r.current||(r.current=v()),(0,l.useEffect)(()=>{let e=r.current;return()=>{let t=e.getState();m(t.modelPathPrefix,Object.keys(t.buffers))}},[]),(0,l.createElement)(j.Provider,{value:r.current},t)}function w(){let e=(0,l.useContext)(j);return null!=e?e:b}var N=r(43672);class k{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(e=!0,this.reconnectDelay=1e3,this.lastReceiveTs=Date.now(),this.lastProbeTs=0,this.missedProbes=0,this.pendingQueue))this.ws.send(JSON.stringify(t));for(let[e,t]of(this.pendingQueue=[],this.pendingAcks))this.transmitChat(e,t);this.emit("_connected",{})},this.ws.onmessage=e=>{this.lastReceiveTs=Date.now();try{let t=JSON.parse(e.data),r=t.type;"chat:ack"===r&&this.resolveAck(t.clientMsgId),r&&this.emit(r,t)}catch(e){console.error("[WsClient] Failed to parse message:",e)}},this.ws.onclose=()=>{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(){for(let e of(this.intentionalClose=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopLiveness(),this.pendingAcks.values()))e.ackTimer&&clearTimeout(e.ackTimer),clearTimeout(e.deadlineTimer);this.pendingAcks.clear(),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)try{this.ws.close()}catch(e){}return}if(e===WebSocket.CLOSING||e===WebSocket.CLOSED){this.ws=null,this.emit("_disconnected",{}),this.reconnect();return}if(this.lastProbeTs>0&&this.lastReceiveTs<this.lastProbeTs){if(this.missedProbes++,this.missedProbes>=2){try{this.ws.close()}catch(e){}return}}else this.missedProbes=0;try{this.ws.send(JSON.stringify({type:"__ping__"})),this.lastProbeTs=Date.now()}catch(e){try{this.ws.close()}catch(e){}}},15e3)}stopLiveness(){this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}send(e){let{type:t,clientMsgId:r}=e;return"chat"===t&&r?void this.sendChat(r,e):this.ws&&this.ws.readyState===WebSocket.OPEN?void this.ws.send(JSON.stringify(e)):"__ping__"===t||"terminal:input"===t||"terminal:resize"===t?void 0:void(this.pendingQueue.length>=100&&this.pendingQueue.shift(),this.pendingQueue.push(e))}sendChat(e,t){if(this.pendingAcks.size>=100){let e=this.pendingAcks.keys().next().value;void 0!==e&&this.failPendingChat(e)}let r={message:t,attempts:0,ackTimer:null,deadlineTimer:setTimeout(()=>this.failPendingChat(e),12e4)};if(this.pendingAcks.set(e,r),this.ws&&this.ws.readyState===WebSocket.OPEN){if(Date.now()-this.lastReceiveTs>3e4){try{this.ws.close()}catch(e){}return}this.transmitChat(e,r)}}transmitChat(e,t){t.ackTimer&&(clearTimeout(t.ackTimer),t.ackTimer=null),t.attempts++;try{this.ws.send(JSON.stringify(t.message))}catch(e){try{var r;null==(r=this.ws)||r.close()}catch(e){}return}t.ackTimer=setTimeout(()=>{if((t.ackTimer=null,this.pendingAcks.has(e))&&!(t.attempts>=3))try{var r;null==(r=this.ws)||r.close()}catch(e){}},5e3)}failPendingChat(e){let t=this.pendingAcks.get(e);t&&(t.ackTimer&&clearTimeout(t.ackTimer),clearTimeout(t.deadlineTimer),this.pendingAcks.delete(e),this.emit("_chat_send_failed",{clientMsgId:e}))}resolveAck(e){if("string"!=typeof e)return;let t=this.pendingAcks.get(e);t&&(t.ackTimer&&clearTimeout(t.ackTimer),clearTimeout(t.deadlineTimer),this.pendingAcks.delete(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}get lastReceiveAgeMs(){return 0===this.lastReceiveTs?1/0:Date.now()-this.lastReceiveTs}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){try{this.ws.close()}catch(e){}return}if(this.ws.readyState===WebSocket.OPEN&&!(Date.now()-this.lastReceiveTs<e))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||(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){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.pendingAcks=new Map,this.lastReceiveTs=0,this.lastProbeTs=0,this.missedProbes=0,this.connectStartedAt=0,this.livenessTimer=null}}let S=new k;function C(e,t){let r=e.connected;return e.on("_connected",()=>{if(!r){r=!0;return}t()})}function A(e,t){var r,n;return{name:null!=(n=null!=(r=t.root)?r:e.split("/").filter(Boolean).pop())?n:"root",path:"",type:"directory",hasChildren:t.tree.length>0,children:t.tree}}function I(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:b;N.F.files.tree(e).then(r=>{t.getState().setFileTree(A(e,r))}).catch(e=>{console.error("[Explorer] Failed to load file tree:",e)})}async function E(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:b;try{let n=await N.F.files.tree(e,t);r.getState().setDirChildren(t,n.tree)}catch(e){console.error("[Explorer] Failed to load directory:",t,e)}}let T=[".halo/sessions/",".halo/logs/",".halo/halo.db"];function M(e){let t=e.path;return"string"==typeof t&&T.some(e=>t.startsWith(e))}let F={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"}},D={letter:"?",color:"#487E02",label:"Untracked"};function P(e){var t;return null!=(t=F[e])?t:D}function L(e){return""!==e&&" "!==e&&"?"!==e}function R(e){return""!==e&&" "!==e}let _={files:new Map,dirs:new Map,ignored:new Set},z=(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 O=r(59344),U=r(1623);function B(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,U.QP)((0,O.$)(t))}function W(){return Math.random().toString(36).substring(2,10)+Date.now().toString(36)}function H(e){return!!e&&!!(e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\"))}function K(e,t){let r=window;return"function"==typeof r.haloPrompt?r.haloPrompt(e,t):Promise.resolve(window.prompt(e,t))}function G(e){let t=window;return"function"==typeof t.haloConfirm?t.haloConfirm(e):Promise.resolve(window.confirm(e))}function q(e,t){let r="number"==typeof e?e:new Date(e).getTime(),n=Math.floor((Date.now()-r)/6e4);if(n<1)return t?t("time.justNow"):"just now";if(n<60)return t?t("time.minutes",{n:n}):"".concat(n,"m ago");let a=Math.floor(n/60);if(a<24)return t?t("time.hours",{n:a}):"".concat(a,"h ago");let s=Math.floor(a/24);return s<30?t?t("time.days",{n:s}):"".concat(s,"d ago"):new Date(r).toLocaleDateString()}function J(e){return e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}function Z(e){var t,r,n;return null!=(n=({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:""])?n:"plaintext"}var $=r(27322),Y=r(54810),V=r(93396),Q=r(19478),X=r(70101),ee=r(87212),et=r(74262),er=r(58781),en=r(44607),ea=r(14909),es=r(34996),el=r(5431),eo=r(71311),ei=r(60086),ec=r(13743),ed=r(77470),eu=r(2038),em=r(94944),ex=r(95342),ep=r(58983),eh=r(28963),ef=r(42563),eg=r(60768);let ev={ts:et.A,tsx:et.A,mts:et.A,cts:et.A,js:et.A,jsx:et.A,mjs:et.A,cjs:et.A,json:er.A,jsonc:er.A,html:en.A,htm:en.A,svg:en.A,xml:en.A,css:ea.A,scss:ea.A,sass:ea.A,less:ea.A,md:es.A,mdx:es.A,txt:es.A,rst:es.A,log:es.A,csv:el.A,tsv:el.A,xlsx:el.A,xls:el.A,sql:eo.A,sh:ei.A,bash:ei.A,zsh:ei.A,yaml:ec.A,yml:ec.A,toml:ec.A,ini:ec.A,env:ec.A,py:ed.A,go:eu.A,rs:eu.A,c:eu.A,cpp:eu.A,h:eu.A,hpp:eu.A,java:eu.A,kt:eu.A,scala:eu.A,cs:eu.A,swift:eu.A,dart:eu.A,rb:eu.A,php:eu.A,lua:eu.A,r:eu.A,png:em.A,jpg:em.A,jpeg:em.A,gif:em.A,webp:em.A,bmp:em.A,ico:em.A,avif:em.A,mp4:ex.A,webm:ex.A,mov:ex.A,avi:ex.A,mkv:ex.A,ogg:ex.A,mp3:ep.A,wav:ep.A,flac:ep.A,aac:ep.A,m4a:ep.A,wma:ep.A,zip:eh.A,tar:eh.A,gz:eh.A,"7z":eh.A,rar:eh.A,pdf:ef.A,docx:ef.A,doc:ef.A,pptx:ef.A,ppt:ef.A},eb={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 ej(e){var t,r,n,a,s,l;let o=null!=(n=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?n:"",i=null!=(a=null==(r=e.split("/").pop())?void 0:r.toLowerCase())?a:"";return"dockerfile"===i||i.startsWith("dockerfile.")?{Icon:ei.A,color:"text-cyan-400"}:".gitignore"===i||".gitattributes"===i?{Icon:ec.A,color:"text-[var(--muted-foreground)]"}:".env"===i||i.startsWith(".env.")?{Icon:ec.A,color:"text-yellow-300"}:"makefile"===i||"cmake"===i?{Icon:ei.A,color:"text-[var(--muted-foreground)]"}:{Icon:null!=(s=ev[o])?s:eg.A,color:null!=(l=eb[o])?l:"text-[var(--muted-foreground)]"}}let ey="halo:file-tree:expanded",ew=null,eN=new Map;function ek(){if(ew)return ew;try{let e=localStorage.getItem(ey);ew=e?new Set(JSON.parse(e)):new Set}catch(e){ew=new Set}return ew}let eS=null;function eC(e,t){let r=ek(),n=r.has(e);if(t?r.add(e):r.delete(e),eS&&clearTimeout(eS),eS=setTimeout(()=>{try{let e=ek();localStorage.setItem(ey,JSON.stringify([...e]))}catch(e){}},300),n!==t){let r=eN.get(e);if(r)for(let e of r)e(t)}}function eA(e){return ek().has(e)}let eI="application/x-halo-path";function eE(e){let{depth:t,initialValue:r,iconKind:n,onCommit:a,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"===n&&t>0?e.setSelectionRange(0,t):e.select()},[r,n]);let m="folder"===n?$.A:Y.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)(m,{className:B("h-3.5 w-3.5 shrink-0","folder"===n?"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,a(c)):"Escape"===e.key&&(e.preventDefault(),u.current=!0,o()),e.stopPropagation()},onBlur:()=>{u.current||(""===c.trim()?o():a(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 eT(e){let t=e.items;if(t&&t.length>0){let e=[];for(let a=0;a<t.length;a++){var r,n;let s=null==(r=(n=t[a]).webkitGetAsEntry)?void 0:r.call(n);s&&e.push(s)}if(e.some(e=>e.isDirectory)){let t=[];async function a(e,r){if(e.isFile){let n=await new Promise((t,r)=>e.file(t,r)),a=r?"".concat(r,"/").concat(e.name):e.name;t.push(new File([n],a,{type:n.type,lastModified:n.lastModified}))}else if(e.isDirectory){let t,n=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))}(n))await a(e,s);while(t.length>0)}}for(let t of e)await a(t,"");return t}}return Array.from(e.files)}function eM(e,t){return e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)}function eF(e){let t=[];if(e.path&&t.push(e.path),"directory"===e.type&&e.children&&(!e.path||eA(e.path))){var r;for(let n of[...null!=(r=e.children)?r:[]].sort(eM))t.push(...eF(n))}return t}function eD(e){var t,r,n;let{node:a,projectId:o,onSelect:i,onContextMenu:c,onDropFiles:d,onMoveFile:u,selectedPaths:m,onSelectionChange:x,lastAnchor:p,visiblePaths:h,depth:f,pendingEdit:g,onCommitEdit:v,onCancelEdit:b}=e,j=w(),[y,N]=(0,l.useState)(()=>!!a.path&&eA(a.path)),[k,S]=(0,l.useState)(!1),[C,A]=(0,l.useState)(!1),I=(0,l.useRef)(null),T=(0,l.useRef)(null),M="directory"===a.type,F=M&&!1!==a.hasChildren&&void 0===a.children,D=(0,l.useRef)(y),L=(0,l.useCallback)(e=>{N(e),a.path&&eC(a.path,e)},[a.path]);(0,l.useEffect)(()=>{if(a.path){var e,t;let r;return e=a.path,t=e=>N(e),(r=eN.get(e))||(r=new Set,eN.set(e,r)),r.add(t),()=>{let r=eN.get(e);r&&(r.delete(t),0===r.size&&eN.delete(e))}}},[a.path]),(0,l.useEffect)(()=>{let e=D.current;D.current=y,y&&!C&&a.path&&(F||!e)&&(A(!0),E(o,a.path,j).finally(()=>A(!1)))},[y,F,C,a.path,o,j]);let R=j(e=>e.modifiedPaths),O=j(e=>e.activeTab),U=z(e=>{var t;return null!=(t=o?e.byProject[o]:void 0)?t:_}),W=0===f&&!a.path,H=(e,t,r)=>{var n;return(0,s.jsxs)(s.Fragment,{children:[e&&g&&(0,s.jsx)(eE,{depth:t,initialValue:"",iconKind:"create-folder"===g.mode?"folder":"file",onCommit:e=>null==v?void 0:v(e),onCancel:()=>null==b?void 0:b()}),(null!=(n=a.children)?n:[]).sort(eM).map(e=>(0,s.jsx)(eD,{node:e,projectId:o,onSelect:i,onContextMenu:c,onDropFiles:d,onMoveFile:u,selectedPaths:m,onSelectionChange:x,lastAnchor:p,visiblePaths:r,depth:t,pendingEdit:g,onCommitEdit:v,onCancelEdit:b},e.path))]})};if(W){let e=(0,l.useCallback)(()=>eF(a),[a])(),t=async e=>{e.preventDefault(),e.stopPropagation(),S(!1);let t=e.dataTransfer.getData(eI);if(t){null==u||u(t,"");return}let r=await eT(e.dataTransfer);r.length>0&&(null==d||d(r,""))},r=g&&""===g.parentDir&&"rename"!==g.mode;return(0,s.jsx)("div",{onClick:e=>{e.target===e.currentTarget&&x&&x(new Set,"")},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),null==c||c({x:e.clientX,y:e.clientY,path:"",name:"/",isDir:!0}))},onDragOver:e=>{(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(eI))&&(e.preventDefault(),e.stopPropagation(),S(!0))},onDragLeave:e=>{e.currentTarget===e.target&&S(!1)},onDrop:t,className:B("min-h-full",k&&"bg-[var(--accent)]/30"),children:H(!!r,0,e)})}let K=R.has(a.path),G=O===a.path,q=null!=(r=null==m?void 0:m.has(a.path))&&r,{Icon:J,color:Z}=ej(a.path),et=M?U.dirs.get(a.path):U.files.get(a.path),er=et&&"*"!==et?P(et):null,en="*"===et?"#8C8C8C":null==er?void 0:er.color,ea=!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}(U.ignored,a.path),es=()=>{T.current&&(clearTimeout(T.current),T.current=null)},el=async e=>{if(!M)return;e.preventDefault(),e.stopPropagation(),S(!1),es(),y||L(!0);let t=e.dataTransfer.getData(eI);if(t){try{for(let e of JSON.parse(t))e===a.path||e.startsWith(a.path+"/")||null==u||u(e,a.path)}catch(e){t===a.path||t.startsWith(a.path+"/")||null==u||u(t,a.path)}return}let r=await eT(e.dataTransfer);r.length>0&&(null==d||d(r,a.path))},eo=M&&(null==(t=a.children)?void 0:t.some(e=>{let t=e=>{var r,n;return!!R.has(e.path)||null!=(n=null==(r=e.children)?void 0:r.some(t))&&n};return t(e)})),ei=g&&"rename"===g.mode&&g.originalPath===a.path,ec=g&&"rename"!==g.mode&&g.parentDir===a.path&&M;return ei&&g?(0,s.jsx)(eE,{depth:f,initialValue:null!=(n=g.originalName)?n:a.name,iconKind:M?"folder":"file",onCommit:e=>null==v?void 0:v(e),onCancel:()=>null==b?void 0:b()}):(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{draggable:!0,"data-path":a.path,onClick:e=>{if(e.stopPropagation(),M&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){x&&x(new Set([a.path]),a.path),L(!y);return}if(e.shiftKey&&x&&h&&p){let e=h.indexOf(p),t=h.indexOf(a.path);if(e>=0&&t>=0){let r=Math.min(e,t),n=Math.max(e,t);x(new Set(h.slice(r,n+1)),p)}return}if((e.ctrlKey||e.metaKey)&&x){let e=new Set(m);e.has(a.path)?e.delete(a.path):e.add(a.path),x(e,a.path);return}M||(x&&x(new Set([a.path]),a.path),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{I.current=null,i(a.path)},300))},onDoubleClick:e=>{e.stopPropagation(),I.current&&(clearTimeout(I.current),I.current=null),M?L(!y):i(a.path)},onDragStart:e=>{m&&m.size>1&&m.has(a.path)?e.dataTransfer.setData(eI,JSON.stringify([...m])):e.dataTransfer.setData(eI,JSON.stringify([a.path])),e.dataTransfer.effectAllowed="move"},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),!q&&x&&x(new Set([a.path]),a.path),null==c||c({x:e.clientX,y:e.clientY,path:a.path,name:a.name,isDir:M})},onDragOver:e=>{M&&(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(eI))&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",S(!0),y||T.current||(T.current=setTimeout(()=>{T.current=null,L(!0)},600)))},onDragLeave:()=>{S(!1),es()},onDrop:el,className:B("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&&G&&"bg-[var(--accent)] text-[var(--accent-foreground)]",!q&&!G&&"text-[var(--foreground)]",k&&M&&"bg-[var(--accent)] ring-1 ring-[var(--primary)]"),style:{paddingLeft:"".concat(12*f+8,"px")},children:[M&&(0,s.jsx)("span",{className:"shrink-0 text-[var(--muted-foreground)]",children:y?(0,s.jsx)(V.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(Q.A,{className:"h-3.5 w-3.5"})}),!M&&(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),M?y?(0,s.jsx)(X.A,{className:B("h-3.5 w-3.5 shrink-0 text-blue-400",ea&&"opacity-60")}):(0,s.jsx)($.A,{className:B("h-3.5 w-3.5 shrink-0 text-blue-400",ea&&"opacity-60")}):(0,s.jsx)(J,{className:B("h-3.5 w-3.5 shrink-0",Z,ea&&"opacity-60")}),(0,s.jsx)("span",{className:B("truncate",ea&&"text-[var(--muted-foreground)] opacity-60"),style:en?{color:en}:void 0,children:a.name}),(0,s.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-1 pl-1 pr-2",children:[(K||eo)&&(0,s.jsx)(Y.A,{className:"h-1.5 w-1.5 shrink-0 fill-amber-400 text-amber-400"}),M?en&&(0,s.jsx)(Y.A,{className:"h-1.5 w-1.5 shrink-0",style:{fill:en,color:en}}):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})]})]}),M&&y&&C&&!a.children&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-[10px] text-[var(--muted-foreground)]",style:{paddingLeft:"".concat((f+1)*12+8,"px")},children:[(0,s.jsx)(ee.A,{className:"h-3 w-3 animate-spin"}),(0,s.jsx)("span",{children:"Loading..."})]}),M&&y&&(a.children||ec)&&(0,s.jsx)("div",{children:H(!!ec,f+1,h)})]})}var eP=r(80151),eL=r(66731),eR=r(877),e_=r(94665),ez=r(11943),eO=r(90302),eU=r(19127);function eB(e){let{x:t,y:r,path:n,name:a,isDir:o,selectedCount:i,onAction:c,onClose:d}=e,u=(0,l.useRef)(null),[m,x]=(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 n=e.getBoundingClientRect(),a=window.innerWidth,s=window.innerHeight,l=t+n.width+4>a?Math.max(4,a-n.width-4):t,o=r+n.height+4>s?Math.max(4,s-n.height-4):r;(l!==m.x||o!==m.y)&&x({x:l,y:o})},[t,r,m.x,m.y]);let p={position:"fixed",left:m.x,top:m.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:n,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)(eP.A,{className:"h-3.5 w-3.5"}),"Delete ",i," items"]})]});let h=""===n&&o,f=!!window.haloReveal,g=h?[{icon:eL.A,label:"New File...",type:"new-file"},{icon:eR.A,label:"New Folder...",type:"new-folder"},{icon:ei.A,label:"Open in Integrated Terminal",type:"open-terminal"},...f?[{icon:e_.A,label:"Reveal in File Manager",type:"reveal-in-file-manager"}]:[]]:[{icon:eL.A,label:"New File...",type:"new-file",separatorAfter:!1},{icon:eR.A,label:"New Folder...",type:"new-folder",separatorAfter:!1},{icon:ei.A,label:"Open in Integrated Terminal",type:"open-terminal",separatorAfter:!f},...f?[{icon:e_.A,label:"Reveal in File Manager",type:"reveal-in-file-manager",separatorAfter:!0}]:[],...o?[]:[{icon:ez.A,label:"Open to the Side",type:"open-to-side",separatorAfter:!1},{icon:eO.A,label:"Download",type:"download"}],{icon:eU.A,label:"Rename",type:"rename"},{icon:eP.A,label:"Delete",type:"delete",danger:!0,separatorAfter:o},...o?[{icon:X.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:a}),g.map(e=>{let t=e.icon;return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>{c({type:e.type,path:n,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)})]})}d.wG.config({paths:{vs:"/monaco/vs"}});var eW=r(58321);let eH={dark:"vs-dark",light:"vs",midnight:"halo-midnight",warm:"halo-warm"},eK=!1;function eG(e){eK||(eK=!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 eq(e){let{path:t,content:r,language:n,onChange:a,onSave:o,onClose:i}=e,c=w(),u=(0,l.useRef)(null),{theme:m}=(0,eW.useTheme)(),x=(0,l.useRef)(o),p=(0,l.useRef)(i),h=(0,l.useRef)(r);(0,l.useEffect)(()=>{x.current=o,p.current=i,h.current=r},[o,i,r]),(0,l.useEffect)(()=>()=>{c.getState().setSelectedText(null,null)},[t]);let f=(0,l.useCallback)(e=>{void 0!==e&&a&&a(e)},[a]),g=(0,l.useCallback)((e,t)=>{u.current=e;let r=e.getModel();r&&r.getValue()!==h.current&&r.setValue(h.current),e.onDidChangeCursorSelection(t=>{var r,n;let a=e.getSelection();if(!a||a.isEmpty())return void c.getState().setSelectedText(null,null);let s=null!=(n=null==(r=e.getModel())?void 0:r.getValueInRange(a))?n:null;s&&c.getState().setSelectedText(s,{startLine:a.startLineNumber,endLine:a.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=p.current)||e.call(p)}})},[]);return(0,s.jsx)(d.Ay,{path:t,keepCurrentModel:!0,height:"100%",language:n,value:r,onChange:f,beforeMount:eG,onMount:g,theme:eH[m],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 eJ=r(10691),eZ=r(76633),e$=r(5659),eY=r(28965),eV=r(17119);function eQ(e){let{content:t,filePath:r,projectId:n}=e,a=(0,eV.kj)(),o=w(),i=(0,l.useRef)(null),c=(0,l.useMemo)(()=>(function(e){let t=[],r=new Map,n=!1;for(let s of e.split("\n")){var a;let e=s.trimEnd();if(/^\s*(```|~~~)/.test(e)){n=!n;continue}if(n)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!=(a=r.get(c))?a: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]),d=0,u=e=>{let t=i.current;if(!t)return;let r=t.querySelector("#".concat(CSS.escape(e)));r&&r.scrollIntoView({behavior:"smooth",block:"start"})},[m,x]=(0,l.useState)(()=>{try{return"1"===localStorage.getItem("halo.mdOutlineHidden")}catch(e){return!1}}),p=()=>{x(e=>{let t=!e;try{localStorage.setItem("halo.mdOutlineHidden",t?"1":"0")}catch(e){}return t})};(0,l.useEffect)(()=>{let e=i.current;if(!e)return;let t=o.getState().setSelectedText;function r(){let r=window.getSelection();if(!r||0===r.rangeCount)return;let n=r.getRangeAt(0);if(!(e&&e.contains(n.commonAncestorContainer)))return;if(r.isCollapsed)return void t(null,null);let a=r.toString();if(!a.trim())return void t(null,null);t(a,null)}return document.addEventListener("selectionchange",r),()=>{document.removeEventListener("selectionchange",r),t(null,null)}},[o]);let h=e=>function(t){var r;let{children:n}=t;return(0,s.jsx)(e,{id:null==(r=c[d++])?void 0:r.slug,children:n})};return(0,s.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[c.length>1&&!m&&(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:a("editor.outline")}),(0,s.jsx)("button",{onClick:p,title:a("editor.hideOutline"),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(e$.A,{className:"h-3.5 w-3.5"})})]}),c.map((e,t)=>(0,s.jsx)("button",{onClick:()=>u(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:i,className:"relative flex-1 overflow-y-auto px-8 py-6",children:[c.length>1&&m&&(0,s.jsx)("button",{onClick:p,title:a("editor.showOutline"),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)(eY.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)(eJ.oz,{remarkPlugins:[eZ.A],components:{h1:h("h1"),h2:h("h2"),h3:h("h3"),h4:h("h4"),h5:h("h5"),h6:h("h6"),a(e){let{href:t,children:r,node:n,...a}=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){}u(r)},...a,children:r}):(0,s.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...a,children:r})},img(e){let{src:t,alt:a,node:l,...o}=e,i=function(e,t,r){let n;if(!e)return null;if(/^(https?:|data:|blob:)/i.test(e))return e;if(!r)return null;if(e.startsWith("/"))n=e;else{if(!t)return null;let a=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",s=a?"".concat(a,"/").concat(e):e,l=[];for(let e of s.split("/"))""!==e&&"."!==e&&(".."===e?l.pop():l.push(e));n="".concat(r.replace(/\/$/,""),"/").concat(l.join("/"))}let a=new URLSearchParams;return a.set("path",n),a.set("projectId",r),a.set("inline","1"),"/api/files/download?".concat(a.toString())}("string"==typeof t?t:"",r,n);return i?(0,s.jsx)("img",{src:i,alt:null!=a?a:"",...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: ",a||String(t),"]"]})}},children:t})})]})]})}let eX=new Set;function e0(e){for(let r of eX)try{var t;null==(t=r.contentWindow)||t.postMessage({haloFace:e},"*")}catch(e){}}function e1(e){let{url:t,name:r}=e,n=(0,l.useRef)(null);return(0,l.useEffect)(()=>{if(n.current){var e;return e=n.current,eX.add(e),()=>{eX.delete(e)}}},[]),(0,s.jsx)("iframe",{ref:n,src:t,title:r,className:"h-full w-full border-0 bg-white",sandbox:"allow-scripts allow-same-origin",allow:"autoplay"})}function e3(e){let{original:t,modified:r,path:n}=e,a=Z(n),{theme:l}=(0,eW.useTheme)();return(0,s.jsx)(d.zC,{height:"100%",language:a,original:t,modified:r,beforeMount:eG,theme:eH[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 e5=r(74037),e2=r(97558),e4=r(56279),e8=r(53105);function e6(e){var t,r;let{x:n,y:a,path:o,groupIdx:i,onClose:c,onCloseTab:d}=e,u=w(),m=(0,l.useRef)(null);(0,l.useEffect)(()=>{function e(e){m.current&&!m.current.contains(e.target)&&c()}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]);let x=u.getState(),p=(null!=(r=null==(t=x.groups[i])?void 0:t.tabs)?r:[]).map(e=>x.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:m,className:"fixed z-50 min-w-[160px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",style:{left:n,top:a},children:f.map((e,t)=>(0,s.jsx)("button",{disabled:e.disabled,onClick:()=>{e.action(),c()},className:B("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 e9="application/x-halo-tab";function e7(e){let{tabs:t,activeTab:r,groupIdx:n,canSplit:a,onCloseTab:o,renderMode:i,onToggleRenderMode:c,showDiffButton:d,onToggleDiff:u}=e,m=(0,eV.kj)(),x=w(),p=(0,l.useRef)(null),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[y,N]=(0,l.useState)(null),[k,S]=(0,l.useState)(!1),[C,A]=(0,l.useState)(null),I=function(e){var t,r,n,a;let s=new Map,l=new Map;for(let n of e){let e=null!=(t=n.path.split("/").pop())?t:n.path;l.set(e,(null!=(r=l.get(e))?r:0)+1)}for(let t of e){let e=t.path.split("/"),r=null!=(n=e.pop())?n:t.path;(null!=(a=l.get(r))?a:0)>1&&e.length>0?s.set(t.path,"".concat(e[e.length-1],"/").concat(r)):s.set(t.path,r)}return s}(t),E=(0,l.useCallback)(()=>{let e=p.current;e&&(f(e.scrollLeft>0),v(e.scrollLeft+e.clientWidth<e.scrollWidth-1))},[]);(0,l.useEffect)(()=>{E();let e=p.current;if(!e)return;e.addEventListener("scroll",E);let t=new ResizeObserver(E);return t.observe(e),()=>{e.removeEventListener("scroll",E),t.disconnect()}},[E,t.length]);let T=e=>{var t;null==(t=p.current)||t.scrollBy({left:e,behavior:"smooth"})},M=()=>{j(null),N(null),S(!1)},F=x(e=>e.activeGroupIdx);return(0,s.jsxs)("div",{className:B("relative flex shrink-0 items-center border-b border-[var(--border)] bg-[var(--card)]",k&&"ring-1 ring-[var(--primary)]"),onDragOver:e=>{if(!te(e))return;let t=e.dataTransfer.types.includes(e9)?{srcGroupIdx:-1,path:""}:null;t&&t.srcGroupIdx!==n&&(e.preventDefault(),e.dataTransfer.dropEffect="move",S(!0))},onDragLeave:e=>{e.currentTarget===e.target&&S(!1)},onDrop:e=>{if(!te(e))return;e.preventDefault();let t=tt(e);t&&t.srcGroupIdx!==n&&x.getState().moveTabToGroup(t.srcGroupIdx,t.path,n),j(null),N(null),S(!1)},onMouseDown:()=>x.getState().setActiveGroup(n),children:[h&&(0,s.jsx)("button",{onClick:()=>T(-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)(e5.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("div",{ref:p,className:"flex flex-1 overflow-x-hidden",children:t.map((e,t)=>{var a;let{Icon:l,color:i}=ej(e.path),c=e.path===r&&n===F,d=e.path===r&&n!==F;return(0,s.jsxs)("div",{draggable:!0,onDragStart:r=>{var a;return a=e.path,j(t),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),void r.dataTransfer.setData(e9,JSON.stringify({srcGroupIdx:n,path:a}))},onDragOver:e=>{te(e)&&(e.preventDefault(),e.dataTransfer.dropEffect="move",N(t))},onDrop:e=>((e,t)=>{if(!te(e))return;e.preventDefault();let r=tt(e);r&&x.getState().moveTabToGroup(r.srcGroupIdx,r.path,n,t),j(null),N(null),S(!1)})(e,t),onDragEnd:M,onContextMenu:t=>{t.preventDefault(),A({x:t.clientX,y:t.clientY,path:e.path})},className:B("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,n),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:B("h-3.5 w-3.5 shrink-0",i)}),(0,s.jsx)("span",{className:"max-w-40 truncate",children:null!=(a=I.get(e.path))?a:e.path.split("/").pop()}),e.modified?(0,s.jsx)(Y.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)(e2.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)(e2.A,{className:"h-3 w-3"})})]},e.path)})}),g&&(0,s.jsx)("button",{onClick:()=>T(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)(Q.A,{className:"h-3.5 w-3.5"})}),(()=>{let e=t.find(e=>e.path===r),n=(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:[n&&(0,s.jsxs)("button",{onClick:c,title:i?"Switch to source view":"Switch to rendered view",className:B("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)(eU.A,{className:"h-3 w-3"}):(0,s.jsx)(e4.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:i?"Edit":"Preview"})]}),d&&(0,s.jsxs)("button",{onClick:u,title:m("editor.viewDiff"),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)(e8.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:m("editor.diff")})]})]})})(),a&&(0,s.jsx)("button",{title:m("editor.splitRight"),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)(ez.A,{className:"h-3.5 w-3.5"})}),C&&(0,s.jsx)(e6,{x:C.x,y:C.y,path:C.path,groupIdx:n,onClose:()=>A(null),onCloseTab:o})]})}function te(e){return e.dataTransfer.types.includes(e9)}function tt(e){try{let t=e.dataTransfer.getData(e9);if(!t)return null;return JSON.parse(t)}catch(e){return null}}let tr=new Map,tn={extensions:[],errors:[]},ta=0,ts=new Set;function tl(){for(let e of(ta++,ts))e()}function to(e){return ts.add(e),()=>{ts.delete(e)}}function ti(){return ta}function tc(){return(0,l.useSyncExternalStore)(to,ti,ti)}function td(e){for(let t of e.extensions)tr.set(t.toLowerCase(),e);tl()}function tu(e){tn=e,tl()}let tm=null;function tx(){if(!tm){let e=N.F.extensions.list().then(tu).catch(e=>{console.error("[PreviewRegistry] Failed to load extensions:",e)});tm=Promise.race([e,new Promise(t=>{let r=setTimeout(()=>{console.warn("[PreviewRegistry] Extension list not back after ".concat(3e3,"ms, opening files without it")),t()},3e3);e.finally(()=>clearTimeout(r))})])}return tm}function tp(){return tn}function th(e,t){let r=".".concat(e);return tn.extensions.filter(e=>e.priority===t&&e.extensions.includes(r)).sort((e,t)=>t.installedAt-e.installedAt).map(e=>({kind:"extension",info:e}))}function tf(e){let t=e.toLowerCase().replace(/^\./,""),r=th(t,"default"),n=tr.get(t);return n&&r.push({kind:"builtin",plugin:n}),r.push(...th(t,"option")),r.push({kind:"text"}),r}function tg(e){switch(e.kind){case"extension":return"extension:".concat(e.info.id);case"builtin":return"builtin:".concat(e.plugin.id);case"text":return"text"}}function tv(e){return"text"!==tf(e)[0].kind}let tb={id:"pdf",extensions:["pdf"],Component:(0,l.lazy)(()=>r.e(839).then(r.bind(r,9839)).then(e=>({default:e.PdfPreview})))},tj={id:"docx",extensions:["docx","doc"],Component:(0,l.lazy)(()=>r.e(449).then(r.bind(r,32449)).then(e=>({default:e.DocxPreview})))},ty={id:"xlsx",extensions:["xlsx","xls"],Component:(0,l.lazy)(()=>r.e(892).then(r.bind(r,28892)).then(e=>({default:e.XlsxPreview})))},tw={id:"pptx",extensions:["pptx","ppt"],Component:(0,l.lazy)(()=>Promise.all([r.e(819),r.e(522),r.e(160),r.e(868)]).then(r.bind(r,49868)).then(e=>({default:e.PptxPreview}))),heavy:!0};var tN=r(27173);let tk={id:"parquet",extensions:["parquet"],Component:(0,l.lazy)(()=>r.e(613).then(r.bind(r,37613)).then(e=>({default:e.ParquetPreview})))},tS={id:"sqlite",extensions:["db","sqlite","sqlite3"],Component:(0,l.lazy)(()=>r.e(362).then(r.bind(r,84362)).then(e=>({default:e.SqlitePreview})))},tC={id:"csv",extensions:["csv","tsv"],Component:(0,l.lazy)(()=>r.e(73).then(r.bind(r,27073)).then(e=>({default:e.CsvPreview})))};td(tb),td(tj),td(ty),td(tw),td(tN.SQ),td(tk),td(tS),td(tC);var tA=r(37050);let tI=null,tE=null;function tT(e){return{ready:!1,dirty:!1,mtime:null,saving:!1,retried:!1,capabilities:e}}function tM(e){return e.capabilities.includes("save")}function tF(e,t,r){return r.ok?{state:{...e,saving:!1,retried:!1,dirty:!1,mtime:r.mtime},effects:[{type:"post",frame:{haloExt:1,type:"saved",mtime:r.mtime}},{type:"set-modified",modified:!1}]}:"mtime"in r?e.retried?{state:{...e,saving:!1,retried:!1},effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"conflict",message:"file changed on disk again",mtime:r.mtime}},{type:"error",message:"Save failed: the file keeps changing on disk"}]}:{state:{...e,saving:!1},effects:[{type:"confirm-conflict",buffer:t,diskMtime:r.mtime}]}:{state:{...e,saving:!1,retried:!1},effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"io",message:r.message}},{type:"error",message:"Save failed: ".concat(r.message)}]}}let tD=new Map;function tP(e,t){return"".concat(null!=e?e:"","::").concat(t)}function tL(e){var t,r;let{info:n,uninstalled:a,name:o,path:i,projectId:c,viewUrl:d,downloadUrl:u,size:m,onOpenAsText:x}=e,p=(0,eV.kj)(),h=w(),{theme:f}=(0,eW.useTheme)(),g="light"===f?"light":"dark",v=(0,l.useRef)(null),b=(0,l.useRef)(tT(n.capabilities)),[j,y]=(0,l.useState)(0),[k,S]=(0,l.useState)(null),[C,A]=(0,l.useState)("token"),[I,E]=(0,l.useState)(null),[T,M]=(0,l.useState)(null),F=(0,l.useRef)(null),D=(0,l.useRef)(null),P=(0,l.useRef)(n.version),L={file:{name:o,path:i,size:null!=m?m:0,ext:null!=(r=null==(t=o.split(".").pop())?void 0:t.toLowerCase())?r:""},theme:g},R=(0,l.useRef)(L),_=(0,l.useRef)(()=>{}),z=(0,l.useCallback)(e=>{for(let t of(b.current=e.state,e.effects))_.current(t)},[]),O=()=>{F.current&&(clearTimeout(F.current),F.current=null)},U=e=>{var t,r,a,s;switch(e.type){case"post":null==(r=v.current)||null==(t=r.contentWindow)||t.postMessage(e.frame,"*",null!=(a=e.transfer)?a:[]);return;case"load":(async()=>{try{var e;let[t,r]=await Promise.all([fetch(d),c?N.F.files.stat(i,c).catch(()=>null):Promise.resolve(null)]);if(!t.ok)throw Error("HTTP ".concat(t.status));let n=await t.arrayBuffer();z(function(e,t,r){let n=[{type:"post",frame:{haloExt:1,type:"load",buffer:t,mtime:null!=r?r:0},transfer:[t]}];return e.dirty&&n.push({type:"set-modified",modified:!1}),{state:{...e,mtime:r,dirty:!1},effects:n}}(b.current,n,null!=(e=null==r?void 0:r.modifiedAt)?e:null))}catch(e){E("Failed to load file: ".concat(e instanceof Error?e.message:String(e)))}})();return;case"put":if(O(),!c)return void z(tF(b.current,e.buffer,{ok:!1,status:0,message:"no workspace"}));N.F.files.saveRaw(i,e.buffer,c,null!=(s=e.expectMtime)?s:void 0).then(t=>z(tF(b.current,e.buffer,t)));return;case"set-modified":e.modified?h.getState().markModified(i):h.getState().clearModified(i);return;case"error":E(e.message);return;case"confirm-conflict":(async()=>{let t=i.split("/").pop(),r=await G('"'.concat(t,'" changed on disk since you opened it. Overwrite the disk version with your changes?'))?"overwrite":await G('Discard your changes and reload "'.concat(t,'" from disk? (Cancel keeps your unsaved changes.)'))?"discard":"cancel";z(function(e,t,r,n){switch(t){case"overwrite":return{state:{...e,saving:!0,retried:!0},effects:[{type:"put",buffer:r,expectMtime:n}]};case"discard":return{state:e,effects:[{type:"load"}]};case"cancel":return{state:e,effects:[]}}}(b.current,r,e.buffer,e.diskMtime))})();return;case"warn":console.warn("[ExtensionHost] ".concat(n.id,": ").concat(e.message));return}};(0,l.useEffect)(()=>{R.current=L,_.current=U});let B=()=>{M(null),A("token"),E(null),S(null),y(e=>e+1)};(0,l.useEffect)(()=>{let e=!1;return b.current.dirty&&h.getState().clearModified(i),b.current=tT(n.capabilities),(tI&&tI.expiresAt-Date.now()>6e4?Promise.resolve(tI.token):(!tE&&(tE=N.F.extensions.token().then(e=>(tI=e,e.token)).finally(()=>{tE=null})),tE)).then(t=>{if(!e){var r,a,s;P.current=n.version,S((r=n.id,a=n.version,s=n.entry,"/api/extensions/".concat(encodeURIComponent(r),"/").concat(encodeURIComponent(a),"/").concat(encodeURIComponent(t),"/").concat(s))),A("loading"),D.current=setTimeout(()=>{b.current.ready||A("failed")},1e4)}}).catch(t=>{e||(E(t instanceof Error?t.message:String(t)),A("failed"))}),()=>{e=!0,D.current&&clearTimeout(D.current)}},[j]),(0,l.useEffect)(()=>{let e=e=>{var t,r;e.source===(null==(t=v.current)?void 0:t.contentWindow)&&"object"==typeof(r=e.data)&&null!==r&&1===r.haloExt&&"string"==typeof r.type&&("ready"===e.data.type&&(D.current&&(clearTimeout(D.current),D.current=null),A("ready")),"save"===e.data.type&&O(),z(function(e,t,r){switch(t.type){case"ready":if(e.ready)return{state:e,effects:[{type:"warn",message:"duplicate ready frame ignored"}]};return{state:{...e,ready:!0},effects:[{type:"post",frame:{haloExt:1,type:"init",protocol:1,file:r.file,capabilities:e.capabilities,theme:r.theme}},{type:"load"}]};case"dirty":if(!e.ready)return{state:e,effects:[{type:"warn",message:"dirty before ready ignored"}]};if(!tM(e))return{state:e,effects:[{type:"warn",message:"dirty from an extension without the save capability ignored"}]};if(e.dirty===t.dirty)return{state:e,effects:[]};return{state:{...e,dirty:t.dirty},effects:[{type:"set-modified",modified:t.dirty}]};case"save":if(!e.ready)return{state:e,effects:[{type:"warn",message:"save before ready ignored"}]};if(!tM(e))return{state:e,effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"denied",message:"extension did not declare the save capability"}},{type:"warn",message:"save from an extension without the save capability denied"}]};if(e.saving)return{state:e,effects:[{type:"warn",message:"save while a save is in flight dropped"}]};return{state:{...e,saving:!0},effects:[{type:"put",buffer:t.buffer,expectMtime:e.mtime}]};case"error":return{state:e,effects:[{type:"error",message:t.message}]}}}(b.current,e.data,R.current)))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[z]),(0,l.useEffect)(()=>{var e;z((e=b.current,e.ready?{state:e,effects:[{type:"post",frame:{haloExt:1,type:"theme",theme:g}}]}:{state:e,effects:[]}))},[g,z]);let W=(0,l.useCallback)(()=>{let e=b.current;z(e.ready&&tM(e)&&e.dirty&&!e.saving?{state:e,effects:[{type:"post",frame:{haloExt:1,type:"save-request"}}]}:{state:e,effects:[]}),e.ready&&e.dirty&&!e.saving&&(O(),F.current=setTimeout(()=>{F.current=null,b.current.dirty&&!b.current.saving&&window.alert('Extension "'.concat(n.name,'" did not respond to the save request.'))},5e3))},[z,n.name]);(0,l.useEffect)(()=>(function(e,t,r){let n=tP(e,t);return tD.set(n,r),()=>{tD.get(n)===r&&tD.delete(n)}})(c,i,{requestSave:W,fileChanged(){c&&N.F.files.stat(i,c).then(e=>{var t,r;return z((t=b.current,r=e.modifiedAt,!t.ready||null!=t.mtime&&r<=t.mtime||t.dirty?{state:t,effects:[]}:{state:t,effects:[{type:"load"}]}))}).catch(()=>{})}}),[c,i,W,z]),(0,l.useEffect)(()=>{if(n.version!==P.current){if(b.current.dirty)return void M(p("editor.extension.updated",{version:n.version}));B()}},[n.version,p]),(0,l.useEffect)(()=>()=>{O(),b.current.dirty&&h.getState().clearModified(i)},[h,i]);let H=async()=>{(!b.current.dirty||await G('"'.concat(o,'" has unsaved changes. Discard them and reload?')))&&B()},K=n.capabilities.includes("save")?(0,s.jsx)(tA.IB,{onClick:W,title:p("editor.extension.save"),children:(0,s.jsx)("span",{children:p("editor.extension.save")})}):void 0;return(0,s.jsx)(tA.no,{name:o,downloadUrl:u,onOpenAsText:x,extraToolbar:K,children:(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[a&&(0,s.jsx)(tR,{children:p("editor.extension.uninstalled")}),T&&(0,s.jsxs)(tR,{onClose:()=>M(null),children:[T,(0,s.jsx)("button",{onClick:H,className:"ml-2 text-[var(--primary)] hover:underline",children:p("editor.extension.reload")})]}),I&&"failed"!==C&&(0,s.jsx)(tR,{onClose:()=>E(null),children:I}),"failed"===C?(0,s.jsxs)("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[(0,s.jsx)("p",{className:"text-sm text-[var(--foreground)]",children:p("editor.extension.unresponsive",{name:n.name})}),I&&(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:I}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{onClick:H,className:"inline-flex items-center rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90",children:p("editor.extension.retry")}),x&&(0,s.jsx)("button",{onClick:x,className:"inline-flex items-center rounded-md border border-[var(--border)] bg-[var(--secondary)] px-4 py-2 text-xs font-medium text-[var(--foreground)] hover:opacity-90",children:p("editor.openAsText")})]})]}):(0,s.jsxs)("div",{className:"relative min-h-0 flex-1",children:[k&&(0,s.jsx)("iframe",{ref:v,src:k,sandbox:"allow-scripts allow-same-origin",allow:"",referrerPolicy:"no-referrer",title:n.name,className:"h-full w-full border-0 bg-[var(--background)]"},j),"ready"!==C&&(0,s.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-[var(--background)]/80 text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})]})]})})}function tR(e){let{children:t,onClose:r}=e;return(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5 text-xs text-[var(--foreground)]",children:[(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t}),r&&(0,s.jsx)("button",{onClick:r,className:"shrink-0 text-[var(--muted-foreground)] hover:text-[var(--foreground)]","aria-label":"Dismiss",children:"\xd7"})]})}var t_=r(46415),tz=r(22726);function tO(e){let{candidates:t,current:r,onPick:n}=e,a=(0,eV.kj)(),[o,i]=(0,l.useState)(!1),c=tg(r);return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsxs)("button",{onClick:()=>i(e=>!e),title:a("editor.openWith"),className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[(0,s.jsx)(t_.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:a("editor.openWith")})]}),o&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-20",onClick:()=>i(!1)}),(0,s.jsx)("div",{className:"absolute right-0 top-full z-30 mt-0.5 min-w-[180px] rounded-md border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:t.map(e=>{let t=tg(e),r=t===c;return(0,s.jsxs)("button",{onClick:()=>{i(!1),r||n(e)},className:B("flex w-full items-center gap-2 px-3 py-1.5 text-left text-[11px] transition-colors hover:bg-[var(--secondary)]",r?"text-[var(--foreground)]":"text-[var(--foreground)]/80"),children:[(0,s.jsx)(tz.A,{className:B("h-3 w-3 shrink-0",!r&&"invisible")}),(0,s.jsx)("span",{className:"truncate",children:"text"===e.kind?a("editor.openAsText"):"builtin"===e.kind?a("editor.openWith.builtin",{id:e.plugin.id}):e.info.name}),"extension"===e.kind&&(0,s.jsxs)("span",{className:"ml-auto shrink-0 text-[9px] text-[var(--muted-foreground)]",children:["v",e.info.version]})]},t)})})]})]})}let tU="https://github.com/turmind/halo-hub";function tB(){return(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})}function tW(e){var t,r;tc();let n=w();if(e.tooLarge)return(0,s.jsx)(tK,{...e});let a=null!=(r=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?r:"",l=tf(a);return(0,s.jsx)(tH,{...e,candidates:l,useEditorStore:n},a)}function tH(e){var t,r;let n,{candidates:a,useEditorStore:o,...i}=e,[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)(null),x=o(e=>{var t;return!!(null==(t=e.buffers[i.path])?void 0:t.modified)}),p=e=>a.find(t=>tg(t)===tg(e)),h=null!=(t=c&&p(c))?t:a[0],f=!1;(null==u?void 0:u.kind)==="extension"&&!p(u)&&x&&(h=u,f=!0),u&&tg(u)===tg(h)&&("extension"!==u.kind||"extension"!==h.kind||u.info===h.info)||m(h);let g=async e=>{if(!x||await G('"'.concat(i.name,'" has unsaved changes. Discard them and switch viewer?'))){if("text"===e.kind){var t;null==(t=i.onOpenAsText)||t.call(i);return}d(e)}},v=a.length>2?(0,s.jsx)(tO,{candidates:a,current:h,onPick:g}):null;if("extension"===h.kind&&(null!=(r=i.size)?r:0)>0x6400000)n=(0,s.jsx)(tA.no,{name:i.name,downloadUrl:i.downloadUrl,onOpenAsText:i.onOpenAsText,children:(0,s.jsx)(tK,{...i,maxLabel:"100MB"})});else if("extension"===h.kind)n=(0,s.jsx)(tL,{...i,info:h.info,uninstalled:f},h.info.id);else if("builtin"===h.kind){let{Component:e}=h.plugin;n=(0,s.jsx)(l.Suspense,{fallback:(0,s.jsx)(tB,{}),children:(0,s.jsx)(e,{...i})})}else n=(0,s.jsx)(tG,{...i});return(0,s.jsx)(tA.NU.Provider,{value:v,children:n})}function tK(e){let{name:t,size:r,downloadUrl:n,maxLabel:a="10MB"}=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)(eg.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.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)]",children:[null!=r?"".concat(J(r)," \xb7 "):"","File is too large to preview (max ",a,")"]}),(0,s.jsx)("a",{href:n,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"})]})}function tG(e){let{name:t,projectId:r,downloadUrl:n,onOpenAsText:a}=e,o=(0,eV.kj)(),[i,c]=(0,l.useState)({url:tU,raw:""});return(0,l.useEffect)(()=>{let e=!0;return N.F.settings.getSchema(r).then(t=>{var r,n;let a=null==(r=t.sections.find(e=>"extension"===e.namespaceId))?void 0:r.fields.find(e=>"hub_repo"===e.key);e&&c({url:function(e){let t=(null!=e?e:"").trim();return!t||t.startsWith("{{")?tU:/^[A-Za-z0-9][\w.-]*\/[\w.-]+$/.test(t)?"https://github.com/".concat(t):/^https?:\/\//.test(t)?t.replace(/\/+$/,"").replace(/\.git$/,""):null}(null==a?void 0:a.value),raw:null!=(n=null==a?void 0:a.value)?n:""})}).catch(()=>{}),()=>{e=!1}},[r]),(0,s.jsx)(tA.no,{name:t,downloadUrl:n,onOpenAsText:a,children:(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)(eg.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:o("editor.unsupported.title")}),(0,s.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)]",children:[o("editor.unsupported.hub")," ",i.url?(0,s.jsxs)("a",{href:i.url,target:"_blank",rel:"noopener",className:"text-[var(--primary)] hover:underline",children:[i.url===tU?"halo-hub":i.url.replace(/^https?:\/\//,"")," ↗"]}):(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:i.raw})]}),(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:o("editor.openAsText")}),(0,s.jsx)("a",{href:n,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:o("editor.download")})]})]})})}let tq=(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,n){var a;let s=r.trim();if(!s)return;let l=null!=(a=s.split("/").filter(Boolean).pop())?a:s,o={id:s,name:l,path:s,workspaceId:n,createdAt:Date.now()},i=t().projects;i.find(e=>e.path===s)||e({projects:[...i,o]}),e({activeProject:o,folderPath:s})}}));var tJ=r(65099),tZ=r(95037),t$=r(31367);function tY(e,t){if(!e||!t)return!0;let r=t.split("/").filter(Boolean),n=e;for(let e of r){var a;if(!(n=null==n||null==(a=n.children)?void 0:a.find(t=>t.name===e)))return!1}return"directory"===n.type}function tV(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}let tQ=new Set(["tiff","tif","zip","tar","gz","bz2","xz","7z","rar","woff","woff2","ttf","otf","eot","exe","dll","so","dylib","o","a","class","pyc","wasm"]);async function tX(e){return!!(tQ.has(e)||tv(e))||(await tx(),tv(e))}function t0(e){let{projectId:t,mode:r="full",showMaximize:n=!0}=e,a=(0,eV.kj)(),o=w(),c=o(e=>e.tabs),d=o(e=>e.activeTab),x=o(e=>e.buffers),p=o(e=>e.groups),h=o(e=>e.activeGroupIdx),f=o(e=>e.maximized),g="editor-only"===r,[v,j]=(0,l.useState)(!0),[y,k]=(0,l.useState)({}),[E,T]=(0,l.useState)({});function M(e){var t;return null==(t=E[e])||t}let[F,D]=(0,l.useState)(null),[P,L]=(0,l.useState)(new Set),[R,_]=(0,l.useState)(null),[z,O]=(0,l.useState)(null),[U,W]=(0,l.useState)(null),H=(0,l.useRef)(null),K=(0,l.useRef)(null),{tree:q,loading:$}=function(e){let t=w(),[r,n]=(0,l.useState)(!1),[a,s]=(0,l.useState)(null),o=t(e=>e.fileTree),i=(0,l.useCallback)(async()=>{if(e){n(!0),s(null);try{let r=await N.F.files.tree(e);t.getState().setFileTree(A(e,r))}catch(e){s(e instanceof Error?e.message:"Failed to load file tree"),console.error("[useFileTree] Error:",e)}finally{n(!1)}}},[e,t]);return(0,l.useEffect)(()=>{e&&i()},[e,i]),(0,l.useEffect)(()=>{if(e)return S.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]),(0,l.useEffect)(()=>{if(e)return C(S,()=>I(e,t))},[e,t]),{tree:o,loading:r,error:a,refresh:i}}(t),[Y,V]=(0,l.useState)(!1),Q=(0,l.useRef)(null),X=tc(),ee=(0,l.useCallback)(e=>{var t,r;let n=tf(null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"")[0];return"builtin"===n.kind?!!n.plugin.heavy:"extension"===n.kind&&!n.info.capabilities.includes("save")},[]),[et,er]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=[];for(let t of p){let r=t.activeTab;if(!r)continue;let n=x[r];(null==n?void 0:n.preview)&&(ee(r)||e.push(r))}0!==e.length&&er(t=>{let r=t.slice();for(let t=e.length-1;t>=0;t--){let n=e[t];r=[n,...r.filter(e=>e!==n)]}return(r=[...r.slice(0,5),...r.slice(5).filter(e=>{var t;return null==(t=x[e])?void 0:t.modified})],t.length===r.length&&t.every((e,t)=>e===r[t]))?t:r})},[p,x,ee,X]),(0,l.useEffect)(()=>{er(e=>{let t=new Set;for(let e of p)for(let r of e.tabs)t.add(r);let r=e.filter(e=>t.has(e));return r.length===e.length?e:r})},[p]),(0,l.useEffect)(()=>{o.getState().setModelPathPrefix(null!=t?t:null)},[t,o]),(0,l.useEffect)(()=>{if(!t)return;Q.current&&Q.current!==t&&(m(Q.current,Object.keys(o.getState().buffers)),o.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}}),V(!1)),Q.current=t;let e="halo_tabs:".concat(t),r=localStorage.getItem(e);if(!r)return void V(!0);let n=!1;return async function(){try{var e,a,s;let l=JSON.parse(r),i=null!=(a=l.groups)?a:l.tabs?[{tabs:l.tabs,activeTab:null!=(e=l.activeTab)?e:null}]:[],c=null!=(s=l.activeGroupIdx)?s:0;if(0===i.length)return void V(!0);let d=Array.from(new Set(i.flatMap(e=>e.tabs.map(e=>e.path)))),u=new Map;for(let e of i)for(let t of e.tabs)u.has(t.path)||u.set(t.path,t.language);let m=await Promise.all(d.map(async e=>{var r,n;let a=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";if(await tX(a))try{let r=await N.F.files.stat(e,t);return{path:e,content:"",originalContent:"",language:"",size:r.size,mtime:r.modifiedAt,createdAt:r.createdAt,preview:{downloadUrl:N.F.files.downloadUrl(e,t),viewUrl:N.F.files.viewUrl(e,t)}}}catch(e){return null}try{let r=await N.F.files.read(e,t);return{path:e,content:r.content,originalContent:r.content,language:u.get(e)||Z(e),mtime:r.modifiedAt,size:r.size,createdAt:r.createdAt}}catch(e){return null}}));if(n)return;let x={};for(let e of m)e&&(x[e.path]=e);let p=i.map((e,t)=>{var r;let n=e.tabs.map(e=>e.path).filter(e=>x[e]),a=e.activeTab&&n.includes(e.activeTab)?e.activeTab:null!=(r=n[0])?r:null;return{id:"g_restored_".concat(t,"_").concat(Date.now().toString(36)),tabs:n,activeTab:a}}).filter(e=>e.tabs.length>0);if(0===p.length)o.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(c,p.length-1)),t=p[e],r=t.tabs.map(e=>x[e]).filter(e=>!!e);o.setState({buffers:x,groups:p,activeGroupIdx:e,tabs:r,activeTab:t.activeTab})}}catch(e){}n||V(!0)}(),()=>{n=!0}},[t]),(0,l.useEffect)(()=>{if(!t||!Y)return;let e=p.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(t),JSON.stringify({groups:e,activeGroupIdx:h}))},[p,h,x,t,Y]);let en=c.find(e=>e.path===d),ea=(0,l.useCallback)(()=>{let e=o.getState().activeTab;if(!e||!t)return;let r=o.getState().tabs.find(t=>t.path===e);r&&!r.preview&&N.F.files.stat(e,t).then(r=>{o.getState().checkAndRefresh(e,r.modifiedAt,()=>N.F.files.read(e,t))}).catch(()=>{})},[t]);(0,l.useEffect)(()=>{Y&&ea()},[d,ea,Y]);let es=tq(e=>{var t;return null==(t=e.activeProject)?void 0:t.path});(0,l.useEffect)(()=>{if(t&&es)return S.on("file:changed",e=>{if("change"!==e.action)return;let r="".concat(es,"/").concat(e.path),n=t.endsWith("/")?t:"".concat(t,"/");if(!r.startsWith(n))return;let a=r.slice(n.length),s=o.getState().tabs.find(e=>e.path===a);if(s){if(s.preview){var l;null===(l=tD.get(tP(t,a)))||void 0===l||l.fileChanged();return}s.modified||N.F.files.read(a,t).then(e=>{o.getState().checkAndRefresh(a,e.modifiedAt,async()=>({content:e.content,modifiedAt:e.modifiedAt}))}).catch(()=>{})}})},[t,es,o]),(0,l.useEffect)(()=>{if("tree-only"===r)return;let e=()=>ea();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[ea,r]),(0,l.useEffect)(()=>{if("tree-only"!==r)return C(S,ea)},[ea,r]);let el=(0,l.useCallback)(async e=>{var r,n;if(!t)return;let a=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"";if(await tX(a)){let r,n=N.F.files.downloadUrl(e,t),a=N.F.files.viewUrl(e,t);try{let n=await N.F.files.stat(e,t);r={size:n.size,mtime:n.modifiedAt,createdAt:n.createdAt}}catch(e){}o.getState().openPreview(e,n,a,r);return}if(o.getState().tabs.find(t=>t.path===e))return void o.getState().setActiveTab(e);try{let r=await N.F.files.read(e,t),n=Z(e);o.getState().openFile(e,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(n){console.error("[EditorPanel] Failed to read file:",n);let r=n instanceof Error?n.message:String(n);if(r.includes("413")||r.includes("too large")){let r;try{let n=await N.F.files.stat(e,t);r={size:n.size,mtime:n.modifiedAt,createdAt:n.createdAt}}catch(e){}o.getState().openPreview(e,N.F.files.downloadUrl(e,t),N.F.files.viewUrl(e,t),{...r,tooLarge:!0})}}},[t]),eo=(0,l.useCallback)(async(e,t)=>{let r=o.getState(),n=r.buffers[t],a=r.groups.some((r,n)=>n!==e&&r.tabs.includes(t));(null==n||!n.modified||a||await G('"'.concat(t.split("/").pop(),'" has unsaved changes. Close anyway?')))&&o.getState().closeTabIn(e,t)},[]),ei=(0,l.useCallback)(async e=>{if(t)try{let r=await N.F.files.read(e,t),n=Z(e);o.getState().closeTab(e),o.getState().openFile(e,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(e){console.error("[EditorPanel] Failed to open as text:",e)}},[t]),ec=(0,l.useCallback)((e,t)=>{o.getState().updateContent(e,t)},[]),ed=(0,l.useCallback)(async e=>{let r=null!=e?e:d;if(!r||!t)return;let n=o.getState().tabs.find(e=>e.path===r);if(!n||!n.modified)return;let a=tD.get(tP(t,r));if(a)return void a.requestSave();try{let e=await N.F.files.save(r,n.content,t);o.getState().markSaved(r,e.modifiedAt)}catch(e){console.error("[EditorPanel] Failed to save file:",e)}},[t,d]),eu=(0,l.useCallback)((e,t)=>{let r=o.getState().buffers[t];r&&k(n=>({...n,[e]:{original:r.originalContent,modified:r.content,path:t}}))},[]),em=(0,l.useCallback)(e=>{k(t=>({...t,[e]:null}))},[]),ex=(0,l.useCallback)(async(e,r)=>{if(!t)return;let n=new AbortController;H.current=n,W({count:e.length,progress:0});try{await N.F.files.upload(e,t,r||void 0,(e,t)=>{t>0&&W(r=>r?{...r,progress:e/t*100}:null)},n.signal),W(e=>e?{...e,progress:100}:null),setTimeout(()=>W(null),400),I(t,o)}catch(e){if(W(null),e instanceof DOMException&&"AbortError"===e.name)return;console.error("[EditorPanel] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}finally{H.current=null}},[t]),ep=(0,l.useCallback)(async(e,r)=>{var n;if(!t)return;let a=null!=(n=e.split("/").pop())?n:"",s=r?"".concat(r,"/").concat(a):a;if(e!==s)try{await N.F.files.rename(e,s,t);let r=o.getState();r.tabs.find(t=>t.path===e)&&r.closeTab(e),I(t,o)}catch(e){console.error("[EditorPanel] Move failed:",e),window.alert(e instanceof Error?e.message:"Move failed")}},[t]),eh=(0,l.useCallback)((e,t)=>{L(e),t&&_(t)},[]),ef=(0,l.useCallback)(e=>{D(e)},[]),eg=(0,l.useCallback)(async e=>{var r,n,a,s,l;if(!t)return;let i=""===e.path&&e.isDir,c=(()=>{if(!i)return{path:e.path,isDir:e.isDir};if(0===P.size)return{path:"",isDir:!0};let t=P.values().next().value;return{path:t,isDir:tY(q,t)}})(),d=c.isDir?c.path:c.path.includes("/")?c.path.substring(0,c.path.lastIndexOf("/")):"";if("new-file"===e.type||"new-folder"===e.type){d&&eC(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!=(n=null==(r=e.path.split(".").pop())?void 0:r.toLowerCase())?n:"",l=await tX(s),i=o.getState();1===i.groups.length&&i.splitToRight(null!=(a=i.groups[0].activeTab)?a:e.path);let c=+(o.getState().groups.length>1);if(l){let r=await N.F.files.stat(e.path,t);o.getState().openFileInGroup(c,e.path,"","",r.modifiedAt,{size:r.size,createdAt:r.createdAt}),o.setState(r=>({buffers:{...r.buffers,[e.path]:{...r.buffers[e.path],preview:{downloadUrl:N.F.files.downloadUrl(e.path,t),viewUrl:N.F.files.viewUrl(e.path,t)}}}}))}else{let r=await N.F.files.read(e.path,t),n=Z(e.path);o.getState().openFileInGroup(c,e.path,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.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(!es)return;let e=d?"".concat(es,"/").concat(d):es;b.getState().requestTerminalSpawn(e),b.getState().setBottomTab("terminal");return}if("open-as-workspace"===e.type){if(!e.isDir||!es)return;let t=e.path?"".concat(es,"/").concat(e.path):es;window.dispatchEvent(new CustomEvent("halo:open-workspace",{detail:{path:t}}));return}if("reveal-in-file-manager"===e.type){if(!es)return;let t=window.haloReveal;if(!t)return;let r=e.path?"".concat(es,"/").concat(e.path):es;t.reveal(r,e.isDir);return}if("download"===e.type){let r=N.F.files.downloadUrl(e.path,t),n=document.createElement("a");n.href=r,n.download=null!=(s=e.path.split("/").pop())?s:"file",document.body.appendChild(n),n.click(),n.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 r=P.size>1&&P.has(e.path)?Array.from(P):[e.path];if(r.length>1){if(!await G("Delete ".concat(r.length," items?")))return}else{let t=e.isDir?"folder":"file";if(!await G("Delete ".concat(t,' "').concat(e.path.split("/").pop(),'"?')))return}try{for(let e of r)await N.F.files.remove(e,t),o.getState().closeTab(e);L(new Set),I(t,o)}catch(e){console.error("[EditorPanel] Delete failed:",e),window.alert(e instanceof Error?e.message:"Delete failed"),I(t,o)}}},[t,P]),ev=(0,l.useCallback)(()=>{O(null)},[]),eb=(0,l.useCallback)(async e=>{if(!t||!z)return;let r=e.trim();if(""===r)return void O(null);let{mode:n,parentDir:a,originalPath:s,originalName:l}=z;if("rename"===n){if(!s||r===l)return void O(null);let e=a?"".concat(a,"/").concat(r):r;try{await N.F.files.rename(s,e,t),o.getState().closeTab(s),I(t,o)}catch(e){console.error("[EditorPanel] Rename failed:",e),window.alert(e instanceof Error?e.message:"Rename failed")}return void O(null)}let i=a?"".concat(a,"/").concat(r):r;try{"create-file"===n?await N.F.files.create(i,t):await N.F.files.mkdir(i,t),I(t,o)}catch(e){console.error("[EditorPanel] Create failed:",e),window.alert(e instanceof Error?e.message:"Create failed")}O(null)},[t,z,o]);(0,l.useEffect)(()=>{function e(e){var t;let r=null==(t=K.current)?void 0:t.querySelector('button[data-path="'.concat(CSS.escape(e),'"]'));r&&(r.focus({preventScroll:!0}),r.scrollIntoView({block:"nearest"}))}function t(t){if(z)return;let r=K.current;if(!r||!q)return;let n=t.target;if(!n||!r.contains(n)||t.ctrlKey||t.metaKey||t.altKey)return;let a=eF(q);if(0===a.length)return;let s=[...P].map(e=>a.indexOf(e)).filter(e=>e>=0),l=s.length?Math.min(...s):-1,o=s.length?Math.max(...s):-1,i=R?a.indexOf(R):-1,c=0===s.length?-1:i>=0&&l<i?l:o,d=i>=0?i:c,u=t=>{let r=a[t];eh(new Set([r]),r),e(r)};switch(t.key){case"ArrowDown":case"ArrowUp":{t.preventDefault();let r="ArrowDown"===t.key?1:-1;if(t.shiftKey&&d>=0&&c>=0){let t=Math.max(0,Math.min(a.length-1,c+r)),n=Math.min(d,t),s=Math.max(d,t);eh(new Set(a.slice(n,s+1)),a[d]),e(a[t]);return}if(c<0)return void u(1===r?0:a.length-1);u(Math.max(0,Math.min(a.length-1,c+r)));return}case"ArrowRight":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c];if(!tY(q,e))return;if(!eA(e))return void eC(e,!0);let r=a[c+1];r&&r.startsWith("".concat(e,"/"))&&u(c+1);return}case"ArrowLeft":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c];if(tY(q,e)&&eA(e))return void eC(e,!1);if(!e.includes("/"))return;let r=a.indexOf(e.slice(0,e.lastIndexOf("/")));r>=0&&u(r);return}case"Enter":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c];tY(q,e)?eC(e,!eA(e)):el(e);return}case"Home":case"End":if(t.shiftKey)return;t.preventDefault(),u("Home"===t.key?0:a.length-1);return;case"F2":{var m;if(1!==P.size)return;t.preventDefault();let e=P.values().next().value,r=null!=(m=e.split("/").pop())?m:"";O({mode:"rename",parentDir:e.includes("/")?e.substring(0,e.lastIndexOf("/")):"",originalPath:e,originalName:r});return}}}return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[q,P,R,z,el,eh]);let ej=U&&(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 ",U.count," file",U.count>1?"s":"","..."]}),(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[Math.round(U.progress),"%",(0,s.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=H.current)?void 0:e.abort()},className:"rounded p-0.5 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:"Cancel upload",children:(0,s.jsx)(e2.A,{className:"h-3 w-3"})})]})]}),(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(U.progress,"%")}})})]});if("tree-only"===r)return(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[ej,P.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:[P.size," selected"]}),(0,s.jsx)("button",{onClick:()=>L(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)(e2.A,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{ref:K,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:$?(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):q?(0,s.jsx)(eD,{node:q,projectId:t,onSelect:el,onContextMenu:ef,onDropFiles:ex,onMoveFile:ep,selectedPaths:P,onSelectionChange:eh,lastAnchor:R,depth:0,pendingEdit:z,onCommitEdit:eb,onCancelEdit:ev}):(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"})}),F&&(0,s.jsx)(eB,{x:F.x,y:F.y,path:F.path,name:F.name,isDir:F.isDir,selectedCount:P.size>1&&P.has(F.path)?P.size:void 0,onAction:eg,onClose:()=>D(null)})]});let ey="full"===r&&v;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"===r&&(0,s.jsx)("button",{onClick:()=>j(!v),className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:v?(0,s.jsx)(e$.A,{className:"h-4 w-4"}):(0,s.jsx)(eY.A,{className:"h-4 w-4"})}),(0,s.jsx)(tJ.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.canvas")}),en&&(null!=en.size||null!=en.mtime)&&(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",[null!=en.size?J(en.size):"",null!=en.createdAt?"Created ".concat(tV(en.createdAt)):"",null!=en.mtime?"Modified ".concat(tV(en.mtime)):""].filter(Boolean).join(" \xb7 "),")"]})]}),(0,s.jsx)("div",{className:"flex items-center gap-1",children:n&&(0,s.jsx)("button",{onClick:()=>o.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)(tZ.A,{className:"h-4 w-4"}):(0,s.jsx)(t$.A,{className:"h-4 w-4"})})})]}),(0,s.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:ey?"halo-editor-tree":void 0,children:[ey&&(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:[ej,(0,s.jsx)("div",{ref:K,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:t?$?(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):q?(0,s.jsx)(eD,{node:q,projectId:t,onSelect:el,onContextMenu:ef,onDropFiles:ex,onMoveFile:ep,selectedPaths:P,onSelectionChange:eh,lastAnchor:R,depth:0,pendingEdit:z,onCommitEdit:eb,onCancelEdit:ev}):(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:p.map((e,r)=>{var n;let a=e.tabs.map(e=>x[e]).filter(e=>!!e),l=e.activeTab,c=a.find(e=>e.path===l),d=r===h;return(0,s.jsx)(i.Zk,{defaultSize:100/p.length,minSize:20,children:(0,s.jsxs)("div",{className:B("flex h-full flex-col overflow-hidden",d&&p.length>1&&"ring-1 ring-inset ring-[var(--primary)]/30"),onMouseDown:()=>o.getState().setActiveGroup(r),children:[a.length>0&&(()=>{let t=M(e.id),n=y[e.id],o=!!(null==c?void 0:c.modified)&&!c.preview;return(0,s.jsx)(e7,{tabs:a,activeTab:l,groupIdx:r,canSplit:g&&1===p.length,onCloseTab:e=>eo(r,e),renderMode:t,onToggleRenderMode:()=>T(r=>({...r,[e.id]:!t})),showDiffButton:o,onToggleDiff:()=>{n?em(e.id):c&&eu(e.id,c.path)}})})(),(0,s.jsxs)("div",{className:"flex-1 overflow-hidden",children:[et.map(e=>a.find(t=>t.path===e&&t.preview)).filter(e=>!!e).map(e=>{var r;return(0,s.jsx)("div",{className:B("h-full",(null==c?void 0:c.path)!==e.path&&"hidden"),children:(0,s.jsx)(tW,{path:e.path,name:null!=(r=e.path.split("/").pop())?r:"",projectId:null!=t?t:void 0,downloadUrl:e.preview.downloadUrl,viewUrl:e.preview.viewUrl,tooLarge:e.preview.tooLarge,size:e.size,onOpenAsText:()=>ei(e.path)})},e.path)}),(null==c?void 0:c.preview)&&ee(c.path)&&!et.includes(c.path)&&(0,s.jsx)("div",{className:"h-full",children:(0,s.jsx)(tW,{path:c.path,name:null!=(n=c.path.split("/").pop())?n:"",projectId:null!=t?t:void 0,downloadUrl:c.preview.downloadUrl,viewUrl:c.preview.viewUrl,tooLarge:c.preview.tooLarge,size:c.size,onOpenAsText:()=>ei(c.path)})},c.path),(()=>{let n=y[e.id],a=M(e.id);if(null==c?void 0:c.preview)return null;if(n)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: ",n.path]}),(0,s.jsx)("button",{onClick:()=>em(e.id),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(e2.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)(e3,{original:n.original,modified:n.modified,path:n.path})})]});if(c){var l;let e=a&&"markdown"===c.language,n=a&&"html"===c.language&&!!t;return(0,s.jsxs)(s.Fragment,{children:[e&&(0,s.jsx)(eQ,{content:c.content,filePath:c.path,projectId:t}),n&&(0,s.jsx)(e1,{url:N.F.files.viewUrl(c.path,t),name:null!=(l=c.path.split("/").pop())?l:""}),(0,s.jsx)("div",{className:B("h-full",(e||n)&&"hidden"),children:(0,s.jsx)(eq,{path:u(t,c.path),content:c.content,language:c.language,onChange:e=>ec(c.path,e),onSave:()=>ed(c.path),onClose:()=>eo(r,c.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)(tJ.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])},p.length)})]}),F&&(0,s.jsx)(eB,{x:F.x,y:F.y,path:F.path,name:F.name,isDir:F.isDir,selectedCount:P.size>1&&P.has(F.path)?P.size:void 0,onAction:eg,onClose:()=>D(null)})]})}function t1(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"}var t3=r(4671),t5=r(46073),t2=r(77497);let t4=/\.(png|jpe?g|gif|webp|bmp|svg)$/i,t8=/\.(mp4|webm|mov|m4v|ogv)$/i,t6=/\.(mp3|wav|flac|aac|m4a|ogg|opus|amr|silk)$/i;function t9(e){return t4.test(e)?"image":t8.test(e)?"video":t6.test(e)?"audio":"file"}function t7(e){let t=[],r=e.replace(/\[(图片|视频|语音消息(?:\s*[^\s]+)?|文件(?:\s*"[^"]*")?)\s*已保存:\s*([^,\]]+)(?:,\s*服务端转写:\s*([^\]]+))?\]/g,(e,r,n,a)=>{let s,l=n.trim();s=r.startsWith("图片")?"image":r.startsWith("视频")?"video":r.startsWith("语音")?"audio":r.startsWith("文件")?"file":t9(l);let o=r.match(/"([^"]+)"/),i=o?o[1]:a?a.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 n=r.trim();return t.push({path:n,kind:t9(n)}),""})).replace(/\n{3,}/g,"\n\n").trim(),media:t}}function re(e){let{media:t}=e,[r,n]=(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)(rr,{media:e,onOpen:()=>n(e)},"".concat(e.path,"-").concat(t)))}),r&&(0,s.jsx)(ra,{media:r,onClose:()=>n(null)})]})}function rt(e,t){if(!t)return null;let r=e=>e.replace(/\\/g,"/").toLowerCase(),n=r(e),a=r(t).replace(/\/$/,""),s=n===a||n.startsWith(a+"/"),l=/(^|\/)(tmp|temp)\//.test(n);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 rr(e){var t;let{media:r,onOpen:n}=e,a=tq(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),l=rt(r.path,a),o=null!=(t=r.path.split("/").pop())?t:r.path;return l?(0,s.jsxs)("button",{onClick:n,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)(rn,{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)(rn,{kind:r.kind}),o]})}function rn(e){let{kind:t}=e,r="h-3 w-3";return"image"===t?(0,s.jsx)(t3.A,{className:r}):"video"===t?(0,s.jsx)(t5.A,{className:r}):"audio"===t?(0,s.jsx)(t2.A,{className:r}):(0,s.jsx)(es.A,{className:r})}function ra(e){var t;let{media:r,onClose:n}=e,a=tq(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),o=rt(r.path,a),[i]=(0,l.useState)(()=>Date.now()),c=null!=(t=r.path.split("/").pop())?t:"file";if((0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),!o)return null;let d="".concat(o,"&t=").concat(i),u="".concat(o.replace("&inline=1",""),"&t=").concat(i);return(0,s.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:n,children:["file"!==r.kind&&(0,s.jsx)("a",{href:u,download:c,onClick:e=>e.stopPropagation(),className:"absolute right-14 top-4 rounded p-2 text-white/80 hover:bg-white/10 hover:text-white","aria-label":"Download",title:"Download",children:(0,s.jsx)(eO.A,{className:"h-5 w-5"})}),(0,s.jsx)("button",{onClick:n,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)(e2.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:d,alt:r.path,className:"max-h-[85vh] max-w-[90vw] object-contain"}),"video"===r.kind&&(0,s.jsx)("video",{src:d,controls:!0,autoPlay:!0,className:"max-h-[85vh] max-w-[90vw]"}),"audio"===r.kind&&(0,s.jsx)("audio",{src:d,controls:!0,autoPlay:!0,className:"w-[min(80vw,480px)]"}),"file"===r.kind&&(0,s.jsxs)("a",{href:u,download:c,className:"rounded bg-white/10 px-4 py-2 text-sm text-white hover:bg-white/20 no-underline",children:["Download ",c]}),(0,s.jsx)("div",{className:"max-w-[90vw] truncate font-mono text-[11px] text-white/60",children:r.path})]})]})}var rs=r(45764);function rl(e){let t=t1(e);return"tool_call"===t||"tool_result"===t||"usage"===t||"context"===t||"agent_start"===t||"agent_done"===t}function ro(e){if(e.taskId)return!1;let t=t1(e);return"user"===t||"assistant"===t||"notification"===t}function ri(e){var t,r;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return!!e.streaming&&!e.content&&!(null==(t=e.toolCalls)?void 0:t.length)&&!(null==(r=e.contentBlocks)?void 0:r.length)&&n-e.timestamp>3e4}let rc=0;function rd(e){var t;return"system"!==e.role||"notification"!==t1(e)?null:"".concat(null!=(t=e.taskId)?t:"","\0").concat(e.content)}function ru(e){return null!=e?e:""}function rm(e,t,r){if("assistant"===t.role&&t.streaming&&e.streamingIdx.set(ru(t.taskId),r),t.toolCalls)for(let n of t.toolCalls)n.toolUseId&&e.toolUseIdIdx.set(n.toolUseId,r);if(t.contentBlocks)for(let n of t.contentBlocks)"tool_call"===n.type&&n.toolCall.toolUseId&&e.toolUseIdIdx.set(n.toolCall.toolUseId,r)}function rx(e,t){e.streamingIdx.clear(),e.toolUseIdIdx.clear();for(let r=0;r<t.length;r++)rm(e,t[r],r)}function rp(e,t){for(let[r,n]of e.streamingIdx){let a=t[n];a&&"assistant"===a.role&&a.streaming&&ru(a.taskId)===r||e.streamingIdx.delete(r)}}function rh(e,t,r){let n=ru(r),a=e.streamingIdx.get(n);if(void 0!==a){let e=t[a];if(e&&"assistant"===e.role&&e.streaming&&e.taskId===r)return a}for(let a=t.length-1;a>=0;a--){let s=t[a];if("assistant"===s.role&&s.streaming&&s.taskId===r)return e.streamingIdx.set(n,a),a}return e.streamingIdx.delete(n),-1}function rf(e,t,r,n,a){if(!a)return{messages:t,slotIdx:rh(e,t,n),copied:!1};let s=rh(e,t,n),l=-1===s?void 0:t[s];if(l&&!(r&&l.agentName&&l.agentName.toLowerCase()!==r.toLowerCase())){var o;let i=null!=(o=l.contentBlocks)?o:[],c=i.length>0?i[i.length-1].turnId:void 0;if(!c||c===a)return{messages:t,slotIdx:s,copied:!1};let d=[...t];return d[s]={...l,streaming:!1},d.push({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:r,taskId:n}),e.streamingIdx.set(ru(n),d.length-1),{messages:d,slotIdx:d.length-1,copied:!0}}let i=[...t,{id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:r,taskId:n}];return e.streamingIdx.set(ru(n),i.length-1),{messages:i,slotIdx:i.length-1,copied:!0}}function rg(e){let t="",r=[];for(let n of e)"text"===n.type?t+=n.text:"tool_call"===n.type&&r.push(n.toolCall);return{content:t,toolCalls:r,contentBlocks:e}}let rv={usableAgentCount:-1,sandboxAvailable:null,captureSource:null},rb=new Set;function rj(e){for(let t of(Object.assign(rv,e),rb))t.setState(e)}let ry=new Set;function rw(){let e,t={streamingIdx:new Map,toolUseIdIdx:new Map,roundStart:0,lastSnapshot:null},r=(0,rs.y)()((e=()=>queueMicrotask(()=>{if(rb.has(r)&&!r.getState().isStreaming)for(let e of ry)e(r)}),(r,n)=>({messages:[],isStreaming:!1,sessionId:null,pendingMessages:[],contextTokens:0,outputTokens:0,maxContextTokens:0,isCompacting:!1,selectedAgentId:"default",accessLevel:"full",...rv,addMessage(e){var n,a;let s={id:null!=(n=e.id)?n:W(),type:e.type,role:e.role,content:e.content,timestamp:null!=(a=e.timestamp)?a:Date.now(),streaming:e.streaming,agentName:e.agentName,taskId:e.taskId,contentBlocks:e.contentBlocks,toolName:e.toolName,toolInput:e.toolInput,toolOutput:e.toolOutput,systemPrompt:e.systemPrompt,usage:e.usage,turnId:e.turnId,modelId:e.modelId,durationMs:e.durationMs,localImages:e.localImages,clientMsgId:e.clientMsgId};r(r=>{var n;let a,l=function(e,t,r){var n;if("assistant"===r.role||!ro(r))return null;let a=rh(e,t);if(-1===a)return null;let s=t[a],l=null!=(n=s.contentBlocks)?n:[],o=l.findIndex(e=>"tool_call"===e.type&&!e.toolCall.output),i=-1===o?!l.some(e=>"tool_call"===e.type):0===o;if(!s.content.trim()&&i)return{prefix:[...t.slice(0,a),...t.slice(a+1)],slot:s};let c=[...t];return c[a]=-1===o?{...s,streaming:!1}:{...s,...rg(l.slice(0,o)),streaming:!1},{prefix:c,slot:{id:W(),role:"assistant",timestamp:Date.now(),streaming:!0,agentName:s.agentName,...rg(-1===o?[]:l.slice(o))}}}(t,r.messages,s),o=rd(s);return null!==o&&function(e,t){for(let r=e.length-1;r>=0;r--){let n=rd(e[r]);if(null===n)break;if(n===t)return!0}return!1}(null!=(n=null==l?void 0:l.prefix)?n:r.messages,o)?r:(l?rx(t,a=[...l.prefix,s,l.slot]):(rm(t,s,r.messages.length),a=[...r.messages,s]),{messages:a,isStreaming:!!e.streaming&&!e.taskId||r.isStreaming})})},appendThinking(e,n,a,s){r(r=>{var l;let o=rf(t,r.messages,n,a,s);if(-1===o.slotIdx)return r;let i=o.copied?o.messages:[...o.messages],c=i[o.slotIdx],d=[...null!=(l=c.contentBlocks)?l:[]],u=d[d.length-1];return u&&"thinking"===u.type&&(!s||u.turnId===s)?d[d.length-1]={type:"thinking",text:u.text+e,turnId:null!=s?s:u.turnId}:d.push({type:"thinking",text:e,turnId:s}),i[o.slotIdx]={...c,contentBlocks:d},{messages:i}})},updateLastAssistant(e,n,a,s){r(r=>{var l;let o=rf(t,r.messages,n,a,s);if(-1===o.slotIdx)return r;let i=o.copied?o.messages:[...o.messages],c=i[o.slotIdx],d=[...null!=(l=c.contentBlocks)?l:[]],u=d[d.length-1];return u&&"text"===u.type&&(!s||u.turnId===s)?d[d.length-1]={type:"text",text:u.text+e,turnId:null!=s?s:u.turnId}:d.push({type:"text",text:e,turnId:s}),i[o.slotIdx]={...c,content:c.content+e,contentBlocks:d},a?{messages:i}:{messages:i,isStreaming:!0}})},addToolCallToLastAssistant(e,n,a,s){r(r=>{var l,o;if(e.toolUseId&&t.toolUseIdIdx.has(e.toolUseId))return r;let i=rf(t,r.messages,n,a,s);if(-1===i.slotIdx)return r;let c=i.copied?i.messages:[...i.messages],d=c[i.slotIdx],u=[...null!=(l=d.contentBlocks)?l:[]];return u.push({type:"tool_call",toolCall:e,turnId:s}),c[i.slotIdx]={...d,toolCalls:[...null!=(o=d.toolCalls)?o:[],e],contentBlocks:u},e.toolUseId&&t.toolUseIdIdx.set(e.toolUseId,i.slotIdx),{messages:c}})},updateLastToolCallResult(e,n,a,s){r(r=>{var n,l,o,i,c,d,u;if(s){let n=null!=(i=t.toolUseIdIdx.get(s))?i:-1,a=-1===n?void 0:r.messages[n],u=null!=(c=null==a||null==(l=a.toolCalls)?void 0:l.findIndex(e=>e.toolUseId===s))?c:-1,m=null!=(d=null==a||null==(o=a.contentBlocks)?void 0:o.findIndex(e=>"tool_call"===e.type&&e.toolCall.toolUseId===s))?d:-1;if(a&&(-1!==u||-1!==m)){if(-1!==u&&void 0!==a.toolCalls[u].output||-1!==m&&void 0!==a.contentBlocks[m].toolCall.output)return r;let t=a.toolCalls?[...a.toolCalls]:a.toolCalls;t&&-1!==u&&(t[u]={...t[u],output:e});let s=a.contentBlocks?[...a.contentBlocks]:a.contentBlocks;if(s&&-1!==m){let t=s[m];s[m]={type:"tool_call",toolCall:{...t.toolCall,output:e},turnId:t.turnId}}let l=[...r.messages];return l[n]={...a,toolCalls:t,contentBlocks:s},{messages:l}}}let m=rh(t,r.messages,a),x=-1===m?void 0:r.messages[m];if(!x||!(null==(n=x.toolCalls)?void 0:n.length))return r;let p=[...x.toolCalls],h=p.findIndex(e=>void 0===e.output);-1!==h&&(p[h]={...p[h],output:e});let f=[...null!=(u=x.contentBlocks)?u:[]];for(let t=0;t<f.length;t++){let r=f[t];if("tool_call"===r.type&&void 0===r.toolCall.output){f[t]={type:"tool_call",toolCall:{...r.toolCall,output:e},turnId:r.turnId};break}}let g=[...r.messages];return g[m]={...x,toolCalls:p,contentBlocks:f},{messages:g}})},completeStreaming(){r(e=>{let r=e.messages.map(e=>e.streaming?{...e,streaming:!1}:e);return rp(t,r),{messages:r,isStreaming:!1}})},completeAgentStreaming(a,s,l){let o=n().isStreaming;r(e=>{let r=e.messages.filter(ro).length,n=e.messages.map(e=>e.streaming?(!s||e.taskId!==s)&&(s||e.taskId)?e:{...e,streaming:!1}:e),l=n.filter(ro).length,o=n.some(e=>e.streaming&&!e.taskId);return r!==l&&console.warn("[ChatStore:completeAgentStreaming] main msgs changed ".concat(r," -> ").concat(l,", agentName=").concat(a,", taskId=").concat(s)),rp(t,n),{messages:n,isStreaming:o}}),!o||n().isStreaming||l||e()},takeRoundReplies(){let{messages:e}=n(),r=e.slice(t.roundStart).filter(e=>"assistant"===e.role&&!e.taskId);return t.roundStart=e.length,r},noteSnapshot(e,r){t.lastSnapshot={sessionId:e,messages:r}},takeReplaySnapshot(){let e=n().sessionId;return t.lastSnapshot&&e&&t.lastSnapshot.sessionId===e?t.lastSnapshot.messages:null},dropOptimisticSend(e){let{messages:a}=n(),s=a.findIndex(t=>t.clientMsgId===e);if(-1===s)return;let l=a.filter((e,t)=>{var r,n;return t!==s&&!(t>s&&e.streaming&&!e.taskId&&!e.content&&!(null==(r=e.toolCalls)?void 0:r.length)&&!(null==(n=e.contentBlocks)?void 0:n.length))});rx(t,l),t.roundStart=Math.min(t.roundStart,l.length),r({messages:l,isStreaming:l.some(e=>e.streaming&&!e.taskId)})},setSessionId(e){r({sessionId:e})},setMessages(e){rx(t,e),t.roundStart=e.length,r({messages:e})},setTokenUsage(e,t){r({contextTokens:e,outputTokens:t})},setMaxContextTokens(e){e>0&&r({maxContextTokens:e})},setCompacting(e){r({isCompacting:e})},setSelectedAgentId(e){r({selectedAgentId:e})},setUsableAgentCount(e){rj({usableAgentCount:e})},setAccessLevel(e){r({accessLevel:e})},setSandboxAvailable(e){rj({sandboxAvailable:e})},setCaptureSource(e){rj({captureSource:e})},addPendingMessage(e){r(t=>({pendingMessages:[...t.pendingMessages,e]}))},removePendingMessage(e){r(t=>({pendingMessages:t.pendingMessages.filter((t,r)=>r!==e)}))},shiftPendingMessage(){let e=n().pendingMessages;if(0===e.length)return;let[t,...a]=e;return r({pendingMessages:a}),t},markChatSendFailed(e){r(r=>{let n=r.messages.findIndex(t=>t.clientMsgId===e);if(-1===n)return r;let a=r.messages.map((e,t)=>{var r,a;return t===n?{...e,sendFailed:!0}:!(t>n)||!e.streaming||e.taskId||e.content||(null==(r=e.toolCalls)?void 0:r.length)||(null==(a=e.contentBlocks)?void 0:a.length)?e:{...e,streaming:!1,interrupted:!0}});return rp(t,a),{messages:a,isStreaming:a.some(e=>e.streaming&&!e.taskId)}})},convergeStaleStreaming(){if(n().isCompacting||0===rc)return;let e=Date.now(),a=t=>t.timestamp<=rc&&ri(t,e);n().messages.some(a)&&r(e=>{let r=e.messages.map(e=>a(e)?{...e,streaming:!1,interrupted:!0}:e);return rp(t,r),{messages:r,isStreaming:r.some(e=>e.streaming&&!e.taskId)}})},clear(){rx(t,[]),t.roundStart=0,t.lastSnapshot=null,r({messages:[],isStreaming:!1,pendingMessages:[],sessionId:null,contextTokens:0,outputTokens:0,accessLevel:"full"})}})));return rb.add(r),r}function rN(e){rb.delete(e)}function rk(e){for(let t of rb)e(t)}let rS=rw(),rC=new Set;function rA(){return rS}function rI(e){return rC.add(e),()=>{rC.delete(e)}}let rE=Object.assign(function(e){let t=(0,l.useSyncExternalStore)(rI,rA,rA);return(0,c.P)(t,e)},{getState:()=>rS.getState(),setState:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return rS.setState(...t)}}),rT=new Map,rM=(0,c.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function rF(e,t){let r=rM.getState();r.sessionId===e&&t<=r.anchor||rM.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}function rD(e,t,r){let n=rM.getState();n.sessionId===e&&n.cursor===t&&rM.setState({messages:[...r,...n.messages],cursor:t-1,loading:!1})}async function rP(){var e,t;let r=null==(e=tq.getState().activeProject)?void 0:e.id,{sessionId:n,cursor:a,loading:s}=rM.getState();if(!r||!n||a<1||s)return;let l="".concat(n,"\0").concat(a),o=rT.get(l);if(o)return void rD(n,a,o);rM.setState({loading:!0});try{let e=null!=(t=(await N.F.sessionLogs.archiveSegment(n,a,r)).messages)?t:[];if(rT.size>=20){let e=rT.keys().next().value;void 0!==e&&rT.delete(e)}rT.set(l,e),rD(n,a,e)}catch(e){rM.setState({loading:!1})}}function rL(e){return{tabId:W(),sessionId:null,store:e}}let rR=rL(rA()),r_=(0,c.v)(()=>({projectId:null,tabs:[rR],activeTabId:rR.tabId})),rz=e=>"halo_chat_tabs_".concat(e);function rO(){var e,t;let{projectId:r,tabs:n,activeTabId:a}=r_.getState();if(!r)return;let s=null!=(t=null==(e=n.find(e=>e.tabId===a))?void 0:e.sessionId)?t:null;try{localStorage.setItem(rz(r),JSON.stringify({active:s}))}catch(e){}}let rU=new Map;function rB(e,t){rU.set(e,{scrollTop:0,userScrolledUp:!1,hiddenTurns:0,...rU.get(e),...t})}function rW(e){return r_.getState().tabs.find(e)}function rH(e,t){r_.setState(r=>({tabs:r.tabs.map(r=>r.tabId===e?{...r,...t}:r)}))}function rK(e){return null===e.sessionId&&(!e.store||0===e.store.getState().messages.length)}function rG(e,t){let r=rA().getState(),n=rw(),a=n.getState();return a.setSelectedAgentId(null!=t?t:r.selectedAgentId),a.setMaxContextTokens(r.maxContextTokens),e&&a.setSessionId(e),n}function rq(e){var t;let r=null==(t=tq.getState().activeProject)?void 0:t.id;r&&S.connected&&S.send({type:"subscribe",sessionId:e,projectId:r})}function rJ(e){let t=rW(t=>t.tabId===e);if(!t)return null;let r={},n=null,a=t.store;!a&&(r.store=a=rG(t.sessionId),t.sessionId&&(n=t.sessionId,r.loading=!0,r.attempt=(null!=(s=t.attempt)?s:0)+1)),t.unread&&(r.unread=!1);var s,l,o=a;if(o!==rS)for(let e of(rS=o,rC))e();return r_.setState(t=>({activeTabId:e,tabs:Object.keys(r).length>0?t.tabs.map(t=>t.tabId===e?{...t,...r}:t):t.tabs})),t.sessionId&&rF(t.sessionId,null!=(l=t.archiveCount)?l:0),rO(),n}function rZ(e){let t=r$(e);t&&rq(t)}function r$(e){let t=r_.getState(),r=t.tabs.find(t=>t.sessionId===e);if(r)return rJ(r.tabId);let n={tabId:W(),sessionId:e},a=t.tabs.find(e=>e.tabId===t.activeTabId),s=a&&rK(a)?a:null;r_.setState({tabs:s?t.tabs.map(e=>e===s?n:e):[...t.tabs,n]});let l=rJ(n.tabId);return s&&(s.store&&rN(s.store),rU.delete(s.tabId)),l}function rY(e){let t=r_.getState(),r=t.tabs.find(rK);if(r){var n;rJ(r.tabId),e&&(null==(n=r.store)||n.getState().setSelectedAgentId(e));return}let a=rL(rG(null,e));r_.setState({tabs:[...t.tabs,a]}),rJ(a.tabId)}function rV(e){let t=rW(t=>t.sessionId===e);t&&function(e){let t=r_.getState(),r=t.tabs.findIndex(t=>t.tabId===e);if(-1===r)return;let n=t.tabs[r],a=t.tabs.filter(t=>t.tabId!==e);if(0===a.length&&(a=[rL(rG(null))]),r_.setState({tabs:a}),t.activeTabId===e){let e=rJ(a[Math.min(r,a.length-1)].tabId);e&&rq(e)}else rO();n.store&&rN(n.store),rU.delete(e)}(t.tabId)}function rQ(e){let t=rA();t.getState().sessionId!==e&&t.getState().setSessionId(e);let r=rW(e=>e.store===t);r&&r.sessionId!==e&&(rH(r.tabId,{sessionId:e}),rO())}function rX(e){var t;let r=[];return rk(t=>{t.getState().sessionId===e&&r.push(t)}),null!=(t=r[0])?t:null}function r0(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],r=e?rX(e):rA();if(r&&t&&r!==rA()){let e=rW(e=>e.store===r);e&&!e.unread&&rH(e.tabId,{unread:!0})}return r}function r1(e){e.store&&(rN(e.store),rH(e.tabId,{store:void 0,loading:!1,unread:!1}))}function r3(e){return"halo_goal_dismissed_".concat(e)}let r5=(0,c.v)(e=>({enabled:!1,setEnabled:t=>e({enabled:t}),goal:null,dismissedGoalId:null,setGoal:t=>e({goal:t}),dismiss:t=>{var r;e({dismissedGoalId:t});let n=null==(r=tq.getState().activeProject)?void 0:r.id;n&&localStorage.setItem(r3(n),t)}}));async function r2(e){if(!r5.getState().enabled)return;let t=localStorage.getItem(r3(e));r5.setState({dismissedGoalId:t});try{var r;let t=await N.F.sessionLogs.goal(e);r5.getState().setGoal(null!=(r=t.goal)?r:null)}catch(e){}}let r4=(0,c.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function r8(e,t){let r=r4.getState();r.sessionId===e&&t<=r.anchor||r4.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}async function r6(){var e,t;let r=null==(e=tq.getState().activeProject)?void 0:e.id,{sessionId:n,cursor:a,loading:s}=r4.getState();if(r&&n&&!(a<1)&&!s){r4.setState({loading:!0});try{let e=await N.F.sessionLogs.archiveSegment(n,a,r),s=r4.getState();if(s.sessionId!==n||s.cursor!==a)return;r4.setState({messages:[...null!=(t=e.messages)?t:[],...s.messages],cursor:a-1,loading:!1})}catch(t){let e=r4.getState();e.sessionId===n&&e.cursor===a&&r4.setState({loading:!1})}}}let r9=new Map,r7=null,ne=!1;function nt(e){return r9.get(e)}function nr(e,t,r){let n=r9.get(e);if(n){n.messages=t,n.archiveCount=r;return}if(r9.set(e,{messages:t,archiveCount:r,scrollOffset:0,atBottom:!0,stale:!1}),!(r9.size<=20)){for(let e of r9.keys())if(e!==r7)return void r9.delete(e)}}function nn(e,t){let r=r9.get(e);r&&(r.stale=t)}function na(e){for(let t of r9.keys())(t===e||t.startsWith("".concat(e,">")))&&r9.delete(t)}function ns(e){return e.slice(e.lastIndexOf(">")+1)}function nl(e,t){if(t)return e.find(e=>void 0!==e.store&&!e.loading&&e.sessionId===t)}function no(){let e=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));return{useBus:e,bump:()=>e.getState().bump()}}let ni=no(),nc=ni.useBus,nd=ni.bump;function nu(e,t){let r=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let t=r.current;if(!t||"undefined"==typeof IntersectionObserver)return;let n=new IntersectionObserver(t=>{var r;(null==(r=t[0])?void 0:r.isIntersecting)&&e()},{rootMargin:"64px"});return n.observe(t),()=>n.disconnect()},[e,t]),r}var nm=r(63129),nx=r(22936),np=r(87343),nh=r(4882),nf=r(70207);let ng=(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 nv(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 nb(e){let t=0;for(let r of e)t+=1+nb(r.children);return t}function nj(e){let{value:t,onChange:r,onCommit:n,onCancel:a,textSize:l}=e;return(0,s.jsx)("input",{autoFocus:!0,value:t,onChange:e=>r(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),n()):"Escape"===e.key&&(e.preventDefault(),a())},onBlur:n,className:B("min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[var(--foreground)] outline-none focus:border-blue-500",l)})}function ny(e){let{nodes:t,depth:r,expanded:n,selectedSessionId:a,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:x}=e,p=(0,eV.kj)(),h=r5(e=>e.enabled),f=12+16*r;return(0,s.jsx)(s.Fragment,{children:t.map(e=>{let t=a===e.id,g=!!e.stoppedAt,v=!!e.archivedAt,b=e.children.length>0,j=n.has(e.id);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>o(e),title:"Click to preview sub-agent session",className:B("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",v&&"opacity-50"),style:{paddingLeft:"".concat(f,"px")},children:[b?(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)(Q.A,{className:B("h-2.5 w-2.5 text-[var(--muted-foreground)] transition-transform",j&&"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)(nj,{value:c,onChange:d,onCommit:()=>m(e.id),onCancel:x,textSize:"text-[10px]"}):(0,s.jsxs)("p",{className:"truncate text-[10px] text-[var(--foreground)]",children:[h&&e.goalSessionId&&(0,s.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),e.title||"Untitled"]}),g&&(0,s.jsx)("span",{title:"Stopped",children:(0,s.jsx)(nm.A,{className:"h-2.5 w-2.5 shrink-0 text-[var(--muted-foreground)]"})}),v&&(0,s.jsx)("span",{title:"Archived",children:(0,s.jsx)(nx.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),b&&(0,s.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",nb(e.children)]})]}),(0,s.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.exchangeCount," msgs \xb7 ",q(e.updatedAt,p)]})]}),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)(eU.A,{className:"h-2.5 w-2.5"})})]}),j&&b&&(0,s.jsx)(ny,{nodes:e.children,depth:r+1,expanded:n,selectedSessionId:a,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:x})]},e.id)})})}let nw=e=>"halo_selected_session_".concat(e);function nN(e){let t=[];return!function e(r){for(let n of r)t.push(n),e(n.children)}(e),t}function nk(){let e=(0,eV.kj)(),t=rE(e=>e.isStreaming),r=rE(e=>e.sessionId),n=tq(e=>e.activeProject),{selectedSessionId:a,setSelectedSession:o,clearSelection:i,setLoadedMessages:c,setLoading:d}=ng(),[u,m]=(0,l.useState)([]),[x,p]=(0,l.useState)(null),h=(0,l.useRef)(0),f=(0,l.useRef)(null),[g,v]=(0,l.useState)(new Set),[b,j]=(0,l.useState)(!0),[y,w]=(0,l.useState)(!1),k=(0,l.useRef)(null),[S,C]=(0,l.useState)(null),[A,I]=(0,l.useState)(""),E=(0,l.useRef)(""),T=(0,l.useRef)(null),M=(0,l.useRef)(!1);(0,l.useEffect)(()=>{(null==n?void 0:n.id)&&k.current&&k.current!==n.id&&(i(),r9.clear(),k.current=null)},[null==n?void 0:n.id,i]);let F=(0,l.useCallback)(async function(){let{showSpinner:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showSpinner:!0};if(!(null==n?void 0:n.path)){m([]),p(null),j(!1);return}if(null!==T.current){M.current=!0;return}M.current=!1,e&&j(!0);let t=n.path,r=Date.now();try{let e=await N.F.sessionLogs.list(t,{includeArchived:!0,limit:30}),r=e.sessions,n=e.nextCursor;if(f.current!==t||h.current<=30||null===n)m(nv(r)),p(n);else{let e=new Set(r.map(e=>e.id));m(t=>{let a=t.filter(t=>t.updatedAt<n&&!e.has(t.id));return nv([...r,...nN(a)])})}f.current=t}catch(e){console.error("[Sessions] Failed to fetch:",e),m([]),p(null)}finally{e?setTimeout(()=>j(!1),Math.max(0,350-(Date.now()-r))):j(!1)}},[null==n?void 0:n.path]),D=(0,l.useCallback)(async()=>{if((null==n?void 0:n.path)&&null!==x&&!y){w(!0);try{let e=await N.F.sessionLogs.list(n.path,{includeArchived:!0,limit:30,cursor:x}),t=e.sessions;m(e=>{let r=nN(e),n=new Set(r.map(e=>e.id)),a=[...r,...t.filter(e=>!n.has(e.id))];return nv(a)}),p(e.nextCursor)}catch(e){console.error("[Sessions] loadMore failed:",e)}finally{w(!1)}}},[null==n?void 0:n.path,x,y]);(0,l.useEffect)(()=>{h.current=u.length},[u.length]);let P=nc(e=>e.version),L=(0,l.useRef)(!0);(0,l.useEffect)(()=>{F({showSpinner:L.current}),L.current=!1},[F,P]),(0,l.useEffect)(()=>{a&&!b&&!new Set(nN(u).map(e=>e.id)).has(a)&&(i(),(null==n?void 0:n.id)&&localStorage.removeItem(nw(n.id)))},[u,a,b,i,null==n?void 0:n.id]);let R=(0,l.useCallback)(e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),_=(0,l.useCallback)(async e=>{var t,r;let a=ng.getState();if(a.selectedSessionId===e.id&&(null!==a.loadedMessages||a.loading))return;o(e),d(!0),(null==n?void 0:n.id)&&localStorage.setItem(nw(n.id),e.id);let s=nl(r_.getState().tabs,e.id);if(null==s?void 0:s.store){r8(e.id,null!=(t=s.archiveCount)?t:0),c(s.store.getState().messages);return}let l=nt(e.id);if(l){r8(e.id,l.archiveCount),c(l.messages);return}let i=()=>ng.getState().selectedSessionId===e.id;try{let t=await N.F.sessionLogs.get(e.id,null==n?void 0:n.path),a="number"==typeof t.archiveCount?t.archiveCount:0,s=null!=(r=t.messages)?r:[];if(nr(e.id,s,a),!i())return;r8(e.id,a),c(s)}catch(t){if(console.error("[Sessions] Load failed:",t),!i())return;r8(e.id,0),c([])}},[null==n?void 0:n.id,null==n?void 0:n.path,o,c,d]);(0,l.useEffect)(()=>{if(!(null==n?void 0:n.id)||b||0===u.length||k.current===n.id)return;k.current=n.id;let e=localStorage.getItem(nw(n.id));if(!e)return;let t=nN(u),r=t.find(t=>t.id===e);if(!r)return;let a=new Map(t.map(e=>[e.id,e])),s=[],l=r;for(;null==l?void 0:l.parentSessionId;)s.push(l.parentSessionId),l=a.get(l.parentSessionId);s.length>0&&v(e=>{let t=new Set(e);for(let e of s)t.add(e);return t}),_(r)},[null==n?void 0:n.id,b,u,_]);let z=(0,l.useCallback)(e=>{rZ(e.id)},[]),O=(0,l.useCallback)(async(t,r)=>{if((t.stopPropagation(),null==n?void 0:n.path)&&await G(e("chat.sessions.deleteTreeConfirm")))try{m(e=>e.filter(e=>e.id!==r)),rV(r),na(r),a===r&&(i(),(null==n?void 0:n.id)&&localStorage.removeItem(nw(n.id))),await N.F.sessionLogs.delete(r,n.path),nd()}catch(e){console.error("[Sessions] Delete failed:",e),nd()}},[null==n?void 0:n.path,null==n?void 0:n.id,a,i,e]),U=(0,l.useCallback)((e,t)=>{e.stopPropagation(),T.current=t.id,E.current=t.title||"",C(t.id),I(t.title||"")},[]),W=(0,l.useCallback)(()=>{T.current=null,C(null),I(""),M.current&&F({showSpinner:!1})},[F]),H=(0,l.useCallback)(async e=>{if(T.current!==e)return;let t=A.trim();if(!t||t===E.current||!(null==n?void 0:n.path))return void W();T.current=null,C(null),m(r=>(function e(t,r,n){return t.map(t=>t.id===r?{...t,title:n}:{...t,children:e(t.children,r,n)})})(r,e,t));try{await N.F.sessionLogs.rename(e,t,n.path),nd()}catch(e){console.error("[Sessions] Rename failed:",e),nd()}},[A,null==n?void 0:n.path,W]),K=u.length,J=nu(D,u.length);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 gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(np.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Sessions"}),K>0&&(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",K,null!==x?"+":"",")"]}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:()=>F(),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 sessions",children:(0,s.jsx)(nh.A,{className:B("h-3.5 w-3.5",b&&"animate-spin")})}),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:"running"})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:b?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(ee.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading..."]}):0===u.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,s.jsx)(np.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:[u.map(t=>{let n=t.children,l=g.has(t.id),o=t.id===r,i=a===t.id,c=!!t.archivedAt,d=n.length>0,u=nb(n);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>_(t),onDoubleClick:()=>z(t),title:"Click to preview, double-click to load into chat",className:B("group flex w-full items-center gap-1.5 px-3 py-2 text-left border-b border-[var(--border)]/30 transition-colors",i?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",c&&"opacity-50"),children:[d?(0,s.jsx)("span",{onClick:e=>{e.stopPropagation(),R(t.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)(Q.A,{className:B("h-3 w-3 text-[var(--muted-foreground)] transition-transform",l&&"rotate-90")})}):(0,s.jsx)("span",{className:"w-5 shrink-0 -ml-1"}),(0,s.jsx)(nf.A,{className:B("h-3.5 w-3.5 shrink-0",o?"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:[S===t.id?(0,s.jsx)(nj,{value:A,onChange:I,onCommit:()=>void H(t.id),onCancel:W,textSize:"text-[11px]"}):(0,s.jsx)("p",{className:"truncate text-[11px] font-medium text-[var(--foreground)]",children:t.title||"Untitled"}),o&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1 py-0.5 text-[8px] text-blue-400",children:"active"}),c&&(0,s.jsx)("span",{title:"Archived",children:(0,s.jsx)(nx.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),d&&(0,s.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",u]})]}),(0,s.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[t.exchangeCount," msgs \xb7 ",q(t.updatedAt,e)]})]}),S!==t.id&&(0,s.jsx)("button",{onClick:e=>U(e,t),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)(eU.A,{className:"h-3 w-3"})}),(0,s.jsx)("button",{onClick:e=>O(e,t.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)(eP.A,{className:"h-3 w-3"})})]}),l&&d&&(0,s.jsx)(ny,{nodes:n,depth:1,expanded:g,selectedSessionId:a,onToggle:R,onSelect:_,editingId:S,editingTitle:A,setEditingTitle:I,onStartRename:U,onCommitRename:H,onCancelRename:W})]},t.id)}),null!==x&&(0,s.jsx)("div",{ref:J,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)(ee.A,{className:"h-3 w-3 animate-spin mr-1"})," Loading more…"]}):(0,s.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})})]})}var nS=r(32031),nC=r(75037);function nA(e){var t;let r=null==(t=tq.getState().activeProject)?void 0:t.id;if(!r)return null;let n=rE.getState();if(n.sessionId&&n.messages.some(t=>t.id===e))return n.sessionId.includes(">")?null:{sessionId:n.sessionId,projectId:r,archiveCount:nI(rM.getState(),n.sessionId)};let a=ng.getState().selectedSessionId;return a&&!a.includes(">")?{sessionId:a,projectId:r,archiveCount:nI(r4.getState(),a)}:null}function nI(e,t){return e.sessionId===t?e.anchor:0}function nE(e){let{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a}=e;return(0,s.jsx)(nT,{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a})}function nT(e){let{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a}=e,o=(0,l.useMemo)(()=>(function(e){let t=[],r=null;for(let n of e)"context"!==t1(n)&&("user"===n.role?(r&&t.push(r),r={user:n,responses:[]}):r?r.responses.push(n):t.push({user:n,responses:[]}));return r&&t.push(r),t})(t),[t]),i=(0,l.useMemo)(()=>{if(n)return!1;let e=t.find(e=>"user"===e.role);return!!e&&null!==nA(e.id)},[t,n]),c=null!=a?a:0;return(0,s.jsx)("div",{className:"flex flex-col",children:o.map(e=>{let t="user"===e.user.role?c++:-1;return(0,s.jsx)(nM,{user:e.user,responses:e.responses,debugMode:r,userOrdinal:t,deletable:i},e.user.id)})})}let nM=(0,l.memo)(function(e){let{user:t,responses:r,debugMode:n,userOrdinal:a,deletable:l}=e,o=!!t.deleted;return(0,s.jsxs)("div",{className:B("border-b border-[var(--border)]/50 last:border-b-0",o&&"opacity-50"),children:["user"===t.role?nP(t.content)?(0,s.jsx)(nL,{content:t.content,userOrdinal:a,deleted:o,messageId:t.id,deletable:l}):nR(t.content)?(0,s.jsx)(n_,{content:t.content,userOrdinal:a,deleted:o,messageId:t.id,deletable:l}):(0,s.jsx)(nW,{content:t.content,localImages:t.localImages,timestamp:t.timestamp,userOrdinal:a,deleted:o,messageId:t.id,deletable:l,sendFailed:t.sendFailed}):(0,s.jsx)("div",{className:"px-3 py-2",children:(0,s.jsx)(nU,{message:t,debugMode:n})}),r.length>0&&(0,s.jsx)(nz,{responses:r,debugMode:n})]})},(e,t)=>e.user===t.user&&e.debugMode===t.debugMode&&e.userOrdinal===t.userOrdinal&&e.deletable===t.deletable&&e.responses.length===t.responses.length&&e.responses.every((e,r)=>e===t.responses[r]));function nF(e){let{copyText:t,userOrdinal:r,deleted:n,messageId:a,deletable:o}=e,i=(0,eV.kj)(),[c,d]=(0,l.useState)(!1),u=o&&!n&&r>=0,m=async()=>{let e=nA(a);e&&await G(i("chat.exchange.deleteConfirm"))&&S.send({type:"exchange:delete",sessionId:e.sessionId,projectId:e.projectId,userOrdinal:r,archiveCount:e.archiveCount})};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)}).catch(()=>{})},title:"Copy message",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--background)]/40",children:c?(0,s.jsx)(tz.A,{className:"h-3 w-3 text-emerald-400"}):(0,s.jsx)(nS.A,{className:"h-3 w-3"})}),u&&(0,s.jsx)("button",{onClick:m,title:"Delete message",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-red-900/30 hover:text-red-400",children:(0,s.jsx)(eP.A,{className:"h-3 w-3"})})]})}let nD="rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400";function nP(e){let t=e.match(/^\(from: session ([^)]+)\)\n([\s\S]*)$/);return t?{sessionId:t[1],body:t[2]}:null}function nL(e){var t;let{content:r,...n}=e,a=nP(r),o=null!=(t=a.sessionId.split(">").pop())?t:a.sessionId,{contentRef:i,clamped:c,expanded:d,toggle:u,contentStyle:m}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20*e,r=(0,l.useRef)(null),[n,a]=(0,l.useState)(!1),[s,o]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let t=r.current;if(!t)return;let n=20*e+4,s=new ResizeObserver(()=>{let e=t.scrollHeight>n;a(t=>t===e?t:e)});return s.observe(t),()=>s.disconnect()},[e]),{contentRef:r,clamped:n,expanded:s,toggle:()=>o(e=>!e),contentStyle:n?s?{maxHeight:"40vh",overflowY:"auto"}:{maxHeight:"".concat(t,"px"),overflow:"hidden"}:void 0}}(4);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.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,s.jsx)(nF,{copyText:a.body,...n})}),(0,s.jsxs)("button",{onClick:u,disabled:!c,className:"mb-1 flex w-full items-center gap-2 pr-16 text-left text-[10px] font-medium text-emerald-400 enabled:hover:text-emerald-300",children:[c&&(d?(0,s.jsx)(V.A,{className:"h-3 w-3"}):(0,s.jsx)(Q.A,{className:"h-3 w-3"})),(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:o}),n.deleted&&(0,s.jsx)("span",{className:nD,children:"deleted"})]}),(0,s.jsx)("div",{ref:i,style:m,children:(0,s.jsx)("div",{className:"text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed",children:a.body})})]})}function nR(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 n_(e){let{content:t,...r}=e,n=nR(t),[a,o]=(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.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,s.jsx)(nF,{copyText:n.body,...r})}),(0,s.jsxs)("button",{onClick:()=>o(!a),className:"flex w-full items-center gap-2 px-3 py-2 pr-14 text-[10px] font-medium text-purple-400 hover:bg-purple-900/30 transition-colors",children:[a?(0,s.jsx)(V.A,{className:"h-3 w-3"}):(0,s.jsx)(Q.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:[n.olderCount," messages compacted"]}),r.deleted&&(0,s.jsx)("span",{className:nD,children:"deleted"})]}),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:n.body})]})}function nz(e){let{responses:t,debugMode:r}=e,n=(0,l.useMemo)(()=>{var e,n;let a=new Map;if(!r)return a;let s=t.filter(e=>"usage"===t1(e)&&e.usage);if(0===s.length)return a;let l=new Map;for(let e of t)if("assistant"===t1(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 n=null!=(e=a.get(r))?e:[];n.push(t),a.set(r,n)}else o.push(t)}if(o.length>0){let e=[...t].reverse().find(e=>"assistant"===t1(e));if(e){let t=null!=(n=a.get(e.id))?n:[];t.push(...o),a.set(e.id,t)}}return a},[r,t]);return(0,s.jsx)("div",{className:"px-3 py-2",children:t.map(e=>(0,s.jsx)(nU,{message:e,debugMode:r,usages:n.get(e.id)},e.id))})}function nO(e){var t,r,n,a,l,o,i,c;let{message:d}=e,u=d.usage;if(!u)return null;let m=null!=(r=null==(t=d.modelId)?void 0:t.replace(/^global\.anthropic\./,""))?r:"",x=u.inputTokens+(null!=(n=u.cacheReadInputTokens)?n:0)+(null!=(a=u.cacheWriteInputTokens)?a:0),p=x+u.outputTokens,h=x>0?Math.round(u.cacheReadInputTokens/x*100):0,f=e=>e>=1e3?"".concat((e/1e3).toFixed(1),"s"):"".concat(e,"ms"),g=new Date(d.timestamp),v=e=>e.toString().padStart(2,"0"),b="".concat(v(g.getMonth()+1),"-").concat(v(g.getDate())," ").concat(v(g.getHours()),":").concat(v(g.getMinutes()),":").concat(v(g.getSeconds()));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:b}),(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"}),m&&(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:m})]})}function nU(e){var t,r,n,a;let{message:o,debugMode:i,usages:c}=e,d=(0,eV.kj)(),u=t1(o),m="assistant"===u,x=(0,l.useMemo)(()=>{if(!i||!m||!(null==c?void 0:c.length))return null;let e=new Map;for(let t of c)t.turnId&&e.set(t.turnId,t);return e.size>0?e:null},[i,m,c]);if("tool_call"===u||"tool_result"===u||"usage"===u||"context"===u)return null;if("agent_start"===u||"agent_done"===u)return i?(0,s.jsx)("div",{className:"my-0.5 px-1",children:(0,s.jsxs)("span",{className:B("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!=(n=o.agentName)?n:"Agent",": ",o.content||("agent_start"===u?"started":"done")]})}):null;let p=m&&o.contentBlocks&&o.contentBlocks.length>0,h=p?o.contentBlocks.filter(e=>"tool_call"===e.type).length:0;if(o.interrupted&&!o.content&&!(null==(t=o.toolCalls)?void 0:t.length))return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,s.jsx)(nC.A,{className:"h-3 w-3 text-amber-400"}),(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:d("chat.interrupted")})]});if(o.streaming&&!o.content&&!(null==(r=o.toolCalls)?void 0:r.length))return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,s.jsx)(ee.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 f=[];if(p){let e=o.contentBlocks,t=0;for(let r=0;r<e.length;r++){let n=e[r];if("thinking"===n.type&&n.text.trim()&&i?f.push((0,s.jsx)(nB,{text:n.text},"b".concat(r))):"text"===n.type&&n.text.trim()?f.push((0,s.jsx)(nH,{text:n.text},"b".concat(r))):"tool_call"===n.type&&(t++,f.push((0,s.jsx)(nZ,{call:n.toolCall,isStreaming:o.streaming,isLast:t===h},"b".concat(r)))),x&&n.turnId){let t=null==(a=e[r+1])?void 0:a.turnId;if(!t||t!==n.turnId){let e=x.get(n.turnId);e&&f.push((0,s.jsx)(nO,{message:e},"u".concat(n.turnId)))}}}if(x){let t=new Set(e.map(e=>e.turnId).filter(Boolean));for(let[e,r]of x)t.has(e)||f.push((0,s.jsx)(nO,{message:r},"u".concat(e)))}}else{if(m&&o.toolCalls&&o.toolCalls.length>0&&o.toolCalls.forEach((e,t)=>{f.push((0,s.jsx)(nZ,{call:e,isStreaming:o.streaming,isLast:t===o.toolCalls.length-1},"tc".concat(t)))}),x)for(let[e,t]of x)f.push((0,s.jsx)(nO,{message:t},"u".concat(e)));if(o.content){let e=!m&&/^Compacting context /.test(o.content);f.push(m?(0,s.jsx)(nH,{text:o.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)(ee.A,{className:"h-3 w-3 animate-spin shrink-0"}),(0,s.jsx)("span",{className:"whitespace-pre-wrap",children:o.content})]},"txt"):(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] whitespace-pre-wrap",children:o.content},"txt"))}}return 0===f.length?null:(0,s.jsx)("div",{className:"py-1",children:f})}function nB(e){let{text:t}=e,[r,n]=(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:()=>n(!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)(V.A,{className:"h-3 w-3"}):(0,s.jsx)(Q.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 nW(e){let{content:t,localImages:r,timestamp:n,userOrdinal:a,deleted:o,messageId:i,deletable:c,sendFailed:d}=e,u=(0,eV.kj)(),{text:m,media:x}=(0,l.useMemo)(()=>t7(t),[t]),[p,h]=(0,l.useState)(null),[f,g]=(0,l.useState)(!1),[v,b]=(0,l.useState)(!1),j=(0,l.useRef)(null),y=m.trim().split("\n"),w=y.length>1,N=(w?"".concat(y[0].trim(),"…"):y[0].trim())||(x.length>0||(null==r?void 0:r.length)?"(attachment)":""),k=w||v;(0,l.useEffect)(()=>{let e=j.current;if(!e)return;let t=new ResizeObserver(()=>{let t=e.scrollWidth>e.clientWidth;b(e=>e===t?e:t)});return t.observe(e),()=>t.disconnect()},[N]);let S=new Date(n),C=e=>e.toString().padStart(2,"0"),A=o?"text-[var(--muted-foreground)] line-through":"text-[var(--accent-foreground)]";return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:B("sticky top-0 z-10 bg-[var(--accent)] border-b border-[var(--border)] border-l-2 px-4 py-2.5 shadow-sm",o||d?"border-l-red-500/60":"border-l-blue-500"),children:[(0,s.jsxs)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:[o&&(0,s.jsx)("span",{className:B("mr-1",nD),children:"deleted"}),d&&!o&&(0,s.jsxs)("span",{className:"mr-1 inline-flex items-center gap-0.5 rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400",title:u("chat.sendFailed"),children:[(0,s.jsx)(nC.A,{className:"h-2.5 w-2.5"}),u("chat.sendFailedBadge")]}),(0,s.jsx)(nF,{copyText:m,userOrdinal:a,deleted:o,messageId:i,deletable:c})]}),(0,s.jsxs)("button",{onClick:()=>g(e=>!e),disabled:!k,className:B("flex w-full min-w-0 items-center gap-1.5 text-left",o||d?"pr-32":"pr-14"),children:[(0,s.jsx)("span",{className:"flex w-3 shrink-0 justify-center text-[var(--muted-foreground)]",children:k?f?(0,s.jsx)(V.A,{className:"h-3 w-3"}):(0,s.jsx)(Q.A,{className:"h-3 w-3"}):"\xb7"}),(0,s.jsxs)("span",{className:"shrink-0 text-[10px] font-mono text-[var(--muted-foreground)] opacity-70",title:S.toLocaleString(),children:[C(S.getHours()),":",C(S.getMinutes())]}),(0,s.jsx)("span",{ref:j,className:B("min-w-0 truncate text-xs",A,f&&k&&"invisible"),children:N})]}),f&&k&&(0,s.jsx)("div",{className:"mt-1 max-h-[40vh] overflow-y-auto",children:(0,s.jsx)("div",{className:B("text-xs leading-relaxed whitespace-pre-wrap",A),children:m})})]}),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:()=>h(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))}),x.length>0&&(0,s.jsx)("div",{className:"px-4 py-2 border-b border-[var(--border)]/30",children:(0,s.jsx)(re,{media:x})}),p&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:()=>h(null),children:(0,s.jsx)("img",{src:p,alt:"screenshot",className:"max-h-[90vh] max-w-[92vw] object-contain"})})]})}function nH(e){let{text:t}=e,{text:r,media:n}=(0,l.useMemo)(()=>t7(t),[t]),a=(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:[a&&(0,s.jsx)(eJ.oz,{remarkPlugins:[eZ.A],components:{a(e){let{href:t,children:r,node:n,...a}=e;return(0,s.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...a,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:n,...a}=e;return(null==t?void 0:t.startsWith("language-"))||String(r).includes("\n")?(0,s.jsx)(n$,{className:t,children:r}):(0,s.jsx)("code",{className:t,...a,children:r})}},children:a}),(0,s.jsx)(re,{media:n})]})}function nK(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t?t:null}catch(e){return null}}let nG="__TOOL_ERROR__",nq="__TOOL_WARN__",nJ={running:"bg-amber-400 animate-pulse",success:"bg-emerald-400",warn:"bg-yellow-400",error:"bg-red-400"};function nZ(e){let{call:t,isStreaming:r,isLast:n}=e,[a,o]=(0,l.useState)(!1),i=function(e,t,r){var n;if(!e.output&&""!==e.output)return"running";let a=null!=(n=e.output)?n:"";return a.startsWith(nG)?"error":a.startsWith(nq)?"warn":"success"}(t,r,0),c=void 0!==t.output&&""!==t.output,{summary:d}=(0,l.useMemo)(()=>(function(e,t){let r=nK(t);if(r){var n,a,s,l,o,i,c,d,u,m,x,p,h,f,g,v,b,j,y,w,N,k,S;switch(e){case"shell_exec":return{summary:String(null!=(a=null!=(n=r.command)?n:r.cmd)?a:"")||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!=(x=null!=(m=r.path)?m:r.file)?x: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):"",n=r.include?" (".concat(r.include,")"):"";return{summary:'"'.concat(e,'"').concat(t).concat(n)}}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:""),n=t.length>100?t.slice(0,100)+"...":t;return{summary:e?"→ ".concat(e,": ").concat(n):n}}}}return{summary:t}})(t.name,t.input),[t.name,t.input]),u=(0,l.useMemo)(()=>{var e;return c?function(e,t){let r=nK(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(nG+"\n")?e.slice(nG.length+1):e.startsWith(nq+"\n")?e.slice(nq.length+1):e):""},[t.name,t.output,c]),m=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(!a),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:B("h-2 w-2 shrink-0 rounded-full",nJ[i])}),a?(0,s.jsx)(V.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}):(0,s.jsx)(Q.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})]}),a&&(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:B("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)(ee.A,{className:"h-3 w-3 animate-spin text-amber-400"}),(0,s.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"Running..."})]})]}),!a&&c&&m&&(0,s.jsx)("div",{className:"ml-[22px] text-[11px] text-[var(--muted-foreground)] truncate",children:m})]})}function n$(e){let{children:t,className:r}=e,[n,a]=(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:"block mb-1 text-[9px] leading-none text-[var(--muted-foreground)] opacity-60",children:i}),(0,s.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{a(!0),setTimeout(()=>a(!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:n?(0,s.jsx)(tz.A,{className:"h-3 w-3 text-emerald-400"}):(0,s.jsx)(nS.A,{className:"h-3 w-3"})}),(0,s.jsx)("code",{className:r,children:t})]})}var nY=r(8985),nV=r(98285),nQ=r(73082),nX=r(57482),n0=r(48253),n1=r(37784);let n3=no(),n5=n3.useBus,n2=n3.bump,n4=[{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"}],n8=[];async function n6(e,t,r){try{n8=(await N.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){n8=[]}}function n9(){let e=n8.length>0?n8:n4;return r5.getState().enabled?e:e.filter(e=>"/goal"!==e.name)}function n7(e){let{commands:t,selectedIndex:r,onSelect:n}=e,a=(0,l.useRef)(null);return((0,l.useEffect)(()=>{var e;let t=null==(e=a.current)?void 0:e.children[r];null==t||t.scrollIntoView({block:"nearest"})},[r]),0===t.length)?null:(0,s.jsx)("div",{ref:a,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(),n(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 ae(e){let{matches:t,selectedIndex:r,onSelect:n,dirs:a=!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=ej(e),i=a?$.A:o.Icon,c=a?"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(),n(e)},className:B("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:B("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)})})}let at=["image/jpeg","image/png","image/gif","image/webp"];async function ar(e){if("image/svg+xml"!==e.type){let t=await createImageBitmap(e);return{source:t,width:t.width,height:t.height,close:()=>t.close()}}let t=URL.createObjectURL(e);try{let e=new Image;e.src=t,await e.decode();let r=e.naturalWidth||1,n=e.naturalHeight||1,a=1024/Math.max(r,n);return{source:e,width:Math.round(r*a),height:Math.round(n*a),close:()=>{}}}finally{URL.revokeObjectURL(t)}}async function an(e){try{let t=await ar(e),r=Math.min(1,1568/Math.max(t.width,t.height)),n=Math.max(1,Math.round(t.width*r)),a=Math.max(1,Math.round(t.height*r)),s=document.createElement("canvas");s.width=n,s.height=a;let l=s.getContext("2d");if(!l)throw Error("no 2d context");"image/svg+xml"===e.type&&(l.fillStyle="#fff",l.fillRect(0,0,n,a)),l.drawImage(t.source,0,0,n,a),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){if(at.includes(e.type))return{base64:await new Promise((t,r)=>{let n=new FileReader;n.onload=()=>t(n.result.split(",")[1]),n.onerror=r,n.readAsDataURL(e)}),mimeType:e.type};throw t}}async function aa(e){if(at.includes(e.type))return!0;try{return(await ar(e)).close(),!0}catch(e){return!1}}let as=null,al=null,ao=-1,ai=".halo/canvas/self.html";function ac(){let e=(0,eV.kj)(),t=tq(e=>e.activeProject);if(!t)return null;let r=async()=>{let e=t.id;try{let t=await N.F.files.read(ai,e);window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}})),b.getState().openFile(ai,t.content,Z(ai),t.modifiedAt,{size:t.size,createdAt:t.createdAt}),setTimeout(()=>e0("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)(nY.A,{className:"h-4 w-4"})})}function ad(e){var t;let{cameras:r,activeId:n,onPick:a,onTurnOff:o,onClose:i}=e,c=(0,eV.kj)(),[d,u]=(0,l.useState)(n||(null==(t=r[0])?void 0:t.deviceId)||""),m=(0,l.useRef)(null),x=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=!1,t=()=>{if(x.current){for(let e of x.current.getTracks())e.stop();x.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}x.current=t,m.current&&(m.current.srcObject=t,m.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)(e2.A,{className:"h-4 w-4"})})]}),(0,s.jsx)("video",{ref:m,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:B("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)(nV.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.label}),n===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&&a(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")})]})]})})}let au=["full","workspace","readonly"],am={full:"bg-amber-500/15 text-amber-300",workspace:"bg-blue-500/15 text-blue-300",readonly:"bg-emerald-500/15 text-emerald-300"};function ax(){let e=(0,eV.kj)(),t=rE(e=>e.accessLevel),r=rE(e=>e.isStreaming),n=rE(e=>e.sandboxAvailable),[a,o]=(0,l.useState)(!1),i=(0,l.useRef)(null);(0,l.useEffect)(()=>{null===n&&N.F.health().then(e=>rE.getState().setSandboxAvailable(!!e.sandbox)).catch(()=>{})},[n]),(0,l.useEffect)(()=>{if(!a)return;let e=e=>{i.current&&!i.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]);let c=!1===n,d=c?"full":t,u=r||c;return(0,s.jsxs)("div",{ref:i,className:"relative",children:[(0,s.jsxs)("button",{onClick:()=>!u&&o(!a),disabled:u,title:c?e("chat.access.noSandbox"):e("chat.access.title"),className:B("flex w-24 shrink-0 items-center justify-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium transition-opacity",am[d],u?"opacity-50 cursor-default":"hover:opacity-80"),children:[(0,s.jsx)("span",{className:"truncate",children:e("chat.access.".concat(d))}),!u&&(0,s.jsx)(V.A,{className:"h-2.5 w-2.5"})]}),a&&(0,s.jsx)("div",{className:"absolute bottom-full left-0 mb-1 min-w-[180px] rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-30",children:au.map(r=>(0,s.jsxs)("button",{onClick:()=>{rE.getState().setAccessLevel(r),o(!1)},className:B("flex w-full flex-col items-start px-3 py-1.5 text-left transition-colors",r===t?"bg-[var(--accent)]":"hover:bg-[var(--secondary)]"),children:[(0,s.jsx)("span",{className:B("rounded px-1.5 py-0.5 text-[10px] font-medium",am[r]),children:e("chat.access.".concat(r))}),(0,s.jsx)("span",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("chat.access.".concat(r,"Desc"))})]},r))})]})}function ap(){let e=(0,eV.kj)(),t=rE(e=>e.captureSource),r=rE(e=>e.setCaptureSource),[n,a]=(0,l.useState)(!1),[o,i]=(0,l.useState)([]),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(!1),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)([]),[b,j]=(0,l.useState)(!1),y=(0,l.useRef)(null),w=window.haloCapture,k=window.haloCamera,S=function(){let e=rE(e=>e.selectedAgentId),t=tq(e=>{var t;return null==(t=e.activeProject)?void 0:t.path}),r=n5(e=>e.version),[n,a]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{if(!t)return;let n=!1;return Promise.all([N.F.agentConfigs.list(t),(r!==ao&&(ao=r,as=null,al=null),as)?Promise.resolve(as):(!al&&(al=N.F.agentConfigs.models().then(e=>{let t={};for(let n of e.providers){var r;for(let e of n.models)t[e.id]=!!(null==(r=e.capabilities)?void 0:r.image)}return as=t,t}).catch(()=>({}))),al)]).then(t=>{var r;let[s,l]=t;if(n)return;let o=null!=(r=s.agents.find(t=>t.id===e))?r:s.agents[0],i=null==o?void 0:o.model;if(!i||!(i in l))return void a(!0);a(l[i])}).catch(()=>{n||a(!0)}),()=>{n=!0}},[e,t,r]),n}();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(!n&&!b)return;let e=e=>{y.current&&!y.current.contains(e.target)&&(a(!1),j(!1))},t=e=>{"Escape"===e.key&&(a(!1),j(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[n,b]),!w&&!k||!S)return null;let C=async()=>{if(n)return void a(!1);a(!0),m(!0);try{let e=await w.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{m(!1)}},A=(t,n)=>{if(f(!1),j(!1),t)try{localStorage.setItem("halo.cameraId",t)}catch(e){}r({id:t,name:n||e("capture.cameraName"),thumb:"",kind:"camera"})},I=async()=>{if((null==t?void 0:t.kind)==="camera")return void j(e=>!e);if(!await k.requestPermission())return void f(!0);let e=await k.list();if(0===e.length)return void A("",void 0);v(e),j(!0)};return(0,s.jsxs)("div",{ref:y,className:"relative flex items-center gap-1",children:[w&&(0,s.jsx)("button",{onClick:C,title:(null==t?void 0:t.kind)==="screen"?e("capture.bound",{name:t.name}):e("capture.button"),className:B("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)(nQ.A,{className:"h-4 w-4"})}),k&&x&&(0,s.jsx)("button",{onClick:I,title:(null==t?void 0:t.kind)==="camera"?e("capture.cameraBound"):e("capture.cameraButton"),className:B("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)(nV.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)(nV.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)(nQ.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)(e2.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")})]})]}),b&&g.length>=1&&(0,s.jsx)(ad,{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),j(!1)}:void 0,onClose:()=>j(!1)}),n&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:()=>a(!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:()=>a(!1),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(e2.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:()=>w.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"}),a(!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 ah(e){let{onCompact:t}=e,r=rE(e=>e.messages),n=rE(e=>e.contextTokens),a=rE(e=>e.maxContextTokens),o=rE(e=>e.isCompacting),i=rE(e=>e.isStreaming),c=(0,l.useMemo)(()=>n>0?n:0,[n]);if(0===c||0===r.length||0===a)return null;let d=Math.min(c/a*100,100),u=(c/1e3).toFixed(2),m=2*Math.PI*8,x=r.length>5&&t&&!o&&!i;return(0,s.jsx)("div",{className:B("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",x&&"cursor-pointer hover:bg-[var(--secondary)]"),title:o?"Compacting...":"~".concat(u,"K / ").concat(a/1e3,"K tokens (").concat(Math.round(d),"%)").concat(x?"\nClick to compact context":""),onClick:x?t:void 0,children:(0,s.jsxs)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",className:B("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:m,strokeDashoffset:m-d/100*m,strokeLinecap:"round",className:"transition-all duration-300"})]})})}function af(e){let{onSend:t,disabled:r,isStreaming:n,onStop:a,onInterrupt:o,pendingMessages:i,onRemovePending:c,onCommand:d,onCompact:u,renderLeftControls:m}=e,x=(0,eV.kj)(),p=b(e=>e.selectedText),h=b(e=>e.selectedRange),f=b(e=>e.activeTab),g=b(e=>e.contextEnabled),v=b(e=>e.setContextEnabled),[j,y]=(0,l.useState)(""),[w,k]=(0,l.useState)([]),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(0),[E,T]=(0,l.useState)([]),[M,F]=(0,l.useState)(0),[D,P]=(0,l.useState)(0),[L,R]=(0,l.useState)(!1),[_,z]=(0,l.useState)(null),O=(0,l.useRef)(null),U=(0,l.useRef)(null),W=tq(e=>e.activeProject),H=0===rE(e=>e.usableAgentCount),K=r5(e=>e.enabled),G=r5(e=>e.goal),q=rE(e=>e.sessionId),J=K&&!!G&&("intake"===G.status||"running"===G.status)&&q===G.workerSessionId,Z=J&&!j.trim().startsWith("/"),$=(0,l.useMemo)(()=>{var e,t;if(p&&f){let t=null!=(e=f.split("/").pop())?e:f,r=h?":".concat(h.startLine,"-").concat(h.endLine):"";return"".concat(t).concat(r," (").concat(p.length," chars)")}return f?null!=(t=f.split("/").pop())?t:f:null},[p,h,f]),Y=(0,l.useMemo)(()=>{if(!j.startsWith("/")||/\s/.test(j))return[];if(!j.startsWith("/"))return[];let e=j.toLowerCase();return n9().filter(t=>t.name.startsWith(e))},[j]),V=(0,l.useMemo)(()=>(function(e){var t;let r=e.match(/^(\/\S+)\s+(\S*)$/);if(!r)return[];let n=n9().find(e=>e.name===r[1].toLowerCase());if(!(null==n||null==(t=n.verbs)?void 0:t.length))return[];let a=r[2].toLowerCase();return n.verbs.filter(e=>e.name.startsWith(a)&&e.name!==a).map(e=>({cmd:n,verb:e}))})(j),[j]),[Q,X]=(0,l.useState)(0);(0,l.useEffect)(()=>{X(0)},[V.length]);let ee=(0,l.useCallback)(e=>{var t;y("".concat(e.cmd.name," ").concat(e.verb.name," ")),null==(t=O.current)||t.focus()},[]),et=(0,l.useMemo)(()=>{let e=j.slice(0,D).match(/(^|\s)@scope\s+(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,D]),er=(0,l.useMemo)(()=>{if(et)return null;let e=j.slice(0,D).match(/(^|\s)@(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,D,et]),[en,ea]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(!er||L||!W)return void ea([]);let e=!1,t=setTimeout(()=>{N.F.files.search(W.id,er.query,15).then(t=>{e||ea(t.matches.map(e=>e.path))}).catch(()=>{e||ea([])})},120);return()=>{e=!0,clearTimeout(t)}},[er,L,W]);let es=(0,l.useCallback)(e=>{if(!er)return;let t=j.slice(0,er.startIdx);y(t+j.slice(er.startIdx+1+er.query.length)),T(t=>t.includes(e)?t:[...t,e]),F(0),R(!1),requestAnimationFrame(()=>{if(O.current){let e=t.length;O.current.selectionStart=e,O.current.selectionEnd=e,O.current.focus(),P(e)}})},[j,er]),[el,eo]=(0,l.useState)([]),[ei,ec]=(0,l.useState)(0);(0,l.useEffect)(()=>{if(!et||!W)return void eo([]);let e=!1,t=setTimeout(()=>{N.F.files.search(W.id,et.query,15,!0).then(t=>{e||eo(t.matches.map(e=>e.path))}).catch(()=>{e||eo([])})},120);return()=>{e=!0,clearTimeout(t)}},[et,W]);let ed=(0,l.useCallback)(e=>{if(!et)return;let t=j.slice(0,et.startIdx),r=j.slice(D),n="@scope ".concat(e," ");y(t+n+r),ec(0),requestAnimationFrame(()=>{if(O.current){let e=t.length+n.length;O.current.selectionStart=e,O.current.selectionEnd=e,O.current.focus(),P(e)}})},[j,et,D]),eu=(0,l.useCallback)(e=>{T(t=>t.filter(t=>t!==e))},[]),em=(0,l.useCallback)(e=>{var t,r;let n=j.split(/\s+/),a=null!=(t=n[0])?t:"",s=n.slice(1).join(" ");if(e.argHint&&!s&&a!==e.name){y(e.name+" "),I(0),null==(r=O.current)||r.focus();return}null==d||d(e,s),y(""),I(0),O.current&&(O.current.style.height="auto")},[j,d]),ex=(0,l.useCallback)(e=>{let t=Array.from(e).filter(e=>e.type.startsWith("image/"));Promise.all(t.map(aa)).then(e=>{let r=t.filter((t,r)=>!e[r]);z(r.length>0?x("chat.attachUnsupported",{names:r.map(e=>e.name).join(", ")}):null);let n=t.filter((t,r)=>e[r]).map(e=>({file:e,preview:URL.createObjectURL(e)}));n.length>0&&k(e=>[...e,...n])})},[x]),ep=(0,l.useCallback)(e=>{k(t=>{let r=t[e];return(null==r?void 0:r.preview)&&URL.revokeObjectURL(r.preview),t.filter((t,r)=>r!==e)})},[]),eh=(0,l.useCallback)(async()=>{var e,r;let n=j.trim();if(!n&&0===w.length||H)return;if(V.length>0)return void ee(null!=(e=V[Q])?e:V[0]);if(n.startsWith("/")){if(Y.length>0)return void em(null!=(r=Y[A])?r:Y[0]);let e=n9().find(e=>{var t;return e.name===(null==(t=n.split(/\s+/)[0])?void 0:t.toLowerCase())});if(e)return void em(e)}if(J)return;let a=[];for(let e of w)try{let{base64:t,mimeType:r}=await an(e.file);a.push({data:t,mimeType:r})}catch(e){console.error("[MessageInput] Image conversion failed:",e)}(n||a.length>0)&&t(n||"(image)",a.length>0?a:void 0,E.length>0?E:void 0),w.forEach(e=>{e.preview&&URL.revokeObjectURL(e.preview)}),k([]),T([]),y(""),O.current&&(O.current.style.height="auto")},[j,w,t,Y,A,em,E,V,Q,ee,H,J]),ef=(0,l.useCallback)(e=>{if(el.length>0){if("ArrowDown"===e.key){e.preventDefault(),ec(e=>Math.min(e+1,el.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),ec(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=el[ei];t&&ed(t);return}if("Escape"===e.key){e.preventDefault(),eo([]);return}}if(en.length>0){if("ArrowDown"===e.key){e.preventDefault(),F(e=>Math.min(e+1,en.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=en[M];t&&es(t);return}if("Escape"===e.key){e.preventDefault(),R(!0);return}}if(V.length>0){if("ArrowDown"===e.key){e.preventDefault(),X(e=>Math.min(e+1,V.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),X(e=>Math.max(e-1,0));return}if("Tab"===e.key){e.preventDefault();let t=V[Q];t&&ee(t);return}if("Escape"===e.key){e.preventDefault(),X(0);return}}if(Y.length>0){if("ArrowDown"===e.key){e.preventDefault(),I(e=>Math.min(e+1,Y.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),I(e=>Math.max(e-1,0));return}if("Escape"===e.key){e.preventDefault(),y(""),I(0);return}if("Tab"===e.key){e.preventDefault();let t=Y[A];t&&y(t.name+" ");return}}if("Escape"===e.key&&n&&!j.trim()&&o){e.preventDefault(),o();return}"Enter"!==e.key||e.nativeEvent.isComposing||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),eh())},[eh,Y,A,V,Q,ee,en,M,es,el,ei,ed,n,j,o]),ev=(0,l.useCallback)(e=>{y(e.target.value),P(e.target.selectionStart),I(0),R(!1),F(0),ec(0);let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"},[]),eb=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!0)},[]),ej=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!1)},[]),ey=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!1),e.dataTransfer.files.length>0&&ex(e.dataTransfer.files)},[ex]),ew=(0,l.useCallback)(e=>{let t=e.clipboardData.items,r=[];for(let e=0;e<t.length;e++){let n=t[e];if("file"===n.kind){let e=n.getAsFile();e&&r.push(e)}}r.length>0&&(e.preventDefault(),ex(r))},[ex]);return(0,s.jsxs)("div",{className:B("relative px-3 pb-3 pt-1 transition-colors",S&&"bg-[var(--accent)]"),onDragOver:eb,onDragLeave:ej,onDrop:ey,children:[(0,s.jsx)(n7,{commands:Y,selectedIndex:A,onSelect:em}),(0,s.jsx)(n7,{commands:V.map(e=>{var t;return{name:"".concat(e.cmd.name," ").concat(e.verb.name),description:null!=(t=e.verb.desc)?t:"",type:"server"}}),selectedIndex:Q,onSelect:e=>{var t;y(e.name+" "),null==(t=O.current)||t.focus()}}),(0,s.jsx)(ae,{matches:en,selectedIndex:M,onSelect:es}),(0,s.jsx)(ae,{matches:el,selectedIndex:ei,onSelect:ed,dirs:!0}),S&&(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:U,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&ex(e.target.files),e.target.value=""}}),_&&(0,s.jsxs)("div",{className:"mb-1 flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1.5 text-xs text-amber-300",children:[(0,s.jsx)("span",{className:"flex-1",children:_}),(0,s.jsx)("button",{onClick:()=>z(null),className:"shrink-0 rounded p-0.5 hover:bg-amber-500/20",children:(0,s.jsx)(e2.A,{className:"h-3 w-3"})})]}),(0,s.jsxs)("div",{className:B("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:O,value:j,onChange:ev,onKeyDown:ef,onPaste:ew,onSelect:e=>P(e.target.selectionStart),placeholder:H?"All agents are disabled — enable one in the Agents tab to chat":J?x("goal.inputLocked"):n?"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)(ax,{}),(0,s.jsx)("button",{onClick:()=>{var e;return null==(e=U.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)(nX.A,{className:"h-4 w-4"})}),(0,s.jsx)(ap,{}),(0,s.jsx)(ac,{}),(0,s.jsx)(ah,{onCompact:u}),null==m?void 0:m(),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)(e2.A,{className:"h-2.5 w-2.5"})})]},"q-".concat(t))),$&&(0,s.jsx)("button",{onClick:()=>v(!g),title:g?"Click to exclude context":"Click to include context",className:B("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:$})}),E.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:()=>eu(e),className:"ml-0.5 rounded-full p-0.5 hover:bg-green-500/20 hover:text-green-300",children:(0,s.jsx)(e2.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)(eg.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:()=>ep(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)(e2.A,{className:"h-2.5 w-2.5"})})]},"f-".concat(t))),(0,s.jsx)("div",{className:"flex-1"}),n&&!j.trim()&&0===w.length?(0,s.jsx)("button",{onClick:a,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)(n0.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,s.jsx)("button",{onClick:eh,disabled:H||Z||!j.trim()&&0===w.length,title:H?"All agents are disabled — enable one to chat":Z?x("goal.inputLocked"):n&&j.trim()?"Send (interrupts current response)":"Send (Enter)",className:B("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors",!H&&!Z&&(j.trim()||w.length>0)?n?"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)(n1.A,{className:"h-4 w-4"})})]})]})]})}let ag={intake:"border-blue-500/30 bg-blue-500/10 text-blue-400",running:"border-emerald-500/30 bg-emerald-500/10 text-emerald-400",paused:"border-amber-500/30 bg-amber-500/10 text-amber-400",halted:"border-red-500/30 bg-red-500/10 text-red-400",done:"border-emerald-500/30 bg-emerald-500/10 text-emerald-400"};function av(e){let{currentSessionId:t,onJump:r}=e,n=r5(e=>e.enabled),a=r5(e=>e.goal),l=r5(e=>e.dismissedGoalId),o=r5(e=>e.dismiss),i=(0,eV.kj)();if(!n||!a)return null;let c="done"===a.status||"halted"===a.status;if(c&&l===a.goalSessionId)return null;let d=i("goal.banner.".concat(a.status),{round:a.round,max:a.maxRounds}),u=t===a.goalSessionId,m=t===a.workerSessionId;return(0,s.jsxs)("div",{className:B("flex items-center gap-2 border-t px-3 py-1.5 text-[11px]",ag[a.status]),children:[(0,s.jsx)("button",{onClick:()=>!u&&r(a.goalSessionId),title:u?void 0:i("goal.banner.jump"),className:B("min-w-0 flex-1 truncate text-left",!u&&"hover:underline cursor-pointer"),children:d}),(0,s.jsx)("button",{onClick:()=>!m&&r(a.workerSessionId),title:m?void 0:i("goal.banner.jump_worker"),className:B("shrink-0",!m&&"hover:underline cursor-pointer"),children:i("goal.banner.worker")}),c&&(0,s.jsx)("button",{onClick:()=>o(a.goalSessionId),title:i("goal.banner.dismiss"),className:"shrink-0 rounded p-0.5 opacity-60 hover:opacity-100 transition-opacity",children:(0,s.jsx)(e2.A,{className:"h-3 w-3"})})]})}var ab=r(70805);function aj(e){let{onLoadOlder:t,scrollRef:r}=e,n=(0,eV.kj)(),a=rE(e=>e.sessionId),o=rM(e=>e.sessionId),i=rM(e=>e.anchor),c=rM(e=>e.cursor),d=rM(e=>e.messages),u=rM(e=>e.loading),[m,x]=(0,l.useState)(!1),p=(0,l.useRef)(null);(0,l.useLayoutEffect)(()=>{let e=r.current,t=p.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,p.current=null)},[m,r]);let h=(0,l.useMemo)(()=>d.filter(ro),[d]);return null===o||o!==a||0===i?null:(0,s.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[c>0?(0,s.jsxs)("button",{onClick:t,disabled:u,className:"flex w-full items-center justify-center gap-1.5 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:hover:bg-transparent",children:[u&&(0,s.jsx)(ee.A,{className:"h-3 w-3 animate-spin"}),n(u?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,s.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.noEarlier")}),h.length>0&&(0,s.jsxs)(s.Fragment,{children:[m&&(0,s.jsx)(nE,{messages:h,readOnly:!0}),(0,s.jsxs)("button",{onClick:()=>{let e=r.current;p.current=e?e.scrollHeight-e.scrollTop:null,x(!m)},className:"flex w-full items-center gap-2 border-t border-[var(--border)]/50 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[m?(0,s.jsx)(ab.A,{className:"h-3 w-3"}):(0,s.jsx)(Q.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:n("chat.archive.header",{segments:i-c,messages:h.length})})]})]})]})}var ay=r(39802),aw=r(72486);let aN=e=>Math.min(480,Math.max(120,Math.round(e)));function ak(e,t){try{localStorage.setItem(e,t)}catch(e){}}function aS(e){let{openKey:t,widthKey:r,defaultWidth:n,title:a,children:o,collapsedContent:i}=e,c=(0,eV.kj)(),[d,u]=(0,l.useState)(()=>"false"!==localStorage.getItem(t)),[m,x]=(0,l.useState)(()=>(function(e,t){let r=Number(localStorage.getItem(e));return Number.isFinite(r)&&r>0?aN(r):t})(r,n)),p=(0,l.useCallback)(e=>{u(e),ak(t,String(e))},[t]),h=(0,l.useCallback)(e=>{if(0!==e.button)return;e.preventDefault();let t=e.clientX,n=m,a=document.body.style,s=a.cursor,l=a.userSelect;a.cursor="col-resize",a.userSelect="none";let o=e=>{x(n=aN(m+t-e.clientX))},i=()=>{window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i),a.cursor=s,a.userSelect=l,ak(r,String(n))};window.addEventListener("pointermove",o),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i)},[m,r]);return d?(0,s.jsxs)("div",{className:"relative flex shrink-0 flex-col border-l border-[var(--border)] bg-[var(--card)]",style:{width:m},children:[(0,s.jsx)("div",{onPointerDown:h,title:c("sidebar.resize"),className:"absolute inset-y-0 -left-0.5 z-10 w-1 cursor-col-resize transition-colors hover:bg-[var(--primary)]/40"}),(0,s.jsxs)("div",{className:"flex h-7 shrink-0 items-center justify-between gap-1 border-b border-[var(--border)] pl-2 pr-1",children:[(0,s.jsx)("span",{className:"truncate text-[10px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",children:a}),(0,s.jsx)("button",{onClick:()=>p(!1),title:c("sidebar.collapse"),"aria-label":c("sidebar.collapse"),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(aw.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:o})]}):(0,s.jsxs)("div",{className:B("flex shrink-0 flex-col items-center border-l border-[var(--border)] bg-[var(--card)] pt-1",i?"w-10":"w-6"),children:[(0,s.jsx)("button",{onClick:()=>p(!0),title:c("sidebar.expand"),"aria-label":c("sidebar.expand"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(ay.A,{className:"h-3.5 w-3.5"})}),i&&(0,s.jsx)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center",children:i})]})}var aC=r(58958);let aA=e=>e?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]";function aI(e){let{icon:t,label:r,tooltip:n,active:a,onActivate:l,badge:o,actions:i,onClose:c,closeLabel:d,closeIcon:u}=e;return(0,s.jsxs)("div",{onClick:l,title:n,"aria-selected":a,className:B("group mx-1.5 flex h-7 shrink-0 cursor-pointer select-none items-center gap-2 rounded-md px-2 text-[11px] transition-colors",aA(a)),children:[(0,s.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:t}),(0,s.jsx)("div",{className:"min-w-0 flex-1 truncate",children:r}),o,i&&(0,s.jsx)("span",{className:"flex shrink-0 items-center opacity-0 group-hover:opacity-100",children:i}),c&&(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),c(e)},title:d,"aria-label":d,className:"shrink-0 rounded p-0.5 opacity-0 hover:bg-[var(--accent)] group-hover:opacity-100",children:null!=u?u:(0,s.jsx)(e2.A,{className:"h-3 w-3"})})]})}function aE(e){let{icon:t,tooltip:r,active:n,onActivate:a,badge:l}=e;return(0,s.jsxs)("button",{onClick:a,title:r,"aria-label":r,"aria-pressed":n,className:B("relative flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[11px] font-medium transition-colors",aA(n)),children:[t,l]})}function aT(e){let{onClick:t,label:r,collapsed:n=!1}=e;return(0,s.jsx)("div",{className:B("flex shrink-0 justify-center",n?"py-1.5":"p-1.5"),children:(0,s.jsx)("button",{onClick:t,title:r,"aria-label":r,className:B("flex h-7 items-center justify-center rounded-md bg-[var(--secondary)]/50 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",n?"w-7":"w-full"),children:(0,s.jsx)(aC.A,{className:"h-3.5 w-3.5"})})})}let aM=new Map;function aF(e){let{sessions:t,currentSessionId:r,onSelect:n,onDelete:a,onNew:o,onLoadMore:i,hasMore:c=!1,loadingMore:d=!1}=e,u=(0,eV.kj)(),m=r5(e=>e.enabled),x=tq(e=>e.activeProject),[p,h]=(0,l.useState)(null),[f,g]=(0,l.useState)(""),v=(0,l.useRef)(null),b=(0,l.useRef)(""),j=()=>{v.current=null,h(null),g("")},y=async e=>{if(v.current!==e)return;let t=f.trim();if(!t||t===b.current||!(null==x?void 0:x.path))return void j();v.current=null,h(null);try{await N.F.sessionLogs.rename(e,t,x.path)}catch(e){console.error("[SessionSidebar] Rename failed:",e)}nd()};(0,l.useEffect)(()=>{for(let e of(aM.clear(),t))e.title&&aM.set(e.id,e.title)},[t]);let 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)&&(null==i||i())},{rootMargin:"48px"});return t.observe(e),()=>t.disconnect()},[i,t.length]);let k=r_(e=>e.tabs),S=(0,l.useMemo)(()=>new Map(k.flatMap(e=>e.sessionId?[[e.sessionId,e]]:[])),[k]),C=null===r,A=e=>{let t=S.get(e.id);return e.id!==r&&!!(null==t?void 0:t.store)&&!!t.unread},I=e=>e.title||u("chat.tabs.untitled"),E=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center gap-0.5 overflow-y-auto py-1",children:[C&&(0,s.jsx)(aE,{icon:(0,s.jsx)(nf.A,{className:"h-3.5 w-3.5"}),tooltip:u("chat.tabs.newSession"),active:!0,onActivate:()=>{}}),t.map(e=>{let t=S.get(e.id);return(0,s.jsx)(aP,{title:e.title,tooltip:I(e),active:r===e.id,store:null==t?void 0:t.store,unread:A(e),onActivate:()=>n(e.id)},e.id)})]}),o&&(0,s.jsx)(aT,{collapsed:!0,onClick:o,label:u("chat.sessions.new")})]});return(0,s.jsxs)(aS,{openKey:"halo_session_sidebar_open",widthKey:"halo_session_sidebar_width",defaultWidth:200,title:u("chat.sessions.title"),collapsedContent:E,children:[(0,s.jsxs)("div",{className:"flex flex-1 flex-col gap-0.5 overflow-y-auto py-1",children:[C&&(0,s.jsx)(aI,{icon:(0,s.jsx)(nf.A,{className:"h-3 w-3"}),label:u("chat.tabs.newSession"),active:!0,onActivate:()=>{}}),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;let l=S.get(e.id),o=p===e.id,i="string"==typeof(null==(t=e.agentSnapshot)?void 0:t.model)?" \xb7 ".concat(e.agentSnapshot.model.split(".").pop()):"";return(0,s.jsx)(aI,{icon:(0,s.jsx)(aD,{store:null==l?void 0:l.store,unread:A(e)}),tooltip:"".concat(I(e),"\n").concat(e.exchangeCount," msgs \xb7 ").concat(q(e.updatedAt,u)).concat(i),active:r===e.id,onActivate:()=>n(e.id),label:o?(0,s.jsx)("input",{autoFocus:!0,value:f,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),y(e.id)):"Escape"===t.key&&(t.preventDefault(),j())},onBlur:()=>y(e.id),className:"w-full 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.jsxs)(s.Fragment,{children:[m&&e.goalSessionId&&(0,s.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),I(e)]}),actions:o?void 0:(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),v.current=e.id,b.current=e.title||"",h(e.id),g(e.title||"")},title:u("chat.sessions.rename"),"aria-label":u("chat.sessions.rename"),className:"rounded p-0.5 text-[var(--muted-foreground)] hover:text-blue-400",children:(0,s.jsx)(eU.A,{className:"h-3 w-3"})}),onClose:o?void 0:t=>a(e.id,t),closeLabel:u("chat.sessions.delete"),closeIcon:(0,s.jsx)(eP.A,{className:"h-3 w-3"})},e.id)}),c&&(0,s.jsx)("div",{ref:w,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)(ee.A,{className:"h-2.5 w-2.5 animate-spin mr-1"})," Loading…"]}):(0,s.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]}),o&&(0,s.jsx)(aT,{onClick:o,label:u("chat.sessions.new")})]})}function aD(e){let{store:t,unread:r,className:n}=e,a=(0,eV.kj)(),o=function(e){let t=(0,l.useCallback)(t=>e?e.subscribe(t):()=>{},[e]),r=()=>{var t;return null!=(t=null==e?void 0:e.getState().isStreaming)&&t};return(0,l.useSyncExternalStore)(t,r,r)}(t);return(0,s.jsx)("span",{title:a(o?"status.busy":r?"chat.tabs.unread":"status.idle"),className:B("inline-block h-2 w-2 shrink-0 rounded-full",o?"bg-amber-400 animate-pulse":r?"bg-blue-500":"bg-emerald-500",n)})}function aP(e){let{title:t,tooltip:r,active:n,store:a,unread:l,onActivate:o}=e,i=Array.from(t.trim())[0];return(0,s.jsx)(aE,{icon:i?i.toUpperCase():(0,s.jsx)(nf.A,{className:"h-3.5 w-3.5"}),tooltip:r,active:n,onActivate:o,badge:(0,s.jsx)(aD,{store:a,unread:l,className:"absolute right-0.5 top-0.5"})})}var aL=r(81324);let aR=no(),a_=aR.useBus,az=aR.bump;function aO(){var e,t;let r=rE(e=>e.selectedAgentId),n=rE(e=>e.sessionId),a=rE(e=>e.isStreaming),o=tq(e=>e.activeProject),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!1),m=(0,l.useRef)(null),x=a_(e=>e.version);(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&N.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),rE.getState().setUsableAgentCount(t.length);let r=rE.getState();!r.sessionId&&"default"===r.selectedAgentId&&t[0]&&"default"!==t[0].id&&r.setSelectedAgentId(t[0].id)}).catch(()=>{})},[null==o?void 0:o.path,x]),(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&n6(o.path,null!=n?n:void 0,null!=r?r:void 0).catch(()=>{})},[null==o?void 0:o.path,n,r,x]),(0,l.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let p=!!n,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:m,className:"relative",children:[(0,s.jsxs)("button",{onClick:()=>!p&&!a&&u(!d),disabled:p||a,title:p?"Agent is locked to current session. Start a new session to switch.":"Select agent",className:B("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)(np.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{className:"max-w-[80px] truncate",children:f}),!p&&(0,s.jsx)(V.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:()=>{rE.getState().setSelectedAgentId(e.id),u(!1)},className:B("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)(np.A,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name})]},"".concat(e.id,":").concat(e.scope)))})]})}function aU(){let e=(0,eV.kj)(),{messages:t,sendMessage:r,isStreaming:n,deleteSession:a,stopGeneration:o,interruptGeneration:i,pendingMessages:c,removePendingMessage:d,handleCommand:u,sessionId:m}=function(){let e=(0,eV.kj)(),t=rE(e=>e.messages),r=rE(e=>e.isStreaming),n=rE(e=>e.sessionId),a=rE(e=>e.pendingMessages),s=tq(e=>e.activeProject);(0,l.useEffect)(()=>{s&&function(e){var t;let r=r_.getState();if(r.projectId===e)return;let n=function(e){try{let t=localStorage.getItem(rz(e));if(t){let e=JSON.parse(t);return"string"==typeof e.active&&e.active.length>0?e.active:null}for(let t of["halo_session_".concat(e),"halo_session_id"]){let e=localStorage.getItem(t);if(e)return localStorage.removeItem(t),e}}catch(e){}return null}(e),a=n?{tabId:W(),sessionId:n}:rL(rG(null));for(let n of(r_.setState({projectId:e,tabs:[a],activeTabId:a.tabId}),rq(null!=(t=rJ(a.tabId))?t:""),r.tabs))n.store&&rN(n.store);rU.clear()}(s.id)},[null==s?void 0:s.id]);let o=(0,l.useCallback)(()=>{let{activeTab:e,selectedText:t,selectedRange:r,tabs:n,contextEnabled:a}=b.getState();if(!a)return"";let s=[];if(e&&s.push("[Currently viewing: ".concat(e,"]")),t&&t.trim()&&e){let n=r?":".concat(r.startLine,"-").concat(r.endLine):"";s.push("[Selected text in ".concat(e).concat(n,"]\n```\n").concat(t,"\n```"))}return s.length>0?s.join("\n")+"\n\n":""},[]),i=(0,l.useCallback)((t,r,a)=>{if(!s)return;let l=null!=n?n:W();n||rQ(l);let i=o(),c=[];i&&c.push(i.trim()),(null==a?void 0:a.length)&&c.push("[Referenced files:\n".concat(a.map(e=>" - ".concat(e)).join("\n"),"]"));let d=rE.getState().captureSource,u=window;d&&u&&("camera"===d.kind&&u.haloCamera?c.push(e("capture.cameraLlmPrompt")):"screen"===d.kind&&u.haloCapture&&c.push(e("capture.llmPrompt",{name:d.name})));let m=(c.length>0?c.join("\n")+"\n\n":"")+t.trim(),x=rE.getState(),p=t.trim();if(null==a?void 0:a.length){let e=a.map(e=>"@".concat(e.split("/").pop())).join(" ");p="".concat(e," ").concat(p)}if(null==r?void 0:r.length){let t=e("chat.imageSent",{n:r.length});p=p?"".concat(t,"\n").concat(p):t}let h=W();x.addMessage({id:W(),role:"user",content:p,timestamp:Date.now(),clientMsgId:h,...(null==r?void 0:r.length)?{localImages:r.map(e=>"data:".concat(e.mimeType,";base64,").concat(e.data))}:{}}),x.messages.some(e=>e.streaming&&"assistant"===e.role&&!e.taskId)||x.addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let{selectedAgentId:f,accessLevel:g}=rE.getState();S.send({type:"chat",sessionId:l,projectId:s.id,message:m,clientMsgId:h,accessLevel:g,..."default"!==f?{agentId:f}:{},...(null==r?void 0:r.length)?{images:r}:{}})},[n,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,n]),d=(0,l.useCallback)(()=>{S.send({type:"chat:stop",sessionId:n})},[n]),u=(0,l.useCallback)(()=>{S.send({type:"chat:interrupt",sessionId:n})},[n]),m=(0,l.useCallback)(e=>{rE.getState().removePendingMessage(e)},[]);(0,l.useEffect)(()=>{if(r)return;let e=rE.getState().shiftPendingMessage();if(e){let t=setTimeout(()=>i(e),100);return()=>clearTimeout(t)}},[r,i]);let x=(0,l.useCallback)(e=>{s&&(S.send({type:"session:delete",sessionId:e,projectId:s.path}),rV(e),na(e))},[s]),p=(0,l.useCallback)((e,t)=>{if(!s)return;if("/clear"===e.name||"/session"===e.name&&"new"===t.trim())return void rY();let r=null!=n?n:W();n||rQ(r);let a=e.name.slice(1),l=rE.getState().selectedAgentId,o={type:"command:".concat(a),sessionId:r,projectId:s.id,..."default"!==l?{agentId:l}:{}};t.trim()&&(o.message=t.trim()),S.send(o),rE.getState().addMessage({id:W(),role:"system",content:"Executing ".concat(e.name).concat(t.trim()?" ".concat(t.trim()):"","..."),timestamp:Date.now()})},[s,n]);return{messages:t,sendMessage:c,isStreaming:r,sessionId:n,deleteSession:x,stopGeneration:d,interruptGeneration:u,pendingMessages:a,removePendingMessage:m,handleCommand:p}}(),x=r_(e=>e.tabs.find(t=>t.tabId===e.activeTabId)),{sessions:p,remove:h,loadMore:f,hasMore:g,loadingMore:v}=function(){let e=tq(e=>e.activeProject);return function(e){let[t,r]=(0,l.useState)([]),[n,a]=(0,l.useState)(null),[s,o]=(0,l.useState)(!1),i=nc(e=>e.version),c=(0,l.useCallback)(async()=>{if(!e){r([]),a(null);return}try{let t=await N.F.sessionLogs.list(e,{rootOnly:!0,limit:30});r(t.sessions),a(t.nextCursor)}catch(e){r([]),a(null)}},[e]);(0,l.useEffect)(()=>{c()},[c,i]);let d=(0,l.useCallback)(async()=>{if(null!==n&&!s){o(!0);try{if(!e)return;let t=await N.F.sessionLogs.list(e,{rootOnly:!0,limit:30,cursor:n}),s=t.sessions;r(e=>{let t=new Set(e.map(e=>e.id));return[...e,...s.filter(e=>!t.has(e.id))]}),a(t.nextCursor)}catch(e){console.error("[SessionList] loadMore failed:",e)}finally{o(!1)}}},[e,n,s]);return{sessions:t,refresh:c,remove:(0,l.useCallback)(async t=>{try{await N.F.sessionLogs.delete(t,e),r(e=>e.filter(e=>e.id!==t)),na(t),nd()}catch(e){console.error("[SessionList] Delete failed:",e)}},[e]),loadMore:d,hasMore:null!==n,loadingMore:s}}(null==e?void 0:e.path)}(),[j,y]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_chat_debug"));(0,l.useEffect)(()=>{localStorage.setItem("halo_chat_debug",j?"1":"0")},[j]);let w=tq(e=>{var t;return null==(t=e.activeProject)?void 0:t.id});(0,l.useEffect)(()=>{w&&r2(w)},[w]);let k=(0,l.useCallback)(async(t,r)=>{r.stopPropagation(),await G(e("chat.sessions.deleteConfirm"))&&(await h(t),a(t))},[a,h,e]),C=(0,l.useMemo)(()=>j?t.filter(e=>!e.taskId):t.filter(ro),[t,j]);return(0,s.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-full min-w-0 flex-1 flex-col",children:[x&&(0,s.jsx)(aB,{tab:x,sessionId:m,mainMessages:C,debugMode:j},x.tabId),(0,s.jsxs)("div",{className:"shrink-0",children:[(0,s.jsx)(av,{currentSessionId:m,onJump:rZ}),(0,s.jsx)(af,{onSend:r,isStreaming:n,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:[(0,s.jsxs)("button",{onClick:()=>y(!j),className:B("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",j?"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 tool calls and usage",children:[(0,s.jsx)(aL.A,{className:"h-3 w-3"}),"Debug"]}),(0,s.jsx)(aO,{})]})})]})]}),(0,s.jsx)(aF,{sessions:p,currentSessionId:m,onSelect:rZ,onDelete:k,onNew:()=>rY(),onLoadMore:f,hasMore:g,loadingMore:v})]})}function aB(e){var t,r;let{tab:n,sessionId:a,mainMessages:o,debugMode:i}=e,c=(0,eV.kj)(),d=n.tabId,u=(0,l.useRef)(null),[m]=(0,l.useState)(()=>rU.get(d)),[x,p]=(0,l.useState)(null),h=!!n.loading,f=null!=(t=n.attempt)?t:0;(0,l.useEffect)(()=>{if(!h)return;let e=setTimeout(()=>p(f),3e4);return()=>clearTimeout(e)},[h,f]);let g=h&&x===f,v=(0,l.useRef)(null!=(r=null==m?void 0:m.userScrolledUp)&&r),b=(0,l.useMemo)(()=>{let e=0;for(let t of o)"user"===t.role&&e++;return e},[o]),j=Math.max(0,b-30),[y,w]=(0,l.useState)(()=>({sessionId:a,hiddenTurns:m?Math.min(m.hiddenTurns,j):j,seenTurns:b}));y.sessionId!==a?w({sessionId:a,hiddenTurns:j,seenTurns:b}):(y.hiddenTurns>j||0===y.seenTurns&&b>0)&&w({sessionId:y.sessionId,hiddenTurns:j,seenTurns:b});let N=y.hiddenTurns;(0,l.useLayoutEffect)(()=>{y.seenTurns!==b&&w(e=>({sessionId:e.sessionId,hiddenTurns:v.current?e.hiddenTurns:Math.max(0,b-30),seenTurns:b}))}),(0,l.useEffect)(()=>{rB(d,{hiddenTurns:N})},[d,N]);let k=(0,l.useMemo)(()=>{if(N<=0)return o;let e=0;for(let t=0;t<o.length;t++)if("user"===o[t].role&&++e>N)return o.slice(t);return o},[o,N]),S=(0,l.useRef)(null),C=(0,l.useCallback)(()=>{let e=u.current;S.current=e?e.scrollHeight-e.scrollTop:null,w(e=>({...e,hiddenTurns:Math.max(0,e.hiddenTurns-30)}))},[]);(0,l.useLayoutEffect)(()=>{let e=u.current,t=S.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,S.current=null)},[N]),(0,l.useLayoutEffect)(()=>{let e=u.current;e&&(e.scrollTop=(null==m?void 0:m.userScrolledUp)?m.scrollTop:e.scrollHeight)},[m]);let A=(0,l.useRef)(null),I=(0,l.useRef)(!0),E=(0,l.useCallback)(()=>{let e=u.current;A.current=e?e.scrollHeight-e.scrollTop:null,rP()},[]),T=N>0;(0,l.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;v.current=!t,rB(d,{scrollTop:e.scrollTop,userScrolledUp:!t}),e.scrollTop>200?I.current=!0:e.scrollTop<80&&I.current&&(I.current=!1,T?C():E())};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[d,E,C,T]);let M=rM(e=>e.messages);return(0,l.useEffect)(()=>{let e=u.current,t=A.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,A.current=null)},[M]),(0,l.useEffect)(()=>{u.current&&!v.current&&(u.current.scrollTop=u.current.scrollHeight)},[o]),(0,l.useEffect)(()=>{let e=u.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{v.current||(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]),(0,s.jsx)("div",{ref:u,className:"flex-1 min-h-0 overflow-y-auto",children:h&&n.sessionId?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)(ee.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}),g&&(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{children:"Slow network — still loading…"}),(0,s.jsx)("button",{onClick:()=>(function(e){var t;let r=rW(t=>t.tabId===e);(null==r?void 0:r.sessionId)&&(rH(e,{loading:!0,attempt:(null!=(t=r.attempt)?t:0)+1}),rq(r.sessionId))})(d),className:"text-[var(--primary)] hover:underline",children:"Retry"})]})]}):0===o.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)(nf.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.jsxs)(s.Fragment,{children:[N>0?(0,s.jsx)("button",{onClick:C,className:"flex w-full items-center justify-center gap-1.5 border-b border-[var(--border)]/50 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:c("chat.window.showEarlier",{count:N})}):(0,s.jsx)(aj,{onLoadOlder:E,scrollRef:u}),(0,s.jsx)(nE,{messages:k,debugMode:i,userOrdinalBase:N})]})})}var aW=r(86557),aH=r(21379);let aK="halo_browser_id";function aG(){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 aq=null;function aJ(){if(aq)return aq;try{let e=window.localStorage.getItem(aK);return e||(e=aG(),window.localStorage.setItem(aK,e)),aq=e,e}catch(e){return aq=aG()}}r(87063);let aZ=0,a$={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"}},aY={fontFamily:"'JetBrains Mono', 'Fira Code', Menlo, Monaco, monospace",fontSize:13,lineHeight:1.4,cursorBlink:!0,scrollback:1e4};function aV(e,t,r){let n=document.createElement("div");n.className="absolute inset-0",n.style.display="none",e.appendChild(n);let a=new aW.B({...aY,theme:a$[r]}),s=new aH.Y;a.loadAddon(s),a.open(n),s.fit(),a.onData(e=>{S.send({type:"terminal:input",data:e,terminalId:t})});let l=null,o=new ResizeObserver(()=>{s.fit(),l&&clearTimeout(l),l=setTimeout(()=>{S.send({type:"terminal:resize",cols:a.cols,rows:a.rows,terminalId:t})},150)});return o.observe(n),{term:a,fit:s,container:n,ro:o}}function aQ(){let{headerless:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,eV.kj)(),r=(0,l.useRef)(null),n=(0,l.useRef)(new Map),[a,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(null),d=tq(e=>e.activeProject),{theme:u}=(0,eW.useTheme)(),m=(0,l.useRef)(u);(0,l.useEffect)(()=>{for(let e of(m.current=u,n.current.values()))e.term.options.theme=a$[u]},[u]);let x=(0,l.useCallback)(e=>{var t,s,l;let i=r.current;if(!i)return;aZ++;let u="term_".concat(Date.now().toString(36),"_").concat(aZ),x=0===a.length?"bash":"bash (".concat(aZ,")"),{term:p,fit:h,container:f,ro:g}=aV(i,u,m.current);n.current.set(u,{id:u,name:x,term:p,fit:h,container:f,ro:g,ready:!1,exited:!1});let v=new URLSearchParams(window.location.search).get("folder"),b=null!=(s=null!=(t=null!=e?e:null==d?void 0:d.path)?t:v)?s:"~";return S.send({type:"terminal:start",terminalId:u,cwd:b,cols:p.cols,rows:p.rows,browserId:aJ(),workspacePath:null!=(l=null==d?void 0:d.path)?l:""}),o(e=>[...e,{id:u,name:x}]),c(u),u},[d,a.length]),p=(0,l.useCallback)(e=>{let t=n.current.get(e);t&&(S.send({type:"terminal:close",terminalId:e}),t.ro.disconnect(),t.term.dispose(),t.container.remove(),n.current.delete(e),o(t=>{let r=t.filter(t=>t.id!==e);return c(n=>{if(n===e){var a,s;return null!=(s=null==(a=r[Math.min(t.findIndex(t=>t.id===e),r.length-1)])?void 0:a.id)?s:null}return n}),r}))},[]),h=(0,l.useCallback)(e=>{c(e)},[]);(0,l.useEffect)(()=>{let e=n.current;return()=>{for(let t of e.values())t.ro.disconnect(),t.term.dispose(),t.container.remove();e.clear()}},[]),(0,l.useEffect)(()=>{for(let[e,t]of n.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(S.on("terminal:output",e=>{let{terminalId:t,data:r}=e;if(t){var a;null==(a=n.current.get(t))||a.term.write(r)}else{let e=n.current.values().next().value;null==e||e.term.write(r)}})),e.push(S.on("terminal:ready",e=>{let{terminalId:t}=e;if(t){let e=n.current.get(t);e&&(e.ready=!0)}})),e.push(S.on("terminal:exit",e=>{let{terminalId:t}=e;if(t){let e=n.current.get(t);e&&(e.exited=!0,e.term.writeln("\r\n\x1b[90m[Process exited]\x1b[0m"))}})),()=>e.forEach(e=>e())},[]);let f=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(f.current)return;f.current=!0;let e=S.on("terminal:reattached",e=>{let t=e.terminalIds,a=r.current,s=0;for(let e of t){if(n.current.has(e)){let t=n.current.get(e);S.send({type:"terminal:resize",cols:t.term.cols,rows:t.term.rows,terminalId:e});continue}if(!a)continue;aZ++;let t=0===s&&0===n.current.size?"bash":"bash (".concat(aZ,")");s++;let{term:r,fit:l,container:i,ro:d}=aV(a,e,m.current);r.write("\x1b[?2004h");let u={id:e,name:t,term:r,fit:l,container:i,ro:d,ready:!0,exited:!1};n.current.set(e,u),o(r=>[...r,{id:e,name:t}]),c(t=>null!=t?t:e),S.send({type:"terminal:resize",cols:r.cols,rows:r.rows,terminalId:e})}0===t.length&&0===n.current.size&&x()}),t=()=>{var e;S.send({type:"terminal:reattach",browserId:aJ(),workspacePath:null!=(e=null==d?void 0:d.path)?e:""})};t();let a=S.on("_connected",t),s=setTimeout(()=>{0===n.current.size&&x()},2e3);return()=>{clearTimeout(s),e(),a()}},[x]),(0,l.useEffect)(()=>{let e=b.getState().pendingTerminalCwd;return b.subscribe(t=>{let r=t.pendingTerminalCwd;if(r&&r!==e){e=r;let n=t.consumeTerminalSpawn();n&&x(n)}else e=r})},[x]),(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)(aS,{openKey:"halo_terminal_sidebar_open",widthKey:"halo_terminal_sidebar_width",defaultWidth:160,title:t("terminal.list.title"),collapsedContent:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center gap-0.5 overflow-y-auto py-1",children:a.map(e=>(0,s.jsx)(aE,{icon:(0,s.jsx)(ei.A,{className:"h-3.5 w-3.5"}),tooltip:e.name,active:e.id===i,onActivate:()=>h(e.id)},e.id))}),(0,s.jsx)(aT,{collapsed:!0,onClick:()=>x(),label:t("terminal.list.new")})]}),children:[(0,s.jsx)("div",{className:"flex flex-1 flex-col gap-0.5 overflow-y-auto py-1",children:a.map(e=>(0,s.jsx)(aI,{icon:(0,s.jsx)(ei.A,{className:"h-3 w-3"}),label:e.name,tooltip:e.name,active:e.id===i,onActivate:()=>h(e.id),onClose:a.length>1?()=>p(e.id):void 0,closeLabel:t("terminal.list.close")},e.id))}),(0,s.jsx)(aT,{onClick:()=>x(),label:t("terminal.list.new")})]})]})}var aX=r(39768);function a0(){let{floating:e=!1,dragHandleRef:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=(0,eV.kj)(),n=b(e=>e.bottomTab),a=b(e=>e.setBottomTab),o=b(e=>e.setBottomFloating),i=b(e=>e.bottomMaximized),c=b(e=>e.setBottomMaximized),[d,u]=(0,l.useState)("terminal"===n);(0,l.useEffect)(()=>{"terminal"===n&&u(!0)},[n]);let[m,x]=(0,l.useState)(0);return(0,l.useEffect)(()=>S.on("_disconnected",()=>x(e=>e+1)),[]),(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{ref:t,className:B("flex h-[35px] shrink-0 items-center gap-0 border-b border-[var(--border)] bg-[var(--card)] px-2",e&&"cursor-move select-none"),children:[(0,s.jsx)(a1,{label:r("nav.chat"),active:"chat"===n,onClick:()=>a("chat")}),(0,s.jsx)(a1,{label:r("nav.terminal"),active:"terminal"===n,onClick:()=>a("terminal")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>c(!i),title:i?"Restore panel":"Maximize panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:i?(0,s.jsx)(tZ.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(t$.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>o(!e),title:e?"Dock back":"Float panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:e?(0,s.jsx)(e2.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(aX.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)(aU,{})}),(0,s.jsx)("div",{className:"terminal"===n?"h-full":"hidden",children:d&&(0,s.jsx)(aQ,{headerless:!0},m)})]})]})}function a1(e){let{label:t,active:r,onClick:n}=e;return(0,s.jsxs)("button",{onClick:n,className:B("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 a3(e){let{slotRef:t,dragHandleRef:r}=e,n=b(e=>e.bottomFloatRect),a=b(e=>e.setBottomFloatRect),o=b(e=>e.bottomMaximized),i=(0,l.useRef)(n);(0,l.useEffect)(()=>{i.current=n}),(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,n={...i.current};function s(e){let s=e.clientX-t,l=e.clientY-r;a({x:a5(n.x+s,0,window.innerWidth-n.w),y:a5(n.y+l,0,window.innerHeight-n.h),w:n.w,h:n.h})}window.addEventListener("mousemove",s),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",e)})}},[a,o,r]),(0,l.useEffect)(()=>{function e(){let e=i.current,t=a5(e.x,0,Math.max(0,window.innerWidth-e.w)),r=a5(e.y,0,Math.max(0,window.innerHeight-e.h));(t!==e.x||r!==e.y)&&a({...e,x:t,y:r})}return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[a]);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 n=null!=(t=r.getAttribute("data-edges"))?t:"",s={top:n.includes("top"),bottom:n.includes("bottom"),left:n.includes("left"),right:n.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 m(e){let t=e.clientX-l,r=e.clientY-o,{x:n,y:i,w:m,h:x}=c;if(s.right&&(m=a5(c.w+t,320,window.innerWidth-c.x)),s.bottom&&(x=a5(c.h+r,240,window.innerHeight-c.y)),s.left){let e=a5(c.x+t,0,d-320);n=e,m=d-e}if(s.top){let e=a5(c.y+r,0,u-240);i=e,x=u-e}a({x:n,y:i,w:m,h:x})}window.addEventListener("mousemove",m),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",e)})}},[a,o]);let d=o?{left:0,top:0,width:"100vw",height:"100vh"}:{left:n.x,top:n.y,width:n.w,height:n.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 a5(e,t,r){return Math.max(t,Math.min(r,e))}let a2={ts:eu.A,tsx:eu.A,js:eu.A,jsx:eu.A,json:er.A,md:es.A};function a4(e){let{onSelect:t,onClose:r}=e,n=tq(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),[a,o]=(0,l.useState)(""),[i,c]=(0,l.useState)(0),[d,u]=(0,l.useState)([]),[m,x]=(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)},[a]),(0,l.useEffect)(()=>{if(!n)return;let e=a.trim();if(!e){u([]),x(!1);return}x(!0);let t=!1,r=setTimeout(()=>{N.F.files.search(n,e,50).then(e=>{t||u(e.matches)}).catch(e=>{t||(console.error("[QuickOpen] Search failed:",e),u([]))}).finally(()=>{t||x(!1)})},150);return()=>{t=!0,clearTimeout(r)}},[n,a]),(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:a,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:m?"Searching...":"No files found"}):d.map((e,n)=>{var a,l,o;let c=null!=(o=a2[null!=(l=null==(a=e.name.split(".").pop())?void 0:a.toLowerCase())?l:""])?o:eg.A;return(0,s.jsxs)("button",{onClick:()=>{t(e.path),r()},className:B("flex w-full items-center gap-2 px-4 py-2 text-left text-xs transition-colors",n===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 a8=r(82011),a6=r(35418);function a9(e){let{initialPath:t,onSelect:r,onClose:n}=e,[a,o]=(0,l.useState)(null!=t?t:""),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)([]),[m,x]=(0,l.useState)(!1),[p,h]=(0,l.useState)(null),f=(0,l.useCallback)(async e=>{x(!0),h(null);try{let t=await N.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{x(!1)}},[]);return(0,l.useEffect)(()=>{t?f(t):N.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:n,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:n,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,s.jsx)(e2.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:m||!i||i===a,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)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>N.F.fs.home().then(e=>{let{home:t}=e;return f(t)}),disabled:m,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)(a6.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("input",{type:"text",value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&f(a)},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}),m&&!p&&(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}),!m&&!p&&0===d.length&&(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"(empty)"}),!m&&d.map(e=>(0,s.jsxs)("button",{onDoubleClick:()=>f(e.path),onClick:()=>o(e.path),className:B("flex w-full items-center gap-2 px-4 py-1.5 text-xs text-left transition-colors",a===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:n,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(a),disabled:!a,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 a7="halo_recent_workspaces";function se(){try{let e=localStorage.getItem(a7),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function st(e){try{localStorage.setItem(a7,JSON.stringify(e))}catch(e){}}var sr=r(42981),sn=r(29062),sa=r(24619);function ss(e){var t,r;let{projectId:n,pathInput:a,onPathInputChange:o,onOpenFolder:i,onOpenPath:c,activeProject:d}=e,u=(0,eV.kj)(),m=rE(e=>e.isStreaming),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g=(0,l.useRef)(null),{recent:v,remove:b}=function(){let[e,t]=(0,l.useState)([]);return(0,l.useEffect)(()=>{t(se())},[]),{recent:e,remove:(0,l.useCallback)(e=>{t(t=>{let r=t.filter(t=>t!==e);return st(r),r})},[])}}(),[j,y]=(0,l.useState)(!1),[w,k]=(0,l.useState)(!1),S=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(j)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){S.current&&!S.current.contains(e.target)&&y(!1)}},[j]);let C=w?a.trim().toLowerCase():"",A=v.filter(e=>e!==(null==d?void 0:d.path)&&(!C||e.toLowerCase().includes(C)));async function E(){if(!n)return;let e=await K("New file name (relative path, e.g. src/hello.ts):");if(null==e?void 0:e.trim())try{await N.F.files.create(e.trim(),n),I(n)}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(!n)return;let e=await K("New folder name (relative path, e.g. src/utils):");if(null==e?void 0:e.trim())try{await N.F.files.mkdir(e.trim(),n),I(n)}catch(e){console.error("[Explorer] Failed to create folder:",e),window.alert(e instanceof Error?e.message:"Failed to create folder")}}async function M(e){var t;if(!n||!(null==(t=e.target.files)?void 0:t.length))return;let r=Array.from(e.target.files);try{await N.F.files.upload(r,n),I(n)}catch(e){console.error("[Explorer] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}e.target.value=""}let F=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)(sr.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"}),n&&(0,s.jsx)("button",{onClick:function(){n&&(p(!0),I(n),setTimeout(()=>p(!1),500))},disabled:x,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)(nh.A,{className:B("h-3.5 w-3.5",x&&"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:S,className:"relative min-w-0 flex-1",children:[(0,s.jsx)("input",{type:"text",value:a,onChange:e=>{o(e.target.value),k(!0),y(!0)},onFocus:()=>{k(!1),y(!0)},onKeyDown:e=>{"Enter"!==e.key||e.repeat||e.nativeEvent.isComposing?"Escape"===e.key&&y(!1):(y(!1),i())},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)]"}),j&&A.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:A.map(e=>(0,s.jsxs)("div",{onClick:()=>{y(!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)(sn.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(),b(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)(e2.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)(e_.A,{className:"h-3.5 w-3.5"})})]}),h&&(0,s.jsx)(a9,{initialPath:null==d?void 0:d.path,onSelect:e=>{f(!1),c(e)},onClose:()=>f(!1)}),n&&(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(m?"status.busy":"status.idle"),className:B("inline-block h-2 w-2 shrink-0 rounded-full",m?"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:F})]}),(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)(eL.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)(eR.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)(sa.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("input",{ref:g,type:"file",multiple:!0,className:"hidden",onChange:M})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:n?(0,s.jsx)(t0,{projectId:n,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)(X.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"})]})})]})}let sl=no(),so=sl.useBus,si=sl.bump;var sc=r(91061),sd=r(40876),su=r(35829);function sm(e){return"".concat(e.id,":").concat(e.scope)}let sx="halo_skills_selectedKey",sp="halo_skills_expandedScopes";function sh(){try{let e=localStorage.getItem(sp);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}let sf=(0,c.v)(e=>({skills:[],selectedKey:localStorage.getItem(sx),setSkills:t=>e({skills:t}),setSelectedKey:t=>{t?localStorage.setItem(sx,t):localStorage.removeItem(sx),e({selectedKey:t})},addSkill:t=>e(e=>({skills:[...e.skills,t]})),removeSkill:t=>e(e=>{let r=e.skills.filter(e=>sm(e)!==t),[n,a]=t.split(":"),s="workspace"===a?r.map(e=>e.id===n&&"global"===e.scope?{...e,overridden:!1}:e):r,l=e.selectedKey===t?null:e.selectedKey;return e.selectedKey===t&&localStorage.removeItem(sx),{skills:s,selectedKey:l}})}));function sg(){let e=(0,eV.kj)(),{skills:t,selectedKey:r,setSkills:n,setSelectedKey:a,addSkill:o,removeSkill:i}=sf(),c=tq(e=>e.activeProject),d=null==c?void 0:c.path,[u,m]=(0,l.useState)(sh),[x,p]=(0,l.useState)(!1),h=so(e=>e.version);async function f(e){if("workspace"===e&&!d)return;let r=await K("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 G(t))return}try{let s=(await N.F.skills.create({name:r.trim(),scope:e,projectId:"workspace"===e?d:void 0})).skill;"workspace"===e&&i?n(t.map(e=>e.id===s.id&&"global"===e.scope?{...e,overridden:!0}:e).concat(s)):o(s),m(t=>new Set(t).add(e)),a(sm(s)),si()}catch(e){console.error("[SkillsSidebar] Create failed:",e)}}async function g(e,t){if(e.stopPropagation(),await G('Delete skill "'.concat(t.name,'"?')))try{await N.F.skills.remove(t.id,"workspace"===t.scope?{scope:"workspace",projectId:d}:void 0),i(sm(t)),si()}catch(e){console.error("[SkillsSidebar] Delete failed:",e)}}async function v(e,r){e.stopPropagation();try{let e=await N.F.skills.toggle(r.id,{scope:r.scope,projectId:d});n(t.map(t=>sm(t)===sm(r)?{...t,disabled:e.disabled}:t)),si()}catch(e){console.error("[SkillsSidebar] Toggle failed:",e)}}(0,l.useEffect)(()=>{localStorage.setItem(sp,JSON.stringify([...u]))},[u]),(0,l.useEffect)(()=>{p(!0),N.F.skills.list(d).then(e=>n(e.skills)).catch(()=>{}).finally(()=>p(!1))},[d,h,n]),(0,l.useEffect)(()=>{if(!d)return;let e=S.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/skills/")&&si()}),t=C(S,si);return()=>{e(),t()}},[d]),(0,l.useEffect)(()=>{let e=()=>si();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]);let b=t.filter(e=>"global"===e.scope),j=t.filter(e=>"workspace"===e.scope),y=(e,t,n,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:()=>{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)(Q.A,{className:B("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:n}),(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)(aC.A,{className:"h-3 w-3"})})]}),o&&l.map(e=>{let t=sm(e);return(0,s.jsxs)("div",{onClick:()=>a(t),className:B("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)(sc.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=>v(t,e),className:B("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)(sd.A,{className:"h-4.5 w-4.5"}):(0,s.jsx)(su.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)(eP.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)(sc.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:()=>si(),disabled:x,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)(nh.A,{className:B("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[y("global",en.A,e("common.global"),b),d&&y("workspace",X.A,e("common.workspace"),j),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)(sc.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 sv=r(67889),sb=r(79773),sj=r(73743),sy=r(4196);function sw(e){let{value:t,disabled:r,presets:n,placeholder:a,onCommit:o,minWidth:i=240,className:c}=e,[d,u]=(0,l.useState)(t),[m,x]=(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)(()=>{m&&(h(""),g(0),setTimeout(()=>{var e;return null==(e=b.current)?void 0:e.focus()},0))},[m]);let j=(0,l.useMemo)(()=>{if(!p)return n;let e=p.toLowerCase();return n.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))},[p,n]);function y(e){u(e),x(!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(m)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){v.current&&!v.current.contains(e.target)&&x(!1)}},[m]),(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:()=>x(!0),onChange:e=>u(e.target.value),onBlur:()=>{setTimeout(()=>{m||w()},120)},onKeyDown:e=>{"ArrowDown"!==e.key||m?"Enter"===e.key?(e.preventDefault(),w()):"Escape"===e.key&&x(!1):(e.preventDefault(),x(!0))},placeholder:a,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:"▾"}),m&&(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&&x(!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 sN={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 sk(e,t){var r,n,a,s,l,o,i,c,d,u;let m=null==e?void 0:e.capabilities,x={},p=null==m?void 0:m.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))x.thinking=void 0;else if("manual"===e){let e=null==h?void 0:h.budget_tokens;x.thinking={enabled:!0,budget_tokens:null!=(n=null!=e?e:null==p?void 0:p.defaultBudgetTokens)?n: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)),n=null!=(o=null!=(l=null==p?void 0:p.default)?l:null==e||null==(a=e[0])?void 0:a.value)?o:"medium";x.thinking={enabled:!0,effort:r?t:n}}}let f=null==m?void 0:m.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)?x.promptCaching=r:r?x.promptCaching=null!=(i=null==f?void 0:f.default)?i:g[0].value:x.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 x.promptCaching=void 0;let v=null==m?void 0:m.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)?x.verbosity=j:x.verbosity=null!=(u=null==v?void 0:v.default)?u:void 0:x.verbosity=void 0,x}let sS="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)]",sC="text-[11px] font-medium text-[var(--foreground)]",sA="text-[10px] text-[var(--muted-foreground)]";function sI(e){let{label:t,enabled:r,value:n,defaultValue:a,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?n||a: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:sC,children:t})]}),r&&(0,s.jsx)(sw,{value:n||a,presets:l.map(e=>({id:e.value,label:e.label})),onCommit:e=>o(e||void 0),minWidth:110,className:"h-7"})]})}function sE(e){var t,r,n,a,l,o,i,c,d,u,m,x;let{data:p,availableSkills:h,availableTools:f,allAgents:g,selfId:v,modelsRegistry:b,onUpdate:j,onUpdateNested:y,onToggleArrayItem:w}=e,N=(0,eV.kj)(),k=null!=(n=p.model)?n:{},S=null!=(a=p.context)?a:{},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:""),M=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:sC,children:N("agent.name")}),(0,s.jsx)("input",{value:String(null!=(i=p.name)?i:""),onChange:e=>j("name",e.target.value),className:B(sS,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:sC,children:N("agent.description")}),(0,s.jsx)("input",{value:String(null!=(c=p.description)?c:""),onChange:e=>j("description",e.target.value),className:B(sS,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:sC,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:B(sS,"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:sC,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,n,a,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!=(n=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)?n:null==l?void 0:l.models[0];j("model",{...k,provider:e.target.value,id:null!=(a=null==c?void 0:c.id)?a:"",endpoint:null!=(s=null==l?void 0:l.defaultEndpoint)?s:"",...sk(c,k)})},className:B("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!=(m=k.provider)?m:""),onChange:e=>y("model","provider",e.target.value),className:B(sS,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:sC,children:N("agent.modelId")}),(()=>{var e,t,r,n,a;let l=String(null!=(n=k.provider)?n:null!=(r=null==b||null==(e=b.providers[0])?void 0:e.id)?r:""),o=null!=(a=null==b||null==(t=b.providers.find(e=>e.id===l))?void 0:t.models)?a:[];return(0,s.jsx)(sw,{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,...sk(t,k)})})(e),className:"mt-1"})})()]}),(()=>{var e,t,r,n,a;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!=(n=null==o?void 0:o.defaultEndpoint)?n:"",c=null==o?void 0:o.endpointPresets;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:sC,children:N("agent.endpoint")}),(0,s.jsx)(sw,{value:String(null!=(a=k.endpoint)?a:""),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:B(sA,"mt-0.5"),children:["Default: ",i]})]})})(),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:sC,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:B(sS,"mt-1"),placeholder:(null==M?void 0:M.maxOutputTokens)?String(M.maxOutputTokens):"auto"}),(0,s.jsx)("p",{className:B(sA,"mt-0.5"),children:(null==M?void 0:M.maxOutputTokens)?N("agent.maxTokensDefault",{max:M.maxOutputTokens.toLocaleString()}):N("agent.maxTokensAuto")})]})]}),(()=>{var e,t,r,n,a,l,o,i;let c=null!=(l=null==M?void 0:M.capabilities)?l:T?sN: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)(sI,{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==(a=c.verbosity)||null==(n=a.presets)?void 0:n.length)&&(0,s.jsx)(sI,{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=!M&&""!==T,t=k.image,r=k.video,n=k.audio;if(e){let e=e=>{let{field:t,label:r,value:n}=e;return(0,s.jsx)("button",{type:"button",onClick:()=>y("model",t,!n||void 0),className:B("rounded px-2 py-0.5 text-[10px] font-medium transition-colors cursor-pointer",n?"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:n})]})}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:B("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:B("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:B("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,n,a,l,o,i,d;let m=k.thinking,x=!!(null==m?void 0:m.enabled),p=!M&&""!==T,h=null!=(n=null==(e=c.thinking)?void 0:e.mode)?n:"adaptive",f=p?(null==m?void 0:m.budget_tokens)!=null?"manual":"adaptive":h,g=null!=(l=null!=(a=null==(t=c.thinking)?void 0:t.default)?a: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:x,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:sC,children:"Thinking"})]}),x&&"adaptive"===f&&u&&(0,s.jsx)(sw,{value:null!=(i=null!=(o=null==m?void 0:m.effort)?o:null==m?void 0:m.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"}),x&&"manual"===f&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:sA,children:"budget"}),(0,s.jsx)("input",{type:"number",min:1024,step:1024,value:null!=(d=null==m?void 0:m.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:sA,children:"tokens"})]}),x&&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:sC,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:B(sS,"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!=(x=p.system_prompt)?x:""),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:B("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:sA,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"]),n=A.filter(e=>!t.has(e)&&!r.has(e)),a=k.image,l=null!=a?a:null==M||null==(e=M.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,n=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:n,onClick:()=>w("tools",e.name),className:B("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)}),n.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:sA,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:B("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 sT(e){return"".concat(e.id,":").concat(e.scope)}let sM="halo_agents_selectedKey",sF="halo_agents_expandedScopes";function sD(){try{let e=localStorage.getItem(sF);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}function sP(){var e,t;let r=(0,eV.kj)(),n=tq(e=>e.activeProject),a=null!=(e=null==n?void 0:n.path)?e:void 0,[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(()=>localStorage.getItem(sM)),[m,x]=(0,l.useState)(sD),{skills:p,setSkills:h}=sf(),[f,g]=(0,l.useState)(null),[v,b]=(0,l.useState)(!1);(0,l.useEffect)(()=>{d?localStorage.setItem(sM,d):localStorage.removeItem(sM)},[d]),(0,l.useEffect)(()=>{localStorage.setItem(sF,JSON.stringify([...m]))},[m]);let j=n5(e=>e.version);(0,l.useEffect)(()=>{N.F.agentConfigs.models().then(g).catch(()=>{})},[j]);let y=(0,l.useCallback)(async()=>{b(!0);try{let e=await N.F.agentConfigs.list(a);c(e.agents),!d&&e.agents.length>0&&u(sT(e.agents[0]))}catch(e){console.error("[AgentManagement] Load failed:",e)}finally{b(!1)}},[a,d]),w=a_(e=>e.version);(0,l.useEffect)(()=>{y()},[y,w]),(0,l.useEffect)(()=>{if(!a)return;let e=S.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/agents/")&&az()}),t=C(S,az);return()=>{e(),t()}},[a]),(0,l.useEffect)(()=>{let e=()=>az();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),(0,l.useEffect)(()=>{p.length>0||N.F.skills.list(null==n?void 0:n.path).then(e=>{h(e.skills)}).catch(()=>{})},[null==n?void 0:n.path,p.length,h]);let k=null!=(t=o.find(e=>sT(e)===d))?t:null;async function A(e){var t;if("workspace"===e&&!a)return;let r=await K("Agent name:");if(!(null==r?void 0:r.trim()))return;let n=null!=(t=await K("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 G(t))return}try{let t=(await N.F.agentConfigs.create({name:r.trim(),description:n.trim(),scope:e,projectId:"workspace"===e?a:void 0})).agent;c(r=>[..."workspace"===e?r.map(e=>e.id===t.id&&"global"===e.scope?{...e,overridden:!0}:e):r,t]),x(t=>new Set(t).add(e)),u(sT(t)),az()}catch(e){console.error("[AgentManagement] Create failed:",e)}}async function I(e){if(await G('Delete agent "'.concat(e.name,'"?')))try{await N.F.agentConfigs.remove(e.id,{scope:e.scope,projectId:a}),c(t=>{let r=t.filter(t=>sT(t)!==sT(e));return"workspace"===e.scope?r.map(t=>t.id===e.id&&"global"===t.scope?{...t,overridden:!1}:t):r}),d===sT(e)&&u(null),az()}catch(e){console.error("[AgentManagement] Delete failed:",e)}}async function E(e){try{let{disabled:t}=await N.F.agentConfigs.toggle(e.id,{scope:e.scope,projectId:a});c(r=>r.map(r=>sT(r)===sT(e)?{...r,disabled:t}:r)),az()}catch(e){console.error("[AgentManagement] Toggle failed:",e)}}let T=o.filter(e=>e.internal),M=o.filter(e=>"global"===e.scope&&!e.internal),F=o.filter(e=>"workspace"===e.scope&&!e.internal),D=(()=>{let e=new Map;for(let t of[...M,...F])t.overridden||t.disabled||e.set(t.id,{id:t.id,name:t.name});return[...e.values()]})(),P=function(e,t,r,n){let l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{allowCreate:!0},o=m.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)(Q.A,{className:B("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:n.length})]}),l.allowCreate&&"internal"!==e&&(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),A(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)(aC.A,{className:"h-3 w-3"})})]}),o&&n.map(t=>{let r=sT(t);return(0,s.jsxs)("div",{className:B("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)(np.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&&a&&(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),E(t)},title:t.disabled?"Enable (show in roster)":"Disable (hide from roster)",className:B("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)(sd.A,{className:"h-4.5 w-4.5"}):(0,s.jsx)(su.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)(sv.A,{className:"h-3 w-3 shrink-0 text-amber-500"})}):(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),I(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)(eP.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:()=>y(),disabled:v,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)(nh.A,{className:B("h-3.5 w-3.5",v&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[P("global",en.A,r("common.global"),M),a&&P("workspace",X.A,r("common.workspace"),F),T.length>0&&P("internal",sb.A,r("common.internal"),T,{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)(sL,{agent:k,allAgents:D,modelsRegistry:f,onSaved:e=>{c(t=>t.map(t=>sT(t)===sT(e)?e:t))}},sT(k)):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center",children:[(0,s.jsx)(np.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 sL(e){let{agent:t,allAgents:n,modelsRegistry:a,onSaved:o}=e,i=(0,eV.kj)(),{skills:c}=sf(),d=tq(e=>e.activeProject),[u,m]=(0,l.useState)({}),x="halo_agent_view:".concat(sT(t)),[p,h]=(0,l.useState)(()=>{var e;return null!=(e=localStorage.getItem(x))?e:"form"}),f=(0,l.useCallback)(e=>{localStorage.setItem(x,e),h(e)},[x]),[g,v]=(0,l.useState)(!0),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[S,C]=(0,l.useState)([]),[A,I]=(0,l.useState)("");(0,l.useEffect)(()=>{N.F.agentConfigs.tools().then(e=>C(e.tools)).catch(()=>{})},[]);let E=(0,l.useRef)(o);(0,l.useEffect)(()=>{E.current=o});let T=(0,l.useRef)(null),M=(0,l.useCallback)(async()=>{v(!0),j(null);let e="workspace"===t.scope?null==d?void 0:d.path:void 0;try{let n=await N.F.agentConfigs.getYaml(t.id,{scope:t.scope,projectId:e}),{parse:a,stringify:s}=await r.e(510).then(r.bind(r,5510)),l=null,o=!1;try{l=a(n.yaml)}catch(e){o=!0}if(o||null!==l&&("object"!=typeof l||Array.isArray(l)))j("agent.yamlInvalid");else{let e=null!=l?l:{};m(e),T.current=s(e,{lineWidth:120})}}catch(e){console.error("[AgentEditor] Load YAML failed:",e),j("agent.loadFailed"),m({}),T.current=null}try{var n,a;let r=await N.F.agentConfigs.getMdAll(t.id,{scope:t.scope,projectId:e});I(null!=(a=null==(n=r.files["AGENT.md"])?void 0:n.content)?a:"")}catch(e){I("")}v(!1)},[t.id,t.scope,null==d?void 0:d.path]);(0,l.useEffect)(()=>{M()},[M]);let F=(0,l.useRef)(p);return(0,l.useEffect)(()=>{"edit"===F.current&&"form"===p&&M(),F.current=p},[p,M]),(0,l.useEffect)(()=>{if(g||b)return;let e=setTimeout(async()=>{try{let{stringify:e}=await r.e(510).then(r.bind(r,5510)),n=e(u,{lineWidth:120});if(T.current===n)return;k(!0);let a="workspace"===t.scope?null==d?void 0:d.path:void 0,s=await N.F.agentConfigs.saveYaml(t.id,n,{scope:t.scope,projectId:a});T.current=n,E.current(s.agent)}catch(e){console.error("[AgentEditor] Auto-save failed:",e)}finally{k(!1)}},500);return()=>clearTimeout(e)},[u,t.id,t.scope,null==d?void 0:d.path,g,b]),(0,l.useEffect)(()=>{T.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:()=>f("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)(sj.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:()=>{rY(t.id),window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}}))},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)(sy.A,{className:"h-3 w-3"}),i("agent.test")]}),"form"===p&&(0,s.jsxs)("button",{onClick:()=>f("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)(eU.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)(y,{children:(0,s.jsx)(t0,{projectId:t.path,mode:"full",showMaximize:!1})},"".concat(t.id,":").concat(t.scope)):g?(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:i("agent.loading")}):b?(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-sm text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{children:i(b)}),(0,s.jsxs)("button",{onClick:()=>M(),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)(nh.A,{className:"h-3 w-3"}),i("agent.retry")]})]}):(0,s.jsxs)("div",{className:"h-full overflow-y-auto",children:[(0,s.jsx)(sE,{data:u,availableSkills:c,availableTools:S,allAgents:n,selfId:t.id,modelsRegistry:a,onUpdate:function(e,t){m(r=>({...r,[e]:t}))},onUpdateNested:function(e,t,r){m(n=>{var a;let s=null!=(a=n[e])?a:{};return{...n,[e]:{...s,[t]:r}}})},onToggleArrayItem:function(e,t){m(r=>{let n=Array.isArray(r[e])?[...r[e]]:[],a=n.indexOf(t);return a>=0?n.splice(a,1):n.push(t),{...r,[e]:n}})}}),A.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)(eQ,{content:A})]})]})})]})}function sR(){var e;let{skills:t,selectedKey:r}=sf(),n=null!=(e=t.find(e=>"".concat(e.id,":").concat(e.scope)===r))?e:null;return n?(0,s.jsx)(y,{children:(0,s.jsx)(t0,{projectId:n.path,mode:"full",showMaximize:!1})},"".concat(n.id,":").concat(n.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)(sc.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 s_=r(99603);let sz=[],sO=()=>()=>{};function sU(e){var t;let{visible:r}=e,n=(0,eV.kj)(),a=ng(e=>e.selectedSessionId),o=ng(e=>e.selectedSession),i=ng(e=>e.loadedMessages),c=ng(e=>e.loading),d=r_(e=>nl(e.tabs,a)),u=null==d?void 0:d.store,m=void 0!==u,x=u&&r?u.subscribe:sO,p=()=>{var e;return null!=(e=null==u?void 0:u.getState().messages)?e:sz},h=(0,l.useSyncExternalStore)(x,p,p),f=()=>{var e;return null!=(e=null==u?void 0:u.getState().isStreaming)&&e},g=(0,l.useSyncExternalStore)(x,f,f),v=(0,l.useRef)(null),[b,j]=(0,l.useState)(!1),[y,w]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_debug")),[k,A]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_prompt"));(0,l.useEffect)(()=>{localStorage.setItem("halo_session_debug",y?"1":"0")},[y]),(0,l.useEffect)(()=>{localStorage.setItem("halo_session_prompt",k?"1":"0")},[k]),(0,l.useEffect)(()=>{r7=a;let e=a?r9.get(a):void 0;a&&e&&(r9.delete(a),r9.set(a,e))},[a]),(0,l.useEffect)(()=>{ne=r},[r]);let I=ng(e=>e.setLoadedMessages),E=(0,l.useRef)(new Map),T=(0,l.useCallback)(e=>{let t=E.current;if(t.has(e))return void t.set(e,!0);let r=()=>{var n;let a=null==(n=tq.getState().activeProject)?void 0:n.path;a&&(t.set(e,!1),nn(e,!1),N.F.sessionLogs.get(e,a).then(t=>{var r,n,a;let s="number"==typeof t.archiveCount?t.archiveCount:0,l=null!=(n=t.messages)?n:[],o=ng.getState(),i=o.selectedSessionId===e,c=function(e,t){if(!e||0===e.length)return t;let r=Math.min(e.length,t.length),n=Math.max(0,e.length-2),a=t.length>=e.length;for(let r=0;a&&r<n;r++)(e[r].id!==t[r].id||e[r].deleted!==t[r].deleted)&&(a=!1);if(a){let a=e.length===t.length,s=t.slice();for(let t=0;t<n;t++)s[t]=e[t];for(let l=n;l<r;l++)JSON.stringify(e[l])===JSON.stringify(t[l])?s[l]=e[l]:a=!1;return a?e:s}let s=e.length===t.length,l=t.map((t,r)=>{let n=e[r];return n&&JSON.stringify(n)===JSON.stringify(t)?n:(s=!1,t)});return s?e:l}(null!=(a=null==(r=nt(e))?void 0:r.messages)?a:null,l);nr(e,c,s),i&&(r8(e,s),c!==o.loadedMessages&&I(c))}).catch(()=>nn(e,!0)).finally(()=>{let n=t.get(e);t.delete(e),n&&(nn(e,!0),ng.getState().selectedSessionId===e&&r())}))};r()},[I]);(0,l.useEffect)(()=>{let e=e=>{e&&!nl(r_.getState().tabs,e)&&T(e)},t=S.on("file:changed",t=>e(function(e,t){if("change"!==t&&"add"!==t||!e.startsWith(".halo/sessions/")||!e.endsWith(".json"))return null;let r=e.slice(e.lastIndexOf("/")+1,-5);for(let[e,t]of r9)ns(e)===r&&(t.stale=!0);return ne&&null!==r7&&ns(r7)===r?r7:null}(t.path,t.action))),r=C(S,()=>e(function(){for(let e of r9.values())e.stale=!0;return ne?r7:null}()));return()=>{t(),r()}},[T]),(0,l.useEffect)(()=>{if(!r||!a||m)return;let e=ng.getState();if(e.loading)return;let t=nt(a);!t||t.stale?T(a):e.loadedMessages!==t.messages&&I(t.messages)},[r,a,m,T,I]);let M=(0,l.useMemo)(()=>{if(!a)return[];if(m){let e=h.filter(e=>!e.taskId);return y?e:e.filter(ro)}let e=null!=i?i:[];return y?e:e.filter(e=>!rl(e))},[a,m,h,i,y]),F=(0,l.useMemo)(()=>{for(let e of m?h:null!=i?i:[])if("context"===t1(e)&&e.systemPrompt)return e.systemPrompt;return null},[m,h,i]),D=r4(e=>e.sessionId),P=r4(e=>e.anchor),L=r4(e=>e.cursor),R=r4(e=>e.messages),_=r4(e=>e.loading),z=null!==D&&D===a,O=null!=(t=null==d?void 0:d.archiveCount)?t:0;(0,l.useEffect)(()=>{a&&m&&r8(a,O)},[a,m,O]);let U=(0,l.useMemo)(()=>z?y?R:R.filter(e=>!rl(e)):[],[z,R,y]),W=(0,l.useRef)(!0),H=(0,l.useRef)(null),K=(0,l.useRef)(!0),G=(0,l.useRef)(r),J=(0,l.useRef)(null),Z=(0,l.useRef)(null),$=(0,l.useRef)(!0),Y=(0,l.useRef)(0),V=(0,l.useCallback)(()=>{let e=r4.getState();if(e.sessionId!==a||e.cursor<1||e.loading)return;let t=v.current;H.current=t?t.scrollHeight-t.scrollTop:null,r6()},[a]);return(0,l.useLayoutEffect)(()=>{K.current=!0,H.current=null,$.current=!0,W.current=!0,Y.current=0},[a]),(0,l.useLayoutEffect)(()=>{G.current=r,$.current=!0},[r]),(0,l.useLayoutEffect)(()=>{J.current=m?null:a},[m,a]),(0,l.useLayoutEffect)(()=>{let e=v.current;if(!$.current||!r||!e||c||0===M.length)return;$.current=!1;let t=a&&!m?nt(a):void 0;if(t&&(W.current=t.atBottom,Y.current=t.scrollOffset),W.current)e.scrollTop=e.scrollHeight;else{var n,s;e.scrollTop=(null!=(s=null==(n=Z.current)?void 0:n.offsetTop)?s:0)+Y.current,e.scrollTop<80&&(K.current=!1)}},[a,r,c,M,m]),(0,l.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{var t,r;if(!G.current)return;W.current=e.scrollHeight-e.scrollTop-e.clientHeight<60,Y.current=e.scrollTop-(null!=(r=null==(t=Z.current)?void 0:t.offsetTop)?r:0);let n=J.current;n&&function(e,t,r){let n=r9.get(e);n&&(n.scrollOffset=t,n.atBottom=r)}(n,Y.current,W.current),e.scrollTop>200?K.current=!0:e.scrollTop<80&&K.current&&(K.current=!1,V())};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[V]),(0,l.useLayoutEffect)(()=>{let e=v.current,t=H.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,H.current=null)},[R]),(0,l.useEffect)(()=>{W.current&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[M]),(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)(s_.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(null==o?void 0:o.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:o.agentName}),(0,s.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",title:(null==o?void 0:o.title)||"Untitled",children:(null==o?void 0:o.title)||"Untitled"}),(0,s.jsxs)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:["(",M.length,")"]}),m&&(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==o?void 0:o.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==o?void 0:o.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==o?void 0:o.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(o.archivedAt).toLocaleString()),children:"archived"}),(null==o?void 0:o.createdAt)&&(0,s.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",title:"Created: ".concat(new Date(o.createdAt).toLocaleString()),children:q(o.createdAt)}),(0,s.jsxs)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a).then(()=>{j(!0),setTimeout(()=>j(!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:[b?(0,s.jsx)(tz.A,{className:"h-2.5 w-2.5 text-green-400"}):(0,s.jsx)(nS.A,{className:"h-2.5 w-2.5"}),a.slice(0,8)]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(np.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:[F&&(0,s.jsxs)("button",{onClick:()=>A(!k),className:B("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",k?"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)(es.A,{className:"h-3 w-3"}),"Prompt"]}),(0,s.jsxs)("button",{onClick:()=>w(!y),className:B("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",y?"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"]})]}),g&&(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:v,className:"relative flex-1 overflow-y-auto",children:[k&&F&&(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:()=>A(!1),title:"Close",className:"rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(e2.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:F})]}),c?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(ee.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):a?0===M.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)(np.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.jsxs)(s.Fragment,{children:[z&&P>0&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[L>0?(0,s.jsxs)("button",{onClick:V,disabled:_,className:"flex w-full items-center justify-center gap-1.5 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:hover:bg-transparent",children:[_&&(0,s.jsx)(ee.A,{className:"h-3 w-3 animate-spin"}),n(_?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,s.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.noEarlier")}),U.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(nE,{messages:U,debugMode:y,readOnly:!0}),(0,s.jsx)("div",{className:"border-t border-[var(--border)]/50 px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.header",{segments:P-L,messages:U.length})})]})]}),(0,s.jsx)("div",{ref:Z}),(0,s.jsx)(nE,{messages:M,debugMode:y})]}):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,s.jsx)(np.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 sB=r(37568),sW=r(28976),sH=r(29656),sK=r(3546),sG=r(23715),sq=r(85615),sJ=r(8565);function sZ(){return(0,s.jsxs)("div",{className:"space-y-8 p-6",children:[(0,s.jsx)(s$,{}),(0,s.jsx)(sY,{})]})}function s$(){let{t:e}=(0,eV.s9)(),[t,r]=(0,l.useState)(""),[n,a]=(0,l.useState)(""),[o,i]=(0,l.useState)(""),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(""),[x,p]=(0,l.useState)(!1),h=""!==n?n.length<8?"tooShort":/[A-Za-z]/.test(n)?/[0-9]/.test(n)?null:"needDigit":"needLetter":null,f=""!==n&&n===t,g=""!==o&&o!==n,v=!c&&""!==t&&""!==n&&o===n&&null===h&&!f;async function b(s){if(s.preventDefault(),v){d(!0),m(""),p(!1);try{let e=await fetch("/api/auth/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPassword:t,newPassword:n}),credentials:"include"});if(e.ok)p(!0),r(""),a(""),i("");else{let t=await e.json().catch(()=>null);m((null==t?void 0:t.error)||"HTTP ".concat(e.status))}}catch(t){m(e("security.changePassword.connectionFailed"))}finally{d(!1)}}}return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.changePassword.title")}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.changePassword.desc")})]}),(0,s.jsxs)("form",{onSubmit:b,className:"max-w-md space-y-4 rounded-md border border-[var(--border)] bg-[var(--card)] p-4",children:[(0,s.jsx)(sV,{label:e("security.changePassword.current"),value:t,disabled:c,autoComplete:"current-password",onChange:e=>{r(e),p(!1)}}),(0,s.jsx)(sV,{label:e("security.changePassword.new"),value:n,disabled:c,autoComplete:"new-password",onChange:e=>{a(e),p(!1)},error:h?e("security.changePassword.".concat(h)):f?e("security.changePassword.sameAsOld"):void 0,hint:e("security.changePassword.rule")}),(0,s.jsx)(sV,{label:e("security.changePassword.confirm"),value:o,disabled:c,autoComplete:"new-password",onChange:e=>{i(e),p(!1)},error:g?e("security.changePassword.mismatch"):void 0}),u&&(0,s.jsx)("p",{className:"text-[11px] text-red-400",children:u}),x&&(0,s.jsx)("p",{className:"text-[11px] text-emerald-400",children:e("security.changePassword.success")}),(0,s.jsx)("button",{type:"submit",disabled:!v,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90 disabled:opacity-50",children:c?e("security.changePassword.submitting"):e("security.changePassword.submit")})]})]})}function sY(){let{t:e}=(0,eV.s9)(),[t,r]=(0,l.useState)(!1);async function n(){r(!0);try{await fetch("/api/auth/logout",{method:"POST",credentials:"include"})}catch(e){}window.location.reload()}return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.logout")}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.logout.desc")})]}),(0,s.jsxs)("button",{onClick:n,disabled:t,className:"flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--card)] px-3 py-1.5 text-xs font-medium text-red-400 transition-colors hover:bg-[var(--secondary)] disabled:opacity-50",children:[(0,s.jsx)(sJ.A,{className:"h-3.5 w-3.5"}),e("security.logout")]})]})}function sV(e){let{label:t,value:r,disabled:n,autoComplete:a,onChange:l,error:o,hint:i}=e;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:t}),(0,s.jsx)("input",{type:"password",value:r,autoComplete:a,disabled:n,onChange:e=>l(e.target.value),className:B("mt-1 h-7 w-full rounded border bg-[var(--background)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]",o?"border-red-400/60":"border-[var(--border)]")}),o?(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-red-400",children:o}):i?(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:i}):null]})}function sQ(){let{t:e}=(0,eV.s9)(),t=(0,l.useSyncExternalStore)(to,tp,tp),r=(0,l.useRef)(null),[n,a]=(0,l.useState)(!1),[o,i]=(0,l.useState)(null);async function c(e){a(!0),i(null);try{await N.F.extensions.install(e)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}}async function d(t,r){if(await G(e("settings.extensions.confirmRemove",{name:r}))){a(!0),i(null);try{await N.F.extensions.remove(t)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}}}let u=0===t.extensions.length&&0===t.errors.length;return(0,s.jsxs)("div",{className:"space-y-6 p-6",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("settings.extensions.title")}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("settings.extensions.intro")})]}),(0,s.jsx)("input",{ref:r,type:"file",accept:".zip,application/zip",className:"hidden",onChange:e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];e.target.value="",r&&c(r)}}),(0,s.jsxs)("button",{onClick:()=>{var e;return null==(e=r.current)?void 0:e.click()},disabled:n,className:"flex shrink-0 items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90 disabled:opacity-50",children:[(0,s.jsx)(sa.A,{className:"h-3.5 w-3.5"}),n?e("settings.extensions.working"):e("settings.extensions.upload")]})]}),o&&(0,s.jsx)("p",{className:"text-[11px] text-red-400",children:o}),u?(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:e("settings.extensions.empty")}):(0,s.jsxs)("ul",{className:"divide-y divide-[var(--border)] rounded border border-[var(--border)]",children:[t.extensions.map(t=>(0,s.jsxs)("li",{className:"flex items-center gap-3 px-3 py-2",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,s.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",children:t.name}),(0,s.jsxs)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:[t.id,"@",t.version]})]}),(0,s.jsxs)("p",{className:"mt-0.5 truncate text-[10px] text-[var(--muted-foreground)]",children:[t.extensions.join(" "),"option"===t.priority&&" \xb7 ".concat(e("settings.extensions.optionOnly")),t.capabilities.includes("save")&&" \xb7 ".concat(e("settings.extensions.canSave")),t.description&&" — ".concat(t.description)]})]}),(0,s.jsx)(sX,{disabled:n,onClick:()=>d(t.id,t.name),label:e("settings.extensions.remove")})]},t.id)),t.errors.map(t=>(0,s.jsxs)("li",{className:"flex items-center gap-3 px-3 py-2",children:[(0,s.jsx)(nC.A,{className:"h-3.5 w-3.5 shrink-0 text-red-400"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("code",{className:"text-xs text-red-400",children:t.id}),(0,s.jsx)("p",{className:"mt-0.5 truncate text-[10px] text-[var(--muted-foreground)]",children:t.error})]}),(0,s.jsx)(sX,{disabled:n,onClick:()=>d(t.id,t.id),label:e("settings.extensions.remove")})]},t.id))]})]})}function sX(e){let{disabled:t,onClick:r,label:n}=e;return(0,s.jsxs)("button",{onClick:r,disabled:t,className:"flex shrink-0 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 disabled:opacity-50",children:[(0,s.jsx)(eP.A,{className:"h-3 w-3"}),n]})}function s0(){var e,t,r;let{t:n,refreshFromServer:a}=(0,eV.s9)(),{refreshFromServer:o}=(0,eW.useTheme)(),i=tq(e=>e.activeProject),[c,d]=(0,l.useState)("global"),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)("general"),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[y,w]=(0,l.useState)([]),k="workspace"===c?null==i?void 0:i.path:void 0,S=(0,l.useCallback)(()=>{v(!0),N.F.settings.getSchema(k).then(e=>{m(e),p(t=>"__orphans"===t||"__security"===t||"__extensions"===t||e.sections.find(e=>e.namespaceId===t)?t:"general")}).catch(e=>{console.error("[Settings] schema load failed:",e)}).finally(()=>v(!1))},[k]),C=n5(e=>e.version);function A(e,t){e.restartRequired&&w(e=>e.includes(t)?e:[...e,t])}async function I(e,t,r){f(!0);try{let n="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);if(""===r)await N.F.settings.remove(c,n,k);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 N.F.settings.patch(c,n,e,k)}A(t,n),S(),a(),o()}catch(e){console.error("[Settings] save failed:",e)}finally{f(!1)}}async function E(e,t){f(!0);try{let r="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);await N.F.settings.remove(c,r,k),A(t,r),S(),a(),o()}catch(e){console.error("[Settings] reset failed:",e)}finally{f(!1)}}async function T(e){let t="".concat(e.namespaceId,".").concat(e.kind,"s.").concat(e.key);if(confirm(n("settings.orphans.confirm",{key:t}))){f(!0);try{await N.F.settings.remove(c,t,k),S()}catch(e){console.error("[Settings] orphan remove failed:",e)}finally{f(!1)}}}(0,l.useEffect)(()=>{S()},[S,C]),(0,l.useEffect)(()=>{N.F.health().then(e=>j("string"==typeof(null==e?void 0:e.version)?e.version:null)).catch(()=>j(null))},[]);let M=null!=(e=null==u?void 0:u.sections)?e:[],F=null!=(t=null==u?void 0:u.orphans)?t:[],D=(0,l.useMemo)(()=>M.find(e=>e.namespaceId===x),[M,x]);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)(sB.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:n("nav.settings")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:S,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)(nh.A,{className:B("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:B("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)(en.A,{className:"h-3 w-3"}),n("common.global")]}),(0,s.jsxs)("button",{onClick:()=>d("workspace"),disabled:!i,className:B("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)(sW.A,{className:"h-3 w-3"}),n("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)(s1,{sections:M,orphans:F,active:x,onPick:p})]}),b&&(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",b]})]}),(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.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"__security"===x?(0,s.jsxs)(s.Fragment,{children:["~/.halo/secrets/config.yaml → ",(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:"server.password"})]}):"__extensions"===x?(0,s.jsx)(s.Fragment,{children:"~/.halo/global/extensions/"}):(0,s.jsxs)(s.Fragment,{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:x})]})})}),y.length>0&&(0,s.jsxs)("div",{className:"flex shrink-0 items-start gap-2 border-b border-amber-500/30 bg-amber-500/10 px-4 py-2 text-[11px] text-amber-400",children:[(0,s.jsx)(nC.A,{className:"mt-px h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 break-words",children:n("settings.restartNotice",{keys:y.join(", ")})}),(0,s.jsx)("button",{onClick:()=>w([]),title:n("settings.restartNotice.dismiss"),className:"shrink-0 cursor-pointer rounded p-0.5 hover:bg-amber-500/20",children:(0,s.jsx)(e2.A,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:"__security"===x?(0,s.jsx)(sZ,{}):"__extensions"===x?(0,s.jsx)(sQ,{}):"__orphans"===x?(0,s.jsx)(lt,{orphans:F,onRemove:T,saving:h}):D?(0,s.jsx)(s5,{section:D,scope:c,saving:h,onSave:(e,t)=>I(D.namespaceId,e,t),onReset:e=>E(D.namespaceId,e)}):(0,s.jsx)("div",{className:"p-10 text-center text-xs text-[var(--muted-foreground)]",children:u?n("settings.empty"):n("settings.loading")})})]})]})}function s1(e){let{sections:t,orphans:r,active:n,onPick:a}=e,{t:o}=(0,eV.s9)(),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)(s3,{label:o("settings.nav.system"),items:i.general,active:n,onPick:a}),(0,s.jsxs)("button",{onClick:()=>a("__security"),className:B("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__security"===n?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(sH.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:o("settings.nav.security")})]}),(0,s.jsxs)("button",{onClick:()=>a("__extensions"),className:B("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__extensions"===n?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(sK.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:o("settings.nav.extensions")})]}),(0,s.jsx)(s3,{label:o("settings.nav.providers"),items:i.providers,active:n,onPick:a}),(0,s.jsx)(s3,{label:o("settings.nav.agents"),items:i.agents,active:n,onPick:a}),(0,s.jsx)(s3,{label:o("settings.nav.skills"),items:i.skills,active:n,onPick:a}),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:()=>a("__orphans"),className:B("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__orphans"===n?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(eP.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 s3(e){let{label:t,items:r,active:n,onPick:a}=e,{lang:l}=(0,eV.s9)();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:()=>a(e.namespaceId),className:B("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors",n===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 s5(e){let{section:t,scope:r,saving:n,onSave:a,onReset:o}=e,{t:i,lang:c}=(0,eV.s9)(),[d,u]=(0,l.useState)(!1),m=t.fields.filter(e=>"param"===e.kind),x=m.filter(e=>!e.advanced),p=m.filter(e=>e.advanced),h=t.fields.filter(e=>"secret"===e.kind),f=e=>(0,s.jsx)(s2,{namespaceId:t.namespaceId,field:e,scope:r,saving:n,onSave:t=>a(e,t),onReset:()=>o(e)},e.key),g="zh"===c&&t.displayName_zh||t.displayName,v="zh"===c&&t.description_zh||t.description,[b,j]=i("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:g}),v&&(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:v}),(0,s.jsxs)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:[i("settings.section.namespace"),": ",(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:t.namespaceId})," \xb7 ",i("settings.section.declaredBy"),": ",(0,s.jsx)("span",{children:i("settings.section.declaredBy.".concat(t.source))})]})]}),m.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:i("general"===t.namespaceId?"settings.section.settings":"settings.section.params")}),x.map(f),p.length>0&&(0,s.jsxs)("div",{className:"space-y-4 border-t border-[var(--border)] pt-3",children:[(0,s.jsxs)("button",{onClick:()=>u(e=>!e),className:"flex cursor-pointer items-center gap-1 text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[(0,s.jsx)(Q.A,{className:B("h-3 w-3 transition-transform",d&&"rotate-90")}),i("settings.section.advanced"),(0,s.jsx)("span",{className:"rounded bg-[var(--card)] px-1 py-0 text-[9px] font-normal normal-case",children:p.length})]}),d&&p.map(f)]})]}),h.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:i("settings.section.secrets")}),(0,s.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[b,(0,s.jsx)("code",{className:"rounded bg-[var(--card)] px-1 py-0.5",children:"<<ENV_NAME>>"}),j]}),h.map(f)]})]})}function s2(e){var t,r;let{namespaceId:n,field:a,scope:l,saving:o,onSave:i,onReset:c}=e,{lang:d,t:u}=(0,eV.s9)(),m="zh"===d&&a.description_zh||a.description||"",x="general"===n?"general.".concat(a.key):"".concat(n,".").concat(a.kind,"s.").concat(a.key),p="workspace"===l&&a.inheritedFromGlobal,h="workspace"===l&&!0===a.globalOnly,f=!h&&a.source===l&&("workspace"===l||(null!=(t=a.value)?t:"")!==(null!=(r=a.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:a.key}),(0,s.jsx)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:x}),(0,s.jsx)(s4,{source:a.source,inherited:p}),a.globalOnly&&(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-px text-[10px] uppercase text-[var(--muted-foreground)]",title:u("settings.globalOnlyHint"),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)(sG.A,{className:"h-2.5 w-2.5"}),u("settings.field.reset")]})]}),m&&(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:m}),(0,s.jsx)("div",{className:B("mt-1.5",h&&"opacity-60 pointer-events-none"),children:function(e,t,r){var n,a,l,o,i,c,d,u;if(e.secret)return(0,s.jsx)(le,{initial:null!=(n=e.value)?n:"",placeholder:null!=(a=e.default)?a:"",saving:t,onCommit:r});switch(e.type){case"int":case"float":return(0,s.jsx)(s6,{initial:null!=(l=e.value)?l:"",placeholder:null!=(o=e.default)?o:"",type:"number",step:"int"===e.type?1:.1,saving:t,onCommit:r});case"boolean":return(0,s.jsx)(s9,{value:e.value,saving:t,onCommit:r});case"enum":return(0,s.jsx)(s7,{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)(s6,{initial:null!=(d=e.value)?d:"",placeholder:null!=(u=e.default)?u:"",saving:t,onCommit:r})}}(a,o||h,i)})]})}function s4(e){let{source:t,inherited:r}=e,{t:n}=(0,eV.s9)();return(0,s.jsx)("span",{className:B("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:n("unset"===t?"settings.source.unset":r?"settings.source.inherited":"settings.source.".concat(t))})}let s8=/^<<[A-Z_][A-Z0-9_]*>>$/;function s6(e){let{initial:t,placeholder:r,type:n="text",step:a,saving:o,onCommit:i}=e,c=""===t&&!!r,[d,u]=(0,l.useState)(t),[m,x]=(0,l.useState)(!1),p=(0,l.useRef)(t);function h(){x(!1),d!==p.current&&(p.current=d,i(d))}(0,l.useEffect)(()=>{u(t),p.current=t,x(!1)},[t]);let f=c&&!m?null!=r?r:"":d;return(0,s.jsx)("input",{type:n,step:a,value:f,placeholder:r,onFocus:()=>{c&&u(""),x(!0)},onChange:e=>{u(e.target.value),x(!0)},onBlur:h,onKeyDown:e=>{"Enter"===e.key&&h()},disabled:o,className:B("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)]",c&&!m?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function s9(e){let{value:t,saving:r,onCommit:n}=e,a="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:a,disabled:r,onChange:e=>n(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:a?"on":"off"})]})}function s7(e){var t,r;let{value:n,options:a,optionLabels:l,placeholder:o,saving:i,onCommit:c}=e,d=null!=(r=null!=(t=null!=n?n:o)?t:a[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:a.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 le(e){let{initial:t,placeholder:r,saving:n,onCommit:a}=e,o=s8.test(t),[i,c]=(0,l.useState)(t),[d,u]=(0,l.useState)(!1),[m,x]=(0,l.useState)(o),p=(0,l.useRef)(t);function h(){if(d){if(i===p.current)return void u(!1);p.current=i,a(i),u(!1)}}return(0,l.useEffect)(()=>{c(t),p.current=t,u(!1),x(s8.test(t))},[t]),(0,s.jsxs)("div",{className:"relative w-full max-w-md",children:[(0,s.jsx)("input",{type:m||d?"text":"password",value:d?i:t||"",placeholder:r,onFocus:()=>{d||!t||s8.test(t)||c(""),u(!0)},onChange:e=>c(e.target.value),onBlur:h,onKeyDown:e=>{"Enter"===e.key&&h()},disabled:n,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:()=>x(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:m?(0,s.jsx)(sq.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(e4.A,{className:"h-3.5 w-3.5"})})]})}function lt(e){let{orphans:t,onRemove:r,saving:n}=e,{t:a}=(0,eV.s9)(),o=(0,l.useMemo)(()=>{let e=new Map;for(let n of t){var r;let t=null!=(r=e.get(n.namespaceId))?r:[];t.push(n),e.set(n.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:a("settings.orphans.title")}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:a("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:n,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)(eP.A,{className:"h-3 w-3"}),a("settings.orphans.remove")]})]},"".concat(e.kind,".").concat(e.key)))})]},t)})]})}var lr=r(84064);let ln=no(),la=ln.useBus,ls=ln.bump;var ll=r(89918),lo=r(27269),li=r(78547),lc=r(45211),ld=r(35622);function lu(e,t){return B(e?"mt-0.5":"mt-1","w-full rounded border border-[var(--border)] bg-[var(--card)] px-2",e?"py-1":"py-1.5",t&&"font-mono","text-xs")}function lm(e){return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:B(e.compact?"text-[10px]":"text-[11px]","text-[var(--muted-foreground)]"),children:e.label}),e.children,e.hint&&(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:e.hint})]})}function lx(e){return(0,s.jsx)("input",{type:e.type,value:e.value,onChange:t=>e.onChange(t.target.value),className:lu(e.compact,e.mono),placeholder:e.placeholder})}function lp(e){let t=(0,eV.kj)(),{ns:r}=e;return(0,s.jsxs)("select",{value:e.value,onChange:t=>e.onChange(t.target.value),className:lu(e.compact),children:[(0,s.jsx)("option",{value:"readonly",children:t("".concat(r,".readonly"))}),e.observer?(0,s.jsx)("option",{value:"observer",children:t("".concat(r,".observer"))}):"observer"===e.value&&(0,s.jsx)("option",{value:"observer",disabled:!0,children:t("channels.observerAdminOnly")}),(0,s.jsx)("option",{value:"workspace",children:t("".concat(r,".wsWrite"))}),(0,s.jsx)("option",{value:"full",children:t("".concat(r,".full"))})]})}function lh(e){return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:e.onClose,children:(0,s.jsxs)("div",{className:B(e.width,"max-h-[90vh] overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl"),onClick:e=>e.stopPropagation(),children:[e.title&&(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:e.title}),(0,s.jsx)("button",{onClick:e.onClose,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(e2.A,{className:"h-4 w-4"})})]}),e.children]})})}function lf(e){let t=(0,eV.kj)(),{ns:r,value:n,onChange:a}=e;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(lm,{label:t("".concat(r,".bindWorkspace")),hint:e.workspaceHint,children:(0,s.jsx)(lx,{mono:!0,value:n.workspacePath,onChange:e=>a({workspacePath:e}),placeholder:"/home/user/project"})}),(0,s.jsx)(lm,{label:t("".concat(r,".nameOptional")),children:(0,s.jsx)(lx,{value:n.label,onChange:e=>a({label:e}),placeholder:t("".concat(r,".namePlaceholder"))})}),(0,s.jsx)(lm,{label:t("".concat(r,".accessLevel")),hint:e.accessHint,children:(0,s.jsx)(lp,{ns:r,value:n.accessLevel,onChange:e=>a({accessLevel:e}),observer:e.observer})}),(0,s.jsx)(eV.pZ,{value:n.language,onChange:e=>a({language:e})})]})}function lg(e){let t=(0,eV.kj)(),{lang:r}=(0,eV.s9)(),{ns:n,onClose:a,canSubmit:o=!0}=e,i=tq(e=>e.activeProject),[c,d]=(0,l.useState)({workspacePath:(null==i?void 0:i.path)||"",label:"",accessLevel:"readonly",language:r}),[u,m]=(0,l.useState)(!1),[x,p]=(0,l.useState)("");async function h(){p(""),m(!0);try{e.onDone(await e.create({...c,label:c.label||void 0}))}catch(e){p(e instanceof Error?e.message:String(e))}finally{m(!1)}}return(0,s.jsx)(lh,{width:e.width,title:t("".concat(n,".addTitle")),onClose:a,children:(0,s.jsxs)("div",{className:"space-y-3",children:[e.children,(0,s.jsx)(lf,{ns:n,value:c,onChange:e=>d(t=>({...t,...e})),observer:e.observer}),e.extraFields,x&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:x}),(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("".concat(n,".cancel"))}),(0,s.jsxs)("button",{onClick:h,disabled:u||!o||!H(c.workspacePath),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[u&&(0,s.jsx)(ee.A,{className:"h-3 w-3 animate-spin"}),t("".concat(n,".addBtn"))]})]})]})})}function lv(e,t){let[r,n]=(0,l.useState)([]),[a,s]=(0,l.useState)(!0),o=(0,l.useCallback)(()=>{s(!0),t().then(e=>n(e.accounts)).catch(t=>{console.error("[".concat(e,"] list failed:"),t)}).finally(()=>s(!1))},[e,t]);(0,l.useEffect)(()=>{o()},[o]);let i=la(e=>e.version);return(0,l.useEffect)(()=>{i>0&&o()},[i,o]),{accounts:r,loading:a,reload:o}}function lb(e){let t=(0,eV.kj)(),{ns:r,accounts:n,loading:a,reload:o}=e,[i,c]=(0,l.useState)(null);return(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:t("".concat(r,".title"))}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("".concat(r,".desc"))})]}),(0,s.jsxs)("button",{onClick:e.onAdd,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)(aC.A,{className:"h-3.5 w-3.5"}),t("".concat(r,".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)(ee.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),t("".concat(r,".loading"))]}):0===n.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:t("".concat(r,".empty"))}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:n.map(t=>(0,s.jsx)(l.Fragment,{children:e.renderRow(t,{editing:i===t.accountId,onEdit:()=>c(t.accountId),onCancelEdit:()=>c(null),onSaved:()=>{c(null),o()},onChanged:o})},t.accountId))})}),e.children]})}function lj(e){let t=e.icon;return(0,s.jsx)("button",{onClick:e.onClick,disabled:e.disabled,title:e.title,className:B("rounded p-1.5 text-[var(--muted-foreground)]",e.danger?"hover:bg-red-500/20 hover:text-red-400":"hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(t,{className:"h-3.5 w-3.5"})})}let ly={readonly:{text:"Readonly",className:"bg-emerald-500/15 text-emerald-300"},observer:{text:"Observer",className:"bg-teal-500/15 text-teal-300"},workspace:{text:"Workspace",className:"bg-blue-500/15 text-blue-300"},full:{text:"Full",className:"bg-amber-500/15 text-amber-300"}};function lw(e){return e instanceof Error?e.message:String(e)}function lN(e){var t;let r=(0,eV.kj)(),{ns:n,account:a,onEdit:o,onChanged:i}=e,[c,d]=(0,l.useState)(!1);if(e.editing)return(0,s.jsx)(lk,{...e});async function u(e,t){d(!0);try{await e(),i()}catch(e){alert(r("".concat(n,".").concat(t),{error:lw(e)}))}finally{d(!1)}}async function m(){var t;await G(r("".concat(n,".confirmDelete"),{name:null!=(t=e.deleteName)?t:""}))&&await u(e.remove,"deleteFailed")}let x=ly[a.accessLevel];return(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:B("h-2 w-2 rounded-full",a.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:e.title}),(0,s.jsx)("span",{className:B("rounded px-1.5 py-0.5 text-[9px] font-medium",x.className),children:x.text}),e.titleExtra]}),(0,s.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:[e.detail,e.workspaceMissing&&(0,s.jsx)("span",{className:"ml-1 text-red-400",children:r("".concat(n,".pathMissing"))})]}),e.footer]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)(lj,{onClick:()=>u(()=>e.setEnabled(!a.enabled),"switchFailed"),disabled:c,title:a.enabled?r("".concat(n,".disable")):r("".concat(n,".enable")),icon:a.enabled?li.A:lc.A}),null==(t=e.actions)?void 0:t.call(e,c),(0,s.jsx)(lj,{onClick:o,disabled:c,title:r("".concat(n,".edit")),icon:ld.A}),(0,s.jsx)(lj,{onClick:m,disabled:c,title:r("".concat(n,".delete")),icon:eP.A,danger:!0})]})]})}function lk(e){var t;let r=(0,eV.kj)(),{ns:n,account:a}=e,o=()=>({label:a.label,workspacePath:a.workspacePath,accessLevel:a.accessLevel,language:a.language||"en",...e.extraDraft}),[i,c]=(0,l.useState)(o),[d,u]=(0,l.useState)(a);d!==a&&(u(a),c(o()));let[m,x]=(0,l.useState)(!1),p=e=>c(t=>({...t,...e}));async function h(){x(!0);let{accessLevel:t,...a}=i;try{await e.save("observer"===t&&!e.observer?a:i),e.onSaved()}catch(e){alert(r("".concat(n,".saveFailed"),{error:lw(e)}))}finally{x(!1)}}return(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(lm,{compact:!0,label:r("".concat(n,".label")),children:(0,s.jsx)(lx,{compact:!0,value:i.label,onChange:e=>p({label:e}),placeholder:r("".concat(n,".labelPlaceholder"))})}),(0,s.jsx)(lm,{compact:!0,label:r("".concat(n,".workspace")),children:(0,s.jsx)(lx,{compact:!0,mono:!0,value:i.workspacePath,onChange:e=>p({workspacePath:e}),placeholder:"/home/user/project"})}),(0,s.jsx)(lm,{compact:!0,label:r("".concat(n,".accessLevel")),hint:e.accessHint,children:(0,s.jsx)(lp,{compact:!0,ns:n,value:i.accessLevel,onChange:e=>p({accessLevel:e}),observer:e.observer})}),(0,s.jsx)(eV.pZ,{value:i.language,onChange:e=>p({language:e})}),null==(t=e.editExtra)?void 0:t.call(e,i,e=>c(t=>({...t,...e}))),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:h,disabled:m||!H(i.workspacePath),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)(tz.A,{className:"h-3 w-3"})," ",r("".concat(n,".save"))]}),(0,s.jsxs)("button",{onClick:e.onCancelEdit,disabled:m,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(e2.A,{className:"h-3 w-3"})," ",r("".concat(n,".cancel"))]})]})]})})}function lS(e){let t=(0,eV.kj)(),{intent:r,onClose:n,onDone:a}=e,o=tq(e=>e.activeProject),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),[m,x]=(0,l.useState)("loading"),[p,h]=(0,l.useState)(t("wx.generatingQr")),[f,g]=(0,l.useState)({workspacePath:r.workspacePath||(null==o?void 0:o.path)||"",label:r.label||"",accessLevel:r.accessLevel,language:r.language}),{workspacePath:v,label:b,accessLevel:j,language:y}=f,[w,k]=(0,l.useState)(r.skipConfig?"scan":"config"),S=(0,l.useRef)(!1),C=r.skipConfig;async function A(){if(!H(v))return void h(t("wx.pathRequired"));k("scan"),x("loading"),h(t("wx.generatingQr"));try{let{qrcodeUrl:r,sessionKey:n}=await N.F.wechat.startLogin();if(S.current)return;if(!r){x("error"),h(t("wx.qrFailed"));return}c(n);let s=await ll.toDataURL(r,{width:256,margin:2});if(S.current)return;u(s),x("waiting"),h(t("wx.scanPrompt"));let l=await N.F.wechat.waitLogin({sessionKey:n,workspacePath:v,label:b||void 0,accessLevel:j,language:y});if(S.current)return;if(l.connected){var e;x("success"),h(t("wx.connected",{id:null!=(e=l.accountId)?e:""})),setTimeout(a,1200)}else x("error"),h(l.message||t("wx.loginFailed"))}catch(e){if(S.current)return;x("error"),h(e instanceof Error?e.message:String(e))}}return(0,l.useEffect)(()=>()=>{S.current=!0},[]),(0,l.useEffect)(()=>{r.skipConfig&&A()},[]),(0,s.jsxs)(lh,{width:"w-[400px]",title:C?t("wx.rescanBtn"):t("wx.addTitle"),onClose:n,children:["config"===w?(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(lf,{ns:"wx",value:f,onChange:e=>g(t=>({...t,...e})),workspaceHint:t("wx.bindHint"),accessHint:t("wx.readonlyShareHint")}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:n,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.cancel")}),(0,s.jsx)("button",{onClick:A,disabled:!H(v),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)(ee.A,{className:"h-6 w-6 animate-spin text-[var(--muted-foreground)]"})}),(0,s.jsx)("p",{className:B("text-center text-xs","success"===m&&"text-emerald-400","error"===m&&"text-red-400","success"!==m&&"error"!==m&&"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:v})]}),"error"===m&&(0,s.jsx)("button",{onClick:()=>{k("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 lC={id:"wechat",label:"channels.wechat",Icon:lr.A,Component:function(){let e=(0,eV.kj)(),{lang:t}=(0,eV.s9)(),{accounts:r,loading:n,reload:a}=lv("wechat",N.F.wechat.listAccounts),[o,i]=(0,l.useState)(null);return(0,s.jsx)(lb,{ns:"wx",accounts:r,loading:n,reload:a,onAdd:()=>i({workspacePath:"",label:"",accessLevel:"readonly",language:t,skipConfig:!1}),renderRow:(t,r)=>(0,s.jsx)(lN,{...r,ns:"wx",account:t,title:t.label||t.accountId,deleteName:t.label,titleExtra:(0,s.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:t.accountId}),detail:t.workspacePath,workspaceMissing:t.workspaceMissing,accessHint:e("wx.readonlyHint"),actions:r=>(0,s.jsx)(lj,{onClick:()=>i({workspacePath:t.workspacePath,label:t.label,accessLevel:t.accessLevel,language:t.language,skipConfig:!0}),disabled:r,title:e("wx.rescan"),icon:lo.A}),save:e=>N.F.wechat.updateAccount(t.accountId,e),setEnabled:e=>N.F.wechat.updateAccount(t.accountId,{enabled:e}),remove:()=>N.F.wechat.deleteAccount(t.accountId)}),children:o&&(0,s.jsx)(lS,{intent:o,onClose:()=>i(null),onDone:()=>{i(null),a()}})})}};function lA(e){let t=(0,eV.kj)(),[r,n]=(0,l.useState)(""),[a,o]=(0,l.useState)("");return(0,s.jsx)(lg,{ns:"tg",width:"w-[420px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim(),create:e=>N.F.telegram.createAccount({botToken:r,...e,allowedUsers:a||void 0}),extraFields:(0,s.jsx)(lm,{label:t("tg.allowedUsersOptional"),children:(0,s.jsx)(lx,{mono:!0,value:a,onChange:o,placeholder:t("tg.allowedUsersHint")})}),children:(0,s.jsx)(lm,{label:t("tg.tokenLabel"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:r,onChange:n,placeholder:"123456:ABC-DEF..."})})})}let lI={id:"telegram",label:"Telegram",Icon:n1.A,Component:function(){let e=(0,eV.kj)(),{accounts:t,loading:r,reload:n}=lv("telegram",N.F.telegram.listAccounts),[a,o]=(0,l.useState)(!1);return(0,s.jsx)(lb,{ns:"tg",accounts:t,loading:r,reload:n,onAdd:()=>o(!0),renderRow:(t,r)=>(0,s.jsx)(lN,{...r,ns:"tg",account:t,title:t.label||"@".concat(t.botUsername),deleteName:t.botUsername,titleExtra:t.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:e("tg.whitelist")}),detail:(0,s.jsxs)(s.Fragment,{children:["@",t.botUsername," → ",t.workspacePath]}),workspaceMissing:t.workspaceMissing,extraDraft:{allowedUsers:t.allowedUsers},editExtra:(t,r)=>(0,s.jsx)(lm,{compact:!0,label:e("tg.allowedUsers"),children:(0,s.jsx)(lx,{compact:!0,mono:!0,value:t.allowedUsers,onChange:e=>r({allowedUsers:e}),placeholder:"123456789,@username"})}),save:e=>N.F.telegram.updateAccount(t.accountId,e),setEnabled:e=>N.F.telegram.updateAccount(t.accountId,{enabled:e}),remove:()=>N.F.telegram.deleteAccount(t.accountId)}),children:a&&(0,s.jsx)(lA,{onClose:()=>o(!1),onDone:()=>{o(!1),n()}})})}};function lE(e){let t=(0,eV.kj)(),[r,n]=(0,l.useState)(!1);return(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:[e.token.slice(0,12),"..."]}),(0,s.jsx)("button",{onClick:function(){navigator.clipboard.writeText(e.token),n(!0),setTimeout(()=>n(!1),2e3)},className:"text-[10px] text-[var(--primary)] hover:underline",children:t(r?"web.copied":"web.copyToken")})]})}function lT(e){let t=(0,eV.kj)(),{onClose:r,onDone:n}=e,[a,o]=(0,l.useState)(null);return a?(0,s.jsxs)(lh,{width:"w-[420px]",onClose:n,children:[(0,s.jsx)("h3",{className:"mb-3 text-sm font-medium text-[var(--foreground)]",children:t("web.createSuccess")}),(0,s.jsx)("p",{className:"mb-2 text-xs text-[var(--muted-foreground)]",children:t("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:a.token}),(0,s.jsx)("button",{onClick:()=>navigator.clipboard.writeText(a.token),className:"rounded p-1 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(nS.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"mt-4 flex justify-end",children:(0,s.jsx)("button",{onClick:n,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white",children:t("web.done")})})]}):(0,s.jsx)(lg,{ns:"web",width:"w-[420px]",observer:!0,onClose:r,create:e=>N.F.web.createAccount(e),onDone:e=>o({token:e.token})})}let lM={id:"web_demo",label:"Web",Icon:en.A,Component:function(){let{accounts:e,loading:t,reload:r}=lv("web",N.F.web.listAccounts),[n,a]=(0,l.useState)(!1);return(0,s.jsx)(lb,{ns:"web",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,s.jsx)(lN,{...t,ns:"web",account:e,observer:!0,title:e.label||e.accountId,detail:e.workspacePath,workspaceMissing:e.workspaceMissing,footer:(0,s.jsx)(lE,{token:e.token}),save:t=>N.F.web.updateAccount(e.accountId,t),setEnabled:t=>N.F.web.updateAccount(e.accountId,{enabled:t}),remove:()=>N.F.web.deleteAccount(e.accountId)}),children:n&&(0,s.jsx)(lT,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}};function lF(e){let t=(0,eV.kj)(),[r,n]=(0,l.useState)(""),[a,o]=(0,l.useState)("");return(0,s.jsxs)(lg,{ns:"slack",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>N.F.slack.createAccount({botToken:r,appToken:a,...e}),children:[(0,s.jsx)(lm,{label:t("slack.botTokenLabel"),hint:t("slack.botTokenHint"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:r,onChange:n,placeholder:"xoxb-..."})}),(0,s.jsx)(lm,{label:t("slack.appTokenLabel"),hint:t("slack.appTokenHint"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:a,onChange:o,placeholder:"xapp-..."})})]})}let lD={id:"slack",label:"Slack",Icon:ed.A,Component:function(){let{accounts:e,loading:t,reload:r}=lv("slack",N.F.slack.listAccounts),[n,a]=(0,l.useState)(!1);return(0,s.jsx)(lb,{ns:"slack",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,s.jsx)(lN,{...t,ns:"slack",account:e,title:e.label||e.teamId,deleteName:e.teamId,detail:(0,s.jsxs)(s.Fragment,{children:["team:",e.teamId," bot:",e.botUserId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>N.F.slack.updateAccount(e.accountId,t),setEnabled:t=>N.F.slack.updateAccount(e.accountId,{enabled:t}),remove:()=>N.F.slack.deleteAccount(e.accountId)}),children:n&&(0,s.jsx)(lF,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}};function lP(e){let t=(0,eV.kj)(),[r,n]=(0,l.useState)(""),[a,o]=(0,l.useState)(""),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)("");return(0,s.jsxs)(lg,{ns:"feishu",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>N.F.feishu.createAccount({appId:r,appSecret:a,verificationToken:i||void 0,encryptKey:d||void 0,...e}),children:[(0,s.jsx)(lm,{label:t("feishu.appIdLabel"),children:(0,s.jsx)(lx,{mono:!0,value:r,onChange:n,placeholder:"cli_xxxxxxx"})}),(0,s.jsx)(lm,{label:t("feishu.appSecretLabel"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:a,onChange:o,placeholder:"****************"})}),(0,s.jsx)(lm,{label:t("feishu.verificationTokenLabel"),children:(0,s.jsx)(lx,{mono:!0,value:i,onChange:c,placeholder:""})}),(0,s.jsx)(lm,{label:t("feishu.encryptKeyLabel"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:d,onChange:u,placeholder:""})})]})}function lL(e){let t=(0,eV.kj)(),[r,n]=(0,l.useState)(""),[a,o]=(0,l.useState)("");return(0,s.jsxs)(lg,{ns:"wecom",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>N.F.wecom.createAccount({botId:r,secret:a,...e}),children:[(0,s.jsx)(lm,{label:t("wecom.botIdLabel"),children:(0,s.jsx)(lx,{mono:!0,value:r,onChange:n,placeholder:"wecombot_xxxxxxx"})}),(0,s.jsx)(lm,{label:t("wecom.secretLabel"),children:(0,s.jsx)(lx,{mono:!0,type:"password",value:a,onChange:o,placeholder:"****************"})})]})}let lR=[lC,lI,lM,lD,{id:"feishu",label:"Feishu",Icon:r(61557).A,Component:function(){let{accounts:e,loading:t,reload:r}=lv("feishu",N.F.feishu.listAccounts),[n,a]=(0,l.useState)(!1);return(0,s.jsx)(lb,{ns:"feishu",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,s.jsx)(lN,{...t,ns:"feishu",account:e,title:e.label||e.appId,deleteName:e.appId,detail:(0,s.jsxs)(s.Fragment,{children:["app:",e.appId," bot:",e.botOpenId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>N.F.feishu.updateAccount(e.accountId,t),setEnabled:t=>N.F.feishu.updateAccount(e.accountId,{enabled:t}),remove:()=>N.F.feishu.deleteAccount(e.accountId)}),children:n&&(0,s.jsx)(lP,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}},{id:"wecom",label:"WeCom",Icon:r(60490).A,Component:function(){let{accounts:e,loading:t,reload:r}=lv("wecom",N.F.wecom.listAccounts),[n,a]=(0,l.useState)(!1);return(0,s.jsx)(lb,{ns:"wecom",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,s.jsx)(lN,{...t,ns:"wecom",account:e,title:e.label||e.botId,deleteName:e.botId,detail:(0,s.jsxs)(s.Fragment,{children:["bot:",e.botId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>N.F.wecom.updateAccount(e.accountId,t),setEnabled:t=>N.F.wecom.updateAccount(e.accountId,{enabled:t}),remove:()=>N.F.wecom.deleteAccount(e.accountId)}),children:n&&(0,s.jsx)(lL,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}}],l_="halo_channel_active",lz=new Set(lR.map(e=>e.id)),lO=null!=(a=null==(n=lR[0])?void 0:n.id)?a:"",lU=(0,c.v)(e=>({active:function(){try{let e=localStorage.getItem(l_);if(e&&lz.has(e))return e}catch(e){}return lO}(),setActive(t){if(lz.has(t)){try{localStorage.setItem(l_,t)}catch(e){}e({active:t})}}}));function lB(){let e=(0,eV.kj)(),t=lU(e=>e.active),r=lU(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)(lr.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:()=>ls(),title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:(0,s.jsx)(nh.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:lR.map(n=>{if(!1===n.enabled)return null;let a=n.Icon,l=e(n.label),o=l===n.label?n.label:l;return(0,s.jsxs)("button",{onClick:()=>r(n.id),className:B("flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors",t===n.id?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]"),children:[(0,s.jsx)(a,{className:"h-3.5 w-3.5"}),o]},n.id)})})]})}function lW(){let e=lU(e=>e.active),t=lR.find(t=>t.id===e);if(!t)return null;let r=t.Component;return(0,s.jsx)(r,{})}var lH=r(2462);let lK=(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 lG(e){var t;let{status:r}=e,n=null!=(t=lq[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,s.jsx)("span",{className:B("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",n),children:r.replace("_"," ")})}let lq={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 lJ(){let e=(0,eV.kj)(),t=lK(e=>e.selectedId);return t?(0,s.jsx)(l$,{id:t}):(0,s.jsx)(lZ,{label:e("evolution.list.pickRun")})}function lZ(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 l$(e){var t,r,n,a;let{id:o}=e,i=(0,eV.kj)(),c=lK(e=>e.refreshTick),d=lK(e=>e.setSelectedId),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)(!0),[h,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(""),[y,w]=(0,l.useState)(""),[k,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),[M,F]=(0,l.useState)(""),D=(0,l.useCallback)(async()=>{p(!0);try{let e=await N.F.evolution.getRun(o);m(e),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}finally{p(!1)}},[o]);if((0,l.useEffect)(()=>{m(null),C(!1),I(!1),j(""),w(""),D()},[o,D]),(0,l.useEffect)(()=>{0!==c&&D()},[c,D]),(0,l.useEffect)(()=>S.on("evolution:run_changed",e=>{e.id===o&&("deleted"===e.kind?d(null):D())}),[o,D,d]),x&&!u)return(0,s.jsx)(lZ,{label:i("evolution.list.loading")});if(h)return(0,s.jsx)(lZ,{label:i("cron.error",{error:h})});if(!u)return(0,s.jsx)(lZ,{label:i("evolution.list.noRun")});let{run:P,patchMd:L,scoreJson:R,skipReasonMd:_,snapshotSummary:z,wrapperLog:O,subCliLog:U}=u,B="awaiting_review"===P.status,W="approved"===P.status&&("failed"===P.applyStatus||"timeout"===P.applyStatus),H=async()=>{v(!0);try{await N.F.evolution.approve(o,b.trim()||void 0),C(!1),j(""),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},K=async()=>{if(await G(i("evolution.action.confirmReject"))){v(!0);try{await N.F.evolution.reject(o),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},q=async()=>{let e=y.trim();if(e){v(!0);try{await N.F.evolution.addHint(o,e),w(""),I(!1),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},J=async()=>{let e=M.trim();if(!e)return void alert(i("evolution.action.retryNeedsHint"));v(!0);try{await N.F.evolution.retry(o,e),F(""),T(!1),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},Z=async()=>{if(await G(i("evolution.action.confirmDelete"))){v(!0);try{await N.F.evolution.delete(o),d(null)}catch(e){alert(e instanceof Error?e.message:String(e)),v(!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)(lG,{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)(eP.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")}),W&&(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)(tz.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.approve")]}),(0,s.jsxs)("button",{disabled:g,onClick:()=>{K()},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)(e2.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)(lH.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)(nh.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||W)&&(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)(nh.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:M,onChange:e=>F(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||!M.trim(),onClick:()=>{J()},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),F("")},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&&k&&(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:b,onChange:e=>j(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:()=>{H()},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),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.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: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.hint.placeholder")}),(0,s.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,s.jsx)("button",{disabled:g||!y.trim(),onClick:()=>{q()},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),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")})]})]}),R&&(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)(lV,{label:i("evolution.score.lint"),value:R.lint}),(0,s.jsx)(lV,{label:i("evolution.score.behavior"),value:R.behavior}),(0,s.jsx)(lV,{label:i("evolution.score.scope"),value:R.scope}),(0,s.jsx)(lV,{label:i("evolution.score.avg"),value:R.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=R.confidence)?t:"—"})]}),"string"==typeof R.notes&&(0,s.jsx)("div",{className:"mt-2 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs text-[var(--foreground)]",children:R.notes})]}),z&&(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=z.messageCount)?r:0})}),z.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:z.firstUser})]}),z.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:(n=z.firstAssistant,a=400,n.length<=400?n:n.slice(0,a)+"…")})]})]}),(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")}),(O||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")}),O&&(0,s.jsx)(lY,{title:i("evolution.logs.wrapper"),body:O}),U&&(0,s.jsx)(lY,{title:i("evolution.logs.subCli"),body:U})]})]})]})}function lY(e){let{title:t,body:r}=e,[n,a]=(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:()=>a(e=>!e),children:[(0,s.jsx)("span",{children:n?"▼":"▶"}),(0,s.jsx)("span",{children:t}),(0,s.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",(r.length/1024).toFixed(1)," KB)"]})]}),n&&(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 lV(e){let{label:t,value:r,highlight:n}=e;return(0,s.jsxs)("div",{className:B("rounded p-2",n?"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:B("text-lg font-medium",n&&"text-[var(--primary)]"),children:"number"==typeof r?r:"—"})]})}let lQ=["all","awaiting_review","pending","running","approved","applied","skipped","rejected","failed","timeout","archived"];function lX(){let e=(0,eV.kj)(),t=lK(e=>e.filter),r=lK(e=>e.setFilter),n=lK(e=>e.selectedId),a=lK(e=>e.setSelectedId),o=lK(e=>e.bumpRefresh),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[m,x]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[v,b]=(0,l.useState)(!1),j=(0,l.useRef)(0);(0,l.useEffect)(()=>{j.current=i.length,i.length>=300&&g(null)},[i.length]);let y=(0,l.useCallback)(async()=>{let e=Math.min(300,Math.max(20,j.current));try{let r=await N.F.evolution.listRuns({archived:"archived"===t,limit:e});c(r.runs),g(r.hasMore?r.nextCursor:null),x(null)}catch(e){x(e instanceof Error?e.message:String(e))}finally{u(!1)}},[t]),w=(0,l.useCallback)(async()=>{if(f&&!v){b(!0);try{let e=await N.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{b(!1)}}},[t,f,v]);(0,l.useEffect)(()=>{y()},[y]);let k=nu(w,i.length);(0,l.useEffect)(()=>{let e=S.on("evolution:run_changed",()=>{y()}),t=S.on("evolution:apply_changed",()=>{y()});return()=>{e(),t()}},[y]);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(n)return;let t=null!=(e=i.find(e=>"awaiting_review"===e.status))?e:i[0];t&&a(t.id)},[i,n,a]),(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)(nY.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([y(),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)(nh.A,{className:B("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:lQ.map(n=>(0,s.jsx)("button",{onClick:()=>r(n),className:B("w-16 shrink-0 rounded px-2 py-0.5 text-xs text-center",t===n?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:e("evolution.filter.".concat(n))},n))}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[d&&(0,s.jsx)(l0,{label:e("evolution.list.loading")}),m&&(0,s.jsx)(l0,{label:e("cron.error",{error:m})}),!d&&!m&&0===C.length&&(0,s.jsx)(l0,{label:e("evolution.list.empty")}),C.map(e=>(0,s.jsx)(l1,{run:e,selected:e.id===n,onClick:()=>a(e.id)},e.id)),f&&(0,s.jsx)("div",{ref:k,className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:v?e("evolution.list.loading"):e("cron.loadOlder")})]})]})}function l0(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 l1(e){var t;let{run:r,selected:n,onClick:a}=e,l=(0,eV.kj)();return(0,s.jsxs)("button",{onClick:a,className:B("flex w-full flex-col gap-1 border-b border-[var(--border)] px-3 py-2 text-left text-sm transition-colors",n?"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)(lG,{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:q(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})})]})]})]})}var l3=r(30478),l5=r.n(l3),l2=r(90144);let l4=(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 l8(e,t){return e?e.includes("ret=-2")?t("cron.err.wechat.noInbound"):e:"?"}function l6(){let e=(0,eV.kj)(),t=l4(e=>e.selectedId),r=l4(e=>e.setSelectedId),n=l4(e=>e.formMode),a=l4(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 N.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)(()=>S.on("cron:job_changed",()=>{c()}),[c]);let d=(0,l.useCallback)(async n=>{if(await G(e("cron.confirmDelete")))try{await N.F.cron.deleteJob(n),t===n&&r(null)}catch(e){alert(e instanceof Error?e.message:String(e))}},[t,r,e]),u=(0,l.useCallback)(async e=>{try{await N.F.cron.runNow(e)}catch(e){alert(e instanceof Error?e.message:String(e))}},[]);return"create"===n?(0,s.jsx)(oe,{onClose:a,onSaved:a}):"edit"===n&&o?(0,s.jsx)(oe,{initial:o,onClose:a,onSaved:a}):o?(0,s.jsx)(l9,{job:o,onEdit:()=>l4.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 l9(e){var t;let{job:r,onEdit:n,onDelete:a,onRunNow:o}=e,i=(0,eV.kj)(),[c,d]=(0,l.useState)([]),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(null),[b,j]=(0,l.useState)(!1),y=(0,l.useCallback)(async()=>{try{let e=await N.F.cron.listRuns(r.id,{limit:20});d(e.runs),v(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns",e)}},[r.id]),w=(0,l.useCallback)(async()=>{if(g&&!b){j(!0);try{let e=await N.F.cron.listRuns(r.id,{limit:20,before:g});d(t=>[...t,...e.runs]),v(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns more",e)}finally{j(!1)}}},[r.id,g,b]);(0,l.useEffect)(()=>{y()},[y]);let k=nu(w,c.length);(0,l.useEffect)(()=>S.on("cron:run_changed",e=>{e.jobId===r.id&&y()}),[r.id,y]);let C=(0,l.useCallback)(async e=>{m(e),p(null),f(!0);try{let{log:t}=await N.F.cron.getRunLog(e);p(null!=t?t:"(log file not available — retention or never written)")}catch(e){p("error: ".concat(e instanceof Error?e.message:String(e)))}finally{f(!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)(l2.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:r.label||r.id}),0===r.enabled&&(0,s.jsx)("span",{className:"rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] uppercase",children:i("cron.disabled")})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsxs)("button",{onClick:o,className:"flex items-center gap-1 rounded bg-emerald-600 px-2 py-1 text-xs text-white hover:opacity-90",title:i("cron.runNow"),children:[(0,s.jsx)(sy.A,{className:"h-3 w-3"})," ",i("cron.runNow")]}),(0,s.jsxs)("button",{onClick:n,className:"flex items-center gap-1 rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:opacity-90",title:i("cron.edit"),children:[(0,s.jsx)(ld.A,{className:"h-3 w-3"})," ",i("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:i("cron.delete"),children:(0,s.jsx)(eP.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:[r.runAt?(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.runAt")})," ",(0,s.jsxs)("span",{className:"font-mono",children:[new Date(r.runAt).toLocaleString(),r.timezone?" (".concat(r.timezone,")"):""]})]}):(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.schedule")})," ",(0,s.jsxs)("span",{className:"font-mono",children:[r.schedule,r.timezone?" (".concat(r.timezone,")"):""]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.agent")})," ",r.agentId]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.timeoutSec")})," ",null!=r.timeoutSec?"".concat(r.timeoutSec,"s"):i("cron.field.timeoutSecDefault")]}),(0,s.jsxs)("div",{className:"col-span-2 truncate",children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.workspace")})," ",r.workspacePath]}),(0,s.jsxs)("div",{className:"col-span-2 truncate",children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.session")})," ",(0,s.jsx)("span",{className:"font-mono",children:null!=(t=r.sessionId)?t:i("cron.field.sessionDefault",{id:"cron-".concat(r.id)})})]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.targets")})," ",0===r.targets.length?i("cron.field.targetsLogOnly"):r.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:i("cron.field.prompt")}),(0,s.jsx)("pre",{className:"mt-1 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs",children:r.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:i("cron.runHistory")}),0===c.length?(0,s.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:i("cron.noRuns")}):(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("ul",{className:"divide-y divide-[var(--border)] text-xs",children:[c.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:B("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:()=>{C(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:l8(e.failureReason,i)}),e.dispatchResults&&e.dispatchResults.length>0&&(0,s.jsxs)("div",{className:"mt-1 text-[var(--muted-foreground)]",children:[i("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(l8(e.error,i),")"))}).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)),g&&(0,s.jsx)("li",{ref:k,className:"py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?i("cron.loading"):i("cron.loadOlder")})]})})]}),u&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:()=>m(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:i("cron.log.title",{id:u})}),(0,s.jsx)("button",{onClick:()=>m(null),className:"rounded px-2 py-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:i("cron.log.close")})]}),(0,s.jsx)("pre",{className:"flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-[11px] leading-relaxed",children:h?i("cron.loading"):null!=x?x:""})]})})]})}function l7(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 oe(e){var t,r,n,a,o,i,c;let{initial:d,onClose:u,onSaved:m}=e,x=(0,eV.kj)(),p=tq(e=>e.activeProject),[h,f]=(0,l.useState)(null!=(t=null==d?void 0:d.label)?t:""),[g,v]=(0,l.useState)(null!=(n=null!=(r=null==d?void 0:d.workspacePath)?r:null==p?void 0:p.path)?n:""),[b,j]=(0,l.useState)(g),[y,w]=(0,l.useState)(null!=(a=null==d?void 0:d.agentId)?a:"default"),[k,S]=(0,l.useState)([]),[C,A]=(0,l.useState)(null!=(o=null==d?void 0:d.sessionId)?o:""),[I,E]=(0,l.useState)([]),[T,M]=(0,l.useState)((null==d?void 0:d.runAt)?"oneShot":"recurring"),[F,D]=(0,l.useState)((null==d?void 0:d.schedule)||"0 9 * * *"),[P,L]=(0,l.useState)(()=>(null==d?void 0:d.runAt)?l7(new Date(d.runAt)):l7(new Date(Date.now()+36e5))),[R,_]=(0,l.useState)(()=>(function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}})());(0,l.useEffect)(()=>{let e=!0;return N.F.cron.meta().then(t=>{let{hostTimezone:r}=t;e&&r&&_(r)}).catch(e=>console.error("cron.meta",e)),()=>{e=!1}},[]);let z=(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(R)?R:e[0];return[{id:t,label:"".concat(t," (default)")},...e.filter(e=>e!==t).map(e=>({id:e,label:e}))]},[R]),[O,U]=(0,l.useState)(null!=(i=null==d?void 0:d.timezone)?i:""),[W,H]=(0,l.useState)((null==d?void 0:d.timeoutSec)!=null?String(d.timeoutSec):""),[K,G]=(0,l.useState)(null!=(c=null==d?void 0:d.userPrompt)?c:""),[q,J]=(0,l.useState)((null==d?void 0:d.enabled)!==0),[Z,$]=(0,l.useState)([]),[Y,V]=(0,l.useState)(()=>{var e;let t=new Set;for(let r of null!=(e=null==d?void 0:d.targets)?e:[])t.add("".concat(r.channelType,":").concat(r.accountId));return t}),[Q,X]=(0,l.useState)(()=>{var e;let t={};for(let r of null!=(e=null==d?void 0:d.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}),[ee,et]=(0,l.useState)(!1),[er,en]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!0,t=async()=>{try{let{agents:t}=await N.F.agentConfigs.list(b||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}));S(r),r.length>0&&w(e=>r.some(t=>t.id===e)?e:r[0].id)}catch(e){console.error("agentConfigs.list",e)}};return b&&t(),()=>{e=!1}},[b]),(0,l.useEffect)(()=>{let e=!0;if(b)return N.F.sessionLogs.list(b,{rootOnly:!0,limit:50}).then(t=>{let{sessions:r}=t;e&&E(r.map(e=>({id:e.id,label:"".concat(e.title||e.id," \xb7 ").concat(e.agentName||e.agentId)})))}).catch(t=>{e&&E([]),console.error("sessionLogs.list",t)}),()=>{e=!1}},[b]),(0,l.useEffect)(()=>{let e=!0;return N.F.cron.listChannelTargets().then(t=>{let{targets:r}=t;e&&$(r)}).catch(e=>console.error("listChannelTargets",e)),()=>{e=!1}},[]);let ea=(0,l.useCallback)(e=>{V(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),es=(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[,n,a,s,l,o]=r,i=Date.UTC(+n,a-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)},[]),el=(0,l.useCallback)(async()=>{if(en(null),!g.trim())return void en(x("cron.form.err.workspace"));if(!y.trim())return void en(x("cron.form.err.agent"));if("recurring"===T&&!F.trim())return void en(x("cron.form.err.schedule"));if("oneShot"===T&&!P)return void en(x("cron.form.err.runAt"));if(!K.trim())return void en(x("cron.form.err.prompt"));let e=O||R,t="oneShot"===T?es(P,e):void 0;if("oneShot"===T&&void 0!==t&&t<=Date.now())return void en(x("cron.form.err.runAtPast"));let r=W.trim(),n=r?Number(r):void 0;if(void 0!==n&&(!Number.isInteger(n)||n<60||n>21600))return void en(x("cron.form.err.timeoutSec"));let a=[];for(let e of Y){var s;let[t,r]=e.split(":"),n=(null!=(s=Q[e])?s:"").trim(),l=n?n.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)?"wecom"!==t||/^[\w@.-]+$/.test(e)?"telegram"!==t||/^-?\d+$/.test(e)?null:x("cron.form.err.chatId.telegram",{chatId:e}):x("cron.form.err.chatId.wecom",{chatId:e}):x("cron.form.err.chatId.feishu",{chatId:e}):x("cron.form.err.chatId.slack",{chatId:e});for(let e of l){let t=o(e);if(t)return void en(t)}if(0===l.length)a.push({channelType:t,accountId:r});else for(let e of l)a.push({channelType:t,accountId:r,chatId:e})}et(!0);try{let e={label:h||void 0,workspacePath:g,agentId:y,userPrompt:K,timezone:O||void 0,targets:a,enabled:q};d?await N.F.cron.updateJob(d.id,{...e,schedule:"recurring"===T?F:"",runAt:"oneShot"===T?t:null,timeoutSec:null!=n?n:null,sessionId:C||null}):await N.F.cron.createJob({...e,schedule:"recurring"===T?F:"",runAt:"oneShot"===T?t:void 0,timeoutSec:n,sessionId:C||void 0}),m()}catch(e){en(e instanceof Error?e.message:String(e))}finally{et(!1)}},[d,h,g,y,C,K,T,F,P,O,R,es,W,Y,Q,q,m,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:d?x("cron.form.edit"):x("cron.form.create")}),(0,s.jsx)("button",{onClick:u,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)(ot,{label:x("cron.form.label"),children:(0,s.jsx)("input",{value:h,onChange:e=>f(e.target.value),placeholder:x("cron.form.label.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,s.jsx)(ot,{label:x("cron.form.workspace"),children:(0,s.jsx)("input",{value:g,onChange:e=>v(e.target.value),onBlur:()=>j(g),onKeyDown:e=>{"Enter"===e.key&&j(g)},placeholder:x("cron.form.workspace.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"})}),(0,s.jsx)(ot,{label:x("cron.form.agent"),children:(0,s.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base",children:[0===k.length&&(0,s.jsx)("option",{value:"default",className:"jsx-8283b0ed0bcf6928",children:"default"}),k.map(e=>(0,s.jsxs)("option",{value:e.id,className:"jsx-8283b0ed0bcf6928",children:[e.name," (",e.id,")"]},e.id))]})}),(0,s.jsxs)(ot,{label:x("cron.form.session"),children:[(0,s.jsx)(sw,{value:C,placeholder:x("cron.form.session.placeholder"),presets:b?I:[],onCommit:e=>A(e.trim()),minWidth:280}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.session.hint")})]}),(0,s.jsx)(ot,{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"===T,onChange:()=>M("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"===T,onChange:()=>M("oneShot"),className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:x("cron.form.mode.oneShot")})]})]})}),"recurring"===T?(0,s.jsxs)(ot,{label:x("cron.form.schedule"),children:[(0,s.jsx)("input",{value:F,onChange:e=>D(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)(ot,{label:x("cron.form.runAt"),children:[(0,s.jsx)("input",{type:"datetime-local",value:P,onChange:e=>L(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)(ot,{label:x("cron.form.timezone"),children:(0,s.jsx)(sw,{value:O||R,placeholder:x("cron.form.timezone.hostDefault",{tz:R}),presets:z,onCommit:e=>{U(e===R?"":e)},minWidth:280})}),(0,s.jsxs)(ot,{label:x("cron.form.timeoutSec"),children:[(0,s.jsx)("input",{type:"number",min:60,max:21600,step:1,value:W,onChange:e=>H(e.target.value),placeholder:x("cron.form.timeoutSec.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.timeoutSec.hint")})]}),(0,s.jsx)(ot,{label:x("cron.form.userPrompt"),children:(0,s.jsx)("textarea",{value:K,onChange:e=>G(e.target.value),rows:5,placeholder:x("cron.form.userPrompt.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,s.jsx)(ot,{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===Z.length?(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-[var(--muted-foreground)]",children:x("cron.form.targets.empty")}):Z.map(e=>{var t;let r="".concat(e.channelType,":").concat(e.accountId),n=Y.has(r),a="wechat"!==e.channelType,l="slack"===e.channelType?"D… (DM) / C… (channel) / C…:1700.0 (thread)":"telegram"===e.channelType?x("cron.form.chatIdHint.telegram"):"feishu"===e.channelType?x("cron.form.chatIdHint.feishu"):"wecom"===e.channelType?x("cron.form.chatIdHint.wecom"):"";return(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 "+(B("rounded px-1 py-0.5",n&&"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:n,onChange:()=>ea(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")})]}),n&&a&&(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 ml-6",children:[(0,s.jsx)(or,{channelType:e.channelType,accountId:e.accountId,value:null!=(t=Q[r])?t:"",onChange:e=>X(t=>({...t,[r]:e})),placeholder:l}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.chatIdHelp")})]})]},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:q,onChange:e=>J(e.target.checked),className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:x("cron.form.enabled")})]}),er&&(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 rounded border border-red-500/50 bg-red-950/40 p-2 text-red-300",children:er})]}),(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:u,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--accent)] px-3 py-1 text-xs",children:x("cron.form.cancel")}),(0,s.jsx)("button",{onClick:()=>{el()},disabled:ee,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--primary)] px-3 py-1 text-xs text-[var(--primary-foreground)] disabled:opacity-50",children:ee?x("cron.form.saving"):d?x("cron.form.save"):x("cron.form.create.btn")})]}),(0,s.jsx)(l5(),{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 ot(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 or(e){let{channelType:t,accountId:r,value:n,onChange:a,placeholder:o}=e,i=(0,eV.kj)(),[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)([]),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g="slack"===t||"feishu"===t;return(0,l.useEffect)(()=>{if(!g||!c.trim())return void m([]);let e=!1;f(!0);let n=setTimeout(async()=>{try{let n="slack"===t?await N.F.slack.searchTargets(r,c):await N.F.feishu.searchTargets(r,c);if(e)return;let a=n.hits.map(e=>{var t,r;let n=null!=(r=null!=(t=e.realName)?t:e.email)?r:"";return{id:e.id,name:e.name,chatId:e.chatId,kind:e.kind,subtitle:n}});m(a)}catch(t){e||m([]),console.error("[cron-form] target search failed:",t)}finally{e||f(!1)}},300);return()=>{e=!0,clearTimeout(n)}},[c,t,r,g]),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{value:n,onChange:e=>(function(e){var t,r;if(a(e),!g)return;let n=null!=(r=null==(t=e.split(",").pop())?void 0:t.trim())?r:"";d(n),p(n.length>0)})(e.target.value),onFocus:()=>{c&&p(!0)},onBlur:()=>setTimeout(()=>p(!1),150),placeholder:o,className:"input-base font-mono text-[11px]"}),g&&x&&(h||u.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:[h&&(0,s.jsx)("div",{className:"px-2 py-1 text-[10px] text-[var(--muted-foreground)]",children:i("cron.form.searching")}),!h&&u.map(e=>(0,s.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>(function(e){let t=n.split(",").map(e=>e.trim()).filter(Boolean);t.length>0?t[t.length-1]=e:t.push(e),a(t.join(", ")),d(""),m([]),p(!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 on(){let e=(0,eV.kj)(),[t,r]=(0,l.useState)([]),[n,a]=(0,l.useState)(!0),[o,i]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)(!1),h=l4(e=>e.selectedId),f=l4(e=>e.setSelectedId),g=l4(e=>e.openCreate),v=(0,l.useCallback)(async()=>{try{let e=await N.F.cron.listJobs({limit:20});r(e.jobs),m(e.hasMore?e.nextCursor:null),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]),b=nu((0,l.useCallback)(async()=>{if(u&&!x){p(!0);try{let e=await N.F.cron.listJobs({limit:20,before:u});r(t=>[...t,...e.jobs]),m(e.hasMore?e.nextCursor:null)}catch(e){console.error("cron.listJobs more",e)}finally{p(!1)}}},[u,x]),t.length),j=(0,l.useCallback)(async()=>{d(!0);let e=new Promise(e=>setTimeout(e,400));await Promise.all([v(),e]),d(!1)},[v]);return(0,l.useEffect)(()=>{v()},[v]),(0,l.useEffect)(()=>{let e=S.on("cron:job_changed",()=>{v()}),t=S.on("cron:run_changed",()=>{v()});return()=>{e(),t()}},[v]),(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)(l2.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)(aC.A,{className:"h-3 w-3"})," ",e("cron.new")]}),(0,s.jsx)("button",{onClick:()=>{j()},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)(nh.A,{className:B("h-3.5 w-3.5",c&&"animate-spin")})})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:n&&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,n=t.lastRunStatus;return(0,s.jsxs)("li",{className:B("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:B("inline-block h-2 w-2 rounded-full",0===t.enabled?"bg-[var(--muted-foreground)]":"succeeded"===n?"bg-emerald-500":"running"===n?"bg-amber-400 animate-pulse":"failed"===n||"timeout"===n?"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=>{b.current=e},className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:x?e("cron.loading"):e("cron.loadOlder")})]})})]})}var oa=r(88373),os=r(43180),ol=r(10969),oo=r(60087),oi=r(82358),oc=r(80566);let od=(0,c.v)(e=>({selected:null,select:t=>e({selected:t}),clear:()=>e({selected:null})}));function ou(e){let{files:t,group:r,selectedPath:n,onSelect:a,onAction:o}=e,[i,c]=(0,l.useState)(new Set),d=function(e,t){let r={type:"dir",name:"",path:"",children:[]};for(let n of e){let e=n.path.split("/"),a=r;for(let t=0;t<e.length-1;t++){let r=e[t],n=a.path?"".concat(a.path,"/").concat(r):r,s=a.children.find(e=>"dir"===e.type&&e.name===r);s||(s={type:"dir",name:r,path:n,children:[]},a.children.push(s)),a=s}a.children.push({type:"file",name:e[e.length-1],file:n,char:t(n)})}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)(Q.A,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)(V.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=P(t.char),m=n===t.file.path,x="staged"===r?oc.A:aC.A,{Icon:p,color:h}=ej(t.file.path);return(0,s.jsxs)("div",{onClick:()=>a(t.file),className:B("group flex w-full cursor-pointer items-center gap-1.5 py-0.5 pr-2 text-xs",m?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),style:{paddingLeft:"".concat(d+16,"px")},children:[(0,s.jsx)(p,{className:B("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)(x,{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 om=r(4704),ox=r(6821),op=r(16936);function oh(e){let{projectId:t,onClose:r,onSaved:n}=e,a=(0,eV.kj)(),[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:a("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)(e2.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:B("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?a("sc.cred.tabHttps"):a("sc.cred.tabSsh")},e))}),"https"===o?(0,s.jsx)(og,{onClose:r,onSaved:n}):(0,s.jsx)(ov,{projectId:t,onClose:r})]})})}let of="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 og(e){let{onClose:t,onSaved:r}=e,n=(0,eV.kj)(),[a,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)("github.com"),[m,x]=(0,l.useState)(""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[v,b]=(0,l.useState)(null),j=(0,l.useCallback)(()=>{N.F.git.getCredentials().then(e=>o(e.credentials)).catch(()=>o([]))},[]);async function y(){if(!d.trim()||!m.trim()||!p)return void b(n("sc.cred.required"));g(!0),b(null);try{await N.F.git.saveCredentials({host:d.trim(),username:m.trim(),token:p}),h(""),j(),r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function w(e){b(null);try{await N.F.git.deleteCredential(e),j()}catch(e){b(e instanceof Error?e.message:String(e))}finally{c(null)}}return(0,l.useEffect)(()=>{j()},[j]),(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:n("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:n("sc.cred.configuredList")}),0===a.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:n("sc.cred.noCredsYet")}):a.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:()=>w(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:n("sc.cred.confirmDelete")}):(0,s.jsx)("button",{onClick:()=>c(e.host),title:n("sc.cred.delete"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:text-red-400",children:(0,s.jsx)(eP.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:n("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:n("sc.cred.host")}),(0,s.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"github.com",className:of})]}),(0,s.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.username")}),(0,s.jsx)("input",{type:"text",value:m,onChange:e=>x(e.target.value),autoComplete:"off",className:of})]}),(0,s.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.token")}),(0,s.jsx)("input",{type:"password",value:p,onChange:e=>h(e.target.value),autoComplete:"new-password",className:of}),(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[n("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:[n("sc.cred.tokenLink"),(0,s.jsx)(om.A,{className:"h-2.5 w-2.5"})]})]})]})]}),v&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(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:n("sc.cred.cancel")}),(0,s.jsx)("button",{onClick:y,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?n("sc.cred.saving"):n("sc.cred.save")})]})]})}function ov(e){let{projectId:t,onClose:r}=e,n=(0,eV.kj)(),[a,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)([]),[m,x]=(0,l.useState)("other"),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[v,b]=(0,l.useState)(null),[j,y]=(0,l.useState)(null),[w,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(null),E=(0,l.useCallback)(()=>{N.F.git.sshKeys().then(e=>o(e.keys)).catch(()=>o([])),N.F.git.sshAgent().then(e=>{c(e.agentRunning),u(e.loadedKeys)}).catch(()=>{}),N.F.git.getRemoteProtocol(t).then(e=>{x(e.protocol),h(e.url)}).catch(()=>{})},[t]);function T(){y(null),k(""),I(null)}async function M(e){C(!0),I(null);try{let r=await N.F.git.unlockSshKey({keyPath:e.path,passphrase:w});if(r.ok)T(),E();else{var t;I(null!=(t=r.error)?t:n("sc.cred.sshUnlockFailed"))}}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}async function F(e){g(!0),b(null);try{let r=await N.F.git.setRemoteProtocol(t,e);x(e),h(r.url)}catch(e){b(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:n("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:B("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?n("sc.cred.sshAgentOn",{count:String(d.length)}):n("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:n("sc.cred.sshRefresh"),children:(0,s.jsx)(nh.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:n("sc.cred.sshKeys")}),0===a.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:n("sc.cred.sshNoKeys")}):a.map(e=>{let t=d.some(t=>t.includes(e.path)||t.includes(e.name)),r=j===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)(ox.A,{className:"h-3 w-3 shrink-0 text-amber-400"}):(0,s.jsx)(op.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:n("sc.cred.sshLoaded")}):!r&&(0,s.jsx)("button",{onClick:()=>{y(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:n("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:n("sc.cred.sshUnlockHint")}),(0,s.jsx)("input",{type:"password",autoFocus:!0,autoComplete:"off",value:w,onChange:e=>k(e.target.value),onKeyDown:t=>{"Enter"!==t.key||S||M(e)},placeholder:n("sc.cred.sshPassphrase"),className:of}),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:n("sc.cred.cancel")}),(0,s.jsx)("button",{onClick:()=>M(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?n("sc.cred.sshUnlocking"):n("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:n("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:()=>F(e),disabled:f||m===e,className:B("px-2 py-0.5 text-[10px] font-medium",m===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:n("sc.cred.sshRestartNote")}),v&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(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:n("sc.cred.close")})})]})}var ob=r(72526);function oj(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 oy(e){let{info:t}=e,r="tag"===t.kind?ob.A:oa.A,n="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:B("inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] leading-tight",n),children:[(0,s.jsx)(r,{className:"h-2.5 w-2.5 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:t.label})]})}function ow(e){let{file:t,active:r,onSelect:n}=e,a=P(t.status),{Icon:l,color:o}=ej(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:n,className:B("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:B("h-3.5 w-3.5 shrink-0",o)}),(0,s.jsx)("span",{className:"shrink-0 truncate",style:{color:a.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:a.color},title:a.label,children:a.letter})]})}function oN(e){let{projectId:t}=e,r=(0,eV.kj)(),n=od(e=>e.select),a=od(e=>e.selected),[o,i]=(0,l.useState)([]),[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)(!1),[x,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(50),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)({}),y=(0,l.useRef)(null),w=(0,l.useCallback)(async()=>{try{let e=await N.F.git.log(t,h);i(e.commits),v(e.commits.length>=h),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{m(!0)}},[t,h]);(0,l.useEffect)(()=>{w()},[w]),(0,l.useEffect)(()=>{let e=null,t=S.on("file:changed",t=>{M(t)||(e&&clearTimeout(e),e=setTimeout(()=>{w()},400))}),r=C(S,()=>{w()});return()=>{e&&clearTimeout(e),t(),r()}},[w]),(0,l.useEffect)(()=>{let e=y.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 k=(0,l.useCallback)(e=>{p(t=>t===e?null:e),j(r=>(r[e]||N.F.git.commitFiles(t,e).then(t=>j(r=>({...r,[e]:t.files}))).catch(()=>j(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=x===e.hash,i=e.pushed?"var(--muted-foreground)":"var(--primary)",c=b[e.hash],d=e.refs?e.refs.split(",").map(e=>e.trim()).filter(Boolean).map(oj).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:B("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:()=>k(e.hash),className:B("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 ",q(e.date)]})]}),d.length>0&&(0,s.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:d.map(e=>(0,s.jsx)(oy,{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)(ow,{file:t,active:(null==a?void 0:a.commit)===e.hash&&a.path===t.path,onSelect:()=>n({path:t.path,staged:!1,from:t.from,commit:e.hash})},t.path))})]})]},e.hash)}),g&&(0,s.jsx)("div",{ref:y,className:"h-4"})]})}function ok(e){return/authentication|could not read username|permission denied|publickey|passphrase|\b401\b|\b403\b/i.test(e)}function oS(){var e,t,r;let n=(0,eV.kj)(),a=tq(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),o=od(e=>e.selected),i=od(e=>e.select),c=od(e=>e.clear),[d,u]=(0,l.useState)(null),[m,x]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(""),[v,b]=(0,l.useState)(!1),[j,y]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),[F,D]=(0,l.useState)("changes"),[P,_]=(0,l.useState)(null),[z,O]=(0,l.useState)(""),U=(0,l.useCallback)(async()=>{if(a)try{let e=await N.F.git.status(a);if(!1===e.isRepo){h(!0),u(null),_(null),x(null);return}u(e),h(!1),x(null);let t=await N.F.git.remotes(a);_(t.remotes)}catch(e){x(e instanceof Error?e.message:String(e))}},[a]);(0,l.useEffect)(()=>{U()},[U]),(0,l.useEffect)(()=>{if(!a)return;let e=null,t=S.on("file:changed",t=>{M(t)||(e&&clearTimeout(e),e=setTimeout(()=>{U()},400))}),r=C(S,()=>{U()});return()=>{e&&clearTimeout(e),t(),r()}},[a,U]);let W=null!=(e=null==d?void 0:d.files)?e:[],H=W.filter(e=>L(e.index)),K=W.filter(e=>R(e.workingDir));async function G(e){b(!0),y(null);try{await e(),await U()}catch(e){y(e instanceof Error?e.message:String(e))}finally{b(!1)}}let q=(0,l.useCallback)((e,t)=>{i({path:e.path,staged:t,from:e.from})},[i]);function J(e){G(()=>N.F.git.stage(a,e))}function Z(e){G(()=>N.F.git.unstage(a,e))}async function $(){a&&f.trim()&&await G(async()=>{await N.F.git.commit(a,f),g(""),c()})}function Y(){a&&z.trim()&&G(async()=>{await N.F.git.addRemote(a,z.trim()),O("")})}let X=(null!=(t=null==P?void 0:P.length)?t:0)>0;return a?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)(os.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:n("sc.initRepoDesc")}),(0,s.jsxs)("button",{onClick:function(){G(()=>N.F.git.init(a))},disabled:v,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)(os.A,{className:"h-3.5 w-3.5"}),n(v?"sc.initializing":"sc.initRepo")]}),j&&(0,s.jsx)("p",{className:"max-w-[240px] text-[11px] text-red-400",children:j})]}):(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)(oa.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:n("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:()=>D("changes"),title:n("sc.viewChanges"),className:B("rounded-l p-1","changes"===F?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(ol.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>D("graph"),title:n("sc.viewGraph"),className:B("rounded-r p-1","graph"===F?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(oo.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("button",{onClick:()=>k(!0),title:n("sc.cred.title"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(ec.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>{U()},title:n("sc.refresh"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(nh.A,{className:B("h-3.5 w-3.5",v&&"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)(oa.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)(oi.A,{className:"h-3 w-3"}),d.behind]}),d.ahead>0&&(0,s.jsxs)("span",{className:"flex items-center",children:[(0,s.jsx)(a8.A,{className:"h-3 w-3"}),d.ahead]})]}),(0,s.jsx)("div",{className:"flex-1"}),X&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:()=>void G(()=>N.F.git.pull(a)),disabled:v,title:n("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)(oi.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>void G(()=>N.F.git.push(a)),disabled:v,title:n("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)(a8.A,{className:"h-3.5 w-3.5"})})]})]}),!X&&"changes"===F&&(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)(sa.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{children:n("sc.addRemoteDesc")})]}),(0,s.jsx)("input",{type:"text",value:z,onChange:e=>O(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z.trim()&&Y()},placeholder:n("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:v||!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)(sa.A,{className:"h-3.5 w-3.5"})," ",n(v?"sc.adding":"sc.addRemote")]})]}),"changes"===F&&(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(),$())},placeholder:n("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 $(),disabled:v||!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)(tz.A,{className:"h-3.5 w-3.5"})," ",n("sc.commit")]})]}),j&&(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:[ok(j)?n("sc.authError"):j,ok(j)&&(0,s.jsx)("button",{onClick:()=>k(!0),className:"ml-1 underline hover:text-red-300",children:n("sc.openCreds")})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:"graph"===F?(0,s.jsx)(oN,{projectId:a}):m?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:m}):0===W.length?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:n("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:()=>I(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:[A?(0,s.jsx)(Q.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(V.A,{className:"h-3.5 w-3.5"}),n("sc.staged")]}),(0,s.jsx)("button",{onClick:()=>Z(H.map(e=>e.path)),title:n("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)(oc.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})]}),!A&&(0,s.jsx)(ou,{files:H,group:"staged",selectedPath:(null==o?void 0:o.staged)?o.path:null,onSelect:e=>q(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:()=>T(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:[E?(0,s.jsx)(Q.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(V.A,{className:"h-3.5 w-3.5"}),n("sc.changes")]}),(0,s.jsx)("button",{onClick:()=>J(K.map(e=>e.path)),title:n("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)(aC.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})]}),!E&&(0,s.jsx)(ou,{files:K,group:"changes",selectedPath:o&&!o.staged?o.path:null,onSelect:e=>q(e,!1),onAction:J})]})]})}),w&&(0,s.jsx)(oh,{projectId:a,onClose:()=>k(!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)(oa.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:n("sc.noWorkspace")})]})}var oC=r(34016);function oA(){let e=(0,eV.kj)(),t=tq(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),r=od(e=>e.selected),[n,a]=(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 a(null);let e=!1;return i(!0),d(null),N.F.git.diff(t,r.path,r.staged,r.from,r.commit).then(t=>{e||a({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)(oC.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}):n?(0,s.jsx)(e3,{original:n.original,modified:n.modified,path:n.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)(oC.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 oI=r(6023),oE=r(83599),oT=r(62803),oM=r(28109),oF=r(81208);let oD="text-[var(--muted-foreground)]/40",oP={fresh:"text-emerald-400",stale:"text-amber-400 animate-pulse",down:"text-[var(--destructive)]"};function oL(e){return window[e]}function oR(e){let[t,r]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let t=oL(e);t&&t.get().then(r)},[e]);let n=(0,l.useCallback)(()=>{let t=oL(e);t&&t.toggle().then(r)},[e]);return{available:!!oL(e),on:t,toggle:n}}function o_(e){let{items:t}=e,r=(0,eV.kj)(),[n,a]=(0,l.useState)(!1),o=(0,l.useRef)(null),i=t.filter(e=>e.available),c=i.some(e=>e.alert);(0,l.useEffect)(()=>{if(!n)return;let e=e=>{var t;(null==(t=o.current)?void 0:t.contains(e.target))||a(!1)},t=e=>{"Escape"===e.key&&a(!1)};return document.addEventListener("mousedown",e),window.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("keydown",t)}},[n]);let d=e=>"string"==typeof e.state?e.state:r(e.state?"quick.on":"quick.off"),u="".concat(r("quick.title")," — ").concat(i.map(e=>"".concat(e.label," ").concat(d(e))).join(" \xb7 "));return(0,s.jsxs)("div",{ref:o,className:"relative w-full",children:[(0,s.jsxs)("button",{onClick:()=>a(e=>!e),title:u,"aria-expanded":n,className:B("flex h-12 w-full flex-col items-center justify-center gap-1 transition-colors",c?"text-[var(--destructive)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",n&&"bg-[var(--secondary)]"),children:[(0,s.jsx)(ec.A,{className:"h-5 w-5"}),(0,s.jsx)("span",{className:"flex h-[3px] w-[30px] gap-[2px]",children:i.map(e=>(0,s.jsx)("span",{"data-segment":e.id,className:B("flex-1 rounded-full bg-current",e.color)},e.id))})]}),n&&(0,s.jsxs)("div",{className:"absolute bottom-0 left-full z-[60] ml-1 w-[260px] rounded-lg border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:[(0,s.jsx)("div",{className:"px-3 py-1.5 text-[10px] font-medium uppercase tracking-wider text-[var(--muted-foreground)]",children:r("quick.panelTitle")}),i.map((e,t)=>{let r=e.icon,n=(0,s.jsxs)("div",{className:"min-w-0 flex-1 text-left",children:[(0,s.jsx)("div",{className:"truncate text-xs text-[var(--foreground)]",children:e.title}),(0,s.jsx)("div",{className:"text-[10px] text-[var(--muted-foreground)]",children:e.subtitle})]}),a=t>0&&e.onToggle&&!i[t-1].onToggle?(0,s.jsx)("div",{className:"my-1 border-t border-[var(--border)]"}):null;if(!e.onToggle)return(0,s.jsxs)("div",{"data-row":e.id,className:"flex items-center gap-3 px-3 py-2",children:[(0,s.jsx)(r,{className:B("h-4 w-4 shrink-0",e.color)}),n,(0,s.jsx)("span",{className:B("shrink-0 text-[11px]",e.color),children:d(e)})]},e.id);let l=!0===e.state,o=l?su.A:sd.A;return(0,s.jsxs)("div",{children:[a,(0,s.jsxs)("button",{"data-row":e.id,role:"switch","aria-checked":l,onClick:e.onToggle,className:"flex w-full items-center gap-3 px-3 py-2 transition-colors hover:bg-[var(--secondary)]",children:[(0,s.jsx)(r,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),n,(0,s.jsx)(o,{className:B("h-5 w-5 shrink-0",l?e.color:"text-[var(--muted-foreground)]")})]})]},e.id)})]})]})}let oz=null;function oO(){return oz?"[".concat(oz,"] "):""}let oU=["explorer","source-control","sessions","skills","channels","evolution","cron"],oB=null;function oW(e){var t;let{linkState:r}=e,n=(0,eV.kj)(),a=tq(e=>e.activeProject),c=tq(e=>e.openFolder),d=rE(e=>e.isStreaming),[u,m]=(0,l.useState)(()=>localStorage.getItem("halo_sidebar_tab")||"explorer"),[x,p]=(0,l.useState)(()=>"false"!==localStorage.getItem("halo_sidebar_open")),[h,f]=(0,l.useState)("sessions"===u);"sessions"!==u||h||f(!0);let[g,v]=(0,l.useState)(""),[j,y]=(0,l.useState)(!1),{items:w,notifyOnFinish:k}=function(e){let t=(0,eV.kj)(),r=oR("haloPin"),n=oR("haloAwake"),a=!!window.haloNotify||"Notification"in window,[s,o]=(0,l.useState)(()=>"true"===localStorage.getItem("halo_notify_on_finish")),i=(0,l.useCallback)(async()=>{let e=!!window.haloNotify;if(!s&&!e&&"Notification"in window){let e=Notification.permission;if("default"===e&&(e=await Notification.requestPermission()),"granted"!==e)return}o(e=>{let t=!e;try{localStorage.setItem("halo_notify_on_finish",String(t))}catch(e){}return t})},[s]);return{items:[{id:"network",icon:"down"===e?oI.A:oE.A,label:t("quick.network"),title:t("quick.networkTitle"),subtitle:t("quick.networkSub"),state:t("link.".concat(e)),color:oP[e],available:!0,alert:"down"===e},{id:"notify",icon:oT.A,label:t("quick.notify"),title:t("quick.notifyTitle"),subtitle:t("quick.notifySub"),state:s,color:s?"text-[var(--primary)]":oD,onToggle:()=>{i()},available:a},{id:"pin",icon:oM.A,label:t("quick.pin"),title:t("quick.pinTitle"),subtitle:t("quick.pinSub"),state:r.on,color:r.on?"text-[var(--primary)]":oD,onToggle:r.toggle,available:r.available},{id:"awake",icon:oF.A,label:t("quick.awake"),title:t("quick.awakeTitle"),subtitle:t("quick.awakeSub"),state:n.on,color:n.on?"text-amber-400":oD,onToggle:n.toggle,available:n.available}],notifyOnFinish:s}}(r);(0,l.useEffect)(()=>{let e=null==a?void 0:a.name;document.title=oO()+(e?"".concat(d?"● ":"","Halo — ").concat(e):"Halo")},[d,null==a?void 0:a.name]),(0,l.useEffect)(()=>{if(k){var e;return e=e=>{if(!function(){try{let e=window.AudioContext||window.webkitAudioContext;if(!e)return;oB||(oB=new e);let t=oB;t.resume();let r=t.currentTime;[[880,0],[1174.66,.15]].forEach(e=>{let[n,a]=e,s=t.createOscillator(),l=t.createGain();s.type="sine",s.frequency.value=n,l.gain.setValueAtTime(1e-4,r+a),l.gain.exponentialRampToValueAtTime(.2,r+a+.02),l.gain.exponentialRampToValueAtTime(1e-4,r+a+.35),s.connect(l).connect(t.destination),s.start(r+a),s.stop(r+a+.4)})}catch(e){}}(),document.hasFocus())return;let t=null==a?void 0:a.name,r=t?"Halo — ".concat(t):"Halo",s=e.getState().sessionId,l=s?aM.get(s):void 0,o=l?n("status.notifyBodySession",{title:l}):n("status.notifyBody"),i=window.haloNotify;if(i)i.notify({title:r,body:o});else if("Notification"in window&&"granted"===Notification.permission){let e=new Notification(r,{body:o});e.onclick=()=>{window.focus(),e.close()}}},ry.add(e),()=>{ry.delete(e)}}},[k,null==a?void 0:a.name,n]),(0,l.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("folder"),t=async(e,t)=>{try{let n=await N.F.fs.resolveWorkspace(e);c(n.path,n.id),v(n.path),I(n.path);try{localStorage.setItem("halo_last_folder",n.path)}catch(e){}var r=n.path;let a=se().filter(e=>e!==r);if(a.unshift(r),st(a.slice(0,8)),t||n.path!==e){let e=new URL(window.location.href);e.searchParams.set("folder",n.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=()=>N.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)(()=>{tx()},[]);let A=(0,l.useRef)(!1);(0,l.useEffect)(()=>{function e(e){A.current||e.preventDefault()}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let E=(0,l.useCallback)(()=>{let e=b.getState(),t=e.activeTab;if(!t)return!1;let r=e.tabs.find(e=>e.path===t);return(async()=>{(null==r||!r.modified||await G('"'.concat(r.path.split("/").pop(),'" has unsaved changes. Close anyway?')))&&e.closeTab(t)})(),!0},[]);(0,l.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&"p"===e.key&&(e.preventDefault(),y(e=>!e)),(e.metaKey||e.ctrlKey)&&"`"===e.key){e.preventDefault();let t=b.getState();t.setBottomTab("terminal"===t.bottomTab?"chat":"terminal")}!e.altKey||"KeyW"!==e.code||e.metaKey||e.ctrlKey||(e.preventDefault(),E())}return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[E]),(0,l.useEffect)(()=>{let e=window.haloCloseShortcut;e&&e.onTrigger(()=>{E()||e.closeWindow()})},[E]),(0,l.useEffect)(()=>{function e(e){if("Escape"!==e.key||!b.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}j||b.getState().setMaximized(!1)}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j]),(0,l.useEffect)(()=>{let e=e=>{let t=e.detail;if(!(null==t?void 0:t.tab))return;let{bottomFloating:r}=b.getState();r&&"explorer"===t.tab||(m(t.tab),p(!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&&F(r)};return window.addEventListener("halo:open-workspace",e),()=>window.removeEventListener("halo:open-workspace",e)},[]),(0,l.useEffect)(()=>{localStorage.setItem("halo_sidebar_tab",u),localStorage.setItem("halo_sidebar_open",String(x))},[u,x]);let T=(0,l.useRef)(!1);async function F(e){let t=e.trim();if(!t||T.current)return;T.current=!0;try{let e=await N.F.fs.exists(t);if(!e.exists||!e.isDirectory){window.alert("Workspace not found: ".concat(t)),T.current=!1;return}}catch(e){window.alert(e instanceof Error?e.message:"Failed to validate path"),T.current=!1;return}let r=b.getState().tabs.filter(e=>e.modified);if(r.length>0){let e=r.map(e=>e.path.split("/").pop()).join(", ");if(!await G("Unsaved changes in ".concat(e," will be lost. Switch workspace anyway?"))){T.current=!1;return}}A.current=!0;try{localStorage.setItem("halo_last_folder",t)}catch(e){}let n=new URL(window.location.href);n.searchParams.set("folder",t),window.location.href=n.toString()}let D=(0,l.useCallback)(async e=>{let t=null==a?void 0:a.id;if(t){if(b.getState().tabs.find(t=>t.path===e))return void b.getState().setActiveTab(e);try{let r=await N.F.files.read(e,t),n=Z(e);b.getState().openFile(e,r.content,n)}catch(e){console.error("[QuickOpen] Failed to read file:",e)}}},[a]),P=[{id:"explorer",icon:sr.A,label:n("nav.explorer")},{id:"source-control",icon:oa.A,label:n("nav.sourceControl")},{id:"sessions",icon:nf.A,label:n("nav.sessions")},{id:"skills",icon:sc.A,label:"Skills"},{id:"management",icon:np.A,label:"Agents"},{id:"channels",icon:lr.A,label:n("nav.channels")},{id:"evolution",icon:nY.A,label:"Evolution"},{id:"cron",icon:l2.A,label:"Cron"},{id:"settings",icon:sB.A,label:n("nav.settings"),position:"bottom"}],_=null!=(t=null==a?void 0:a.id)?t:null;(0,l.useEffect)(()=>{if(!_)return;let{setForProject:e,clearProject:t,setRepoStatus:r,clearRepoStatus:n}=z.getState(),a=!1;async function s(){try{let[n,s]=await Promise.all([N.F.git.status(_),N.F.git.ignored(_)]);if(!1===n.isRepo){a||(t(_),r(_,!1));return}a||(e(_,function(e,t){let r=new Map,n=new Map;for(let t of e){var a,s;let e=(a=t.index,R(s=t.workingDir)?"?"===s?"?":s:L(a)?a:"");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("/"),a=n.get(r);void 0===a?n.set(r,e):a!==e&&"*"!==a&&n.set(r,"*")}}return{files:r,dirs:n,ignored:new Set(t)}}(n.files,s.ignored)),r(_,!0))}catch(e){a||(t(_),r(_,!1))}}s();let l=null,o=S.on("file:changed",e=>{M(e)||(l&&clearTimeout(l),l=setTimeout(()=>{s()},400))}),i=C(S,()=>{s()});return()=>{a=!0,l&&clearTimeout(l),o(),i(),t(_),n(_)}},[_]);let O=z(e=>{var t;return null!=(t=_?e.repoStatus[_]:void 0)?t:"unknown"}),U=P.filter(e=>"bottom"!==e.position).filter(e=>"source-control"!==e.id||!1!==O),W=P.filter(e=>"bottom"===e.position),H=b(e=>e.maximized),K=b(e=>e.bottomFloating),q=b(e=>e.bottomMaximized),J=x&&!H,$=oU.includes(u)&&x&&"explorer"!==u,Y="explorer"===u;(0,l.useEffect)(()=>{!1===O&&"source-control"===u&&m("explorer")},[O,u]);let[V]=(0,l.useState)(()=>{if("undefined"==typeof document)return null;let e=document.createElement("div");return e.className="h-full",e}),Q=(0,l.useRef)(null),[X,ee]=(0,l.useState)(null),[et,er]=(0,l.useState)(null),[en,ea]=(0,l.useState)(null),es=K?en:q?et:X;(0,l.useLayoutEffect)(()=>{V&&es&&V.parentElement!==es&&es.appendChild(V)},[V,es]);let el=e=>{let t=e.icon,r=u===e.id;return(0,s.jsxs)("button",{onClick:()=>{var t;return t=e.id,void(b.getState().maximized&&b.getState().setMaximized(!1),u===t&&x?p(!1):(m(t),p(!0)))},title:e.label,className:B("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)};return(0,s.jsxs)("div",{className:"flex h-full",children:[(0,s.jsxs)("div",{className:B("flex w-12 shrink-0 flex-col items-center border-r border-[var(--border)] bg-[var(--card)] py-2",H&&"hidden"),children:[U.map(el),(0,s.jsx)("div",{className:"flex-1"}),W.map(el),(0,s.jsx)(o_,{items:w})]}),(0,s.jsx)("div",{className:B("flex min-w-0 flex-1",!Y&&"hidden",H&&"fixed inset-0 z-40 bg-[var(--background)]"),children:(0,s.jsx)(oH,{showSidebar:J,sidebar:(0,s.jsx)(ss,{projectId:_,pathInput:g,onPathInputChange:v,onOpenFolder:function(){F(g)},onOpenPath:F,activeProject:a}),main:(0,s.jsx)(oK,{projectId:_,showBottom:!K&&!H,bottomSlotRef:ee})})}),h&&(0,s.jsx)("div",{className:B("flex min-w-0 flex-1",("sessions"!==u||H)&&"hidden"),children:(0,s.jsx)(oH,{autoSaveId:"halo-h-sessions",showSidebar:x,sidebar:(0,s.jsx)(nk,{}),main:(0,s.jsx)(sU,{visible:"sessions"===u&&!H})})}),!Y&&"sessions"!==u&&!H&&($?(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"===u&&(0,s.jsx)(oS,{}),"skills"===u&&(0,s.jsx)(sg,{}),"channels"===u&&(0,s.jsx)(lB,{}),"evolution"===u&&(0,s.jsx)(lX,{}),"cron"===u&&(0,s.jsx)(on,{})]})}),(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)(oG,{activeTab:u})})]}):(0,s.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,s.jsx)(oG,{activeTab:u})})),j&&(0,s.jsx)(a4,{onSelect:D,onClose:()=>y(!1)}),K&&(0,s.jsx)(a3,{slotRef:ea,dragHandleRef:Q}),q&&!K&&(0,s.jsx)("div",{ref:er,className:"fixed inset-0 z-50 bg-[var(--background)]"}),V&&(0,o.createPortal)((0,s.jsx)(a0,{floating:K,dragHandleRef:Q}),V)]})}function oH(e){let{showSidebar:t,sidebar:r,main:n,autoSaveId:a="halo-h-sidebar"}=e,o=(0,l.useRef)(null),c=(0,l.useRef)([22,78]);return(0,l.useEffect)(()=>{let e=o.current;if(e)if(t)e.setLayout(c.current);else{let t=e.getLayout();t[0]>0&&(c.current=t),e.setLayout([0,100])}},[t]),(0,s.jsxs)(i.YZ,{ref:o,direction:"horizontal",autoSaveId:a,className:"flex-1",children:[(0,s.jsx)(i.Zk,{defaultSize:22,minSize:0,maxSize:40,collapsible:!0,children:(0,s.jsx)("div",{className:B("h-full overflow-hidden",!t&&"hidden"),children:r})}),(0,s.jsx)(i.TW,{className:B("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:n})]})}function oK(e){let{projectId:t,showBottom:r,bottomSlotRef:n}=e,a=(0,l.useRef)(null),o=(0,l.useRef)([65,35]);return(0,l.useEffect)(()=>{let e=a.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:a,direction:"vertical",autoSaveId:"halo-v-editor",className:"h-full",children:[(0,s.jsx)(i.Zk,{defaultSize:65,minSize:20,children:(0,s.jsx)(t0,{projectId:t,mode:"editor-only"})}),(0,s.jsx)(i.TW,{className:B("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:n,className:B("h-full",!r&&"hidden")})})]})}function oG(e){let{activeTab:t}=e;return"source-control"===t?(0,s.jsx)(oA,{}):"management"===t?(0,s.jsx)(sP,{}):"skills"===t?(0,s.jsx)(sR,{}):"channels"===t?(0,s.jsx)(lW,{}):"evolution"===t?(0,s.jsx)(lJ,{}):"cron"===t?(0,s.jsx)(l6,{}):"settings"===t?(0,s.jsx)(s0,{}):null}var oq=r(45966),oJ=r(42883);let oZ=/<<<CAPTURE>>>/,o$=/<<<SHOW:([\s\S]*?)>>>/g;async function oY(e,t,r){let n=t.getState(),a=window,s=n.captureSource;if(!s)return;let l="camera"===s.kind;if(!(l?a.haloCamera:a.haloCapture)||!r.some(e=>oZ.test(e.content)))return;let o=tq.getState().activeProject,i=n.sessionId;if(!o||!i)return;let c=W(),d="image/jpeg",u=null;try{u=l?await a.haloCamera.snap(s.id||void 0):await a.haloCapture.grab(s.id)}catch(e){u=null}let m=("undefined"!=typeof localStorage&&"zh"===localStorage.getItem("halo_lang")?oJ.zh:oq.en)[l?"capture.cameraFailNote":"capture.failNote"].replace("{name}",s.name),x=l?"[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(s.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.]');n.addMessage({id:W(),role:"user",content:u?"[\uD83D\uDCF7 ".concat(s.name,"]"):m,timestamp:Date.now(),clientMsgId:c,...u?{localImages:["data:".concat(d,";base64,").concat(u)]}:{}}),n.addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let p=n.selectedAgentId;e.send({type:"chat",sessionId:i,projectId:o.id,message:u?l?"[Photo from the camera]":'[Screenshot of "'.concat(s.name,'"]'):x,clientMsgId:c,..."default"!==p?{agentId:p}:{},...u?{images:[{data:u,mimeType:d}]}:{}})}function oV(e){let{onSuccess:t}=e,[r,n]=(0,l.useState)(""),[a,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"),n(""))}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)(ox.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=>n(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)]"}),a&&(0,s.jsx)("p",{className:"mt-2 text-xs text-red-400",children:a}),(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 oQ(){let{linkState:e}=function(){let[e,t]=(0,l.useState)(!1),[r,n]=(0,l.useState)("down"),a=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(a.current)return;a.current=!0,S.connect();let e=[S.on("_connected",()=>{t(!0),n("fresh");let e=tq.getState().activeProject;(null==e?void 0:e.id)&&r_.getState().projectId===e.id&&S.send({type:"subscribe",sessionId:function(){var e;let{tabs:t,activeTabId:r}=r_.getState();for(let e of t)e.tabId!==r&&r1(e);return null!=(e=rA().getState().sessionId)?e:""}(),projectId:e.id})}),S.on("_disconnected",()=>{t(!1),n("down")}),function(e){let t=[];t.push(e.on("_chat_send_failed",e=>{e.clientMsgId&&rk(t=>t.getState().markChatSendFailed(e.clientMsgId))})),t.push(e.on("_disconnected",()=>void(rc=Date.now())));let r=setInterval(()=>{rk(e=>e.getState().convergeStaleStreaming())},5e3);t.push(()=>clearInterval(r)),t.push(e.on("chat:thinking",e=>{var t;null==(t=r0(e.sessionId))||t.getState().appendThinking(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:stream",e=>{var t;null==(t=r0(e.sessionId))||t.getState().updateLastAssistant(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:complete",t=>{let r=r0(t.sessionId);if(!r)return;let n=r.getState();n.completeAgentStreaming(void 0,void 0,t.batchBoundary);let a=n.takeRoundReplies();if(r===rA()){oY(e,r,a);for(let e of a)for(let t of e.content.matchAll(o$)){let e=t[1].trim();e&&e0(e)}}})),t.push(e.on("chat:stopped",e=>{var t;null==(t=r0(e.sessionId))||t.getState().completeAgentStreaming()})),t.push(e.on("error",e=>{var t,r;let n=null==(t=r0(e.sessionId))?void 0:t.getState();if(!n)return;let a=e.code?null!=(r=e.error)?r:"":e.error?"Error: ".concat(e.error):"An unknown error occurred.";n.addMessage({id:W(),role:"system",content:a,timestamp:Date.now(),agentName:e.agentName}),e.taskId||n.completeAgentStreaming(e.agentName)})),t.push(e.on("chat:followup",e=>{var t;let r=null==(t=r0(e.sessionId))?void 0:t.getState();if(r){if(e.replay){let t=r.takeReplaySnapshot();t?r.setMessages(t):r.completeAgentStreaming(e.agentName)}else r.completeAgentStreaming(e.agentName);r.addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName})}})),t.push(e.on("chat:user",e=>{var t;null==(t=r0(e.sessionId))||t.getState().addMessage({id:W(),role:"user",content:e.text,timestamp:Date.now()})})),t.push(e.on("chat:usage",e=>{var t;let r=null==(t=r0(e.sessionId,!1))?void 0:t.getState();r&&(r.setTokenUsage(e.contextTokens,e.outputTokens),e.usage&&r.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:switched",t=>{if(!t.sessionId)return;if(t.clientMsgId&&t.fromSessionId){var r;null==(r=rX(t.fromSessionId))||r.getState().dropOptimisticSend(t.clientMsgId)}let n=r$(t.sessionId),a=tq.getState().activeProject;n&&a&&e.send({type:"subscribe",sessionId:n,projectId:a.id})})),t.push(e.on("session:compacted",e=>{var t,r;let n=r0(e.sessionId);if(!n)return;let a=null!=(t=e.message)?t:"Context compacted",l=n.getState();l.setCompacting(!1),s(n),l.setTokenUsage(null!=(r=e.contextTokens)?r:0,l.outputTokens),l.addMessage({id:W(),role:"system",content:a,timestamp:Date.now()})}));let n=new Map;function a(e){s(e),n.set(e,setTimeout(()=>{n.delete(e),e.getState().setCompacting(!1)},6e4))}function s(e){let t=n.get(e);void 0!==t&&(clearTimeout(t),n.delete(e))}for(let r of(t.push(()=>{for(let e of n.values())clearTimeout(e);n.clear()}),t.push(e.on("chat:system",e=>{let t=r0(e.sessionId);if(!t)return;let r=t.getState(),n=e.text;if(!e.taskId){let e=n.match(/^Compacting context \((\d+)K tokens\)…$/);if(e&&(r.setCompacting(!0),a(t),"0"===e[1])){let e=t.getState().contextTokens;e>0&&(n="Compacting context (~".concat(Math.round(e/1e3),"K tokens)…"))}}r.addMessage({id:W(),role:"system",content:n,timestamp:Date.now(),taskId:e.taskId,agentName:e.agentName})})),t.push(e.on("chat:queued",e=>{var t,r;null==(t=r0(e.sessionId))||t.getState().addMessage({id:W(),role:"system",content:null!=(r=e.message)?r:"Message queued.",timestamp:Date.now()})})),["compact:progress","compact:started","compact:summarizing"]))t.push(e.on(r,e=>{let t=r0(e.sessionId,!1);t&&(t.getState().setCompacting(!0),a(t))}));return t.push(e.on("compact:done",e=>{let t=r0(e.sessionId,!1);t&&(t.getState().setCompacting(!1),s(t))})),()=>t.forEach(e=>e())}(S),function(e){let t=[];return t.push(e.on("agent:start",e=>{var t;let r=null==(t=r0(e.sessionId))?void 0:t.getState();r&&r.addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName,taskId:e.taskId})})),t.push(e.on("agent:done",e=>{var t;let r=null==(t=r0(e.sessionId))?void 0:t.getState();r&&r.completeAgentStreaming(e.agentName,e.taskId)})),t.push(e.on("agent:context",e=>{var t,r;let n=null==(t=r0(e.sessionId))?void 0:t.getState();n&&n.addMessage({id:W(),role:"system",content:"[System Prompt: ".concat(null!=(r=e.agentName)?r:"Agent","]"),timestamp:Date.now(),agentName:e.agentName,taskId:e.taskId,systemPrompt:e.systemPrompt})})),t.push(e.on("agent:tool_call",e=>{var t,r,n,a;let s=null==(t=r0(e.sessionId))?void 0:t.getState();if(!s)return;let l=null!=(r=e.agentName)?r:"default",o="string"==typeof e.input?e.input:JSON.stringify(null!=(n=e.input)?n:{});s.addToolCallToLastAssistant({name:null!=(a=e.tool)?a:"",input:o,toolUseId:e.toolUseId},l,e.taskId,e.turnId)})),t.push(e.on("agent:tool_result",e=>{var t,r,n;let a=null==(t=r0(e.sessionId))?void 0:t.getState();if(!a)return;let s=null!=(r=e.agentName)?r:"default",l="string"==typeof e.result?e.result:JSON.stringify(null!=(n=e.result)?n:"");a.updateLastToolCallResult(l,s,e.taskId,e.toolUseId)})),()=>t.forEach(e=>e())}(S),function(e){let t=[];return t.push(e.on("file:changed",e=>{let t=b.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())}(S),function(e){let t=[];return t.push(e.on("state:snapshot",e=>{var t,r,n;let{snapshot:a}=e,s=r0(a.sessionId,!1);if(!s)return;let l=s.getState();if(a.sessionId){let e=null!=(t=a.archiveCount)?t:0;!function(e,t){var r,n;let a=rW(t=>t.store===e);if(!a)return;let s=Math.max(null!=(r=a.archiveCount)?r:0,t);(a.loading||s!==(null!=(n=a.archiveCount)?n:0))&&rH(a.tabId,{loading:!1,archiveCount:s})}(s,e),s===rA()&&rF(a.sessionId,e)}a.agentId&&l.setSelectedAgentId(a.agentId),void 0!==a.accessLevel&&l.setAccessLevel(null!=(r=a.accessLevel)?r:"full");let o=s.getState().messages.some(e=>e.streaming&&!ri(e)),i=null!=(n=a.recentMessages)?n:a.messages;i&&a.sessionId&&l.noteSnapshot(a.sessionId,i),!o&&i&&i.length>0&&l.setMessages(i),"number"==typeof a.maxContextTokens&&a.maxContextTokens>0&&l.setMaxContextTokens(a.maxContextTokens)})),t.push(e.on("listener:released",t=>{let{sessionId:r}=t,n=tq.getState().activeProject;if(!(null==n?void 0:n.id)||!r)return;let a=rX(r);if(a){if(a!==rA())return void function(e){let{tabs:t,activeTabId:r}=r_.getState(),n=t.find(t=>t.sessionId===e);n&&n.tabId!==r&&r1(n)}(r);e.send({type:"subscribe",sessionId:r,projectId:n.id})}})),t.push(e.on("session:changed",()=>nd())),t.push(C(e,()=>nd())),t.push(e.on("goal:changed",()=>{var e;let t=null==(e=tq.getState().activeProject)?void 0:e.id;t&&r2(t),nd()})),t.push(e.on("extension:changed",e=>{let{extensions:t,errors:r}=e;return tu({extensions:t,errors:r})})),t.push(C(e,()=>{N.F.extensions.list().then(tu).catch(()=>{})})),t.push(e.on("models:changed",()=>n2())),t.push(C(e,()=>n2())),()=>t.forEach(e=>e())}(S)],r=()=>S.reconnectIfStale(0);window.addEventListener("online",r);let s=0,l=()=>{if(document.hidden){s=Date.now();return}s>0&&Date.now()-s>=3e5&&S.reconnectIfStale(45e3),s=0};document.addEventListener("visibilitychange",l);let o=setInterval(()=>{n(S.connected?S.lastReceiveAgeMs>45e3?"stale":"fresh":"down")},5e3);return()=>{e.forEach(e=>e()),window.removeEventListener("online",r),document.removeEventListener("visibilitychange",l),clearInterval(o),S.disconnect(),a.current=!1}},[]),{connected:e,linkState:r,send:(0,l.useCallback)(e=>{S.send(e)},[])}}(),[t,r]=(0,l.useState)("checking");(0,l.useEffect)(()=>{fetch("/api/auth/check",{credentials:"include"}).then(async e=>{let t=await e.json().catch(()=>null);var n=null==t?void 0:t.badge;let a="string"==typeof n&&n.trim()?n.trim():null;a&&!oz&&(oz=a,document.title=oO()+document.title,function(e){let t=document.createElement("canvas");t.width=64,t.height=64;let r=t.getContext("2d");if(!r)return;r.beginPath(),r.moveTo(14.08,0),r.arcTo(64,0,64,64,14.08),r.arcTo(64,64,0,64,14.08),r.arcTo(0,64,0,0,14.08),r.arcTo(0,0,64,0,14.08),r.closePath();let n=r.createLinearGradient(0,0,64,64);n.addColorStop(0,"#0e1430"),n.addColorStop(1,"#070a16"),r.fillStyle=n,r.fill(),r.clip();for(let[e,t]of[[8.96,.55],[13.44,.3]])r.beginPath(),r.arc(32,21.12,e,0,2*Math.PI),r.strokeStyle="rgba(125, 140, 255, ".concat(t,")"),r.lineWidth=2.24,r.stroke();let a=r.createRadialGradient(32,21.12,0,32,21.12,6.4);a.addColorStop(0,"#d8e6ff"),a.addColorStop(1,"#8aa6ff"),r.beginPath(),r.arc(32,21.12,6.4,0,2*Math.PI),r.fillStyle=a,r.fill();r.fillStyle="#e8401c",r.fillRect(0,64-26.88,64,26.88),r.fillStyle="#ffffff",r.textAlign="center",r.textBaseline="middle";let s=Math.round(22.0416);r.font="bold ".concat(s,"px system-ui, sans-serif");for(;s>8&&r.measureText(e).width>58.88;)s-=1,r.font="bold ".concat(s,"px system-ui, sans-serif");r.fillText(e,32,51.56),document.querySelectorAll('link[rel="icon"]').forEach(e=>e.remove());let l=document.createElement("link");l.rel="icon",l.type="image/png",l.href=t.toDataURL("image/png"),document.head.appendChild(l)}(a.slice(0,4))),r5.getState().setEnabled(e.ok&&(null==t?void 0:t.goalModeEnabled)===!0),r(e.ok?"authenticated":"login")}).catch(()=>{r("login")})},[]),(0,l.useEffect)(()=>S.on("_auth_expired",()=>{r("login")}),[]);let n=(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)(oV,{onSuccess:n}):(0,s.jsx)("div",{className:"h-screen w-screen overflow-hidden bg-[var(--background)]",children:(0,s.jsx)(oW,{linkState:e})})}},27173:(e,t,r)=>{"use strict";r.d(t,{SQ:()=>o,Tv:()=>s,_H:()=>l,dj:()=>a});var n=r(54604);let a=["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:[...a,...s,...l],Component:(0,n.lazy)(()=>r.e(220).then(r.bind(r,62839)).then(e=>({default:e.MediaPreview})))}},37050:(e,t,r)=>{"use strict";r.d(t,{IB:()=>d,NU:()=>i,no:()=>c});var n=r(41440),a=r(54604),s=r(48434),l=r(90302),o=r(17119);let i=(0,a.createContext)(null);function c(e){let{name:t,downloadUrl:r,onOpenAsText:c,extraToolbar:u,loading:m,error:x,children:p}=e,h=(0,o.kj)(),f=(0,a.useContext)(i);return(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-8 shrink-0 items-center gap-2 border-b border-[var(--border)] bg-[var(--card)] px-3",children:[(0,n.jsx)("span",{className:"truncate text-xs text-[var(--muted-foreground)]",children:t}),(0,n.jsx)("div",{className:"flex-1"}),u,f,c&&(0,n.jsxs)(d,{onClick:c,title:h("editor.openAsText"),children:[(0,n.jsx)(s.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:h("editor.openAsText")})]}),(0,n.jsxs)("a",{href:r,download:!0,className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:h("editor.download"),children:[(0,n.jsx)(l.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:h("editor.download")})]})]}),(0,n.jsx)("div",{className:"relative min-h-0 flex-1",children:x?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-red-400",children:x}):(0,n.jsxs)(n.Fragment,{children:[p,m&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-[var(--background)]/80 text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})]})})]})}function d(e){let{onClick:t,title:r,children:a}=e;return(0,n.jsx)("button",{onClick:t,title:r,className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:a})}},44652:(e,t,r)=>{Promise.resolve().then(r.bind(r,17851))}},e=>{e.O(0,[772,560,422,989,946,698,358],()=>e(e.s=44652)),_N_E=e.O()}]);
|