@turmind/halo 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/admin-out/404.html +1 -1
  2. package/admin-out/_next/static/chunks/212-394c4fd40216e633.js +1 -0
  3. package/admin-out/_next/static/chunks/220.e5a2532bda77e816.js +1 -0
  4. package/admin-out/_next/static/chunks/4-e7ba0b1ced30190b.js +1 -0
  5. package/admin-out/_next/static/chunks/442.68ed26e27eb1d84f.js +1 -0
  6. package/admin-out/_next/static/chunks/515.4d98fae302278913.js +1 -0
  7. package/admin-out/_next/static/chunks/896.ed21ec1e0846d20d.js +1 -0
  8. package/admin-out/_next/static/chunks/935.543aeec8456b6061.js +1 -0
  9. package/admin-out/_next/static/chunks/app/page-86cb00582129ae76.js +1 -0
  10. package/admin-out/_next/static/chunks/webpack-fc1574554e7b1108.js +1 -0
  11. package/admin-out/_next/static/css/0d0ca7b3c8cc5562.css +3 -0
  12. package/admin-out/index.html +1 -1
  13. package/admin-out/index.txt +5 -5
  14. package/bundled-docs/design/agent.md +13 -1
  15. package/bundled-docs/design/agentcore.md +10 -0
  16. package/bundled-docs/design/architecture.md +28 -29
  17. package/bundled-docs/design/background-dispatch.md +30 -43
  18. package/bundled-docs/design/cron.md +19 -4
  19. package/bundled-docs/design/evolution.md +18 -2
  20. package/bundled-docs/design/feishu.md +19 -6
  21. package/bundled-docs/design/goal-mode.md +2 -2
  22. package/bundled-docs/design/halo-city.md +7 -0
  23. package/bundled-docs/design/session.md +53 -3
  24. package/bundled-docs/design/slack.md +20 -6
  25. package/bundled-docs/design/storage.md +39 -2
  26. package/bundled-docs/design/telegram.md +20 -8
  27. package/bundled-docs/design/web.md +1 -0
  28. package/bundled-docs/design/wechat.md +13 -17
  29. package/bundled-docs/design/ws.md +56 -13
  30. package/bundled-docs/dev/add-channel.md +49 -37
  31. package/bundled-docs/dev/api.md +158 -38
  32. package/bundled-docs/dev/deploy.md +48 -0
  33. package/bundled-docs/dev/desktop-packaging.md +41 -7
  34. package/bundled-docs/dev/env.md +3 -0
  35. package/bundled-docs/dev/previews.md +58 -3
  36. package/bundled-docs/dev/tools.md +13 -4
  37. package/bundled-docs/guide/channels/wechat.md +3 -3
  38. package/bundled-docs/guide/chat.md +1 -1
  39. package/bundled-docs/guide/cli.md +24 -5
  40. package/bundled-docs/guide/workspace.md +2 -2
  41. package/bundled-docs/requirements/chat.md +11 -2
  42. package/bundled-docs/requirements/editor.md +5 -2
  43. package/bundled-docs/requirements/explorer.md +1 -0
  44. package/bundled-docs/requirements/session.md +4 -3
  45. package/bundled-docs/requirements/settings.md +8 -0
  46. package/bundled-docs/requirements/source-control.md +1 -0
  47. package/dist/index.js +14092 -12842
  48. package/package.json +4 -1
  49. package/templates/agents/__apply_agent__/agent.yaml +1 -1
  50. package/templates/agents/__evo_agent__/agent.yaml +1 -1
  51. package/templates/agents/__score__/agent.yaml +1 -1
  52. package/templates/agents/deep-executor/agent.yaml +1 -1
  53. package/templates/agents/default/agent.yaml +1 -1
  54. package/templates/agents/goal/agent.yaml +1 -1
  55. package/templates/schema.sql +8 -10
  56. package/templates/skills/agent/SKILL.md +2 -2
  57. package/admin-out/_next/static/chunks/212-e217e00ce6cc2bdc.js +0 -1
  58. package/admin-out/_next/static/chunks/220.3dc41cd6269b88e6.js +0 -1
  59. package/admin-out/_next/static/chunks/397-fc5a406d80d46ca7.js +0 -1
  60. package/admin-out/_next/static/chunks/442.f4302087bddb1ec1.js +0 -1
  61. package/admin-out/_next/static/chunks/app/page-f8208e0c7f315faa.js +0 -1
  62. package/admin-out/_next/static/chunks/webpack-47520cdc55be63e7.js +0 -1
  63. package/admin-out/_next/static/css/80eca65cb72e5c69.css +0 -3
  64. /package/admin-out/_next/static/{WvYu_osMZVpohYN4ntkpS → lOrGs0dR-jmXz9PgabRBc}/_buildManifest.js +0 -0
  65. /package/admin-out/_next/static/{WvYu_osMZVpohYN4ntkpS → lOrGs0dR-jmXz9PgabRBc}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{46601:(e,t,r)=>{Promise.resolve().then(r.bind(r,90207))},89759:(e,t,r)=>{"use strict";r.d(t,{SQ:()=>o,Tv:()=>n,_H:()=>l,dj:()=>s});var a=r(43853);let s=["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"],n=["mp4","webm","ogg","mov","avi","mkv"],l=["mp3","wav","flac","aac","m4a","wma"],o={id:"media",extensions:[...s,...n,...l],Component:(0,a.lazy)(()=>r.e(200).then(r.bind(r,21200)).then(e=>({default:e.MediaPreview})))}},90207:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>nR});var a,s,n=r(69625),l=r(43853),o=r(52992),i=r(10842),c=r(48476);let d=1;function u(){return"g".concat(d++)}function m(e){let t=e.groups[e.activeGroupIdx];if(!t)return{tabs:[],activeTab:null};let r=[];for(let a of t.tabs){let t=e.buffers[a];t&&r.push(t)}return{tabs:r,activeTab:t.activeTab}}function x(){return(0,c.v)((e,t)=>({buffers:{},groups:[{id:u(),tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,fileTree:null,modifiedPaths:new Set,rejectedFile:null,bottomTab:"chat",maximized:"true"===localStorage.getItem("halo_editor_maximized"),bottomFloating:"true"===sessionStorage.getItem("halo_bottom_floating"),bottomMaximized:!1,bottomFloatRect:(()=>{let e=sessionStorage.getItem("halo_bottom_float_rect");if(e)try{return JSON.parse(e)}catch(e){}return{x:Math.max(0,window.innerWidth-480-24),y:Math.max(0,window.innerHeight-640-24),w:480,h:640}})(),selectedText:null,selectedRange:null,contextEnabled:"false"!==localStorage.getItem("halo_context_enabled"),setSelectedText(t,r){e({selectedText:t||null,selectedRange:null!=r?r:null})},setContextEnabled(t){e({contextEnabled:t}),localStorage.setItem("halo_context_enabled",String(t))},openFile(t,r,a,s,n){e(e=>{let l=e.buffers[t]?e.buffers:{...e.buffers,[t]:{path:t,content:r,originalContent:r,language:a,mtime:s,size:null==n?void 0:n.size,createdAt:null==n?void 0:n.createdAt}},o=e.activeGroupIdx,i=e.groups[o],c=i.tabs.includes(t)?i.tabs:[...i.tabs,t],d=e.groups.map((e,r)=>r===o?{...e,tabs:c,activeTab:t}:e),u={...e,buffers:l,groups:d};return{buffers:l,groups:d,...m(u)}})},openPreview(t,r,a,s){e(e=>{let n=e.buffers[t]?e.buffers:{...e.buffers,[t]:{path:t,content:"",originalContent:"",language:"",preview:{downloadUrl:r,viewUrl:a},size:null==s?void 0:s.size,mtime:null==s?void 0:s.mtime,createdAt:null==s?void 0:s.createdAt}},l=e.activeGroupIdx,o=e.groups[l],i=o.tabs.includes(t)?o.tabs:[...o.tabs,t],c=e.groups.map((e,r)=>r===l?{...e,tabs:i,activeTab:t}:e),d={...e,buffers:n,groups:c};return{buffers:n,groups:c,...m(d)}})},openFileInGroup(t,r,a,s,n,l){e(e=>{if(t<0||t>=e.groups.length)return e;let o=e.buffers[r]?e.buffers:{...e.buffers,[r]:{path:r,content:a,originalContent:a,language:s,mtime:n,size:null==l?void 0:l.size,createdAt:null==l?void 0:l.createdAt}},i=e.groups[t],c=i.tabs.includes(r)?i.tabs:[...i.tabs,r],d=e.groups.map((e,a)=>a===t?{...e,tabs:c,activeTab:r}:e),u={...e,buffers:o,groups:d,activeGroupIdx:t};return{buffers:o,groups:d,activeGroupIdx:t,...m(u)}})},closeTab(t){e(e=>{let r=e.groups.map(e=>{if(!e.tabs.includes(t))return e;let r=e.tabs.filter(e=>e!==t),a=e.activeTab;if(a===t){var s;a=null!=(s=r[Math.min(e.tabs.indexOf(t),r.length-1)])?s:null}return{...e,tabs:r,activeTab:a}}),a=r.some(e=>e.tabs.includes(t)),s=a?e.buffers:(()=>{let{[t]:r,...a}=e.buffers;return a})(),n=a?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(t))return e.modifiedPaths;let r=new Set(e.modifiedPaths);return r.delete(t),r})(),l=r.length>1&&0===r[1].tabs.length?{groups:[r[0]],activeGroupIdx:0}:{groups:r,activeGroupIdx:Math.min(e.activeGroupIdx,r.length-1)},o={...e,buffers:s,modifiedPaths:n,...l};return{buffers:s,modifiedPaths:n,...l,...m(o)}})},closeTabIn(t,r){e(e=>{if(t<0||t>=e.groups.length)return e;let a=e.groups[t];if(!a.tabs.includes(r))return e;let s=a.tabs.filter(e=>e!==r),n=a.activeTab;if(n===r){var l;n=null!=(l=s[Math.min(a.tabs.indexOf(r),s.length-1)])?l:null}let o=e.groups.map((e,r)=>r===t?{...e,tabs:s,activeTab:n}:e),i=e.activeGroupIdx;o.length>1&&0===o[1].tabs.length&&(o=[o[0]],i=0);let c=o.some(e=>e.tabs.includes(r)),d=c?e.buffers:(()=>{let{[r]:t,...a}=e.buffers;return a})(),u=c?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(r))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(r),t})(),x={...e,groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u};return{groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u,...m(x)}})},setActiveTab(t,r){e(e=>{let a=null!=r?r:-1;if(a<0){let r=e.groups[e.activeGroupIdx];a=(null==r?void 0:r.tabs.includes(t))?e.activeGroupIdx:e.groups.findIndex(e=>e.tabs.includes(t))}if(a<0||!e.groups[a].tabs.includes(t))return e;let s=e.groups.map((e,r)=>r===a?{...e,activeTab:t}:e),n=a,l={...e,groups:s,activeGroupIdx:n};return{groups:s,activeGroupIdx:n,...m(l)}})},updateContent(t,r){e(e=>{let a=e.buffers[t];if(!a)return e;let s=r!==a.originalContent,n={...e.buffers,[t]:{...a,content:r,modified:s}},l=new Set(e.modifiedPaths);s?l.add(t):l.delete(t);let o={...e,buffers:n,modifiedPaths:l};return{buffers:n,modifiedPaths:l,...m(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,...m(r)}})},splitToRight(t){e(e=>{var r,a;if(e.groups.length>=2)return e;let s=null!=(a=null!=t?t:null==(r=e.groups[e.activeGroupIdx])?void 0:r.activeTab)?a:null;if(!s||!e.buffers[s])return e;let n={id:u(),tabs:[s],activeTab:s},l=[e.groups[0],n],o={...e,groups:l,activeGroupIdx:1};return{groups:l,activeGroupIdx:1,...m(o)}})},closeGroup(t){e(e=>{if(e.groups.length<=1||t<0||t>=e.groups.length)return e;e.groups[t];let r=e.groups.filter((e,r)=>r!==t),a=new Set;for(let e of r)for(let t of e.tabs)a.add(t);let s={};for(let[t,r]of Object.entries(e.buffers))a.has(t)&&(s[t]=r);let n=new Set;for(let t of e.modifiedPaths)a.has(t)&&n.add(t);let l=Math.max(0,Math.min(e.activeGroupIdx,r.length-1)),o={...e,groups:r,activeGroupIdx:l,buffers:s,modifiedPaths:n};return{groups:r,activeGroupIdx:l,buffers:s,modifiedPaths:n,...m(o)}})},moveTabToGroup(t,r,a,s){e(e=>{if(t===a){if(t<0||t>=e.groups.length)return e;let a=e.groups[t],n=a.tabs.indexOf(r);if(n<0)return e;let l=null==s?a.tabs.length-1:Math.max(0,Math.min(s,a.tabs.length-1));if(n===l)return e;let o=function(e,t,r){let a=[...e],[s]=a.splice(t,1);return a.splice(r,0,s),a}(a.tabs,n,l),i=e.groups.map((e,a)=>a===t?{...e,tabs:o,activeTab:r}:e),c={...e,groups:i};return{groups:i,...m(c)}}if(t<0||t>=e.groups.length||a<0||a>e.groups.length)return e;let n=e.groups[t];if(!n.tabs.includes(r))return e;let l=n.tabs.filter(e=>e!==r),o=n.activeTab;if(o===r){var i;o=null!=(i=l[Math.min(n.tabs.indexOf(r),l.length-1)])?i:null}let c=e.groups.slice();if(a===e.groups.length){if(e.groups.length>=2)return e;c[t]={...n,tabs:l,activeTab:o},c.push({id:u(),tabs:[r],activeTab:r})}else{let e=c[a],i=e.tabs.includes(r)?e.tabs:(()=>{let t=[...e.tabs];return null==s||s>=t.length?t.push(r):t.splice(Math.max(0,s),0,r),t})();c[t]={...n,tabs:l,activeTab:o},c[a]={...e,tabs:i,activeTab:r}}let d=a;0===c[t].tabs.length&&c.length>1&&(c=c.filter((e,r)=>r!==t),d=Math.max(0,Math.min(a>t?a-1:a,c.length-1)));let x={...e,groups:c,activeGroupIdx:d};return{groups:c,activeGroupIdx:d,...m(x)}})},setFileTree(t){e({fileTree:t})},setDirChildren(t,r){e(e=>{if(!e.fileTree)return e;let a=[...r].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),s=JSON.parse(JSON.stringify(e.fileTree));if(!t)return s.children=a,s.hasChildren=a.length>0,{fileTree:s};let n=t.split("/").filter(Boolean),l=s;for(let t of n)if(!(null==l?void 0:l.children)||!(l=l.children.find(e=>e.name===t&&"directory"===e.type)))return e;return l.children=a,l.hasChildren=a.length>0,{fileTree:s}})},markModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let a=new Set(e.modifiedPaths);a.add(t);let s={...e.buffers,[t]:{...r,modified:!0}},n={...e,buffers:s,modifiedPaths:a};return{buffers:s,modifiedPaths:a,...m(n)}})},clearModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let a=new Set(e.modifiedPaths);a.delete(t);let s={...e.buffers,[t]:{...r,modified:!1}},n={...e,buffers:s,modifiedPaths:a};return{buffers:s,modifiedPaths:a,...m(n)}})},markSaved(t,r){e(e=>{let a=e.buffers[t];if(!a)return e;let s=new Set(e.modifiedPaths);s.delete(t);let n={...e.buffers,[t]:{...a,originalContent:a.content,modified:!1,mtime:null!=r?r:a.mtime}},l={...e,buffers:n,modifiedPaths:s};return{buffers:n,modifiedPaths:s,...m(l)}})},setRejectedFile(t){e({rejectedFile:t})},setBottomTab(t){e({bottomTab:t})},pendingTerminalCwd:null,requestTerminalSpawn(t){e({pendingTerminalCwd:t})},consumeTerminalSpawn(){let r=t().pendingTerminalCwd;return null!=r&&e({pendingTerminalCwd:null}),r},toggleMaximized(){e(e=>{let t=!e.maximized;return localStorage.setItem("halo_editor_maximized",String(t)),{maximized:t}})},setMaximized(t){localStorage.setItem("halo_editor_maximized",String(t)),e({maximized:t})},setBottomFloating(t){sessionStorage.setItem("halo_bottom_floating",String(t)),e({bottomFloating:t})},setBottomMaximized(t){e({bottomMaximized:t})},setBottomFloatRect(t){sessionStorage.setItem("halo_bottom_float_rect",JSON.stringify(t)),e({bottomFloatRect:t})},insertFileNode(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"file";e(e=>{if(!e.fileTree)return e;let a=t.split("/").filter(Boolean);if(0===a.length)return e;let s=JSON.parse(JSON.stringify(e.fileTree)),n=s;for(let e=0;e<a.length-1;e++){var l;let t=null==(l=n.children)?void 0:l.find(t=>t.name===a[e]&&"directory"===t.type);if(!t)return void 0===n.children&&(n.hasChildren=!0),{fileTree:s};n=t}if(void 0===n.children)return n.hasChildren=!0,{fileTree:s};let o=a[a.length-1];if(n.children.some(e=>e.name===o))return{fileTree:s};let i="directory"===r?{name:o,path:t,type:"directory",hasChildren:!1,children:[]}:{name:o,path:t,type:"file"};return n.children.push(i),n.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 a=JSON.parse(JSON.stringify(e.fileTree)),s=a;for(let t=0;t<r.length-1;t++){var n;let a=null==(n=s.children)?void 0:n.find(e=>e.name===r[t]&&"directory"===e.type);if(!a)return e;s=a}let l=r[r.length-1];if(!s.children)return e;let o=s.children.findIndex(e=>e.name===l);return -1===o?e:(s.children.splice(o,1),{fileTree:a})})},async checkAndRefresh(r,a,s){let n=t().buffers[r];if(!n||n.preview||n.mtime&&a<=n.mtime||n.modified)return!1;let l=await s();return e(e=>{var t,a;let s=e.buffers[r];if(!s)return e;let n={...e.buffers,[r]:{...s,content:l.content,originalContent:l.content,mtime:l.modifiedAt,size:null!=(t=l.size)?t:s.size,createdAt:null!=(a=l.createdAt)?a:s.createdAt}},o={...e,buffers:n};return{buffers:n,...m(o)}}),!0}}))}let p=x(),h=(0,l.createContext)(null);function f(e){let{children:t}=e,r=(0,l.useRef)(null);return r.current||(r.current=x()),(0,l.createElement)(h.Provider,{value:r.current},t)}function g(){let e=(0,l.useContext)(h);return null!=e?e:p}var v=r(17246);class b{connect(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING){this.url=null!=e?e:this.getDefaultUrl(),this.intentionalClose=!1,this.connectStartedAt=Date.now(),this.startLiveness();try{let e=!1;this.ws=new WebSocket(this.url),this.ws.onopen=()=>{for(let t of(console.log("[WsClient] Connected"),e=!0,this.reconnectDelay=1e3,this.lastReceiveTs=Date.now(),this.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=()=>{console.log("[WsClient] Disconnected"),this.ws=null,this.emit("_disconnected",{}),this.intentionalClose||(e?this.reconnect():this.checkAuthThenReconnect())},this.ws.onerror=e=>{console.error("[WsClient] Error:",e)}}catch(e){console.error("[WsClient] Failed to connect:",e),this.reconnect()}}}disconnect(){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){console.log("[WsClient] CONNECTING for >10s, forcing reconnect");try{this.ws.close()}catch(e){}}return}if(e===WebSocket.CLOSING||e===WebSocket.CLOSED){console.log("[WsClient] readyState=CLOSED with no onclose, forcing reconnect"),this.ws=null,this.emit("_disconnected",{}),this.reconnect();return}if(this.lastProbeTs>0&&this.lastReceiveTs<this.lastProbeTs){if(this.missedProbes++,this.missedProbes>=2){console.log("[WsClient] 2 liveness probes unanswered, closing zombie socket");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){console.log("[WsClient] send threw on liveness probe, forcing reconnect:",e);try{this.ws.close()}catch(e){}}},15e3)}stopLiveness(){this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}send(e){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){console.log("[WsClient] Link stale at chat send, reconnecting first");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)){if(t.attempts>=3)return void console.log("[WsClient] Chat ".concat(e," unacked after ").concat(t.attempts," attempts, waiting for deadline"));console.log("[WsClient] Chat ".concat(e," unacked after ").concat(5e3,"ms (attempt ").concat(t.attempts,"), forcing reconnect"));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),console.log("[WsClient] Chat ".concat(e," unacked after ").concat(t.attempts," transmit(s), giving up")),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){console.log("[WsClient] Network back online; tearing down stalled CONNECTING socket");try{this.ws.close()}catch(e){}return}if(this.ws.readyState===WebSocket.OPEN&&!(Date.now()-this.lastReceiveTs<e)){console.log("[WsClient] Connection looks stale, forcing reconnect");try{this.ws.close()}catch(e){}}}emit(e,t){let r=this.listeners.get(e);r&&r.forEach(r=>{try{r(t)}catch(t){console.error('[WsClient] Error in handler for "'.concat(e,'":'),t)}})}reconnect(){this.reconnectTimer||(console.log("[WsClient] Reconnecting in ".concat(this.reconnectDelay,"ms...")),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(2*this.reconnectDelay,this.maxReconnectDelay),this.connect(this.url)},this.reconnectDelay))}async checkAuthThenReconnect(){try{let e=await fetch("/api/auth/check",{credentials:"include"});if(401===e.status){console.log("[WsClient] Auth expired — stopping reconnect, login required"),this.stopLiveness(),this.emit("_auth_expired",{});return}}catch(e){}this.intentionalClose||this.reconnect()}getDefaultUrl(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}constructor(){this.ws=null,this.listeners=new Map,this.reconnectTimer=null,this.reconnectDelay=1e3,this.maxReconnectDelay=3e4,this.url="",this.intentionalClose=!1,this.pendingQueue=[],this.pendingAcks=new Map,this.lastReceiveTs=0,this.lastProbeTs=0,this.missedProbes=0,this.connectStartedAt=0,this.livenessTimer=null}}let j=new b;function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;v.F.files.tree(e).then(r=>{var a,s;let n={name:null!=(s=null!=(a=r.root)?a:e.split("/").filter(Boolean).pop())?s:"root",path:"",type:"directory",hasChildren:r.tree.length>0,children:r.tree};t.getState().setFileTree(n)}).catch(e=>{console.error("[Explorer] Failed to load file tree:",e)})}async function w(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:p;try{let a=await v.F.files.tree(e,t);r.getState().setDirChildren(t,a.tree)}catch(e){console.error("[Explorer] Failed to load directory:",t,e)}}let N={M:{letter:"M",color:"#1B81A8",label:"Modified"},A:{letter:"A",color:"#487E02",label:"Added"},D:{letter:"D",color:"#F48771",label:"Deleted"},R:{letter:"R",color:"#2090D3",label:"Renamed"},C:{letter:"C",color:"#2090D3",label:"Copied"},U:{letter:"C",color:"#E4676B",label:"Conflict"},"?":{letter:"U",color:"#487E02",label:"Untracked"}},k={letter:"?",color:"#487E02",label:"Untracked"};function S(e){var t;return null!=(t=N[e])?t:k}function C(e){return""!==e&&" "!==e&&"?"!==e}function A(e){return""!==e&&" "!==e}let I={files:new Map,dirs:new Map,ignored:new Set},T=(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 E=r(10666),D=r(1833);function F(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,D.QP)((0,E.$)(t))}function P(){return Math.random().toString(36).substring(2,10)+Date.now().toString(36)}function M(e){return!!e&&!!(e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\"))}function L(e,t){let r=window;return"function"==typeof r.haloPrompt?r.haloPrompt(e,t):Promise.resolve(window.prompt(e,t))}function R(e){let t=window;return"function"==typeof t.haloConfirm?t.haloConfirm(e):Promise.resolve(window.confirm(e))}function _(e){var t,r,a;return null!=(a=({ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",html:"html",yaml:"yaml",yml:"yaml",py:"python",rs:"rust",go:"go",sh:"shell",bash:"shell",sql:"sql",toml:"toml",xml:"xml",svg:"xml",env:"plaintext",gitignore:"plaintext",dockerfile:"dockerfile"})[null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""])?a:"plaintext"}var z=r(51332),O=r(23028),W=r(62186),U=r(98844),B=r(98299),H=r(53298),K=r(24604),G=r(91531),J=r(1813),q=r(61031),Z=r(378),V=r(17317),Y=r(80037),$=r(67508),Q=r(26205),X=r(59800),ee=r(5276),et=r(48550),er=r(79464),ea=r(68301),es=r(71473),en=r(27153),el=r(44242);let eo={ts:K.A,tsx:K.A,mts:K.A,cts:K.A,js:K.A,jsx:K.A,mjs:K.A,cjs:K.A,json:G.A,jsonc:G.A,html:J.A,htm:J.A,svg:J.A,xml:J.A,css:q.A,scss:q.A,sass:q.A,less:q.A,md:Z.A,mdx:Z.A,txt:Z.A,rst:Z.A,log:Z.A,csv:V.A,tsv:V.A,xlsx:V.A,xls:V.A,sql:Y.A,sh:$.A,bash:$.A,zsh:$.A,yaml:Q.A,yml:Q.A,toml:Q.A,ini:Q.A,env:Q.A,py:X.A,go:ee.A,rs:ee.A,c:ee.A,cpp:ee.A,h:ee.A,hpp:ee.A,java:ee.A,kt:ee.A,scala:ee.A,cs:ee.A,swift:ee.A,dart:ee.A,rb:ee.A,php:ee.A,lua:ee.A,r:ee.A,png:et.A,jpg:et.A,jpeg:et.A,gif:et.A,webp:et.A,bmp:et.A,ico:et.A,avif:et.A,mp4:er.A,webm:er.A,mov:er.A,avi:er.A,mkv:er.A,ogg:er.A,mp3:ea.A,wav:ea.A,flac:ea.A,aac:ea.A,m4a:ea.A,wma:ea.A,zip:es.A,tar:es.A,gz:es.A,"7z":es.A,rar:es.A,pdf:en.A,docx:en.A,doc:en.A,pptx:en.A,ppt:en.A},ei={ts:"text-blue-400",tsx:"text-blue-400",mts:"text-blue-400",cts:"text-blue-400",js:"text-yellow-400",jsx:"text-yellow-400",mjs:"text-yellow-400",cjs:"text-yellow-400",json:"text-yellow-300",jsonc:"text-yellow-300",html:"text-orange-400",htm:"text-orange-400",css:"text-blue-300",scss:"text-pink-400",sass:"text-pink-400",less:"text-blue-300",md:"text-sky-300",mdx:"text-sky-300",py:"text-green-400",go:"text-cyan-400",rs:"text-orange-400",java:"text-red-400",rb:"text-red-300",php:"text-indigo-300",sh:"text-green-300",bash:"text-green-300",svg:"text-orange-300",xml:"text-orange-300",yaml:"text-red-300",yml:"text-red-300",sql:"text-cyan-300",png:"text-purple-300",jpg:"text-purple-300",jpeg:"text-purple-300",gif:"text-purple-300",webp:"text-purple-300",avif:"text-purple-300",mp4:"text-pink-300",webm:"text-pink-300",mov:"text-pink-300",mp3:"text-emerald-300",wav:"text-emerald-300",flac:"text-emerald-300",pdf:"text-red-400",docx:"text-blue-400",doc:"text-blue-400",pptx:"text-orange-400",ppt:"text-orange-400",zip:"text-amber-400",tar:"text-amber-400",gz:"text-amber-400"};function ec(e){var t,r,a,s,n,l;let o=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"",i=null!=(s=null==(r=e.split("/").pop())?void 0:r.toLowerCase())?s:"";return"dockerfile"===i||i.startsWith("dockerfile.")?{Icon:$.A,color:"text-cyan-400"}:".gitignore"===i||".gitattributes"===i?{Icon:Q.A,color:"text-[var(--muted-foreground)]"}:".env"===i||i.startsWith(".env.")?{Icon:Q.A,color:"text-yellow-300"}:"makefile"===i||"cmake"===i?{Icon:$.A,color:"text-[var(--muted-foreground)]"}:{Icon:null!=(n=eo[o])?n:el.A,color:null!=(l=ei[o])?l:"text-[var(--muted-foreground)]"}}let ed="halo:file-tree:expanded",eu=null,em=new Map;function ex(){if(eu)return eu;try{let e=localStorage.getItem(ed);eu=e?new Set(JSON.parse(e)):new Set}catch(e){eu=new Set}return eu}let ep=null;function eh(e,t){let r=ex(),a=r.has(e);if(t?r.add(e):r.delete(e),ep&&clearTimeout(ep),ep=setTimeout(()=>{try{let e=ex();localStorage.setItem(ed,JSON.stringify([...e]))}catch(e){}},300),a!==t){let r=em.get(e);if(r)for(let e of r)e(t)}}let ef="application/x-halo-path";function eg(e){let{depth:t,initialValue:r,iconKind:a,onCommit:s,onCancel:o}=e,i=(0,l.useRef)(null),[c,d]=(0,l.useState)(r),u=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=i.current;if(!e)return;e.focus();let t=r.lastIndexOf(".");"file"===a&&t>0?e.setSelectionRange(0,t):e.select()},[r,a]);let m="folder"===a?z.A:O.A;return(0,n.jsxs)("div",{className:"flex w-full items-center gap-1 py-1 text-xs",style:{paddingLeft:"".concat(12*t+8,"px")},children:[(0,n.jsx)("span",{className:"w-3.5 shrink-0"}),(0,n.jsx)(m,{className:F("h-3.5 w-3.5 shrink-0","folder"===a?"text-blue-400":"fill-[var(--muted-foreground)] text-[var(--muted-foreground)]")}),(0,n.jsx)("input",{ref:i,type:"text",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u.current=!0,s(c)):"Escape"===e.key&&(e.preventDefault(),u.current=!0,o()),e.stopPropagation()},onBlur:()=>{u.current||(""===c.trim()?o():s(c))},className:"min-w-0 flex-1 rounded border border-[var(--primary)] bg-[var(--background)] px-1 py-0 text-xs text-[var(--foreground)] outline-none"})]})}async function ev(e){let t=e.items;if(t&&t.length>0){let e=[];for(let s=0;s<t.length;s++){var r,a;let n=null==(r=(a=t[s]).webkitGetAsEntry)?void 0:r.call(a);n&&e.push(n)}if(e.some(e=>e.isDirectory)){let t=[];async function s(e,r){if(e.isFile){let a=await new Promise((t,r)=>e.file(t,r)),s=r?"".concat(r,"/").concat(e.name):e.name;t.push(new File([a],s,{type:a.type,lastModified:a.lastModified}))}else if(e.isDirectory){let t,a=e.createReader(),n=r?"".concat(r,"/").concat(e.name):e.name;do for(let e of t=await function(e){return new Promise((t,r)=>e.readEntries(t,r))}(a))await s(e,n);while(t.length>0)}}for(let t of e)await s(t,"");return t}}return Array.from(e.files)}function eb(e){var t,r,a,s,o;let{node:i,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:m,onMoveFile:x,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:v,depth:b,pendingEdit:j,onCommitEdit:y,onCancelEdit:N}=e,k=g(),[C,A]=(0,l.useState)(()=>{var e;return!!i.path&&(e=i.path,ex().has(e))}),[E,D]=(0,l.useState)(!1),[P,M]=(0,l.useState)(!1),L=(0,l.useRef)(null),R=(0,l.useRef)(null),_="directory"===i.type,K=_&&!1!==i.hasChildren&&void 0===i.children,G=(0,l.useRef)(C),J=(0,l.useCallback)(e=>{A(e),i.path&&eh(i.path,e)},[i.path]);(0,l.useEffect)(()=>{if(i.path){var e,t;let r;return e=i.path,t=e=>A(e),(r=em.get(e))||(r=new Set,em.set(e,r)),r.add(t),()=>{let r=em.get(e);r&&(r.delete(t),0===r.size&&em.delete(e))}}},[i.path]),(0,l.useEffect)(()=>{let e=G.current;G.current=C,C&&!P&&i.path&&(K||!e)&&(M(!0),w(c,i.path,k).finally(()=>M(!1)))},[C,K,P,i.path,c,k]);let q=k(e=>e.modifiedPaths),Z=k(e=>e.activeTab),V=T(e=>{var t;return null!=(t=c?e.byProject[c]:void 0)?t:I});if(0===b&&!i.path){let e=(0,l.useCallback)(()=>(function e(t){var r,a;let s=[];if(t.path&&s.push(t.path),"directory"===t.type&&t.children&&(!t.path||(r=t.path,ex().has(r))))for(let r of[...null!=(a=t.children)?a:[]].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)))s.push(...e(r));return s})(i),[i])(),t=async e=>{e.preventDefault(),e.stopPropagation(),D(!1);let t=e.dataTransfer.getData(ef);if(t){null==x||x(t,"");return}let r=await ev(e.dataTransfer);r.length>0&&(null==m||m(r,""))},a=j&&""===j.parentDir&&"rename"!==j.mode;return(0,n.jsxs)("div",{"data-file-tree-root":"true",onClick:e=>{e.target===e.currentTarget&&h&&h(new Set,"")},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),null==u||u({x:e.clientX,y:e.clientY,path:"",name:"/",isDir:!0}))},onDragOver:e=>{(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(ef))&&(e.preventDefault(),e.stopPropagation(),D(!0))},onDragLeave:e=>{e.currentTarget===e.target&&D(!1)},onDrop:t,className:F("min-h-full",E&&"bg-[var(--accent)]/30"),children:[a&&j&&(0,n.jsx)(eg,{depth:0,initialValue:"",iconKind:"create-folder"===j.mode?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}),null==(r=i.children)?void 0:r.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)).map(t=>(0,n.jsx)(eb,{node:t,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:m,onMoveFile:x,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:e,depth:0,pendingEdit:j,onCommitEdit:y,onCancelEdit:N},t.path))]})}let Y=q.has(i.path),$=Z===i.path,Q=null!=(a=null==p?void 0:p.has(i.path))&&a,{Icon:X,color:ee}=ec(i.path),et=_?V.dirs.get(i.path):V.files.get(i.path),er=et&&"*"!==et?S(et):null,ea="*"===et?"#8C8C8C":null==er?void 0:er.color,es=!et&&function(e,t){if(0===e.size)return!1;if(e.has(t))return!0;for(let r of e)if(t.startsWith(r+"/"))return!0;return!1}(V.ignored,i.path),en=()=>{R.current&&(clearTimeout(R.current),R.current=null)},el=async e=>{if(!_)return;e.preventDefault(),e.stopPropagation(),D(!1),en(),C||J(!0);let t=e.dataTransfer.getData(ef);if(t){try{for(let e of JSON.parse(t))e===i.path||e.startsWith(i.path+"/")||null==x||x(e,i.path)}catch(e){t===i.path||t.startsWith(i.path+"/")||null==x||x(t,i.path)}return}let r=await ev(e.dataTransfer);r.length>0&&(null==m||m(r,i.path))},eo=_&&(null==(t=i.children)?void 0:t.some(e=>{let t=e=>{var r,a;return!!q.has(e.path)||null!=(a=null==(r=e.children)?void 0:r.some(t))&&a};return t(e)})),ei=j&&"rename"===j.mode&&j.originalPath===i.path,ed=j&&"rename"!==j.mode&&j.parentDir===i.path&&_;return ei&&j?(0,n.jsx)(eg,{depth:b,initialValue:null!=(s=j.originalName)?s:i.name,iconKind:_?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}):(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{draggable:!0,onClick:e=>{if(e.stopPropagation(),_&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){h&&h(new Set([i.path]),i.path),J(!C);return}if(e.shiftKey&&h&&v&&f){let e=v.indexOf(f),t=v.indexOf(i.path);if(e>=0&&t>=0){let r=Math.min(e,t),a=Math.max(e,t);h(new Set(v.slice(r,a+1)),f)}return}if((e.ctrlKey||e.metaKey)&&h){let e=new Set(p);e.has(i.path)?e.delete(i.path):e.add(i.path),h(e,i.path);return}_||(h&&h(new Set([i.path]),i.path),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{L.current=null,d(i.path)},300))},onDoubleClick:e=>{e.stopPropagation(),L.current&&(clearTimeout(L.current),L.current=null),_?J(!C):d(i.path)},onDragStart:e=>{p&&p.size>1&&p.has(i.path)?e.dataTransfer.setData(ef,JSON.stringify([...p])):e.dataTransfer.setData(ef,JSON.stringify([i.path])),e.dataTransfer.effectAllowed="move"},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),!Q&&h&&h(new Set([i.path]),i.path),null==u||u({x:e.clientX,y:e.clientY,path:i.path,name:i.name,isDir:_})},onDragOver:e=>{_&&(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(ef))&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",D(!0),C||R.current||(R.current=setTimeout(()=>{R.current=null,J(!0)},600)))},onDragLeave:()=>{D(!1),en()},onDrop:el,className:F("flex w-full items-center gap-1 py-1 text-left text-xs transition-colors hover:bg-[var(--secondary)]",Q&&"bg-[var(--primary)]/20 text-[var(--foreground)]",!Q&&$&&"bg-[var(--accent)] text-[var(--accent-foreground)]",!Q&&!$&&"text-[var(--foreground)]",E&&_&&"bg-[var(--accent)] ring-1 ring-[var(--primary)]"),style:{paddingLeft:"".concat(12*b+8,"px")},children:[_&&(0,n.jsx)("span",{className:"shrink-0 text-[var(--muted-foreground)]",children:C?(0,n.jsx)(W.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(U.A,{className:"h-3.5 w-3.5"})}),!_&&(0,n.jsx)("span",{className:"w-3.5 shrink-0"}),_?C?(0,n.jsx)(B.A,{className:F("h-3.5 w-3.5 shrink-0 text-blue-400",es&&"opacity-60")}):(0,n.jsx)(z.A,{className:F("h-3.5 w-3.5 shrink-0 text-blue-400",es&&"opacity-60")}):(0,n.jsx)(X,{className:F("h-3.5 w-3.5 shrink-0",ee,es&&"opacity-60")}),(0,n.jsx)("span",{className:F("truncate",es&&"text-[var(--muted-foreground)] opacity-60"),style:ea?{color:ea}:void 0,children:i.name}),(0,n.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-1 pl-1 pr-2",children:[(Y||eo)&&(0,n.jsx)(O.A,{className:"h-1.5 w-1.5 shrink-0 fill-amber-400 text-amber-400"}),_?ea&&(0,n.jsx)(O.A,{className:"h-1.5 w-1.5 shrink-0",style:{fill:ea,color:ea}}):er&&(0,n.jsx)("span",{className:"w-3 text-center font-mono text-[11px] font-semibold",style:{color:er.color},title:er.label,children:er.letter})]})]}),_&&C&&P&&!i.children&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-[10px] text-[var(--muted-foreground)]",style:{paddingLeft:"".concat((b+1)*12+8,"px")},children:[(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),(0,n.jsx)("span",{children:"Loading..."})]}),_&&C&&(i.children||ed)&&(0,n.jsxs)("div",{children:[ed&&j&&(0,n.jsx)(eg,{depth:b+1,initialValue:"",iconKind:"create-folder"===j.mode?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}),(null!=(o=i.children)?o:[]).sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)).map(e=>(0,n.jsx)(eb,{node:e,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:m,onMoveFile:x,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:v,depth:b+1,pendingEdit:j,onCommitEdit:y,onCancelEdit:N},e.path))]})]})}var ej=r(90429),ey=r(93717),ew=r(93247),eN=r(35179),ek=r(34633),eS=r(17612),eC=r(19869);function eA(e){let{x:t,y:r,path:a,name:s,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 a=e.getBoundingClientRect(),s=window.innerWidth,n=window.innerHeight,l=t+a.width+4>s?Math.max(4,s-a.width-4):t,o=r+a.height+4>n?Math.max(4,n-a.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,n.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,n.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,n.jsxs)("button",{onClick:()=>{c({type:"delete",path:a,isDir:o}),d()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs text-red-400 transition-colors hover:bg-[var(--secondary)] hover:text-red-300",children:[(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"}),"Delete ",i," items"]})]});let h=""===a&&o,f=!!window.haloReveal,g=h?[{icon:ey.A,label:"New File...",type:"new-file"},{icon:ew.A,label:"New Folder...",type:"new-folder"},{icon:$.A,label:"Open in Integrated Terminal",type:"open-terminal"},...f?[{icon:eN.A,label:"Reveal in File Manager",type:"reveal-in-file-manager"}]:[]]:[{icon:ey.A,label:"New File...",type:"new-file",separatorAfter:!1},{icon:ew.A,label:"New Folder...",type:"new-folder",separatorAfter:!1},{icon:$.A,label:"Open in Integrated Terminal",type:"open-terminal",separatorAfter:!f},...f?[{icon:eN.A,label:"Reveal in File Manager",type:"reveal-in-file-manager",separatorAfter:!0}]:[],...o?[]:[{icon:ek.A,label:"Open to the Side",type:"open-to-side",separatorAfter:!1},{icon:eS.A,label:"Download",type:"download"}],{icon:eC.A,label:"Rename",type:"rename"},{icon:ej.A,label:"Delete",type:"delete",danger:!0,separatorAfter:o},...o?[{icon:B.A,label:"Open as Workspace",type:"open-as-workspace"}]:[]];return(0,n.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,n.jsx)("div",{className:"truncate border-b border-[var(--border)] px-3 py-1.5 text-[10px] text-[var(--muted-foreground)]",children:s}),g.map(e=>{let t=e.icon;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>{c({type:e.type,path:a,isDir:o}),d()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs transition-colors hover:bg-[var(--secondary)] ".concat(e.danger?"text-red-400 hover:text-red-300":"text-[var(--foreground)]"),children:[(0,n.jsx)(t,{className:"h-3.5 w-3.5"}),e.label]}),e.separatorAfter&&(0,n.jsx)("div",{className:"my-1 border-t border-[var(--border)]"})]},e.type)})]})}var eI=r(70812);eI.wG.config({paths:{vs:"/monaco/vs"}});var eT=r(59391);let eE={dark:"vs-dark",light:"vs",midnight:"halo-midnight",warm:"halo-warm"},eD=!1;function eF(e){eD||(eD=!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 eP(e){let{path:t,content:r,language:a,onChange:s,onSave:o,onClose:i}=e,c=g(),d=(0,l.useRef)(null),{theme:u}=(0,eT.useTheme)(),m=(0,l.useRef)(o),x=(0,l.useRef)(i),p=(0,l.useRef)(r);(0,l.useEffect)(()=>{m.current=o,x.current=i,p.current=r},[o,i,r]),(0,l.useEffect)(()=>()=>{c.getState().setSelectedText(null,null)},[t]);let h=(0,l.useCallback)(e=>{void 0!==e&&s&&s(e)},[s]),f=(0,l.useCallback)((e,t)=>{d.current=e;let r=e.getModel();r&&r.getValue()!==p.current&&r.setValue(p.current),e.onDidChangeCursorSelection(t=>{var r,a;let s=e.getSelection();if(!s||s.isEmpty())return void c.getState().setSelectedText(null,null);let n=null!=(a=null==(r=e.getModel())?void 0:r.getValueInRange(s))?a:null;n&&c.getState().setSelectedText(n,{startLine:s.startLineNumber,endLine:s.endLineNumber})}),e.addAction({id:"halo-save",label:"Save File",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.KeyS],run:()=>{var e;null==(e=m.current)||e.call(m)}}),e.addAction({id:"halo-close-tab",label:"Close Tab",keybindings:[t.KeyMod.Alt|t.KeyCode.KeyW],run:()=>{var e;null==(e=x.current)||e.call(x)}})},[]);return(0,n.jsx)(eI.Ay,{path:t,keepCurrentModel:!0,height:"100%",language:a,value:r,onChange:h,beforeMount:eF,onMount:f,theme:eE[u],options:{fontSize:13,lineHeight:20,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:"on",tabSize:2,renderLineHighlight:"line",cursorBlinking:"smooth",smoothScrolling:!0,padding:{top:12,bottom:12},bracketPairColorization:{enabled:!0},automaticLayout:!0,overviewRulerLanes:0,hideCursorInOverviewRuler:!0,overviewRulerBorder:!1,scrollbar:{verticalScrollbarSize:6,horizontalScrollbarSize:6}},loading:(0,n.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,n.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading editor..."})})})}var eM=r(40549),eL=r(29978),eR=r(87917),e_=r(28687);function ez(e){let{content:t,filePath:r,projectId:a}=e,s=g(),o=(0,l.useRef)(null),i=(0,l.useMemo)(()=>(function(e){let t=[],r=new Map,a=!1;for(let n of e.split("\n")){var s;let e=n.trimEnd();if(/^\s*(```|~~~)/.test(e)){a=!a;continue}if(a)continue;let l=/^(#{1,6})\s+(.+?)\s*#*$/.exec(e);if(!l)continue;let o=l[1].length,i=l[2].trim(),c=i.trim().toLowerCase().replace(/[^\w一-鿿\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"section",d=null!=(s=r.get(c))?s:0;r.set(c,d+1),d>0&&(c="".concat(c,"-").concat(d)),t.push({level:o,text:i,slug:c})}return t})(t),[t]),c=0,d=e=>{let t=o.current;if(!t)return;let r=t.querySelector("#".concat(CSS.escape(e)));r&&r.scrollIntoView({behavior:"smooth",block:"start"})},[u,m]=(0,l.useState)(()=>{try{return"1"===localStorage.getItem("halo.mdOutlineHidden")}catch(e){return!1}}),x=()=>{m(e=>{let t=!e;try{localStorage.setItem("halo.mdOutlineHidden",t?"1":"0")}catch(e){}return t})};(0,l.useEffect)(()=>{let e=o.current;if(!e)return;let t=s.getState().setSelectedText;function r(){let r=window.getSelection();if(!r||0===r.rangeCount)return;let a=r.getRangeAt(0);if(!(e&&e.contains(a.commonAncestorContainer)))return;if(r.isCollapsed)return void t(null,null);let s=r.toString();if(!s.trim())return void t(null,null);t(s,null)}return document.addEventListener("selectionchange",r),()=>{document.removeEventListener("selectionchange",r),t(null,null)}},[s]);let p=e=>function(t){var r;let{children:a}=t;return(0,n.jsx)(e,{id:null==(r=i[c++])?void 0:r.slug,children:a})};return(0,n.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[i.length>1&&!u&&(0,n.jsxs)("nav",{className:"hidden w-56 shrink-0 flex-col overflow-y-auto border-r border-[var(--border)] py-4 md:flex",children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center justify-between px-3 pb-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",children:"Outline"}),(0,n.jsx)("button",{onClick:x,title:"Hide outline",className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eR.A,{className:"h-3.5 w-3.5"})})]}),i.map((e,t)=>(0,n.jsx)("button",{onClick:()=>d(e.slug),title:e.text,className:"block w-full shrink-0 truncate px-3 py-1 text-left text-xs text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",style:{paddingLeft:"".concat(.75+(e.level-1)*.75,"rem")},children:e.text},"".concat(e.slug,"-").concat(t)))]}),(0,n.jsxs)("div",{ref:o,className:"relative flex-1 overflow-y-auto px-8 py-6",children:[i.length>1&&u&&(0,n.jsx)("button",{onClick:x,title:"Show outline",className:"absolute left-2 top-2 z-10 hidden rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] md:block",children:(0,n.jsx)(e_.A,{className:"h-4 w-4"})}),(0,n.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,n.jsx)(eM.oz,{remarkPlugins:[eL.A],components:{h1:p("h1"),h2:p("h2"),h3:p("h3"),h4:p("h4"),h5:p("h5"),h6:p("h6"),a(e){let{href:t,children:r,node:a,...s}=e;return(null==t?void 0:t.startsWith("#"))?(0,n.jsx)("a",{href:t,onClick:e=>{e.preventDefault();let r=t.slice(1);try{r=decodeURIComponent(r)}catch(e){}d(r)},...s,children:r}):(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...s,children:r})},img(e){let{src:t,alt:s,node:l,...o}=e,i=function(e,t,r){let a;if(!e)return null;if(/^(https?:|data:|blob:)/i.test(e))return e;if(!r)return null;if(e.startsWith("/"))a=e;else{if(!t)return null;let s=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",n=s?"".concat(s,"/").concat(e):e,l=[];for(let e of n.split("/"))""!==e&&"."!==e&&(".."===e?l.pop():l.push(e));a="".concat(r.replace(/\/$/,""),"/").concat(l.join("/"))}let s=new URLSearchParams;return s.set("path",a),s.set("projectId",r),s.set("inline","1"),"/api/files/download?".concat(s.toString())}("string"==typeof t?t:"",r,a);return i?(0,n.jsx)("img",{src:i,alt:null!=s?s:"",...o}):(0,n.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: ",s||String(t),"]"]})}},children:t})})]})]})}let eO=new Set;function eW(e){for(let r of eO)try{var t;null==(t=r.contentWindow)||t.postMessage({haloFace:e},"*")}catch(e){}}function eU(e){let{url:t,name:r}=e,a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{if(a.current){var e;return e=a.current,eO.add(e),()=>{eO.delete(e)}}},[]),(0,n.jsx)("iframe",{ref:a,src:t,title:r,className:"h-full w-full border-0 bg-white",sandbox:"allow-scripts allow-same-origin",allow:"autoplay"})}function eB(e){let{original:t,modified:r,path:a}=e,s=_(a),{theme:l}=(0,eT.useTheme)();return(0,n.jsx)(eI.zC,{height:"100%",language:s,original:t,modified:r,beforeMount:eF,theme:eE[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,n.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,n.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading diff..."})})})}var eH=r(38067),eK=r(61648),eG=r(30865),eJ=r(84099);function eq(e){var t,r;let{x:a,y:s,path:o,groupIdx:i,onClose:c,onCloseTab:d}=e,u=g(),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,n.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:a,top:s},children:f.map((e,t)=>(0,n.jsx)("button",{disabled:e.disabled,onClick:()=>{e.action(),c()},className:F("w-full px-3 py-1.5 text-left text-xs transition-colors",e.disabled?"text-[var(--muted-foreground)]/40 cursor-default":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:e.label},t))})}let eZ="application/x-halo-tab";function eV(e){let{tabs:t,activeTab:r,groupIdx:a,canSplit:s,onCloseTab:o,renderMode:i,onToggleRenderMode:c,showDiffButton:d,onToggleDiff:u}=e,m=g(),x=(0,l.useRef)(null),[p,h]=(0,l.useState)(!1),[f,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[y,w]=(0,l.useState)(null),[N,k]=(0,l.useState)(!1),[S,C]=(0,l.useState)(null),A=function(e){var t,r,a,s;let n=new Map,l=new Map;for(let a of e){let e=null!=(t=a.path.split("/").pop())?t:a.path;l.set(e,(null!=(r=l.get(e))?r:0)+1)}for(let t of e){let e=t.path.split("/"),r=null!=(a=e.pop())?a:t.path;(null!=(s=l.get(r))?s:0)>1&&e.length>0?n.set(t.path,"".concat(e[e.length-1],"/").concat(r)):n.set(t.path,r)}return n}(t),I=(0,l.useCallback)(()=>{let e=x.current;e&&(h(e.scrollLeft>0),v(e.scrollLeft+e.clientWidth<e.scrollWidth-1))},[]);(0,l.useEffect)(()=>{I();let e=x.current;if(!e)return;e.addEventListener("scroll",I);let t=new ResizeObserver(I);return t.observe(e),()=>{e.removeEventListener("scroll",I),t.disconnect()}},[I,t.length]);let T=e=>{var t;null==(t=x.current)||t.scrollBy({left:e,behavior:"smooth"})},E=()=>{j(null),w(null),k(!1)},D=m(e=>e.activeGroupIdx);return(0,n.jsxs)("div",{className:F("relative flex shrink-0 items-center border-b border-[var(--border)] bg-[var(--card)]",N&&"ring-1 ring-[var(--primary)]"),onDragOver:e=>{if(!eY(e))return;let t=e.dataTransfer.types.includes(eZ)?{srcGroupIdx:-1,path:""}:null;t&&t.srcGroupIdx!==a&&(e.preventDefault(),e.dataTransfer.dropEffect="move",k(!0))},onDragLeave:e=>{e.currentTarget===e.target&&k(!1)},onDrop:e=>{if(!eY(e))return;e.preventDefault();let t=e$(e);t&&t.srcGroupIdx!==a&&m.getState().moveTabToGroup(t.srcGroupIdx,t.path,a),j(null),w(null),k(!1)},onMouseDown:()=>m.getState().setActiveGroup(a),children:[p&&(0,n.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,n.jsx)(eH.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("div",{ref:x,className:"flex flex-1 overflow-x-hidden",children:t.map((e,t)=>{var s;let{Icon:l,color:i}=ec(e.path),c=e.path===r&&a===D,d=e.path===r&&a!==D;return(0,n.jsxs)("div",{draggable:!0,onDragStart:r=>{var s;return s=e.path,j(t),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),void r.dataTransfer.setData(eZ,JSON.stringify({srcGroupIdx:a,path:s}))},onDragOver:e=>{eY(e)&&(e.preventDefault(),e.dataTransfer.dropEffect="move",w(t))},onDrop:e=>((e,t)=>{if(!eY(e))return;e.preventDefault();let r=e$(e);r&&m.getState().moveTabToGroup(r.srcGroupIdx,r.path,a,t),j(null),w(null),k(!1)})(e,t),onDragEnd:E,onContextMenu:t=>{t.preventDefault(),C({x:t.clientX,y:t.clientY,path:e.path})},className:F("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:()=>{m.getState().setActiveTab(e.path,a),m.getState().setRejectedFile(null)},children:[y===t&&null!==b&&b>t&&(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),y===t&&null!==b&&b<t&&(0,n.jsx)("div",{className:"absolute right-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),(0,n.jsx)(l,{className:F("h-3.5 w-3.5 shrink-0",i)}),(0,n.jsx)("span",{className:"max-w-40 truncate",children:null!=(s=A.get(e.path))?s:e.path.split("/").pop()}),e.modified?(0,n.jsx)(O.A,{className:"h-2 w-2 fill-amber-400 text-amber-400 shrink-0"}):(0,n.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,n.jsx)(eK.A,{className:"h-3 w-3"})}),e.modified&&(0,n.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,n.jsx)(eK.A,{className:"h-3 w-3"})})]},e.path)})}),f&&(0,n.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,n.jsx)(U.A,{className:"h-3.5 w-3.5"})}),(()=>{let e=t.find(e=>e.path===r),a=(null==e?void 0:e.language)==="markdown"||(null==e?void 0:e.language)==="html";return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 mr-1",children:[a&&(0,n.jsxs)("button",{onClick:c,title:i?"Switch to source view":"Switch to rendered view",className:F("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,n.jsx)(eC.A,{className:"h-3 w-3"}):(0,n.jsx)(eG.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:i?"Edit":"Preview"})]}),d&&(0,n.jsxs)("button",{onClick:u,title:"View unsaved diff",className:"flex items-center gap-1 rounded px-1.5 py-1 text-[11px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[(0,n.jsx)(eJ.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"Diff"})]})]})})(),s&&(0,n.jsx)("button",{title:"Split editor right",onClick:()=>m.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,n.jsx)(ek.A,{className:"h-3.5 w-3.5"})}),S&&(0,n.jsx)(eq,{x:S.x,y:S.y,path:S.path,groupIdx:a,onClose:()=>C(null),onCloseTab:o})]})}function eY(e){return e.dataTransfer.types.includes(eZ)}function e$(e){try{let t=e.dataTransfer.getData(eZ);if(!t)return null;return JSON.parse(t)}catch(e){return null}}let eQ=new Map;function eX(e){for(let t of e.extensions)eQ.set(t.toLowerCase(),e)}let e0={id:"pdf",extensions:["pdf"],Component:(0,l.lazy)(()=>r.e(65).then(r.bind(r,50065)).then(e=>({default:e.PdfPreview})))},e1={id:"docx",extensions:["docx","doc"],Component:(0,l.lazy)(()=>r.e(579).then(r.bind(r,37579)).then(e=>({default:e.DocxPreview})))},e5={id:"xlsx",extensions:["xlsx","xls","csv"],Component:(0,l.lazy)(()=>r.e(442).then(r.bind(r,36442)).then(e=>({default:e.XlsxPreview})))},e3={id:"pptx",extensions:["pptx","ppt"],Component:(0,l.lazy)(()=>Promise.all([r.e(819),r.e(868),r.e(533),r.e(525)]).then(r.bind(r,78525)).then(e=>({default:e.PptxPreview}))),heavy:!0};var e2=r(89759);function e4(){return(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})}function e8(e){var t,r,a;let s=(a=null!=(r=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?r:"",eQ.get(a.toLowerCase()));if(!s)return(0,n.jsx)(e6,{...e});let{Component:o}=s;return(0,n.jsx)(l.Suspense,{fallback:(0,n.jsx)(e4,{}),children:(0,n.jsx)(o,{...e})})}function e6(e){let{name:t,downloadUrl:r,onOpenAsText:a}=e;return(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 bg-[var(--background)] p-8",children:[(0,n.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-[var(--secondary)]",children:(0,n.jsx)(el.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"})}),(0,n.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:t}),(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"This file type does not support preview"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[a&&(0,n.jsx)("button",{onClick:a,className:"inline-flex items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--secondary)] px-4 py-2 text-xs font-medium text-[var(--foreground)] transition-colors hover:opacity-90",children:"Open as Text"}),(0,n.jsx)("a",{href:r,download:!0,className:"inline-flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",children:"Download"})]})]})}eX(e0),eX(e1),eX(e5),eX(e3),eX(e2.SQ);let e9=(0,c.v)((e,t)=>({projects:[],activeProject:null,folderPath:"",setProjects(t){e({projects:t})},setActiveProject(t){e({activeProject:t})},setFolderPath(t){e({folderPath:t})},openFolder(r,a){var s;let n=r.trim();if(!n)return;let l=null!=(s=n.split("/").filter(Boolean).pop())?s:n,o={id:n,name:l,path:n,workspaceId:a,createdAt:Date.now()},i=t().projects;i.find(e=>e.path===n)||e({projects:[...i,o]}),e({activeProject:o,folderPath:n})}}));var e7=r(29241),te=r(97095),tt=r(98413),tr=r(8808);r(38045);var ta=r(87826);function ts(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}r(26967);let tn=new Set([...eQ.keys(),"tiff","tif","zip","tar","gz","bz2","xz","7z","rar","woff","woff2","ttf","otf","eot","exe","dll","so","dylib","o","a","class","pyc","wasm"]);function tl(e){var t;let{projectId:r,mode:a="full",showMaximize:s=!0}=e,o=(0,tr.useT)(),c=g(),d=c(e=>e.tabs),u=c(e=>e.activeTab),m=c(e=>e.buffers),x=c(e=>e.groups),h=c(e=>e.activeGroupIdx),f=c(e=>e.maximized),b="editor-only"===a,[w,N]=(0,l.useState)(!0),[k,S]=(0,l.useState)({}),[C,A]=(0,l.useState)({});function I(e){var t;return null==(t=C[e])||t}let[T,E]=(0,l.useState)(null),[D,P]=(0,l.useState)(new Set),[M,L]=(0,l.useState)(null),[z,O]=(0,l.useState)(null),[W,U]=(0,l.useState)(null),{tree:B,loading:H}=function(e){let t=g(),[r,a]=(0,l.useState)(!1),[s,n]=(0,l.useState)(null),o=t(e=>e.fileTree),i=(0,l.useCallback)(async()=>{if(e){a(!0),n(null);try{var r,s;let a=await v.F.files.tree(e),n={name:null!=(s=null!=(r=a.root)?r:e.split("/").filter(Boolean).pop())?s:"root",path:"",type:"directory",hasChildren:a.tree.length>0,children:a.tree};t.getState().setFileTree(n)}catch(e){n(e instanceof Error?e.message:"Failed to load file tree"),console.error("[useFileTree] Error:",e)}finally{a(!1)}}},[e,t]);return(0,l.useEffect)(()=>{e&&i()},[e,i]),(0,l.useEffect)(()=>{if(e)return j.on("file:changed",e=>{"add"===e.action||"addDir"===e.action?t.getState().insertFileNode(e.path,"addDir"===e.action?"directory":"file"):("unlink"===e.action||"unlinkDir"===e.action)&&t.getState().removeFileNode(e.path)})},[e,t]),{tree:o,loading:r,error:s,refresh:i}}(r),[K,G]=(0,l.useState)(!1),J=(0,l.useRef)(null),q=(0,l.useCallback)(e=>{var t,r,a,s;return a=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"",!!(null==(s=eQ.get(a.toLowerCase()))?void 0:s.heavy)},[]),[Z,V]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=[];for(let t of x){let r=t.activeTab;if(!r)continue;let a=m[r];(null==a?void 0:a.preview)&&(q(r)||e.push(r))}0!==e.length&&V(t=>{let r=t.slice();for(let t=e.length-1;t>=0;t--){let a=e[t];r=[a,...r.filter(e=>e!==a)]}return(r=r.slice(0,5),t.length===r.length&&t.every((e,t)=>e===r[t]))?t:r})},[x,m,q]),(0,l.useEffect)(()=>{V(e=>{let t=new Set;for(let e of x)for(let r of e.tabs)t.add(r);let r=e.filter(e=>t.has(e));return r.length===e.length?e:r})},[x]),(0,l.useEffect)(()=>{if(!r)return;J.current&&J.current!==r&&(c.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modifiedPaths:new Set}}),G(!1)),J.current=r;let e="halo_tabs:".concat(r),t=localStorage.getItem(e);if(!t)return void G(!0);let a=!1;return async function(){try{var e,s,n;let l=JSON.parse(t),o=null!=(s=l.groups)?s:l.tabs?[{tabs:l.tabs,activeTab:null!=(e=l.activeTab)?e:null}]:[],i=null!=(n=l.activeGroupIdx)?n:0;if(0===o.length)return void G(!0);let d=Array.from(new Set(o.flatMap(e=>e.tabs.map(e=>e.path)))),u=new Map;for(let e of o)for(let t of e.tabs)u.has(t.path)||u.set(t.path,t.language);let m=await Promise.all(d.map(async e=>{var t,a;let s=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"";if(tn.has(s))try{let t=await v.F.files.stat(e,r);return{path:e,content:"",originalContent:"",language:"",size:t.size,mtime:t.modifiedAt,createdAt:t.createdAt,preview:{downloadUrl:v.F.files.downloadUrl(e,r),viewUrl:v.F.files.viewUrl(e,r)}}}catch(e){return null}try{let t=await v.F.files.read(e,r);return{path:e,content:t.content,originalContent:t.content,language:u.get(e)||_(e),mtime:t.modifiedAt,size:t.size,createdAt:t.createdAt}}catch(e){return null}}));if(a)return;let x={};for(let e of m)e&&(x[e.path]=e);let p=o.map((e,t)=>{var r;let a=e.tabs.map(e=>e.path).filter(e=>x[e]),s=e.activeTab&&a.includes(e.activeTab)?e.activeTab:null!=(r=a[0])?r:null;return{id:"g_restored_".concat(t,"_").concat(Date.now().toString(36)),tabs:a,activeTab:s}}).filter(e=>e.tabs.length>0);if(0===p.length)c.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null}});else{let e=Math.max(0,Math.min(i,p.length-1)),t=p[e],r=t.tabs.map(e=>x[e]).filter(e=>!!e);c.setState({buffers:x,groups:p,activeGroupIdx:e,tabs:r,activeTab:t.activeTab})}}catch(e){}a||G(!0)}(),()=>{a=!0}},[r]),(0,l.useEffect)(()=>{if(!r||!K)return;let e=x.map(e=>({tabs:e.tabs.map(e=>{let t=m[e];return{path:e,isPreview:!!(null==t?void 0:t.preview),language:null==t?void 0:t.language}}),activeTab:e.activeTab}));localStorage.setItem("halo_tabs:".concat(r),JSON.stringify({groups:e,activeGroupIdx:h}))},[x,h,m,r,K]);let Y=d.find(e=>e.path===u),$=(0,l.useCallback)(()=>{let e=c.getState().activeTab;if(!e||!r)return;let t=c.getState().tabs.find(t=>t.path===e);t&&!t.preview&&v.F.files.stat(e,r).then(t=>{c.getState().checkAndRefresh(e,t.modifiedAt,()=>v.F.files.read(e,r))}).catch(()=>{})},[r]);(0,l.useEffect)(()=>{K&&$()},[u,$,K]);let Q=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.path});(0,l.useEffect)(()=>{if(r&&Q)return j.on("file:changed",e=>{if("change"!==e.action)return;let t="".concat(Q,"/").concat(e.path),a=r.endsWith("/")?r:"".concat(r,"/");if(!t.startsWith(a))return;let s=t.slice(a.length),n=c.getState().tabs.find(e=>e.path===s);!n||n.preview||n.modified||v.F.files.read(s,r).then(e=>{c.getState().checkAndRefresh(s,e.modifiedAt,async()=>({content:e.content,modifiedAt:e.modifiedAt}))}).catch(()=>{})})},[r,Q,c]),(0,l.useEffect)(()=>{let e=()=>$();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[$]);let X=(0,l.useCallback)(async e=>{var t,a,s;if(!r)return;let n=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"";if(tn.has(n)){let t,a=v.F.files.downloadUrl(e,r),s=v.F.files.viewUrl(e,r);try{let a=await v.F.files.stat(e,r);t={size:a.size,mtime:a.modifiedAt,createdAt:a.createdAt}}catch(e){}c.getState().openPreview(e,a,s,t);return}if(c.getState().tabs.find(t=>t.path===e))return void c.getState().setActiveTab(e);try{let t=await v.F.files.read(e,r),a=_(e);c.getState().openFile(e,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}catch(r){console.error("[EditorPanel] Failed to read file:",r);let t=r instanceof Error?r.message:String(r);if(t.includes("413")||t.includes("too large")){let t=null!=(s=e.split("/").pop())?s:e;alert('"'.concat(t,'" is too large to open in the editor (max 10MB).'))}}},[r]),ee=(0,l.useCallback)(async(e,t)=>{let r=c.getState(),a=r.buffers[t],s=r.groups.some((r,a)=>a!==e&&r.tabs.includes(t));(null==a||!a.modified||s||await R('"'.concat(t.split("/").pop(),'" has unsaved changes. Close anyway?')))&&c.getState().closeTabIn(e,t)},[]),et=(0,l.useCallback)(async e=>{if(r)try{let t=await v.F.files.read(e,r),a=_(e);c.getState().closeTab(e),c.getState().openFile(e,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}catch(e){console.error("[EditorPanel] Failed to open as text:",e)}},[r]),er=(0,l.useCallback)((e,t)=>{c.getState().updateContent(e,t)},[]),ea=(0,l.useCallback)(async e=>{let t=null!=e?e:u;if(!t||!r)return;let a=c.getState().tabs.find(e=>e.path===t);if(a&&a.modified)try{let e=await v.F.files.save(t,a.content,r);c.getState().markSaved(t,e.modifiedAt)}catch(e){console.error("[EditorPanel] Failed to save file:",e)}},[r,u]),es=(0,l.useCallback)((e,t)=>{let r=c.getState().buffers[t];r&&S(a=>({...a,[e]:{original:r.originalContent,modified:r.content,path:t}}))},[]),en=(0,l.useCallback)(e=>{S(t=>({...t,[e]:null}))},[]),el=(0,l.useCallback)(async(e,t)=>{if(r){U({count:e.length,progress:0});try{await v.F.files.upload(e,r,t||void 0,(e,t)=>{t>0&&U(r=>r?{...r,progress:e/t*100}:null)}),U(e=>e?{...e,progress:100}:null),setTimeout(()=>U(null),400),y(r,c)}catch(e){U(null),console.error("[EditorPanel] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}}},[r]),eo=(0,l.useCallback)(async(e,t)=>{var a;if(!r)return;let s=null!=(a=e.split("/").pop())?a:"",n=t?"".concat(t,"/").concat(s):s;if(e!==n)try{await v.F.files.rename(e,n,r);let t=c.getState();t.tabs.find(t=>t.path===e)&&t.closeTab(e),y(r,c)}catch(e){console.error("[EditorPanel] Move failed:",e),window.alert(e instanceof Error?e.message:"Move failed")}},[r]),ei=(0,l.useCallback)((e,t)=>{P(e),t&&L(t)},[]),ec=(0,l.useCallback)(e=>{E(e)},[]),ed=(0,l.useCallback)(async e=>{var t,a,s,n,l;if(!r)return;let o=""===e.path&&e.isDir,i=(()=>{if(!o)return{path:e.path,isDir:e.isDir};if(0===D.size)return{path:"",isDir:!0};let t=D.values().next().value;return{path:t,isDir:function(e,t){if(!e||!t)return!0;let r=t.split("/").filter(Boolean),a=e;for(let e of r){var s;if(!(a=null==a||null==(s=a.children)?void 0:s.find(t=>t.name===e)))return!1}return"directory"===a.type}(B,t)}})(),d=i.isDir?i.path:i.path.includes("/")?i.path.substring(0,i.path.lastIndexOf("/")):"";if("new-file"===e.type||"new-folder"===e.type){d&&eh(d,!0),O({mode:"new-file"===e.type?"create-file":"create-folder",parentDir:d});return}if("open-to-side"===e.type){if(e.isDir)return;try{let n=null!=(a=null==(t=e.path.split(".").pop())?void 0:t.toLowerCase())?a:"",l=tn.has(n),o=c.getState();1===o.groups.length&&o.splitToRight(null!=(s=o.groups[0].activeTab)?s:e.path);let i=+(c.getState().groups.length>1);if(l){let t=await v.F.files.stat(e.path,r);c.getState().openFileInGroup(i,e.path,"","",t.modifiedAt,{size:t.size,createdAt:t.createdAt}),c.setState(t=>({buffers:{...t.buffers,[e.path]:{...t.buffers[e.path],preview:{downloadUrl:v.F.files.downloadUrl(e.path,r),viewUrl:v.F.files.viewUrl(e.path,r)}}}}))}else{let t=await v.F.files.read(e.path,r),a=_(e.path);c.getState().openFileInGroup(i,e.path,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}}catch(e){console.error("[EditorPanel] Open to the side failed:",e),window.alert(e instanceof Error?e.message:"Open to the side failed")}return}if("open-terminal"===e.type){if(!Q)return;let e=d?"".concat(Q,"/").concat(d):Q;p.getState().requestTerminalSpawn(e),p.getState().setBottomTab("terminal");return}if("open-as-workspace"===e.type){if(!e.isDir||!Q)return;let t=e.path?"".concat(Q,"/").concat(e.path):Q;window.dispatchEvent(new CustomEvent("halo:open-workspace",{detail:{path:t}}));return}if("reveal-in-file-manager"===e.type){if(!Q)return;let t=window.haloReveal;if(!t)return;let r=e.path?"".concat(Q,"/").concat(e.path):Q;t.reveal(r,e.isDir);return}if("download"===e.type){let t=v.F.files.downloadUrl(e.path,r),a=document.createElement("a");a.href=t,a.download=null!=(n=e.path.split("/").pop())?n:"file",document.body.appendChild(a),a.click(),a.remove();return}if("rename"===e.type){let t=null!=(l=e.path.split("/").pop())?l:"";O({mode:"rename",parentDir:e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"",originalPath:e.path,originalName:t});return}if("delete"===e.type){let t=D.size>1&&D.has(e.path)?Array.from(D):[e.path];if(t.length>1){if(!await R("Delete ".concat(t.length," items?")))return}else{let t=e.isDir?"folder":"file";if(!await R("Delete ".concat(t,' "').concat(e.path.split("/").pop(),'"?')))return}try{for(let e of t)await v.F.files.remove(e,r),c.getState().closeTab(e);P(new Set),y(r,c)}catch(e){console.error("[EditorPanel] Delete failed:",e),window.alert(e instanceof Error?e.message:"Delete failed"),y(r,c)}}},[r,D]),eu=(0,l.useCallback)(()=>{O(null)},[]),em=(0,l.useCallback)(async e=>{if(!r||!z)return;let t=e.trim();if(""===t)return void O(null);let{mode:a,parentDir:s,originalPath:n,originalName:l}=z;if("rename"===a){if(!n||t===l)return void O(null);let e=s?"".concat(s,"/").concat(t):t;try{await v.F.files.rename(n,e,r),c.getState().closeTab(n),y(r,c)}catch(e){console.error("[EditorPanel] Rename failed:",e),window.alert(e instanceof Error?e.message:"Rename failed")}return void O(null)}let o=s?"".concat(s,"/").concat(t):t;try{"create-file"===a?await v.F.files.create(o,r):await v.F.files.mkdir(o,r),y(r,c)}catch(e){console.error("[EditorPanel] Create failed:",e),window.alert(e instanceof Error?e.message:"Create failed")}O(null)},[r,z,c]);(0,l.useEffect)(()=>{function e(e){var t,r;if("Enter"!==e.key||z||1!==D.size)return;let a=e.target;if(!(null==a||null==(t=a.closest)?void 0:t.call(a,"[data-file-tree-root]")))return;let s=D.values().next().value,n=null!=(r=s.split("/").pop())?r:"";O({mode:"rename",parentDir:s.includes("/")?s.substring(0,s.lastIndexOf("/")):"",originalPath:s,originalName:n})}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D,z]);let ex=W&&(0,n.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between text-[10px] text-[var(--muted-foreground)]",children:[(0,n.jsxs)("span",{children:["Uploading ",W.count," file",W.count>1?"s":"","..."]}),(0,n.jsxs)("span",{children:[Math.round(W.progress),"%"]})]}),(0,n.jsx)("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-[var(--secondary)]",children:(0,n.jsx)("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-150",style:{width:"".concat(W.progress,"%")}})})]});if("tree-only"===a)return(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[ex,D.size>0&&(0,n.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,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[D.size," selected"]}),(0,n.jsx)("button",{onClick:()=>P(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,n.jsx)(eK.A,{className:"h-3 w-3"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:H?(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):B?(0,n.jsx)(eb,{node:B,projectId:r,onSelect:X,onContextMenu:ec,onDropFiles:el,onMoveFile:eo,selectedPaths:D,onSelectionChange:ei,lastAnchor:M,depth:0,pendingEdit:z,onCommitEdit:em,onCancelEdit:eu}):(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"})}),T&&(0,n.jsx)(eA,{x:T.x,y:T.y,path:T.path,name:T.name,isDir:T.isDir,selectedCount:D.size>1&&D.has(T.path)?D.size:void 0,onAction:ed,onClose:()=>E(null)})]});let ep="full"===a&&w;return(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:["full"===a&&(0,n.jsx)("button",{onClick:()=>N(!w),className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:w?(0,n.jsx)(eR.A,{className:"h-4 w-4"}):(0,n.jsx)(e_.A,{className:"h-4 w-4"})}),(0,n.jsx)(e7.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:o("nav.canvas")}),Y&&(null!=Y.size||null!=Y.mtime)&&(0,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",[null!=Y.size?(t=Y.size)<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MB"):"",null!=Y.createdAt?"Created ".concat(ts(Y.createdAt)):"",null!=Y.mtime?"Modified ".concat(ts(Y.mtime)):""].filter(Boolean).join(" \xb7 "),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1",children:s&&(0,n.jsx)("button",{onClick:()=>c.getState().toggleMaximized(),title:f?"Exit full screen":"Maximize editor",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:f?(0,n.jsx)(te.A,{className:"h-4 w-4"}):(0,n.jsx)(tt.A,{className:"h-4 w-4"})})})]}),(0,n.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:ep?"halo-editor-tree":void 0,children:[ep&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.Zk,{defaultSize:20,minSize:10,maxSize:40,children:(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--card)]",children:[ex,(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:r?H?(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):B?(0,n.jsx)(eb,{node:B,projectId:r,onSelect:X,onContextMenu:ec,onDropFiles:el,onMoveFile:eo,selectedPaths:D,onSelectionChange:ei,lastAnchor:M,depth:0,pendingEdit:z,onCommitEdit:em,onCancelEdit:eu}):(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"}):(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Open a folder to view files"})})]})}),(0,n.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"})]}),(0,n.jsx)(i.Zk,{defaultSize:80,minSize:40,children:(0,n.jsx)(i.YZ,{direction:"horizontal",autoSaveId:"halo-editor-panes",children:x.map((e,t)=>{var a;let s=e.tabs.map(e=>m[e]).filter(e=>!!e),l=e.activeTab,o=s.find(e=>e.path===l),d=t===h;return(0,n.jsx)(i.Zk,{defaultSize:100/x.length,minSize:20,children:(0,n.jsxs)("div",{className:F("flex h-full flex-col overflow-hidden",d&&x.length>1&&"ring-1 ring-inset ring-[var(--primary)]/30"),onMouseDown:()=>c.getState().setActiveGroup(t),children:[s.length>0&&(()=>{let r=I(e.id),a=k[e.id],i=!!(null==o?void 0:o.modified)&&!o.preview;return(0,n.jsx)(eV,{tabs:s,activeTab:l,groupIdx:t,canSplit:b&&1===x.length,onCloseTab:e=>ee(t,e),renderMode:r,onToggleRenderMode:()=>A(t=>({...t,[e.id]:!r})),showDiffButton:i,onToggleDiff:()=>{a?en(e.id):o&&es(e.id,o.path)}})})(),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden",children:[Z.map(e=>s.find(t=>t.path===e&&t.preview)).filter(e=>!!e).map(e=>{var t;return(0,n.jsx)("div",{className:F("h-full",(null==o?void 0:o.path)!==e.path&&"hidden"),children:(0,n.jsx)(e8,{path:e.path,name:null!=(t=e.path.split("/").pop())?t:"",downloadUrl:e.preview.downloadUrl,viewUrl:e.preview.viewUrl,onOpenAsText:()=>et(e.path)})},e.path)}),(null==o?void 0:o.preview)&&q(o.path)&&(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(e8,{path:o.path,name:null!=(a=o.path.split("/").pop())?a:"",downloadUrl:o.preview.downloadUrl,viewUrl:o.preview.viewUrl,onOpenAsText:()=>et(o.path)})}),(()=>{let a=k[e.id],s=I(e.id);if(null==o?void 0:o.preview)return null;if(a)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,n.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["Diff: ",a.path]}),(0,n.jsx)("button",{onClick:()=>en(e.id),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(eB,{original:a.original,modified:a.modified,path:a.path})})]});if(o){var l;let e=s&&"markdown"===o.language,a=s&&"html"===o.language&&!!r;return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)(ez,{content:o.content,filePath:o.path,projectId:r}),a&&(0,n.jsx)(eU,{url:v.F.files.viewUrl(o.path,r),name:null!=(l=o.path.split("/").pop())?l:""}),(0,n.jsx)("div",{className:F("h-full",(e||a)&&"hidden"),children:(0,n.jsx)(eP,{path:"".concat(null!=r?r:"","/").concat(o.path),content:o.content,language:o.language,onChange:e=>er(o.path,e),onSave:()=>ea(o.path),onClose:()=>ee(t,o.path)})})]})}return(0,n.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(e7.A,{className:"mx-auto h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.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,n.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"},"rh-".concat(t))]:[e])},x.length)})]}),T&&(0,n.jsx)(eA,{x:T.x,y:T.y,path:T.path,name:T.name,isDir:T.isDir,selectedCount:D.size>1&&D.has(T.path)?D.size:void 0,onAction:ed,onClose:()=>E(null)})]})}function to(e){return e.type?e.type:"user"===e.role?"user":"assistant"===e.role?"assistant":e.toolName?"tool_call":void 0===e.toolOutput||e.toolName?e.usage?"usage":e.systemPrompt?"context":"notification":"tool_result"}function ti(e){if(e.taskId)return!1;let t=to(e);return"user"===t||"assistant"===t||"notification"===t}var tc=r(22813),td=r(80685),tu=r(92387),tm=r(13277),tx=r(99484),tp=r(76042);let th={pending:{icon:O.A,color:"text-[var(--muted-foreground)]",label:"Pending"},running:{icon:H.A,color:"text-blue-400",label:"Running"},completed:{icon:tc.A,color:"text-emerald-400",label:"Done"},failed:{icon:td.A,color:"text-red-400",label:"Failed"},skipped:{icon:tu.A,color:"text-[var(--muted-foreground)]",label:"Skipped"}};function tf(e){let{plan:t}=e,[r,a]=(0,l.useState)(!0),[s,o]=(0,l.useState)(!1),[i,c]=(0,l.useState)(""),d="pending_approval"===t.status,u=t.tasks.filter(e=>"completed"===e.status).length,m=t.tasks.length,x=(0,l.useCallback)(()=>{j.send({type:"approve",planId:t.id})},[t.id]),p=(0,l.useCallback)(()=>{i.trim()&&(j.send({type:"reject",planId:t.id,feedback:i.trim()}),o(!1),c(""))},[t.id,i]);return(0,n.jsxs)("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--card)] overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>a(!r),className:"flex w-full items-center justify-between px-3 py-2.5 text-left transition-colors hover:bg-[var(--secondary)]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[r?(0,n.jsx)(W.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}):(0,n.jsx)(U.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Task Plan"}),(0,n.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",u,"/",m,")"]})]}),(0,n.jsx)(tv,{status:t.status})]}),r&&(0,n.jsxs)("div",{className:"border-t border-[var(--border)]",children:[(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-[var(--muted-foreground)]",children:t.description}),(0,n.jsx)("div",{className:"px-3 pb-2",children:t.tasks.map(e=>(0,n.jsx)(tg,{task:e,allTasks:t.tasks},e.id))}),d&&(0,n.jsx)("div",{className:"border-t border-[var(--border)] px-3 py-2.5",children:s?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:i,onChange:e=>c(e.target.value),placeholder:"Explain what should be changed...",rows:2,className:"w-full resize-none rounded-md border border-[var(--border)] bg-[var(--secondary)] px-2.5 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:p,disabled:!i.trim(),className:F("rounded-md px-3 py-1.5 text-xs font-medium transition-colors",i.trim()?"bg-[var(--destructive)] text-white hover:bg-red-500":"bg-[var(--secondary)] text-[var(--muted-foreground)] cursor-not-allowed"),children:"Send Feedback"}),(0,n.jsx)("button",{onClick:()=>{o(!1),c("")},className:"rounded-md px-3 py-1.5 text-xs text-[var(--muted-foreground)] transition-colors hover:text-[var(--foreground)]",children:"Cancel"})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:x,className:"flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-emerald-500",children:[(0,n.jsx)(tm.A,{className:"h-3.5 w-3.5"}),"Approve"]}),(0,n.jsxs)("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--secondary)] px-3 py-1.5 text-xs font-medium text-[var(--secondary-foreground)] transition-colors hover:bg-[var(--accent)]",children:[(0,n.jsx)(tx.A,{className:"h-3.5 w-3.5"}),"Reject"]})]})})]})]})}function tg(e){let{task:t,allTasks:r}=e,a=th[t.status],s=a.icon,l=t.dependencies.map(e=>{var t;return null==(t=r.find(t=>t.id===e))?void 0:t.name}).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-start gap-2 py-1.5",children:[(0,n.jsx)(s,{className:F("mt-0.5 h-4 w-4 shrink-0",a.color,"running"===t.status&&"animate-spin")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.name}),t.agentId&&(0,n.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)]",children:t.agentId})]}),t.description&&(0,n.jsx)("p",{className:"mt-0.5 text-[11px] leading-relaxed text-[var(--muted-foreground)]",children:t.description}),l.length>0&&(0,n.jsxs)("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] text-[var(--muted-foreground)]",children:[(0,n.jsx)(tp.A,{className:"h-3 w-3"}),(0,n.jsxs)("span",{children:["after: ",l.join(", ")]})]})]})]})}function tv(e){var t,r;let{status:a}=e;return(0,n.jsx)("span",{className:F("rounded-full border px-2 py-0.5 text-[10px] font-medium",null!=(t=({pending_approval:"bg-amber-900/50 text-amber-300 border-amber-700",approved:"bg-blue-900/50 text-blue-300 border-blue-700",running:"bg-blue-900/50 text-blue-300 border-blue-700",completed:"bg-emerald-900/50 text-emerald-300 border-emerald-700",failed:"bg-red-900/50 text-red-300 border-red-700",rejected:"bg-[var(--secondary)] text-[var(--muted-foreground)] border-[var(--border)]"})[a])?t:"bg-[var(--secondary)] text-[var(--muted-foreground)] border-[var(--border)]"),children:null!=(r=({pending_approval:"Needs Approval",approved:"Approved",running:"Running",completed:"Completed",failed:"Failed",rejected:"Rejected"})[a])?r:a})}var tb=r(10509),tj=r(93099),ty=r(13523);let tw=/\.(png|jpe?g|gif|webp|bmp|svg)$/i,tN=/\.(mp4|webm|mov|m4v|ogv)$/i,tk=/\.(mp3|wav|flac|aac|m4a|ogg|opus|amr|silk)$/i;function tS(e){return tw.test(e)?"image":tN.test(e)?"video":tk.test(e)?"audio":"file"}function tC(e){let t=[],r=e.replace(/\[(图片|视频|语音消息(?:\s*[^\s]+)?|文件(?:\s*"[^"]*")?)\s*已保存:\s*([^,\]]+)(?:,\s*服务端转写:\s*([^\]]+))?\]/g,(e,r,a,s)=>{let n,l=a.trim();n=r.startsWith("图片")?"image":r.startsWith("视频")?"video":r.startsWith("语音")?"audio":r.startsWith("文件")?"file":tS(l);let o=r.match(/"([^"]+)"/),i=o?o[1]:s?s.trim():void 0;return t.push({path:l,kind:n,label:i}),""});return{text:r=(r=r.replace(/^[ \t]*MEDIA:\s*(\S.*?)\s*$/gm,(e,r)=>{let a=r.trim();return t.push({path:a,kind:tS(a)}),""})).replace(/\n{3,}/g,"\n\n").trim(),media:t}}function tA(e){let{media:t}=e,[r,a]=(0,l.useState)(null);return 0===t.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:t.map((e,t)=>(0,n.jsx)(tT,{media:e,onOpen:()=>a(e)},"".concat(e.path,"-").concat(t)))}),r&&(0,n.jsx)(tD,{media:r,onClose:()=>a(null)})]})}function tI(e,t){if(!t)return null;let r=e=>e.replace(/\\/g,"/").toLowerCase(),a=r(e),s=r(t).replace(/\/$/,""),n=a===s||a.startsWith(s+"/"),l=/(^|\/)(tmp|temp)\//.test(a);if(!n&&!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 tT(e){var t;let{media:r,onOpen:a}=e,s=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),l=tI(r.path,s),o=null!=(t=r.path.split("/").pop())?t:r.path;return l?(0,n.jsxs)("button",{onClick:a,className:"inline-flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 text-[11px] text-[var(--foreground)] cursor-pointer hover:ring-1 hover:ring-[var(--primary)]/40 transition-all no-underline",title:o,children:[(0,n.jsx)(tE,{kind:r.kind}),(0,n.jsx)("span",{className:"truncate max-w-[240px] font-mono",children:r.label||o})]}):(0,n.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,n.jsx)(tE,{kind:r.kind}),o]})}function tE(e){let{kind:t}=e,r="h-3 w-3";return"image"===t?(0,n.jsx)(tb.A,{className:r}):"video"===t?(0,n.jsx)(tj.A,{className:r}):"audio"===t?(0,n.jsx)(ty.A,{className:r}):(0,n.jsx)(Z.A,{className:r})}function tD(e){var t;let{media:r,onClose:a}=e,s=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),o=tI(r.path,s),[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&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]),!o)return null;let d="".concat(o,"&t=").concat(i),u="".concat(o.replace("&inline=1",""),"&t=").concat(i);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:a,children:["file"!==r.kind&&(0,n.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,n.jsx)(eS.A,{className:"h-5 w-5"})}),(0,n.jsx)("button",{onClick:a,className:"absolute right-4 top-4 rounded p-2 text-white/80 hover:bg-white/10 hover:text-white","aria-label":"Close",children:(0,n.jsx)(eK.A,{className:"h-5 w-5"})}),(0,n.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,n.jsx)("img",{src:d,alt:r.path,className:"max-h-[85vh] max-w-[90vw] object-contain"}),"video"===r.kind&&(0,n.jsx)("video",{src:d,controls:!0,autoPlay:!0,className:"max-h-[85vh] max-w-[90vw]"}),"audio"===r.kind&&(0,n.jsx)("audio",{src:d,controls:!0,autoPlay:!0,className:"w-[min(80vw,480px)]"}),"file"===r.kind&&(0,n.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,n.jsx)("div",{className:"max-w-[90vw] truncate font-mono text-[11px] text-white/60",children:r.path})]})]})}function tF(e){var t,r;let a=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)&&a-e.timestamp>3e4}let tP=0,tM=null;function tL(e,t,r,a){if(!a)return e;for(let n=e.length-1;n>=0;n--){var s;let l=e[n];if(l.taskId!==r||"assistant"!==l.role||!l.streaming||t&&l.agentName&&l.agentName.toLowerCase()!==t.toLowerCase())continue;let o=null!=(s=l.contentBlocks)?s:[],i=o.length>0?o[o.length-1].turnId:void 0;if(!i||i===a)return e;let c=[...e];return c[n]={...l,streaming:!1},c.push({id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}),c}return[...e,{id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}]}let tR=(0,c.v)((e,t)=>({messages:[],isStreaming:!1,sessionId:null,pendingMessages:[],contextTokens:0,outputTokens:0,maxContextTokens:0,isCompacting:!1,selectedAgentId:"default",usableAgentCount:-1,captureSource:null,addMessage(t){var r,a;let s={id:null!=(r=t.id)?r:P(),type:t.type,role:t.role,content:t.content,timestamp:null!=(a=t.timestamp)?a:Date.now(),plan:t.plan,streaming:t.streaming,agentName:t.agentName,taskId:t.taskId,contentBlocks:t.contentBlocks,toolName:t.toolName,toolInput:t.toolInput,toolOutput:t.toolOutput,systemPrompt:t.systemPrompt,usage:t.usage,turnId:t.turnId,modelId:t.modelId,durationMs:t.durationMs,localImages:t.localImages,clientMsgId:t.clientMsgId};e(e=>{var r,a;let n=e.messages.filter(ti).length;return console.log("[ChatStore:addMessage] role=".concat(s.role," type=").concat(null!=(r=s.type)?r:"-"," streaming=").concat(!!s.streaming," taskId=").concat(null!=(a=s.taskId)?a:"-"," main=").concat(n,"+").concat(+!!ti(s))),{messages:[...e.messages,s],isStreaming:!!t.streaming&&!t.taskId||e.isStreaming}})},appendThinking(t,r,a,s){e(e=>{let n=[...tL(e.messages,r,a,s)];for(let e=n.length-1;e>=0;e--){let r=n[e];if("assistant"===r.role&&r.streaming){var l;if(r.taskId!==a)continue;let o=[...null!=(l=r.contentBlocks)?l:[]],i=o[o.length-1];i&&"thinking"===i.type&&(!s||i.turnId===s)?o[o.length-1]={type:"thinking",text:i.text+t,turnId:null!=s?s:i.turnId}:o.push({type:"thinking",text:t,turnId:s}),n[e]={...r,contentBlocks:o};break}}return{messages:n}})},updateLastAssistant(t,r,a,s){e(e=>{let n=[...tL(e.messages,r,a,s)],l=!1;for(let e=n.length-1;e>=0;e--){let r=n[e];if("assistant"===r.role&&r.streaming){var o;if(r.taskId!==a)continue;let i=[...null!=(o=r.contentBlocks)?o:[]],c=i[i.length-1];c&&"text"===c.type&&(!s||c.turnId===s)?i[i.length-1]={type:"text",text:c.text+t,turnId:null!=s?s:c.turnId}:i.push({type:"text",text:t,turnId:s}),n[e]={...r,content:r.content+t,contentBlocks:i},l=!0;break}}return l&&!a?{messages:n,isStreaming:!0}:{messages:n}})},addToolCallToLastAssistant(t,r,a,s){e(e=>{if(t.toolUseId&&e.messages.some(e=>{var r,a;return(null==(r=e.toolCalls)?void 0:r.some(e=>e.toolUseId===t.toolUseId))||(null==(a=e.contentBlocks)?void 0:a.some(e=>"tool_call"===e.type&&e.toolCall.toolUseId===t.toolUseId))}))return e;let n=[...tL(e.messages,r,a,s)];for(let e=n.length-1;e>=0;e--){let r=n[e];if("assistant"===r.role&&r.streaming){var l,o;if(r.taskId!==a)continue;let i=[...null!=(l=r.contentBlocks)?l:[]];i.push({type:"tool_call",toolCall:t,turnId:s}),n[e]={...r,toolCalls:[...null!=(o=r.toolCalls)?o:[],t],contentBlocks:i};break}}return{messages:n}})},updateLastToolCallResult(t,r,a,s){e(e=>{var r,n,l,o,i,c;let d=[...e.messages];if(s)for(let a=d.length-1;a>=0;a--){let i=d[a],c=null!=(l=null==(r=i.toolCalls)?void 0:r.findIndex(e=>e.toolUseId===s))?l:-1,u=null!=(o=null==(n=i.contentBlocks)?void 0:n.findIndex(e=>"tool_call"===e.type&&e.toolCall.toolUseId===s))?o:-1;if(-1===c&&-1===u)continue;if(-1!==c&&void 0!==i.toolCalls[c].output||-1!==u&&void 0!==i.contentBlocks[u].toolCall.output)return e;let m=i.toolCalls?[...i.toolCalls]:i.toolCalls;m&&-1!==c&&(m[c]={...m[c],output:t});let x=i.contentBlocks?[...i.contentBlocks]:i.contentBlocks;if(x&&-1!==u){let e=x[u];x[u]={type:"tool_call",toolCall:{...e.toolCall,output:t},turnId:e.turnId}}return d[a]={...i,toolCalls:m,contentBlocks:x},{messages:d}}for(let e=d.length-1;e>=0;e--){let r=d[e];if("assistant"===r.role&&r.streaming&&(null==(i=r.toolCalls)?void 0:i.length)){if(r.taskId!==a)continue;let s=[...r.toolCalls],n=s.findIndex(e=>void 0===e.output);-1!==n&&(s[n]={...s[n],output:t});let l=[...null!=(c=r.contentBlocks)?c:[]];for(let e=0;e<l.length;e++){let r=l[e];if("tool_call"===r.type&&void 0===r.toolCall.output){l[e]={type:"tool_call",toolCall:{...r.toolCall,output:t},turnId:r.turnId};break}}d[e]={...r,toolCalls:s,contentBlocks:l};break}}return{messages:d}})},completeStreaming(){e(e=>({messages:e.messages.map(e=>e.streaming?{...e,streaming:!1}:e),isStreaming:!1}))},completeAgentStreaming(t,r){e(e=>{let a=e.messages.filter(ti).length,s=e.messages.map(e=>e.streaming?(!r||e.taskId!==r)&&(r||e.taskId)?e:{...e,streaming:!1}:e),n=s.filter(ti).length,l=s.some(e=>e.streaming&&!e.taskId);return a!==n&&console.warn("[ChatStore:completeAgentStreaming] main msgs changed ".concat(a," -> ").concat(n,", agentName=").concat(t,", taskId=").concat(r)),{messages:s,isStreaming:l}})},setSessionId(t){e({sessionId:t})},setMessages(r){var a;let s=t().messages;console.log("[ChatStore:setMessages] ".concat(s.length," -> ").concat(r.length),null==(a=Error().stack)?void 0:a.split("\n").slice(1,4).join(" <- ")),e({messages:r})},setTokenUsage(t,r){e({contextTokens:t,outputTokens:r})},setMaxContextTokens(t){t>0&&e({maxContextTokens:t})},setCompacting(t){e({isCompacting:t})},setSelectedAgentId(t){e({selectedAgentId:t})},setUsableAgentCount(t){e({usableAgentCount:t})},setCaptureSource(t){e({captureSource:t})},addPendingMessage(t){e(e=>({pendingMessages:[...e.pendingMessages,t]}))},removePendingMessage(t){e(e=>({pendingMessages:e.pendingMessages.filter((e,r)=>r!==t)}))},shiftPendingMessage(){let r=t().pendingMessages;if(0===r.length)return;let[a,...s]=r;return e({pendingMessages:s}),a},markChatSendFailed(t){e(e=>{let r=e.messages.findIndex(e=>e.clientMsgId===t);if(-1===r)return e;let a=e.messages.map((e,t)=>{var a,s;return t===r?{...e,sendFailed:!0}:!(t>r)||!e.streaming||e.taskId||e.content||(null==(a=e.toolCalls)?void 0:a.length)||(null==(s=e.contentBlocks)?void 0:s.length)?e:{...e,streaming:!1,interrupted:!0}});return{messages:a,isStreaming:a.some(e=>e.streaming&&!e.taskId)}})},convergeStaleStreaming(){if(t().isCompacting||0===tP)return;let r=Date.now(),a=e=>e.timestamp<=tP&&tF(e,r);t().messages.some(a)&&e(e=>{let t=e.messages.map(e=>a(e)?{...e,streaming:!1,interrupted:!0}:e);return{messages:t,isStreaming:t.some(e=>e.streaming&&!e.taskId)}})},clear(){var r;console.log("[ChatStore:clear] dropping ".concat(t().messages.length," messages"),null==(r=Error().stack)?void 0:r.split("\n").slice(1,4).join(" <- ")),e({messages:[],isStreaming:!1,pendingMessages:[],sessionId:null,contextTokens:0,outputTokens:0})}})),t_=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function tz(){t_.getState().bump()}var tO=r(57580);function tW(e){let t="number"==typeof e?e:new Date(e).getTime(),r=Math.floor((Date.now()-t)/1e3);if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return"".concat(a,"m ago");let s=Math.floor(a/60);if(s<24)return"".concat(s,"h ago");let n=Math.floor(s/24);return n<30?"".concat(n,"d ago"):new Date(t).toLocaleDateString()}function tU(e){let{count:t,onClick:r}=e;return 0===t?null:(0,n.jsxs)("button",{onClick:r,className:"flex items-center gap-1 text-[10px] text-[var(--primary)] hover:underline",children:[(0,n.jsx)(tO.A,{className:"h-3 w-3"}),t," previous session",t>1?"s":""]})}var tB=r(89983),tH=r(66926),tK=r(63865),tG=r(76688),tJ=r(87097);let tq=(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 tZ(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 tV(e){let t=0;for(let r of e)t+=1+tV(r.children);return t}function tY(e){let{nodes:t,depth:r,expanded:a,selectedSessionId:s,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:x}=e,p=12+16*r;return(0,n.jsx)(n.Fragment,{children:t.map(e=>{let t=s===e.id,h=!!e.stoppedAt,f=!!e.archivedAt,g=e.children.length>0,v=a.has(e.id);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>o(e),title:"Click to preview sub-agent session",className:F("group flex w-full items-center gap-1.5 pr-3 py-1.5 text-left transition-colors border-b border-[var(--border)]/10",t?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/40",f&&"opacity-50"),style:{paddingLeft:"".concat(p,"px")},children:[g?(0,n.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,n.jsx)(U.A,{className:F("h-2.5 w-2.5 text-[var(--muted-foreground)] transition-transform",v&&"rotate-90")})}):(0,n.jsx)("span",{className:"w-4 shrink-0 -ml-0.5"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.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,n.jsx)("input",{autoFocus:!0,value:c,onChange:e=>d(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),m(e.id)):"Escape"===t.key&&(t.preventDefault(),x())},onBlur:()=>m(e.id),className:"min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[10px] text-[var(--foreground)] outline-none focus:border-blue-500"}):(0,n.jsxs)("p",{className:"truncate text-[10px] text-[var(--foreground)]",children:[e.goalSessionId&&(0,n.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),e.title||"Untitled"]}),h&&(0,n.jsx)("span",{title:"Stopped",children:(0,n.jsx)(tB.A,{className:"h-2.5 w-2.5 shrink-0 text-[var(--muted-foreground)]"})}),f&&(0,n.jsx)("span",{title:"Archived",children:(0,n.jsx)(tH.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),g&&(0,n.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",tV(e.children)]})]}),(0,n.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",tW(e.updatedAt)]})]}),i!==e.id&&(0,n.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,n.jsx)(eC.A,{className:"h-2.5 w-2.5"})})]}),v&&g&&(0,n.jsx)(tY,{nodes:e.children,depth:r+1,expanded:a,selectedSessionId:s,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:x})]},e.id)})})}let t$=e=>"halo_selected_session_".concat(e);function tQ(e){let t=[];return!function e(r){for(let a of r)t.push(a),e(a.children)}(e),t}function tX(){let e=tR(e=>e.isStreaming),t=tR(e=>e.sessionId),r=e9(e=>e.activeProject),{selectedSessionId:a,setSelectedSession:s,clearSelection:o,setLoadedMessages:i,setLoading:c}=tq(),[d,u]=(0,l.useState)([]),[m,x]=(0,l.useState)(null),p=(0,l.useRef)(0),[h,f]=(0,l.useState)(new Set),[g,b]=(0,l.useState)(!0),[y,w]=(0,l.useState)(!1),N=(0,l.useRef)(null),[k,S]=(0,l.useState)(null),[C,A]=(0,l.useState)(""),I=(0,l.useRef)(""),T=(0,l.useRef)(null),E=(0,l.useRef)(!1);(0,l.useEffect)(()=>{(null==r?void 0:r.id)&&N.current&&N.current!==r.id&&(o(),N.current=null)},[null==r?void 0:r.id,o]);let D=(0,l.useCallback)(async function(){let{showSpinner:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showSpinner:!0};if(!(null==r?void 0:r.path)){u([]),x(null),b(!1);return}if(null!==T.current){E.current=!0;return}E.current=!1,e&&b(!0);let t=Math.min(300,Math.max(30,p.current)),a=Date.now();try{let e=await v.F.sessionLogs.list(r.path,{includeArchived:!0,limit:t}),a=e.sessions;u(tZ(a)),x(e.nextCursor)}catch(e){console.error("[Sessions] Failed to fetch:",e),u([]),x(null)}finally{e?setTimeout(()=>b(!1),Math.max(0,350-(Date.now()-a))):b(!1)}},[null==r?void 0:r.path]),P=(0,l.useCallback)(async()=>{if((null==r?void 0:r.path)&&null!==m&&!y){w(!0);try{let e=await v.F.sessionLogs.list(r.path,{includeArchived:!0,limit:30,cursor:m}),t=e.sessions;u(e=>{let r=tQ(e),a=new Set(r.map(e=>e.id)),s=[...r,...t.filter(e=>!a.has(e.id))];return tZ(s)}),x(e.nextCursor)}catch(e){console.error("[Sessions] loadMore failed:",e)}finally{w(!1)}}},[null==r?void 0:r.path,m,y]);(0,l.useEffect)(()=>{p.current=d.length,d.length>=300&&x(null)},[d.length]);let M=t_(e=>e.version),L=(0,l.useRef)(!0);(0,l.useEffect)(()=>{D({showSpinner:L.current}),L.current=!1},[D,M]),(0,l.useEffect)(()=>{a&&!g&&!new Set(tQ(d).map(e=>e.id)).has(a)&&(o(),(null==r?void 0:r.id)&&localStorage.removeItem(t$(r.id)))},[d,a,g,o,null==r?void 0:r.id]);let _=(0,l.useRef)(e);(0,l.useEffect)(()=>{_.current&&!e&&setTimeout(()=>D({showSpinner:!1}),500),_.current=e},[e,D]);let z=(0,l.useCallback)(e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),O=(0,l.useCallback)(async e=>{if(s(e),c(!0),(null==r?void 0:r.id)&&localStorage.setItem(t$(r.id),e.id),e.id===t)return void i(tR.getState().messages);try{var a;let t=await v.F.sessionLogs.get(e.id,null==r?void 0:r.path);i(null!=(a=t.messages)?a:[])}catch(e){console.error("[Sessions] Load failed:",e),i([])}},[t,null==r?void 0:r.id,null==r?void 0:r.path,s,i,c]);(0,l.useEffect)(()=>{if(!(null==r?void 0:r.id)||g||0===d.length||N.current===r.id)return;N.current=r.id;let e=localStorage.getItem(t$(r.id));if(!e)return;let t=tQ(d),a=t.find(t=>t.id===e);if(!a)return;let s=new Map(t.map(e=>[e.id,e])),n=[],l=a;for(;null==l?void 0:l.parentSessionId;)n.push(l.parentSessionId),l=s.get(l.parentSessionId);n.length>0&&f(e=>{let t=new Set(e);for(let e of n)t.add(e);return t}),O(a)},[null==r?void 0:r.id,g,d,O]);let W=(0,l.useCallback)(e=>{r&&(tR.getState().setSessionId(e.id),tR.getState().setMessages([]),j.send({type:"subscribe",sessionId:e.id,projectId:r.id}),localStorage.setItem("halo_session_".concat(r.id),e.id))},[r]),B=(0,l.useCallback)(async(e,s)=>{if((e.stopPropagation(),null==r?void 0:r.path)&&await R("Delete this session and all its sub-sessions? History cannot be recovered."))try{u(e=>e.filter(e=>e.id!==s)),s===t&&((null==r?void 0:r.id)&&localStorage.removeItem("halo_session_".concat(r.id)),tR.getState().clear()),a===s&&(o(),(null==r?void 0:r.id)&&localStorage.removeItem(t$(r.id))),await v.F.sessionLogs.delete(s,r.path),tz()}catch(e){console.error("[Sessions] Delete failed:",e),tz()}},[t,null==r?void 0:r.path,null==r?void 0:r.id,a,o]),K=(0,l.useCallback)((e,t)=>{e.stopPropagation(),T.current=t.id,I.current=t.title||"",S(t.id),A(t.title||"")},[]),G=(0,l.useCallback)(()=>{T.current=null,S(null),A(""),E.current&&D({showSpinner:!1})},[D]),J=(0,l.useCallback)(async e=>{if(T.current!==e)return;let t=C.trim();if(!t||t===I.current||!(null==r?void 0:r.path))return void G();T.current=null,S(null),u(r=>(function e(t,r,a){return t.map(t=>t.id===r?{...t,title:a}:{...t,children:e(t.children,r,a)})})(r,e,t));try{await v.F.sessionLogs.rename(e,t,r.path),tz()}catch(e){console.error("[Sessions] Rename failed:",e),tz()}},[C,null==r?void 0:r.path,G]),q=d.length,Z=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=Z.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&P()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[P,d.length]),(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,n.jsx)(tK.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Sessions"}),q>0&&(0,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",q,null!==m?"+":"",")"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>D(),disabled:g,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh sessions",children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",g&&"animate-spin")})}),e&&(0,n.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"running"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:g?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading..."]}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,n.jsx)(tK.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"No session history yet"}),(0,n.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:"Start a conversation in the Chat panel"})]}):(0,n.jsxs)(n.Fragment,{children:[d.map(e=>{let r=e.children,s=h.has(e.id),l=e.id===t,o=a===e.id,i=!!e.archivedAt,c=r.length>0,d=tV(r);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>O(e),onDoubleClick:()=>W(e),title:"Click to preview, double-click to load into chat",className:F("group flex w-full items-center gap-1.5 px-3 py-2 text-left border-b border-[var(--border)]/30 transition-colors",o?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",i&&"opacity-50"),children:[c?(0,n.jsx)("span",{onClick:t=>{t.stopPropagation(),z(e.id)},className:"shrink-0 flex items-center justify-center w-5 h-5 -ml-1 cursor-pointer rounded hover:bg-[var(--muted)]/50",children:(0,n.jsx)(U.A,{className:F("h-3 w-3 text-[var(--muted-foreground)] transition-transform",s&&"rotate-90")})}):(0,n.jsx)("span",{className:"w-5 shrink-0 -ml-1"}),(0,n.jsx)(tJ.A,{className:F("h-3.5 w-3.5 shrink-0",l?"text-blue-400":"text-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[k===e.id?(0,n.jsx)("input",{autoFocus:!0,value:C,onChange:e=>A(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),J(e.id)):"Escape"===t.key&&(t.preventDefault(),G())},onBlur:()=>J(e.id),className:"min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[11px] text-[var(--foreground)] outline-none focus:border-blue-500"}):(0,n.jsx)("p",{className:"truncate text-[11px] font-medium text-[var(--foreground)]",children:e.title||"Untitled"}),l&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1 py-0.5 text-[8px] text-blue-400",children:"active"}),i&&(0,n.jsx)("span",{title:"Archived",children:(0,n.jsx)(tH.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),c&&(0,n.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",d]})]}),(0,n.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",tW(e.updatedAt)]})]}),k!==e.id&&(0,n.jsx)("button",{onClick:t=>K(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,n.jsx)(eC.A,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:t=>B(t,e.id),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:(0,n.jsx)(ej.A,{className:"h-3 w-3"})})]}),s&&c&&(0,n.jsx)(tY,{nodes:r,depth:1,expanded:h,selectedSessionId:a,onToggle:z,onSelect:O,editingId:k,editingTitle:C,setEditingTitle:A,onStartRename:K,onCommitRename:J,onCancelRename:G})]},e.id)}),null!==m&&(0,n.jsx)("div",{ref:Z,className:"flex items-center justify-center py-2 text-[10px] text-[var(--muted-foreground)]",children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin mr-1"})," Loading more…"]}):(0,n.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})})]})}var t0=r(72140),t1=r(68709),t5=r(6843);function t3(e){var t;let r=null==(t=e9.getState().activeProject)?void 0:t.id;if(!r)return null;let a=tR.getState();if(a.sessionId&&a.messages.some(t=>t.id===e))return a.sessionId.includes(">")?null:{sessionId:a.sessionId,projectId:r};let s=tq.getState().selectedSessionId;return s&&!s.includes(">")?{sessionId:s,projectId:r}:null}function t2(e){let{messages:t,debugMode:r}=e;return(0,n.jsx)(t4,{messages:t,debugMode:r})}function t4(e){let{messages:t,debugMode:r}=e,a=(0,l.useMemo)(()=>(function(e){let t=[],r=null;for(let a of e)"user"===a.role?(r&&t.push(r),r={user:a,responses:[]}):r?r.responses.push(a):t.push({user:a,responses:[]});return r&&t.push(r),t})(t),[t]),s=(0,l.useMemo)(()=>{let e=t.find(e=>"user"===e.role);return!!e&&null!==t3(e.id)},[t]),o=0;return(0,n.jsx)("div",{className:"flex flex-col",children:a.map(e=>{let t="user"===e.user.role?o++:-1;return(0,n.jsx)(t8,{user:e.user,responses:e.responses,debugMode:r,userOrdinal:t,deletable:s},e.user.id)})})}let t8=(0,l.memo)(function(e){let{user:t,responses:r,debugMode:a,userOrdinal:s,deletable:l}=e,o=!!t.deleted;return(0,n.jsxs)("div",{className:F("border-b border-[var(--border)]/50 last:border-b-0",o&&"opacity-50"),children:["user"===t.role?t7(t.content)?(0,n.jsx)(re,{content:t.content,userOrdinal:s,deleted:o,messageId:t.id,deletable:l}):rt(t.content)?(0,n.jsx)(rr,{content:t.content,userOrdinal:s,deleted:o,messageId:t.id,deletable:l}):(0,n.jsx)(ro,{content:t.content,localImages:t.localImages,userOrdinal:s,deleted:o,messageId:t.id,deletable:l,sendFailed:t.sendFailed}):(0,n.jsx)("div",{className:"px-3 py-2",children:(0,n.jsx)(rn,{message:t,debugMode:a})}),r.length>0&&(0,n.jsx)(ra,{responses:r,debugMode:a})]})},(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 t6(e){let{copyText:t,userOrdinal:r,deleted:a,messageId:s,deletable:o}=e,[i,c]=(0,l.useState)(!1),d=o&&!a&&r>=0,u=async()=>{let e=t3(s);e&&await R("Delete this message and its responses from the conversation? The agent will no longer see this exchange.")&&j.send({type:"exchange:delete",sessionId:e.sessionId,projectId:e.projectId,userOrdinal:r})};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t).then(()=>{c(!0),setTimeout(()=>c(!1),2e3)}).catch(()=>{})},title:"Copy message",className:"rounded p-1 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:bg-[var(--background)]/40 transition-opacity",children:i?(0,n.jsx)(t0.A,{className:"h-3 w-3 text-emerald-400"}):(0,n.jsx)(t1.A,{className:"h-3 w-3"})}),d&&(0,n.jsx)("button",{onClick:u,title:"Delete message",className:"rounded p-1 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:bg-red-900/30 hover:text-red-400 transition-opacity",children:(0,n.jsx)(ej.A,{className:"h-3 w-3"})})]})}let t9="rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400";function t7(e){let t=e.match(/^\(from: session ([^)]+)\)\n([\s\S]*)$/);return t?{sessionId:t[1],body:t[2]}:null}function re(e){var t;let{content:r,...a}=e,s=t7(r),l=null!=(t=s.sessionId.split(">").pop())?t:s.sessionId;return(0,n.jsxs)("div",{className:"group 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,n.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,n.jsx)(t6,{copyText:s.body,...a})}),(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-2 pr-14 text-[10px] font-medium text-emerald-400",children:[(0,n.jsx)("span",{children:"Report from sub-session"}),(0,n.jsx)("span",{className:"rounded bg-emerald-900/40 px-1 py-0.5 font-mono text-emerald-300/80",children:l}),a.deleted&&(0,n.jsx)("span",{className:t9,children:"deleted"})]}),(0,n.jsx)(rp,{maxLines:4,children:(0,n.jsx)("div",{className:"text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed",children:s.body})})]})}function rt(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 rr(e){let{content:t,...r}=e,a=rt(t),[s,o]=(0,l.useState)(!1);return(0,n.jsxs)("div",{className:"group sticky top-0 z-10 border-l-2 border-l-purple-500/70 bg-purple-950/40 backdrop-blur-sm shadow-sm",children:[(0,n.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,n.jsx)(t6,{copyText:a.body,...r})}),(0,n.jsxs)("button",{onClick:()=>o(!s),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:[s?(0,n.jsx)(W.A,{className:"h-3 w-3"}):(0,n.jsx)(U.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"Conversation summary sent to LLM"}),(0,n.jsxs)("span",{className:"rounded bg-purple-900/40 px-1 py-0.5 font-mono text-purple-300/80",children:[a.olderCount," messages compacted"]}),r.deleted&&(0,n.jsx)("span",{className:t9,children:"deleted"})]}),s&&(0,n.jsx)("div",{className:"px-3 pb-2 text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed max-h-[40vh] overflow-y-auto",children:a.body})]})}function ra(e){let{responses:t,debugMode:r}=e,a=(0,l.useMemo)(()=>{var e,a;let s=new Map;if(!r)return s;let n=t.filter(e=>"usage"===to(e)&&e.usage);if(0===n.length)return s;let l=new Map;for(let e of t)if("assistant"===to(e)&&e.contentBlocks)for(let t of e.contentBlocks)t.turnId&&l.set(t.turnId,e.id);let o=[];for(let t of n){let r=t.turnId?l.get(t.turnId):void 0;if(r){let a=null!=(e=s.get(r))?e:[];a.push(t),s.set(r,a)}else o.push(t)}if(o.length>0){let e=[...t].reverse().find(e=>"assistant"===to(e));if(e){let t=null!=(a=s.get(e.id))?a:[];t.push(...o),s.set(e.id,t)}}return s},[r,t]);return(0,n.jsx)("div",{className:"px-3 py-2",children:t.map(e=>(0,n.jsx)(rn,{message:e,debugMode:r,usages:a.get(e.id)},e.id))})}function rs(e){var t,r,a,s,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!=(a=u.cacheReadInputTokens)?a:0)+(null!=(s=u.cacheWriteInputTokens)?s: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="".concat(g.getHours().toString().padStart(2,"0"),":").concat(g.getMinutes().toString().padStart(2,"0"),":").concat(g.getSeconds().toString().padStart(2,"0"));return(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px opacity-70",title:g.toLocaleString(),children:v}),(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,n.jsx)("span",{className:"opacity-60",children:"in"}),(u.inputTokens/1e3).toFixed(1),"K"]}),(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,n.jsx)("span",{className:"opacity-60",children:"out"}),(u.outputTokens/1e3).toFixed(1),"K"]}),(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,n.jsx)("span",{className:"opacity-60",children:"ctx"}),(p/1e3).toFixed(1),"K"]}),(null!=(l=u.cacheReadInputTokens)?l:0)>0&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,n.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,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-amber-900/30 px-1 py-px text-amber-400",children:[(0,n.jsx)("span",{className:"opacity-60",children:"write"}),((null!=(c=u.cacheWriteInputTokens)?c:0)/1e3).toFixed(1),"K"]}),h>0&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,n.jsx)("span",{className:"opacity-60",children:"cache"}),h,"%"]}),null!=u.ttftMs&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,n.jsx)("span",{className:"opacity-60",children:"ttft"}),f(u.ttftMs)]}),null!=u.e2eMs&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,n.jsx)("span",{className:"opacity-60",children:"e2e"}),f(u.e2eMs)]}),u.thinkingEffort&&"off"!==u.thinkingEffort&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-purple-900/30 px-1 py-px text-purple-400",children:[(0,n.jsx)("span",{className:"opacity-60",children:"think"}),u.thinkingEffort]}),"off"===u.thinkingEffort&&(0,n.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,n.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 rn(e){var t,r,a,s,o,i;let{message:c,debugMode:d,usages:u}=e,m=(0,tr.useT)(),x=to(c),p="assistant"===x,h=(0,l.useMemo)(()=>{if(!d||!p||!(null==u?void 0:u.length))return null;let e=new Map;for(let t of u)t.turnId&&e.set(t.turnId,t);return e.size>0?e:null},[d,p,u]);if("tool_call"===x||"tool_result"===x||"usage"===x||"context"===x)return null;if("agent_start"===x||"agent_done"===x)return d?(0,n.jsx)("div",{className:"my-0.5 px-1",children:(0,n.jsxs)("span",{className:F("inline-block rounded px-1.5 py-0.5 text-[9px]","agent_start"===x?"bg-blue-900/40 text-blue-400":"bg-emerald-900/40 text-emerald-400"),children:[null!=(a=c.agentName)?a:"Agent",": ",c.content||("agent_start"===x?"started":"done")]})}):null;let f=p&&c.contentBlocks&&c.contentBlocks.length>0;if(c.interrupted&&!c.content&&!(null==(t=c.toolCalls)?void 0:t.length))return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,n.jsx)(t5.A,{className:"h-3 w-3 text-amber-400"}),(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:m("chat.interrupted")})]});if(c.streaming&&!c.content&&!(null==(r=c.toolCalls)?void 0:r.length))return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin text-[var(--primary)]"}),(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:"Thinking..."})]});let g=[];if(f){let e=c.contentBlocks;for(let t=0;t<e.length;t++){let r=e[t];if("thinking"===r.type&&r.text.trim()&&d)g.push((0,n.jsx)(rl,{text:r.text},"b".concat(t)));else if("text"===r.type&&r.text.trim())g.push((0,n.jsx)(ri,{text:r.text},"b".concat(t)));else if("tool_call"===r.type){let a=e.slice(0,t+1).filter(e=>"tool_call"===e.type).length-1==(null!=(o=null==(s=c.toolCalls)?void 0:s.length)?o:0)-1;g.push((0,n.jsx)(rx,{call:r.toolCall,isStreaming:c.streaming,isLast:a},"b".concat(t)))}if(h&&r.turnId){let a=null==(i=e[t+1])?void 0:i.turnId;if(!a||a!==r.turnId){let e=h.get(r.turnId);e&&g.push((0,n.jsx)(rs,{message:e},"u".concat(r.turnId)))}}}if(h){let t=new Set(e.map(e=>e.turnId).filter(Boolean));for(let[e,r]of h)t.has(e)||g.push((0,n.jsx)(rs,{message:r},"u".concat(e)))}}else{if(p&&c.toolCalls&&c.toolCalls.length>0&&c.toolCalls.forEach((e,t)=>{g.push((0,n.jsx)(rx,{call:e,isStreaming:c.streaming,isLast:t===c.toolCalls.length-1},"tc".concat(t)))}),h)for(let[e,t]of h)g.push((0,n.jsx)(rs,{message:t},"u".concat(e)));if(c.content){let e=!p&&/^Compacting context /.test(c.content);g.push(p?(0,n.jsx)(ri,{text:c.content},"txt"):e?(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin shrink-0"}),(0,n.jsx)("span",{className:"whitespace-pre-wrap",children:c.content})]},"txt"):(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] whitespace-pre-wrap",children:c.content},"txt"))}}return c.plan&&g.push((0,n.jsx)("div",{className:"mt-2",children:(0,n.jsx)(tf,{plan:c.plan})},"plan")),(0,n.jsx)("div",{className:"py-1",children:g})}function rl(e){let{text:t}=e,[r,a]=(0,l.useState)(!1);return(0,n.jsxs)("div",{className:"my-1 rounded border border-purple-900/50 bg-purple-950/20",children:[(0,n.jsxs)("button",{onClick:()=>a(!r),className:"flex w-full items-center gap-1.5 px-2 py-1 text-left text-[11px] text-purple-400 hover:bg-purple-900/20 transition-colors",children:[r?(0,n.jsx)(W.A,{className:"h-3 w-3"}):(0,n.jsx)(U.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{className:"font-medium",children:"Thinking"}),(0,n.jsxs)("span",{className:"text-[10px] text-purple-400/60",children:[t.length.toLocaleString()," chars"]})]}),r&&(0,n.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 ro(e){let{content:t,localImages:r,userOrdinal:a,deleted:s,messageId:o,deletable:i,sendFailed:c}=e,d=(0,tr.useT)(),{text:u,media:m}=(0,l.useMemo)(()=>tC(t),[t]),[x,p]=(0,l.useState)(null);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:F("group sticky top-0 z-10 bg-[var(--accent)] border-b border-[var(--border)] border-l-2 px-4 py-2.5 shadow-sm",s||c?"border-l-red-500/60":"border-l-blue-500"),children:[(0,n.jsxs)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:[s&&(0,n.jsx)("span",{className:F("mr-1",t9),children:"deleted"}),c&&!s&&(0,n.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:d("chat.sendFailed"),children:[(0,n.jsx)(t5.A,{className:"h-2.5 w-2.5"}),d("chat.sendFailedBadge")]}),(0,n.jsx)(t6,{copyText:u,userOrdinal:a,deleted:s,messageId:o,deletable:i})]}),(0,n.jsx)(rp,{maxLines:2,toggleClassName:"top-auto bottom-0",children:(0,n.jsx)("div",{className:F("text-xs leading-relaxed whitespace-pre-wrap pr-14",s?"text-[var(--muted-foreground)] line-through":"text-[var(--accent-foreground)]"),children:u||(m.length>0||(null==r?void 0:r.length)?"(attachment)":"")})})]}),r&&r.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap gap-2 px-4 py-2 border-b border-[var(--border)]/30",children:r.map((e,t)=>(0,n.jsx)("img",{src:e,alt:"screenshot",onClick:()=>p(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))}),m.length>0&&(0,n.jsx)("div",{className:"px-4 py-2 border-b border-[var(--border)]/30",children:(0,n.jsx)(tA,{media:m})}),x&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:()=>p(null),children:(0,n.jsx)("img",{src:x,alt:"screenshot",className:"max-h-[90vh] max-w-[92vw] object-contain"})})]})}function ri(e){let{text:t}=e,{text:r,media:a}=(0,l.useMemo)(()=>tC(t),[t]),s=(0,l.useMemo)(()=>r.replace(/<<<CAPTURE>>>/g,"").replace(/<<<SHOW:[\s\S]*?>>>/g,"").trim(),[r]);return(0,n.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:[s&&(0,n.jsx)(eM.oz,{remarkPlugins:[eL.A],components:{a(e){let{href:t,children:r,node:a,...s}=e;return(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...s,children:r})},pre(e){let{children:t}=e;return(0,n.jsx)("pre",{className:"overflow-x-auto",children:t})},code(e){let{className:t,children:r,node:a,...s}=e;return(null==t?void 0:t.startsWith("language-"))||String(r).includes("\n")?(0,n.jsx)(rh,{className:t,children:r}):(0,n.jsx)("code",{className:t,...s,children:r})}},children:s}),(0,n.jsx)(tA,{media:a})]})}function rc(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t?t:null}catch(e){return null}}let rd="__TOOL_ERROR__",ru="__TOOL_WARN__",rm={running:"bg-amber-400 animate-pulse",success:"bg-emerald-400",warn:"bg-yellow-400",error:"bg-red-400"};function rx(e){let{call:t,isStreaming:r,isLast:a}=e,[s,o]=(0,l.useState)(!1),i=function(e,t,r){var a;if(!e.output&&""!==e.output)return"running";let s=null!=(a=e.output)?a:"";return s.startsWith(rd)?"error":s.startsWith(ru)?"warn":"success"}(t,r,0),c=void 0!==t.output&&""!==t.output,{summary:d}=(0,l.useMemo)(()=>(function(e,t){let r=rc(t);if(r){var a,s,n,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!=(s=null!=(a=r.command)?a:r.cmd)?s:"")||t};case"file_read":return{summary:String(null!=(o=null!=(l=null!=(n=r.path)?n: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):"",a=r.include?" (".concat(r.include,")"):"";return{summary:'"'.concat(e,'"').concat(t).concat(a)}}case"glob":{let e=String(null!=(y=null!=(j=r.pattern)?j:r.glob)?y:""),t=r.path?" in ".concat(r.path):"";return{summary:"".concat(e).concat(t)}}case"web_fetch":return{summary:String(null!=(w=r.url)?w:"")};case"delegate_task":{let e=String(null!=(N=r.agent_id)?N:""),t=String(null!=(S=null!=(k=r.task)?k:r.input)?S:""),a=t.length>100?t.slice(0,100)+"...":t;return{summary:e?"→ ".concat(e,": ").concat(a):a}}}}return{summary:t}})(t.name,t.input),[t.name,t.input]),u=(0,l.useMemo)(()=>{var e;return c?function(e,t){let r=rc(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(rd+"\n")?e.slice(rd.length+1):e.startsWith(ru+"\n")?e.slice(ru.length+1):e):""},[t.name,t.output,c]),m=u.length>120?u.slice(0,120)+"...":u;return(0,n.jsxs)("div",{className:"my-0.5 text-[12px] font-mono",children:[(0,n.jsxs)("button",{onClick:()=>o(!s),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,n.jsx)("span",{className:F("h-2 w-2 shrink-0 rounded-full",rm[i])}),s?(0,n.jsx)(W.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}):(0,n.jsx)(U.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"shrink-0 font-semibold text-[var(--foreground)]",children:t.name}),(0,n.jsx)("span",{className:"truncate text-[var(--muted-foreground)]",children:d})]}),s&&(0,n.jsxs)("div",{className:"ml-[22px] mt-0.5 mb-1 rounded border border-[var(--border)] bg-[var(--card)] overflow-hidden",children:[(0,n.jsxs)("div",{className:"border-b border-[var(--border)] px-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"IN"}),(0,n.jsx)("pre",{className:"text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-all leading-relaxed",children:d})]}),c&&(0,n.jsxs)("div",{className:"px-2.5 py-1.5",children:[(0,n.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"OUT"}),(0,n.jsx)("pre",{className:F("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,n.jsxs)("div",{className:"px-2.5 py-1.5 flex items-center gap-1.5",children:[(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin text-amber-400"}),(0,n.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"Running..."})]})]}),!s&&c&&m&&(0,n.jsx)("div",{className:"ml-[22px] text-[11px] text-[var(--muted-foreground)] truncate",children:m})]})}function rp(e){let{children:t,maxLines:r=2,className:a,toggleClassName:s}=e,o=(0,l.useRef)(null),[i,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=o.current;if(!e)return;let t=20*r+4,a=new ResizeObserver(()=>{let r=e.scrollHeight>t;c(e=>e===r?e:r)});return a.observe(e),()=>a.disconnect()},[r]),(0,n.jsxs)("div",{className:F("relative",a),children:[i&&(0,n.jsx)("button",{onClick:()=>u(!d),className:F("absolute top-0 right-0 text-[11px] text-[var(--primary)] hover:underline z-10",s),children:d?"Show less":"Show more"}),(0,n.jsx)("div",{ref:o,style:!d&&i?{maxHeight:"".concat(20*r,"px"),overflow:"hidden"}:void 0,children:t})]})}function rh(e){let{children:t,className:r}=e,[a,s]=(0,l.useState)(!1),o=String(t).replace(/\n$/,""),i=(null==r?void 0:r.replace("language-",""))||"";return(0,n.jsxs)("div",{className:"relative group",children:[i&&(0,n.jsx)("span",{className:"absolute top-1 left-2 text-[9px] text-[var(--muted-foreground)] opacity-60",children:i}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)})},className:"absolute top-1 right-1 rounded p-1 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)] transition-opacity",children:a?(0,n.jsx)(t0.A,{className:"h-3 w-3 text-emerald-400"}):(0,n.jsx)(t1.A,{className:"h-3 w-3"})}),(0,n.jsx)("code",{className:r,children:t})]})}var rf=r(62783),rg=r(14307),rv=r(51456),rb=r(93436),rj=r(48931),ry=r(56838);function rw(e){return"halo_goal_dismissed_".concat(e)}let rN=(0,c.v)(e=>({goal:null,dismissedGoalId:null,setGoal:t=>e({goal:t}),dismiss:t=>{var r;e({dismissedGoalId:t});let a=null==(r=e9.getState().activeProject)?void 0:r.path;a&&localStorage.setItem(rw(a),t)}}));async function rk(e){let t=localStorage.getItem(rw(e));rN.setState({dismissedGoalId:t});try{var r;let t=await v.F.sessionLogs.goal(e);rN.getState().setGoal(null!=(r=t.goal)?r:null)}catch(e){}}let rS=[{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"}],rC=[];async function rA(e,t,r){try{rC=(await v.F.commands.list(e,t,r)).commands.map(e=>({name:e.slashName,description:e.description,type:e.type,argHint:e.argHint,source:e.source,skillId:e.skillId,verbs:e.verbs}))}catch(e){rC=[]}}function rI(){return rC.length>0?rC:rS}function rT(e){let{commands:t,selectedIndex:r,onSelect:a}=e,s=(0,l.useRef)(null);return((0,l.useEffect)(()=>{var e;let t=null==(e=s.current)?void 0:e.children[r];null==t||t.scrollIntoView({block:"nearest"})},[r]),0===t.length)?null:(0,n.jsx)("div",{ref:s,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,n.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),a(e)},className:"flex w-full items-center gap-3 px-3 py-2 text-left text-sm transition-colors ".concat(t===r?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,n.jsx)("span",{className:"font-mono font-medium text-[var(--primary)]",children:e.name}),e.argHint&&(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:e.argHint}),(0,n.jsx)("span",{className:"flex-1 truncate text-xs",children:e.description})]},e.name))})}function rE(e){let{matches:t,selectedIndex:r,onSelect:a,dirs:s=!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,n.jsx)("div",{ref:o,className:"absolute bottom-full left-3 right-3 mb-1 max-h-48 overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-20",children:t.map((e,t)=>{var l;let o=ec(e),i=s?z.A:o.Icon,c=s?"text-amber-500":o.color,d=null!=(l=e.split("/").pop())?l:e,u=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"";return(0,n.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),a(e)},className:F("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,n.jsx)(i,{className:F("h-3.5 w-3.5 shrink-0",c)}),(0,n.jsx)("span",{className:"truncate font-medium",children:d}),u&&(0,n.jsx)("span",{className:"ml-auto truncate text-xs text-[var(--muted-foreground)] opacity-60",children:u})]},e)})})}function rD(e){return new Promise((t,r)=>{let a=new FileReader;a.onload=()=>t(a.result.split(",")[1]),a.onerror=r,a.readAsDataURL(e)})}async function rF(e){if(!e.type.startsWith("image/"))return{base64:await rD(e),mimeType:e.type||"application/octet-stream"};try{let t=await createImageBitmap(e),r=Math.min(1,1568/Math.max(t.width,t.height)),a=Math.max(1,Math.round(t.width*r)),s=Math.max(1,Math.round(t.height*r)),n=document.createElement("canvas");n.width=a,n.height=s;let l=n.getContext("2d");if(!l)throw Error("no 2d context");l.drawImage(t,0,0,a,s),t.close();let o=n.toDataURL("image/jpeg",.85).split(",")[1];if(!o)throw Error("encode failed");return{base64:o,mimeType:"image/jpeg"}}catch(t){return{base64:await rD(e),mimeType:e.type||"image/png"}}}let rP=null,rM=null,rL=".halo/canvas/self.html";function rR(){let e=(0,tr.useT)(),t=e9(e=>e.activeProject);if(!t)return null;let r=async()=>{let e=t.id;try{let t=await v.F.files.read(rL,e);window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}})),p.getState().openFile(rL,t.content,_(rL),t.modifiedAt,{size:t.size,createdAt:t.createdAt}),setTimeout(()=>eW("self.intro()"),400)}catch(e){}};return(0,n.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,n.jsx)(rf.A,{className:"h-4 w-4"})})}function r_(e){var t;let{cameras:r,activeId:a,onPick:s,onTurnOff:o,onClose:i}=e,c=(0,tr.useT)(),[d,u]=(0,l.useState)(a||(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,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:i,children:(0,n.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,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:c("capture.cameraPick")}),(0,n.jsx)("button",{onClick:i,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsx)("video",{ref:m,muted:!0,playsInline:!0,className:"aspect-video w-full bg-black object-contain"}),(0,n.jsx)("div",{className:"flex flex-col gap-1 p-2",children:r.map(e=>(0,n.jsxs)("button",{onClick:()=>u(e.deviceId),title:e.label,className:F("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,n.jsx)(rg.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.label}),a===e.deviceId&&(0,n.jsx)("span",{className:"shrink-0 text-[10px]",children:c("capture.cameraCurrent")})]},e.deviceId))}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--border)] px-4 py-3",children:[o?(0,n.jsx)("button",{onClick:o,className:"text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:c("capture.cameraBound")}):(0,n.jsx)("span",{}),(0,n.jsx)("button",{onClick:()=>{let e=r.find(e=>e.deviceId===d);e&&s(e)},className:"rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:c("capture.cameraUse")})]})]})})}function rz(){let e=(0,tr.useT)(),t=tR(e=>e.captureSource),r=tR(e=>e.setCaptureSource),[a,s]=(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,b]=(0,l.useState)([]),[j,y]=(0,l.useState)(!1),w=(0,l.useRef)(null),N=window.haloCapture,k=window.haloCamera,S=function(){let e=tR(e=>e.selectedAgentId),t=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.path}),[r,a]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{if(!t)return;let r=!1;return Promise.all([v.F.agentConfigs.list(t),rP?Promise.resolve(rP):(!rM&&(rM=v.F.agentConfigs.models().then(e=>{let t={};for(let a of e.providers){var r;for(let e of a.models)t[e.id]=!!(null==(r=e.capabilities)?void 0:r.image)}return rP=t,t}).catch(()=>({}))),rM)]).then(t=>{var s;let[n,l]=t;if(r)return;let o=null!=(s=n.agents.find(t=>t.id===e))?s:n.agents[0],i=null==o?void 0:o.model;if(!i||!(i in l))return void a(!0);a(l[i])}).catch(()=>{r||a(!0)}),()=>{r=!0}},[e,t]),r}();if((0,l.useEffect)(()=>{!S&&t&&r(null)},[S,t,r]),(0,l.useEffect)(()=>{if(!k||!S)return void p(!1);let e=!1;return k.has().then(t=>{e||p(t)}).catch(()=>{}),()=>{e=!0}},[k,S]),(0,l.useEffect)(()=>{if(!a&&!j)return;let e=e=>{w.current&&!w.current.contains(e.target)&&(s(!1),y(!1))},t=e=>{"Escape"===e.key&&(s(!1),y(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a,j]),!N&&!k||!S)return null;let C=async()=>{if(a)return void s(!1);s(!0),m(!0);try{let e=await N.list();i(e);let t=e.filter(e=>e.id.startsWith("screen:"));d(t.length>0&&t.every(e=>e.blank))}catch(e){i([])}finally{m(!1)}},A=(t,a)=>{if(f(!1),y(!1),t)try{localStorage.setItem("halo.cameraId",t)}catch(e){}r({id:t,name:a||e("capture.cameraName"),thumb:"",kind:"camera"})},I=async()=>{if((null==t?void 0:t.kind)==="camera")return void y(e=>!e);if(!await k.requestPermission())return void f(!0);let e=await k.list();if(0===e.length)return void A("",void 0);b(e),y(!0)};return(0,n.jsxs)("div",{ref:w,className:"relative flex items-center gap-1",children:[N&&(0,n.jsx)("button",{onClick:C,title:(null==t?void 0:t.kind)==="screen"?e("capture.bound",{name:t.name}):e("capture.button"),className:F("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,n.jsx)(rv.A,{className:"h-4 w-4"})}),k&&x&&(0,n.jsx)("button",{onClick:I,title:(null==t?void 0:t.kind)==="camera"?e("capture.cameraBound"):e("capture.cameraButton"),className:F("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,n.jsx)(rg.A,{className:"h-4 w-4"})}),t&&(0,n.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,n.jsx)(rg.A,{className:"h-3.5 w-3.5"}):t.thumb?(0,n.jsx)("img",{src:t.thumb,alt:"",className:"h-3.5 w-3.5 rounded-sm object-cover"}):(0,n.jsx)(rv.A,{className:"h-3.5 w-3.5"}),(0,n.jsx)("span",{className:"max-w-24 truncate",children:t.name}),(0,n.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,n.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]}),h&&(0,n.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,n.jsx)("div",{children:e("capture.cameraPermissionHint")}),(0,n.jsxs)("div",{className:"mt-1.5 flex items-center gap-3",children:[(0,n.jsx)("button",{onClick:()=>k.openSettings(),className:"underline hover:text-amber-200",children:e("capture.openSettings")}),(0,n.jsx)("button",{onClick:()=>f(!1),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:e("capture.dismiss")})]})]}),j&&g.length>=1&&(0,n.jsx)(r_,{cameras:g,activeId:(null==t?void 0:t.kind)==="camera"?t.id:null,onPick:e=>A(e.deviceId,e.label),onTurnOff:(null==t?void 0:t.kind)==="camera"?()=>{r(null),y(!1)}:void 0,onClose:()=>y(!1)}),a&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:()=>s(!1),children:(0,n.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,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:e("capture.pickTitle")}),(0,n.jsx)("button",{onClick:()=>s(!1),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[c&&(0,n.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,n.jsx)("div",{children:e("capture.permissionHint")}),(0,n.jsx)("button",{onClick:()=>N.openSettings(),className:"mt-1.5 underline hover:text-amber-200",children:e("capture.openSettings")})]}),u?(0,n.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:e("capture.loading")}):0===o.length?(0,n.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:e("capture.empty")}):(0,n.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-3",children:o.map(t=>(0,n.jsxs)("button",{onClick:()=>{var e;r({id:t.id,name:t.name,thumb:null!=(e=t.thumb)?e:"",kind:"screen"}),s(!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,n.jsx)("img",{src:t.thumb,alt:t.name,className:"aspect-video w-full rounded object-cover bg-black/20"}):(0,n.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,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.icon&&(0,n.jsx)("img",{src:t.icon,alt:"",className:"h-4 w-4 shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs text-[var(--foreground)]",children:t.name})]})]},t.id))})]})]})})]})}function rO(e){let{onCompact:t}=e,r=tR(e=>e.messages),a=tR(e=>e.contextTokens),s=tR(e=>e.maxContextTokens),o=tR(e=>e.isCompacting),i=tR(e=>e.isStreaming),c=(0,l.useMemo)(()=>a>0?a:0,[a]);if(0===c||0===r.length||0===s)return null;let d=Math.min(c/s*100,100),u=(c/1e3).toFixed(2),m=2*Math.PI*8,x=r.length>5&&t&&!o&&!i;return(0,n.jsx)("div",{className:F("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(s/1e3,"K tokens (").concat(Math.round(d),"%)").concat(x?"\nClick to compact context":""),onClick:x?t:void 0,children:(0,n.jsxs)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",className:F("transform -rotate-90",o&&"animate-pulse"),children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:8,fill:"none",stroke:"var(--muted-foreground)",strokeWidth:"2.5",opacity:"0.3"}),(0,n.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 rW(e){let{onSend:t,disabled:r,isStreaming:a,onStop:s,onInterrupt:o,pendingMessages:i,onRemovePending:c,onCommand:d,onCompact:u,renderLeftControls:m}=e,x=(0,tr.useT)(),h=p(e=>e.selectedText),f=p(e=>e.selectedRange),g=p(e=>e.activeTab),b=p(e=>e.contextEnabled),j=p(e=>e.setContextEnabled),[y,w]=(0,l.useState)(""),[N,k]=(0,l.useState)([]),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(0),[T,E]=(0,l.useState)([]),[D,P]=(0,l.useState)(0),[M,L]=(0,l.useState)(0),[R,_]=(0,l.useState)(!1),z=(0,l.useRef)(null),O=(0,l.useRef)(null),W=e9(e=>e.activeProject),U=0===tR(e=>e.usableAgentCount),B=rN(e=>e.goal),H=tR(e=>e.sessionId),K=!!B&&("intake"===B.status||"running"===B.status)&&H===B.workerSessionId,G=K&&!y.trim().startsWith("/"),J=(0,l.useMemo)(()=>{var e,t;if(h&&g){let t=null!=(e=g.split("/").pop())?e:g,r=f?":".concat(f.startLine,"-").concat(f.endLine):"";return"".concat(t).concat(r," (").concat(h.length," chars)")}return g?null!=(t=g.split("/").pop())?t:g:null},[h,f,g]),q=(0,l.useMemo)(()=>{if(!y.startsWith("/")||/\s/.test(y))return[];if(!y.startsWith("/"))return[];let e=y.toLowerCase();return rI().filter(t=>t.name.startsWith(e))},[y]),Z=(0,l.useMemo)(()=>(function(e){var t;let r=e.match(/^(\/\S+)\s+(\S*)$/);if(!r)return[];let a=rI().find(e=>e.name===r[1].toLowerCase());if(!(null==a||null==(t=a.verbs)?void 0:t.length))return[];let s=r[2].toLowerCase();return a.verbs.filter(e=>e.name.startsWith(s)&&e.name!==s).map(e=>({cmd:a,verb:e}))})(y),[y]),[V,Y]=(0,l.useState)(0);(0,l.useEffect)(()=>{Y(0)},[Z.length]);let $=(0,l.useCallback)(e=>{var t;w("".concat(e.cmd.name," ").concat(e.verb.name," ")),null==(t=z.current)||t.focus()},[]),Q=(0,l.useMemo)(()=>{let e=y.slice(0,M).match(/(^|\s)@scope\s+(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[y,M]),X=(0,l.useMemo)(()=>{if(Q)return null;let e=y.slice(0,M).match(/(^|\s)@(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[y,M,Q]),[ee,et]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(!X||R||!W)return void et([]);let e=!1,t=setTimeout(()=>{v.F.files.search(W.id,X.query,15).then(t=>{e||et(t.matches.map(e=>e.path))}).catch(()=>{e||et([])})},120);return()=>{e=!0,clearTimeout(t)}},[X,R,W]);let er=(0,l.useCallback)(e=>{if(!X)return;let t=y.slice(0,X.startIdx);w(t+y.slice(X.startIdx+1+X.query.length)),E(t=>t.includes(e)?t:[...t,e]),P(0),_(!1),requestAnimationFrame(()=>{if(z.current){let e=t.length;z.current.selectionStart=e,z.current.selectionEnd=e,z.current.focus(),L(e)}})},[y,X]),[ea,es]=(0,l.useState)([]),[en,eo]=(0,l.useState)(0);(0,l.useEffect)(()=>{if(!Q||!W)return void es([]);let e=!1,t=setTimeout(()=>{v.F.files.search(W.id,Q.query,15,!0).then(t=>{e||es(t.matches.map(e=>e.path))}).catch(()=>{e||es([])})},120);return()=>{e=!0,clearTimeout(t)}},[Q,W]);let ei=(0,l.useCallback)(e=>{if(!Q)return;let t=y.slice(0,Q.startIdx),r=y.slice(M),a="@scope ".concat(e," ");w(t+a+r),eo(0),requestAnimationFrame(()=>{if(z.current){let e=t.length+a.length;z.current.selectionStart=e,z.current.selectionEnd=e,z.current.focus(),L(e)}})},[y,Q,M]),ec=(0,l.useCallback)(e=>{E(t=>t.filter(t=>t!==e))},[]),ed=(0,l.useCallback)(e=>{var t,r;let a=y.split(/\s+/),s=null!=(t=a[0])?t:"",n=a.slice(1).join(" ");if(e.argHint&&!n&&s!==e.name){w(e.name+" "),I(0),null==(r=z.current)||r.focus();return}null==d||d(e,n),w(""),I(0),z.current&&(z.current.style.height="auto")},[y,d]),eu=(0,l.useCallback)(e=>{let t=Array.from(e).filter(e=>e.type.startsWith("image/")).map(e=>({file:e,preview:URL.createObjectURL(e)}));k(e=>[...e,...t])},[]),em=(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)})},[]),ex=(0,l.useCallback)(async()=>{var e,r;let a=y.trim();if(!a&&0===N.length||U)return;if(Z.length>0)return void $(null!=(e=Z[V])?e:Z[0]);if(a.startsWith("/")){if(q.length>0)return void ed(null!=(r=q[A])?r:q[0]);let e=rI().find(e=>{var t;return e.name===(null==(t=a.split(/\s+/)[0])?void 0:t.toLowerCase())});if(e)return void ed(e)}if(K)return;let s=[];for(let e of N)try{let{base64:t,mimeType:r}=await rF(e.file);s.push({data:t,mimeType:r})}catch(e){console.error("[MessageInput] Image conversion failed:",e)}(a||s.length>0)&&t(a||"(image)",s.length>0?s:void 0,T.length>0?T:void 0),N.forEach(e=>{e.preview&&URL.revokeObjectURL(e.preview)}),k([]),E([]),w(""),z.current&&(z.current.style.height="auto")},[y,N,t,q,A,ed,T,Z,V,$,U,K]),ep=(0,l.useCallback)(e=>{if(ea.length>0){if("ArrowDown"===e.key){e.preventDefault(),eo(e=>Math.min(e+1,ea.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),eo(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=ea[en];t&&ei(t);return}if("Escape"===e.key){e.preventDefault(),es([]);return}}if(ee.length>0){if("ArrowDown"===e.key){e.preventDefault(),P(e=>Math.min(e+1,ee.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),P(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=ee[D];t&&er(t);return}if("Escape"===e.key){e.preventDefault(),_(!0);return}}if(Z.length>0){if("ArrowDown"===e.key){e.preventDefault(),Y(e=>Math.min(e+1,Z.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),Y(e=>Math.max(e-1,0));return}if("Tab"===e.key){e.preventDefault();let t=Z[V];t&&$(t);return}if("Escape"===e.key){e.preventDefault(),Y(0);return}}if(q.length>0){if("ArrowDown"===e.key){e.preventDefault(),I(e=>Math.min(e+1,q.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),I(e=>Math.max(e-1,0));return}if("Escape"===e.key){e.preventDefault(),w(""),I(0);return}if("Tab"===e.key){e.preventDefault();let t=q[A];t&&w(t.name+" ");return}}if("Escape"===e.key&&a&&!y.trim()&&o){e.preventDefault(),o();return}"Enter"!==e.key||e.nativeEvent.isComposing||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),ex())},[ex,q,A,Z,V,$,ee,D,er,ea,en,ei,a,y,o]),eh=(0,l.useCallback)(e=>{w(e.target.value),L(e.target.selectionStart),I(0),_(!1),P(0),eo(0);let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"},[]),ef=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!0)},[]),eg=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!1)},[]),ev=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),C(!1),e.dataTransfer.files.length>0&&eu(e.dataTransfer.files)},[eu]),eb=(0,l.useCallback)(e=>{let t=e.clipboardData.items,r=[];for(let e=0;e<t.length;e++){let a=t[e];if("file"===a.kind){let e=a.getAsFile();e&&r.push(e)}}r.length>0&&(e.preventDefault(),eu(r))},[eu]);return(0,n.jsxs)("div",{className:F("relative px-3 pb-3 pt-1 transition-colors",S&&"bg-[var(--accent)]"),onDragOver:ef,onDragLeave:eg,onDrop:ev,children:[(0,n.jsx)(rT,{commands:q,selectedIndex:A,onSelect:ed}),(0,n.jsx)(rT,{commands:Z.map(e=>{var t;return{name:"".concat(e.cmd.name," ").concat(e.verb.name),description:null!=(t=e.verb.desc)?t:"",type:"server"}}),selectedIndex:V,onSelect:e=>{var t;w(e.name+" "),null==(t=z.current)||t.focus()}}),(0,n.jsx)(rE,{matches:ee,selectedIndex:D,onSelect:er}),(0,n.jsx)(rE,{matches:ea,selectedIndex:en,onSelect:ei,dirs:!0}),S&&(0,n.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,n.jsx)("p",{className:"text-sm text-[var(--primary)]",children:"Drop images here"})}),(0,n.jsx)("input",{ref:O,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&eu(e.target.files),e.target.value=""}}),(0,n.jsxs)("div",{className:F("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,n.jsx)("textarea",{ref:z,value:y,onChange:eh,onKeyDown:ep,onPaste:eb,onSelect:e=>L(e.target.selectionStart),placeholder:U?"All agents are disabled — enable one in the Agents tab to chat":K?x("goal.inputLocked"):a?"Send to interrupt current response...":"Type @ to reference files...",rows:1,className:"w-full resize-none bg-transparent px-3.5 pt-3 pb-1 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none max-h-[200px]"}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1 px-2 pb-2",children:[(0,n.jsx)("button",{onClick:()=>{var e;return null==(e=O.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,n.jsx)(rb.A,{className:"h-4 w-4"})}),(0,n.jsx)(rz,{}),(0,n.jsx)(rR,{}),(0,n.jsx)(rO,{onCompact:u}),null==m?void 0:m(),null==i?void 0:i.map((e,t)=>(0,n.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,n.jsx)("span",{className:"max-w-32 truncate",children:e}),(0,n.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,n.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"q-".concat(t))),J&&(0,n.jsx)("button",{onClick:()=>j(!b),title:b?"Click to exclude context":"Click to include context",className:F("flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] transition-colors",b?"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,n.jsx)("span",{className:"max-w-36 truncate",children:J})}),T.map(e=>(0,n.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,n.jsxs)("span",{className:"max-w-32 truncate",children:["@",e.split("/").pop()]}),(0,n.jsx)("button",{onClick:()=>ec(e),className:"ml-0.5 rounded-full p-0.5 hover:bg-green-500/20 hover:text-green-300",children:(0,n.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"@".concat(e))),N.map((e,t)=>(0,n.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,n.jsx)("img",{src:e.preview,alt:e.file.name,className:"h-5 w-5 rounded object-cover"}):(0,n.jsx)(el.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"max-w-20 truncate text-[10px] text-[var(--muted-foreground)]",children:e.file.name}),(0,n.jsx)("button",{onClick:()=>em(t),className:"ml-0.5 rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"f-".concat(t))),(0,n.jsx)("div",{className:"flex-1"}),a&&!y.trim()&&0===N.length?(0,n.jsx)("button",{onClick:s,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,n.jsx)(rj.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,n.jsx)("button",{onClick:ex,disabled:U||G||!y.trim()&&0===N.length,title:U?"All agents are disabled — enable one to chat":G?x("goal.inputLocked"):a&&y.trim()?"Send (interrupts current response)":"Send (Enter)",className:F("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors",!U&&!G&&(y.trim()||N.length>0)?a?"bg-orange-600 text-white hover:bg-orange-700":"bg-[var(--primary)] text-[var(--primary-foreground)] hover:bg-blue-600":"text-[var(--muted-foreground)] cursor-not-allowed"),children:(0,n.jsx)(ry.A,{className:"h-4 w-4"})})]})]})]})}let rU={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 rB(e){let{currentSessionId:t,onJump:r}=e,a=rN(e=>e.goal),s=rN(e=>e.dismissedGoalId),l=rN(e=>e.dismiss),o=(0,tr.useT)();if(!a)return null;let i="done"===a.status||"halted"===a.status;if(i&&s===a.goalSessionId)return null;let c=o("goal.banner.".concat(a.status),{round:a.round,max:a.maxRounds}),d=t===a.goalSessionId,u=t===a.workerSessionId;return(0,n.jsxs)("div",{className:F("flex items-center gap-2 border-t px-3 py-1.5 text-[11px]",rU[a.status]),children:[(0,n.jsx)("button",{onClick:()=>!d&&r(a.goalSessionId),title:d?void 0:o("goal.banner.jump"),className:F("min-w-0 flex-1 truncate text-left",!d&&"hover:underline cursor-pointer"),children:c}),(0,n.jsx)("button",{onClick:()=>!u&&r(a.workerSessionId),title:u?void 0:o("goal.banner.jump_worker"),className:F("shrink-0",!u&&"hover:underline cursor-pointer"),children:o("goal.banner.worker")}),i&&(0,n.jsx)("button",{onClick:()=>l(a.goalSessionId),title:o("goal.banner.dismiss"),className:"shrink-0 rounded p-0.5 opacity-60 hover:opacity-100 transition-opacity",children:(0,n.jsx)(eK.A,{className:"h-3 w-3"})})]})}function rH(e){return"halo_session_".concat(e)}let rK="halo_session_id";function rG(e){let t=localStorage.getItem(rH(e));if(t)return t;let r=localStorage.getItem(rK);return r?(localStorage.setItem(rH(e),r),localStorage.removeItem(rK),r):null}function rJ(e,t){localStorage.setItem(rH(e),t)}function rq(e){localStorage.removeItem(rH(e))}var rZ=r(28968);function rV(e){let{sessions:t,currentSessionId:r,loadingSessionId:a,onSelect:s,onDelete:o,onNew:i,onLoadMore:c,hasMore:d,loadingMore:u}=e,m=e9(e=>e.activeProject),[x,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(""),g=(0,l.useRef)(null),b=(0,l.useRef)(""),j=()=>{g.current=null,p(null),f("")},y=async e=>{if(g.current!==e)return;let t=h.trim();if(!t||t===b.current||!(null==m?void 0:m.path))return void j();g.current=null,p(null);try{await v.F.sessionLogs.rename(e,t,m.path)}catch(e){console.error("[SessionSidebar] Rename failed:",e)}tz()},w=(0,l.useRef)(null);return(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)&&c()},{rootMargin:"48px"});return t.observe(e),()=>t.disconnect()},[c,t.length]),(0,n.jsxs)("div",{className:"flex w-[200px] shrink-0 flex-col border-l border-[var(--border)] bg-[var(--card)]",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-[10px] text-[var(--muted-foreground)]",children:"No sessions yet"}):t.map(e=>{var t;return(0,n.jsxs)("div",{onClick:()=>s(e.id),className:F("group flex items-center gap-1.5 px-2 py-1.5 cursor-pointer select-none transition-colors",r===e.id?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50"),children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[x===e.id?(0,n.jsx)("input",{autoFocus:!0,value:h,onChange:e=>f(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,n.jsxs)("p",{className:"text-[11px] text-[var(--foreground)] truncate",children:[e.goalSessionId&&(0,n.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),e.title]}),(0,n.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",tW(e.updatedAt),"string"==typeof(null==(t=e.agentSnapshot)?void 0:t.model)&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.agentSnapshot.model.split(".").pop()]})]})]}),a===e.id?(0,n.jsx)(H.A,{className:"h-3 w-3 shrink-0 animate-spin text-[var(--muted-foreground)]"}):x!==e.id&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),g.current=e.id,b.current=e.title||"",p(e.id),f(e.title||"")},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,n.jsx)(eC.A,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:t=>o(e.id,t),title:"Delete",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,n.jsx)(ej.A,{className:"h-3 w-3"})})]})]},e.id)}),d&&(0,n.jsx)("div",{ref:w,className:"flex items-center justify-center py-2 text-[9px] text-[var(--muted-foreground)]",children:u?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(H.A,{className:"h-2.5 w-2.5 animate-spin mr-1"})," Loading…"]}):(0,n.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]}),(0,n.jsxs)("button",{onClick:i,title:"New session",className:"flex shrink-0 items-center gap-1.5 border-t border-[var(--border)] px-2 py-1.5 text-[11px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]",children:[(0,n.jsx)(rZ.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"New Session"})]})]})}let rY=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function r$(){rY.getState().bump()}function rQ(){var e,t;let r=tR(e=>e.selectedAgentId),a=tR(e=>e.sessionId),s=tR(e=>e.isStreaming),o=e9(e=>e.activeProject),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!1),m=(0,l.useRef)(null),x=rY(e=>e.version);(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&(v.F.agentConfigs.list(o.path).then(e=>{let t=e.agents.filter(e=>!e.overridden&&!e.disabled&&!e.internal).map(e=>{var t;return{id:e.id,name:e.name,scope:e.scope,priority:null!=(t=e.priority)?t:0}}).sort((e,t)=>t.priority-e.priority||e.name.localeCompare(t.name));c(t),tR.getState().setUsableAgentCount(t.length);let r=tR.getState();!r.sessionId&&"default"===r.selectedAgentId&&t[0]&&"default"!==t[0].id&&r.setSelectedAgentId(t[0].id)}).catch(()=>{}),rA(o.path,null!=a?a:void 0,null!=r?r:void 0).catch(()=>{}))},[null==o?void 0:o.path,a,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=!!a,h=null!=(e=i.find(e=>e.id===r))?e:i[0],f=null!=(t=null==h?void 0:h.name)?t:r;return i.length<=1?null:(0,n.jsxs)("div",{ref:m,className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>!p&&!s&&u(!d),disabled:p||s,title:p?"Agent is locked to current session. Start a new session to switch.":"Select agent",className:F("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,n.jsx)(tK.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{className:"max-w-[80px] truncate",children:f}),!p&&(0,n.jsx)(W.A,{className:"h-2.5 w-2.5"})]}),d&&(0,n.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,n.jsxs)("button",{onClick:()=>{tR.getState().setSelectedAgentId(e.id),u(!1)},className:F("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,n.jsx)(tK.A,{className:"h-3 w-3 shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]},"".concat(e.id,":").concat(e.scope)))})]})}let rX="halo_session_sidebar_open";function r0(){let{messages:e,sendMessage:t,isStreaming:r,clearSession:a,deleteSession:s,stopGeneration:o,interruptGeneration:i,pendingMessages:c,removePendingMessage:d,handleCommand:u,sessionId:m}=function(){let e=(0,tr.useT)(),t=tR(e=>e.messages),r=tR(e=>e.isStreaming),a=tR(e=>e.sessionId),s=tR(e=>e.pendingMessages),n=e9(e=>e.activeProject);(0,l.useEffect)(()=>{if(!n)return;let e=n.id,t=rG(e),r=tR.getState().sessionId;t&&t!==r?(tR.getState().setSessionId(t),tR.getState().setMessages([])):!t&&r&&tR.getState().clear();let a=tR.getState().sessionId;a&&j.connected&&j.send({type:"subscribe",sessionId:a,projectId:e})},[null==n?void 0:n.id]);let o=(0,l.useCallback)(()=>{let{activeTab:e,selectedText:t,selectedRange:r,tabs:a,contextEnabled:s}=p.getState();if(!s)return"";let n=[];if(e&&n.push("[Currently viewing: ".concat(e,"]")),t&&t.trim()&&e){let a=r?":".concat(r.startLine,"-").concat(r.endLine):"";n.push("[Selected text in ".concat(e).concat(a,"]\n```\n").concat(t,"\n```"))}return n.length>0?n.join("\n")+"\n\n":""},[]),i=(0,l.useCallback)((t,r,s)=>{var l;if(!n)return;let i=null!=(l=null!=a?a:rG(n.id))?l:P();a&&a===i||(tR.getState().setSessionId(i),rJ(n.id,i));let c=o(),d=[];c&&d.push(c.trim()),(null==s?void 0:s.length)&&d.push("[Referenced files:\n".concat(s.map(e=>" - ".concat(e)).join("\n"),"]"));let u=tR.getState().captureSource,m=window;u&&m&&("camera"===u.kind&&m.haloCamera?d.push(e("capture.cameraLlmPrompt")):"screen"===u.kind&&m.haloCapture&&d.push(e("capture.llmPrompt",{name:u.name})));let x=(d.length>0?d.join("\n")+"\n\n":"")+t.trim(),p=tR.getState(),h=t.trim();if(null==s?void 0:s.length){let e=s.map(e=>"@".concat(e.split("/").pop())).join(" ");h="".concat(e," ").concat(h)}if(null==r?void 0:r.length){let t=e("chat.imageSent",{n:r.length});h=h?"".concat(t,"\n").concat(h):t}let f=P();p.addMessage({id:P(),role:"user",content:h,timestamp:Date.now(),clientMsgId:f,...(null==r?void 0:r.length)?{localImages:r.map(e=>"data:".concat(e.mimeType,";base64,").concat(e.data))}:{}}),p.messages.some(e=>e.streaming&&"assistant"===e.role&&!e.taskId)||p.addMessage({id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let g=tR.getState().selectedAgentId;j.send({type:"chat",sessionId:i,projectId:n.id,message:x,clientMsgId:f,..."default"!==g?{agentId:g}:{},...(null==r?void 0:r.length)?{images:r}:{}})},[a,n,o]),c=(0,l.useCallback)((e,t,r)=>{if(e.trim()||(null==t?void 0:t.length)){if(!n)return void console.warn("[useChat] No active project selected");i(e,t,r)}},[n,i,a]),d=(0,l.useCallback)(()=>{j.send({type:"chat:stop",sessionId:a})},[a]),u=(0,l.useCallback)(()=>{j.send({type:"chat:interrupt",sessionId:a})},[a]),m=(0,l.useCallback)(e=>{tR.getState().removePendingMessage(e)},[]);(0,l.useEffect)(()=>{if(r)return;let e=tR.getState().shiftPendingMessage();if(e){let t=setTimeout(()=>i(e),100);return()=>clearTimeout(t)}},[r,i]);let x=(0,l.useCallback)(()=>{if(!n)return;let e=null!=a?a:rG(n.id);e&&j.send({type:"session:clear",sessionId:e}),rq(n.id),tR.getState().clear()},[n,a]),h=(0,l.useCallback)(e=>{n&&(j.send({type:"session:delete",sessionId:e,projectId:n.path}),e===(null!=a?a:rG(n.id))&&(rq(n.id),tR.getState().clear()))},[n,a]),f=(0,l.useCallback)((e,t)=>{var r;if(!n)return;let s=null!=(r=null!=a?a:rG(n.id))?r:P();a&&a===s||(tR.getState().setSessionId(s),rJ(n.id,s));let l=e.name.slice(1),o=tR.getState().selectedAgentId,i={type:"command:".concat(l),sessionId:s,projectId:n.id,..."default"!==o?{agentId:o}:{}};t.trim()&&(i.message=t.trim()),j.send(i),tR.getState().addMessage({id:P(),role:"system",content:"Executing ".concat(e.name).concat(t.trim()?" ".concat(t.trim()):"","..."),timestamp:Date.now()})},[n,a]);return{messages:t,sendMessage:c,isStreaming:r,sessionId:a,clearSession:x,deleteSession:h,stopGeneration:d,interruptGeneration:u,pendingMessages:s,removePendingMessage:m,handleCommand:f}}(),x=(0,l.useRef)(null),h=e9(e=>e.activeProject),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(0),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)(()=>"false"!==localStorage.getItem(rX)),{sessions:C,refresh:A,remove:I,loadMore:T,hasMore:E,loadingMore:D}=function(){let e=e9(e=>e.activeProject);return function(e){let[t,r]=(0,l.useState)([]),[a,s]=(0,l.useState)(null),[n,o]=(0,l.useState)(!1),i=t_(e=>e.version),c=(0,l.useCallback)(async()=>{if(!e){r([]),s(null);return}try{let t=await v.F.sessionLogs.list(e,{rootOnly:!0,limit:30});r(t.sessions),s(t.nextCursor)}catch(e){r([]),s(null)}},[e]);(0,l.useEffect)(()=>{c()},[c,i]);let d=(0,l.useCallback)(async()=>{if(null!==a&&!n){o(!0);try{if(!e)return;let t=await v.F.sessionLogs.list(e,{rootOnly:!0,limit:30,cursor:a}),n=t.sessions;r(e=>{let t=new Set(e.map(e=>e.id));return[...e,...n.filter(e=>!t.has(e.id))]}),s(t.nextCursor)}catch(e){console.error("[SessionList] loadMore failed:",e)}finally{o(!1)}}},[e,a,n]);return{sessions:t,refresh:c,remove:(0,l.useCallback)(async t=>{try{await v.F.sessionLogs.delete(t,e),r(e=>e.filter(e=>e.id!==t)),tz()}catch(e){console.error("[SessionList] Delete failed:",e)}},[e]),loadMore:d,hasMore:null!==a,loadingMore:n}}(null==e?void 0:e.path)}(),F=(0,l.useCallback)(e=>{S(e),localStorage.setItem(rX,String(e))},[]),M=(0,l.useCallback)(e=>{h&&(g(e),N(!1),y(e=>e+1),tR.getState().setSessionId(e),tR.getState().setMessages([]),j.send({type:"subscribe",sessionId:e,projectId:h.id}),localStorage.setItem("halo_session_".concat(h.id),e))},[h]);(0,l.useEffect)(()=>{if(!f)return;let e=j.on("state:snapshot",e=>{let t=e.snapshot;(null==t?void 0:t.sessionId)===f&&(g(null),N(!1))}),t=setTimeout(()=>N(!0),3e4);return()=>{e(),clearTimeout(t)}},[f,b]),(0,l.useEffect)(()=>{(null==h?void 0:h.path)&&rk(h.path)},[null==h?void 0:h.path]);let L=(0,l.useCallback)(()=>{g(null),N(!1),a(),setTimeout(()=>{A(),tz()},300)},[a,A]),_=(0,l.useCallback)(async(e,t)=>{t.stopPropagation(),await R("Delete this session? Its history cannot be recovered.")&&(s(e),await I(e))},[s,I]),z=(0,l.useRef)(r);(0,l.useEffect)(()=>{z.current&&!r&&setTimeout(()=>A(),500),z.current=r},[r,A]);let O=(0,l.useMemo)(()=>e.filter(ti),[e]),W=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{let e=x.current;if(!e)return;let t=()=>{W.current=!(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,l.useEffect)(()=>{x.current&&!W.current&&(x.current.scrollTop=x.current.scrollHeight)},[O]),(0,l.useEffect)(()=>{let e=x.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{W.current||(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]),(0,n.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-full min-w-0 flex-1 flex-col",children:[(0,n.jsx)("div",{ref:x,className:"flex-1 min-h-0 overflow-y-auto",children:f?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}),w&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{children:"Slow network — still loading…"}),(0,n.jsx)("button",{onClick:()=>M(f),className:"text-[var(--primary)] hover:underline",children:"Retry"})]})]}):0===O.length?(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,n.jsx)("div",{className:"rounded-full bg-[var(--secondary)] p-3",children:(0,n.jsx)(tJ.A,{className:"h-6 w-6 text-[var(--muted-foreground)]"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:"Start a conversation"}),(0,n.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,n.jsx)(tU,{count:C.length,onClick:()=>F(!0)})]}):(0,n.jsx)(t2,{messages:O})}),(0,n.jsxs)("div",{className:"shrink-0",children:[(0,n.jsx)(rB,{currentSessionId:m,onJump:M}),(0,n.jsx)(rW,{onSend:t,isStreaming:r,onStop:o,onInterrupt:i,pendingMessages:c,onRemovePending:d,onCommand:u,onCompact:()=>u({name:"/session",description:"",type:"server"},"compact"),renderLeftControls:()=>(0,n.jsxs)("div",{className:"relative flex items-center gap-0.5",children:[(C.length>0||O.length>0)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>F(!k),title:k?"Hide session list":"Show session list",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] relative",children:[(0,n.jsx)(tO.A,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 flex h-3.5 min-w-[14px] items-center justify-center rounded-full bg-[var(--muted-foreground)] px-0.5 text-[8px] font-medium text-[var(--background)]",children:C.length})]}),(0,n.jsx)("button",{onClick:L,title:"New session",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(rZ.A,{className:"h-4 w-4"})})]}),(0,n.jsx)(rQ,{})]})})]})]}),k&&(0,n.jsx)(rV,{sessions:C,currentSessionId:m,loadingSessionId:f,onSelect:M,onDelete:_,onNew:L,onLoadMore:T,hasMore:E,loadingMore:D})]})}var r1=r(55499),r5=r(93345);let r3="halo_browser_id";function r2(){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 r4=null;function r8(){if(r4)return r4;try{let e=window.localStorage.getItem(r3);return e||(e=r2(),window.localStorage.setItem(r3,e)),r4=e,e}catch(e){return r4=r2()}}r(14113);let r6=0,r9={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"}},r7={fontFamily:"'JetBrains Mono', 'Fira Code', Menlo, Monaco, monospace",fontSize:13,lineHeight:1.4,cursorBlink:!0,scrollback:1e4};function ae(){let{headerless:e,cwd:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=(0,l.useRef)(null),a=(0,l.useRef)(new Map),[s,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(null),d=e9(e=>e.activeProject),{theme:u}=(0,eT.useTheme)(),m=(0,l.useRef)(u);(0,l.useEffect)(()=>{for(let e of(m.current=u,a.current.values()))e.term.options.theme=r9[u]},[u]);let x=(0,l.useCallback)(e=>{var n,l,i,u;let x=r.current;if(!x)return;r6++;let p="term_".concat(Date.now().toString(36),"_").concat(r6),h=0===s.length?"bash":"bash (".concat(r6,")"),f=document.createElement("div");f.className="absolute inset-0",f.style.display="none",x.appendChild(f);let g=new r1.B({...r7,theme:r9[m.current]}),v=new r5.Y;g.loadAddon(v),g.open(f),v.fit(),g.onData(e=>{j.send({type:"terminal:input",data:e,terminalId:p})}),a.current.set(p,{id:p,name:h,term:g,fit:v,container:f,ready:!1,exited:!1});let b=null;new ResizeObserver(()=>{v.fit(),b&&clearTimeout(b),b=setTimeout(()=>{j.send({type:"terminal:resize",cols:g.cols,rows:g.rows,terminalId:p})},150)}).observe(f);let y=new URLSearchParams(window.location.search).get("folder"),w=null!=(i=null!=(l=null!=(n=null!=e?e:t)?n:null==d?void 0:d.path)?l:y)?i:"~";return j.send({type:"terminal:start",terminalId:p,cwd:w,cols:g.cols,rows:g.rows,browserId:r8(),workspacePath:null!=(u=null==d?void 0:d.path)?u:""}),o(e=>[...e,{id:p,name:h}]),c(p),p},[d,s.length,t]),h=(0,l.useCallback)(e=>{let t=a.current.get(e);t&&(j.send({type:"terminal:close",terminalId:e}),t.term.dispose(),t.container.remove(),a.current.delete(e),o(t=>{let r=t.filter(t=>t.id!==e);return c(a=>{if(a===e){var s,n;return null!=(n=null==(s=r[Math.min(t.findIndex(t=>t.id===e),r.length-1)])?void 0:s.id)?n:null}return a}),r}))},[]),f=(0,l.useCallback)(e=>{c(e)},[]);(0,l.useEffect)(()=>{for(let[e,t]of a.current){let r=e===i;t.container.style.display=r?"block":"none",r&&(t.fit.fit(),t.term.focus())}},[i]),(0,l.useEffect)(()=>{let e=[];return e.push(j.on("terminal:output",e=>{let{terminalId:t,data:r}=e;if(t){var s;null==(s=a.current.get(t))||s.term.write(r)}else{let e=a.current.values().next().value;null==e||e.term.write(r)}})),e.push(j.on("terminal:ready",e=>{let{terminalId:t}=e;if(t){let e=a.current.get(t);e&&(e.ready=!0)}})),e.push(j.on("terminal:exit",e=>{let{terminalId:t}=e;if(t){let e=a.current.get(t);e&&(e.exited=!0,e.term.writeln("\r\n\x1b[90m[Process exited]\x1b[0m"))}})),()=>e.forEach(e=>e())},[]);let g=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(g.current)return;g.current=!0;let e=j.on("terminal:reattached",e=>{let t=e.terminalIds,s=r.current,n=0;for(let e of t){if(a.current.has(e)){let t=a.current.get(e);j.send({type:"terminal:resize",cols:t.term.cols,rows:t.term.rows,terminalId:e});continue}if(!s)continue;r6++;let t=0===n&&0===a.current.size?"bash":"bash (".concat(r6,")");n++;let r=document.createElement("div");r.className="absolute inset-0",r.style.display="none",s.appendChild(r);let l=new r1.B({...r7,theme:r9[m.current]}),i=new r5.Y;l.loadAddon(i),l.open(r),i.fit(),l.write("\x1b[?2004h"),l.onData(t=>{j.send({type:"terminal:input",data:t,terminalId:e})});let d=null;new ResizeObserver(()=>{i.fit(),d&&clearTimeout(d),d=setTimeout(()=>{j.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})},150)}).observe(r);let u={id:e,name:t,term:l,fit:i,container:r,ready:!0,exited:!1};a.current.set(e,u),o(r=>[...r,{id:e,name:t}]),c(t=>null!=t?t:e),j.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})}0===t.length&&0===a.current.size&&x()}),t=()=>{var e;j.send({type:"terminal:reattach",browserId:r8(),workspacePath:null!=(e=null==d?void 0:d.path)?e:""})};t();let s=j.on("_connected",t),n=setTimeout(()=>{0===a.current.size&&x()},2e3);return()=>{clearTimeout(n),e(),s()}},[x]),(0,l.useEffect)(()=>{let e=p.getState().pendingTerminalCwd;return p.subscribe(t=>{let r=t.pendingTerminalCwd;if(r&&r!==e){e=r;let a=t.consumeTerminalSpawn();a&&x(a)}else e=r})},[x]),(0,n.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,n.jsx)("div",{ref:r,className:"relative min-h-0 flex-1 overflow-hidden"}),(0,n.jsxs)("div",{className:"flex w-[160px] shrink-0 flex-col border-l border-[var(--border)] bg-[var(--card)]",children:[(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:s.map(e=>(0,n.jsxs)("div",{onClick:()=>f(e.id),className:F("group flex items-center gap-1.5 px-2 py-1.5 text-[11px] cursor-pointer select-none",e.id===i?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]/50"),children:[(0,n.jsx)($.A,{className:"h-3 w-3 shrink-0"}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),s.length>1&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id)},className:"rounded p-0.5 opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)]",children:(0,n.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},e.id))}),(0,n.jsxs)("button",{onClick:()=>x(),className:"flex items-center gap-1.5 border-t border-[var(--border)] px-2 py-1.5 text-[11px] text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]/50",title:"New Terminal",children:[(0,n.jsx)(rZ.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"New Terminal"})]})]})]})}var at=r(90590);function ar(){let{cwd:e,floating:t=!1,dragHandleRef:r}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=(0,tr.useT)(),s=p(e=>e.bottomTab),o=p(e=>e.setBottomTab),i=p(e=>e.setBottomFloating),c=p(e=>e.bottomMaximized),d=p(e=>e.setBottomMaximized),[u,m]=(0,l.useState)("terminal"===s);(0,l.useEffect)(()=>{"terminal"===s&&m(!0)},[s]);let[x,h]=(0,l.useState)(0);return(0,l.useEffect)(()=>j.on("_disconnected",()=>h(e=>e+1)),[]),(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{ref:r,className:F("flex h-[35px] shrink-0 items-center gap-0 border-b border-[var(--border)] bg-[var(--card)] px-2",t&&"cursor-move select-none"),children:[(0,n.jsx)(aa,{label:a("nav.chat"),active:"chat"===s,onClick:()=>o("chat")}),(0,n.jsx)(aa,{label:a("nav.terminal"),active:"terminal"===s,onClick:()=>o("terminal")}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>d(!c),title:c?"Restore panel":"Maximize panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:c?(0,n.jsx)(te.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(tt.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>i(!t),title:t?"Dock back":"Float panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:t?(0,n.jsx)(eK.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(at.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsxs)("div",{className:"min-h-0 flex-1",children:[(0,n.jsx)("div",{className:"chat"===s?"h-full":"hidden",children:(0,n.jsx)(r0,{})}),(0,n.jsx)("div",{className:"terminal"===s?"h-full":"hidden",children:u&&(0,n.jsx)(ae,{headerless:!0,cwd:e},x)})]})]})}function aa(e){let{label:t,active:r,onClick:a}=e;return(0,n.jsxs)("button",{onClick:a,className:F("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,n.jsx)("div",{className:"absolute bottom-0 left-2 right-2 h-px bg-[var(--foreground)]"})]})}function as(e){let{slotRef:t,dragHandleRef:r}=e,a=p(e=>e.bottomFloatRect),s=p(e=>e.setBottomFloatRect),o=p(e=>e.bottomMaximized),i=(0,l.useRef)(a);(0,l.useEffect)(()=>{i.current=a}),(0,l.useEffect)(()=>{let e=r.current;if(e&&!o)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){if(e.target.closest("button"))return;e.preventDefault();let t=e.clientX,r=e.clientY,a={...i.current};function n(e){let n=e.clientX-t,l=e.clientY-r;s({x:an(a.x+n,0,window.innerWidth-a.w),y:an(a.y+l,0,window.innerHeight-a.h),w:a.w,h:a.h})}window.addEventListener("mousemove",n),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",e)})}},[s,o,r]),(0,l.useEffect)(()=>{function e(){let e=i.current,t=an(e.x,0,Math.max(0,window.innerWidth-e.w)),r=an(e.y,0,Math.max(0,window.innerHeight-e.h));(t!==e.x||r!==e.y)&&s({...e,x:t,y:r})}return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[s]);let c=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=c.current;if(e&&!o)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){var t;let r=e.target.closest("[data-edges]");if(!r)return;let a=null!=(t=r.getAttribute("data-edges"))?t:"",n={top:a.includes("top"),bottom:a.includes("bottom"),left:a.includes("left"),right:a.includes("right")};e.preventDefault(),e.stopPropagation();let l=e.clientX,o=e.clientY,c={...i.current},d=c.x+c.w,u=c.y+c.h;function m(e){let t=e.clientX-l,r=e.clientY-o,{x:a,y:i,w:m,h:x}=c;if(n.right&&(m=an(c.w+t,320,window.innerWidth-c.x)),n.bottom&&(x=an(c.h+r,240,window.innerHeight-c.y)),n.left){let e=an(c.x+t,0,d-320);a=e,m=d-e}if(n.top){let e=an(c.y+r,0,u-240);i=e,x=u-e}s({x:a,y:i,w:m,h:x})}window.addEventListener("mousemove",m),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",e)})}},[s,o]);let d=o?{left:0,top:0,width:"100vw",height:"100vh"}:{left:a.x,top:a.y,width:a.w,height:a.h};return(0,n.jsxs)("div",{className:"fixed z-50 flex flex-col rounded-md border border-[var(--border)] bg-[var(--background)] shadow-2xl",style:d,children:[(0,n.jsx)("div",{ref:t,className:"min-h-0 flex-1 overflow-hidden rounded-md"}),!o&&(0,n.jsxs)("div",{ref:c,children:[(0,n.jsx)("div",{"data-edges":"top",className:"absolute -top-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,n.jsx)("div",{"data-edges":"bottom",className:"absolute -bottom-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,n.jsx)("div",{"data-edges":"left",className:"absolute -left-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,n.jsx)("div",{"data-edges":"right",className:"absolute -right-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,n.jsx)("div",{"data-edges":"top left",className:"absolute -top-1 -left-1 h-3 w-3 cursor-nwse-resize"}),(0,n.jsx)("div",{"data-edges":"top right",className:"absolute -top-1 -right-1 h-3 w-3 cursor-nesw-resize"}),(0,n.jsx)("div",{"data-edges":"bottom left",className:"absolute -bottom-1 -left-1 h-3 w-3 cursor-nesw-resize"}),(0,n.jsx)("div",{"data-edges":"bottom right",className:"absolute -bottom-1 -right-1 h-3 w-3 cursor-nwse-resize"})]})]})}function an(e,t,r){return Math.max(t,Math.min(r,e))}let al={ts:ee.A,tsx:ee.A,js:ee.A,jsx:ee.A,json:G.A,md:Z.A};function ao(e){let{onSelect:t,onClose:r}=e,a=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),[s,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)},[s]),(0,l.useEffect)(()=>{if(!a)return;let e=s.trim();if(!e){u([]),x(!1);return}x(!0);let t=!1,r=setTimeout(()=>{v.F.files.search(a,e,50).then(e=>{t||u(e.matches)}).catch(e=>{t||(console.error("[QuickOpen] Search failed:",e),u([]))}).finally(()=>{t||x(!1)})},150);return()=>{t=!0,clearTimeout(r)}},[a,s]),(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,n.jsxs)("div",{className:"fixed inset-0 z-50 flex justify-center pt-[15vh]",children:[(0,n.jsx)("div",{className:"fixed inset-0 bg-black/40"}),(0,n.jsxs)("div",{"data-quick-open":!0,className:"relative w-full max-w-lg",children:[(0,n.jsx)("input",{ref:p,value:s,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,n.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,n.jsx)("div",{className:"px-4 py-6 text-center text-xs text-[var(--muted-foreground)]",children:m?"Searching...":"No files found"}):d.map((e,a)=>{var s,l,o;let c=null!=(o=al[null!=(l=null==(s=e.name.split(".").pop())?void 0:s.toLowerCase())?l:""])?o:el.A;return(0,n.jsxs)("button",{onClick:()=>{t(e.path),r()},className:F("flex w-full items-center gap-2 px-4 py-2 text-left text-xs transition-colors",a===i?"bg-[var(--accent)] text-[var(--accent-foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,n.jsx)(c,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"truncate font-medium",children:e.name}),(0,n.jsx)("span",{className:"ml-auto truncate text-[10px] text-[var(--muted-foreground)]",children:e.path})]},e.path)})})]})]})}var ai=r(49353),ac=r(24284);function ad(e){let{initialPath:t,onSelect:r,onClose:a}=e,[s,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 v.F.fs.browse(e);o(t.path),c(t.parent),u(t.entries)}catch(e){h(e instanceof Error?e.message:"Failed to load directory")}finally{x(!1)}},[]);return(0,l.useEffect)(()=>{t?f(t):v.F.fs.home().then(e=>{let{home:t}=e;return f(t)}).catch(e=>h(String(e)))},[t,f]),(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,n.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,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:"Open Workspace"}),(0,n.jsx)("button",{onClick:a,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] px-3 py-2",children:[(0,n.jsx)("button",{onClick:()=>f(i),disabled:m||!i||i===s,title:"Parent directory",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-30",children:(0,n.jsx)(ai.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>v.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,n.jsx)(ac.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("input",{type:"text",value:s,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&f(s)},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,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[p&&(0,n.jsx)("p",{className:"px-4 py-3 text-xs text-red-400",children:p}),m&&!p&&(0,n.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}),!m&&!p&&0===d.length&&(0,n.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"(empty)"}),!m&&d.map(e=>(0,n.jsxs)("button",{onDoubleClick:()=>f(e.path),onClick:()=>o(e.path),className:F("flex w-full items-center gap-2 px-4 py-1.5 text-xs text-left transition-colors",s===e.path?"bg-[var(--primary)]/20 text-[var(--foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,n.jsx)(z.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),e.name]},e.path))]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,n.jsx)("button",{onClick:a,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>r(s),disabled:!s,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 au="halo_recent_workspaces";function am(){try{let e=localStorage.getItem(au),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function ax(e){try{localStorage.setItem(au,JSON.stringify(e))}catch(e){}}var ap=r(12143),ah=r(59821);function af(e){var t,r;let{projectId:a,pathInput:s,onPathInputChange:o,onOpenFolder:i,onOpenPath:c,activeProject:d}=e,u=(0,tr.useT)(),m=tR(e=>e.isStreaming),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g=(0,l.useRef)(null),{recent:b,remove:j}=function(){let[e,t]=(0,l.useState)([]);return(0,l.useEffect)(()=>{t(am())},[]),{recent:e,remove:(0,l.useCallback)(e=>{t(t=>{let r=t.filter(t=>t!==e);return ax(r),r})},[])}}(),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)(!1),C=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(w)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){C.current&&!C.current.contains(e.target)&&N(!1)}},[w]);let A=k?s.trim().toLowerCase():"",I=b.filter(e=>e!==(null==d?void 0:d.path)&&(!A||e.toLowerCase().includes(A)));async function T(){if(!a)return;let e=await L("New file name (relative path, e.g. src/hello.ts):");if(null==e?void 0:e.trim())try{await v.F.files.create(e.trim(),a),y(a)}catch(e){console.error("[Explorer] Failed to create file:",e),window.alert(e instanceof Error?e.message:"Failed to create file")}}async function E(){if(!a)return;let e=await L("New folder name (relative path, e.g. src/utils):");if(null==e?void 0:e.trim())try{await v.F.files.mkdir(e.trim(),a),y(a)}catch(e){console.error("[Explorer] Failed to create folder:",e),window.alert(e instanceof Error?e.message:"Failed to create folder")}}async function D(e){var t;if(!a||!(null==(t=e.target.files)?void 0:t.length))return;let r=Array.from(e.target.files);try{await v.F.files.upload(r,a),y(a)}catch(e){console.error("[Explorer] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}e.target.value=""}let P=null!=(r=null==d||null==(t=d.path.split("/").filter(Boolean).pop())?void 0:t.toUpperCase())?r:"EXPLORER";return(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,n.jsx)(ap.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:u("nav.explorer")}),(0,n.jsx)("div",{className:"flex-1"}),a&&(0,n.jsx)("button",{onClick:function(){a&&(p(!0),y(a),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,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] p-3",children:[(0,n.jsxs)("div",{ref:C,className:"relative min-w-0 flex-1",children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>{o(e.target.value),S(!0),N(!0)},onFocus:()=>{S(!1),N(!0)},onKeyDown:e=>{"Enter"===e.key?(N(!1),i()):"Escape"===e.key&&N(!1)},placeholder:"Enter folder path, press Enter",className:"w-full rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),w&&I.length>0&&(0,n.jsx)("div",{className:"absolute left-0 right-0 top-full z-20 mt-1 max-h-64 overflow-y-auto rounded border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:I.map(e=>(0,n.jsxs)("div",{onClick:()=>{N(!1),c(e)},className:"group flex cursor-pointer items-center gap-2 px-2 py-1.5 hover:bg-[var(--secondary)]",children:[(0,n.jsx)(tO.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"truncate text-xs text-[var(--foreground)]",children:e.split(/[/\\]/).filter(Boolean).pop()||e}),(0,n.jsx)("div",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},title:"Remove from recent",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 hover:bg-[var(--border)] hover:text-[var(--foreground)] group-hover:opacity-100",children:(0,n.jsx)(eK.A,{className:"h-3 w-3"})})]},e))})]}),(0,n.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,n.jsx)(eN.A,{className:"h-3.5 w-3.5"})})]}),h&&(0,n.jsx)(ad,{initialPath:null==d?void 0:d.path,onSelect:e=>{f(!1),c(e)},onClose:()=>f(!1)}),a&&(0,n.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--border)] px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,n.jsx)("span",{title:u(m?"status.busy":"status.idle"),className:F("inline-block h-2 w-2 shrink-0 rounded-full",m?"bg-amber-400 animate-pulse":"bg-emerald-500")}),(0,n.jsx)("span",{className:"truncate text-[10px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:P})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:T,title:"New File",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(ey.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:E,title:"New Folder",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(ew.A,{className:"h-3.5 w-3.5"})}),(0,n.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,n.jsx)(ah.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("input",{ref:g,type:"file",multiple:!0,className:"hidden",onChange:D})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:a?(0,n.jsx)(tl,{projectId:a,mode:"tree-only"}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,n.jsx)(B.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"Enter a folder path to explore files"})]})})]})}let ag=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function av(){ag.getState().bump()}var ab=r(9747),aj=r(36822),ay=r(58271);function aw(e){return"".concat(e.id,":").concat(e.scope)}let aN="halo_skills_selectedKey",ak="halo_skills_expandedScopes";function aS(){try{let e=localStorage.getItem(ak);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}let aC=(0,c.v)(e=>({skills:[],selectedKey:localStorage.getItem(aN),setSkills:t=>e({skills:t}),setSelectedKey:t=>{t?localStorage.setItem(aN,t):localStorage.removeItem(aN),e({selectedKey:t})},addSkill:t=>e(e=>({skills:[...e.skills,t]})),removeSkill:t=>e(e=>{let r=e.skills.filter(e=>aw(e)!==t),[a,s]=t.split(":"),n="workspace"===s?r.map(e=>e.id===a&&"global"===e.scope?{...e,overridden:!1}:e):r,l=e.selectedKey===t?null:e.selectedKey;return e.selectedKey===t&&localStorage.removeItem(aN),{skills:n,selectedKey:l}})}));function aA(){let e=(0,tr.useT)(),{skills:t,selectedKey:r,setSkills:a,setSelectedKey:s,addSkill:o,removeSkill:i}=aC(),c=e9(e=>e.activeProject),d=null==c?void 0:c.path,[u,m]=(0,l.useState)(aS),[x,p]=(0,l.useState)(!1),h=ag(e=>e.version);async function f(e){if("workspace"===e&&!d)return;let r=await L("New ".concat(e," skill name:"));if(!(null==r?void 0:r.trim()))return;let n=r.trim().toLowerCase().replace(/[^a-z0-9一-鿿]+/g,"-").replace(/^-|-$/g,""),l="workspace"===e?"global":"workspace",i=t.find(e=>e.id===n&&e.scope===l);if(i){let t="workspace"===e?'Global skill "'.concat(i.name,'" has the same ID.\nWorkspace version will override it at runtime.\n\nContinue?'):'Workspace skill "'.concat(i.name,'" has the same ID.\nIt will override this global skill in that project.\n\nContinue?');if(!await R(t))return}try{let n=(await v.F.skills.create({name:r.trim(),scope:e,projectId:"workspace"===e?d:void 0})).skill;"workspace"===e&&i?a(t.map(e=>e.id===n.id&&"global"===e.scope?{...e,overridden:!0}:e).concat(n)):o(n),m(t=>new Set(t).add(e)),s(aw(n)),av()}catch(e){console.error("[SkillsSidebar] Create failed:",e)}}async function g(e,t){if(e.stopPropagation(),await R('Delete skill "'.concat(t.name,'"?')))try{await v.F.skills.remove(t.id,"workspace"===t.scope?{scope:"workspace",projectId:d}:void 0),i(aw(t)),av()}catch(e){console.error("[SkillsSidebar] Delete failed:",e)}}async function b(e,r){e.stopPropagation();try{let e=await v.F.skills.toggle(r.id,{scope:r.scope,projectId:d});a(t.map(t=>aw(t)===aw(r)?{...t,disabled:e.disabled}:t)),av()}catch(e){console.error("[SkillsSidebar] Toggle failed:",e)}}(0,l.useEffect)(()=>{localStorage.setItem(ak,JSON.stringify([...u]))},[u]),(0,l.useEffect)(()=>{p(!0),v.F.skills.list(d).then(e=>a(e.skills)).catch(()=>{}).finally(()=>p(!1))},[d,h,a]),(0,l.useEffect)(()=>{if(d)return j.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/skills/")&&av()})},[d]),(0,l.useEffect)(()=>{let e=()=>av();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]);let y=t.filter(e=>"global"===e.scope),w=t.filter(e=>"workspace"===e.scope),N=(e,t,a,l)=>{let o=u.has(e);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,n.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,n.jsx)(U.A,{className:F("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,n.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:a}),(0,n.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:l.length})]}),(0,n.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,n.jsx)(rZ.A,{className:"h-3 w-3"})})]}),o&&l.map(e=>{let t=aw(e);return(0,n.jsxs)("div",{onClick:()=>s(t),className:F("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,n.jsx)(ab.A,{className:"h-3 w-3 shrink-0 text-amber-500"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:e.name}),(e.disabled||e.overridden||e.description)&&(0,n.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:e.disabled?"disabled":e.overridden?"overridden":e.description})]}),(0,n.jsx)("button",{onClick:t=>b(t,e),className:F("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,n.jsx)(aj.A,{className:"h-4.5 w-4.5"}):(0,n.jsx)(ay.A,{className:"h-4.5 w-4.5 text-blue-500"})}),(0,n.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,n.jsx)(ej.A,{className:"h-3 w-3"})})]},t)})]},e)};return(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,n.jsx)(ab.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:e("skill.skills")}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>av(),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,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[N("global",J.A,e("common.global"),y),d&&N("workspace",B.A,e("common.workspace"),w),0===t.length&&(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,n.jsx)(ab.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:e("skill.noSkills")})]})]})]})}var aI=r(1247),aT=r(71611),aE=r(41601),aD=r(30042);function aF(e){let{value:t,disabled:r,presets:a,placeholder:s,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 a;let e=p.toLowerCase();return a.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))},[p,a]);function y(e){u(e),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,n.jsxs)("div",{ref:v,className:"relative ".concat(null!=c?c:""),style:{minWidth:i},children:[(0,n.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:s,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,n.jsx)("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] opacity-50",children:"▾"}),m&&(0,n.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,n.jsx)("div",{className:"border-b border-[var(--border)] p-1",children:(0,n.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,n.jsx)("div",{className:"max-h-56 overflow-auto",children:0===j.length?(0,n.jsx)("div",{className:"px-2 py-2 text-xs text-[var(--muted-foreground)]",children:"No matches"}):j.map((e,t)=>(0,n.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,n.jsx)("div",{className:"font-medium",children:e.label}),e.label!==e.id&&(0,n.jsx)("div",{className:"text-[10px] ".concat(t===f?"opacity-80":"opacity-60"),children:e.id})]},e.id))})]})]})}let aP={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 aM(e,t){var r,a,s,n,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!=(a=null!=e?e:null==p?void 0:p.defaultBudgetTokens)?a:8192}}else{let e=null==p?void 0:p.effortPresets,t=null!=(n=null==h?void 0:h.effort)?n:null==h?void 0:h.budget,r=t&&(null==e?void 0:e.some(e=>e.value===t)),a=null!=(o=null!=(l=null==p?void 0:p.default)?l:null==e||null==(s=e[0])?void 0:s.value)?o:"medium";x.thinking={enabled:!0,effort:r?t:a}}}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 aL="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)]",aR="text-[11px] font-medium text-[var(--foreground)]",a_="text-[10px] text-[var(--muted-foreground)]";function az(e){let{label:t,enabled:r,value:a,defaultValue:s,presets:l,onChange:o}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:r,onChange:e=>o(e.target.checked?a||s: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,n.jsx)("span",{className:aR,children:t})]}),r&&(0,n.jsx)(aF,{value:a||s,presets:l.map(e=>({id:e.value,label:e.label})),onCommit:e=>o(e||void 0),minWidth:110,className:"h-7"})]})}function aO(e){var t,r,a,s,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,tr.useT)(),k=null!=(a=p.model)?a:{},S=null!=(s=p.context)?s:{},C=Array.isArray(p.skills)?p.skills:[],A=Array.isArray(p.tools)?p.tools:[],I=Array.isArray(p.team)?p.team:void 0,T=null!=(l=null==b||null==(t=b.providers)?void 0:t.flatMap(e=>e.models))?l:[],E=String(null!=(o=k.id)?o:""),D=T.find(e=>e.id===E);return(0,n.jsxs)("div",{className:"h-full overflow-y-auto p-5 space-y-5",children:[(0,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.basic")}),(0,n.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_80px] gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.name")}),(0,n.jsx)("input",{value:String(null!=(i=p.name)?i:""),onChange:e=>j("name",e.target.value),className:F(aL,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.description")}),(0,n.jsx)("input",{value:String(null!=(c=p.description)?c:""),onChange:e=>j("description",e.target.value),className:F(aL,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.priority")}),(0,n.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:F(aL,"mt-1"),placeholder:"0"})]})]})]}),(0,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.model")}),(0,n.jsxs)("div",{className:"grid grid-cols-4 gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.provider")}),b&&b.providers.length>0?(0,n.jsx)("select",{value:String(null!=(u=k.provider)?u:null!=(d=null==(r=b.providers[0])?void 0:r.id)?d:""),onChange:e=>{var t,r,a,s,n;let l=b.providers.find(t=>t.id===e.target.value),o=String(null!=(t=k.id)?t:""),i=null==l?void 0:l.models.some(e=>e.id===o),c=null!=(a=null!=(r=null==l?void 0:l.models.find(e=>e.id===l.defaultModelId))?r:i?l.models.find(e=>e.id===o):void 0)?a:null==l?void 0:l.models[0];j("model",{...k,provider:e.target.value,id:null!=(s=null==c?void 0:c.id)?s:"",endpoint:null!=(n=null==l?void 0:l.defaultEndpoint)?n:"",...aM(c,k)})},className:F("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,n.jsx)("option",{value:e.id,title:e.description,children:null!=(t=e.displayName)?t:e.id},e.id)})}):(0,n.jsx)("input",{value:String(null!=(m=k.provider)?m:""),onChange:e=>y("model","provider",e.target.value),className:F(aL,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.modelId")}),(()=>{var e,t,r,a,s;let l=String(null!=(a=k.provider)?a:null!=(r=null==b||null==(e=b.providers[0])?void 0:e.id)?r:""),o=null!=(s=null==b||null==(t=b.providers.find(e=>e.id===l))?void 0:t.models)?s:[];return(0,n.jsx)(aF,{value:E,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,...aM(t,k)})})(e),className:"mt-1"})})()]}),(()=>{var e,t,r,a,s;let l=String(null!=(r=k.provider)?r:null!=(t=null==b||null==(e=b.providers[0])?void 0:e.id)?t:""),o=null==b?void 0:b.providers.find(e=>e.id===l),i=null!=(a=null==o?void 0:o.defaultEndpoint)?a:"",c=null==o?void 0:o.endpointPresets;return(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.endpoint")}),(0,n.jsx)(aF,{value:String(null!=(s=k.endpoint)?s:""),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,n.jsxs)("p",{className:F(a_,"mt-0.5"),children:["Default: ",i]})]})})(),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:N("agent.maxTokens")}),(0,n.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:F(aL,"mt-1"),placeholder:(null==D?void 0:D.maxOutputTokens)?String(D.maxOutputTokens):"auto"}),(0,n.jsx)("p",{className:F(a_,"mt-0.5"),children:(null==D?void 0:D.maxOutputTokens)?N("agent.maxTokensDefault",{max:D.maxOutputTokens.toLocaleString()}):N("agent.maxTokensAuto")})]})]}),(()=>{var e,t,r,a,s,l,o,i;let c=null!=(l=null==D?void 0:D.capabilities)?l:E?aP: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,n.jsxs)("div",{className:"flex flex-wrap gap-6 pt-1",children:[d&&(0,n.jsx)(az,{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==(s=c.verbosity)||null==(a=s.presets)?void 0:a.length)&&(0,n.jsx)(az,{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=!D&&""!==E,t=k.image,r=k.video,a=k.audio;if(e){let e=e=>{let{field:t,label:r,value:a}=e;return(0,n.jsx)("button",{type:"button",onClick:()=>y("model",t,!a||void 0),className:F("rounded px-2 py-0.5 text-[10px] font-medium transition-colors cursor-pointer",a?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:r})};return(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)(e,{field:"image",label:"Image",value:t}),(0,n.jsx)(e,{field:"video",label:"Video",value:r}),(0,n.jsx)(e,{field:"audio",label:"Audio",value:a})]})}return void 0===c.image&&void 0===c.video&&void 0===c.audio?null:(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[void 0!==c.image&&(0,n.jsx)("span",{className:F("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,n.jsx)("span",{className:F("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,n.jsx)("span",{className:F("rounded px-2 py-0.5 text-[10px] font-medium",c.audio?"bg-emerald-500/15 text-emerald-600":"bg-[var(--secondary)] text-[var(--muted-foreground)]"),children:"Audio"})]})})(),(u||c.thinking)&&(()=>{var e,t,r,a,s,l,o,i,d;let m=k.thinking,x=!!(null==m?void 0:m.enabled),p=!D&&""!==E,h=null!=(a=null==(e=c.thinking)?void 0:e.mode)?a:"adaptive",f=p?(null==m?void 0:m.budget_tokens)!=null?"manual":"adaptive":h,g=null!=(l=null!=(s=null==(t=c.thinking)?void 0:t.default)?s: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,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,n.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,n.jsx)("span",{className:aR,children:"Thinking"})]}),x&&"adaptive"===f&&u&&(0,n.jsx)(aF,{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,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:a_,children:"budget"}),(0,n.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,n.jsx)("span",{className:a_,children:"tokens"})]}),x&&p&&(0,n.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,n.jsx)("div",{className:"grid grid-cols-2 gap-4 pt-1",children:Object.entries(S).map(e=>{let[t,r]=e;return(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:aR,children:"context.".concat(t)}),(0,n.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:F(aL,"mt-1")})]},t)})})]}),(0,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.systemPrompt")}),(0,n.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.systemPromptHint")})]}),(0,n.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,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.team")}),(0,n.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.teamHint")})]}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:g.map(e=>{let t=void 0!==I&&I.includes(e.id);return(0,n.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:F("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,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Tools"}),0===f.length?(0,n.jsx)("p",{className:a_,children:N("agent.loadingTools")}):(()=>{var e;let t=new Set(f.map(e=>e.name)),r=new Set(["query_agent","start_session","session_list","get_session_output","query_session","interrupt_session","stop_session","archive_session"]),a=A.filter(e=>!t.has(e)&&!r.has(e)),s=k.image,l=null!=s?s:null==D||null==(e=D.capabilities)?void 0:e.image;return(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[f.map(e=>{let t=A.includes(e.name),r="view_image"===e.name&&""!==E&&!0!==l,a=r?"".concat(e.description,"\n\nNote: the selected model does not declare capabilities.image: true — view_image will be dropped from this agent's tool list at runtime."):e.description;return(0,n.jsxs)("button",{type:"button",title:a,onClick:()=>w("tools",e.name),className:F("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,n.jsx)("span",{className:"ml-1",children:"⊘"})]},e.name)}),a.map(e=>(0,n.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,n.jsxs)("section",{className:"space-y-3",children:[(0,n.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,n.jsx)("p",{className:a_,children:N("agent.noSkills")}):(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[e.map(e=>{let t=C.includes(e.id);return(0,n.jsx)("button",{type:"button",title:[e.description,"(".concat(e.scope,")")].filter(Boolean).join(" "),onClick:()=>w("skills",e.id),className:F("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,n.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 aW(e){return"".concat(e.id,":").concat(e.scope)}let aU="halo_agents_selectedKey",aB="halo_agents_expandedScopes";function aH(){try{let e=localStorage.getItem(aB);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}function aK(){var e,t;let r=(0,tr.useT)(),a=e9(e=>e.activeProject),s=null!=(e=null==a?void 0:a.path)?e:void 0,[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(()=>localStorage.getItem(aU)),[m,x]=(0,l.useState)(aH),{skills:p,setSkills:h}=aC(),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!1);(0,l.useEffect)(()=>{d?localStorage.setItem(aU,d):localStorage.removeItem(aU)},[d]),(0,l.useEffect)(()=>{localStorage.setItem(aB,JSON.stringify([...m]))},[m]),(0,l.useEffect)(()=>{v.F.agentConfigs.models().then(g).catch(()=>{})},[]);let w=(0,l.useCallback)(async()=>{y(!0);try{let e=await v.F.agentConfigs.list(s);c(e.agents),!d&&e.agents.length>0&&u(aW(e.agents[0]))}catch(e){console.error("[AgentManagement] Load failed:",e)}finally{y(!1)}},[s,d]),N=rY(e=>e.version);(0,l.useEffect)(()=>{w()},[w,N]),(0,l.useEffect)(()=>{if(s)return j.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/agents/")&&r$()})},[s]),(0,l.useEffect)(()=>{let e=()=>r$();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),(0,l.useEffect)(()=>{p.length>0||v.F.skills.list(null==a?void 0:a.path).then(e=>{h(e.skills)}).catch(()=>{})},[null==a?void 0:a.path,p.length,h]);let k=null!=(t=o.find(e=>aW(e)===d))?t:null;async function S(e){var t;if("workspace"===e&&!s)return;let r=await L("Agent name:");if(!(null==r?void 0:r.trim()))return;let a=null!=(t=await L("Agent description (optional):"))?t:"",n=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/^-|-$/g,""),l="workspace"===e?"global":"workspace",i=o.find(e=>e.id===n&&e.scope===l);if(i){let t="workspace"===e?'Global agent "'.concat(i.name,'" has the same ID.\nWorkspace version will override it at runtime.\n\nContinue?'):'Workspace agent "'.concat(i.name,'" has the same ID.\nIt will override this global agent in that project.\n\nContinue?');if(!await R(t))return}try{let t=(await v.F.agentConfigs.create({name:r.trim(),description:a.trim(),scope:e,projectId:"workspace"===e?s: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(aW(t)),r$()}catch(e){console.error("[AgentManagement] Create failed:",e)}}async function C(e){if(await R('Delete agent "'.concat(e.name,'"?')))try{await v.F.agentConfigs.remove(e.id,{scope:e.scope,projectId:s}),c(t=>{let r=t.filter(t=>aW(t)!==aW(e));return"workspace"===e.scope?r.map(t=>t.id===e.id&&"global"===t.scope?{...t,overridden:!1}:t):r}),d===aW(e)&&u(null),r$()}catch(e){console.error("[AgentManagement] Delete failed:",e)}}async function A(e){try{let{disabled:t}=await v.F.agentConfigs.toggle(e.id,{scope:e.scope,projectId:s});c(r=>r.map(r=>aW(r)===aW(e)?{...r,disabled:t}:r)),r$()}catch(e){console.error("[AgentManagement] Toggle failed:",e)}}let I=o.filter(e=>e.internal),T=o.filter(e=>"global"===e.scope&&!e.internal),E=o.filter(e=>"workspace"===e.scope&&!e.internal),D=(()=>{let e=new Map;for(let t of[...T,...E])t.overridden||t.disabled||e.set(t.id,{id:t.id,name:t.name});return[...e.values()]})(),P=function(e,t,r,a){let l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{allowCreate:!0},o=m.has(e);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,n.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,n.jsx)(U.A,{className:F("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,n.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:r}),(0,n.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:a.length})]}),l.allowCreate&&"internal"!==e&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),S(e)},title:"New ".concat(e," agent"),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]",children:(0,n.jsx)(rZ.A,{className:"h-3 w-3"})})]}),o&&a.map(t=>{let r=aW(t);return(0,n.jsxs)("div",{className:F("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,n.jsx)(tK.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:t.name}),(t.overridden||t.disabled||t.description)&&(0,n.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:t.overridden?"overridden":t.disabled?"disabled":t.description})]}),"internal"!==e&&s&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),A(t)},title:t.disabled?"Enable (show in roster)":"Disable (hide from roster)",className:F("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,n.jsx)(aj.A,{className:"h-4.5 w-4.5"}):(0,n.jsx)(ay.A,{className:"h-4.5 w-4.5 text-blue-500"})}),"global"===t.scope?(0,n.jsx)("span",{title:"Global agent (cannot delete)",children:(0,n.jsx)(aI.A,{className:"h-3 w-3 shrink-0 text-amber-500"})}):(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),C(t)},className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 transition-opacity group-hover:opacity-100 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3 w-3"})})]},r)})]},e)};return(0,n.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:"halo-agent-mgmt",className:"h-full",children:[(0,n.jsx)(i.Zk,{defaultSize:22,minSize:12,maxSize:40,children:(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 items-center border-b border-[var(--border)] px-3",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:r("agent.agents")}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>w(),disabled:b,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh agents",children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",b&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[P("global",J.A,r("common.global"),T),s&&P("workspace",B.A,r("common.workspace"),E),I.length>0&&P("internal",aT.A,"Internal",I,{allowCreate:!1})]})]})}),(0,n.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,n.jsx)(i.Zk,{defaultSize:78,minSize:40,children:k?(0,n.jsx)(aG,{agent:k,allAgents:D,modelsRegistry:f,onSaved:e=>{c(t=>t.map(t=>aW(t)===aW(e)?e:t))}},aW(k)):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center",children:[(0,n.jsx)(tK.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:r("agent.selectToEdit")})]})})]})}function aG(e){let{agent:t,allAgents:a,modelsRegistry:s,onSaved:o}=e,i=(0,tr.useT)(),{skills:c}=aC(),d=e9(e=>e.activeProject),[u,m]=(0,l.useState)({}),x="halo_agent_view:".concat(aW(t)),[p,h]=(0,l.useState)(()=>{var e;return null!=(e=localStorage.getItem(x))?e:"form"}),g=(0,l.useCallback)(e=>{localStorage.setItem(x,e),h(e)},[x]),[b,y]=(0,l.useState)(!0),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)([]),[C,A]=(0,l.useState)("");(0,l.useEffect)(()=>{v.F.agentConfigs.tools().then(e=>S(e.tools)).catch(()=>{})},[]);let I=(0,l.useRef)(o);(0,l.useEffect)(()=>{I.current=o});let T=(0,l.useRef)(null),E=(0,l.useCallback)(async()=>{y(!0);let e="workspace"===t.scope?null==d?void 0:d.path:void 0;try{let a=await v.F.agentConfigs.getYaml(t.id,{scope:t.scope,projectId:e}),{parse:s,stringify:n}=await r.e(443).then(r.bind(r,51443)),l={};try{l=s(a.yaml)}catch(e){}let o=l&&"object"==typeof l?l:{};m(o),T.current=n(o,{lineWidth:120})}catch(e){console.error("[AgentEditor] Load YAML failed:",e),m({}),T.current=null}try{var a,s;let r=await v.F.agentConfigs.getMdAll(t.id,{scope:t.scope,projectId:e});A(null!=(s=null==(a=r.files["AGENT.md"])?void 0:a.content)?s:"")}catch(e){A("")}y(!1)},[t.id,t.scope,null==d?void 0:d.path]);(0,l.useEffect)(()=>{E()},[E]);let D=(0,l.useRef)(p);return(0,l.useEffect)(()=>{"edit"===D.current&&"form"===p&&E(),D.current=p},[p,E]),(0,l.useEffect)(()=>{if(b)return;let e=setTimeout(async()=>{try{let{stringify:e}=await r.e(443).then(r.bind(r,51443)),a=e(u,{lineWidth:120});if(T.current===a)return;N(!0);let s="workspace"===t.scope?null==d?void 0:d.path:void 0,n=await v.F.agentConfigs.saveYaml(t.id,a,{scope:t.scope,projectId:s});T.current=a,I.current(n.agent)}catch(e){console.error("[AgentEditor] Auto-save failed:",e)}finally{N(!1)}},500);return()=>clearTimeout(e)},[u,t.id,t.scope,null==d?void 0:d.path,b]),(0,l.useEffect)(()=>{T.current=null},[t.id,t.scope]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex h-10 items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:["edit"===p&&(0,n.jsxs)("button",{onClick:()=>g("form"),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:"Back to form",children:[(0,n.jsx)(aE.A,{className:"h-3 w-3"}),i("agent.back")]}),(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.name}),(0,n.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,n.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:i("agent.saving")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[!t.internal&&(0,n.jsxs)("button",{onClick:()=>(function(e,t){let r=tR.getState().sessionId;r&&j.send({type:"session:clear",sessionId:r}),t&&localStorage.removeItem("halo_session_".concat(t)),tR.getState().clear(),tR.getState().setSelectedAgentId(e),window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}}))})(t.id,null==d?void 0:d.id),className:"flex items-center gap-1.5 rounded bg-[var(--secondary)] px-2.5 py-1 text-xs font-medium text-[var(--foreground)] transition-colors hover:bg-[var(--secondary)]/80",children:[(0,n.jsx)(aD.A,{className:"h-3 w-3"}),i("agent.test")]}),"form"===p&&(0,n.jsxs)("button",{onClick:()=>g("edit"),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",title:i("agent.editHint"),children:[(0,n.jsx)(eC.A,{className:"h-3 w-3"}),i("agent.edit")]})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:"edit"===p?(0,n.jsx)(f,{children:(0,n.jsx)(tl,{projectId:t.path,mode:"full",showMaximize:!1})},"".concat(t.id,":").concat(t.scope)):b?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:i("agent.loading")}):(0,n.jsxs)("div",{className:"h-full overflow-y-auto",children:[(0,n.jsx)(aO,{data:u,availableSkills:c,availableTools:k,allAgents:a,selfId:t.id,modelsRegistry:s,onUpdate:function(e,t){m(r=>({...r,[e]:t}))},onUpdateNested:function(e,t,r){m(a=>{var s;let n=null!=(s=a[e])?s:{};return{...a,[e]:{...n,[t]:r}}})},onToggleArrayItem:function(e,t){m(r=>{let a=Array.isArray(r[e])?[...r[e]]:[],s=a.indexOf(t);return s>=0?a.splice(s,1):a.push(t),{...r,[e]:a}})}}),C.trim()&&(0,n.jsxs)("div",{className:"border-t border-[var(--border)]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-8 pt-6 text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5",children:"AGENT.md"}),(0,n.jsx)("span",{children:i("agent.mdPreviewHint")})]}),(0,n.jsx)(ez,{content:C})]})]})})]})}function aJ(){var e;let{skills:t,selectedKey:r}=aC(),a=null!=(e=t.find(e=>"".concat(e.id,":").concat(e.scope)===r))?e:null;return a?(0,n.jsx)(f,{children:(0,n.jsx)(tl,{projectId:a.path,mode:"full",showMaximize:!1})},"".concat(a.id,":").concat(a.scope)):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center bg-[var(--background)]",children:[(0,n.jsx)(ab.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a skill to edit, or create a new one"})]})}var aq=r(34409),aZ=r(68654);function aV(){let e=tR(e=>e.messages),t=tR(e=>e.sessionId),r=tR(e=>e.isStreaming),a=tq(e=>e.selectedSessionId),s=tq(e=>e.selectedSession),o=tq(e=>e.loadedMessages),i=tq(e=>e.loading),c=e9(e=>e.activeProject),d=(0,l.useRef)(null),[u,m]=(0,l.useState)(!1),[x,p]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_debug")),[h,f]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_prompt"));(0,l.useEffect)(()=>{localStorage.setItem("halo_session_debug",x?"1":"0")},[x]),(0,l.useEffect)(()=>{localStorage.setItem("halo_session_prompt",h?"1":"0")},[h]);let g=tq(e=>e.setLoadedMessages);(0,l.useEffect)(()=>{var e;if(!a||!(null==c?void 0:c.path)||a===t)return;let r=null!=(e=a.split(">").pop())?e:a;return j.on("file:changed",e=>{("change"===e.action||"add"===e.action)&&e.path.startsWith(".halo/sessions/")&&e.path.endsWith("/".concat(r,".json"))&&v.F.sessionLogs.get(a,c.path).then(e=>{var t;let r=null!=(t=e.messages)?t:[],a=tq.getState().loadedMessages,s=function(e,t){if(!e||0===e.length)return t;let r=e.length===t.length,a=t.map((t,a)=>{let s=e[a];return s&&JSON.stringify(s)===JSON.stringify(t)?s:(r=!1,t)});return r?e:a}(a,r);s!==a&&g(s)}).catch(()=>{})})},[a,t,null==c?void 0:c.path,g]);let b=(0,l.useMemo)(()=>{if(!a)return[];if(a===t){let t=e.filter(e=>!e.taskId);return x?t:t.filter(ti)}let r=null!=o?o:[];return x?r:r.filter(e=>!function(e){let t=to(e);return"tool_call"===t||"tool_result"===t||"usage"===t||"context"===t||"agent_start"===t||"agent_done"===t}(e))},[a,t,e,o,x]),y=(0,l.useMemo)(()=>{for(let r of a===t?e:null!=o?o:[])if("context"===to(r)&&r.systemPrompt)return r.systemPrompt;return null},[a,t,e,o]),w=(0,l.useRef)(!0);return(0,l.useEffect)(()=>{let e=d.current;if(!e)return;let t=()=>{w.current=e.scrollHeight-e.scrollTop-e.clientHeight<60};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[]),(0,l.useEffect)(()=>{w.current&&d.current&&(d.current.scrollTop=d.current.scrollHeight)},[b]),(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.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,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(aq.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(null==s?void 0:s.agentName)&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-purple-900/50 px-1.5 py-0.5 text-[10px] text-purple-400",children:s.agentName}),(0,n.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",title:(null==s?void 0:s.title)||"Untitled",children:(null==s?void 0:s.title)||"Untitled"}),(0,n.jsxs)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:["(",b.length,")"]}),a===t&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1.5 py-0.5 text-[8px] text-blue-400",children:"live"}),(null==s?void 0:s.parentSessionId)&&(0,n.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==s?void 0:s.stoppedAt)&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1 py-0.5 text-[8px] text-[var(--muted-foreground)]",children:"stopped"}),(null==s?void 0:s.archivedAt)&&(0,n.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(s.archivedAt).toLocaleString()),children:"archived"}),(null==s?void 0:s.createdAt)&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",title:"Created: ".concat(new Date(s.createdAt).toLocaleString()),children:tW(s.createdAt)}),(0,n.jsxs)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a).then(()=>{m(!0),setTimeout(()=>m(!1),1200)}).catch(()=>{})},title:"Session ID: ".concat(a),className:"shrink-0 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:[u?(0,n.jsx)(t0.A,{className:"h-2.5 w-2.5 text-green-400"}):(0,n.jsx)(t1.A,{className:"h-2.5 w-2.5"}),a.slice(0,8)]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tK.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Session Viewer"})]}),a&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[y&&(0,n.jsxs)("button",{onClick:()=>f(!h),className:F("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",h?"bg-purple-900/50 text-purple-400":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:"View system prompt",children:[(0,n.jsx)(Z.A,{className:"h-3 w-3"}),"Prompt"]}),(0,n.jsxs)("button",{onClick:()=>p(!x),className:F("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",x?"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,n.jsx)(aZ.A,{className:"h-3 w-3"}),"Debug"]})]}),r&&a===t&&(0,n.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"streaming"})]}),(0,n.jsxs)("div",{ref:d,className:"relative flex-1 overflow-y-auto",children:[h&&y&&(0,n.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,n.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,n.jsx)("span",{className:"text-[10px] font-semibold text-purple-400",children:"System Prompt"}),(0,n.jsx)("button",{onClick:()=>f(!1),title:"Close",className:"rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-3 w-3"})})]}),(0,n.jsx)("pre",{className:"px-3 py-2 text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-words leading-relaxed max-h-[60vh] overflow-y-auto",children:y})]}),i?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):a?0===b.length?(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,n.jsx)(tK.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"No messages in this session"})]}):(0,n.jsx)(t2,{messages:b,debugMode:x}):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,n.jsx)(tK.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a session from the sidebar to view messages"})]})]})]})}var aY=r(53762),a$=r(51334),aQ=r(46565),aX=r(6653);function a0(){var e,t,r;let{t:a,refreshFromServer:s}=(0,tr.useI18n)(),{refreshFromServer:o}=(0,eT.useTheme)(),i=e9(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,b]=(0,l.useState)(!1),[j,y]=(0,l.useState)(null),w="workspace"===c?null==i?void 0:i.path:void 0,N=(0,l.useCallback)(()=>{b(!0),v.F.settings.getSchema(w).then(e=>{m(e),p(t=>"__orphans"===t||e.sections.find(e=>e.namespaceId===t)?t:"general")}).catch(e=>{console.error("[Settings] schema load failed:",e)}).finally(()=>b(!1))},[w]);async function k(e,t,r){f(!0);try{let a="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);if(""===r)await v.F.settings.remove(c,a,w);else{let e=function(e,t){switch(e){case"int":{let e=parseInt(t,10);return Number.isFinite(e)?e:t}case"float":{let e=parseFloat(t);return Number.isFinite(e)?e:t}case"boolean":return"true"===t;default:return t}}(t.type,r);await v.F.settings.patch(c,a,e,w)}N(),s(),o()}catch(e){console.error("[Settings] save failed:",e)}finally{f(!1)}}async function S(e,t){f(!0);try{let r="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);await v.F.settings.remove(c,r,w),N(),s(),o()}catch(e){console.error("[Settings] reset failed:",e)}finally{f(!1)}}async function C(e){let t="".concat(e.namespaceId,".").concat(e.kind,"s.").concat(e.key);if(confirm(a("settings.orphans.confirm",{key:t}))){f(!0);try{await v.F.settings.remove(c,t,w),N()}catch(e){console.error("[Settings] orphan remove failed:",e)}finally{f(!1)}}}(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{v.F.health().then(e=>y("string"==typeof(null==e?void 0:e.version)?e.version:null)).catch(()=>y(null))},[]);let A=null!=(e=null==u?void 0:u.sections)?e:[],I=null!=(t=null==u?void 0:u.orphans)?t:[],T=(0,l.useMemo)(()=>A.find(e=>e.namespaceId===x),[A,x]);return(0,n.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex w-[220px] shrink-0 flex-col border-r border-[var(--border)]",children:[(0,n.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,n.jsx)(aY.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:a("nav.settings")}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:N,disabled:g,title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",g&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-[var(--border)] p-2",children:[(0,n.jsxs)("div",{className:"flex rounded-md bg-[var(--card)] p-0.5",children:[(0,n.jsxs)("button",{onClick:()=>d("global"),className:F("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,n.jsx)(J.A,{className:"h-3 w-3"}),a("common.global")]}),(0,n.jsxs)("button",{onClick:()=>d("workspace"),disabled:!i,className:F("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,n.jsx)(a$.A,{className:"h-3 w-3"}),a("common.workspace")]})]}),"workspace"===c&&i&&(0,n.jsx)("p",{className:"mt-1 truncate text-[9px] text-[var(--muted-foreground)]",children:i.path})]}),(0,n.jsx)(a1,{sections:A,orphans:I,active:x,onPick:p})]}),j&&(0,n.jsxs)("div",{className:"shrink-0 border-t border-[var(--border)] px-3 py-2 text-[10px] text-[var(--muted-foreground)]",children:["Halo v",j]})]}),(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,n.jsx)("div",{className:"flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-4",children:(0,n.jsxs)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:["global"===c?"~/.halo/secrets/settings.yaml":"".concat(null!=(r=null==i?void 0:i.path)?r:"...","/.halo/settings.yaml")," ","→ ",(0,n.jsx)("code",{className:"text-[var(--foreground)]",children:x})]})}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:"__orphans"===x?(0,n.jsx)(sr,{orphans:I,onRemove:C,saving:h}):T?(0,n.jsx)(a3,{section:T,scope:c,saving:h,onSave:(e,t)=>k(T.namespaceId,e,t),onReset:e=>S(T.namespaceId,e)}):(0,n.jsx)("div",{className:"p-10 text-center text-xs text-[var(--muted-foreground)]",children:u?a("settings.empty"):a("settings.loading")})})]})]})}function a1(e){let{sections:t,orphans:r,active:a,onPick:s}=e,{t:o}=(0,tr.useI18n)(),i=(0,l.useMemo)(()=>{let e=t.filter(e=>"general"===e.source),r=t.filter(e=>"provider"===e.source);return{general:e,providers:r,skills:t.filter(e=>"skill"===e.source),agents:t.filter(e=>"agent"===e.source)}},[t]);return(0,n.jsxs)("div",{className:"py-1",children:[(0,n.jsx)(a5,{label:o("settings.nav.system"),items:i.general,active:a,onPick:s}),(0,n.jsx)(a5,{label:o("settings.nav.providers"),items:i.providers,active:a,onPick:s}),(0,n.jsx)(a5,{label:o("settings.nav.agents"),items:i.agents,active:a,onPick:s}),(0,n.jsx)(a5,{label:o("settings.nav.skills"),items:i.skills,active:a,onPick:s}),r.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.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,n.jsxs)("button",{onClick:()=>s("__orphans"),className:F("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__orphans"===a?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,n.jsx)(ej.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:o("settings.nav.unclaimed")}),(0,n.jsx)("span",{className:"ml-auto rounded bg-[var(--card)] px-1 py-0 text-[9px]",children:r.length})]})]})]})}function a5(e){let{label:t,items:r,active:a,onPick:s}=e,{lang:l}=(0,tr.useI18n)();return 0===r.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.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,n.jsx)("button",{onClick:()=>s(e.namespaceId),className:F("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors",a===e.namespaceId?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:null!=r?r:e.namespaceId,children:(0,n.jsx)("span",{className:"truncate",children:t})},e.namespaceId)})]})}function a3(e){let{section:t,scope:r,saving:a,onSave:s,onReset:l}=e,{t:o,lang:i}=(0,tr.useI18n)(),c=t.fields.filter(e=>"param"===e.kind),d=t.fields.filter(e=>"secret"===e.kind),u="zh"===i&&t.displayName_zh||t.displayName,m="zh"===i&&t.description_zh||t.description,[x,p]=o("settings.section.secretsHint",{placeholder:"\0"}).split("\0");return(0,n.jsxs)("div",{className:"space-y-6 p-6",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:u}),m&&(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:m}),(0,n.jsxs)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:[o("settings.section.namespace"),": ",(0,n.jsx)("code",{className:"text-[var(--foreground)]",children:t.namespaceId})," \xb7 ",o("settings.section.declaredBy"),": ",(0,n.jsx)("span",{children:o("settings.section.declaredBy.".concat(t.source))})]})]}),c.length>0&&(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:o("general"===t.namespaceId?"settings.section.settings":"settings.section.params")}),c.map(e=>(0,n.jsx)(a2,{namespaceId:t.namespaceId,field:e,scope:r,saving:a,onSave:t=>s(e,t),onReset:()=>l(e)},e.key))]}),d.length>0&&(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:o("settings.section.secrets")}),(0,n.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[x,(0,n.jsx)("code",{className:"rounded bg-[var(--card)] px-1 py-0.5",children:"<<ENV_NAME>>"}),p]}),d.map(e=>(0,n.jsx)(a2,{namespaceId:t.namespaceId,field:e,scope:r,saving:a,onSave:t=>s(e,t),onReset:()=>l(e)},e.key))]})]})}function a2(e){var t,r;let{namespaceId:a,field:s,scope:l,saving:o,onSave:i,onReset:c}=e,{lang:d,t:u}=(0,tr.useI18n)(),m="zh"===d&&s.description_zh||s.description||"",x="general"===a?"general.".concat(s.key):"".concat(a,".").concat(s.kind,"s.").concat(s.key),p="workspace"===l&&s.inheritedFromGlobal,h="workspace"===l&&!0===s.globalOnly,f=!h&&s.source===l&&("workspace"===l||(null!=(t=s.value)?t:"")!==(null!=(r=s.default)?r:""));return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:s.key}),(0,n.jsx)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:x}),(0,n.jsx)(a4,{source:s.source,inherited:p}),s.globalOnly&&(0,n.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-px text-[10px] uppercase text-[var(--muted-foreground)]",title:"zh"===d?"只在全局生效;workspace 级覆盖会被忽略":"Honored only at the global layer; workspace overrides are ignored",children:"global only"}),f&&(0,n.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,n.jsx)(aQ.A,{className:"h-2.5 w-2.5"}),u("settings.field.reset")]})]}),m&&(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:m}),(0,n.jsx)("div",{className:F("mt-1.5",h&&"opacity-60 pointer-events-none"),children:function(e,t,r){var a,s,l,o,i,c,d,u;if(e.secret)return(0,n.jsx)(st,{initial:null!=(a=e.value)?a:"",placeholder:null!=(s=e.default)?s:"",saving:t,onCommit:r});switch(e.type){case"int":case"float":return(0,n.jsx)(a9,{initial:null!=(l=e.value)?l:"",placeholder:null!=(o=e.default)?o:"",step:"int"===e.type?1:.1,saving:t,onCommit:r});case"boolean":return(0,n.jsx)(a7,{value:e.value,saving:t,onCommit:r});case"enum":return(0,n.jsx)(se,{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,n.jsx)(a6,{initial:null!=(d=e.value)?d:"",placeholder:null!=(u=e.default)?u:"",saving:t,onCommit:r})}}(s,o||h,i)})]})}function a4(e){let{source:t,inherited:r}=e,{t:a}=(0,tr.useI18n)();return(0,n.jsx)("span",{className:F("rounded px-1.5 py-0 text-[9px] font-medium",{workspace:"bg-blue-500/20 text-blue-300",global:r?"bg-[var(--secondary)] text-[var(--muted-foreground)]":"bg-emerald-500/20 text-emerald-300",unset:"bg-[var(--secondary)] text-[var(--muted-foreground)] opacity-60"}[t]),children:a("unset"===t?"settings.source.unset":r?"settings.source.inherited":"settings.source.".concat(t))})}let a8=/^<<[A-Z_][A-Z0-9_]*>>$/;function a6(e){let{initial:t,placeholder:r,saving:a,onCommit:s}=e,o=""===t&&!!r,[i,c]=(0,l.useState)(t),[d,u]=(0,l.useState)(!1),m=(0,l.useRef)(t);function x(){u(!1),i!==m.current&&(m.current=i,s(i))}(0,l.useEffect)(()=>{c(t),m.current=t,u(!1)},[t]);let p=o&&!d?null!=r?r:"":i;return(0,n.jsx)("input",{type:"text",value:p,placeholder:r,onFocus:()=>{o&&c(""),u(!0)},onChange:e=>{c(e.target.value),u(!0)},onBlur:x,onKeyDown:e=>{"Enter"===e.key&&x()},disabled:a,className:F("h-7 w-full max-w-md rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs outline-none focus:border-[var(--primary)]",o&&!d?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function a9(e){let{initial:t,placeholder:r,step:a,saving:s,onCommit:o}=e,i=""===t&&!!r,[c,d]=(0,l.useState)(t),[u,m]=(0,l.useState)(!1),x=(0,l.useRef)(t);function p(){m(!1),c!==x.current&&(x.current=c,o(c))}(0,l.useEffect)(()=>{d(t),x.current=t,m(!1)},[t]);let h=i&&!u?null!=r?r:"":c;return(0,n.jsx)("input",{type:"number",step:a,value:h,placeholder:r,onFocus:()=>{i&&d(""),m(!0)},onChange:e=>{d(e.target.value),m(!0)},onBlur:p,onKeyDown:e=>{"Enter"===e.key&&p()},disabled:s,className:F("h-7 w-full max-w-md rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs outline-none focus:border-[var(--primary)]",i&&!u?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function a7(e){let{value:t,saving:r,onCommit:a}=e,s="true"===t||"1"===t;return(0,n.jsxs)("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[(0,n.jsx)("input",{type:"checkbox",checked:s,disabled:r,onChange:e=>a(e.target.checked?"true":"false"),className:"h-3.5 w-3.5 cursor-pointer rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)]"}),(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:s?"on":"off"})]})}function se(e){var t,r;let{value:a,options:s,optionLabels:l,placeholder:o,saving:i,onCommit:c}=e,d=null!=(r=null!=(t=null!=a?a:o)?t:s[0])?r:"";return(0,n.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:s.map((e,t)=>{var r;return(0,n.jsx)("option",{value:e,children:null!=(r=null==l?void 0:l[t])?r:e},e)})})}function st(e){let{initial:t,placeholder:r,saving:a,onCommit:s}=e,o=a8.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,s(i),u(!1)}}return(0,l.useEffect)(()=>{c(t),p.current=t,u(!1),x(a8.test(t))},[t]),(0,n.jsxs)("div",{className:"relative w-full max-w-md",children:[(0,n.jsx)("input",{type:m||d?"text":"password",value:d?i:t||"",placeholder:r,onFocus:()=>{d||!t||a8.test(t)||c(""),u(!0)},onChange:e=>c(e.target.value),onBlur:h,onKeyDown:e=>{"Enter"===e.key&&h()},disabled:a,className:"h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 pr-7 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),!o&&(0,n.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,n.jsx)(aX.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(eG.A,{className:"h-3.5 w-3.5"})})]})}function sr(e){let{orphans:t,onRemove:r,saving:a}=e,{t:s}=(0,tr.useI18n)(),o=(0,l.useMemo)(()=>{let e=new Map;for(let a of t){var r;let t=null!=(r=e.get(a.namespaceId))?r:[];t.push(a),e.set(a.namespaceId,t)}return Array.from(e.entries())},[t]);return 0===t.length?null:(0,n.jsxs)("div",{className:"space-y-6 p-6",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:s("settings.orphans.title")}),(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:s("settings.orphans.intro")})]}),o.map(e=>{let[t,l]=e;return(0,n.jsxs)("div",{className:"space-y-2 rounded border border-[var(--border)] p-3",children:[(0,n.jsx)("h3",{className:"text-[11px] font-semibold text-[var(--foreground)]",children:t}),(0,n.jsx)("ul",{className:"space-y-1",children:l.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between text-[11px]",children:[(0,n.jsxs)("code",{className:"text-[var(--muted-foreground)]",children:[t,".",e.kind,"s.",e.key]}),(0,n.jsxs)("button",{onClick:()=>r(e),disabled:a,className:"flex cursor-pointer items-center gap-1 rounded px-2 py-0.5 text-[10px] text-red-400 hover:bg-red-500/10 hover:text-red-300",children:[(0,n.jsx)(ej.A,{className:"h-3 w-3"}),s("settings.orphans.remove")]})]},"".concat(e.kind,".").concat(e.key)))})]},t)})]})}var sa=r(76966);let ss=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));var sn=r(32400),sl=r(10561),so=r(2573),si=r(25843),sc=r(70764);function sd(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:s,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d,onRescan:u}=e,[m,x]=(0,l.useState)(r.label),[p,h]=(0,l.useState)(r.workspacePath),[f,g]=(0,l.useState)(r.accessLevel),[b,j]=(0,l.useState)(r.language),[y,w]=(0,l.useState)(!1);async function N(){w(!0);try{await v.F.weixin.updateAccount(r.accountId,{label:m,workspacePath:p,accessLevel:f,language:b}),i()}catch(e){alert(t("wx.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}async function k(){w(!0);try{await v.F.weixin.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("wx.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}async function S(){if(await R(t("wx.confirmDelete",{name:r.label}))){w(!0);try{await v.F.weixin.deleteAccount(r.accountId),c()}catch(e){alert(t("wx.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}}return((0,l.useEffect)(()=>{a&&(x(r.label),h(r.workspacePath),g(r.accessLevel),j(r.language))},[a,r]),a)?(0,n.jsx)("li",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.label")}),(0,n.jsx)("input",{value:m,onChange:e=>x(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("wx.labelPlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.workspace")}),(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.accessLevel")}),(0,n.jsxs)("select",{value:f,onChange:e=>g(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("wx.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("wx.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("wx.full")})]}),(0,n.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.readonlyHint")})]}),(0,n.jsx)(ta.LanguageSelect,{value:b,onChange:j}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:N,disabled:y||!M(p),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,n.jsx)(t0.A,{className:"h-3 w-3"})," ",t("wx.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:y,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(eK.A,{className:"h-3 w-3"})," ",t("wx.cancel")]})]})]})}):(0,n.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,n.jsx)("div",{className:F("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.accountId}),(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"}),(0,n.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:r.accountId})]}),(0,n.jsx)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:r.workspacePath})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:k,disabled:y,title:r.enabled?t("wx.disable"):t("wx.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,n.jsx)(sl.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(so.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:u,disabled:y,title:t("wx.rescan"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(si.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:y,title:t("wx.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:S,disabled:y,title:t("wx.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function su(e){let t=(0,tr.useT)(),{intent:r,onClose:a,onDone:s}=e,o=e9(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)(r.workspacePath||(null==o?void 0:o.path)||""),[b,j]=(0,l.useState)(r.label||""),[y,w]=(0,l.useState)(r.accessLevel),[N,k]=(0,l.useState)(r.language),[S,C]=(0,l.useState)(r.skipConfig?"scan":"config"),A=(0,l.useRef)(!1),I=r.skipConfig;async function T(){if(!M(f))return void h(t("wx.pathRequired"));C("scan"),x("loading"),h(t("wx.generatingQr"));try{let{qrcodeUrl:r,sessionKey:a}=await v.F.weixin.startLogin();if(A.current)return;if(!r){x("error"),h(t("wx.qrFailed"));return}c(a);let n=await sn.toDataURL(r,{width:256,margin:2});if(A.current)return;u(n),x("waiting"),h(t("wx.scanPrompt"));let l=await v.F.weixin.waitLogin({sessionKey:a,workspacePath:f,label:b||void 0,accessLevel:y,language:N});if(A.current)return;if(l.connected){var e;x("success"),h(t("wx.connected",{id:null!=(e=l.accountId)?e:""})),setTimeout(s,1200)}else x("error"),h(l.message||t("wx.loginFailed"))}catch(e){if(A.current)return;x("error"),h(e instanceof Error?e.message:String(e))}}return(0,l.useEffect)(()=>()=>{A.current=!0},[]),(0,l.useEffect)(()=>{r.skipConfig&&T()},[]),(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,n.jsxs)("div",{className:"w-[400px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:I?t("wx.rescanBtn"):t("wx.addTitle")}),(0,n.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),"config"===S?(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.bindWorkspace")}),(0,n.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"}),(0,n.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.bindHint")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.nameOptional")}),(0,n.jsx)("input",{value:b,onChange:e=>j(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("wx.namePlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.accessLevel")}),(0,n.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("wx.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("wx.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("wx.full")})]}),(0,n.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.readonlyShareHint")})]}),(0,n.jsx)(ta.LanguageSelect,{value:N,onChange:k}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,n.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.cancel")}),(0,n.jsx)("button",{onClick:T,disabled:!M(f),className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:t("wx.nextStep")})]})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[d?(0,n.jsx)("img",{src:d,alt:t("wx.scanTitle"),className:"rounded border border-[var(--border)]"}):(0,n.jsx)("div",{className:"flex h-64 w-64 items-center justify-center rounded border border-[var(--border)] bg-[var(--card)]",children:(0,n.jsx)(H.A,{className:"h-6 w-6 animate-spin text-[var(--muted-foreground)]"})}),(0,n.jsx)("p",{className:F("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,n.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[t("wx.bindTo")," ",(0,n.jsx)("code",{className:"text-[var(--foreground)]",children:f})]}),"error"===m&&(0,n.jsx)("button",{onClick:()=>{C("config")},className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.restart")})]}),i&&(0,n.jsx)("input",{type:"hidden",value:i,readOnly:!0})]})})}let sm={id:"weixin",label:"channels.weixin",Icon:sa.A,Component:function(){let e=(0,tr.useT)(),{lang:t}=(0,tr.useI18n)(),[r,a]=(0,l.useState)([]),[s,o]=(0,l.useState)(!0),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),m=(0,l.useCallback)(()=>{o(!0),v.F.weixin.listAccounts().then(e=>a(e.accounts)).catch(e=>{console.error("[weixin] list failed:",e)}).finally(()=>o(!1))},[]);(0,l.useEffect)(()=>{m()},[m]);let x=ss(e=>e.version);return(0,l.useEffect)(()=>{x>0&&m()},[x,m]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("wx.title")}),(0,n.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("wx.desc")})]}),(0,n.jsxs)("button",{onClick:()=>c({workspacePath:"",label:"",accessLevel:"readonly",language:t,skipConfig:!1}),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"}),e("wx.add")]})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("wx.loading")]}):0===r.length?(0,n.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("wx.empty")}):(0,n.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:r.map(e=>(0,n.jsx)(sd,{account:e,editing:d===e.accountId,onEdit:()=>u(e.accountId),onCancelEdit:()=>u(null),onSaved:()=>{u(null),m()},onDeleted:m,onToggled:m,onRescan:()=>c({workspacePath:e.workspacePath,label:e.label,accessLevel:e.accessLevel,language:e.language,skipConfig:!0})},e.accountId))})}),i&&(0,n.jsx)(su,{intent:i,onClose:()=>c(null),onDone:()=>{c(null),m()}})]})}};function sx(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:s,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,m]=(0,l.useState)(r.label),[x,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.allowedUsers),[j,y]=(0,l.useState)(r.language||"en"),[w,N]=(0,l.useState)(!1);async function k(){N(!0);try{await v.F.telegram.updateAccount(r.accountId,{label:u,workspacePath:x,accessLevel:h,allowedUsers:g,language:j}),i()}catch(e){alert(t("tg.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}async function S(){N(!0);try{await v.F.telegram.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("tg.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}async function C(){if(await R(t("tg.confirmDelete",{name:r.botUsername}))){N(!0);try{await v.F.telegram.deleteAccount(r.accountId),c()}catch(e){alert(t("tg.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),p(r.workspacePath),f(r.accessLevel),b(r.allowedUsers),y(r.language||"en"))},[a,r]),a)?(0,n.jsx)("li",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.label")}),(0,n.jsx)("input",{value:u,onChange:e=>m(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("tg.labelPlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.workspace")}),(0,n.jsx)("input",{value:x,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.accessLevel")}),(0,n.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("tg.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("tg.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("tg.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:j,onChange:y}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.allowedUsers")}),(0,n.jsx)("input",{value:g,onChange:e=>b(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"123456789,@username"})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:k,disabled:w||!M(x),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,n.jsx)(t0.A,{className:"h-3 w-3"})," ",t("tg.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:w,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(eK.A,{className:"h-3 w-3"})," ",t("tg.cancel")]})]})]})}):(0,n.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,n.jsx)("div",{className:F("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||"@".concat(r.botUsername)}),(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"}),r.allowedUsers&&(0,n.jsx)("span",{className:"rounded bg-blue-500/15 px-1.5 py-0.5 text-[9px] font-medium text-blue-300",children:t("tg.whitelist")})]}),(0,n.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["@",r.botUsername," → ",r.workspacePath,r.workspaceMissing&&(0,n.jsx)("span",{className:"ml-1 text-red-400",children:t("tg.pathMissing")})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:S,disabled:w,title:r.enabled?t("tg.disable"):t("tg.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,n.jsx)(sl.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(so.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:w,title:t("tg.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:C,disabled:w,title:t("tg.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function sp(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:s}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)((null==o?void 0:o.path)||""),[m,x]=(0,l.useState)(""),[p,h]=(0,l.useState)("readonly"),[f,g]=(0,l.useState)(""),[b,j]=(0,l.useState)(r),[y,w]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),w(!0);try{await v.F.telegram.createAccount({botToken:i,workspacePath:d,label:m||void 0,accessLevel:p,allowedUsers:f||void 0,language:b}),s()}catch(e){k(e instanceof Error?e.message:String(e))}finally{w(!1)}}return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,n.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("tg.addTitle")}),(0,n.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.tokenLabel")}),(0,n.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"123456:ABC-DEF..."})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.bindWorkspace")}),(0,n.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.nameOptional")}),(0,n.jsx)("input",{value:m,onChange:e=>x(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("tg.namePlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.accessLevel")}),(0,n.jsxs)("select",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("tg.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("tg.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("tg.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:b,onChange:j}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.allowedUsersOptional")}),(0,n.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:t("tg.allowedUsersHint")})]}),N&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:N}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,n.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("tg.cancel")}),(0,n.jsxs)("button",{onClick:S,disabled:y||!i.trim()||!M(d),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[y&&(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("tg.addBtn")]})]})]})]})})}let sh={id:"telegram",label:"Telegram",Icon:ry.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,s]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{s(!0),v.F.telegram.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[telegram] list failed:",e)}).finally(()=>s(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let m=ss(e=>e.version);return(0,l.useEffect)(()=>{m>0&&u()},[m,u]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("tg.title")}),(0,n.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("tg.desc")})]}),(0,n.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"}),e("tg.add")]})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("tg.loading")]}):0===t.length?(0,n.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("tg.empty")}):(0,n.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,n.jsx)(sx,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,n.jsx)(sp,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function sf(e){let{account:t,editing:r,onEdit:a,onCancelEdit:s,onSaved:o,onDeleted:i,onToggled:c}=e,d=(0,tr.useT)(),[u,m]=(0,l.useState)(t.label),[x,p]=(0,l.useState)(t.workspacePath),[h,f]=(0,l.useState)(t.accessLevel),[g,b]=(0,l.useState)(t.language||"en"),[j,y]=(0,l.useState)(!1),[w,N]=(0,l.useState)(!1);async function k(){y(!0);try{await v.F.web.updateAccount(t.accountId,{label:u,workspacePath:x,accessLevel:h,language:g}),o()}catch(e){alert(d("web.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function S(){y(!0);try{await v.F.web.updateAccount(t.accountId,{enabled:!t.enabled}),c()}catch(e){alert(d("web.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function C(){if(await R(d("web.confirmDelete"))){y(!0);try{await v.F.web.deleteAccount(t.accountId),i()}catch(e){alert(d("web.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{r&&(m(t.label),p(t.workspacePath),f(t.accessLevel),b(t.language||"en"))},[r,t]),r)?(0,n.jsx)("li",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.label")}),(0,n.jsx)("input",{value:u,onChange:e=>m(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:d("web.labelPlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.workspace")}),(0,n.jsx)("input",{value:x,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.accessLevel")}),(0,n.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:d("web.readonly")}),(0,n.jsx)("option",{value:"observer",children:d("web.observer")}),(0,n.jsx)("option",{value:"workspace",children:d("web.wsWrite")}),(0,n.jsx)("option",{value:"full",children:d("web.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:k,disabled:j||!M(x),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,n.jsx)(t0.A,{className:"h-3 w-3"})," ",d("web.save")]}),(0,n.jsxs)("button",{onClick:s,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(eK.A,{className:"h-3 w-3"})," ",d("web.cancel")]})]})]})}):(0,n.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,n.jsx)("div",{className:F("h-2 w-2 rounded-full",t.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.label||t.accountId}),(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===t.accessLevel?"bg-emerald-500/15 text-emerald-300":"observer"===t.accessLevel?"bg-teal-500/15 text-teal-300":"workspace"===t.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===t.accessLevel?"Readonly":"observer"===t.accessLevel?"Observer":"workspace"===t.accessLevel?"Workspace":"Full"})]}),(0,n.jsx)("div",{className:"mt-0.5 flex items-center gap-2",children:(0,n.jsxs)("p",{className:"truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:[t.workspacePath,t.workspaceMissing&&(0,n.jsx)("span",{className:"ml-1 text-red-400",children:d("web.pathMissing")})]})}),(0,n.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[(0,n.jsxs)("code",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 font-mono text-[9px] text-[var(--muted-foreground)]",children:[t.token.slice(0,12),"..."]}),(0,n.jsx)("button",{onClick:function(){navigator.clipboard.writeText(t.token),N(!0),setTimeout(()=>N(!1),2e3)},className:"text-[10px] text-[var(--primary)] hover:underline",children:w?d("web.copied"):d("web.copyToken")})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:S,disabled:j,title:t.enabled?d("web.disable"):d("web.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:t.enabled?(0,n.jsx)(sl.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(so.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:a,disabled:j,title:d("web.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:C,disabled:j,title:d("web.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function sg(e){let{onClose:t,onDone:r}=e,a=(0,tr.useT)(),{lang:s}=(0,tr.useI18n)(),o=e9(e=>e.activeProject),[i,c]=(0,l.useState)((null==o?void 0:o.path)||""),[d,u]=(0,l.useState)(""),[m,x]=(0,l.useState)("readonly"),[p,h]=(0,l.useState)(s),[f,g]=(0,l.useState)(!1),[b,j]=(0,l.useState)(""),[y,w]=(0,l.useState)(null);async function N(){j(""),g(!0);try{let e=await v.F.web.createAccount({workspacePath:i,label:d||void 0,accessLevel:m,language:p});w({token:e.token})}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}return y?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:r,children:(0,n.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"mb-3 text-sm font-medium text-[var(--foreground)]",children:a("web.createSuccess")}),(0,n.jsx)("p",{className:"mb-2 text-xs text-[var(--muted-foreground)]",children:a("web.tokenNotice")}),(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] bg-[var(--card)] p-2",children:[(0,n.jsx)("code",{className:"flex-1 break-all font-mono text-xs text-[var(--foreground)]",children:y.token}),(0,n.jsx)("button",{onClick:()=>navigator.clipboard.writeText(y.token),className:"rounded p-1 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(t1.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("div",{className:"mt-4 flex justify-end",children:(0,n.jsx)("button",{onClick:r,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white",children:a("web.done")})})]})}):(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:t,children:(0,n.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:a("web.createTitle")}),(0,n.jsx)("button",{onClick:t,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.bindWorkspace")}),(0,n.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.nameOptional")}),(0,n.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:a("web.namePlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.accessLevel")}),(0,n.jsxs)("select",{value:m,onChange:e=>x(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:a("web.readonly")}),(0,n.jsx)("option",{value:"observer",children:a("web.observer")}),(0,n.jsx)("option",{value:"workspace",children:a("web.wsWrite")}),(0,n.jsx)("option",{value:"full",children:a("web.full")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("common.language")}),(0,n.jsxs)("select",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"en",children:"English"}),(0,n.jsx)("option",{value:"zh",children:"中文"})]})]}),b&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:b}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,n.jsx)("button",{onClick:t,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:a("web.cancel")}),(0,n.jsxs)("button",{onClick:N,disabled:f||!M(i),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[f&&(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),a("web.createBtn")]})]})]})]})})}let sv={id:"web_demo",label:"Web",Icon:J.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,s]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{s(!0),v.F.web.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[web] list failed:",e)}).finally(()=>s(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let m=ss(e=>e.version);return(0,l.useEffect)(()=>{m>0&&u()},[m,u]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("web.title")}),(0,n.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("web.desc")})]}),(0,n.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"}),e("web.create")]})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("web.loading")]}):0===t.length?(0,n.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("web.empty")}):(0,n.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,n.jsx)(sf,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,n.jsx)(sg,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function sb(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:s,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,m]=(0,l.useState)(r.label),[x,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.language||"en"),[j,y]=(0,l.useState)(!1);async function w(){y(!0);try{await v.F.slack.updateAccount(r.accountId,{label:u,workspacePath:x,accessLevel:h,language:g}),i()}catch(e){alert(t("slack.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function N(){y(!0);try{await v.F.slack.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("slack.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function k(){if(await R(t("slack.confirmDelete",{name:r.teamId}))){y(!0);try{await v.F.slack.deleteAccount(r.accountId),c()}catch(e){alert(t("slack.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),p(r.workspacePath),f(r.accessLevel),b(r.language||"en"))},[a,r]),a)?(0,n.jsx)("li",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.label")}),(0,n.jsx)("input",{value:u,onChange:e=>m(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("slack.labelPlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.workspace")}),(0,n.jsx)("input",{value:x,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.accessLevel")}),(0,n.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("slack.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("slack.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("slack.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:w,disabled:j||!M(x),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,n.jsx)(t0.A,{className:"h-3 w-3"})," ",t("slack.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(eK.A,{className:"h-3 w-3"})," ",t("slack.cancel")]})]})]})}):(0,n.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,n.jsx)("div",{className:F("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.teamId}),(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"})]}),(0,n.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["team:",r.teamId," bot:",r.botUserId," → ",r.workspacePath,r.workspaceMissing&&(0,n.jsx)("span",{className:"ml-1 text-red-400",children:t("slack.pathMissing")})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:N,disabled:j,title:r.enabled?t("slack.disable"):t("slack.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,n.jsx)(sl.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(so.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:j,title:t("slack.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:k,disabled:j,title:t("slack.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function sj(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:s}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)(""),[m,x]=(0,l.useState)((null==o?void 0:o.path)||""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)("readonly"),[b,j]=(0,l.useState)(r),[y,w]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),w(!0);try{await v.F.slack.createAccount({botToken:i,appToken:d,workspacePath:m,label:p||void 0,accessLevel:f,language:b}),s()}catch(e){k(e instanceof Error?e.message:String(e))}finally{w(!1)}}return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,n.jsxs)("div",{className:"w-[480px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("slack.addTitle")}),(0,n.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.botTokenLabel")}),(0,n.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"xoxb-..."}),(0,n.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("slack.botTokenHint")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.appTokenLabel")}),(0,n.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"xapp-..."}),(0,n.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("slack.appTokenHint")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.bindWorkspace")}),(0,n.jsx)("input",{value:m,onChange:e=>x(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.nameOptional")}),(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("slack.namePlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.accessLevel")}),(0,n.jsxs)("select",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("slack.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("slack.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("slack.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:b,onChange:j}),N&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:N}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,n.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("slack.cancel")}),(0,n.jsxs)("button",{onClick:S,disabled:y||!i.trim()||!d.trim()||!M(m),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[y&&(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("slack.addBtn")]})]})]})]})})}function sy(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:s,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,m]=(0,l.useState)(r.label),[x,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.language||"en"),[j,y]=(0,l.useState)(!1);async function w(){y(!0);try{await v.F.feishu.updateAccount(r.accountId,{label:u,workspacePath:x,accessLevel:h,language:g}),i()}catch(e){alert(t("feishu.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function N(){y(!0);try{await v.F.feishu.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("feishu.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function k(){if(await R(t("feishu.confirmDelete",{name:r.appId}))){y(!0);try{await v.F.feishu.deleteAccount(r.accountId),c()}catch(e){alert(t("feishu.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),p(r.workspacePath),f(r.accessLevel),b(r.language||"en"))},[a,r]),a)?(0,n.jsx)("li",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.label")}),(0,n.jsx)("input",{value:u,onChange:e=>m(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("feishu.labelPlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.workspace")}),(0,n.jsx)("input",{value:x,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.accessLevel")}),(0,n.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("feishu.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("feishu.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("feishu.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:w,disabled:j||!M(x),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,n.jsx)(t0.A,{className:"h-3 w-3"})," ",t("feishu.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(eK.A,{className:"h-3 w-3"})," ",t("feishu.cancel")]})]})]})}):(0,n.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,n.jsx)("div",{className:F("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.appId}),(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"})]}),(0,n.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["app:",r.appId," bot:",r.botOpenId," → ",r.workspacePath,r.workspaceMissing&&(0,n.jsx)("span",{className:"ml-1 text-red-400",children:t("feishu.pathMissing")})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:N,disabled:j,title:r.enabled?t("feishu.disable"):t("feishu.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,n.jsx)(sl.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(so.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:j,title:t("feishu.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:k,disabled:j,title:t("feishu.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function sw(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:s}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)(""),[m,x]=(0,l.useState)(""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)((null==o?void 0:o.path)||""),[b,j]=(0,l.useState)(""),[y,w]=(0,l.useState)("readonly"),[N,k]=(0,l.useState)(r),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)("");async function T(){I(""),C(!0);try{await v.F.feishu.createAccount({appId:i,appSecret:d,verificationToken:m||void 0,encryptKey:p||void 0,workspacePath:f,label:b||void 0,accessLevel:y,language:N}),s()}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,n.jsxs)("div",{className:"w-[480px] max-h-[90vh] overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("feishu.addTitle")}),(0,n.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.appIdLabel")}),(0,n.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"cli_xxxxxxx"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.appSecretLabel")}),(0,n.jsx)("input",{type:"password",value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"****************"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.verificationTokenLabel")}),(0,n.jsx)("input",{value:m,onChange:e=>x(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:""})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.encryptKeyLabel")}),(0,n.jsx)("input",{type:"password",value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:""})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.bindWorkspace")}),(0,n.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.nameOptional")}),(0,n.jsx)("input",{value:b,onChange:e=>j(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("feishu.namePlaceholder")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.accessLevel")}),(0,n.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,n.jsx)("option",{value:"readonly",children:t("feishu.readonly")}),(0,n.jsx)("option",{value:"workspace",children:t("feishu.wsWrite")}),(0,n.jsx)("option",{value:"full",children:t("feishu.full")})]})]}),(0,n.jsx)(ta.LanguageSelect,{value:N,onChange:k}),A&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:A}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,n.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("feishu.cancel")}),(0,n.jsxs)("button",{onClick:T,disabled:S||!i.trim()||!d.trim()||!M(f),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[S&&(0,n.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("feishu.addBtn")]})]})]})]})})}let sN=[sm,sh,sv,{id:"slack",label:"Slack",Icon:X.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,s]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{s(!0),v.F.slack.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[slack] list failed:",e)}).finally(()=>s(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let m=ss(e=>e.version);return(0,l.useEffect)(()=>{m>0&&u()},[m,u]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("slack.title")}),(0,n.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("slack.desc")})]}),(0,n.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"}),e("slack.add")]})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("slack.loading")]}):0===t.length?(0,n.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("slack.empty")}):(0,n.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,n.jsx)(sb,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,n.jsx)(sj,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}},{id:"feishu",label:"Feishu",Icon:r(29659).A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,s]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{s(!0),v.F.feishu.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[feishu] list failed:",e)}).finally(()=>s(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let m=ss(e=>e.version);return(0,l.useEffect)(()=>{m>0&&u()},[m,u]),(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("feishu.title")}),(0,n.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("feishu.desc")})]}),(0,n.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"}),e("feishu.add")]})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("feishu.loading")]}):0===t.length?(0,n.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("feishu.empty")}):(0,n.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,n.jsx)(sy,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,n.jsx)(sw,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}}],sk="halo_channel_active",sS=new Set(sN.map(e=>e.id)),sC=null!=(s=null==(a=sN[0])?void 0:a.id)?s:"",sA=(0,c.v)(e=>({active:function(){try{let e=localStorage.getItem(sk);if(e&&sS.has(e))return e}catch(e){}return sC}(),setActive(t){if(sS.has(t)){try{localStorage.setItem(sk,t)}catch(e){}e({active:t})}}}));function sI(){let e=(0,tr.useT)(),t=sA(e=>e.active),r=sA(e=>e.setActive);return(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,n.jsx)(sa.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Channels"}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>void ss.getState().bump(),title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:(0,n.jsx)(tG.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:sN.map(a=>{if(!1===a.enabled)return null;let s=a.Icon,l=e(a.label),o=l===a.label?a.label:l;return(0,n.jsxs)("button",{onClick:()=>r(a.id),className:F("flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors",t===a.id?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]"),children:[(0,n.jsx)(s,{className:"h-3.5 w-3.5"}),o]},a.id)})})]})}function sT(){let e=sA(e=>e.active),t=sN.find(t=>t.id===e);if(!t)return null;let r=t.Component;return(0,n.jsx)(r,{})}var sE=r(23704);let sD=(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 sF(){let e=(0,tr.useT)(),t=sD(e=>e.selectedId);return t?(0,n.jsx)(sR,{id:t}):(0,n.jsx)(sP,{label:e("evolution.list.pickRun")})}function sP(e){let{label:t}=e;return(0,n.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function sM(e){var t;let{status:r}=e,a=null!=(t=sL[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let sL={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 sR(e){var t,r,a,s;let{id:o}=e,i=(0,tr.useT)(),c=sD(e=>e.refreshTick),d=sD(e=>e.setSelectedId),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)(!0),[h,f]=(0,l.useState)(null),[g,b]=(0,l.useState)(!1),[y,w]=(0,l.useState)(""),[N,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[T,E]=(0,l.useState)(!1),[D,F]=(0,l.useState)(""),P=(0,l.useCallback)(async()=>{p(!0);try{let e=await v.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),w(""),k(""),P()},[o,P]),(0,l.useEffect)(()=>{0!==c&&P()},[c,P]),(0,l.useEffect)(()=>j.on("evolution:run_changed",e=>{e.id===o&&("deleted"===e.kind?d(null):P())}),[o,P,d]),x&&!u)return(0,n.jsx)(sP,{label:i("evolution.list.loading")});if(h)return(0,n.jsx)(sP,{label:i("cron.error",{error:h})});if(!u)return(0,n.jsx)(sP,{label:i("evolution.list.noRun")});let{run:M,patchMd:L,scoreJson:_,skipReasonMd:z,snapshotSummary:O,wrapperLog:W,subCliLog:U}=u,B="awaiting_review"===M.status,H="approved"===M.status&&("failed"===M.applyStatus||"timeout"===M.applyStatus),K=async()=>{b(!0);try{await v.F.evolution.approve(o,y.trim()||void 0),C(!1),w(""),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}},G=async()=>{if(await R(i("evolution.action.confirmReject"))){b(!0);try{await v.F.evolution.reject(o),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}}},J=async()=>{let e=N.trim();if(e){b(!0);try{await v.F.evolution.addHint(o,e),k(""),I(!1),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}}},q=async()=>{let e=D.trim();if(!e)return void alert(i("evolution.action.retryNeedsHint"));b(!0);try{await v.F.evolution.retry(o,e),F(""),E(!1),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}},Z=async()=>{if(await R(i("evolution.action.confirmDelete"))){b(!0);try{await v.F.evolution.delete(o),d(null)}catch(e){alert(e instanceof Error?e.message:String(e)),b(!1)}}};return(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(sM,{status:M.status}),(0,n.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:M.triggerKind}),(0,n.jsx)("span",{className:"ml-auto text-xs text-[var(--muted-foreground)]",children:M.id}),"pending"!==M.status&&"running"!==M.status&&"approved"!==M.status&&(0,n.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,n.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:[i("evolution.detail.workspace")," ",(0,n.jsx)("span",{className:"font-mono",children:M.workspacePath})]}),M.userHint&&(0,n.jsxs)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs",children:[(0,n.jsx)("div",{className:"font-medium text-[var(--foreground)]",children:i("evolution.detail.hint")}),(0,n.jsx)("div",{className:"mt-1 whitespace-pre-wrap text-[var(--muted-foreground)]",children:M.userHint})]}),M.failureReason&&(0,n.jsx)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:i("evolution.detail.failure",{reason:M.failureReason})}),"skipped"===M.status&&(0,n.jsx)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs text-[var(--muted-foreground)]",children:i("evolution.detail.skipped")}),H&&(0,n.jsxs)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:[(0,n.jsx)("div",{className:"font-medium",children:i("evolution.detail.applyFailed")}),M.applyFailureReason&&(0,n.jsx)("div",{className:"mt-1 whitespace-pre-wrap",children:M.applyFailureReason})]})]}),B&&(0,n.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,n.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,n.jsx)(t0.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.approve")]}),(0,n.jsxs)("button",{disabled:g,onClick:()=>{G()},className:"flex items-center gap-1 rounded bg-red-700 px-2 py-1 text-xs text-red-50 hover:bg-red-600 disabled:opacity-50",children:[(0,n.jsx)(eK.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.reject")]}),(0,n.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,n.jsx)(sE.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.addHint")]}),(0,n.jsxs)("button",{disabled:g,onClick:()=>E(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,n.jsx)(tG.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retry")]})]}),!B&&("failed"===M.status||"timeout"===M.status||"skipped"===M.status||"rejected"===M.status||H)&&(0,n.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,n.jsxs)("button",{disabled:g,onClick:()=>E(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,n.jsx)(tG.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retryWithHint")]})}),T&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)] bg-sky-950/20 px-4 py-2",children:[(0,n.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.retry.title")}),(0,n.jsx)("textarea",{value:D,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,n.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,n.jsx)("button",{disabled:g||!D.trim(),onClick:()=>{q()},className:"rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",children:i("evolution.action.confirmRetry")}),(0,n.jsx)("button",{disabled:g,onClick:()=>{E(!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&&S&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)] bg-emerald-950/20 px-4 py-2",children:[(0,n.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.approve.title")}),(0,n.jsx)("textarea",{value:y,onChange:e=>w(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.approve.placeholder")}),(0,n.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,n.jsx)("button",{disabled:g,onClick:()=>{K()},className:"rounded bg-emerald-700 px-2 py-1 text-xs text-emerald-50 hover:bg-emerald-600 disabled:opacity-50",children:i("evolution.action.confirmApprove")}),(0,n.jsx)("button",{disabled:g,onClick:()=>{C(!1),w("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),B&&A&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)] bg-[var(--background)]/40 px-4 py-2",children:[(0,n.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.hint.title")}),(0,n.jsx)("textarea",{value:N,onChange:e=>k(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.hint.placeholder")}),(0,n.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,n.jsx)("button",{disabled:g||!N.trim(),onClick:()=>{J()},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.add")}),(0,n.jsx)("button",{disabled:g,onClick:()=>{I(!1),k("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),_&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.score.title")}),(0,n.jsxs)("div",{className:"grid grid-cols-4 gap-3 text-xs",children:[(0,n.jsx)(sz,{label:i("evolution.score.lint"),value:_.lint}),(0,n.jsx)(sz,{label:i("evolution.score.behavior"),value:_.behavior}),(0,n.jsx)(sz,{label:i("evolution.score.scope"),value:_.scope}),(0,n.jsx)(sz,{label:i("evolution.score.avg"),value:_.avg,highlight:!0})]}),(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{children:i("evolution.score.confidence")}),(0,n.jsx)("span",{className:"font-medium text-[var(--foreground)]",children:null!=(t=_.confidence)?t:"—"})]}),"string"==typeof _.notes&&(0,n.jsx)("div",{className:"mt-2 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs text-[var(--foreground)]",children:_.notes})]}),O&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3 text-xs",children:[(0,n.jsx)("div",{className:"mb-1 font-medium",children:i("evolution.snapshot.title",{n:null!=(r=O.messageCount)?r:0})}),O.firstUser&&(0,n.jsxs)("div",{className:"mb-1",children:[(0,n.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstUser")," "]}),(0,n.jsx)("span",{className:"line-clamp-2 whitespace-pre-wrap",children:O.firstUser})]}),O.firstAssistant&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstAssistant")," "]}),(0,n.jsx)("span",{className:"line-clamp-3 whitespace-pre-wrap",children:(a=O.firstAssistant,s=400,a.length<=400?a:a.slice(0,s)+"…")})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[z&&(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.skip.title")}),(0,n.jsx)("pre",{className:"whitespace-pre-wrap rounded border border-[var(--border)]/40 bg-[var(--secondary)]/40 p-3 text-xs leading-relaxed",children:z})]}),(0,n.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.patch.title")}),L?(0,n.jsx)("pre",{className:"whitespace-pre-wrap rounded bg-[var(--accent)] p-3 text-xs leading-relaxed",children:L}):(0,n.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:i("evolution.patch.empty")}),(W||U)&&(0,n.jsxs)("div",{className:"mt-6 space-y-4 border-t border-[var(--border)] pt-4",children:[(0,n.jsx)("div",{className:"text-xs uppercase tracking-wide text-[var(--muted-foreground)]",children:i("evolution.logs.title")}),W&&(0,n.jsx)(s_,{title:i("evolution.logs.wrapper"),body:W}),U&&(0,n.jsx)(s_,{title:i("evolution.logs.subCli"),body:U})]})]})]})}function s_(e){let{title:t,body:r}=e,[a,s]=(0,l.useState)(r.length<4e3);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)] hover:text-[var(--primary)]",onClick:()=>s(e=>!e),children:[(0,n.jsx)("span",{children:a?"▼":"▶"}),(0,n.jsx)("span",{children:t}),(0,n.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",(r.length/1024).toFixed(1)," KB)"]})]}),a&&(0,n.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 sz(e){let{label:t,value:r,highlight:a}=e;return(0,n.jsxs)("div",{className:F("rounded p-2",a?"bg-[var(--primary)]/10":"bg-[var(--accent)]"),children:[(0,n.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:t}),(0,n.jsx)("div",{className:F("text-lg font-medium",a&&"text-[var(--primary)]"),children:"number"==typeof r?r:"—"})]})}let sO=["all","awaiting_review","pending","running","approved","applied","skipped","rejected","failed","timeout","archived"];function sW(){let e=(0,tr.useT)(),t=sD(e=>e.filter),r=sD(e=>e.setFilter),a=sD(e=>e.selectedId),s=sD(e=>e.setSelectedId),o=sD(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),[b,y]=(0,l.useState)(!1),w=(0,l.useRef)(0);(0,l.useEffect)(()=>{w.current=i.length,i.length>=300&&g(null)},[i.length]);let N=(0,l.useCallback)(async()=>{let e=Math.min(300,Math.max(20,w.current));try{let r=await v.F.evolution.listRuns({archived:"archived"===t,limit:e});c(r.runs),g(r.hasMore?r.nextCursor:null),x(null)}catch(e){x(e instanceof Error?e.message:String(e))}finally{u(!1)}},[t]),k=(0,l.useCallback)(async()=>{if(f&&!b){y(!0);try{let e=await v.F.evolution.listRuns({archived:"archived"===t,limit:20,before:f});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("evolution.listRuns more",e)}finally{y(!1)}}},[t,f,b]);(0,l.useEffect)(()=>{N()},[N]);let S=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=S.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&k()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[k,i.length]),(0,l.useEffect)(()=>{let e=j.on("evolution:run_changed",()=>{N()}),t=j.on("evolution:apply_changed",()=>{N()});return()=>{e(),t()}},[N]);let C=(0,l.useMemo)(()=>"all"===t||"archived"===t?i:i.filter(e=>e.status===t),[i,t]);return(0,l.useEffect)(()=>{var e;if(a)return;let t=null!=(e=i.find(e=>"awaiting_review"===e.status))?e:i[0];t&&s(t.id)},[i,a,s]),(0,n.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,n.jsx)(rf.A,{className:"h-4 w-4"}),e("evolution.title")]}),(0,n.jsx)("button",{onClick:async()=>{h(!0),o();let e=new Promise(e=>setTimeout(e,400));await Promise.all([N(),e]),h(!1)},disabled:p,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)] disabled:cursor-default",title:e("evolution.refresh"),children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",p&&"animate-spin")})})]}),(0,n.jsx)("div",{className:"flex flex-wrap gap-1 border-b border-[var(--border)] px-2 py-2",children:sO.map(a=>(0,n.jsx)("button",{onClick:()=>r(a),className:F("w-16 shrink-0 rounded px-2 py-0.5 text-xs text-center",t===a?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:e("evolution.filter.".concat(a))},a))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[d&&(0,n.jsx)(sU,{label:e("evolution.list.loading")}),m&&(0,n.jsx)(sU,{label:e("cron.error",{error:m})}),!d&&!m&&0===C.length&&(0,n.jsx)(sU,{label:e("evolution.list.empty")}),C.map(e=>(0,n.jsx)(sB,{run:e,selected:e.id===a,onClick:()=>s(e.id)},e.id)),f&&(0,n.jsx)("div",{ref:S,className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?e("evolution.list.loading"):e("cron.loadOlder")})]})]})}function sU(e){let{label:t}=e;return(0,n.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function sB(e){var t;let{run:r,selected:a,onClick:s}=e,l=(0,tr.useT)();return(0,n.jsxs)("button",{onClick:s,className:F("flex w-full flex-col gap-1 border-b border-[var(--border)] px-3 py-2 text-left text-sm transition-colors",a?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(sH,{status:r.status}),"approved"===r.status&&("failed"===r.applyStatus||"timeout"===r.applyStatus)&&(0,n.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,n.jsx)("span",{className:"text-xs",children:r.triggerKind})]}),(0,n.jsx)("div",{className:"truncate text-xs text-[var(--muted-foreground)]",children:null!=(t=r.userHint)?t:(0,n.jsx)("span",{className:"italic",children:l("evolution.list.noHint")})}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{children:function(e,t){let r=Math.floor((Date.now()-e)/6e4);if(r<1)return t("evolution.time.justNow");if(r<60)return t("evolution.time.minutes",{n:r});let a=Math.floor(r/60);return a<24?t("evolution.time.hours",{n:a}):t("evolution.time.days",{n:Math.floor(a/24)})}(r.createdAt,l)}),(0,n.jsx)("span",{children:"•"}),(0,n.jsx)("span",{title:r.workspacePath,className:"truncate",children:r.workspacePath.split("/").pop()}),r.attempts>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"•"}),(0,n.jsx)("span",{children:l("evolution.list.attempts",{n:r.attempts})})]})]})]})}function sH(e){var t;let{status:r}=e,a=null!=(t=sK[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,n.jsx)("span",{className:F("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let sK={pending:"bg-[var(--accent)] text-[var(--foreground)]",running:"bg-blue-700 text-blue-100",awaiting_review:"bg-amber-600 text-amber-50",approved:"bg-emerald-700 text-emerald-50",applied:"bg-emerald-800 text-emerald-100",skipped:"bg-[var(--accent)] text-[var(--foreground)]",rejected:"bg-red-700 text-red-50",failed:"bg-red-800 text-red-100",timeout:"bg-orange-700 text-orange-100"};var sG=r(97016),sJ=r.n(sG),sq=r(97482);let sZ=(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 sV(e,t){return e?e.includes("ret=-2")?t("cron.err.wechat.noInbound"):e:"?"}function sY(){let e=(0,tr.useT)(),t=sZ(e=>e.selectedId),r=sZ(e=>e.setSelectedId),a=sZ(e=>e.formMode),s=sZ(e=>e.closeForm),[o,i]=(0,l.useState)(null),c=(0,l.useCallback)(async()=>{if(!t)return void i(null);try{var e;let{jobs:r}=await v.F.cron.listJobs();i(null!=(e=r.find(e=>e.id===t))?e:null)}catch(e){console.error("cron.listJobs",e)}},[t]);(0,l.useEffect)(()=>{c()},[c]),(0,l.useEffect)(()=>j.on("cron:job_changed",()=>{c()}),[c]);let d=(0,l.useCallback)(async a=>{if(await R(e("cron.confirmDelete")))try{await v.F.cron.deleteJob(a),t===a&&r(null)}catch(e){alert(e instanceof Error?e.message:String(e))}},[t,r,e]),u=(0,l.useCallback)(async e=>{try{await v.F.cron.runNow(e)}catch(e){alert(e instanceof Error?e.message:String(e))}},[]);return"create"===a?(0,n.jsx)(sX,{onClose:s,onSaved:s}):"edit"===a&&o?(0,n.jsx)(sX,{initial:o,onClose:s,onSaved:s}):o?(0,n.jsx)(s$,{job:o,onEdit:()=>sZ.getState().openEdit(),onDelete:()=>d(o.id),onRunNow:()=>u(o.id)},o.id):(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("cron.pickJob")})}function s$(e){let{job:t,onEdit:r,onDelete:a,onRunNow:s}=e,o=(0,tr.useT)(),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(null),[m,x]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!1),w=(0,l.useCallback)(async()=>{try{let e=await v.F.cron.listRuns(t.id,{limit:20});c(e.runs),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns",e)}},[t.id]),N=(0,l.useCallback)(async()=>{if(f&&!b){y(!0);try{let e=await v.F.cron.listRuns(t.id,{limit:20,before:f});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns more",e)}finally{y(!1)}}},[t.id,f,b]);(0,l.useEffect)(()=>{w()},[w]);let k=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=k.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&N()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[N,i.length]),(0,l.useEffect)(()=>j.on("cron:run_changed",e=>{e.jobId===t.id&&w()}),[t.id,w]);let S=(0,l.useCallback)(async e=>{u(e),x(null),h(!0);try{let{log:t}=await v.F.cron.getRunLog(e);x(null!=t?t:"(log file not available — retention or never written)")}catch(e){x("error: ".concat(e instanceof Error?e.message:String(e)))}finally{h(!1)}},[]);return(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,n.jsx)(sq.A,{className:"h-4 w-4"}),(0,n.jsx)("span",{children:t.label||t.id}),0===t.enabled&&(0,n.jsx)("span",{className:"rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] uppercase",children:o("cron.disabled")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:s,className:"flex items-center gap-1 rounded bg-emerald-600 px-2 py-1 text-xs text-white hover:opacity-90",title:o("cron.runNow"),children:[(0,n.jsx)(aD.A,{className:"h-3 w-3"})," ",o("cron.runNow")]}),(0,n.jsxs)("button",{onClick:r,className:"flex items-center gap-1 rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:opacity-90",title:o("cron.edit"),children:[(0,n.jsx)(sc.A,{className:"h-3 w-3"})," ",o("cron.edit")]}),(0,n.jsx)("button",{onClick:a,className:"flex items-center gap-1 rounded bg-red-700/80 px-2 py-1 text-xs text-white hover:opacity-90",title:o("cron.delete"),children:(0,n.jsx)(ej.A,{className:"h-3 w-3"})})]})]}),(0,n.jsxs)("div",{className:"mt-3 grid grid-cols-2 gap-2 text-xs text-[var(--muted-foreground)]",children:[t.runAt?(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.runAt")})," ",(0,n.jsxs)("span",{className:"font-mono",children:[new Date(t.runAt).toLocaleString(),t.timezone?" (".concat(t.timezone,")"):""]})]}):(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.schedule")})," ",(0,n.jsxs)("span",{className:"font-mono",children:[t.schedule,t.timezone?" (".concat(t.timezone,")"):""]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.agent")})," ",t.agentId]}),(0,n.jsxs)("div",{className:"col-span-2 truncate",children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.workspace")})," ",t.workspacePath]}),(0,n.jsxs)("div",{className:"col-span-2",children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.targets")})," ",0===t.targets.length?o("cron.field.targetsLogOnly"):t.targets.map(e=>"".concat(e.channelType,":").concat(e.accountId).concat(e.chatId?"/"+e.chatId:"")).join(", ")]})]}),(0,n.jsxs)("div",{className:"mt-2",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-[var(--foreground)]",children:o("cron.field.prompt")}),(0,n.jsx)("pre",{className:"mt-1 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs",children:t.userPrompt})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[(0,n.jsx)("div",{className:"mb-2 text-xs font-medium text-[var(--foreground)]",children:o("cron.runHistory")}),0===i.length?(0,n.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:o("cron.noRuns")}):(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("ul",{className:"divide-y divide-[var(--border)] text-xs",children:[i.map(e=>(0,n.jsxs)("li",{className:"py-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:F("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,n.jsx)("span",{className:"text-[var(--muted-foreground)]",children:new Date(e.startedAt).toLocaleString()}),(0,n.jsx)("span",{className:"text-[var(--muted-foreground)]",children:"\xb7"}),(0,n.jsx)("span",{className:"text-[var(--muted-foreground)]",children:e.triggerKind})]}),(0,n.jsx)("button",{onClick:()=>{S(e.id)},className:"rounded bg-[var(--accent)] px-2 py-0.5 text-[10px] hover:opacity-90",children:"Log"})]}),e.failureReason&&(0,n.jsx)("div",{className:"mt-1 text-red-400",children:sV(e.failureReason,o)}),e.dispatchResults&&e.dispatchResults.length>0&&(0,n.jsxs)("div",{className:"mt-1 text-[var(--muted-foreground)]",children:[o("cron.dispatch")," ",e.dispatchResults.map(e=>{let t=e.chatId?"".concat(e.channelType,":").concat(e.accountId,"/").concat(e.chatId):"".concat(e.channelType,":").concat(e.accountId);return"".concat(t," ").concat(e.ok?"✓":"✗ (".concat(sV(e.error,o),")"))}).join(" \xb7 ")]}),e.output&&(0,n.jsx)("pre",{className:"mt-1 line-clamp-3 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-[11px]",children:e.output})]},e.id)),f&&(0,n.jsx)("li",{ref:k,className:"py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?o("cron.loading"):o("cron.loadOlder")})]})})]}),d&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:()=>u(null),children:(0,n.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,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-3 py-2 text-xs",children:[(0,n.jsx)("span",{children:o("cron.log.title",{id:d})}),(0,n.jsx)("button",{onClick:()=>u(null),className:"rounded px-2 py-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:o("cron.log.close")})]}),(0,n.jsx)("pre",{className:"flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-[11px] leading-relaxed",children:p?o("cron.loading"):null!=m?m:""})]})})]})}function sQ(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 sX(e){var t,r,a,s,o,i;let{initial:c,onClose:d,onSaved:u}=e,m=(0,tr.useT)(),x=e9(e=>e.activeProject),[p,h]=(0,l.useState)(null!=(t=null==c?void 0:c.label)?t:""),[f,g]=(0,l.useState)(null!=(a=null!=(r=null==c?void 0:c.workspacePath)?r:null==x?void 0:x.path)?a:""),[b,j]=(0,l.useState)(null!=(s=null==c?void 0:c.agentId)?s:"default"),[y,w]=(0,l.useState)([]),[N,k]=(0,l.useState)((null==c?void 0:c.runAt)?"oneShot":"recurring"),[S,C]=(0,l.useState)((null==c?void 0:c.schedule)||"0 9 * * *"),[A,I]=(0,l.useState)(()=>(null==c?void 0:c.runAt)?sQ(new Date(c.runAt)):sQ(new Date(Date.now()+36e5))),[T,E]=(0,l.useState)(()=>(function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}})());(0,l.useEffect)(()=>{let e=!0;return v.F.cron.meta().then(t=>{let{hostTimezone:r}=t;e&&r&&E(r)}).catch(e=>console.error("cron.meta",e)),()=>{e=!1}},[]);let D=(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(T)?T:e[0];return[{id:t,label:"".concat(t," (default)")},...e.filter(e=>e!==t).map(e=>({id:e,label:e}))]},[T]),[P,M]=(0,l.useState)(null!=(o=null==c?void 0:c.timezone)?o:""),[L,R]=(0,l.useState)(null!=(i=null==c?void 0:c.userPrompt)?i:""),[_,z]=(0,l.useState)((null==c?void 0:c.enabled)!==0),[O,W]=(0,l.useState)([]),[U,B]=(0,l.useState)(()=>{var e;let t=new Set;for(let r of null!=(e=null==c?void 0:c.targets)?e:[])t.add("".concat(r.channelType,":").concat(r.accountId));return t}),[H,K]=(0,l.useState)(()=>{var e;let t={};for(let r of null!=(e=null==c?void 0:c.targets)?e:[]){let e="".concat(r.channelType,":").concat(r.accountId);r.chatId&&(t[e]=t[e]?"".concat(t[e],", ").concat(r.chatId):r.chatId)}return t}),[G,J]=(0,l.useState)(!1),[q,Z]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!0,t=async()=>{try{let{agents:t}=await v.F.agentConfigs.list(f||void 0);if(!e)return;let r=t.filter(e=>!e.id.startsWith("__")&&!e.overridden&&!e.disabled).map(e=>({id:e.id,name:e.name||e.id}));w(r),r.length>0&&!r.some(e=>e.id===b)&&j(r[0].id)}catch(e){console.error("agentConfigs.list",e)}};return f&&t(),()=>{e=!1}},[f,b]),(0,l.useEffect)(()=>{let e=!0;return v.F.cron.listChannelTargets().then(t=>{let{targets:r}=t;e&&W(r)}).catch(e=>console.error("listChannelTargets",e)),()=>{e=!1}},[]);let V=(0,l.useCallback)(e=>{B(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),Y=(0,l.useCallback)((e,t)=>{let r=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(e);if(!r)return Date.parse(e);let[,a,s,n,l,o]=r,i=Date.UTC(+a,s-1,+n,+l,+o),c=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(i)).filter(e=>"literal"!==e.type).map(e=>[e.type,e.value]));return i-(Date.UTC(+c.year,c.month-1,+c.day,24==+c.hour?0:+c.hour,+c.minute,+c.second)-i)},[]),$=(0,l.useCallback)(async()=>{if(Z(null),!f.trim())return void Z(m("cron.form.err.workspace"));if(!b.trim())return void Z(m("cron.form.err.agent"));if("recurring"===N&&!S.trim())return void Z(m("cron.form.err.schedule"));if("oneShot"===N&&!A)return void Z(m("cron.form.err.runAt"));if(!L.trim())return void Z(m("cron.form.err.prompt"));let e=P||T,t="oneShot"===N?Y(A,e):void 0;if("oneShot"===N&&void 0!==t&&t<=Date.now())return void Z(m("cron.form.err.runAtPast"));let r=[];for(let e of U){var a;let[t,s]=e.split(":"),n=(null!=(a=H[e])?a:"").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)?"telegram"!==t||/^-?\d+$/.test(e)?null:"Telegram chatId 必须是数字(私聊 = user id)。「".concat(e,"」无效。"):"飞书 chatId 格式错误:「".concat(e,"」。应该是 oc_…。请用搜索后点击建议项填入。"):"Slack chatId 格式错误:「".concat(e,"」。应该是 D…(DM) / C…(频道) / G…(私有频道)。请用搜索后点击建议项填入,或从 Slack URL 复制。");for(let e of l){let t=o(e);if(t)return void Z(t)}if(0===l.length)r.push({channelType:t,accountId:s});else for(let e of l)r.push({channelType:t,accountId:s,chatId:e})}J(!0);try{let e={label:p||void 0,workspacePath:f,agentId:b,userPrompt:L,timezone:P||void 0,targets:r,enabled:_};c?await v.F.cron.updateJob(c.id,{...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:null}):await v.F.cron.createJob({...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:void 0}),u()}catch(e){Z(e instanceof Error?e.message:String(e))}finally{J(!1)}},[c,p,f,b,L,N,S,A,P,T,Y,U,H,_,u,m]);return(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex h-full flex-col",children:[(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-sm font-medium",children:c?m("cron.form.edit"):m("cron.form.create")}),(0,n.jsx)("button",{onClick:d,className:"jsx-8283b0ed0bcf6928 rounded px-2 py-1 text-xs text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:m("cron.form.cancel")})]}),(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex-1 space-y-3 overflow-y-auto p-4 text-xs",children:[(0,n.jsx)(s0,{label:m("cron.form.label"),children:(0,n.jsx)("input",{value:p,onChange:e=>h(e.target.value),placeholder:m("cron.form.label.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,n.jsx)(s0,{label:m("cron.form.workspace"),children:(0,n.jsx)("input",{value:f,onChange:e=>g(e.target.value),placeholder:m("cron.form.workspace.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"})}),(0,n.jsx)(s0,{label:m("cron.form.agent"),children:(0,n.jsxs)("select",{value:b,onChange:e=>j(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base",children:[0===y.length&&(0,n.jsx)("option",{value:"default",className:"jsx-8283b0ed0bcf6928",children:"default"}),y.map(e=>(0,n.jsxs)("option",{value:e.id,className:"jsx-8283b0ed0bcf6928",children:[e.name," (",e.id,")"]},e.id))]})}),(0,n.jsx)(s0,{label:m("cron.form.mode"),children:(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex gap-3",children:[(0,n.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,n.jsx)("input",{type:"radio",name:"cron-mode",value:"recurring",checked:"recurring"===N,onChange:()=>k("recurring"),className:"jsx-8283b0ed0bcf6928"}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:m("cron.form.mode.recurring")})]}),(0,n.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,n.jsx)("input",{type:"radio",name:"cron-mode",value:"oneShot",checked:"oneShot"===N,onChange:()=>k("oneShot"),className:"jsx-8283b0ed0bcf6928"}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:m("cron.form.mode.oneShot")})]})]})}),"recurring"===N?(0,n.jsxs)(s0,{label:m("cron.form.schedule"),children:[(0,n.jsx)("input",{value:S,onChange:e=>C(e.target.value),placeholder:m("cron.form.schedule.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:m("cron.form.schedule.hint")})]}):(0,n.jsxs)(s0,{label:m("cron.form.runAt"),children:[(0,n.jsx)("input",{type:"datetime-local",value:A,onChange:e=>I(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:m("cron.form.runAt.hint")})]}),(0,n.jsx)(s0,{label:m("cron.form.timezone"),children:(0,n.jsx)(aF,{value:P||T,placeholder:m("cron.form.timezone.hostDefault",{tz:T}),presets:D,onCommit:e=>{M(e===T?"":e)},minWidth:280})}),(0,n.jsx)(s0,{label:m("cron.form.userPrompt"),children:(0,n.jsx)("textarea",{value:L,onChange:e=>R(e.target.value),rows:5,placeholder:m("cron.form.userPrompt.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,n.jsx)(s0,{label:m("cron.form.targets"),children:(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 space-y-1 rounded border border-[var(--border)] p-2",children:[0===O.length?(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-[var(--muted-foreground)]",children:m("cron.form.targets.empty")}):O.map(e=>{var t;let r="".concat(e.channelType,":").concat(e.accountId),a=U.has(r),s="wechat"!==e.channelType,l="slack"===e.channelType?"D… (DM) / C… (channel) / C…:1700.0 (thread)":"telegram"===e.channelType?"数字 chat id(私聊 = user id)":"feishu"===e.channelType?"oc_… 聊天 id":"";return(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 "+(F("rounded px-1 py-0.5",a&&"bg-[var(--accent)]")||""),children:[(0,n.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-2",children:[(0,n.jsx)("input",{type:"checkbox",checked:a,onChange:()=>V(r),disabled:!e.enabled,className:"jsx-8283b0ed0bcf6928"}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928 font-medium",children:e.channelType}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:e.label}),!e.enabled&&(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928 text-[10px] text-[var(--muted-foreground)]",children:m("cron.form.targets.disabled")}),!e.hasActiveChat&&(0,n.jsx)("span",{title:m("cron.form.targets.noActiveChat"),className:"jsx-8283b0ed0bcf6928 text-[10px] text-amber-400",children:m("cron.form.targets.noActiveChatLabel")})]}),a&&s&&(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 ml-6",children:[(0,n.jsx)(s1,{channelType:e.channelType,accountId:e.accountId,value:null!=(t=H[r])?t:"",onChange:e=>K(t=>({...t,[r]:e})),placeholder:l}),(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:"多个 chat 用逗号分隔。留空则不推送(仅写日志)。"})]})]},r)}),(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:m("cron.form.targets.hint")})]})}),(0,n.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex items-center gap-2",children:[(0,n.jsx)("input",{type:"checkbox",checked:_,onChange:e=>z(e.target.checked),className:"jsx-8283b0ed0bcf6928"}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:m("cron.form.enabled")})]}),q&&(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 rounded border border-red-500/50 bg-red-950/40 p-2 text-red-300",children:q})]}),(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex justify-end gap-2 border-t border-[var(--border)] px-4 py-3",children:[(0,n.jsx)("button",{onClick:d,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--accent)] px-3 py-1 text-xs",children:m("cron.form.cancel")}),(0,n.jsx)("button",{onClick:()=>{$()},disabled:G,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--primary)] px-3 py-1 text-xs text-[var(--primary-foreground)] disabled:opacity-50",children:G?m("cron.form.saving"):c?m("cron.form.save"):m("cron.form.create.btn")})]}),(0,n.jsx)(sJ(),{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 s0(e){let{label:t,children:r}=e;return(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"mb-1 block text-[var(--foreground)]",children:t}),r]})}function s1(e){let{channelType:t,accountId:r,value:a,onChange:s,placeholder:o}=e,[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)([]),[m,x]=(0,l.useState)(!1),[p,h]=(0,l.useState)(!1),f="slack"===t||"feishu"===t;return(0,l.useEffect)(()=>{if(!f||!i.trim())return void u([]);let e=!1;h(!0);let a=setTimeout(async()=>{try{let a="slack"===t?await v.F.slack.searchTargets(r,i):await v.F.feishu.searchTargets(r,i);if(e)return;let s=a.hits.map(e=>{var t,r;let a=null!=(r=null!=(t=e.realName)?t:e.email)?r:"";return{id:e.id,name:e.name,chatId:e.chatId,kind:e.kind,subtitle:a}});u(s)}catch(t){e||u([]),console.error("[cron-form] target search failed:",t)}finally{e||h(!1)}},300);return()=>{e=!0,clearTimeout(a)}},[i,t,r,f]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{value:a,onChange:e=>(function(e){var t,r;if(s(e),!f)return;let a=null!=(r=null==(t=e.split(",").pop())?void 0:t.trim())?r:"";c(a),x(a.length>0)})(e.target.value),onFocus:()=>{i&&x(!0)},onBlur:()=>setTimeout(()=>x(!1),150),placeholder:o,className:"input-base font-mono text-[11px]"}),f&&m&&(p||d.length>0)&&(0,n.jsxs)("div",{className:"absolute z-10 mt-1 max-h-60 w-full overflow-y-auto rounded border border-[var(--border)] bg-[var(--background)] shadow-lg",children:[p&&(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] text-[var(--muted-foreground)]",children:"搜索中…"}),!p&&d.map(e=>(0,n.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>(function(e){let t=a.split(",").map(e=>e.trim()).filter(Boolean);t.length>0?t[t.length-1]=e:t.push(e),s(t.join(", ")),c(""),u([]),x(!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,n.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,n.jsxs)("span",{className:"flex-1 truncate",children:[e.name,e.subtitle&&(0,n.jsx)("span",{className:"ml-1 text-[10px] text-[var(--muted-foreground)]",children:e.subtitle})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:e.chatId})]},e.kind+":"+e.id))]})]})}function s5(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,s]=(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=sZ(e=>e.selectedId),f=sZ(e=>e.setSelectedId),g=sZ(e=>e.openCreate),b=(0,l.useCallback)(async()=>{try{let e=await v.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{s(!1)}},[]),y=(0,l.useCallback)(async()=>{if(u&&!x){p(!0);try{let e=await v.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]),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=w.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&y()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[y,t.length]);let N=(0,l.useCallback)(async()=>{d(!0);let e=new Promise(e=>setTimeout(e,400));await Promise.all([b(),e]),d(!1)},[b]);return(0,l.useEffect)(()=>{b()},[b]),(0,l.useEffect)(()=>{let e=j.on("cron:job_changed",()=>{b()}),t=j.on("cron:run_changed",()=>{b()});return()=>{e(),t()}},[b]),(0,l.useEffect)(()=>{!h&&t[0]&&f(t[0].id)},[t,h,f]),(0,n.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,n.jsx)(sq.A,{className:"h-4 w-4"}),e("cron.title")]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.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,n.jsx)(rZ.A,{className:"h-3 w-3"})," ",e("cron.new")]}),(0,n.jsx)("button",{onClick:()=>{N()},disabled:c,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)] disabled:cursor-default",title:e("cron.refresh"),children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",c&&"animate-spin")})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:a&&0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.loading")}):o?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:e("cron.error",{error:o})}):0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.empty")}):(0,n.jsxs)("ul",{className:"divide-y divide-[var(--border)]",children:[t.map(t=>{let r=h===t.id,a=t.lastRunStatus;return(0,n.jsxs)("li",{className:F("cursor-pointer px-3 py-2 text-xs hover:bg-[var(--accent)]",r&&"bg-[var(--accent)]"),onClick:()=>f(t.id),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:F("inline-block h-2 w-2 rounded-full",0===t.enabled?"bg-[var(--muted-foreground)]":"succeeded"===a?"bg-emerald-500":"running"===a?"bg-amber-400 animate-pulse":"failed"===a||"timeout"===a?"bg-red-500":"bg-[var(--muted-foreground)]")}),(0,n.jsx)("span",{className:"truncate font-medium text-[var(--foreground)]",children:t.label||t.id})]}),(0,n.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{className:"font-mono",children:t.runAt?new Date(t.runAt).toLocaleString():t.schedule}),(0,n.jsx)("span",{children:t.agentId})]}),(0,n.jsx)("div",{className:"mt-0.5 truncate text-[var(--muted-foreground)]",children:t.workspacePath}),t.nextRunAt&&1===t.enabled&&(0,n.jsxs)("div",{className:"mt-0.5 text-[var(--muted-foreground)]",children:[e("cron.next")," ",new Date(t.nextRunAt).toLocaleString()]})]},t.id)}),u&&(0,n.jsx)("li",{ref:e=>{w.current=e},className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:x?e("cron.loading"):e("cron.loadOlder")})]})})]})}var s3=r(9207),s2=r(16374),s4=r(48403),s8=r(16981),s6=r(81616),s9=r(71008);let s7=(0,c.v)(e=>({selected:null,select:t=>e({selected:t}),clear:()=>e({selected:null})}));function ne(e){let{files:t,group:r,selectedPath:a,onSelect:s,onAction:o}=e,[i,c]=(0,l.useState)(new Set),d=function(e,t){let r={type:"dir",name:"",path:"",children:[]};for(let a of e){let e=a.path.split("/"),s=r;for(let t=0;t<e.length-1;t++){let r=e[t],a=s.path?"".concat(s.path,"/").concat(r):r,n=s.children.find(e=>"dir"===e.type&&e.name===r);n||(n={type:"dir",name:r,path:a,children:[]},s.children.push(n)),s=n}s.children.push({type:"file",name:e[e.length-1],file:a,char:t(a)})}return function e(t){for(let r of t.children)"dir"===r.type&&e(r);for(;1===t.children.length&&"dir"===t.children[0].type&&""!==t.name;){let e=t.children[0];t.name="".concat(t.name,"/").concat(e.name),t.path=e.path,t.children=e.children}}(r),function e(t){for(let r of(t.children.sort((e,t)=>e.type!==t.type?"dir"===e.type?-1:1:e.name.localeCompare(t.name)),t.children))"dir"===r.type&&e(r)}(r),r.children}(t,e=>"staged"===r?e.index:e.workingDir);return(0,n.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,n.jsxs)("div",{children:[(0,n.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,n.jsx)(U.A,{className:"h-3.5 w-3.5 shrink-0"}):(0,n.jsx)(W.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:t.name})]}),!r&&t.children.map(t=>e(t,l+1))]},"d:".concat(t.path))}let u=S(t.char),m=a===t.file.path,x="staged"===r?s9.A:rZ.A,{Icon:p,color:h}=ec(t.file.path);return(0,n.jsxs)("div",{onClick:()=>s(t.file),className:F("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,n.jsx)(p,{className:F("h-3.5 w-3.5 shrink-0",h)}),(0,n.jsx)("span",{className:"truncate text-[var(--foreground)]",style:{color:u.color},children:t.name}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.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,n.jsx)(x,{className:"h-3.5 w-3.5"})}),(0,n.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 nt=r(35930),nr=r(77271),na=r(93374);function ns(e){let{projectId:t,onClose:r,onSaved:a}=e,s=(0,tr.useT)(),[o,i]=(0,l.useState)("https");return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:r,children:(0,n.jsxs)("div",{className:"w-[460px] rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:s("sc.cred.title")}),(0,n.jsx)("button",{onClick:r,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,n.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,n.jsx)("div",{className:"flex gap-1 border-b border-[var(--border)] px-4 pt-3",children:["https","ssh"].map(e=>(0,n.jsx)("button",{onClick:()=>i(e),className:F("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?s("sc.cred.tabHttps"):s("sc.cred.tabSsh")},e))}),"https"===o?(0,n.jsx)(nl,{onClose:r,onSaved:a}):(0,n.jsx)(no,{projectId:t,onClose:r})]})})}let nn="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 nl(e){let{onClose:t,onSaved:r}=e,a=(0,tr.useT)(),[s,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),[b,j]=(0,l.useState)(null),y=(0,l.useCallback)(()=>{v.F.git.getCredentials().then(e=>o(e.credentials)).catch(()=>o([]))},[]);async function w(){if(!d.trim()||!m.trim()||!p)return void j(a("sc.cred.required"));g(!0),j(null);try{await v.F.git.saveCredentials({host:d.trim(),username:m.trim(),token:p}),h(""),y(),r()}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function N(e){j(null);try{await v.F.git.deleteCredential(e),y()}catch(e){j(e instanceof Error?e.message:String(e))}finally{c(null)}}return(0,l.useEffect)(()=>{y()},[y]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.httpsDesc")}),(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.configuredList")}),0===s.length?(0,n.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:a("sc.cred.noCredsYet")}):s.map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] px-2.5 py-1.5 text-xs",children:[(0,n.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-emerald-400"}),(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,n.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.host}),(0,n.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e.username})]}),i===e.host?(0,n.jsx)("button",{onClick:()=>N(e.host),className:"shrink-0 rounded bg-red-500/15 px-2 py-0.5 text-[10px] font-medium text-red-400 hover:bg-red-500/25",children:a("sc.cred.confirmDelete")}):(0,n.jsx)("button",{onClick:()=>c(e.host),title:a("sc.cred.delete"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:text-red-400",children:(0,n.jsx)(ej.A,{className:"h-3 w-3"})})]},e.host))]}),(0,n.jsx)("div",{className:"border-t border-[var(--border)]"}),(0,n.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.addNew")}),(0,n.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.host")}),(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"github.com",className:nn})]}),(0,n.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.username")}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>x(e.target.value),autoComplete:"off",className:nn})]}),(0,n.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.token")}),(0,n.jsx)("input",{type:"password",value:p,onChange:e=>h(e.target.value),autoComplete:"new-password",className:nn}),(0,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[a("sc.cred.tokenHint")," ",(0,n.jsxs)("a",{href:"https://github.com/settings/tokens",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-0.5 text-[var(--primary)] hover:underline",children:[a("sc.cred.tokenLink"),(0,n.jsx)(nt.A,{className:"h-2.5 w-2.5"})]})]})]})]}),b&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:b})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,n.jsx)("button",{onClick:t,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:a("sc.cred.cancel")}),(0,n.jsx)("button",{onClick:w,disabled:f,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:f?a("sc.cred.saving"):a("sc.cred.save")})]})]})}function no(e){let{projectId:t,onClose:r}=e,a=(0,tr.useT)(),[s,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),[b,j]=(0,l.useState)(null),[y,w]=(0,l.useState)(null),[N,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(null),T=(0,l.useCallback)(()=>{v.F.git.sshKeys().then(e=>o(e.keys)).catch(()=>o([])),v.F.git.sshAgent().then(e=>{c(e.agentRunning),u(e.loadedKeys)}).catch(()=>{}),v.F.git.getRemoteProtocol(t).then(e=>{x(e.protocol),h(e.url)}).catch(()=>{})},[t]);function E(){w(null),k(""),I(null)}async function D(e){C(!0),I(null);try{let r=await v.F.git.unlockSshKey({keyPath:e.path,passphrase:N});if(r.ok)E(),T();else{var t;I(null!=(t=r.error)?t:a("sc.cred.sshUnlockFailed"))}}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}async function P(e){g(!0),j(null);try{let r=await v.F.git.setRemoteProtocol(t,e);x(e),h(r.url)}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}return(0,l.useEffect)(()=>{T()},[T]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,n.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshDesc")}),(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5 text-xs",children:[(0,n.jsx)("span",{className:F("h-2 w-2 rounded-full",i?"bg-emerald-400":"bg-[var(--muted-foreground)]")}),(0,n.jsx)("span",{className:"text-[var(--muted-foreground)]",children:i?a("sc.cred.sshAgentOn",{count:String(d.length)}):a("sc.cred.sshAgentOff")}),(0,n.jsx)("button",{onClick:T,className:"ml-auto rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",title:a("sc.cred.sshRefresh"),children:(0,n.jsx)(tG.A,{className:"h-3 w-3"})})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshKeys")}),0===s.length?(0,n.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:a("sc.cred.sshNoKeys")}):s.map(e=>{let t=d.some(t=>t.includes(e.path)||t.includes(e.name)),r=y===e.path;return(0,n.jsxs)("div",{className:"rounded border border-[var(--border)]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 text-xs",children:[e.encrypted?(0,n.jsx)(nr.A,{className:"h-3 w-3 shrink-0 text-amber-400"}):(0,n.jsx)(na.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.name}),t?(0,n.jsx)("span",{className:"ml-auto text-[10px] text-emerald-400",children:a("sc.cred.sshLoaded")}):!r&&(0,n.jsx)("button",{onClick:()=>{w(e.path),k(""),I(null)},className:"ml-auto shrink-0 rounded bg-[var(--secondary)] px-2 py-0.5 text-[10px] font-medium text-[var(--foreground)] hover:opacity-90",children:a("sc.cred.sshUnlock")})]}),!t&&r&&(0,n.jsxs)("div",{className:"flex flex-col gap-1.5 border-t border-[var(--border)] px-2.5 py-2",children:[(0,n.jsx)("span",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:a("sc.cred.sshUnlockHint")}),(0,n.jsx)("input",{type:"password",autoFocus:!0,autoComplete:"off",value:N,onChange:e=>k(e.target.value),onKeyDown:t=>{"Enter"!==t.key||S||D(e)},placeholder:a("sc.cred.sshPassphrase"),className:nn}),A&&(0,n.jsx)("span",{className:"text-[10px] leading-relaxed text-red-400",children:A}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:E,disabled:S,className:"rounded px-2 py-0.5 text-[10px] font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)] disabled:opacity-40",children:a("sc.cred.cancel")}),(0,n.jsx)("button",{onClick:()=>D(e),disabled:S,className:"rounded bg-[var(--primary)] px-2 py-0.5 text-[10px] font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:S?a("sc.cred.sshUnlocking"):a("sc.cred.sshUnlock")})]})]})]},e.path)})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshRemote")}),(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5",children:[(0,n.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",title:p,children:p||"—"}),(0,n.jsx)("div",{className:"ml-auto flex shrink-0 overflow-hidden rounded border border-[var(--border)]",children:["https","ssh"].map(e=>(0,n.jsx)("button",{onClick:()=>P(e),disabled:f||m===e,className:F("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,n.jsx)("p",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:a("sc.cred.sshRestartNote")}),b&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:b})]}),(0,n.jsx)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:(0,n.jsx)("button",{onClick:r,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:a("sc.cred.close")})})]})}var ni=r(81540);function nc(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 nd(e){let{info:t}=e,r="tag"===t.kind?ni.A:s3.A,a="head"===t.kind?"bg-[var(--primary)] text-[var(--primary-foreground)] font-medium":"tag"===t.kind?"bg-amber-400/10 text-amber-300 ring-1 ring-inset ring-amber-400/30":"remote"===t.kind?"text-[var(--muted-foreground)] ring-1 ring-inset ring-[var(--border)]":"bg-[var(--secondary)] text-[var(--foreground)] ring-1 ring-inset ring-[var(--border)]";return(0,n.jsxs)("span",{className:F("inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] leading-tight",a),children:[(0,n.jsx)(r,{className:"h-2.5 w-2.5 shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:t.label})]})}function nu(e){let{file:t,active:r,onSelect:a}=e,s=S(t.status),{Icon:l,color:o}=ec(t.path),{name:i,dir:c}=function(e){let t=e.lastIndexOf("/");return -1===t?{name:e,dir:""}:{name:e.slice(t+1),dir:e.slice(0,t)}}(t.path);return(0,n.jsxs)("button",{onClick:a,className:F("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,n.jsx)(l,{className:F("h-3.5 w-3.5 shrink-0",o)}),(0,n.jsx)("span",{className:"shrink-0 truncate",style:{color:s.color},children:i}),c&&(0,n.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:c}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("span",{className:"w-4 shrink-0 text-center font-mono text-[11px] font-semibold",style:{color:s.color},title:s.label,children:s.letter})]})}function nm(e){let{projectId:t}=e,r=(0,tr.useT)(),a=s7(e=>e.select),s=s7(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,b]=(0,l.useState)(!1),[y,w]=(0,l.useState)({}),N=(0,l.useRef)(null),k=(0,l.useCallback)(async()=>{try{let e=await v.F.git.log(t,h);i(e.commits),b(e.commits.length>=h),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{m(!0)}},[t,h]);(0,l.useEffect)(()=>{k()},[k]),(0,l.useEffect)(()=>{let e=null,t=j.on("file:changed",()=>{e&&clearTimeout(e),e=setTimeout(()=>{k()},400)});return()=>{e&&clearTimeout(e),t()}},[k]),(0,l.useEffect)(()=>{let e=N.current;if(!e||!g)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&f(e=>e+50)});return t.observe(e),()=>t.disconnect()},[g]);let S=(0,l.useCallback)(e=>{p(t=>t===e?null:e),w(r=>(r[e]||v.F.git.commitFiles(t,e).then(t=>w(r=>({...r,[e]:t.files}))).catch(()=>w(t=>({...t,[e]:[]}))),r))},[t]);return c?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:c}):u&&0===o.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:r("sc.noCommits")}):(0,n.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=y[e.hash],d=e.refs?e.refs.split(",").map(e=>e.trim()).filter(Boolean).map(nc).filter(e=>null!==e):[];return(0,n.jsxs)("div",{className:"flex px-3",children:[(0,n.jsxs)("div",{className:"relative shrink-0",style:{width:24},children:[!l&&(0,n.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:0,height:16}}),(0,n.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:16,bottom:0}}),(0,n.jsx)("div",{className:F("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,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{onClick:()=>S(e.hash),className:F("cursor-pointer rounded-sm py-2",o?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),children:[(0,n.jsx)("div",{className:"truncate text-xs leading-4 text-[var(--foreground)]",children:e.message}),(0,n.jsxs)("div",{className:"mt-1 flex items-center gap-1.5 text-[10px] text-[var(--muted-foreground)]",children:[(0,n.jsx)("span",{className:"font-mono",children:e.shortHash}),(0,n.jsx)("span",{className:"truncate",children:e.author}),(0,n.jsxs)("span",{className:"shrink-0",children:["\xb7 ",tW(e.date)]})]}),d.length>0&&(0,n.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:d.map(e=>(0,n.jsx)(nd,{info:e},"".concat(e.kind,":").concat(e.label)))})]}),o&&(0,n.jsx)("div",{className:"mb-1 ml-1 border-l border-[var(--border)] pl-2",children:void 0===c?(0,n.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:"…"}):0===c.length?(0,n.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:r("sc.noCommitFiles")}):c.map(t=>(0,n.jsx)(nu,{file:t,active:(null==s?void 0:s.commit)===e.hash&&s.path===t.path,onSelect:()=>a({path:t.path,staged:!1,from:t.from,commit:e.hash})},t.path))})]})]},e.hash)}),g&&(0,n.jsx)("div",{ref:N,className:"h-4"})]})}function nx(e){return/authentication|could not read username|permission denied|publickey|passphrase|\b401\b|\b403\b/i.test(e)}function np(){var e,t,r;let a=(0,tr.useT)(),s=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),o=s7(e=>e.selected),i=s7(e=>e.select),c=s7(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)(""),[b,y]=(0,l.useState)(!1),[w,N]=(0,l.useState)(null),[k,S]=(0,l.useState)(!1),[I,T]=(0,l.useState)(!1),[E,D]=(0,l.useState)(!1),[P,M]=(0,l.useState)("changes"),[L,R]=(0,l.useState)(null),[_,z]=(0,l.useState)(""),O=(0,l.useCallback)(async()=>{if(s)try{let e=await v.F.git.status(s);if(!1===e.isRepo){h(!0),u(null),R(null),x(null);return}u(e),h(!1),x(null);let t=await v.F.git.remotes(s);R(t.remotes)}catch(e){x(e instanceof Error?e.message:String(e))}},[s]);(0,l.useEffect)(()=>{O()},[O]),(0,l.useEffect)(()=>{if(!s)return;let e=null,t=j.on("file:changed",()=>{e&&clearTimeout(e),e=setTimeout(()=>{O()},400)});return()=>{e&&clearTimeout(e),t()}},[s,O]);let B=null!=(e=null==d?void 0:d.files)?e:[],H=B.filter(e=>C(e.index)),K=B.filter(e=>A(e.workingDir));async function G(e){y(!0),N(null);try{await e(),await O()}catch(e){N(e instanceof Error?e.message:String(e))}finally{y(!1)}}let J=(0,l.useCallback)((e,t)=>{i({path:e.path,staged:t,from:e.from})},[i]);function q(e){G(()=>v.F.git.stage(s,e))}function Z(e){G(()=>v.F.git.unstage(s,e))}async function V(){s&&f.trim()&&await G(async()=>{await v.F.git.commit(s,f),g(""),c()})}function Y(){s&&_.trim()&&G(async()=>{await v.F.git.addRemote(s,_.trim()),z("")})}let $=(null!=(t=null==L?void 0:L.length)?t:0)>0;return s?p?(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 bg-[var(--background)] p-6 text-center",children:[(0,n.jsx)(s2.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"max-w-[240px] text-xs text-[var(--muted-foreground)]",children:a("sc.initRepoDesc")}),(0,n.jsxs)("button",{onClick:function(){G(()=>v.F.git.init(s))},disabled:b,className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,n.jsx)(s2.A,{className:"h-3.5 w-3.5"}),a(b?"sc.initializing":"sc.initRepo")]}),w&&(0,n.jsx)("p",{className:"max-w-[240px] text-[11px] text-red-400",children:w})]}):(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,n.jsx)(s3.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:a("nav.sourceControl")}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("div",{className:"flex items-center rounded border border-[var(--border)]",children:[(0,n.jsx)("button",{onClick:()=>M("changes"),title:a("sc.viewChanges"),className:F("rounded-l p-1","changes"===P?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,n.jsx)(s4.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>M("graph"),title:a("sc.viewGraph"),className:F("rounded-r p-1","graph"===P?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,n.jsx)(s8.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("button",{onClick:()=>S(!0),title:a("sc.cred.title"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(Q.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>{O()},title:a("sc.refresh"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(tG.A,{className:F("h-3.5 w-3.5",b&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--border)] px-3 py-1.5",children:[(0,n.jsx)(s3.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,n.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,n.jsxs)("span",{className:"flex items-center gap-1 text-[10px] text-[var(--muted-foreground)]",children:[d.behind>0&&(0,n.jsxs)("span",{className:"flex items-center",children:[(0,n.jsx)(s6.A,{className:"h-3 w-3"}),d.behind]}),d.ahead>0&&(0,n.jsxs)("span",{className:"flex items-center",children:[(0,n.jsx)(ai.A,{className:"h-3 w-3"}),d.ahead]})]}),(0,n.jsx)("div",{className:"flex-1"}),$&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>void G(()=>v.F.git.pull(s)),disabled:b,title:a("sc.pull"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,n.jsx)(s6.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>void G(()=>v.F.git.push(s)),disabled:b,title:a("sc.push"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,n.jsx)(ai.A,{className:"h-3.5 w-3.5"})})]})]}),!$&&"changes"===P&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-[var(--muted-foreground)]",children:[(0,n.jsx)(ah.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,n.jsx)("span",{children:a("sc.addRemoteDesc")})]}),(0,n.jsx)("input",{type:"text",value:_,onChange:e=>z(e.target.value),onKeyDown:e=>{"Enter"===e.key&&_.trim()&&Y()},placeholder:a("sc.remotePlaceholder"),autoComplete:"off",className:"rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 font-mono text-[11px] text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,n.jsxs)("button",{onClick:Y,disabled:b||!_.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,n.jsx)(ah.A,{className:"h-3.5 w-3.5"})," ",a(b?"sc.adding":"sc.addRemote")]})]}),"changes"===P&&(0,n.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,n.jsx)("textarea",{value:f,onChange:e=>g(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),V())},placeholder:a("sc.commitPlaceholder"),rows:2,className:"resize-none rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,n.jsxs)("button",{onClick:()=>void V(),disabled:b||!f.trim()||0===H.length,className:"flex items-center justify-center gap-1.5 rounded bg-[var(--primary)] px-2 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,n.jsx)(t0.A,{className:"h-3.5 w-3.5"})," ",a("sc.commit")]})]}),w&&(0,n.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-red-500/10 px-3 py-2 text-[11px] text-red-400",children:[nx(w)?a("sc.authError"):w,nx(w)&&(0,n.jsx)("button",{onClick:()=>S(!0),className:"ml-1 underline hover:text-red-300",children:a("sc.openCreds")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:"graph"===P?(0,n.jsx)(nm,{projectId:s}):m?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:m}):0===B.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:a("sc.clean")}):(0,n.jsxs)(n.Fragment,{children:[H.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,n.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:[I?(0,n.jsx)(U.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(W.A,{className:"h-3.5 w-3.5"}),a("sc.staged")]}),(0,n.jsx)("button",{onClick:()=>Z(H.map(e=>e.path)),title:a("sc.unstageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,n.jsx)(s9.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:H.length})]}),!I&&(0,n.jsx)(ne,{files:H,group:"staged",selectedPath:(null==o?void 0:o.staged)?o.path:null,onSelect:e=>J(e,!0),onAction:Z})]}),K.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,n.jsxs)("button",{onClick:()=>D(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,n.jsx)(U.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(W.A,{className:"h-3.5 w-3.5"}),a("sc.changes")]}),(0,n.jsx)("button",{onClick:()=>q(K.map(e=>e.path)),title:a("sc.stageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,n.jsx)(rZ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:K.length})]}),!E&&(0,n.jsx)(ne,{files:K,group:"changes",selectedPath:o&&!o.staged?o.path:null,onSelect:e=>J(e,!1),onAction:q})]})]})}),k&&(0,n.jsx)(ns,{projectId:s,onClose:()=>S(!1),onSaved:()=>{}})]}):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] p-6 text-center",children:[(0,n.jsx)(s3.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:a("sc.noWorkspace")})]})}var nh=r(61754);function nf(){let e=(0,tr.useT)(),t=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),r=s7(e=>e.selected),[a,s]=(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 s(null);let e=!1;return i(!0),d(null),v.F.git.diff(t,r.path,r.staged,r.from,r.commit).then(t=>{e||s({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,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,n.jsx)(nh.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"truncate text-xs text-[var(--foreground)]",children:r.path}),(0,n.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,n.jsx)("div",{className:"flex-1 overflow-hidden",children:o?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("sc.loadingDiff")}):c?(0,n.jsx)("div",{className:"px-4 py-3 text-xs text-red-400",children:c}):a?(0,n.jsx)(eB,{original:a.original,modified:a.modified,path:a.path}):null})]}):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] text-center",children:[(0,n.jsx)(nh.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,n.jsx)("p",{className:"mt-2 text-sm text-[var(--muted-foreground)]",children:e("sc.selectFile")})]})}var ng=r(98171),nv=r(96739),nb=r(68213),nj=r(75457),ny=r(20869),nw=r(20273);let nN=["explorer","source-control","sessions","skills","channels","evolution","cron"],nk=null;function nS(e){var t;let{linkState:r}=e,a=(0,tr.useT)(),s=e9(e=>e.activeProject),c=e9(e=>e.openFolder),d=tR(e=>e.isStreaming),u=tR(e=>e.sessionId),[m,x]=(0,l.useState)(()=>localStorage.getItem("halo_sidebar_tab")||"explorer"),[h,f]=(0,l.useState)(()=>"false"!==localStorage.getItem("halo_sidebar_open")),[g,b]=(0,l.useState)(""),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=window.haloPin;e&&e.get().then(S)},[]);let I=(0,l.useCallback)(()=>{let e=window.haloPin;e&&e.toggle().then(S)},[]),E=!!window.haloNotify||"Notification"in window,[D,P]=(0,l.useState)(()=>"true"===localStorage.getItem("halo_notify_on_finish")),M=(0,l.useCallback)(async()=>{let e=!!window.haloNotify;if(!D&&!e&&"Notification"in window){let e=Notification.permission;if("default"===e&&(e=await Notification.requestPermission()),"granted"!==e)return}P(e=>{let t=!e;try{localStorage.setItem("halo_notify_on_finish",String(t))}catch(e){}return t})},[D]),L=(0,l.useRef)(d),z=(0,l.useRef)(u);(0,l.useEffect)(()=>{let e=null==s?void 0:s.name;document.title=e?"".concat(d?"● ":"","Halo — ").concat(e):"Halo";let t=L.current,r=z.current;if(L.current=d,z.current=u,D&&t&&!d&&r===u&&null!=u&&(!function(){try{let e=window.AudioContext||window.webkitAudioContext;if(!e)return;nk||(nk=new e);let t=nk;t.resume();let r=t.currentTime;[[880,0],[1174.66,.15]].forEach(e=>{let[a,s]=e,n=t.createOscillator(),l=t.createGain();n.type="sine",n.frequency.value=a,l.gain.setValueAtTime(1e-4,r+s),l.gain.exponentialRampToValueAtTime(.2,r+s+.02),l.gain.exponentialRampToValueAtTime(1e-4,r+s+.35),n.connect(l).connect(t.destination),n.start(r+s),n.stop(r+s+.4)})}catch(e){}}(),!document.hasFocus())){let t=e?"Halo — ".concat(e):"Halo",r=a("status.notifyBody"),s=window.haloNotify;if(s)s.notify({title:t,body:r});else if("Notification"in window&&"granted"===Notification.permission){let e=new Notification(t,{body:r});e.onclick=()=>{window.focus(),e.close()}}}},[d,u,null==s?void 0:s.name,a,D]),(0,l.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("folder"),t=async(e,t)=>{try{let a=await v.F.fs.resolveWorkspace(e);c(a.path,a.id),b(a.path),y(a.path);try{localStorage.setItem("halo_last_folder",a.path)}catch(e){}var r=a.path;let s=am().filter(e=>e!==r);if(s.unshift(r),ax(s.slice(0,8)),t||a.path!==e){let e=new URL(window.location.href);e.searchParams.set("folder",a.path),window.history.replaceState({},"",e.toString())}}catch(e){return console.error("[Workspace] Failed to resolve workspace:",e),!1}return!0};if(e)t(e,!1);else{let e=(()=>{try{return localStorage.getItem("halo_last_folder")}catch(e){return null}})(),r=()=>v.F.fs.home().then(e=>{let{home:r}=e;return t(r,!0)}).catch(e=>{console.error("[Workspace] Failed to resolve home dir:",e)});e?t(e,!0).then(e=>{e||r()}):r()}},[]),(0,l.useEffect)(()=>{function e(e){e.preventDefault()}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let O=(0,l.useCallback)(()=>{let e=p.getState(),t=e.activeTab;if(!t)return!1;let r=e.tabs.find(e=>e.path===t);return(async()=>{(null==r||!r.modified||await R('"'.concat(r.path.split("/").pop(),'" has unsaved changes. Close anyway?')))&&e.closeTab(t)})(),!0},[]);function W(e){p.getState().maximized&&p.getState().setMaximized(!1),m===e&&h?f(!1):(x(e),f(!0))}async function U(e){let t=e.trim();if(!t)return;try{let e=await v.F.fs.exists(t);if(!e.exists||!e.isDirectory)return void window.alert("Workspace not found: ".concat(t))}catch(e){window.alert(e instanceof Error?e.message:"Failed to validate path");return}try{localStorage.setItem("halo_last_folder",t)}catch(e){}let r=new URL(window.location.href);r.searchParams.set("folder",t),window.location.href=r.toString()}(0,l.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&"p"===e.key&&(e.preventDefault(),N(e=>!e)),(e.metaKey||e.ctrlKey)&&"`"===e.key){e.preventDefault();let t=p.getState();t.setBottomTab("terminal"===t.bottomTab?"chat":"terminal")}!e.altKey||"KeyW"!==e.code||e.metaKey||e.ctrlKey||(e.preventDefault(),O())}return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[O]),(0,l.useEffect)(()=>{let e=window.haloCloseShortcut;e&&e.onTrigger(()=>{O()||e.closeWindow()})},[O]),(0,l.useEffect)(()=>{function e(e){if("Escape"!==e.key||!p.getState().maximized)return;let t=document.activeElement;if(t){let e=t.tagName;if("INPUT"===e||"TEXTAREA"===e||t.isContentEditable||t.closest(".monaco-editor"))return}w||p.getState().setMaximized(!1)}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w]),(0,l.useEffect)(()=>{let e=e=>{let t=e.detail;if(!(null==t?void 0:t.tab))return;let{bottomFloating:r}=p.getState();r&&"explorer"===t.tab||(x(t.tab),f(!0))};return window.addEventListener("halo:navigate",e),()=>window.removeEventListener("halo:navigate",e)},[]),(0,l.useEffect)(()=>{let e=e=>{var t;let r=null==(t=e.detail)?void 0:t.path;r&&U(r)};return window.addEventListener("halo:open-workspace",e),()=>window.removeEventListener("halo:open-workspace",e)},[]),(0,l.useEffect)(()=>{localStorage.setItem("halo_sidebar_tab",m),localStorage.setItem("halo_sidebar_open",String(h))},[m,h]);let B=(0,l.useCallback)(async e=>{let t=null==s?void 0:s.id;if(t){if(p.getState().tabs.find(t=>t.path===e))return void p.getState().setActiveTab(e);try{let r=await v.F.files.read(e,t),a=_(e);p.getState().openFile(e,r.content,a)}catch(e){console.error("[QuickOpen] Failed to read file:",e)}}},[s]),H=[{id:"explorer",icon:ap.A,label:a("nav.explorer")},{id:"source-control",icon:s3.A,label:a("nav.sourceControl")},{id:"sessions",icon:tJ.A,label:a("nav.sessions")},{id:"skills",icon:ab.A,label:"Skills"},{id:"management",icon:tK.A,label:"Agents"},{id:"channels",icon:sa.A,label:a("nav.channels")},{id:"evolution",icon:rf.A,label:"Evolution"},{id:"cron",icon:sq.A,label:"Cron"},{id:"settings",icon:aY.A,label:a("nav.settings"),position:"bottom"}],K=null!=(t=null==s?void 0:s.id)?t:null;(0,l.useEffect)(()=>{if(!K)return;let{setForProject:e,clearProject:t,setRepoStatus:r,clearRepoStatus:a}=T.getState(),s=!1;async function n(){try{let[a,n]=await Promise.all([v.F.git.status(K),v.F.git.ignored(K)]);if(!1===a.isRepo){s||(t(K),r(K,!1));return}s||(e(K,function(e,t){let r=new Map,a=new Map;for(let t of e){var s,n;let e=(s=t.index,A(n=t.workingDir)?"?"===n?"?":n:C(s)?s:"");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("/"),s=a.get(r);void 0===s?a.set(r,e):s!==e&&"*"!==s&&a.set(r,"*")}}return{files:r,dirs:a,ignored:new Set(t)}}(a.files,n.ignored)),r(K,!0))}catch(e){s||(t(K),r(K,!1))}}n();let l=null,o=j.on("file:changed",()=>{l&&clearTimeout(l),l=setTimeout(()=>{n()},400)});return()=>{s=!0,l&&clearTimeout(l),o(),t(K),a(K)}},[K]);let G=T(e=>{var t;return null!=(t=K?e.repoStatus[K]:void 0)?t:"unknown"}),J=H.filter(e=>"bottom"!==e.position).filter(e=>"source-control"!==e.id||!1!==G),q=H.filter(e=>"bottom"===e.position),Z=p(e=>e.maximized),V=p(e=>e.bottomFloating),Y=p(e=>e.bottomMaximized),$=h&&!Z,Q=nN.includes(m)&&h&&"explorer"!==m,X="explorer"===m;(0,l.useEffect)(()=>{!1===G&&"source-control"===m&&x("explorer")},[G,m]);let[ee]=(0,l.useState)(()=>{if("undefined"==typeof document)return null;let e=document.createElement("div");return e.className="h-full",e}),et=(0,l.useRef)(null),[er,ea]=(0,l.useState)(null),[es,en]=(0,l.useState)(null),[el,eo]=(0,l.useState)(null),ei=V?el:Y?es:er;return(0,l.useLayoutEffect)(()=>{ee&&ei&&ee.parentElement!==ei&&ei.appendChild(ee)},[ee,ei]),(0,n.jsxs)("div",{className:"flex h-full",children:[(0,n.jsxs)("div",{className:F("flex w-12 shrink-0 flex-col items-center border-r border-[var(--border)] bg-[var(--card)] py-2",Z&&"hidden"),children:[J.map(e=>{let t=e.icon,r=m===e.id;return(0,n.jsxs)("button",{onClick:()=>W(e.id),title:e.label,className:F("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,n.jsx)("div",{className:"absolute left-0 top-1/2 h-6 w-0.5 -translate-y-1/2 rounded-r bg-[var(--primary)]"}),(0,n.jsx)(t,{className:"h-5 w-5"})]},e.id)}),(0,n.jsx)("div",{className:"flex-1"}),q.map(e=>{let t=e.icon,r=m===e.id;return(0,n.jsxs)("button",{onClick:()=>W(e.id),title:e.label,className:F("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,n.jsx)("div",{className:"absolute left-0 top-1/2 h-6 w-0.5 -translate-y-1/2 rounded-r bg-[var(--primary)]"}),(0,n.jsx)(t,{className:"h-5 w-5"})]},e.id)}),null!==k&&(0,n.jsx)("button",{onClick:I,title:k?a("workspace.unpin"):a("workspace.pin"),className:F("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",k?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:k?(0,n.jsx)(ng.A,{className:"h-5 w-5"}):(0,n.jsx)(nv.A,{className:"h-5 w-5"})}),E&&(0,n.jsx)("button",{onClick:M,title:D?a("workspace.notifyOn"):a("workspace.notifyOff"),className:F("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",D?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:D?(0,n.jsx)(nb.A,{className:"h-5 w-5"}):(0,n.jsx)(nj.A,{className:"h-5 w-5"})}),(0,n.jsx)("div",{className:"pb-2",title:a("link.".concat(r)),children:"fresh"===r?(0,n.jsx)(ny.A,{className:"h-4 w-4 text-emerald-400"}):"stale"===r?(0,n.jsx)(ny.A,{className:"h-4 w-4 text-amber-400 animate-pulse"}):(0,n.jsx)(nw.A,{className:"h-4 w-4 text-[var(--destructive)]"})})]}),(0,n.jsx)("div",{className:F("flex min-w-0 flex-1",!X&&"hidden",Z&&"fixed inset-0 z-40 bg-[var(--background)]"),children:(0,n.jsx)(nC,{showSidebar:$,sidebar:(0,n.jsx)(af,{projectId:K,pathInput:g,onPathInputChange:b,onOpenFolder:function(){U(g)},onOpenPath:U,activeProject:s}),main:(0,n.jsx)(nA,{projectId:K,showBottom:!V&&!Z,bottomSlotRef:ea})})}),!X&&!Z&&(Q?(0,n.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:"halo-h-sidebar",className:"flex-1",children:[(0,n.jsx)(i.Zk,{defaultSize:22,minSize:15,maxSize:40,children:(0,n.jsxs)("div",{className:"h-full overflow-hidden",children:["source-control"===m&&(0,n.jsx)(np,{}),"sessions"===m&&(0,n.jsx)(tX,{}),"skills"===m&&(0,n.jsx)(aA,{}),"channels"===m&&(0,n.jsx)(sI,{}),"evolution"===m&&(0,n.jsx)(sW,{}),"cron"===m&&(0,n.jsx)(s5,{})]})}),(0,n.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,n.jsx)(i.Zk,{defaultSize:78,minSize:40,children:(0,n.jsx)(nI,{activeTab:m})})]}):(0,n.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,n.jsx)(nI,{activeTab:m})})),w&&(0,n.jsx)(ao,{onSelect:B,onClose:()=>N(!1)}),V&&(0,n.jsx)(as,{slotRef:eo,dragHandleRef:et}),Y&&!V&&(0,n.jsx)("div",{ref:en,className:"fixed inset-0 z-50 bg-[var(--background)]"}),ee&&(0,o.createPortal)((0,n.jsx)(ar,{floating:V,dragHandleRef:et}),ee)]})}function nC(e){let{showSidebar:t,sidebar:r,main:a}=e,s=(0,l.useRef)(null),o=(0,l.useRef)([22,78]);return(0,l.useEffect)(()=>{let e=s.current;if(e)if(t)e.setLayout(o.current);else{let t=e.getLayout();t[0]>0&&(o.current=t),e.setLayout([0,100])}},[t]),(0,n.jsxs)(i.YZ,{ref:s,direction:"horizontal",autoSaveId:"halo-h-sidebar",className:"flex-1",children:[(0,n.jsx)(i.Zk,{defaultSize:22,minSize:0,maxSize:40,collapsible:!0,children:(0,n.jsx)("div",{className:F("h-full overflow-hidden",!t&&"hidden"),children:r})}),(0,n.jsx)(i.TW,{className:F("w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors",!t&&"pointer-events-none opacity-0")}),(0,n.jsx)(i.Zk,{defaultSize:78,minSize:40,children:a})]})}function nA(e){let{projectId:t,showBottom:r,bottomSlotRef:a}=e,s=(0,l.useRef)(null),o=(0,l.useRef)([65,35]);return(0,l.useEffect)(()=>{let e=s.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,n.jsxs)(i.YZ,{ref:s,direction:"vertical",autoSaveId:"halo-v-editor",className:"h-full",children:[(0,n.jsx)(i.Zk,{defaultSize:65,minSize:20,children:(0,n.jsx)(tl,{projectId:t,mode:"editor-only"})}),(0,n.jsx)(i.TW,{className:F("h-px bg-[var(--border)] hover:h-1 hover:bg-[var(--primary)] transition-colors",!r&&"pointer-events-none opacity-0")}),(0,n.jsx)(i.Zk,{defaultSize:35,minSize:0,collapsible:!0,children:(0,n.jsx)("div",{ref:a,className:F("h-full",!r&&"hidden")})})]})}function nI(e){let{activeTab:t}=e;return"source-control"===t?(0,n.jsx)(nf,{}):"sessions"===t?(0,n.jsx)(aV,{}):"management"===t?(0,n.jsx)(aK,{}):"skills"===t?(0,n.jsx)(aJ,{}):"channels"===t?(0,n.jsx)(sT,{}):"evolution"===t?(0,n.jsx)(sF,{}):"cron"===t?(0,n.jsx)(sY,{}):"settings"===t?(0,n.jsx)(a0,{}):null}let nT=/<<<CAPTURE>>>/,nE=/<<<SHOW:([\s\S]*?)>>>/g,nD=new Set,nF=new Set;async function nP(e){let t=tR.getState(),r=window,a=t.captureSource;if(!a)return;let s="camera"===a.kind;if(!(s?r.haloCamera:r.haloCapture))return;let n=[...t.messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!n||nD.has(n.id)||!nT.test(n.content))return;nD.add(n.id);let l=e9.getState().activeProject,o=t.sessionId;if(!l||!o)return;let i=P(),c="image/jpeg",d=null;try{d=s?await r.haloCamera.snap(a.id||void 0):await r.haloCapture.grab(a.id)}catch(e){d=null}let u=s?"[\uD83D\uDCF7 ".concat(a.name," — 拍照失败:摄像头可能被其他应用占用或权限被关闭]"):"[\uD83D\uDCF7 ".concat(a.name," — 截图失败:该窗口在后台太久被系统回收了画面,切到它再让我截一次]"),m=s?"[Could not take a photo from the camera — it may be in use by another app, or camera permission was revoked. Ask the user to check, then request the capture again.]":'[Could not capture "'.concat(a.name,'" — it was likely occluded/minimized long enough that macOS purged its rendered frame (came back blank/black). Ask the user to briefly bring that window to the foreground, then request the capture again.]');t.addMessage({id:P(),role:"user",content:d?"[\uD83D\uDCF7 ".concat(a.name,"]"):u,timestamp:Date.now(),clientMsgId:i,...d?{localImages:["data:".concat(c,";base64,").concat(d)]}:{}}),t.addMessage({id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let x=t.selectedAgentId;e.send({type:"chat",sessionId:o,projectId:l.id,message:d?s?"[Photo from the camera]":'[Screenshot of "'.concat(a.name,'"]'):m,clientMsgId:i,..."default"!==x?{agentId:x}:{},...d?{images:[{data:d,mimeType:c}]}:{}})}let nM=(0,c.v)(e=>({activePlan:null,agents:[],agentConfigs:[],setActivePlan(t){e({activePlan:t})},updateTaskStatus(t,r){e(e=>{if(!e.activePlan)return e;let a=e.activePlan.tasks.map(e=>e.id===t?{...e,status:r}:e);return{activePlan:{...e.activePlan,tasks:a}}})},setAgents(t){e({agents:t})},updateAgentState(t,r){e(e=>({agents:e.agents.map(e=>e.agentId===t?{...e,state:r}:e)}))},setAgentConfigs(t){e({agentConfigs:t})},clearPlan(){e({activePlan:null})}}));function nL(e){let{onSuccess:t}=e,[r,a]=(0,l.useState)(""),[s,o]=(0,l.useState)(""),[i,c]=(0,l.useState)(!1),d=(0,l.useCallback)(async e=>{if(e.preventDefault(),r.trim()){c(!0),o("");try{(await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r.trim()}),credentials:"include"})).ok?t():(o("Incorrect password"),a(""))}catch(e){o("Connection failed")}finally{c(!1)}}},[r,t]);return(0,n.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,n.jsxs)("div",{className:"w-full max-w-sm px-6",children:[(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-xl bg-[var(--secondary)]",children:(0,n.jsx)(nr.A,{className:"h-7 w-7 text-[var(--foreground)]"})}),(0,n.jsx)("h1",{className:"text-xl font-semibold text-[var(--foreground)]",children:"Halo"}),(0,n.jsx)("p",{className:"mt-1 text-sm text-[var(--muted-foreground)]",children:"Enter password to access workspace"})]}),(0,n.jsxs)("form",{onSubmit:d,className:"mt-8",children:[(0,n.jsx)("input",{type:"password",value:r,onChange:e=>a(e.target.value),placeholder:"Password",autoFocus:!0,className:"w-full rounded-md border border-[var(--border)] bg-[var(--secondary)] px-3 py-2.5 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)] focus:ring-1 focus:ring-[var(--primary)]"}),s&&(0,n.jsx)("p",{className:"mt-2 text-xs text-red-400",children:s}),(0,n.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 nR(){let{linkState:e}=function(){let[e,t]=(0,l.useState)(!1),[r,a]=(0,l.useState)("down"),s=(0,l.useRef)(!1),n=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.id}),o=(0,l.useRef)(void 0);return(0,l.useEffect)(()=>{var t;if(!e||!n)return;if(void 0===o.current){o.current=n;return}if(o.current===n)return;o.current=n;let r=null!=(t=tR.getState().sessionId)?t:"";j.send({type:"subscribe",sessionId:r,projectId:n})},[e,n]),(0,l.useEffect)(()=>{if(s.current)return;s.current=!0,j.connect();let e=[j.on("_connected",()=>{t(!0),a("fresh");let e=tR.getState().sessionId,r=e9.getState().activeProject;(null==r?void 0:r.id)&&j.send({type:"subscribe",sessionId:null!=e?e:"",projectId:r.id})}),j.on("_disconnected",()=>{t(!1),a("down")}),function(e){let t=[];t.push(e.on("_chat_send_failed",e=>{e.clientMsgId&&tR.getState().markChatSendFailed(e.clientMsgId)})),t.push(e.on("_disconnected",()=>void(tP=Date.now())));let r=setInterval(()=>{tR.getState().convergeStaleStreaming()},5e3);t.push(()=>clearInterval(r)),t.push(e.on("chat:thinking",e=>{tR.getState().appendThinking(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:stream",e=>{tR.getState().updateLastAssistant(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:complete",t=>{let r=tR.getState();t.text&&r.updateLastAssistant(t.text),r.completeAgentStreaming(),nP(e),function(){let e=[...tR.getState().messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!e)return;let t=0;for(let r of e.content.matchAll(nE)){let a="".concat(e.id,"#").concat(t++);if(nF.has(a))continue;nF.add(a);let s=r[1].trim();s&&eW(s)}}()})),t.push(e.on("chat:stopped",()=>{tR.getState().completeAgentStreaming()})),t.push(e.on("error",e=>{let t=tR.getState(),r=e.error?"Error: ".concat(e.error):"An unknown error occurred.";t.addMessage({id:P(),role:"system",content:r,timestamp:Date.now(),agentName:e.agentName}),e.taskId||t.completeAgentStreaming(e.agentName)})),t.push(e.on("chat:followup",e=>{let t=tR.getState();if(e.replay){var r;let a=(r=t.sessionId,tM&&r&&tM.sessionId===r?tM.messages:null);a?t.setMessages(a):t.completeAgentStreaming(e.agentName)}else t.completeAgentStreaming(e.agentName);t.addMessage({id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName})})),t.push(e.on("chat:user",e=>{tR.getState().addMessage({id:P(),role:"user",content:e.text,timestamp:Date.now()})})),t.push(e.on("chat:usage",e=>{let t=tR.getState();t.setTokenUsage(e.contextTokens,e.outputTokens),e.usage&&t.addMessage({type:"usage",role:"system",content:"[Usage] in=".concat(e.usage.inputTokens," out=").concat(e.usage.outputTokens," cache=").concat(e.usage.cacheReadInputTokens),usage:e.usage,turnId:e.turnId,modelId:e.modelId})})),t.push(e.on("session:cleared",()=>{let e=tR.getState();(e.messages.length>0||e.sessionId)&&e.clear()})),t.push(e.on("session:switched",t=>{if(!t.sessionId)return;let r=e9.getState().activeProject;if(r)try{localStorage.setItem("halo_session_".concat(r.id),t.sessionId)}catch(e){}let a=tR.getState();a.clear(),a.setSessionId(t.sessionId),r&&e.send({type:"subscribe",sessionId:t.sessionId,projectId:r.id})})),t.push(e.on("session:compacted",e=>{var t,r;let a=null!=(t=e.message)?t:"Context compacted",s=tR.getState();s.setCompacting(!1),n(),s.setTokenUsage(null!=(r=e.contextTokens)?r:0,s.outputTokens),s.addMessage({id:P(),role:"system",content:a,timestamp:Date.now()})}));let a=null;function s(){a&&clearTimeout(a),a=setTimeout(()=>{tR.getState().setCompacting(!1),a=null},6e4)}function n(){a&&(clearTimeout(a),a=null)}for(let r of(t.push(e.on("chat:system",e=>{let t=e.text;if(!e.taskId){let e=t.match(/^Compacting context \((\d+)K tokens\)…$/);if(e&&(tR.getState().setCompacting(!0),s(),"0"===e[1])){let e=tR.getState().contextTokens;e>0&&(t="Compacting context (~".concat(Math.round(e/1e3),"K tokens)…"))}}tR.getState().addMessage({id:P(),role:"system",content:t,timestamp:Date.now(),taskId:e.taskId,agentName:e.agentName})})),t.push(e.on("chat:queued",e=>{var t;tR.getState().addMessage({id:P(),role:"system",content:null!=(t=e.message)?t:"Message queued.",timestamp:Date.now()})})),["compact:progress","compact:started","compact:summarizing"]))t.push(e.on(r,()=>{tR.getState().setCompacting(!0),s()}));return t.push(e.on("compact:done",()=>{tR.getState().setCompacting(!1),n()})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("agent:start",e=>{tR.getState().addMessage({id:P(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName,taskId:e.taskId})})),t.push(e.on("agent:done",e=>{tR.getState().completeAgentStreaming(e.agentName,e.taskId)})),t.push(e.on("agent:context",e=>{var t;tR.getState().addMessage({id:P(),role:"system",content:"[System Prompt: ".concat(null!=(t=e.agentName)?t:"Agent","]"),timestamp:Date.now(),agentName:e.agentName,taskId:e.taskId,systemPrompt:e.systemPrompt})})),t.push(e.on("agent:tool_call",e=>{var t,r;let a=null!=(t=e.agentName)?t:"default",s="string"==typeof e.input?e.input:JSON.stringify(null!=(r=e.input)?r:{});tR.getState().addToolCallToLastAssistant({name:e.tool,input:s,toolUseId:e.toolUseId},a,e.taskId,e.turnId)})),t.push(e.on("agent:tool_result",e=>{var t,r;let a=null!=(t=e.agentName)?t:"default",s="string"==typeof e.result?e.result:JSON.stringify(null!=(r=e.result)?r:"");tR.getState().updateLastToolCallResult(s,a,e.taskId,e.toolUseId)})),t.push(e.on("agent:configs",e=>{nM.getState().setAgentConfigs(e.agents)})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("task:plan",e=>{tR.getState().addMessage({id:P(),role:"assistant",content:"Task plan created: ".concat(e.plan.description),timestamp:Date.now(),plan:e.plan}),nM.getState().setActivePlan(e.plan)})),t.push(e.on("task:status",e=>{nM.getState().updateTaskStatus(e.taskId,e.status)})),t.push(e.on("plan:complete",e=>{tR.getState().addMessage({id:P(),role:"system",content:"Plan completed: ".concat(e.summary),timestamp:Date.now()}),tR.getState().completeStreaming()})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("file:changed",e=>{let t=p.getState();"add"===e.action||"addDir"===e.action?t.insertFileNode(e.path,"addDir"===e.action?"directory":"file"):("unlink"===e.action||"unlinkDir"===e.action)&&t.removeFileNode(e.path)})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("state:snapshot",e=>{var t;let{snapshot:r}=e;r.sessionId&&tR.getState().setSessionId(r.sessionId),r.agentId&&tR.getState().setSelectedAgentId(r.agentId);let a=tR.getState().messages.some(e=>e.streaming&&!tF(e)),s=null!=(t=r.recentMessages)?t:r.messages;s&&r.sessionId&&(tM={sessionId:r.sessionId,messages:s}),a?console.debug("[state-handlers] skipping snapshot replace — streaming in flight"):s&&s.length>0&&tR.getState().setMessages(s),r.activePlan&&nM.getState().setActivePlan(r.activePlan),r.agents&&nM.getState().setAgentConfigs(r.agents),"number"==typeof r.maxContextTokens&&r.maxContextTokens>0&&tR.getState().setMaxContextTokens(r.maxContextTokens)})),t.push(e.on("session:changed",()=>tz())),t.push(e.on("goal:changed",()=>{var e;let t=null==(e=e9.getState().activeProject)?void 0:e.path;t&&rk(t),tz()})),()=>t.forEach(e=>e())}(j)],r=()=>j.reconnectIfStale(0);window.addEventListener("online",r);let n=0,l=()=>{if(document.hidden){n=Date.now();return}n>0&&Date.now()-n>=3e5&&j.reconnectIfStale(45e3),n=0};document.addEventListener("visibilitychange",l);let o=setInterval(()=>{a(j.connected?j.lastReceiveAgeMs>45e3?"stale":"fresh":"down")},5e3);return()=>{e.forEach(e=>e()),window.removeEventListener("online",r),document.removeEventListener("visibilitychange",l),clearInterval(o),j.disconnect(),s.current=!1}},[]),{connected:e,linkState:r,send:(0,l.useCallback)(e=>{j.send(e)},[])}}(),[t,r]=(0,l.useState)("checking");(0,l.useEffect)(()=>{fetch("/api/auth/check",{credentials:"include"}).then(e=>{r(e.ok?"authenticated":"login")}).catch(()=>{r("login")})},[]),(0,l.useEffect)(()=>j.on("_auth_expired",()=>{r("login")}),[]);let a=(0,l.useCallback)(()=>{r("authenticated"),window.location.reload()},[]);return"checking"===t?(0,n.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,n.jsx)("div",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading..."})}):"login"===t?(0,n.jsx)(nL,{onSuccess:a}):(0,n.jsx)("div",{className:"h-screen w-screen overflow-hidden bg-[var(--background)]",children:(0,n.jsx)(nS,{linkState:e})})}}},e=>{e.O(0,[372,560,397,212,489,635,358],()=>e(e.s=46601)),_N_E=e.O()}]);