@turmind/halo 1.6.0 → 1.6.2

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 (59) hide show
  1. package/admin-out/404.html +1 -1
  2. package/admin-out/_next/static/chunks/58.d26b1c4f14404226.js +1 -0
  3. package/admin-out/_next/static/chunks/989-ddba0eb72566da23.js +1 -0
  4. package/admin-out/_next/static/chunks/app/page-1d27029caba48956.js +1 -0
  5. package/admin-out/_next/static/chunks/webpack-74f577c1b094f942.js +1 -0
  6. package/admin-out/_next/static/css/3b4dcd0ac6b8eae8.css +1 -0
  7. package/admin-out/index.html +1 -1
  8. package/admin-out/index.txt +5 -5
  9. package/bundled-docs/design/agent.md +6 -4
  10. package/bundled-docs/design/canvas-extensions.md +30 -4
  11. package/bundled-docs/design/cron.md +24 -11
  12. package/bundled-docs/design/prompt-system.md +10 -5
  13. package/bundled-docs/design/session.md +4 -1
  14. package/bundled-docs/design/storage.md +36 -11
  15. package/bundled-docs/design/ws.md +7 -5
  16. package/bundled-docs/dev/add-model-provider.md +17 -11
  17. package/bundled-docs/dev/api.md +25 -12
  18. package/bundled-docs/dev/deploy.md +3 -0
  19. package/bundled-docs/dev/desktop-packaging.md +11 -5
  20. package/bundled-docs/dev/env.md +1 -1
  21. package/bundled-docs/dev/previews.md +26 -0
  22. package/bundled-docs/guide/agents.md +6 -6
  23. package/bundled-docs/guide/cli.md +5 -4
  24. package/bundled-docs/guide/skills.md +12 -6
  25. package/bundled-docs/guide/workspace.md +1 -1
  26. package/bundled-docs/requirements/agent.md +5 -0
  27. package/bundled-docs/requirements/chat.md +9 -5
  28. package/bundled-docs/requirements/command.md +4 -0
  29. package/bundled-docs/requirements/editor.md +20 -6
  30. package/bundled-docs/requirements/session.md +1 -1
  31. package/bundled-docs/requirements/skill.md +15 -9
  32. package/dist/index.js +2332 -1348
  33. package/package.json +1 -1
  34. package/templates/models/anthropic.yaml +109 -13
  35. package/templates/models/aws-bedrock-claude-invoke.yaml +39 -13
  36. package/templates/models/aws-bedrock-mantle.yaml +60 -28
  37. package/templates/models/aws-bedrock-openai.yaml +52 -29
  38. package/templates/models/deepseek.yaml +19 -10
  39. package/templates/models/doubao.yaml +72 -20
  40. package/templates/models/hunyuan.yaml +79 -15
  41. package/templates/models/kimi.yaml +63 -3
  42. package/templates/models/mimo-token-plan-china.yaml +9 -1
  43. package/templates/models/minimax.yaml +9 -3
  44. package/templates/models/openai.yaml +120 -17
  45. package/templates/models/qwen.yaml +103 -6
  46. package/templates/models/zhipu.yaml +9 -1
  47. package/templates/schema.sql +1 -1
  48. package/templates/skills/cron/SKILL.md +40 -3
  49. package/templates/skills/cron/manage-cron.py +140 -15
  50. package/templates/skills/skill/SKILL.md +22 -11
  51. package/templates/skills/workspace/share.md +5 -2
  52. package/templates/skills/workspace/stage.py +51 -14
  53. package/admin-out/_next/static/chunks/220.7566bc89f3d98993.js +0 -1
  54. package/admin-out/_next/static/chunks/989-a7f752480eaaa2dc.js +0 -1
  55. package/admin-out/_next/static/chunks/app/page-8173112f256bc483.js +0 -1
  56. package/admin-out/_next/static/chunks/webpack-dc73047e0279979b.js +0 -1
  57. package/admin-out/_next/static/css/981c9e5610ce535a.css +0 -1
  58. /package/admin-out/_next/static/{_F_Fkyh9PainUNY82EEjY → VgAe62AuGEiYrF4JQ7WQe}/_buildManifest.js +0 -0
  59. /package/admin-out/_next/static/{_F_Fkyh9PainUNY82EEjY → VgAe62AuGEiYrF4JQ7WQe}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{17119:(e,t,r)=>{"use strict";r.d(t,{kj:()=>n.useT,pZ:()=>a.LanguageSelect,s9:()=>n.useI18n});var n=r(19882);r(38115);var a=r(53804);r(24554)},27173:(e,t,r)=>{"use strict";r.d(t,{SQ:()=>o,Tv:()=>s,_H:()=>l,dj:()=>a});var n=r(54604);let a=["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"],s=["mp4","webm","ogg","mov","avi","mkv"],l=["mp3","wav","flac","aac","m4a","wma"],o={id:"media",extensions:[...a,...s,...l],Component:(0,n.lazy)(()=>r.e(220).then(r.bind(r,62839)).then(e=>({default:e.MediaPreview})))}},37050:(e,t,r)=>{"use strict";r.d(t,{IB:()=>d,NU:()=>i,no:()=>c});var n=r(41440),a=r(54604),s=r(48434),l=r(90302),o=r(17119);let i=(0,a.createContext)(null);function c(e){let{name:t,downloadUrl:r,onOpenAsText:c,extraToolbar:u,loading:m,error:p,hideHeader:x,children:f}=e,h=(0,o.kj)(),g=(0,a.useContext)(i);return(0,n.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,n.jsxs)("div",{className:"flex h-8 shrink-0 items-center gap-2 border-b border-[var(--border)] bg-[var(--card)] px-3".concat(x?" hidden":""),children:[(0,n.jsx)("span",{className:"truncate text-xs text-[var(--muted-foreground)]",children:t}),(0,n.jsx)("div",{className:"flex-1"}),u,g,c&&(0,n.jsxs)(d,{onClick:c,title:h("editor.openAsText"),children:[(0,n.jsx)(s.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:h("editor.openAsText")})]}),r&&(0,n.jsxs)("a",{href:r,download:!0,className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:h("editor.download"),children:[(0,n.jsx)(l.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:h("editor.download")})]})]}),(0,n.jsx)("div",{className:"relative min-h-0 flex-1",children:p?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-red-400",children:p}):(0,n.jsxs)(n.Fragment,{children:[f,m&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-[var(--background)]/80 text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})]})})]})}function d(e){let{onClick:t,title:r,children:a}=e;return(0,n.jsx)("button",{onClick:t,title:r,className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:a})}},40909:(e,t,r)=>{"use strict";r.d(t,{$C:()=>l,Z1:()=>o,ZC:()=>i,cn:()=>s,fN:()=>c,fw:()=>d,sQ:()=>m,v7:()=>u});var n=r(59344),a=r(1623);function s(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,a.QP)((0,n.$)(t))}function l(){return Math.random().toString(36).substring(2,10)+Date.now().toString(36)}function o(e){return!!e&&!!(e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\"))}function i(e,t){let r=window;return"function"==typeof r.haloPrompt?r.haloPrompt(e,t):Promise.resolve(window.prompt(e,t))}function c(e){let t=window;return"function"==typeof t.haloConfirm?t.haloConfirm(e):Promise.resolve(window.confirm(e))}function d(e,t){let r="number"==typeof e?e:new Date(e).getTime(),n=Math.floor((Date.now()-r)/6e4);if(n<1)return t?t("time.justNow"):"just now";if(n<60)return t?t("time.minutes",{n:n}):"".concat(n,"m ago");let a=Math.floor(n/60);if(a<24)return t?t("time.hours",{n:a}):"".concat(a,"h ago");let s=Math.floor(a/24);return s<30?t?t("time.days",{n:s}):"".concat(s,"d ago"):new Date(r).toLocaleDateString()}function u(e){return e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}function m(e){var t,r,n;return null!=(n=({ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",html:"html",yaml:"yaml",yml:"yaml",py:"python",rs:"rust",go:"go",sh:"shell",bash:"shell",sql:"sql",toml:"toml",xml:"xml",svg:"xml",env:"plaintext",gitignore:"plaintext",dockerfile:"dockerfile"})[null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""])?n:"plaintext"}},44652:(e,t,r)=>{Promise.resolve().then(r.bind(r,45264))},45264:(e,t,r)=>{"use strict";let n;r.r(t),r.d(t,{default:()=>cy});var a,s,l=r(41440),o=r(54604),i=r(2877),c=r(17640),d=r(60252),u=r(56207);function m(e,t){return"".concat(null!=e?e:"","/").concat(t)}function p(e,t){let r=u.wG.__getMonacoInstance();if(r)for(let a of t){var n;null==(n=r.editor.getModel(r.Uri.parse(m(e,a))))||n.dispose()}}let x=1;function f(){return"g".concat(x++)}function h(e){let t=e.groups[e.activeGroupIdx];if(!t)return{tabs:[],activeTab:null};let r=[];for(let n of t.tabs){let t=e.buffers[n];t&&r.push(t)}return{tabs:r,activeTab:t.activeTab}}function g(e,t,r,n){let a=e.buffers[r]?e.buffers:{...e.buffers,[r]:n()},s=e.groups[t],l=s.tabs.includes(r)?s.tabs:[...s.tabs,r];return{buffers:a,groups:e.groups.map((e,n)=>n===t?{...e,tabs:l,activeTab:r}:e)}}function v(e,t){let r={...e,children:e.children&&[...e.children]},n=r,a=0;for(let e of t){if(!n.children)break;let t=n.children.findIndex(t=>t.name===e&&"directory"===t.type);if(-1===t)break;let r={...n.children[t]};r.children&&(r.children=[...r.children]),n.children[t]=r,n=r,a++}return{root:r,node:n,depth:a}}function b(){return(0,d.v)((e,t)=>({buffers:{},groups:[{id:f(),tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modelPathPrefix:null,setModelPathPrefix(r){t().modelPathPrefix!==r&&e({modelPathPrefix:r})},pinnedTab:null,pinTab(r,n){let a=r.path,s=t().buffers[a];e(e=>{let t=e.groups.findIndex(e=>e.tabs.includes(a)),s=e.pinnedTab===a&&t>=0?t:e.activeGroupIdx,l=e.groups.map((e,t)=>{var r,l;if(t!==s){if(!e.tabs.includes(a))return e;let t=e.tabs.filter(e=>e!==a),r=e.activeTab===a?null!=(l=t[Math.min(e.tabs.indexOf(a),t.length-1)])?l:null:e.activeTab;return{...e,tabs:t,activeTab:r}}let o=[a,...e.tabs.filter(e=>e!==a)];return{...e,tabs:o,activeTab:n?a:null!=(r=e.activeTab)?r:a}}),o=l.length>1?l.filter(e=>e.tabs.length>0):l,i=o.indexOf(l[s]),c=n||o.length!==l.length?i:e.activeGroupIdx,d={...e.buffers,[a]:r},u=e.modifiedPaths.has(a)?(()=>{let t=new Set(e.modifiedPaths);return t.delete(a),t})():e.modifiedPaths,m={...e,buffers:d,groups:o,activeGroupIdx:c,modifiedPaths:u};return{buffers:d,groups:o,activeGroupIdx:c,modifiedPaths:u,pinnedTab:a,...h(m)}}),s&&!s.preview&&p(t().modelPathPrefix,[a])},unpinTab(){let r=t().pinnedTab;r&&(e({pinnedTab:null}),t().closeTab(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(r,n,a,s,l){if(r===t().pinnedTab)return void t().setActiveTab(r);e(e=>{let{buffers:t,groups:o}=g(e,e.activeGroupIdx,r,()=>({path:r,content:n,originalContent:n,language:a,mtime:s,size:null==l?void 0:l.size,createdAt:null==l?void 0:l.createdAt})),i={...e,buffers:t,groups:o};return{buffers:t,groups:o,...h(i)}})},openPreview(r,n,a,s){if(r===t().pinnedTab)return void t().setActiveTab(r);e(e=>{let{buffers:t,groups:l}=g(e,e.activeGroupIdx,r,()=>({path:r,content:"",originalContent:"",language:"",preview:{downloadUrl:n,viewUrl:a,tooLarge:null==s?void 0:s.tooLarge,...(null==s?void 0:s.bundle)?{bundle:!0}:{}},size:null==s?void 0:s.size,mtime:null==s?void 0:s.mtime,createdAt:null==s?void 0:s.createdAt})),o={...e,buffers:t,groups:l};return{buffers:t,groups:l,...h(o)}})},openFileInGroup(r,n,a,s,l,o){if(n===t().pinnedTab)return void t().setActiveTab(n);e(e=>{if(r<0||r>=e.groups.length)return e;let{buffers:t,groups:i}=g(e,r,n,()=>({path:n,content:a,originalContent:a,language:s,mtime:l,size:null==o?void 0:o.size,createdAt:null==o?void 0:o.createdAt})),c={...e,buffers:t,groups:i,activeGroupIdx:r};return{buffers:t,groups:i,activeGroupIdx:r,...h(c)}})},closeTab(r){if(r===t().pinnedTab)return;e(e=>{let t=e.groups.map(e=>{if(!e.tabs.includes(r))return e;let t=e.tabs.filter(e=>e!==r),n=e.activeTab;if(n===r){var a;n=null!=(a=t[Math.min(e.tabs.indexOf(r),t.length-1)])?a:null}return{...e,tabs:t,activeTab:n}}),n=t.some(e=>e.tabs.includes(r)),a=n?e.buffers:(()=>{let{[r]:t,...n}=e.buffers;return n})(),s=n?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(r))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(r),t})(),l=t.length>1&&0===t[1].tabs.length?{groups:[t[0]],activeGroupIdx:0}:{groups:t,activeGroupIdx:Math.min(e.activeGroupIdx,t.length-1)},o={...e,buffers:a,modifiedPaths:s,...l};return{buffers:a,modifiedPaths:s,...l,...h(o)}});let n=t();n.buffers[r]||p(n.modelPathPrefix,[r])},closeTabIn(r,n){if(n===t().pinnedTab)return;e(e=>{if(r<0||r>=e.groups.length)return e;let t=e.groups[r];if(!t.tabs.includes(n))return e;let a=t.tabs.filter(e=>e!==n),s=t.activeTab;if(s===n){var l;s=null!=(l=a[Math.min(t.tabs.indexOf(n),a.length-1)])?l:null}let o=e.groups.map((e,t)=>t===r?{...e,tabs:a,activeTab:s}:e),i=e.activeGroupIdx;o.length>1&&0===o[1].tabs.length&&(o=[o[0]],i=0);let c=o.some(e=>e.tabs.includes(n)),d=c?e.buffers:(()=>{let{[n]:t,...r}=e.buffers;return r})(),u=c?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(n))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(n),t})(),m={...e,groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u};return{groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u,...h(m)}});let a=t();a.buffers[n]||p(a.modelPathPrefix,[n])},setActiveTab(t,r){e(e=>{let n=null!=r?r:-1;if(n<0){let r=e.groups[e.activeGroupIdx];n=(null==r?void 0:r.tabs.includes(t))?e.activeGroupIdx:e.groups.findIndex(e=>e.tabs.includes(t))}if(n<0||!e.groups[n].tabs.includes(t))return e;let a=e.groups.map((e,r)=>r===n?{...e,activeTab:t}:e),s=n,l={...e,groups:a,activeGroupIdx:s};return{groups:a,activeGroupIdx:s,...h(l)}})},updateContent(t,r){e(e=>{let n=e.buffers[t];if(!n)return e;let a=r!==n.originalContent,s={...e.buffers,[t]:{...n,content:r,modified:a}},l=new Set(e.modifiedPaths);a?l.add(t):l.delete(t);let o={...e,buffers:s,modifiedPaths:l};return{buffers:s,modifiedPaths:l,...h(o)}})},setActiveGroup(t){e(e=>{if(t<0||t>=e.groups.length||t===e.activeGroupIdx)return e;let r={...e,activeGroupIdx:t};return{activeGroupIdx:t,...h(r)}})},splitToRight(t){e(e=>{var r,n,a,s;if(e.groups.length>=2)return e;let l=null!=(n=null!=t?t:null==(r=e.groups[e.activeGroupIdx])?void 0:r.activeTab)?n:null;if(l&&l===e.pinnedTab&&(l=null!=(s=null==(a=e.groups[e.activeGroupIdx])?void 0:a.tabs.find(t=>t!==e.pinnedTab))?s:null),!l||!e.buffers[l])return e;let o={id:f(),tabs:[l],activeTab:l},i=[e.groups[0],o],c={...e,groups:i,activeGroupIdx:1};return{groups:i,activeGroupIdx:1,...h(c)}})},closeGroup(r){let n=[];e(e=>{if(e.groups.length<=1||r<0||r>=e.groups.length)return e;let t=e.groups.filter((e,t)=>t!==r),a=new Set;for(let e of t)for(let t of e.tabs)a.add(t);let s={};for(let[t,r]of Object.entries(e.buffers))a.has(t)?s[t]=r:n.push(t);let l=new Set;for(let t of e.modifiedPaths)a.has(t)&&l.add(t);let o=Math.max(0,Math.min(e.activeGroupIdx,t.length-1)),i={...e,groups:t,activeGroupIdx:o,buffers:s,modifiedPaths:l};return{groups:t,activeGroupIdx:o,buffers:s,modifiedPaths:l,...h(i)}}),n.length>0&&p(t().modelPathPrefix,n)},moveTabToGroup(t,r,n,a){e(e=>{if(t===n){if(t<0||t>=e.groups.length)return e;let n=e.groups[t],s=n.tabs.indexOf(r);if(s<0)return e;let l=null==a?n.tabs.length-1:Math.max(0,Math.min(a,n.tabs.length-1));if(s===l)return e;let o=function(e,t,r){let n=[...e],[a]=n.splice(t,1);return n.splice(r,0,a),n}(n.tabs,s,l),i=e.groups.map((e,n)=>n===t?{...e,tabs:o,activeTab:r}:e),c={...e,groups:i};return{groups:i,...h(c)}}if(t<0||t>=e.groups.length||n<0||n>e.groups.length)return e;let s=e.groups[t];if(!s.tabs.includes(r))return e;let l=s.tabs.filter(e=>e!==r),o=s.activeTab;if(o===r){var i;o=null!=(i=l[Math.min(s.tabs.indexOf(r),l.length-1)])?i:null}let c=e.groups.slice();if(n===e.groups.length){if(e.groups.length>=2)return e;c[t]={...s,tabs:l,activeTab:o},c.push({id:f(),tabs:[r],activeTab:r})}else{let e=c[n],i=e.tabs.includes(r)?e.tabs:(()=>{let t=[...e.tabs];return null==a||a>=t.length?t.push(r):t.splice(Math.max(0,a),0,r),t})();c[t]={...s,tabs:l,activeTab:o},c[n]={...e,tabs:i,activeTab:r}}let d=n;0===c[t].tabs.length&&c.length>1&&(c=c.filter((e,r)=>r!==t),d=Math.max(0,Math.min(n>t?n-1:n,c.length-1)));let u={...e,groups:c,activeGroupIdx:d};return{groups:c,activeGroupIdx:d,...h(u)}})},setFileTree(t){e({fileTree:t})},setDirChildren(t,r){e(e=>{if(!e.fileTree)return e;let n=t.split("/").filter(Boolean),{root:a,node:s,depth:l}=v(e.fileTree,n);if(l<n.length)return e;let o=[...r].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name));return s.children=o,s.hasChildren=o.length>0,{fileTree:a}})},markModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let n=new Set(e.modifiedPaths);n.add(t);let a={...e.buffers,[t]:{...r,modified:!0}},s={...e,buffers:a,modifiedPaths:n};return{buffers:a,modifiedPaths:n,...h(s)}})},clearModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let n=new Set(e.modifiedPaths);n.delete(t);let a={...e.buffers,[t]:{...r,modified:!1}},s={...e,buffers:a,modifiedPaths:n};return{buffers:a,modifiedPaths:n,...h(s)}})},markSaved(t,r){e(e=>{let n=e.buffers[t];if(!n)return e;let a=new Set(e.modifiedPaths);a.delete(t);let s={...e.buffers,[t]:{...n,originalContent:n.content,modified:!1,mtime:null!=r?r:n.mtime}},l={...e,buffers:s,modifiedPaths:a};return{buffers:s,modifiedPaths:a,...h(l)}})},setRejectedFile(t){e({rejectedFile:t})},setBottomTab(t){e({bottomTab:t})},pendingTerminalCwd:null,requestTerminalSpawn(t){e({pendingTerminalCwd:t})},consumeTerminalSpawn(){let r=t().pendingTerminalCwd;return null!=r&&e({pendingTerminalCwd:null}),r},toggleMaximized(){e(e=>{let t=!e.maximized;return localStorage.setItem("halo_editor_maximized",String(t)),{maximized:t}})},setMaximized(t){localStorage.setItem("halo_editor_maximized",String(t)),e({maximized:t})},setBottomFloating(t){sessionStorage.setItem("halo_bottom_floating",String(t)),e({bottomFloating:t})},setBottomMaximized(t){e({bottomMaximized:t})},setBottomFloatRect(t){sessionStorage.setItem("halo_bottom_float_rect",JSON.stringify(t)),e({bottomFloatRect:t})},insertFileNode(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"file";e(e=>{if(!e.fileTree)return e;let n=t.split("/").filter(Boolean);if(0===n.length)return e;let a=n.slice(0,-1),{root:s,node:l,depth:o}=v(e.fileTree,a);if(o<a.length||void 0===l.children)return void 0===l.children&&!0!==l.hasChildren?(l.hasChildren=!0,{fileTree:s}):e;let i=n[n.length-1];if(l.children.some(e=>e.name===i))return e;let c="directory"===r?{name:i,path:t,type:"directory",hasChildren:!1,children:[]}:{name:i,path:t,type:"file"};return l.children.push(c),l.children.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),{fileTree:s}})},removeFileNode(t){e(e=>{if(!e.fileTree)return e;let r=t.split("/").filter(Boolean);if(0===r.length)return e;let n=r.slice(0,-1),{root:a,node:s,depth:l}=v(e.fileTree,n);if(l<n.length||!s.children)return e;let o=r[r.length-1],i=s.children.findIndex(e=>e.name===o);return -1===i?e:(s.children.splice(i,1),{fileTree:a})})},async checkAndRefresh(r,n,a){let s=t().buffers[r];if(!s||s.preview||s.mtime&&n<=s.mtime||s.modified)return!1;let l=await a();return e(e=>{var t,n;let a=e.buffers[r];if(!a||a.modified)return e;let s={...e.buffers,[r]:{...a,content:l.content,originalContent:l.content,mtime:l.modifiedAt,size:null!=(t=l.size)?t:a.size,createdAt:null!=(n=l.createdAt)?n:a.createdAt}},o={...e,buffers:s};return{buffers:s,...h(o)}}),!0}}))}let y=b(),j=(0,o.createContext)(null);function w(e){let{children:t}=e,r=(0,o.useRef)(null);return r.current||(r.current=b()),(0,o.useEffect)(()=>{let e=r.current;return()=>{let t=e.getState();p(t.modelPathPrefix,Object.keys(t.buffers))}},[]),(0,o.createElement)(j.Provider,{value:r.current},t)}function N(){let e=(0,o.useContext)(j);return null!=e?e:y}var k=r(43672);class S{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 C=new S;function A(e,t){let r=e.connected;return e.on("_connected",()=>{if(!r){r=!0;return}t()})}function I(e,t){var r,n;return{name:null!=(n=null!=(r=t.root)?r:e.split("/").filter(Boolean).pop())?n:"root",path:"",type:"directory",hasChildren:t.tree.length>0,children:t.tree}}function E(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y;k.F.files.tree(e).then(r=>{t.getState().setFileTree(I(e,r))}).catch(e=>{console.error("[Explorer] Failed to load file tree:",e)})}async function T(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:y;try{let n=await k.F.files.tree(e,t);r.getState().setDirChildren(t,n.tree)}catch(e){console.error("[Explorer] Failed to load directory:",t,e)}}let M=[".halo/sessions/",".halo/logs/",".halo/halo.db"];function F(e){let t=e.path;return"string"==typeof t&&M.some(e=>t.startsWith(e))}let P={M:{letter:"M",color:"#1B81A8",label:"Modified"},A:{letter:"A",color:"#487E02",label:"Added"},D:{letter:"D",color:"#F48771",label:"Deleted"},R:{letter:"R",color:"#2090D3",label:"Renamed"},C:{letter:"C",color:"#2090D3",label:"Copied"},U:{letter:"C",color:"#E4676B",label:"Conflict"},"?":{letter:"U",color:"#487E02",label:"Untracked"}},D={letter:"?",color:"#487E02",label:"Untracked"};function L(e){var t;return null!=(t=P[e])?t:D}function R(e){return""!==e&&" "!==e&&"?"!==e}function _(e){return""!==e&&" "!==e}let z={files:new Map,dirs:new Map,ignored:new Set},O=(0,d.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 U=r(40909),B=r(27322),W=r(54810),H=r(93396),K=r(19478),G=r(54718),q=r(70101),$=r(87212),J=r(74262),Z=r(58781),V=r(44607),Y=r(14909),Q=r(34996),X=r(5431),ee=r(71311),et=r(60086),er=r(13743),en=r(77470),ea=r(2038),es=r(94944),el=r(95342),eo=r(58983),ei=r(28963),ec=r(42563),ed=r(60768);let eu={ts:J.A,tsx:J.A,mts:J.A,cts:J.A,js:J.A,jsx:J.A,mjs:J.A,cjs:J.A,json:Z.A,jsonc:Z.A,html:V.A,htm:V.A,svg:V.A,xml:V.A,css:Y.A,scss:Y.A,sass:Y.A,less:Y.A,md:Q.A,mdx:Q.A,txt:Q.A,rst:Q.A,log:Q.A,csv:X.A,tsv:X.A,xlsx:X.A,xls:X.A,sql:ee.A,sh:et.A,bash:et.A,zsh:et.A,yaml:er.A,yml:er.A,toml:er.A,ini:er.A,env:er.A,py:en.A,go:ea.A,rs:ea.A,c:ea.A,cpp:ea.A,h:ea.A,hpp:ea.A,java:ea.A,kt:ea.A,scala:ea.A,cs:ea.A,swift:ea.A,dart:ea.A,rb:ea.A,php:ea.A,lua:ea.A,r:ea.A,png:es.A,jpg:es.A,jpeg:es.A,gif:es.A,webp:es.A,bmp:es.A,ico:es.A,avif:es.A,mp4:el.A,webm:el.A,mov:el.A,avi:el.A,mkv:el.A,ogg:el.A,mp3:eo.A,wav:eo.A,flac:eo.A,aac:eo.A,m4a:eo.A,wma:eo.A,zip:ei.A,tar:ei.A,gz:ei.A,"7z":ei.A,rar:ei.A,pdf:ec.A,docx:ec.A,doc:ec.A,pptx:ec.A,ppt:ec.A},em={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 ep(e){var t,r,n,a,s,l;let o=null!=(n=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?n:"",i=null!=(a=null==(r=e.split("/").pop())?void 0:r.toLowerCase())?a:"";return"dockerfile"===i||i.startsWith("dockerfile.")?{Icon:et.A,color:"text-cyan-400"}:".gitignore"===i||".gitattributes"===i?{Icon:er.A,color:"text-[var(--muted-foreground)]"}:".env"===i||i.startsWith(".env.")?{Icon:er.A,color:"text-yellow-300"}:"makefile"===i||"cmake"===i?{Icon:et.A,color:"text-[var(--muted-foreground)]"}:{Icon:null!=(s=eu[o])?s:ed.A,color:null!=(l=em[o])?l:"text-[var(--muted-foreground)]"}}let ex=new Map,ef={extensions:[],errors:[]},eh=0,eg=new Set;function ev(){for(let e of(eh++,eg))e()}function eb(e){return eg.add(e),()=>{eg.delete(e)}}function ey(){return eh}function ej(){return(0,o.useSyncExternalStore)(eb,ey,ey)}function ew(e){for(let t of e.extensions)ex.set(t.toLowerCase(),e);ev()}function eN(e){ef=e,ev()}let ek=null;function eS(){if(!ek){let e=k.F.extensions.list().then(eN).catch(e=>{console.error("[PreviewRegistry] Failed to load extensions:",e)});ek=Promise.race([e,new Promise(t=>{let r=setTimeout(()=>{console.warn("[PreviewRegistry] Extension list not back after ".concat(3e3,"ms, opening files without it")),t()},3e3);e.finally(()=>clearTimeout(r))})])}return ek}function eC(){return ef}function eA(e){return e.toLowerCase().replace(/^\./,"")}let eI=null;function eE(){var e;return eI?eI:"undefined"==typeof navigator?"web":eI=(e=navigator.userAgent).includes("Electron/")?/Macintosh|Mac OS X/.test(e)?"desktop-mac":e.includes("Windows")?"desktop-win":"desktop-linux":"web"}function eT(e,t){return e.map(e=>t("extensions.platform.".concat(e))).join(t("extensions.platform.sep"))}function eM(e){return!e.platforms||e.platforms.includes(eE())}function eF(e,t,r){return!!e.bundle===r&&e.extensions.includes(".".concat(t))}function eP(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return ef.extensions.filter(n=>n.priority===t&&eF(n,e,r)&&eM(n)).sort((e,t)=>t.installedAt-e.installedAt).map(e=>({kind:"extension",info:e}))}function eD(e){let t=eA(e),r=eP(t,"default"),n=ex.get(t);return n&&r.push({kind:"builtin",plugin:n}),r.push(...eP(t,"option")),r.push({kind:"text"}),r}function eL(e){let t=eA(e);return[...eP(t,"default",!0),...eP(t,"option",!0),{kind:"text"}]}function eR(e){let t=e.lastIndexOf(".");return!(t<=0)&&eP(eA(e.slice(t+1)),"default",!0).length>0}function e_(e){switch(e.kind){case"extension":return"extension:".concat(e.info.id);case"builtin":return"builtin:".concat(e.plugin.id);case"text":return"text"}}function ez(e){return"text"!==eD(e)[0].kind}let eO="halo:file-tree:expanded",eU=null,eB=new Map;function eW(){if(eU)return eU;try{let e=localStorage.getItem(eO);eU=e?new Set(JSON.parse(e)):new Set}catch(e){eU=new Set}return eU}let eH=null;function eK(e,t){let r=eW(),n=r.has(e);if(t?r.add(e):r.delete(e),eH&&clearTimeout(eH),eH=setTimeout(()=>{try{let e=eW();localStorage.setItem(eO,JSON.stringify([...e]))}catch(e){}},300),n!==t){let r=eB.get(e);if(r)for(let e of r)e(t)}}function eG(e){return eW().has(e)}let eq="application/x-halo-path";function e$(e){let{depth:t,initialValue:r,iconKind:n,onCommit:a,onCancel:s}=e,i=(0,o.useRef)(null),[c,d]=(0,o.useState)(r),u=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=i.current;if(!e)return;e.focus();let t=r.lastIndexOf(".");"file"===n&&t>0?e.setSelectionRange(0,t):e.select()},[r,n]);let m="folder"===n?B.A:W.A;return(0,l.jsxs)("div",{className:"flex w-full items-center gap-1 py-1 text-xs",style:{paddingLeft:"".concat(12*t+8,"px")},children:[(0,l.jsx)("span",{className:"w-3.5 shrink-0"}),(0,l.jsx)(m,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0","folder"===n?"text-blue-400":"fill-[var(--muted-foreground)] text-[var(--muted-foreground)]")}),(0,l.jsx)("input",{ref:i,type:"text",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u.current=!0,a(c)):"Escape"===e.key&&(e.preventDefault(),u.current=!0,s()),e.stopPropagation()},onBlur:()=>{u.current||(""===c.trim()?s():a(c))},className:"min-w-0 flex-1 rounded border border-[var(--primary)] bg-[var(--background)] px-1 py-0 text-xs text-[var(--foreground)] outline-none"})]})}async function eJ(e){let t=e.items;if(t&&t.length>0){let e=[];for(let a=0;a<t.length;a++){var r,n;let s=null==(r=(n=t[a]).webkitGetAsEntry)?void 0:r.call(n);s&&e.push(s)}if(e.some(e=>e.isDirectory)){let t=[];async function a(e,r){if(e.isFile){let n=await new Promise((t,r)=>e.file(t,r)),a=r?"".concat(r,"/").concat(e.name):e.name;t.push(new File([n],a,{type:n.type,lastModified:n.lastModified}))}else if(e.isDirectory){let t,n=e.createReader(),s=r?"".concat(r,"/").concat(e.name):e.name;do for(let e of t=await function(e){return new Promise((t,r)=>e.readEntries(t,r))}(n))await a(e,s);while(t.length>0)}}for(let t of e)await a(t,"");return t}}return Array.from(e.files)}function eZ(e,t){return e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)}function eV(e){let t=[];if(e.path&&t.push(e.path),"directory"===e.type&&e.children&&(!e.path||eG(e.path))){var r;for(let n of[...null!=(r=e.children)?r:[]].sort(eZ))t.push(...eV(n))}return t}function eY(e){var t,r,n;let{node:a,projectId:s,onSelect:i,onContextMenu:c,onDropFiles:d,onMoveFile:u,selectedPaths:m,onSelectionChange:p,lastAnchor:x,visiblePaths:f,depth:h,pendingEdit:g,onCommitEdit:v,onCancelEdit:b}=e,y=N(),[j,w]=(0,o.useState)(()=>!!a.path&&eG(a.path)),[k,S]=(0,o.useState)(!1),[C,A]=(0,o.useState)(!1),I=(0,o.useRef)(null),E=(0,o.useRef)(null),M="directory"===a.type;ej();let F=M&&eR(a.name),P=M&&!1!==a.hasChildren&&void 0===a.children,D=(0,o.useRef)(j),R=(0,o.useCallback)(e=>{w(e),a.path&&eK(a.path,e)},[a.path]);(0,o.useEffect)(()=>{if(a.path){var e,t;let r;return e=a.path,t=e=>w(e),(r=eB.get(e))||(r=new Set,eB.set(e,r)),r.add(t),()=>{let r=eB.get(e);r&&(r.delete(t),0===r.size&&eB.delete(e))}}},[a.path]),(0,o.useEffect)(()=>{let e=D.current;D.current=j,j&&!C&&a.path&&(P||!e)&&(A(!0),T(s,a.path,y).finally(()=>A(!1)))},[j,P,C,a.path,s,y]);let _=y(e=>e.modifiedPaths),J=y(e=>e.activeTab),Z=O(e=>{var t;return null!=(t=s?e.byProject[s]:void 0)?t:z}),V=0===h&&!a.path,Y=(e,t,r)=>{var n;return(0,l.jsxs)(l.Fragment,{children:[e&&g&&(0,l.jsx)(e$,{depth:t,initialValue:"",iconKind:"create-folder"===g.mode?"folder":"file",onCommit:e=>null==v?void 0:v(e),onCancel:()=>null==b?void 0:b()}),(null!=(n=a.children)?n:[]).sort(eZ).map(e=>(0,l.jsx)(eY,{node:e,projectId:s,onSelect:i,onContextMenu:c,onDropFiles:d,onMoveFile:u,selectedPaths:m,onSelectionChange:p,lastAnchor:x,visiblePaths:r,depth:t,pendingEdit:g,onCommitEdit:v,onCancelEdit:b},e.path))]})};if(V){let e=(0,o.useCallback)(()=>eV(a),[a])(),t=async e=>{e.preventDefault(),e.stopPropagation(),S(!1);let t=e.dataTransfer.getData(eq);if(t){null==u||u(t,"");return}let r=await eJ(e.dataTransfer);r.length>0&&(null==d||d(r,""))},r=g&&""===g.parentDir&&"rename"!==g.mode;return(0,l.jsx)("div",{onClick:e=>{e.target===e.currentTarget&&p&&p(new Set,"")},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),null==c||c({x:e.clientX,y:e.clientY,path:"",name:"/",isDir:!0}))},onDragOver:e=>{(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(eq))&&(e.preventDefault(),e.stopPropagation(),S(!0))},onDragLeave:e=>{e.currentTarget===e.target&&S(!1)},onDrop:t,className:(0,U.cn)("min-h-full",k&&"bg-[var(--accent)]/30"),children:Y(!!r,0,e)})}let Q=_.has(a.path),X=J===a.path,ee=null!=(r=null==m?void 0:m.has(a.path))&&r,{Icon:et,color:er}=ep(a.path),en=M?Z.dirs.get(a.path):Z.files.get(a.path),ea=en&&"*"!==en?L(en):null,es="*"===en?"#8C8C8C":null==ea?void 0:ea.color,el=!en&&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}(Z.ignored,a.path),eo=()=>{E.current&&(clearTimeout(E.current),E.current=null)},ei=async e=>{if(!M)return;e.preventDefault(),e.stopPropagation(),S(!1),eo(),j||R(!0);let t=e.dataTransfer.getData(eq);if(t){try{for(let e of JSON.parse(t))e===a.path||e.startsWith(a.path+"/")||null==u||u(e,a.path)}catch(e){t===a.path||t.startsWith(a.path+"/")||null==u||u(t,a.path)}return}let r=await eJ(e.dataTransfer);r.length>0&&(null==d||d(r,a.path))},ec=M&&(null==(t=a.children)?void 0:t.some(e=>{let t=e=>{var r,n;return!!_.has(e.path)||null!=(n=null==(r=e.children)?void 0:r.some(t))&&n};return t(e)})),ed=g&&"rename"===g.mode&&g.originalPath===a.path,eu=g&&"rename"!==g.mode&&g.parentDir===a.path&&M;return ed&&g?(0,l.jsx)(e$,{depth:h,initialValue:null!=(n=g.originalName)?n:a.name,iconKind:M?"folder":"file",onCommit:e=>null==v?void 0:v(e),onCancel:()=>null==b?void 0:b()}):(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{draggable:!0,"data-path":a.path,onClick:e=>{if(e.stopPropagation(),M&&!F&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){p&&p(new Set([a.path]),a.path),R(!j);return}if(e.shiftKey&&p&&f&&x){let e=f.indexOf(x),t=f.indexOf(a.path);if(e>=0&&t>=0){let r=Math.min(e,t),n=Math.max(e,t);p(new Set(f.slice(r,n+1)),x)}return}if((e.ctrlKey||e.metaKey)&&p){let e=new Set(m);e.has(a.path)?e.delete(a.path):e.add(a.path),p(e,a.path);return}(!M||F)&&(p&&p(new Set([a.path]),a.path),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{I.current=null,i(a.path,F?{bundle:!0}:void 0)},300))},onDoubleClick:e=>{e.stopPropagation(),I.current&&(clearTimeout(I.current),I.current=null),M&&!F?R(!j):i(a.path,F?{bundle:!0}:void 0)},onDragStart:e=>{m&&m.size>1&&m.has(a.path)?e.dataTransfer.setData(eq,JSON.stringify([...m])):e.dataTransfer.setData(eq,JSON.stringify([a.path])),e.dataTransfer.effectAllowed="move"},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),!ee&&p&&p(new Set([a.path]),a.path),null==c||c({x:e.clientX,y:e.clientY,path:a.path,name:a.name,isDir:M})},onDragOver:e=>{M&&(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(eq))&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",S(!0),j||E.current||(E.current=setTimeout(()=>{E.current=null,R(!0)},600)))},onDragLeave:()=>{S(!1),eo()},onDrop:ei,className:(0,U.cn)("flex w-full items-center gap-1 py-1 text-left text-xs transition-colors hover:bg-[var(--secondary)]",ee&&"bg-[var(--primary)]/20 text-[var(--foreground)]",!ee&&X&&"bg-[var(--accent)] text-[var(--accent-foreground)]",!ee&&!X&&"text-[var(--foreground)]",k&&M&&"bg-[var(--accent)] ring-1 ring-[var(--primary)]"),style:{paddingLeft:"".concat(12*h+8,"px")},children:[M&&(0,l.jsx)("span",{className:(0,U.cn)("shrink-0 text-[var(--muted-foreground)]",F&&"rounded hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),onClick:e=>{F&&(e.stopPropagation(),R(!j))},onDoubleClick:F?e=>e.stopPropagation():void 0,children:j?(0,l.jsx)(H.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(K.A,{className:"h-3.5 w-3.5"})}),!M&&(0,l.jsx)("span",{className:"w-3.5 shrink-0"}),F?(0,l.jsx)(G.A,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0 text-violet-400",el&&"opacity-60")}):M?j?(0,l.jsx)(q.A,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0 text-blue-400",el&&"opacity-60")}):(0,l.jsx)(B.A,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0 text-blue-400",el&&"opacity-60")}):(0,l.jsx)(et,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",er,el&&"opacity-60")}),(0,l.jsx)("span",{className:(0,U.cn)("truncate",el&&"text-[var(--muted-foreground)] opacity-60"),style:es?{color:es}:void 0,children:a.name}),(0,l.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-1 pl-1 pr-2",children:[(Q||ec)&&(0,l.jsx)(W.A,{className:"h-1.5 w-1.5 shrink-0 fill-amber-400 text-amber-400"}),M?es&&(0,l.jsx)(W.A,{className:"h-1.5 w-1.5 shrink-0",style:{fill:es,color:es}}):ea&&(0,l.jsx)("span",{className:"w-3 text-center font-mono text-[11px] font-semibold",style:{color:ea.color},title:ea.label,children:ea.letter})]})]}),M&&j&&C&&!a.children&&(0,l.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-[10px] text-[var(--muted-foreground)]",style:{paddingLeft:"".concat((h+1)*12+8,"px")},children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin"}),(0,l.jsx)("span",{children:"Loading..."})]}),M&&j&&(a.children||eu)&&(0,l.jsx)("div",{children:Y(!!eu,h+1,f)})]})}var eQ=r(80151),eX=r(66731),e0=r(877),e1=r(94665),e3=r(11943),e5=r(90302),e2=r(19127);function e4(e){let{x:t,y:r,path:n,name:a,isDir:s,selectedCount:i,onAction:c,onClose:d}=e,u=(0,o.useRef)(null),[m,p]=(0,o.useState)({x:t,y:r});(0,o.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,o.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let n=e.getBoundingClientRect(),a=window.innerWidth,s=window.innerHeight,l=t+n.width+4>a?Math.max(4,a-n.width-4):t,o=r+n.height+4>s?Math.max(4,s-n.height-4):r;(l!==m.x||o!==m.y)&&p({x:l,y:o})},[t,r,m.x,m.y]);let x={position:"fixed",left:m.x,top:m.y,zIndex:9999};if(void 0!==i&&i>1)return(0,l.jsxs)("div",{ref:u,style:x,className:"min-w-[140px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",children:[(0,l.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,l.jsxs)("button",{onClick:()=>{c({type:"delete",path:n,isDir:s}),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,l.jsx)(eQ.A,{className:"h-3.5 w-3.5"}),"Delete ",i," items"]})]});let f=""===n&&s,h=!!window.haloReveal,g=f?[{icon:eX.A,label:"New File...",type:"new-file"},{icon:e0.A,label:"New Folder...",type:"new-folder"},{icon:et.A,label:"Open in Integrated Terminal",type:"open-terminal"},...h?[{icon:e1.A,label:"Reveal in File Manager",type:"reveal-in-file-manager"}]:[]]:[{icon:eX.A,label:"New File...",type:"new-file",separatorAfter:!1},{icon:e0.A,label:"New Folder...",type:"new-folder",separatorAfter:!1},{icon:et.A,label:"Open in Integrated Terminal",type:"open-terminal",separatorAfter:!h},...h?[{icon:e1.A,label:"Reveal in File Manager",type:"reveal-in-file-manager",separatorAfter:!0}]:[],...s?eR(a)?[{icon:e3.A,label:"Open to the Side",type:"open-to-side"}]:[]:[{icon:e3.A,label:"Open to the Side",type:"open-to-side",separatorAfter:!1},{icon:e5.A,label:"Download",type:"download"}],{icon:e2.A,label:"Rename",type:"rename"},{icon:eQ.A,label:"Delete",type:"delete",danger:!0,separatorAfter:s},...s?[{icon:q.A,label:"Open as Workspace",type:"open-as-workspace"}]:[]];return(0,l.jsxs)("div",{ref:u,style:x,className:"min-w-[140px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",children:[(0,l.jsx)("div",{className:"truncate border-b border-[var(--border)] px-3 py-1.5 text-[10px] text-[var(--muted-foreground)]",children:a}),g.map(e=>{let t=e.icon;return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{onClick:()=>{c({type:e.type,path:n,isDir:s}),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,l.jsx)(t,{className:"h-3.5 w-3.5"}),e.label]}),e.separatorAfter&&(0,l.jsx)("div",{className:"my-1 border-t border-[var(--border)]"})]},e.type)})]})}u.wG.config({paths:{vs:"/monaco/vs"}});var e8=r(58321);let e6={dark:"vs-dark",light:"vs",midnight:"halo-midnight",warm:"halo-warm"},e9=!1;function e7(e){e9||(e9=!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 te(e){let{path:t,content:r,language:n,onChange:a,onSave:s,onClose:i}=e,c=N(),d=(0,o.useRef)(null),{theme:m}=(0,e8.useTheme)(),p=(0,o.useRef)(s),x=(0,o.useRef)(i),f=(0,o.useRef)(r);(0,o.useEffect)(()=>{p.current=s,x.current=i,f.current=r},[s,i,r]),(0,o.useEffect)(()=>()=>{c.getState().setSelectedText(null,null)},[t]);let h=(0,o.useCallback)(e=>{void 0!==e&&a&&a(e)},[a]),g=(0,o.useCallback)((e,t)=>{d.current=e;let r=e.getModel();r&&r.getValue()!==f.current&&r.setValue(f.current),e.onDidChangeCursorSelection(t=>{var r,n;let a=e.getSelection();if(!a||a.isEmpty())return void c.getState().setSelectedText(null,null);let s=null!=(n=null==(r=e.getModel())?void 0:r.getValueInRange(a))?n:null;s&&c.getState().setSelectedText(s,{startLine:a.startLineNumber,endLine:a.endLineNumber})}),e.addAction({id:"halo-save",label:"Save File",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.KeyS],run:()=>{var e;null==(e=p.current)||e.call(p)}}),e.addAction({id:"halo-close-tab",label:"Close Tab",keybindings:[t.KeyMod.Alt|t.KeyCode.KeyW],run:()=>{var e;null==(e=x.current)||e.call(x)}})},[]);return(0,l.jsx)(u.Ay,{path:t,keepCurrentModel:!0,height:"100%",language:n,value:r,onChange:h,beforeMount:e7,onMount:g,theme:e6[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,l.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,l.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading editor..."})})})}var tt=r(10691),tr=r(76633),tn=r(5659),ta=r(28965),ts=r(17119),tl=r(79906);function to(e){let{content:t,filePath:r,projectId:n}=e,a=(0,ts.kj)(),s=N(),i=(0,o.useRef)(null),c=(0,o.useMemo)(()=>(function(e){let t=[],r=new Map,n=!1;for(let s of e.split("\n")){var a;let e=s.trimEnd();if(/^\s*(```|~~~)/.test(e)){n=!n;continue}if(n)continue;let l=/^(#{1,6})\s+(.+?)\s*#*$/.exec(e);if(!l)continue;let o=l[1].length,i=l[2].trim(),c=i.trim().toLowerCase().replace(/[^\w一-鿿\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"section",d=null!=(a=r.get(c))?a:0;r.set(c,d+1),d>0&&(c="".concat(c,"-").concat(d)),t.push({level:o,text:i,slug:c})}return t})(t),[t]),d=0,u=e=>{let t=i.current;if(!t)return;let r=t.querySelector("#".concat(CSS.escape(e)));r&&r.scrollIntoView({behavior:"smooth",block:"start"})},[m,p]=(0,o.useState)(()=>{try{return"1"===localStorage.getItem("halo.mdOutlineHidden")}catch(e){return!1}}),x=()=>{p(e=>{let t=!e;try{localStorage.setItem("halo.mdOutlineHidden",t?"1":"0")}catch(e){}return t})};(0,o.useEffect)(()=>{let e=i.current;if(!e)return;let t=s.getState().setSelectedText;function r(){let r=window.getSelection();if(!r||0===r.rangeCount)return;let n=r.getRangeAt(0);if(!(e&&e.contains(n.commonAncestorContainer)))return;if(r.isCollapsed)return void t(null,null);let a=r.toString();if(!a.trim())return void t(null,null);t(a,null)}return document.addEventListener("selectionchange",r),()=>{document.removeEventListener("selectionchange",r),t(null,null)}},[s]);let f=e=>function(t){var r;let{children:n}=t;return(0,l.jsx)(e,{id:null==(r=c[d++])?void 0:r.slug,children:n})};return(0,l.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[c.length>1&&!m&&(0,l.jsxs)("nav",{className:"hidden w-56 shrink-0 flex-col overflow-y-auto border-r border-[var(--border)] py-4 md:flex",children:[(0,l.jsxs)("div",{className:"flex shrink-0 items-center justify-between px-3 pb-2",children:[(0,l.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",children:a("editor.outline")}),(0,l.jsx)("button",{onClick:x,title:a("editor.hideOutline"),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tn.A,{className:"h-3.5 w-3.5"})})]}),c.map((e,t)=>(0,l.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,l.jsxs)("div",{ref:i,className:"relative flex-1 overflow-y-auto px-8 py-6",children:[c.length>1&&m&&(0,l.jsx)("button",{onClick:x,title:a("editor.showOutline"),className:"absolute left-2 top-2 z-10 hidden rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] md:block",children:(0,l.jsx)(ta.A,{className:"h-4 w-4"})}),(0,l.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,l.jsx)(tt.oz,{remarkPlugins:[tr.A],components:{h1:f("h1"),h2:f("h2"),h3:f("h3"),h4:f("h4"),h5:f("h5"),h6:f("h6"),a(e){let{href:t,children:r,node:n,...a}=e;return(null==t?void 0:t.startsWith("#"))?(0,l.jsx)("a",{href:t,onClick:e=>{e.preventDefault();let r=t.slice(1);try{r=decodeURIComponent(r)}catch(e){}u(r)},...a,children:r}):(0,l.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...a,children:r})},img(e){let{src:t,alt:a,node:s,...o}=e,i=function(e,t,r){let n;if(!e)return null;if(/^(https?:|data:|blob:)/i.test(e))return e;if(!r)return null;if(e.startsWith("/"))n=e;else{if(!t)return null;let a=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",s=a?"".concat(a,"/").concat(e):e,l=[];for(let e of s.split("/"))""!==e&&"."!==e&&(".."===e?l.pop():l.push(e));n="".concat(r.replace(/\/$/,""),"/").concat(l.join("/"))}let a=new URLSearchParams;return a.set("path",n),a.set("projectId",r),a.set("inline","1"),"/api/files/download?".concat(a.toString())}("string"==typeof t?t:"",r,n);return i?(0,l.jsx)(tl.p,{src:i,alt:null!=a?a:"",...o,placeholderClassName:"my-2 aspect-[4/3] w-full max-w-sm"}):(0,l.jsxs)("span",{className:"rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 text-xs text-[var(--muted-foreground)]",children:["[image unavailable: ",a||String(t),"]"]})}},children:t})})]})]})}let ti=["background","foreground","card","card-foreground","border","input","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","destructive","ring"];function tc(){if("undefined"==typeof document)return{theme:"dark",themeVars:{}};let e=function(e){let t={};for(let r of ti){let n=e.getPropertyValue("--".concat(r)).trim();n&&(t[r]=n)}return t}(getComputedStyle(document.documentElement)),t=e.background?document.createElement("canvas").getContext("2d",{willReadFrequently:!0}):null;if(!t||!e.background)return{theme:"dark",themeVars:e};t.fillStyle=e.background,t.fillRect(0,0,1,1);let[r,n,a]=t.getImageData(0,0,1,1).data;return{theme:function(e){let[t,r,n]=e,a=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*a(t)+.7152*a(r)+.0722*a(n)>.4?"light":"dark"}([r,n,a]),themeVars:e}}let td=".halo/canvas/self.html",tu=new Set,tm=!1;function tp(e){let{theme:t,themeVars:r}=tc();try{var n;null==(n=e.contentWindow)||n.postMessage({haloFaceTheme:{scheme:t,vars:r}},"*")}catch(e){}}function tx(e,t){try{var r;null==(r=e.contentWindow)||r.postMessage({haloFaceLang:t},"*")}catch(e){}}let tf=[];function th(e){let t=e.replace(/[[\]\r\n]+/g," ").replace(/\s+/g," ").trim().slice(0,100);t&&((tf=tf.filter(e=>e!==t)).push(t),tf.length>8&&(tf=tf.slice(-8)))}let tg=null,tv=!1,tb=!1,ty=new Set(["image/jpeg","image/png","image/webp"]),tj=!1;function tw(e){let{url:t,name:r,face:n}=e,a=(0,o.useRef)(null),{theme:s}=(0,e8.useTheme)(),{lang:i}=(0,ts.s9)();return(0,o.useEffect)(()=>{if(n&&a.current){var e;return e=a.current,tu.add(e),tj||(tj=!0,window.addEventListener("message",e=>(function(e,t){var r,n;if(!e||"object"!=typeof e||void 0===e.haloFaceAck&&void 0===e.haloFaceSnap)return;let a=!1;for(let e of tu)e.contentWindow&&e.contentWindow===t&&(a=!0);if(!a)return;"string"==typeof e.haloFaceAck&&th(e.haloFaceAck);let s=e.haloFaceSnap;s&&"string"==typeof s.data&&s.data&&s.data.length<=8388608&&"string"==typeof s.mimeType&&ty.has(s.mimeType)&&(r=s.data,n=s.mimeType,tv?th("snap skipped (1 per round)"):tb?th("snap skipped (chain)"):tg?tg(r,n)&&(tv=!0,tb=!0):th("snap skipped"))})(e.data,e.source))),()=>{tu.delete(e)}}},[n]),(0,o.useEffect)(()=>{n&&a.current&&tp(a.current)},[n,s]),(0,o.useEffect)(()=>{n&&a.current&&tx(a.current,i)},[n,i]),(0,l.jsx)("iframe",{ref:a,src:t,title:r,className:"h-full w-full border-0 ".concat(n?"bg-[var(--background)]":"bg-white"),sandbox:"allow-scripts allow-same-origin",allow:"autoplay",onLoad:n?e=>(function(e,t){if(tp(e),tx(e,t),tm){tm=!1;try{var r;null==(r=e.contentWindow)||r.postMessage({haloFace:"self.intro()"},"*")}catch(e){}}})(e.currentTarget,i):void 0})}let tN=e=>"halo_face_on:".concat(e);function tk(e){return"1"===localStorage.getItem(tN(e))}let tS=(0,d.v)(e=>({on:{},setFaceOn(t,r){tA(t)!==r&&(r?localStorage.setItem(tN(t),"1"):localStorage.removeItem(tN(t)),tf=[],e(e=>({on:{...e.on,[t]:r}})))}})),tC=!1;function tA(e){var t;return!!e&&(null!=(t=tS.getState().on[e])?t:tk(e))}function tI(e){return tS(t=>{var r;return!!e&&(null!=(r=t.on[e])?r:tk(e))})}function tE(e){let{original:t,modified:r,path:n}=e,a=(0,U.sQ)(n),{theme:s}=(0,e8.useTheme)();return(0,l.jsx)(u.zC,{height:"100%",language:a,original:t,modified:r,beforeMount:e7,theme:e6[s],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,l.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,l.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading diff..."})})})}var tT=r(74037),tM=r(97558),tF=r(56279),tP=r(53105);function tD(e){var t,r;let{x:n,y:a,path:s,groupIdx:i,onClose:c,onCloseTab:d}=e,u=N(),m=(0,o.useRef)(null);(0,o.useEffect)(()=>{function e(e){m.current&&!m.current.contains(e.target)&&c()}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]);let p=u.getState(),x=(null!=(r=null==(t=p.groups[i])?void 0:t.tabs)?r:[]).filter(e=>e!==p.pinnedTab).map(e=>p.buffers[e]).filter(e=>!!e),f=x.findIndex(e=>e.path===s),h=[{label:"Close",action:()=>d(s),disabled:s===p.pinnedTab},{label:"Close Others",action:()=>{x.forEach(e=>{e.path!==s&&d(e.path)})},disabled:0===x.filter(e=>e.path!==s).length},{label:"Close to the Right",action:()=>{x.slice(f+1).forEach(e=>d(e.path))},disabled:f>=x.length-1},{label:"Close Saved",action:()=>{x.forEach(e=>{e.modified||d(e.path)})}},{label:"Close All",action:()=>{x.forEach(e=>d(e.path))}}];return(0,l.jsx)("div",{ref:m,className:"fixed z-50 min-w-[160px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",style:{left:n,top:a},children:h.map((e,t)=>(0,l.jsx)("button",{disabled:e.disabled,onClick:()=>{e.action(),c()},className:(0,U.cn)("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 tL="application/x-halo-tab";function tR(e){let{tabs:t,activeTab:r,groupIdx:n,canSplit:a,onCloseTab:s,renderMode:i,onToggleRenderMode:c,showDiffButton:d,onToggleDiff:u}=e,m=(0,ts.kj)(),p=N(),x=(0,o.useRef)(null),[f,h]=(0,o.useState)(!1),[g,v]=(0,o.useState)(!1),[b,y]=(0,o.useState)(null),[j,w]=(0,o.useState)(null),[k,S]=(0,o.useState)(!1),[C,A]=(0,o.useState)(null),I=function(e){var t,r,n,a;let s=new Map,l=new Map;for(let n of e){let e=null!=(t=n.path.split("/").pop())?t:n.path;l.set(e,(null!=(r=l.get(e))?r:0)+1)}for(let t of e){let e=t.path.split("/"),r=null!=(n=e.pop())?n:t.path;(null!=(a=l.get(r))?a:0)>1&&e.length>0?s.set(t.path,"".concat(e[e.length-1],"/").concat(r)):s.set(t.path,r)}return s}(t),E=(0,o.useCallback)(()=>{let e=x.current;e&&(h(e.scrollLeft>0),v(e.scrollLeft+e.clientWidth<e.scrollWidth-1))},[]);(0,o.useEffect)(()=>{E();let e=x.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=x.current)||t.scrollBy({left:e,behavior:"smooth"})},M=()=>{y(null),w(null),S(!1)},F=p(e=>e.activeGroupIdx),P=p(e=>e.pinnedTab);return(0,l.jsxs)("div",{className:(0,U.cn)("relative flex shrink-0 items-center border-b border-[var(--border)] bg-[var(--card)]",k&&"ring-1 ring-[var(--primary)]"),onDragOver:e=>{if(!t_(e))return;let t=e.dataTransfer.types.includes(tL)?{srcGroupIdx:-1,path:""}:null;t&&t.srcGroupIdx!==n&&(e.preventDefault(),e.dataTransfer.dropEffect="move",S(!0))},onDragLeave:e=>{e.currentTarget===e.target&&S(!1)},onDrop:e=>{if(!t_(e))return;e.preventDefault();let t=tz(e);t&&t.srcGroupIdx!==n&&p.getState().moveTabToGroup(t.srcGroupIdx,t.path,n),y(null),w(null),S(!1)},onMouseDown:()=>p.getState().setActiveGroup(n),children:[f&&(0,l.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,l.jsx)(tT.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("div",{ref:x,className:"flex flex-1 overflow-x-hidden",children:t.map((e,t)=>{var a;let{Icon:o,color:i}=ep(e.path),c=e.path===r&&n===F,d=e.path===r&&n!==F;return(0,l.jsxs)("div",{draggable:!0,onDragStart:r=>{var a;return a=e.path,y(t),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),void r.dataTransfer.setData(tL,JSON.stringify({srcGroupIdx:n,path:a}))},onDragOver:e=>{t_(e)&&(e.preventDefault(),e.dataTransfer.dropEffect="move",w(t))},onDrop:e=>((e,t)=>{if(!t_(e))return;e.preventDefault();let r=tz(e);r&&p.getState().moveTabToGroup(r.srcGroupIdx,r.path,n,t),y(null),w(null),S(!1)})(e,t),onDragEnd:M,onContextMenu:t=>{t.preventDefault(),A({x:t.clientX,y:t.clientY,path:e.path})},className:(0,U.cn)("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:()=>{p.getState().setActiveTab(e.path,n),p.getState().setRejectedFile(null)},children:[j===t&&null!==b&&b>t&&(0,l.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),j===t&&null!==b&&b<t&&(0,l.jsx)("div",{className:"absolute right-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),(0,l.jsx)(o,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",i)}),(0,l.jsx)("span",{className:"max-w-40 truncate",children:null!=(a=I.get(e.path))?a:e.path.split("/").pop()}),e.path===P?null:e.modified?(0,l.jsx)(W.A,{className:"h-2 w-2 fill-amber-400 text-amber-400 shrink-0"}):(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),s(e.path)},className:"ml-0.5 rounded p-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-[var(--secondary)]",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})}),e.modified&&e.path!==P&&(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),s(e.path)},className:"ml-0.5 rounded p-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-[var(--secondary)]",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]},e.path)})}),g&&(0,l.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,l.jsx)(K.A,{className:"h-3.5 w-3.5"})}),(()=>{let e=t.find(e=>e.path===r),n=(null==e?void 0:e.language)==="markdown"||(null==e?void 0:e.language)==="html";return(0,l.jsxs)("div",{className:"flex items-center gap-0.5 mr-1",children:[n&&(0,l.jsxs)("button",{onClick:c,title:i?"Switch to source view":"Switch to rendered view",className:(0,U.cn)("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,l.jsx)(e2.A,{className:"h-3 w-3"}):(0,l.jsx)(tF.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{children:i?"Edit":"Preview"})]}),d&&(0,l.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,l.jsx)(tP.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{children:m("editor.diff")})]})]})})(),a&&(0,l.jsx)("button",{title:m("editor.splitRight"),onClick:()=>p.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,l.jsx)(e3.A,{className:"h-3.5 w-3.5"})}),C&&(0,l.jsx)(tD,{x:C.x,y:C.y,path:C.path,groupIdx:n,onClose:()=>A(null),onCloseTab:s})]})}function t_(e){return e.dataTransfer.types.includes(tL)}function tz(e){try{let t=e.dataTransfer.getData(tL);if(!t)return null;return JSON.parse(t)}catch(e){return null}}let tO={id:"pdf",extensions:["pdf"],Component:(0,o.lazy)(()=>r.e(839).then(r.bind(r,9839)).then(e=>({default:e.PdfPreview})))},tU={id:"docx",extensions:["docx","doc"],Component:(0,o.lazy)(()=>r.e(449).then(r.bind(r,32449)).then(e=>({default:e.DocxPreview})))},tB={id:"xlsx",extensions:["xlsx","xls"],Component:(0,o.lazy)(()=>r.e(892).then(r.bind(r,28892)).then(e=>({default:e.XlsxPreview})))},tW={id:"pptx",extensions:["pptx","ppt"],Component:(0,o.lazy)(()=>Promise.all([r.e(819),r.e(522),r.e(160),r.e(868)]).then(r.bind(r,49868)).then(e=>({default:e.PptxPreview}))),heavy:!0};var tH=r(27173);let tK={id:"parquet",extensions:["parquet"],Component:(0,o.lazy)(()=>r.e(613).then(r.bind(r,37613)).then(e=>({default:e.ParquetPreview})))},tG={id:"sqlite",extensions:["db","sqlite","sqlite3"],Component:(0,o.lazy)(()=>r.e(362).then(r.bind(r,84362)).then(e=>({default:e.SqlitePreview})))},tq={id:"csv",extensions:["csv","tsv"],Component:(0,o.lazy)(()=>r.e(73).then(r.bind(r,27073)).then(e=>({default:e.CsvPreview})))};ew(tO),ew(tU),ew(tB),ew(tW),ew(tH.SQ),ew(tK),ew(tG),ew(tq);var t$=r(43180),tJ=r(35418),tZ=r(19875);let tV=e=>e.replace(/\\/g,"/");function tY(e){var t,r;let{workspace:n,accept:a,start:s,onDone:c}=e,d=(0,ts.kj)(),[u,m]=(0,o.useState)(null),[p,x]=(0,o.useState)(null),[f,h]=(0,o.useState)(null),[g,v]=(0,o.useState)(0),[b,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(null),N=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(!1),A=(0,o.useCallback)(e=>{C.current||(C.current=!0,c(e))},[c]),I=(0,o.useCallback)((e,t)=>{x(null),h(null),k.F.fs.browseFiles(e).then(e=>{let t=tV(e.path);m(t),y(t),x(e.entries.map(e=>({...e,path:tV(e.path)})).filter(e=>"directory"===e.type||((e,t)=>{if(0===t.length)return!0;let r=e.toLowerCase();return t.some(e=>r.endsWith(e))})(e.name,a))),v(0)},r=>{if(t&&e!==n)return void I(n,!1);m(e),y(e),x([]),h(r instanceof Error?r.message:String(r))})},[a,n]);(0,o.useEffect)(()=>{I(s,!0)},[I,s]),(0,o.useEffect)(()=>{k.F.fs.home().then(e=>w(tV(e.home)),()=>{})},[]),(0,o.useEffect)(()=>{var e;null==(e=S.current)||e.focus()},[]);let E=u?null!=(r=null==(t=/^[A-Za-z]:\//.exec(u))?void 0:t[0])?r:"/":"/",T=u&&u!==E?u.lastIndexOf("/")<=E.length-1?E:u.slice(0,u.lastIndexOf("/")):null,M=[...null!==T?["up"]:[],...null!=p?p:[]],F=e=>{var t;if("up"===e){null!==T&&I(T,!1);return}if("directory"===e.type)return void I(e.path,!1);A({path:e.path,name:e.name,size:null!=(t=e.size)?t:0})};(0,o.useEffect)(()=>{let e=e=>{var t;let r=(null==(t=e.target)?void 0:t.tagName)==="INPUT";["Escape","Enter","ArrowDown","ArrowUp","Backspace"].includes(e.key)&&(!r||"Backspace"!==e.key)&&(e.preventDefault(),e.stopImmediatePropagation(),"Escape"===e.key?A(null):r&&"Enter"===e.key?b.trim()&&I(tV(b.trim()),!1):"ArrowDown"===e.key?v(e=>Math.min(e+1,M.length-1)):"ArrowUp"===e.key?v(e=>Math.max(e-1,0)):"Backspace"===e.key?null!==T&&I(T,!1):M[g]&&F(M[g]))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)}),(0,o.useEffect)(()=>{var e,t;null==(t=N.current)||null==(e=t.children[g])||e.scrollIntoView({block:"nearest"})},[g]);let P=u?u.slice(E.length).split("/").filter(Boolean):[],D="flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-xs hover:bg-[var(--secondary)]";return(0,i.createPortal)((0,l.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":d("picker.title"),"data-file-picker":!0,className:"fixed inset-0 z-[90] flex items-center justify-center bg-black/40 p-3",onPointerDown:e=>{e.target===e.currentTarget&&A(null)},children:(0,l.jsxs)("div",{ref:S,tabIndex:-1,className:"flex max-h-[85vh] w-full max-w-xl flex-col overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--card)] text-[var(--foreground)] shadow-xl outline-none",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,l.jsx)("span",{className:"text-sm font-medium",children:d("picker.title")}),a.length>0&&(0,l.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:a.join(" ")}),(0,l.jsx)("button",{type:"button",onClick:()=>A(null),"aria-label":d("picker.cancel"),className:"ml-auto rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,l.jsxs)("button",{type:"button",onClick:()=>I(n,!1),className:D,children:[(0,l.jsx)(t$.A,{className:"h-3.5 w-3.5"}),d("picker.workspace")]}),j&&(0,l.jsxs)("button",{type:"button",onClick:()=>I(j,!1),className:D,children:[(0,l.jsx)(tJ.A,{className:"h-3.5 w-3.5"}),d("picker.home")]}),(0,l.jsx)("input",{value:b,onChange:e=>y(e.target.value),"aria-label":d("picker.pathBox"),spellCheck:!1,className:"min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-2 py-1 font-mono text-xs outline-none focus:border-[var(--primary)]"})]}),(0,l.jsxs)("nav",{className:"flex flex-wrap items-center gap-0.5 border-b border-[var(--border)] px-3 py-1.5 text-xs",children:[(0,l.jsx)("button",{type:"button",onClick:()=>I(E,!1),className:"rounded px-1 py-0.5 font-mono hover:bg-[var(--secondary)]",children:E}),P.map((e,t)=>(0,l.jsxs)("span",{className:"flex items-center gap-0.5",children:[t>0&&(0,l.jsx)(K.A,{className:"h-3 w-3 text-[var(--muted-foreground)]"}),(0,l.jsx)("button",{type:"button",onClick:()=>I(E+P.slice(0,t+1).join("/"),!1),className:"rounded px-1 py-0.5 hover:bg-[var(--secondary)]",children:e})]},t))]}),(0,l.jsxs)("div",{ref:N,className:"min-h-[8rem] flex-1 overflow-y-auto py-1",children:[M.map((e,t)=>(0,l.jsx)("button",{type:"button",onClick:()=>F(e),onPointerEnter:e=>{"mouse"===e.pointerType&&v(t)},className:(0,U.cn)("flex w-full items-center gap-2 px-3 py-2.5 text-left text-sm sm:py-1.5 sm:text-xs",t===g?"bg-[var(--accent)] text-[var(--accent-foreground)]":"hover:bg-[var(--secondary)]"),children:"up"===e?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(tZ.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{children:".."})]}):(0,l.jsxs)(l.Fragment,{children:["directory"===e.type?(0,l.jsx)(B.A,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"}):(0,l.jsx)(ed.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name}),"file"===e.type&&void 0!==e.size&&(0,l.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:(0,U.v7)(e.size)})]})},"up"===e?"..":e.path)),null===p&&(0,l.jsx)("p",{className:"px-3 py-4 text-center text-xs text-[var(--muted-foreground)]",children:d("picker.loading")}),null!==p&&f&&(0,l.jsx)("p",{className:"px-3 py-4 text-center text-xs text-[var(--muted-foreground)]",children:f}),null!==p&&!f&&!p.some(e=>"file"===e.type)&&(0,l.jsx)("p",{className:"px-3 py-4 text-center text-xs text-[var(--muted-foreground)]",children:a.length>0?d("picker.emptyAccept",{accept:a.join(" ")}):d("picker.empty")})]}),(0,l.jsx)("div",{className:"flex justify-end border-t border-[var(--border)] px-3 py-2",children:(0,l.jsx)("button",{type:"button",onClick:()=>A(null),className:"rounded-md border border-[var(--border)] bg-[var(--secondary)] px-4 py-1.5 text-xs hover:opacity-90",children:d("picker.cancel")})})]})}),document.body)}var tQ=r(37050);let tX=null,t0=null,t1=(0,o.createContext)(null),t3=null,t5=new Set;function t2(){for(let e of t5)e()}function t4(e){return t5.add(e),()=>{t5.delete(e)}}function t8(){return null!==t3}function t6(){return(0,o.useSyncExternalStore)(t4,t8,()=>!1)}let t9=!1,t7=!1;function re(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t3&&(t7=!1===e.refocus,y.getState().setMaximized(!1))}function rt(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return{ready:!1,dirty:!1,mtime:null,saving:!1,retried:!1,capabilities:e,bundle:t}}function rr(e){return e.capabilities.includes("save")}function rn(e){return e.capabilities.includes("fs-read")}let ra=new Set(["read","write","append","list","stat"]);function rs(e,t){return"string"==typeof e&&(""===e?t:!(e.includes("\\")||e.includes("\0"))&&e.split("/").every(e=>""!==e&&"."!==e&&".."!==e))}function rl(e){var t;if("string"!=typeof e||e.includes("\\")||e.includes("\0"))return!1;let r=null==(t=/^(\/|[A-Za-z]:\/)/.exec(e))?void 0:t[0];if(!r)return!1;let n=e.slice(r.length);return""===n||n.split("/").every(e=>""!==e&&"."!==e&&".."!==e)}function ro(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}function ri(e,t){return{type:"post",frame:{haloExt:1,type:"export-error",reason:e,message:t}}}function rc(e,t,r){return{type:"post",frame:{haloExt:1,type:"fs-result",id:e,ok:!1,code:t,error:r}}}function rd(e,t){return{type:"post",frame:{haloExt:1,type:"pick-result",id:e,...t}}}function ru(e,t,r){if(!r.ok)return{state:e,effects:[rc(t,404===r.status?"not-found":403===r.status?"denied":"io",r.message)]};let{ok:n,...a}=r;return{state:e,effects:[{type:"post",frame:{haloExt:1,type:"fs-result",id:t,ok:!0,...a},...a.buffer?{transfer:[a.buffer]}:{}}]}}function rm(e,t,r){return r.ok?{state:{...e,saving:!1,retried:!1,dirty:!1,mtime:r.mtime},effects:[{type:"post",frame:{haloExt:1,type:"saved",mtime:r.mtime}},{type:"set-modified",modified:!1}]}:"mtime"in r?e.retried?{state:{...e,saving:!1,retried:!1},effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"conflict",message:"file changed on disk again",mtime:r.mtime}},{type:"error",message:"Save failed: the file keeps changing on disk"}]}:{state:{...e,saving:!1},effects:[{type:"confirm-conflict",buffer:t,diskMtime:r.mtime}]}:{state:{...e,saving:!1,retried:!1},effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"io",message:r.message}},{type:"error",message:"Save failed: ".concat(r.message)}]}}let rp=new Map;function rx(e,t){return"".concat(null!=e?e:"","::").concat(t)}let rf=e=>e.replace(/\\/g,"/");async function rh(e){var t;let r=await e.json().catch(()=>({}));return{ok:!1,status:e.status,message:null!=(t=r.error)?t:e.statusText}}async function rg(e){let t=encodeURIComponent(e.path);switch(e.op){case"read":{let e=await fetch("/api/fs/raw?path=".concat(t));return e.ok?{ok:!0,buffer:await e.arrayBuffer()}:await rh(e)}case"list":{let e=await fetch("/api/fs/browse?path=".concat(t,"&files=1"));if(!e.ok)return await rh(e);return{ok:!0,entries:(await e.json()).entries.map(e=>{let{name:t,type:r}=e;return{name:t,type:r}})}}case"stat":{let e=await fetch("/api/fs/stat?path=".concat(t));if(!e.ok)return await rh(e);let r=await e.json();return{ok:!0,size:r.size,mtime:r.modifiedAt}}default:return{ok:!1,status:403,message:"system scope is read-only"}}}async function rv(e,t,r){if("system"===r.scope)try{return await rg(r)}catch(e){return{ok:!1,status:0,message:e instanceof Error?e.message:String(e)}}let n="workspace"===r.scope?r.path:r.path?"".concat(t,"/").concat(r.path):t,a=new URLSearchParams({path:n,projectId:e});try{switch(r.op){case"read":{let t=await fetch(k.F.files.viewUrl(n,e));return t.ok?{ok:!0,buffer:await t.arrayBuffer()}:await rh(t)}case"list":{let e=await fetch("/api/files/tree?".concat(a));if(!e.ok)return await rh(e);let t=await e.json();return{ok:!0,entries:t.tree.map(e=>{let{name:t,type:r}=e;return{name:t,type:r}})}}case"stat":{let e=await fetch("/api/files/stat?".concat(a));if(!e.ok)return await rh(e);let t=await e.json();return{ok:!0,size:t.size,mtime:t.modifiedAt}}case"write":case"append":{let a=await k.F.files.saveRaw(n,r.buffer,e,void 0,{create:!0,append:"append"===r.op,root:t});if(a.ok)return{ok:!0,size:a.size,mtime:a.mtime};return{ok:!1,status:a.status,message:"message"in a?a.message:"conflict"}}}}catch(e){return{ok:!1,status:0,message:e instanceof Error?e.message:String(e)}}}function rb(e){var t,r;let{info:n,uninstalled:a,name:s,path:i,projectId:c,viewUrl:d,downloadUrl:u,size:m,onOpenAsText:p}=e,{t:x,lang:f}=(0,ts.s9)(),h=N(),{theme:g}=(0,e8.useTheme)(),v=(0,o.useMemo)(()=>tc(),[g]),b=(0,o.useRef)(null),y=(0,o.useRef)(rt(n.capabilities,n.bundle)),j=(0,o.useRef)(function(){let e=new Map;return{run(t,r){var n;let a=(null!=(n=e.get(t))?n:Promise.resolve()).then(r),s=a.then(()=>{},()=>{});return e.set(t,s),s.then(()=>{e.get(t)===s&&e.delete(t)}),a}}}()),[w,S]=(0,o.useState)(0),C=(0,o.useRef)(w),[A,I]=(0,o.useState)(null),[E,T]=(0,o.useState)("token"),[M,F]=(0,o.useState)(null),[P,D]=(0,o.useState)(null),[L,R]=(0,o.useState)(null),_=(0,o.useRef)(null),[z,O]=(0,o.useState)(null),B=e=>{_.current=e,O(e)},W=(0,o.useRef)(null),H=(0,o.useRef)(null),K=(0,o.useRef)(n.version),G={file:{name:s,path:i,size:null!=m?m:0,ext:null!=(r=null==(t=s.split(".").pop())?void 0:t.toLowerCase())?r:""},theme:v.theme,themeVars:v.themeVars,platform:eE(),lang:f},q=(0,o.useRef)(G),$=(0,o.useRef)(()=>{}),J=(0,o.useCallback)(e=>{for(let t of(y.current=e.state,e.effects))$.current(t)},[]),Z=()=>{W.current&&(clearTimeout(W.current),W.current=null)},V=e=>{var t,r,a,s,l;switch(e.type){case"post":null==(r=b.current)||null==(t=r.contentWindow)||t.postMessage(e.frame,"*",null!=(a=e.transfer)?a:[]);return;case"load":(async()=>{try{var e;let[t,r]=await Promise.all([fetch(d),c?k.F.files.stat(i,c).catch(()=>null):Promise.resolve(null)]);if(!t.ok)throw Error("HTTP ".concat(t.status));let n=await t.arrayBuffer();J(function(e,t,r){let n=[{type:"post",frame:{haloExt:1,type:"load",buffer:t,mtime:null!=r?r:0},transfer:[t]}];return e.dirty&&n.push({type:"set-modified",modified:!1}),{state:{...e,mtime:r,dirty:!1},effects:n}}(y.current,n,null!=(e=null==r?void 0:r.modifiedAt)?e:null))}catch(e){F("Failed to load file: ".concat(e instanceof Error?e.message:String(e)))}})();return;case"put":if(Z(),!c)return void J(rm(y.current,e.buffer,{ok:!1,status:0,message:"no workspace"}));k.F.files.saveRaw(i,e.buffer,c,null!=(s=e.expectMtime)?s:void 0).then(t=>J(rm(y.current,e.buffer,t)));return;case"set-modified":e.modified?h.getState().markModified(i):h.getState().clearModified(i);return;case"error":F(e.message);return;case"confirm-conflict":(async()=>{let t=i.split("/").pop(),r=await (0,U.fN)('"'.concat(t,'" changed on disk since you opened it. Overwrite the disk version with your changes?'))?"overwrite":await (0,U.fN)('Discard your changes and reload "'.concat(t,'" from disk? (Cancel keeps your unsaved changes.)'))?"discard":"cancel";J(function(e,t,r,n){switch(t){case"overwrite":return{state:{...e,saving:!0,retried:!0},effects:[{type:"put",buffer:r,expectMtime:n}]};case"discard":return{state:e,effects:[{type:"load"}]};case"cancel":return{state:e,effects:[]}}}(y.current,r,e.buffer,e.diskMtime))})();return;case"warn":console.warn("[ExtensionHost] ".concat(n.id,": ").concat(e.message));return;case"fs":{if(!c)return void J(ru(y.current,e.id,{ok:!1,status:0,message:"no workspace"}));let t=C.current,r=()=>rv(c,i,e);("write"===e.op||"append"===e.op?j.current.run(e.path,r):r()).then(r=>{C.current===t&&J(ru(y.current,e.id,r))});return}case"export":{let t=C.current,r=e=>{C.current===t&&$.current(e)};if(!c)return void r(ri("io","no workspace"));let n=i.lastIndexOf("/"),a=n<0?e.name:"".concat(i.slice(0,n),"/").concat(e.name);(async()=>{if(await k.F.files.stat(a,c).then(()=>!0,()=>!1)&&!await (0,U.fN)(x("editor.extension.exportOverwrite",{name:e.name})))return r(ri("cancelled","overwrite declined"));let t=await k.F.files.saveRaw(a,e.buffer,c,void 0,{create:!0});if(t.ok){r({type:"post",frame:{haloExt:1,type:"exported",name:e.name,path:a}}),D({path:a,url:k.F.files.downloadUrl(a,c)});return}let n="message"in t?t.message:"HTTP ".concat(t.status);r(ri("io",n)),F(x("editor.extension.exportFailed",{message:n}))})();return}case"pick":{if(!c||_.current)return void J({state:y.current,effects:[rd(e.id,{ok:!1,code:"cancelled",error:c?"a picker is already open":"no workspace"})]});let t=document.fullscreenElement;t&&t!==document.documentElement&&document.exitFullscreen().catch(()=>{});let r=rf(c).replace(/(.)\/$/,"$1"),a=null!=(l=e.start)?l:n.bundle?i:i.includes("/")?i.slice(0,i.lastIndexOf("/")):"",s=rl(a)?a:a?"".concat(r,"/").concat(a):r;B({id:e.id,accept:e.accept,start:s,attempt:C.current});return}}},Y=async e=>{let t=_.current;B(null);let r=e=>{t&&t.attempt===C.current&&(J({state:y.current,effects:[rd(t.id,e)]}),ec())};if(!e||!c)return void r({ok:!1,code:"cancelled",error:"picker closed"});try{let[t,n]=await Promise.all([k.F.fs.stat(e.path),k.F.fs.stat(c)]),a=rf(t.realPath),s=rf(n.realPath).replace(/(.)\/$/,"$1"),l=a.startsWith(s.endsWith("/")?s:"".concat(s,"/"));r({ok:!0,path:l?a.slice(s.length).replace(/^\//,""):e.path,name:e.name,size:t.size})}catch(e){r({ok:!1,code:"cancelled",error:"could not stat the picked file: ".concat(e instanceof Error?e.message:String(e))})}};(0,o.useEffect)(()=>{q.current=G,$.current=V});let Q=()=>{R(null),T("token"),F(null),I(null),S(e=>e+1)};(0,o.useEffect)(()=>{let e=!1;return C.current=w,y.current.dirty&&h.getState().clearModified(i),y.current=rt(n.capabilities,n.bundle),(tX&&tX.expiresAt-Date.now()>6e4?Promise.resolve(tX.token):(!t0&&(t0=k.F.extensions.token().then(e=>(tX=e,e.token)).finally(()=>{t0=null})),t0)).then(t=>{if(!e){var r,a,s;K.current=n.version,I((r=n.id,a=n.version,s=n.entry,"/api/extensions/".concat(encodeURIComponent(r),"/").concat(encodeURIComponent(a),"/").concat(encodeURIComponent(t),"/").concat(s))),T("loading"),H.current=setTimeout(()=>{y.current.ready||T("failed")},1e4)}}).catch(t=>{e||(F(t instanceof Error?t.message:String(t)),T("failed"))}),()=>{e=!0,H.current&&clearTimeout(H.current)}},[w]),(0,o.useEffect)(()=>{let e=e=>{var t,r;e.source===(null==(t=b.current)?void 0:t.contentWindow)&&"object"==typeof(r=e.data)&&null!==r&&1===r.haloExt&&"string"==typeof r.type&&("ready"===e.data.type&&(H.current&&(clearTimeout(H.current),H.current=null),T("ready")),"save"===e.data.type&&Z(),J(function(e,t,r){switch(t.type){case"ready":{let t=e.dirty?[{type:"set-modified",modified:!1}]:[],n={type:"post",frame:{haloExt:1,type:"init",protocol:1,file:r.file,capabilities:e.capabilities,theme:r.theme,themeVars:r.themeVars,bundle:e.bundle,platform:r.platform,lang:r.lang,export:rr(e)&&!e.bundle}};return{state:{...e,ready:!0,dirty:!1},effects:e.bundle?[...t,n]:[...t,n,{type:"load"}]}}case"dirty":if(!e.ready)return{state:e,effects:[{type:"warn",message:"dirty before ready ignored"}]};if(!rr(e)&&!e.bundle)return{state:e,effects:[{type:"warn",message:"dirty from an extension without the save capability ignored"}]};if(e.dirty===t.dirty)return{state:e,effects:[]};return{state:{...e,dirty:t.dirty},effects:[{type:"set-modified",modified:t.dirty}]};case"save":if(!e.ready)return{state:e,effects:[{type:"warn",message:"save before ready ignored"}]};if(!rr(e))return{state:e,effects:[{type:"post",frame:{haloExt:1,type:"save-error",reason:"denied",message:"extension did not declare the save capability"}},{type:"warn",message:"save from an extension without the save capability denied"}]};if(e.saving)return{state:e,effects:[{type:"warn",message:"save while a save is in flight dropped"}]};return{state:{...e,saving:!0},effects:[{type:"put",buffer:t.buffer,expectMtime:e.mtime}]};case"error":return{state:e,effects:[{type:"error",message:t.message}]};case"fs":let{id:n}=t;if("number"!=typeof n||!Number.isFinite(n))return{state:e,effects:[{type:"warn",message:"fs frame without a numeric id ignored"}]};if(void 0!==t.scope){let{scope:r}=t;return"workspace"!==r&&"system"!==r?{state:e,effects:[rc(n,"denied","unknown fs scope: ".concat(String(r)))]}:rn(e)?ra.has(t.op)?"write"===t.op||"append"===t.op?{state:e,effects:[rc(n,"denied","".concat(r," scope is read-only"))]}:("system"===r?rl(t.path):rs(t.path,"list"===t.op))?{state:e,effects:[{type:"fs",id:n,op:t.op,path:t.path,scope:r}]}:{state:e,effects:[rc(n,"invalid-path","invalid ".concat(r," path: ").concat(JSON.stringify(t.path)))]}:{state:e,effects:[rc(n,"denied","unknown fs op: ".concat(String(t.op)))]}:{state:e,effects:[rc(n,"denied","".concat(r," fs needs the fs-read capability")),{type:"warn",message:"".concat(r," fs without fs-read denied")}]}}if(!e.bundle)return{state:e,effects:[rc(n,"denied","fs is only available to bundle extensions"),{type:"warn",message:"fs from a non-bundle extension denied"}]};if(!ra.has(t.op))return{state:e,effects:[rc(n,"denied","unknown fs op: ".concat(String(t.op)))]};if(!rs(t.path,"list"===t.op))return{state:e,effects:[rc(n,"invalid-path","invalid bundle path: ".concat(JSON.stringify(t.path)))]};if("write"===t.op||"append"===t.op)return ro(t.buffer)?{state:e,effects:[{type:"fs",id:n,op:t.op,path:t.path,buffer:t.buffer}]}:{state:e,effects:[rc(n,"io","".concat(t.op," needs an ArrayBuffer buffer"))]};return{state:e,effects:[{type:"fs",id:n,op:t.op,path:t.path}]};case"export":var a;if(!e.ready)return{state:e,effects:[{type:"warn",message:"export before ready ignored"}]};if(!rr(e)||e.bundle)return{state:e,effects:[ri("denied","export needs the save capability (non-bundle)"),{type:"warn",message:"export from an extension without export support denied"}]};return"string"!=typeof(a=t.name)||""===a||"."===a||".."===a||/[/\\\0]/.test(a)?{state:e,effects:[ri("invalid","invalid export file name: ".concat(JSON.stringify(t.name)))]}:t.name===r.file.name?{state:e,effects:[ri("invalid","export must not overwrite the open file")]}:ro(t.buffer)?{state:e,effects:[{type:"export",name:t.name,buffer:t.buffer}]}:{state:e,effects:[ri("invalid","export needs an ArrayBuffer buffer")]};case"pick":let{id:s}=t;if("number"!=typeof s||!Number.isFinite(s))return{state:e,effects:[{type:"warn",message:"pick frame without a numeric id ignored"}]};if(!rn(e))return{state:e,effects:[rd(s,{ok:!1,code:"denied",error:"pick needs the fs-read capability"}),{type:"warn",message:"pick without fs-read denied"}]};let l=Array.isArray(t.accept)?t.accept.filter(e=>"string"==typeof e&&""!==e).map(e=>e.toLowerCase()):[],o=rs(t.start,!0)||rl(t.start)?t.start:void 0;return{state:e,effects:[{type:"pick",id:s,accept:l,...void 0!==o?{start:o}:{}}]}}}(y.current,e.data,q.current)))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[J]),(0,o.useEffect)(()=>{var e,t,r;J((e=y.current,t=v.theme,r=v.themeVars,e.ready?{state:e,effects:[{type:"post",frame:{haloExt:1,type:"theme",theme:t,themeVars:r}}]}:{state:e,effects:[]}))},[v,J]),(0,o.useEffect)(()=>{var e;J((e=y.current,e.ready?{state:e,effects:[{type:"post",frame:{haloExt:1,type:"lang",lang:f}}]}:{state:e,effects:[]}))},[f,J]);let X=(0,o.useCallback)(()=>{var e;let t=(e=y.current).ready&&rr(e)&&e.dirty&&!e.saving?{state:e,effects:[{type:"post",frame:{haloExt:1,type:"save-request"}}]}:{state:e,effects:[]};J(t),0!==t.effects.length&&(Z(),W.current=setTimeout(()=>{W.current=null,y.current.dirty&&!y.current.saving&&window.alert('Extension "'.concat(n.name,'" did not respond to the save request.'))},5e3))},[J,n.name]);(0,o.useEffect)(()=>(function(e,t,r){let n=rx(e,t);return rp.set(n,r),()=>{rp.get(n)===r&&rp.delete(n)}})(c,i,{requestSave:X,fileChanged(){c&&!y.current.bundle&&k.F.files.stat(i,c).then(e=>{var t,r;return J((t=y.current,r=e.modifiedAt,!t.ready||t.bundle||null!=t.mtime&&r<=t.mtime||t.dirty?{state:t,effects:[]}:{state:t,effects:[{type:"load"}]}))}).catch(()=>{})}}),[c,i,X,J]),(0,o.useEffect)(()=>{if(n.version!==K.current){if(y.current.dirty)return void R(x("editor.extension.updated",{version:n.version}));Q()}},[n.version,x]),(0,o.useEffect)(()=>()=>{Z(),y.current.dirty&&h.getState().clearModified(i)},[h,i]);let ee=async()=>{(!y.current.dirty||await (0,U.fN)('"'.concat(s,'" has unsaved changes. Discard them and reload?')))&&Q()},et=(0,o.useContext)(t1)===i&&!n.capabilities.includes("save"),[er,en]=(0,o.useState)(!1),[ea]=(0,o.useState)(()=>(function(e){let{enterMs:t=2500,leaveMs:r=1500,tapMs:n=3e3}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=!1,s=null,l=t=>{t!==a&&(a=t,e(t))},o=()=>{s&&(clearTimeout(s),s=null)},i=e=>{o(),s=setTimeout(()=>{s=null,l(!1)},e)};return{start(){l(!0),i(t)},move(e){if(e<=48){o(),l(!0);return}a&&!s&&i(r)},tap(e){e>48||(l(!0),i(n))},dispose:o}})(en)),[es]=(0,o.useState)(()=>{var e,t;return!!(null==(e=(t=window).matchMedia)?void 0:e.call(t,"(pointer: coarse)").matches)}),el=(0,o.useRef)(!1),[eo,ei]=(0,o.useState)(0),ec=()=>{var e;let t=b.current;null==t||t.focus(),null==t||null==(e=t.contentWindow)||e.focus()};(0,o.useEffect)(()=>{if(!et)return;let e=function(){let e={};return t3=e,t2(),()=>{t3===e&&(t3=null,t2())}}();ea.start();let t=!1,r=!1,n=document.documentElement;(function(){let e=t9;return t9=!1,e})()&&!document.fullscreenElement&&n.requestFullscreen&&n.requestFullscreen().then(()=>{t=!0,r&&document.exitFullscreen().catch(()=>{})},()=>{});let a=document.fullscreenElement,s=()=>{let e=document.fullscreenElement,r=null!==a&&a!==n;a=e,t&&!e&&(t=!1,r||re())},l=e=>{"mouse"===e.pointerType&&ea.move(e.clientY)},o=()=>ea.move(1/0),i=e=>{"mouse"!==e.pointerType&&ea.tap(e.clientY)};return document.addEventListener("fullscreenchange",s),window.addEventListener("pointermove",l),n.addEventListener("mouseleave",o),window.addEventListener("pointerdown",i,!0),()=>{r=!0,document.removeEventListener("fullscreenchange",s),window.removeEventListener("pointermove",l),n.removeEventListener("mouseleave",o),window.removeEventListener("pointerdown",i,!0),ea.dispose(),e(),t&&document.fullscreenElement===n&&document.exitFullscreen().catch(()=>{}),function(){let e=!t7;return t7=!1,e}()&&ec()}},[et,ea]),(0,o.useEffect)(()=>{if(!et||0===eo)return;let e=b.current,t=null==e?void 0:e.contentWindow;if(!e||!t)return;let r=()=>e.getBoundingClientRect().top,n=e=>{"Escape"===e.key&&(t.document.fullscreenElement||(e.preventDefault(),e.stopPropagation(),re()))},a=e=>{"mouse"===e.pointerType&&ea.move(e.clientY+r())},s=()=>ea.move(1/0),l=e=>{"mouse"!==e.pointerType&&ea.tap(e.clientY+r())},o=null;try{o=t.document,t.addEventListener("keydown",n,!0),t.addEventListener("pointermove",a),t.addEventListener("pointerdown",l,!0),o.documentElement.addEventListener("mouseleave",s)}catch(e){}return ec(),()=>{try{t.removeEventListener("keydown",n,!0),t.removeEventListener("pointermove",a),t.removeEventListener("pointerdown",l,!0),null==o||o.documentElement.removeEventListener("mouseleave",s)}catch(e){}}},[et,eo,ea]);let ed=n.capabilities.includes("save")?(0,l.jsx)(tQ.IB,{onClick:X,title:x("editor.extension.save"),children:(0,l.jsx)("span",{children:x("editor.extension.save")})}):void 0;return(0,l.jsx)(tQ.no,{name:s,downloadUrl:u,onOpenAsText:p,extraToolbar:ed,hideHeader:et,children:(0,l.jsxs)("div",{"data-immersive":et||void 0,className:(0,U.cn)("flex h-full flex-col",et&&"fixed inset-0 z-[70] bg-[var(--background)]"),children:[a&&(0,l.jsx)(ry,{children:x("editor.extension.uninstalled")}),L&&(0,l.jsxs)(ry,{onClose:()=>R(null),children:[L,(0,l.jsx)("button",{onClick:ee,className:"ml-2 text-[var(--primary)] hover:underline",children:x("editor.extension.reload")})]}),M&&"failed"!==E&&(0,l.jsx)(ry,{onClose:()=>F(null),children:M}),P&&(0,l.jsxs)(ry,{onClose:()=>D(null),children:[x("editor.extension.exported",{path:P.path}),(0,l.jsx)("a",{href:P.url,download:!0,className:"ml-2 text-[var(--primary)] hover:underline",children:x("editor.download")})]}),"failed"===E?(0,l.jsxs)("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[(0,l.jsx)("p",{className:"text-sm text-[var(--foreground)]",children:x("editor.extension.unresponsive",{name:n.name})}),M&&(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:M}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:ee,className:"inline-flex items-center rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90",children:x("editor.extension.retry")}),p&&(0,l.jsx)("button",{onClick:p,className:"inline-flex items-center rounded-md border border-[var(--border)] bg-[var(--secondary)] px-4 py-2 text-xs font-medium text-[var(--foreground)] hover:opacity-90",children:x("editor.openAsText")})]})]}):(0,l.jsxs)("div",{className:"relative min-h-0 flex-1",children:[A&&(0,l.jsx)("iframe",{ref:b,src:A,sandbox:"allow-scripts allow-same-origin",allow:n.capabilities.includes("media")?"microphone; display-capture; clipboard-write":"",referrerPolicy:"no-referrer",title:n.name,className:"h-full w-full border-0 bg-[var(--background)]",onLoad:()=>ei(e=>e+1)},w),"ready"!==E&&(0,l.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-[var(--background)]/80 text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})]}),z&&c&&(0,l.jsx)(tY,{workspace:rf(c),accept:z.accept,start:z.start,onDone:e=>{Y(e)}}),et&&(0,l.jsx)("button",{type:"button",onPointerDown:()=>{el.current=!0},onClick:e=>{let t=el.current;el.current=!1,(t||0===e.detail)&&re()},onPointerEnter:e=>{"mouse"===e.pointerType&&ea.move(0)},"aria-label":x("editor.immersive.exit"),className:(0,U.cn)("absolute z-10 flex items-center justify-center rounded-full border border-[var(--border)] bg-[var(--card)]/90 text-xs text-[var(--foreground)] shadow-lg backdrop-blur transition-all duration-200",es?"left-2":"left-1/2 -translate-x-1/2",er?"top-2 h-7 gap-1 px-3 opacity-100":es?"top-1.5 h-7 w-7 opacity-60":"pointer-events-none -top-2 h-7 px-3 opacity-0"),children:er||!es?x("editor.immersive.exit"):"\xd7"})]})})}function ry(e){let{children:t,onClose:r}=e;return(0,l.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5 text-xs text-[var(--foreground)]",children:[(0,l.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t}),r&&(0,l.jsx)("button",{onClick:r,className:"shrink-0 text-[var(--muted-foreground)] hover:text-[var(--foreground)]","aria-label":"Dismiss",children:"\xd7"})]})}var rj=r(46415),rw=r(22726);function rN(e){let{candidates:t,current:r,onPick:n}=e,a=(0,ts.kj)(),[s,i]=(0,o.useState)(!1),c=e_(r);return(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsxs)("button",{onClick:()=>i(e=>!e),title:a("editor.openWith"),className:"flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[(0,l.jsx)(rj.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{children:a("editor.openWith")})]}),s&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"fixed inset-0 z-20",onClick:()=>i(!1)}),(0,l.jsx)("div",{className:"absolute right-0 top-full z-30 mt-0.5 min-w-[180px] rounded-md border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:t.map(e=>{let t=e_(e),r=t===c;return(0,l.jsxs)("button",{onClick:()=>{i(!1),r||n(e)},className:(0,U.cn)("flex w-full items-center gap-2 px-3 py-1.5 text-left text-[11px] transition-colors hover:bg-[var(--secondary)]",r?"text-[var(--foreground)]":"text-[var(--foreground)]/80"),children:[(0,l.jsx)(rw.A,{className:(0,U.cn)("h-3 w-3 shrink-0",!r&&"invisible")}),(0,l.jsx)("span",{className:"truncate",children:"text"===e.kind?a("editor.openAsText"):"builtin"===e.kind?a("editor.openWith.builtin",{id:e.plugin.id}):e.info.name}),"extension"===e.kind&&(0,l.jsxs)("span",{className:"ml-auto shrink-0 text-[9px] text-[var(--muted-foreground)]",children:["v",e.info.version]})]},t)})})]})]})}let rk="https://github.com/turmind/halo-hub";function rS(){return(0,l.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})}function rC(e){var t,r;ej();let n=N();if(e.tooLarge)return(0,l.jsx)(rI,{...e});let a=null!=(r=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?r:"",s=e.bundle?eL(a):eD(a),o=e.bundle?void 0:e.onOpenAsText;return(0,l.jsx)(rA,{...e,onOpenAsText:o,candidates:s,useEditorStore:n},a)}function rA(e){var t,r;let n,{candidates:a,useEditorStore:s,...i}=e,[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)(null),p=s(e=>{var t;return!!(null==(t=e.buffers[i.path])?void 0:t.modified)}),x=e=>a.find(t=>e_(t)===e_(e)),f=null!=(t=c&&x(c))?t:a[0],h=!1;(null==u?void 0:u.kind)==="extension"&&!x(u)&&p&&(f=u,h=!0),u&&e_(u)===e_(f)&&("extension"!==u.kind||"extension"!==f.kind||u.info===f.info)||m(f);let g=async e=>{if(!p||await (0,U.fN)('"'.concat(i.name,'" has unsaved changes. Discard them and switch viewer?'))){if("text"===e.kind){var t;null==(t=i.onOpenAsText)||t.call(i);return}d(e)}},v=a.length>2?(0,l.jsx)(rN,{candidates:i.bundle?a.filter(e=>"text"!==e.kind):a,current:f,onPick:g}):null;if("extension"===f.kind&&!i.bundle&&(null!=(r=i.size)?r:0)>0x6400000)n=(0,l.jsx)(tQ.no,{name:i.name,downloadUrl:i.downloadUrl,onOpenAsText:i.onOpenAsText,children:(0,l.jsx)(rI,{...i,maxLabel:"100MB"})});else if("extension"===f.kind)n=(0,l.jsx)(rb,{...i,info:f.info,uninstalled:h},f.info.id);else if("builtin"===f.kind){let{Component:e}=f.plugin;n=(0,l.jsx)(o.Suspense,{fallback:(0,l.jsx)(rS,{}),children:(0,l.jsx)(e,{...i})})}else n=(0,l.jsx)(rE,{...i});return(0,l.jsx)(tQ.NU.Provider,{value:v,children:n})}function rI(e){let{name:t,size:r,downloadUrl:n,maxLabel:a="10MB"}=e;return(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 bg-[var(--background)] p-8",children:[(0,l.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-[var(--secondary)]",children:(0,l.jsx)(ed.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"})}),(0,l.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:t}),(0,l.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)]",children:[null!=r?"".concat((0,U.v7)(r)," \xb7 "):"","File is too large to preview (max ",a,")"]}),(0,l.jsx)("a",{href:n,download:!0,className:"inline-flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",children:"Download"})]})}function rE(e){var t;let{name:r,projectId:n,downloadUrl:a,onOpenAsText:s,bundle:i}=e,c=(0,ts.kj)(),[d,u]=(0,o.useState)({url:rk,raw:""}),m=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=eA(e);return ef.extensions.filter(e=>eF(e,r,t)&&!eM(e))}(null!=(t=r.split(".").pop())?t:"",!!i);return(0,o.useEffect)(()=>{let e=!0;return k.F.settings.getSchema(n).then(t=>{var r,n;let a=null==(r=t.sections.find(e=>"extension"===e.namespaceId))?void 0:r.fields.find(e=>"hub_repo"===e.key);e&&u({url:function(e){let t=(null!=e?e:"").trim();return!t||t.startsWith("{{")?rk:/^[A-Za-z0-9][\w.-]*\/[\w.-]+$/.test(t)?"https://github.com/".concat(t):/^https?:\/\//.test(t)?t.replace(/\/+$/,"").replace(/\.git$/,""):null}(null==a?void 0:a.value),raw:null!=(n=null==a?void 0:a.value)?n:""})}).catch(()=>{}),()=>{e=!1}},[n]),(0,l.jsx)(tQ.no,{name:r,downloadUrl:a,onOpenAsText:s,children:(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 bg-[var(--background)] p-8",children:[(0,l.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-[var(--secondary)]",children:(0,l.jsx)(ed.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"})}),(0,l.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:r}),(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:c("editor.unsupported.title")}),m.map(e=>{var t;return(0,l.jsx)("p",{className:"text-xs text-[var(--foreground)]",children:c("editor.unsupported.platform",{name:e.name,platforms:eT(null!=(t=e.platforms)?t:[],c)})},e.id)}),(0,l.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)]",children:[c("editor.unsupported.hub")," ",d.url?(0,l.jsxs)("a",{href:d.url,target:"_blank",rel:"noopener",className:"text-[var(--primary)] hover:underline",children:[d.url===rk?"halo-hub":d.url.replace(/^https?:\/\//,"")," ↗"]}):(0,l.jsx)("code",{className:"text-[var(--foreground)]",children:d.raw})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[s&&(0,l.jsx)("button",{onClick:s,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:c("editor.openAsText")}),a&&(0,l.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:c("editor.download")})]})]})})}let rT=(0,d.v)((e,t)=>({projects:[],activeProject:null,folderPath:"",setProjects(t){e({projects:t})},setActiveProject(t){e({activeProject:t})},setFolderPath(t){e({folderPath:t})},openFolder(r,n){var a;let s=r.trim();if(!s)return;let l=null!=(a=s.split("/").filter(Boolean).pop())?a:s,o={id:s,name:l,path:s,workspaceId:n,createdAt:Date.now()},i=t().projects;i.find(e=>e.path===s)||e({projects:[...i,o]}),e({activeProject:o,folderPath:s})}}));var rM=r(65099),rF=r(95037),rP=r(31367);function rD(e,t){if(!e||!t)return!0;let r=t.split("/").filter(Boolean),n=e;for(let e of r){var a;if(!(n=null==n||null==(a=n.children)?void 0:a.find(t=>t.name===e)))return!1}return"directory"===n.type}function rL(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}let rR=new Set(["tiff","tif","zip","tar","gz","bz2","xz","7z","rar","woff","woff2","ttf","otf","eot","exe","dll","so","dylib","o","a","class","pyc","wasm"]);async function r_(e){return!!(rR.has(e)||ez(e))||(await eS(),ez(e))}function rz(e,t,r){return r?{downloadUrl:"",viewUrl:"",bundle:!0}:{downloadUrl:k.F.files.downloadUrl(e,t),viewUrl:k.F.files.viewUrl(e,t)}}function rO(e){var t;return null!=(t=e.split("/").pop())?t:""}function rU(e){let{projectId:t,mode:r="full",showMaximize:n=!0}=e,a=(0,ts.kj)(),s=N(),i=s(e=>e.tabs),d=s(e=>e.activeTab),u=s(e=>e.buffers),x=s(e=>e.groups),f=s(e=>e.activeGroupIdx),h=s(e=>e.pinnedTab),g=s(e=>e.maximized),v=t6()&&n&&g,b="editor-only"===r,[j,w]=(0,o.useState)(!0),[S,T]=(0,o.useState)({}),[M,F]=(0,o.useState)({});function P(e){var t;return null==(t=M[e])||t}let[D,L]=(0,o.useState)(null),[R,_]=(0,o.useState)(new Set),[z,O]=(0,o.useState)(null),[B,W]=(0,o.useState)(null),[H,K]=(0,o.useState)(null),G=(0,o.useRef)(null),q=(0,o.useRef)(null),{tree:$,loading:J}=function(e){let t=N(),[r,n]=(0,o.useState)(!1),[a,s]=(0,o.useState)(null),l=t(e=>e.fileTree),i=(0,o.useCallback)(async()=>{if(e){n(!0),s(null);try{let r=await k.F.files.tree(e);t.getState().setFileTree(I(e,r))}catch(e){s(e instanceof Error?e.message:"Failed to load file tree"),console.error("[useFileTree] Error:",e)}finally{n(!1)}}},[e,t]);return(0,o.useEffect)(()=>{e&&i()},[e,i]),(0,o.useEffect)(()=>{if(e)return C.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,o.useEffect)(()=>{if(e)return A(C,()=>E(e,t))},[e,t]),{tree:l,loading:r,error:a,refresh:i}}(t),[Z,V]=(0,o.useState)(!1),Y=(0,o.useRef)(null),Q=ej(),X=(0,o.useCallback)(e=>{var t,r,n,a;return function(e){var t;let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=(r?eL(e):eD(e))[0];return"builtin"===n.kind?!!n.plugin.heavy:"extension"===n.kind&&!(t=n.info).capabilities.includes("save")&&!t.bundle}(null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"",!!(null==(n=s.getState().buffers[e])||null==(r=n.preview)?void 0:r.bundle))},[s]),[ee,et]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=[];for(let t of x){let r=t.activeTab;if(!r)continue;let n=u[r];(null==n?void 0:n.preview)&&r!==h&&(X(r)||e.push(r))}0!==e.length&&et(t=>{let r=t.slice();for(let t=e.length-1;t>=0;t--){let n=e[t];r=[n,...r.filter(e=>e!==n)]}return(r=[...r.slice(0,5),...r.slice(5).filter(e=>{var t;return null==(t=u[e])?void 0:t.modified})],t.length===r.length&&t.every((e,t)=>e===r[t]))?t:r})},[x,u,X,Q,h]),(0,o.useEffect)(()=>{et(e=>{let t=new Set;for(let e of x)for(let r of e.tabs)t.add(r);let r=e.filter(e=>t.has(e));return r.length===e.length?e:r})},[x]),(0,o.useEffect)(()=>{s.getState().setModelPathPrefix(null!=t?t:null)},[t,s]),(0,o.useEffect)(()=>{if(!t)return;Y.current&&Y.current!==t&&(p(Y.current,Object.keys(s.getState().buffers)),s.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,pinnedTab:null}}),V(!1)),Y.current=t;let e="halo_tabs:".concat(t),r=localStorage.getItem(e);if(!r)return void V(!0);let n=!1;return async function(){try{var e,a,l;let o=JSON.parse(r),i=null!=(a=o.groups)?a:o.tabs?[{tabs:o.tabs,activeTab:null!=(e=o.activeTab)?e:null}]:[],c=null!=(l=o.activeGroupIdx)?l: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,m=new Set;for(let e of i)for(let t of e.tabs)u.has(t.path)||u.set(t.path,t.language),t.bundle&&m.add(t.path);let p=await Promise.all(d.map(async e=>{var r,n;let a=null!=(n=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?n:"",s=!1;if(m.has(e)){if(await eS(),!eR(rO(e)))return null;s=!0}if(s||await r_(a))try{let r=await k.F.files.stat(e,t);return{path:e,content:"",originalContent:"",language:"",size:r.size,mtime:r.modifiedAt,createdAt:r.createdAt,preview:rz(e,t,s)}}catch(e){return null}try{let r=await k.F.files.read(e,t);return{path:e,content:r.content,originalContent:r.content,language:u.get(e)||(0,U.sQ)(e),mtime:r.modifiedAt,size:r.size,createdAt:r.createdAt}}catch(e){return null}}));if(n)return;let x={};for(let e of p)e&&(x[e.path]=e);let f=i.map((e,t)=>{var r;let n=e.tabs.map(e=>e.path).filter(e=>x[e]),a=e.activeTab&&n.includes(e.activeTab)?e.activeTab:null!=(r=n[0])?r:null;return{id:"g_restored_".concat(t,"_").concat(Date.now().toString(36)),tabs:n,activeTab:a}}).filter(e=>e.tabs.length>0);if(0===f.length)s.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,f.length-1)),t=f[e],r=t.tabs.map(e=>x[e]).filter(e=>!!e);s.setState({buffers:x,groups:f,activeGroupIdx:e,tabs:r,activeTab:t.activeTab})}}catch(e){}n||V(!0)}(),()=>{n=!0}},[t]),(0,o.useEffect)(()=>{if(!t||!Z)return;let e=x.map(e=>({tabs:e.tabs.filter(e=>e!==h).map(e=>{var t;let r=u[e];return{path:e,isPreview:!!(null==r?void 0:r.preview),...(null==r||null==(t=r.preview)?void 0:t.bundle)?{bundle:!0}:{},language:null==r?void 0:r.language}}),activeTab:e.activeTab===h?null:e.activeTab}));localStorage.setItem("halo_tabs:".concat(t),JSON.stringify({groups:e,activeGroupIdx:f}))},[x,f,u,t,Z,h]);let er=tI(t);(0,o.useEffect)(()=>{var e;if("editor-only"!==r||!t||!Z)return;let n=s.getState();if(!er)return void n.unpinTab();let a=function(){let e=tC;return tC=!1,e}();if(n.pinnedTab===td&&(null==(e=n.buffers[td])?void 0:e.preview)&&n.groups.some(e=>e.tabs.includes(td))){a&&n.setActiveTab(td);return}let l=!1;return k.F.files.stat(td,t).then(e=>{l||s.getState().pinTab({path:td,content:"",originalContent:"",language:"",size:e.size,mtime:e.modifiedAt,createdAt:e.createdAt,preview:rz(td,t,!1)},a)}).catch(e=>console.warn("[EditorPanel] Face page missing:",e)),()=>{l=!0}},[er,t,Z,r,s]);let en=i.find(e=>e.path===d),ea=(0,o.useCallback)(()=>{let e=s.getState().activeTab;if(!e||!t)return;let r=s.getState().tabs.find(t=>t.path===e);r&&!r.preview&&k.F.files.stat(e,t).then(r=>{s.getState().checkAndRefresh(e,r.modifiedAt,()=>k.F.files.read(e,t))}).catch(()=>{})},[t]);(0,o.useEffect)(()=>{Z&&ea()},[d,ea,Z]);let es=rT(e=>{var t;return null==(t=e.activeProject)?void 0:t.path});(0,o.useEffect)(()=>{if(t&&es)return C.on("file:changed",e=>{if("change"!==e.action)return;let r="".concat(es,"/").concat(e.path),n=t.endsWith("/")?t:"".concat(t,"/");if(!r.startsWith(n))return;let a=r.slice(n.length),l=s.getState().tabs.find(e=>e.path===a);if(l){if(l.preview){var o;null===(o=rp.get(rx(t,a)))||void 0===o||o.fileChanged();return}l.modified||k.F.files.read(a,t).then(e=>{s.getState().checkAndRefresh(a,e.modifiedAt,async()=>({content:e.content,modifiedAt:e.modifiedAt}))}).catch(()=>{})}})},[t,es,s]),(0,o.useEffect)(()=>{if("tree-only"===r)return;let e=()=>ea();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[ea,r]),(0,o.useEffect)(()=>{if("tree-only"!==r)return A(C,ea)},[ea,r]);let el=(0,o.useCallback)(async(e,r)=>{var n,a;if(!t)return;if(e===s.getState().pinnedTab)return void s.getState().setActiveTab(e);let l=null!=(a=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?a:"",o=!!(null==r?void 0:r.bundle);if(o||await r_(l)){let r,{downloadUrl:n,viewUrl:a}=rz(e,t,o);try{let n=await k.F.files.stat(e,t);r={size:n.size,mtime:n.modifiedAt,createdAt:n.createdAt}}catch(e){}s.getState().openPreview(e,n,a,{...r,bundle:o});return}if(s.getState().tabs.find(t=>t.path===e))return void s.getState().setActiveTab(e);try{let r=await k.F.files.read(e,t),n=(0,U.sQ)(e);s.getState().openFile(e,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(n){console.error("[EditorPanel] Failed to read file:",n);let r=n instanceof Error?n.message:String(n);if(r.includes("413")||r.includes("too large")){let r;try{let n=await k.F.files.stat(e,t);r={size:n.size,mtime:n.modifiedAt,createdAt:n.createdAt}}catch(e){}s.getState().openPreview(e,k.F.files.downloadUrl(e,t),k.F.files.viewUrl(e,t),{...r,tooLarge:!0})}}},[t]),eo=(0,o.useCallback)(async(e,t)=>{let r=s.getState(),n=r.buffers[t],a=r.groups.some((r,n)=>n!==e&&r.tabs.includes(t));(null==n||!n.modified||a&&!n.preview||await (0,U.fN)('"'.concat(t.split("/").pop(),'" has unsaved changes. Close anyway?')))&&s.getState().closeTabIn(e,t)},[]),ei=(0,o.useCallback)(async e=>{let t=Object.values(s.getState().buffers).filter(t=>{var r;return t.modified&&(null==(r=t.preview)?void 0:r.bundle)&&e.some(e=>t.path===e||t.path.startsWith("".concat(e,"/")))}).map(e=>e.path);for(let e of t)if(!await (0,U.fN)('"'.concat(rO(e),'" has unsaved changes. Close anyway?')))return!1;for(let e of t)s.getState().closeTab(e);return!0},[s]),ec=(0,o.useCallback)(async e=>{if(t)try{let r=await k.F.files.read(e,t),n=(0,U.sQ)(e);s.getState().closeTab(e),s.getState().openFile(e,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}catch(e){console.error("[EditorPanel] Failed to open as text:",e)}},[t]),ed=(0,o.useCallback)((e,t)=>{s.getState().updateContent(e,t)},[]),eu=(0,o.useCallback)(async e=>{var r;let n=null!=e?e:d;if(!n||!t)return;let a=s.getState().tabs.find(e=>e.path===n);if(!a||!a.modified||(null==(r=a.preview)?void 0:r.bundle))return;let l=rp.get(rx(t,n));if(l)return void l.requestSave();try{let e=await k.F.files.save(n,a.content,t);s.getState().markSaved(n,e.modifiedAt)}catch(e){console.error("[EditorPanel] Failed to save file:",e)}},[t,d]),em=(0,o.useCallback)((e,t)=>{let r=s.getState().buffers[t];r&&T(n=>({...n,[e]:{original:r.originalContent,modified:r.content,path:t}}))},[]),ep=(0,o.useCallback)(e=>{T(t=>({...t,[e]:null}))},[]),ex=(0,o.useCallback)(async(e,r)=>{if(!t)return;let n=new AbortController;G.current=n,K({count:e.length,progress:0});try{await k.F.files.upload(e,t,r||void 0,(e,t)=>{t>0&&K(r=>r?{...r,progress:e/t*100}:null)},n.signal),K(e=>e?{...e,progress:100}:null),setTimeout(()=>K(null),400),E(t,s)}catch(e){if(K(null),e instanceof DOMException&&"AbortError"===e.name)return;console.error("[EditorPanel] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}finally{G.current=null}},[t]),ef=(0,o.useCallback)(async(e,r)=>{var n;if(!t)return;let a=null!=(n=e.split("/").pop())?n:"",l=r?"".concat(r,"/").concat(a):a;if(e!==l&&await ei([e]))try{await k.F.files.rename(e,l,t);let r=s.getState();r.tabs.find(t=>t.path===e)&&r.closeTab(e),E(t,s)}catch(e){console.error("[EditorPanel] Move failed:",e),window.alert(e instanceof Error?e.message:"Move failed")}},[t,ei]),eh=(0,o.useCallback)((e,t)=>{_(e),t&&O(t)},[]),eg=(0,o.useCallback)(e=>{L(e)},[]),ev=(0,o.useCallback)(async e=>{var r,n,a,l,o;if(!t)return;let i=""===e.path&&e.isDir,c=(()=>{if(!i)return{path:e.path,isDir:e.isDir};if(0===R.size)return{path:"",isDir:!0};let t=R.values().next().value;return{path:t,isDir:rD($,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),W({mode:"new-file"===e.type?"create-file":"create-folder",parentDir:d});return}if("open-to-side"===e.type){let l=e.isDir&&eR(rO(e.path));if(e.isDir&&!l)return;try{let o=null!=(n=null==(r=e.path.split(".").pop())?void 0:r.toLowerCase())?n:"",i=l||await r_(o),c=s.getState();1===c.groups.length&&c.splitToRight(null!=(a=c.groups[0].activeTab)?a:e.path);let d=+(s.getState().groups.length>1);if(i){let r=await k.F.files.stat(e.path,t);s.getState().openFileInGroup(d,e.path,"","",r.modifiedAt,{size:r.size,createdAt:r.createdAt}),s.setState(r=>({buffers:{...r.buffers,[e.path]:{...r.buffers[e.path],preview:rz(e.path,t,l)}}}))}else{let r=await k.F.files.read(e.path,t),n=(0,U.sQ)(e.path);s.getState().openFileInGroup(d,e.path,r.content,n,r.modifiedAt,{size:r.size,createdAt:r.createdAt})}}catch(e){console.error("[EditorPanel] Open to the side failed:",e),window.alert(e instanceof Error?e.message:"Open to the side failed")}return}if("open-terminal"===e.type){if(!es)return;let e=d?"".concat(es,"/").concat(d):es;y.getState().requestTerminalSpawn(e),y.getState().setBottomTab("terminal");return}if("open-as-workspace"===e.type){if(!e.isDir||!es)return;let t=e.path?"".concat(es,"/").concat(e.path):es;window.dispatchEvent(new CustomEvent("halo:open-workspace",{detail:{path:t}}));return}if("reveal-in-file-manager"===e.type){if(!es)return;let t=window.haloReveal;if(!t)return;let r=e.path?"".concat(es,"/").concat(e.path):es;t.reveal(r,e.isDir);return}if("download"===e.type){let r=k.F.files.downloadUrl(e.path,t),n=document.createElement("a");n.href=r,n.download=null!=(l=e.path.split("/").pop())?l:"file",document.body.appendChild(n),n.click(),n.remove();return}if("rename"===e.type){let t=null!=(o=e.path.split("/").pop())?o:"";W({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=R.size>1&&R.has(e.path)?Array.from(R):[e.path];if(r.length>1){if(!await (0,U.fN)("Delete ".concat(r.length," items?")))return}else{let t=e.isDir?"folder":"file";if(!await (0,U.fN)("Delete ".concat(t,' "').concat(e.path.split("/").pop(),'"?')))return}if(!await ei(r))return;try{for(let e of r)await k.F.files.remove(e,t),s.getState().closeTab(e);_(new Set),E(t,s)}catch(e){console.error("[EditorPanel] Delete failed:",e),window.alert(e instanceof Error?e.message:"Delete failed"),E(t,s)}}},[t,R,ei]),eb=(0,o.useCallback)(()=>{W(null)},[]),ey=(0,o.useCallback)(async e=>{if(!t||!B)return;let r=e.trim();if(""===r)return void W(null);let{mode:n,parentDir:a,originalPath:l,originalName:o}=B;if("rename"===n){if(!l||r===o)return void W(null);let e=a?"".concat(a,"/").concat(r):r;if(!await ei([l]))return void W(null);try{await k.F.files.rename(l,e,t),s.getState().closeTab(l),E(t,s)}catch(e){console.error("[EditorPanel] Rename failed:",e),window.alert(e instanceof Error?e.message:"Rename failed")}return void W(null)}let i=a?"".concat(a,"/").concat(r):r,c="create-file"===n&&eR(r);try{"create-file"!==n||c?await k.F.files.mkdir(i,t):await k.F.files.create(i,t),E(t,s),c&&el(i,{bundle:!0})}catch(e){console.error("[EditorPanel] Create failed:",e),window.alert(e instanceof Error?e.message:"Create failed")}W(null)},[t,B,s,el,ei]);(0,o.useEffect)(()=>{function e(e){var t;let r=null==(t=q.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(B)return;let r=q.current;if(!r||!$)return;let n=t.target;if(!n||!r.contains(n)||t.ctrlKey||t.metaKey||t.altKey)return;let a=eV($);if(0===a.length)return;let s=[...R].map(e=>a.indexOf(e)).filter(e=>e>=0),l=s.length?Math.min(...s):-1,o=s.length?Math.max(...s):-1,i=z?a.indexOf(z):-1,c=0===s.length?-1:i>=0&&l<i?l:o,d=i>=0?i:c,u=t=>{let r=a[t];eh(new Set([r]),r),e(r)};switch(t.key){case"ArrowDown":case"ArrowUp":{t.preventDefault();let r="ArrowDown"===t.key?1:-1;if(t.shiftKey&&d>=0&&c>=0){let t=Math.max(0,Math.min(a.length-1,c+r)),n=Math.min(d,t),s=Math.max(d,t);eh(new Set(a.slice(n,s+1)),a[d]),e(a[t]);return}if(c<0)return void u(1===r?0:a.length-1);u(Math.max(0,Math.min(a.length-1,c+r)));return}case"ArrowRight":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c];if(!rD($,e))return;if(!eG(e))return void eK(e,!0);let r=a[c+1];r&&r.startsWith("".concat(e,"/"))&&u(c+1);return}case"ArrowLeft":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c];if(rD($,e)&&eG(e))return void eK(e,!1);if(!e.includes("/"))return;let r=a.indexOf(e.slice(0,e.lastIndexOf("/")));r>=0&&u(r);return}case"Enter":{if(t.shiftKey||c<0)return;t.preventDefault();let e=a[c],r=rD($,e);r&&eR(rO(e))?el(e,{bundle:!0}):r?eK(e,!eG(e)):el(e);return}case"Home":case"End":if(t.shiftKey)return;t.preventDefault(),u("Home"===t.key?0:a.length-1);return;case"F2":{var m;if(1!==R.size)return;t.preventDefault();let e=R.values().next().value,r=null!=(m=e.split("/").pop())?m:"";W({mode:"rename",parentDir:e.includes("/")?e.substring(0,e.lastIndexOf("/")):"",originalPath:e,originalName:r});return}}}return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[$,R,z,B,el,eh]);let ew=H&&(0,l.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between text-[10px] text-[var(--muted-foreground)]",children:[(0,l.jsxs)("span",{children:["Uploading ",H.count," file",H.count>1?"s":"","..."]}),(0,l.jsxs)("span",{className:"flex items-center gap-1.5",children:[Math.round(H.progress),"%",(0,l.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=G.current)?void 0:e.abort()},className:"rounded p-0.5 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:"Cancel upload",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]})]}),(0,l.jsx)("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-[var(--secondary)]",children:(0,l.jsx)("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-150",style:{width:"".concat(H.progress,"%")}})})]});if("tree-only"===r)return(0,l.jsxs)("div",{className:"flex h-full flex-col",children:[ew,R.size>0&&(0,l.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,l.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[R.size," selected"]}),(0,l.jsx)("button",{onClick:()=>_(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,l.jsx)(tM.A,{className:"h-3 w-3"})})]}),(0,l.jsx)("div",{ref:q,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:J?(0,l.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):$?(0,l.jsx)(eY,{node:$,projectId:t,onSelect:el,onContextMenu:eg,onDropFiles:ex,onMoveFile:ef,selectedPaths:R,onSelectionChange:eh,lastAnchor:z,depth:0,pendingEdit:B,onCommitEdit:ey,onCancelEdit:eb}):(0,l.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"})}),D&&(0,l.jsx)(e4,{x:D.x,y:D.y,path:D.path,name:D.name,isDir:D.isDir,selectedCount:R.size>1&&R.has(D.path)?R.size:void 0,onAction:ev,onClose:()=>L(null)})]});let eN="full"===r&&j;return(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:(0,U.cn)("flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-3",v&&"hidden"),children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:["full"===r&&(0,l.jsx)("button",{onClick:()=>w(!j),className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:j?(0,l.jsx)(tn.A,{className:"h-4 w-4"}):(0,l.jsx)(ta.A,{className:"h-4 w-4"})}),(0,l.jsx)(rM.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:a("nav.canvas")}),en&&(null!=en.size||null!=en.mtime)&&(0,l.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",[null!=en.size?(0,U.v7)(en.size):"",null!=en.createdAt?"Created ".concat(rL(en.createdAt)):"",null!=en.mtime?"Modified ".concat(rL(en.mtime)):""].filter(Boolean).join(" \xb7 "),")"]})]}),(0,l.jsx)("div",{className:"flex items-center gap-1",children:n&&(0,l.jsx)("button",{onClick:()=>{let e=s.getState();e.maximized||(t9=!0,setTimeout(()=>{t9=!1},0)),e.toggleMaximized()},title:g?"Exit full screen":"Maximize editor",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:g?(0,l.jsx)(rF.A,{className:"h-4 w-4"}):(0,l.jsx)(rP.A,{className:"h-4 w-4"})})})]}),(0,l.jsxs)(c.YZ,{direction:"horizontal",autoSaveId:eN?"halo-editor-tree":void 0,children:[eN&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.Zk,{defaultSize:20,minSize:10,maxSize:40,children:(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--card)]",children:[ew,(0,l.jsx)("div",{ref:q,tabIndex:0,className:"flex-1 overflow-y-auto outline-none",children:t?J?(0,l.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):$?(0,l.jsx)(eY,{node:$,projectId:t,onSelect:el,onContextMenu:eg,onDropFiles:ex,onMoveFile:ef,selectedPaths:R,onSelectionChange:eh,lastAnchor:z,depth:0,pendingEdit:B,onCommitEdit:ey,onCancelEdit:eb}):(0,l.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"}):(0,l.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Open a folder to view files"})})]})}),(0,l.jsx)(c.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"})]}),(0,l.jsx)(c.Zk,{defaultSize:80,minSize:40,children:(0,l.jsx)(c.YZ,{direction:"horizontal",autoSaveId:"halo-editor-panes",children:x.map((e,r)=>{var a,o;let i=e.tabs.map(e=>u[e]).filter(e=>!!e),d=e.activeTab,p=i.find(e=>e.path===d),y=r===f;return(0,l.jsx)(c.Zk,{defaultSize:100/x.length,minSize:20,children:(0,l.jsxs)("div",{className:(0,U.cn)("flex h-full flex-col overflow-hidden",y&&x.length>1&&"ring-1 ring-inset ring-[var(--primary)]/30",v&&!y&&"hidden"),onMouseDown:()=>s.getState().setActiveGroup(r),children:[i.length>0&&(()=>{let t=P(e.id),n=S[e.id],a=!!(null==p?void 0:p.modified)&&!p.preview;return(0,l.jsx)("div",{className:v?"hidden":"contents",children:(0,l.jsx)(tR,{tabs:i,activeTab:d,groupIdx:r,canSplit:b&&1===x.length,onCloseTab:e=>eo(r,e),renderMode:t,onToggleRenderMode:()=>F(r=>({...r,[e.id]:!t})),showDiffButton:a,onToggleDiff:()=>{n?ep(e.id):p&&em(e.id,p.path)}})})})(),(0,l.jsx)(t1.Provider,{value:g&&n&&y?d:null,children:(0,l.jsxs)("div",{className:"flex-1 overflow-hidden",children:[h&&e.tabs.includes(h)&&(null==(a=u[h])?void 0:a.preview)&&(0,l.jsx)("div",{className:(0,U.cn)("h-full",d!==h&&"hidden"),children:(0,l.jsx)(tw,{url:u[h].preview.viewUrl,name:rO(h),face:!0})}),[...ee].sort().map(e=>i.find(t=>t.path===e&&t.preview)).filter(e=>!!e).map(e=>{var r;return(0,l.jsx)("div",{className:(0,U.cn)("h-full",(null==p?void 0:p.path)!==e.path&&"hidden"),children:(0,l.jsx)(rC,{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,bundle:e.preview.bundle,size:e.size,onOpenAsText:()=>ec(e.path)})},e.path)}),(null==p?void 0:p.preview)&&p.path!==h&&X(p.path)&&!ee.includes(p.path)&&(0,l.jsx)("div",{className:"h-full",children:(0,l.jsx)(rC,{path:p.path,name:null!=(o=p.path.split("/").pop())?o:"",projectId:null!=t?t:void 0,downloadUrl:p.preview.downloadUrl,viewUrl:p.preview.viewUrl,tooLarge:p.preview.tooLarge,bundle:p.preview.bundle,size:p.size,onOpenAsText:()=>ec(p.path)})},p.path),(()=>{let n=S[e.id],a=P(e.id);if(null==p?void 0:p.preview)return null;if(n)return(0,l.jsxs)("div",{className:"h-full flex flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,l.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["Diff: ",n.path]}),(0,l.jsx)("button",{onClick:()=>ep(e.id),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsx)("div",{className:"flex-1",children:(0,l.jsx)(tE,{original:n.original,modified:n.modified,path:n.path})})]});if(p){var s;let e=a&&"markdown"===p.language,n=a&&"html"===p.language&&!!t;return(0,l.jsxs)(l.Fragment,{children:[e&&(0,l.jsx)(to,{content:p.content,filePath:p.path,projectId:t}),n&&(0,l.jsx)(tw,{url:k.F.files.viewUrl(p.path,t),name:null!=(s=p.path.split("/").pop())?s:"",face:p.path===td}),(0,l.jsx)("div",{className:(0,U.cn)("h-full",(e||n)&&"hidden"),children:(0,l.jsx)(te,{path:m(t,p.path),content:p.content,language:p.language,onChange:e=>ed(p.path,e),onSave:()=>eu(p.path),onClose:()=>eo(r,p.path)})})]})}return(0,l.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)(rM.A,{className:"mx-auto h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.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,l.jsx)(c.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"},"rh-".concat(t))]:[e])},x.length)})]}),D&&(0,l.jsx)(e4,{x:D.x,y:D.y,path:D.path,name:D.name,isDir:D.isDir,selectedCount:R.size>1&&R.has(D.path)?R.size:void 0,onAction:ev,onClose:()=>L(null)})]})}function rB(e){return e.type?e.type:"user"===e.role?"user":"assistant"===e.role?"assistant":e.toolName?"tool_call":void 0===e.toolOutput||e.toolName?e.usage?"usage":e.systemPrompt?"context":"notification":"tool_result"}var rW=r(4671),rH=r(46073),rK=r(77497);let rG=/\.(png|jpe?g|gif|webp|bmp|svg)$/i,rq=/\.(mp4|webm|mov|m4v|ogv)$/i,r$=/\.(mp3|wav|flac|aac|m4a|ogg|opus|amr|silk)$/i;function rJ(e){return rG.test(e)?"image":rq.test(e)?"video":r$.test(e)?"audio":"file"}function rZ(e){let t=[],r=e.replace(/\[(图片|视频|语音消息(?:\s*[^\s]+)?|文件(?:\s*"[^"]*")?)\s*已保存:\s*([^,\]]+)(?:,\s*服务端转写:\s*([^\]]+))?\]/g,(e,r,n,a)=>{let s,l=n.trim();s=r.startsWith("图片")?"image":r.startsWith("视频")?"video":r.startsWith("语音")?"audio":r.startsWith("文件")?"file":rJ(l);let o=r.match(/"([^"]+)"/),i=o?o[1]:a?a.trim():void 0;return t.push({path:l,kind:s,label:i}),""});return{text:r=(r=r.replace(/^[ \t]*MEDIA:\s*(\S.*?)\s*$/gm,(e,r)=>{let n=r.trim();return t.push({path:n,kind:rJ(n)}),""})).replace(/\n{3,}/g,"\n\n").trim(),media:t}}function rV(e){let{media:t}=e,[r,n]=(0,o.useState)(null);return 0===t.length?null:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:t.map((e,t)=>(0,l.jsx)(rQ,{media:e,onOpen:()=>n(e)},"".concat(e.path,"-").concat(t)))}),r&&(0,l.jsx)(r0,{media:r,onClose:()=>n(null)})]})}function rY(e,t){if(!t)return null;let r=e=>e.replace(/\\/g,"/").toLowerCase(),n=r(e),a=r(t).replace(/\/$/,""),s=n===a||n.startsWith(a+"/"),l=/(^|\/)(tmp|temp)\//.test(n);if(!s&&!l)return null;let o=new URLSearchParams;return o.set("path",e),o.set("projectId",t),o.set("inline","1"),"/api/files/download?".concat(o.toString())}function rQ(e){var t;let{media:r,onOpen:n}=e,a=rT(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),s=rY(r.path,a),o=null!=(t=r.path.split("/").pop())?t:r.path;return s?(0,l.jsxs)("button",{onClick:n,className:"inline-flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 text-[11px] text-[var(--foreground)] cursor-pointer hover:ring-1 hover:ring-[var(--primary)]/40 transition-all no-underline",title:o,children:[(0,l.jsx)(rX,{kind:r.kind}),(0,l.jsx)("span",{className:"truncate max-w-[240px] font-mono",children:r.label||o})]}):(0,l.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,l.jsx)(rX,{kind:r.kind}),o]})}function rX(e){let{kind:t}=e,r="h-3 w-3";return"image"===t?(0,l.jsx)(rW.A,{className:r}):"video"===t?(0,l.jsx)(rH.A,{className:r}):"audio"===t?(0,l.jsx)(rK.A,{className:r}):(0,l.jsx)(Q.A,{className:r})}function r0(e){var t;let{media:r,onClose:n}=e,a=rT(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),s=rY(r.path,a),[i]=(0,o.useState)(()=>Date.now()),c=null!=(t=r.path.split("/").pop())?t:"file";if((0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),!s)return null;let d="".concat(s,"&t=").concat(i),u="".concat(s.replace("&inline=1",""),"&t=").concat(i);return(0,l.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:n,children:["file"!==r.kind&&(0,l.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,l.jsx)(e5.A,{className:"h-5 w-5"})}),(0,l.jsx)("button",{onClick:n,className:"absolute right-4 top-4 rounded p-2 text-white/80 hover:bg-white/10 hover:text-white","aria-label":"Close",children:(0,l.jsx)(tM.A,{className:"h-5 w-5"})}),(0,l.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,l.jsx)(tl.p,{src:d,alt:r.path,className:"max-h-[85vh] max-w-[90vw] object-contain",placeholderClassName:"aspect-video w-[min(90vw,640px)]"}),"video"===r.kind&&(0,l.jsx)("video",{src:d,controls:!0,autoPlay:!0,className:"max-h-[85vh] max-w-[90vw]"}),"audio"===r.kind&&(0,l.jsx)("audio",{src:d,controls:!0,autoPlay:!0,className:"w-[min(80vw,480px)]"}),"file"===r.kind&&(0,l.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,l.jsx)("div",{className:"max-w-[90vw] truncate font-mono text-[11px] text-white/60",children:r.path})]})]})}var r1=r(45764);function r3(e){let t=rB(e);return"tool_call"===t||"tool_result"===t||"usage"===t||"context"===t||"agent_start"===t||"agent_done"===t}function r5(e){if(e.taskId)return!1;let t=rB(e);return"user"===t||"assistant"===t||"notification"===t}function r2(e){var t,r;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return!!e.streaming&&!e.content&&!(null==(t=e.toolCalls)?void 0:t.length)&&!(null==(r=e.contentBlocks)?void 0:r.length)&&n-e.timestamp>3e4}let r4=0;function r8(e){var t;return"system"!==e.role||"notification"!==rB(e)?null:"".concat(null!=(t=e.taskId)?t:"","\0").concat(e.content)}function r6(e){return null!=e?e:""}function r9(e,t,r){if("assistant"===t.role&&t.streaming&&e.streamingIdx.set(r6(t.taskId),r),t.toolCalls)for(let n of t.toolCalls)n.toolUseId&&e.toolUseIdIdx.set(n.toolUseId,r);if(t.contentBlocks)for(let n of t.contentBlocks)"tool_call"===n.type&&n.toolCall.toolUseId&&e.toolUseIdIdx.set(n.toolCall.toolUseId,r)}function r7(e,t){e.streamingIdx.clear(),e.toolUseIdIdx.clear();for(let r=0;r<t.length;r++)r9(e,t[r],r)}function ne(e,t){for(let[r,n]of e.streamingIdx){let a=t[n];a&&"assistant"===a.role&&a.streaming&&r6(a.taskId)===r||e.streamingIdx.delete(r)}}function nt(e,t,r){let n=r6(r),a=e.streamingIdx.get(n);if(void 0!==a){let e=t[a];if(e&&"assistant"===e.role&&e.streaming&&e.taskId===r)return a}for(let a=t.length-1;a>=0;a--){let s=t[a];if("assistant"===s.role&&s.streaming&&s.taskId===r)return e.streamingIdx.set(n,a),a}return e.streamingIdx.delete(n),-1}function nr(e,t,r,n,a){if(!a)return{messages:t,slotIdx:nt(e,t,n),copied:!1};let s=nt(e,t,n),l=-1===s?void 0:t[s];if(l&&!(r&&l.agentName&&l.agentName.toLowerCase()!==r.toLowerCase())){var o;let i=null!=(o=l.contentBlocks)?o:[],c=i.length>0?i[i.length-1].turnId:void 0;if(!c||c===a)return{messages:t,slotIdx:s,copied:!1};let d=[...t];return d[s]={...l,streaming:!1},d.push({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:r,taskId:n}),e.streamingIdx.set(r6(n),d.length-1),{messages:d,slotIdx:d.length-1,copied:!0}}let i=[...t,{id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:r,taskId:n}];return e.streamingIdx.set(r6(n),i.length-1),{messages:i,slotIdx:i.length-1,copied:!0}}function nn(e){let t="",r=[];for(let n of e)"text"===n.type?t+=n.text:"tool_call"===n.type&&r.push(n.toolCall);return{content:t,toolCalls:r,contentBlocks:e}}let na={usableAgentCount:-1,sandboxAvailable:null,screenSource:null,cameraSource:null},ns=new Set;function nl(e){for(let t of(Object.assign(na,e),ns))t.setState(e)}let no=new Set;function ni(){let e,t={streamingIdx:new Map,toolUseIdIdx:new Map,roundStart:0,lastSnapshot:null},r=(0,r1.y)()((e=()=>queueMicrotask(()=>{if(ns.has(r)&&!r.getState().isStreaming)for(let e of no)e(r)}),(r,n)=>({messages:[],isStreaming:!1,sessionId:null,pendingMessages:[],contextTokens:0,outputTokens:0,maxContextTokens:0,isCompacting:!1,selectedAgentId:"default",accessLevel:"full",...na,addMessage(e){var n,a;let s={id:null!=(n=e.id)?n:(0,U.$C)(),type:e.type,role:e.role,content:e.content,timestamp:null!=(a=e.timestamp)?a:Date.now(),streaming:e.streaming,agentName:e.agentName,taskId:e.taskId,contentBlocks:e.contentBlocks,toolName:e.toolName,toolInput:e.toolInput,toolOutput:e.toolOutput,systemPrompt:e.systemPrompt,usage:e.usage,turnId:e.turnId,modelId:e.modelId,durationMs:e.durationMs,localImages:e.localImages,clientMsgId:e.clientMsgId};r(r=>{var n;let a,l=function(e,t,r){var n;if("assistant"===r.role||!r5(r))return null;let a=nt(e,t);if(-1===a)return null;let s=t[a],l=null!=(n=s.contentBlocks)?n:[],o=l.findIndex(e=>"tool_call"===e.type&&!e.toolCall.output),i=-1===o?!l.some(e=>"tool_call"===e.type):0===o;if(!s.content.trim()&&i)return{prefix:[...t.slice(0,a),...t.slice(a+1)],slot:s};let c=[...t];return c[a]=-1===o?{...s,streaming:!1}:{...s,...nn(l.slice(0,o)),streaming:!1},{prefix:c,slot:{id:(0,U.$C)(),role:"assistant",timestamp:Date.now(),streaming:!0,agentName:s.agentName,...nn(-1===o?[]:l.slice(o))}}}(t,r.messages,s),o=r8(s);return null!==o&&function(e,t){for(let r=e.length-1;r>=0;r--){let n=r8(e[r]);if(null===n)break;if(n===t)return!0}return!1}(null!=(n=null==l?void 0:l.prefix)?n:r.messages,o)?r:(l?r7(t,a=[...l.prefix,s,l.slot]):(r9(t,s,r.messages.length),a=[...r.messages,s]),{messages:a,isStreaming:!!e.streaming&&!e.taskId||r.isStreaming})})},appendThinking(e,n,a,s){r(r=>{var l;let o=nr(t,r.messages,n,a,s);if(-1===o.slotIdx)return r;let i=o.copied?o.messages:[...o.messages],c=i[o.slotIdx],d=[...null!=(l=c.contentBlocks)?l:[]],u=d[d.length-1];return u&&"thinking"===u.type&&(!s||u.turnId===s)?d[d.length-1]={type:"thinking",text:u.text+e,turnId:null!=s?s:u.turnId}:d.push({type:"thinking",text:e,turnId:s}),i[o.slotIdx]={...c,contentBlocks:d},{messages:i}})},updateLastAssistant(e,n,a,s){r(r=>{var l;let o=nr(t,r.messages,n,a,s);if(-1===o.slotIdx)return r;let i=o.copied?o.messages:[...o.messages],c=i[o.slotIdx],d=[...null!=(l=c.contentBlocks)?l:[]],u=d[d.length-1];return u&&"text"===u.type&&(!s||u.turnId===s)?d[d.length-1]={type:"text",text:u.text+e,turnId:null!=s?s:u.turnId}:d.push({type:"text",text:e,turnId:s}),i[o.slotIdx]={...c,content:c.content+e,contentBlocks:d},a?{messages:i}:{messages:i,isStreaming:!0}})},addToolCallToLastAssistant(e,n,a,s){r(r=>{var l,o;if(e.toolUseId&&t.toolUseIdIdx.has(e.toolUseId))return r;let i=nr(t,r.messages,n,a,s);if(-1===i.slotIdx)return r;let c=i.copied?i.messages:[...i.messages],d=c[i.slotIdx],u=[...null!=(l=d.contentBlocks)?l:[]];return u.push({type:"tool_call",toolCall:e,turnId:s}),c[i.slotIdx]={...d,toolCalls:[...null!=(o=d.toolCalls)?o:[],e],contentBlocks:u},e.toolUseId&&t.toolUseIdIdx.set(e.toolUseId,i.slotIdx),{messages:c}})},updateLastToolCallResult(e,n,a,s){r(r=>{var n,l,o,i,c,d,u;if(s){let n=null!=(i=t.toolUseIdIdx.get(s))?i:-1,a=-1===n?void 0:r.messages[n],u=null!=(c=null==a||null==(l=a.toolCalls)?void 0:l.findIndex(e=>e.toolUseId===s))?c:-1,m=null!=(d=null==a||null==(o=a.contentBlocks)?void 0:o.findIndex(e=>"tool_call"===e.type&&e.toolCall.toolUseId===s))?d:-1;if(a&&(-1!==u||-1!==m)){if(-1!==u&&void 0!==a.toolCalls[u].output||-1!==m&&void 0!==a.contentBlocks[m].toolCall.output)return r;let t=a.toolCalls?[...a.toolCalls]:a.toolCalls;t&&-1!==u&&(t[u]={...t[u],output:e});let s=a.contentBlocks?[...a.contentBlocks]:a.contentBlocks;if(s&&-1!==m){let t=s[m];s[m]={type:"tool_call",toolCall:{...t.toolCall,output:e},turnId:t.turnId}}let l=[...r.messages];return l[n]={...a,toolCalls:t,contentBlocks:s},{messages:l}}}let m=nt(t,r.messages,a),p=-1===m?void 0:r.messages[m];if(!p||!(null==(n=p.toolCalls)?void 0:n.length))return r;let x=[...p.toolCalls],f=x.findIndex(e=>void 0===e.output);-1!==f&&(x[f]={...x[f],output:e});let h=[...null!=(u=p.contentBlocks)?u:[]];for(let t=0;t<h.length;t++){let r=h[t];if("tool_call"===r.type&&void 0===r.toolCall.output){h[t]={type:"tool_call",toolCall:{...r.toolCall,output:e},turnId:r.turnId};break}}let g=[...r.messages];return g[m]={...p,toolCalls:x,contentBlocks:h},{messages:g}})},completeStreaming(){r(e=>{let r=e.messages.map(e=>e.streaming?{...e,streaming:!1}:e);return ne(t,r),{messages:r,isStreaming:!1}})},completeAgentStreaming(a,s,l){let o=n().isStreaming;r(e=>{let r=e.messages.filter(r5).length,n=e.messages.map(e=>e.streaming?(!s||e.taskId!==s)&&(s||e.taskId)?e:{...e,streaming:!1}:e),l=n.filter(r5).length,o=n.some(e=>e.streaming&&!e.taskId);return r!==l&&console.warn("[ChatStore:completeAgentStreaming] main msgs changed ".concat(r," -> ").concat(l,", agentName=").concat(a,", taskId=").concat(s)),ne(t,n),{messages:n,isStreaming:o}}),!o||n().isStreaming||l||e()},takeRoundReplies(){let{messages:e}=n(),r=e.slice(t.roundStart).filter(e=>"assistant"===e.role&&!e.taskId);return t.roundStart=e.length,r},noteSnapshot(e,r){t.lastSnapshot={sessionId:e,messages:r}},takeReplaySnapshot(){let e=n().sessionId;return t.lastSnapshot&&e&&t.lastSnapshot.sessionId===e?t.lastSnapshot.messages:null},dropOptimisticSend(e){let{messages:a}=n(),s=a.findIndex(t=>t.clientMsgId===e);if(-1===s)return;let l=a.filter((e,t)=>{var r,n;return t!==s&&!(t>s&&e.streaming&&!e.taskId&&!e.content&&!(null==(r=e.toolCalls)?void 0:r.length)&&!(null==(n=e.contentBlocks)?void 0:n.length))});r7(t,l),t.roundStart=Math.min(t.roundStart,l.length),r({messages:l,isStreaming:l.some(e=>e.streaming&&!e.taskId)})},setSessionId(e){r({sessionId:e})},setMessages(e){r7(t,e),t.roundStart=e.length,r({messages:e})},setTokenUsage(e,t){r({contextTokens:e,outputTokens:t})},setMaxContextTokens(e){e>0&&r({maxContextTokens:e})},setCompacting(e){r({isCompacting:e})},setSelectedAgentId(e){r({selectedAgentId:e})},setUsableAgentCount(e){nl({usableAgentCount:e})},setAccessLevel(e){r({accessLevel:e})},setSandboxAvailable(e){nl({sandboxAvailable:e})},setScreenSource(e){nl({screenSource:e})},setCameraSource(e){nl({cameraSource:e})},addPendingMessage(e){r(t=>({pendingMessages:[...t.pendingMessages,e]}))},removePendingMessage(e){r(t=>({pendingMessages:t.pendingMessages.filter((t,r)=>r!==e)}))},shiftPendingMessage(){let e=n().pendingMessages;if(0===e.length)return;let[t,...a]=e;return r({pendingMessages:a}),t},markChatSendFailed(e){r(r=>{let n=r.messages.findIndex(t=>t.clientMsgId===e);if(-1===n)return r;let a=r.messages.map((e,t)=>{var r,a;return t===n?{...e,sendFailed:!0}:!(t>n)||!e.streaming||e.taskId||e.content||(null==(r=e.toolCalls)?void 0:r.length)||(null==(a=e.contentBlocks)?void 0:a.length)?e:{...e,streaming:!1,interrupted:!0}});return ne(t,a),{messages:a,isStreaming:a.some(e=>e.streaming&&!e.taskId)}})},convergeStaleStreaming(){if(n().isCompacting||0===r4)return;let e=Date.now(),a=t=>t.timestamp<=r4&&r2(t,e);n().messages.some(a)&&r(e=>{let r=e.messages.map(e=>a(e)?{...e,streaming:!1,interrupted:!0}:e);return ne(t,r),{messages:r,isStreaming:r.some(e=>e.streaming&&!e.taskId)}})},clear(){r7(t,[]),t.roundStart=0,t.lastSnapshot=null,r({messages:[],isStreaming:!1,pendingMessages:[],sessionId:null,contextTokens:0,outputTokens:0,accessLevel:"full"})}})));return ns.add(r),r}function nc(e){ns.delete(e)}function nd(e){for(let t of ns)e(t)}let nu=ni(),nm=new Set;function np(){return nu}function nx(e){return nm.add(e),()=>{nm.delete(e)}}let nf=Object.assign(function(e){let t=(0,o.useSyncExternalStore)(nx,np,np);return(0,d.P)(t,e)},{getState:()=>nu.getState(),setState:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return nu.setState(...t)}}),nh=new Map,ng=(0,d.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function nv(e,t){let r=ng.getState();r.sessionId===e&&t<=r.anchor||ng.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}function nb(e,t,r){let n=ng.getState();n.sessionId===e&&n.cursor===t&&ng.setState({messages:[...r,...n.messages],cursor:t-1,loading:!1})}async function ny(){var e,t;let r=null==(e=rT.getState().activeProject)?void 0:e.id,{sessionId:n,cursor:a,loading:s}=ng.getState();if(!r||!n||a<1||s)return;let l="".concat(n,"\0").concat(a),o=nh.get(l);if(o)return void nb(n,a,o);ng.setState({loading:!0});try{let e=null!=(t=(await k.F.sessionLogs.archiveSegment(n,a,r)).messages)?t:[];if(nh.size>=20){let e=nh.keys().next().value;void 0!==e&&nh.delete(e)}nh.set(l,e),nb(n,a,e)}catch(e){ng.setState({loading:!1})}}function nj(e){return{tabId:(0,U.$C)(),sessionId:null,store:e}}let nw=nj(np()),nN=(0,d.v)(()=>({projectId:null,tabs:[nw],activeTabId:nw.tabId})),nk=e=>"halo_chat_tabs_".concat(e);function nS(){var e,t;let{projectId:r,tabs:n,activeTabId:a}=nN.getState();if(!r)return;let s=null!=(t=null==(e=n.find(e=>e.tabId===a))?void 0:e.sessionId)?t:null;try{localStorage.setItem(nk(r),JSON.stringify({active:s}))}catch(e){}}let nC=new Map;function nA(e,t){nC.set(e,{scrollTop:0,userScrolledUp:!1,hiddenTurns:0,...nC.get(e),...t})}function nI(e){return nN.getState().tabs.find(e)}function nE(e,t){nN.setState(r=>({tabs:r.tabs.map(r=>r.tabId===e?{...r,...t}:r)}))}function nT(e){return null===e.sessionId&&(!e.store||0===e.store.getState().messages.length)}function nM(e,t){let r=np().getState(),n=ni(),a=n.getState();return a.setSelectedAgentId(null!=t?t:r.selectedAgentId),a.setMaxContextTokens(r.maxContextTokens),e&&a.setSessionId(e),n}function nF(e){var t;let r=null==(t=rT.getState().activeProject)?void 0:t.id;r&&C.connected&&C.send({type:"subscribe",sessionId:e,projectId:r})}function nP(e){let t=nI(t=>t.tabId===e);if(!t)return null;let r={},n=null,a=t.store;!a&&(r.store=a=nM(t.sessionId),t.sessionId&&(n=t.sessionId,r.loading=!0,r.attempt=(null!=(s=t.attempt)?s:0)+1)),t.unread&&(r.unread=!1);var s,l,o=a;if(o!==nu)for(let e of(nu=o,nm))e();return nN.setState(t=>({activeTabId:e,tabs:Object.keys(r).length>0?t.tabs.map(t=>t.tabId===e?{...t,...r}:t):t.tabs})),t.sessionId&&nv(t.sessionId,null!=(l=t.archiveCount)?l:0),nS(),n}function nD(e){let t=nL(e);t&&nF(t)}function nL(e){let t=nN.getState(),r=t.tabs.find(t=>t.sessionId===e);if(r)return nP(r.tabId);let n={tabId:(0,U.$C)(),sessionId:e},a=t.tabs.find(e=>e.tabId===t.activeTabId),s=a&&nT(a)?a:null;nN.setState({tabs:s?t.tabs.map(e=>e===s?n:e):[...t.tabs,n]});let l=nP(n.tabId);return s&&(s.store&&nc(s.store),nC.delete(s.tabId)),l}function nR(e){let t=nN.getState(),r=t.tabs.find(nT);if(r){var n;nP(r.tabId),e&&(null==(n=r.store)||n.getState().setSelectedAgentId(e));return}let a=nj(nM(null,e));nN.setState({tabs:[...t.tabs,a]}),nP(a.tabId)}function n_(e){let t=nI(t=>t.sessionId===e);t&&function(e){let t=nN.getState(),r=t.tabs.findIndex(t=>t.tabId===e);if(-1===r)return;let n=t.tabs[r],a=t.tabs.filter(t=>t.tabId!==e);if(0===a.length&&(a=[nj(nM(null))]),nN.setState({tabs:a}),t.activeTabId===e){let e=nP(a[Math.min(r,a.length-1)].tabId);e&&nF(e)}else nS();n.store&&nc(n.store),nC.delete(e)}(t.tabId)}function nz(e){let t=np();t.getState().sessionId!==e&&t.getState().setSessionId(e);let r=nI(e=>e.store===t);r&&r.sessionId!==e&&(nE(r.tabId,{sessionId:e}),nS())}function nO(e){var t;let r=[];return nd(t=>{t.getState().sessionId===e&&r.push(t)}),null!=(t=r[0])?t:null}function nU(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],r=e?nO(e):np();if(r&&t&&r!==np()){let e=nI(e=>e.store===r);e&&!e.unread&&nE(e.tabId,{unread:!0})}return r}function nB(e){e.store&&(nc(e.store),nE(e.tabId,{store:void 0,loading:!1,unread:!1}))}function nW(e){return"halo_goal_dismissed_".concat(e)}let nH=(0,d.v)(e=>({enabled:!1,setEnabled:t=>e({enabled:t}),goal:null,dismissedGoalId:null,setGoal:t=>e({goal:t}),dismiss:t=>{var r;e({dismissedGoalId:t});let n=null==(r=rT.getState().activeProject)?void 0:r.id;n&&localStorage.setItem(nW(n),t)}}));async function nK(e){if(!nH.getState().enabled)return;let t=localStorage.getItem(nW(e));nH.setState({dismissedGoalId:t});try{var r;let t=await k.F.sessionLogs.goal(e);nH.getState().setGoal(null!=(r=t.goal)?r:null)}catch(e){}}let nG=(0,d.v)(()=>({sessionId:null,anchor:0,cursor:0,messages:[],loading:!1}));function nq(e,t){let r=nG.getState();r.sessionId===e&&t<=r.anchor||nG.setState({sessionId:e,anchor:t,cursor:t,messages:[],loading:!1})}async function n$(){var e,t;let r=null==(e=rT.getState().activeProject)?void 0:e.id,{sessionId:n,cursor:a,loading:s}=nG.getState();if(r&&n&&!(a<1)&&!s){nG.setState({loading:!0});try{let e=await k.F.sessionLogs.archiveSegment(n,a,r),s=nG.getState();if(s.sessionId!==n||s.cursor!==a)return;nG.setState({messages:[...null!=(t=e.messages)?t:[],...s.messages],cursor:a-1,loading:!1})}catch(t){let e=nG.getState();e.sessionId===n&&e.cursor===a&&nG.setState({loading:!1})}}}let nJ=new Map,nZ=null,nV=!1;function nY(e){return nJ.get(e)}function nQ(e,t,r){let n=nJ.get(e);if(n){n.messages=t,n.archiveCount=r;return}if(nJ.set(e,{messages:t,archiveCount:r,scrollOffset:0,atBottom:!0,stale:!1}),!(nJ.size<=20)){for(let e of nJ.keys())if(e!==nZ)return void nJ.delete(e)}}function nX(e,t){let r=nJ.get(e);r&&(r.stale=t)}function n0(e){for(let t of nJ.keys())(t===e||t.startsWith("".concat(e,">")))&&nJ.delete(t)}function n1(e){return e.slice(e.lastIndexOf(">")+1)}function n3(e,t){if(t)return e.find(e=>void 0!==e.store&&!e.loading&&e.sessionId===t)}function n5(){let e=(0,d.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));return{useBus:e,bump:()=>e.getState().bump()}}let n2=n5(),n4=n2.useBus,n8=n2.bump;function n6(e,t){let r=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let t=r.current;if(!t||"undefined"==typeof IntersectionObserver)return;let n=new IntersectionObserver(t=>{var r;(null==(r=t[0])?void 0:r.isIntersecting)&&e()},{rootMargin:"64px"});return n.observe(t),()=>n.disconnect()},[e,t]),r}var n9=r(63129),n7=r(22936),ae=r(70207),at=r(4882),ar=r(87343);let an=(0,d.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 aa(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 as(e){let t=0;for(let r of e)t+=1+as(r.children);return t}function al(e){let{value:t,onChange:r,onCommit:n,onCancel:a,textSize:s}=e;return(0,l.jsx)("input",{autoFocus:!0,value:t,onChange:e=>r(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),n()):"Escape"===e.key&&(e.preventDefault(),a())},onBlur:n,className:(0,U.cn)("min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[var(--foreground)] outline-none focus:border-blue-500",s)})}function ao(e){let{nodes:t,depth:r,expanded:n,selectedSessionId:a,onToggle:s,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:p}=e,x=(0,ts.kj)(),f=nH(e=>e.enabled),h=12+16*r;return(0,l.jsx)(l.Fragment,{children:t.map(e=>{let t=a===e.id,g=!!e.stoppedAt,v=!!e.archivedAt,b=e.children.length>0,y=n.has(e.id);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{onClick:()=>o(e),title:"Click to preview sub-agent session",className:(0,U.cn)("group flex w-full items-center gap-1.5 pr-3 py-1.5 text-left transition-colors border-b border-[var(--border)]/10",t?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/40",v&&"opacity-50"),style:{paddingLeft:"".concat(h,"px")},children:[b?(0,l.jsx)("span",{onClick:t=>{t.stopPropagation(),s(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,l.jsx)(K.A,{className:(0,U.cn)("h-2.5 w-2.5 text-[var(--muted-foreground)] transition-transform",y&&"rotate-90")})}):(0,l.jsx)("span",{className:"w-4 shrink-0 -ml-0.5"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,l.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,l.jsx)(al,{value:c,onChange:d,onCommit:()=>m(e.id),onCancel:p,textSize:"text-[10px]"}):(0,l.jsxs)("p",{className:"truncate text-[10px] text-[var(--foreground)]",children:[f&&e.goalSessionId&&(0,l.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),e.title||"Untitled"]}),g&&(0,l.jsx)("span",{title:"Stopped",children:(0,l.jsx)(n9.A,{className:"h-2.5 w-2.5 shrink-0 text-[var(--muted-foreground)]"})}),v&&(0,l.jsx)("span",{title:"Archived",children:(0,l.jsx)(n7.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),b&&(0,l.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",as(e.children)]})]}),(0,l.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.exchangeCount," msgs \xb7 ",(0,U.fw)(e.updatedAt,x)]})]}),i!==e.id&&(0,l.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,l.jsx)(e2.A,{className:"h-2.5 w-2.5"})})]}),y&&b&&(0,l.jsx)(ao,{nodes:e.children,depth:r+1,expanded:n,selectedSessionId:a,onToggle:s,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:m,onCancelRename:p})]},e.id)})})}let ai=e=>"halo_selected_session_".concat(e);function ac(e){let t=[];return!function e(r){for(let n of r)t.push(n),e(n.children)}(e),t}function ad(){let e=(0,ts.kj)(),t=nf(e=>e.isStreaming),r=nf(e=>e.sessionId),n=rT(e=>e.activeProject),{selectedSessionId:a,setSelectedSession:s,clearSelection:i,setLoadedMessages:c,setLoading:d}=an(),[u,m]=(0,o.useState)([]),[p,x]=(0,o.useState)(null),f=(0,o.useRef)(0),h=(0,o.useRef)(null),[g,v]=(0,o.useState)(new Set),[b,y]=(0,o.useState)(!0),[j,w]=(0,o.useState)(!1),N=(0,o.useRef)(null),[S,C]=(0,o.useState)(null),[A,I]=(0,o.useState)(""),E=(0,o.useRef)(""),T=(0,o.useRef)(null),M=(0,o.useRef)(!1);(0,o.useEffect)(()=>{(null==n?void 0:n.id)&&N.current&&N.current!==n.id&&(i(),nJ.clear(),N.current=null)},[null==n?void 0:n.id,i]);let F=(0,o.useCallback)(async function(){let{showSpinner:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showSpinner:!0};if(!(null==n?void 0:n.path)){m([]),x(null),y(!1);return}if(null!==T.current){M.current=!0;return}M.current=!1,e&&y(!0);let t=n.path,r=Date.now();try{let e=await k.F.sessionLogs.list(t,{includeArchived:!0,limit:30}),r=e.sessions,n=e.nextCursor;if(h.current!==t||f.current<=30||null===n)m(aa(r)),x(n);else{let e=new Set(r.map(e=>e.id));m(t=>{let a=t.filter(t=>t.updatedAt<n&&!e.has(t.id));return aa([...r,...ac(a)])})}h.current=t}catch(e){console.error("[Sessions] Failed to fetch:",e),m([]),x(null)}finally{e?setTimeout(()=>y(!1),Math.max(0,350-(Date.now()-r))):y(!1)}},[null==n?void 0:n.path]),P=(0,o.useCallback)(async()=>{if((null==n?void 0:n.path)&&null!==p&&!j){w(!0);try{let e=await k.F.sessionLogs.list(n.path,{includeArchived:!0,limit:30,cursor:p}),t=e.sessions;m(e=>{let r=ac(e),n=new Set(r.map(e=>e.id)),a=[...r,...t.filter(e=>!n.has(e.id))];return aa(a)}),x(e.nextCursor)}catch(e){console.error("[Sessions] loadMore failed:",e)}finally{w(!1)}}},[null==n?void 0:n.path,p,j]);(0,o.useEffect)(()=>{f.current=u.length},[u.length]);let D=n4(e=>e.version),L=(0,o.useRef)(!0);(0,o.useEffect)(()=>{F({showSpinner:L.current}),L.current=!1},[F,D]),(0,o.useEffect)(()=>{a&&!b&&!new Set(ac(u).map(e=>e.id)).has(a)&&(i(),(null==n?void 0:n.id)&&localStorage.removeItem(ai(n.id)))},[u,a,b,i,null==n?void 0:n.id]);let R=(0,o.useCallback)(e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),_=(0,o.useCallback)(async e=>{var t,r;let a=an.getState();if(a.selectedSessionId===e.id&&(null!==a.loadedMessages||a.loading))return;s(e),d(!0),(null==n?void 0:n.id)&&localStorage.setItem(ai(n.id),e.id);let l=n3(nN.getState().tabs,e.id);if(null==l?void 0:l.store){nq(e.id,null!=(t=l.archiveCount)?t:0),c(l.store.getState().messages);return}let o=nY(e.id);if(o){nq(e.id,o.archiveCount),c(o.messages);return}let i=()=>an.getState().selectedSessionId===e.id;try{let t=await k.F.sessionLogs.get(e.id,null==n?void 0:n.path),a="number"==typeof t.archiveCount?t.archiveCount:0,s=null!=(r=t.messages)?r:[];if(nQ(e.id,s,a),!i())return;nq(e.id,a),c(s)}catch(t){if(console.error("[Sessions] Load failed:",t),!i())return;nq(e.id,0),c([])}},[null==n?void 0:n.id,null==n?void 0:n.path,s,c,d]);(0,o.useEffect)(()=>{if(!(null==n?void 0:n.id)||b||0===u.length||N.current===n.id)return;N.current=n.id;let e=localStorage.getItem(ai(n.id));if(!e)return;let t=ac(u),r=t.find(t=>t.id===e);if(!r)return;let a=new Map(t.map(e=>[e.id,e])),s=[],l=r;for(;null==l?void 0:l.parentSessionId;)s.push(l.parentSessionId),l=a.get(l.parentSessionId);s.length>0&&v(e=>{let t=new Set(e);for(let e of s)t.add(e);return t}),_(r)},[null==n?void 0:n.id,b,u,_]);let z=(0,o.useCallback)(e=>{nD(e.id)},[]),O=(0,o.useCallback)(async(t,r)=>{if((t.stopPropagation(),null==n?void 0:n.path)&&await (0,U.fN)(e("chat.sessions.deleteTreeConfirm")))try{m(e=>e.filter(e=>e.id!==r)),n_(r),n0(r),a===r&&(i(),(null==n?void 0:n.id)&&localStorage.removeItem(ai(n.id))),await k.F.sessionLogs.delete(r,n.path),n8()}catch(e){console.error("[Sessions] Delete failed:",e),n8()}},[null==n?void 0:n.path,null==n?void 0:n.id,a,i,e]),B=(0,o.useCallback)((e,t)=>{e.stopPropagation(),T.current=t.id,E.current=t.title||"",C(t.id),I(t.title||"")},[]),W=(0,o.useCallback)(()=>{T.current=null,C(null),I(""),M.current&&F({showSpinner:!1})},[F]),H=(0,o.useCallback)(async e=>{if(T.current!==e)return;let t=A.trim();if(!t||t===E.current||!(null==n?void 0:n.path))return void W();T.current=null,C(null),m(r=>(function e(t,r,n){return t.map(t=>t.id===r?{...t,title:n}:{...t,children:e(t.children,r,n)})})(r,e,t));try{await k.F.sessionLogs.rename(e,t,n.path),n8()}catch(e){console.error("[Sessions] Rename failed:",e),n8()}},[A,null==n?void 0:n.path,W]),G=u.length,q=n6(P,u.length);return(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(ae.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Sessions"}),G>0&&(0,l.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",G,null!==p?"+":"",")"]}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onClick:()=>F(),disabled:b,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh sessions",children:(0,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",b&&"animate-spin")})}),t&&(0,l.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"running"})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto",children:b?(0,l.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsx)($.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading..."]}):0===u.length?(0,l.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,l.jsx)(ar.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"No session history yet"}),(0,l.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:"Start a conversation in the Chat panel"})]}):(0,l.jsxs)(l.Fragment,{children:[u.map(t=>{let n=t.children,s=g.has(t.id),o=t.id===r,i=a===t.id,c=!!t.archivedAt,d=n.length>0,u=as(n);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{onClick:()=>_(t),onDoubleClick:()=>z(t),title:"Click to preview, double-click to load into chat",className:(0,U.cn)("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,l.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,l.jsx)(K.A,{className:(0,U.cn)("h-3 w-3 text-[var(--muted-foreground)] transition-transform",s&&"rotate-90")})}):(0,l.jsx)("span",{className:"w-5 shrink-0 -ml-1"}),(0,l.jsx)(ae.A,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",o?"text-blue-400":"text-[var(--muted-foreground)]")}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5",children:[S===t.id?(0,l.jsx)(al,{value:A,onChange:I,onCommit:()=>void H(t.id),onCancel:W,textSize:"text-[11px]"}):(0,l.jsx)("p",{className:"truncate text-[11px] font-medium text-[var(--foreground)]",children:t.title||"Untitled"}),o&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1 py-0.5 text-[8px] text-blue-400",children:"active"}),c&&(0,l.jsx)("span",{title:"Archived",children:(0,l.jsx)(n7.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),d&&(0,l.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",u]})]}),(0,l.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[t.exchangeCount," msgs \xb7 ",(0,U.fw)(t.updatedAt,e)]})]}),S!==t.id&&(0,l.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,l.jsx)(e2.A,{className:"h-3 w-3"})}),(0,l.jsx)("button",{onClick:e=>O(e,t.id),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})})]}),s&&d&&(0,l.jsx)(ao,{nodes:n,depth:1,expanded:g,selectedSessionId:a,onToggle:R,onSelect:_,editingId:S,editingTitle:A,setEditingTitle:I,onStartRename:B,onCommitRename:H,onCancelRename:W})]},t.id)}),null!==p&&(0,l.jsx)("div",{ref:q,className:"flex items-center justify-center py-2 text-[10px] text-[var(--muted-foreground)]",children:j?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin mr-1"})," Loading more…"]}):(0,l.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})})]})}let au=/<<<CAPTURE(?::(screen|camera))?>>>/g,am="web:screen",ap=e=>new Promise(t=>setTimeout(t,e));function ax(e){if(e)for(let t of e.getTracks())t.stop()}function af(e){return!!e&&e.getVideoTracks().some(e=>"live"===e.readyState)}function ah(e){let t=document.createElement("video");return t.muted=!0,t.playsInline=!0,t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-10000px;top:0;width:160px;height:90px;opacity:0;pointer-events:none",t.srcObject=e,document.body.appendChild(t),t.play().catch(()=>{}),t}function ag(e,t){ax(e),t&&(t.srcObject=null,t.remove())}async function av(e){e.paused&&await e.play().catch(()=>{}),e.videoWidth||await new Promise(t=>{e.addEventListener("loadedmetadata",()=>t(),{once:!0}),setTimeout(t,1e3)})}function ab(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1920,r=e.videoWidth,n=e.videoHeight;if(!r||!n)return null;let a=Math.min(1,t/r),s=document.createElement("canvas");s.width=Math.max(1,Math.round(r*a)),s.height=Math.max(1,Math.round(n*a));let l=s.getContext("2d");return l?(l.drawImage(e,0,0,s.width,s.height),s):null}function ay(e,t){let r=e.getContext("2d").getImageData(0,0,e.width,e.height).data;if(r.length<4)return!0;let n=4*Math.max(1,Math.floor(r.length/4/1e3)),a=0,s=0;for(let e=0;e+2<r.length;e+=n)a++,r[e]<=t&&r[e+1]<=t&&r[e+2]<=t&&s++;return a>0&&s/a>.99}function aj(e){return e.toDataURL("image/jpeg",.85).split(",")[1]||null}function aw(e){return(null==e?void 0:e.id)===am}let aN=null;function ak(){aN&&(ag(aN.stream,aN.video),aN=null)}let aS={web:!0,start:async()=>{var e;let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1})}catch(e){return null}let r=t.getVideoTracks()[0];if(!r)return ax(t),null;ak();let n={stream:t,video:ah(t)};return aN=n,r.addEventListener("ended",()=>{if(aN!==n)return;ak();let e=nf.getState();aw(e.screenSource)&&e.setScreenSource(null)}),"window"===(e=r.getSettings().displaySurface)?"capture.webSurfaceWindow":"browser"===e?"capture.webSurfaceTab":"capture.webSurfaceScreen"},grab:async()=>{for(let e=0;e<3;e++){e>0&&await ap(300);let t=aN;if(!t||!af(t.stream))break;await av(t.video);let r=ab(t.video);if(r&&!ay(r,8))return aj(r)}return null}};async function aC(){let e,t=window.CaptureController,r=t?new t:void 0;try{e=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,...r?{controller:r}:{}})}catch(e){return null}try{null==r||r.setFocusBehavior("no-focus-change")}catch(e){}let n=ah(e),a=null;try{for(let e=0;e<4;e++){var s;if(e>0&&await ap(300),await av(n),(a=null!=(s=ab(n,1/0))?s:a)&&!ay(a,8))break}}finally{ag(e,n)}if(!a)return null;let l=await new Promise(e=>a.toBlob(e,"image/png"));return l?URL.createObjectURL(l):null}let aA=null;function aI(e){var t;if(e.opening)return e.opening;ag(e.stream,e.video),e.stream=null,e.video=null;let r=navigator.mediaDevices.getUserMedia({video:(t=e.deviceId)?{deviceId:{exact:t},width:{ideal:1280},height:{ideal:720}}:{width:{ideal:1280},height:{ideal:720}},audio:!1}).then(t=>aA!==e?(ax(t),!1):(e.stream=t,e.video=ah(t),e.openedAt=Date.now(),!0),()=>!1).finally(()=>{e.opening=null});return e.opening=r,r}let aE={web:!0,has:async()=>{try{return(await navigator.mediaDevices.enumerateDevices()).some(e=>"videoinput"===e.kind)}catch(e){return!1}},list:async()=>{try{return(await navigator.mediaDevices.enumerateDevices()).filter(e=>"videoinput"===e.kind).map((e,t)=>({deviceId:e.deviceId,label:e.label||"Camera ".concat(t+1)}))}catch(e){return[]}},requestPermission:async()=>{try{return ax(await navigator.mediaDevices.getUserMedia({video:!0})),!0}catch(e){return!1}},snap:async e=>{var t;let r=aA;if(!r||r.deviceId!==(null!=e?e:"")||!af(r.stream)&&!await (t=aI(r),Promise.race([t,ap(5e3).then(()=>!1)])))return null;let n=r.video;if(aA!==r||!n)return null;try{await av(n);let e=r.openedAt+500-Date.now();e>0&&await ap(e);let t=ab(n);return(!t||ay(t,10))&&(await ap(500),t=ab(n)),t?aj(t):null}catch(e){return null}}};function aT(){var e;let t=window.haloCapture;return t||("function"==typeof(null==(e=navigator.mediaDevices)?void 0:e.getDisplayMedia)?aS:void 0)}function aM(){var e;let t=window.haloCamera;return t||("function"==typeof(null==(e=navigator.mediaDevices)?void 0:e.getUserMedia)?aE:void 0)}let aF=new Set(["PageUp","ArrowUp","Home"]),aP=e=>e.scrollHeight-e.scrollTop-e.clientHeight;function aD(e,t){let r=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{let n=e.current;if(!n)return;let a=function(e,t){let r=e.scrollTop,n=null,a=!1,s=r=>{e.scrollTop>0&&!function(e,t){for(let r=e instanceof Element?e:null;r&&r!==t;r=r.parentElement)if(r.scrollTop>0&&r.scrollHeight>r.clientHeight){let e=getComputedStyle(r).overflowY;if("auto"===e||"scroll"===e)return!0}return!1}(r,e)&&(t.current=!0)},l=()=>{1>=aP(e)&&(t.current=!1)},o=e=>{!e.ctrlKey&&(e.deltaY<0?s(e.target):e.deltaY>0&&l())},i=e=>{var t,r;n=null!=(r=null==(t=e.touches[0])?void 0:t.clientY)?r:null},c=e=>{var t;let r=null==(t=e.touches[0])?void 0:t.clientY;void 0!==r&&(null!==n&&r>n?s(e.target):null!==n&&r<n&&l(),n=r)},d=e=>{(aF.has(e.key)||" "===e.key&&e.shiftKey)&&s(e.target)},u=()=>{a=!1,80>=aP(e)&&(t.current=!1)},m=r=>{r.target!==e||r.offsetX<e.clientWidth||(a=!0,t.current=!0,window.addEventListener("pointerup",u,{once:!0}))},p=()=>{let n=e.scrollTop;n>r?aP(e)>80?t.current=!0:a||(t.current=!1):n<r&&aP(e)>1&&(t.current=!0),r=n},x={passive:!0};return e.addEventListener("wheel",o,x),e.addEventListener("touchstart",i,x),e.addEventListener("touchmove",c,x),e.addEventListener("keydown",d),e.addEventListener("pointerdown",m),e.addEventListener("scroll",p,x),{pin(){e.clientHeight>0&&e.scrollHeight<=e.clientHeight&&(t.current=!1),t.current||(e.scrollTop=e.scrollHeight,r=e.scrollTop)},destroy(){e.removeEventListener("wheel",o),e.removeEventListener("touchstart",i),e.removeEventListener("touchmove",c),e.removeEventListener("keydown",d),e.removeEventListener("pointerdown",m),e.removeEventListener("scroll",p),window.removeEventListener("pointerup",u)}}}(n,t);return r.current=a,()=>{a.destroy(),r.current=null}},[e,t]),(0,o.useCallback)(()=>{var e;return null==(e=r.current)?void 0:e.pin()},[])}var aL=r(32031),aR=r(75037);function a_(e){var t;let r=null==(t=rT.getState().activeProject)?void 0:t.id;if(!r)return null;let n=nf.getState();if(n.sessionId&&n.messages.some(t=>t.id===e))return n.sessionId.includes(">")?null:{sessionId:n.sessionId,projectId:r,archiveCount:az(ng.getState(),n.sessionId)};let a=an.getState().selectedSessionId;return a&&!a.includes(">")?{sessionId:a,projectId:r,archiveCount:az(nG.getState(),a)}:null}function az(e,t){return e.sessionId===t?e.anchor:0}function aO(e){let{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a}=e;return(0,l.jsx)(aU,{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a})}function aU(e){let{messages:t,debugMode:r,readOnly:n,userOrdinalBase:a}=e,s=(0,o.useMemo)(()=>(function(e){let t=[],r=null;for(let n of e)"context"!==rB(n)&&("user"===n.role?(r&&t.push(r),r={user:n,responses:[]}):r?r.responses.push(n):t.push({user:n,responses:[]}));return r&&t.push(r),t})(t),[t]),i=(0,o.useMemo)(()=>{if(n)return!1;let e=t.find(e=>"user"===e.role);return!!e&&null!==a_(e.id)},[t,n]),c=null!=a?a:0;return(0,l.jsx)("div",{className:"flex flex-col",children:s.map(e=>{let t="user"===e.user.role?c++:-1;return(0,l.jsx)(aB,{user:e.user,responses:e.responses,debugMode:r,userOrdinal:t,deletable:i},e.user.id)})})}let aB=(0,o.memo)(function(e){let{user:t,responses:r,debugMode:n,userOrdinal:a,deletable:s}=e,o=!!t.deleted;return(0,l.jsxs)("div",{className:(0,U.cn)("border-b border-[var(--border)]/50 last:border-b-0",o&&"opacity-50"),children:["user"===t.role?aK(t.content)?(0,l.jsx)(aG,{content:t.content,userOrdinal:a,deleted:o,messageId:t.id,deletable:s}):aq(t.content)?(0,l.jsx)(a$,{content:t.content,userOrdinal:a,deleted:o,messageId:t.id,deletable:s}):(0,l.jsx)(aX,{content:t.content,localImages:t.localImages,timestamp:t.timestamp,userOrdinal:a,deleted:o,messageId:t.id,deletable:s,sendFailed:t.sendFailed}):(0,l.jsx)("div",{className:"px-3 py-2",children:(0,l.jsx)(aV,{message:t,debugMode:n})}),r.length>0&&(0,l.jsx)(aJ,{responses:r,debugMode:n})]})},(e,t)=>e.user===t.user&&e.debugMode===t.debugMode&&e.userOrdinal===t.userOrdinal&&e.deletable===t.deletable&&e.responses.length===t.responses.length&&e.responses.every((e,r)=>e===t.responses[r]));function aW(e){let{copyText:t,userOrdinal:r,deleted:n,messageId:a,deletable:s}=e,i=(0,ts.kj)(),[c,d]=(0,o.useState)(!1),u=s&&!n&&r>=0,m=async()=>{let e=a_(a);e&&await (0,U.fN)(i("chat.exchange.deleteConfirm"))&&C.send({type:"exchange:delete",sessionId:e.sessionId,projectId:e.projectId,userOrdinal:r,archiveCount:e.archiveCount})};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)}).catch(()=>{})},title:"Copy message",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--background)]/40",children:c?(0,l.jsx)(rw.A,{className:"h-3 w-3 text-emerald-400"}):(0,l.jsx)(aL.A,{className:"h-3 w-3"})}),u&&(0,l.jsx)("button",{onClick:m,title:"Delete message",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-red-900/30 hover:text-red-400",children:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})})]})}let aH="rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400";function aK(e){let t=e.match(/^\(from: session ([^)]+)\)\n([\s\S]*)$/);return t?{sessionId:t[1],body:t[2]}:null}function aG(e){var t;let{content:r,...n}=e,a=aK(r),s=null!=(t=a.sessionId.split(">").pop())?t:a.sessionId,{contentRef:i,clamped:c,expanded:d,toggle:u,contentStyle:m}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20*e,r=(0,o.useRef)(null),[n,a]=(0,o.useState)(!1),[s,l]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=r.current;if(!t)return;let n=20*e+4,s=new ResizeObserver(()=>{let e=t.scrollHeight>n;a(t=>t===e?t:e)});return s.observe(t),()=>s.disconnect()},[e]),{contentRef:r,clamped:n,expanded:s,toggle:()=>l(e=>!e),contentStyle:n?s?{maxHeight:"40vh",overflowY:"auto"}:{maxHeight:"".concat(t,"px"),overflow:"hidden"}:void 0}}(4);return(0,l.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-2 border-b border-[var(--border)] border-l-2 border-l-emerald-500/70 bg-emerald-950/40 backdrop-blur-sm shadow-sm",children:[(0,l.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,l.jsx)(aW,{copyText:a.body,...n})}),(0,l.jsxs)("button",{onClick:u,disabled:!c,className:"mb-1 flex w-full items-center gap-2 pr-16 text-left text-[10px] font-medium text-emerald-400 enabled:hover:text-emerald-300",children:[c&&(d?(0,l.jsx)(H.A,{className:"h-3 w-3"}):(0,l.jsx)(K.A,{className:"h-3 w-3"})),(0,l.jsx)("span",{children:"Report from sub-session"}),(0,l.jsx)("span",{className:"rounded bg-emerald-900/40 px-1 py-0.5 font-mono text-emerald-300/80",children:s}),n.deleted&&(0,l.jsx)("span",{className:aH,children:"deleted"})]}),(0,l.jsx)("div",{ref:i,style:m,children:(0,l.jsx)("div",{className:"text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed",children:a.body})})]})}function aq(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 a$(e){let{content:t,...r}=e,n=aq(t),[a,s]=(0,o.useState)(!1);return(0,l.jsxs)("div",{className:"sticky top-0 z-10 border-l-2 border-l-purple-500/70 bg-purple-950/40 backdrop-blur-sm shadow-sm",children:[(0,l.jsx)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:(0,l.jsx)(aW,{copyText:n.body,...r})}),(0,l.jsxs)("button",{onClick:()=>s(!a),className:"flex w-full items-center gap-2 px-3 py-2 pr-14 text-[10px] font-medium text-purple-400 hover:bg-purple-900/30 transition-colors",children:[a?(0,l.jsx)(H.A,{className:"h-3 w-3"}):(0,l.jsx)(K.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{children:"Conversation summary sent to LLM"}),(0,l.jsxs)("span",{className:"rounded bg-purple-900/40 px-1 py-0.5 font-mono text-purple-300/80",children:[n.olderCount," messages compacted"]}),r.deleted&&(0,l.jsx)("span",{className:aH,children:"deleted"})]}),a&&(0,l.jsx)("div",{className:"px-3 pb-2 text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed max-h-[40vh] overflow-y-auto",children:n.body})]})}function aJ(e){let{responses:t,debugMode:r}=e,n=(0,o.useMemo)(()=>{var e,n;let a=new Map;if(!r)return a;let s=t.filter(e=>"usage"===rB(e)&&e.usage);if(0===s.length)return a;let l=new Map;for(let e of t)if("assistant"===rB(e)&&e.contentBlocks)for(let t of e.contentBlocks)t.turnId&&l.set(t.turnId,e.id);let o=[];for(let t of s){let r=t.turnId?l.get(t.turnId):void 0;if(r){let n=null!=(e=a.get(r))?e:[];n.push(t),a.set(r,n)}else o.push(t)}if(o.length>0){let e=[...t].reverse().find(e=>"assistant"===rB(e));if(e){let t=null!=(n=a.get(e.id))?n:[];t.push(...o),a.set(e.id,t)}}return a},[r,t]);return(0,l.jsx)("div",{className:"px-3 py-2",children:t.map(e=>(0,l.jsx)(aV,{message:e,debugMode:r,usages:n.get(e.id)},e.id))})}function aZ(e){var t,r,n,a,s,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:"",p=u.inputTokens+(null!=(n=u.cacheReadInputTokens)?n:0)+(null!=(a=u.cacheWriteInputTokens)?a:0),x=p+u.outputTokens,f=p>0?Math.round(u.cacheReadInputTokens/p*100):0,h=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,l.jsxs)("div",{className:"flex flex-wrap items-center gap-1 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)]",children:[(0,l.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,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,l.jsx)("span",{className:"opacity-60",children:"in"}),(u.inputTokens/1e3).toFixed(1),"K"]}),(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,l.jsx)("span",{className:"opacity-60",children:"out"}),(u.outputTokens/1e3).toFixed(1),"K"]}),(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,l.jsx)("span",{className:"opacity-60",children:"ctx"}),(x/1e3).toFixed(1),"K"]}),(null!=(s=u.cacheReadInputTokens)?s:0)>0&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,l.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,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-amber-900/30 px-1 py-px text-amber-400",children:[(0,l.jsx)("span",{className:"opacity-60",children:"write"}),((null!=(c=u.cacheWriteInputTokens)?c:0)/1e3).toFixed(1),"K"]}),f>0&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,l.jsx)("span",{className:"opacity-60",children:"cache"}),f,"%"]}),null!=u.ttftMs&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,l.jsx)("span",{className:"opacity-60",children:"ttft"}),h(u.ttftMs)]}),null!=u.e2eMs&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,l.jsx)("span",{className:"opacity-60",children:"e2e"}),h(u.e2eMs)]}),u.thinkingEffort&&"off"!==u.thinkingEffort&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-purple-900/30 px-1 py-px text-purple-400",children:[(0,l.jsx)("span",{className:"opacity-60",children:"think"}),u.thinkingEffort]}),"off"===u.thinkingEffort&&(0,l.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,l.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 aV(e){var t,r,n,a,s;let{message:i,debugMode:c,usages:d}=e,u=(0,ts.kj)(),m=rB(i),p="assistant"===m,x=(0,o.useMemo)(()=>{if(!c||!p||!(null==d?void 0:d.length))return null;let e=new Map;for(let t of d)t.turnId&&e.set(t.turnId,t);return e.size>0?e:null},[c,p,d]);if("tool_call"===m||"tool_result"===m||"usage"===m||"context"===m)return null;if("agent_start"===m||"agent_done"===m)return c?(0,l.jsx)("div",{className:"my-0.5 px-1",children:(0,l.jsxs)("span",{className:(0,U.cn)("inline-block rounded px-1.5 py-0.5 text-[9px]","agent_start"===m?"bg-blue-900/40 text-blue-400":"bg-emerald-900/40 text-emerald-400"),children:[null!=(a=i.agentName)?a:"Agent",": ",i.content||("agent_start"===m?"started":"done")]})}):null;let f=p&&i.contentBlocks&&i.contentBlocks.length>0,h=f?i.contentBlocks.filter(e=>"tool_call"===e.type).length:0;if(i.interrupted&&!i.content&&!(null==(t=i.toolCalls)?void 0:t.length))return(0,l.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,l.jsx)(aR.A,{className:"h-3 w-3 text-amber-400"}),(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:u("chat.interrupted")})]});if(i.streaming&&!i.content&&!(null==(r=i.toolCalls)?void 0:r.length)&&(c||!(null==(n=i.contentBlocks)?void 0:n.some(e=>"thinking"===e.type&&e.text.trim()))))return(0,l.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin text-[var(--primary)]"}),(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:"Thinking..."})]});let g=[];if(f){let e=i.contentBlocks,t=0;for(let r=0;r<e.length;r++){let n=e[r];if("thinking"===n.type&&n.text.trim()?g.push(!c&&i.streaming&&r===e.length-1?(0,l.jsx)(aQ,{text:n.text},"b".concat(r)):(0,l.jsx)(aY,{text:n.text},"b".concat(r))):"text"===n.type&&n.text.trim()?g.push((0,l.jsx)(a0,{text:n.text},"b".concat(r))):"tool_call"===n.type&&(t++,g.push((0,l.jsx)(a4,{call:n.toolCall,isStreaming:i.streaming,isLast:t===h},"b".concat(r)))),x&&n.turnId){let t=null==(s=e[r+1])?void 0:s.turnId;if(!t||t!==n.turnId){let e=x.get(n.turnId);e&&g.push((0,l.jsx)(aZ,{message:e},"u".concat(n.turnId)))}}}if(x){let t=new Set(e.map(e=>e.turnId).filter(Boolean));for(let[e,r]of x)t.has(e)||g.push((0,l.jsx)(aZ,{message:r},"u".concat(e)))}}else{if(p&&i.toolCalls&&i.toolCalls.length>0&&i.toolCalls.forEach((e,t)=>{g.push((0,l.jsx)(a4,{call:e,isStreaming:i.streaming,isLast:t===i.toolCalls.length-1},"tc".concat(t)))}),x)for(let[e,t]of x)g.push((0,l.jsx)(aZ,{message:t},"u".concat(e)));if(i.content){let e=!p&&/^Compacting context /.test(i.content);g.push(p?(0,l.jsx)(a0,{text:i.content},"txt"):e?(0,l.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin shrink-0"}),(0,l.jsx)("span",{className:"whitespace-pre-wrap",children:i.content})]},"txt"):(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] whitespace-pre-wrap",children:i.content},"txt"))}}return 0===g.length?null:(0,l.jsx)("div",{className:"py-1",children:g})}function aY(e){let{text:t}=e,[r,n]=(0,o.useState)(!1);return(0,l.jsxs)("div",{className:"my-1 rounded border border-purple-900/50 bg-purple-950/20",children:[(0,l.jsxs)("button",{onClick:()=>n(!r),className:"flex w-full items-center gap-1.5 px-2 py-1 text-left text-[11px] text-purple-400 hover:bg-purple-900/20 transition-colors",children:[r?(0,l.jsx)(H.A,{className:"h-3 w-3"}):(0,l.jsx)(K.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{className:"font-medium",children:"Thinking"}),(0,l.jsxs)("span",{className:"text-[10px] text-purple-400/60",children:[t.length.toLocaleString()," chars"]})]}),r&&(0,l.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 aQ(e){let{text:t}=e,r=(0,o.useRef)(null),n=aD(r,(0,o.useRef)(!1));return(0,o.useLayoutEffect)(n,[t,n]),(0,l.jsxs)("div",{"data-thinking-live":"",className:"my-1 rounded border border-purple-900/50 bg-purple-950/20",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-purple-400",children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin"}),(0,l.jsx)("span",{className:"font-medium",children:"Thinking..."}),(0,l.jsxs)("span",{className:"text-[10px] text-purple-400/60",children:[t.length.toLocaleString()," chars"]})]}),(0,l.jsx)("pre",{ref:r,className:"max-h-40 overflow-y-auto px-2 pb-2 text-[11px] leading-relaxed text-[var(--muted-foreground)] whitespace-pre-wrap break-words",children:t})]})}function aX(e){let{content:t,localImages:r,timestamp:n,userOrdinal:a,deleted:s,messageId:i,deletable:c,sendFailed:d}=e,u=(0,ts.kj)(),{text:m,media:p}=(0,o.useMemo)(()=>rZ(t),[t]),[x,f]=(0,o.useState)(null),[h,g]=(0,o.useState)(!1),[v,b]=(0,o.useState)(!1),y=(0,o.useRef)(null),j=m.trim().split("\n"),w=j.length>1,N=(w?"".concat(j[0].trim(),"…"):j[0].trim())||(p.length>0||(null==r?void 0:r.length)?"(attachment)":""),k=w||v;(0,o.useEffect)(()=>{let e=y.current;if(!e)return;let t=new ResizeObserver(()=>{let t=e.scrollWidth>e.clientWidth;b(e=>e===t?e:t)});return t.observe(e),()=>t.disconnect()},[N]);let S=new Date(n),C=e=>e.toString().padStart(2,"0"),A=s?"text-[var(--muted-foreground)] line-through":"text-[var(--accent-foreground)]";return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:(0,U.cn)("sticky top-0 z-10 bg-[var(--accent)] border-b border-[var(--border)] border-l-2 px-4 py-2.5 shadow-sm",s||d?"border-l-red-500/60":"border-l-blue-500"),children:[(0,l.jsxs)("div",{className:"absolute top-1.5 right-1.5 z-20 flex items-center gap-0.5",children:[s&&(0,l.jsx)("span",{className:(0,U.cn)("mr-1",aH),children:"deleted"}),d&&!s&&(0,l.jsxs)("span",{className:"mr-1 inline-flex items-center gap-0.5 rounded bg-red-900/30 px-1 py-px text-[9px] font-medium text-red-400",title:u("chat.sendFailed"),children:[(0,l.jsx)(aR.A,{className:"h-2.5 w-2.5"}),u("chat.sendFailedBadge")]}),(0,l.jsx)(aW,{copyText:m,userOrdinal:a,deleted:s,messageId:i,deletable:c})]}),(0,l.jsxs)("button",{onClick:()=>g(e=>!e),disabled:!k,className:(0,U.cn)("flex w-full min-w-0 items-center gap-1.5 text-left",s||d?"pr-32":"pr-14"),children:[(0,l.jsx)("span",{className:"flex w-3 shrink-0 justify-center text-[var(--muted-foreground)]",children:k?h?(0,l.jsx)(H.A,{className:"h-3 w-3"}):(0,l.jsx)(K.A,{className:"h-3 w-3"}):"\xb7"}),(0,l.jsxs)("span",{className:"shrink-0 text-[10px] font-mono text-[var(--muted-foreground)] opacity-70",title:S.toLocaleString(),children:[C(S.getHours()),":",C(S.getMinutes())]}),(0,l.jsx)("span",{ref:y,className:(0,U.cn)("min-w-0 truncate text-xs",A,h&&k&&"invisible"),children:N})]}),h&&k&&(0,l.jsx)("div",{className:"mt-1 max-h-[40vh] overflow-y-auto",children:(0,l.jsx)("div",{className:(0,U.cn)("text-xs leading-relaxed whitespace-pre-wrap",A),children:m})})]}),r&&r.length>0&&(0,l.jsx)("div",{className:"flex flex-wrap gap-2 px-4 py-2 border-b border-[var(--border)]/30",children:r.map((e,t)=>(0,l.jsx)(tl.p,{src:e,alt:"screenshot",onClick:()=>f(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",placeholderClassName:"aspect-video w-40"},t))}),p.length>0&&(0,l.jsx)("div",{className:"px-4 py-2 border-b border-[var(--border)]/30",children:(0,l.jsx)(rV,{media:p})}),x&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:()=>f(null),children:(0,l.jsx)(tl.p,{src:x,alt:"screenshot",className:"max-h-[90vh] max-w-[92vw] object-contain",placeholderClassName:"aspect-video w-[min(92vw,640px)]"})})]})}function a0(e){let{text:t}=e,{text:r,media:n}=(0,o.useMemo)(()=>rZ(t),[t]),a=(0,o.useMemo)(()=>r.replace(au,"").replace(/<<<SHOW:[\s\S]*?>>>/g,"").trim(),[r]);return(0,l.jsxs)("div",{className:"prose prose-sm prose-invert max-w-none prose-p:my-1.5 prose-headings:my-2 prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-pre:my-2 prose-code:text-amber-300 prose-code:before:content-none prose-code:after:content-none prose-pre:bg-[var(--secondary)] prose-pre:border prose-pre:border-[var(--border)] prose-a:text-[var(--primary)] prose-code:bg-[var(--secondary)] prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:text-xs prose-th:border prose-th:border-[var(--border)] prose-th:px-2 prose-th:py-1 prose-th:bg-[var(--secondary)] prose-td:border prose-td:border-[var(--border)] prose-td:px-2 prose-td:py-1",children:[a&&(0,l.jsx)(tt.oz,{remarkPlugins:[tr.A],components:{a(e){let{href:t,children:r,node:n,...a}=e;return(0,l.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...a,children:r})},img(e){let{src:t,alt:r,node:n,...a}=e;return(0,l.jsx)(tl.p,{src:t,alt:null!=r?r:"",...a,placeholderClassName:"my-2 aspect-[4/3] w-full max-w-sm"})},pre(e){let{children:t}=e;return(0,l.jsx)("pre",{className:"overflow-x-auto",children:t})},code(e){let{className:t,children:r,node:n,...a}=e;return(null==t?void 0:t.startsWith("language-"))||String(r).includes("\n")?(0,l.jsx)(a8,{className:t,children:r}):(0,l.jsx)("code",{className:t,...a,children:r})}},children:a}),(0,l.jsx)(rV,{media:n})]})}function a1(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t?t:null}catch(e){return null}}let a3="__TOOL_ERROR__",a5="__TOOL_WARN__",a2={running:"bg-amber-400 animate-pulse",success:"bg-emerald-400",warn:"bg-yellow-400",error:"bg-red-400"};function a4(e){let{call:t,isStreaming:r,isLast:n}=e,[a,s]=(0,o.useState)(!1),i=function(e,t,r){var n;if(!e.output&&""!==e.output)return"running";let a=null!=(n=e.output)?n:"";return a.startsWith(a3)?"error":a.startsWith(a5)?"warn":"success"}(t,r,0),c=void 0!==t.output&&""!==t.output,{summary:d}=(0,o.useMemo)(()=>(function(e,t){let r=a1(t);if(r){var n,a,s,l,o,i,c,d,u,m,p,x,f,h,g,v,b,y,j,w,N,k,S;switch(e){case"shell_exec":return{summary:String(null!=(a=null!=(n=r.command)?n:r.cmd)?a:"")||t};case"file_read":return{summary:String(null!=(o=null!=(l=null!=(s=r.path)?s:r.file)?l:r.filePath)?o:"")||t};case"file_write":{let e=String(null!=(d=null!=(c=null!=(i=r.path)?i:r.file)?c:r.filePath)?d:""),t=String(null!=(u=r.content)?u:"");return{summary:e,detail:t?"".concat(t.length," chars"):void 0}}case"file_edit":return{summary:String(null!=(x=null!=(p=null!=(m=r.path)?m:r.file)?p:r.filePath)?x:"")};case"file_list":return{summary:String(null!=(g=null!=(h=null!=(f=r.path)?f:r.directory)?h:r.dir)?g:".")};case"grep":{let e=String(null!=(b=null!=(v=r.pattern)?v:r.query)?b:""),t=r.path?" in ".concat(r.path):"",n=r.include?" (".concat(r.include,")"):"";return{summary:'"'.concat(e,'"').concat(t).concat(n)}}case"glob":{let e=String(null!=(j=null!=(y=r.pattern)?y:r.glob)?j:""),t=r.path?" in ".concat(r.path):"";return{summary:"".concat(e).concat(t)}}case"web_fetch":return{summary:String(null!=(w=r.url)?w:"")};case"delegate_task":{let e=String(null!=(N=r.agent_id)?N:""),t=String(null!=(S=null!=(k=r.task)?k:r.input)?S:""),n=t.length>100?t.slice(0,100)+"...":t;return{summary:e?"→ ".concat(e,": ").concat(n):n}}}}return{summary:t}})(t.name,t.input),[t.name,t.input]),u=(0,o.useMemo)(()=>{var e;return c?function(e,t){let r=a1(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(a3+"\n")?e.slice(a3.length+1):e.startsWith(a5+"\n")?e.slice(a5.length+1):e):""},[t.name,t.output,c]),m=u.length>120?u.slice(0,120)+"...":u;return(0,l.jsxs)("div",{className:"my-0.5 text-[12px] font-mono",children:[(0,l.jsxs)("button",{onClick:()=>s(!a),className:"flex w-full items-center gap-1.5 rounded px-1 py-0.5 hover:bg-[var(--secondary)]/60 transition-colors text-left group",children:[(0,l.jsx)("span",{className:(0,U.cn)("h-2 w-2 shrink-0 rounded-full",a2[i])}),a?(0,l.jsx)(H.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}):(0,l.jsx)(K.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"shrink-0 font-semibold text-[var(--foreground)]",children:t.name}),(0,l.jsx)("span",{className:"truncate text-[var(--muted-foreground)]",children:d})]}),a&&(0,l.jsxs)("div",{className:"ml-[22px] mt-0.5 mb-1 rounded border border-[var(--border)] bg-[var(--card)] overflow-hidden",children:[(0,l.jsxs)("div",{className:"border-b border-[var(--border)] px-2.5 py-1.5",children:[(0,l.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"IN"}),(0,l.jsx)("pre",{className:"text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-all leading-relaxed",children:d})]}),c&&(0,l.jsxs)("div",{className:"px-2.5 py-1.5",children:[(0,l.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"OUT"}),(0,l.jsx)("pre",{className:(0,U.cn)("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,l.jsxs)("div",{className:"px-2.5 py-1.5 flex items-center gap-1.5",children:[(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin text-amber-400"}),(0,l.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"Running..."})]})]}),!a&&c&&m&&(0,l.jsx)("div",{className:"ml-[22px] text-[11px] text-[var(--muted-foreground)] truncate",children:m})]})}function a8(e){let{children:t,className:r}=e,[n,a]=(0,o.useState)(!1),s=String(t).replace(/\n$/,""),i=(null==r?void 0:r.replace("language-",""))||"";return(0,l.jsxs)("div",{className:"relative group",children:[i&&(0,l.jsx)("span",{className:"block mb-1 text-[9px] leading-none text-[var(--muted-foreground)] opacity-60",children:i}),(0,l.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(s).then(()=>{a(!0),setTimeout(()=>a(!1),2e3)})},className:"absolute top-1 right-1 rounded p-1 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)] transition-opacity",children:n?(0,l.jsx)(rw.A,{className:"h-3 w-3 text-emerald-400"}):(0,l.jsx)(aL.A,{className:"h-3 w-3"})}),(0,l.jsx)("code",{className:r,children:t})]})}var a6=r(8985),a9=r(98285),a7=r(16936),se=r(30906),st=r(73082),sr=r(78153),sn=r(57482),sa=r(48253),ss=r(37784);let sl=n5(),so=sl.useBus,si=sl.bump,sc=[{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"}],sd=[];async function su(e,t,r){try{sd=(await k.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){sd=[]}}function sm(){let e=sd.length>0?sd:sc;return nH.getState().enabled?e:e.filter(e=>"/goal"!==e.name)}function sp(e){let{commands:t,selectedIndex:r,onSelect:n}=e,a=(0,o.useRef)(null);return((0,o.useEffect)(()=>{var e;let t=null==(e=a.current)?void 0:e.children[r];null==t||t.scrollIntoView({block:"nearest"})},[r]),0===t.length)?null:(0,l.jsx)("div",{ref:a,className:"absolute bottom-full left-3 right-3 mb-1 max-h-48 overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-20",children:t.map((e,t)=>(0,l.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),n(e)},className:"flex w-full items-center gap-3 px-3 py-2 text-left text-sm transition-colors ".concat(t===r?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,l.jsx)("span",{className:"font-mono font-medium text-[var(--primary)]",children:e.name}),e.argHint&&(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:e.argHint}),(0,l.jsx)("span",{className:"flex-1 truncate text-xs",children:e.description})]},e.name))})}function sx(e){let{matches:t,selectedIndex:r,onSelect:n,dirs:a=!1}=e,s=(0,o.useRef)(null);return((0,o.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,l.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)=>{var s;let o=ep(e),i=a?B.A:o.Icon,c=a?"text-amber-500":o.color,d=null!=(s=e.split("/").pop())?s:e,u=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"";return(0,l.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),n(e)},className:(0,U.cn)("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,l.jsx)(i,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",c)}),(0,l.jsx)("span",{className:"truncate font-medium",children:d}),u&&(0,l.jsx)("span",{className:"ml-auto truncate text-xs text-[var(--muted-foreground)] opacity-60",children:u})]},e)})})}let sf=(e,t,r)=>Math.min(r,Math.max(t,e));function sh(e){let{src:t,onConfirm:r,onCancel:n}=e,a=(0,ts.kj)(),s=(0,o.useRef)(null),c=(0,o.useRef)(null),[d,u]=(0,o.useState)(null),[m,p]=(0,o.useState)(null),[x,f]=(0,o.useState)(null),h=(0,o.useRef)(null),g=(0,o.useRef)(!1);(0,o.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=new ResizeObserver(()=>{p({w:e.clientWidth,h:e.clientHeight}),f(null)});return t.observe(e),()=>t.disconnect()},[]);let v=d&&m?function(e,t,r,n){let a=Math.min(r/e,n/t),s=e*a,l=t*a;return{x:(r-s)/2,y:(n-l)/2,w:s,h:l}}(d.w,d.h,m.w,m.h):null,b=(0,o.useCallback)(async()=>{var e;let t=c.current;if(g.current||!t||!d)return;g.current=!0;let a=function(e,t,r,n){let a={x:0,y:0,w:r,h:n};if(!e||e.w<8||e.h<8||t.w<=0||t.h<=0)return a;let s=r/t.w,l=n/t.h,o=sf(Math.round((e.x-t.x)*s),0,r),i=sf(Math.round((e.y-t.y)*l),0,n),c=sf(Math.round((e.x+e.w-t.x)*s),0,r),d=sf(Math.round((e.y+e.h-t.y)*l),0,n);return c-o<1||d-i<1?a:{x:o,y:i,w:c-o,h:d-i}}(x,null!=v?v:{x:0,y:0,w:0,h:0},d.w,d.h),s=document.createElement("canvas");s.width=a.w,s.height=a.h,null==(e=s.getContext("2d"))||e.drawImage(t,a.x,a.y,a.w,a.h,0,0,a.w,a.h);let l=await new Promise(e=>s.toBlob(e,"image/png"));l?r(new File([l],function(e){let t=e=>String(e).padStart(2,"0");return"screenshot-".concat(e.getFullYear()).concat(t(e.getMonth()+1)).concat(t(e.getDate()),"-").concat(t(e.getHours())).concat(t(e.getMinutes())).concat(t(e.getSeconds()),".png")}(new Date),{type:"image/png"})):n()},[x,v,d,r,n]);(0,o.useEffect)(()=>{let e=e=>{("Escape"===e.key||"Enter"===e.key)&&(e.preventDefault(),e.stopImmediatePropagation(),"Escape"===e.key?n():b())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[b,n]);let y=e=>{let t=s.current.getBoundingClientRect();return{x:sf(e.clientX-t.left,v.x,v.x+v.w),y:sf(e.clientY-t.top,v.y,v.y+v.h)}};return(0,i.createPortal)((0,l.jsxs)("div",{role:"dialog","aria-label":a("capture.screenshotHint"),className:"fixed inset-0 z-[10000] flex select-none flex-col bg-black/90",children:[(0,l.jsxs)("div",{className:"flex h-12 shrink-0 items-center justify-center gap-3 text-xs text-white/80",children:[(0,l.jsx)("span",{children:a("capture.screenshotHint")}),(0,l.jsx)("button",{onClick:()=>void b(),title:a("capture.screenshotConfirm"),className:"flex h-7 w-7 items-center justify-center rounded-md bg-[var(--primary)] text-[var(--primary-foreground)] transition-opacity hover:opacity-90",children:(0,l.jsx)(rw.A,{className:"h-4 w-4"})}),(0,l.jsx)("button",{onClick:n,title:a("capture.screenshotCancel"),className:"flex h-7 w-7 items-center justify-center rounded-md bg-white/10 text-white transition-colors hover:bg-white/20",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsxs)("div",{ref:s,className:"relative mx-4 mb-4 min-h-0 flex-1 cursor-crosshair touch-none",onPointerDown:e=>{0===e.button&&v&&(e.currentTarget.setPointerCapture(e.pointerId),h.current={...y(e),moved:!1})},onPointerMove:e=>{let t=h.current;if(!t||!v)return;let r=y(e);!t.moved&&3>Math.hypot(r.x-t.x,r.y-t.y)||(t.moved=!0,f({x:Math.min(t.x,r.x),y:Math.min(t.y,r.y),w:Math.abs(r.x-t.x),h:Math.abs(r.y-t.y)}))},onPointerUp:()=>{h.current=null},onDoubleClick:e=>{if(!x||!v)return;let t=y(e);t.x>=x.x&&t.x<=x.x+x.w&&t.y>=x.y&&t.y<=x.y+x.h&&b()},children:[(0,l.jsx)("img",{ref:c,src:t,alt:"",draggable:!1,onLoad:e=>u({w:e.currentTarget.naturalWidth,h:e.currentTarget.naturalHeight}),onError:n,className:"pointer-events-none absolute",style:v?{left:v.x,top:v.y,width:v.w,height:v.h}:{visibility:"hidden"}}),v&&(0,l.jsx)("div",{className:"pointer-events-none absolute overflow-hidden",style:{left:v.x,top:v.y,width:v.w,height:v.h},children:x?(0,l.jsx)("div",{className:"absolute border border-[var(--primary)] shadow-[0_0_0_9999px_rgba(0,0,0,0.55)]",style:{left:x.x-v.x,top:x.y-v.y,width:x.w,height:x.h}}):(0,l.jsx)("div",{className:"absolute inset-0 bg-black/30"})})]})]}),document.body)}let sg=["image/jpeg","image/png","image/gif","image/webp"];async function sv(e){if("image/svg+xml"!==e.type){let t=await createImageBitmap(e);return{source:t,width:t.width,height:t.height,close:()=>t.close()}}let t=URL.createObjectURL(e);try{let e=new Image;e.src=t,await e.decode();let r=e.naturalWidth||1,n=e.naturalHeight||1,a=1024/Math.max(r,n);return{source:e,width:Math.round(r*a),height:Math.round(n*a),close:()=>{}}}finally{URL.revokeObjectURL(t)}}async function sb(e){try{let t=await sv(e),r=Math.min(1,1568/Math.max(t.width,t.height)),n=Math.max(1,Math.round(t.width*r)),a=Math.max(1,Math.round(t.height*r)),s=document.createElement("canvas");s.width=n,s.height=a;let l=s.getContext("2d");if(!l)throw Error("no 2d context");"image/svg+xml"===e.type&&(l.fillStyle="#fff",l.fillRect(0,0,n,a)),l.drawImage(t.source,0,0,n,a),t.close();let o=s.toDataURL("image/jpeg",.85).split(",")[1];if(!o)throw Error("encode failed");return{base64:o,mimeType:"image/jpeg"}}catch(t){if(sg.includes(e.type))return{base64:await new Promise((t,r)=>{let n=new FileReader;n.onload=()=>t(n.result.split(",")[1]),n.onerror=r,n.readAsDataURL(e)}),mimeType:e.type};throw t}}async function sy(e){if(sg.includes(e.type))return!0;try{return(await sv(e)).close(),!0}catch(e){return!1}}let sj=null,sw=null,sN=-1;function sk(){let e=(0,ts.kj)(),t=rT(e=>e.activeProject),r=tI(null==t?void 0:t.id);return t?(0,l.jsx)("button",{onClick:()=>{let e=t.id;if(r)return void tS.getState().setFaceOn(e,!1);window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}})),tC=!0,tm=!0,tS.getState().setFaceOn(e,!0)},"aria-pressed":r,title:e(r?"face.on":"face.button"),className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",r?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(a6.A,{className:(0,U.cn)("h-4 w-4",r&&"fill-current")})}):null}function sS(e){var t;let{cameras:r,onPick:n,onClose:a}=e,s=(0,ts.kj)(),[i,c]=(0,o.useState)((null==(t=r[0])?void 0:t.deviceId)||""),d=(0,o.useRef)(null),u=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=!1,t=()=>{if(u.current){for(let e of u.current.getTracks())e.stop();u.current=null}};return t(),navigator.mediaDevices.getUserMedia({video:!i||{deviceId:{exact:i}},audio:!1}).then(t=>{if(e){for(let e of t.getTracks())e.stop();return}u.current=t,d.current&&(d.current.srcObject=t,d.current.play().catch(()=>{}))}).catch(()=>{}),()=>{e=!0,t()}},[i]),(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:a,children:(0,l.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,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:s("capture.cameraPick")}),(0,l.jsx)("button",{onClick:a,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsx)("video",{ref:d,muted:!0,playsInline:!0,className:"aspect-video w-full bg-black object-contain"}),(0,l.jsx)("div",{className:"flex flex-col gap-1 p-2",children:r.map(e=>(0,l.jsxs)("button",{onClick:()=>c(e.deviceId),title:e.label,className:(0,U.cn)("flex items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-[var(--secondary)]",i===e.deviceId?"text-[var(--primary)]":"text-[var(--foreground)]"),children:[(0,l.jsx)(a9.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,l.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.label})]},e.deviceId))}),(0,l.jsx)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-4 py-3",children:(0,l.jsx)("button",{onClick:()=>{let e=r.find(e=>e.deviceId===i);e&&n(e)},className:"rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:s("capture.cameraUse")})})]})})}let sC=["full","workspace","readonly"],sA={full:{Icon:a7.A,color:"text-amber-400"},workspace:{Icon:se.A,color:"text-blue-400"},readonly:{Icon:tF.A,color:"text-emerald-400"}};function sI(){let e=(0,ts.kj)(),t=nf(e=>e.accessLevel),r=nf(e=>e.isStreaming),n=nf(e=>e.sandboxAvailable),[a,s]=(0,o.useState)(!1),i=(0,o.useRef)(null);(0,o.useEffect)(()=>{null===n&&k.F.health().then(e=>nf.getState().setSandboxAvailable(!!e.sandbox)).catch(()=>{})},[n]),(0,o.useEffect)(()=>{if(!a)return;let e=e=>{i.current&&!i.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]);let c=!1===n,d=c?"full":t,u=r||c,{Icon:m,color:p}=sA[d];return(0,l.jsxs)("div",{ref:i,className:"relative",children:[(0,l.jsxs)("button",{onClick:()=>!u&&s(!a),disabled:u,title:c?e("chat.access.noSandbox"):e("chat.access.title"),className:(0,U.cn)("flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors",u?"opacity-50 cursor-default":"hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,l.jsx)(m,{className:(0,U.cn)("h-3 w-3",p)}),(0,l.jsx)("span",{children:e("chat.access.".concat(d))}),!u&&(0,l.jsx)(H.A,{className:"h-2.5 w-2.5"})]}),a&&(0,l.jsx)("div",{className:"absolute bottom-full left-0 mb-1 min-w-[180px] rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-30",children:sC.map(r=>{let{Icon:n,color:a}=sA[r];return(0,l.jsxs)("button",{onClick:()=>{nf.getState().setAccessLevel(r),s(!1)},className:(0,U.cn)("flex w-full items-start gap-2 px-3 py-1.5 text-left text-xs transition-colors",r===t?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,l.jsx)(n,{className:(0,U.cn)("mt-0.5 h-3 w-3 shrink-0",a)}),(0,l.jsxs)("span",{className:"flex min-w-0 flex-col",children:[(0,l.jsx)("span",{children:e("chat.access.".concat(r))}),(0,l.jsx)("span",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("chat.access.".concat(r,"Desc"))})]}),r===t&&(0,l.jsx)(rw.A,{className:"ml-auto h-3.5 w-3.5 shrink-0 self-center text-[var(--primary)]"})]},r)})})]})}function sE(){return(0,l.jsx)("span",{className:"mx-1 h-4 w-px shrink-0 bg-[var(--border)]"})}function sT(){let e=(0,ts.kj)(),t=nf(e=>e.screenSource),r=nf(e=>e.cameraSource);return[t&&{key:"screen",Icon:st.A,name:t.name,unbind:()=>nf.getState().setScreenSource(null)},r&&{key:"camera",Icon:a9.A,name:r.name,unbind:()=>nf.getState().setCameraSource(null)}].filter(e=>!!e).map(t=>{let{key:r,Icon:n,name:a,unbind:s}=t;return(0,l.jsxs)("div",{className:"flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium text-[var(--primary)]",children:[(0,l.jsx)(n,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{className:"max-w-[80px] truncate",title:a,children:a}),(0,l.jsx)("button",{onClick:s,title:e("capture.unbind"),className:"rounded opacity-75 hover:opacity-100",children:(0,l.jsx)(tM.A,{className:"h-2.5 w-2.5"})})]},r)})}function sM(e){let{modelSupportsImage:t}=e,r=(0,ts.kj)(),n=nf(e=>e.screenSource),a=nf(e=>e.cameraSource),s=nf(e=>e.setScreenSource),i=nf(e=>e.setCameraSource),[c,d]=(0,o.useState)(!1),[u,m]=(0,o.useState)([]),[p,x]=(0,o.useState)(!1),[f,h]=(0,o.useState)(!1),[g,v]=(0,o.useState)(!1),[b,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)([]),[N,k]=(0,o.useState)(!1),S=(0,o.useRef)(null),C=aT(),A=aM();if((0,o.useEffect)(()=>{!t&&(n&&s(null),a&&i(null))},[t,n,a,s,i]),(0,o.useEffect)(()=>{var e,t=n,r=a;aw(t)||ak();let s=r&&(null==(e=aM())?void 0:e.web)?r.id:null;aA&&aA.deviceId===s||(aA&&(ag(aA.stream,aA.video),aA=null),null!==s&&aI(aA={deviceId:s,stream:null,video:null,opening:null,openedAt:0}))},[n,a]),(0,o.useEffect)(()=>{if(!A||!t)return void v(!1);let e=!1;return A.has().then(t=>{e||v(t)}).catch(()=>{}),()=>{e=!0}},[A,t]),(0,o.useEffect)(()=>{if(!c&&!N)return;let e=e=>{S.current&&!S.current.contains(e.target)&&(d(!1),k(!1))},t=e=>{"Escape"===e.key&&(d(!1),k(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[c,N]),!C&&!A||!t)return null;let I=async()=>{if(n)return void s(null);if(null==C?void 0:C.web){let e=await C.start();e&&s({id:am,name:r(e)});return}if(c)return void d(!1);d(!0),h(!0);try{let e=await C.list();m(e);let t=e.filter(e=>e.id.startsWith("screen:"));x(t.length>0&&t.every(e=>e.blank))}catch(e){m([])}finally{h(!1)}},E=(e,t)=>{if(y(!1),k(!1),e)try{localStorage.setItem("halo.cameraId",e)}catch(e){}i({id:e,name:t||r("capture.cameraName")})},T=async()=>{if(a)return void i(null);if(!await A.requestPermission())return void y(!0);let e=await A.list();if(0===e.length)return void E("",void 0);w(e),k(!0)};return(0,l.jsxs)("div",{ref:S,className:"relative flex items-center gap-1",children:[C&&(0,l.jsx)("button",{onClick:I,title:n?r("capture.bound",{name:n.name}):r("capture.button"),className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",n?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(st.A,{className:"h-4 w-4"})}),A&&g&&(0,l.jsx)("button",{onClick:T,title:a?r("capture.cameraBound"):r("capture.cameraButton"),className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",a?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(a9.A,{className:"h-4 w-4"})}),b&&(0,l.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,l.jsx)("div",{children:r((null==A?void 0:A.web)?"capture.cameraPermissionHintWeb":"capture.cameraPermissionHint")}),(0,l.jsxs)("div",{className:"mt-1.5 flex items-center gap-3",children:[A&&!A.web&&(0,l.jsx)("button",{onClick:()=>A.openSettings(),className:"underline hover:text-amber-200",children:r("capture.openSettings")}),(0,l.jsx)("button",{onClick:()=>y(!1),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:r("capture.dismiss")})]})]}),N&&j.length>=1&&(0,l.jsx)(sS,{cameras:j,onPick:e=>E(e.deviceId,e.label),onClose:()=>k(!1)}),c&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:()=>d(!1),children:(0,l.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,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:r("capture.pickTitle")}),(0,l.jsx)("button",{onClick:()=>d(!1),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[p&&C&&!C.web&&(0,l.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,l.jsx)("div",{children:r("capture.permissionHint")}),(0,l.jsx)("button",{onClick:()=>C.openSettings(),className:"mt-1.5 underline hover:text-amber-200",children:r("capture.openSettings")})]}),f?(0,l.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:r("capture.loading")}):0===u.length?(0,l.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:r("capture.empty")}):(0,l.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-3",children:u.map(e=>(0,l.jsxs)("button",{onClick:()=>{s({id:e.id,name:e.name}),d(!1)},title:e.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:[e.thumb?(0,l.jsx)("img",{src:e.thumb,alt:e.name,className:"aspect-video w-full rounded object-cover bg-black/20"}):(0,l.jsx)("div",{className:"flex aspect-video w-full items-center justify-center rounded bg-black/20 text-[10px] text-[var(--muted-foreground)]",children:r("capture.noPreview")}),(0,l.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.icon&&(0,l.jsx)("img",{src:e.icon,alt:"",className:"h-4 w-4 shrink-0"}),(0,l.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs text-[var(--foreground)]",children:e.name})]})]},e.id))})]})]})})]})}function sF(e){let{disabled:t,onCapture:r,onNotice:n}=e,a=(0,ts.kj)(),s=function(){var e,t;let r=null==(e=window.haloCapture)?void 0:e.screenshot;return"function"==typeof r?async()=>{let e=await r();return"string"==typeof e?"data:image/jpeg;base64,".concat(e):e}:"function"==typeof(null==(t=navigator.mediaDevices)?void 0:t.getDisplayMedia)?aC:void 0}(),[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(null),m=(0,o.useRef)(0);if((0,o.useEffect)(()=>()=>{(null==d?void 0:d.startsWith("blob:"))&&URL.revokeObjectURL(d)},[d]),!s)return null;let p=i||null!==d,x=async()=>{if(p){m.current++,c(!1),u(null);return}let e=++m.current;c(!0);let t=null;try{t=await s()}catch(e){}if(e!==m.current){"string"==typeof t&&t.startsWith("blob:")&&URL.revokeObjectURL(t);return}c(!1),t&&"object"==typeof t?n(a("capture.permissionHint")):t&&u(t)};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{onClick:x,disabled:t,title:p?a("capture.screenshotActive"):a("capture.screenshotButton"),className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",p?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(sr.A,{className:"h-4 w-4"})}),d&&(0,l.jsx)(sh,{src:d,onConfirm:e=>{u(null),r(e)},onCancel:()=>u(null)})]})}function sP(e){let{onCompact:t}=e,r=nf(e=>e.messages),n=nf(e=>e.contextTokens),a=nf(e=>e.maxContextTokens),s=nf(e=>e.isCompacting),i=nf(e=>e.isStreaming),c=(0,o.useMemo)(()=>n>0?n:0,[n]);if(0===c||0===r.length||0===a)return null;let d=Math.min(c/a*100,100),u=(c/1e3).toFixed(2),m=2*Math.PI*8,p=r.length>5&&t&&!s&&!i;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(sE,{}),(0,l.jsx)("div",{className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",p&&"cursor-pointer hover:bg-[var(--secondary)]"),title:s?"Compacting...":"~".concat(u,"K / ").concat(a/1e3,"K tokens (").concat(Math.round(d),"%)").concat(p?"\nClick to compact context":""),onClick:p?t:void 0,children:(0,l.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 22 22",className:(0,U.cn)("transform -rotate-90",s&&"animate-pulse"),children:[(0,l.jsx)("circle",{cx:"11",cy:"11",r:8,fill:"none",stroke:"var(--muted-foreground)",strokeWidth:"2.5",opacity:"0.3"}),(0,l.jsx)("circle",{cx:"11",cy:"11",r:8,fill:"none",stroke:s?"#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 sD(e){let{onSend:t,disabled:r,isStreaming:n,onStop:a,onInterrupt:s,pendingMessages:i,onRemovePending:c,onCommand:d,onCompact:u,agentControl:m,debugControl:p}=e,x=(0,ts.kj)(),f=y(e=>e.selectedText),h=y(e=>e.selectedRange),g=y(e=>e.activeTab),v=y(e=>e.contextEnabled),b=y(e=>e.setContextEnabled),[j,w]=(0,o.useState)(""),[N,S]=(0,o.useState)([]),[C,A]=(0,o.useState)(!1),[I,E]=(0,o.useState)(0),[T,M]=(0,o.useState)([]),[F,P]=(0,o.useState)(0),[D,L]=(0,o.useState)(0),[R,_]=(0,o.useState)(!1),[z,O]=(0,o.useState)(null),B=function(){let e=nf(e=>e.selectedAgentId),t=rT(e=>{var t;return null==(t=e.activeProject)?void 0:t.path}),r=so(e=>e.version),[n,a]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{if(!t)return;let n=!1;return Promise.all([k.F.agentConfigs.list(t),(r!==sN&&(sN=r,sj=null,sw=null),sj)?Promise.resolve(sj):(!sw&&(sw=k.F.agentConfigs.models().then(e=>{let t={};for(let n of e.providers){var r;for(let e of n.models)t[e.id]=!!(null==(r=e.capabilities)?void 0:r.image)}return sj=t,t}).catch(()=>({}))),sw)]).then(t=>{var r;let[s,l]=t;if(n)return;let o=null!=(r=s.agents.find(t=>t.id===e))?r:s.agents[0],i=null==o?void 0:o.model;if(!i||!(i in l))return void a(!0);a(l[i])}).catch(()=>{n||a(!0)}),()=>{n=!0}},[e,t,r]),n}(),W=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=()=>{var e;return null==(e=W.current)?void 0:e.focus()};return window.addEventListener("halo:focus-chat-input",e),()=>window.removeEventListener("halo:focus-chat-input",e)},[]);let H=(0,o.useRef)(null),K=rT(e=>e.activeProject),G=0===nf(e=>e.usableAgentCount),q=nH(e=>e.enabled),$=nH(e=>e.goal),J=nf(e=>e.sessionId),Z=q&&!!$&&("intake"===$.status||"running"===$.status)&&J===$.workerSessionId,V=Z&&!j.trim().startsWith("/"),Y=(0,o.useMemo)(()=>{var e,t;if(f&&g){let t=null!=(e=g.split("/").pop())?e:g,r=h?":".concat(h.startLine,"-").concat(h.endLine):"";return"".concat(t).concat(r," (").concat(f.length," chars)")}return g?null!=(t=g.split("/").pop())?t:g:null},[f,h,g]),X=(0,o.useMemo)(()=>{if(!j.startsWith("/")||/\s/.test(j))return[];if(!j.startsWith("/"))return[];let e=j.toLowerCase();return sm().filter(t=>t.name.startsWith(e))},[j]),ee=(0,o.useMemo)(()=>(function(e){var t;let r=e.match(/^(\/\S+)\s+(\S*)$/);if(!r)return[];let n=sm().find(e=>e.name===r[1].toLowerCase());if(!(null==n||null==(t=n.verbs)?void 0:t.length))return[];let a=r[2].toLowerCase();return n.verbs.filter(e=>e.name.startsWith(a)&&e.name!==a).map(e=>({cmd:n,verb:e}))})(j),[j]),[et,er]=(0,o.useState)(0);(0,o.useEffect)(()=>{er(0)},[ee.length]);let en=(0,o.useCallback)(e=>{var t;w("".concat(e.cmd.name," ").concat(e.verb.name," ")),null==(t=W.current)||t.focus()},[]),ea=(0,o.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]),es=(0,o.useMemo)(()=>{if(ea)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,ea]),[el,eo]=(0,o.useState)([]);(0,o.useEffect)(()=>{if(!es||R||!K)return void eo([]);let e=!1,t=setTimeout(()=>{k.F.files.search(K.id,es.query,15).then(t=>{e||eo(t.matches.map(e=>e.path))}).catch(()=>{e||eo([])})},120);return()=>{e=!0,clearTimeout(t)}},[es,R,K]);let ei=(0,o.useCallback)(e=>{if(!es)return;let t=j.slice(0,es.startIdx);w(t+j.slice(es.startIdx+1+es.query.length)),M(t=>t.includes(e)?t:[...t,e]),P(0),_(!1),requestAnimationFrame(()=>{if(W.current){let e=t.length;W.current.selectionStart=e,W.current.selectionEnd=e,W.current.focus(),L(e)}})},[j,es]),[ec,eu]=(0,o.useState)([]),[em,ep]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(!ea||!K)return void eu([]);let e=!1,t=setTimeout(()=>{k.F.files.search(K.id,ea.query,15,!0).then(t=>{e||eu(t.matches.map(e=>e.path))}).catch(()=>{e||eu([])})},120);return()=>{e=!0,clearTimeout(t)}},[ea,K]);let ex=(0,o.useCallback)(e=>{if(!ea)return;let t=j.slice(0,ea.startIdx),r=j.slice(D),n="@scope ".concat(e," ");w(t+n+r),ep(0),requestAnimationFrame(()=>{if(W.current){let e=t.length+n.length;W.current.selectionStart=e,W.current.selectionEnd=e,W.current.focus(),L(e)}})},[j,ea,D]),ef=(0,o.useCallback)(e=>{M(t=>t.filter(t=>t!==e))},[]),eh=(0,o.useCallback)(e=>{var t,r;let n=j.split(/\s+/),a=null!=(t=n[0])?t:"",s=n.slice(1).join(" ");if(e.argHint&&!s&&a!==e.name){w(e.name+" "),E(0),null==(r=W.current)||r.focus();return}null==d||d(e,s),w(""),E(0),W.current&&(W.current.style.height="auto")},[j,d]),eg=(0,o.useCallback)(e=>{let t=Array.from(e).filter(e=>e.type.startsWith("image/"));Promise.all(t.map(sy)).then(e=>{let r=t.filter((t,r)=>!e[r]);O(r.length>0?x("chat.attachUnsupported",{names:r.map(e=>e.name).join(", ")}):null);let n=t.filter((t,r)=>e[r]).map(e=>({file:e,preview:URL.createObjectURL(e)}));n.length>0&&S(e=>[...e,...n])})},[x]),ev=(0,o.useCallback)(e=>{S(t=>{let r=t[e];return(null==r?void 0:r.preview)&&URL.revokeObjectURL(r.preview),t.filter((t,r)=>r!==e)})},[]),eb=(0,o.useCallback)(async()=>{var e,r;let n=j.trim();if(!n&&0===N.length||G)return;if(ee.length>0)return void en(null!=(e=ee[et])?e:ee[0]);if(n.startsWith("/")){if(X.length>0)return void eh(null!=(r=X[I])?r:X[0]);let e=sm().find(e=>{var t;return e.name===(null==(t=n.split(/\s+/)[0])?void 0:t.toLowerCase())});if(e)return void eh(e)}if(Z)return;let a=[];for(let e of N)try{let{base64:t,mimeType:r}=await sb(e.file);a.push({data:t,mimeType:r})}catch(e){console.error("[MessageInput] Image conversion failed:",e)}(n||a.length>0)&&t(n||"(image)",a.length>0?a:void 0,T.length>0?T:void 0),N.forEach(e=>{e.preview&&URL.revokeObjectURL(e.preview)}),S([]),M([]),w(""),W.current&&(W.current.style.height="auto")},[j,N,t,X,I,eh,T,ee,et,en,G,Z]),ey=(0,o.useCallback)(e=>{if(ec.length>0){if("ArrowDown"===e.key){e.preventDefault(),ep(e=>Math.min(e+1,ec.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),ep(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=ec[em];t&&ex(t);return}if("Escape"===e.key){e.preventDefault(),eu([]);return}}if(el.length>0){if("ArrowDown"===e.key){e.preventDefault(),P(e=>Math.min(e+1,el.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),P(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=el[F];t&&ei(t);return}if("Escape"===e.key){e.preventDefault(),_(!0);return}}if(ee.length>0){if("ArrowDown"===e.key){e.preventDefault(),er(e=>Math.min(e+1,ee.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),er(e=>Math.max(e-1,0));return}if("Tab"===e.key){e.preventDefault();let t=ee[et];t&&en(t);return}if("Escape"===e.key){e.preventDefault(),er(0);return}}if(X.length>0){if("ArrowDown"===e.key){e.preventDefault(),E(e=>Math.min(e+1,X.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),E(e=>Math.max(e-1,0));return}if("Escape"===e.key){e.preventDefault(),w(""),E(0);return}if("Tab"===e.key){e.preventDefault();let t=X[I];t&&w(t.name+" ");return}}if("Escape"===e.key&&n&&!j.trim()&&s){e.preventDefault(),s();return}"Enter"!==e.key||e.nativeEvent.isComposing||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),eb())},[eb,X,I,ee,et,en,el,F,ei,ec,em,ex,n,j,s]),ej=(0,o.useCallback)(e=>{w(e.target.value),L(e.target.selectionStart),E(0),_(!1),P(0),ep(0);let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"},[]),ew=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),A(!0)},[]),eN=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),A(!1)},[]),ek=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),A(!1),e.dataTransfer.files.length>0&&eg(e.dataTransfer.files)},[eg]),eS=(0,o.useCallback)(e=>{let t=e.clipboardData.items,r=[];for(let e=0;e<t.length;e++){let n=t[e];if("file"===n.kind){let e=n.getAsFile();e&&r.push(e)}}r.length>0&&(e.preventDefault(),eg(r))},[eg]);return(0,l.jsxs)("div",{className:(0,U.cn)("relative px-3 pb-3 pt-1 transition-colors",C&&"bg-[var(--accent)]"),onDragOver:ew,onDragLeave:eN,onDrop:ek,children:[(0,l.jsx)(sp,{commands:X,selectedIndex:I,onSelect:eh}),(0,l.jsx)(sp,{commands:ee.map(e=>{var t;return{name:"".concat(e.cmd.name," ").concat(e.verb.name),description:null!=(t=e.verb.desc)?t:"",type:"server"}}),selectedIndex:et,onSelect:e=>{var t;w(e.name+" "),null==(t=W.current)||t.focus()}}),(0,l.jsx)(sx,{matches:el,selectedIndex:F,onSelect:ei}),(0,l.jsx)(sx,{matches:ec,selectedIndex:em,onSelect:ex,dirs:!0}),C&&(0,l.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,l.jsx)("p",{className:"text-sm text-[var(--primary)]",children:"Drop images here"})}),(0,l.jsx)("input",{ref:H,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&eg(e.target.files),e.target.value=""}}),z&&(0,l.jsxs)("div",{className:"mb-1 flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1.5 text-xs text-amber-300",children:[(0,l.jsx)("span",{className:"flex-1",children:z}),(0,l.jsx)("button",{onClick:()=>O(null),className:"shrink-0 rounded p-0.5 hover:bg-amber-500/20",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]}),(0,l.jsxs)("div",{className:(0,U.cn)("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,l.jsx)("textarea",{ref:W,value:j,onChange:ej,onKeyDown:ey,onPaste:eS,onSelect:e=>L(e.target.selectionStart),placeholder:G?"All agents are disabled — enable one in the Agents tab to chat":Z?x("goal.inputLocked"):n?"Send to interrupt current response...":"Type @ to reference files...",rows:1,className:"w-full resize-none bg-transparent px-3.5 pt-3 pb-1 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none max-h-[200px]"}),(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-1 px-2 pb-2",children:[(0,l.jsx)(sI,{}),m,(0,l.jsx)(sT,{}),(0,l.jsx)(sP,{onCompact:u}),(0,l.jsx)(sE,{}),(0,l.jsx)("button",{onClick:()=>{var e;return null==(e=H.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,l.jsx)(sn.A,{className:"h-4 w-4"})}),B&&(0,l.jsx)(sF,{disabled:r,onCapture:e=>eg([e]),onNotice:O}),(0,l.jsx)(sM,{modelSupportsImage:B}),(K||p||Y)&&(0,l.jsx)(sE,{}),(0,l.jsx)(sk,{}),p,Y&&(0,l.jsxs)("button",{onClick:()=>b(!v),title:v?"Click to exclude context":"Click to include context",className:(0,U.cn)("flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium transition-colors hover:bg-[var(--secondary)]",v?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] line-through opacity-50"),children:[(0,l.jsx)(Q.A,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{className:"max-w-36 truncate",children:Y})]}),null==i?void 0:i.map((e,t)=>(0,l.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,l.jsx)("span",{className:"max-w-32 truncate",children:e}),(0,l.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,l.jsx)(tM.A,{className:"h-2.5 w-2.5"})})]},"q-".concat(t))),T.map(e=>(0,l.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,l.jsxs)("span",{className:"max-w-32 truncate",children:["@",e.split("/").pop()]}),(0,l.jsx)("button",{onClick:()=>ef(e),className:"ml-0.5 rounded-full p-0.5 hover:bg-green-500/20 hover:text-green-300",children:(0,l.jsx)(tM.A,{className:"h-2.5 w-2.5"})})]},"@".concat(e))),N.map((e,t)=>(0,l.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,l.jsx)("img",{src:e.preview,alt:e.file.name,className:"h-5 w-5 rounded object-cover"}):(0,l.jsx)(ed.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"max-w-20 truncate text-[10px] text-[var(--muted-foreground)]",children:e.file.name}),(0,l.jsx)("button",{onClick:()=>ev(t),className:"ml-0.5 rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-2.5 w-2.5"})})]},"f-".concat(t))),(0,l.jsx)("div",{className:"flex-1"}),n&&!j.trim()&&0===N.length?(0,l.jsx)("button",{onClick:a,title:"Stop generation",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-red-600 text-white transition-colors hover:bg-red-700",children:(0,l.jsx)(sa.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,l.jsx)("button",{onClick:eb,disabled:G||V||!j.trim()&&0===N.length,title:G?"All agents are disabled — enable one to chat":V?x("goal.inputLocked"):n&&j.trim()?"Send (interrupts current response)":"Send (Enter)",className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors",!G&&!V&&(j.trim()||N.length>0)?n?"bg-orange-600 text-white hover:bg-orange-700":"bg-[var(--primary)] text-[var(--primary-foreground)] hover:bg-blue-600":"text-[var(--muted-foreground)] cursor-not-allowed"),children:(0,l.jsx)(ss.A,{className:"h-4 w-4"})})]})]})]})}let sL={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 sR(e){let{currentSessionId:t,onJump:r}=e,n=nH(e=>e.enabled),a=nH(e=>e.goal),s=nH(e=>e.dismissedGoalId),o=nH(e=>e.dismiss),i=(0,ts.kj)();if(!n||!a)return null;let c="done"===a.status||"halted"===a.status;if(c&&s===a.goalSessionId)return null;let d=i("goal.banner.".concat(a.status),{round:a.round,max:a.maxRounds}),u=t===a.goalSessionId,m=t===a.workerSessionId;return(0,l.jsxs)("div",{className:(0,U.cn)("flex items-center gap-2 border-t px-3 py-1.5 text-[11px]",sL[a.status]),children:[(0,l.jsx)("button",{onClick:()=>!u&&r(a.goalSessionId),title:u?void 0:i("goal.banner.jump"),className:(0,U.cn)("min-w-0 flex-1 truncate text-left",!u&&"hover:underline cursor-pointer"),children:d}),(0,l.jsx)("button",{onClick:()=>!m&&r(a.workerSessionId),title:m?void 0:i("goal.banner.jump_worker"),className:(0,U.cn)("shrink-0",!m&&"hover:underline cursor-pointer"),children:i("goal.banner.worker")}),c&&(0,l.jsx)("button",{onClick:()=>o(a.goalSessionId),title:i("goal.banner.dismiss"),className:"shrink-0 rounded p-0.5 opacity-60 hover:opacity-100 transition-opacity",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]})}var s_=r(70805);function sz(e){let{onLoadOlder:t,scrollRef:r}=e,n=(0,ts.kj)(),a=nf(e=>e.sessionId),s=ng(e=>e.sessionId),i=ng(e=>e.anchor),c=ng(e=>e.cursor),d=ng(e=>e.messages),u=ng(e=>e.loading),[m,p]=(0,o.useState)(!1),x=(0,o.useRef)(null);(0,o.useLayoutEffect)(()=>{let e=r.current,t=x.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,x.current=null)},[m,r]);let f=(0,o.useMemo)(()=>d.filter(r5),[d]);return null===s||s!==a||0===i?null:(0,l.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[c>0?(0,l.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,l.jsx)($.A,{className:"h-3 w-3 animate-spin"}),n(u?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,l.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.noEarlier")}),f.length>0&&(0,l.jsxs)(l.Fragment,{children:[m&&(0,l.jsx)(aO,{messages:f,readOnly:!0}),(0,l.jsxs)("button",{onClick:()=>{let e=r.current;x.current=e?e.scrollHeight-e.scrollTop:null,p(!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,l.jsx)(s_.A,{className:"h-3 w-3"}):(0,l.jsx)(K.A,{className:"h-3 w-3"}),(0,l.jsx)("span",{children:n("chat.archive.header",{segments:i-c,messages:f.length})})]})]})]})}var sO=r(39802),sU=r(72486);let sB=e=>Math.min(480,Math.max(120,Math.round(e)));function sW(e,t){try{localStorage.setItem(e,t)}catch(e){}}function sH(e){let{openKey:t,widthKey:r,defaultWidth:n,title:a,children:s,collapsedContent:i,hoverPeek:c}=e,d=(0,ts.kj)(),[u,m]=(0,o.useState)(()=>"false"!==localStorage.getItem(t)),[p,x]=(0,o.useState)(()=>(function(e,t){let r=Number(localStorage.getItem(e));return Number.isFinite(r)&&r>0?sB(r):t})(r,n)),f=null==c?void 0:c.close,h=(0,o.useCallback)((e,r)=>{m(e),sW(t,String(e)),null==f||f(!e&&!!r&&r.detail>0)},[t,f]),g=(0,o.useCallback)(e=>{if(0!==e.button)return;e.preventDefault();let t=e.clientX,n=p,a=document.body.style,s=a.cursor,l=a.userSelect;a.cursor="col-resize",a.userSelect="none";let o=e=>{x(n=sB(p+t-e.clientX))},i=()=>{window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i),a.cursor=s,a.userSelect=l,sW(r,String(n))};window.addEventListener("pointermove",o),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i)},[p,r]),v=e=>{let t=d(e?"sidebar.expand":"sidebar.collapse"),r=e?sO.A:sU.A;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex h-7 shrink-0 items-center justify-between gap-1 border-b border-[var(--border)] pl-2 pr-1",children:[(0,l.jsx)("span",{className:"truncate text-[10px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",children:a}),(0,l.jsx)("button",{onClick:t=>h(e,t),title:t,"aria-label":t,className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(r,{className:"h-3.5 w-3.5"})})]}),(0,l.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:s})]})};return u?(0,l.jsxs)("div",{className:"relative flex shrink-0 flex-col border-l border-[var(--border)] bg-[var(--card)]",style:{width:p},children:[(0,l.jsx)("div",{onPointerDown:g,title:d("sidebar.resize"),className:"absolute inset-y-0 -left-0.5 z-10 w-1 cursor-col-resize transition-colors hover:bg-[var(--primary)]/40"}),v(!1)]}):(0,l.jsxs)("div",{...null==c?void 0:c.bind,className:(0,U.cn)("relative flex shrink-0 flex-col items-center border-l border-[var(--border)] bg-[var(--card)] pt-1",i?"w-10":"w-6"),children:[(0,l.jsx)("button",{onClick:()=>h(!0),title:d("sidebar.expand"),"aria-label":d("sidebar.expand"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(sO.A,{className:"h-3.5 w-3.5"})}),i&&(0,l.jsx)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center",children:i}),(null==c?void 0:c.open)&&(0,l.jsx)("div",{ref:sK,"data-peek":!0,className:"absolute inset-y-0 right-0 z-30 flex flex-col border-l border-[var(--border)] bg-[var(--card)] shadow-[-6px_0_16px_-6px_rgba(0,0,0,0.35)] transition-[translate,opacity] duration-150 ease-out starting:translate-x-4 starting:opacity-0 motion-reduce:transition-none",style:{width:p},children:v(!0)})]})}function sK(e){var t;let r=null==e||null==(t=e.parentElement)?void 0:t.parentElement;e&&r&&(e.style.maxWidth="".concat(r.clientWidth,"px"))}var sG=r(58958);let sq=e=>e?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]";function s$(e){let{icon:t,label:r,tooltip:n,active:a,onActivate:s,badge:o,statusBar:i,actions:c,onClose:d,closeLabel:u,closeIcon:m}=e;return(0,l.jsxs)("div",{onClick:s,title:n,"aria-selected":a,className:(0,U.cn)("group relative mx-1.5 flex h-7 shrink-0 cursor-pointer select-none items-center gap-2 rounded-md px-2 text-[11px] transition-colors",sq(a)),children:[t&&(0,l.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:t}),(0,l.jsx)("div",{className:"min-w-0 flex-1 truncate",children:r}),o,c&&(0,l.jsx)("span",{className:"flex shrink-0 items-center opacity-0 group-hover:opacity-100",children:c}),d&&(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),d(e)},title:u,"aria-label":u,className:"shrink-0 rounded p-0.5 opacity-0 hover:bg-[var(--accent)] group-hover:opacity-100",children:null!=m?m:(0,l.jsx)(tM.A,{className:"h-3 w-3"})}),i]})}function sJ(e){let{icon:t,tooltip:r,active:n,onActivate:a,badge:s}=e;return(0,l.jsxs)("button",{onClick:a,title:r,"aria-label":r,"aria-pressed":n,className:(0,U.cn)("group relative flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[11px] font-medium transition-colors",sq(n)),children:[t,s]})}function sZ(e){let{onClick:t,label:r,collapsed:n=!1}=e;return(0,l.jsx)("div",{className:(0,U.cn)("flex shrink-0 justify-center",n?"py-1.5":"p-1.5"),children:(0,l.jsx)("button",{onClick:t,title:r,"aria-label":r,className:(0,U.cn)("flex h-7 items-center justify-center rounded-md bg-[var(--secondary)]/50 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",n?"w-7":"w-full"),children:(0,l.jsx)(sG.A,{className:"h-3.5 w-3.5"})})})}function sV(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],[t,r]=(0,o.useState)(!1),[a]=(0,o.useState)(()=>(function(e){let t,{openDelay:r=300,closeDelay:n=200}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=!1,s=!1,l=!1,o=!1,i=()=>{clearTimeout(t),t=void 0},c=t=>{i(),a!==t&&(a=t,e(t))},d=(e,r)=>{i(),t=setTimeout(()=>c(e),r)};return{enter(){s=!0,l||o||(a?i():d(!0,r))},leave(){s=!1,o=!1,l||(a?d(!1,n):i())},close(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];o=e,c(!1)},setHold(e){(l=e)?i():a&&!s&&d(!1,n)},dispose:i}})(r));(0,o.useEffect)(()=>()=>a.dispose(),[a]),(0,o.useEffect)(()=>a.setHold(e),[a,e]);let s=(0,o.useMemo)(()=>({onPointerEnter:e=>{"mouse"===e.pointerType&&"function"==typeof window.matchMedia&&(null!=n||(n=window.matchMedia("(hover: hover) and (pointer: fine)")),n.matches)&&a.enter()},onPointerLeave:e=>{"mouse"===e.pointerType&&a.leave()}}),[a]);return{open:t,close:a.close,bind:s}}let sY=new Map;function sQ(e){let{sessions:t,currentSessionId:r,onSelect:n,onDelete:a,onNew:s,onLoadMore:i,hasMore:c=!1,loadingMore:d=!1}=e,u=(0,ts.kj)(),m=nH(e=>e.enabled),p=rT(e=>e.activeProject),[x,f]=(0,o.useState)(null),[h,g]=(0,o.useState)(""),v=(0,o.useRef)(null),b=(0,o.useRef)(""),y=()=>{v.current=null,f(null),g("")},j=async e=>{if(v.current!==e)return;let t=h.trim();if(!t||t===b.current||!(null==p?void 0:p.path))return void y();v.current=null,f(null);try{await k.F.sessionLogs.rename(e,t,p.path)}catch(e){console.error("[SessionSidebar] Rename failed:",e)}n8()},[w,N]=(0,o.useState)(!1),S=sV(null!==x||w),C=e=>{S.close(),n(e)},A=async(e,t)=>{N(!0);try{await a(e,t)}finally{N(!1)}};(0,o.useEffect)(()=>{for(let e of(sY.clear(),t))e.title&&sY.set(e.id,e.title)},[t]);let I=(0,o.useCallback)(e=>{if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&(null==i||i())},{rootMargin:"48px"});return t.observe(e),()=>t.disconnect()},[i,t.length]),E=nN(e=>e.tabs),T=(0,o.useMemo)(()=>new Map(E.flatMap(e=>e.sessionId?[[e.sessionId,e]]:[])),[E]),M=null===r,F=e=>{let t=T.get(e.id);return e.id!==r&&!!(null==t?void 0:t.store)&&!!t.unread},P=e=>e.title||u("chat.tabs.untitled"),D=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center gap-0.5 overflow-y-auto py-1",children:[M&&(0,l.jsx)(sJ,{icon:(0,l.jsx)(ae.A,{className:"h-3.5 w-3.5"}),tooltip:u("chat.tabs.newSession"),active:!0,onActivate:()=>{}}),t.map(e=>{let t=T.get(e.id);return(0,l.jsx)(s5,{title:e.title,tooltip:P(e),active:r===e.id,store:null==t?void 0:t.store,unread:F(e),onActivate:()=>C(e.id)},e.id)})]}),s&&(0,l.jsx)(sZ,{collapsed:!0,onClick:s,label:u("chat.sessions.new")})]});return(0,l.jsxs)(sH,{openKey:"halo_session_sidebar_open",widthKey:"halo_session_sidebar_width",defaultWidth:200,title:u("chat.sessions.title"),collapsedContent:D,hoverPeek:S,children:[(0,l.jsxs)("div",{className:"flex flex-1 flex-col gap-0.5 overflow-y-auto py-1",children:[M&&(0,l.jsx)(s$,{label:u("chat.tabs.newSession"),active:!0,onActivate:()=>{}}),0===t.length?(0,l.jsx)("div",{className:"px-3 py-4 text-center text-[10px] text-[var(--muted-foreground)]",children:"No sessions yet"}):t.map(e=>{var t;let n=T.get(e.id),a=x===e.id,s="string"==typeof(null==(t=e.agentSnapshot)?void 0:t.model)?" \xb7 ".concat(e.agentSnapshot.model.split(".").pop()):"";return(0,l.jsx)(s3,{store:null==n?void 0:n.store,unread:F(e),tooltip:"".concat(P(e),"\n").concat(e.exchangeCount," msgs \xb7 ").concat((0,U.fw)(e.updatedAt,u)).concat(s),active:r===e.id,onActivate:()=>C(e.id),label:a?(0,l.jsx)("input",{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),j(e.id)):"Escape"===t.key&&(t.preventDefault(),y())},onBlur:()=>j(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,l.jsxs)(l.Fragment,{children:[m&&e.goalSessionId&&(0,l.jsx)("span",{title:"Goal-bound worker session",className:"mr-1",children:"\uD83C\uDFAF"}),P(e)]}),actions:a?void 0:(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),v.current=e.id,b.current=e.title||"",f(e.id),g(e.title||"")},title:u("chat.sessions.rename"),"aria-label":u("chat.sessions.rename"),className:"rounded p-0.5 text-[var(--muted-foreground)] hover:text-blue-400",children:(0,l.jsx)(e2.A,{className:"h-3 w-3"})}),onClose:a?void 0:t=>{A(e.id,t)},closeLabel:u("chat.sessions.delete"),closeIcon:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})},e.id)}),c&&(0,l.jsx)("div",{ref:I,className:"flex items-center justify-center py-2 text-[9px] text-[var(--muted-foreground)]",children:d?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)($.A,{className:"h-2.5 w-2.5 animate-spin mr-1"})," Loading…"]}):(0,l.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]}),s&&(0,l.jsx)(sZ,{onClick:()=>{S.close(),s()},label:u("chat.sessions.new")})]})}function sX(e,t){return!function(e){let t=(0,o.useCallback)(t=>e?e.subscribe(t):()=>{},[e]),r=()=>{var t;return null!=(t=null==e?void 0:e.getState().isStreaming)&&t};return(0,o.useSyncExternalStore)(t,r,r)}(e)?t?"unread":"idle":"busy"}let s0={busy:"status.busy",unread:"chat.tabs.unread",idle:"status.idle"};function s1(e){let{status:t,active:r,className:n}=e;return(0,l.jsx)("span",{"aria-hidden":!0,className:(0,U.cn)("pointer-events-none absolute bottom-0 h-0.5 rounded-full transition-colors","busy"===t&&"bg-amber-400 animate-pulse","unread"===t&&"bg-blue-500","idle"===t&&(r?"bg-emerald-500/70":"bg-emerald-500/40 group-hover:bg-emerald-500/70"),n)})}function s3(e){let{store:t,unread:r,tooltip:n,...a}=e,s=(0,ts.kj)(),o=sX(t,r);return(0,l.jsx)(s$,{...a,tooltip:"".concat(n," \xb7 ").concat(s(s0[o])),statusBar:(0,l.jsx)(s1,{status:o,active:a.active,className:"inset-x-1.5"})})}function s5(e){let{title:t,tooltip:r,active:n,store:a,unread:s,onActivate:o}=e,i=(0,ts.kj)(),c=sX(a,s),d=Array.from(t.trim())[0];return(0,l.jsx)(sJ,{icon:d?d.toUpperCase():(0,l.jsx)(ae.A,{className:"h-3.5 w-3.5"}),tooltip:"".concat(r," \xb7 ").concat(i(s0[c])),active:n,onActivate:o,badge:(0,l.jsx)(s1,{status:c,active:n,className:"inset-x-[20%]"})})}var s2=r(81324);let s4=n5(),s8=s4.useBus,s6=s4.bump;function s9(){var e,t;let r=nf(e=>e.selectedAgentId),n=nf(e=>e.sessionId),a=nf(e=>e.isStreaming),s=rT(e=>e.activeProject),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(!1),m=(0,o.useRef)(null),p=(0,ts.kj)(),x=s8(e=>e.version);(0,o.useEffect)(()=>{(null==s?void 0:s.path)&&k.F.agentConfigs.list(s.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),nf.getState().setUsableAgentCount(t.length);let r=nf.getState();!r.sessionId&&"default"===r.selectedAgentId&&t[0]&&"default"!==t[0].id&&r.setSelectedAgentId(t[0].id)}).catch(()=>{})},[null==s?void 0:s.path,x]),(0,o.useEffect)(()=>{(null==s?void 0:s.path)&&su(s.path,null!=n?n:void 0,null!=r?r:void 0).catch(()=>{})},[null==s?void 0:s.path,n,r,x]),(0,o.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 f=!!n,h=null!=(e=i.find(e=>e.id===r))?e:i[0],g=null!=(t=null==h?void 0:h.name)?t:r;return i.length<=1?null:(0,l.jsxs)("div",{ref:m,className:"relative",children:[(0,l.jsxs)("button",{onClick:()=>!f&&!a&&u(!d),disabled:f||a,title:p(f?"chat.agent.locked":"chat.agent.select"),className:(0,U.cn)("flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium transition-colors",f?"text-[var(--muted-foreground)] opacity-50 cursor-default":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,l.jsx)(ar.A,{className:(0,U.cn)("h-3 w-3",!f&&!a&&"text-[var(--primary)]")}),(0,l.jsx)("span",{className:"max-w-[80px] truncate",children:g}),!f&&(0,l.jsx)(H.A,{className:"h-2.5 w-2.5"})]}),d&&(0,l.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,l.jsxs)("button",{onClick:()=>{nf.getState().setSelectedAgentId(e.id),u(!1)},className:(0,U.cn)("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,l.jsx)(ar.A,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{className:"truncate",children:e.name})]},"".concat(e.id,":").concat(e.scope)))})]})}function s7(){let e=(0,ts.kj)(),{messages:t,sendMessage:r,isStreaming:n,deleteSession:a,stopGeneration:s,interruptGeneration:i,pendingMessages:c,removePendingMessage:d,handleCommand:u,sessionId:m}=function(){let e=(0,ts.kj)(),t=nf(e=>e.messages),r=nf(e=>e.isStreaming),n=nf(e=>e.sessionId),a=nf(e=>e.pendingMessages),s=rT(e=>e.activeProject);(0,o.useEffect)(()=>{s&&function(e){var t;let r=nN.getState();if(r.projectId===e)return;let n=function(e){try{let t=localStorage.getItem(nk(e));if(t){let e=JSON.parse(t);return"string"==typeof e.active&&e.active.length>0?e.active:null}for(let t of["halo_session_".concat(e),"halo_session_id"]){let e=localStorage.getItem(t);if(e)return localStorage.removeItem(t),e}}catch(e){}return null}(e),a=n?{tabId:(0,U.$C)(),sessionId:n}:nj(nM(null));for(let n of(nN.setState({projectId:e,tabs:[a],activeTabId:a.tabId}),nF(null!=(t=nP(a.tabId))?t:""),r.tabs))n.store&&nc(n.store);nC.clear()}(s.id)},[null==s?void 0:s.id]);let l=(0,o.useCallback)(()=>{let{activeTab:e,selectedText:t,selectedRange:r,tabs:n,contextEnabled:a}=y.getState();if(!a)return"";let s=[];if(e&&s.push("[Currently viewing: ".concat(e,"]")),t&&t.trim()&&e){let n=r?":".concat(r.startLine,"-").concat(r.endLine):"";s.push("[Selected text in ".concat(e).concat(n,"]\n```\n").concat(t,"\n```"))}return s.length>0?s.join("\n")+"\n\n":""},[]),i=(0,o.useCallback)((t,r,a)=>{var o;if(!s)return;let i=null!=n?n:(0,U.$C)();n||nz(i);let c=l(),d=[];c&&d.push(c.trim()),(null==a?void 0:a.length)&&d.push("[Referenced files:\n".concat(a.map(e=>" - ".concat(e)).join("\n"),"]"));let{screenSource:u,cameraSource:m}=nf.getState(),p=aT(),x=!!u&&!!p,f=!!m&&!!aM();x&&f?d.push(e("capture.bothLlmPrompt",{name:u.name})):f?d.push(e("capture.cameraLlmPrompt")):x&&d.push(e(p.web?"capture.webLlmPrompt":"capture.llmPrompt",{name:u.name})),tb=!1,tA(s.id)&&d.push((o=function(){let e=tf;return tf=[],e}(),"[Face open: ".concat(td).concat(o.length?" \xb7 last: ".concat(o.join(", ")):"","]")));let h=(d.length>0?d.join("\n")+"\n\n":"")+t.trim(),g=nf.getState(),v=t.trim();if(null==a?void 0:a.length){let e=a.map(e=>"@".concat(e.split("/").pop())).join(" ");v="".concat(e," ").concat(v)}if(null==r?void 0:r.length){let t=e("chat.imageSent",{n:r.length});v=v?"".concat(t,"\n").concat(v):t}let b=(0,U.$C)();g.addMessage({id:(0,U.$C)(),role:"user",content:v,timestamp:Date.now(),clientMsgId:b,...(null==r?void 0:r.length)?{localImages:r.map(e=>"data:".concat(e.mimeType,";base64,").concat(e.data))}:{}}),g.messages.some(e=>e.streaming&&"assistant"===e.role&&!e.taskId)||g.addMessage({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let{selectedAgentId:y,accessLevel:j}=nf.getState();C.send({type:"chat",sessionId:i,projectId:s.id,message:h,clientMsgId:b,accessLevel:j,..."default"!==y?{agentId:y}:{},...(null==r?void 0:r.length)?{images:r}:{}})},[n,s,l]),c=(0,o.useCallback)((e,t,r)=>{if(e.trim()||(null==t?void 0:t.length)){if(!s)return void console.warn("[useChat] No active project selected");i(e,t,r)}},[s,i,n]),d=(0,o.useCallback)(()=>{C.send({type:"chat:stop",sessionId:n})},[n]),u=(0,o.useCallback)(()=>{C.send({type:"chat:interrupt",sessionId:n})},[n]),m=(0,o.useCallback)(e=>{nf.getState().removePendingMessage(e)},[]);(0,o.useEffect)(()=>{if(r)return;let e=nf.getState().shiftPendingMessage();if(e){let t=setTimeout(()=>i(e),100);return()=>clearTimeout(t)}},[r,i]);let p=(0,o.useCallback)(e=>{s&&(C.send({type:"session:delete",sessionId:e,projectId:s.path}),n_(e),n0(e))},[s]),x=(0,o.useCallback)((e,t)=>{if(!s)return;if("/clear"===e.name||"/session"===e.name&&"new"===t.trim())return void nR();let r=null!=n?n:(0,U.$C)();n||nz(r);let a=e.name.slice(1),l=nf.getState().selectedAgentId,o={type:"command:".concat(a),sessionId:r,projectId:s.id,..."default"!==l?{agentId:l}:{}};t.trim()&&(o.message=t.trim()),C.send(o),nf.getState().addMessage({id:(0,U.$C)(),role:"system",content:"Executing ".concat(e.name).concat(t.trim()?" ".concat(t.trim()):"","..."),timestamp:Date.now()})},[s,n]);return{messages:t,sendMessage:c,isStreaming:r,sessionId:n,deleteSession:p,stopGeneration:d,interruptGeneration:u,pendingMessages:a,removePendingMessage:m,handleCommand:x}}(),p=nN(e=>e.tabs.find(t=>t.tabId===e.activeTabId)),{sessions:x,remove:f,loadMore:h,hasMore:g,loadingMore:v}=function(){let e=rT(e=>e.activeProject);return function(e){let[t,r]=(0,o.useState)([]),[n,a]=(0,o.useState)(null),[s,l]=(0,o.useState)(!1),i=n4(e=>e.version),c=(0,o.useCallback)(async()=>{if(!e){r([]),a(null);return}try{let t=await k.F.sessionLogs.list(e,{rootOnly:!0,limit:30});r(t.sessions),a(t.nextCursor)}catch(e){r([]),a(null)}},[e]);(0,o.useEffect)(()=>{c()},[c,i]);let d=(0,o.useCallback)(async()=>{if(null!==n&&!s){l(!0);try{if(!e)return;let t=await k.F.sessionLogs.list(e,{rootOnly:!0,limit:30,cursor:n}),s=t.sessions;r(e=>{let t=new Set(e.map(e=>e.id));return[...e,...s.filter(e=>!t.has(e.id))]}),a(t.nextCursor)}catch(e){console.error("[SessionList] loadMore failed:",e)}finally{l(!1)}}},[e,n,s]);return{sessions:t,refresh:c,remove:(0,o.useCallback)(async t=>{try{await k.F.sessionLogs.delete(t,e),r(e=>e.filter(e=>e.id!==t)),n0(t),n8()}catch(e){console.error("[SessionList] Delete failed:",e)}},[e]),loadMore:d,hasMore:null!==n,loadingMore:s}}(null==e?void 0:e.path)}(),[b,j]=(0,o.useState)(()=>"1"===localStorage.getItem("halo_chat_debug"));(0,o.useEffect)(()=>{localStorage.setItem("halo_chat_debug",b?"1":"0")},[b]);let w=rT(e=>{var t;return null==(t=e.activeProject)?void 0:t.id});(0,o.useEffect)(()=>{w&&nK(w)},[w]);let N=(0,o.useCallback)(async(t,r)=>{r.stopPropagation(),await (0,U.fN)(e("chat.sessions.deleteConfirm"))&&(await f(t),a(t))},[a,f,e]),S=(0,o.useMemo)(()=>b?t.filter(e=>!e.taskId):t.filter(r5),[t,b]);return(0,l.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-full min-w-0 flex-1 flex-col",children:[p&&(0,l.jsx)(le,{tab:p,sessionId:m,mainMessages:S,debugMode:b},p.tabId),(0,l.jsxs)("div",{className:"shrink-0",children:[(0,l.jsx)(sR,{currentSessionId:m,onJump:nD}),(0,l.jsx)(sD,{onSend:r,isStreaming:n,onStop:s,onInterrupt:i,pendingMessages:c,onRemovePending:d,onCommand:u,onCompact:()=>u({name:"/session",description:"",type:"server"},"compact"),agentControl:(0,l.jsx)(s9,{}),debugControl:(0,l.jsx)("button",{onClick:()=>j(!b),"aria-pressed":b,className:(0,U.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",b?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),title:"Debug mode: show all messages including tool calls and usage",children:(0,l.jsx)(s2.A,{className:"h-4 w-4"})})})]})]}),(0,l.jsx)(sQ,{sessions:x,currentSessionId:m,onSelect:nD,onDelete:N,onNew:()=>nR(),onLoadMore:h,hasMore:g,loadingMore:v})]})}function le(e){var t,r;let{tab:n,sessionId:a,mainMessages:s,debugMode:i}=e,c=(0,ts.kj)(),d=n.tabId,u=(0,o.useRef)(null),[m]=(0,o.useState)(()=>nC.get(d)),[p,x]=(0,o.useState)(null),f=!!n.loading,h=null!=(t=n.attempt)?t:0;(0,o.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>x(h),3e4);return()=>clearTimeout(e)},[f,h]);let g=f&&p===h,v=(0,o.useRef)(null!=(r=null==m?void 0:m.userScrolledUp)&&r),b=(0,o.useMemo)(()=>{let e=0;for(let t of s)"user"===t.role&&e++;return e},[s]),y=Math.max(0,b-30),[j,w]=(0,o.useState)(()=>({sessionId:a,hiddenTurns:m?Math.min(m.hiddenTurns,y):y,seenTurns:b}));j.sessionId!==a?w({sessionId:a,hiddenTurns:y,seenTurns:b}):(j.hiddenTurns>y||0===j.seenTurns&&b>0)&&w({sessionId:j.sessionId,hiddenTurns:y,seenTurns:b});let N=j.hiddenTurns;(0,o.useLayoutEffect)(()=>{j.seenTurns!==b&&w(e=>({sessionId:e.sessionId,hiddenTurns:v.current?e.hiddenTurns:Math.max(0,b-30),seenTurns:b}))}),(0,o.useEffect)(()=>{nA(d,{hiddenTurns:N})},[d,N]);let k=(0,o.useMemo)(()=>{if(N<=0)return s;let e=0;for(let t=0;t<s.length;t++)if("user"===s[t].role&&++e>N)return s.slice(t);return s},[s,N]),S=(0,o.useRef)(null),C=(0,o.useCallback)(()=>{let e=u.current;S.current=e?e.scrollHeight-e.scrollTop:null,w(e=>({...e,hiddenTurns:Math.max(0,e.hiddenTurns-30)}))},[]);(0,o.useLayoutEffect)(()=>{let e=u.current,t=S.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,S.current=null)},[N]),(0,o.useLayoutEffect)(()=>{let e=u.current;e&&(e.scrollTop=(null==m?void 0:m.userScrolledUp)?m.scrollTop:e.scrollHeight)},[m]);let A=aD(u,v),I=(0,o.useRef)(null),E=(0,o.useRef)(!0),T=(0,o.useCallback)(()=>{let e=u.current;I.current=e?e.scrollHeight-e.scrollTop:null,ny()},[]),M=N>0;(0,o.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{nA(d,{scrollTop:e.scrollTop,userScrolledUp:v.current}),e.scrollTop>200?E.current=!0:e.scrollTop<80&&E.current&&(E.current=!1,M?C():T())};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[d,T,C,M]);let F=ng(e=>e.messages);return(0,o.useEffect)(()=>{let e=u.current,t=I.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,I.current=null)},[F]),(0,o.useEffect)(()=>{A()},[s,A]),(0,o.useEffect)(()=>{let e=u.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(A);return t.observe(e),()=>t.disconnect()},[A]),(0,l.jsx)("div",{ref:u,className:"flex-1 min-h-0 overflow-y-auto",children:f&&n.sessionId?(0,l.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)($.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}),g&&(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{children:"Slow network — still loading…"}),(0,l.jsx)("button",{onClick:()=>(function(e){var t;let r=nI(t=>t.tabId===e);(null==r?void 0:r.sessionId)&&(nE(e,{loading:!0,attempt:(null!=(t=r.attempt)?t:0)+1}),nF(r.sessionId))})(d),className:"text-[var(--primary)] hover:underline",children:"Retry"})]})]}):0===s.length?(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,l.jsx)("div",{className:"rounded-full bg-[var(--secondary)] p-3",children:(0,l.jsx)(ae.A,{className:"h-6 w-6 text-[var(--muted-foreground)]"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:"Start a conversation"}),(0,l.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,l.jsxs)(l.Fragment,{children:[N>0?(0,l.jsx)("button",{onClick:C,className:"flex w-full items-center justify-center gap-1.5 border-b border-[var(--border)]/50 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:c("chat.window.showEarlier",{count:N})}):(0,l.jsx)(sz,{onLoadOlder:T,scrollRef:u}),(0,l.jsx)(aO,{messages:k,debugMode:i,userOrdinalBase:N})]})})}var lt=r(86557),lr=r(21379);let ln="halo_browser_id";function la(){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 ls=null;function ll(){if(ls)return ls;try{let e=window.localStorage.getItem(ln);return e||(e=la(),window.localStorage.setItem(ln,e)),ls=e,e}catch(e){return ls=la()}}let lo="undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.userAgent);var li=r(65146),lc=r(77408),ld=r(89678);function lu(e){let{x:t,y:r,term:n,onClose:a}=e,s=(0,ts.kj)(),i=(0,o.useRef)(null),[c,d]=(0,o.useState)({x:t,y:r}),[u]=(0,o.useState)(()=>n.hasSelection()),[m,p]=(0,o.useState)(!1);(0,o.useEffect)(()=>{var e;function t(e){i.current&&!i.current.contains(e.target)&&a()}function r(e){"Escape"===e.key&&(a(),n.focus())}return null==(e=i.current)||e.focus(),document.addEventListener("mousedown",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r)}},[a,n]),(0,o.useLayoutEffect)(()=>{let e=i.current;if(!e)return;let n=e.getBoundingClientRect(),a=window.innerWidth,s=window.innerHeight,l=t+n.width+4>a?Math.max(4,a-n.width-4):t,o=r+n.height+4>s?Math.max(4,s-n.height-4):r;(l!==c.x||o!==c.y)&&d({x:l,y:o})},[t,r,c.x,c.y]);let x=()=>{n.focus(),a()},f=async()=>{let e=n.getSelection();try{await navigator.clipboard.writeText(e)}catch(e){n.focus(),document.execCommand("copy")}x()},h=async()=>{try{n.paste(await navigator.clipboard.readText()),x()}catch(e){p(!0)}},g=[{key:"copy",icon:aL.A,label:s("terminal.menu.copy"),hint:lo?"⌘C":"Ctrl+C",disabled:!u,run:f},{key:"paste",icon:li.A,label:s("terminal.menu.paste"),hint:lo?"⌘V":"Ctrl+V",run:h},{key:"selectAll",icon:lc.A,label:s("terminal.menu.selectAll"),run:()=>{n.selectAll(),x()}},{key:"clear",icon:ld.A,label:s("terminal.menu.clear"),run:()=>{n.clear(),x()}}];return(0,l.jsx)("div",{ref:i,tabIndex:-1,style:{position:"fixed",left:c.x,top:c.y,zIndex:9999},onContextMenu:e=>e.preventDefault(),className:"min-w-[160px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg outline-none",children:g.map(e=>{let t=e.icon;return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{disabled:e.disabled,onClick:()=>{e.run()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs text-[var(--foreground)] transition-colors hover:bg-[var(--secondary)] disabled:pointer-events-none disabled:opacity-40",children:[(0,l.jsx)(t,{className:"h-3.5 w-3.5"}),(0,l.jsx)("span",{className:"flex-1 text-left",children:e.label}),e.hint&&(0,l.jsx)("span",{className:"pl-4 text-[10px] text-[var(--muted-foreground)]",children:e.hint})]}),"paste"===e.key&&m&&(0,l.jsx)("div",{className:"max-w-[220px] px-3 pb-1.5 text-[10px] text-[var(--muted-foreground)]",children:s("terminal.menu.pasteHint",{key:lo?"⌘V":"Ctrl+V"})}),"paste"===e.key&&(0,l.jsx)("div",{className:"my-1 border-t border-[var(--border)]"})]},e.key)})})}r(87063);let lm=0,lp={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"}},lx={fontFamily:"'JetBrains Mono', 'Fira Code', Menlo, Monaco, monospace",fontSize:13,lineHeight:1,cursorBlink:!0,scrollback:1e4};function lf(e,t,r,n){let a=document.createElement("div");a.className="absolute inset-0",a.style.display="none",e.appendChild(a);let s=new lt.B({...lx,theme:lp[r]}),l=new lr.Y;s.loadAddon(l),s.open(a),l.fit(),s.onData(e=>{C.send({type:"terminal:input",data:e,terminalId:t})}),s.attachCustomKeyEventHandler(e=>{let t=function(e,t){let{isMac:r,hasSelection:n}=t;if(r||"keydown"!==e.type||!e.ctrlKey||e.altKey||e.metaKey)return null;let a=e.key.toLowerCase();return"c"===a?e.shiftKey||n?"copy":null:"v"===a?"paste":null}(e,{isMac:lo,hasSelection:s.hasSelection()});return"copy"===t&&(e.preventDefault(),s.hasSelection()&&(document.execCommand("copy"),s.clearSelection())),null===t}),a.addEventListener("contextmenu",e=>{e.preventDefault(),n({x:e.clientX,y:e.clientY,term:s})});let o=null,i=new ResizeObserver(()=>{l.fit(),o&&clearTimeout(o),o=setTimeout(()=>{C.send({type:"terminal:resize",cols:s.cols,rows:s.rows,terminalId:t})},150)});return i.observe(a),{term:s,fit:l,container:a,ro:i}}function lh(){let{headerless:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,ts.kj)(),r=(0,o.useRef)(null),n=(0,o.useRef)(new Map),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(null),m=(0,o.useCallback)(()=>u(null),[]),p=rT(e=>e.activeProject),{theme:x}=(0,e8.useTheme)(),f=(0,o.useRef)(x);(0,o.useEffect)(()=>{for(let e of(f.current=x,n.current.values()))e.term.options.theme=lp[x]},[x]);let h=(0,o.useCallback)(e=>{var t,l,o;let i=r.current;if(!i)return;lm++;let d="term_".concat(Date.now().toString(36),"_").concat(lm),m=0===a.length?"bash":"bash (".concat(lm,")"),{term:x,fit:h,container:g,ro:v}=lf(i,d,f.current,u);n.current.set(d,{id:d,name:m,term:x,fit:h,container:g,ro:v,ready:!1,exited:!1});let b=new URLSearchParams(window.location.search).get("folder"),y=null!=(l=null!=(t=null!=e?e:null==p?void 0:p.path)?t:b)?l:"~";return C.send({type:"terminal:start",terminalId:d,cwd:y,cols:x.cols,rows:x.rows,browserId:ll(),workspacePath:null!=(o=null==p?void 0:p.path)?o:""}),s(e=>[...e,{id:d,name:m}]),c(d),d},[p,a.length]),g=(0,o.useCallback)(e=>{let t=n.current.get(e);t&&(C.send({type:"terminal:close",terminalId:e}),t.ro.disconnect(),t.term.dispose(),t.container.remove(),n.current.delete(e),s(t=>{let r=t.filter(t=>t.id!==e);return c(n=>{if(n===e){var a,s;return null!=(s=null==(a=r[Math.min(t.findIndex(t=>t.id===e),r.length-1)])?void 0:a.id)?s:null}return n}),r}))},[]),v=(0,o.useCallback)(e=>{c(e)},[]);(0,o.useEffect)(()=>{let e=n.current;return()=>{for(let t of e.values())t.ro.disconnect(),t.term.dispose(),t.container.remove();e.clear()}},[]),(0,o.useEffect)(()=>{for(let[e,t]of n.current){let r=e===i;t.container.style.display=r?"block":"none",r&&(t.fit.fit(),t.term.focus())}},[i]),(0,o.useEffect)(()=>{let e=[];return e.push(C.on("terminal:output",e=>{let{terminalId:t,data:r}=e;if(t){var a;null==(a=n.current.get(t))||a.term.write(r)}else{let e=n.current.values().next().value;null==e||e.term.write(r)}})),e.push(C.on("terminal:ready",e=>{let{terminalId:t}=e;if(t){let e=n.current.get(t);e&&(e.ready=!0)}})),e.push(C.on("terminal:exit",e=>{let{terminalId:t}=e;if(t){let e=n.current.get(t);e&&(e.exited=!0,e.term.writeln("\r\n\x1b[90m[Process exited]\x1b[0m"))}})),()=>e.forEach(e=>e())},[]);let b=(0,o.useRef)(!1);return(0,o.useEffect)(()=>{if(b.current)return;b.current=!0;let e=C.on("terminal:reattached",e=>{let t=e.terminalIds,a=r.current,l=0;for(let e of t){if(n.current.has(e)){let t=n.current.get(e);C.send({type:"terminal:resize",cols:t.term.cols,rows:t.term.rows,terminalId:e});continue}if(!a)continue;lm++;let t=0===l&&0===n.current.size?"bash":"bash (".concat(lm,")");l++;let{term:r,fit:o,container:i,ro:d}=lf(a,e,f.current,u);r.write("\x1b[?2004h");let m={id:e,name:t,term:r,fit:o,container:i,ro:d,ready:!0,exited:!1};n.current.set(e,m),s(r=>[...r,{id:e,name:t}]),c(t=>null!=t?t:e),C.send({type:"terminal:resize",cols:r.cols,rows:r.rows,terminalId:e})}0===t.length&&0===n.current.size&&h()}),t=()=>{var e;C.send({type:"terminal:reattach",browserId:ll(),workspacePath:null!=(e=null==p?void 0:p.path)?e:""})};t();let a=C.on("_connected",t),l=setTimeout(()=>{0===n.current.size&&h()},2e3);return()=>{clearTimeout(l),e(),a()}},[h]),(0,o.useEffect)(()=>{let e=y.getState().pendingTerminalCwd;return y.subscribe(t=>{let r=t.pendingTerminalCwd;if(r&&r!==e){e=r;let n=t.consumeTerminalSpawn();n&&h(n)}else e=r})},[h]),(0,l.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,l.jsx)("div",{ref:r,className:"relative min-h-0 flex-1 overflow-hidden"}),d&&(0,l.jsx)(lu,{x:d.x,y:d.y,term:d.term,onClose:m}),(0,l.jsxs)(sH,{openKey:"halo_terminal_sidebar_open",widthKey:"halo_terminal_sidebar_width",defaultWidth:160,title:t("terminal.list.title"),collapsedContent:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex min-h-0 w-full flex-1 flex-col items-center gap-0.5 overflow-y-auto py-1",children:a.map(e=>(0,l.jsx)(sJ,{icon:(0,l.jsx)(et.A,{className:"h-3.5 w-3.5"}),tooltip:e.name,active:e.id===i,onActivate:()=>v(e.id)},e.id))}),(0,l.jsx)(sZ,{collapsed:!0,onClick:()=>h(),label:t("terminal.list.new")})]}),children:[(0,l.jsx)("div",{className:"flex flex-1 flex-col gap-0.5 overflow-y-auto py-1",children:a.map(e=>(0,l.jsx)(s$,{icon:(0,l.jsx)(et.A,{className:"h-3 w-3"}),label:e.name,tooltip:e.name,active:e.id===i,onActivate:()=>v(e.id),onClose:a.length>1?()=>g(e.id):void 0,closeLabel:t("terminal.list.close")},e.id))}),(0,l.jsx)(sZ,{onClick:()=>h(),label:t("terminal.list.new")})]})]})}var lg=r(39768);function lv(){let{floating:e=!1,dragHandleRef:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=(0,ts.kj)(),n=y(e=>e.bottomTab),a=y(e=>e.setBottomTab),s=y(e=>e.setBottomFloating),i=y(e=>e.bottomMaximized),c=y(e=>e.setBottomMaximized),[d,u]=(0,o.useState)("terminal"===n);(0,o.useEffect)(()=>{"terminal"===n&&u(!0)},[n]);let[m,p]=(0,o.useState)(0);return(0,o.useEffect)(()=>C.on("_disconnected",()=>p(e=>e+1)),[]),(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{ref:t,className:(0,U.cn)("flex h-[35px] shrink-0 items-center gap-0 border-b border-[var(--border)] bg-[var(--card)] px-2",e&&"cursor-move select-none"),children:[(0,l.jsx)(lb,{label:r("nav.chat"),active:"chat"===n,onClick:()=>a("chat")}),(0,l.jsx)(lb,{label:r("nav.terminal"),active:"terminal"===n,onClick:()=>a("terminal")}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>c(!i),title:i?"Restore panel":"Maximize panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:i?(0,l.jsx)(rF.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(rP.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>s(!e),title:e?"Dock back":"Float panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:e?(0,l.jsx)(tM.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(lg.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsxs)("div",{className:"min-h-0 flex-1",children:[(0,l.jsx)("div",{className:"chat"===n?"h-full":"hidden",children:(0,l.jsx)(s7,{})}),(0,l.jsx)("div",{className:"terminal"===n?"h-full":"hidden",children:d&&(0,l.jsx)(lh,{headerless:!0},m)})]})]})}function lb(e){let{label:t,active:r,onClick:n}=e;return(0,l.jsxs)("button",{onClick:n,className:(0,U.cn)("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,l.jsx)("div",{className:"absolute bottom-0 left-2 right-2 h-px bg-[var(--foreground)]"})]})}function ly(e){let{slotRef:t,dragHandleRef:r}=e,n=y(e=>e.bottomFloatRect),a=y(e=>e.setBottomFloatRect),s=y(e=>e.bottomMaximized),i=(0,o.useRef)(n);(0,o.useEffect)(()=>{i.current=n}),(0,o.useEffect)(()=>{let e=r.current;if(e&&!s)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){if(e.target.closest("button"))return;e.preventDefault();let t=e.clientX,r=e.clientY,n={...i.current};function s(e){let s=e.clientX-t,l=e.clientY-r;a({x:lj(n.x+s,0,window.innerWidth-n.w),y:lj(n.y+l,0,window.innerHeight-n.h),w:n.w,h:n.h})}window.addEventListener("mousemove",s),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",e)})}},[a,s,r]),(0,o.useEffect)(()=>{function e(){let e=i.current,t=lj(e.x,0,Math.max(0,window.innerWidth-e.w)),r=lj(e.y,0,Math.max(0,window.innerHeight-e.h));(t!==e.x||r!==e.y)&&a({...e,x:t,y:r})}return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[a]);let c=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=c.current;if(e&&!s)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){var t;let r=e.target.closest("[data-edges]");if(!r)return;let n=null!=(t=r.getAttribute("data-edges"))?t:"",s={top:n.includes("top"),bottom:n.includes("bottom"),left:n.includes("left"),right:n.includes("right")};e.preventDefault(),e.stopPropagation();let l=e.clientX,o=e.clientY,c={...i.current},d=c.x+c.w,u=c.y+c.h;function m(e){let t=e.clientX-l,r=e.clientY-o,{x:n,y:i,w:m,h:p}=c;if(s.right&&(m=lj(c.w+t,320,window.innerWidth-c.x)),s.bottom&&(p=lj(c.h+r,240,window.innerHeight-c.y)),s.left){let e=lj(c.x+t,0,d-320);n=e,m=d-e}if(s.top){let e=lj(c.y+r,0,u-240);i=e,p=u-e}a({x:n,y:i,w:m,h:p})}window.addEventListener("mousemove",m),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",e)})}},[a,s]);let d=s?{left:0,top:0,width:"100vw",height:"100vh"}:{left:n.x,top:n.y,width:n.w,height:n.h};return(0,l.jsxs)("div",{className:"fixed z-50 flex flex-col rounded-md border border-[var(--border)] bg-[var(--background)] shadow-2xl",style:d,children:[(0,l.jsx)("div",{ref:t,className:"min-h-0 flex-1 overflow-hidden rounded-md"}),!s&&(0,l.jsxs)("div",{ref:c,children:[(0,l.jsx)("div",{"data-edges":"top",className:"absolute -top-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,l.jsx)("div",{"data-edges":"bottom",className:"absolute -bottom-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,l.jsx)("div",{"data-edges":"left",className:"absolute -left-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,l.jsx)("div",{"data-edges":"right",className:"absolute -right-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,l.jsx)("div",{"data-edges":"top left",className:"absolute -top-1 -left-1 h-3 w-3 cursor-nwse-resize"}),(0,l.jsx)("div",{"data-edges":"top right",className:"absolute -top-1 -right-1 h-3 w-3 cursor-nesw-resize"}),(0,l.jsx)("div",{"data-edges":"bottom left",className:"absolute -bottom-1 -left-1 h-3 w-3 cursor-nesw-resize"}),(0,l.jsx)("div",{"data-edges":"bottom right",className:"absolute -bottom-1 -right-1 h-3 w-3 cursor-nwse-resize"})]})]})}function lj(e,t,r){return Math.max(t,Math.min(r,e))}let lw={ts:ea.A,tsx:ea.A,js:ea.A,jsx:ea.A,json:Z.A,md:Q.A};function lN(e){let{onSelect:t,onClose:r}=e,n=rT(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)(0),[d,u]=(0,o.useState)([]),[m,p]=(0,o.useState)(!1),x=(0,o.useRef)(null),f=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]),(0,o.useEffect)(()=>{c(0)},[a]),(0,o.useEffect)(()=>{if(!n)return;let e=a.trim();if(!e){u([]),p(!1);return}p(!0);let t=!1,r=setTimeout(()=>{k.F.files.search(n,e,50).then(e=>{t||u(e.matches)}).catch(e=>{t||(console.error("[QuickOpen] Search failed:",e),u([]))}).finally(()=>{t||p(!1)})},150);return()=>{t=!0,clearTimeout(r)}},[n,a]),(0,o.useEffect)(()=>{var e;let t=null==(e=f.current)?void 0:e.children[i];null==t||t.scrollIntoView({block:"nearest"})},[i]);let h=(0,o.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,o.useEffect)(()=>{function e(e){e.target.closest("[data-quick-open]")||r()}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]),(0,l.jsxs)("div",{className:"fixed inset-0 z-50 flex justify-center pt-[15vh]",children:[(0,l.jsx)("div",{className:"fixed inset-0 bg-black/40"}),(0,l.jsxs)("div",{"data-quick-open":!0,className:"relative w-full max-w-lg",children:[(0,l.jsx)("input",{ref:x,value:a,onChange:e=>s(e.target.value),onKeyDown:h,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,l.jsx)("div",{ref:f,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,l.jsx)("div",{className:"px-4 py-6 text-center text-xs text-[var(--muted-foreground)]",children:m?"Searching...":"No files found"}):d.map((e,n)=>{var a,s,o;let c=null!=(o=lw[null!=(s=null==(a=e.name.split(".").pop())?void 0:a.toLowerCase())?s:""])?o:ed.A;return(0,l.jsxs)("button",{onClick:()=>{t(e.path),r()},className:(0,U.cn)("flex w-full items-center gap-2 px-4 py-2 text-left text-xs transition-colors",n===i?"bg-[var(--accent)] text-[var(--accent-foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,l.jsx)(c,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"truncate font-medium",children:e.name}),(0,l.jsx)("span",{className:"ml-auto truncate text-[10px] text-[var(--muted-foreground)]",children:e.path})]},e.path)})})]})]})}var lk=r(82011);function lS(e){let{initialPath:t,onSelect:r,onClose:n}=e,[a,s]=(0,o.useState)(null!=t?t:""),[i,c]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),[m,p]=(0,o.useState)(!1),[x,f]=(0,o.useState)(null),h=(0,o.useCallback)(async e=>{p(!0),f(null);try{let t=await k.F.fs.browse(e);s(t.path),c(t.parent),u(t.entries)}catch(e){f(e instanceof Error?e.message:"Failed to load directory")}finally{p(!1)}},[]);return(0,o.useEffect)(()=>{t?h(t):k.F.fs.home().then(e=>{let{home:t}=e;return h(t)}).catch(e=>f(String(e)))},[t,h]),(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:n,children:(0,l.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,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,l.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:"Open Workspace"}),(0,l.jsx)("button",{onClick:n,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] px-3 py-2",children:[(0,l.jsx)("button",{onClick:()=>h(i),disabled:m||!i||i===a,title:"Parent directory",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-30",children:(0,l.jsx)(lk.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:()=>k.F.fs.home().then(e=>{let{home:t}=e;return h(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,l.jsx)(tJ.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("input",{type:"text",value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h(a)},className:"flex-1 rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"})]}),(0,l.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[x&&(0,l.jsx)("p",{className:"px-4 py-3 text-xs text-red-400",children:x}),m&&!x&&(0,l.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}),!m&&!x&&0===d.length&&(0,l.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"(empty)"}),!m&&d.map(e=>(0,l.jsxs)("button",{onDoubleClick:()=>h(e.path),onClick:()=>s(e.path),className:(0,U.cn)("flex w-full items-center gap-2 px-4 py-1.5 text-xs text-left transition-colors",a===e.path?"bg-[var(--primary)]/20 text-[var(--foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,l.jsx)(B.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),e.name]},e.path))]}),(0,l.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,l.jsx)("button",{onClick:n,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:"Cancel"}),(0,l.jsx)("button",{onClick:()=>r(a),disabled:!a,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-30",children:"Open"})]})]})})}let lC="halo_recent_workspaces";function lA(){try{let e=localStorage.getItem(lC),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function lI(e){try{localStorage.setItem(lC,JSON.stringify(e))}catch(e){}}var lE=r(42981),lT=r(29062),lM=r(24619);function lF(e){var t,r;let{projectId:n,pathInput:a,onPathInputChange:s,onOpenFolder:i,onOpenPath:c,activeProject:d}=e,u=(0,ts.kj)(),m=N(),p=nf(e=>e.isStreaming),[x,f]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),v=(0,o.useRef)(null),{recent:b,remove:y}=function(){let[e,t]=(0,o.useState)([]);return(0,o.useEffect)(()=>{t(lA())},[]),{recent:e,remove:(0,o.useCallback)(e=>{t(t=>{let r=t.filter(t=>t!==e);return lI(r),r})},[])}}(),[j,w]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),A=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(j)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){A.current&&!A.current.contains(e.target)&&w(!1)}},[j]);let I=S?a.trim().toLowerCase():"",T=b.filter(e=>e!==(null==d?void 0:d.path)&&(!I||e.toLowerCase().includes(I)));async function M(){var e;if(!n)return;let t=await (0,U.ZC)("New file name (relative path, e.g. src/hello.ts):");if(!(null==t?void 0:t.trim()))return;let r=t.trim(),a=eR(null!=(e=r.split("/").pop())?e:"");try{a?await k.F.files.mkdir(r,n):await k.F.files.create(r,n),E(n),a&&m.getState().openPreview(r,"","",{bundle:!0})}catch(e){console.error("[Explorer] Failed to create file:",e),window.alert(e instanceof Error?e.message:"Failed to create file")}}async function F(){if(!n)return;let e=await (0,U.ZC)("New folder name (relative path, e.g. src/utils):");if(null==e?void 0:e.trim())try{await k.F.files.mkdir(e.trim(),n),E(n)}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(!n||!(null==(t=e.target.files)?void 0:t.length))return;let r=Array.from(e.target.files);try{await k.F.files.upload(r,n),E(n)}catch(e){console.error("[Explorer] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}e.target.value=""}let D=null!=(r=null==d||null==(t=d.path.split("/").filter(Boolean).pop())?void 0:t.toUpperCase())?r:"EXPLORER";return(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,l.jsx)(lE.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:u("nav.explorer")}),(0,l.jsx)("div",{className:"flex-1"}),n&&(0,l.jsx)("button",{onClick:function(){n&&(f(!0),E(n),setTimeout(()=>f(!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,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] p-3",children:[(0,l.jsxs)("div",{ref:A,className:"relative min-w-0 flex-1",children:[(0,l.jsx)("input",{type:"text",value:a,onChange:e=>{s(e.target.value),C(!0),w(!0)},onFocus:()=>{C(!1),w(!0)},onKeyDown:e=>{"Enter"!==e.key||e.repeat||e.nativeEvent.isComposing?"Escape"===e.key&&w(!1):(w(!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&&T.length>0&&(0,l.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:T.map(e=>(0,l.jsxs)("div",{onClick:()=>{w(!1),c(e)},className:"group flex cursor-pointer items-center gap-2 px-2 py-1.5 hover:bg-[var(--secondary)]",children:[(0,l.jsx)(lT.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsx)("div",{className:"truncate text-xs text-[var(--foreground)]",children:e.split(/[/\\]/).filter(Boolean).pop()||e}),(0,l.jsx)("div",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e})]}),(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),y(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,l.jsx)(tM.A,{className:"h-3 w-3"})})]},e))})]}),(0,l.jsx)("button",{onClick:()=>g(!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,l.jsx)(e1.A,{className:"h-3.5 w-3.5"})})]}),h&&(0,l.jsx)(lS,{initialPath:null==d?void 0:d.path,onSelect:e=>{g(!1),c(e)},onClose:()=>g(!1)}),n&&(0,l.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--border)] px-3 py-1.5",children:[(0,l.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,l.jsx)("span",{title:u(p?"status.busy":"status.idle"),className:(0,U.cn)("inline-block h-2 w-2 shrink-0 rounded-full",p?"bg-amber-400 animate-pulse":"bg-emerald-500")}),(0,l.jsx)("span",{className:"truncate text-[10px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:D})]}),(0,l.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,l.jsx)("button",{onClick:M,title:"New File",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(eX.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:F,title:"New Folder",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(e0.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:()=>{var e;return null==(e=v.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,l.jsx)(lM.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("input",{ref:v,type:"file",multiple:!0,className:"hidden",onChange:P})]})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto",children:n?(0,l.jsx)(rU,{projectId:n,mode:"tree-only"}):(0,l.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,l.jsx)(q.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"Enter a folder path to explore files"})]})})]})}let lP=n5(),lD=lP.useBus,lL=lP.bump;var lR=r(91061),l_=r(40876),lz=r(35829);function lO(e){return"".concat(e.id,":").concat(e.scope)}let lU="halo_skills_selectedKey",lB="halo_skills_expandedScopes";function lW(){try{let e=localStorage.getItem(lB);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}let lH=(0,d.v)(e=>({skills:[],selectedKey:localStorage.getItem(lU),setSkills:t=>e({skills:t}),setSelectedKey:t=>{t?localStorage.setItem(lU,t):localStorage.removeItem(lU),e({selectedKey:t})},addSkill:t=>e(e=>({skills:[...e.skills,t]})),removeSkill:t=>e(e=>{let r=e.skills.filter(e=>lO(e)!==t),[n,a]=t.split(":"),s="workspace"===a?r.map(e=>e.id===n&&"global"===e.scope?{...e,overridden:!1}:e):r,l=e.selectedKey===t?null:e.selectedKey;return e.selectedKey===t&&localStorage.removeItem(lU),{skills:s,selectedKey:l}})}));function lK(){let e=(0,ts.kj)(),{skills:t,selectedKey:r,setSkills:n,setSelectedKey:a,addSkill:s,removeSkill:i}=lH(),c=rT(e=>e.activeProject),d=null==c?void 0:c.path,[u,m]=(0,o.useState)(lW),[p,x]=(0,o.useState)(!1),f=lD(e=>e.version);async function h(e){if("workspace"===e&&!d)return;let r=await (0,U.ZC)("New ".concat(e," skill name:"));if(!(null==r?void 0:r.trim()))return;let l=r.trim().toLowerCase().replace(/[^a-z0-9一-鿿]+/g,"-").replace(/^-|-$/g,""),o="workspace"===e?"global":"workspace",i=t.find(e=>e.id===l&&e.scope===o);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 (0,U.fN)(t))return}try{let l=(await k.F.skills.create({name:r.trim(),scope:e,projectId:"workspace"===e?d:void 0})).skill;"workspace"===e&&i?n(t.map(e=>e.id===l.id&&"global"===e.scope?{...e,overridden:!0}:e).concat(l)):s(l),m(t=>new Set(t).add(e)),a(lO(l)),lL()}catch(e){console.error("[SkillsSidebar] Create failed:",e)}}async function g(e,t){if(e.stopPropagation(),await (0,U.fN)('Delete skill "'.concat(t.name,'"?')))try{await k.F.skills.remove(t.id,"workspace"===t.scope?{scope:"workspace",projectId:d}:void 0),i(lO(t)),lL()}catch(e){console.error("[SkillsSidebar] Delete failed:",e)}}async function v(e,r){e.stopPropagation();try{let e=await k.F.skills.toggle(r.id,{scope:r.scope,projectId:d});n(t.map(t=>lO(t)===lO(r)?{...t,disabled:e.disabled}:t)),lL()}catch(e){console.error("[SkillsSidebar] Toggle failed:",e)}}(0,o.useEffect)(()=>{localStorage.setItem(lB,JSON.stringify([...u]))},[u]),(0,o.useEffect)(()=>{x(!0),k.F.skills.list(d).then(e=>n(e.skills)).catch(()=>{}).finally(()=>x(!1))},[d,f,n]),(0,o.useEffect)(()=>{if(!d)return;let e=C.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/skills/")&&lL()}),t=A(C,lL);return()=>{e(),t()}},[d]),(0,o.useEffect)(()=>{let e=()=>lL();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]);let b=t.filter(e=>"global"===e.scope),y=t.filter(e=>"workspace"===e.scope),j=(e,t,n,s)=>{let o=u.has(e);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,l.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,l.jsx)(K.A,{className:(0,U.cn)("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,l.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:n}),(0,l.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:s.length})]}),(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),h(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,l.jsx)(sG.A,{className:"h-3 w-3"})})]}),o&&s.map(e=>{let t=lO(e);return(0,l.jsxs)("div",{onClick:()=>a(t),className:(0,U.cn)("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,l.jsx)(lR.A,{className:"h-3 w-3 shrink-0 text-amber-500"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:e.name}),(e.disabled||e.overridden||e.description)&&(0,l.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:e.disabled?"disabled":e.overridden?"overridden":e.description})]}),(0,l.jsx)("button",{onClick:t=>v(t,e),className:(0,U.cn)("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,l.jsx)(l_.A,{className:"h-4.5 w-4.5"}):(0,l.jsx)(lz.A,{className:"h-4.5 w-4.5 text-blue-500"})}),(0,l.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,l.jsx)(eQ.A,{className:"h-3 w-3"})})]},t)})]},e)};return(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,l.jsx)(lR.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:e("skill.skills")}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onClick:()=>lL(),disabled:p,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,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",p&&"animate-spin")})})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[j("global",V.A,e("common.global"),b),d&&j("workspace",q.A,e("common.workspace"),y),0===t.length&&(0,l.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,l.jsx)(lR.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:e("skill.noSkills")})]})]})]})}var lG=r(67889),lq=r(79773),l$=r(73743),lJ=r(4196);function lZ(e){let{value:t,disabled:r,presets:n,placeholder:a,onCommit:s,minWidth:i=240,className:c}=e,[d,u]=(0,o.useState)(t),[m,p]=(0,o.useState)(!1),[x,f]=(0,o.useState)(""),[h,g]=(0,o.useState)(0),v=(0,o.useRef)(null),b=(0,o.useRef)(null);(0,o.useEffect)(()=>{u(t)},[t]),(0,o.useEffect)(()=>{m&&(f(""),g(0),setTimeout(()=>{var e;return null==(e=b.current)?void 0:e.focus()},0))},[m]);let y=(0,o.useMemo)(()=>{if(!x)return n;let e=x.toLowerCase();return n.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))},[x,n]);function j(e){u(e),p(!1),e!==t&&s(e)}function w(){d!==t&&s(d)}return(0,o.useEffect)(()=>{h>=y.length&&g(0)},[y.length,h]),(0,o.useEffect)(()=>{if(m)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){v.current&&!v.current.contains(e.target)&&p(!1)}},[m]),(0,l.jsxs)("div",{ref:v,className:"relative ".concat(null!=c?c:""),style:{minWidth:i},children:[(0,l.jsx)("input",{value:d,disabled:r,onFocus:()=>p(!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&&p(!1):(e.preventDefault(),p(!0))},placeholder:a,className:"h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 pr-6 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),(0,l.jsx)("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] opacity-50",children:"▾"}),m&&(0,l.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,l.jsx)("div",{className:"border-b border-[var(--border)] p-1",children:(0,l.jsx)("input",{ref:b,value:x,onChange:e=>{f(e.target.value),g(0)},onKeyDown:e=>{if("ArrowDown"===e.key)e.preventDefault(),g(e=>Math.min(y.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=y[h];t&&j(t.id)}else"Escape"===e.key&&p(!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,l.jsx)("div",{className:"max-h-56 overflow-auto",children:0===y.length?(0,l.jsx)("div",{className:"px-2 py-2 text-xs text-[var(--muted-foreground)]",children:"No matches"}):y.map((e,t)=>(0,l.jsxs)("div",{onMouseDown:t=>{t.preventDefault(),j(e.id)},onMouseEnter:()=>g(t),className:"cursor-pointer px-2 py-1 text-xs ".concat(t===h?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,l.jsx)("div",{className:"font-medium",children:e.label}),e.label!==e.id&&(0,l.jsx)("div",{className:"text-[10px] ".concat(t===h?"opacity-80":"opacity-60"),children:e.id})]},e.id))})]})]})}let lV={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 lY(e,t){var r,n,a,s,l,o,i,c,d,u;let m=null==e?void 0:e.capabilities,p={},x=null==m?void 0:m.thinking,f=t.thinking;if(x||f){let e=null!=(r=null==x?void 0:x.mode)?r:"adaptive";if(f?!f.enabled:!(null==x?void 0:x.defaultEnabled))p.thinking=void 0;else if("manual"===e){let e=null==f?void 0:f.budget_tokens;p.thinking={enabled:!0,budget_tokens:null!=(n=null!=e?e:null==x?void 0:x.defaultBudgetTokens)?n:8192}}else{let e=null==x?void 0:x.effortPresets,t=null!=(s=null==f?void 0:f.effort)?s:null==f?void 0:f.budget,r=t&&(null==e?void 0:e.some(e=>e.value===t)),n=null!=(o=null!=(l=null==x?void 0:x.default)?l:null==e||null==(a=e[0])?void 0:a.value)?o:"medium";p.thinking={enabled:!0,effort:r?t:n}}}let h=null==m?void 0:m.promptCaching,g=null==h?void 0:h.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)?p.promptCaching=r:r?p.promptCaching=null!=(i=null==h?void 0:h.default)?i:g[0].value:p.promptCaching=null==(c=null==h?void 0:h.defaultEnabled)||c?null!=(d=null==h?void 0:h.default)?d:g[0].value:void 0}else p.promptCaching=void 0;let v=null==m?void 0:m.verbosity,b=null==v?void 0:v.presets,y="string"==typeof t.verbosity?t.verbosity:void 0;return(null==b?void 0:b.length)?y&&b.some(e=>e.value===y)?p.verbosity=y:p.verbosity=null!=(u=null==v?void 0:v.default)?u:void 0:p.verbosity=void 0,p}let lQ="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)]",lX="text-[11px] font-medium text-[var(--foreground)]",l0="text-[10px] text-[var(--muted-foreground)]";function l1(e){let{label:t,enabled:r,value:n,defaultValue:a,presets:s,onChange:o}=e;return(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:r,onChange:e=>o(e.target.checked?n||a:void 0),className:"rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)] h-3.5 w-3.5 cursor-pointer"}),(0,l.jsx)("span",{className:lX,children:t})]}),r&&(0,l.jsx)(lZ,{value:n||a,presets:s.map(e=>({id:e.value,label:e.label})),onCommit:e=>o(e||void 0),minWidth:110,className:"h-7"})]})}function l3(e){var t,r,n,a,s,o,i,c,d,u,m,p;let{data:x,availableSkills:f,availableTools:h,allAgents:g,selfId:v,modelsRegistry:b,onUpdate:y,onUpdateNested:j,onToggleArrayItem:w}=e,N=(0,ts.kj)(),k=null!=(n=x.model)?n:{},S=null!=(a=x.context)?a:{},C=Array.isArray(x.skills)?x.skills:[],A=Array.isArray(x.tools)?x.tools:[],I=Array.isArray(x.team)?x.team:void 0,E=null!=(s=null==b||null==(t=b.providers)?void 0:t.flatMap(e=>e.models))?s:[],T=String(null!=(o=k.id)?o:""),M=E.find(e=>e.id===T);return(0,l.jsxs)("div",{className:"h-full overflow-y-auto p-5 space-y-5",children:[(0,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.basic")}),(0,l.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_80px] gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.name")}),(0,l.jsx)("input",{value:String(null!=(i=x.name)?i:""),onChange:e=>y("name",e.target.value),className:(0,U.cn)(lQ,"mt-1")})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.description")}),(0,l.jsx)("input",{value:String(null!=(c=x.description)?c:""),onChange:e=>y("description",e.target.value),className:(0,U.cn)(lQ,"mt-1")})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.priority")}),(0,l.jsx)("input",{type:"number",value:null!=x.priority?String(x.priority):"",onChange:e=>y("priority",e.target.value?Number(e.target.value):void 0),className:(0,U.cn)(lQ,"mt-1"),placeholder:"0"})]})]})]}),(0,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.model")}),(0,l.jsxs)("div",{className:"grid grid-cols-4 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.provider")}),b&&b.providers.length>0?(0,l.jsx)("select",{value:String(null!=(u=k.provider)?u:null!=(d=null==(r=b.providers[0])?void 0:r.id)?d:""),onChange:e=>{var t,r,n,a,s;let l=b.providers.find(t=>t.id===e.target.value),o=String(null!=(t=k.id)?t:""),i=null==l?void 0:l.models.some(e=>e.id===o),c=null!=(n=null!=(r=null==l?void 0:l.models.find(e=>e.id===l.defaultModelId))?r:i?l.models.find(e=>e.id===o):void 0)?n:null==l?void 0:l.models[0];y("model",{...k,provider:e.target.value,id:null!=(a=null==c?void 0:c.id)?a:"",endpoint:null!=(s=null==l?void 0:l.defaultEndpoint)?s:"",...lY(c,k)})},className:(0,U.cn)("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,l.jsx)("option",{value:e.id,title:e.description,children:null!=(t=e.displayName)?t:e.id},e.id)})}):(0,l.jsx)("input",{value:String(null!=(m=k.provider)?m:""),onChange:e=>j("model","provider",e.target.value),className:(0,U.cn)(lQ,"mt-1")})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.modelId")}),(()=>{var e,t,r,n,a;let s=String(null!=(n=k.provider)?n:null!=(r=null==b||null==(e=b.providers[0])?void 0:e.id)?r:""),o=null!=(a=null==b||null==(t=b.providers.find(e=>e.id===s))?void 0:t.models)?a:[];return(0,l.jsx)(lZ,{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);y("model",{...k,id:e,...lY(t,k)})})(e),className:"mt-1"})})()]}),(()=>{var e,t,r,n,a;let s=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===s),i=null!=(n=null==o?void 0:o.defaultEndpoint)?n:"",c=null==o?void 0:o.endpointPresets;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.endpoint")}),(0,l.jsx)(lZ,{value:String(null!=(a=k.endpoint)?a:""),presets:(null!=c?c:[]).map(e=>({id:e,label:e})),placeholder:i||"https://...",onCommit:e=>j("model","endpoint",e),className:"mt-1"}),i&&!k.endpoint&&(0,l.jsxs)("p",{className:(0,U.cn)(l0,"mt-0.5"),children:["Default: ",i]})]})})(),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:N("agent.maxTokens")}),(0,l.jsx)("input",{type:"number",value:null!=k.maxTokens?String(k.maxTokens):"",onChange:e=>j("model","maxTokens",e.target.value?Number(e.target.value):void 0),className:(0,U.cn)(lQ,"mt-1"),placeholder:(null==M?void 0:M.maxOutputTokens)?String(M.maxOutputTokens):"auto"}),(0,l.jsx)("p",{className:(0,U.cn)(l0,"mt-0.5"),children:(null==M?void 0:M.maxOutputTokens)?N("agent.maxTokensDefault",{max:M.maxOutputTokens.toLocaleString()}):N("agent.maxTokensAuto")})]})]}),(()=>{var e,t,r,n,a,s,o,i;let c=null!=(s=null==M?void 0:M.capabilities)?s:T?lV: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,l.jsxs)("div",{className:"flex flex-wrap gap-6 pt-1",children:[d&&(0,l.jsx)(l1,{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=>j("model","promptCaching",e)}),(null==(a=c.verbosity)||null==(n=a.presets)?void 0:n.length)&&(0,l.jsx)(l1,{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=>j("model","verbosity",e)}),(()=>{let e=!M&&""!==T,t=k.image,r=k.video,n=k.audio;if(e){let e=e=>{let{field:t,label:r,value:n}=e;return(0,l.jsx)("button",{type:"button",onClick:()=>j("model",t,!n||void 0),className:(0,U.cn)("rounded px-2 py-0.5 text-[10px] font-medium transition-colors cursor-pointer",n?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:r})};return(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)(e,{field:"image",label:"Image",value:t}),(0,l.jsx)(e,{field:"video",label:"Video",value:r}),(0,l.jsx)(e,{field:"audio",label:"Audio",value:n})]})}return void 0===c.image&&void 0===c.video&&void 0===c.audio?null:(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[void 0!==c.image&&(0,l.jsx)("span",{className:(0,U.cn)("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,l.jsx)("span",{className:(0,U.cn)("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,l.jsx)("span",{className:(0,U.cn)("rounded px-2 py-0.5 text-[10px] font-medium",c.audio?"bg-emerald-500/15 text-emerald-600":"bg-[var(--secondary)] text-[var(--muted-foreground)]"),children:"Audio"})]})})(),(u||c.thinking)&&(()=>{var e,t,r,n,a,s,o,i,d;let m=k.thinking,p=!!(null==m?void 0:m.enabled),x=!M&&""!==T,f=null!=(n=null==(e=c.thinking)?void 0:e.mode)?n:"adaptive",h=x?(null==m?void 0:m.budget_tokens)!=null?"manual":"adaptive":f,g=null!=(s=null!=(a=null==(t=c.thinking)?void 0:t.default)?a:null==u||null==(r=u[0])?void 0:r.value)?s:"medium",v="manual"===h?{enabled:!0,budget_tokens:8192}:{enabled:!0,effort:g};return(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:p,onChange:e=>{j("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,l.jsx)("span",{className:lX,children:"Thinking"})]}),p&&"adaptive"===h&&u&&(0,l.jsx)(lZ,{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=>j("model","thinking",{enabled:!0,effort:e}),minWidth:110,className:"h-7"}),p&&"manual"===h&&(0,l.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,l.jsx)("span",{className:l0,children:"budget"}),(0,l.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&&j("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,l.jsx)("span",{className:l0,children:"tokens"})]}),p&&x&&(0,l.jsx)("button",{type:"button",onClick:()=>{"adaptive"===h?j("model","thinking",{enabled:!0,budget_tokens:8192}):j("model","thinking",{enabled:!0,effort:g})},className:"text-[10px] text-[var(--muted-foreground)] hover:text-[var(--foreground)] underline cursor-pointer",children:"adaptive"===h?"use budget":"use effort"})]})})()]})})(),Object.keys(S).length>0&&(0,l.jsx)("div",{className:"grid grid-cols-2 gap-4 pt-1",children:Object.entries(S).map(e=>{let[t,r]=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:lX,children:"context.".concat(t)}),(0,l.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=>j("context",t,"number"==typeof r?Number(e.target.value):e.target.value),className:(0,U.cn)(lQ,"mt-1")})]},t)})})]}),(0,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.systemPrompt")}),(0,l.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.systemPromptHint")})]}),(0,l.jsx)("textarea",{value:String(null!=(p=x.system_prompt)?p:""),onChange:e=>y("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,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.team")}),(0,l.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.teamHint")})]}),(0,l.jsx)("div",{className:"flex flex-wrap gap-2",children:g.map(e=>{let t=void 0!==I&&I.includes(e.id);return(0,l.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];y("team",0===r.length?void 0:r)},className:(0,U.cn)("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,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Tools"}),0===h.length?(0,l.jsx)("p",{className:l0,children:N("agent.loadingTools")}):(()=>{var e;let t=new Set(h.map(e=>e.name)),r=new Set(["query_agent","start_session","session_list","get_session_output","query_session","interrupt_session","stop_session","archive_session"]),n=A.filter(e=>!t.has(e)&&!r.has(e)),a=k.image,s=null!=a?a:null==M||null==(e=M.capabilities)?void 0:e.image;return(0,l.jsxs)("div",{className:"flex flex-wrap gap-2",children:[h.map(e=>{let t=A.includes(e.name),r="view_image"===e.name&&""!==T&&!0!==s,n=r?"".concat(e.description,"\n\nNote: the selected model does not declare capabilities.image: true — view_image will be dropped from this agent's tool list at runtime."):e.description;return(0,l.jsxs)("button",{type:"button",title:n,onClick:()=>w("tools",e.name),className:(0,U.cn)("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,l.jsx)("span",{className:"ml-1",children:"⊘"})]},e.name)}),n.map(e=>(0,l.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,l.jsxs)("section",{className:"space-y-3",children:[(0,l.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Skills"}),(()=>{let e=f.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,l.jsx)("p",{className:l0,children:N("agent.noSkills")}):(0,l.jsxs)("div",{className:"flex flex-wrap gap-2",children:[e.map(e=>{let t=C.includes(e.id);return(0,l.jsx)("button",{type:"button",title:[e.description,"(".concat(e.scope,")")].filter(Boolean).join(" "),onClick:()=>w("skills",e.id),className:(0,U.cn)("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,l.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 l5(e){return"".concat(e.id,":").concat(e.scope)}let l2="halo_agents_selectedKey",l4="halo_agents_expandedScopes";function l8(){try{let e=localStorage.getItem(l4);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}function l6(){var e,t;let r=(0,ts.kj)(),n=rT(e=>e.activeProject),a=null!=(e=null==n?void 0:n.path)?e:void 0,[s,i]=(0,o.useState)([]),[d,u]=(0,o.useState)(()=>localStorage.getItem(l2)),[m,p]=(0,o.useState)(l8),{skills:x,setSkills:f}=lH(),[h,g]=(0,o.useState)(null),[v,b]=(0,o.useState)(!1);(0,o.useEffect)(()=>{d?localStorage.setItem(l2,d):localStorage.removeItem(l2)},[d]),(0,o.useEffect)(()=>{localStorage.setItem(l4,JSON.stringify([...m]))},[m]);let y=so(e=>e.version);(0,o.useEffect)(()=>{k.F.agentConfigs.models().then(g).catch(()=>{})},[y]);let j=(0,o.useCallback)(async()=>{b(!0);try{let e=(await k.F.agentConfigs.list(a)).agents.filter(e=>!(e.internal&&"goal"===e.id));i(e),!e.some(e=>l5(e)===d)&&e.length>0&&u(l5(e[0]))}catch(e){console.error("[AgentManagement] Load failed:",e)}finally{b(!1)}},[a,d]),w=s8(e=>e.version);(0,o.useEffect)(()=>{j()},[j,w]),(0,o.useEffect)(()=>{if(!a)return;let e=C.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/agents/")&&s6()}),t=A(C,s6);return()=>{e(),t()}},[a]),(0,o.useEffect)(()=>{let e=()=>s6();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),(0,o.useEffect)(()=>{x.length>0||k.F.skills.list(null==n?void 0:n.path).then(e=>{f(e.skills)}).catch(()=>{})},[null==n?void 0:n.path,x.length,f]);let N=null!=(t=s.find(e=>l5(e)===d))?t:null;async function S(e){var t;if("workspace"===e&&!a)return;let r=await (0,U.ZC)("Agent name:");if(!(null==r?void 0:r.trim()))return;let n=null!=(t=await (0,U.ZC)("Agent description (optional):"))?t:"",l=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/^-|-$/g,""),o="workspace"===e?"global":"workspace",c=s.find(e=>e.id===l&&e.scope===o);if(c){let t="workspace"===e?'Global agent "'.concat(c.name,'" has the same ID.\nWorkspace version will override it at runtime.\n\nContinue?'):'Workspace agent "'.concat(c.name,'" has the same ID.\nIt will override this global agent in that project.\n\nContinue?');if(!await (0,U.fN)(t))return}try{let t=(await k.F.agentConfigs.create({name:r.trim(),description:n.trim(),scope:e,projectId:"workspace"===e?a:void 0})).agent;i(r=>[..."workspace"===e?r.map(e=>e.id===t.id&&"global"===e.scope?{...e,overridden:!0}:e):r,t]),p(t=>new Set(t).add(e)),u(l5(t)),s6()}catch(e){console.error("[AgentManagement] Create failed:",e)}}async function I(e){if(await (0,U.fN)('Delete agent "'.concat(e.name,'"?')))try{await k.F.agentConfigs.remove(e.id,{scope:e.scope,projectId:a}),i(t=>{let r=t.filter(t=>l5(t)!==l5(e));return"workspace"===e.scope?r.map(t=>t.id===e.id&&"global"===t.scope?{...t,overridden:!1}:t):r}),d===l5(e)&&u(null),s6()}catch(e){console.error("[AgentManagement] Delete failed:",e)}}async function E(e){try{let{disabled:t}=await k.F.agentConfigs.toggle(e.id,{scope:e.scope,projectId:a});i(r=>r.map(r=>l5(r)===l5(e)?{...r,disabled:t}:r)),s6()}catch(e){console.error("[AgentManagement] Toggle failed:",e)}}let T=s.filter(e=>e.internal),M=s.filter(e=>"global"===e.scope&&!e.internal),F=s.filter(e=>"workspace"===e.scope&&!e.internal),P=(()=>{let e=new Map;for(let t of[...M,...F])t.overridden||t.disabled||e.set(t.id,{id:t.id,name:t.name});return[...e.values()]})(),D=function(e,t,r,n){let s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{allowCreate:!0},o=m.has(e);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,l.jsxs)("button",{onClick:()=>{p(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,l.jsx)(K.A,{className:(0,U.cn)("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,l.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:r}),(0,l.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:n.length})]}),s.allowCreate&&"internal"!==e&&(0,l.jsx)("button",{onClick:t=>{t.stopPropagation(),S(e)},title:"New ".concat(e," agent"),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]",children:(0,l.jsx)(sG.A,{className:"h-3 w-3"})})]}),o&&n.map(t=>{let r=l5(t);return(0,l.jsxs)("div",{className:(0,U.cn)("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,l.jsx)(ar.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:t.name}),(t.overridden||t.disabled||t.description)&&(0,l.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:t.overridden?"overridden":t.disabled?"disabled":t.description})]}),"internal"!==e&&a&&(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),E(t)},title:t.disabled?"Enable (show in roster)":"Disable (hide from roster)",className:(0,U.cn)("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,l.jsx)(l_.A,{className:"h-4.5 w-4.5"}):(0,l.jsx)(lz.A,{className:"h-4.5 w-4.5 text-blue-500"})}),"global"===t.scope?(0,l.jsx)("span",{title:"Global agent (cannot delete)",children:(0,l.jsx)(lG.A,{className:"h-3 w-3 shrink-0 text-amber-500"})}):(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),I(t)},className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 transition-opacity group-hover:opacity-100 hover:text-red-400",children:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})})]},r)})]},e)};return(0,l.jsxs)(c.YZ,{direction:"horizontal",autoSaveId:"halo-agent-mgmt",className:"h-full",children:[(0,l.jsx)(c.Zk,{defaultSize:22,minSize:12,maxSize:40,children:(0,l.jsxs)("div",{className:"h-full flex flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(ar.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:r("agent.agents")}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.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,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",v&&"animate-spin")})})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[D("global",V.A,r("common.global"),M),a&&D("workspace",q.A,r("common.workspace"),F),T.length>0&&D("internal",lq.A,r("common.internal"),T,{allowCreate:!1})]})]})}),(0,l.jsx)(c.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,l.jsx)(c.Zk,{defaultSize:78,minSize:40,children:N?(0,l.jsx)(l9,{agent:N,allAgents:P,modelsRegistry:h,onSaved:e=>{i(t=>t.map(t=>l5(t)===l5(e)?e:t))}},l5(N)):(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center",children:[(0,l.jsx)(ar.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:r("agent.selectToEdit")})]})})]})}function l9(e){let{agent:t,allAgents:n,modelsRegistry:a,onSaved:s}=e,i=(0,ts.kj)(),{skills:c}=lH(),d=rT(e=>e.activeProject),[u,m]=(0,o.useState)({}),p="halo_agent_view:".concat(l5(t)),[x,f]=(0,o.useState)(()=>{var e;return null!=(e=localStorage.getItem(p))?e:"form"}),h=(0,o.useCallback)(e=>{localStorage.setItem(p,e),f(e)},[p]),[g,v]=(0,o.useState)(!0),[b,y]=(0,o.useState)(null),[j,N]=(0,o.useState)(!1),[S,C]=(0,o.useState)([]),[A,I]=(0,o.useState)("");(0,o.useEffect)(()=>{k.F.agentConfigs.tools().then(e=>C(e.tools)).catch(()=>{})},[]);let E=(0,o.useRef)(s);(0,o.useEffect)(()=>{E.current=s});let T=(0,o.useRef)(null),M=(0,o.useCallback)(async()=>{v(!0),y(null);let e="workspace"===t.scope?null==d?void 0:d.path:void 0;try{let n=await k.F.agentConfigs.getYaml(t.id,{scope:t.scope,projectId:e}),{parse:a,stringify:s}=await r.e(510).then(r.bind(r,5510)),l=null,o=!1;try{l=a(n.yaml)}catch(e){o=!0}if(o||null!==l&&("object"!=typeof l||Array.isArray(l)))y("agent.yamlInvalid");else{let e=null!=l?l:{};m(e),T.current=s(e,{lineWidth:120})}}catch(e){console.error("[AgentEditor] Load YAML failed:",e),y("agent.loadFailed"),m({}),T.current=null}try{var n,a;let r=await k.F.agentConfigs.getMdAll(t.id,{scope:t.scope,projectId:e});I(null!=(a=null==(n=r.files["AGENT.md"])?void 0:n.content)?a:"")}catch(e){I("")}v(!1)},[t.id,t.scope,null==d?void 0:d.path]);(0,o.useEffect)(()=>{M()},[M]);let F=(0,o.useRef)(x);return(0,o.useEffect)(()=>{"edit"===F.current&&"form"===x&&M(),F.current=x},[x,M]),(0,o.useEffect)(()=>{if(g||b)return;let e=setTimeout(async()=>{try{let{stringify:e}=await r.e(510).then(r.bind(r,5510)),n=e(u,{lineWidth:120});if(T.current===n)return;N(!0);let a="workspace"===t.scope?null==d?void 0:d.path:void 0,s=await k.F.agentConfigs.saveYaml(t.id,n,{scope:t.scope,projectId:a});T.current=n,E.current(s.agent)}catch(e){console.error("[AgentEditor] Auto-save failed:",e)}finally{N(!1)}},500);return()=>clearTimeout(e)},[u,t.id,t.scope,null==d?void 0:d.path,g,b]),(0,o.useEffect)(()=>{T.current=null},[t.id,t.scope]),(0,l.jsxs)("div",{className:"flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"flex h-10 items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:["edit"===x&&(0,l.jsxs)("button",{onClick:()=>h("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,l.jsx)(l$.A,{className:"h-3 w-3"}),i("agent.back")]}),(0,l.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.name}),(0,l.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 text-[9px] text-[var(--muted-foreground)]",children:t.scope}),"form"===x&&j&&(0,l.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:i("agent.saving")})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[!t.internal&&(0,l.jsxs)("button",{onClick:()=>{nR(t.id),window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}}))},className:"flex items-center gap-1.5 rounded bg-[var(--secondary)] px-2.5 py-1 text-xs font-medium text-[var(--foreground)] transition-colors hover:bg-[var(--secondary)]/80",children:[(0,l.jsx)(lJ.A,{className:"h-3 w-3"}),i("agent.test")]}),"form"===x&&(0,l.jsxs)("button",{onClick:()=>h("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,l.jsx)(e2.A,{className:"h-3 w-3"}),i("agent.edit")]})]})]}),(0,l.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:"edit"===x?(0,l.jsx)(w,{children:(0,l.jsx)(rU,{projectId:t.path,mode:"full",showMaximize:!1})},"".concat(t.id,":").concat(t.scope)):g?(0,l.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:i("agent.loading")}):b?(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-sm text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{children:i(b)}),(0,l.jsxs)("button",{onClick:()=>M(),className:"flex items-center gap-1.5 rounded bg-[var(--secondary)] px-2.5 py-1 text-xs font-medium text-[var(--foreground)] transition-colors hover:bg-[var(--secondary)]/80",children:[(0,l.jsx)(at.A,{className:"h-3 w-3"}),i("agent.retry")]})]}):(0,l.jsxs)("div",{className:"h-full overflow-y-auto",children:[(0,l.jsx)(l3,{data:u,availableSkills:c,availableTools:S,allAgents:n,selfId:t.id,modelsRegistry:a,onUpdate:function(e,t){m(r=>({...r,[e]:t}))},onUpdateNested:function(e,t,r){m(n=>{var a;let s=null!=(a=n[e])?a:{};return{...n,[e]:{...s,[t]:r}}})},onToggleArrayItem:function(e,t){m(r=>{let n=Array.isArray(r[e])?[...r[e]]:[],a=n.indexOf(t);return a>=0?n.splice(a,1):n.push(t),{...r,[e]:n}})}}),A.trim()&&(0,l.jsxs)("div",{className:"border-t border-[var(--border)]",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5 px-8 pt-6 text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5",children:"AGENT.md"}),(0,l.jsx)("span",{children:i("agent.mdPreviewHint")})]}),(0,l.jsx)(to,{content:A})]})]})})]})}function l7(){var e;let{skills:t,selectedKey:r}=lH(),n=null!=(e=t.find(e=>"".concat(e.id,":").concat(e.scope)===r))?e:null;return n?(0,l.jsx)(w,{children:(0,l.jsx)(rU,{projectId:n.path,mode:"full",showMaximize:!1})},"".concat(n.id,":").concat(n.scope)):(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center bg-[var(--background)]",children:[(0,l.jsx)(lR.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a skill to edit, or create a new one"})]})}var oe=r(99603);let ot=[],or=()=>()=>{};function on(e){var t;let{visible:r}=e,n=(0,ts.kj)(),a=an(e=>e.selectedSessionId),s=an(e=>e.selectedSession),i=an(e=>e.loadedMessages),c=an(e=>e.loading),d=nN(e=>n3(e.tabs,a)),u=null==d?void 0:d.store,m=void 0!==u,p=u&&r?u.subscribe:or,x=()=>{var e;return null!=(e=null==u?void 0:u.getState().messages)?e:ot},f=(0,o.useSyncExternalStore)(p,x,x),h=()=>{var e;return null!=(e=null==u?void 0:u.getState().isStreaming)&&e},g=(0,o.useSyncExternalStore)(p,h,h),v=(0,o.useRef)(null),[b,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)(()=>"1"===localStorage.getItem("halo_session_debug")),[N,S]=(0,o.useState)(()=>"1"===localStorage.getItem("halo_session_prompt"));(0,o.useEffect)(()=>{localStorage.setItem("halo_session_debug",j?"1":"0")},[j]),(0,o.useEffect)(()=>{localStorage.setItem("halo_session_prompt",N?"1":"0")},[N]),(0,o.useEffect)(()=>{nZ=a;let e=a?nJ.get(a):void 0;a&&e&&(nJ.delete(a),nJ.set(a,e))},[a]),(0,o.useEffect)(()=>{nV=r},[r]);let I=an(e=>e.setLoadedMessages),E=(0,o.useRef)(new Map),T=(0,o.useCallback)(e=>{let t=E.current;if(t.has(e))return void t.set(e,!0);let r=()=>{var n;let a=null==(n=rT.getState().activeProject)?void 0:n.path;a&&(t.set(e,!1),nX(e,!1),k.F.sessionLogs.get(e,a).then(t=>{var r,n,a;let s="number"==typeof t.archiveCount?t.archiveCount:0,l=null!=(n=t.messages)?n:[],o=an.getState(),i=o.selectedSessionId===e,c=function(e,t){if(!e||0===e.length)return t;let r=Math.min(e.length,t.length),n=Math.max(0,e.length-2),a=t.length>=e.length;for(let r=0;a&&r<n;r++)(e[r].id!==t[r].id||e[r].deleted!==t[r].deleted)&&(a=!1);if(a){let a=e.length===t.length,s=t.slice();for(let t=0;t<n;t++)s[t]=e[t];for(let l=n;l<r;l++)JSON.stringify(e[l])===JSON.stringify(t[l])?s[l]=e[l]:a=!1;return a?e:s}let s=e.length===t.length,l=t.map((t,r)=>{let n=e[r];return n&&JSON.stringify(n)===JSON.stringify(t)?n:(s=!1,t)});return s?e:l}(null!=(a=null==(r=nY(e))?void 0:r.messages)?a:null,l);nQ(e,c,s),i&&(nq(e,s),c!==o.loadedMessages&&I(c))}).catch(()=>nX(e,!0)).finally(()=>{let n=t.get(e);t.delete(e),n&&(nX(e,!0),an.getState().selectedSessionId===e&&r())}))};r()},[I]);(0,o.useEffect)(()=>{let e=e=>{e&&!n3(nN.getState().tabs,e)&&T(e)},t=C.on("file:changed",t=>e(function(e,t){if("change"!==t&&"add"!==t||!e.startsWith(".halo/sessions/")||!e.endsWith(".json"))return null;let r=e.slice(e.lastIndexOf("/")+1,-5);for(let[e,t]of nJ)n1(e)===r&&(t.stale=!0);return nV&&null!==nZ&&n1(nZ)===r?nZ:null}(t.path,t.action))),r=A(C,()=>e(function(){for(let e of nJ.values())e.stale=!0;return nV?nZ:null}()));return()=>{t(),r()}},[T]),(0,o.useEffect)(()=>{if(!r||!a||m)return;let e=an.getState();if(e.loading)return;let t=nY(a);!t||t.stale?T(a):e.loadedMessages!==t.messages&&I(t.messages)},[r,a,m,T,I]);let M=(0,o.useMemo)(()=>{if(!a)return[];if(m){let e=f.filter(e=>!e.taskId);return j?e:e.filter(r5)}let e=null!=i?i:[];return j?e:e.filter(e=>!r3(e))},[a,m,f,i,j]),F=(0,o.useMemo)(()=>{for(let e of m?f:null!=i?i:[])if("context"===rB(e)&&e.systemPrompt)return e.systemPrompt;return null},[m,f,i]),P=nG(e=>e.sessionId),D=nG(e=>e.anchor),L=nG(e=>e.cursor),R=nG(e=>e.messages),_=nG(e=>e.loading),z=null!==P&&P===a,O=null!=(t=null==d?void 0:d.archiveCount)?t:0;(0,o.useEffect)(()=>{a&&m&&nq(a,O)},[a,m,O]);let B=(0,o.useMemo)(()=>z?j?R:R.filter(e=>!r3(e)):[],[z,R,j]),W=(0,o.useRef)(!1),H=aD(v,W),K=(0,o.useRef)(null),G=(0,o.useRef)(!0),q=(0,o.useRef)(r),J=(0,o.useRef)(null),Z=(0,o.useRef)(null),V=(0,o.useRef)(!0),Y=(0,o.useRef)(0),X=(0,o.useCallback)(()=>{let e=nG.getState();if(e.sessionId!==a||e.cursor<1||e.loading)return;let t=v.current;K.current=t?t.scrollHeight-t.scrollTop:null,n$()},[a]);return(0,o.useLayoutEffect)(()=>{G.current=!0,K.current=null,V.current=!0,W.current=!1,Y.current=0},[a]),(0,o.useLayoutEffect)(()=>{q.current=r,V.current=!0},[r]),(0,o.useLayoutEffect)(()=>{J.current=m?null:a},[m,a]),(0,o.useLayoutEffect)(()=>{let e=v.current;if(!V.current||!r||!e||c||0===M.length)return;V.current=!1;let t=a&&!m?nY(a):void 0;if(t&&(W.current=!t.atBottom,Y.current=t.scrollOffset),W.current){var n,s;e.scrollTop=(null!=(s=null==(n=Z.current)?void 0:n.offsetTop)?s:0)+Y.current,e.scrollTop<80&&(G.current=!1)}else H()},[a,r,c,M,m]),(0,o.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{var t,r;if(!q.current)return;Y.current=e.scrollTop-(null!=(r=null==(t=Z.current)?void 0:t.offsetTop)?r:0);let n=J.current;n&&function(e,t,r){let n=nJ.get(e);n&&(n.scrollOffset=t,n.atBottom=r)}(n,Y.current,!W.current),e.scrollTop>200?G.current=!0:e.scrollTop<80&&G.current&&(G.current=!1,X())};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[X]),(0,o.useLayoutEffect)(()=>{let e=v.current,t=K.current;e&&null!==t&&(e.scrollTop=e.scrollHeight-t,K.current=null)},[R]),(0,o.useEffect)(()=>{H()},[M,H]),(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3 min-w-0",children:[a?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(oe.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(null==s?void 0:s.agentName)&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-purple-900/50 px-1.5 py-0.5 text-[10px] text-purple-400",children:s.agentName}),(0,l.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",title:(null==s?void 0:s.title)||"Untitled",children:(null==s?void 0:s.title)||"Untitled"}),(0,l.jsxs)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:["(",M.length,")"]}),m&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1.5 py-0.5 text-[8px] text-blue-400",children:"live"}),(null==s?void 0:s.parentSessionId)&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1 py-0.5 text-[8px] text-[var(--muted-foreground)]",title:"Sub-session",children:"sub"}),(null==s?void 0:s.stoppedAt)&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1 py-0.5 text-[8px] text-[var(--muted-foreground)]",children:"stopped"}),(null==s?void 0:s.archivedAt)&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-amber-900/50 px-1 py-0.5 text-[8px] text-amber-400",title:"Archived: ".concat(new Date(s.archivedAt).toLocaleString()),children:"archived"}),(null==s?void 0:s.createdAt)&&(0,l.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",title:"Created: ".concat(new Date(s.createdAt).toLocaleString()),children:(0,U.fw)(s.createdAt)}),(0,l.jsxs)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a).then(()=>{y(!0),setTimeout(()=>y(!1),1200)}).catch(()=>{})},title:"Session ID: ".concat(a),className:"shrink-0 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:[b?(0,l.jsx)(rw.A,{className:"h-2.5 w-2.5 text-green-400"}):(0,l.jsx)(aL.A,{className:"h-2.5 w-2.5"}),a.slice(0,8)]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(ar.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Session Viewer"})]}),a&&(0,l.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[F&&(0,l.jsxs)("button",{onClick:()=>S(!N),className:(0,U.cn)("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",N?"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,l.jsx)(Q.A,{className:"h-3 w-3"}),"Prompt"]}),(0,l.jsxs)("button",{onClick:()=>w(!j),className:(0,U.cn)("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",j?"bg-amber-900/50 text-amber-400":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:"Debug mode: show all messages including sub-agent tool calls",children:[(0,l.jsx)(s2.A,{className:"h-3 w-3"}),"Debug"]})]}),g&&(0,l.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"streaming"})]}),(0,l.jsxs)("div",{ref:v,className:"relative flex-1 overflow-y-auto",children:[N&&F&&(0,l.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,l.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,l.jsx)("span",{className:"text-[10px] font-semibold text-purple-400",children:"System Prompt"}),(0,l.jsx)("button",{onClick:()=>S(!1),title:"Close",className:"rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]}),(0,l.jsx)("pre",{className:"px-3 py-2 text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-words leading-relaxed max-h-[60vh] overflow-y-auto",children:F})]}),c?(0,l.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsx)($.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):a?0===M.length?(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,l.jsx)(ar.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"No messages in this session"})]}):(0,l.jsxs)(l.Fragment,{children:[z&&D>0&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)]/50",children:[L>0?(0,l.jsxs)("button",{onClick:X,disabled:_,className:"flex w-full items-center justify-center gap-1.5 px-3 py-2 text-[10px] font-medium text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:hover:bg-transparent",children:[_&&(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin"}),n(_?"chat.archive.loading":"chat.archive.loadOlder")]}):(0,l.jsx)("div",{className:"px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.noEarlier")}),B.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(aO,{messages:B,debugMode:j,readOnly:!0}),(0,l.jsx)("div",{className:"border-t border-[var(--border)]/50 px-3 py-2 text-center text-[10px] text-[var(--muted-foreground)]",children:n("chat.archive.header",{segments:D-L,messages:B.length})})]})]}),(0,l.jsx)("div",{ref:Z}),(0,l.jsx)(aO,{messages:M,debugMode:j})]}):(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,l.jsx)(ar.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a session from the sidebar to view messages"})]})]})]})}var oa=r(37568),os=r(28976),ol=r(70539),oo=r(29656),oi=r(3546),oc=r(23715),od=r(85615),ou=r(8565);function om(){return(0,l.jsxs)("div",{className:"space-y-8 p-6",children:[(0,l.jsx)(op,{}),(0,l.jsx)(ox,{})]})}function op(){let{t:e}=(0,ts.s9)(),[t,r]=(0,o.useState)(""),[n,a]=(0,o.useState)(""),[s,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(!1),[u,m]=(0,o.useState)(""),[p,x]=(0,o.useState)(!1),f=""!==n?n.length<8?"tooShort":/[A-Za-z]/.test(n)?/[0-9]/.test(n)?null:"needDigit":"needLetter":null,h=""!==n&&n===t,g=""!==s&&s!==n,v=!c&&""!==t&&""!==n&&s===n&&null===f&&!h;async function b(s){if(s.preventDefault(),v){d(!0),m(""),x(!1);try{let e=await fetch("/api/auth/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPassword:t,newPassword:n}),credentials:"include"});if(e.ok)x(!0),r(""),a(""),i("");else{let t=await e.json().catch(()=>null);m((null==t?void 0:t.error)||"HTTP ".concat(e.status))}}catch(t){m(e("security.changePassword.connectionFailed"))}finally{d(!1)}}}return(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.changePassword.title")}),(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.changePassword.desc")})]}),(0,l.jsxs)("form",{onSubmit:b,className:"max-w-md space-y-4 rounded-md border border-[var(--border)] bg-[var(--card)] p-4",children:[(0,l.jsx)(of,{label:e("security.changePassword.current"),value:t,disabled:c,autoComplete:"current-password",onChange:e=>{r(e),x(!1)}}),(0,l.jsx)(of,{label:e("security.changePassword.new"),value:n,disabled:c,autoComplete:"new-password",onChange:e=>{a(e),x(!1)},error:f?e("security.changePassword.".concat(f)):h?e("security.changePassword.sameAsOld"):void 0,hint:e("security.changePassword.rule")}),(0,l.jsx)(of,{label:e("security.changePassword.confirm"),value:s,disabled:c,autoComplete:"new-password",onChange:e=>{i(e),x(!1)},error:g?e("security.changePassword.mismatch"):void 0}),u&&(0,l.jsx)("p",{className:"text-[11px] text-red-400",children:u}),p&&(0,l.jsx)("p",{className:"text-[11px] text-emerald-400",children:e("security.changePassword.success")}),(0,l.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 ox(){let{t:e}=(0,ts.s9)(),[t,r]=(0,o.useState)(!1);async function n(){r(!0);try{await fetch("/api/auth/logout",{method:"POST",credentials:"include"})}catch(e){}window.location.reload()}return(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("security.logout")}),(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("security.logout.desc")})]}),(0,l.jsxs)("button",{onClick:n,disabled:t,className:"flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--card)] px-3 py-1.5 text-xs font-medium text-red-400 transition-colors hover:bg-[var(--secondary)] disabled:opacity-50",children:[(0,l.jsx)(ou.A,{className:"h-3.5 w-3.5"}),e("security.logout")]})]})}function of(e){let{label:t,value:r,disabled:n,autoComplete:a,onChange:s,error:o,hint:i}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:t}),(0,l.jsx)("input",{type:"password",value:r,autoComplete:a,disabled:n,onChange:e=>s(e.target.value),className:(0,U.cn)("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,l.jsx)("p",{className:"mt-0.5 text-[10px] text-red-400",children:o}):i?(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:i}):null]})}function oh(){let{t:e}=(0,ts.s9)(),t=(0,o.useSyncExternalStore)(eb,eC,eC),r=(0,o.useRef)(null),[n,a]=(0,o.useState)(!1),[s,i]=(0,o.useState)(null);async function c(e){a(!0),i(null);try{await k.F.extensions.install(e)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}}async function d(t,r){if(await (0,U.fN)(e("settings.extensions.confirmRemove",{name:r}))){a(!0),i(null);try{await k.F.extensions.remove(t)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}}}let u=0===t.extensions.length&&0===t.errors.length;return(0,l.jsxs)("div",{className:"space-y-6 p-6",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:e("settings.extensions.title")}),(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("settings.extensions.intro")})]}),(0,l.jsx)("input",{ref:r,type:"file",accept:".zip,application/zip",className:"hidden",onChange:e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];e.target.value="",r&&c(r)}}),(0,l.jsxs)("button",{onClick:()=>{var e;return null==(e=r.current)?void 0:e.click()},disabled:n,className:"flex shrink-0 items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90 disabled:opacity-50",children:[(0,l.jsx)(lM.A,{className:"h-3.5 w-3.5"}),n?e("settings.extensions.working"):e("settings.extensions.upload")]})]}),s&&(0,l.jsx)("p",{className:"text-[11px] text-red-400",children:s}),u?(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:e("settings.extensions.empty")}):(0,l.jsxs)("ul",{className:"divide-y divide-[var(--border)] rounded border border-[var(--border)]",children:[t.extensions.map(t=>(0,l.jsxs)("li",{className:"flex items-center gap-3 px-3 py-2",children:[(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,l.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",children:t.name}),(0,l.jsxs)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:[t.id,"@",t.version]}),t.platforms&&(0,l.jsx)("span",{className:"shrink-0 rounded border border-[var(--border)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:eT(t.platforms,e)}),!eM(t)&&(0,l.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:e("settings.extensions.unsupportedHere")})]}),(0,l.jsxs)("p",{className:"mt-0.5 truncate text-[10px] text-[var(--muted-foreground)]",children:[t.extensions.join(" "),"option"===t.priority&&" \xb7 ".concat(e("settings.extensions.optionOnly")),t.bundle&&" \xb7 ".concat(e("settings.extensions.bundle")),t.capabilities.includes("save")&&" \xb7 ".concat(e("settings.extensions.canSave")),t.capabilities.includes("media")&&" \xb7 ".concat(e("settings.extensions.media")),t.capabilities.includes("fs-read")&&" \xb7 ".concat(e("settings.extensions.fsRead")),t.description&&" — ".concat(t.description)]})]}),(0,l.jsx)(og,{disabled:n,onClick:()=>d(t.id,t.name),label:e("settings.extensions.remove")})]},t.id)),t.errors.map(t=>(0,l.jsxs)("li",{className:"flex items-center gap-3 px-3 py-2",children:[(0,l.jsx)(aR.A,{className:"h-3.5 w-3.5 shrink-0 text-red-400"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsx)("code",{className:"text-xs text-red-400",children:t.id}),(0,l.jsx)("p",{className:"mt-0.5 truncate text-[10px] text-[var(--muted-foreground)]",children:t.error})]}),(0,l.jsx)(og,{disabled:n,onClick:()=>d(t.id,t.id),label:e("settings.extensions.remove")})]},t.id))]})]})}function og(e){let{disabled:t,onClick:r,label:n}=e;return(0,l.jsxs)("button",{onClick:r,disabled:t,className:"flex shrink-0 cursor-pointer items-center gap-1 rounded px-2 py-0.5 text-[10px] text-red-400 hover:bg-red-500/10 hover:text-red-300 disabled:opacity-50",children:[(0,l.jsx)(eQ.A,{className:"h-3 w-3"}),n]})}function ov(){var e,t,r;let{t:n,refreshFromServer:a}=(0,ts.s9)(),{refreshFromServer:s}=(0,e8.useTheme)(),i=rT(e=>e.activeProject),[c,d]=(0,o.useState)("global"),[u,m]=(0,o.useState)(null),[p,x]=(0,o.useState)("general"),[f,h]=(0,o.useState)(!1),[g,v]=(0,o.useState)(!1),[b,y]=(0,o.useState)(null),[j,w]=(0,o.useState)([]),N="workspace"===c?null==i?void 0:i.path:void 0,S=(0,o.useCallback)(()=>{v(!0),k.F.settings.getSchema(N).then(e=>{m(e),x(t=>"__orphans"===t||"__security"===t||"__extensions"===t||e.sections.find(e=>e.namespaceId===t)?t:"general")}).catch(e=>{console.error("[Settings] schema load failed:",e)}).finally(()=>v(!1))},[N]),C=so(e=>e.version),A=(0,o.useSyncExternalStore)(eb,eC,eC);function I(e,t){e.restartRequired&&w(e=>e.includes(t)?e:[...e,t])}async function E(e,t,r){h(!0);try{let n="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);if(""===r)await k.F.settings.remove(c,n,N);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 k.F.settings.patch(c,n,e,N)}I(t,n),S(),a(),s()}catch(e){console.error("[Settings] save failed:",e)}finally{h(!1)}}async function T(e,t){h(!0);try{let r="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);await k.F.settings.remove(c,r,N),I(t,r),S(),a(),s()}catch(e){console.error("[Settings] reset failed:",e)}finally{h(!1)}}async function M(e){let t="".concat(e.namespaceId,".").concat(e.kind,"s.").concat(e.key);if(confirm(n("settings.orphans.confirm",{key:t}))){h(!0);try{await k.F.settings.remove(c,t,N),S()}catch(e){console.error("[Settings] orphan remove failed:",e)}finally{h(!1)}}}(0,o.useEffect)(()=>{S()},[S,C,A]),(0,o.useEffect)(()=>{k.F.health().then(e=>y("string"==typeof(null==e?void 0:e.version)?e.version:null)).catch(()=>y(null))},[]);let F=null!=(e=null==u?void 0:u.sections)?e:[],P=null!=(t=null==u?void 0:u.orphans)?t:[],D=(0,o.useMemo)(()=>F.find(e=>e.namespaceId===p),[F,p]);return(0,l.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex w-[220px] shrink-0 flex-col border-r border-[var(--border)]",children:[(0,l.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(oa.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:n("nav.settings")}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onClick:S,disabled:g,title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",children:(0,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",g&&"animate-spin")})})]}),(0,l.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,l.jsxs)("div",{className:"border-b border-[var(--border)] p-2",children:[(0,l.jsxs)("div",{className:"flex rounded-md bg-[var(--card)] p-0.5",children:[(0,l.jsxs)("button",{onClick:()=>d("global"),className:(0,U.cn)("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,l.jsx)(V.A,{className:"h-3 w-3"}),n("common.global")]}),(0,l.jsxs)("button",{onClick:()=>d("workspace"),disabled:!i,className:(0,U.cn)("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,l.jsx)(os.A,{className:"h-3 w-3"}),n("common.workspace")]})]}),"workspace"===c&&i&&(0,l.jsx)("p",{className:"mt-1 truncate text-[9px] text-[var(--muted-foreground)]",children:i.path})]}),(0,l.jsx)(ob,{sections:F,orphans:P,active:p,onPick:x})]}),b&&(0,l.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,l.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,l.jsx)("div",{className:"flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-4",children:(0,l.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"__security"===p?(0,l.jsxs)(l.Fragment,{children:["~/.halo/secrets/config.yaml → ",(0,l.jsx)("code",{className:"text-[var(--foreground)]",children:"server.password"})]}):"__extensions"===p?(0,l.jsx)(l.Fragment,{children:"~/.halo/global/extensions/"}):(0,l.jsxs)(l.Fragment,{children:["global"===c?"~/.halo/secrets/settings.yaml":"".concat(null!=(r=null==i?void 0:i.path)?r:"...","/.halo/settings.yaml")," ","→ ",(0,l.jsx)("code",{className:"text-[var(--foreground)]",children:p})]})})}),j.length>0&&(0,l.jsxs)("div",{className:"flex shrink-0 items-start gap-2 border-b border-amber-500/30 bg-amber-500/10 px-4 py-2 text-[11px] text-amber-400",children:[(0,l.jsx)(aR.A,{className:"mt-px h-3.5 w-3.5 shrink-0"}),(0,l.jsx)("span",{className:"min-w-0 flex-1 break-words",children:n("settings.restartNotice",{keys:j.join(", ")})}),(0,l.jsx)("button",{onClick:()=>w([]),title:n("settings.restartNotice.dismiss"),className:"shrink-0 cursor-pointer rounded p-0.5 hover:bg-amber-500/20",children:(0,l.jsx)(tM.A,{className:"h-3 w-3"})})]}),(0,l.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:"__security"===p?(0,l.jsx)(om,{}):"__extensions"===p?(0,l.jsx)(oh,{}):"__orphans"===p?(0,l.jsx)(oM,{orphans:P,onRemove:M,saving:f}):D?(0,l.jsx)(oN,{section:D,scope:c,saving:f,onSave:(e,t)=>E(D.namespaceId,e,t),onReset:e=>T(D.namespaceId,e)}):(0,l.jsx)("div",{className:"p-10 text-center text-xs text-[var(--muted-foreground)]",children:u?n("settings.empty"):n("settings.loading")})})]})]})}function ob(e){let{sections:t,orphans:r,active:n,onPick:a}=e,{t:s}=(0,ts.s9)(),i=(0,o.useMemo)(()=>{let e=t.filter(e=>"general"===e.source),r=t.filter(e=>"provider"===e.source),n=t.filter(e=>"skill"===e.source);return{general:e,providers:r,skills:n,agents:t.filter(e=>"agent"===e.source),extensions:t.filter(e=>"extension"===e.source)}},[t]),[c,d]=function(){let[e,t]=(0,o.useState)(()=>{try{var e;return new Set(JSON.parse(null!=(e=localStorage.getItem(oy))?e:"[]"))}catch(e){return new Set}});return[e,(0,o.useCallback)(e=>{t(t=>{let r=new Set(t);return r.delete(e)||r.add(e),localStorage.setItem(oy,JSON.stringify([...r])),r})},[])]}(),u=(e,t)=>({label:t,collapsed:c.has(e),onToggle:()=>d(e)});return(0,l.jsxs)("div",{className:"py-1",children:[(0,l.jsxs)(ow,{...u("system",s("settings.nav.system")),items:i.general,icons:{general:ol.A},active:n,onPick:a,children:[(0,l.jsxs)(oj,{active:"__security"===n,onClick:()=>a("__security"),children:[(0,l.jsx)(oo.A,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{children:s("settings.nav.security")})]}),(0,l.jsxs)(oj,{active:"__extensions"===n,onClick:()=>a("__extensions"),children:[(0,l.jsx)(oi.A,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{children:s("settings.nav.extensions")})]})]}),(0,l.jsx)(ow,{...u("extensions",s("settings.nav.extensionSettings")),items:i.extensions,active:n,onPick:a}),(0,l.jsx)(ow,{...u("providers",s("settings.nav.providers")),items:i.providers,active:n,onPick:a}),(0,l.jsx)(ow,{...u("agents",s("settings.nav.agents")),items:i.agents,active:n,onPick:a}),(0,l.jsx)(ow,{...u("skills",s("settings.nav.skills")),items:i.skills,active:n,onPick:a}),r.length>0&&(0,l.jsx)(ow,{...u("orphans",s("settings.nav.orphans")),items:[],active:n,onPick:a,children:(0,l.jsxs)(oj,{active:"__orphans"===n,onClick:()=>a("__orphans"),children:[(0,l.jsx)(eQ.A,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{children:s("settings.nav.unclaimed")}),(0,l.jsx)("span",{className:"ml-auto rounded bg-[var(--card)] px-1 py-0 text-[9px]",children:r.length})]})})]})}let oy="halo_settings_navCollapsed";function oj(e){let{active:t,onClick:r,title:n,children:a}=e;return(0,l.jsx)("button",{onClick:r,title:n,className:(0,U.cn)("flex w-full cursor-pointer items-center gap-2 py-1.5 pl-6 pr-3 text-[11px] transition-colors",t?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:a})}function ow(e){let{label:t,items:r,icons:n,active:a,onPick:s,collapsed:o,onToggle:i,children:c}=e,{lang:d}=(0,ts.s9)();return 0!==r.length||c?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("button",{onClick:i,"aria-expanded":!o,className:"flex w-full cursor-pointer items-center gap-1 px-2 pb-1 pt-2.5 text-[10px] font-medium tracking-wide text-[var(--muted-foreground)] transition-colors hover:text-[var(--foreground)]",children:[(0,l.jsx)(K.A,{className:(0,U.cn)("h-3 w-3 shrink-0 transition-transform",!o&&"rotate-90")}),(0,l.jsx)("span",{className:"truncate",children:t})]}),!o&&r.map(e=>{let t="zh"===d&&e.displayName_zh||e.displayName,r="zh"===d&&e.description_zh||e.description,o=null==n?void 0:n[e.namespaceId];return(0,l.jsxs)(oj,{active:a===e.namespaceId,onClick:()=>s(e.namespaceId),title:null!=r?r:e.namespaceId,children:[o&&(0,l.jsx)(o,{className:"h-3 w-3 shrink-0"}),(0,l.jsx)("span",{className:"truncate",children:t})]},e.namespaceId)}),!o&&c]}):null}function oN(e){let{section:t,scope:r,saving:n,onSave:a,onReset:s}=e,{t:i,lang:c}=(0,ts.s9)(),[d,u]=(0,o.useState)(!1),m=t.fields.filter(e=>"param"===e.kind),p=m.filter(e=>!e.advanced),x=m.filter(e=>e.advanced),f=t.fields.filter(e=>"secret"===e.kind),h=e=>(0,l.jsx)(ok,{namespaceId:t.namespaceId,field:e,scope:r,saving:n,onSave:t=>a(e,t),onReset:()=>s(e)},e.key),g="zh"===c&&t.displayName_zh||t.displayName,v="zh"===c&&t.description_zh||t.description,[b,y]=i("settings.section.secretsHint",{placeholder:"\0"}).split("\0");return(0,l.jsxs)("div",{className:"space-y-6 p-6",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:g}),v&&(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:v}),(0,l.jsxs)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:[i("settings.section.namespace"),": ",(0,l.jsx)("code",{className:"text-[var(--foreground)]",children:t.namespaceId})," \xb7 ",i("settings.section.declaredBy"),": ",(0,l.jsx)("span",{children:i("settings.section.declaredBy.".concat(t.source))})]})]}),m.length>0&&(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:i("general"===t.namespaceId?"settings.section.settings":"settings.section.params")}),p.map(h),x.length>0&&(0,l.jsxs)("div",{className:"space-y-4 border-t border-[var(--border)] pt-3",children:[(0,l.jsxs)("button",{onClick:()=>u(e=>!e),className:"flex cursor-pointer items-center gap-1 text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[(0,l.jsx)(K.A,{className:(0,U.cn)("h-3 w-3 transition-transform",d&&"rotate-90")}),i("settings.section.advanced"),(0,l.jsx)("span",{className:"rounded bg-[var(--card)] px-1 py-0 text-[9px] font-normal normal-case",children:x.length})]}),d&&x.map(h)]})]}),f.length>0&&(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:i("settings.section.secrets")}),(0,l.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[b,(0,l.jsx)("code",{className:"rounded bg-[var(--card)] px-1 py-0.5",children:"<<ENV_NAME>>"}),y]}),f.map(h)]})]})}function ok(e){var t,r;let{namespaceId:n,field:a,scope:s,saving:o,onSave:i,onReset:c}=e,{lang:d,t:u}=(0,ts.s9)(),m="zh"===d&&a.description_zh||a.description||"",p="general"===n?"general.".concat(a.key):"".concat(n,".").concat(a.kind,"s.").concat(a.key),x="workspace"===s&&a.inheritedFromGlobal,f="workspace"===s&&!0===a.globalOnly,h=!f&&a.source===s&&("workspace"===s||(null!=(t=a.value)?t:"")!==(null!=(r=a.default)?r:""));return(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:a.key}),(0,l.jsx)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:p}),(0,l.jsx)(oS,{source:a.source,inherited:x}),a.globalOnly&&(0,l.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"}),h&&(0,l.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"===s?"settings.field.resetTitleWorkspace":"settings.field.resetTitleGlobal"),children:[(0,l.jsx)(oc.A,{className:"h-2.5 w-2.5"}),u("settings.field.reset")]})]}),m&&(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:m}),(0,l.jsx)("div",{className:(0,U.cn)("mt-1.5",f&&"opacity-60 pointer-events-none"),children:function(e,t,r){var n,a,s,o,i,c,d,u;if(e.secret)return(0,l.jsx)(oT,{initial:null!=(n=e.value)?n:"",placeholder:null!=(a=e.default)?a:"",saving:t,onCommit:r});switch(e.type){case"int":case"float":return(0,l.jsx)(oA,{initial:null!=(s=e.value)?s:"",placeholder:null!=(o=e.default)?o:"",type:"number",step:"int"===e.type?1:.1,saving:t,onCommit:r});case"boolean":return(0,l.jsx)(oI,{value:e.value,saving:t,onCommit:r});case"enum":return(0,l.jsx)(oE,{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,l.jsx)(oA,{initial:null!=(d=e.value)?d:"",placeholder:null!=(u=e.default)?u:"",saving:t,onCommit:r})}}(a,o||f,i)})]})}function oS(e){let{source:t,inherited:r}=e,{t:n}=(0,ts.s9)();return(0,l.jsx)("span",{className:(0,U.cn)("rounded px-1.5 py-0 text-[9px] font-medium",{workspace:"bg-blue-500/20 text-blue-300",global:r?"bg-[var(--secondary)] text-[var(--muted-foreground)]":"bg-emerald-500/20 text-emerald-300",unset:"bg-[var(--secondary)] text-[var(--muted-foreground)] opacity-60"}[t]),children:n("unset"===t?"settings.source.unset":r?"settings.source.inherited":"settings.source.".concat(t))})}let oC=/^<<[A-Z_][A-Z0-9_]*>>$/;function oA(e){let{initial:t,placeholder:r,type:n="text",step:a,saving:s,onCommit:i}=e,c=""===t&&!!r,[d,u]=(0,o.useState)(t),[m,p]=(0,o.useState)(!1),x=(0,o.useRef)(t);function f(){p(!1),d!==x.current&&(x.current=d,i(d))}(0,o.useEffect)(()=>{u(t),x.current=t,p(!1)},[t]);let h=c&&!m?null!=r?r:"":d;return(0,l.jsx)("input",{type:n,step:a,value:h,placeholder:r,onFocus:()=>{c&&u(""),p(!0)},onChange:e=>{u(e.target.value),p(!0)},onBlur:f,onKeyDown:e=>{"Enter"===e.key&&f()},disabled:s,className:(0,U.cn)("h-7 w-full max-w-md rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs outline-none focus:border-[var(--primary)]",c&&!m?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function oI(e){let{value:t,saving:r,onCommit:n}=e,a="true"===t||"1"===t;return(0,l.jsxs)("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[(0,l.jsx)("input",{type:"checkbox",checked:a,disabled:r,onChange:e=>n(e.target.checked?"true":"false"),className:"h-3.5 w-3.5 cursor-pointer rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)]"}),(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a?"on":"off"})]})}function oE(e){var t,r;let{value:n,options:a,optionLabels:s,placeholder:o,saving:i,onCommit:c}=e,d=null!=(r=null!=(t=null!=n?n:o)?t:a[0])?r:"";return(0,l.jsx)("select",{value:d,disabled:i,onChange:e=>c(e.target.value),className:"h-7 w-full max-w-md cursor-pointer rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]",children:a.map((e,t)=>{var r;return(0,l.jsx)("option",{value:e,children:null!=(r=null==s?void 0:s[t])?r:e},e)})})}function oT(e){let{initial:t,placeholder:r,saving:n,onCommit:a}=e,s=oC.test(t),[i,c]=(0,o.useState)(t),[d,u]=(0,o.useState)(!1),[m,p]=(0,o.useState)(s),x=(0,o.useRef)(t);function f(){if(d){if(i===x.current)return void u(!1);x.current=i,a(i),u(!1)}}return(0,o.useEffect)(()=>{c(t),x.current=t,u(!1),p(oC.test(t))},[t]),(0,l.jsxs)("div",{className:"relative w-full max-w-md",children:[(0,l.jsx)("input",{type:m||d?"text":"password",value:d?i:t||"",placeholder:r,onFocus:()=>{d||!t||oC.test(t)||c(""),u(!0)},onChange:e=>c(e.target.value),onBlur:f,onKeyDown:e=>{"Enter"===e.key&&f()},disabled:n,className:"h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 pr-7 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),!s&&(0,l.jsx)("button",{type:"button",onClick:()=>p(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,l.jsx)(od.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(tF.A,{className:"h-3.5 w-3.5"})})]})}function oM(e){let{orphans:t,onRemove:r,saving:n}=e,{t:a}=(0,ts.s9)(),s=(0,o.useMemo)(()=>{let e=new Map;for(let n of t){var r;let t=null!=(r=e.get(n.namespaceId))?r:[];t.push(n),e.set(n.namespaceId,t)}return Array.from(e.entries())},[t]);return 0===t.length?null:(0,l.jsxs)("div",{className:"space-y-6 p-6",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:a("settings.orphans.title")}),(0,l.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:a("settings.orphans.intro")})]}),s.map(e=>{let[t,s]=e;return(0,l.jsxs)("div",{className:"space-y-2 rounded border border-[var(--border)] p-3",children:[(0,l.jsx)("h3",{className:"text-[11px] font-semibold text-[var(--foreground)]",children:t}),(0,l.jsx)("ul",{className:"space-y-1",children:s.map(e=>(0,l.jsxs)("li",{className:"flex items-center justify-between text-[11px]",children:[(0,l.jsxs)("code",{className:"text-[var(--muted-foreground)]",children:[t,".",e.kind,"s.",e.key]}),(0,l.jsxs)("button",{onClick:()=>r(e),disabled:n,className:"flex cursor-pointer items-center gap-1 rounded px-2 py-0.5 text-[10px] text-red-400 hover:bg-red-500/10 hover:text-red-300",children:[(0,l.jsx)(eQ.A,{className:"h-3 w-3"}),a("settings.orphans.remove")]})]},"".concat(e.kind,".").concat(e.key)))})]},t)})]})}var oF=r(84064);let oP=n5(),oD=oP.useBus,oL=oP.bump;var oR=r(89918),o_=r(27269),oz=r(78547),oO=r(45211),oU=r(35622);function oB(e,t){return(0,U.cn)(e?"mt-0.5":"mt-1","w-full rounded border border-[var(--border)] bg-[var(--card)] px-2",e?"py-1":"py-1.5",t&&"font-mono","text-xs")}function oW(e){return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:(0,U.cn)(e.compact?"text-[10px]":"text-[11px]","text-[var(--muted-foreground)]"),children:e.label}),e.children,e.hint&&(0,l.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:e.hint})]})}function oH(e){return(0,l.jsx)("input",{type:e.type,value:e.value,onChange:t=>e.onChange(t.target.value),className:oB(e.compact,e.mono),placeholder:e.placeholder})}function oK(e){let t=(0,ts.kj)(),{ns:r}=e;return(0,l.jsxs)("select",{value:e.value,onChange:t=>e.onChange(t.target.value),className:oB(e.compact),children:[(0,l.jsx)("option",{value:"readonly",children:t("".concat(r,".readonly"))}),e.observer?(0,l.jsx)("option",{value:"observer",children:t("".concat(r,".observer"))}):"observer"===e.value&&(0,l.jsx)("option",{value:"observer",disabled:!0,children:t("channels.observerAdminOnly")}),(0,l.jsx)("option",{value:"workspace",children:t("".concat(r,".wsWrite"))}),(0,l.jsx)("option",{value:"full",children:t("".concat(r,".full"))})]})}function oG(e){return(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:e.onClose,children:(0,l.jsxs)("div",{className:(0,U.cn)(e.width,"max-h-[90vh] overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl"),onClick:e=>e.stopPropagation(),children:[e.title&&(0,l.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,l.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:e.title}),(0,l.jsx)("button",{onClick:e.onClose,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),e.children]})})}function oq(e){let t=(0,ts.kj)(),{ns:r,value:n,onChange:a}=e;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(oW,{label:t("".concat(r,".bindWorkspace")),hint:e.workspaceHint,children:(0,l.jsx)(oH,{mono:!0,value:n.workspacePath,onChange:e=>a({workspacePath:e}),placeholder:"/home/user/project"})}),(0,l.jsx)(oW,{label:t("".concat(r,".nameOptional")),children:(0,l.jsx)(oH,{value:n.label,onChange:e=>a({label:e}),placeholder:t("".concat(r,".namePlaceholder"))})}),(0,l.jsx)(oW,{label:t("".concat(r,".accessLevel")),hint:e.accessHint,children:(0,l.jsx)(oK,{ns:r,value:n.accessLevel,onChange:e=>a({accessLevel:e}),observer:e.observer})}),(0,l.jsx)(ts.pZ,{value:n.language,onChange:e=>a({language:e})})]})}function o$(e){let t=(0,ts.kj)(),{lang:r}=(0,ts.s9)(),{ns:n,onClose:a,canSubmit:s=!0}=e,i=rT(e=>e.activeProject),[c,d]=(0,o.useState)({workspacePath:(null==i?void 0:i.path)||"",label:"",accessLevel:"readonly",language:r}),[u,m]=(0,o.useState)(!1),[p,x]=(0,o.useState)("");async function f(){x(""),m(!0);try{e.onDone(await e.create({...c,label:c.label||void 0}))}catch(e){x(e instanceof Error?e.message:String(e))}finally{m(!1)}}return(0,l.jsx)(oG,{width:e.width,title:t("".concat(n,".addTitle")),onClose:a,children:(0,l.jsxs)("div",{className:"space-y-3",children:[e.children,(0,l.jsx)(oq,{ns:n,value:c,onChange:e=>d(t=>({...t,...e})),observer:e.observer}),e.extraFields,p&&(0,l.jsx)("p",{className:"text-xs text-red-400",children:p}),(0,l.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,l.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("".concat(n,".cancel"))}),(0,l.jsxs)("button",{onClick:f,disabled:u||!s||!(0,U.Z1)(c.workspacePath),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[u&&(0,l.jsx)($.A,{className:"h-3 w-3 animate-spin"}),t("".concat(n,".addBtn"))]})]})]})})}function oJ(e,t){let[r,n]=(0,o.useState)([]),[a,s]=(0,o.useState)(!0),l=(0,o.useCallback)(()=>{s(!0),t().then(e=>n(e.accounts)).catch(t=>{console.error("[".concat(e,"] list failed:"),t)}).finally(()=>s(!1))},[e,t]);(0,o.useEffect)(()=>{l()},[l]);let i=oD(e=>e.version);return(0,o.useEffect)(()=>{i>0&&l()},[i,l]),{accounts:r,loading:a,reload:l}}function oZ(e){let t=(0,ts.kj)(),{ns:r,accounts:n,loading:a,reload:s}=e,[i,c]=(0,o.useState)(null);return(0,l.jsxs)("div",{className:"flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:t("".concat(r,".title"))}),(0,l.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("".concat(r,".desc"))})]}),(0,l.jsxs)("button",{onClick:e.onAdd,className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,l.jsx)(sG.A,{className:"h-3.5 w-3.5"}),t("".concat(r,".add"))]})]}),(0,l.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,l.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsx)($.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),t("".concat(r,".loading"))]}):0===n.length?(0,l.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:t("".concat(r,".empty"))}):(0,l.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:n.map(t=>(0,l.jsx)(o.Fragment,{children:e.renderRow(t,{editing:i===t.accountId,onEdit:()=>c(t.accountId),onCancelEdit:()=>c(null),onSaved:()=>{c(null),s()},onChanged:s})},t.accountId))})}),e.children]})}function oV(e){let t=e.icon;return(0,l.jsx)("button",{onClick:e.onClick,disabled:e.disabled,title:e.title,className:(0,U.cn)("rounded p-1.5 text-[var(--muted-foreground)]",e.danger?"hover:bg-red-500/20 hover:text-red-400":"hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(t,{className:"h-3.5 w-3.5"})})}let oY={readonly:{text:"Readonly",className:"bg-emerald-500/15 text-emerald-300"},observer:{text:"Observer",className:"bg-teal-500/15 text-teal-300"},workspace:{text:"Workspace",className:"bg-blue-500/15 text-blue-300"},full:{text:"Full",className:"bg-amber-500/15 text-amber-300"}};function oQ(e){return e instanceof Error?e.message:String(e)}function oX(e){var t;let r=(0,ts.kj)(),{ns:n,account:a,onEdit:s,onChanged:i}=e,[c,d]=(0,o.useState)(!1);if(e.editing)return(0,l.jsx)(o0,{...e});async function u(e,t){d(!0);try{await e(),i()}catch(e){alert(r("".concat(n,".").concat(t),{error:oQ(e)}))}finally{d(!1)}}async function m(){var t;await (0,U.fN)(r("".concat(n,".confirmDelete"),{name:null!=(t=e.deleteName)?t:""}))&&await u(e.remove,"deleteFailed")}let p=oY[a.accessLevel];return(0,l.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,l.jsx)("div",{className:(0,U.cn)("h-2 w-2 rounded-full",a.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:e.title}),(0,l.jsx)("span",{className:(0,U.cn)("rounded px-1.5 py-0.5 text-[9px] font-medium",p.className),children:p.text}),e.titleExtra]}),(0,l.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:[e.detail,e.workspaceMissing&&(0,l.jsx)("span",{className:"ml-1 text-red-400",children:r("".concat(n,".pathMissing"))})]}),e.footer]}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)(oV,{onClick:()=>u(()=>e.setEnabled(!a.enabled),"switchFailed"),disabled:c,title:a.enabled?r("".concat(n,".disable")):r("".concat(n,".enable")),icon:a.enabled?oz.A:oO.A}),null==(t=e.actions)?void 0:t.call(e,c),(0,l.jsx)(oV,{onClick:s,disabled:c,title:r("".concat(n,".edit")),icon:oU.A}),(0,l.jsx)(oV,{onClick:m,disabled:c,title:r("".concat(n,".delete")),icon:eQ.A,danger:!0})]})]})}function o0(e){var t;let r=(0,ts.kj)(),{ns:n,account:a}=e,s=()=>({label:a.label,workspacePath:a.workspacePath,accessLevel:a.accessLevel,language:a.language||"en",...e.extraDraft}),[i,c]=(0,o.useState)(s),[d,u]=(0,o.useState)(a);d!==a&&(u(a),c(s()));let[m,p]=(0,o.useState)(!1),x=e=>c(t=>({...t,...e}));async function f(){p(!0);let{accessLevel:t,...a}=i;try{await e.save("observer"===t&&!e.observer?a:i),e.onSaved()}catch(e){alert(r("".concat(n,".saveFailed"),{error:oQ(e)}))}finally{p(!1)}}return(0,l.jsx)("li",{className:"px-4 py-3",children:(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsx)(oW,{compact:!0,label:r("".concat(n,".label")),children:(0,l.jsx)(oH,{compact:!0,value:i.label,onChange:e=>x({label:e}),placeholder:r("".concat(n,".labelPlaceholder"))})}),(0,l.jsx)(oW,{compact:!0,label:r("".concat(n,".workspace")),children:(0,l.jsx)(oH,{compact:!0,mono:!0,value:i.workspacePath,onChange:e=>x({workspacePath:e}),placeholder:"/home/user/project"})}),(0,l.jsx)(oW,{compact:!0,label:r("".concat(n,".accessLevel")),hint:e.accessHint,children:(0,l.jsx)(oK,{compact:!0,ns:n,value:i.accessLevel,onChange:e=>x({accessLevel:e}),observer:e.observer})}),(0,l.jsx)(ts.pZ,{value:i.language,onChange:e=>x({language:e})}),null==(t=e.editExtra)?void 0:t.call(e,i,e=>c(t=>({...t,...e}))),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsxs)("button",{onClick:f,disabled:m||!(0,U.Z1)(i.workspacePath),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,l.jsx)(rw.A,{className:"h-3 w-3"})," ",r("".concat(n,".save"))]}),(0,l.jsxs)("button",{onClick:e.onCancelEdit,disabled:m,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,l.jsx)(tM.A,{className:"h-3 w-3"})," ",r("".concat(n,".cancel"))]})]})]})})}function o1(e){let t=(0,ts.kj)(),{intent:r,onClose:n,onDone:a}=e,s=rT(e=>e.activeProject),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(null),[m,p]=(0,o.useState)("loading"),[x,f]=(0,o.useState)(t("wx.generatingQr")),[h,g]=(0,o.useState)({workspacePath:r.workspacePath||(null==s?void 0:s.path)||"",label:r.label||"",accessLevel:r.accessLevel,language:r.language}),{workspacePath:v,label:b,accessLevel:y,language:j}=h,[w,N]=(0,o.useState)(r.skipConfig?"scan":"config"),S=(0,o.useRef)(!1),C=r.skipConfig;async function A(){if(!(0,U.Z1)(v))return void f(t("wx.pathRequired"));N("scan"),p("loading"),f(t("wx.generatingQr"));try{let{qrcodeUrl:r,sessionKey:n}=await k.F.wechat.startLogin();if(S.current)return;if(!r){p("error"),f(t("wx.qrFailed"));return}c(n);let s=await oR.toDataURL(r,{width:256,margin:2});if(S.current)return;u(s),p("waiting"),f(t("wx.scanPrompt"));let l=await k.F.wechat.waitLogin({sessionKey:n,workspacePath:v,label:b||void 0,accessLevel:y,language:j});if(S.current)return;if(l.connected){var e;p("success"),f(t("wx.connected",{id:null!=(e=l.accountId)?e:""})),setTimeout(a,1200)}else p("error"),f(l.message||t("wx.loginFailed"))}catch(e){if(S.current)return;p("error"),f(e instanceof Error?e.message:String(e))}}return(0,o.useEffect)(()=>()=>{S.current=!0},[]),(0,o.useEffect)(()=>{r.skipConfig&&A()},[]),(0,l.jsxs)(oG,{width:"w-[400px]",title:C?t("wx.rescanBtn"):t("wx.addTitle"),onClose:n,children:["config"===w?(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsx)(oq,{ns:"wx",value:h,onChange:e=>g(t=>({...t,...e})),workspaceHint:t("wx.bindHint"),accessHint:t("wx.readonlyShareHint")}),(0,l.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,l.jsx)("button",{onClick:n,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.cancel")}),(0,l.jsx)("button",{onClick:A,disabled:!(0,U.Z1)(v),className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:t("wx.nextStep")})]})]}):(0,l.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[d?(0,l.jsx)("img",{src:d,alt:t("wx.scanTitle"),className:"rounded border border-[var(--border)]"}):(0,l.jsx)("div",{className:"flex h-64 w-64 items-center justify-center rounded border border-[var(--border)] bg-[var(--card)]",children:(0,l.jsx)($.A,{className:"h-6 w-6 animate-spin text-[var(--muted-foreground)]"})}),(0,l.jsx)("p",{className:(0,U.cn)("text-center text-xs","success"===m&&"text-emerald-400","error"===m&&"text-red-400","success"!==m&&"error"!==m&&"text-[var(--muted-foreground)]"),children:x}),(0,l.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[t("wx.bindTo")," ",(0,l.jsx)("code",{className:"text-[var(--foreground)]",children:v})]}),"error"===m&&(0,l.jsx)("button",{onClick:()=>{N("config")},className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.restart")})]}),i&&(0,l.jsx)("input",{type:"hidden",value:i,readOnly:!0})]})}let o3={id:"wechat",label:"channels.wechat",Icon:oF.A,Component:function(){let e=(0,ts.kj)(),{lang:t}=(0,ts.s9)(),{accounts:r,loading:n,reload:a}=oJ("wechat",k.F.wechat.listAccounts),[s,i]=(0,o.useState)(null);return(0,l.jsx)(oZ,{ns:"wx",accounts:r,loading:n,reload:a,onAdd:()=>i({workspacePath:"",label:"",accessLevel:"readonly",language:t,skipConfig:!1}),renderRow:(t,r)=>(0,l.jsx)(oX,{...r,ns:"wx",account:t,title:t.label||t.accountId,deleteName:t.label,titleExtra:(0,l.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:t.accountId}),detail:t.workspacePath,workspaceMissing:t.workspaceMissing,accessHint:e("wx.readonlyHint"),actions:r=>(0,l.jsx)(oV,{onClick:()=>i({workspacePath:t.workspacePath,label:t.label,accessLevel:t.accessLevel,language:t.language,skipConfig:!0}),disabled:r,title:e("wx.rescan"),icon:o_.A}),save:e=>k.F.wechat.updateAccount(t.accountId,e),setEnabled:e=>k.F.wechat.updateAccount(t.accountId,{enabled:e}),remove:()=>k.F.wechat.deleteAccount(t.accountId)}),children:s&&(0,l.jsx)(o1,{intent:s,onClose:()=>i(null),onDone:()=>{i(null),a()}})})}};function o5(e){let t=(0,ts.kj)(),[r,n]=(0,o.useState)(""),[a,s]=(0,o.useState)("");return(0,l.jsx)(o$,{ns:"tg",width:"w-[420px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim(),create:e=>k.F.telegram.createAccount({botToken:r,...e,allowedUsers:a||void 0}),extraFields:(0,l.jsx)(oW,{label:t("tg.allowedUsersOptional"),children:(0,l.jsx)(oH,{mono:!0,value:a,onChange:s,placeholder:t("tg.allowedUsersHint")})}),children:(0,l.jsx)(oW,{label:t("tg.tokenLabel"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:r,onChange:n,placeholder:"123456:ABC-DEF..."})})})}let o2={id:"telegram",label:"Telegram",Icon:ss.A,Component:function(){let e=(0,ts.kj)(),{accounts:t,loading:r,reload:n}=oJ("telegram",k.F.telegram.listAccounts),[a,s]=(0,o.useState)(!1);return(0,l.jsx)(oZ,{ns:"tg",accounts:t,loading:r,reload:n,onAdd:()=>s(!0),renderRow:(t,r)=>(0,l.jsx)(oX,{...r,ns:"tg",account:t,title:t.label||"@".concat(t.botUsername),deleteName:t.botUsername,titleExtra:t.allowedUsers&&(0,l.jsx)("span",{className:"rounded bg-blue-500/15 px-1.5 py-0.5 text-[9px] font-medium text-blue-300",children:e("tg.whitelist")}),detail:(0,l.jsxs)(l.Fragment,{children:["@",t.botUsername," → ",t.workspacePath]}),workspaceMissing:t.workspaceMissing,extraDraft:{allowedUsers:t.allowedUsers},editExtra:(t,r)=>(0,l.jsx)(oW,{compact:!0,label:e("tg.allowedUsers"),children:(0,l.jsx)(oH,{compact:!0,mono:!0,value:t.allowedUsers,onChange:e=>r({allowedUsers:e}),placeholder:"123456789,@username"})}),save:e=>k.F.telegram.updateAccount(t.accountId,e),setEnabled:e=>k.F.telegram.updateAccount(t.accountId,{enabled:e}),remove:()=>k.F.telegram.deleteAccount(t.accountId)}),children:a&&(0,l.jsx)(o5,{onClose:()=>s(!1),onDone:()=>{s(!1),n()}})})}};function o4(e){let t=(0,ts.kj)(),[r,n]=(0,o.useState)(!1);return(0,l.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[(0,l.jsxs)("code",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 font-mono text-[9px] text-[var(--muted-foreground)]",children:[e.token.slice(0,12),"..."]}),(0,l.jsx)("button",{onClick:function(){navigator.clipboard.writeText(e.token),n(!0),setTimeout(()=>n(!1),2e3)},className:"text-[10px] text-[var(--primary)] hover:underline",children:t(r?"web.copied":"web.copyToken")})]})}function o8(e){let t=(0,ts.kj)(),{onClose:r,onDone:n}=e,[a,s]=(0,o.useState)(null);return a?(0,l.jsxs)(oG,{width:"w-[420px]",onClose:n,children:[(0,l.jsx)("h3",{className:"mb-3 text-sm font-medium text-[var(--foreground)]",children:t("web.createSuccess")}),(0,l.jsx)("p",{className:"mb-2 text-xs text-[var(--muted-foreground)]",children:t("web.tokenNotice")}),(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] bg-[var(--card)] p-2",children:[(0,l.jsx)("code",{className:"flex-1 break-all font-mono text-xs text-[var(--foreground)]",children:a.token}),(0,l.jsx)("button",{onClick:()=>navigator.clipboard.writeText(a.token),className:"rounded p-1 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,l.jsx)(aL.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsx)("div",{className:"mt-4 flex justify-end",children:(0,l.jsx)("button",{onClick:n,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white",children:t("web.done")})})]}):(0,l.jsx)(o$,{ns:"web",width:"w-[420px]",observer:!0,onClose:r,create:e=>k.F.web.createAccount(e),onDone:e=>s({token:e.token})})}let o6={id:"web_demo",label:"Web",Icon:V.A,Component:function(){let{accounts:e,loading:t,reload:r}=oJ("web",k.F.web.listAccounts),[n,a]=(0,o.useState)(!1);return(0,l.jsx)(oZ,{ns:"web",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,l.jsx)(oX,{...t,ns:"web",account:e,observer:!0,title:e.label||e.accountId,detail:e.workspacePath,workspaceMissing:e.workspaceMissing,footer:(0,l.jsx)(o4,{token:e.token}),save:t=>k.F.web.updateAccount(e.accountId,t),setEnabled:t=>k.F.web.updateAccount(e.accountId,{enabled:t}),remove:()=>k.F.web.deleteAccount(e.accountId)}),children:n&&(0,l.jsx)(o8,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}};function o9(e){let t=(0,ts.kj)(),[r,n]=(0,o.useState)(""),[a,s]=(0,o.useState)("");return(0,l.jsxs)(o$,{ns:"slack",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>k.F.slack.createAccount({botToken:r,appToken:a,...e}),children:[(0,l.jsx)(oW,{label:t("slack.botTokenLabel"),hint:t("slack.botTokenHint"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:r,onChange:n,placeholder:"xoxb-..."})}),(0,l.jsx)(oW,{label:t("slack.appTokenLabel"),hint:t("slack.appTokenHint"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:a,onChange:s,placeholder:"xapp-..."})})]})}let o7={id:"slack",label:"Slack",Icon:en.A,Component:function(){let{accounts:e,loading:t,reload:r}=oJ("slack",k.F.slack.listAccounts),[n,a]=(0,o.useState)(!1);return(0,l.jsx)(oZ,{ns:"slack",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,l.jsx)(oX,{...t,ns:"slack",account:e,title:e.label||e.teamId,deleteName:e.teamId,detail:(0,l.jsxs)(l.Fragment,{children:["team:",e.teamId," bot:",e.botUserId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>k.F.slack.updateAccount(e.accountId,t),setEnabled:t=>k.F.slack.updateAccount(e.accountId,{enabled:t}),remove:()=>k.F.slack.deleteAccount(e.accountId)}),children:n&&(0,l.jsx)(o9,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}};function ie(e){let t=(0,ts.kj)(),[r,n]=(0,o.useState)(""),[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)(""),[d,u]=(0,o.useState)("");return(0,l.jsxs)(o$,{ns:"feishu",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>k.F.feishu.createAccount({appId:r,appSecret:a,verificationToken:i||void 0,encryptKey:d||void 0,...e}),children:[(0,l.jsx)(oW,{label:t("feishu.appIdLabel"),children:(0,l.jsx)(oH,{mono:!0,value:r,onChange:n,placeholder:"cli_xxxxxxx"})}),(0,l.jsx)(oW,{label:t("feishu.appSecretLabel"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:a,onChange:s,placeholder:"****************"})}),(0,l.jsx)(oW,{label:t("feishu.verificationTokenLabel"),children:(0,l.jsx)(oH,{mono:!0,value:i,onChange:c,placeholder:""})}),(0,l.jsx)(oW,{label:t("feishu.encryptKeyLabel"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:d,onChange:u,placeholder:""})})]})}function it(e){let t=(0,ts.kj)(),[r,n]=(0,o.useState)(""),[a,s]=(0,o.useState)("");return(0,l.jsxs)(o$,{ns:"wecom",width:"w-[480px]",onClose:e.onClose,onDone:e.onDone,canSubmit:!!r.trim()&&!!a.trim(),create:e=>k.F.wecom.createAccount({botId:r,secret:a,...e}),children:[(0,l.jsx)(oW,{label:t("wecom.botIdLabel"),children:(0,l.jsx)(oH,{mono:!0,value:r,onChange:n,placeholder:"wecombot_xxxxxxx"})}),(0,l.jsx)(oW,{label:t("wecom.secretLabel"),children:(0,l.jsx)(oH,{mono:!0,type:"password",value:a,onChange:s,placeholder:"****************"})})]})}let ir=[o3,o2,o6,o7,{id:"feishu",label:"Feishu",Icon:r(61557).A,Component:function(){let{accounts:e,loading:t,reload:r}=oJ("feishu",k.F.feishu.listAccounts),[n,a]=(0,o.useState)(!1);return(0,l.jsx)(oZ,{ns:"feishu",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,l.jsx)(oX,{...t,ns:"feishu",account:e,title:e.label||e.appId,deleteName:e.appId,detail:(0,l.jsxs)(l.Fragment,{children:["app:",e.appId," bot:",e.botOpenId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>k.F.feishu.updateAccount(e.accountId,t),setEnabled:t=>k.F.feishu.updateAccount(e.accountId,{enabled:t}),remove:()=>k.F.feishu.deleteAccount(e.accountId)}),children:n&&(0,l.jsx)(ie,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}},{id:"wecom",label:"WeCom",Icon:r(60490).A,Component:function(){let{accounts:e,loading:t,reload:r}=oJ("wecom",k.F.wecom.listAccounts),[n,a]=(0,o.useState)(!1);return(0,l.jsx)(oZ,{ns:"wecom",accounts:e,loading:t,reload:r,onAdd:()=>a(!0),renderRow:(e,t)=>(0,l.jsx)(oX,{...t,ns:"wecom",account:e,title:e.label||e.botId,deleteName:e.botId,detail:(0,l.jsxs)(l.Fragment,{children:["bot:",e.botId," → ",e.workspacePath]}),workspaceMissing:e.workspaceMissing,save:t=>k.F.wecom.updateAccount(e.accountId,t),setEnabled:t=>k.F.wecom.updateAccount(e.accountId,{enabled:t}),remove:()=>k.F.wecom.deleteAccount(e.accountId)}),children:n&&(0,l.jsx)(it,{onClose:()=>a(!1),onDone:()=>{a(!1),r()}})})}}],ia="halo_channel_active",is=new Set(ir.map(e=>e.id)),il=null!=(s=null==(a=ir[0])?void 0:a.id)?s:"",io=(0,d.v)(e=>({active:function(){try{let e=localStorage.getItem(ia);if(e&&is.has(e))return e}catch(e){}return il}(),setActive(t){if(is.has(t)){try{localStorage.setItem(ia,t)}catch(e){}e({active:t})}}}));function ii(){let e=(0,ts.kj)(),t=io(e=>e.active),r=io(e=>e.setActive);return(0,l.jsxs)("div",{className:"flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(oF.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Channels"}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onClick:()=>oL(),title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:(0,l.jsx)(at.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:ir.map(n=>{if(!1===n.enabled)return null;let a=n.Icon,s=e(n.label),o=s===n.label?n.label:s;return(0,l.jsxs)("button",{onClick:()=>r(n.id),className:(0,U.cn)("flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors",t===n.id?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]"),children:[(0,l.jsx)(a,{className:"h-3.5 w-3.5"}),o]},n.id)})})]})}function ic(){let e=io(e=>e.active),t=ir.find(t=>t.id===e);if(!t)return null;let r=t.Component;return(0,l.jsx)(r,{})}var id=r(2462);let iu=(0,d.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 im(e){var t;let{status:r}=e,n=null!=(t=ip[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,l.jsx)("span",{className:(0,U.cn)("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",n),children:r.replace("_"," ")})}let ip={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 ix(){let e=(0,ts.kj)(),t=iu(e=>e.selectedId);return t?(0,l.jsx)(ig,{id:t}):(0,l.jsx)(ih,{label:e("evolution.list.pickRun")})}function ih(e){let{label:t}=e;return(0,l.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function ig(e){var t,r,n,a;let{id:s}=e,i=(0,ts.kj)(),c=iu(e=>e.refreshTick),d=iu(e=>e.setSelectedId),[u,m]=(0,o.useState)(null),[p,x]=(0,o.useState)(!0),[f,h]=(0,o.useState)(null),[g,v]=(0,o.useState)(!1),[b,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(""),[N,S]=(0,o.useState)(!1),[A,I]=(0,o.useState)(!1),[E,T]=(0,o.useState)(!1),[M,F]=(0,o.useState)(""),P=(0,o.useCallback)(async()=>{x(!0);try{let e=await k.F.evolution.getRun(s);m(e),h(null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{x(!1)}},[s]);if((0,o.useEffect)(()=>{m(null),S(!1),I(!1),y(""),w(""),P()},[s,P]),(0,o.useEffect)(()=>{0!==c&&P()},[c,P]),(0,o.useEffect)(()=>C.on("evolution:run_changed",e=>{e.id===s&&("deleted"===e.kind?d(null):P())}),[s,P,d]),p&&!u)return(0,l.jsx)(ih,{label:i("evolution.list.loading")});if(f)return(0,l.jsx)(ih,{label:i("cron.error",{error:f})});if(!u)return(0,l.jsx)(ih,{label:i("evolution.list.noRun")});let{run:D,patchMd:L,scoreJson:R,skipReasonMd:_,snapshotSummary:z,wrapperLog:O,subCliLog:B}=u,W="awaiting_review"===D.status,H="approved"===D.status&&("failed"===D.applyStatus||"timeout"===D.applyStatus),K=async()=>{v(!0);try{await k.F.evolution.approve(s,b.trim()||void 0),S(!1),y(""),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},G=async()=>{if(await (0,U.fN)(i("evolution.action.confirmReject"))){v(!0);try{await k.F.evolution.reject(s),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},q=async()=>{let e=j.trim();if(e){v(!0);try{await k.F.evolution.addHint(s,e),w(""),I(!1),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}}},$=async()=>{let e=M.trim();if(!e)return void alert(i("evolution.action.retryNeedsHint"));v(!0);try{await k.F.evolution.retry(s,e),F(""),T(!1),await P()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{v(!1)}},J=async()=>{if(await (0,U.fN)(i("evolution.action.confirmDelete"))){v(!0);try{await k.F.evolution.delete(s),d(null)}catch(e){alert(e instanceof Error?e.message:String(e)),v(!1)}}};return(0,l.jsxs)("div",{className:"flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(im,{status:D.status}),(0,l.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:D.triggerKind}),(0,l.jsx)("span",{className:"ml-auto text-xs text-[var(--muted-foreground)]",children:D.id}),"pending"!==D.status&&"running"!==D.status&&"approved"!==D.status&&(0,l.jsx)("button",{disabled:g,onClick:()=>{J()},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,l.jsx)(eQ.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsxs)("div",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:[i("evolution.detail.workspace")," ",(0,l.jsx)("span",{className:"font-mono",children:D.workspacePath})]}),D.userHint&&(0,l.jsxs)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs",children:[(0,l.jsx)("div",{className:"font-medium text-[var(--foreground)]",children:i("evolution.detail.hint")}),(0,l.jsx)("div",{className:"mt-1 whitespace-pre-wrap text-[var(--muted-foreground)]",children:D.userHint})]}),D.failureReason&&(0,l.jsx)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:i("evolution.detail.failure",{reason:D.failureReason})}),"skipped"===D.status&&(0,l.jsx)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs text-[var(--muted-foreground)]",children:i("evolution.detail.skipped")}),H&&(0,l.jsxs)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:[(0,l.jsx)("div",{className:"font-medium",children:i("evolution.detail.applyFailed")}),D.applyFailureReason&&(0,l.jsx)("div",{className:"mt-1 whitespace-pre-wrap",children:D.applyFailureReason})]})]}),W&&(0,l.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,l.jsxs)("button",{disabled:g,onClick:()=>S(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,l.jsx)(rw.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.approve")]}),(0,l.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,l.jsx)(tM.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.reject")]}),(0,l.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,l.jsx)(id.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.addHint")]}),(0,l.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,l.jsx)(at.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retry")]})]}),!W&&("failed"===D.status||"timeout"===D.status||"skipped"===D.status||"rejected"===D.status||H)&&(0,l.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,l.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,l.jsx)(at.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retryWithHint")]})}),E&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)] bg-sky-950/20 px-4 py-2",children:[(0,l.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.retry.title")}),(0,l.jsx)("textarea",{value:M,onChange:e=>F(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.retry.placeholder"),autoFocus:!0}),(0,l.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,l.jsx)("button",{disabled:g||!M.trim(),onClick:()=>{$()},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,l.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")})]})]}),W&&N&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)] bg-emerald-950/20 px-4 py-2",children:[(0,l.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.approve.title")}),(0,l.jsx)("textarea",{value:b,onChange:e=>y(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,l.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,l.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,l.jsx)("button",{disabled:g,onClick:()=>{S(!1),y("")},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")})]})]}),W&&A&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)] bg-[var(--background)]/40 px-4 py-2",children:[(0,l.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.hint.title")}),(0,l.jsx)("textarea",{value:j,onChange:e=>w(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.hint.placeholder")}),(0,l.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,l.jsx)("button",{disabled:g||!j.trim(),onClick:()=>{q()},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.add")}),(0,l.jsx)("button",{disabled:g,onClick:()=>{I(!1),w("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),R&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.score.title")}),(0,l.jsxs)("div",{className:"grid grid-cols-4 gap-3 text-xs",children:[(0,l.jsx)(ib,{label:i("evolution.score.lint"),value:R.lint}),(0,l.jsx)(ib,{label:i("evolution.score.behavior"),value:R.behavior}),(0,l.jsx)(ib,{label:i("evolution.score.scope"),value:R.scope}),(0,l.jsx)(ib,{label:i("evolution.score.avg"),value:R.avg,highlight:!0})]}),(0,l.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-xs text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{children:i("evolution.score.confidence")}),(0,l.jsx)("span",{className:"font-medium text-[var(--foreground)]",children:null!=(t=R.confidence)?t:"—"})]}),"string"==typeof R.notes&&(0,l.jsx)("div",{className:"mt-2 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs text-[var(--foreground)]",children:R.notes})]}),z&&(0,l.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3 text-xs",children:[(0,l.jsx)("div",{className:"mb-1 font-medium",children:i("evolution.snapshot.title",{n:null!=(r=z.messageCount)?r:0})}),z.firstUser&&(0,l.jsxs)("div",{className:"mb-1",children:[(0,l.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstUser")," "]}),(0,l.jsx)("span",{className:"line-clamp-2 whitespace-pre-wrap",children:z.firstUser})]}),z.firstAssistant&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstAssistant")," "]}),(0,l.jsx)("span",{className:"line-clamp-3 whitespace-pre-wrap",children:(n=z.firstAssistant,a=400,n.length<=400?n:n.slice(0,a)+"…")})]})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[_&&(0,l.jsxs)("div",{className:"mb-4",children:[(0,l.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.skip.title")}),(0,l.jsx)("pre",{className:"whitespace-pre-wrap rounded border border-[var(--border)]/40 bg-[var(--secondary)]/40 p-3 text-xs leading-relaxed",children:_})]}),(0,l.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.patch.title")}),L?(0,l.jsx)("pre",{className:"whitespace-pre-wrap rounded bg-[var(--accent)] p-3 text-xs leading-relaxed",children:L}):(0,l.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:i("evolution.patch.empty")}),(O||B)&&(0,l.jsxs)("div",{className:"mt-6 space-y-4 border-t border-[var(--border)] pt-4",children:[(0,l.jsx)("div",{className:"text-xs uppercase tracking-wide text-[var(--muted-foreground)]",children:i("evolution.logs.title")}),O&&(0,l.jsx)(iv,{title:i("evolution.logs.wrapper"),body:O}),B&&(0,l.jsx)(iv,{title:i("evolution.logs.subCli"),body:B})]})]})]})}function iv(e){let{title:t,body:r}=e,[n,a]=(0,o.useState)(r.length<4e3);return(0,l.jsxs)("div",{children:[(0,l.jsxs)("button",{type:"button",className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)] hover:text-[var(--primary)]",onClick:()=>a(e=>!e),children:[(0,l.jsx)("span",{children:n?"▼":"▶"}),(0,l.jsx)("span",{children:t}),(0,l.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",(r.length/1024).toFixed(1)," KB)"]})]}),n&&(0,l.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 ib(e){let{label:t,value:r,highlight:n}=e;return(0,l.jsxs)("div",{className:(0,U.cn)("rounded p-2",n?"bg-[var(--primary)]/10":"bg-[var(--accent)]"),children:[(0,l.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:t}),(0,l.jsx)("div",{className:(0,U.cn)("text-lg font-medium",n&&"text-[var(--primary)]"),children:"number"==typeof r?r:"—"})]})}let iy=["all","awaiting_review","pending","running","approved","applied","skipped","rejected","failed","timeout","archived"];function ij(){let e=(0,ts.kj)(),t=iu(e=>e.filter),r=iu(e=>e.setFilter),n=iu(e=>e.selectedId),a=iu(e=>e.setSelectedId),s=iu(e=>e.bumpRefresh),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(!0),[m,p]=(0,o.useState)(null),[x,f]=(0,o.useState)(!1),[h,g]=(0,o.useState)(null),[v,b]=(0,o.useState)(!1),y=(0,o.useRef)(0);(0,o.useEffect)(()=>{y.current=i.length,i.length>=300&&g(null)},[i.length]);let j=(0,o.useCallback)(async()=>{let e=Math.min(300,Math.max(20,y.current));try{let r=await k.F.evolution.listRuns({archived:"archived"===t,limit:e});c(r.runs),g(r.hasMore?r.nextCursor:null),p(null)}catch(e){p(e instanceof Error?e.message:String(e))}finally{u(!1)}},[t]),w=(0,o.useCallback)(async()=>{if(h&&!v){b(!0);try{let e=await k.F.evolution.listRuns({archived:"archived"===t,limit:20,before:h});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("evolution.listRuns more",e)}finally{b(!1)}}},[t,h,v]);(0,o.useEffect)(()=>{j()},[j]);let N=n6(w,i.length);(0,o.useEffect)(()=>{let e=C.on("evolution:run_changed",()=>{j()}),t=C.on("evolution:apply_changed",()=>{j()});return()=>{e(),t()}},[j]);let S=(0,o.useMemo)(()=>"all"===t||"archived"===t?i:i.filter(e=>e.status===t),[i,t]);return(0,o.useEffect)(()=>{var e;if(n)return;let t=null!=(e=i.find(e=>"awaiting_review"===e.status))?e:i[0];t&&a(t.id)},[i,n,a]),(0,l.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,l.jsx)(a6.A,{className:"h-4 w-4"}),e("evolution.title")]}),(0,l.jsx)("button",{onClick:async()=>{f(!0),s();let e=new Promise(e=>setTimeout(e,400));await Promise.all([j(),e]),f(!1)},disabled:x,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,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",x&&"animate-spin")})})]}),(0,l.jsx)("div",{className:"flex flex-wrap gap-1 border-b border-[var(--border)] px-2 py-2",children:iy.map(n=>(0,l.jsx)("button",{onClick:()=>r(n),className:(0,U.cn)("w-16 shrink-0 rounded px-2 py-0.5 text-xs text-center",t===n?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:e("evolution.filter.".concat(n))},n))}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[d&&(0,l.jsx)(iw,{label:e("evolution.list.loading")}),m&&(0,l.jsx)(iw,{label:e("cron.error",{error:m})}),!d&&!m&&0===S.length&&(0,l.jsx)(iw,{label:e("evolution.list.empty")}),S.map(e=>(0,l.jsx)(iN,{run:e,selected:e.id===n,onClick:()=>a(e.id)},e.id)),h&&(0,l.jsx)("div",{ref:N,className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:v?e("evolution.list.loading"):e("cron.loadOlder")})]})]})}function iw(e){let{label:t}=e;return(0,l.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function iN(e){var t;let{run:r,selected:n,onClick:a}=e,s=(0,ts.kj)();return(0,l.jsxs)("button",{onClick:a,className:(0,U.cn)("flex w-full flex-col gap-1 border-b border-[var(--border)] px-3 py-2 text-left text-sm transition-colors",n?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(im,{status:r.status}),"approved"===r.status&&("failed"===r.applyStatus||"timeout"===r.applyStatus)&&(0,l.jsx)("span",{className:"rounded bg-red-800 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-red-100",children:s("evolution.list.applyFailed")}),(0,l.jsx)("span",{className:"text-xs",children:r.triggerKind})]}),(0,l.jsx)("div",{className:"truncate text-xs text-[var(--muted-foreground)]",children:null!=(t=r.userHint)?t:(0,l.jsx)("span",{className:"italic",children:s("evolution.list.noHint")})}),(0,l.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{children:(0,U.fw)(r.createdAt,s)}),(0,l.jsx)("span",{children:"•"}),(0,l.jsx)("span",{title:r.workspacePath,className:"truncate",children:r.workspacePath.split("/").pop()}),r.attempts>1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{children:"•"}),(0,l.jsx)("span",{children:s("evolution.list.attempts",{n:r.attempts})})]})]})]})}var ik=r(30478),iS=r.n(ik),iC=r(90144);let iA=(0,d.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 iI(e,t){return e?e.includes("ret=-2")?t("cron.err.wechat.noInbound"):e:"?"}function iE(){let e=(0,ts.kj)(),t=iA(e=>e.selectedId),r=iA(e=>e.setSelectedId),n=iA(e=>e.formMode),a=iA(e=>e.closeForm),[s,i]=(0,o.useState)(null),c=(0,o.useCallback)(async()=>{if(!t)return void i(null);try{var e;let{jobs:r}=await k.F.cron.listJobs();i(null!=(e=r.find(e=>e.id===t))?e:null)}catch(e){console.error("cron.listJobs",e)}},[t]);(0,o.useEffect)(()=>{c()},[c]),(0,o.useEffect)(()=>C.on("cron:job_changed",()=>{c()}),[c]);let d=(0,o.useCallback)(async n=>{if(await (0,U.fN)(e("cron.confirmDelete")))try{await k.F.cron.deleteJob(n),t===n&&r(null)}catch(e){alert(e instanceof Error?e.message:String(e))}},[t,r,e]),u=(0,o.useCallback)(async e=>{try{await k.F.cron.runNow(e)}catch(e){alert(e instanceof Error?e.message:String(e))}},[]);return"create"===n?(0,l.jsx)(iF,{onClose:a,onSaved:a}):"edit"===n&&s?(0,l.jsx)(iF,{initial:s,onClose:a,onSaved:a}):s?(0,l.jsx)(iT,{job:s,onEdit:()=>iA.getState().openEdit(),onDelete:()=>d(s.id),onRunNow:()=>u(s.id)},s.id):(0,l.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("cron.pickJob")})}function iT(e){var t;let{job:r,onEdit:n,onDelete:a,onRunNow:s}=e,i=(0,ts.kj)(),[c,d]=(0,o.useState)([]),[u,m]=(0,o.useState)(null),[p,x]=(0,o.useState)(null),[f,h]=(0,o.useState)(!1),[g,v]=(0,o.useState)(null),[b,y]=(0,o.useState)(!1),j=(0,o.useCallback)(async()=>{try{let e=await k.F.cron.listRuns(r.id,{limit:20});d(e.runs),v(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns",e)}},[r.id]),w=(0,o.useCallback)(async()=>{if(g&&!b){y(!0);try{let e=await k.F.cron.listRuns(r.id,{limit:20,before:g});d(t=>[...t,...e.runs]),v(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns more",e)}finally{y(!1)}}},[r.id,g,b]);(0,o.useEffect)(()=>{j()},[j]);let N=n6(w,c.length);(0,o.useEffect)(()=>C.on("cron:run_changed",e=>{e.jobId===r.id&&j()}),[r.id,j]);let S=(0,o.useCallback)(async e=>{m(e),x(null),h(!0);try{let{log:t}=await k.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,l.jsxs)("div",{className:"flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,l.jsxs)("div",{className:"flex flex-1 items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,l.jsx)(iC.A,{className:"h-4 w-4"}),(0,l.jsx)("span",{children:r.label||r.id}),0===r.enabled&&(0,l.jsx)("span",{className:"rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] uppercase",children:i("cron.disabled")})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.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:i("cron.runNow"),children:[(0,l.jsx)(lJ.A,{className:"h-3 w-3"})," ",i("cron.runNow")]}),(0,l.jsxs)("button",{onClick:n,className:"flex items-center gap-1 rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:opacity-90",title:i("cron.edit"),children:[(0,l.jsx)(oU.A,{className:"h-3 w-3"})," ",i("cron.edit")]}),(0,l.jsx)("button",{onClick:a,className:"flex items-center gap-1 rounded bg-red-700/80 px-2 py-1 text-xs text-white hover:opacity-90",title:i("cron.delete"),children:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})})]})]}),(0,l.jsxs)("div",{className:"mt-3 grid grid-cols-2 gap-2 text-xs text-[var(--muted-foreground)]",children:[r.runAt?(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.runAt")})," ",(0,l.jsxs)("span",{className:"font-mono",children:[new Date(r.runAt).toLocaleString(),r.timezone?" (".concat(r.timezone,")"):""]})]}):(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.schedule")})," ",(0,l.jsxs)("span",{className:"font-mono",children:[r.schedule,r.timezone?" (".concat(r.timezone,")"):""]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.agent")})," ",r.agentId]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.timeoutSec")})," ",null!=r.timeoutSec?"".concat(r.timeoutSec,"s"):i("cron.field.timeoutSecDefault")]}),null!=r.activeFrom&&(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.activeFrom")})," ",(0,l.jsx)("span",{className:"font-mono",children:new Date(r.activeFrom).toLocaleString()})]}),null!=r.activeUntil&&(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.activeUntil")})," ",(0,l.jsx)("span",{className:"font-mono",children:new Date(r.activeUntil).toLocaleString()})]}),(0,l.jsxs)("div",{className:"col-span-2 truncate",children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.workspace")})," ",r.workspacePath]}),(0,l.jsxs)("div",{className:"col-span-2 truncate",children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.session")})," ",(0,l.jsx)("span",{className:"font-mono",children:null!=(t=r.sessionId)?t:i("cron.field.sessionDefault",{id:r.effectiveSessionId})})]}),(0,l.jsxs)("div",{className:"col-span-2",children:[(0,l.jsx)("span",{className:"text-[var(--foreground)]",children:i("cron.field.targets")})," ",0===r.targets.length?i("cron.field.targetsLogOnly"):r.targets.map(e=>"".concat(e.channelType,":").concat(e.accountId).concat(e.chatId?"/"+e.chatId:"")).join(", ")]})]}),(0,l.jsxs)("div",{className:"mt-2",children:[(0,l.jsx)("div",{className:"text-xs font-medium text-[var(--foreground)]",children:i("cron.field.prompt")}),(0,l.jsx)("pre",{className:"mt-1 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs",children:r.userPrompt})]})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[(0,l.jsx)("div",{className:"mb-2 text-xs font-medium text-[var(--foreground)]",children:i("cron.runHistory")}),0===c.length?(0,l.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:i("cron.noRuns")}):(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)("ul",{className:"divide-y divide-[var(--border)] text-xs",children:[c.map(e=>(0,l.jsxs)("li",{className:"py-2",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:(0,U.cn)("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,l.jsx)("span",{className:"text-[var(--muted-foreground)]",children:new Date(e.startedAt).toLocaleString()}),(0,l.jsx)("span",{className:"text-[var(--muted-foreground)]",children:"\xb7"}),(0,l.jsx)("span",{className:"text-[var(--muted-foreground)]",children:e.triggerKind})]}),(0,l.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,l.jsx)("div",{className:"mt-1 text-red-400",children:iI(e.failureReason,i)}),e.dispatchResults&&e.dispatchResults.length>0&&(0,l.jsxs)("div",{className:"mt-1 text-[var(--muted-foreground)]",children:[i("cron.dispatch")," ",e.dispatchResults.map(e=>{let t=e.chatId?"".concat(e.channelType,":").concat(e.accountId,"/").concat(e.chatId):"".concat(e.channelType,":").concat(e.accountId);return"".concat(t," ").concat(e.ok?"✓":"✗ (".concat(iI(e.error,i),")"))}).join(" \xb7 ")]}),e.output&&(0,l.jsx)("pre",{className:"mt-1 line-clamp-3 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-[11px]",children:e.output})]},e.id)),g&&(0,l.jsx)("li",{ref:N,className:"py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?i("cron.loading"):i("cron.loadOlder")})]})})]}),u&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:()=>m(null),children:(0,l.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,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-3 py-2 text-xs",children:[(0,l.jsx)("span",{children:i("cron.log.title",{id:u})}),(0,l.jsx)("button",{onClick:()=>m(null),className:"rounded px-2 py-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:i("cron.log.close")})]}),(0,l.jsx)("pre",{className:"flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-[11px] leading-relaxed",children:f?i("cron.loading"):null!=p?p:""})]})})]})}function iM(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 iF(e){var t,r,n,a,s,i,c;let{initial:d,onClose:u,onSaved:m}=e,p=(0,ts.kj)(),x=rT(e=>e.activeProject),[f,h]=(0,o.useState)(null!=(t=null==d?void 0:d.label)?t:""),[g,v]=(0,o.useState)(null!=(n=null!=(r=null==d?void 0:d.workspacePath)?r:null==x?void 0:x.path)?n:""),[b,y]=(0,o.useState)(g),[j,w]=(0,o.useState)(null!=(a=null==d?void 0:d.agentId)?a:"default"),[N,S]=(0,o.useState)([]),[C,A]=(0,o.useState)(null!=(s=null==d?void 0:d.sessionId)?s:""),[I,E]=(0,o.useState)([]),[T,M]=(0,o.useState)((null==d?void 0:d.runAt)?"oneShot":"recurring"),[F,P]=(0,o.useState)((null==d?void 0:d.schedule)||"0 9 * * *"),[D,L]=(0,o.useState)(()=>(null==d?void 0:d.runAt)?iM(new Date(d.runAt)):iM(new Date(Date.now()+36e5))),[R,_]=(0,o.useState)(()=>(function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}})());(0,o.useEffect)(()=>{let e=!0;return k.F.cron.meta().then(t=>{let{hostTimezone:r}=t;e&&r&&_(r)}).catch(e=>console.error("cron.meta",e)),()=>{e=!1}},[]);let z=(0,o.useMemo)(()=>{let e=function(){let e=Intl;if("function"==typeof e.supportedValuesOf)try{return e.supportedValuesOf("timeZone")}catch(e){}return["UTC","Asia/Shanghai","Asia/Tokyo","Asia/Singapore","Europe/London","Europe/Paris","America/New_York","America/Los_Angeles"]}(),t=e.includes(R)?R:e[0];return[{id:t,label:"".concat(t," (default)")},...e.filter(e=>e!==t).map(e=>({id:e,label:e}))]},[R]),[O,B]=(0,o.useState)(null!=(i=null==d?void 0:d.timezone)?i:""),[W,H]=(0,o.useState)((null==d?void 0:d.timeoutSec)!=null?String(d.timeoutSec):""),[K,G]=(0,o.useState)(null),[q,$]=(0,o.useState)(null),[J,Z]=(0,o.useState)(null!=(c=null==d?void 0:d.userPrompt)?c:""),[V,Y]=(0,o.useState)((null==d?void 0:d.enabled)!==0),[Q,X]=(0,o.useState)([]),[ee,et]=(0,o.useState)(()=>{var e;let t=new Set;for(let r of null!=(e=null==d?void 0:d.targets)?e:[])t.add("".concat(r.channelType,":").concat(r.accountId));return t}),[er,en]=(0,o.useState)(()=>{var e;let t={};for(let r of null!=(e=null==d?void 0:d.targets)?e:[]){let e="".concat(r.channelType,":").concat(r.accountId);r.chatId&&(t[e]=t[e]?"".concat(t[e],", ").concat(r.chatId):r.chatId)}return t}),[ea,es]=(0,o.useState)(!1),[el,eo]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!0,t=async()=>{try{let{agents:t}=await k.F.agentConfigs.list(b||void 0);if(!e)return;let r=t.filter(e=>!e.internal&&!e.overridden&&!e.disabled).map(e=>({id:e.id,name:e.name||e.id}));S(r),r.length>0&&w(e=>r.some(t=>t.id===e)?e:r[0].id)}catch(e){console.error("agentConfigs.list",e)}};return b&&t(),()=>{e=!1}},[b]),(0,o.useEffect)(()=>{let e=!0;if(b)return k.F.sessionLogs.list(b,{rootOnly:!0,limit:50}).then(t=>{let{sessions:r}=t;e&&E(r.map(e=>({id:e.id,label:"".concat(e.title||e.id," \xb7 ").concat(e.agentName||e.agentId)})))}).catch(t=>{e&&E([]),console.error("sessionLogs.list",t)}),()=>{e=!1}},[b]),(0,o.useEffect)(()=>{let e=!0;return k.F.cron.listChannelTargets().then(t=>{let{targets:r}=t;e&&X(r)}).catch(e=>console.error("listChannelTargets",e)),()=>{e=!1}},[]);let ei=(0,o.useCallback)(e=>{et(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ec=(0,o.useCallback)((e,t)=>{let r=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(e);if(!r)return Date.parse(e);let[,n,a,s,l,o]=r,i=Date.UTC(+n,a-1,+s,+l,+o),c=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(i)).filter(e=>"literal"!==e.type).map(e=>[e.type,e.value]));return i-(Date.UTC(+c.year,c.month-1,+c.day,24==+c.hour?0:+c.hour,+c.minute,+c.second)-i)},[]),ed=(0,o.useCallback)(async()=>{if(eo(null),!g.trim())return void eo(p("cron.form.err.workspace"));if(!j.trim())return void eo(p("cron.form.err.agent"));if("recurring"===T&&!F.trim())return void eo(p("cron.form.err.schedule"));if("oneShot"===T&&!D)return void eo(p("cron.form.err.runAt"));if(!J.trim())return void eo(p("cron.form.err.prompt"));let e=O||R,t="oneShot"===T?ec(D,e):void 0;if("oneShot"===T&&void 0!==t&&t<=Date.now())return void eo(p("cron.form.err.runAtPast"));let r=W.trim(),n=r?Number(r):void 0;if(void 0!==n&&(!Number.isInteger(n)||n<60||n>21600))return void eo(p("cron.form.err.timeoutSec"));let a=(t,r)=>null===t?null!=r?r:null:t?ec(t,e):null,s="recurring"===T?a(K,null==d?void 0:d.activeFrom):null,l="recurring"===T?a(q,null==d?void 0:d.activeUntil):null;if(q&&null!==l&&l<=Date.now())return void eo(p("cron.form.err.activeUntilPast"));if(null!==s&&null!==l&&l<=s)return void eo(p("cron.form.err.activeOrder"));let o=[];for(let e of ee){var i;let[t,r]=e.split(":"),n=(null!=(i=er[e])?i:"").trim(),a=n?n.split(",").map(e=>e.trim()).filter(Boolean):[],s=e=>"slack"!==t||/^[DCG][A-Z0-9]+(:[\d.]+)?$/.test(e)?"feishu"!==t||/^oc_[a-zA-Z0-9]+(:[a-zA-Z0-9_-]+)?$/.test(e)?"wecom"!==t||/^[\w@.-]+$/.test(e)?"telegram"!==t||/^-?\d+$/.test(e)?null:p("cron.form.err.chatId.telegram",{chatId:e}):p("cron.form.err.chatId.wecom",{chatId:e}):p("cron.form.err.chatId.feishu",{chatId:e}):p("cron.form.err.chatId.slack",{chatId:e});for(let e of a){let t=s(e);if(t)return void eo(t)}if(0===a.length)o.push({channelType:t,accountId:r});else for(let e of a)o.push({channelType:t,accountId:r,chatId:e})}es(!0);try{let e={label:f||void 0,workspacePath:g,agentId:j,userPrompt:J,timezone:O||void 0,targets:o,enabled:V};d?await k.F.cron.updateJob(d.id,{...e,schedule:"recurring"===T?F:"",runAt:"oneShot"===T?t:null,timeoutSec:null!=n?n:null,sessionId:C||null,..."oneShot"===T||null!==K?{activeFrom:s}:{},..."oneShot"===T||null!==q?{activeUntil:l}:{}}):await k.F.cron.createJob({...e,schedule:"recurring"===T?F:"",runAt:"oneShot"===T?t:void 0,timeoutSec:n,sessionId:C||void 0,activeFrom:null!=s?s:void 0,activeUntil:null!=l?l:void 0}),m()}catch(e){eo(e instanceof Error?e.message:String(e))}finally{es(!1)}},[d,f,g,j,C,J,T,F,D,O,R,ec,W,K,q,ee,er,V,m,p]);return(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex h-full flex-col",children:[(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-sm font-medium",children:d?p("cron.form.edit"):p("cron.form.create")}),(0,l.jsx)("button",{onClick:u,className:"jsx-8283b0ed0bcf6928 rounded px-2 py-1 text-xs text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:p("cron.form.cancel")})]}),(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex-1 space-y-3 overflow-y-auto p-4 text-xs",children:[(0,l.jsx)(iP,{label:p("cron.form.label"),children:(0,l.jsx)("input",{value:f,onChange:e=>h(e.target.value),placeholder:p("cron.form.label.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,l.jsx)(iP,{label:p("cron.form.workspace"),children:(0,l.jsx)("input",{value:g,onChange:e=>v(e.target.value),onBlur:()=>y(g),onKeyDown:e=>{"Enter"===e.key&&y(g)},placeholder:p("cron.form.workspace.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"})}),(0,l.jsx)(iP,{label:p("cron.form.agent"),children:(0,l.jsxs)("select",{value:j,onChange:e=>w(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base",children:[0===N.length&&(0,l.jsx)("option",{value:"default",className:"jsx-8283b0ed0bcf6928",children:"default"}),N.map(e=>(0,l.jsxs)("option",{value:e.id,className:"jsx-8283b0ed0bcf6928",children:[e.name," (",e.id,")"]},e.id))]})}),(0,l.jsxs)(iP,{label:p("cron.form.session"),children:[(0,l.jsx)(lZ,{value:C,placeholder:p("cron.form.session.placeholder"),presets:b?I:[],onCommit:e=>A(e.trim()),minWidth:280}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.session.hint")})]}),(0,l.jsx)(iP,{label:p("cron.form.mode"),children:(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex gap-3",children:[(0,l.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,l.jsx)("input",{type:"radio",name:"cron-mode",value:"recurring",checked:"recurring"===T,onChange:()=>M("recurring"),className:"jsx-8283b0ed0bcf6928"}),(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:p("cron.form.mode.recurring")})]}),(0,l.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,l.jsx)("input",{type:"radio",name:"cron-mode",value:"oneShot",checked:"oneShot"===T,onChange:()=>M("oneShot"),className:"jsx-8283b0ed0bcf6928"}),(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:p("cron.form.mode.oneShot")})]})]})}),"recurring"===T?(0,l.jsxs)(iP,{label:p("cron.form.schedule"),children:[(0,l.jsx)("input",{value:F,onChange:e=>P(e.target.value),placeholder:p("cron.form.schedule.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.schedule.hint")})]}):(0,l.jsxs)(iP,{label:p("cron.form.runAt"),children:[(0,l.jsx)("input",{type:"datetime-local",value:D,onChange:e=>L(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.runAt.hint")})]}),(0,l.jsx)(iP,{label:p("cron.form.timezone"),children:(0,l.jsx)(lZ,{value:O||R,placeholder:p("cron.form.timezone.hostDefault",{tz:R}),presets:z,onCommit:e=>{B(e===R?"":e)},minWidth:280})}),"recurring"===T&&(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928",children:[(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 grid grid-cols-2 gap-2",children:[["cron.form.activeFrom",K,null==d?void 0:d.activeFrom,G],["cron.form.activeUntil",q,null==d?void 0:d.activeUntil,$]].map(e=>{let[t,r,n,a]=e,s=null!=r?r:null!=n?function(e,t){let r=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(new Date(e)).filter(e=>"literal"!==e.type).map(e=>[e.type,e.value]));return"".concat(r.year,"-").concat(r.month,"-").concat(r.day,"T").concat("24"===r.hour?"00":r.hour,":").concat(r.minute)}(n,O||R):"";return(0,l.jsx)(iP,{label:p(t),children:(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex items-center gap-1",children:[(0,l.jsx)("input",{type:"datetime-local",value:s,onChange:e=>a(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),s&&(0,l.jsx)("button",{type:"button",onClick:()=>a(""),className:"jsx-8283b0ed0bcf6928 shrink-0 rounded px-2 py-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:p("cron.form.activeClear")})]})},t)})}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.active.hint")})]}),(0,l.jsxs)(iP,{label:p("cron.form.timeoutSec"),children:[(0,l.jsx)("input",{type:"number",min:60,max:21600,step:1,value:W,onChange:e=>H(e.target.value),placeholder:p("cron.form.timeoutSec.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.timeoutSec.hint")})]}),(0,l.jsx)(iP,{label:p("cron.form.userPrompt"),children:(0,l.jsx)("textarea",{value:J,onChange:e=>Z(e.target.value),rows:5,placeholder:p("cron.form.userPrompt.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,l.jsx)(iP,{label:p("cron.form.targets"),children:(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 space-y-1 rounded border border-[var(--border)] p-2",children:[0===Q.length?(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-[var(--muted-foreground)]",children:p("cron.form.targets.empty")}):Q.map(e=>{var t;let r="".concat(e.channelType,":").concat(e.accountId),n=ee.has(r),a="wechat"!==e.channelType,s="slack"===e.channelType?"D… (DM) / C… (channel) / C…:1700.0 (thread)":"telegram"===e.channelType?p("cron.form.chatIdHint.telegram"):"feishu"===e.channelType?p("cron.form.chatIdHint.feishu"):"wecom"===e.channelType?p("cron.form.chatIdHint.wecom"):"";return(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 "+((0,U.cn)("rounded px-1 py-0.5",n&&"bg-[var(--accent)]")||""),children:[(0,l.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-2",children:[(0,l.jsx)("input",{type:"checkbox",checked:n,onChange:()=>ei(r),disabled:!e.enabled,className:"jsx-8283b0ed0bcf6928"}),(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928 font-medium",children:e.channelType}),(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:e.label}),!e.enabled&&(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.targets.disabled")}),!e.hasActiveChat&&(0,l.jsx)("span",{title:p("cron.form.targets.noActiveChat"),className:"jsx-8283b0ed0bcf6928 text-[10px] text-amber-400",children:p("cron.form.targets.noActiveChatLabel")})]}),n&&a&&(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 ml-6",children:[(0,l.jsx)(iD,{channelType:e.channelType,accountId:e.accountId,value:null!=(t=er[r])?t:"",onChange:e=>en(t=>({...t,[r]:e})),placeholder:s}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.chatIdHelp")})]})]},r)}),(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:p("cron.form.targets.hint")})]})}),(0,l.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex items-center gap-2",children:[(0,l.jsx)("input",{type:"checkbox",checked:V,onChange:e=>Y(e.target.checked),className:"jsx-8283b0ed0bcf6928"}),(0,l.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:p("cron.form.enabled")})]}),el&&(0,l.jsx)("div",{className:"jsx-8283b0ed0bcf6928 rounded border border-red-500/50 bg-red-950/40 p-2 text-red-300",children:el})]}),(0,l.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex justify-end gap-2 border-t border-[var(--border)] px-4 py-3",children:[(0,l.jsx)("button",{onClick:u,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--accent)] px-3 py-1 text-xs",children:p("cron.form.cancel")}),(0,l.jsx)("button",{onClick:()=>{ed()},disabled:ea,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--primary)] px-3 py-1 text-xs text-[var(--primary-foreground)] disabled:opacity-50",children:ea?p("cron.form.saving"):d?p("cron.form.save"):p("cron.form.create.btn")})]}),(0,l.jsx)(iS(),{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 iP(e){let{label:t,children:r}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"mb-1 block text-[var(--foreground)]",children:t}),r]})}function iD(e){let{channelType:t,accountId:r,value:n,onChange:a,placeholder:s}=e,i=(0,ts.kj)(),[c,d]=(0,o.useState)(""),[u,m]=(0,o.useState)([]),[p,x]=(0,o.useState)(!1),[f,h]=(0,o.useState)(!1),g="slack"===t||"feishu"===t;return(0,o.useEffect)(()=>{if(!g||!c.trim())return void m([]);let e=!1;h(!0);let n=setTimeout(async()=>{try{let n="slack"===t?await k.F.slack.searchTargets(r,c):await k.F.feishu.searchTargets(r,c);if(e)return;let a=n.hits.map(e=>{var t,r;let n=null!=(r=null!=(t=e.realName)?t:e.email)?r:"";return{id:e.id,name:e.name,chatId:e.chatId,kind:e.kind,subtitle:n}});m(a)}catch(t){e||m([]),console.error("[cron-form] target search failed:",t)}finally{e||h(!1)}},300);return()=>{e=!0,clearTimeout(n)}},[c,t,r,g]),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{value:n,onChange:e=>(function(e){var t,r;if(a(e),!g)return;let n=null!=(r=null==(t=e.split(",").pop())?void 0:t.trim())?r:"";d(n),x(n.length>0)})(e.target.value),onFocus:()=>{c&&x(!0)},onBlur:()=>setTimeout(()=>x(!1),150),placeholder:s,className:"input-base font-mono text-[11px]"}),g&&p&&(f||u.length>0)&&(0,l.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:[f&&(0,l.jsx)("div",{className:"px-2 py-1 text-[10px] text-[var(--muted-foreground)]",children:i("cron.form.searching")}),!f&&u.map(e=>(0,l.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>(function(e){let t=n.split(",").map(e=>e.trim()).filter(Boolean);t.length>0?t[t.length-1]=e:t.push(e),a(t.join(", ")),d(""),m([]),x(!1)})(e.chatId),className:"flex w-full items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-[var(--accent)]",children:[(0,l.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,l.jsxs)("span",{className:"flex-1 truncate",children:[e.name,e.subtitle&&(0,l.jsx)("span",{className:"ml-1 text-[10px] text-[var(--muted-foreground)]",children:e.subtitle})]}),(0,l.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:e.chatId})]},e.kind+":"+e.id))]})]})}function iL(){let e=(0,ts.kj)(),[t,r]=(0,o.useState)([]),[n,a]=(0,o.useState)(!0),[s,i]=(0,o.useState)(null),[c,d]=(0,o.useState)(!1),[u,m]=(0,o.useState)(null),[p,x]=(0,o.useState)(!1),[f,h]=(0,o.useState)(0),g=iA(e=>e.selectedId),v=iA(e=>e.setSelectedId),b=iA(e=>e.openCreate),y=(0,o.useCallback)(async()=>{try{let e=await k.F.cron.listJobs({limit:20});r(e.jobs),h(Date.now()),m(e.hasMore?e.nextCursor:null),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]),j=n6((0,o.useCallback)(async()=>{if(u&&!p){x(!0);try{let e=await k.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{x(!1)}}},[u,p]),t.length),w=(0,o.useCallback)(async()=>{d(!0);let e=new Promise(e=>setTimeout(e,400));await Promise.all([y(),e]),d(!1)},[y]);return(0,o.useEffect)(()=>{y()},[y]),(0,o.useEffect)(()=>{let e=C.on("cron:job_changed",()=>{y()}),t=C.on("cron:run_changed",()=>{y()});return()=>{e(),t()}},[y]),(0,o.useEffect)(()=>{!g&&t[0]&&v(t[0].id)},[t,g,v]),(0,l.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,l.jsx)(iC.A,{className:"h-4 w-4"}),e("cron.title")]}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsxs)("button",{onClick:b,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,l.jsx)(sG.A,{className:"h-3 w-3"})," ",e("cron.new")]}),(0,l.jsx)("button",{onClick:()=>{w()},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,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",c&&"animate-spin")})})]})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto",children:n&&0===t.length?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.loading")}):s?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:e("cron.error",{error:s})}):0===t.length?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.empty")}):(0,l.jsxs)("ul",{className:"divide-y divide-[var(--border)]",children:[t.map(t=>{let r=g===t.id,n=t.lastRunStatus;return(0,l.jsxs)("li",{className:(0,U.cn)("cursor-pointer px-3 py-2 text-xs hover:bg-[var(--accent)]",r&&"bg-[var(--accent)]"),onClick:()=>v(t.id),children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:(0,U.cn)("inline-block h-2 w-2 rounded-full",0===t.enabled?"bg-[var(--muted-foreground)]":"succeeded"===n?"bg-emerald-500":"running"===n?"bg-amber-400 animate-pulse":"failed"===n||"timeout"===n?"bg-red-500":"bg-[var(--muted-foreground)]")}),(0,l.jsx)("span",{className:"truncate font-medium text-[var(--foreground)]",children:t.label||t.id}),null!=t.activeUntil&&t.activeUntil<=f?(0,l.jsx)("span",{className:"shrink-0 rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("cron.badge.ended")}):null!=t.activeFrom&&t.activeFrom>f?(0,l.jsx)("span",{className:"shrink-0 rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)]",children:e("cron.badge.activeFrom",{date:new Date(t.activeFrom).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"})})}):null]}),(0,l.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{className:"font-mono",children:t.runAt?new Date(t.runAt).toLocaleString():t.schedule}),(0,l.jsx)("span",{children:t.agentId})]}),(0,l.jsx)("div",{className:"mt-0.5 truncate text-[var(--muted-foreground)]",children:t.workspacePath}),t.nextRunAt&&1===t.enabled&&(0,l.jsxs)("div",{className:"mt-0.5 text-[var(--muted-foreground)]",children:[e("cron.next")," ",new Date(t.nextRunAt).toLocaleString()]})]},t.id)}),u&&(0,l.jsx)("li",{ref:e=>{j.current=e},className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:p?e("cron.loading"):e("cron.loadOlder")})]})})]})}var iR=r(88373),i_=r(10969),iz=r(60087),iO=r(82358),iU=r(80566);let iB=(0,d.v)(e=>({selected:null,select:t=>e({selected:t}),clear:()=>e({selected:null})}));function iW(e){let{files:t,group:r,selectedPath:n,onSelect:a,onAction:s}=e,[i,c]=(0,o.useState)(new Set),d=function(e,t){let r={type:"dir",name:"",path:"",children:[]};for(let n of e){let e=n.path.split("/"),a=r;for(let t=0;t<e.length-1;t++){let r=e[t],n=a.path?"".concat(a.path,"/").concat(r):r,s=a.children.find(e=>"dir"===e.type&&e.name===r);s||(s={type:"dir",name:r,path:n,children:[]},a.children.push(s)),a=s}a.children.push({type:"file",name:e[e.length-1],file:n,char:t(n)})}return function e(t){for(let r of t.children)"dir"===r.type&&e(r);for(;1===t.children.length&&"dir"===t.children[0].type&&""!==t.name;){let e=t.children[0];t.name="".concat(t.name,"/").concat(e.name),t.path=e.path,t.children=e.children}}(r),function e(t){for(let r of(t.children.sort((e,t)=>e.type!==t.type?"dir"===e.type?-1:1:e.name.localeCompare(t.name)),t.children))"dir"===r.type&&e(r)}(r),r.children}(t,e=>"staged"===r?e.index:e.workingDir);return(0,l.jsx)("div",{children:d.map(e=>(function e(t,o){let d=12*o+8;if("dir"===t.type){let r=i.has(t.path);return(0,l.jsxs)("div",{children:[(0,l.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,l.jsx)(K.A,{className:"h-3.5 w-3.5 shrink-0"}):(0,l.jsx)(H.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,l.jsx)("span",{className:"truncate",children:t.name})]}),!r&&t.children.map(t=>e(t,o+1))]},"d:".concat(t.path))}let u=L(t.char),m=n===t.file.path,p="staged"===r?iU.A:sG.A,{Icon:x,color:f}=ep(t.file.path);return(0,l.jsxs)("div",{onClick:()=>a(t.file),className:(0,U.cn)("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,l.jsx)(x,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",f)}),(0,l.jsx)("span",{className:"truncate text-[var(--foreground)]",style:{color:u.color},children:t.name}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),s([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,l.jsx)(p,{className:"h-3.5 w-3.5"})}),(0,l.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 iH=r(4704),iK=r(6821);function iG(e){let{projectId:t,onClose:r,onSaved:n}=e,a=(0,ts.kj)(),[s,i]=(0,o.useState)("https");return(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:r,children:(0,l.jsxs)("div",{className:"w-[460px] rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,l.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:a("sc.cred.title")}),(0,l.jsx)("button",{onClick:r,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,l.jsx)(tM.A,{className:"h-4 w-4"})})]}),(0,l.jsx)("div",{className:"flex gap-1 border-b border-[var(--border)] px-4 pt-3",children:["https","ssh"].map(e=>(0,l.jsx)("button",{onClick:()=>i(e),className:(0,U.cn)("rounded-t px-3 py-1.5 text-xs font-medium",s===e?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:"https"===e?a("sc.cred.tabHttps"):a("sc.cred.tabSsh")},e))}),"https"===s?(0,l.jsx)(i$,{onClose:r,onSaved:n}):(0,l.jsx)(iJ,{projectId:t,onClose:r})]})})}let iq="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 i$(e){let{onClose:t,onSaved:r}=e,n=(0,ts.kj)(),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)("github.com"),[m,p]=(0,o.useState)(""),[x,f]=(0,o.useState)(""),[h,g]=(0,o.useState)(!1),[v,b]=(0,o.useState)(null),y=(0,o.useCallback)(()=>{k.F.git.getCredentials().then(e=>s(e.credentials)).catch(()=>s([]))},[]);async function j(){if(!d.trim()||!m.trim()||!x)return void b(n("sc.cred.required"));g(!0),b(null);try{await k.F.git.saveCredentials({host:d.trim(),username:m.trim(),token:x}),f(""),y(),r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function w(e){b(null);try{await k.F.git.deleteCredential(e),y()}catch(e){b(e instanceof Error?e.message:String(e))}finally{c(null)}}return(0,o.useEffect)(()=>{y()},[y]),(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.httpsDesc")}),(0,l.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.configuredList")}),0===a.length?(0,l.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:n("sc.cred.noCredsYet")}):a.map(e=>(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] px-2.5 py-1.5 text-xs",children:[(0,l.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-emerald-400"}),(0,l.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,l.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.host}),(0,l.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e.username})]}),i===e.host?(0,l.jsx)("button",{onClick:()=>w(e.host),className:"shrink-0 rounded bg-red-500/15 px-2 py-0.5 text-[10px] font-medium text-red-400 hover:bg-red-500/25",children:n("sc.cred.confirmDelete")}):(0,l.jsx)("button",{onClick:()=>c(e.host),title:n("sc.cred.delete"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:text-red-400",children:(0,l.jsx)(eQ.A,{className:"h-3 w-3"})})]},e.host))]}),(0,l.jsx)("div",{className:"border-t border-[var(--border)]"}),(0,l.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.addNew")}),(0,l.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.host")}),(0,l.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"github.com",className:iq})]}),(0,l.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.username")}),(0,l.jsx)("input",{type:"text",value:m,onChange:e=>p(e.target.value),autoComplete:"off",className:iq})]}),(0,l.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.token")}),(0,l.jsx)("input",{type:"password",value:x,onChange:e=>f(e.target.value),autoComplete:"new-password",className:iq}),(0,l.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[n("sc.cred.tokenHint")," ",(0,l.jsxs)("a",{href:"https://github.com/settings/tokens",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-0.5 text-[var(--primary)] hover:underline",children:[n("sc.cred.tokenLink"),(0,l.jsx)(iH.A,{className:"h-2.5 w-2.5"})]})]})]})]}),v&&(0,l.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(0,l.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,l.jsx)("button",{onClick:t,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:n("sc.cred.cancel")}),(0,l.jsx)("button",{onClick:j,disabled:h,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:h?n("sc.cred.saving"):n("sc.cred.save")})]})]})}function iJ(e){let{projectId:t,onClose:r}=e,n=(0,ts.kj)(),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)([]),[m,p]=(0,o.useState)("other"),[x,f]=(0,o.useState)(""),[h,g]=(0,o.useState)(!1),[v,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(null),[w,N]=(0,o.useState)(""),[S,C]=(0,o.useState)(!1),[A,I]=(0,o.useState)(null),E=(0,o.useCallback)(()=>{k.F.git.sshKeys().then(e=>s(e.keys)).catch(()=>s([])),k.F.git.sshAgent().then(e=>{c(e.agentRunning),u(e.loadedKeys)}).catch(()=>{}),k.F.git.getRemoteProtocol(t).then(e=>{p(e.protocol),f(e.url)}).catch(()=>{})},[t]);function T(){j(null),N(""),I(null)}async function M(e){C(!0),I(null);try{let r=await k.F.git.unlockSshKey({keyPath:e.path,passphrase:w});if(r.ok)T(),E();else{var t;I(null!=(t=r.error)?t:n("sc.cred.sshUnlockFailed"))}}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}async function F(e){g(!0),b(null);try{let r=await k.F.git.setRemoteProtocol(t,e);p(e),f(r.url)}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}}return(0,o.useEffect)(()=>{E()},[E]),(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,l.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.sshDesc")}),(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5 text-xs",children:[(0,l.jsx)("span",{className:(0,U.cn)("h-2 w-2 rounded-full",i?"bg-emerald-400":"bg-[var(--muted-foreground)]")}),(0,l.jsx)("span",{className:"text-[var(--muted-foreground)]",children:i?n("sc.cred.sshAgentOn",{count:String(d.length)}):n("sc.cred.sshAgentOff")}),(0,l.jsx)("button",{onClick:E,className:"ml-auto rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",title:n("sc.cred.sshRefresh"),children:(0,l.jsx)(at.A,{className:"h-3 w-3"})})]}),(0,l.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.sshKeys")}),0===a.length?(0,l.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:n("sc.cred.sshNoKeys")}):a.map(e=>{let t=d.some(t=>t.includes(e.path)||t.includes(e.name)),r=y===e.path;return(0,l.jsxs)("div",{className:"rounded border border-[var(--border)]",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 text-xs",children:[e.encrypted?(0,l.jsx)(iK.A,{className:"h-3 w-3 shrink-0 text-amber-400"}):(0,l.jsx)(a7.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.name}),t?(0,l.jsx)("span",{className:"ml-auto text-[10px] text-emerald-400",children:n("sc.cred.sshLoaded")}):!r&&(0,l.jsx)("button",{onClick:()=>{j(e.path),N(""),I(null)},className:"ml-auto shrink-0 rounded bg-[var(--secondary)] px-2 py-0.5 text-[10px] font-medium text-[var(--foreground)] hover:opacity-90",children:n("sc.cred.sshUnlock")})]}),!t&&r&&(0,l.jsxs)("div",{className:"flex flex-col gap-1.5 border-t border-[var(--border)] px-2.5 py-2",children:[(0,l.jsx)("span",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:n("sc.cred.sshUnlockHint")}),(0,l.jsx)("input",{type:"password",autoFocus:!0,autoComplete:"off",value:w,onChange:e=>N(e.target.value),onKeyDown:t=>{"Enter"!==t.key||S||M(e)},placeholder:n("sc.cred.sshPassphrase"),className:iq}),A&&(0,l.jsx)("span",{className:"text-[10px] leading-relaxed text-red-400",children:A}),(0,l.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,l.jsx)("button",{onClick:T,disabled:S,className:"rounded px-2 py-0.5 text-[10px] font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)] disabled:opacity-40",children:n("sc.cred.cancel")}),(0,l.jsx)("button",{onClick:()=>M(e),disabled:S,className:"rounded bg-[var(--primary)] px-2 py-0.5 text-[10px] font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:S?n("sc.cred.sshUnlocking"):n("sc.cred.sshUnlock")})]})]})]},e.path)})]}),(0,l.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,l.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n("sc.cred.sshRemote")}),(0,l.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5",children:[(0,l.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",title:x,children:x||"—"}),(0,l.jsx)("div",{className:"ml-auto flex shrink-0 overflow-hidden rounded border border-[var(--border)]",children:["https","ssh"].map(e=>(0,l.jsx)("button",{onClick:()=>F(e),disabled:h||m===e,className:(0,U.cn)("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,l.jsx)("p",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:n("sc.cred.sshRestartNote")}),v&&(0,l.jsx)("p",{className:"text-xs text-red-400",children:v})]}),(0,l.jsx)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:(0,l.jsx)("button",{onClick:r,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:n("sc.cred.close")})})]})}var iZ=r(72526);function iV(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 iY(e){let{info:t}=e,r="tag"===t.kind?iZ.A:iR.A,n="head"===t.kind?"bg-[var(--primary)] text-[var(--primary-foreground)] font-medium":"tag"===t.kind?"bg-amber-400/10 text-amber-300 ring-1 ring-inset ring-amber-400/30":"remote"===t.kind?"text-[var(--muted-foreground)] ring-1 ring-inset ring-[var(--border)]":"bg-[var(--secondary)] text-[var(--foreground)] ring-1 ring-inset ring-[var(--border)]";return(0,l.jsxs)("span",{className:(0,U.cn)("inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] leading-tight",n),children:[(0,l.jsx)(r,{className:"h-2.5 w-2.5 shrink-0"}),(0,l.jsx)("span",{className:"truncate",children:t.label})]})}function iQ(e){let{file:t,active:r,onSelect:n}=e,a=L(t.status),{Icon:s,color:o}=ep(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,l.jsxs)("button",{onClick:n,className:(0,U.cn)("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,l.jsx)(s,{className:(0,U.cn)("h-3.5 w-3.5 shrink-0",o)}),(0,l.jsx)("span",{className:"shrink-0 truncate",style:{color:a.color},children:i}),c&&(0,l.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:c}),(0,l.jsx)("span",{className:"flex-1"}),(0,l.jsx)("span",{className:"w-4 shrink-0 text-center font-mono text-[11px] font-semibold",style:{color:a.color},title:a.label,children:a.letter})]})}function iX(e){let{projectId:t}=e,r=(0,ts.kj)(),n=iB(e=>e.select),a=iB(e=>e.selected),[s,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)(!1),[p,x]=(0,o.useState)(null),[f,h]=(0,o.useState)(50),[g,v]=(0,o.useState)(!1),[b,y]=(0,o.useState)({}),j=(0,o.useRef)(null),w=(0,o.useCallback)(async()=>{try{let e=await k.F.git.log(t,f);i(e.commits),v(e.commits.length>=f),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{m(!0)}},[t,f]);(0,o.useEffect)(()=>{w()},[w]),(0,o.useEffect)(()=>{let e=null,t=C.on("file:changed",t=>{F(t)||(e&&clearTimeout(e),e=setTimeout(()=>{w()},400))}),r=A(C,()=>{w()});return()=>{e&&clearTimeout(e),t(),r()}},[w]),(0,o.useEffect)(()=>{let e=j.current;if(!e||!g)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&h(e=>e+50)});return t.observe(e),()=>t.disconnect()},[g]);let N=(0,o.useCallback)(e=>{x(t=>t===e?null:e),y(r=>(r[e]||k.F.git.commitFiles(t,e).then(t=>y(r=>({...r,[e]:t.files}))).catch(()=>y(t=>({...t,[e]:[]}))),r))},[t]);return c?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:c}):u&&0===s.length?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:r("sc.noCommits")}):(0,l.jsxs)("div",{className:"py-1",children:[s.map((e,t)=>{let s=0===t,o=p===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(iV).filter(e=>null!==e):[];return(0,l.jsxs)("div",{className:"flex px-3",children:[(0,l.jsxs)("div",{className:"relative shrink-0",style:{width:24},children:[!s&&(0,l.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:0,height:16}}),(0,l.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:16,bottom:0}}),(0,l.jsx)("div",{className:(0,U.cn)("absolute left-1/2 z-10 -translate-x-1/2 rounded-full",s&&"border-2 bg-[var(--background)]"),style:{top:11,width:10,height:10,...s?{borderColor:i}:{backgroundColor:i}},title:e.pushed?r("sc.pushed"):r("sc.unpushed")})]}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsxs)("div",{onClick:()=>N(e.hash),className:(0,U.cn)("cursor-pointer rounded-sm py-2",o?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),children:[(0,l.jsx)("div",{className:"truncate text-xs leading-4 text-[var(--foreground)]",children:e.message}),(0,l.jsxs)("div",{className:"mt-1 flex items-center gap-1.5 text-[10px] text-[var(--muted-foreground)]",children:[(0,l.jsx)("span",{className:"font-mono",children:e.shortHash}),(0,l.jsx)("span",{className:"truncate",children:e.author}),(0,l.jsxs)("span",{className:"shrink-0",children:["\xb7 ",(0,U.fw)(e.date)]})]}),d.length>0&&(0,l.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:d.map(e=>(0,l.jsx)(iY,{info:e},"".concat(e.kind,":").concat(e.label)))})]}),o&&(0,l.jsx)("div",{className:"mb-1 ml-1 border-l border-[var(--border)] pl-2",children:void 0===c?(0,l.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:"…"}):0===c.length?(0,l.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:r("sc.noCommitFiles")}):c.map(t=>(0,l.jsx)(iQ,{file:t,active:(null==a?void 0:a.commit)===e.hash&&a.path===t.path,onSelect:()=>n({path:t.path,staged:!1,from:t.from,commit:e.hash})},t.path))})]})]},e.hash)}),g&&(0,l.jsx)("div",{ref:j,className:"h-4"})]})}function i0(e){return/authentication|could not read username|permission denied|publickey|passphrase|\b401\b|\b403\b/i.test(e)}function i1(){var e,t,r;let n=(0,ts.kj)(),a=rT(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),s=iB(e=>e.selected),i=iB(e=>e.select),c=iB(e=>e.clear),[d,u]=(0,o.useState)(null),[m,p]=(0,o.useState)(null),[x,f]=(0,o.useState)(!1),[h,g]=(0,o.useState)(""),[v,b]=(0,o.useState)(!1),[y,j]=(0,o.useState)(null),[w,N]=(0,o.useState)(!1),[S,I]=(0,o.useState)(!1),[E,T]=(0,o.useState)(!1),[M,P]=(0,o.useState)("changes"),[D,L]=(0,o.useState)(null),[z,O]=(0,o.useState)(""),B=(0,o.useCallback)(async()=>{if(a)try{let e=await k.F.git.status(a);if(!1===e.isRepo){f(!0),u(null),L(null),p(null);return}u(e),f(!1),p(null);let t=await k.F.git.remotes(a);L(t.remotes)}catch(e){p(e instanceof Error?e.message:String(e))}},[a]);(0,o.useEffect)(()=>{B()},[B]),(0,o.useEffect)(()=>{if(!a)return;let e=null,t=C.on("file:changed",t=>{F(t)||(e&&clearTimeout(e),e=setTimeout(()=>{B()},400))}),r=A(C,()=>{B()});return()=>{e&&clearTimeout(e),t(),r()}},[a,B]);let W=null!=(e=null==d?void 0:d.files)?e:[],G=W.filter(e=>R(e.index)),q=W.filter(e=>_(e.workingDir));async function $(e){b(!0),j(null);try{await e(),await B()}catch(e){j(e instanceof Error?e.message:String(e))}finally{b(!1)}}let J=(0,o.useCallback)((e,t)=>{i({path:e.path,staged:t,from:e.from})},[i]);function Z(e){$(()=>k.F.git.stage(a,e))}function V(e){$(()=>k.F.git.unstage(a,e))}async function Y(){a&&h.trim()&&await $(async()=>{await k.F.git.commit(a,h),g(""),c()})}function Q(){a&&z.trim()&&$(async()=>{await k.F.git.addRemote(a,z.trim()),O("")})}let X=(null!=(t=null==D?void 0:D.length)?t:0)>0;return a?x?(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 bg-[var(--background)] p-6 text-center",children:[(0,l.jsx)(t$.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"max-w-[240px] text-xs text-[var(--muted-foreground)]",children:n("sc.initRepoDesc")}),(0,l.jsxs)("button",{onClick:function(){$(()=>k.F.git.init(a))},disabled:v,className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,l.jsx)(t$.A,{className:"h-3.5 w-3.5"}),n(v?"sc.initializing":"sc.initRepo")]}),y&&(0,l.jsx)("p",{className:"max-w-[240px] text-[11px] text-red-400",children:y})]}):(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(iR.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:n("nav.sourceControl")}),(0,l.jsx)("div",{className:"flex-1"}),(0,l.jsxs)("div",{className:"flex items-center rounded border border-[var(--border)]",children:[(0,l.jsx)("button",{onClick:()=>P("changes"),title:n("sc.viewChanges"),className:(0,U.cn)("rounded-l p-1","changes"===M?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(i_.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:()=>P("graph"),title:n("sc.viewGraph"),className:(0,U.cn)("rounded-r p-1","graph"===M?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,l.jsx)(iz.A,{className:"h-3.5 w-3.5"})})]}),(0,l.jsx)("button",{onClick:()=>N(!0),title:n("sc.cred.title"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(er.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:()=>{B()},title:n("sc.refresh"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,l.jsx)(at.A,{className:(0,U.cn)("h-3.5 w-3.5",v&&"animate-spin")})})]}),(0,l.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--border)] px-3 py-1.5",children:[(0,l.jsx)(iR.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,l.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,l.jsxs)("span",{className:"flex items-center gap-1 text-[10px] text-[var(--muted-foreground)]",children:[d.behind>0&&(0,l.jsxs)("span",{className:"flex items-center",children:[(0,l.jsx)(iO.A,{className:"h-3 w-3"}),d.behind]}),d.ahead>0&&(0,l.jsxs)("span",{className:"flex items-center",children:[(0,l.jsx)(lk.A,{className:"h-3 w-3"}),d.ahead]})]}),(0,l.jsx)("div",{className:"flex-1"}),X&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{onClick:()=>void $(()=>k.F.git.pull(a)),disabled:v,title:n("sc.pull"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,l.jsx)(iO.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("button",{onClick:()=>void $(()=>k.F.git.push(a)),disabled:v,title:n("sc.push"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,l.jsx)(lk.A,{className:"h-3.5 w-3.5"})})]})]}),!X&&"changes"===M&&(0,l.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-[var(--muted-foreground)]",children:[(0,l.jsx)(lM.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,l.jsx)("span",{children:n("sc.addRemoteDesc")})]}),(0,l.jsx)("input",{type:"text",value:z,onChange:e=>O(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z.trim()&&Q()},placeholder:n("sc.remotePlaceholder"),autoComplete:"off",className:"rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 font-mono text-[11px] text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,l.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,l.jsx)(lM.A,{className:"h-3.5 w-3.5"})," ",n(v?"sc.adding":"sc.addRemote")]})]}),"changes"===M&&(0,l.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,l.jsx)("textarea",{value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),Y())},placeholder:n("sc.commitPlaceholder"),rows:2,className:"resize-none rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,l.jsxs)("button",{onClick:()=>void Y(),disabled:v||!h.trim()||0===G.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,l.jsx)(rw.A,{className:"h-3.5 w-3.5"})," ",n("sc.commit")]})]}),y&&(0,l.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-red-500/10 px-3 py-2 text-[11px] text-red-400",children:[i0(y)?n("sc.authError"):y,i0(y)&&(0,l.jsx)("button",{onClick:()=>N(!0),className:"ml-1 underline hover:text-red-300",children:n("sc.openCreds")})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto",children:"graph"===M?(0,l.jsx)(iX,{projectId:a}):m?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:m}):0===W.length?(0,l.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:n("sc.clean")}):(0,l.jsxs)(l.Fragment,{children:[G.length>0&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,l.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:[S?(0,l.jsx)(K.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(H.A,{className:"h-3.5 w-3.5"}),n("sc.staged")]}),(0,l.jsx)("button",{onClick:()=>V(G.map(e=>e.path)),title:n("sc.unstageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,l.jsx)(iU.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:G.length})]}),!S&&(0,l.jsx)(iW,{files:G,group:"staged",selectedPath:(null==s?void 0:s.staged)?s.path:null,onSelect:e=>J(e,!0),onAction:V})]}),q.length>0&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,l.jsxs)("button",{onClick:()=>T(e=>!e),className:"flex flex-1 items-center gap-1 text-[11px] font-semibold uppercase tracking-wide text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[E?(0,l.jsx)(K.A,{className:"h-3.5 w-3.5"}):(0,l.jsx)(H.A,{className:"h-3.5 w-3.5"}),n("sc.changes")]}),(0,l.jsx)("button",{onClick:()=>Z(q.map(e=>e.path)),title:n("sc.stageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,l.jsx)(sG.A,{className:"h-3.5 w-3.5"})}),(0,l.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:q.length})]}),!E&&(0,l.jsx)(iW,{files:q,group:"changes",selectedPath:s&&!s.staged?s.path:null,onSelect:e=>J(e,!1),onAction:Z})]})]})}),w&&(0,l.jsx)(iG,{projectId:a,onClose:()=>N(!1),onSaved:()=>{}})]}):(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] p-6 text-center",children:[(0,l.jsx)(iR.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:n("sc.noWorkspace")})]})}var i3=r(34016);function i5(){let e=(0,ts.kj)(),t=rT(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),r=iB(e=>e.selected),[n,a]=(0,o.useState)(null),[s,i]=(0,o.useState)(!1),[c,d]=(0,o.useState)(null);return((0,o.useEffect)(()=>{if(!t||!r)return void a(null);let e=!1;return i(!0),d(null),k.F.git.diff(t,r.path,r.staged,r.from,r.commit).then(t=>{e||a({original:t.original,modified:t.modified,path:r.path})}).catch(t=>{e||d(t instanceof Error?t.message:String(t))}).finally(()=>{e||i(!1)}),()=>{e=!0}},[t,r]),r)?(0,l.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,l.jsxs)("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,l.jsx)(i3.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,l.jsx)("span",{className:"truncate text-xs text-[var(--foreground)]",children:r.path}),(0,l.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,l.jsx)("div",{className:"flex-1 overflow-hidden",children:s?(0,l.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("sc.loadingDiff")}):c?(0,l.jsx)("div",{className:"px-4 py-3 text-xs text-red-400",children:c}):n?(0,l.jsx)(tE,{original:n.original,modified:n.modified,path:n.path}):null})]}):(0,l.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] text-center",children:[(0,l.jsx)(i3.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,l.jsx)("p",{className:"mt-2 text-sm text-[var(--muted-foreground)]",children:e("sc.selectFile")})]})}var i2=r(6023),i4=r(83599),i8=r(62803),i6=r(28109),i9=r(81208);function i7(e){let{expanded:t,title:r,desc:n}=e;return(0,l.jsxs)("span",{className:(0,U.cn)("min-w-0 flex-1 whitespace-nowrap pr-3 text-left transition-opacity duration-150 ease-out motion-reduce:transition-none",t?"opacity-100":"opacity-0"),children:[(0,l.jsx)("span",{className:"block truncate text-sm leading-5 text-[var(--foreground)]",children:r}),(0,l.jsx)("span",{className:"block truncate text-[11px] leading-4 text-[var(--muted-foreground)]",children:n})]})}let ce="text-[var(--muted-foreground)]/40",ct={fresh:"text-emerald-400",stale:"text-amber-400 animate-pulse",down:"text-[var(--destructive)]"};function cr(e){return window[e]}function cn(e){let[t,r]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let t=cr(e);t&&t.get().then(r)},[e]);let n=(0,o.useCallback)(()=>{let t=cr(e);t&&t.toggle().then(r)},[e]);return{available:!!cr(e),on:t,toggle:n}}function ca(e){let{items:t,expanded:r=!1,onOpenChange:n}=e,a=(0,ts.kj)(),[s,i]=(0,o.useState)(!1);(0,o.useEffect)(()=>{null==n||n(s)},[s,n]);let c=(0,o.useRef)(null),d=t.filter(e=>e.available),u=d.some(e=>e.alert);(0,o.useEffect)(()=>{if(!s)return;let e=e=>{var t;(null==(t=c.current)?void 0:t.contains(e.target))||i(!1)},t=e=>{"Escape"===e.key&&i(!1)};return document.addEventListener("mousedown",e),window.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("keydown",t)}},[s]);let m=e=>"string"==typeof e.state?e.state:a(e.state?"quick.on":"quick.off"),p="".concat(a("quick.title")," — ").concat(d.map(e=>"".concat(e.label," ").concat(m(e))).join(" \xb7 "));return(0,l.jsxs)("div",{ref:c,className:"relative w-full",children:[(0,l.jsxs)("button",{onClick:()=>i(e=>!e),title:p,"aria-expanded":s,className:(0,U.cn)("flex h-12 w-full items-center overflow-hidden transition-colors",u?"text-[var(--destructive)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",s&&"bg-[var(--secondary)]"),children:[(0,l.jsxs)("span",{className:"flex w-12 shrink-0 flex-col items-center justify-center gap-1",children:[(0,l.jsx)(er.A,{className:"h-5 w-5"}),(0,l.jsx)("span",{className:"flex h-[3px] w-[30px] gap-[2px]",children:d.map(e=>(0,l.jsx)("span",{"data-segment":e.id,className:(0,U.cn)("flex-1 rounded-full bg-current",e.color)},e.id))})]}),(0,l.jsx)(i7,{expanded:r,title:a("quick.title"),desc:a("nav.desc.quick")})]}),s&&(0,l.jsxs)("div",{className:"absolute bottom-0 left-full z-[60] ml-1 w-[260px] rounded-lg border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:[(0,l.jsx)("div",{className:"px-3 py-1.5 text-[10px] font-medium uppercase tracking-wider text-[var(--muted-foreground)]",children:a("quick.panelTitle")}),d.map((e,t)=>{let r=e.icon,n=(0,l.jsxs)("div",{className:"min-w-0 flex-1 text-left",children:[(0,l.jsx)("div",{className:"truncate text-xs text-[var(--foreground)]",children:e.title}),(0,l.jsx)("div",{className:"text-[10px] text-[var(--muted-foreground)]",children:e.subtitle})]}),a=t>0&&e.onToggle&&!d[t-1].onToggle?(0,l.jsx)("div",{className:"my-1 border-t border-[var(--border)]"}):null;if(!e.onToggle)return(0,l.jsxs)("div",{"data-row":e.id,className:"flex items-center gap-3 px-3 py-2",children:[(0,l.jsx)(r,{className:(0,U.cn)("h-4 w-4 shrink-0",e.color)}),n,(0,l.jsx)("span",{className:(0,U.cn)("shrink-0 text-[11px]",e.color),children:m(e)})]},e.id);let s=!0===e.state,o=s?lz.A:l_.A;return(0,l.jsxs)("div",{children:[a,(0,l.jsxs)("button",{"data-row":e.id,role:"switch","aria-checked":s,onClick:e.onToggle,className:"flex w-full items-center gap-3 px-3 py-2 transition-colors hover:bg-[var(--secondary)]",children:[(0,l.jsx)(r,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),n,(0,l.jsx)(o,{className:(0,U.cn)("h-5 w-5 shrink-0",s?e.color:"text-[var(--muted-foreground)]")})]})]},e.id)})]})]})}let cs=null;function cl(){return cs?"[".concat(cs,"] "):""}let co=["explorer","source-control","sessions","skills","channels","evolution","cron"],ci=null;function cc(e){var t,r;let{linkState:n}=e,a=(0,ts.kj)(),s=rT(e=>e.activeProject),d=rT(e=>e.openFolder),u=nf(e=>e.isStreaming),[m,p]=(0,o.useState)(()=>localStorage.getItem("halo_sidebar_tab")||"explorer"),[x,f]=(0,o.useState)(()=>"false"!==localStorage.getItem("halo_sidebar_open")),[h,g]=(0,o.useState)("sessions"===m);"sessions"!==m||h||g(!0);let[v,b]=(0,o.useState)(""),[j,w]=(0,o.useState)(!1),{items:N,notifyOnFinish:S}=function(e){let t=(0,ts.kj)(),r=cn("haloPin"),n=cn("haloAwake"),a=!!window.haloNotify||"Notification"in window,[s,l]=(0,o.useState)(()=>"true"===localStorage.getItem("halo_notify_on_finish")),i=(0,o.useCallback)(async()=>{let e=!!window.haloNotify;if(!s&&!e&&"Notification"in window){let e=Notification.permission;if("default"===e&&(e=await Notification.requestPermission()),"granted"!==e)return}l(e=>{let t=!e;try{localStorage.setItem("halo_notify_on_finish",String(t))}catch(e){}return t})},[s]);return{items:[{id:"network",icon:"down"===e?i2.A:i4.A,label:t("quick.network"),title:t("quick.networkTitle"),subtitle:t("quick.networkSub"),state:t("link.".concat(e)),color:ct[e],available:!0,alert:"down"===e},{id:"notify",icon:i8.A,label:t("quick.notify"),title:t("quick.notifyTitle"),subtitle:t("quick.notifySub"),state:s,color:s?"text-[var(--primary)]":ce,onToggle:()=>{i()},available:a},{id:"pin",icon:i6.A,label:t("quick.pin"),title:t("quick.pinTitle"),subtitle:t("quick.pinSub"),state:r.on,color:r.on?"text-[var(--primary)]":ce,onToggle:r.toggle,available:r.available},{id:"awake",icon:i9.A,label:t("quick.awake"),title:t("quick.awakeTitle"),subtitle:t("quick.awakeSub"),state:n.on,color:n.on?"text-amber-400":ce,onToggle:n.toggle,available:n.available}],notifyOnFinish:s}}(n),[I,T]=(0,o.useState)(!1),M=sV(I),P=M.close;(0,o.useEffect)(()=>{if(!M.open)return;let e=e=>{"Escape"===e.key&&P()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M.open,P]),(0,o.useEffect)(()=>{let e=null==s?void 0:s.name;document.title=cl()+(e?"".concat(u?"● ":"","Halo — ").concat(e):"Halo")},[u,null==s?void 0:s.name]);let D=t6(),[L,z]=(0,o.useState)(null);!D&&L&&z(null),(0,o.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>z(null),8e3);return()=>clearTimeout(e)},[L]),(0,o.useEffect)(()=>{if(S){var e;return e=e=>{!function(){try{let e=window.AudioContext||window.webkitAudioContext;if(!e)return;ci||(ci=new e);let t=ci;t.resume();let r=t.currentTime;[[880,0],[1174.66,.15]].forEach(e=>{let[n,a]=e,s=t.createOscillator(),l=t.createGain();s.type="sine",s.frequency.value=n,l.gain.setValueAtTime(1e-4,r+a),l.gain.exponentialRampToValueAtTime(.2,r+a+.02),l.gain.exponentialRampToValueAtTime(1e-4,r+a+.35),s.connect(l).connect(t.destination),s.start(r+a),s.stop(r+a+.4)})}catch(e){}}();let t=e.getState().sessionId,r=t?sY.get(t):void 0;if(t&&t8()&&z(e=>{var n;return{sessionIds:[t,...(null!=(n=null==e?void 0:e.sessionIds)?n:[]).filter(e=>e!==t)],title:r}}),document.hasFocus())return;let n=null==s?void 0:s.name,l=n?"Halo — ".concat(n):"Halo",o=r?a("status.notifyBodySession",{title:r}):a("status.notifyBody"),i=window.haloNotify;if(i)i.notify({title:l,body:o});else if("Notification"in window&&"granted"===Notification.permission){let e=new Notification(l,{body:o});e.onclick=()=>{window.focus(),e.close()}}},no.add(e),()=>{no.delete(e)}}},[S,null==s?void 0:s.name,a]),(0,o.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("folder"),t=async(e,t)=>{try{let n=await k.F.fs.resolveWorkspace(e);d(n.path,n.id),b(n.path),E(n.path);try{localStorage.setItem("halo_last_folder",n.path)}catch(e){}var r=n.path;let a=lA().filter(e=>e!==r);if(a.unshift(r),lI(a.slice(0,8)),t||n.path!==e){let e=new URL(window.location.href);e.searchParams.set("folder",n.path),window.history.replaceState({},"",e.toString())}}catch(e){return console.error("[Workspace] Failed to resolve workspace:",e),!1}return!0};if(e)t(e,!1);else{let e=(()=>{try{return localStorage.getItem("halo_last_folder")}catch(e){return null}})(),r=()=>k.F.fs.home().then(e=>{let{home:r}=e;return t(r,!0)}).catch(e=>{console.error("[Workspace] Failed to resolve home dir:",e)});e?t(e,!0).then(e=>{e||r()}):r()}},[]),(0,o.useEffect)(()=>{eS()},[]);let B=(0,o.useRef)(!1);(0,o.useEffect)(()=>{function e(e){B.current||("web"===eE()||0!==y.getState().modifiedPaths.size)&&e.preventDefault()}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let W=(0,o.useCallback)(()=>{let e=y.getState(),t=e.activeTab;if(!t)return!1;let r=e.tabs.find(e=>e.path===t);return(async()=>{(null==r||!r.modified||await (0,U.fN)('"'.concat(r.path.split("/").pop(),'" has unsaved changes. Close anyway?')))&&e.closeTab(t)})(),!0},[]);(0,o.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&"p"===e.key&&(e.preventDefault(),w(e=>!e)),(e.metaKey||e.ctrlKey)&&"`"===e.key){e.preventDefault();let t=y.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,o.useEffect)(()=>{let e=window.haloCloseShortcut;e&&e.onTrigger(()=>{W()||e.closeWindow()})},[W]),(0,o.useEffect)(()=>{function e(e){if("Escape"!==e.key||!y.getState().maximized)return;let t=document.activeElement;if(t){let e=t.tagName;if("INPUT"===e||"TEXTAREA"===e||t.isContentEditable||t.closest(".monaco-editor"))return}j||y.getState().setMaximized(!1)}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j]),(0,o.useEffect)(()=>{let e=e=>{let t=e.detail;if(!(null==t?void 0:t.tab))return;let{bottomFloating:r}=y.getState();r&&"explorer"===t.tab||(p(t.tab),f(!0))};return window.addEventListener("halo:navigate",e),()=>window.removeEventListener("halo:navigate",e)},[]),(0,o.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,o.useEffect)(()=>{localStorage.setItem("halo_sidebar_tab",m),localStorage.setItem("halo_sidebar_open",String(x))},[m,x]);let H=(0,o.useRef)(!1);async function K(e){let t=e.trim();if(!t||H.current)return;H.current=!0;try{let e=await k.F.fs.exists(t);if(!e.exists||!e.isDirectory){window.alert("Workspace not found: ".concat(t)),H.current=!1;return}}catch(e){window.alert(e instanceof Error?e.message:"Failed to validate path"),H.current=!1;return}let r=y.getState().tabs.filter(e=>e.modified);if(r.length>0){let e=r.map(e=>e.path.split("/").pop()).join(", ");if(!await (0,U.fN)("Unsaved changes in ".concat(e," will be lost. Switch workspace anyway?"))){H.current=!1;return}}B.current=!0;try{localStorage.setItem("halo_last_folder",t)}catch(e){}let n=new URL(window.location.href);n.searchParams.set("folder",t),window.location.href=n.toString()}let G=(0,o.useCallback)(async e=>{let t=null==s?void 0:s.id;if(t){if(y.getState().tabs.find(t=>t.path===e))return void y.getState().setActiveTab(e);try{let r=await k.F.files.read(e,t),n=(0,U.sQ)(e);y.getState().openFile(e,r.content,n)}catch(e){console.error("[QuickOpen] Failed to read file:",e)}}},[s]),q=[{id:"explorer",icon:lE.A,label:a("nav.explorer")},{id:"sessions",icon:ae.A,label:a("nav.sessions")},{id:"source-control",icon:iR.A,label:a("nav.sourceControl")},{id:"management",icon:ar.A,label:"Agents"},{id:"skills",icon:lR.A,label:"Skills"},{id:"channels",icon:oF.A,label:a("nav.channels")},{id:"evolution",icon:a6.A,label:"Evolution"},{id:"cron",icon:iC.A,label:"Cron"},{id:"settings",icon:oa.A,label:a("nav.settings"),position:"bottom"}],$=null!=(t=null==s?void 0:s.id)?t:null;(0,o.useEffect)(()=>{if(!$)return;let{setForProject:e,clearProject:t,setRepoStatus:r,clearRepoStatus:n}=O.getState(),a=!1;async function s(){try{let[n,s]=await Promise.all([k.F.git.status($),k.F.git.ignored($)]);if(!1===n.isRepo){a||(t($),r($,!1));return}a||(e($,function(e,t){let r=new Map,n=new Map;for(let t of e){var a,s;let e=(a=t.index,_(s=t.workingDir)?"?"===s?"?":s:R(a)?a:"");if(!e)continue;r.set(t.path,e);let l=t.path.split("/");for(let t=0;t<l.length-1;t++){let r=l.slice(0,t+1).join("/"),a=n.get(r);void 0===a?n.set(r,e):a!==e&&"*"!==a&&n.set(r,"*")}}return{files:r,dirs:n,ignored:new Set(t)}}(n.files,s.ignored)),r($,!0))}catch(e){a||(t($),r($,!1))}}s();let l=null,o=C.on("file:changed",e=>{F(e)||(l&&clearTimeout(l),l=setTimeout(()=>{s()},400))}),i=A(C,()=>{s()});return()=>{a=!0,l&&clearTimeout(l),o(),i(),t($),n($)}},[$]);let J=O(e=>{var t;return null!=(t=$?e.repoStatus[$]:void 0)?t:"unknown"}),Z=q.filter(e=>"bottom"!==e.position).filter(e=>"source-control"!==e.id||!1!==J),V=q.filter(e=>"bottom"===e.position),Y=y(e=>e.maximized),Q=y(e=>e.bottomFloating),X=y(e=>e.bottomMaximized),ee=x&&!Y,et=co.includes(m)&&x&&"explorer"!==m,er="explorer"===m;(0,o.useEffect)(()=>{!1===J&&"source-control"===m&&p("explorer")},[J,m]);let[en]=(0,o.useState)(()=>{if("undefined"==typeof document)return null;let e=document.createElement("div");return e.className="h-full",e}),ea=(0,o.useRef)(null),[es,el]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),[ec,ed]=(0,o.useState)(null),eu=Q?ec:X?eo:es;(0,o.useLayoutEffect)(()=>{en&&eu&&en.parentElement!==eu&&eu.appendChild(en)},[en,eu]);let em=e=>{let t=e.icon,r=m===e.id;return(0,l.jsxs)("button",{onClick:()=>{var t;t=e.id,y.getState().maximized&&y.getState().setMaximized(!1),m===t&&x?f(!1):(p(t),f(!0)),M.close()},"aria-label":e.label,className:(0,U.cn)("relative flex h-12 w-full shrink-0 items-center overflow-hidden transition-colors hover:text-[var(--foreground)]",r?"text-[var(--foreground)]":"text-[var(--muted-foreground)]"),children:[r&&(0,l.jsx)("div",{className:"absolute left-0 top-1/2 h-6 w-0.5 -translate-y-1/2 rounded-r bg-[var(--primary)]"}),(0,l.jsx)("span",{className:"flex w-12 shrink-0 justify-center",children:(0,l.jsx)(t,{className:"h-5 w-5"})}),(0,l.jsx)(i7,{expanded:M.open,title:e.label,desc:a("nav.desc.".concat(e.id))})]},e.id)};return(0,l.jsxs)("div",{className:"flex h-full",children:[(0,l.jsx)("div",{className:(0,U.cn)("relative w-12 shrink-0",Y&&"hidden"),children:(0,l.jsxs)("div",{...M.bind,className:(0,U.cn)("absolute inset-y-0 left-0 flex flex-col border-r border-[var(--border)] bg-[var(--card)] py-2 transition-[width,box-shadow] duration-150 ease-out motion-reduce:transition-none",M.open?"w-60 shadow-[6px_0_16px_-6px_rgba(0,0,0,0.35)]":"w-12",I?"z-[60]":"z-[45]"),children:[Z.map(em),(0,l.jsx)("div",{className:"flex-1"}),V.map(em),(0,l.jsx)(ca,{items:N,expanded:M.open,onOpenChange:T})]})}),(0,l.jsx)("div",{className:(0,U.cn)("flex min-w-0 flex-1",!er&&"hidden",Y&&"fixed inset-0 z-40 bg-[var(--background)]"),children:(0,l.jsx)(cd,{showSidebar:ee,sidebar:(0,l.jsx)(lF,{projectId:$,pathInput:v,onPathInputChange:b,onOpenFolder:function(){K(v)},onOpenPath:K,activeProject:s}),main:(0,l.jsx)(cu,{projectId:$,showBottom:!Q&&!Y,bottomSlotRef:el})})}),h&&(0,l.jsx)("div",{className:(0,U.cn)("flex min-w-0 flex-1",("sessions"!==m||Y)&&"hidden"),children:(0,l.jsx)(cd,{autoSaveId:"halo-h-sessions",showSidebar:x,sidebar:(0,l.jsx)(ad,{}),main:(0,l.jsx)(on,{visible:"sessions"===m&&!Y})})}),!er&&"sessions"!==m&&!Y&&(et?(0,l.jsxs)(c.YZ,{direction:"horizontal",autoSaveId:"halo-h-sidebar",className:"flex-1",children:[(0,l.jsx)(c.Zk,{defaultSize:22,minSize:15,maxSize:40,children:(0,l.jsxs)("div",{className:"h-full overflow-hidden",children:["source-control"===m&&(0,l.jsx)(i1,{}),"skills"===m&&(0,l.jsx)(lK,{}),"channels"===m&&(0,l.jsx)(ii,{}),"evolution"===m&&(0,l.jsx)(ij,{}),"cron"===m&&(0,l.jsx)(iL,{})]})}),(0,l.jsx)(c.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,l.jsx)(c.Zk,{defaultSize:78,minSize:40,children:(0,l.jsx)(cm,{activeTab:m})})]}):(0,l.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,l.jsx)(cm,{activeTab:m})})),j&&(0,l.jsx)(lN,{onSelect:G,onClose:()=>w(!1)}),Q&&(0,l.jsx)("div",{className:D?"hidden":"contents",children:(0,l.jsx)(ly,{slotRef:ed,dragHandleRef:ea})}),D&&L&&(0,l.jsxs)("div",{role:"status",onMouseDown:e=>e.preventDefault(),className:"fixed right-4 top-14 z-[80] flex max-w-[360px] items-center gap-3 rounded-lg border border-[var(--border)] bg-[var(--card)] px-3 py-2 text-xs text-[var(--foreground)] shadow-lg",children:[(0,l.jsx)("span",{className:"min-w-0 flex-1 truncate",children:L.sessionIds.length>1?a("editor.immersive.repliedMany",{count:L.sessionIds.length}):a("editor.immersive.replied",{title:null!=(r=L.title)?r:a("chat.tabs.untitled")})}),(0,l.jsx)("button",{type:"button",onClick:()=>{var e;return e=L.sessionIds[0],void(z(null),re({refocus:!1}),nD(e),y.getState().setBottomTab("chat"),requestAnimationFrame(()=>window.dispatchEvent(new CustomEvent("halo:focus-chat-input"))))},className:"shrink-0 font-medium text-[var(--primary)] hover:underline",children:a("editor.immersive.backToChat")})]}),X&&!Q&&(0,l.jsx)("div",{ref:ei,className:"fixed inset-0 z-50 bg-[var(--background)]"}),en&&(0,i.createPortal)((0,l.jsx)(lv,{floating:Q,dragHandleRef:ea}),en)]})}function cd(e){let{showSidebar:t,sidebar:r,main:n,autoSaveId:a="halo-h-sidebar"}=e,s=(0,o.useRef)(null),i=(0,o.useRef)([22,78]);return(0,o.useEffect)(()=>{let e=s.current;if(e)if(t)e.setLayout(i.current);else{let t=e.getLayout();t[0]>0&&(i.current=t),e.setLayout([0,100])}},[t]),(0,l.jsxs)(c.YZ,{ref:s,direction:"horizontal",autoSaveId:a,className:"flex-1",children:[(0,l.jsx)(c.Zk,{defaultSize:22,minSize:0,maxSize:40,collapsible:!0,children:(0,l.jsx)("div",{className:(0,U.cn)("h-full overflow-hidden",!t&&"hidden"),children:r})}),(0,l.jsx)(c.TW,{className:(0,U.cn)("w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors",!t&&"pointer-events-none opacity-0")}),(0,l.jsx)(c.Zk,{defaultSize:78,minSize:40,children:n})]})}function cu(e){let{projectId:t,showBottom:r,bottomSlotRef:n}=e,a=(0,o.useRef)(null),s=(0,o.useRef)([65,35]);return(0,o.useEffect)(()=>{let e=a.current;if(e)if(r)e.setLayout(s.current);else{let t=e.getLayout();t[1]>0&&(s.current=t),e.setLayout([100,0])}},[r]),(0,l.jsxs)(c.YZ,{ref:a,direction:"vertical",autoSaveId:"halo-v-editor",className:"h-full",children:[(0,l.jsx)(c.Zk,{defaultSize:65,minSize:20,children:(0,l.jsx)(rU,{projectId:t,mode:"editor-only"})}),(0,l.jsx)(c.TW,{className:(0,U.cn)("h-px bg-[var(--border)] hover:h-1 hover:bg-[var(--primary)] transition-colors",!r&&"pointer-events-none opacity-0")}),(0,l.jsx)(c.Zk,{defaultSize:35,minSize:0,collapsible:!0,children:(0,l.jsx)("div",{ref:n,className:(0,U.cn)("h-full",!r&&"hidden")})})]})}function cm(e){let{activeTab:t}=e;return"source-control"===t?(0,l.jsx)(i5,{}):"management"===t?(0,l.jsx)(l6,{}):"skills"===t?(0,l.jsx)(l7,{}):"channels"===t?(0,l.jsx)(ic,{}):"evolution"===t?(0,l.jsx)(ix,{}):"cron"===t?(0,l.jsx)(iE,{}):"settings"===t?(0,l.jsx)(ov,{}):null}var cp=r(45966),cx=r(42883);let cf=/<<<SHOW:([\s\S]*?)>>>/g,ch="[Face snapshot]",cg=null;async function cv(e,t,r){let n=t.getState(),a=n.screenSource,s=n.cameraSource,l=a?aT():void 0,o=s?aM():void 0,i=[];l&&i.push("screen"),o&&i.push("camera");let c=function(e,t){let r=new Set,n=!1;for(let a of e)for(let e of a.content.matchAll(au))if(n=!0,e[1])r.add(e[1]);else for(let e of t)r.add(e);if(!n)return[];let a=t.filter(e=>r.has(e));return a.length>0?a:t}(r,i);if(0===c.length)return;let d=rT.getState().activeProject,u=n.sessionId;if(!d||!u)return;let m=(0,U.$C)(),p="undefined"!=typeof localStorage&&"zh"===localStorage.getItem("halo_lang")?cx.zh:cp.en,x="image/jpeg",f=await Promise.all(c.map(async e=>{let t="camera"===e?s:a,r=null;try{r="camera"===e?await o.snap(t.id||void 0):await l.grab(t.id)}catch(e){r=null}return r?{base64:r,note:"[\uD83D\uDCF7 ".concat(t.name,"]"),msg:"camera"===e?"[Photo from the camera]":'[Screenshot of "'.concat(t.name,'"]')}:{base64:null,note:p["camera"===e?"capture.cameraFailNote":(null==l?void 0:l.web)?"capture.webFailNote":"capture.failNote"].replace("{name}",t.name),msg:"camera"===e?"[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.]":(null==l?void 0:l.web)?"[Could not capture the shared screen — sharing may have stopped, or the shared window is minimized. Ask the user to check, then request the capture again.]":'[Could not capture "'.concat(t.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.]')}})),h=f.flatMap(e=>e.base64?[e.base64]:[]);n.addMessage({id:(0,U.$C)(),role:"user",content:f.map(e=>e.note).join("\n"),timestamp:Date.now(),clientMsgId:m,...h.length>0?{localImages:h.map(e=>"data:".concat(x,";base64,").concat(e))}:{}}),n.addMessage({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let g=n.selectedAgentId;e.send({type:"chat",sessionId:u,projectId:d.id,message:f.map(e=>e.msg).join("\n"),clientMsgId:m,..."default"!==g?{agentId:g}:{},...h.length>0?{images:h.map(e=>({data:e,mimeType:x}))}:{}})}function cb(e){let{onSuccess:t}=e,[r,n]=(0,o.useState)(""),[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)(!1),d=(0,o.useCallback)(async e=>{if(e.preventDefault(),r.trim()){c(!0),s("");try{(await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r.trim()}),credentials:"include"})).ok?t():(s("Incorrect password"),n(""))}catch(e){s("Connection failed")}finally{c(!1)}}},[r,t]);return(0,l.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,l.jsxs)("div",{className:"w-full max-w-sm px-6",children:[(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-xl bg-[var(--secondary)]",children:(0,l.jsx)(iK.A,{className:"h-7 w-7 text-[var(--foreground)]"})}),(0,l.jsx)("h1",{className:"text-xl font-semibold text-[var(--foreground)]",children:"Halo"}),(0,l.jsx)("p",{className:"mt-1 text-sm text-[var(--muted-foreground)]",children:"Enter password to access workspace"})]}),(0,l.jsxs)("form",{onSubmit:d,className:"mt-8",children:[(0,l.jsx)("input",{type:"password",value:r,onChange:e=>n(e.target.value),placeholder:"Password",autoFocus:!0,className:"w-full rounded-md border border-[var(--border)] bg-[var(--secondary)] px-3 py-2.5 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)] focus:ring-1 focus:ring-[var(--primary)]"}),a&&(0,l.jsx)("p",{className:"mt-2 text-xs text-red-400",children:a}),(0,l.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 cy(){let{linkState:e}=function(){let[e,t]=(0,o.useState)(!1),[r,n]=(0,o.useState)("down"),a=(0,o.useRef)(!1);return(0,o.useEffect)(()=>{if(a.current)return;a.current=!0,C.connect();let e=[C.on("_connected",()=>{t(!0),n("fresh");let e=rT.getState().activeProject;(null==e?void 0:e.id)&&nN.getState().projectId===e.id&&C.send({type:"subscribe",sessionId:function(){var e;let{tabs:t,activeTabId:r}=nN.getState();for(let e of t)e.tabId!==r&&nB(e);return null!=(e=np().getState().sessionId)?e:""}(),projectId:e.id})}),C.on("_disconnected",()=>{t(!1),n("down")}),function(e){var t;let r=[];r.push((tg=t=(t,r)=>(function(e,t,r){let n=rT.getState().activeProject,a=np();if(cg&&cg!==a)return th("snap skipped (tab switched)"),!1;let s=a.getState(),l=s.sessionId;if(!n||!l)return th("snap skipped (no session)"),!1;let o=(0,U.$C)();s.addMessage({id:(0,U.$C)(),role:"user",content:ch,timestamp:Date.now(),clientMsgId:o,localImages:["data:".concat(r,";base64,").concat(t)]}),s.messages.some(e=>e.streaming&&"assistant"===e.role&&!e.taskId)||s.addMessage({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let i=s.selectedAgentId;return e.send({type:"chat",sessionId:l,projectId:n.id,message:ch,clientMsgId:o,..."default"!==i?{agentId:i}:{},images:[{data:t,mimeType:r}]}),!0})(e,t,r),()=>{tg===t&&(tg=null)})),r.push(e.on("_chat_send_failed",e=>{e.clientMsgId&&nd(t=>t.getState().markChatSendFailed(e.clientMsgId))})),r.push(e.on("_disconnected",()=>void(r4=Date.now())));let n=setInterval(()=>{nd(e=>e.getState().convergeStaleStreaming())},5e3);r.push(()=>clearInterval(n)),r.push(e.on("chat:thinking",e=>{var t;null==(t=nU(e.sessionId))||t.getState().appendThinking(e.text,e.agentName,e.taskId,e.turnId)})),r.push(e.on("chat:stream",e=>{var t;null==(t=nU(e.sessionId))||t.getState().updateLastAssistant(e.text,e.agentName,e.taskId,e.turnId)})),r.push(e.on("chat:complete",t=>{let r=nU(t.sessionId);if(!r)return;let n=r.getState();n.completeAgentStreaming(void 0,void 0,t.batchBoundary);let a=n.takeRoundReplies();if(r===np()){cv(e,r,a),a.length>0&&(tv=!1,cg=r);for(let e of a)for(let t of e.content.matchAll(cf)){let e=t[1].trim();e&&function(e){for(let r of tu)try{var t;null==(t=r.contentWindow)||t.postMessage({haloFace:e},"*")}catch(e){}}(e)}}})),r.push(e.on("chat:stopped",e=>{var t;null==(t=nU(e.sessionId))||t.getState().completeAgentStreaming()})),r.push(e.on("error",e=>{var t,r;let n=null==(t=nU(e.sessionId))?void 0:t.getState();if(!n)return;let a=e.code?null!=(r=e.error)?r:"":e.error?"Error: ".concat(e.error):"An unknown error occurred.";n.addMessage({id:(0,U.$C)(),role:"system",content:a,timestamp:Date.now(),agentName:e.agentName}),e.taskId||n.completeAgentStreaming(e.agentName)})),r.push(e.on("chat:followup",e=>{var t;let r=null==(t=nU(e.sessionId))?void 0:t.getState();if(r){if(e.replay){let t=r.takeReplaySnapshot();t?r.setMessages(t):r.completeAgentStreaming(e.agentName)}else r.completeAgentStreaming(e.agentName);r.addMessage({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName})}})),r.push(e.on("chat:user",e=>{var t;null==(t=nU(e.sessionId))||t.getState().addMessage({id:(0,U.$C)(),role:"user",content:e.text,timestamp:Date.now()})})),r.push(e.on("chat:usage",e=>{var t;let r=null==(t=nU(e.sessionId,!1))?void 0:t.getState();r&&(r.setTokenUsage(e.contextTokens,e.outputTokens),e.usage&&r.addMessage({type:"usage",role:"system",content:"[Usage] in=".concat(e.usage.inputTokens," out=").concat(e.usage.outputTokens," cache=").concat(e.usage.cacheReadInputTokens),usage:e.usage,turnId:e.turnId,modelId:e.modelId}))})),r.push(e.on("session:switched",t=>{if(!t.sessionId)return;if(t.clientMsgId&&t.fromSessionId){var r;null==(r=nO(t.fromSessionId))||r.getState().dropOptimisticSend(t.clientMsgId)}let n=nL(t.sessionId),a=rT.getState().activeProject;n&&a&&e.send({type:"subscribe",sessionId:n,projectId:a.id})})),r.push(e.on("session:compacted",e=>{var t,r;let n=nU(e.sessionId);if(!n)return;let a=null!=(t=e.message)?t:"Context compacted",s=n.getState();s.setCompacting(!1),l(n),s.setTokenUsage(null!=(r=e.contextTokens)?r:0,s.outputTokens),s.addMessage({id:(0,U.$C)(),role:"system",content:a,timestamp:Date.now()})}));let a=new Map;function s(e){l(e),a.set(e,setTimeout(()=>{a.delete(e),e.getState().setCompacting(!1)},6e4))}function l(e){let t=a.get(e);void 0!==t&&(clearTimeout(t),a.delete(e))}for(let t of(r.push(()=>{for(let e of a.values())clearTimeout(e);a.clear()}),r.push(e.on("chat:system",e=>{let t=nU(e.sessionId);if(!t)return;let r=t.getState(),n=e.text;if(!e.taskId){let e=n.match(/^Compacting context \((\d+)K tokens\)…$/);if(e&&(r.setCompacting(!0),s(t),"0"===e[1])){let e=t.getState().contextTokens;e>0&&(n="Compacting context (~".concat(Math.round(e/1e3),"K tokens)…"))}}r.addMessage({id:(0,U.$C)(),role:"system",content:n,timestamp:Date.now(),taskId:e.taskId,agentName:e.agentName})})),r.push(e.on("chat:queued",e=>{var t,r;null==(t=nU(e.sessionId))||t.getState().addMessage({id:(0,U.$C)(),role:"system",content:null!=(r=e.message)?r:"Message queued.",timestamp:Date.now()})})),["compact:progress","compact:started","compact:summarizing"]))r.push(e.on(t,e=>{let t=nU(e.sessionId,!1);t&&(t.getState().setCompacting(!0),s(t))}));return r.push(e.on("compact:done",e=>{let t=nU(e.sessionId,!1);t&&(t.getState().setCompacting(!1),l(t))})),()=>r.forEach(e=>e())}(C),function(e){let t=[];return t.push(e.on("agent:start",e=>{var t;let r=null==(t=nU(e.sessionId))?void 0:t.getState();r&&r.addMessage({id:(0,U.$C)(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName,taskId:e.taskId})})),t.push(e.on("agent:done",e=>{var t;let r=null==(t=nU(e.sessionId))?void 0:t.getState();r&&r.completeAgentStreaming(e.agentName,e.taskId)})),t.push(e.on("agent:context",e=>{var t,r;let n=null==(t=nU(e.sessionId))?void 0:t.getState();n&&n.addMessage({id:(0,U.$C)(),role:"system",content:"[System Prompt: ".concat(null!=(r=e.agentName)?r:"Agent","]"),timestamp:Date.now(),agentName:e.agentName,taskId:e.taskId,systemPrompt:e.systemPrompt})})),t.push(e.on("agent:tool_call",e=>{var t,r,n,a;let s=null==(t=nU(e.sessionId))?void 0:t.getState();if(!s)return;let l=null!=(r=e.agentName)?r:"default",o="string"==typeof e.input?e.input:JSON.stringify(null!=(n=e.input)?n:{});s.addToolCallToLastAssistant({name:null!=(a=e.tool)?a:"",input:o,toolUseId:e.toolUseId},l,e.taskId,e.turnId)})),t.push(e.on("agent:tool_result",e=>{var t,r,n;let a=null==(t=nU(e.sessionId))?void 0:t.getState();if(!a)return;let s=null!=(r=e.agentName)?r:"default",l="string"==typeof e.result?e.result:JSON.stringify(null!=(n=e.result)?n:"");a.updateLastToolCallResult(l,s,e.taskId,e.toolUseId)})),()=>t.forEach(e=>e())}(C),function(e){let t=[];return t.push(e.on("file:changed",e=>{let t=y.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())}(C),function(e){let t=[];return t.push(e.on("state:snapshot",e=>{var t,r,n;let{snapshot:a}=e,s=nU(a.sessionId,!1);if(!s)return;let l=s.getState();if(a.sessionId){let e=null!=(t=a.archiveCount)?t:0;!function(e,t){var r,n;let a=nI(t=>t.store===e);if(!a)return;let s=Math.max(null!=(r=a.archiveCount)?r:0,t);(a.loading||s!==(null!=(n=a.archiveCount)?n:0))&&nE(a.tabId,{loading:!1,archiveCount:s})}(s,e),s===np()&&nv(a.sessionId,e)}a.agentId&&l.setSelectedAgentId(a.agentId),void 0!==a.accessLevel&&l.setAccessLevel(null!=(r=a.accessLevel)?r:"full");let o=s.getState().messages.some(e=>e.streaming&&!r2(e)),i=null!=(n=a.recentMessages)?n:a.messages;i&&a.sessionId&&l.noteSnapshot(a.sessionId,i),!o&&i&&i.length>0&&l.setMessages(i),"number"==typeof a.maxContextTokens&&a.maxContextTokens>0&&l.setMaxContextTokens(a.maxContextTokens)})),t.push(e.on("listener:released",t=>{let{sessionId:r}=t,n=rT.getState().activeProject;if(!(null==n?void 0:n.id)||!r)return;let a=nO(r);if(a){if(a!==np())return void function(e){let{tabs:t,activeTabId:r}=nN.getState(),n=t.find(t=>t.sessionId===e);n&&n.tabId!==r&&nB(n)}(r);e.send({type:"subscribe",sessionId:r,projectId:n.id})}})),t.push(e.on("session:changed",()=>n8())),t.push(A(e,()=>n8())),t.push(e.on("goal:changed",()=>{var e;let t=null==(e=rT.getState().activeProject)?void 0:e.id;t&&nK(t),n8()})),t.push(e.on("extension:changed",e=>{let{extensions:t,errors:r}=e;return eN({extensions:t,errors:r})})),t.push(A(e,()=>{k.F.extensions.list().then(eN).catch(()=>{})})),t.push(e.on("models:changed",()=>si())),t.push(A(e,()=>si())),()=>t.forEach(e=>e())}(C)],r=()=>C.reconnectIfStale(0);window.addEventListener("online",r);let s=0,l=()=>{if(document.hidden){s=Date.now();return}s>0&&Date.now()-s>=3e5&&C.reconnectIfStale(45e3),s=0};document.addEventListener("visibilitychange",l);let o=setInterval(()=>{n(C.connected?C.lastReceiveAgeMs>45e3?"stale":"fresh":"down")},5e3);return()=>{e.forEach(e=>e()),window.removeEventListener("online",r),document.removeEventListener("visibilitychange",l),clearInterval(o),C.disconnect(),a.current=!1}},[]),{connected:e,linkState:r,send:(0,o.useCallback)(e=>{C.send(e)},[])}}(),[t,r]=(0,o.useState)("checking");(0,o.useEffect)(()=>{fetch("/api/auth/check",{credentials:"include"}).then(async e=>{let t=await e.json().catch(()=>null);var n=null==t?void 0:t.badge;let a="string"==typeof n&&n.trim()?n.trim():null;a&&!cs&&(cs=a,document.title=cl()+document.title,function(e){let t=document.createElement("canvas");t.width=64,t.height=64;let r=t.getContext("2d");if(!r)return;r.beginPath(),r.moveTo(14.08,0),r.arcTo(64,0,64,64,14.08),r.arcTo(64,64,0,64,14.08),r.arcTo(0,64,0,0,14.08),r.arcTo(0,0,64,0,14.08),r.closePath();let n=r.createLinearGradient(0,0,64,64);n.addColorStop(0,"#0e1430"),n.addColorStop(1,"#070a16"),r.fillStyle=n,r.fill(),r.clip();for(let[e,t]of[[8.96,.55],[13.44,.3]])r.beginPath(),r.arc(32,21.12,e,0,2*Math.PI),r.strokeStyle="rgba(125, 140, 255, ".concat(t,")"),r.lineWidth=2.24,r.stroke();let a=r.createRadialGradient(32,21.12,0,32,21.12,6.4);a.addColorStop(0,"#d8e6ff"),a.addColorStop(1,"#8aa6ff"),r.beginPath(),r.arc(32,21.12,6.4,0,2*Math.PI),r.fillStyle=a,r.fill();r.fillStyle="#e8401c",r.fillRect(0,64-26.88,64,26.88),r.fillStyle="#ffffff",r.textAlign="center",r.textBaseline="middle";let s=Math.round(22.0416);r.font="bold ".concat(s,"px system-ui, sans-serif");for(;s>8&&r.measureText(e).width>58.88;)s-=1,r.font="bold ".concat(s,"px system-ui, sans-serif");r.fillText(e,32,51.56),document.querySelectorAll('link[rel="icon"]').forEach(e=>e.remove());let l=document.createElement("link");l.rel="icon",l.type="image/png",l.href=t.toDataURL("image/png"),document.head.appendChild(l)}(a.slice(0,4))),nH.getState().setEnabled(e.ok&&(null==t?void 0:t.goalModeEnabled)===!0),r(e.ok?"authenticated":"login")}).catch(()=>{r("login")})},[]),(0,o.useEffect)(()=>C.on("_auth_expired",()=>{r("login")}),[]);let n=(0,o.useCallback)(()=>{r("authenticated"),window.location.reload()},[]);return"checking"===t?(0,l.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,l.jsx)("div",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading..."})}):"login"===t?(0,l.jsx)(cb,{onSuccess:n}):(0,l.jsx)("div",{className:"h-screen w-screen overflow-hidden bg-[var(--background)]",children:(0,l.jsx)(cc,{linkState:e})})}},79906:(e,t,r)=>{"use strict";r.d(t,{p:()=>i});var n=r(41440),a=r(54604),s=r(9239),l=r(40909),o=r(17119);function i(e){let{src:t,alt:r,className:i,placeholderClassName:c,onLoad:d,onError:u,...m}=e,p=(0,o.kj)(),x=(0,a.useRef)(null),[f,h]=(0,a.useState)({src:t,status:"loading"}),g=t?f.src===t?f.status:"loading":"error";(0,a.useLayoutEffect)(()=>{let e=x.current;(null==e?void 0:e.complete)&&e.naturalWidth>0&&h({src:t,status:"loaded"})},[t]);let v="loaded"!==g;return(0,n.jsx)("span",{role:"error"===g?"img":void 0,"aria-label":"error"===g?r||p("common.imageUnavailable"):void 0,"aria-busy":"loading"===g||void 0,title:"error"===g&&r?r:void 0,className:(0,l.cn)("contents",v&&"relative inline-flex max-w-full items-center justify-center overflow-hidden rounded align-middle bg-[var(--secondary)]/40 text-[var(--muted-foreground)]",v&&(null!=c?c:"aspect-video w-64"),"loading"===g&&"animate-pulse","error"===g&&"flex-col gap-1.5 border border-[var(--border)] p-2 text-center text-xs"),children:"error"===g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.A,{className:"h-5 w-5 shrink-0"}),(0,n.jsx)("span",{children:p("common.imageUnavailable")})]}):(0,n.jsx)("img",{ref:x,src:t,alt:r,...m,className:(0,l.cn)(i,"loading"===g&&"absolute inset-0 h-full w-full opacity-0")||void 0,onLoad:e=>{h({src:t,status:"loaded"}),null==d||d(e)},onError:e=>{h({src:t,status:"error"}),null==u||u(e)}},String(t))})}}},e=>{e.O(0,[772,560,147,989,946,698,358],()=>e(e.s=44652)),_N_E=e.O()}]);