@turmind/halo 1.2.0 → 1.3.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 (73) hide show
  1. package/admin-out/404.html +1 -1
  2. package/admin-out/_next/static/{SiIebna28lHobsJ4LTUOT → Z6KkY5u-XmAPBuUfiAvaG}/_buildManifest.js +1 -1
  3. package/admin-out/_next/static/chunks/132-29179dca2ef093ce.js +1 -0
  4. package/admin-out/_next/static/chunks/{330.3b784cf0dcd69163.js → 170.14d53d7f32df020c.js} +1 -1
  5. package/admin-out/_next/static/chunks/187.9e822f6f0d366d9a.js +1 -0
  6. package/admin-out/_next/static/chunks/188.0cc6998eb0ed3519.js +1 -0
  7. package/admin-out/_next/static/chunks/{1d2d5650-810a3ca1ae20cab5.js → 1d2d5650-f5c38b9df5ca7466.js} +1 -1
  8. package/admin-out/_next/static/chunks/{304eda7d.b1ee7f523653e027.js → 304eda7d.662c3a1a7cd50701.js} +1 -1
  9. package/admin-out/_next/static/chunks/311.3cfaf322ec2a9170.js +1 -0
  10. package/admin-out/_next/static/chunks/401.c5e64882d4305a08.js +1 -0
  11. package/admin-out/_next/static/chunks/{443.d1b289781793f8de.js → 444.c191bedee971e484.js} +1 -1
  12. package/admin-out/_next/static/chunks/496.7997fc6558c88c22.js +1 -0
  13. package/admin-out/_next/static/chunks/530.03c0a6ec971d3528.js +1 -0
  14. package/admin-out/_next/static/chunks/540.a663b46781b2c309.js +1 -0
  15. package/admin-out/_next/static/chunks/556.10e21b9f7b45d412.js +1 -0
  16. package/admin-out/_next/static/chunks/813-9056b8ef0984bee6.js +1 -0
  17. package/admin-out/_next/static/chunks/{533.5f2d4bfe3d076095.js → 841.48a39cec2ef962f3.js} +1 -1
  18. package/admin-out/_next/static/chunks/891.cfe754015339e975.js +1 -0
  19. package/admin-out/_next/static/chunks/915.c6ee9ab9bee0ce9b.js +1 -0
  20. package/admin-out/_next/static/chunks/957-48c734b74e5437a8.js +1 -0
  21. package/admin-out/_next/static/chunks/968.1676baa9449dbd9d.js +1 -0
  22. package/admin-out/_next/static/chunks/app/_not-found/page-2ea4ee5eada04f69.js +1 -0
  23. package/admin-out/_next/static/chunks/app/layout-1853d21b0644f5a1.js +1 -0
  24. package/admin-out/_next/static/chunks/app/page-2ab109c9a25f867e.js +1 -0
  25. package/admin-out/_next/static/chunks/db534642.a148101e95a7d317.js +1 -0
  26. package/admin-out/_next/static/chunks/e3080c2c-fbf81b7cad547976.js +1 -0
  27. package/admin-out/_next/static/chunks/framework-67e5f0af3ea64f2b.js +1 -0
  28. package/admin-out/_next/static/chunks/main-6b28974253a3bc7c.js +1 -0
  29. package/admin-out/_next/static/chunks/main-app-3367dd99b8642c55.js +1 -0
  30. package/admin-out/_next/static/chunks/pages/_app-51a53534a0a4a898.js +1 -0
  31. package/admin-out/_next/static/chunks/pages/_error-dfd19566fa6f79ad.js +1 -0
  32. package/admin-out/_next/static/chunks/webpack-bf41edfde9cdefec.js +1 -0
  33. package/admin-out/index.html +1 -1
  34. package/admin-out/index.txt +13 -13
  35. package/bundled-docs/design/agentcore.md +9 -0
  36. package/bundled-docs/design/goal-mode.md +1 -1
  37. package/bundled-docs/design/observability.md +212 -0
  38. package/bundled-docs/design/relay.md +52 -0
  39. package/bundled-docs/design/session.md +12 -4
  40. package/bundled-docs/design/storage.md +8 -1
  41. package/bundled-docs/dev/api.md +9 -0
  42. package/bundled-docs/dev/deploy.md +23 -1
  43. package/bundled-docs/dev/env.md +4 -0
  44. package/bundled-docs/dev/tools.md +85 -6
  45. package/bundled-docs/guide/workspace.md +1 -0
  46. package/dist/index.js +520 -59
  47. package/package.json +12 -1
  48. package/admin-out/_next/static/chunks/133-e2df20fc6362a02b.js +0 -1
  49. package/admin-out/_next/static/chunks/200.dd28be896c7765de.js +0 -1
  50. package/admin-out/_next/static/chunks/220.e5a2532bda77e816.js +0 -1
  51. package/admin-out/_next/static/chunks/438-866a1a20e9efa78a.js +0 -1
  52. package/admin-out/_next/static/chunks/442.14eec8e615cc727b.js +0 -1
  53. package/admin-out/_next/static/chunks/515.b793a7455c5e8342.js +0 -1
  54. package/admin-out/_next/static/chunks/525.fe35ab8501121729.js +0 -1
  55. package/admin-out/_next/static/chunks/579.3ab0b2bb9244fc37.js +0 -1
  56. package/admin-out/_next/static/chunks/635-d7fd95bff8674116.js +0 -1
  57. package/admin-out/_next/static/chunks/65.3aac567c42cec99c.js +0 -1
  58. package/admin-out/_next/static/chunks/688.4e014ac6cfc7e152.js +0 -1
  59. package/admin-out/_next/static/chunks/868.0c95dfe283400a00.js +0 -1
  60. package/admin-out/_next/static/chunks/896.2069ab525ef81643.js +0 -1
  61. package/admin-out/_next/static/chunks/935.91ddb965b44041c9.js +0 -1
  62. package/admin-out/_next/static/chunks/app/_not-found/page-8e35399c8fd5016d.js +0 -1
  63. package/admin-out/_next/static/chunks/app/layout-e75df4cae90cf325.js +0 -1
  64. package/admin-out/_next/static/chunks/app/page-ca15438e8bddb403.js +0 -1
  65. package/admin-out/_next/static/chunks/db534642.09d3c650ff587175.js +0 -1
  66. package/admin-out/_next/static/chunks/fb4ec4d6-3fa44f69484f91b9.js +0 -1
  67. package/admin-out/_next/static/chunks/framework-c3031ae54a63fe16.js +0 -1
  68. package/admin-out/_next/static/chunks/main-14b48e3c2588354f.js +0 -1
  69. package/admin-out/_next/static/chunks/main-app-483b436873410ddc.js +0 -1
  70. package/admin-out/_next/static/chunks/pages/_app-b2fc6e5f920d1b1a.js +0 -1
  71. package/admin-out/_next/static/chunks/pages/_error-f3696a8f3d67d150.js +0 -1
  72. package/admin-out/_next/static/chunks/webpack-f80c9b8cca4447a3.js +0 -1
  73. /package/admin-out/_next/static/{SiIebna28lHobsJ4LTUOT → Z6KkY5u-XmAPBuUfiAvaG}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{12161:(e,t,r)=>{"use strict";r.d(t,{kj:()=>a.useT,pZ:()=>s.LanguageSelect,s9:()=>a.useI18n});var a=r(8808);r(38045);var s=r(87826);r(91008)},46601:(e,t,r)=>{Promise.resolve().then(r.bind(r,98293))},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})))}},98293:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>ly});var a,s,n=r(69625),l=r(43853),o=r(52992),i=r(10842),c=r(48476),d=r(70812);function u(e,t){return"".concat(null!=e?e:"","/").concat(t)}function m(e,t){let r=d.wG.__getMonacoInstance();if(r)for(let s of t){var a;null==(a=r.editor.getModel(r.Uri.parse(u(e,s))))||a.dispose()}}let x=1;function p(){return"g".concat(x++)}function h(e){let t=e.groups[e.activeGroupIdx];if(!t)return{tabs:[],activeTab:null};let r=[];for(let a of t.tabs){let t=e.buffers[a];t&&r.push(t)}return{tabs:r,activeTab:t.activeTab}}function f(e,t){let r={...e,children:e.children&&[...e.children]},a=r,s=0;for(let e of t){if(!a.children)break;let t=a.children.findIndex(t=>t.name===e&&"directory"===t.type);if(-1===t)break;let r={...a.children[t]};r.children&&(r.children=[...r.children]),a.children[t]=r,a=r,s++}return{root:r,node:a,depth:s}}function g(){return(0,c.v)((e,t)=>({buffers:{},groups:[{id:p(),tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modelPathPrefix:null,setModelPathPrefix(r){t().modelPathPrefix!==r&&e({modelPathPrefix:r})},fileTree:null,modifiedPaths:new Set,rejectedFile:null,bottomTab:"chat",maximized:"true"===localStorage.getItem("halo_editor_maximized"),bottomFloating:"true"===sessionStorage.getItem("halo_bottom_floating"),bottomMaximized:!1,bottomFloatRect:(()=>{let e=sessionStorage.getItem("halo_bottom_float_rect");if(e)try{return JSON.parse(e)}catch(e){}return{x:Math.max(0,window.innerWidth-480-24),y:Math.max(0,window.innerHeight-640-24),w:480,h:640}})(),selectedText:null,selectedRange:null,contextEnabled:"false"!==localStorage.getItem("halo_context_enabled"),setSelectedText(t,r){e({selectedText:t||null,selectedRange:null!=r?r:null})},setContextEnabled(t){e({contextEnabled:t}),localStorage.setItem("halo_context_enabled",String(t))},openFile(t,r,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,...h(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,tooLarge:null==s?void 0:s.tooLarge},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,...h(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,...h(u)}})},closeTab(r){e(e=>{let t=e.groups.map(e=>{if(!e.tabs.includes(r))return e;let t=e.tabs.filter(e=>e!==r),a=e.activeTab;if(a===r){var s;a=null!=(s=t[Math.min(e.tabs.indexOf(r),t.length-1)])?s:null}return{...e,tabs:t,activeTab:a}}),a=t.some(e=>e.tabs.includes(r)),s=a?e.buffers:(()=>{let{[r]:t,...a}=e.buffers;return a})(),n=a?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(r))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(r),t})(),l=t.length>1&&0===t[1].tabs.length?{groups:[t[0]],activeGroupIdx:0}:{groups:t,activeGroupIdx:Math.min(e.activeGroupIdx,t.length-1)},o={...e,buffers:s,modifiedPaths:n,...l};return{buffers:s,modifiedPaths:n,...l,...h(o)}});let a=t();a.buffers[r]||m(a.modelPathPrefix,[r])},closeTabIn(r,a){e(e=>{if(r<0||r>=e.groups.length)return e;let t=e.groups[r];if(!t.tabs.includes(a))return e;let s=t.tabs.filter(e=>e!==a),n=t.activeTab;if(n===a){var l;n=null!=(l=s[Math.min(t.tabs.indexOf(a),s.length-1)])?l:null}let o=e.groups.map((e,t)=>t===r?{...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(a)),d=c?e.buffers:(()=>{let{[a]:t,...r}=e.buffers;return r})(),u=c?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(a))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(a),t})(),m={...e,groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u};return{groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u,...h(m)}});let s=t();s.buffers[a]||m(s.modelPathPrefix,[a])},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,...h(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,...h(o)}})},setActiveGroup(t){e(e=>{if(t<0||t>=e.groups.length||t===e.activeGroupIdx)return e;let r={...e,activeGroupIdx:t};return{activeGroupIdx:t,...h(r)}})},splitToRight(t){e(e=>{var r,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:p(),tabs:[s],activeTab:s},l=[e.groups[0],n],o={...e,groups:l,activeGroupIdx:1};return{groups:l,activeGroupIdx:1,...h(o)}})},closeGroup(r){let a=[];e(e=>{if(e.groups.length<=1||r<0||r>=e.groups.length)return e;let t=e.groups.filter((e,t)=>t!==r),s=new Set;for(let e of t)for(let t of e.tabs)s.add(t);let n={};for(let[t,r]of Object.entries(e.buffers))s.has(t)?n[t]=r:a.push(t);let l=new Set;for(let t of e.modifiedPaths)s.has(t)&&l.add(t);let o=Math.max(0,Math.min(e.activeGroupIdx,t.length-1)),i={...e,groups:t,activeGroupIdx:o,buffers:n,modifiedPaths:l};return{groups:t,activeGroupIdx:o,buffers:n,modifiedPaths:l,...h(i)}}),a.length>0&&m(t().modelPathPrefix,a)},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,...h(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:p(),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 u={...e,groups:c,activeGroupIdx:d};return{groups:c,activeGroupIdx:d,...h(u)}})},setFileTree(t){e({fileTree:t})},setDirChildren(t,r){e(e=>{if(!e.fileTree)return e;let a=t.split("/").filter(Boolean),{root:s,node:n,depth:l}=f(e.fileTree,a);if(l<a.length)return e;let o=[...r].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name));return n.children=o,n.hasChildren=o.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,...h(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,...h(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,...h(l)}})},setRejectedFile(t){e({rejectedFile:t})},setBottomTab(t){e({bottomTab:t})},pendingTerminalCwd:null,requestTerminalSpawn(t){e({pendingTerminalCwd:t})},consumeTerminalSpawn(){let r=t().pendingTerminalCwd;return null!=r&&e({pendingTerminalCwd:null}),r},toggleMaximized(){e(e=>{let t=!e.maximized;return localStorage.setItem("halo_editor_maximized",String(t)),{maximized:t}})},setMaximized(t){localStorage.setItem("halo_editor_maximized",String(t)),e({maximized:t})},setBottomFloating(t){sessionStorage.setItem("halo_bottom_floating",String(t)),e({bottomFloating:t})},setBottomMaximized(t){e({bottomMaximized:t})},setBottomFloatRect(t){sessionStorage.setItem("halo_bottom_float_rect",JSON.stringify(t)),e({bottomFloatRect:t})},insertFileNode(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"file";e(e=>{if(!e.fileTree)return e;let a=t.split("/").filter(Boolean);if(0===a.length)return e;let s=a.slice(0,-1),{root:n,node:l,depth:o}=f(e.fileTree,s);if(o<s.length||void 0===l.children)return void 0===l.children&&!0!==l.hasChildren?(l.hasChildren=!0,{fileTree:n}):e;let i=a[a.length-1];if(l.children.some(e=>e.name===i))return e;let c="directory"===r?{name:i,path:t,type:"directory",hasChildren:!1,children:[]}:{name:i,path:t,type:"file"};return l.children.push(c),l.children.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),{fileTree:n}})},removeFileNode(t){e(e=>{if(!e.fileTree)return e;let r=t.split("/").filter(Boolean);if(0===r.length)return e;let a=r.slice(0,-1),{root:s,node:n,depth:l}=f(e.fileTree,a);if(l<a.length||!n.children)return e;let o=r[r.length-1],i=n.children.findIndex(e=>e.name===o);return -1===i?e:(n.children.splice(i,1),{fileTree:s})})},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||s.modified)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,...h(o)}}),!0}}))}let v=g(),b=(0,l.createContext)(null);function j(e){let{children:t}=e,r=(0,l.useRef)(null);return r.current||(r.current=g()),(0,l.useEffect)(()=>{let e=r.current;return()=>{let t=e.getState();m(t.modelPathPrefix,Object.keys(t.buffers))}},[]),(0,l.createElement)(b.Provider,{value:r.current},t)}function y(){let e=(0,l.useContext)(b);return null!=e?e:v}var w=r(17246);class N{connect(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING){this.url=null!=e?e:this.getDefaultUrl(),this.intentionalClose=!1,this.connectStartedAt=Date.now(),this.startLiveness();try{let e=!1;this.ws=new WebSocket(this.url),this.ws.onopen=()=>{for(let t of(e=!0,this.reconnectDelay=1e3,this.lastReceiveTs=Date.now(),this.lastProbeTs=0,this.missedProbes=0,this.pendingQueue))this.ws.send(JSON.stringify(t));for(let[e,t]of(this.pendingQueue=[],this.pendingAcks))this.transmitChat(e,t);this.emit("_connected",{})},this.ws.onmessage=e=>{this.lastReceiveTs=Date.now();try{let t=JSON.parse(e.data),r=t.type;"chat:ack"===r&&this.resolveAck(t.clientMsgId),r&&this.emit(r,t)}catch(e){console.error("[WsClient] Failed to parse message:",e)}},this.ws.onclose=()=>{this.ws=null,this.emit("_disconnected",{}),this.intentionalClose||(e?this.reconnect():this.checkAuthThenReconnect())},this.ws.onerror=e=>{console.error("[WsClient] Error:",e)}}catch(e){console.error("[WsClient] Failed to connect:",e),this.reconnect()}}}disconnect(){for(let e of(this.intentionalClose=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopLiveness(),this.pendingAcks.values()))e.ackTimer&&clearTimeout(e.ackTimer),clearTimeout(e.deadlineTimer);this.pendingAcks.clear(),this.ws&&(this.ws.close(),this.ws=null)}startLiveness(){this.stopLiveness(),this.livenessTimer=setInterval(()=>{if(!this.ws||this.intentionalClose)return;let e=this.ws.readyState;if(e===WebSocket.CONNECTING){if(Date.now()-this.connectStartedAt>1e4)try{this.ws.close()}catch(e){}return}if(e===WebSocket.CLOSING||e===WebSocket.CLOSED){this.ws=null,this.emit("_disconnected",{}),this.reconnect();return}if(this.lastProbeTs>0&&this.lastReceiveTs<this.lastProbeTs){if(this.missedProbes++,this.missedProbes>=2){try{this.ws.close()}catch(e){}return}}else this.missedProbes=0;try{this.ws.send(JSON.stringify({type:"__ping__"})),this.lastProbeTs=Date.now()}catch(e){try{this.ws.close()}catch(e){}}},15e3)}stopLiveness(){this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}send(e){let{type:t,clientMsgId:r}=e;return"chat"===t&&r?void this.sendChat(r,e):this.ws&&this.ws.readyState===WebSocket.OPEN?void this.ws.send(JSON.stringify(e)):"__ping__"===t||"terminal:input"===t||"terminal:resize"===t?void 0:void(this.pendingQueue.length>=100&&this.pendingQueue.shift(),this.pendingQueue.push(e))}sendChat(e,t){if(this.pendingAcks.size>=100){let e=this.pendingAcks.keys().next().value;void 0!==e&&this.failPendingChat(e)}let r={message:t,attempts:0,ackTimer:null,deadlineTimer:setTimeout(()=>this.failPendingChat(e),12e4)};if(this.pendingAcks.set(e,r),this.ws&&this.ws.readyState===WebSocket.OPEN){if(Date.now()-this.lastReceiveTs>3e4){try{this.ws.close()}catch(e){}return}this.transmitChat(e,r)}}transmitChat(e,t){t.ackTimer&&(clearTimeout(t.ackTimer),t.ackTimer=null),t.attempts++;try{this.ws.send(JSON.stringify(t.message))}catch(e){try{var r;null==(r=this.ws)||r.close()}catch(e){}return}t.ackTimer=setTimeout(()=>{if((t.ackTimer=null,this.pendingAcks.has(e))&&!(t.attempts>=3))try{var r;null==(r=this.ws)||r.close()}catch(e){}},5e3)}failPendingChat(e){let t=this.pendingAcks.get(e);t&&(t.ackTimer&&clearTimeout(t.ackTimer),clearTimeout(t.deadlineTimer),this.pendingAcks.delete(e),this.emit("_chat_send_failed",{clientMsgId:e}))}resolveAck(e){if("string"!=typeof e)return;let t=this.pendingAcks.get(e);t&&(t.ackTimer&&clearTimeout(t.ackTimer),clearTimeout(t.deadlineTimer),this.pendingAcks.delete(e))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{let r=this.listeners.get(e);r&&(r.delete(t),0===r.size&&this.listeners.delete(e))}}get connected(){var e;return(null==(e=this.ws)?void 0:e.readyState)===WebSocket.OPEN}get lastReceiveAgeMs(){return 0===this.lastReceiveTs?1/0:Date.now()-this.lastReceiveTs}reconnectIfStale(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;if(!this.ws)return void this.connect(this.url);if(0===e&&this.ws.readyState===WebSocket.CONNECTING){try{this.ws.close()}catch(e){}return}if(this.ws.readyState===WebSocket.OPEN&&!(Date.now()-this.lastReceiveTs<e))try{this.ws.close()}catch(e){}}emit(e,t){let r=this.listeners.get(e);r&&r.forEach(r=>{try{r(t)}catch(t){console.error('[WsClient] Error in handler for "'.concat(e,'":'),t)}})}reconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(2*this.reconnectDelay,this.maxReconnectDelay),this.connect(this.url)},this.reconnectDelay))}async checkAuthThenReconnect(){try{let e=await fetch("/api/auth/check",{credentials:"include"});if(401===e.status){this.stopLiveness(),this.emit("_auth_expired",{});return}}catch(e){}this.intentionalClose||this.reconnect()}getDefaultUrl(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}constructor(){this.ws=null,this.listeners=new Map,this.reconnectTimer=null,this.reconnectDelay=1e3,this.maxReconnectDelay=3e4,this.url="",this.intentionalClose=!1,this.pendingQueue=[],this.pendingAcks=new Map,this.lastReceiveTs=0,this.lastProbeTs=0,this.missedProbes=0,this.connectStartedAt=0,this.livenessTimer=null}}let k=new N;function S(e,t){let r=e.connected;return e.on("_connected",()=>{if(!r){r=!0;return}t()})}function C(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v;w.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 A(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:v;try{let a=await w.F.files.tree(e,t);r.getState().setDirChildren(t,a.tree)}catch(e){console.error("[Explorer] Failed to load directory:",t,e)}}let I=[".halo/sessions/",".halo/logs/",".halo/halo.db"];function E(e){let t=e.path;return"string"==typeof t&&I.some(e=>t.startsWith(e))}let T={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"}},P={letter:"?",color:"#487E02",label:"Untracked"};function F(e){var t;return null!=(t=T[e])?t:P}function D(e){return""!==e&&" "!==e&&"?"!==e}function M(e){return""!==e&&" "!==e}let L={files:new Map,dirs:new Map,ignored:new Set},R=(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 _=r(10666),z=r(1833);function O(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,z.QP)((0,_.$)(t))}function W(){return Math.random().toString(36).substring(2,10)+Date.now().toString(36)}function B(e){return!!e&&!!(e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\"))}function U(e,t){let r=window;return"function"==typeof r.haloPrompt?r.haloPrompt(e,t):Promise.resolve(window.prompt(e,t))}function H(e){let t=window;return"function"==typeof t.haloConfirm?t.haloConfirm(e):Promise.resolve(window.confirm(e))}function K(e,t){let r="number"==typeof e?e:new Date(e).getTime(),a=Math.floor((Date.now()-r)/6e4);if(a<1)return t?t("time.justNow"):"just now";if(a<60)return t?t("time.minutes",{n:a}):"".concat(a,"m ago");let s=Math.floor(a/60);if(s<24)return t?t("time.hours",{n:s}):"".concat(s,"h ago");let n=Math.floor(s/24);return n<30?t?t("time.days",{n:n}):"".concat(n,"d ago"):new Date(r).toLocaleDateString()}function G(e){return e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}function J(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 q=r(51332),Z=r(23028),V=r(62186),Y=r(98844),$=r(98299),Q=r(53298),X=r(24604),ee=r(91531),et=r(1813),er=r(61031),ea=r(378),es=r(17317),en=r(80037),el=r(67508),eo=r(26205),ei=r(59800),ec=r(5276),ed=r(48550),eu=r(79464),em=r(68301),ex=r(71473),ep=r(27153),eh=r(44242);let ef={ts:X.A,tsx:X.A,mts:X.A,cts:X.A,js:X.A,jsx:X.A,mjs:X.A,cjs:X.A,json:ee.A,jsonc:ee.A,html:et.A,htm:et.A,svg:et.A,xml:et.A,css:er.A,scss:er.A,sass:er.A,less:er.A,md:ea.A,mdx:ea.A,txt:ea.A,rst:ea.A,log:ea.A,csv:es.A,tsv:es.A,xlsx:es.A,xls:es.A,sql:en.A,sh:el.A,bash:el.A,zsh:el.A,yaml:eo.A,yml:eo.A,toml:eo.A,ini:eo.A,env:eo.A,py:ei.A,go:ec.A,rs:ec.A,c:ec.A,cpp:ec.A,h:ec.A,hpp:ec.A,java:ec.A,kt:ec.A,scala:ec.A,cs:ec.A,swift:ec.A,dart:ec.A,rb:ec.A,php:ec.A,lua:ec.A,r:ec.A,png:ed.A,jpg:ed.A,jpeg:ed.A,gif:ed.A,webp:ed.A,bmp:ed.A,ico:ed.A,avif:ed.A,mp4:eu.A,webm:eu.A,mov:eu.A,avi:eu.A,mkv:eu.A,ogg:eu.A,mp3:em.A,wav:em.A,flac:em.A,aac:em.A,m4a:em.A,wma:em.A,zip:ex.A,tar:ex.A,gz:ex.A,"7z":ex.A,rar:ex.A,pdf:ep.A,docx:ep.A,doc:ep.A,pptx:ep.A,ppt:ep.A},eg={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 ev(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:el.A,color:"text-cyan-400"}:".gitignore"===i||".gitattributes"===i?{Icon:eo.A,color:"text-[var(--muted-foreground)]"}:".env"===i||i.startsWith(".env.")?{Icon:eo.A,color:"text-yellow-300"}:"makefile"===i||"cmake"===i?{Icon:el.A,color:"text-[var(--muted-foreground)]"}:{Icon:null!=(n=ef[o])?n:eh.A,color:null!=(l=eg[o])?l:"text-[var(--muted-foreground)]"}}let eb="halo:file-tree:expanded",ej=null,ey=new Map;function ew(){if(ej)return ej;try{let e=localStorage.getItem(eb);ej=e?new Set(JSON.parse(e)):new Set}catch(e){ej=new Set}return ej}let eN=null;function ek(e,t){let r=ew(),a=r.has(e);if(t?r.add(e):r.delete(e),eN&&clearTimeout(eN),eN=setTimeout(()=>{try{let e=ew();localStorage.setItem(eb,JSON.stringify([...e]))}catch(e){}},300),a!==t){let r=ey.get(e);if(r)for(let e of r)e(t)}}function eS(e){return ew().has(e)}let eC="application/x-halo-path";function eA(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?q.A:Z.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:O("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 eI(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 eE(e){let t=[];if(e.path&&t.push(e.path),"directory"===e.type&&e.children&&(!e.path||eS(e.path))){var r;for(let a of[...null!=(r=e.children)?r:[]].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)))t.push(...eE(a))}return t}function eT(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:g,depth:v,pendingEdit:b,onCommitEdit:j,onCancelEdit:w}=e,N=y(),[k,S]=(0,l.useState)(()=>!!i.path&&eS(i.path)),[C,I]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),P=(0,l.useRef)(null),D=(0,l.useRef)(null),M="directory"===i.type,_=M&&!1!==i.hasChildren&&void 0===i.children,z=(0,l.useRef)(k),W=(0,l.useCallback)(e=>{S(e),i.path&&ek(i.path,e)},[i.path]);(0,l.useEffect)(()=>{if(i.path){var e,t;let r;return e=i.path,t=e=>S(e),(r=ey.get(e))||(r=new Set,ey.set(e,r)),r.add(t),()=>{let r=ey.get(e);r&&(r.delete(t),0===r.size&&ey.delete(e))}}},[i.path]),(0,l.useEffect)(()=>{let e=z.current;z.current=k,k&&!E&&i.path&&(_||!e)&&(T(!0),A(c,i.path,N).finally(()=>T(!1)))},[k,_,E,i.path,c,N]);let B=N(e=>e.modifiedPaths),U=N(e=>e.activeTab),H=R(e=>{var t;return null!=(t=c?e.byProject[c]:void 0)?t:L});if(0===v&&!i.path){let e=(0,l.useCallback)(()=>eE(i),[i])(),t=async e=>{e.preventDefault(),e.stopPropagation(),I(!1);let t=e.dataTransfer.getData(eC);if(t){null==x||x(t,"");return}let r=await eI(e.dataTransfer);r.length>0&&(null==m||m(r,""))},a=b&&""===b.parentDir&&"rename"!==b.mode;return(0,n.jsxs)("div",{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(eC))&&(e.preventDefault(),e.stopPropagation(),I(!0))},onDragLeave:e=>{e.currentTarget===e.target&&I(!1)},onDrop:t,className:O("min-h-full",C&&"bg-[var(--accent)]/30"),children:[a&&b&&(0,n.jsx)(eA,{depth:0,initialValue:"",iconKind:"create-folder"===b.mode?"folder":"file",onCommit:e=>null==j?void 0:j(e),onCancel:()=>null==w?void 0:w()}),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)(eT,{node:t,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:m,onMoveFile:x,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:e,depth:0,pendingEdit:b,onCommitEdit:j,onCancelEdit:w},t.path))]})}let K=B.has(i.path),G=U===i.path,J=null!=(a=null==p?void 0:p.has(i.path))&&a,{Icon:X,color:ee}=ev(i.path),et=M?H.dirs.get(i.path):H.files.get(i.path),er=et&&"*"!==et?F(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}(H.ignored,i.path),en=()=>{D.current&&(clearTimeout(D.current),D.current=null)},el=async e=>{if(!M)return;e.preventDefault(),e.stopPropagation(),I(!1),en(),k||W(!0);let t=e.dataTransfer.getData(eC);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 eI(e.dataTransfer);r.length>0&&(null==m||m(r,i.path))},eo=M&&(null==(t=i.children)?void 0:t.some(e=>{let t=e=>{var r,a;return!!B.has(e.path)||null!=(a=null==(r=e.children)?void 0:r.some(t))&&a};return t(e)})),ei=b&&"rename"===b.mode&&b.originalPath===i.path,ec=b&&"rename"!==b.mode&&b.parentDir===i.path&&M;return ei&&b?(0,n.jsx)(eA,{depth:v,initialValue:null!=(s=b.originalName)?s:i.name,iconKind:M?"folder":"file",onCommit:e=>null==j?void 0:j(e),onCancel:()=>null==w?void 0:w()}):(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{draggable:!0,"data-path":i.path,onClick:e=>{if(e.stopPropagation(),M&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){h&&h(new Set([i.path]),i.path),W(!k);return}if(e.shiftKey&&h&&g&&f){let e=g.indexOf(f),t=g.indexOf(i.path);if(e>=0&&t>=0){let r=Math.min(e,t),a=Math.max(e,t);h(new Set(g.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}M||(h&&h(new Set([i.path]),i.path),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null,d(i.path)},300))},onDoubleClick:e=>{e.stopPropagation(),P.current&&(clearTimeout(P.current),P.current=null),M?W(!k):d(i.path)},onDragStart:e=>{p&&p.size>1&&p.has(i.path)?e.dataTransfer.setData(eC,JSON.stringify([...p])):e.dataTransfer.setData(eC,JSON.stringify([i.path])),e.dataTransfer.effectAllowed="move"},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),!J&&h&&h(new Set([i.path]),i.path),null==u||u({x:e.clientX,y:e.clientY,path:i.path,name:i.name,isDir:M})},onDragOver:e=>{M&&(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(eC))&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",I(!0),k||D.current||(D.current=setTimeout(()=>{D.current=null,W(!0)},600)))},onDragLeave:()=>{I(!1),en()},onDrop:el,className:O("flex w-full items-center gap-1 py-1 text-left text-xs transition-colors hover:bg-[var(--secondary)]",J&&"bg-[var(--primary)]/20 text-[var(--foreground)]",!J&&G&&"bg-[var(--accent)] text-[var(--accent-foreground)]",!J&&!G&&"text-[var(--foreground)]",C&&M&&"bg-[var(--accent)] ring-1 ring-[var(--primary)]"),style:{paddingLeft:"".concat(12*v+8,"px")},children:[M&&(0,n.jsx)("span",{className:"shrink-0 text-[var(--muted-foreground)]",children:k?(0,n.jsx)(V.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(Y.A,{className:"h-3.5 w-3.5"})}),!M&&(0,n.jsx)("span",{className:"w-3.5 shrink-0"}),M?k?(0,n.jsx)($.A,{className:O("h-3.5 w-3.5 shrink-0 text-blue-400",es&&"opacity-60")}):(0,n.jsx)(q.A,{className:O("h-3.5 w-3.5 shrink-0 text-blue-400",es&&"opacity-60")}):(0,n.jsx)(X,{className:O("h-3.5 w-3.5 shrink-0",ee,es&&"opacity-60")}),(0,n.jsx)("span",{className:O("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:[(K||eo)&&(0,n.jsx)(Z.A,{className:"h-1.5 w-1.5 shrink-0 fill-amber-400 text-amber-400"}),M?ea&&(0,n.jsx)(Z.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})]})]}),M&&k&&E&&!i.children&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-[10px] text-[var(--muted-foreground)]",style:{paddingLeft:"".concat((v+1)*12+8,"px")},children:[(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin"}),(0,n.jsx)("span",{children:"Loading..."})]}),M&&k&&(i.children||ec)&&(0,n.jsxs)("div",{children:[ec&&b&&(0,n.jsx)(eA,{depth:v+1,initialValue:"",iconKind:"create-folder"===b.mode?"folder":"file",onCommit:e=>null==j?void 0:j(e),onCancel:()=>null==w?void 0:w()}),(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)(eT,{node:e,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:m,onMoveFile:x,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:g,depth:v+1,pendingEdit:b,onCommitEdit:j,onCancelEdit:w},e.path))]})]})}var eP=r(90429),eF=r(93717),eD=r(93247),eM=r(35179),eL=r(34633),eR=r(17612),e_=r(19869);function ez(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)(eP.A,{className:"h-3.5 w-3.5"}),"Delete ",i," items"]})]});let h=""===a&&o,f=!!window.haloReveal,g=h?[{icon:eF.A,label:"New File...",type:"new-file"},{icon:eD.A,label:"New Folder...",type:"new-folder"},{icon:el.A,label:"Open in Integrated Terminal",type:"open-terminal"},...f?[{icon:eM.A,label:"Reveal in File Manager",type:"reveal-in-file-manager"}]:[]]:[{icon:eF.A,label:"New File...",type:"new-file",separatorAfter:!1},{icon:eD.A,label:"New Folder...",type:"new-folder",separatorAfter:!1},{icon:el.A,label:"Open in Integrated Terminal",type:"open-terminal",separatorAfter:!f},...f?[{icon:eM.A,label:"Reveal in File Manager",type:"reveal-in-file-manager",separatorAfter:!0}]:[],...o?[]:[{icon:eL.A,label:"Open to the Side",type:"open-to-side",separatorAfter:!1},{icon:eR.A,label:"Download",type:"download"}],{icon:e_.A,label:"Rename",type:"rename"},{icon:eP.A,label:"Delete",type:"delete",danger:!0,separatorAfter:o},...o?[{icon:$.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)})]})}d.wG.config({paths:{vs:"/monaco/vs"}});var eO=r(59391);let eW={dark:"vs-dark",light:"vs",midnight:"halo-midnight",warm:"halo-warm"},eB=!1;function eU(e){eB||(eB=!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 eH(e){let{path:t,content:r,language:a,onChange:s,onSave:o,onClose:i}=e,c=y(),u=(0,l.useRef)(null),{theme:m}=(0,eO.useTheme)(),x=(0,l.useRef)(o),p=(0,l.useRef)(i),h=(0,l.useRef)(r);(0,l.useEffect)(()=>{x.current=o,p.current=i,h.current=r},[o,i,r]),(0,l.useEffect)(()=>()=>{c.getState().setSelectedText(null,null)},[t]);let f=(0,l.useCallback)(e=>{void 0!==e&&s&&s(e)},[s]),g=(0,l.useCallback)((e,t)=>{u.current=e;let r=e.getModel();r&&r.getValue()!==h.current&&r.setValue(h.current),e.onDidChangeCursorSelection(t=>{var r,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=x.current)||e.call(x)}}),e.addAction({id:"halo-close-tab",label:"Close Tab",keybindings:[t.KeyMod.Alt|t.KeyCode.KeyW],run:()=>{var e;null==(e=p.current)||e.call(p)}})},[]);return(0,n.jsx)(d.Ay,{path:t,keepCurrentModel:!0,height:"100%",language:a,value:r,onChange:f,beforeMount:eU,onMount:g,theme:eW[m],options:{fontSize:13,lineHeight:20,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:"on",tabSize:2,renderLineHighlight:"line",cursorBlinking:"smooth",smoothScrolling:!0,padding:{top:12,bottom:12},bracketPairColorization:{enabled:!0},automaticLayout:!0,overviewRulerLanes:0,hideCursorInOverviewRuler:!0,overviewRulerBorder:!1,scrollbar:{verticalScrollbarSize:6,horizontalScrollbarSize:6}},loading:(0,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 eK=r(40549),eG=r(29978),eJ=r(87917),eq=r(28687),eZ=r(12161);function eV(e){let{content:t,filePath:r,projectId:a}=e,s=(0,eZ.kj)(),o=y(),i=(0,l.useRef)(null),c=(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]),d=0,u=e=>{let t=i.current;if(!t)return;let r=t.querySelector("#".concat(CSS.escape(e)));r&&r.scrollIntoView({behavior:"smooth",block:"start"})},[m,x]=(0,l.useState)(()=>{try{return"1"===localStorage.getItem("halo.mdOutlineHidden")}catch(e){return!1}}),p=()=>{x(e=>{let t=!e;try{localStorage.setItem("halo.mdOutlineHidden",t?"1":"0")}catch(e){}return t})};(0,l.useEffect)(()=>{let e=i.current;if(!e)return;let t=o.getState().setSelectedText;function r(){let r=window.getSelection();if(!r||0===r.rangeCount)return;let 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)}},[o]);let h=e=>function(t){var r;let{children:a}=t;return(0,n.jsx)(e,{id:null==(r=c[d++])?void 0:r.slug,children:a})};return(0,n.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[c.length>1&&!m&&(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:s("editor.outline")}),(0,n.jsx)("button",{onClick:p,title:s("editor.hideOutline"),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eJ.A,{className:"h-3.5 w-3.5"})})]}),c.map((e,t)=>(0,n.jsx)("button",{onClick:()=>u(e.slug),title:e.text,className:"block w-full shrink-0 truncate px-3 py-1 text-left text-xs text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",style:{paddingLeft:"".concat(.75+(e.level-1)*.75,"rem")},children:e.text},"".concat(e.slug,"-").concat(t)))]}),(0,n.jsxs)("div",{ref:i,className:"relative flex-1 overflow-y-auto px-8 py-6",children:[c.length>1&&m&&(0,n.jsx)("button",{onClick:p,title:s("editor.showOutline"),className:"absolute left-2 top-2 z-10 hidden rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] md:block",children:(0,n.jsx)(eq.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)(eK.oz,{remarkPlugins:[eG.A],components:{h1:h("h1"),h2:h("h2"),h3:h("h3"),h4:h("h4"),h5:h("h5"),h6:h("h6"),a(e){let{href:t,children:r,node: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){}u(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 eY=new Set;function e$(e){for(let r of eY)try{var t;null==(t=r.contentWindow)||t.postMessage({haloFace:e},"*")}catch(e){}}function eQ(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,eY.add(e),()=>{eY.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 eX(e){let{original:t,modified:r,path:a}=e,s=J(a),{theme:l}=(0,eO.useTheme)();return(0,n.jsx)(d.zC,{height:"100%",language:s,original:t,modified:r,beforeMount:eU,theme:eW[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 e0=r(38067),e1=r(61648),e5=r(30865),e3=r(84099);function e2(e){var t,r;let{x:a,y:s,path:o,groupIdx:i,onClose:c,onCloseTab:d}=e,u=y(),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:O("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 e4="application/x-halo-tab";function e8(e){let{tabs:t,activeTab:r,groupIdx:a,canSplit:s,onCloseTab:o,renderMode:i,onToggleRenderMode:c,showDiffButton:d,onToggleDiff:u}=e,m=(0,eZ.kj)(),x=y(),p=(0,l.useRef)(null),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,N]=(0,l.useState)(null),[k,S]=(0,l.useState)(!1),[C,A]=(0,l.useState)(null),I=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),E=(0,l.useCallback)(()=>{let e=p.current;e&&(f(e.scrollLeft>0),v(e.scrollLeft+e.clientWidth<e.scrollWidth-1))},[]);(0,l.useEffect)(()=>{E();let e=p.current;if(!e)return;e.addEventListener("scroll",E);let t=new ResizeObserver(E);return t.observe(e),()=>{e.removeEventListener("scroll",E),t.disconnect()}},[E,t.length]);let T=e=>{var t;null==(t=p.current)||t.scrollBy({left:e,behavior:"smooth"})},P=()=>{j(null),N(null),S(!1)},F=x(e=>e.activeGroupIdx);return(0,n.jsxs)("div",{className:O("relative flex shrink-0 items-center border-b border-[var(--border)] bg-[var(--card)]",k&&"ring-1 ring-[var(--primary)]"),onDragOver:e=>{if(!e6(e))return;let t=e.dataTransfer.types.includes(e4)?{srcGroupIdx:-1,path:""}:null;t&&t.srcGroupIdx!==a&&(e.preventDefault(),e.dataTransfer.dropEffect="move",S(!0))},onDragLeave:e=>{e.currentTarget===e.target&&S(!1)},onDrop:e=>{if(!e6(e))return;e.preventDefault();let t=e9(e);t&&t.srcGroupIdx!==a&&x.getState().moveTabToGroup(t.srcGroupIdx,t.path,a),j(null),N(null),S(!1)},onMouseDown:()=>x.getState().setActiveGroup(a),children:[h&&(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)(e0.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("div",{ref:p,className:"flex flex-1 overflow-x-hidden",children:t.map((e,t)=>{var s;let{Icon:l,color:i}=ev(e.path),c=e.path===r&&a===F,d=e.path===r&&a!==F;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(e4,JSON.stringify({srcGroupIdx:a,path:s}))},onDragOver:e=>{e6(e)&&(e.preventDefault(),e.dataTransfer.dropEffect="move",N(t))},onDrop:e=>((e,t)=>{if(!e6(e))return;e.preventDefault();let r=e9(e);r&&x.getState().moveTabToGroup(r.srcGroupIdx,r.path,a,t),j(null),N(null),S(!1)})(e,t),onDragEnd:P,onContextMenu:t=>{t.preventDefault(),A({x:t.clientX,y:t.clientY,path:e.path})},className:O("group relative flex items-center gap-1.5 border-r border-[var(--border)] px-3 py-1.5 text-xs cursor-pointer transition-colors select-none",c?"bg-[var(--background)] text-[var(--foreground)]":d?"bg-[var(--background)]/50 text-[var(--muted-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",b===t&&"opacity-40"),onClick:()=>{x.getState().setActiveTab(e.path,a),x.getState().setRejectedFile(null)},children:[w===t&&null!==b&&b>t&&(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),w===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:O("h-3.5 w-3.5 shrink-0",i)}),(0,n.jsx)("span",{className:"max-w-40 truncate",children:null!=(s=I.get(e.path))?s:e.path.split("/").pop()}),e.modified?(0,n.jsx)(Z.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)(e1.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)(e1.A,{className:"h-3 w-3"})})]},e.path)})}),g&&(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)(Y.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:O("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)(e_.A,{className:"h-3 w-3"}):(0,n.jsx)(e5.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:i?"Edit":"Preview"})]}),d&&(0,n.jsxs)("button",{onClick:u,title:m("editor.viewDiff"),className:"flex items-center gap-1 rounded px-1.5 py-1 text-[11px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[(0,n.jsx)(e3.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:m("editor.diff")})]})]})})(),s&&(0,n.jsx)("button",{title:m("editor.splitRight"),onClick:()=>x.getState().splitToRight(),className:"ml-1 mr-1 shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eL.A,{className:"h-3.5 w-3.5"})}),C&&(0,n.jsx)(e2,{x:C.x,y:C.y,path:C.path,groupIdx:a,onClose:()=>A(null),onCloseTab:o})]})}function e6(e){return e.dataTransfer.types.includes(e4)}function e9(e){try{let t=e.dataTransfer.getData(e4);if(!t)return null;return JSON.parse(t)}catch(e){return null}}let e7=new Map;function te(e){for(let t of e.extensions)e7.set(t.toLowerCase(),e)}let tt={id:"pdf",extensions:["pdf"],Component:(0,l.lazy)(()=>r.e(65).then(r.bind(r,50065)).then(e=>({default:e.PdfPreview})))},tr={id:"docx",extensions:["docx","doc"],Component:(0,l.lazy)(()=>r.e(579).then(r.bind(r,37579)).then(e=>({default:e.DocxPreview})))},ta={id:"xlsx",extensions:["xlsx","xls"],Component:(0,l.lazy)(()=>r.e(442).then(r.bind(r,36442)).then(e=>({default:e.XlsxPreview})))},ts={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 tn=r(89759);let tl={id:"parquet",extensions:["parquet"],Component:(0,l.lazy)(()=>r.e(935).then(r.bind(r,43935)).then(e=>({default:e.ParquetPreview})))},to={id:"sqlite",extensions:["db","sqlite","sqlite3"],Component:(0,l.lazy)(()=>r.e(896).then(r.bind(r,93896)).then(e=>({default:e.SqlitePreview})))},ti={id:"csv",extensions:["csv","tsv"],Component:(0,l.lazy)(()=>r.e(515).then(r.bind(r,16515)).then(e=>({default:e.CsvPreview})))};function tc(){return(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})}function td(e){var t,r,a;if(e.tooLarge)return(0,n.jsx)(tu,{...e});let s=(a=null!=(r=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?r:"",e7.get(a.toLowerCase()));if(!s)return(0,n.jsx)(tm,{...e});let{Component:o}=s;return(0,n.jsx)(l.Suspense,{fallback:(0,n.jsx)(tc,{}),children:(0,n.jsx)(o,{...e})})}function tu(e){let{name:t,size:r,downloadUrl: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)(eh.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.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)]",children:[null!=r?"".concat(G(r)," \xb7 "):"","File is too large to preview (max 10MB)"]}),(0,n.jsx)("a",{href:a,download:!0,className:"inline-flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",children:"Download"})]})}function tm(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)(eh.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"})]})]})}te(tt),te(tr),te(ta),te(ts),te(tn.SQ),te(tl),te(to),te(ti);let tx=(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 tp=r(29241),th=r(97095),tf=r(98413);function tg(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}function tv(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}let tb=new Set([...e7.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 tj(e){let{projectId:t,mode:r="full",showMaximize:a=!0}=e,s=(0,eZ.kj)(),o=y(),c=o(e=>e.tabs),d=o(e=>e.activeTab),x=o(e=>e.buffers),p=o(e=>e.groups),h=o(e=>e.activeGroupIdx),f=o(e=>e.maximized),g="editor-only"===r,[b,j]=(0,l.useState)(!0),[N,A]=(0,l.useState)({}),[I,E]=(0,l.useState)({});function T(e){var t;return null==(t=I[e])||t}let[P,F]=(0,l.useState)(null),[D,M]=(0,l.useState)(new Set),[L,R]=(0,l.useState)(null),[_,z]=(0,l.useState)(null),[W,B]=(0,l.useState)(null),U=(0,l.useRef)(null),{tree:K,loading:q}=function(e){let t=y(),[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 w.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 k.on("file:changed",e=>{"add"===e.action||"addDir"===e.action?t.getState().insertFileNode(e.path,"addDir"===e.action?"directory":"file"):("unlink"===e.action||"unlinkDir"===e.action)&&t.getState().removeFileNode(e.path)})},[e,t]),(0,l.useEffect)(()=>{if(e)return S(k,()=>C(e,t))},[e,t]),{tree:o,loading:r,error:s,refresh:i}}(t),[Z,V]=(0,l.useState)(!1),Y=(0,l.useRef)(null),$=(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=e7.get(a.toLowerCase()))?void 0:s.heavy)},[]),[Q,X]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=[];for(let t of p){let r=t.activeTab;if(!r)continue;let a=x[r];(null==a?void 0:a.preview)&&($(r)||e.push(r))}0!==e.length&&X(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})},[p,x,$]),(0,l.useEffect)(()=>{X(e=>{let t=new Set;for(let e of p)for(let r of e.tabs)t.add(r);let r=e.filter(e=>t.has(e));return r.length===e.length?e:r})},[p]),(0,l.useEffect)(()=>{o.getState().setModelPathPrefix(null!=t?t:null)},[t,o]),(0,l.useEffect)(()=>{if(!t)return;Y.current&&Y.current!==t&&(m(Y.current,Object.keys(o.getState().buffers)),o.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modifiedPaths:new Set}}),V(!1)),Y.current=t;let e="halo_tabs:".concat(t),r=localStorage.getItem(e);if(!r)return void V(!0);let a=!1;return async function(){try{var e,s,n;let l=JSON.parse(r),i=null!=(s=l.groups)?s:l.tabs?[{tabs:l.tabs,activeTab:null!=(e=l.activeTab)?e:null}]:[],c=null!=(n=l.activeGroupIdx)?n:0;if(0===i.length)return void V(!0);let d=Array.from(new Set(i.flatMap(e=>e.tabs.map(e=>e.path)))),u=new Map;for(let e of i)for(let t of e.tabs)u.has(t.path)||u.set(t.path,t.language);let m=await Promise.all(d.map(async e=>{var r,a;let s=null!=(a=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?a:"";if(tb.has(s))try{let r=await w.F.files.stat(e,t);return{path:e,content:"",originalContent:"",language:"",size:r.size,mtime:r.modifiedAt,createdAt:r.createdAt,preview:{downloadUrl:w.F.files.downloadUrl(e,t),viewUrl:w.F.files.viewUrl(e,t)}}}catch(e){return null}try{let r=await w.F.files.read(e,t);return{path:e,content:r.content,originalContent:r.content,language:u.get(e)||J(e),mtime:r.modifiedAt,size:r.size,createdAt:r.createdAt}}catch(e){return null}}));if(a)return;let x={};for(let e of m)e&&(x[e.path]=e);let p=i.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)o.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null}});else{let e=Math.max(0,Math.min(c,p.length-1)),t=p[e],r=t.tabs.map(e=>x[e]).filter(e=>!!e);o.setState({buffers:x,groups:p,activeGroupIdx:e,tabs:r,activeTab:t.activeTab})}}catch(e){}a||V(!0)}(),()=>{a=!0}},[t]),(0,l.useEffect)(()=>{if(!t||!Z)return;let e=p.map(e=>({tabs:e.tabs.map(e=>{let t=x[e];return{path:e,isPreview:!!(null==t?void 0:t.preview),language:null==t?void 0:t.language}}),activeTab:e.activeTab}));localStorage.setItem("halo_tabs:".concat(t),JSON.stringify({groups:e,activeGroupIdx:h}))},[p,h,x,t,Z]);let ee=c.find(e=>e.path===d),et=(0,l.useCallback)(()=>{let e=o.getState().activeTab;if(!e||!t)return;let r=o.getState().tabs.find(t=>t.path===e);r&&!r.preview&&w.F.files.stat(e,t).then(r=>{o.getState().checkAndRefresh(e,r.modifiedAt,()=>w.F.files.read(e,t))}).catch(()=>{})},[t]);(0,l.useEffect)(()=>{Z&&et()},[d,et,Z]);let er=tx(e=>{var t;return null==(t=e.activeProject)?void 0:t.path});(0,l.useEffect)(()=>{if(t&&er)return k.on("file:changed",e=>{if("change"!==e.action)return;let r="".concat(er,"/").concat(e.path),a=t.endsWith("/")?t:"".concat(t,"/");if(!r.startsWith(a))return;let s=r.slice(a.length),n=o.getState().tabs.find(e=>e.path===s);!n||n.preview||n.modified||w.F.files.read(s,t).then(e=>{o.getState().checkAndRefresh(s,e.modifiedAt,async()=>({content:e.content,modifiedAt:e.modifiedAt}))}).catch(()=>{})})},[t,er,o]),(0,l.useEffect)(()=>{let e=()=>et();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[et]),(0,l.useEffect)(()=>S(k,et),[et]);let ea=(0,l.useCallback)(async e=>{var r,a;if(!t)return;let s=null!=(a=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?a:"";if(tb.has(s)){let r,a=w.F.files.downloadUrl(e,t),s=w.F.files.viewUrl(e,t);try{let a=await w.F.files.stat(e,t);r={size:a.size,mtime:a.modifiedAt,createdAt:a.createdAt}}catch(e){}o.getState().openPreview(e,a,s,r);return}if(o.getState().tabs.find(t=>t.path===e))return void o.getState().setActiveTab(e);try{let r=await w.F.files.read(e,t),a=J(e);o.getState().openFile(e,r.content,a,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(a){console.error("[EditorPanel] Failed to read file:",a);let r=a instanceof Error?a.message:String(a);if(r.includes("413")||r.includes("too large")){let r;try{let a=await w.F.files.stat(e,t);r={size:a.size,mtime:a.modifiedAt,createdAt:a.createdAt}}catch(e){}o.getState().openPreview(e,w.F.files.downloadUrl(e,t),w.F.files.viewUrl(e,t),{...r,tooLarge:!0})}}},[t]),es=(0,l.useCallback)(async(e,t)=>{let r=o.getState(),a=r.buffers[t],s=r.groups.some((r,a)=>a!==e&&r.tabs.includes(t));(null==a||!a.modified||s||await H('"'.concat(t.split("/").pop(),'" has unsaved changes. Close anyway?')))&&o.getState().closeTabIn(e,t)},[]),en=(0,l.useCallback)(async e=>{if(t)try{let r=await w.F.files.read(e,t),a=J(e);o.getState().closeTab(e),o.getState().openFile(e,r.content,a,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(e){console.error("[EditorPanel] Failed to open as text:",e)}},[t]),el=(0,l.useCallback)((e,t)=>{o.getState().updateContent(e,t)},[]),eo=(0,l.useCallback)(async e=>{let r=null!=e?e:d;if(!r||!t)return;let a=o.getState().tabs.find(e=>e.path===r);if(a&&a.modified)try{let e=await w.F.files.save(r,a.content,t);o.getState().markSaved(r,e.modifiedAt)}catch(e){console.error("[EditorPanel] Failed to save file:",e)}},[t,d]),ei=(0,l.useCallback)((e,t)=>{let r=o.getState().buffers[t];r&&A(a=>({...a,[e]:{original:r.originalContent,modified:r.content,path:t}}))},[]),ec=(0,l.useCallback)(e=>{A(t=>({...t,[e]:null}))},[]),ed=(0,l.useCallback)(async(e,r)=>{if(t){B({count:e.length,progress:0});try{await w.F.files.upload(e,t,r||void 0,(e,t)=>{t>0&&B(r=>r?{...r,progress:e/t*100}:null)}),B(e=>e?{...e,progress:100}:null),setTimeout(()=>B(null),400),C(t,o)}catch(e){B(null),console.error("[EditorPanel] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}}},[t]),eu=(0,l.useCallback)(async(e,r)=>{var a;if(!t)return;let s=null!=(a=e.split("/").pop())?a:"",n=r?"".concat(r,"/").concat(s):s;if(e!==n)try{await w.F.files.rename(e,n,t);let r=o.getState();r.tabs.find(t=>t.path===e)&&r.closeTab(e),C(t,o)}catch(e){console.error("[EditorPanel] Move failed:",e),window.alert(e instanceof Error?e.message:"Move failed")}},[t]),em=(0,l.useCallback)((e,t)=>{M(e),t&&R(t)},[]),ex=(0,l.useCallback)(e=>{F(e)},[]),ep=(0,l.useCallback)(async e=>{var r,a,s,n,l;if(!t)return;let i=""===e.path&&e.isDir,c=(()=>{if(!i)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:tg(K,t)}})(),d=c.isDir?c.path:c.path.includes("/")?c.path.substring(0,c.path.lastIndexOf("/")):"";if("new-file"===e.type||"new-folder"===e.type){d&&ek(d,!0),z({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==(r=e.path.split(".").pop())?void 0:r.toLowerCase())?a:"",l=tb.has(n),i=o.getState();1===i.groups.length&&i.splitToRight(null!=(s=i.groups[0].activeTab)?s:e.path);let c=+(o.getState().groups.length>1);if(l){let r=await w.F.files.stat(e.path,t);o.getState().openFileInGroup(c,e.path,"","",r.modifiedAt,{size:r.size,createdAt:r.createdAt}),o.setState(r=>({buffers:{...r.buffers,[e.path]:{...r.buffers[e.path],preview:{downloadUrl:w.F.files.downloadUrl(e.path,t),viewUrl:w.F.files.viewUrl(e.path,t)}}}}))}else{let r=await w.F.files.read(e.path,t),a=J(e.path);o.getState().openFileInGroup(c,e.path,r.content,a,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}}catch(e){console.error("[EditorPanel] Open to the side failed:",e),window.alert(e instanceof Error?e.message:"Open to the side failed")}return}if("open-terminal"===e.type){if(!er)return;let e=d?"".concat(er,"/").concat(d):er;v.getState().requestTerminalSpawn(e),v.getState().setBottomTab("terminal");return}if("open-as-workspace"===e.type){if(!e.isDir||!er)return;let t=e.path?"".concat(er,"/").concat(e.path):er;window.dispatchEvent(new CustomEvent("halo:open-workspace",{detail:{path:t}}));return}if("reveal-in-file-manager"===e.type){if(!er)return;let t=window.haloReveal;if(!t)return;let r=e.path?"".concat(er,"/").concat(e.path):er;t.reveal(r,e.isDir);return}if("download"===e.type){let r=w.F.files.downloadUrl(e.path,t),a=document.createElement("a");a.href=r,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:"";z({mode:"rename",parentDir:e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"",originalPath:e.path,originalName:t});return}if("delete"===e.type){let r=D.size>1&&D.has(e.path)?Array.from(D):[e.path];if(r.length>1){if(!await H("Delete ".concat(r.length," items?")))return}else{let t=e.isDir?"folder":"file";if(!await H("Delete ".concat(t,' "').concat(e.path.split("/").pop(),'"?')))return}try{for(let e of r)await w.F.files.remove(e,t),o.getState().closeTab(e);M(new Set),C(t,o)}catch(e){console.error("[EditorPanel] Delete failed:",e),window.alert(e instanceof Error?e.message:"Delete failed"),C(t,o)}}},[t,D]),eh=(0,l.useCallback)(()=>{z(null)},[]),ef=(0,l.useCallback)(async e=>{if(!t||!_)return;let r=e.trim();if(""===r)return void z(null);let{mode:a,parentDir:s,originalPath:n,originalName:l}=_;if("rename"===a){if(!n||r===l)return void z(null);let e=s?"".concat(s,"/").concat(r):r;try{await w.F.files.rename(n,e,t),o.getState().closeTab(n),C(t,o)}catch(e){console.error("[EditorPanel] Rename failed:",e),window.alert(e instanceof Error?e.message:"Rename failed")}return void z(null)}let i=s?"".concat(s,"/").concat(r):r;try{"create-file"===a?await w.F.files.create(i,t):await w.F.files.mkdir(i,t),C(t,o)}catch(e){console.error("[EditorPanel] Create failed:",e),window.alert(e instanceof Error?e.message:"Create failed")}z(null)},[t,_,o]);(0,l.useEffect)(()=>{function e(e){var t;let r=null==(t=U.current)?void 0:t.querySelector('button[data-path="'.concat(CSS.escape(e),'"]'));r&&(r.focus({preventScroll:!0}),r.scrollIntoView({block:"nearest"}))}function t(t){if(_)return;let r=U.current;if(!r||!K)return;let a=t.target;if(!a||!r.contains(a)||t.ctrlKey||t.metaKey||t.altKey)return;let s=eE(K);if(0===s.length)return;let n=[...D].map(e=>s.indexOf(e)).filter(e=>e>=0),l=n.length?Math.min(...n):-1,o=n.length?Math.max(...n):-1,i=L?s.indexOf(L):-1,c=0===n.length?-1:i>=0&&l<i?l:o,d=i>=0?i:c,u=t=>{let r=s[t];em(new Set([r]),r),e(r)};switch(t.key){case"ArrowDown":case"ArrowUp":{t.preventDefault();let r="ArrowDown"===t.key?1:-1;if(t.shiftKey&&d>=0&&c>=0){let t=Math.max(0,Math.min(s.length-1,c+r)),a=Math.min(d,t),n=Math.max(d,t);em(new Set(s.slice(a,n+1)),s[d]),e(s[t]);return}if(c<0)return void u(1===r?0:s.length-1);u(Math.max(0,Math.min(s.length-1,c+r)));return}case"ArrowRight":{if(t.shiftKey||c<0)return;t.preventDefault();let e=s[c];if(!tg(K,e))return;if(!eS(e))return void ek(e,!0);let r=s[c+1];r&&r.startsWith("".concat(e,"/"))&&u(c+1);return}case"ArrowLeft":{if(t.shiftKey||c<0)return;t.preventDefault();let e=s[c];if(tg(K,e)&&eS(e))return void ek(e,!1);if(!e.includes("/"))return;let r=s.indexOf(e.slice(0,e.lastIndexOf("/")));r>=0&&u(r);return}case"Enter":{if(t.shiftKey||c<0)return;t.preventDefault();let e=s[c];tg(K,e)?ek(e,!eS(e)):ea(e);return}case"Home":case"End":if(t.shiftKey)return;t.preventDefault(),u("Home"===t.key?0:s.length-1);return;case"F2":{var m;if(1!==D.size)return;t.preventDefault();let e=D.values().next().value,r=null!=(m=e.split("/").pop())?m:"";z({mode:"rename",parentDir:e.includes("/")?e.substring(0,e.lastIndexOf("/")):"",originalPath:e,originalName:r});return}}}return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[K,D,L,_,ea,em]);let eg=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"===r)return(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[eg,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:()=>M(new Set),className:"rounded px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(e1.A,{className:"h-3 w-3"})})]}),(0,n.jsx)("div",{ref:U,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:q?(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):K?(0,n.jsx)(eT,{node:K,projectId:t,onSelect:ea,onContextMenu:ex,onDropFiles:ed,onMoveFile:eu,selectedPaths:D,onSelectionChange:em,lastAnchor:L,depth:0,pendingEdit:_,onCommitEdit:ef,onCancelEdit:eh}):(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"})}),P&&(0,n.jsx)(ez,{x:P.x,y:P.y,path:P.path,name:P.name,isDir:P.isDir,selectedCount:D.size>1&&D.has(P.path)?D.size:void 0,onAction:ep,onClose:()=>F(null)})]});let ev="full"===r&&b;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"===r&&(0,n.jsx)("button",{onClick:()=>j(!b),className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:b?(0,n.jsx)(eJ.A,{className:"h-4 w-4"}):(0,n.jsx)(eq.A,{className:"h-4 w-4"})}),(0,n.jsx)(tp.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:s("nav.canvas")}),ee&&(null!=ee.size||null!=ee.mtime)&&(0,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",[null!=ee.size?G(ee.size):"",null!=ee.createdAt?"Created ".concat(tv(ee.createdAt)):"",null!=ee.mtime?"Modified ".concat(tv(ee.mtime)):""].filter(Boolean).join(" \xb7 "),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1",children:a&&(0,n.jsx)("button",{onClick:()=>o.getState().toggleMaximized(),title:f?"Exit full screen":"Maximize editor",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:f?(0,n.jsx)(th.A,{className:"h-4 w-4"}):(0,n.jsx)(tf.A,{className:"h-4 w-4"})})})]}),(0,n.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:ev?"halo-editor-tree":void 0,children:[ev&&(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:[eg,(0,n.jsx)("div",{ref:U,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:t?q?(0,n.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):K?(0,n.jsx)(eT,{node:K,projectId:t,onSelect:ea,onContextMenu:ex,onDropFiles:ed,onMoveFile:eu,selectedPaths:D,onSelectionChange:em,lastAnchor:L,depth:0,pendingEdit:_,onCommitEdit:ef,onCancelEdit:eh}):(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:p.map((e,r)=>{var a;let s=e.tabs.map(e=>x[e]).filter(e=>!!e),l=e.activeTab,c=s.find(e=>e.path===l),d=r===h;return(0,n.jsx)(i.Zk,{defaultSize:100/p.length,minSize:20,children:(0,n.jsxs)("div",{className:O("flex h-full flex-col overflow-hidden",d&&p.length>1&&"ring-1 ring-inset ring-[var(--primary)]/30"),onMouseDown:()=>o.getState().setActiveGroup(r),children:[s.length>0&&(()=>{let t=T(e.id),a=N[e.id],o=!!(null==c?void 0:c.modified)&&!c.preview;return(0,n.jsx)(e8,{tabs:s,activeTab:l,groupIdx:r,canSplit:g&&1===p.length,onCloseTab:e=>es(r,e),renderMode:t,onToggleRenderMode:()=>E(r=>({...r,[e.id]:!t})),showDiffButton:o,onToggleDiff:()=>{a?ec(e.id):c&&ei(e.id,c.path)}})})(),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden",children:[Q.map(e=>s.find(t=>t.path===e&&t.preview)).filter(e=>!!e).map(e=>{var r;return(0,n.jsx)("div",{className:O("h-full",(null==c?void 0:c.path)!==e.path&&"hidden"),children:(0,n.jsx)(td,{path:e.path,name:null!=(r=e.path.split("/").pop())?r:"",projectId:null!=t?t:void 0,downloadUrl:e.preview.downloadUrl,viewUrl:e.preview.viewUrl,tooLarge:e.preview.tooLarge,size:e.size,onOpenAsText:()=>en(e.path)})},e.path)}),(null==c?void 0:c.preview)&&$(c.path)&&(0,n.jsx)("div",{className:"h-full",children:(0,n.jsx)(td,{path:c.path,name:null!=(a=c.path.split("/").pop())?a:"",projectId:null!=t?t:void 0,downloadUrl:c.preview.downloadUrl,viewUrl:c.preview.viewUrl,tooLarge:c.preview.tooLarge,size:c.size,onOpenAsText:()=>en(c.path)})}),(()=>{let a=N[e.id],s=T(e.id);if(null==c?void 0:c.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:()=>ec(e.id),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(eX,{original:a.original,modified:a.modified,path:a.path})})]});if(c){var l;let e=s&&"markdown"===c.language,a=s&&"html"===c.language&&!!t;return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)(eV,{content:c.content,filePath:c.path,projectId:t}),a&&(0,n.jsx)(eQ,{url:w.F.files.viewUrl(c.path,t),name:null!=(l=c.path.split("/").pop())?l:""}),(0,n.jsx)("div",{className:O("h-full",(e||a)&&"hidden"),children:(0,n.jsx)(eH,{path:u(t,c.path),content:c.content,language:c.language,onChange:e=>el(c.path,e),onSave:()=>eo(c.path),onClose:()=>es(r,c.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)(tp.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])},p.length)})]}),P&&(0,n.jsx)(ez,{x:P.x,y:P.y,path:P.path,name:P.name,isDir:P.isDir,selectedCount:D.size>1&&D.has(P.path)?D.size:void 0,onAction:ep,onClose:()=>F(null)})]})}function ty(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 tw(e){let t=ty(e);return"tool_call"===t||"tool_result"===t||"usage"===t||"context"===t||"agent_start"===t||"agent_done"===t}function tN(e){if(e.taskId)return!1;let t=ty(e);return"user"===t||"assistant"===t||"notification"===t}var tk=r(22813),tS=r(80685),tC=r(92387),tA=r(13277),tI=r(99484),tE=r(76042);let tT={pending:{icon:Z.A,color:"text-[var(--muted-foreground)]",label:"Pending"},running:{icon:Q.A,color:"text-blue-400",label:"Running"},completed:{icon:tk.A,color:"text-emerald-400",label:"Done"},failed:{icon:tS.A,color:"text-red-400",label:"Failed"},skipped:{icon:tC.A,color:"text-[var(--muted-foreground)]",label:"Skipped"}};function tP(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)(()=>{k.send({type:"approve",planId:t.id})},[t.id]),p=(0,l.useCallback)(()=>{i.trim()&&(k.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)(V.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}):(0,n.jsx)(Y.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)(tD,{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)(tF,{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:O("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)(tA.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)(tI.A,{className:"h-3.5 w-3.5"}),"Reject"]})]})})]})]})}function tF(e){let{task:t,allTasks:r}=e,a=tT[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:O("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)(tE.A,{className:"h-3 w-3"}),(0,n.jsxs)("span",{children:["after: ",l.join(", ")]})]})]})]})}function tD(e){var t,r;let{status:a}=e;return(0,n.jsx)("span",{className:O("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 tM=r(10509),tL=r(93099),tR=r(13523);let t_=/\.(png|jpe?g|gif|webp|bmp|svg)$/i,tz=/\.(mp4|webm|mov|m4v|ogv)$/i,tO=/\.(mp3|wav|flac|aac|m4a|ogg|opus|amr|silk)$/i;function tW(e){return t_.test(e)?"image":tz.test(e)?"video":tO.test(e)?"audio":"file"}function tB(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":tW(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:tW(a)}),""})).replace(/\n{3,}/g,"\n\n").trim(),media:t}}function tU(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)(tK,{media:e,onOpen:()=>a(e)},"".concat(e.path,"-").concat(t)))}),r&&(0,n.jsx)(tJ,{media:r,onClose:()=>a(null)})]})}function tH(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 tK(e){var t;let{media:r,onOpen:a}=e,s=tx(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),l=tH(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)(tG,{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)(tG,{kind:r.kind}),o]})}function tG(e){let{kind:t}=e,r="h-3 w-3";return"image"===t?(0,n.jsx)(tM.A,{className:r}):"video"===t?(0,n.jsx)(tL.A,{className:r}):"audio"===t?(0,n.jsx)(tR.A,{className:r}):(0,n.jsx)(ea.A,{className:r})}function tJ(e){var t;let{media:r,onClose:a}=e,s=tx(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),o=tH(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)(eR.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)(e1.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 tq(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 tZ=0,tV=null;function tY(e){var t;return"system"!==e.role||"notification"!==ty(e)?null:"".concat(null!=(t=e.taskId)?t:"","\0").concat(e.content)}let t$=new Map,tQ=new Map;function tX(e){return null!=e?e:""}function t0(e,t){if("assistant"===e.role&&e.streaming&&t$.set(tX(e.taskId),t),e.toolCalls)for(let r of e.toolCalls)r.toolUseId&&tQ.set(r.toolUseId,t);if(e.contentBlocks)for(let r of e.contentBlocks)"tool_call"===r.type&&r.toolCall.toolUseId&&tQ.set(r.toolCall.toolUseId,t)}function t1(e){t$.clear(),tQ.clear();for(let t=0;t<e.length;t++)t0(e[t],t)}function t5(e){for(let[t,r]of t$){let a=e[r];a&&"assistant"===a.role&&a.streaming&&tX(a.taskId)===t||t$.delete(t)}}function t3(e,t){let r=tX(t),a=t$.get(r);if(void 0!==a){let r=e[a];if(r&&"assistant"===r.role&&r.streaming&&r.taskId===t)return a}for(let a=e.length-1;a>=0;a--){let s=e[a];if("assistant"===s.role&&s.streaming&&s.taskId===t)return t$.set(r,a),a}return t$.delete(r),-1}function t2(e,t,r,a){if(!a)return{messages:e,slotIdx:t3(e,r),copied:!1};let s=t3(e,r),n=-1===s?void 0:e[s];if(n&&!(t&&n.agentName&&n.agentName.toLowerCase()!==t.toLowerCase())){var l;let o=null!=(l=n.contentBlocks)?l:[],i=o.length>0?o[o.length-1].turnId:void 0;if(!i||i===a)return{messages:e,slotIdx:s,copied:!1};let c=[...e];return c[s]={...n,streaming:!1},c.push({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}),t$.set(tX(r),c.length-1),{messages:c,slotIdx:c.length-1,copied:!0}}let o=[...e,{id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}];return t$.set(tX(r),o.length-1),{messages:o,slotIdx:o.length-1,copied:!0}}let t4=(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:W(),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=>{let r=tY(s);return null!==r&&function(e,t){for(let r=e.length-1;r>=0;r--){let a=tY(e[r]);if(null===a)break;if(a===t)return!0}return!1}(e.messages,r)?e:(t0(s,e.messages.length),{messages:[...e.messages,s],isStreaming:!!t.streaming&&!t.taskId||e.isStreaming})})},appendThinking(t,r,a,s){e(e=>{var n;let l=t2(e.messages,r,a,s);if(-1===l.slotIdx)return e;let o=l.copied?l.messages:[...l.messages],i=o[l.slotIdx],c=[...null!=(n=i.contentBlocks)?n:[]],d=c[c.length-1];return d&&"thinking"===d.type&&(!s||d.turnId===s)?c[c.length-1]={type:"thinking",text:d.text+t,turnId:null!=s?s:d.turnId}:c.push({type:"thinking",text:t,turnId:s}),o[l.slotIdx]={...i,contentBlocks:c},{messages:o}})},updateLastAssistant(t,r,a,s){e(e=>{var n;let l=t2(e.messages,r,a,s);if(-1===l.slotIdx)return e;let o=l.copied?l.messages:[...l.messages],i=o[l.slotIdx],c=[...null!=(n=i.contentBlocks)?n:[]],d=c[c.length-1];return d&&"text"===d.type&&(!s||d.turnId===s)?c[c.length-1]={type:"text",text:d.text+t,turnId:null!=s?s:d.turnId}:c.push({type:"text",text:t,turnId:s}),o[l.slotIdx]={...i,content:i.content+t,contentBlocks:c},a?{messages:o}:{messages:o,isStreaming:!0}})},addToolCallToLastAssistant(t,r,a,s){e(e=>{var n,l;if(t.toolUseId&&tQ.has(t.toolUseId))return e;let o=t2(e.messages,r,a,s);if(-1===o.slotIdx)return e;let i=o.copied?o.messages:[...o.messages],c=i[o.slotIdx],d=[...null!=(n=c.contentBlocks)?n:[]];return d.push({type:"tool_call",toolCall:t,turnId:s}),i[o.slotIdx]={...c,toolCalls:[...null!=(l=c.toolCalls)?l:[],t],contentBlocks:d},t.toolUseId&&tQ.set(t.toolUseId,o.slotIdx),{messages:i}})},updateLastToolCallResult(t,r,a,s){e(e=>{var r,n,l,o,i,c,d;if(s){let r=null!=(o=tQ.get(s))?o:-1,a=-1===r?void 0:e.messages[r],d=null!=(i=null==a||null==(n=a.toolCalls)?void 0:n.findIndex(e=>e.toolUseId===s))?i:-1,u=null!=(c=null==a||null==(l=a.contentBlocks)?void 0:l.findIndex(e=>"tool_call"===e.type&&e.toolCall.toolUseId===s))?c:-1;if(a&&(-1!==d||-1!==u)){if(-1!==d&&void 0!==a.toolCalls[d].output||-1!==u&&void 0!==a.contentBlocks[u].toolCall.output)return e;let s=a.toolCalls?[...a.toolCalls]:a.toolCalls;s&&-1!==d&&(s[d]={...s[d],output:t});let n=a.contentBlocks?[...a.contentBlocks]:a.contentBlocks;if(n&&-1!==u){let e=n[u];n[u]={type:"tool_call",toolCall:{...e.toolCall,output:t},turnId:e.turnId}}let l=[...e.messages];return l[r]={...a,toolCalls:s,contentBlocks:n},{messages:l}}}let u=t3(e.messages,a),m=-1===u?void 0:e.messages[u];if(!m||!(null==(r=m.toolCalls)?void 0:r.length))return e;let x=[...m.toolCalls],p=x.findIndex(e=>void 0===e.output);-1!==p&&(x[p]={...x[p],output:t});let h=[...null!=(d=m.contentBlocks)?d:[]];for(let e=0;e<h.length;e++){let r=h[e];if("tool_call"===r.type&&void 0===r.toolCall.output){h[e]={type:"tool_call",toolCall:{...r.toolCall,output:t},turnId:r.turnId};break}}let f=[...e.messages];return f[u]={...m,toolCalls:x,contentBlocks:h},{messages:f}})},completeStreaming(){e(e=>{let t=e.messages.map(e=>e.streaming?{...e,streaming:!1}:e);return t5(t),{messages:t,isStreaming:!1}})},completeAgentStreaming(t,r){e(e=>{let a=e.messages.filter(tN).length,s=e.messages.map(e=>e.streaming?(!r||e.taskId!==r)&&(r||e.taskId)?e:{...e,streaming:!1}:e),n=s.filter(tN).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)),t5(s),{messages:s,isStreaming:l}})},setSessionId(t){e({sessionId:t})},setMessages(t){t1(t),e({messages:t})},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 t5(a),{messages:a,isStreaming:a.some(e=>e.streaming&&!e.taskId)}})},convergeStaleStreaming(){if(t().isCompacting||0===tZ)return;let r=Date.now(),a=e=>e.timestamp<=tZ&&tq(e,r);t().messages.some(a)&&e(e=>{let t=e.messages.map(e=>a(e)?{...e,streaming:!1,interrupted:!0}:e);return t5(t),{messages:t,isStreaming:t.some(e=>e.streaming&&!e.taskId)}})},clear(){t1([]),e({messages:[],isStreaming:!1,pendingMessages:[],sessionId:null,contextTokens:0,outputTokens:0})}})),t8=(0,c.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function t6(e,t){let r=t8.getState();r.sessionId===e&&t<=r.anchor||t8.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}async function t9(){var e,t;let r=null==(e=tx.getState().activeProject)?void 0:e.id,{sessionId:a,cursor:s,loading:n}=t8.getState();if(r&&a&&!(s<1)&&!n){t8.setState({loading:!0});try{let e=await w.F.sessionLogs.archiveSegment(a,s,r),n=t8.getState();if(n.sessionId!==a||n.cursor!==s)return;t8.setState({messages:[...null!=(t=e.messages)?t:[],...n.messages],cursor:s-1,loading:!1})}catch(t){let e=t8.getState();e.sessionId===a&&e.cursor===s&&t8.setState({loading:!1})}}}function t7(){let e=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));return{useBus:e,bump:()=>e.getState().bump()}}let re=t7(),rt=re.useBus,rr=re.bump;var ra=r(89983),rs=r(66926),rn=r(63865),rl=r(76688),ro=r(87097);let ri=(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 rc(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 rd(e){let t=0;for(let r of e)t+=1+rd(r.children);return t}function ru(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=(0,eZ.kj)(),h=12+16*r;return(0,n.jsx)(n.Fragment,{children:t.map(e=>{let t=s===e.id,f=!!e.stoppedAt,g=!!e.archivedAt,v=e.children.length>0,b=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:O("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",g&&"opacity-50"),style:{paddingLeft:"".concat(h,"px")},children:[v?(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)(Y.A,{className:O("h-2.5 w-2.5 text-[var(--muted-foreground)] transition-transform",b&&"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"]}),f&&(0,n.jsx)("span",{title:"Stopped",children:(0,n.jsx)(ra.A,{className:"h-2.5 w-2.5 shrink-0 text-[var(--muted-foreground)]"})}),g&&(0,n.jsx)("span",{title:"Archived",children:(0,n.jsx)(rs.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),v&&(0,n.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",rd(e.children)]})]}),(0,n.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.exchangeCount," msgs \xb7 ",K(e.updatedAt,p)]})]}),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)(e_.A,{className:"h-2.5 w-2.5"})})]}),b&&v&&(0,n.jsx)(ru,{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 rm=e=>"halo_selected_session_".concat(e);function rx(e){let t=[];return!function e(r){for(let a of r)t.push(a),e(a.children)}(e),t}function rp(){let e=(0,eZ.kj)(),t=t4(e=>e.isStreaming),r=t4(e=>e.sessionId),a=tx(e=>e.activeProject),{selectedSessionId:s,setSelectedSession:o,clearSelection:i,setLoadedMessages:c,setLoading:d}=ri(),[u,m]=(0,l.useState)([]),[x,p]=(0,l.useState)(null),h=(0,l.useRef)(0),[f,g]=(0,l.useState)(new Set),[v,b]=(0,l.useState)(!0),[j,y]=(0,l.useState)(!1),N=(0,l.useRef)(null),[S,C]=(0,l.useState)(null),[A,I]=(0,l.useState)(""),E=(0,l.useRef)(""),T=(0,l.useRef)(null),P=(0,l.useRef)(!1);(0,l.useEffect)(()=>{(null==a?void 0:a.id)&&N.current&&N.current!==a.id&&(i(),N.current=null)},[null==a?void 0:a.id,i]);let F=(0,l.useCallback)(async function(){let{showSpinner:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showSpinner:!0};if(!(null==a?void 0:a.path)){m([]),p(null),b(!1);return}if(null!==T.current){P.current=!0;return}P.current=!1,e&&b(!0);let t=Math.min(300,Math.max(30,h.current)),r=Date.now();try{let e=await w.F.sessionLogs.list(a.path,{includeArchived:!0,limit:t}),r=e.sessions;m(rc(r)),p(e.nextCursor)}catch(e){console.error("[Sessions] Failed to fetch:",e),m([]),p(null)}finally{e?setTimeout(()=>b(!1),Math.max(0,350-(Date.now()-r))):b(!1)}},[null==a?void 0:a.path]),D=(0,l.useCallback)(async()=>{if((null==a?void 0:a.path)&&null!==x&&!j){y(!0);try{let e=await w.F.sessionLogs.list(a.path,{includeArchived:!0,limit:30,cursor:x}),t=e.sessions;m(e=>{let r=rx(e),a=new Set(r.map(e=>e.id)),s=[...r,...t.filter(e=>!a.has(e.id))];return rc(s)}),p(e.nextCursor)}catch(e){console.error("[Sessions] loadMore failed:",e)}finally{y(!1)}}},[null==a?void 0:a.path,x,j]);(0,l.useEffect)(()=>{h.current=u.length,u.length>=300&&p(null)},[u.length]);let M=rt(e=>e.version),L=(0,l.useRef)(!0);(0,l.useEffect)(()=>{F({showSpinner:L.current}),L.current=!1},[F,M]),(0,l.useEffect)(()=>{s&&!v&&!new Set(rx(u).map(e=>e.id)).has(s)&&(i(),(null==a?void 0:a.id)&&localStorage.removeItem(rm(a.id)))},[u,s,v,i,null==a?void 0:a.id]);let R=(0,l.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),_=(0,l.useCallback)(async e=>{let t=ri.getState();if(t.selectedSessionId!==e.id||null===t.loadedMessages&&!t.loading){if(o(e),d(!0),(null==a?void 0:a.id)&&localStorage.setItem(rm(a.id),e.id),e.id===r)return void c(t4.getState().messages);try{var s;let t=await w.F.sessionLogs.get(e.id,null==a?void 0:a.path);t6(e.id,"number"==typeof t.archiveCount?t.archiveCount:0),c(null!=(s=t.messages)?s:[])}catch(t){console.error("[Sessions] Load failed:",t),t6(e.id,0),c([])}}},[r,null==a?void 0:a.id,null==a?void 0:a.path,o,c,d]);(0,l.useEffect)(()=>{if(!(null==a?void 0:a.id)||v||0===u.length||N.current===a.id)return;N.current=a.id;let e=localStorage.getItem(rm(a.id));if(!e)return;let t=rx(u),r=t.find(t=>t.id===e);if(!r)return;let s=new Map(t.map(e=>[e.id,e])),n=[],l=r;for(;null==l?void 0:l.parentSessionId;)n.push(l.parentSessionId),l=s.get(l.parentSessionId);n.length>0&&g(e=>{let t=new Set(e);for(let e of n)t.add(e);return t}),_(r)},[null==a?void 0:a.id,v,u,_]);let z=(0,l.useCallback)(e=>{a&&(t4.getState().setSessionId(e.id),t4.getState().setMessages([]),k.send({type:"subscribe",sessionId:e.id,projectId:a.id}),localStorage.setItem("halo_session_".concat(a.id),e.id))},[a]),W=(0,l.useCallback)(async(e,t)=>{if((e.stopPropagation(),null==a?void 0:a.path)&&await H("Delete this session and all its sub-sessions? History cannot be recovered."))try{m(e=>e.filter(e=>e.id!==t)),t===r&&((null==a?void 0:a.id)&&localStorage.removeItem("halo_session_".concat(a.id)),t4.getState().clear()),s===t&&(i(),(null==a?void 0:a.id)&&localStorage.removeItem(rm(a.id))),await w.F.sessionLogs.delete(t,a.path),rr()}catch(e){console.error("[Sessions] Delete failed:",e),rr()}},[r,null==a?void 0:a.path,null==a?void 0:a.id,s,i]),B=(0,l.useCallback)((e,t)=>{e.stopPropagation(),T.current=t.id,E.current=t.title||"",C(t.id),I(t.title||"")},[]),U=(0,l.useCallback)(()=>{T.current=null,C(null),I(""),P.current&&F({showSpinner:!1})},[F]),G=(0,l.useCallback)(async e=>{if(T.current!==e)return;let t=A.trim();if(!t||t===E.current||!(null==a?void 0:a.path))return void U();T.current=null,C(null),m(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 w.F.sessionLogs.rename(e,t,a.path),rr()}catch(e){console.error("[Sessions] Rename failed:",e),rr()}},[A,null==a?void 0:a.path,U]),J=u.length,q=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=q.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&D()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[D,u.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)(rn.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,n.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Sessions"}),J>0&&(0,n.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",J,null!==x?"+":"",")"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>F(),disabled:v,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh sessions",children:(0,n.jsx)(rl.A,{className:O("h-3.5 w-3.5",v&&"animate-spin")})}),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:"running"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:v?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(Q.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading..."]}):0===u.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,n.jsx)(rn.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:[u.map(t=>{let a=t.children,l=f.has(t.id),o=t.id===r,i=s===t.id,c=!!t.archivedAt,d=a.length>0,u=rd(a);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>_(t),onDoubleClick:()=>z(t),title:"Click to preview, double-click to load into chat",className:O("group flex w-full items-center gap-1.5 px-3 py-2 text-left border-b border-[var(--border)]/30 transition-colors",i?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",c&&"opacity-50"),children:[d?(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),R(t.id)},className:"shrink-0 flex items-center justify-center w-5 h-5 -ml-1 cursor-pointer rounded hover:bg-[var(--muted)]/50",children:(0,n.jsx)(Y.A,{className:O("h-3 w-3 text-[var(--muted-foreground)] transition-transform",l&&"rotate-90")})}):(0,n.jsx)("span",{className:"w-5 shrink-0 -ml-1"}),(0,n.jsx)(ro.A,{className:O("h-3.5 w-3.5 shrink-0",o?"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:[S===t.id?(0,n.jsx)("input",{autoFocus:!0,value:A,onChange:e=>I(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),G(t.id)):"Escape"===e.key&&(e.preventDefault(),U())},onBlur:()=>G(t.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:t.title||"Untitled"}),o&&(0,n.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1 py-0.5 text-[8px] text-blue-400",children:"active"}),c&&(0,n.jsx)("span",{title:"Archived",children:(0,n.jsx)(rs.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),d&&(0,n.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",u]})]}),(0,n.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[t.exchangeCount," msgs \xb7 ",K(t.updatedAt,e)]})]}),S!==t.id&&(0,n.jsx)("button",{onClick:e=>B(e,t),title:"Rename",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-blue-400 transition-opacity",children:(0,n.jsx)(e_.A,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:e=>W(e,t.id),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:(0,n.jsx)(eP.A,{className:"h-3 w-3"})})]}),l&&d&&(0,n.jsx)(ru,{nodes:a,depth:1,expanded:f,selectedSessionId:s,onToggle:R,onSelect:_,editingId:S,editingTitle:A,setEditingTitle:I,onStartRename:B,onCommitRename:G,onCancelRename:U})]},t.id)}),null!==x&&(0,n.jsx)("div",{ref:q,className:"flex items-center justify-center py-2 text-[10px] text-[var(--muted-foreground)]",children:j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin mr-1"})," Loading more…"]}):(0,n.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})})]})}var rh=r(72140),rf=r(68709),rg=r(6843);function rv(e){var t;let r=null==(t=tx.getState().activeProject)?void 0:t.id;if(!r)return null;let a=t4.getState();if(a.sessionId&&a.messages.some(t=>t.id===e))return a.sessionId.includes(">")?null:{sessionId:a.sessionId,projectId:r};let s=ri.getState().selectedSessionId;return s&&!s.includes(">")?{sessionId:s,projectId:r}:null}function rb(e){let{messages:t,debugMode:r,readOnly:a,userOrdinalBase:s}=e;return(0,n.jsx)(rj,{messages:t,debugMode:r,readOnly:a,userOrdinalBase:s})}function rj(e){let{messages:t,debugMode:r,readOnly:a,userOrdinalBase:s}=e,o=(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]),i=(0,l.useMemo)(()=>{if(a)return!1;let e=t.find(e=>"user"===e.role);return!!e&&null!==rv(e.id)},[t,a]),c=null!=s?s:0;return(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>{let t="user"===e.user.role?c++:-1;return(0,n.jsx)(ry,{user:e.user,responses:e.responses,debugMode:r,userOrdinal:t,deletable:i},e.user.id)})})}let ry=(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:O("border-b border-[var(--border)]/50 last:border-b-0",o&&"opacity-50"),children:["user"===t.role?rk(t.content)?(0,n.jsx)(rS,{content:t.content,userOrdinal:s,deleted:o,messageId:t.id,deletable:l}):rC(t.content)?(0,n.jsx)(rA,{content:t.content,userOrdinal:s,deleted:o,messageId:t.id,deletable:l}):(0,n.jsx)(rF,{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)(rT,{message:t,debugMode:a})}),r.length>0&&(0,n.jsx)(rI,{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 rw(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=rv(s);e&&await H("Delete this message and its responses from the conversation? The agent will no longer see this exchange.")&&k.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)(rh.A,{className:"h-3 w-3 text-emerald-400"}):(0,n.jsx)(rf.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)(eP.A,{className:"h-3 w-3"})})]})}let rN="rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400";function rk(e){let t=e.match(/^\(from: session ([^)]+)\)\n([\s\S]*)$/);return t?{sessionId:t[1],body:t[2]}:null}function rS(e){var t;let{content:r,...a}=e,s=rk(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)(rw,{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:rN,children:"deleted"})]}),(0,n.jsx)(rO,{maxLines:4,children:(0,n.jsx)("div",{className:"text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed",children:s.body})})]})}function rC(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 rA(e){let{content:t,...r}=e,a=rC(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)(rw,{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)(V.A,{className:"h-3 w-3"}):(0,n.jsx)(Y.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:rN,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 rI(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"===ty(e)&&e.usage);if(0===n.length)return s;let l=new Map;for(let e of t)if("assistant"===ty(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"===ty(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)(rT,{message:e,debugMode:r,usages:a.get(e.id)},e.id))})}function rE(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=e=>e.toString().padStart(2,"0"),b="".concat(v(g.getMonth()+1),"-").concat(v(g.getDate())," ").concat(v(g.getHours()),":").concat(v(g.getMinutes()),":").concat(v(g.getSeconds()));return(0,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:b}),(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 rT(e){var t,r,a,s;let{message:o,debugMode:i,usages:c}=e,d=(0,eZ.kj)(),u=ty(o),m="assistant"===u,x=(0,l.useMemo)(()=>{if(!i||!m||!(null==c?void 0:c.length))return null;let e=new Map;for(let t of c)t.turnId&&e.set(t.turnId,t);return e.size>0?e:null},[i,m,c]);if("tool_call"===u||"tool_result"===u||"usage"===u||"context"===u)return null;if("agent_start"===u||"agent_done"===u)return i?(0,n.jsx)("div",{className:"my-0.5 px-1",children:(0,n.jsxs)("span",{className:O("inline-block rounded px-1.5 py-0.5 text-[9px]","agent_start"===u?"bg-blue-900/40 text-blue-400":"bg-emerald-900/40 text-emerald-400"),children:[null!=(a=o.agentName)?a:"Agent",": ",o.content||("agent_start"===u?"started":"done")]})}):null;let p=m&&o.contentBlocks&&o.contentBlocks.length>0,h=p?o.contentBlocks.filter(e=>"tool_call"===e.type).length:0;if(o.interrupted&&!o.content&&!(null==(t=o.toolCalls)?void 0:t.length))return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,n.jsx)(rg.A,{className:"h-3 w-3 text-amber-400"}),(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:d("chat.interrupted")})]});if(o.streaming&&!o.content&&!(null==(r=o.toolCalls)?void 0:r.length))return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,n.jsx)(Q.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 f=[];if(p){let e=o.contentBlocks,t=0;for(let r=0;r<e.length;r++){let a=e[r];if("thinking"===a.type&&a.text.trim()&&i?f.push((0,n.jsx)(rP,{text:a.text},"b".concat(r))):"text"===a.type&&a.text.trim()?f.push((0,n.jsx)(rD,{text:a.text},"b".concat(r))):"tool_call"===a.type&&(t++,f.push((0,n.jsx)(rz,{call:a.toolCall,isStreaming:o.streaming,isLast:t===h},"b".concat(r)))),x&&a.turnId){let t=null==(s=e[r+1])?void 0:s.turnId;if(!t||t!==a.turnId){let e=x.get(a.turnId);e&&f.push((0,n.jsx)(rE,{message:e},"u".concat(a.turnId)))}}}if(x){let t=new Set(e.map(e=>e.turnId).filter(Boolean));for(let[e,r]of x)t.has(e)||f.push((0,n.jsx)(rE,{message:r},"u".concat(e)))}}else{if(m&&o.toolCalls&&o.toolCalls.length>0&&o.toolCalls.forEach((e,t)=>{f.push((0,n.jsx)(rz,{call:e,isStreaming:o.streaming,isLast:t===o.toolCalls.length-1},"tc".concat(t)))}),x)for(let[e,t]of x)f.push((0,n.jsx)(rE,{message:t},"u".concat(e)));if(o.content){let e=!m&&/^Compacting context /.test(o.content);f.push(m?(0,n.jsx)(rD,{text:o.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)(Q.A,{className:"h-3 w-3 animate-spin shrink-0"}),(0,n.jsx)("span",{className:"whitespace-pre-wrap",children:o.content})]},"txt"):(0,n.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] whitespace-pre-wrap",children:o.content},"txt"))}}return o.plan&&f.push((0,n.jsx)("div",{className:"mt-2",children:(0,n.jsx)(tP,{plan:o.plan})},"plan")),(0,n.jsx)("div",{className:"py-1",children:f})}function rP(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)(V.A,{className:"h-3 w-3"}):(0,n.jsx)(Y.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 rF(e){let{content:t,localImages:r,userOrdinal:a,deleted:s,messageId:o,deletable:i,sendFailed:c}=e,d=(0,eZ.kj)(),{text:u,media:m}=(0,l.useMemo)(()=>tB(t),[t]),[x,p]=(0,l.useState)(null);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:O("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:O("mr-1",rN),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)(rg.A,{className:"h-2.5 w-2.5"}),d("chat.sendFailedBadge")]}),(0,n.jsx)(rw,{copyText:u,userOrdinal:a,deleted:s,messageId:o,deletable:i})]}),(0,n.jsx)(rO,{maxLines:2,toggleClassName:"top-auto bottom-0",children:(0,n.jsx)("div",{className:O("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)(tU,{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 rD(e){let{text:t}=e,{text:r,media:a}=(0,l.useMemo)(()=>tB(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)(eK.oz,{remarkPlugins:[eG.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)(rW,{className:t,children:r}):(0,n.jsx)("code",{className:t,...s,children:r})}},children:s}),(0,n.jsx)(tU,{media:a})]})}function rM(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t?t:null}catch(e){return null}}let rL="__TOOL_ERROR__",rR="__TOOL_WARN__",r_={running:"bg-amber-400 animate-pulse",success:"bg-emerald-400",warn:"bg-yellow-400",error:"bg-red-400"};function rz(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(rL)?"error":s.startsWith(rR)?"warn":"success"}(t,r,0),c=void 0!==t.output&&""!==t.output,{summary:d}=(0,l.useMemo)(()=>(function(e,t){let r=rM(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=rM(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(rL+"\n")?e.slice(rL.length+1):e.startsWith(rR+"\n")?e.slice(rR.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:O("h-2 w-2 shrink-0 rounded-full",r_[i])}),s?(0,n.jsx)(V.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}):(0,n.jsx)(Y.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:O("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)(Q.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 rO(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:O("relative",a),children:[i&&(0,n.jsx)("button",{onClick:()=>u(!d),className:O("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 rW(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:"block mb-1 text-[9px] leading-none 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)(rh.A,{className:"h-3 w-3 text-emerald-400"}):(0,n.jsx)(rf.A,{className:"h-3 w-3"})}),(0,n.jsx)("code",{className:r,children:t})]})}var rB=r(62783),rU=r(14307),rH=r(51456),rK=r(93436),rG=r(48931),rJ=r(56838);function rq(e){return"halo_goal_dismissed_".concat(e)}let rZ=(0,c.v)(e=>({goal:null,dismissedGoalId:null,setGoal:t=>e({goal:t}),dismiss:t=>{var r;e({dismissedGoalId:t});let a=null==(r=tx.getState().activeProject)?void 0:r.id;a&&localStorage.setItem(rq(a),t)}}));async function rV(e){let t=localStorage.getItem(rq(e));rZ.setState({dismissedGoalId:t});try{var r;let t=await w.F.sessionLogs.goal(e);rZ.getState().setGoal(null!=(r=t.goal)?r:null)}catch(e){}}let rY=[{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"}],r$=[];async function rQ(e,t,r){try{r$=(await w.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){r$=[]}}function rX(){return r$.length>0?r$:rY}function r0(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 r1(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=ev(e),i=s?q.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:O("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:O("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 r5(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 r3(e){if(!e.type.startsWith("image/"))return{base64:await r5(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 r5(e),mimeType:e.type||"image/png"}}}let r2=null,r4=null,r8=".halo/canvas/self.html";function r6(){let e=(0,eZ.kj)(),t=tx(e=>e.activeProject);if(!t)return null;let r=async()=>{let e=t.id;try{let t=await w.F.files.read(r8,e);window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}})),v.getState().openFile(r8,t.content,J(r8),t.modifiedAt,{size:t.size,createdAt:t.createdAt}),setTimeout(()=>e$("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)(rB.A,{className:"h-4 w-4"})})}function r9(e){var t;let{cameras:r,activeId:a,onPick:s,onTurnOff:o,onClose:i}=e,c=(0,eZ.kj)(),[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)(e1.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:O("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)(rU.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 r7(){let e=(0,eZ.kj)(),t=t4(e=>e.captureSource),r=t4(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,v]=(0,l.useState)([]),[b,j]=(0,l.useState)(!1),y=(0,l.useRef)(null),N=window.haloCapture,k=window.haloCamera,S=function(){let e=t4(e=>e.selectedAgentId),t=tx(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([w.F.agentConfigs.list(t),r2?Promise.resolve(r2):(!r4&&(r4=w.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 r2=t,t}).catch(()=>({}))),r4)]).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&&!b)return;let e=e=>{y.current&&!y.current.contains(e.target)&&(s(!1),j(!1))},t=e=>{"Escape"===e.key&&(s(!1),j(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a,b]),!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),j(!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 j(e=>!e);if(!await k.requestPermission())return void f(!0);let e=await k.list();if(0===e.length)return void A("",void 0);v(e),j(!0)};return(0,n.jsxs)("div",{ref:y,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:O("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)(rH.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:O("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)(rU.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)(rU.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)(rH.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)(e1.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")})]})]}),b&&g.length>=1&&(0,n.jsx)(r9,{cameras:g,activeId:(null==t?void 0:t.kind)==="camera"?t.id:null,onPick:e=>A(e.deviceId,e.label),onTurnOff:(null==t?void 0:t.kind)==="camera"?()=>{r(null),j(!1)}:void 0,onClose:()=>j(!1)}),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)(e1.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 ae(e){let{onCompact:t}=e,r=t4(e=>e.messages),a=t4(e=>e.contextTokens),s=t4(e=>e.maxContextTokens),o=t4(e=>e.isCompacting),i=t4(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:O("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:O("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 at(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,eZ.kj)(),p=v(e=>e.selectedText),h=v(e=>e.selectedRange),f=v(e=>e.activeTab),g=v(e=>e.contextEnabled),b=v(e=>e.setContextEnabled),[j,y]=(0,l.useState)(""),[N,k]=(0,l.useState)([]),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(0),[E,T]=(0,l.useState)([]),[P,F]=(0,l.useState)(0),[D,M]=(0,l.useState)(0),[L,R]=(0,l.useState)(!1),_=(0,l.useRef)(null),z=(0,l.useRef)(null),W=tx(e=>e.activeProject),B=0===t4(e=>e.usableAgentCount),U=rZ(e=>e.goal),H=t4(e=>e.sessionId),K=!!U&&("intake"===U.status||"running"===U.status)&&H===U.workerSessionId,G=K&&!j.trim().startsWith("/"),J=(0,l.useMemo)(()=>{var e,t;if(p&&f){let t=null!=(e=f.split("/").pop())?e:f,r=h?":".concat(h.startLine,"-").concat(h.endLine):"";return"".concat(t).concat(r," (").concat(p.length," chars)")}return f?null!=(t=f.split("/").pop())?t:f:null},[p,h,f]),q=(0,l.useMemo)(()=>{if(!j.startsWith("/")||/\s/.test(j))return[];if(!j.startsWith("/"))return[];let e=j.toLowerCase();return rX().filter(t=>t.name.startsWith(e))},[j]),Z=(0,l.useMemo)(()=>(function(e){var t;let r=e.match(/^(\/\S+)\s+(\S*)$/);if(!r)return[];let a=rX().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}))})(j),[j]),[V,Y]=(0,l.useState)(0);(0,l.useEffect)(()=>{Y(0)},[Z.length]);let $=(0,l.useCallback)(e=>{var t;y("".concat(e.cmd.name," ").concat(e.verb.name," ")),null==(t=_.current)||t.focus()},[]),Q=(0,l.useMemo)(()=>{let e=j.slice(0,D).match(/(^|\s)@scope\s+(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,D]),X=(0,l.useMemo)(()=>{if(Q)return null;let e=j.slice(0,D).match(/(^|\s)@(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,D,Q]),[ee,et]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(!X||L||!W)return void et([]);let e=!1,t=setTimeout(()=>{w.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,L,W]);let er=(0,l.useCallback)(e=>{if(!X)return;let t=j.slice(0,X.startIdx);y(t+j.slice(X.startIdx+1+X.query.length)),T(t=>t.includes(e)?t:[...t,e]),F(0),R(!1),requestAnimationFrame(()=>{if(_.current){let e=t.length;_.current.selectionStart=e,_.current.selectionEnd=e,_.current.focus(),M(e)}})},[j,X]),[ea,es]=(0,l.useState)([]),[en,el]=(0,l.useState)(0);(0,l.useEffect)(()=>{if(!Q||!W)return void es([]);let e=!1,t=setTimeout(()=>{w.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 eo=(0,l.useCallback)(e=>{if(!Q)return;let t=j.slice(0,Q.startIdx),r=j.slice(D),a="@scope ".concat(e," ");y(t+a+r),el(0),requestAnimationFrame(()=>{if(_.current){let e=t.length+a.length;_.current.selectionStart=e,_.current.selectionEnd=e,_.current.focus(),M(e)}})},[j,Q,D]),ei=(0,l.useCallback)(e=>{T(t=>t.filter(t=>t!==e))},[]),ec=(0,l.useCallback)(e=>{var t,r;let a=j.split(/\s+/),s=null!=(t=a[0])?t:"",n=a.slice(1).join(" ");if(e.argHint&&!n&&s!==e.name){y(e.name+" "),I(0),null==(r=_.current)||r.focus();return}null==d||d(e,n),y(""),I(0),_.current&&(_.current.style.height="auto")},[j,d]),ed=(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])},[]),eu=(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)})},[]),em=(0,l.useCallback)(async()=>{var e,r;let a=j.trim();if(!a&&0===N.length||B)return;if(Z.length>0)return void $(null!=(e=Z[V])?e:Z[0]);if(a.startsWith("/")){if(q.length>0)return void ec(null!=(r=q[A])?r:q[0]);let e=rX().find(e=>{var t;return e.name===(null==(t=a.split(/\s+/)[0])?void 0:t.toLowerCase())});if(e)return void ec(e)}if(K)return;let s=[];for(let e of N)try{let{base64:t,mimeType:r}=await r3(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,E.length>0?E:void 0),N.forEach(e=>{e.preview&&URL.revokeObjectURL(e.preview)}),k([]),T([]),y(""),_.current&&(_.current.style.height="auto")},[j,N,t,q,A,ec,E,Z,V,$,B,K]),ex=(0,l.useCallback)(e=>{if(ea.length>0){if("ArrowDown"===e.key){e.preventDefault(),el(e=>Math.min(e+1,ea.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),el(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=ea[en];t&&eo(t);return}if("Escape"===e.key){e.preventDefault(),es([]);return}}if(ee.length>0){if("ArrowDown"===e.key){e.preventDefault(),F(e=>Math.min(e+1,ee.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),F(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=ee[P];t&&er(t);return}if("Escape"===e.key){e.preventDefault(),R(!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(),y(""),I(0);return}if("Tab"===e.key){e.preventDefault();let t=q[A];t&&y(t.name+" ");return}}if("Escape"===e.key&&a&&!j.trim()&&o){e.preventDefault(),o();return}"Enter"!==e.key||e.nativeEvent.isComposing||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),em())},[em,q,A,Z,V,$,ee,P,er,ea,en,eo,a,j,o]),ep=(0,l.useCallback)(e=>{y(e.target.value),M(e.target.selectionStart),I(0),R(!1),F(0),el(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&&ed(e.dataTransfer.files)},[ed]),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(),ed(r))},[ed]);return(0,n.jsxs)("div",{className:O("relative px-3 pb-3 pt-1 transition-colors",S&&"bg-[var(--accent)]"),onDragOver:ef,onDragLeave:eg,onDrop:ev,children:[(0,n.jsx)(r0,{commands:q,selectedIndex:A,onSelect:ec}),(0,n.jsx)(r0,{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;y(e.name+" "),null==(t=_.current)||t.focus()}}),(0,n.jsx)(r1,{matches:ee,selectedIndex:P,onSelect:er}),(0,n.jsx)(r1,{matches:ea,selectedIndex:en,onSelect:eo,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:z,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&ed(e.target.files),e.target.value=""}}),(0,n.jsxs)("div",{className:O("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:_,value:j,onChange:ep,onKeyDown:ex,onPaste:eb,onSelect:e=>M(e.target.selectionStart),placeholder:B?"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=z.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)(rK.A,{className:"h-4 w-4"})}),(0,n.jsx)(r7,{}),(0,n.jsx)(r6,{}),(0,n.jsx)(ae,{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)(e1.A,{className:"h-2.5 w-2.5"})})]},"q-".concat(t))),J&&(0,n.jsx)("button",{onClick:()=>b(!g),title:g?"Click to exclude context":"Click to include context",className:O("flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] transition-colors",g?"bg-blue-500/10 border-blue-500/20 text-blue-400":"bg-[var(--background)] border-[var(--border)] text-[var(--muted-foreground)] line-through opacity-60"),children:(0,n.jsx)("span",{className:"max-w-36 truncate",children:J})}),E.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:()=>ei(e),className:"ml-0.5 rounded-full p-0.5 hover:bg-green-500/20 hover:text-green-300",children:(0,n.jsx)(e1.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)(eh.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:()=>eu(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)(e1.A,{className:"h-2.5 w-2.5"})})]},"f-".concat(t))),(0,n.jsx)("div",{className:"flex-1"}),a&&!j.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)(rG.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,n.jsx)("button",{onClick:em,disabled:B||G||!j.trim()&&0===N.length,title:B?"All agents are disabled — enable one to chat":G?x("goal.inputLocked"):a&&j.trim()?"Send (interrupts current response)":"Send (Enter)",className:O("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors",!B&&!G&&(j.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)(rJ.A,{className:"h-4 w-4"})})]})]})]})}let ar={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 aa(e){let{currentSessionId:t,onJump:r}=e,a=rZ(e=>e.goal),s=rZ(e=>e.dismissedGoalId),l=rZ(e=>e.dismiss),o=(0,eZ.kj)();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:O("flex items-center gap-2 border-t px-3 py-1.5 text-[11px]",ar[a.status]),children:[(0,n.jsx)("button",{onClick:()=>!d&&r(a.goalSessionId),title:d?void 0:o("goal.banner.jump"),className:O("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:O("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)(e1.A,{className:"h-3 w-3"})})]})}let as=new Map,an=(0,c.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function al(e,t,r){let a=an.getState();a.sessionId===e&&a.cursor===t&&an.setState({messages:[...r,...a.messages],cursor:t-1,loading:!1})}async function ao(){var e,t;let r=null==(e=tx.getState().activeProject)?void 0:e.id,{sessionId:a,cursor:s,loading:n}=an.getState();if(!r||!a||s<1||n)return;let l="".concat(a,"\0").concat(s),o=as.get(l);if(o)return void al(a,s,o);an.setState({loading:!0});try{let e=null!=(t=(await w.F.sessionLogs.archiveSegment(a,s,r)).messages)?t:[];if(as.size>=20){let e=as.keys().next().value;void 0!==e&&as.delete(e)}as.set(l,e),al(a,s,e)}catch(e){an.setState({loading:!1})}}var ai=r(54295);function ac(e){let{onLoadOlder:t,scrollRef:r}=e,a=(0,eZ.kj)(),s=t4(e=>e.sessionId),o=an(e=>e.sessionId),i=an(e=>e.anchor),c=an(e=>e.cursor),d=an(e=>e.messages),u=an(e=>e.loading),[m,x]=(0,l.useState)(!1),p=(0,l.useRef)(null);(0,l.useLayoutEffect)(()=>{let e=r.current,t=p.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,p.current=null)},[m,r]);let h=(0,l.useMemo)(()=>d.filter(tN),[d]);return null===o||o!==s||0===i?null:(0,n.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[c>0?(0,n.jsxs)("button",{onClick:t,disabled:u,className:"flex w-full items-center justify-center gap-1.5 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:hover:bg-transparent",children:[u&&(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin"}),a(u?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,n.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:a("chat.archive.noEarlier")}),h.length>0&&(0,n.jsxs)(n.Fragment,{children:[m&&(0,n.jsx)(rb,{messages:h,readOnly:!0}),(0,n.jsxs)("button",{onClick:()=>{let e=r.current;p.current=e?e.scrollHeight-e.scrollTop:null,x(!m)},className:"flex w-full items-center gap-2 border-t border-[var(--border)]/50 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[m?(0,n.jsx)(ai.A,{className:"h-3 w-3"}):(0,n.jsx)(Y.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:a("chat.archive.header",{segments:i-c,messages:h.length})})]})]})]})}function ad(e){return"halo_session_".concat(e)}let au="halo_session_id";function am(e){let t=localStorage.getItem(ad(e));if(t)return t;let r=localStorage.getItem(au);return r?(localStorage.setItem(ad(e),r),localStorage.removeItem(au),r):null}function ax(e,t){localStorage.setItem(ad(e),t)}function ap(e){localStorage.removeItem(ad(e))}var ah=r(28968),af=r(57580);function ag(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)(af.A,{className:"h-3 w-3"}),t," previous session",t>1?"s":""]})}function av(e){let{sessions:t,currentSessionId:r,loadingSessionId:a,onSelect:s,onDelete:o,onNew:i,onLoadMore:c,hasMore:d,loadingMore:u}=e,m=(0,eZ.kj)(),x=tx(e=>e.activeProject),[p,h]=(0,l.useState)(null),[f,g]=(0,l.useState)(""),v=(0,l.useRef)(null),b=(0,l.useRef)(""),j=()=>{v.current=null,h(null),g("")},y=async e=>{if(v.current!==e)return;let t=f.trim();if(!t||t===b.current||!(null==x?void 0:x.path))return void j();v.current=null,h(null);try{await w.F.sessionLogs.rename(e,t,x.path)}catch(e){console.error("[SessionSidebar] Rename failed:",e)}rr()},N=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=N.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:O("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:[p===e.id?(0,n.jsx)("input",{autoFocus:!0,value:f,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),y(e.id)):"Escape"===t.key&&(t.preventDefault(),j())},onBlur:()=>y(e.id),className:"w-full rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[11px] text-[var(--foreground)] outline-none focus:border-blue-500"}):(0,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.exchangeCount," msgs \xb7 ",K(e.updatedAt,m),"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)(Q.A,{className:"h-3 w-3 shrink-0 animate-spin text-[var(--muted-foreground)]"}):p!==e.id&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v.current=e.id,b.current=e.title||"",h(e.id),g(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)(e_.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)(eP.A,{className:"h-3 w-3"})})]})]},e.id)}),d&&(0,n.jsx)("div",{ref:N,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)(Q.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)(ah.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"New Session"})]})]})}let ab=t7(),aj=ab.useBus,ay=ab.bump;function aw(){var e,t;let r=t4(e=>e.selectedAgentId),a=t4(e=>e.sessionId),s=t4(e=>e.isStreaming),o=tx(e=>e.activeProject),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!1),m=(0,l.useRef)(null),x=aj(e=>e.version);(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&w.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),t4.getState().setUsableAgentCount(t.length);let r=t4.getState();!r.sessionId&&"default"===r.selectedAgentId&&t[0]&&"default"!==t[0].id&&r.setSelectedAgentId(t[0].id)}).catch(()=>{})},[null==o?void 0:o.path,x]),(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&rQ(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:O("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)(rn.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{className:"max-w-[80px] truncate",children:f}),!p&&(0,n.jsx)(V.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:()=>{t4.getState().setSelectedAgentId(e.id),u(!1)},className:O("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)(rn.A,{className:"h-3 w-3 shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]},"".concat(e.id,":").concat(e.scope)))})]})}let aN="halo_session_sidebar_open";function ak(){let e=(0,eZ.kj)(),{messages:t,sendMessage:r,isStreaming:a,clearSession:s,deleteSession:o,stopGeneration:i,interruptGeneration:c,pendingMessages:d,removePendingMessage:u,handleCommand:m,sessionId:x}=function(){let e=(0,eZ.kj)(),t=t4(e=>e.messages),r=t4(e=>e.isStreaming),a=t4(e=>e.sessionId),s=t4(e=>e.pendingMessages),n=tx(e=>e.activeProject);(0,l.useEffect)(()=>{if(!n)return;let e=n.id,t=am(e),r=t4.getState().sessionId;t&&t!==r?(t4.getState().setSessionId(t),t4.getState().setMessages([])):!t&&r&&t4.getState().clear();let a=t4.getState().sessionId;a&&k.connected&&k.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}=v.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:am(n.id))?l:W();a&&a===i||(t4.getState().setSessionId(i),ax(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=t4.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=t4.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=W();p.addMessage({id:W(),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:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let g=t4.getState().selectedAgentId;k.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)(()=>{k.send({type:"chat:stop",sessionId:a})},[a]),u=(0,l.useCallback)(()=>{k.send({type:"chat:interrupt",sessionId:a})},[a]),m=(0,l.useCallback)(e=>{t4.getState().removePendingMessage(e)},[]);(0,l.useEffect)(()=>{if(r)return;let e=t4.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:am(n.id);e&&k.send({type:"session:clear",sessionId:e}),ap(n.id),t4.getState().clear()},[n,a]),p=(0,l.useCallback)(e=>{n&&(k.send({type:"session:delete",sessionId:e,projectId:n.path}),e===(null!=a?a:am(n.id))&&(ap(n.id),t4.getState().clear()))},[n,a]),h=(0,l.useCallback)((e,t)=>{var r;if(!n)return;let s=null!=(r=null!=a?a:am(n.id))?r:W();a&&a===s||(t4.getState().setSessionId(s),ax(n.id,s));let l=e.name.slice(1),o=t4.getState().selectedAgentId,i={type:"command:".concat(l),sessionId:s,projectId:n.id,..."default"!==o?{agentId:o}:{}};t.trim()&&(i.message=t.trim()),k.send(i),t4.getState().addMessage({id:W(),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:p,stopGeneration:d,interruptGeneration:u,pendingMessages:s,removePendingMessage:m,handleCommand:h}}(),p=(0,l.useRef)(null),h=tx(e=>e.activeProject),[f,g]=(0,l.useState)(null),[b,j]=(0,l.useState)(0),[y,N]=(0,l.useState)(!1),[S,C]=(0,l.useState)(()=>"false"!==localStorage.getItem(aN)),{sessions:A,remove:I,loadMore:E,hasMore:T,loadingMore:P}=function(){let e=tx(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=rt(e=>e.version),c=(0,l.useCallback)(async()=>{if(!e){r([]),s(null);return}try{let t=await w.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 w.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 w.F.sessionLogs.delete(t,e),r(e=>e.filter(e=>e.id!==t)),rr()}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=>{C(e),localStorage.setItem(aN,String(e))},[]),D=(0,l.useCallback)(e=>{h&&(g(e),N(!1),j(e=>e+1),t4.getState().setSessionId(e),t4.getState().setMessages([]),k.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=k.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.id)&&rV(h.id)},[null==h?void 0:h.id]);let M=(0,l.useCallback)(()=>{g(null),N(!1),s()},[s]),L=(0,l.useCallback)(async(e,t)=>{t.stopPropagation(),await H("Delete this session? Its history cannot be recovered.")&&(o(e),await I(e))},[o,I]),R=(0,l.useMemo)(()=>t.filter(tN),[t]),_=(0,l.useRef)(!1);(0,l.useEffect)(()=>{_.current=!1},[x]);let z=(0,l.useMemo)(()=>{let e=0;for(let t of R)"user"===t.role&&e++;return e},[R]),[O,B]=(0,l.useState)({sessionId:null,hiddenTurns:0,seenTurns:0}),U=Math.max(0,z-30);O.sessionId!==(null!=x?x:null)?B({sessionId:null!=x?x:null,hiddenTurns:U,seenTurns:z}):(O.hiddenTurns>U||0===O.seenTurns&&z>0)&&B({sessionId:O.sessionId,hiddenTurns:U,seenTurns:z});let K=O.hiddenTurns;(0,l.useLayoutEffect)(()=>{O.seenTurns!==z&&B(e=>({sessionId:e.sessionId,hiddenTurns:_.current?e.hiddenTurns:Math.max(0,z-30),seenTurns:z}))});let G=(0,l.useMemo)(()=>{if(K<=0)return R;let e=0;for(let t=0;t<R.length;t++)if("user"===R[t].role&&++e>K)return R.slice(t);return R},[R,K]),J=(0,l.useRef)(null),q=(0,l.useCallback)(()=>{let e=p.current;J.current=e?e.scrollHeight-e.scrollTop:null,B(e=>({...e,hiddenTurns:Math.max(0,e.hiddenTurns-30)}))},[]);(0,l.useLayoutEffect)(()=>{let e=p.current,t=J.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,J.current=null)},[K]);let Z=(0,l.useRef)(null),V=(0,l.useRef)(!0),Y=(0,l.useCallback)(()=>{let e=p.current;Z.current=e?e.scrollHeight-e.scrollTop:null,ao()},[]),$=K>0;(0,l.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>{_.current=!(e.scrollHeight-e.scrollTop-e.clientHeight<80),e.scrollTop>200?V.current=!0:e.scrollTop<80&&V.current&&(V.current=!1,$?q():Y())};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[Y,q,$]);let X=an(e=>e.messages);return(0,l.useEffect)(()=>{let e=p.current,t=Z.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,Z.current=null)},[X]),(0,l.useEffect)(()=>{p.current&&!_.current&&(p.current.scrollTop=p.current.scrollHeight)},[R]),(0,l.useEffect)(()=>{let e=p.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{_.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:p,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)(Q.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}),y&&(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:()=>D(f),className:"text-[var(--primary)] hover:underline",children:"Retry"})]})]}):0===R.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)(ro.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)(ag,{count:A.length,onClick:()=>F(!0)})]}):(0,n.jsxs)(n.Fragment,{children:[K>0?(0,n.jsx)("button",{onClick:q,className:"flex w-full items-center justify-center gap-1.5 border-b border-[var(--border)]/50 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:e("chat.window.showEarlier",{count:K})}):(0,n.jsx)(ac,{onLoadOlder:Y,scrollRef:p}),(0,n.jsx)(rb,{messages:G,userOrdinalBase:K})]})}),(0,n.jsxs)("div",{className:"shrink-0",children:[(0,n.jsx)(aa,{currentSessionId:x,onJump:D}),(0,n.jsx)(at,{onSend:r,isStreaming:a,onStop:i,onInterrupt:c,pendingMessages:d,onRemovePending:u,onCommand:m,onCompact:()=>m({name:"/session",description:"",type:"server"},"compact"),renderLeftControls:()=>(0,n.jsxs)("div",{className:"relative flex items-center gap-0.5",children:[(0,n.jsxs)("button",{onClick:()=>F(!S),title:S?"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)(af.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:A.length})]}),(0,n.jsx)("button",{onClick:M,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)(ah.A,{className:"h-4 w-4"})}),(0,n.jsx)(aw,{})]})})]})]}),S&&(0,n.jsx)(av,{sessions:A,currentSessionId:x,loadingSessionId:f,onSelect:D,onDelete:L,onNew:M,onLoadMore:E,hasMore:T,loadingMore:P})]})}var aS=r(55499),aC=r(93345);let aA="halo_browser_id";function aI(){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 aE=null;function aT(){if(aE)return aE;try{let e=window.localStorage.getItem(aA);return e||(e=aI(),window.localStorage.setItem(aA,e)),aE=e,e}catch(e){return aE=aI()}}r(14113);let aP=0,aF={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"}},aD={fontFamily:"'JetBrains Mono', 'Fira Code', Menlo, Monaco, monospace",fontSize:13,lineHeight:1.4,cursorBlink:!0,scrollback:1e4};function aM(){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=tx(e=>e.activeProject),{theme:u}=(0,eO.useTheme)(),m=(0,l.useRef)(u);(0,l.useEffect)(()=>{for(let e of(m.current=u,a.current.values()))e.term.options.theme=aF[u]},[u]);let x=(0,l.useCallback)(e=>{var n,l,i,u;let x=r.current;if(!x)return;aP++;let p="term_".concat(Date.now().toString(36),"_").concat(aP),h=0===s.length?"bash":"bash (".concat(aP,")"),f=document.createElement("div");f.className="absolute inset-0",f.style.display="none",x.appendChild(f);let g=new aS.B({...aD,theme:aF[m.current]}),v=new aC.Y;g.loadAddon(v),g.open(f),v.fit(),g.onData(e=>{k.send({type:"terminal:input",data:e,terminalId:p})});let b=null,j=new ResizeObserver(()=>{v.fit(),b&&clearTimeout(b),b=setTimeout(()=>{k.send({type:"terminal:resize",cols:g.cols,rows:g.rows,terminalId:p})},150)});j.observe(f),a.current.set(p,{id:p,name:h,term:g,fit:v,container:f,ro:j,ready:!1,exited:!1});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 k.send({type:"terminal:start",terminalId:p,cwd:w,cols:g.cols,rows:g.rows,browserId:aT(),workspacePath:null!=(u=null==d?void 0:d.path)?u:""}),o(e=>[...e,{id:p,name:h}]),c(p),p},[d,s.length,t]),p=(0,l.useCallback)(e=>{let t=a.current.get(e);t&&(k.send({type:"terminal:close",terminalId:e}),t.ro.disconnect(),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}))},[]),h=(0,l.useCallback)(e=>{c(e)},[]);(0,l.useEffect)(()=>{let e=a.current;return()=>{for(let t of e.values())t.ro.disconnect(),t.term.dispose(),t.container.remove();e.clear()}},[]),(0,l.useEffect)(()=>{for(let[e,t]of 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(k.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(k.on("terminal:ready",e=>{let{terminalId:t}=e;if(t){let e=a.current.get(t);e&&(e.ready=!0)}})),e.push(k.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 f=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(f.current)return;f.current=!0;let e=k.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);k.send({type:"terminal:resize",cols:t.term.cols,rows:t.term.rows,terminalId:e});continue}if(!s)continue;aP++;let t=0===n&&0===a.current.size?"bash":"bash (".concat(aP,")");n++;let r=document.createElement("div");r.className="absolute inset-0",r.style.display="none",s.appendChild(r);let l=new aS.B({...aD,theme:aF[m.current]}),i=new aC.Y;l.loadAddon(i),l.open(r),i.fit(),l.write("\x1b[?2004h"),l.onData(t=>{k.send({type:"terminal:input",data:t,terminalId:e})});let d=null,u=new ResizeObserver(()=>{i.fit(),d&&clearTimeout(d),d=setTimeout(()=>{k.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})},150)});u.observe(r);let x={id:e,name:t,term:l,fit:i,container:r,ro:u,ready:!0,exited:!1};a.current.set(e,x),o(r=>[...r,{id:e,name:t}]),c(t=>null!=t?t:e),k.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})}0===t.length&&0===a.current.size&&x()}),t=()=>{var e;k.send({type:"terminal:reattach",browserId:aT(),workspacePath:null!=(e=null==d?void 0:d.path)?e:""})};t();let s=k.on("_connected",t),n=setTimeout(()=>{0===a.current.size&&x()},2e3);return()=>{clearTimeout(n),e(),s()}},[x]),(0,l.useEffect)(()=>{let e=v.getState().pendingTerminalCwd;return v.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:()=>h(e.id),className:O("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)(el.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(),p(e.id)},className:"rounded p-0.5 opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)]",children:(0,n.jsx)(e1.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)(ah.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:"New Terminal"})]})]})]})}var aL=r(90590);function aR(){let{cwd:e,floating:t=!1,dragHandleRef:r}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=(0,eZ.kj)(),s=v(e=>e.bottomTab),o=v(e=>e.setBottomTab),i=v(e=>e.setBottomFloating),c=v(e=>e.bottomMaximized),d=v(e=>e.setBottomMaximized),[u,m]=(0,l.useState)("terminal"===s);(0,l.useEffect)(()=>{"terminal"===s&&m(!0)},[s]);let[x,p]=(0,l.useState)(0);return(0,l.useEffect)(()=>k.on("_disconnected",()=>p(e=>e+1)),[]),(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{ref:r,className:O("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)(a_,{label:a("nav.chat"),active:"chat"===s,onClick:()=>o("chat")}),(0,n.jsx)(a_,{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)(th.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(tf.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)(e1.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(aL.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)(ak,{})}),(0,n.jsx)("div",{className:"terminal"===s?"h-full":"hidden",children:u&&(0,n.jsx)(aM,{headerless:!0,cwd:e},x)})]})]})}function a_(e){let{label:t,active:r,onClick:a}=e;return(0,n.jsxs)("button",{onClick:a,className:O("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 az(e){let{slotRef:t,dragHandleRef:r}=e,a=v(e=>e.bottomFloatRect),s=v(e=>e.setBottomFloatRect),o=v(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:aO(a.x+n,0,window.innerWidth-a.w),y:aO(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=aO(e.x,0,Math.max(0,window.innerWidth-e.w)),r=aO(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=aO(c.w+t,320,window.innerWidth-c.x)),n.bottom&&(x=aO(c.h+r,240,window.innerHeight-c.y)),n.left){let e=aO(c.x+t,0,d-320);a=e,m=d-e}if(n.top){let e=aO(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 aO(e,t,r){return Math.max(t,Math.min(r,e))}let aW={ts:ec.A,tsx:ec.A,js:ec.A,jsx:ec.A,json:ee.A,md:ea.A};function aB(e){let{onSelect:t,onClose:r}=e,a=tx(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(()=>{w.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=aW[null!=(l=null==(s=e.name.split(".").pop())?void 0:s.toLowerCase())?l:""])?o:eh.A;return(0,n.jsxs)("button",{onClick:()=>{t(e.path),r()},className:O("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 aU=r(49353),aH=r(24284);function aK(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 w.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):w.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)(e1.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)(aU.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>w.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)(aH.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:O("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)(q.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 aG="halo_recent_workspaces";function aJ(){try{let e=localStorage.getItem(aG),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function aq(e){try{localStorage.setItem(aG,JSON.stringify(e))}catch(e){}}var aZ=r(12143),aV=r(59821);function aY(e){var t,r;let{projectId:a,pathInput:s,onPathInputChange:o,onOpenFolder:i,onOpenPath:c,activeProject:d}=e,u=(0,eZ.kj)(),m=t4(e=>e.isStreaming),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g=(0,l.useRef)(null),{recent:v,remove:b}=function(){let[e,t]=(0,l.useState)([]);return(0,l.useEffect)(()=>{t(aJ())},[]),{recent:e,remove:(0,l.useCallback)(e=>{t(t=>{let r=t.filter(t=>t!==e);return aq(r),r})},[])}}(),[j,y]=(0,l.useState)(!1),[N,k]=(0,l.useState)(!1),S=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(j)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){S.current&&!S.current.contains(e.target)&&y(!1)}},[j]);let A=N?s.trim().toLowerCase():"",I=v.filter(e=>e!==(null==d?void 0:d.path)&&(!A||e.toLowerCase().includes(A)));async function E(){if(!a)return;let e=await U("New file name (relative path, e.g. src/hello.ts):");if(null==e?void 0:e.trim())try{await w.F.files.create(e.trim(),a),C(a)}catch(e){console.error("[Explorer] Failed to create file:",e),window.alert(e instanceof Error?e.message:"Failed to create file")}}async function T(){if(!a)return;let e=await U("New folder name (relative path, e.g. src/utils):");if(null==e?void 0:e.trim())try{await w.F.files.mkdir(e.trim(),a),C(a)}catch(e){console.error("[Explorer] Failed to create folder:",e),window.alert(e instanceof Error?e.message:"Failed to create folder")}}async function P(e){var t;if(!a||!(null==(t=e.target.files)?void 0:t.length))return;let r=Array.from(e.target.files);try{await w.F.files.upload(r,a),C(a)}catch(e){console.error("[Explorer] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}e.target.value=""}let F=null!=(r=null==d||null==(t=d.path.split("/").filter(Boolean).pop())?void 0:t.toUpperCase())?r:"EXPLORER";return(0,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)(aZ.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),C(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)(rl.A,{className:O("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:S,className:"relative min-w-0 flex-1",children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>{o(e.target.value),k(!0),y(!0)},onFocus:()=>{k(!1),y(!0)},onKeyDown:e=>{"Enter"!==e.key||e.repeat||e.nativeEvent.isComposing?"Escape"===e.key&&y(!1):(y(!1),i())},placeholder:"Enter folder path, press Enter",className:"w-full rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),j&&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:()=>{y(!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)(af.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(),b(e)},title:"Remove from recent",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 hover:bg-[var(--border)] hover:text-[var(--foreground)] group-hover:opacity-100",children:(0,n.jsx)(e1.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)(eM.A,{className:"h-3.5 w-3.5"})})]}),h&&(0,n.jsx)(aK,{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:O("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:F})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:E,title:"New File",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eF.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:T,title:"New Folder",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(eD.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)(aV.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("input",{ref:g,type:"file",multiple:!0,className:"hidden",onChange:P})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:a?(0,n.jsx)(tj,{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)($.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 a$=t7(),aQ=a$.useBus,aX=a$.bump;var a0=r(9747),a1=r(36822),a5=r(58271);function a3(e){return"".concat(e.id,":").concat(e.scope)}let a2="halo_skills_selectedKey",a4="halo_skills_expandedScopes";function a8(){try{let e=localStorage.getItem(a4);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}let a6=(0,c.v)(e=>({skills:[],selectedKey:localStorage.getItem(a2),setSkills:t=>e({skills:t}),setSelectedKey:t=>{t?localStorage.setItem(a2,t):localStorage.removeItem(a2),e({selectedKey:t})},addSkill:t=>e(e=>({skills:[...e.skills,t]})),removeSkill:t=>e(e=>{let r=e.skills.filter(e=>a3(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(a2),{skills:n,selectedKey:l}})}));function a9(){let e=(0,eZ.kj)(),{skills:t,selectedKey:r,setSkills:a,setSelectedKey:s,addSkill:o,removeSkill:i}=a6(),c=tx(e=>e.activeProject),d=null==c?void 0:c.path,[u,m]=(0,l.useState)(a8),[x,p]=(0,l.useState)(!1),h=aQ(e=>e.version);async function f(e){if("workspace"===e&&!d)return;let r=await U("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 H(t))return}try{let n=(await w.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(a3(n)),aX()}catch(e){console.error("[SkillsSidebar] Create failed:",e)}}async function g(e,t){if(e.stopPropagation(),await H('Delete skill "'.concat(t.name,'"?')))try{await w.F.skills.remove(t.id,"workspace"===t.scope?{scope:"workspace",projectId:d}:void 0),i(a3(t)),aX()}catch(e){console.error("[SkillsSidebar] Delete failed:",e)}}async function v(e,r){e.stopPropagation();try{let e=await w.F.skills.toggle(r.id,{scope:r.scope,projectId:d});a(t.map(t=>a3(t)===a3(r)?{...t,disabled:e.disabled}:t)),aX()}catch(e){console.error("[SkillsSidebar] Toggle failed:",e)}}(0,l.useEffect)(()=>{localStorage.setItem(a4,JSON.stringify([...u]))},[u]),(0,l.useEffect)(()=>{p(!0),w.F.skills.list(d).then(e=>a(e.skills)).catch(()=>{}).finally(()=>p(!1))},[d,h,a]),(0,l.useEffect)(()=>{if(!d)return;let e=k.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/skills/")&&aX()}),t=S(k,aX);return()=>{e(),t()}},[d]),(0,l.useEffect)(()=>{let e=()=>aX();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]);let b=t.filter(e=>"global"===e.scope),j=t.filter(e=>"workspace"===e.scope),y=(e,t,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)(Y.A,{className:O("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)(ah.A,{className:"h-3 w-3"})})]}),o&&l.map(e=>{let t=a3(e);return(0,n.jsxs)("div",{onClick:()=>s(t),className:O("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)(a0.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=>v(t,e),className:O("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)(a1.A,{className:"h-4.5 w-4.5"}):(0,n.jsx)(a5.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)(eP.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)(a0.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:()=>aX(),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)(rl.A,{className:O("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[y("global",et.A,e("common.global"),b),d&&y("workspace",$.A,e("common.workspace"),j),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)(a0.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 a7=r(1247),se=r(71611),st=r(41601),sr=r(30042);function sa(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 ss={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 sn(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 sl="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)]",so="text-[11px] font-medium text-[var(--foreground)]",si="text-[10px] text-[var(--muted-foreground)]";function sc(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:so,children:t})]}),r&&(0,n.jsx)(sa,{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 sd(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,eZ.kj)(),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,E=null!=(l=null==b||null==(t=b.providers)?void 0:t.flatMap(e=>e.models))?l:[],T=String(null!=(o=k.id)?o:""),P=E.find(e=>e.id===T);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:so,children:N("agent.name")}),(0,n.jsx)("input",{value:String(null!=(i=p.name)?i:""),onChange:e=>j("name",e.target.value),className:O(sl,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:so,children:N("agent.description")}),(0,n.jsx)("input",{value:String(null!=(c=p.description)?c:""),onChange:e=>j("description",e.target.value),className:O(sl,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:so,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:O(sl,"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:so,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:"",...sn(c,k)})},className:O("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:O(sl,"mt-1")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:so,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)(sa,{value:T,presets:o.map(e=>{var t;return{id:e.id,label:null!=(t=e.displayName)?t:e.id}}),placeholder:"model id",onCommit:e=>(function(e){let t=o.find(t=>t.id===e);j("model",{...k,id:e,...sn(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:so,children:N("agent.endpoint")}),(0,n.jsx)(sa,{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:O(si,"mt-0.5"),children:["Default: ",i]})]})})(),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:so,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:O(sl,"mt-1"),placeholder:(null==P?void 0:P.maxOutputTokens)?String(P.maxOutputTokens):"auto"}),(0,n.jsx)("p",{className:O(si,"mt-0.5"),children:(null==P?void 0:P.maxOutputTokens)?N("agent.maxTokensDefault",{max:P.maxOutputTokens.toLocaleString()}):N("agent.maxTokensAuto")})]})]}),(()=>{var e,t,r,a,s,l,o,i;let c=null!=(l=null==P?void 0:P.capabilities)?l:T?ss: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)(sc,{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)(sc,{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=!P&&""!==T,t=k.image,r=k.video,a=k.audio;if(e){let e=e=>{let{field:t,label:r,value:a}=e;return(0,n.jsx)("button",{type:"button",onClick:()=>y("model",t,!a||void 0),className:O("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:O("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:O("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:O("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=!P&&""!==T,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:so,children:"Thinking"})]}),x&&"adaptive"===f&&u&&(0,n.jsx)(sa,{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:si,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:si,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:so,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:O(sl,"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:O("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:si,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==P||null==(e=P.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&&""!==T&&!0!==l,a=r?"".concat(e.description,"\n\nNote: the selected model does not declare capabilities.image: true — view_image will be dropped from this agent's tool list at runtime."):e.description;return(0,n.jsxs)("button",{type:"button",title:a,onClick:()=>w("tools",e.name),className:O("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:si,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:O("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 su(e){return"".concat(e.id,":").concat(e.scope)}let sm="halo_agents_selectedKey",sx="halo_agents_expandedScopes";function sp(){try{let e=localStorage.getItem(sx);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}function sh(){var e,t;let r=(0,eZ.kj)(),a=tx(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(sm)),[m,x]=(0,l.useState)(sp),{skills:p,setSkills:h}=a6(),[f,g]=(0,l.useState)(null),[v,b]=(0,l.useState)(!1);(0,l.useEffect)(()=>{d?localStorage.setItem(sm,d):localStorage.removeItem(sm)},[d]),(0,l.useEffect)(()=>{localStorage.setItem(sx,JSON.stringify([...m]))},[m]),(0,l.useEffect)(()=>{w.F.agentConfigs.models().then(g).catch(()=>{})},[]);let j=(0,l.useCallback)(async()=>{b(!0);try{let e=await w.F.agentConfigs.list(s);c(e.agents),!d&&e.agents.length>0&&u(su(e.agents[0]))}catch(e){console.error("[AgentManagement] Load failed:",e)}finally{b(!1)}},[s,d]),y=aj(e=>e.version);(0,l.useEffect)(()=>{j()},[j,y]),(0,l.useEffect)(()=>{if(!s)return;let e=k.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/agents/")&&ay()}),t=S(k,ay);return()=>{e(),t()}},[s]),(0,l.useEffect)(()=>{let e=()=>ay();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),(0,l.useEffect)(()=>{p.length>0||w.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 N=null!=(t=o.find(e=>su(e)===d))?t:null;async function C(e){var t;if("workspace"===e&&!s)return;let r=await U("Agent name:");if(!(null==r?void 0:r.trim()))return;let a=null!=(t=await U("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 H(t))return}try{let t=(await w.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(su(t)),ay()}catch(e){console.error("[AgentManagement] Create failed:",e)}}async function A(e){if(await H('Delete agent "'.concat(e.name,'"?')))try{await w.F.agentConfigs.remove(e.id,{scope:e.scope,projectId:s}),c(t=>{let r=t.filter(t=>su(t)!==su(e));return"workspace"===e.scope?r.map(t=>t.id===e.id&&"global"===t.scope?{...t,overridden:!1}:t):r}),d===su(e)&&u(null),ay()}catch(e){console.error("[AgentManagement] Delete failed:",e)}}async function I(e){try{let{disabled:t}=await w.F.agentConfigs.toggle(e.id,{scope:e.scope,projectId:s});c(r=>r.map(r=>su(r)===su(e)?{...r,disabled:t}:r)),ay()}catch(e){console.error("[AgentManagement] Toggle failed:",e)}}let E=o.filter(e=>e.internal),T=o.filter(e=>"global"===e.scope&&!e.internal),P=o.filter(e=>"workspace"===e.scope&&!e.internal),F=(()=>{let e=new Map;for(let t of[...T,...P])t.overridden||t.disabled||e.set(t.id,{id:t.id,name:t.name});return[...e.values()]})(),D=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)(Y.A,{className:O("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(),C(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)(ah.A,{className:"h-3 w-3"})})]}),o&&a.map(t=>{let r=su(t);return(0,n.jsxs)("div",{className:O("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)(rn.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(),I(t)},title:t.disabled?"Enable (show in roster)":"Disable (hide from roster)",className:O("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)(a1.A,{className:"h-4.5 w-4.5"}):(0,n.jsx)(a5.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)(a7.A,{className:"h-3 w-3 shrink-0 text-amber-500"})}):(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),A(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)(eP.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:()=>j(),disabled:v,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh agents",children:(0,n.jsx)(rl.A,{className:O("h-3.5 w-3.5",v&&"animate-spin")})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[D("global",et.A,r("common.global"),T),s&&D("workspace",$.A,r("common.workspace"),P),E.length>0&&D("internal",se.A,"Internal",E,{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:N?(0,n.jsx)(sf,{agent:N,allAgents:F,modelsRegistry:f,onSaved:e=>{c(t=>t.map(t=>su(t)===su(e)?e:t))}},su(N)):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center",children:[(0,n.jsx)(rn.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 sf(e){let{agent:t,allAgents:a,modelsRegistry:s,onSaved:o}=e,i=(0,eZ.kj)(),{skills:c}=a6(),d=tx(e=>e.activeProject),[u,m]=(0,l.useState)({}),x="halo_agent_view:".concat(su(t)),[p,h]=(0,l.useState)(()=>{var e;return null!=(e=localStorage.getItem(x))?e:"form"}),f=(0,l.useCallback)(e=>{localStorage.setItem(x,e),h(e)},[x]),[g,v]=(0,l.useState)(!0),[b,y]=(0,l.useState)(!1),[N,S]=(0,l.useState)([]),[C,A]=(0,l.useState)("");(0,l.useEffect)(()=>{w.F.agentConfigs.tools().then(e=>S(e.tools)).catch(()=>{})},[]);let I=(0,l.useRef)(o);(0,l.useEffect)(()=>{I.current=o});let E=(0,l.useRef)(null),T=(0,l.useCallback)(async()=>{v(!0);let e="workspace"===t.scope?null==d?void 0:d.path:void 0;try{let a=await w.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),E.current=n(o,{lineWidth:120})}catch(e){console.error("[AgentEditor] Load YAML failed:",e),m({}),E.current=null}try{var a,s;let r=await w.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("")}v(!1)},[t.id,t.scope,null==d?void 0:d.path]);(0,l.useEffect)(()=>{T()},[T]);let P=(0,l.useRef)(p);return(0,l.useEffect)(()=>{"edit"===P.current&&"form"===p&&T(),P.current=p},[p,T]),(0,l.useEffect)(()=>{if(g)return;let e=setTimeout(async()=>{try{let{stringify:e}=await r.e(443).then(r.bind(r,51443)),a=e(u,{lineWidth:120});if(E.current===a)return;y(!0);let s="workspace"===t.scope?null==d?void 0:d.path:void 0,n=await w.F.agentConfigs.saveYaml(t.id,a,{scope:t.scope,projectId:s});E.current=a,I.current(n.agent)}catch(e){console.error("[AgentEditor] Auto-save failed:",e)}finally{y(!1)}},500);return()=>clearTimeout(e)},[u,t.id,t.scope,null==d?void 0:d.path,g]),(0,l.useEffect)(()=>{E.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:()=>f("form"),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:"Back to form",children:[(0,n.jsx)(st.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&&b&&(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=t4.getState().sessionId;r&&k.send({type:"session:clear",sessionId:r}),t&&localStorage.removeItem("halo_session_".concat(t)),t4.getState().clear(),t4.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)(sr.A,{className:"h-3 w-3"}),i("agent.test")]}),"form"===p&&(0,n.jsxs)("button",{onClick:()=>f("edit"),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",title:i("agent.editHint"),children:[(0,n.jsx)(e_.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)(j,{children:(0,n.jsx)(tj,{projectId:t.path,mode:"full",showMaximize:!1})},"".concat(t.id,":").concat(t.scope)):g?(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)(sd,{data:u,availableSkills:c,availableTools:N,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)(eV,{content:C})]})]})})]})}function sg(){var e;let{skills:t,selectedKey:r}=a6(),a=null!=(e=t.find(e=>"".concat(e.id,":").concat(e.scope)===r))?e:null;return a?(0,n.jsx)(j,{children:(0,n.jsx)(tj,{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)(a0.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 sv=r(34409),sb=r(68654);function sj(){let e=(0,eZ.kj)(),t=t4(e=>e.messages),r=t4(e=>e.sessionId),a=t4(e=>e.isStreaming),s=ri(e=>e.selectedSessionId),o=ri(e=>e.selectedSession),i=ri(e=>e.loadedMessages),c=ri(e=>e.loading),d=tx(e=>e.activeProject),u=(0,l.useRef)(null),[m,x]=(0,l.useState)(!1),[p,h]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_debug")),[f,g]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_prompt"));(0,l.useEffect)(()=>{localStorage.setItem("halo_session_debug",p?"1":"0")},[p]),(0,l.useEffect)(()=>{localStorage.setItem("halo_session_prompt",f?"1":"0")},[f]);let v=ri(e=>e.setLoadedMessages);(0,l.useEffect)(()=>{var e;if(!s||!(null==d?void 0:d.path)||s===r)return;let t=()=>{w.F.sessionLogs.get(s,d.path).then(e=>{var t;t6(s,"number"==typeof e.archiveCount?e.archiveCount:0);let r=null!=(t=e.messages)?t:[],a=ri.getState().loadedMessages,n=function(e,t){if(!e||0===e.length)return t;let r=Math.min(e.length,t.length),a=Math.max(0,e.length-2),s=t.length>=e.length;for(let r=0;s&&r<a;r++)(e[r].id!==t[r].id||e[r].deleted!==t[r].deleted)&&(s=!1);if(s){let s=e.length===t.length,n=t.slice();for(let t=0;t<a;t++)n[t]=e[t];for(let l=a;l<r;l++)JSON.stringify(e[l])===JSON.stringify(t[l])?n[l]=e[l]:s=!1;return s?e:n}let n=e.length===t.length,l=t.map((t,r)=>{let a=e[r];return a&&JSON.stringify(a)===JSON.stringify(t)?a:(n=!1,t)});return n?e:l}(a,r);n!==a&&v(n)}).catch(()=>{})},a=null!=(e=s.split(">").pop())?e:s,n=k.on("file:changed",e=>{("change"===e.action||"add"===e.action)&&e.path.startsWith(".halo/sessions/")&&e.path.endsWith("/".concat(a,".json"))&&t()}),l=S(k,t);return()=>{n(),l()}},[s,r,null==d?void 0:d.path,v]);let b=(0,l.useMemo)(()=>{if(!s)return[];if(s===r){let e=t.filter(e=>!e.taskId);return p?e:e.filter(tN)}let e=null!=i?i:[];return p?e:e.filter(e=>!tw(e))},[s,r,t,i,p]),j=(0,l.useMemo)(()=>{for(let e of s===r?t:null!=i?i:[])if("context"===ty(e)&&e.systemPrompt)return e.systemPrompt;return null},[s,r,t,i]),y=t8(e=>e.sessionId),N=t8(e=>e.anchor),C=t8(e=>e.cursor),A=t8(e=>e.messages),I=t8(e=>e.loading),E=null!==y&&y===s,T=an(e=>e.sessionId),P=an(e=>e.anchor);(0,l.useEffect)(()=>{s&&s===r&&T===s&&t6(s,P)},[s,r,T,P]);let F=(0,l.useMemo)(()=>E?p?A:A.filter(e=>!tw(e)):[],[E,A,p]),D=(0,l.useRef)(!0),M=(0,l.useRef)(null),L=(0,l.useRef)(!0),R=(0,l.useCallback)(()=>{let e=t8.getState();if(e.sessionId!==s||e.cursor<1||e.loading)return;let t=u.current;M.current=t?t.scrollHeight-t.scrollTop:null,t9()},[s]);return(0,l.useEffect)(()=>{L.current=!0,M.current=null},[s]),(0,l.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{D.current=e.scrollHeight-e.scrollTop-e.clientHeight<60,e.scrollTop>200?L.current=!0:e.scrollTop<80&&L.current&&(L.current=!1,R())};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[R]),(0,l.useLayoutEffect)(()=>{let e=u.current,t=M.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,M.current=null)},[A]),(0,l.useEffect)(()=>{D.current&&u.current&&(u.current.scrollTop=u.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:[s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(sv.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(null==o?void 0:o.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:o.agentName}),(0,n.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",title:(null==o?void 0:o.title)||"Untitled",children:(null==o?void 0:o.title)||"Untitled"}),(0,n.jsxs)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:["(",b.length,")"]}),s===r&&(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==o?void 0:o.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==o?void 0:o.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==o?void 0:o.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(o.archivedAt).toLocaleString()),children:"archived"}),(null==o?void 0:o.createdAt)&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",title:"Created: ".concat(new Date(o.createdAt).toLocaleString()),children:K(o.createdAt)}),(0,n.jsxs)("button",{onClick:()=>{s&&navigator.clipboard.writeText(s).then(()=>{x(!0),setTimeout(()=>x(!1),1200)}).catch(()=>{})},title:"Session ID: ".concat(s),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:[m?(0,n.jsx)(rh.A,{className:"h-2.5 w-2.5 text-green-400"}):(0,n.jsx)(rf.A,{className:"h-2.5 w-2.5"}),s.slice(0,8)]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rn.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"})]}),s&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[j&&(0,n.jsxs)("button",{onClick:()=>g(!f),className:O("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",f?"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)(ea.A,{className:"h-3 w-3"}),"Prompt"]}),(0,n.jsxs)("button",{onClick:()=>h(!p),className:O("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",p?"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)(sb.A,{className:"h-3 w-3"}),"Debug"]})]}),a&&s===r&&(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:u,className:"relative flex-1 overflow-y-auto",children:[f&&j&&(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:()=>g(!1),title:"Close",className:"rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(e1.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:j})]}),c?(0,n.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,n.jsx)(Q.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):s?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)(rn.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.jsxs)(n.Fragment,{children:[E&&N>0&&(0,n.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[C>0?(0,n.jsxs)("button",{onClick:R,disabled:I,className:"flex w-full items-center justify-center gap-1.5 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:hover:bg-transparent",children:[I&&(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin"}),e(I?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,n.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:e("chat.archive.noEarlier")}),F.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rb,{messages:F,debugMode:p,readOnly:!0}),(0,n.jsx)("div",{className:"border-t border-[var(--border)]/50 px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:e("chat.archive.header",{segments:N-C,messages:F.length})})]})]}),(0,n.jsx)(rb,{messages:b,debugMode:p})]}):(0,n.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,n.jsx)(rn.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 sy=r(53762),sw=r(51334),sN=r(52474),sk=r(46565),sS=r(6653),sC=r(62739);function sA(){return(0,n.jsxs)("div",{className:"space-y-8 p-6",children:[(0,n.jsx)(sI,{}),(0,n.jsx)(sE,{})]})}function sI(){let{t:e}=(0,eZ.s9)(),[t,r]=(0,l.useState)(""),[a,s]=(0,l.useState)(""),[o,i]=(0,l.useState)(""),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(""),[x,p]=(0,l.useState)(!1),h=""!==a?a.length<8?"tooShort":/[A-Za-z]/.test(a)?/[0-9]/.test(a)?null:"needDigit":"needLetter":null,f=""!==a&&a===t,g=""!==o&&o!==a,v=!c&&""!==t&&""!==a&&o===a&&null===h&&!f;async function b(n){if(n.preventDefault(),v){d(!0),m(""),p(!1);try{let e=await fetch("/api/auth/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPassword:t,newPassword:a}),credentials:"include"});if(e.ok)p(!0),r(""),s(""),i("");else{let t=await e.json().catch(()=>null);m((null==t?void 0:t.error)||"HTTP ".concat(e.status))}}catch(t){m(e("security.changePassword.connectionFailed"))}finally{d(!1)}}}return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.changePassword.title")}),(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.changePassword.desc")})]}),(0,n.jsxs)("form",{onSubmit:b,className:"max-w-md space-y-4 rounded-md border border-[var(--border)] bg-[var(--card)] p-4",children:[(0,n.jsx)(sT,{label:e("security.changePassword.current"),value:t,disabled:c,autoComplete:"current-password",onChange:e=>{r(e),p(!1)}}),(0,n.jsx)(sT,{label:e("security.changePassword.new"),value:a,disabled:c,autoComplete:"new-password",onChange:e=>{s(e),p(!1)},error:h?e("security.changePassword.".concat(h)):f?e("security.changePassword.sameAsOld"):void 0,hint:e("security.changePassword.rule")}),(0,n.jsx)(sT,{label:e("security.changePassword.confirm"),value:o,disabled:c,autoComplete:"new-password",onChange:e=>{i(e),p(!1)},error:g?e("security.changePassword.mismatch"):void 0}),u&&(0,n.jsx)("p",{className:"text-[11px] text-red-400",children:u}),x&&(0,n.jsx)("p",{className:"text-[11px] text-emerald-400",children:e("security.changePassword.success")}),(0,n.jsx)("button",{type:"submit",disabled:!v,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90 disabled:opacity-50",children:c?e("security.changePassword.submitting"):e("security.changePassword.submit")})]})]})}function sE(){let{t:e}=(0,eZ.s9)(),[t,r]=(0,l.useState)(!1);async function a(){r(!0);try{await fetch("/api/auth/logout",{method:"POST",credentials:"include"})}catch(e){}window.location.reload()}return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.logout")}),(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.logout.desc")})]}),(0,n.jsxs)("button",{onClick:a,disabled:t,className:"flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--card)] px-3 py-1.5 text-xs font-medium text-red-400 transition-colors hover:bg-[var(--secondary)] disabled:opacity-50",children:[(0,n.jsx)(sC.A,{className:"h-3.5 w-3.5"}),e("security.logout")]})]})}function sT(e){let{label:t,value:r,disabled:a,autoComplete:s,onChange:l,error:o,hint:i}=e;return(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:t}),(0,n.jsx)("input",{type:"password",value:r,autoComplete:s,disabled:a,onChange:e=>l(e.target.value),className:O("mt-1 h-7 w-full rounded border bg-[var(--background)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]",o?"border-red-400/60":"border-[var(--border)]")}),o?(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-red-400",children:o}):i?(0,n.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:i}):null]})}function sP(){var e,t,r;let{t:a,refreshFromServer:s}=(0,eZ.s9)(),{refreshFromServer:o}=(0,eO.useTheme)(),i=tx(e=>e.activeProject),[c,d]=(0,l.useState)("global"),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)("general"),[h,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),y="workspace"===c?null==i?void 0:i.path:void 0,N=(0,l.useCallback)(()=>{v(!0),w.F.settings.getSchema(y).then(e=>{m(e),p(t=>"__orphans"===t||"__security"===t||e.sections.find(e=>e.namespaceId===t)?t:"general")}).catch(e=>{console.error("[Settings] schema load failed:",e)}).finally(()=>v(!1))},[y]);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 w.F.settings.remove(c,a,y);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 w.F.settings.patch(c,a,e,y)}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 w.F.settings.remove(c,r,y),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 w.F.settings.remove(c,t,y),N()}catch(e){console.error("[Settings] orphan remove failed:",e)}finally{f(!1)}}}(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{w.F.health().then(e=>j("string"==typeof(null==e?void 0:e.version)?e.version:null)).catch(()=>j(null))},[]);let A=null!=(e=null==u?void 0:u.sections)?e:[],I=null!=(t=null==u?void 0:u.orphans)?t:[],E=(0,l.useMemo)(()=>A.find(e=>e.namespaceId===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)(sy.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)(rl.A,{className:O("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:O("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)(et.A,{className:"h-3 w-3"}),a("common.global")]}),(0,n.jsxs)("button",{onClick:()=>d("workspace"),disabled:!i,className:O("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)(sw.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)(sF,{sections:A,orphans:I,active:x,onPick:p})]}),b&&(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",b]})]}),(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.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"__security"===x?(0,n.jsxs)(n.Fragment,{children:["~/.halo/secrets/config.yaml → ",(0,n.jsx)("code",{className:"text-[var(--foreground)]",children:"server.password"})]}):(0,n.jsxs)(n.Fragment,{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:"__security"===x?(0,n.jsx)(sA,{}):"__orphans"===x?(0,n.jsx)(sH,{orphans:I,onRemove:C,saving:h}):E?(0,n.jsx)(sM,{section:E,scope:c,saving:h,onSave:(e,t)=>k(E.namespaceId,e,t),onReset:e=>S(E.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 sF(e){let{sections:t,orphans:r,active:a,onPick:s}=e,{t:o}=(0,eZ.s9)(),i=(0,l.useMemo)(()=>{let e=t.filter(e=>"general"===e.source),r=t.filter(e=>"provider"===e.source);return{general:e,providers:r,skills:t.filter(e=>"skill"===e.source),agents:t.filter(e=>"agent"===e.source)}},[t]);return(0,n.jsxs)("div",{className:"py-1",children:[(0,n.jsx)(sD,{label:o("settings.nav.system"),items:i.general,active:a,onPick:s}),(0,n.jsxs)("button",{onClick:()=>s("__security"),className:O("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__security"===a?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,n.jsx)(sN.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:o("settings.nav.security")})]}),(0,n.jsx)(sD,{label:o("settings.nav.providers"),items:i.providers,active:a,onPick:s}),(0,n.jsx)(sD,{label:o("settings.nav.agents"),items:i.agents,active:a,onPick:s}),(0,n.jsx)(sD,{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:O("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)(eP.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 sD(e){let{label:t,items:r,active:a,onPick:s}=e,{lang:l}=(0,eZ.s9)();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:O("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 sM(e){let{section:t,scope:r,saving:a,onSave:s,onReset:l}=e,{t:o,lang:i}=(0,eZ.s9)(),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)(sL,{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)(sL,{namespaceId:t.namespaceId,field:e,scope:r,saving:a,onSave:t=>s(e,t),onReset:()=>l(e)},e.key))]})]})}function sL(e){var t,r;let{namespaceId:a,field:s,scope:l,saving:o,onSave:i,onReset:c}=e,{lang:d,t:u}=(0,eZ.s9)(),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)(sR,{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:u("settings.globalOnlyHint"),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)(sk.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:O("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)(sU,{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)(sO,{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)(sW,{value:e.value,saving:t,onCommit:r});case"enum":return(0,n.jsx)(sB,{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)(sz,{initial:null!=(d=e.value)?d:"",placeholder:null!=(u=e.default)?u:"",saving:t,onCommit:r})}}(s,o||h,i)})]})}function sR(e){let{source:t,inherited:r}=e,{t:a}=(0,eZ.s9)();return(0,n.jsx)("span",{className:O("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 s_=/^<<[A-Z_][A-Z0-9_]*>>$/;function sz(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:O("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 sO(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:O("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 sW(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 sB(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 sU(e){let{initial:t,placeholder:r,saving:a,onCommit:s}=e,o=s_.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(s_.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||s_.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)(sS.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(e5.A,{className:"h-3.5 w-3.5"})})]})}function sH(e){let{orphans:t,onRemove:r,saving:a}=e,{t:s}=(0,eZ.s9)(),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)(eP.A,{className:"h-3 w-3"}),s("settings.orphans.remove")]})]},"".concat(e.kind,".").concat(e.key)))})]},t)})]})}var sK=r(76966);let sG=t7(),sJ=sG.useBus,sq=sG.bump;var sZ=r(32400),sV=r(10561),sY=r(2573),s$=r(25843),sQ=r(70764);function sX(e){let t=(0,eZ.kj)(),{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),[v,b]=(0,l.useState)(r.language),[j,y]=(0,l.useState)(!1);async function N(){y(!0);try{await w.F.wechat.updateAccount(r.accountId,{label:m,workspacePath:p,accessLevel:f,language:v}),i()}catch(e){alert(t("wx.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function k(){y(!0);try{await w.F.wechat.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("wx.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function S(){if(await H(t("wx.confirmDelete",{name:r.label}))){y(!0);try{await w.F.wechat.deleteAccount(r.accountId),c()}catch(e){alert(t("wx.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{a&&(x(r.label),h(r.workspacePath),g(r.accessLevel),b(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)(eZ.pZ,{value:v,onChange:b}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:N,disabled:j||!B(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)(rh.A,{className:"h-3 w-3"})," ",t("wx.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)(e1.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:O("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:O("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:j,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)(sV.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(sY.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:u,disabled:j,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)(s$.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:j,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)(sQ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:S,disabled:j,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)(eP.A,{className:"h-3.5 w-3.5"})})]})]})}function s0(e){let t=(0,eZ.kj)(),{intent:r,onClose:a,onDone:s}=e,o=tx(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)||""),[v,b]=(0,l.useState)(r.label||""),[j,y]=(0,l.useState)(r.accessLevel),[N,k]=(0,l.useState)(r.language),[S,C]=(0,l.useState)(r.skipConfig?"scan":"config"),A=(0,l.useRef)(!1),I=r.skipConfig;async function E(){if(!B(f))return void h(t("wx.pathRequired"));C("scan"),x("loading"),h(t("wx.generatingQr"));try{let{qrcodeUrl:r,sessionKey:a}=await w.F.wechat.startLogin();if(A.current)return;if(!r){x("error"),h(t("wx.qrFailed"));return}c(a);let n=await sZ.toDataURL(r,{width:256,margin:2});if(A.current)return;u(n),x("waiting"),h(t("wx.scanPrompt"));let l=await w.F.wechat.waitLogin({sessionKey:a,workspacePath:f,label:v||void 0,accessLevel:j,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&&E()},[]),(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)(e1.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:v,onChange:e=>b(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:j,onChange:e=>y(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)(eZ.pZ,{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:E,disabled:!B(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)(Q.A,{className:"h-6 w-6 animate-spin text-[var(--muted-foreground)]"})}),(0,n.jsx)("p",{className:O("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 s1={id:"wechat",label:"channels.wechat",Icon:sK.A,Component:function(){let e=(0,eZ.kj)(),{lang:t}=(0,eZ.s9)(),[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),w.F.wechat.listAccounts().then(e=>a(e.accounts)).catch(e=>{console.error("[wechat] list failed:",e)}).finally(()=>o(!1))},[]);(0,l.useEffect)(()=>{m()},[m]);let x=sJ(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)(ah.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)(Q.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)(sX,{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)(s0,{intent:i,onClose:()=>c(null),onDone:()=>{c(null),m()}})]})}};function s5(e){let t=(0,eZ.kj)(),{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,v]=(0,l.useState)(r.allowedUsers),[b,j]=(0,l.useState)(r.language||"en"),[y,N]=(0,l.useState)(!1);async function k(){N(!0);try{await w.F.telegram.updateAccount(r.accountId,{label:u,workspacePath:x,accessLevel:h,allowedUsers:g,language:b}),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 w.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 H(t("tg.confirmDelete",{name:r.botUsername}))){N(!0);try{await w.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),v(r.allowedUsers),j(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)(eZ.pZ,{value:b,onChange:j}),(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=>v(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:y||!B(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)(rh.A,{className:"h-3 w-3"})," ",t("tg.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)(e1.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:O("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:O("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:y,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)(sV.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(sY.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:y,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)(sQ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:C,disabled:y,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)(eP.A,{className:"h-3.5 w-3.5"})})]})]})}function s3(e){let t=(0,eZ.kj)(),{lang:r}=(0,eZ.s9)(),{onClose:a,onDone:s}=e,o=tx(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)(""),[v,b]=(0,l.useState)(r),[j,y]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),y(!0);try{await w.F.telegram.createAccount({botToken:i,workspacePath:d,label:m||void 0,accessLevel:p,allowedUsers:f||void 0,language:v}),s()}catch(e){k(e instanceof Error?e.message:String(e))}finally{y(!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)(e1.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)(eZ.pZ,{value:v,onChange:b}),(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:j||!i.trim()||!B(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:[j&&(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin"}),t("tg.addBtn")]})]})]})]})})}let s2={id:"telegram",label:"Telegram",Icon:rJ.A,Component:function(){let e=(0,eZ.kj)(),[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),w.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=sJ(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)(ah.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)(Q.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)(s5,{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)(s3,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function s4(e){let{account:t,editing:r,onEdit:a,onCancelEdit:s,onSaved:o,onDeleted:i,onToggled:c}=e,d=(0,eZ.kj)(),[u,m]=(0,l.useState)(t.label),[x,p]=(0,l.useState)(t.workspacePath),[h,f]=(0,l.useState)(t.accessLevel),[g,v]=(0,l.useState)(t.language||"en"),[b,j]=(0,l.useState)(!1),[y,N]=(0,l.useState)(!1);async function k(){j(!0);try{await w.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{j(!1)}}async function S(){j(!0);try{await w.F.web.updateAccount(t.accountId,{enabled:!t.enabled}),c()}catch(e){alert(d("web.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}async function C(){if(await H(d("web.confirmDelete"))){j(!0);try{await w.F.web.deleteAccount(t.accountId),i()}catch(e){alert(d("web.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}}return((0,l.useEffect)(()=>{r&&(m(t.label),p(t.workspacePath),f(t.accessLevel),v(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)(eZ.pZ,{value:g,onChange:v}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:k,disabled:b||!B(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)(rh.A,{className:"h-3 w-3"})," ",d("web.save")]}),(0,n.jsxs)("button",{onClick:s,disabled:b,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(e1.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:O("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:O("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:y?d("web.copied"):d("web.copyToken")})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:S,disabled:b,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)(sV.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(sY.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:a,disabled:b,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)(sQ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:C,disabled:b,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)(eP.A,{className:"h-3.5 w-3.5"})})]})]})}function s8(e){let{onClose:t,onDone:r}=e,a=(0,eZ.kj)(),{lang:s}=(0,eZ.s9)(),o=tx(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),[v,b]=(0,l.useState)(""),[j,y]=(0,l.useState)(null);async function N(){b(""),g(!0);try{let e=await w.F.web.createAccount({workspacePath:i,label:d||void 0,accessLevel:m,language:p});y({token:e.token})}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}return j?(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:j.token}),(0,n.jsx)("button",{onClick:()=>navigator.clipboard.writeText(j.token),className:"rounded p-1 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,n.jsx)(rf.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)(e1.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:"中文"})]})]}),v&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:v}),(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||!B(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)(Q.A,{className:"h-3 w-3 animate-spin"}),a("web.createBtn")]})]})]})]})})}let s6={id:"web_demo",label:"Web",Icon:et.A,Component:function(){let e=(0,eZ.kj)(),[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),w.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=sJ(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)(ah.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)(Q.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)(s4,{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)(s8,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function s9(e){let t=(0,eZ.kj)(),{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,v]=(0,l.useState)(r.language||"en"),[b,j]=(0,l.useState)(!1);async function y(){j(!0);try{await w.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{j(!1)}}async function N(){j(!0);try{await w.F.slack.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("slack.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}async function k(){if(await H(t("slack.confirmDelete",{name:r.teamId}))){j(!0);try{await w.F.slack.deleteAccount(r.accountId),c()}catch(e){alert(t("slack.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),p(r.workspacePath),f(r.accessLevel),v(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)(eZ.pZ,{value:g,onChange:v}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:y,disabled:b||!B(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)(rh.A,{className:"h-3 w-3"})," ",t("slack.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:b,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(e1.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:O("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:O("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:b,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)(sV.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(sY.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:b,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)(sQ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:k,disabled:b,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)(eP.A,{className:"h-3.5 w-3.5"})})]})]})}function s7(e){let t=(0,eZ.kj)(),{lang:r}=(0,eZ.s9)(),{onClose:a,onDone:s}=e,o=tx(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"),[v,b]=(0,l.useState)(r),[j,y]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),y(!0);try{await w.F.slack.createAccount({botToken:i,appToken:d,workspacePath:m,label:p||void 0,accessLevel:f,language:v}),s()}catch(e){k(e instanceof Error?e.message:String(e))}finally{y(!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)(e1.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)(eZ.pZ,{value:v,onChange:b}),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:j||!i.trim()||!d.trim()||!B(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:[j&&(0,n.jsx)(Q.A,{className:"h-3 w-3 animate-spin"}),t("slack.addBtn")]})]})]})]})})}function ne(e){let t=(0,eZ.kj)(),{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,v]=(0,l.useState)(r.language||"en"),[b,j]=(0,l.useState)(!1);async function y(){j(!0);try{await w.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{j(!1)}}async function N(){j(!0);try{await w.F.feishu.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("feishu.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}async function k(){if(await H(t("feishu.confirmDelete",{name:r.appId}))){j(!0);try{await w.F.feishu.deleteAccount(r.accountId),c()}catch(e){alert(t("feishu.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{j(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),p(r.workspacePath),f(r.accessLevel),v(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)(eZ.pZ,{value:g,onChange:v}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:y,disabled:b||!B(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)(rh.A,{className:"h-3 w-3"})," ",t("feishu.save")]}),(0,n.jsxs)("button",{onClick:o,disabled:b,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,n.jsx)(e1.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:O("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:O("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:b,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)(sV.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(sY.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:s,disabled:b,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)(sQ.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:k,disabled:b,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)(eP.A,{className:"h-3.5 w-3.5"})})]})]})}function nt(e){let t=(0,eZ.kj)(),{lang:r}=(0,eZ.s9)(),{onClose:a,onDone:s}=e,o=tx(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)||""),[v,b]=(0,l.useState)(""),[j,y]=(0,l.useState)("readonly"),[N,k]=(0,l.useState)(r),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)("");async function E(){I(""),C(!0);try{await w.F.feishu.createAccount({appId:i,appSecret:d,verificationToken:m||void 0,encryptKey:p||void 0,workspacePath:f,label:v||void 0,accessLevel:j,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)(e1.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:v,onChange:e=>b(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:j,onChange:e=>y(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)(eZ.pZ,{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:E,disabled:S||!i.trim()||!d.trim()||!B(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)(Q.A,{className:"h-3 w-3 animate-spin"}),t("feishu.addBtn")]})]})]})]})})}let nr=[s1,s2,s6,{id:"slack",label:"Slack",Icon:ei.A,Component:function(){let e=(0,eZ.kj)(),[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),w.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=sJ(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)(ah.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)(Q.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)(s9,{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)(s7,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}},{id:"feishu",label:"Feishu",Icon:r(29659).A,Component:function(){let e=(0,eZ.kj)(),[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),w.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=sJ(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)(ah.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)(Q.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)(ne,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,n.jsx)(nt,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}}],na="halo_channel_active",ns=new Set(nr.map(e=>e.id)),nn=null!=(s=null==(a=nr[0])?void 0:a.id)?s:"",nl=(0,c.v)(e=>({active:function(){try{let e=localStorage.getItem(na);if(e&&ns.has(e))return e}catch(e){}return nn}(),setActive(t){if(ns.has(t)){try{localStorage.setItem(na,t)}catch(e){}e({active:t})}}}));function no(){let e=(0,eZ.kj)(),t=nl(e=>e.active),r=nl(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)(sK.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:()=>sq(),title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:(0,n.jsx)(rl.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:nr.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:O("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 ni(){let e=nl(e=>e.active),t=nr.find(t=>t.id===e);if(!t)return null;let r=t.Component;return(0,n.jsx)(r,{})}var nc=r(23704);let nd=(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 nu(){let e=(0,eZ.kj)(),t=nd(e=>e.selectedId);return t?(0,n.jsx)(nh,{id:t}):(0,n.jsx)(nm,{label:e("evolution.list.pickRun")})}function nm(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 nx(e){var t;let{status:r}=e,a=null!=(t=np[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,n.jsx)("span",{className:O("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let np={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 nh(e){var t,r,a,s;let{id:o}=e,i=(0,eZ.kj)(),c=nd(e=>e.refreshTick),d=nd(e=>e.setSelectedId),[u,m]=(0,l.useState)(null),[x,p]=(0,l.useState)(!0),[h,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(""),[y,N]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),[P,F]=(0,l.useState)(""),D=(0,l.useCallback)(async()=>{p(!0);try{let e=await w.F.evolution.getRun(o);m(e),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}finally{p(!1)}},[o]);if((0,l.useEffect)(()=>{m(null),C(!1),I(!1),j(""),N(""),D()},[o,D]),(0,l.useEffect)(()=>{0!==c&&D()},[c,D]),(0,l.useEffect)(()=>k.on("evolution:run_changed",e=>{e.id===o&&("deleted"===e.kind?d(null):D())}),[o,D,d]),x&&!u)return(0,n.jsx)(nm,{label:i("evolution.list.loading")});if(h)return(0,n.jsx)(nm,{label:i("cron.error",{error:h})});if(!u)return(0,n.jsx)(nm,{label:i("evolution.list.noRun")});let{run:M,patchMd:L,scoreJson:R,skipReasonMd:_,snapshotSummary:z,wrapperLog:O,subCliLog:W}=u,B="awaiting_review"===M.status,U="approved"===M.status&&("failed"===M.applyStatus||"timeout"===M.applyStatus),K=async()=>{v(!0);try{await w.F.evolution.approve(o,b.trim()||void 0),C(!1),j(""),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},G=async()=>{if(await H(i("evolution.action.confirmReject"))){v(!0);try{await w.F.evolution.reject(o),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},J=async()=>{let e=y.trim();if(e){v(!0);try{await w.F.evolution.addHint(o,e),N(""),I(!1),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},q=async()=>{let e=P.trim();if(!e)return void alert(i("evolution.action.retryNeedsHint"));v(!0);try{await w.F.evolution.retry(o,e),F(""),T(!1),await D()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},Z=async()=>{if(await H(i("evolution.action.confirmDelete"))){v(!0);try{await w.F.evolution.delete(o),d(null)}catch(e){alert(e instanceof Error?e.message:String(e)),v(!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)(nx,{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)(eP.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")}),U&&(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)(rh.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)(e1.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)(nc.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.addHint")]}),(0,n.jsxs)("button",{disabled:g,onClick:()=>T(e=>!e),className:"flex items-center gap-1 rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",title:i("evolution.retry.tooltip"),children:[(0,n.jsx)(rl.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||U)&&(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:()=>T(e=>!e),className:"flex items-center gap-1 rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",title:i("evolution.retry.tooltip"),children:[(0,n.jsx)(rl.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retryWithHint")]})}),E&&(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:P,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||!P.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:()=>{T(!1),F("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),B&&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:b,onChange:e=>j(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.approve.placeholder")}),(0,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),j("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),B&&A&&(0,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:y,onChange:e=>N(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||!y.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),N("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),R&&(0,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)(ng,{label:i("evolution.score.lint"),value:R.lint}),(0,n.jsx)(ng,{label:i("evolution.score.behavior"),value:R.behavior}),(0,n.jsx)(ng,{label:i("evolution.score.scope"),value:R.scope}),(0,n.jsx)(ng,{label:i("evolution.score.avg"),value:R.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=R.confidence)?t:"—"})]}),"string"==typeof R.notes&&(0,n.jsx)("div",{className:"mt-2 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs text-[var(--foreground)]",children:R.notes})]}),z&&(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=z.messageCount)?r:0})}),z.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:z.firstUser})]}),z.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=z.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:[_&&(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:_})]}),(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")}),(O||W)&&(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")}),O&&(0,n.jsx)(nf,{title:i("evolution.logs.wrapper"),body:O}),W&&(0,n.jsx)(nf,{title:i("evolution.logs.subCli"),body:W})]})]})]})}function nf(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 ng(e){let{label:t,value:r,highlight:a}=e;return(0,n.jsxs)("div",{className:O("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:O("text-lg font-medium",a&&"text-[var(--primary)]"),children:"number"==typeof r?r:"—"})]})}let nv=["all","awaiting_review","pending","running","approved","applied","skipped","rejected","failed","timeout","archived"];function nb(){let e=(0,eZ.kj)(),t=nd(e=>e.filter),r=nd(e=>e.setFilter),a=nd(e=>e.selectedId),s=nd(e=>e.setSelectedId),o=nd(e=>e.bumpRefresh),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[m,x]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[v,b]=(0,l.useState)(!1),j=(0,l.useRef)(0);(0,l.useEffect)(()=>{j.current=i.length,i.length>=300&&g(null)},[i.length]);let y=(0,l.useCallback)(async()=>{let e=Math.min(300,Math.max(20,j.current));try{let r=await w.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]),N=(0,l.useCallback)(async()=>{if(f&&!v){b(!0);try{let e=await w.F.evolution.listRuns({archived:"archived"===t,limit:20,before:f});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("evolution.listRuns more",e)}finally{b(!1)}}},[t,f,v]);(0,l.useEffect)(()=>{y()},[y]);let 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)&&N()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[N,i.length]),(0,l.useEffect)(()=>{let e=k.on("evolution:run_changed",()=>{y()}),t=k.on("evolution:apply_changed",()=>{y()});return()=>{e(),t()}},[y]);let C=(0,l.useMemo)(()=>"all"===t||"archived"===t?i:i.filter(e=>e.status===t),[i,t]);return(0,l.useEffect)(()=>{var e;if(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)(rB.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([y(),e]),h(!1)},disabled:p,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)] disabled:cursor-default",title:e("evolution.refresh"),children:(0,n.jsx)(rl.A,{className:O("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:nv.map(a=>(0,n.jsx)("button",{onClick:()=>r(a),className:O("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)(nj,{label:e("evolution.list.loading")}),m&&(0,n.jsx)(nj,{label:e("cron.error",{error:m})}),!d&&!m&&0===C.length&&(0,n.jsx)(nj,{label:e("evolution.list.empty")}),C.map(e=>(0,n.jsx)(ny,{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:v?e("evolution.list.loading"):e("cron.loadOlder")})]})]})}function nj(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 ny(e){var t;let{run:r,selected:a,onClick:s}=e,l=(0,eZ.kj)();return(0,n.jsxs)("button",{onClick:s,className:O("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)(nw,{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:K(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 nw(e){var t;let{status:r}=e,a=null!=(t=nN[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,n.jsx)("span",{className:O("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let nN={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 nk=r(97016),nS=r.n(nk),nC=r(97482);let nA=(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 nI(e,t){return e?e.includes("ret=-2")?t("cron.err.wechat.noInbound"):e:"?"}function nE(){let e=(0,eZ.kj)(),t=nA(e=>e.selectedId),r=nA(e=>e.setSelectedId),a=nA(e=>e.formMode),s=nA(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 w.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)(()=>k.on("cron:job_changed",()=>{c()}),[c]);let d=(0,l.useCallback)(async a=>{if(await H(e("cron.confirmDelete")))try{await w.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 w.F.cron.runNow(e)}catch(e){alert(e instanceof Error?e.message:String(e))}},[]);return"create"===a?(0,n.jsx)(nF,{onClose:s,onSaved:s}):"edit"===a&&o?(0,n.jsx)(nF,{initial:o,onClose:s,onSaved:s}):o?(0,n.jsx)(nT,{job:o,onEdit:()=>nA.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 nT(e){let{job:t,onEdit:r,onDelete:a,onRunNow:s}=e,o=(0,eZ.kj)(),[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),[v,b]=(0,l.useState)(!1),j=(0,l.useCallback)(async()=>{try{let e=await w.F.cron.listRuns(t.id,{limit:20});c(e.runs),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns",e)}},[t.id]),y=(0,l.useCallback)(async()=>{if(f&&!v){b(!0);try{let e=await w.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{b(!1)}}},[t.id,f,v]);(0,l.useEffect)(()=>{j()},[j]);let N=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=N.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,i.length]),(0,l.useEffect)(()=>k.on("cron:run_changed",e=>{e.jobId===t.id&&j()}),[t.id,j]);let S=(0,l.useCallback)(async e=>{u(e),x(null),h(!0);try{let{log:t}=await w.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)(nC.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)(sr.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)(sQ.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)(eP.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",{children:[(0,n.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.timeoutSec")})," ",null!=t.timeoutSec?"".concat(t.timeoutSec,"s"):o("cron.field.timeoutSecDefault")]}),(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:O("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:nI(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(nI(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:N,className:"py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:v?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 nP(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 nF(e){var t,r,a,s,o,i;let{initial:c,onClose:d,onSaved:u}=e,m=(0,eZ.kj)(),x=tx(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:""),[v,b]=(0,l.useState)(null!=(s=null==c?void 0:c.agentId)?s:"default"),[j,y]=(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)?nP(new Date(c.runAt)):nP(new Date(Date.now()+36e5))),[E,T]=(0,l.useState)(()=>(function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}})());(0,l.useEffect)(()=>{let e=!0;return w.F.cron.meta().then(t=>{let{hostTimezone:r}=t;e&&r&&T(r)}).catch(e=>console.error("cron.meta",e)),()=>{e=!1}},[]);let P=(0,l.useMemo)(()=>{let e=function(){let e=Intl;if("function"==typeof e.supportedValuesOf)try{return e.supportedValuesOf("timeZone")}catch(e){}return["UTC","Asia/Shanghai","Asia/Tokyo","Asia/Singapore","Europe/London","Europe/Paris","America/New_York","America/Los_Angeles"]}(),t=e.includes(E)?E:e[0];return[{id:t,label:"".concat(t," (default)")},...e.filter(e=>e!==t).map(e=>({id:e,label:e}))]},[E]),[F,D]=(0,l.useState)(null!=(o=null==c?void 0:c.timezone)?o:""),[M,L]=(0,l.useState)((null==c?void 0:c.timeoutSec)!=null?String(c.timeoutSec):""),[R,_]=(0,l.useState)(null!=(i=null==c?void 0:c.userPrompt)?i:""),[z,W]=(0,l.useState)((null==c?void 0:c.enabled)!==0),[B,U]=(0,l.useState)([]),[H,K]=(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}),[G,J]=(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}),[q,Z]=(0,l.useState)(!1),[V,Y]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!0,t=async()=>{try{let{agents:t}=await w.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}));y(r),r.length>0&&!r.some(e=>e.id===v)&&b(r[0].id)}catch(e){console.error("agentConfigs.list",e)}};return f&&t(),()=>{e=!1}},[f,v]),(0,l.useEffect)(()=>{let e=!0;return w.F.cron.listChannelTargets().then(t=>{let{targets:r}=t;e&&U(r)}).catch(e=>console.error("listChannelTargets",e)),()=>{e=!1}},[]);let $=(0,l.useCallback)(e=>{K(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),Q=(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)},[]),X=(0,l.useCallback)(async()=>{if(Y(null),!f.trim())return void Y(m("cron.form.err.workspace"));if(!v.trim())return void Y(m("cron.form.err.agent"));if("recurring"===N&&!S.trim())return void Y(m("cron.form.err.schedule"));if("oneShot"===N&&!A)return void Y(m("cron.form.err.runAt"));if(!R.trim())return void Y(m("cron.form.err.prompt"));let e=F||E,t="oneShot"===N?Q(A,e):void 0;if("oneShot"===N&&void 0!==t&&t<=Date.now())return void Y(m("cron.form.err.runAtPast"));let r=M.trim(),a=r?Number(r):void 0;if(void 0!==a&&(!Number.isInteger(a)||a<60||a>21600))return void Y(m("cron.form.err.timeoutSec"));let s=[];for(let e of H){var n;let[t,r]=e.split(":"),a=(null!=(n=G[e])?n:"").trim(),l=a?a.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:m("cron.form.err.chatId.telegram",{chatId:e}):m("cron.form.err.chatId.feishu",{chatId:e}):m("cron.form.err.chatId.slack",{chatId:e});for(let e of l){let t=o(e);if(t)return void Y(t)}if(0===l.length)s.push({channelType:t,accountId:r});else for(let e of l)s.push({channelType:t,accountId:r,chatId:e})}Z(!0);try{let e={label:p||void 0,workspacePath:f,agentId:v,userPrompt:R,timezone:F||void 0,targets:s,enabled:z};c?await w.F.cron.updateJob(c.id,{...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:null,timeoutSec:null!=a?a:null}):await w.F.cron.createJob({...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:void 0,timeoutSec:a}),u()}catch(e){Y(e instanceof Error?e.message:String(e))}finally{Z(!1)}},[c,p,f,v,R,N,S,A,F,E,Q,M,H,G,z,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)(nD,{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)(nD,{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)(nD,{label:m("cron.form.agent"),children:(0,n.jsxs)("select",{value:v,onChange:e=>b(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base",children:[0===j.length&&(0,n.jsx)("option",{value:"default",className:"jsx-8283b0ed0bcf6928",children:"default"}),j.map(e=>(0,n.jsxs)("option",{value:e.id,className:"jsx-8283b0ed0bcf6928",children:[e.name," (",e.id,")"]},e.id))]})}),(0,n.jsx)(nD,{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)(nD,{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)(nD,{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)(nD,{label:m("cron.form.timezone"),children:(0,n.jsx)(sa,{value:F||E,placeholder:m("cron.form.timezone.hostDefault",{tz:E}),presets:P,onCommit:e=>{D(e===E?"":e)},minWidth:280})}),(0,n.jsxs)(nD,{label:m("cron.form.timeoutSec"),children:[(0,n.jsx)("input",{type:"number",min:60,max:21600,step:1,value:M,onChange:e=>L(e.target.value),placeholder:m("cron.form.timeoutSec.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.timeoutSec.hint")})]}),(0,n.jsx)(nD,{label:m("cron.form.userPrompt"),children:(0,n.jsx)("textarea",{value:R,onChange:e=>_(e.target.value),rows:5,placeholder:m("cron.form.userPrompt.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,n.jsx)(nD,{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===B.length?(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-[var(--muted-foreground)]",children:m("cron.form.targets.empty")}):B.map(e=>{var t;let r="".concat(e.channelType,":").concat(e.accountId),a=H.has(r),s="wechat"!==e.channelType,l="slack"===e.channelType?"D… (DM) / C… (channel) / C…:1700.0 (thread)":"telegram"===e.channelType?m("cron.form.chatIdHint.telegram"):"feishu"===e.channelType?m("cron.form.chatIdHint.feishu"):"";return(0,n.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 "+(O("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:()=>$(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)(nM,{channelType:e.channelType,accountId:e.accountId,value:null!=(t=G[r])?t:"",onChange:e=>J(t=>({...t,[r]:e})),placeholder:l}),(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:m("cron.form.chatIdHelp")})]})]},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:z,onChange:e=>W(e.target.checked),className:"jsx-8283b0ed0bcf6928"}),(0,n.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:m("cron.form.enabled")})]}),V&&(0,n.jsx)("div",{className:"jsx-8283b0ed0bcf6928 rounded border border-red-500/50 bg-red-950/40 p-2 text-red-300",children:V})]}),(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:()=>{X()},disabled:q,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--primary)] px-3 py-1 text-xs text-[var(--primary-foreground)] disabled:opacity-50",children:q?m("cron.form.saving"):c?m("cron.form.save"):m("cron.form.create.btn")})]}),(0,n.jsx)(nS(),{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 nD(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 nM(e){let{channelType:t,accountId:r,value:a,onChange:s,placeholder:o}=e,i=(0,eZ.kj)(),[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)([]),[x,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g="slack"===t||"feishu"===t;return(0,l.useEffect)(()=>{if(!g||!c.trim())return void m([]);let e=!1;f(!0);let a=setTimeout(async()=>{try{let a="slack"===t?await w.F.slack.searchTargets(r,c):await w.F.feishu.searchTargets(r,c);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}});m(s)}catch(t){e||m([]),console.error("[cron-form] target search failed:",t)}finally{e||f(!1)}},300);return()=>{e=!0,clearTimeout(a)}},[c,t,r,g]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{value:a,onChange:e=>(function(e){var t,r;if(s(e),!g)return;let a=null!=(r=null==(t=e.split(",").pop())?void 0:t.trim())?r:"";d(a),p(a.length>0)})(e.target.value),onFocus:()=>{c&&p(!0)},onBlur:()=>setTimeout(()=>p(!1),150),placeholder:o,className:"input-base font-mono text-[11px]"}),g&&x&&(h||u.length>0)&&(0,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:[h&&(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] text-[var(--muted-foreground)]",children:i("cron.form.searching")}),!h&&u.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(", ")),d(""),m([]),p(!1)})(e.chatId),className:"flex w-full items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-[var(--accent)]",children:[(0,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 nL(){let e=(0,eZ.kj)(),[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=nA(e=>e.selectedId),f=nA(e=>e.setSelectedId),g=nA(e=>e.openCreate),v=(0,l.useCallback)(async()=>{try{let e=await w.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)}},[]),b=(0,l.useCallback)(async()=>{if(u&&!x){p(!0);try{let e=await w.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]),j=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=j.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&b()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[b,t.length]);let y=(0,l.useCallback)(async()=>{d(!0);let e=new Promise(e=>setTimeout(e,400));await Promise.all([v(),e]),d(!1)},[v]);return(0,l.useEffect)(()=>{v()},[v]),(0,l.useEffect)(()=>{let e=k.on("cron:job_changed",()=>{v()}),t=k.on("cron:run_changed",()=>{v()});return()=>{e(),t()}},[v]),(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)(nC.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)(ah.A,{className:"h-3 w-3"})," ",e("cron.new")]}),(0,n.jsx)("button",{onClick:()=>{y()},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)(rl.A,{className:O("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:O("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:O("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=>{j.current=e},className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:x?e("cron.loading"):e("cron.loadOlder")})]})})]})}var nR=r(9207),n_=r(16374),nz=r(48403),nO=r(16981),nW=r(81616),nB=r(71008);let nU=(0,c.v)(e=>({selected:null,select:t=>e({selected:t}),clear:()=>e({selected:null})}));function nH(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)(Y.A,{className:"h-3.5 w-3.5 shrink-0"}):(0,n.jsx)(V.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=F(t.char),m=a===t.file.path,x="staged"===r?nB.A:ah.A,{Icon:p,color:h}=ev(t.file.path);return(0,n.jsxs)("div",{onClick:()=>s(t.file),className:O("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:O("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 nK=r(35930),nG=r(77271),nJ=r(93374);function nq(e){let{projectId:t,onClose:r,onSaved:a}=e,s=(0,eZ.kj)(),[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)(e1.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:O("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)(nV,{onClose:r,onSaved:a}):(0,n.jsx)(nY,{projectId:t,onClose:r})]})})}let nZ="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 nV(e){let{onClose:t,onSaved:r}=e,a=(0,eZ.kj)(),[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),[v,b]=(0,l.useState)(null),j=(0,l.useCallback)(()=>{w.F.git.getCredentials().then(e=>o(e.credentials)).catch(()=>o([]))},[]);async function y(){if(!d.trim()||!m.trim()||!p)return void b(a("sc.cred.required"));g(!0),b(null);try{await w.F.git.saveCredentials({host:d.trim(),username:m.trim(),token:p}),h(""),j(),r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function N(e){b(null);try{await w.F.git.deleteCredential(e),j()}catch(e){b(e instanceof Error?e.message:String(e))}finally{c(null)}}return(0,l.useEffect)(()=>{j()},[j]),(0,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)(eP.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:nZ})]}),(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:nZ})]}),(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:nZ}),(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)(nK.A,{className:"h-2.5 w-2.5"})]})]})]})]}),v&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(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:y,disabled:f,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:f?a("sc.cred.saving"):a("sc.cred.save")})]})]})}function nY(e){let{projectId:t,onClose:r}=e,a=(0,eZ.kj)(),[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),[v,b]=(0,l.useState)(null),[j,y]=(0,l.useState)(null),[N,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(null),E=(0,l.useCallback)(()=>{w.F.git.sshKeys().then(e=>o(e.keys)).catch(()=>o([])),w.F.git.sshAgent().then(e=>{c(e.agentRunning),u(e.loadedKeys)}).catch(()=>{}),w.F.git.getRemoteProtocol(t).then(e=>{x(e.protocol),h(e.url)}).catch(()=>{})},[t]);function T(){y(null),k(""),I(null)}async function P(e){C(!0),I(null);try{let r=await w.F.git.unlockSshKey({keyPath:e.path,passphrase:N});if(r.ok)T(),E();else{var t;I(null!=(t=r.error)?t:a("sc.cred.sshUnlockFailed"))}}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}async function F(e){g(!0),b(null);try{let r=await w.F.git.setRemoteProtocol(t,e);x(e),h(r.url)}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}return(0,l.useEffect)(()=>{E()},[E]),(0,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:O("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:E,className:"ml-auto rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",title:a("sc.cred.sshRefresh"),children:(0,n.jsx)(rl.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=j===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)(nG.A,{className:"h-3 w-3 shrink-0 text-amber-400"}):(0,n.jsx)(nJ.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:()=>{y(e.path),k(""),I(null)},className:"ml-auto shrink-0 rounded bg-[var(--secondary)] px-2 py-0.5 text-[10px] font-medium text-[var(--foreground)] hover:opacity-90",children: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||P(e)},placeholder:a("sc.cred.sshPassphrase"),className:nZ}),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:T,disabled:S,className:"rounded px-2 py-0.5 text-[10px] font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)] disabled:opacity-40",children:a("sc.cred.cancel")}),(0,n.jsx)("button",{onClick:()=>P(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:()=>F(e),disabled:f||m===e,className:O("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")}),v&&(0,n.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(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 n$=r(81540);function nQ(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 nX(e){let{info:t}=e,r="tag"===t.kind?n$.A:nR.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:O("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 n0(e){let{file:t,active:r,onSelect:a}=e,s=F(t.status),{Icon:l,color:o}=ev(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:O("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:O("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 n1(e){let{projectId:t}=e,r=(0,eZ.kj)(),a=nU(e=>e.select),s=nU(e=>e.selected),[o,i]=(0,l.useState)([]),[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)(!1),[x,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(50),[g,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)({}),y=(0,l.useRef)(null),N=(0,l.useCallback)(async()=>{try{let e=await w.F.git.log(t,h);i(e.commits),v(e.commits.length>=h),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{m(!0)}},[t,h]);(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{let e=null,t=k.on("file:changed",t=>{E(t)||(e&&clearTimeout(e),e=setTimeout(()=>{N()},400))}),r=S(k,()=>{N()});return()=>{e&&clearTimeout(e),t(),r()}},[N]),(0,l.useEffect)(()=>{let e=y.current;if(!e||!g)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&f(e=>e+50)});return t.observe(e),()=>t.disconnect()},[g]);let C=(0,l.useCallback)(e=>{p(t=>t===e?null:e),j(r=>(r[e]||w.F.git.commitFiles(t,e).then(t=>j(r=>({...r,[e]:t.files}))).catch(()=>j(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=b[e.hash],d=e.refs?e.refs.split(",").map(e=>e.trim()).filter(Boolean).map(nQ).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:O("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:()=>C(e.hash),className:O("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 ",K(e.date)]})]}),d.length>0&&(0,n.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:d.map(e=>(0,n.jsx)(nX,{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)(n0,{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:y,className:"h-4"})]})}function n5(e){return/authentication|could not read username|permission denied|publickey|passphrase|\b401\b|\b403\b/i.test(e)}function n3(){var e,t,r;let a=(0,eZ.kj)(),s=tx(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),o=nU(e=>e.selected),i=nU(e=>e.select),c=nU(e=>e.clear),[d,u]=(0,l.useState)(null),[m,x]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(""),[v,b]=(0,l.useState)(!1),[j,y]=(0,l.useState)(null),[N,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[T,P]=(0,l.useState)(!1),[F,L]=(0,l.useState)("changes"),[R,_]=(0,l.useState)(null),[z,W]=(0,l.useState)(""),B=(0,l.useCallback)(async()=>{if(s)try{let e=await w.F.git.status(s);if(!1===e.isRepo){h(!0),u(null),_(null),x(null);return}u(e),h(!1),x(null);let t=await w.F.git.remotes(s);_(t.remotes)}catch(e){x(e instanceof Error?e.message:String(e))}},[s]);(0,l.useEffect)(()=>{B()},[B]),(0,l.useEffect)(()=>{if(!s)return;let e=null,t=k.on("file:changed",t=>{E(t)||(e&&clearTimeout(e),e=setTimeout(()=>{B()},400))}),r=S(k,()=>{B()});return()=>{e&&clearTimeout(e),t(),r()}},[s,B]);let U=null!=(e=null==d?void 0:d.files)?e:[],H=U.filter(e=>D(e.index)),K=U.filter(e=>M(e.workingDir));async function G(e){b(!0),y(null);try{await e(),await B()}catch(e){y(e instanceof Error?e.message:String(e))}finally{b(!1)}}let J=(0,l.useCallback)((e,t)=>{i({path:e.path,staged:t,from:e.from})},[i]);function q(e){G(()=>w.F.git.stage(s,e))}function Z(e){G(()=>w.F.git.unstage(s,e))}async function $(){s&&f.trim()&&await G(async()=>{await w.F.git.commit(s,f),g(""),c()})}function Q(){s&&z.trim()&&G(async()=>{await w.F.git.addRemote(s,z.trim()),W("")})}let X=(null!=(t=null==R?void 0:R.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)(n_.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(()=>w.F.git.init(s))},disabled:v,className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,n.jsx)(n_.A,{className:"h-3.5 w-3.5"}),a(v?"sc.initializing":"sc.initRepo")]}),j&&(0,n.jsx)("p",{className:"max-w-[240px] text-[11px] text-red-400",children:j})]}):(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)(nR.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:()=>L("changes"),title:a("sc.viewChanges"),className:O("rounded-l p-1","changes"===F?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,n.jsx)(nz.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>L("graph"),title:a("sc.viewGraph"),className:O("rounded-r p-1","graph"===F?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,n.jsx)(nO.A,{className:"h-3.5 w-3.5"})})]}),(0,n.jsx)("button",{onClick:()=>C(!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)(eo.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>{B()},title:a("sc.refresh"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,n.jsx)(rl.A,{className:O("h-3.5 w-3.5",v&&"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)(nR.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)(nW.A,{className:"h-3 w-3"}),d.behind]}),d.ahead>0&&(0,n.jsxs)("span",{className:"flex items-center",children:[(0,n.jsx)(aU.A,{className:"h-3 w-3"}),d.ahead]})]}),(0,n.jsx)("div",{className:"flex-1"}),X&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>void G(()=>w.F.git.pull(s)),disabled:v,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)(nW.A,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>void G(()=>w.F.git.push(s)),disabled:v,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)(aU.A,{className:"h-3.5 w-3.5"})})]})]}),!X&&"changes"===F&&(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)(aV.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:z,onChange:e=>W(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z.trim()&&Q()},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:Q,disabled:v||!z.trim(),className:"flex items-center justify-center gap-1.5 rounded bg-[var(--primary)] px-2 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,n.jsx)(aV.A,{className:"h-3.5 w-3.5"})," ",a(v?"sc.adding":"sc.addRemote")]})]}),"changes"===F&&(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(),$())},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 $(),disabled:v||!f.trim()||0===H.length,className:"flex items-center justify-center gap-1.5 rounded bg-[var(--primary)] px-2 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,n.jsx)(rh.A,{className:"h-3.5 w-3.5"})," ",a("sc.commit")]})]}),j&&(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:[n5(j)?a("sc.authError"):j,n5(j)&&(0,n.jsx)("button",{onClick:()=>C(!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"===F?(0,n.jsx)(n1,{projectId:s}):m?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:m}):0===U.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:()=>I(e=>!e),className:"flex flex-1 items-center gap-1 text-[11px] font-semibold uppercase tracking-wide text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[A?(0,n.jsx)(Y.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(V.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)(nB.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})]}),!A&&(0,n.jsx)(nH,{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:()=>P(e=>!e),className:"flex flex-1 items-center gap-1 text-[11px] font-semibold uppercase tracking-wide text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[T?(0,n.jsx)(Y.A,{className:"h-3.5 w-3.5"}):(0,n.jsx)(V.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)(ah.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})]}),!T&&(0,n.jsx)(nH,{files:K,group:"changes",selectedPath:o&&!o.staged?o.path:null,onSelect:e=>J(e,!1),onAction:q})]})]})}),N&&(0,n.jsx)(nq,{projectId:s,onClose:()=>C(!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)(nR.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 n2=r(61754);function n4(){let e=(0,eZ.kj)(),t=tx(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),r=nU(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),w.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)(n2.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)(eX,{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)(n2.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 n8=r(98171),n6=r(96739),n9=r(68213),n7=r(75457),le=r(20869),lt=r(20273);let lr=null;function la(){return lr?"[".concat(lr,"] "):""}let ls=["explorer","source-control","sessions","skills","channels","evolution","cron"],ln=null;function ll(e){var t;let{linkState:r}=e,a=(0,eZ.kj)(),s=tx(e=>e.activeProject),c=tx(e=>e.openFolder),d=t4(e=>e.isStreaming),u=t4(e=>e.sessionId),[m,x]=(0,l.useState)(()=>localStorage.getItem("halo_sidebar_tab")||"explorer"),[p,h]=(0,l.useState)(()=>"false"!==localStorage.getItem("halo_sidebar_open")),[f,g]=(0,l.useState)(""),[b,j]=(0,l.useState)(!1),[y,N]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=window.haloPin;e&&e.get().then(N)},[]);let A=(0,l.useCallback)(()=>{let e=window.haloPin;e&&e.toggle().then(N)},[]),I=!!window.haloNotify||"Notification"in window,[T,P]=(0,l.useState)(()=>"true"===localStorage.getItem("halo_notify_on_finish")),F=(0,l.useCallback)(async()=>{let e=!!window.haloNotify;if(!T&&!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})},[T]),L=(0,l.useRef)(d),_=(0,l.useRef)(u);(0,l.useEffect)(()=>{let e=null==s?void 0:s.name;document.title=la()+(e?"".concat(d?"● ":"","Halo — ").concat(e):"Halo");let t=L.current,r=_.current;if(L.current=d,_.current=u,T&&t&&!d&&r===u&&null!=u&&(!function(){try{let e=window.AudioContext||window.webkitAudioContext;if(!e)return;ln||(ln=new e);let t=ln;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,T]),(0,l.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("folder"),t=async(e,t)=>{try{let a=await w.F.fs.resolveWorkspace(e);c(a.path,a.id),g(a.path),C(a.path);try{localStorage.setItem("halo_last_folder",a.path)}catch(e){}var r=a.path;let s=aJ().filter(e=>e!==r);if(s.unshift(r),aq(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=()=>w.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()}},[]);let z=(0,l.useRef)(!1);(0,l.useEffect)(()=>{function e(e){z.current||e.preventDefault()}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let W=(0,l.useCallback)(()=>{let e=v.getState(),t=e.activeTab;if(!t)return!1;let r=e.tabs.find(e=>e.path===t);return(async()=>{(null==r||!r.modified||await H('"'.concat(r.path.split("/").pop(),'" has unsaved changes. Close anyway?')))&&e.closeTab(t)})(),!0},[]);function B(e){v.getState().maximized&&v.getState().setMaximized(!1),m===e&&p?h(!1):(x(e),h(!0))}(0,l.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&"p"===e.key&&(e.preventDefault(),j(e=>!e)),(e.metaKey||e.ctrlKey)&&"`"===e.key){e.preventDefault();let t=v.getState();t.setBottomTab("terminal"===t.bottomTab?"chat":"terminal")}!e.altKey||"KeyW"!==e.code||e.metaKey||e.ctrlKey||(e.preventDefault(),W())}return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[W]),(0,l.useEffect)(()=>{let e=window.haloCloseShortcut;e&&e.onTrigger(()=>{W()||e.closeWindow()})},[W]),(0,l.useEffect)(()=>{function e(e){if("Escape"!==e.key||!v.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}b||v.getState().setMaximized(!1)}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[b]),(0,l.useEffect)(()=>{let e=e=>{let t=e.detail;if(!(null==t?void 0:t.tab))return;let{bottomFloating:r}=v.getState();r&&"explorer"===t.tab||(x(t.tab),h(!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&&K(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(p))},[m,p]);let U=(0,l.useRef)(!1);async function K(e){let t=e.trim();if(!t||U.current)return;U.current=!0;try{let e=await w.F.fs.exists(t);if(!e.exists||!e.isDirectory){window.alert("Workspace not found: ".concat(t)),U.current=!1;return}}catch(e){window.alert(e instanceof Error?e.message:"Failed to validate path"),U.current=!1;return}let r=v.getState().tabs.filter(e=>e.modified);if(r.length>0){let e=r.map(e=>e.path.split("/").pop()).join(", ");if(!await H("Unsaved changes in ".concat(e," will be lost. Switch workspace anyway?"))){U.current=!1;return}}z.current=!0;try{localStorage.setItem("halo_last_folder",t)}catch(e){}let a=new URL(window.location.href);a.searchParams.set("folder",t),window.location.href=a.toString()}let G=(0,l.useCallback)(async e=>{let t=null==s?void 0:s.id;if(t){if(v.getState().tabs.find(t=>t.path===e))return void v.getState().setActiveTab(e);try{let r=await w.F.files.read(e,t),a=J(e);v.getState().openFile(e,r.content,a)}catch(e){console.error("[QuickOpen] Failed to read file:",e)}}},[s]),q=[{id:"explorer",icon:aZ.A,label:a("nav.explorer")},{id:"source-control",icon:nR.A,label:a("nav.sourceControl")},{id:"sessions",icon:ro.A,label:a("nav.sessions")},{id:"skills",icon:a0.A,label:"Skills"},{id:"management",icon:rn.A,label:"Agents"},{id:"channels",icon:sK.A,label:a("nav.channels")},{id:"evolution",icon:rB.A,label:"Evolution"},{id:"cron",icon:nC.A,label:"Cron"},{id:"settings",icon:sy.A,label:a("nav.settings"),position:"bottom"}],Z=null!=(t=null==s?void 0:s.id)?t:null;(0,l.useEffect)(()=>{if(!Z)return;let{setForProject:e,clearProject:t,setRepoStatus:r,clearRepoStatus:a}=R.getState(),s=!1;async function n(){try{let[a,n]=await Promise.all([w.F.git.status(Z),w.F.git.ignored(Z)]);if(!1===a.isRepo){s||(t(Z),r(Z,!1));return}s||(e(Z,function(e,t){let r=new Map,a=new Map;for(let t of e){var s,n;let e=(s=t.index,M(n=t.workingDir)?"?"===n?"?":n:D(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(Z,!0))}catch(e){s||(t(Z),r(Z,!1))}}n();let l=null,o=k.on("file:changed",e=>{E(e)||(l&&clearTimeout(l),l=setTimeout(()=>{n()},400))}),i=S(k,()=>{n()});return()=>{s=!0,l&&clearTimeout(l),o(),i(),t(Z),a(Z)}},[Z]);let V=R(e=>{var t;return null!=(t=Z?e.repoStatus[Z]:void 0)?t:"unknown"}),Y=q.filter(e=>"bottom"!==e.position).filter(e=>"source-control"!==e.id||!1!==V),$=q.filter(e=>"bottom"===e.position),Q=v(e=>e.maximized),X=v(e=>e.bottomFloating),ee=v(e=>e.bottomMaximized),et=p&&!Q,er=ls.includes(m)&&p&&"explorer"!==m,ea="explorer"===m;(0,l.useEffect)(()=>{!1===V&&"source-control"===m&&x("explorer")},[V,m]);let[es]=(0,l.useState)(()=>{if("undefined"==typeof document)return null;let e=document.createElement("div");return e.className="h-full",e}),en=(0,l.useRef)(null),[el,eo]=(0,l.useState)(null),[ei,ec]=(0,l.useState)(null),[ed,eu]=(0,l.useState)(null),em=X?ed:ee?ei:el;return(0,l.useLayoutEffect)(()=>{es&&em&&es.parentElement!==em&&em.appendChild(es)},[es,em]),(0,n.jsxs)("div",{className:"flex h-full",children:[(0,n.jsxs)("div",{className:O("flex w-12 shrink-0 flex-col items-center border-r border-[var(--border)] bg-[var(--card)] py-2",Q&&"hidden"),children:[Y.map(e=>{let t=e.icon,r=m===e.id;return(0,n.jsxs)("button",{onClick:()=>B(e.id),title:e.label,className:O("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"}),$.map(e=>{let t=e.icon,r=m===e.id;return(0,n.jsxs)("button",{onClick:()=>B(e.id),title:e.label,className:O("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!==y&&(0,n.jsx)("button",{onClick:A,title:y?a("workspace.unpin"):a("workspace.pin"),className:O("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",y?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:y?(0,n.jsx)(n8.A,{className:"h-5 w-5"}):(0,n.jsx)(n6.A,{className:"h-5 w-5"})}),I&&(0,n.jsx)("button",{onClick:F,title:T?a("workspace.notifyOn"):a("workspace.notifyOff"),className:O("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",T?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:T?(0,n.jsx)(n9.A,{className:"h-5 w-5"}):(0,n.jsx)(n7.A,{className:"h-5 w-5"})}),(0,n.jsx)("div",{className:"pb-2",title:a("link.".concat(r)),children:"fresh"===r?(0,n.jsx)(le.A,{className:"h-4 w-4 text-emerald-400"}):"stale"===r?(0,n.jsx)(le.A,{className:"h-4 w-4 text-amber-400 animate-pulse"}):(0,n.jsx)(lt.A,{className:"h-4 w-4 text-[var(--destructive)]"})})]}),(0,n.jsx)("div",{className:O("flex min-w-0 flex-1",!ea&&"hidden",Q&&"fixed inset-0 z-40 bg-[var(--background)]"),children:(0,n.jsx)(lo,{showSidebar:et,sidebar:(0,n.jsx)(aY,{projectId:Z,pathInput:f,onPathInputChange:g,onOpenFolder:function(){K(f)},onOpenPath:K,activeProject:s}),main:(0,n.jsx)(li,{projectId:Z,showBottom:!X&&!Q,bottomSlotRef:eo})})}),!ea&&!Q&&(er?(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)(n3,{}),"sessions"===m&&(0,n.jsx)(rp,{}),"skills"===m&&(0,n.jsx)(a9,{}),"channels"===m&&(0,n.jsx)(no,{}),"evolution"===m&&(0,n.jsx)(nb,{}),"cron"===m&&(0,n.jsx)(nL,{})]})}),(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)(lc,{activeTab:m})})]}):(0,n.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,n.jsx)(lc,{activeTab:m})})),b&&(0,n.jsx)(aB,{onSelect:G,onClose:()=>j(!1)}),X&&(0,n.jsx)(az,{slotRef:eu,dragHandleRef:en}),ee&&!X&&(0,n.jsx)("div",{ref:ec,className:"fixed inset-0 z-50 bg-[var(--background)]"}),es&&(0,o.createPortal)((0,n.jsx)(aR,{floating:X,dragHandleRef:en}),es)]})}function lo(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:O("h-full overflow-hidden",!t&&"hidden"),children:r})}),(0,n.jsx)(i.TW,{className:O("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 li(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)(tj,{projectId:t,mode:"editor-only"})}),(0,n.jsx)(i.TW,{className:O("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:O("h-full",!r&&"hidden")})})]})}function lc(e){let{activeTab:t}=e;return"source-control"===t?(0,n.jsx)(n4,{}):"sessions"===t?(0,n.jsx)(sj,{}):"management"===t?(0,n.jsx)(sh,{}):"skills"===t?(0,n.jsx)(sg,{}):"channels"===t?(0,n.jsx)(ni,{}):"evolution"===t?(0,n.jsx)(nu,{}):"cron"===t?(0,n.jsx)(nE,{}):"settings"===t?(0,n.jsx)(sP,{}):null}var ld=r(88900),lu=r(11377);let lm=/<<<CAPTURE>>>/,lx=/<<<SHOW:([\s\S]*?)>>>/g,lp=new Set,lh=new Set,lf=null;function lg(e){e!==lf&&(lf=e,lp.clear(),lh.clear())}async function lv(e){let t=t4.getState(),r=window,a=t.captureSource;if(!a)return;let s="camera"===a.kind;if(!(s?r.haloCamera:r.haloCapture))return;lg(t.sessionId);let n=[...t.messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!n||lp.has(n.id)||!lm.test(n.content))return;lp.add(n.id);let l=tx.getState().activeProject,o=t.sessionId;if(!l||!o)return;let i=W(),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=("undefined"!=typeof localStorage&&"zh"===localStorage.getItem("halo_lang")?lu.zh:ld.en)[s?"capture.cameraFailNote":"capture.failNote"].replace("{name}",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:W(),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:W(),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 lb=(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 lj(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)(nG.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 ly(){let{linkState:e}=function(){let[e,t]=(0,l.useState)(!1),[r,a]=(0,l.useState)("down"),s=(0,l.useRef)(!1),n=tx(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=t4.getState().sessionId)?t:"";k.send({type:"subscribe",sessionId:r,projectId:n})},[e,n]),(0,l.useEffect)(()=>{if(s.current)return;s.current=!0,k.connect();let e=[k.on("_connected",()=>{t(!0),a("fresh");let e=t4.getState().sessionId,r=tx.getState().activeProject;(null==r?void 0:r.id)&&k.send({type:"subscribe",sessionId:null!=e?e:"",projectId:r.id})}),k.on("_disconnected",()=>{t(!1),a("down")}),function(e){let t=[];t.push(e.on("_chat_send_failed",e=>{e.clientMsgId&&t4.getState().markChatSendFailed(e.clientMsgId)})),t.push(e.on("_disconnected",()=>void(tZ=Date.now())));let r=setInterval(()=>{t4.getState().convergeStaleStreaming()},5e3);t.push(()=>clearInterval(r)),t.push(e.on("chat:thinking",e=>{t4.getState().appendThinking(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:stream",e=>{t4.getState().updateLastAssistant(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:complete",t=>{let r=t4.getState();t.text&&r.updateLastAssistant(t.text),r.completeAgentStreaming(),lv(e),function(){let e=t4.getState();lg(e.sessionId);let t=[...e.messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!t)return;let r=0;for(let e of t.content.matchAll(lx)){let a="".concat(t.id,"#").concat(r++);if(lh.has(a))continue;lh.add(a);let s=e[1].trim();s&&e$(s)}}()})),t.push(e.on("chat:stopped",()=>{t4.getState().completeAgentStreaming()})),t.push(e.on("error",e=>{var t;let r=t4.getState(),a=e.code?null!=(t=e.error)?t:"":e.error?"Error: ".concat(e.error):"An unknown error occurred.";r.addMessage({id:W(),role:"system",content:a,timestamp:Date.now(),agentName:e.agentName}),e.taskId||r.completeAgentStreaming(e.agentName)})),t.push(e.on("chat:followup",e=>{let t=t4.getState();if(e.replay){var r;let a=(r=t.sessionId,tV&&r&&tV.sessionId===r?tV.messages:null);a?t.setMessages(a):t.completeAgentStreaming(e.agentName)}else t.completeAgentStreaming(e.agentName);t.addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName})})),t.push(e.on("chat:user",e=>{t4.getState().addMessage({id:W(),role:"user",content:e.text,timestamp:Date.now()})})),t.push(e.on("chat:usage",e=>{let t=t4.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=t4.getState();(e.messages.length>0||e.sessionId)&&e.clear(),rr()})),t.push(e.on("session:switched",t=>{if(!t.sessionId)return;let r=tx.getState().activeProject;if(r)try{localStorage.setItem("halo_session_".concat(r.id),t.sessionId)}catch(e){}let a=t4.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=t4.getState();s.setCompacting(!1),n(),s.setTokenUsage(null!=(r=e.contextTokens)?r:0,s.outputTokens),s.addMessage({id:W(),role:"system",content:a,timestamp:Date.now()})}));let a=null;function s(){a&&clearTimeout(a),a=setTimeout(()=>{t4.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&&(t4.getState().setCompacting(!0),s(),"0"===e[1])){let e=t4.getState().contextTokens;e>0&&(t="Compacting context (~".concat(Math.round(e/1e3),"K tokens)…"))}}t4.getState().addMessage({id:W(),role:"system",content:t,timestamp:Date.now(),taskId:e.taskId,agentName:e.agentName})})),t.push(e.on("chat:queued",e=>{var t;t4.getState().addMessage({id:W(),role:"system",content:null!=(t=e.message)?t:"Message queued.",timestamp:Date.now()})})),["compact:progress","compact:started","compact:summarizing"]))t.push(e.on(r,()=>{t4.getState().setCompacting(!0),s()}));return t.push(e.on("compact:done",()=>{t4.getState().setCompacting(!1),n()})),()=>t.forEach(e=>e())}(k),function(e){let t=[];return t.push(e.on("agent:start",e=>{t4.getState().addMessage({id:W(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName,taskId:e.taskId})})),t.push(e.on("agent:done",e=>{t4.getState().completeAgentStreaming(e.agentName,e.taskId)})),t.push(e.on("agent:context",e=>{var t;t4.getState().addMessage({id:W(),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:{});t4.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:"");t4.getState().updateLastToolCallResult(s,a,e.taskId,e.toolUseId)})),t.push(e.on("agent:configs",e=>{lb.getState().setAgentConfigs(e.agents)})),()=>t.forEach(e=>e())}(k),function(e){let t=[];return t.push(e.on("task:plan",e=>{t4.getState().addMessage({id:W(),role:"assistant",content:"Task plan created: ".concat(e.plan.description),timestamp:Date.now(),plan:e.plan}),lb.getState().setActivePlan(e.plan)})),t.push(e.on("task:status",e=>{lb.getState().updateTaskStatus(e.taskId,e.status)})),t.push(e.on("plan:complete",e=>{t4.getState().addMessage({id:W(),role:"system",content:"Plan completed: ".concat(e.summary),timestamp:Date.now()}),t4.getState().completeStreaming()})),()=>t.forEach(e=>e())}(k),function(e){let t=[];return t.push(e.on("file:changed",e=>{let t=v.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())}(k),function(e){let t=[];return t.push(e.on("state:snapshot",e=>{var t,r;let{snapshot:a}=e;a.sessionId&&(t4.getState().setSessionId(a.sessionId),function(e,t){let r=an.getState();r.sessionId===e&&t<=r.anchor||an.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}(a.sessionId,null!=(t=a.archiveCount)?t:0)),a.agentId&&t4.getState().setSelectedAgentId(a.agentId);let s=t4.getState().messages.some(e=>e.streaming&&!tq(e)),n=null!=(r=a.recentMessages)?r:a.messages;n&&a.sessionId&&(tV={sessionId:a.sessionId,messages:n}),!s&&n&&n.length>0&&t4.getState().setMessages(n),a.activePlan&&lb.getState().setActivePlan(a.activePlan),a.agents&&lb.getState().setAgentConfigs(a.agents),"number"==typeof a.maxContextTokens&&a.maxContextTokens>0&&t4.getState().setMaxContextTokens(a.maxContextTokens)})),t.push(e.on("listener:released",()=>{var t;let r=tx.getState().activeProject;if(!(null==r?void 0:r.id))return;let a=null!=(t=t4.getState().sessionId)?t:"";e.send({type:"subscribe",sessionId:a,projectId:r.id})})),t.push(e.on("session:changed",()=>rr())),t.push(S(e,()=>rr())),t.push(e.on("goal:changed",()=>{var e;let t=null==(e=tx.getState().activeProject)?void 0:e.id;t&&rV(t),rr()})),()=>t.forEach(e=>e())}(k)],r=()=>k.reconnectIfStale(0);window.addEventListener("online",r);let n=0,l=()=>{if(document.hidden){n=Date.now();return}n>0&&Date.now()-n>=3e5&&k.reconnectIfStale(45e3),n=0};document.addEventListener("visibilitychange",l);let o=setInterval(()=>{a(k.connected?k.lastReceiveAgeMs>45e3?"stale":"fresh":"down")},5e3);return()=>{e.forEach(e=>e()),window.removeEventListener("online",r),document.removeEventListener("visibilitychange",l),clearInterval(o),k.disconnect(),s.current=!1}},[]),{connected:e,linkState:r,send:(0,l.useCallback)(e=>{k.send(e)},[])}}(),[t,r]=(0,l.useState)("checking");(0,l.useEffect)(()=>{fetch("/api/auth/check",{credentials:"include"}).then(async e=>{let t=await e.json().catch(()=>null);var a=null==t?void 0:t.badge;let s="string"==typeof a&&a.trim()?a.trim():null;s&&!lr&&(lr=s,document.title=la()+document.title,function(e){let t=document.createElement("canvas");t.width=64,t.height=64;let r=t.getContext("2d");if(!r)return;r.beginPath(),r.moveTo(14.08,0),r.arcTo(64,0,64,64,14.08),r.arcTo(64,64,0,64,14.08),r.arcTo(0,64,0,0,14.08),r.arcTo(0,0,64,0,14.08),r.closePath();let a=r.createLinearGradient(0,0,64,64);a.addColorStop(0,"#0e1430"),a.addColorStop(1,"#070a16"),r.fillStyle=a,r.fill(),r.clip();for(let[e,t]of[[8.96,.55],[13.44,.3]])r.beginPath(),r.arc(32,21.12,e,0,2*Math.PI),r.strokeStyle="rgba(125, 140, 255, ".concat(t,")"),r.lineWidth=2.24,r.stroke();let s=r.createRadialGradient(32,21.12,0,32,21.12,6.4);s.addColorStop(0,"#d8e6ff"),s.addColorStop(1,"#8aa6ff"),r.beginPath(),r.arc(32,21.12,6.4,0,2*Math.PI),r.fillStyle=s,r.fill();r.fillStyle="#e8401c",r.fillRect(0,64-26.88,64,26.88),r.fillStyle="#ffffff",r.textAlign="center",r.textBaseline="middle";let n=Math.round(22.0416);r.font="bold ".concat(n,"px system-ui, sans-serif");for(;n>8&&r.measureText(e).width>58.88;)n-=1,r.font="bold ".concat(n,"px system-ui, sans-serif");r.fillText(e,32,51.56),document.querySelectorAll('link[rel="icon"]').forEach(e=>e.remove());let l=document.createElement("link");l.rel="icon",l.type="image/png",l.href=t.toDataURL("image/png"),document.head.appendChild(l)}(s.slice(0,4))),r(e.ok?"authenticated":"login")}).catch(()=>{r("login")})},[]),(0,l.useEffect)(()=>k.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)(lj,{onSuccess:a}):(0,n.jsx)("div",{className:"h-screen w-screen overflow-hidden bg-[var(--background)]",children:(0,n.jsx)(ll,{linkState:e})})}}},e=>{e.O(0,[372,560,438,133,489,635,358],()=>e(e.s=46601)),_N_E=e.O()}]);