pi-web-ui 0.103.0 → 0.103.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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-PIx1pMZ0.js","assets/rolldown-runtime-hePW80VL.js","assets/react-CR5VJ85Q.js","assets/xterm-Cf5xxe4g.js","assets/xterm-B1njb2Cr.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-DQFDRz0A.js","assets/rolldown-runtime-hePW80VL.js","assets/react-CR5VJ85Q.js","assets/xterm-Cf5xxe4g.js","assets/xterm-B1njb2Cr.css"])))=>i.map(i=>d[i]);
2
2
  import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n,r,t as i}from"./react-CR5VJ85Q.js";import{a,c as o,i as s,l as c,n as l,o as u,r as d,s as f,t as p}from"./markdown-DXwnfD9T.js";import{n as m,t as h}from"./xterm-Cf5xxe4g.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var g=e(t(),1),_={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},v=g.createContext&&g.createContext(_),y=[`attr`,`size`,`title`];function b(e,t){if(e==null)return{};var n,r,i=x(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function x(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function S(){return S=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},S.apply(null,arguments)}function C(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function w(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?C(Object(n),!0).forEach(function(t){T(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function T(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function E(e){var t=D(e,`string`);return typeof t==`symbol`?t:t+``}function D(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){return e&&e.map((e,t)=>g.createElement(e.tag,w({key:t},e.attr),O(e.child)))}function k(e){return t=>g.createElement(A,S({attr:w({},e.attr)},t),O(e.child))}function A(e){var t=t=>{var n=e.attr,r=e.size,i=e.title,a=b(e,y),o=r||t.size||`1em`,s;return t.className&&(s=t.className),e.className&&(s=(s?s+` `:``)+e.className),g.createElement(`svg`,S({stroke:`currentColor`,fill:`currentColor`,strokeWidth:`0`},t.attr,n,a,{className:s,style:w(w({color:e.color||t.color},t.style),e.style),height:o,width:o,xmlns:`http://www.w3.org/2000/svg`}),i&&g.createElement(`title`,null,i),e.children)};return v===void 0?t(_):g.createElement(v.Consumer,null,e=>t(e))}var j=r(),ee=n();function M(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`11`,cy:`11`,r:`8`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`11`,x2:`14`,y2:`11`},child:[]}]})(e)}function te(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`11`,cy:`11`,r:`8`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`},child:[]},{tag:`line`,attr:{x1:`11`,y1:`8`,x2:`11`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`11`,x2:`14`,y2:`11`},child:[]}]})(e)}function ne(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polygon`,attr:{points:`13 2 3 14 12 14 11 22 21 10 12 10 13 2`},child:[]}]})(e)}function N(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`18`,y1:`6`,x2:`6`,y2:`18`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`6`,x2:`18`,y2:`18`},child:[]}]})(e)}function P(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polygon`,attr:{points:`11 5 6 9 2 9 2 15 6 15 11 19 11 5`},child:[]},{tag:`path`,attr:{d:`M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07`},child:[]}]})(e)}function F(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2`},child:[]},{tag:`circle`,attr:{cx:`9`,cy:`7`,r:`4`},child:[]},{tag:`path`,attr:{d:`M23 21v-2a4 4 0 0 0-3-3.87`},child:[]},{tag:`path`,attr:{d:`M16 3.13a4 4 0 0 1 0 7.75`},child:[]}]})(e)}function re(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`},child:[]},{tag:`polyline`,attr:{points:`17 8 12 3 7 8`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`3`,x2:`12`,y2:`15`},child:[]}]})(e)}function ie(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`16 16 12 12 8 16`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`12`,x2:`12`,y2:`21`},child:[]},{tag:`path`,attr:{d:`M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3`},child:[]},{tag:`polyline`,attr:{points:`16 16 12 12 8 16`},child:[]}]})(e)}function I(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`11`,width:`18`,height:`11`,rx:`2`,ry:`2`},child:[]},{tag:`path`,attr:{d:`M7 11V7a5 5 0 0 1 9.9-1`},child:[]}]})(e)}function ae(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`4 7 4 4 20 4 20 7`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`20`,x2:`15`,y2:`20`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`4`,x2:`12`,y2:`20`},child:[]}]})(e)}function L(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`3 6 5 6 21 6`},child:[]},{tag:`path`,attr:{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`},child:[]},{tag:`line`,attr:{x1:`10`,y1:`11`,x2:`10`,y2:`17`},child:[]},{tag:`line`,attr:{x1:`14`,y1:`11`,x2:`14`,y2:`17`},child:[]}]})(e)}function R(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z`},child:[]}]})(e)}function z(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`4 17 10 11 4 5`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`19`,x2:`20`,y2:`19`},child:[]}]})(e)}function B(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`6`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`2`},child:[]}]})(e)}function V(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`5`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`1`,x2:`12`,y2:`3`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`21`,x2:`12`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`4.22`,y1:`4.22`,x2:`5.64`,y2:`5.64`},child:[]},{tag:`line`,attr:{x1:`18.36`,y1:`18.36`,x2:`19.78`,y2:`19.78`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`12`,x2:`3`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`12`,x2:`23`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`4.22`,y1:`19.78`,x2:`5.64`,y2:`18.36`},child:[]},{tag:`line`,attr:{x1:`18.36`,y1:`5.64`,x2:`19.78`,y2:`4.22`},child:[]}]})(e)}function H(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`},child:[]}]})(e)}function U(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`4`,y1:`21`,x2:`4`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`4`,y1:`10`,x2:`4`,y2:`3`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`21`,x2:`12`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`8`,x2:`12`,y2:`3`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`21`,x2:`20`,y2:`16`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`12`,x2:`20`,y2:`3`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`14`,x2:`7`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`8`,x2:`15`,y2:`8`},child:[]},{tag:`line`,attr:{x1:`17`,y1:`16`,x2:`23`,y2:`16`},child:[]}]})(e)}function W(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`6`,x2:`21`,y2:`6`},child:[]},{tag:`path`,attr:{d:`M16 10a4 4 0 0 1-8 0`},child:[]}]})(e)}function oe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z`},child:[]}]})(e)}function G(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`18`,cy:`5`,r:`3`},child:[]},{tag:`circle`,attr:{cx:`6`,cy:`12`,r:`3`},child:[]},{tag:`circle`,attr:{cx:`18`,cy:`19`,r:`3`},child:[]},{tag:`line`,attr:{x1:`8.59`,y1:`13.51`,x2:`15.42`,y2:`17.49`},child:[]},{tag:`line`,attr:{x1:`15.41`,y1:`6.51`,x2:`8.59`,y2:`10.49`},child:[]}]})(e)}function se(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`3`},child:[]},{tag:`path`,attr:{d:`M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z`},child:[]}]})(e)}function ce(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`2`,y:`2`,width:`20`,height:`8`,rx:`2`,ry:`2`},child:[]},{tag:`rect`,attr:{x:`2`,y:`14`,width:`20`,height:`8`,rx:`2`,ry:`2`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`6`,x2:`6.01`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`18`,x2:`6.01`,y2:`18`},child:[]}]})(e)}function K(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`22`,y1:`2`,x2:`11`,y2:`13`},child:[]},{tag:`polygon`,attr:{points:`22 2 15 22 11 13 2 9 22 2`},child:[]}]})(e)}function le(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`11`,cy:`11`,r:`8`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`},child:[]}]})(e)}function ue(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`6`,cy:`6`,r:`3`},child:[]},{tag:`circle`,attr:{cx:`6`,cy:`18`,r:`3`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`4`,x2:`8.12`,y2:`15.88`},child:[]},{tag:`line`,attr:{x1:`14.47`,y1:`14.48`,x2:`20`,y2:`20`},child:[]},{tag:`line`,attr:{x1:`8.12`,y1:`8.12`,x2:`12`,y2:`12`},child:[]}]})(e)}function de(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z`},child:[]},{tag:`polyline`,attr:{points:`17 21 17 13 7 13 7 21`},child:[]},{tag:`polyline`,attr:{points:`7 3 7 8 15 8`},child:[]}]})(e)}function q(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`1 4 1 10 7 10`},child:[]},{tag:`path`,attr:{d:`M3.51 15a9 9 0 1 0 2.13-9.36L1 10`},child:[]}]})(e)}function J(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`23 4 23 10 17 10`},child:[]},{tag:`polyline`,attr:{points:`1 20 1 14 7 14`},child:[]},{tag:`path`,attr:{d:`M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15`},child:[]}]})(e)}function fe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`5`,x2:`12`,y2:`19`},child:[]},{tag:`line`,attr:{x1:`5`,y1:`12`,x2:`19`,y2:`12`},child:[]}]})(e)}function pe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polygon`,attr:{points:`5 3 19 12 5 21 5 3`},child:[]}]})(e)}function me(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48`},child:[]}]})(e)}function Y(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`16.5`,y1:`9.4`,x2:`7.5`,y2:`4.21`},child:[]},{tag:`path`,attr:{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`},child:[]},{tag:`polyline`,attr:{points:`3.27 6.96 12 12.01 20.73 6.96`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`22.08`,x2:`12`,y2:`12`},child:[]}]})(e)}function he(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`1`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`5`,r:`1`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`19`,r:`1`},child:[]}]})(e)}function ge(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`2`,y:`3`,width:`20`,height:`14`,rx:`2`,ry:`2`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`21`,x2:`16`,y2:`21`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`17`,x2:`12`,y2:`21`},child:[]}]})(e)}function _e(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`5`,y1:`12`,x2:`19`,y2:`12`},child:[]}]})(e)}function ve(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3`},child:[]}]})(e)}function ye(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z`},child:[]},{tag:`path`,attr:{d:`M19 10v2a7 7 0 0 1-14 0v-2`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`19`,x2:`12`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`23`,x2:`16`,y2:`23`},child:[]}]})(e)}function be(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`},child:[]}]})(e)}function xe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`3`,y1:`12`,x2:`21`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`6`,x2:`21`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`18`,x2:`21`,y2:`18`},child:[]}]})(e)}function Se(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3`},child:[]}]})(e)}function Ce(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`15 3 21 3 21 9`},child:[]},{tag:`polyline`,attr:{points:`9 21 3 21 3 15`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`3`,x2:`14`,y2:`10`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`21`,x2:`10`,y2:`14`},child:[]}]})(e)}function we(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`11`,width:`18`,height:`11`,rx:`2`,ry:`2`},child:[]},{tag:`path`,attr:{d:`M7 11V7a5 5 0 0 1 10 0v4`},child:[]}]})(e)}function Te(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`2`,x2:`12`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`18`,x2:`12`,y2:`22`},child:[]},{tag:`line`,attr:{x1:`4.93`,y1:`4.93`,x2:`7.76`,y2:`7.76`},child:[]},{tag:`line`,attr:{x1:`16.24`,y1:`16.24`,x2:`19.07`,y2:`19.07`},child:[]},{tag:`line`,attr:{x1:`2`,y1:`12`,x2:`6`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`18`,y1:`12`,x2:`22`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`4.93`,y1:`19.07`,x2:`7.76`,y2:`16.24`},child:[]},{tag:`line`,attr:{x1:`16.24`,y1:`7.76`,x2:`19.07`,y2:`4.93`},child:[]}]})(e)}function Ee(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`8`,y1:`6`,x2:`21`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`12`,x2:`21`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`18`,x2:`21`,y2:`18`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`6`,x2:`3.01`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`12`,x2:`3.01`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`18`,x2:`3.01`,y2:`18`},child:[]}]})(e)}function De(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`},child:[]},{tag:`path`,attr:{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`},child:[]}]})(e)}function Oe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polygon`,attr:{points:`12 2 2 7 12 12 22 7 12 2`},child:[]},{tag:`polyline`,attr:{points:`2 17 12 22 22 17`},child:[]},{tag:`polyline`,attr:{points:`2 12 12 17 22 12`},child:[]}]})(e)}function ke(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4`},child:[]}]})(e)}function Ae(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`16`,x2:`12`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`8`,x2:`12.01`,y2:`8`},child:[]}]})(e)}function je(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`},child:[]},{tag:`circle`,attr:{cx:`8.5`,cy:`8.5`,r:`1.5`},child:[]},{tag:`polyline`,attr:{points:`21 15 16 10 5 21`},child:[]}]})(e)}function Me(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`path`,attr:{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`},child:[]}]})(e)}function Ne(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`7`,height:`7`},child:[]},{tag:`rect`,attr:{x:`14`,y:`3`,width:`7`,height:`7`},child:[]},{tag:`rect`,attr:{x:`14`,y:`14`,width:`7`,height:`7`},child:[]},{tag:`rect`,attr:{x:`3`,y:`14`,width:`7`,height:`7`},child:[]}]})(e)}function Pe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`line`,attr:{x1:`2`,y1:`12`,x2:`22`,y2:`12`},child:[]},{tag:`path`,attr:{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`},child:[]}]})(e)}function Fe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22`},child:[]}]})(e)}function Ie(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`6`,y1:`3`,x2:`6`,y2:`15`},child:[]},{tag:`circle`,attr:{cx:`18`,cy:`6`,r:`3`},child:[]},{tag:`circle`,attr:{cx:`6`,cy:`18`,r:`3`},child:[]},{tag:`path`,attr:{d:`M18 9a9 9 0 0 1-9 9`},child:[]}]})(e)}function Le(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z`},child:[]}]})(e)}function Re(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`11`,x2:`12`,y2:`17`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`14`,x2:`15`,y2:`14`},child:[]}]})(e)}function ze(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z`},child:[]},{tag:`polyline`,attr:{points:`13 2 13 9 20 9`},child:[]}]})(e)}function Be(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`},child:[]},{tag:`polyline`,attr:{points:`14 2 14 8 20 8`},child:[]},{tag:`line`,attr:{x1:`16`,y1:`13`,x2:`8`,y2:`13`},child:[]},{tag:`line`,attr:{x1:`16`,y1:`17`,x2:`8`,y2:`17`},child:[]},{tag:`polyline`,attr:{points:`10 9 9 9 8 9`},child:[]}]})(e)}function Ve(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`},child:[]},{tag:`polyline`,attr:{points:`14 2 14 8 20 8`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`18`,x2:`12`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`15`,x2:`15`,y2:`15`},child:[]}]})(e)}function He(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`3`},child:[]}]})(e)}function Ue(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`},child:[]},{tag:`polyline`,attr:{points:`15 3 21 3 21 9`},child:[]},{tag:`line`,attr:{x1:`10`,y1:`14`,x2:`21`,y2:`3`},child:[]}]})(e)}function We(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M12 20h9`},child:[]},{tag:`path`,attr:{d:`M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z`},child:[]}]})(e)}function Ge(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z`},child:[]}]})(e)}function Ke(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`},child:[]},{tag:`polyline`,attr:{points:`7 10 12 15 17 10`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`15`,x2:`12`,y2:`3`},child:[]}]})(e)}function qe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`1`,x2:`12`,y2:`23`},child:[]},{tag:`path`,attr:{d:`M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6`},child:[]}]})(e)}function Je(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`ellipse`,attr:{cx:`12`,cy:`5`,rx:`9`,ry:`3`},child:[]},{tag:`path`,attr:{d:`M21 12c0 1.66-4 3-9 3s-9-1.34-9-3`},child:[]},{tag:`path`,attr:{d:`M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5`},child:[]}]})(e)}function Ye(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`line`,attr:{x1:`22`,y1:`12`,x2:`18`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`12`,x2:`2`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`6`,x2:`12`,y2:`2`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`22`,x2:`12`,y2:`18`},child:[]}]})(e)}function Xe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,ry:`2`},child:[]},{tag:`rect`,attr:{x:`9`,y:`9`,width:`6`,height:`6`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`1`,x2:`9`,y2:`4`},child:[]},{tag:`line`,attr:{x1:`15`,y1:`1`,x2:`15`,y2:`4`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`20`,x2:`9`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`15`,y1:`20`,x2:`15`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`9`,x2:`23`,y2:`9`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`14`,x2:`23`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`9`,x2:`4`,y2:`9`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`14`,x2:`4`,y2:`14`},child:[]}]})(e)}function Ze(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`9 14 4 9 9 4`},child:[]},{tag:`path`,attr:{d:`M20 20v-7a4 4 0 0 0-4-4H4`},child:[]}]})(e)}function Qe(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`15 10 20 15 15 20`},child:[]},{tag:`path`,attr:{d:`M4 4v7a4 4 0 0 0 4 4h12`},child:[]}]})(e)}function $e(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`9 10 4 15 9 20`},child:[]},{tag:`path`,attr:{d:`M20 4v7a4 4 0 0 1-4 4H4`},child:[]}]})(e)}function et(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`},child:[]},{tag:`path`,attr:{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`},child:[]}]})(e)}function tt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`16 18 22 12 16 6`},child:[]},{tag:`polyline`,attr:{points:`8 6 2 12 8 18`},child:[]}]})(e)}function nt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`polyline`,attr:{points:`12 6 12 12 16 14`},child:[]}]})(e)}function rt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`},child:[]},{tag:`rect`,attr:{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`},child:[]}]})(e)}function it(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]}]})(e)}function at(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`13 17 18 12 13 7`},child:[]},{tag:`polyline`,attr:{points:`6 17 11 12 6 7`},child:[]}]})(e)}function ot(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`11 17 6 12 11 7`},child:[]},{tag:`polyline`,attr:{points:`18 17 13 12 18 7`},child:[]}]})(e)}function st(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`18 15 12 9 6 15`},child:[]}]})(e)}function ct(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`9 18 15 12 9 6`},child:[]}]})(e)}function lt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`15 18 9 12 15 6`},child:[]}]})(e)}function ut(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`6 9 12 15 18 9`},child:[]}]})(e)}function dt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`20 6 9 17 4 12`},child:[]}]})(e)}function ft(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M22 11.08V12a10 10 0 1 1-5.93-9.14`},child:[]},{tag:`polyline`,attr:{points:`22 4 12 14.01 9 11.01`},child:[]}]})(e)}function pt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`13`,r:`4`},child:[]}]})(e)}function mt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`},child:[]},{tag:`polyline`,attr:{points:`3.27 6.96 12 12.01 20.73 6.96`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`22.08`,x2:`12`,y2:`12`},child:[]}]})(e)}function ht(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z`},child:[]},{tag:`path`,attr:{d:`M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z`},child:[]}]})(e)}function gt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9`},child:[]},{tag:`path`,attr:{d:`M13.73 21a2 2 0 0 1-3.46 0`},child:[]}]})(e)}function _t(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`19`,x2:`12`,y2:`5`},child:[]},{tag:`polyline`,attr:{points:`5 12 12 5 19 12`},child:[]}]})(e)}function vt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`7`,y1:`17`,x2:`17`,y2:`7`},child:[]},{tag:`polyline`,attr:{points:`7 7 17 7 17 17`},child:[]}]})(e)}function yt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`5`,y1:`12`,x2:`19`,y2:`12`},child:[]},{tag:`polyline`,attr:{points:`12 5 19 12 12 19`},child:[]}]})(e)}function bt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`5`,x2:`12`,y2:`19`},child:[]},{tag:`polyline`,attr:{points:`19 12 12 19 5 12`},child:[]}]})(e)}function xt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`21 8 21 21 3 21 3 8`},child:[]},{tag:`rect`,attr:{x:`1`,y:`3`,width:`22`,height:`5`},child:[]},{tag:`line`,attr:{x1:`10`,y1:`12`,x2:`14`,y2:`12`},child:[]}]})(e)}function St(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`5`,r:`3`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`22`,x2:`12`,y2:`8`},child:[]},{tag:`path`,attr:{d:`M5 12H2a10 10 0 0 0 20 0h-3`},child:[]}]})(e)}function Ct(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`9`,x2:`12`,y2:`13`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`},child:[]}]})(e)}function wt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`8`,x2:`12`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`},child:[]}]})(e)}function Tt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`22 12 18 12 15 21 9 3 6 12 2 12`},child:[]}]})(e)}function Et(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`},child:[{tag:`path`,attr:{d:`M11.646 15.146 5.854 9.354a.5.5 0 0 1 .353-.854h11.586a.5.5 0 0 1 .353.854l-5.793 5.792a.5.5 0 0 1-.707 0Z`},child:[]}]})(e)}function Dt(e){return k({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 17H7l-4 4v-7`},child:[]},{tag:`path`,attr:{d:`M14 17h1`},child:[]},{tag:`path`,attr:{d:`M14 3h1`},child:[]},{tag:`path`,attr:{d:`M19 3a2 2 0 0 1 2 2`},child:[]},{tag:`path`,attr:{d:`M21 14v1a2 2 0 0 1-2 2`},child:[]},{tag:`path`,attr:{d:`M21 9v1`},child:[]},{tag:`path`,attr:{d:`M3 9v1`},child:[]},{tag:`path`,attr:{d:`M5 3a2 2 0 0 0-2 2`},child:[]},{tag:`path`,attr:{d:`M9 3h1`},child:[]}]})(e)}function Ot(e){return e.map(e=>e.kind===`package`?`pi update npm:${e.name}`:e.kind===`git-extension`?`pi update ${kt(e.source??e.name)}`:e.kind===`plugin`?`pi-web-ui install ${e.source??e.name} --name ${e.pluginId??e.name} --force`:`npm i -g ${e.name}@latest`).join(`; `)}function kt(e){return e.startsWith(`git:`)?e:`git:${e}`}function At(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(16);if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`)crypto.getRandomValues(e);else for(let t=0;t<16;t++)e[t]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function jt(e,t,n={}){let{enabled:r=!0,ignore:i}=n,a=(0,g.useRef)(t);(0,g.useLayoutEffect)(()=>{a.current=t}),(0,g.useEffect)(()=>{if(!r)return;let t=(e,t)=>{if(!t)return!1;let n=`current`in t?t.current:t;return n?n.contains(e):!1},n=n=>{let r=n.target;r instanceof Node&&(e.current?.contains(r)||i&&(Array.isArray(i)?i:[i]).some(e=>t(r,e))||a.current(n))};return document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n)}},[r,e,i])}var Mt=[],Nt=!1;function Pt(e){if(e.key===`Escape`&&Mt.length!==0)for(let t=Mt.length-1;t>=0;t--){let n=Mt[t];if(n()!==!1){e.preventDefault(),e.stopPropagation();break}}}function Ft(){!Nt&&typeof document<`u`&&(document.addEventListener(`keydown`,Pt,!0),Nt=!0)}function It(){Nt&&Mt.length===0&&typeof document<`u`&&(document.removeEventListener(`keydown`,Pt,!0),Nt=!1)}function Lt(e){return Mt.push(e),Ft(),()=>{let t=Mt.lastIndexOf(e);t>=0&&Mt.splice(t,1),It()}}function Rt(e,t=!0){let n=(0,g.useRef)(e);(0,g.useLayoutEffect)(()=>{n.current=e}),(0,g.useEffect)(()=>{if(t)return Lt(()=>n.current())},[t])}var X=i();function zt({align:e,triggerLeft:t,triggerRight:n,menuWidth:r,viewportWidth:i,margin:a=8}){if(r<=0||i<=0)return 0;let o=e===`left`?t:n-r,s=Math.max(a,i-a-r);return Math.round(Math.max(a,Math.min(o,s))-o)}function Bt({trigger:e,open:t,onOpenChange:n,children:r,align:i=`right`,fit:a=!1,direction:o=`down`,tip:s,caret:c=!0,menuClassName:l,triggerClassName:u,menuRef:d,menuStyle:f}){let p=(0,g.useRef)(null),m=(0,g.useRef)(null),[h,_]=(0,g.useState)(0),v=e=>{m.current=e,typeof d==`function`?d(e):d&&`current`in d&&(d.current=e)},y=()=>{let e=p.current,t=m.current;if(!e||!t)return;if(window.innerWidth<=768){h!==0&&_(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){h!==0&&_(0);return}let a=n.width,o=zt({align:i,triggerLeft:r.left,triggerRight:r.right,menuWidth:a,viewportWidth:window.innerWidth,margin:8});o!==h&&_(o)};return(0,g.useLayoutEffect)(()=>{t?y():h!==0&&_(0)}),(0,g.useEffect)(()=>{if(t)return window.addEventListener(`resize`,y),()=>window.removeEventListener(`resize`,y)},[t,h]),jt(p,()=>n(!1),{enabled:t}),Rt(()=>n(!1),t),(0,X.jsxs)(`div`,{className:`dropdown ${i} ${a?`fit`:``} ${o===`up`?`dd-up`:``}`,ref:p,children:[(0,X.jsxs)(`button`,{type:`button`,className:u??`chip`,onClick:()=>n(!t),"aria-expanded":t,"data-tip":s,children:[e,c&&(0,X.jsx)(ut,{className:`dd-caret ${t?`up`:``}`})]}),t&&(0,X.jsx)(`div`,{className:`dd-menu ${l??``}`,ref:v,style:h===0?f:{...f,transform:f?.transform?`${f.transform} translateX(${h}px)`:`translateX(${h}px)`},children:r})]})}function Vt({active:e,disabled:t=!1,title:n,onClick:r,children:i}){return(0,X.jsx)(`button`,{type:`button`,className:`dd-item ${e?`active`:``}`,disabled:t,title:n,onClick:r,children:i})}var Ht=`pi-web-tts`,Ut={enabled:!1,announce:!0,readReplies:!1,rate:1,voiceURI:``};function Wt(){try{let e=localStorage.getItem(Ht);if(!e)return{...Ut};let t={...Ut,...JSON.parse(e)};for(let e of[`enabled`,`announce`,`readReplies`])typeof t[e]!=`boolean`&&(t[e]=Ut[e]);return t.rate=typeof t.rate!=`number`||!Number.isFinite(t.rate)?Ut.rate:Math.round(Math.max(.5,Math.min(2,t.rate))*10)/10,typeof t.voiceURI!=`string`&&(t.voiceURI=Ut.voiceURI),t}catch{return{...Ut}}}function Gt(e){try{localStorage.setItem(Ht,JSON.stringify(e))}catch{}}function Kt(){return typeof window<`u`&&`speechSynthesis`in window}function qt(e,t,n){if(e){let n=t.find(t=>t.voiceURI===e);if(n)return n}let r=n.split(`-`)[0]?.toLowerCase();return r?t.find(e=>e.lang.toLowerCase().startsWith(r))??null:null}function Jt(e){let t=e??``;return t=t.replace(/```[\s\S]*?(?:```|$)/g,` `),t=t.replace(/`([^`]+)`/g,`$1`),t=t.replace(/!\[[^\]]*\]\([^)]*\)/g,` `),t=t.replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`),t=t.replace(/^\s{0,3}#{1,6}\s+/gm,``),t=t.replace(/^\s{0,3}>\s?/gm,``),t=t.replace(/^\s*[-*+]\s+/gm,``),t=t.replace(/^\s*\|?[\s:|-]*\|[\s:|-]*$/gm,``),t=t.replace(/\|/g,` `),t=t.replace(/(\*\*\*|\*\*|__)(.*?)\1/g,`$2`),t=t.replace(/(\*|_)([^*_\n]+)\1/g,`$2`),t=t.replace(/<[^>]+>/g,` `),t=t.replace(/\r/g,``),t=t.replace(/[ \t]+/g,` `),t=t.replace(/\s*\n+\s*/g,` `),t=t.trim(),t.length>600&&(t=`${t.slice(0,600).trimEnd()}…`),t}function Yt(e){if(!Array.isArray(e))return``;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n&&n.role===`assistant`)return Jt((n.content??[]).filter(e=>e?.type===`text`&&typeof e.text==`string`).map(e=>e.text??``).join(`
3
3
  `))}return``}var Xt=!1,Zt=null,Qt=null,$t=new Set;function en(e,t=null){e?(Xt=!0,Zt=t):(Xt=!1,Zt=null);for(let t of $t)try{t(e)}catch{}}function tn(){return Xt}function nn(){return Xt?Zt:null}function rn(e){return $t.add(e),()=>$t.delete(e)}function an(e,t=Wt(),n){if(e&&Kt())try{let r=window.speechSynthesis;r.cancel();let i=new SpeechSynthesisUtterance(e);i.rate=t.rate;let a=qt(t.voiceURI,r.getVoices(),navigator.language);a&&(i.voice=a),i.onend=()=>{Qt===i&&en(!1)},i.onerror=()=>{Qt===i&&en(!1)},Qt=i,en(!0,n??null),r.speak(i)}catch{Qt=null,en(!1)}}function on(){if(Kt()){try{window.speechSynthesis.cancel()}catch{}Qt=null,en(!1)}}var sn=null;function cn(e){if(e===void 0){let t=globalThis.document;if(t&&typeof t.baseURI==`string`&&t.baseURI)try{e=new URL(t.baseURI).pathname}catch{}if(e===void 0)return`/`}if(!e||e===`/`)return`/`;let t=e.replace(/index\.html$/i,``);return t.endsWith(`/`)||(t+=`/`),t}function ln(){return sn===null&&(sn=cn()),sn}function un(e,t){return t===`/`?e:t+e.replace(/^\/+/,``)}function dn(e){return un(e,ln())}var fn=`pi-web-ui:token`;function pn(){try{let e=new URL(window.location.href),t=e.searchParams.get(`token`);t&&(localStorage.setItem(fn,t.trim()),e.searchParams.delete(`token`),window.history.replaceState(null,``,e.toString()))}catch{}}function mn(){try{return localStorage.getItem(fn)??``}catch{return``}}function hn(e){let t=mn();return t?`${e}${e.includes(`?`)?`&`:`?`}token=${encodeURIComponent(t)}`:e}var gn=[`zh`,`en`,`de`,`es`,`fr`,`it`,`ja`,`ko`,`pt`,`ru`];function _n(e,t,n,r=gn){let i=(e??``).trim();if(i)return i;for(let e of t??[]){let t=String(e??``).trim().toLowerCase().replace(/_/g,`-`);if(!t)continue;if(r.includes(t))return t;let n=t.split(`-`)[0];if(n&&r.includes(n))return n}let a=(n??``).trim().toLowerCase();return a&&r.includes(a)?a:`en`}var vn=`pi-web-ui:lang`,yn={docTitle:`pi-web-ui — pi 编码智能体`,cancel:`取消`,ok:`确定`,save:`保存`,close:`关闭`,widgetExpand:`点击放大查看完整输出`,collapsePanel:`收起面板`,expandPanel:`展开面板`,dragToResize:`拖拽调整宽度 · 双击复位`,loading:`加载中…`,connected:`已连接`,connecting:`连接中…`,reconnecting:`重连中…`,language:`语言`,githubRepo:`GitHub 仓库(xing-shuyin/pi-web-ui)`,copy:`复制`,viewSwitch:`视图切换`,chat:`对话`,terminal:`终端`,selectModel:`选择模型`,availableModels:`可用模型`,allProviders:`全部`,providers:`服务商`,noModels:`暂无可用模型(请先配置 API 密钥)`,reasoning:`推理`,vision:`识图`,refreshModels:`刷新模型列表(保留手填,合并新增)`,manageModels:`⚙ 管理模型(新增 / 修改)`,thinkingLevel:`思考强度`,thinking:`思考`,thinkingChip:`{level}`,sound:`声音`,theme:`主题`,themeDefault:`深色(默认)`,themeGroupClassics:`现代经典`,themeGroupBuiltin:`原始预设`,themeLight:`浅色`,themeDark:`深色`,newChat:`新对话`,newChatEphemeral:`临时对话`,newChatEphemeralTip:`临时对话(仅内存,关闭即销毁,不进历史记录)`,ephemeralBadge:`临时`,ephemeralBannerText:`当前为临时对话:消息仅保存在内存中,关闭后自动销毁,不进入历史记录。`,more:`更多`,brand:`品牌`,newChatTip:`新建对话(每个浏览器独立保存会话)`,"thinking.off":`关闭`,"thinking.minimal":`极简`,"thinking.low":`低`,"thinking.medium":`中`,"thinking.high":`高`,"thinking.xhigh":`极高`,"thinking.max":`最大`,thinkingUnsupported:`当前模型不支持该级别,已按模型能力就近生效`,context:`上下文`,contextUsage:`上下文用量`,cumulativeCost:`累计成本`,sessionMessages:`会话消息数`,messages:`消息`,pluginStatus:`插件状态`,engineBadge:`引擎`,working:`工作中`,queued:`排队`,enterPath:`输入路径,Enter 切换`,cwdTip:`工作目录:{path}(点击切换)`,manageProjects:`管理项目和工作目录`,projectPickerTitle:`选择工作目录`,newProject:`新建项目`,projectName:`项目名称`,createAndOpenProject:`创建并打开`,invalidProjectName:`请输入不含路径分隔符的项目名称`,cwdGoUp:`上级目录`,cwdPickCurrent:`选择当前目录`,cwdChoose:`选择`,cwdEnter:`进入`,cwdEmpty:`(空目录)`,cwdNewFolder:`新建文件夹`,cwdNewName:`文件夹名称`,cwdCreate:`创建`,cwdCancel:`取消`,cacheHit:`缓存命中`,cacheHitTip:`缓存读取 {read} · 缓存写入 {write} · 未命中 {miss}(共 {input} 输入 token)`,tps:`t/s`,rateTip:`实时生成速率(估算)`,hostResources:`主机资源`,hostProcessor:`CPU`,hostMemory:`RAM`,hostResourcesTip:`运行 pi-web-ui 服务的主机 · CPU 为约 10 秒平均(2 秒采样),与任务管理器采样时刻不同会有几秒偏差`,folderRef:`文件夹引用:{path}`,refOnly:`仅引用:{path}`,attachContent:`附加内容:{path}`,attachLines:`附加选中行:{path}(第 {start}-{end} 行)`,attachImage:`图片:{name}`,attachFile:`文件:{name}`,removeAttachment:`移除附件`,attachHint:`将随下一条消息发送`,uploadFile:`添加文件(图片/文本/任意文件,也可直接拖入或粘贴截图)`,dropHereToAttach:`松开以添加文件`,imageNotSupported:`当前模型不支持识图:图片将交给视觉桥转写(若未配置视觉模型则可能被忽略)`,imageLoadFailed:`图片读取失败:{name}`,fileLoadFailed:`文件读取失败:{name}`,fileTooLarge:`文件过大已跳过(>{size}MB):{name}`,foldersNotSupported:`不支持直接拖入文件夹,请展开后选择文件`,placeholderStreaming:`智能体正在工作中…回车插队发送,或点「排队」等回答结束后发送`,placeholderStreamingQueued:`智能体正在工作中…回车或点「排队」,回答完全结束后发送(本引擎不支持插队)`,placeholderIdle:`给 pi 发送消息 — Enter 发送,/ 查看命令`,placeholderConnecting:`正在连接服务器…`,stopAgent:`停止智能体`,stop:`停止`,bgTasks:`后台任务`,bgTasksTip:`AI 在后台启动的服务(npm run dev & 等)——可逐个停止或全部关闭,对话结束后仍保留`,bgTasksEmpty:`暂无后台任务`,bgTasksDesc:`AI 运行中启动并仍在监听的进程(按监听端口检测)`,bgTaskPort:`端口`,bgTaskPid:`PID`,bgTaskSince:`启动`,bgTaskStop:`停止`,bgTaskStopAll:`全部关闭`,bgTaskRefresh:`刷新`,bgTaskKeep:`保留(自动清理不碰)`,bgTaskKeepOn:`已保留(自动清理不碰)—— 点一下取消`,bgTaskCleanup:`自动清理遗留`,bgTaskCleanupOff:`关`,bgTaskCleanupMinutes:`闲置 {n} 分钟`,bgTaskCleanupHint:`开启后服务端定期把闲置超阈值的 AI 起后台实例杀掉(📌 钉住的不算);杀完会发一条通知`,bgTaskCleanNow:`立即清理`,bgTaskCleanNowHint:`按当前阈值立刻清一次;阈值为关时按 30 分钟兜底`,bgTaskJustNow:`刚刚`,bgTaskMinutes:`{n} 分钟前`,bgTaskHours:`{n} 小时前`,bgTaskDays:`{n} 天前`,stopBash:`停止`,stopBashTip:`停止正在运行的 bash 命令(对话继续)`,supplement:`排队`,supplementTip:`加入队列:AI 回答完全结束后才发送(不打断)`,steerTip:`插队:立即发送,本回合马上响应(Enter)`,queueSteerTag:`插队`,queueFollowTag:`排队`,queueRemoveTip:`移除此排队消息`,queueRecallTip:`撤回并放回输入框(可编辑后重发)`,sendTip:`发送(Enter)`,composerResize:`拖拽调整输入框高度(双击恢复默认)`,quickPhrases:`快捷短语`,quickPhrasesDesc:`输入框上方的一排常用短语按钮,点击即发送(会带上当前已选的文件附件,不清空输入框草稿)`,quickPhrasesEnabled:`启用快捷短语`,quickPhrasesOffHint:`已关闭:输入框上方不再显示快捷短语按钮(已配置的短语保留,可随时重新启用)`,quickPhrasesPlaceholder:`输入常用短语…(Enter 添加)`,quickPhrasesAdd:`添加`,quickPhrasesEmpty:`还没有快捷短语,在下面添加第一条`,quickPhrasesTip:`点击发送:{text}`,quickPhrasesSendTip:`左键插队发送,右键排队发送`,quickPhrasesMoveUp:`上移`,quickPhrasesMoveDown:`下移`,quickPhrasesDelete:`删除该短语`,quickPhrasesEdit:`编辑该短语`,quickPhrasesEditPh:`修改短语…(Enter 保存,Esc 取消)`,quickPhrasesReset:`恢复默认短语`,slashCommands:`命令`,slashMenuHint:`↑↓ 选择 · Enter/Tab 补全`,atMentions:`提及`,atMenuHint:`↑↓ 选择 · Enter/Tab 插入`,slashHelpTitle:`pi 命令`,slashLoading:`命令列表加载中…(连接服务器后可用)`,slashBuiltin:`内置`,slashExtension:`扩展`,slashPrompt:`模板`,slashSkill:`技能`,slashPlugin:`插件`,slashCopied:`已复制上一条助手回复`,slashCopyFailed:`复制失败,请手动复制`,slashCopyEmpty:`还没有可复制的助手回复`,recentProjects:`最近项目`,runningConversations:`运行的对话`,elsewhereBadge:`另一处`,elsewherePseudoBadge:`无头任务`,elsewhereTip:`在其他标签页 / 设备上打开的对话(运行中或已结束未关闭,右键可过户到本页查看)`,elsewherePseudoTip:`定时任务/插件正在后台会话中执行,报告会自动落回绑定的对话;不支持过户到当前页面`,elsewhereActions:`操作(过户到本页 / 复制 id…)`,takeoverConversation:`过户到当前页面`,takeoverConfirm:`确认过户到当前页面?`,takeoverHasQuestion:`有问卷等答复,点击直接作答`,waitingQuestionBadge:`有问卷等答复,点击查看`,subagentBadge:`子代理`,collapseSubagents:`折叠子代理`,expandSubagents:`展开子代理`,subagentBadgeCount:`{n} 个子代理`,subagentsStreamingTip:`{n} 个子代理(有子代理运行中)`,subagentsQuestionTip:`{n} 个子代理(等待问卷答复)`,subagentsErrorTip:`{n} 个子代理(存在错误)`,subagentsCountTip:`{n} 个子代理`,convErrorBadge:`子代理运行报错:{error}`,subagentTitle:`子代理 · {title}`,historySessions:`历史对话`,openHistory:`历史对话`,openFiles:`文件列表`,openProject:`打开项目`,streaming:`进行中…`,noHistory:`还没有历史对话`,current:`当前`,messageCount:`{n} 条消息`,tuiTip:`pi 终端(TUI)中的对话`,deleteProject:`从最近项目移出`,deleteProjectConfirm:`确认移出`,deleteSession:`删除该对话记录(不可恢复)`,deleteSessionConfirm:`确认删除`,renameSession:`重命名该对话`,renameSessionPlaceholder:`输入新名称…`,dismissConversation:`从运行列表移出(历史记录保留)`,dismissConversationConfirm:`确认移出`,pinConversation:`钉住(切换其他对话也不移出)`,unpinConversation:`取消钉住`,pinnedConversation:`已钉住:切换到其他对话时,本对话会一直留在「运行的对话」里,直到被手动移出`,dismissFinishedSubagents:`关闭已结束的子代理({n} 个)`,dismissFinishedSubagentsScoped:`关闭该对话下已结束的子代理(含嵌套,{n} 个)`,dismissStreamingConfirm:`仍在运行,确认强行关闭?(运行将被中止)`,dismissFinishedOnly:`仅关已结束({n})`,dismissForceAll:`强行全关(含子代理 {n})`,forceDismissTitle:`强行关闭本对话及全部 {n} 个子代理(运行中的 {m} 个将被中止)`,forceDismissConversation:`强行关闭对话(含全部子代理)`,persistSubagent:`固化为普通对话`,saveEphemeral:`保存为正式对话`,forceDismissConfirm:`确认强行关闭?未结束的运行将被中止,再点一次`,noFinishedSubagents:`没有可关闭的已结束子代理`,collapseSection:`折叠`,expandSection:`展开`,emptyChat:`空对话`,reaskDirectly:`直接重问`,reaskDirectlyTip:`直接从这里重新提问(不修改内容,新建分支对话,原对话保留)`,editReask:`编辑重问`,editReaskTip:`修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)`,forkSession:`派生分支`,forkSessionTip:`从此消息处派生新分支会话(截取该位置之前的转录)`,rollbackSession:`回滚到此`,rollbackSessionTip:`丢弃此消息之后的内容,在当前会话直接继续`,rollbackConfirm:`确定要回滚到此消息吗?该消息之后的所有对话将被丢弃,并在当前会话继续。`,rollbackRestoreWorkspace:`同时还原工作区物理文件(Dual-State Rollback)`,rollbackRestoreWorkspaceTip:`还原物理代码到该消息发起时的检查点版本(通过 Git 影子快照)`,toolApprovalTitle:`工具执行待审批(Human-in-the-Loop)`,toolApprovalApprove:`批准执行`,toolApprovalDeny:`拒绝`,toolApprovalEditAndRun:`修改并放行 (Edit & Run)`,toolApprovalRiskAlert:`检测到高危操作或关键配置修改`,toolApprovalHitsTitle:`高危命中清单`,approvalHitPos:`位置:第 {index} 字符起(长 {length} 字符)`,approvalCommandPreview:`高危命令定位`,toolApprovalParams:`工具调用参数`,toolApprovalEditPlaceholder:`就地修改参数 JSON…`,toolApprovalCategory:`规则档位`,toolApprovalAllowCategory:`本对话允许同类`,toolApprovalAllowCategoryHint:`本对话内这一类高危操作后续不再询问(设置 →「工具」页可撤销)`,toolApprovalAllowConversation:`本对话全部允许`,toolApprovalAllowConversationHint:`本对话内所有高危操作后续都不再询问(设置 →「工具」页可撤销)`,toolApprovalEnabled:`工具执行审批(人机协同)`,toolApprovalEnabledDesc:`开:高危操作(rm -rf / 破坏性 git / 敏感文件 / 工作区外写入 / 插件要求确认)弹窗等你批准、拒绝或改参数;关:一切审批都不弹(内置高危检测直接放行,插件要求确认也按放行处理)。`,toolApprovalPolicyTitle:`已记住的放行(本对话)`,toolApprovalPolicyAllowAll:`本对话全部允许审批`,toolApprovalPolicyRevoke:`撤销`,toolApprovalPolicyHint:`只存在内存里:重启服务或新对话即恢复询问;策略跟对话走(手动过户时一起搬)。`,settingsApprovalRules:`审批规则`,settingsApprovalRulesDesc:`全局自定义人机协同拦截规则,支持基于正则/通配符/路径对工具命令或参数配置「需审批」、「直接拒绝」或「免审放行」。规则自顶向下首条匹配优先。`,manageApprovalRules:`管理审批规则`,approvalRuleNew:`新增规则`,approvalRuleEdit:`编辑规则`,approvalRuleDelete:`删除`,approvalRuleReset:`恢复默认`,approvalRuleActionAsk:`需审批`,approvalRuleActionDeny:`直接拒绝`,approvalRuleActionAllow:`免审放行`,approvalRuleTools:`适用工具`,approvalRuleToolsTip:`输入工具名(如 bash、write、edit),以逗号分隔;输入 * 表示匹配所有工具`,approvalRuleField:`检查字段`,approvalRuleFieldCommand:`命令 (command)`,approvalRuleFieldPath:`文件路径 (path)`,approvalRuleFieldParams:`完整参数 JSON (params)`,approvalRuleMatch:`匹配方式`,approvalRuleMatchRegex:`正则表达式 (regex)`,approvalRuleMatchGlob:`通配符 (glob)`,approvalRuleMatchContains:`包含子串 (contains)`,approvalRuleMatchPrefix:`前缀开头 (prefix)`,approvalRuleMatchOutsideWs:`工作区外路径 (outside_workspace)`,approvalRuleValue:`匹配表达式 / 模式串`,approvalRuleValueTip:`根据匹配方式输入对应规则,例如 rm -rf 或 \\.env$`,approvalRuleLabel:`规则名称 (中文)`,approvalRuleLabelEn:`规则名称 (英文)`,approvalRuleReason:`拦截原因说明 (中文)`,approvalRuleReasonEn:`拦截原因说明 (英文)`,approvalRuleEnabled:`启用该规则`,approvalRuleBuiltin:`内置`,approvalRuleEmpty:`当前没有审批规则。点击右上角「+ 新增规则」添加自定义拦截与放行策略。`,approvalRuleMoveUp:`上移`,approvalRuleMoveDown:`下移`,settingsMcp:`MCP 服务器`,settingsMcpDesc:`Model Context Protocol (MCP) 服务器管理。支持通过 stdio 或 HTTP 将外部工具引入 AI 会话。配置支持 Pi 全局 (~/.pi/agent/mcp.json) 与当前项目 (.pi/mcp.json)。`,mcpReload:`重新加载`,mcpAddServer:`添加服务器`,mcpFilterAll:`全部`,mcpFilterGlobal:`全局设置`,mcpFilterProject:`项目级设置`,mcpGlobalPath:`全局配置`,mcpProjectPath:`项目配置`,mcpEmptyTitle:`未配置 MCP 服务器`,mcpEmptyDesc:`Model Context Protocol 让 AI 可以访问本地文件系统、数据库、GitHub 或自定义工具服务器。点击下方快捷预设或右上角按钮添加。`,mcpQuickAdd:`快捷添加预设`,mcpScopeGlobal:`全局设置`,mcpScopeProject:`项目级设置`,mcpScopeGlobalHint:`保存在 ~/.pi/agent/mcp.json,在所有项目中通用生效`,mcpScopeProjectHint:`保存在当前工作区 .pi/mcp.json,仅在当前项目生效`,mcpStatusRunning:`运行中`,mcpStatusStopped:`已停用`,mcpStatusError:`异常`,mcpEnableHint:`启用该 MCP 服务器`,mcpDisableHint:`停用该 MCP 服务器(保留配置)`,mcpToolsCount:`包含 {count} 个工具`,mcpDeleteConfirmTitle:`删除 MCP 服务器`,mcpDeleteConfirmDesc:`确定要从{scope}中删除 MCP 服务器「{name}」吗?该操作不可撤销。`,mcpAddModalTitle:`添加 MCP 服务器`,mcpEditModalTitle:`编辑 MCP 服务器`,mcpPresetSelect:`预设模板(快捷填充)`,mcpScopeLabel:`配置作用域`,mcpNameLabel:`服务器标识名`,mcpNamePlaceholder:`例如 filesystem, github, fetch`,mcpTransportLabel:`传输协议`,mcpTransportStdio:`命令行进程`,mcpTransportHttp:`远程端点`,mcpCommandLabel:`启动命令`,mcpCommandPlaceholder:`例如 npx, uvx, node, python`,mcpArgsLabel:`命令行参数`,mcpArgsPlaceholder:`以空格分隔的参数列表,例如 -y @modelcontextprotocol/server-filesystem .`,mcpCwdLabel:`运行工作目录 (cwd)`,mcpCwdPlaceholder:`留空默认跟随工作区`,mcpEnvLabel:`环境变量 (env)`,mcpAddEnv:`添加变量`,mcpEnvKeyPlaceholder:`变量名(如 API_KEY)`,mcpEnvValuePlaceholder:`变量值`,mcpUrlLabel:`端点 URL`,mcpUrlPlaceholder:`例如 https://mcp.example.com/mcp`,mcpHeadersLabel:`请求头 (Headers)`,mcpAddHeader:`添加请求头`,mcpHeaderKeyPlaceholder:`请求头名称(如 Authorization)`,mcpHeaderValuePlaceholder:`值(如 Bearer token)`,mcpDescriptionLabel:`功能说明`,mcpDescriptionPlaceholder:`简要说明此服务器提供的工具能力`,mcpEnabledLabel:`启用状态`,mcpEnabledDesc:`停用后保留配置但不启动子进程或连接端点`,mcpPresetCustom:`自定义配置`,mcpPresetCustomDesc:`手动输入完整的命令与参数`,mcpPresetFilesystem:`文件系统 (Filesystem)`,mcpPresetFilesystemDesc:`访问指定目录文件的标准 MCP 服务器`,mcpPresetFetch:`网页抓取 (Fetch)`,mcpPresetFetchDesc:`抓取并读取网页内容的 MCP 服务器`,mcpPresetMemory:`持久记忆 (Memory)`,mcpPresetMemoryDesc:`基于知识图谱的持久化记忆管理`,mcpPresetGithub:`GitHub 代码库`,mcpPresetGithubDesc:`GitHub 仓库、Issue 与 PR 操作工具`,mcpPresetSqlite:`SQLite 数据库`,mcpPresetSqliteDesc:`查询与操作本地 SQLite 数据库`,mcpTabConfigured:`已配置`,mcpTabMarket:`MCP 市场`,mcpBrowseMarket:`浏览 MCP 市场`,mcpMarketSearchPlaceholder:`搜索 MCP 服务器名称、包名或能力描述…`,mcpBadgeOfficial:`官方`,mcpConfigured:`已配置`,mcpAddGlobal:`添加全局`,mcpAddProject:`添加项目`,mcpAddGlobalHint:`添加至 Pi 全局配置 (~/.pi/agent/mcp.json),在所有项目生效`,mcpAddProjectHint:`添加至当前项目配置 (.pi/mcp.json),仅在当前项目生效`,skillTabInstalled:`已安装`,skillTabMarket:`技能市场`,skillEmptyDesc:`暂未安装任何技能,前往技能市场发现并一键安装开箱即用的专业工作流技能。`,skillBrowseMarket:`浏览技能市场`,skillMarketSearchPlaceholder:`搜索技能名称、工作流或能力说明…`,skillCatAll:`全部`,skillCatQuality:`代码质量`,skillCatWorkflow:`规范与流程`,skillCatArchitecture:`架构设计`,skillCatDevops:`运维与数据库`,skillCatStack:`语言专项`,skillInspectPrompt:`查看提示词`,skillInstalled:`已安装`,skillInstallGlobal:`全局安装`,skillInstallProject:`项目安装`,skillInstallGlobalHint:`安装到全局用户技能目录 (~/.pi/agent/skills)`,skillInstallProjectHint:`安装到当前工作区技能目录 (.pi/skills)`,skillInspectModalTitle:`技能详情: {name}`,mcpSourceSelectLabel:`源选择`,mcpSourceSmithery:`Smithery 开放注册中心 (api.smithery.ai)`,mcpSourceGithub:`GitHub 官方仓库 (modelcontextprotocol/servers)`,mcpSourceCustom:`自定义 API / 目录源`,mcpSourceCustomPlaceholder:`输入自定义 MCP 注册中心 API 或 JSON 目录 URL`,mcpMarketLoading:`正在检索远程 MCP 服务器…`,mcpMarketRetry:`重试`,skillRepoSelect:`GitHub 仓库源`,skillRepoDefault:`Anthropic 官方技能库 (anthropics/skills)`,skillRepoCustom:`自定义 GitHub 仓库 (owner/repo)`,skillRepoCustomPlaceholder:`输入 GitHub 仓库,例如 your-org/custom-skills`,skillMarketLoading:`正在从 GitHub 检索技能目录…`,skillContentLoading:`正在拉取 SKILL.md 指令内容…`,skillMarketRetry:`重试`,planBoardTitle:`任务`,planBoardCompleted:`已完成`,planBoardInProgress:`进行中`,planBoardPending:`待执行`,planBoardFailed:`失败`,planImplementBtn:`实施`,planImplementTip:`关掉只规划闸门,按上面的计划开始写代码`,planImplementRequest:`按计划看板上的计划开始实施。`,planBoardExportMarkdown:`复制为 Markdown`,planBoardExportSuccess:`计划已复制为 Markdown`,planCleanHandoffBtn:`✨ 净室`,planCleanHandoffTip:`在新会话中开始实施(带走目标与计划,避免历史探索上下文干扰)`,planCleanHandoffPrompt:`我们已在规划期制定了如下任务计划。这是一个全新的净室执行会话,请专注于按照计划步骤推进实施:`,planBoardAddStep:`添加步骤`,planBoardEditStep:`编辑步骤`,planBoardDeleteStep:`删除步骤`,planBoardStepTitlePlaceholder:`步骤标题…`,planBoardStepDescPlaceholder:`步骤描述/验收要求(可选)…`,placeholderPlanMode:`📋 计划模式:只调研与制定计划,代码写入操作将被拦截…`,planModeBadge:`只读规划中`,clear:`清空`,confirm:`确定`,forkBadge:`分支`,forkBadgeTip:`派生自`,reaskFromHere:`从此处重新提问`,editPlaceholder:`修改问题内容…`,editAttachmentHint:`原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消`,expandMsg:`展开`,collapseMsg:`收起`,toolCalls:`工具调用`,bashRuns:`终端运行`,images:`图片`,update:`更新`,currentVersion:`当前版本`,latestVersion:`最新版本`,checkingUpdate:`检查中…`,checkUpdate:`检查更新`,upToDate:`已是最新版本`,updateAvailable:`发现新版本 v{version}`,updateJustPublished:`v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查`,updateNow:`在终端中更新`,updateTabTitle:`更新 pi-web-ui`,updateTerminalHint:`点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。`,updateDesktopNote:`桌面版不走 npm 全局安装:它的服务随应用本身发布,上面的终端命令对它无效。请用下面的应用内更新,或去下载页换包。`,updateDesktopCheck:`检查桌面更新`,updateDesktopChecking:`正在检查桌面更新…`,updateDesktopAvailable:`发现桌面版新版本 v{version}`,updateDesktopDownload:`下载更新`,updateDesktopDownloading:`下载中 {n}%`,updateDesktopDownloaded:`已下载完成,点“安装并重启”生效`,updateDesktopInstall:`安装并重启`,updateDesktopManual:`去下载页手动安装`,updateDesktopError:`桌面更新失败:{error}`,updateDesktopNoBridge:`当前桌面壳太旧,没有内置更新通道,请去下载页换包。`,updatesAllTitle:`全部组件更新`,updatesAllBadge:`{n} 个更新`,updatesAllUpToDate:`全部组件均为最新`,kindWebUi:`Web 界面`,kindPiCore:`核心`,kindPackage:`组件`,kindGitExtension:`Git 组件`,kindPlugin:`插件`,pluginCheckUpdates:`检查插件更新`,pluginCheckUpdatesHint:`检查已安装界面插件是否有新版本(对比远端版本与 commit)`,pluginUpdateAvailableBadge:`可更新`,pluginUpdateAvailableDetail:`可更新:{version}`,updatesAllRefresh:`重新检查全部`,updateCheckFailed:`检查失败`,updateBtn:`更新`,updateAllBtn:`全部更新`,updatePkgTabTitle:`更新 {name}`,updateAllTabTitle:`更新全部组件`,piCoreSplitRun:`服务运行 v{running}`,piSdkSplitNote:`本服务运行的是 pi v{running};机器上装有更新的全局 pi v{installed}。重启服务即可跟上(默认自动选用更新的那份);设了 PI_WEB_SDK=bundled 时会一直用自带副本,升级 pi-web-ui 也可让自带副本跟上。`,piSdkBundledNote:`当前使用随包自带的 pi 引擎 v{running}(随 pi-web-ui 更新)。安装全局引擎后重启服务即可自动切换(服务默认跟随版本更高的那份)。`,installGlobalEngineBtn:`安装全局引擎`,installGlobalEngineTabTitle:`安装全局 pi 引擎`,restartService:`重启服务`,restartingService:`重启中…`,restartServiceTip:`重启 pi-web-ui 服务({name}):本实例由系统服务托管(launchd/systemd/Windows watchdog),进程退出后会被自动拉起,本页会自动重连;更新完成后用它生效`,computer:`此电脑`,workspaceModeLocal:`本地目录`,workspaceModeRemote:`远程 (SSH)`,sshHost:`主机地址`,sshPort:`端口`,sshUser:`用户名`,sshAuthType:`认证方式`,sshPassword:`密码`,sshKeyPath:`私钥路径`,sshAgent:`SSH 代理 (Agent)`,sshSaveProfile:`记住此连接`,sshProfileName:`配置名称 (可选)`,sshConnectAndProbe:`连接并探测环境`,sshConnecting:`正在连接与探测环境…`,sshSavedProfiles:`已保存的远程连接`,sshInstallTool:`一键自动安装`,sshInstalling:`正在安装…`,sshSkipAndBrowse:`跳过并继续浏览`,sshOpenRemoteWorkspace:`打开此远程工作区`,sshDisconnect:`断开连接`,sshDeleteProfileConfirm:`确认删除此连接配置吗?`,rootDir:`根目录`,homeDir:`用户目录`,desktopDir:`桌面`,filesHelp:`浏览:点文件夹进入、点文件预览,「..」返回上级;「根目录」回当前项目根,「此电脑」浏览全盘换盘符,「🏠」直达用户目录,「🖥️」直达桌面。
4
4
  文件操作:右键可新建文件/文件夹、重命名、复制/剪切/粘贴、创建副本、删除、上传文件;文件可下载,行尾按钮可复制名称/路径。
@@ -324,7 +324,7 @@ Avoid three test anti-patterns: tests coupled to the implementation, tautologica
324
324
 
325
325
  {path}
326
326
 
327
- It only opens after you confirm.`,settingsExtensions:`Extensions`,settingsUiPlugins:`UI plugins`,pluginListTab:`Plugin list`,noUiPlugins:`No UI plugins installed (<dataDir>/plugins/)`,pluginPhaseActive:`Active`,pluginPhaseDisabled:`Disabled`,pluginPhaseFailed:`Failed`,pluginPhaseIdle:`Frontend-only`,pluginRescan:`Rescan`,pluginRescanHint:`Re-scan the plugin directory (picks up new/fixed plugins; failure records are cleared and re-evaluated)`,dshPatches:`DSH user patches`,dshPatchesDesc:`Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.`,dshPatchesRescan:`Rescan`,dshPatchesRescanHint:`Re-scan the patch directory and restart the DSH runtime so new patches take effect`,dshPatchesEmpty:`No patch files yet`,dshPatchesPath:`Patch directory: `,dshPreset:`Agent preset`,dshPresetNewChat:`New chat with this preset`,dshPresetLocked:`Locked`,dshPresetBlankOnly:`Locked after the first message; blank sessions can switch`,dshPresetBroken:` (unavailable)`,dshPresetUser:`custom`,dshPresetDefaultTag:`default`,dshPresetMinimalNote:`Minimal: persistent shell only; host plugin tools and questionnaire unavailable`,dshDefaultPreset:`Default preset`,dshDefaultPresetDesc:`Preset for new chats; blank sessions can switch anytime, locked after the first message`,dshPresetUserNote:`Custom presets come from the user preset directory (trusted like shell access); compositions using bare package names cannot mount here (known limitation)`,"preset.standard":`Full access`,"preset.minimal":`Minimal`,"preset.code":`Code development`,"preset.reader":`Read-only analysis`,"preset.ask":`Chat only`,"preset.standardDesc":`All available tools and extension capabilities (default)`,"preset.minimalDesc":`Keeps only bash and read; plugin tools, skill catalog and terminal guidance are hidden too`,"preset.codeDesc":`Focused on reading, writing and running code (bash, read, edit, write, edit_soft); plugin tools and skill catalog are hidden too`,"preset.readerDesc":`Keeps only read-only tools and forbids writes; plugin tools are hidden too (read/write unknown, handled conservatively)`,"preset.askDesc":`No-tools Q&A: the model never calls a tool; plugin tools and skill catalog are hidden too`,dshPerm:`Permissions`,dshPermReadOnly:`Read Only`,dshPermReadOnlyDesc:`Read files and run read-only commands; writes are always denied, no prompts`,dshPermWorkspaceWrite:`Workspace Write`,dshPermWorkspaceWriteDesc:`Read/write inside the workspace, no prompts; out-of-scope operations are denied directly`,dshPermFullAccess:`Full access`,dshPermFullAccessDesc:`Sandbox off, unrestricted machine access; only for tasks you trust`,dshPermFullAccessTag:`risky`,dshPermCustom:`Custom`,dshPermConfirmFull:`Click again to confirm full access`,dshPermDefault:`Default permission for new chats`,dshPermDefaultDesc:`Initial permission for new chats; the current chat can switch live anytime, no restart`,uiPluginNoSource:`Installed manually — no recorded source, online update unavailable`,uiPluginPerms:`Permissions`,pluginDiagTitle:`Diagnostics`,pluginDiagShow:`Diagnostics`,pluginDiagHide:`Hide`,pluginLogTitle:`Runtime logs`,pluginLogShow:`Logs`,pluginLogHide:`Hide`,pluginLogLevel:`Level`,pluginLogAll:`All`,pluginLogEmpty:`No logs yet`,pluginLogClear:`Clear`,pluginDomNeed:`⚠ Requests full DOM access`,pluginDomDesc:`This plugin can freely read and write the page DOM (bypassing UI layout restrictions). Grant only to plugins from sources you trust; once granted its UI code can touch the topbar, composer and any page element.`,pluginDomGrant:`Grant DOM access`,pluginDomRevoke:`Revoke DOM access`,pluginDomGranted:`Full DOM access granted`,pluginSettingsTitle:`Configuration`,pluginSettingsShow:`Configure`,pluginSettingsHide:`Hide`,pluginSettingsSave:`Save plugin settings`,pluginSettingsSaving:`Saving…`,pluginSettingsReset:`Reset defaults`,pluginSettingsInherit:`Follow global default`,pluginSecretSet:`Set (stored encrypted, leave blank to keep)`,pluginSecretUnset:`Not set (stored encrypted)`,settingsPresets:`Presets`,settingsSubagentTemplates:`Subagent templates`,settingsSubagentTemplatesDesc:`Presets for spawned subagents (role system prompt + skills/extensions whitelist + optional model and thinking level). AI may pick a template (subagent_spawn template param) or spawn without one; disabled templates stay in the panel but are invisible to AI tools.`,noSubagentTemplates:`No subagent templates yet. AI can pick a template when spawning a subagent (role prompt + skills/extensions whitelist + optional model and thinking level), or spawn without a template param for default config.`,subagentTemplateNew:`New template`,subagentTemplateEdit:`Edit`,subagentTemplateClosed:`Disabled`,tplDefaultBadge:`Built-in`,subagentDefaultModelLabel:`Default subagent model`,subagentFollowMain:`Follow the main conversation's current model`,subagentDefaultModelHint:`Fallback model for all subagents (a template's own model and the subagent_spawn model param take priority); does not change the main conversation's model.`,subagentNoModels:`No usable models yet (configure a provider API key first) — subagents will follow the main conversation's model.`,subagentTemplateOffHint:`Disabled templates stay in the panel and can be re-enabled, but AI tools can't see or pick them`,subagentTemplateEnable:`Enable`,subagentTemplateDisable:`Disable`,tplNamePlaceholder:`Template name (referenced by AI via subagent_spawn's template param)…`,tplDescriptionPlaceholder:`Description (AI uses it to judge when to pick this template)…`,tplDescriptionEnPlaceholder:`English description (shown to AI under English UI; falls back to the description above)…`,tplPromptModeLabel:`System prompt mode`,tplModelLabel:`Model (empty = follow main conversation)`,tplThinkingLabel:`Thinking level`,tplThinkingFollowMain:`Follow the main conversation's current thinking level`,tplThinkingHint:`Empty = follow the main conversation's current thinking level (same idea as the model fallback); unsupported levels are clamped to the nearest one the model supports.`,tplSystemPromptLabel:`System prompt`,tplSystemPromptPlaceholder:`Template role system prompt… (may be empty in append mode)`,tplSystemPromptEnPlaceholder:`English system prompt… (used under English UI; falls back to the prompt above)`,tplWhitelistHint:`Whitelist: checked = the subagent only gets these; none checked = follow the main session settings`,tplSkillsLabel:`Skills whitelist`,tplExtensionsLabel:`Extensions whitelist`,tplSave:`Save template`,tplCancel:`Cancel edit`,tplDelete:`Delete template`,settingsScheduler:`Scheduled tasks`,schedulerDesc:`Put the agent on a schedule (dependency audits, test runs, morning briefings…): headless pseudo-client runs, no browser needed; notifies when done, history included.`,schedulerEmpty:`No scheduled tasks yet. Click “New task” above to schedule the first one: a 9 AM daily check or an hourly test run.`,schedulerNew:`New task`,schedulerEdit:`Edit`,schedulerDelete:`Delete`,schedulerRunNow:`Run now`,schedulerRunning:`Running…`,schedulerEnable:`Enable`,schedulerDisable:`Disable`,schedulerEnabled:`Enabled`,schedulerDisabled:`Disabled`,schedulerNamePlaceholder:`E.g. Daily dependency & health check…`,schedulerDescPlaceholder:`Description (optional): what this task does…`,schedulerCwdLabel:`Target project`,schedulerCwdPlaceholder:`/absolute/path/to/project…`,schedulerUseCurrentCwd:`Use current project`,schedulerKindLabel:`Schedule`,schedulerKindCron:`Cron expression`,schedulerKindInterval:`Fixed interval`,schedulerCronPlaceholder:`E.g. 0 9 * * * (daily 9:00 AM)`,schedulerPresetDaily:`Daily 9:00 AM`,schedulerPresetHourly:`Hourly on the hour`,schedulerPresetHalfHour:`Every 30 minutes`,schedulerPresetWorkday:`Weekdays 9:00 AM`,schedulerPresetMonday:`Mondays 9:00 AM`,schedulerPresetCustom:`Custom…`,schedulerIntervalMinutes:`Interval (minutes, min 1)`,schedulerPromptPlaceholder:`The task for the agent, e.g. audit dependencies and report upgrades…`,schedulerModelLabel:`Model (empty = default)`,schedulerThinkingLabel:`Thinking level (empty = default)`,schedulerCatchUp:`Catch up one missed run after restart`,schedulerCatchUpHint:`When checked, a trigger missed during downtime runs once at next startup; otherwise it is skipped.`,schedulerNextFire:`Next`,schedulerLastRun:`Last`,schedulerNeverRun:`Never ran`,schedulerHistory:`History`,schedulerManualBadge:`manual`,schedulerRunOk:`ok`,schedulerRunFail:`failed`,schedulerConfirmDelete:`Delete scheduled task “{name}”? Its history goes with it.`,schedulerSave:`Save task`,schedulerCancelEdit:`Cancel edit`,tplInherit:`Follow main session`,settingsEnabled:`Enabled`,settingsDisabled:`Disabled`,presetNamePlaceholder:`Preset name…`,saveAsPreset:`Save as preset`,applyPreset:`Apply`,deletePreset:`Delete preset`,noSkills:`No skills`,noExtensions:`No extensions`,noPresets:`No presets yet (tune your current settings, then enter a name above to save them as a preset)`,presetShare:`Share presets`,presetShareShareBtn:`Share preset`,presetShareImportBtn:`Import preset`,presetShareBrowseBtn:`Browse shared`,presetShareTabExport:`Export / share`,presetShareTabImport:`Import`,presetShareTabBrowse:`Browse shared`,presetShareSource:`Source`,presetShareSourceCurrent:`Current settings`,presetShareDescription:`Description`,presetShareDescriptionPlaceholder:`What is this preset good for? (optional)`,presetShareTags:`Tags`,presetShareTagsPlaceholder:`Comma separated, e.g. coding, minimal (optional)`,presetShareAuthor:`Author (optional)`,presetExportJson:`Export JSON`,presetExportDownload:`Download file`,presetShareSubmit:`Share to the community repo`,presetShareHint:`Creates a GitHub issue: with the gh CLI or a GitHub token it is submitted for you (the repo bot validates and commits it, and it shows up under "Browse shared" within minutes). With neither, a prefilled new-issue page opens — just hit Submit (for very large presets the JSON is copied to the clipboard instead, so you can paste it).`,presetShareSubmitting:`Submitting…`,presetShareOpenWebTitle:`Submit Issue on GitHub`,presetShareOpenWebBtn:`Open submission page in new window`,presetShareOpenIssueBtn:`View created issue`,presetShareCopyJson:`Copy preset JSON`,presetSharePopupBlocked:`If your browser blocked the popup, click the button below to open:`,presetShareBrowserCopied:`Submission page generated — just hit Submit (for large presets the JSON is on your clipboard, paste it)`,presetImportText:`Paste preset JSON`,presetImportTextPlaceholder:`Paste the exported JSON here (or drop a .json file)…`,presetImportPickFile:`Choose file`,presetImportFromUrl:`Import from URL`,presetImportUrlPlaceholder:`https://raw.githubusercontent.com/…/preset.json`,presetImportPreview:`Preview`,presetImportFields:`{n} fields will be written`,presetImportIgnored:`Unknown fields ignored: {list}`,presetImportRejected:`Dropped (wrong type): {list}`,presetImportReplaces:`A local preset with this name already exists — importing overwrites it`,presetImportApply:`Apply right after importing`,presetImportConfirm:`Import`,presetImportPick:`Import selectively: pick what to write`,presetImportSelectAll:`All`,presetImportSelectNone:`None`,presetImportAllSelected:`All selected`,presetImportNoneSelected:`Select at least one field to import`,presetImportPickHint:`Unchecked fields keep your current values; you can still tweak everything afterwards in Settings.`,presetGroupPrompt:`Prompts`,presetGroupTools:`Tools & switches`,presetGroupTerminal:`Terminal takeover`,presetGroupSkills:`Skills & extensions`,presetGroupAi:`Model behavior & dedicated prompts`,presetGroupUi:`Interface & interaction`,presetGroupEngine:`Engine defaults`,presetGroupOther:`Other`,presetImportImported:`Imported: {name}`,presetBrowseEmpty:`No presets in the shared repo yet`,presetBrowseLoading:`Loading community presets…`,presetBrowseSearch:`Search name / tag / author`,presetBrowseRefresh:`Refresh list`,presetBrowseCached:`List cached at {time} — hit refresh to re-fetch`,presetBrowseImport:`Import`,presetBrowseIssue:`Source issue`,presetBadgeTemplate:`Has template`,presetBadgeReview:`Has review prompt`,loadingSession:`Loading session…`,connectingServer:`Connecting to pi-web-ui server…`,localePacks:`Language packs`,localeGetMore:`Get more languages`,localeInstalled:`Installed`,localeInstall:`Download`,localeRemove:`Remove`,localeDownloading:`Downloading…`,localeRemoving:`Removing…`,localeInstallFailed:`Download failed: {error}`,localeListFailed:`Couldn't load language packs: {error}`,localeRemoveHint:`You can re-download it anytime`,wallpaperTitle:`Chat wallpaper`,wallpaperDesc:`Show a full-window background image (side panels, top and bottom bars included): a theme-provided image applies automatically, a URL here takes precedence; use dim and blur to keep text readable.`,wallpaperUrlPh:`Image URL (https://…, empty = off)`,wallpaperDim:`Dim`,wallpaperBlur:`Blur`,wallpaperClear:`Clear`,wallpaperUpload:`Upload image`,wallpaperUploadFailed:`Couldn't read the image (or it's too big) — try another one`,skillFullTextLabel:`Inject full skill text`,skillFullTextDesc:`Expand skill file contents inline into the system prompt (8KB per file, 32KB total cap); otherwise only a catalog is listed and the model reads files on demand`,skillFullTextShort:`Full`,delegateOpenSubagent:`Open subagent`,delegateSecTask:`Task`,delegateSecExpected:`Expected outcome`,delegateSecTools:`Required tools`,delegateSecMustDo:`Must do`,delegateSecMustNotDo:`Must not do`,delegateSecContext:`Context`,copyConversationId:`Copy conversation ID`,copyConversationPath:`Copy session file path`,copyConversationLink:`Copy link to session`,copyMessageLink:`Copy link to message`,quoteConversation:`Quote into composer (readable by the AI)`,quoteConversationShort:`Quote`,attachConversation:`Conversation reference: {name} (the AI reads it via conversation_read on demand)`,attachConversationShort:`conversation`,quoteSelection:`Quote`,quoteText:`Text quote`,quoteSource:`Source message: {id}`,removeQuote:`Remove quote`,presentOpenLocal:`Open locally`,presentMissing:`File missing or unreadable (moved, deleted, or outside the workspace?)`,presentEmpty:`Nothing to show`,presentAutoOpen:`Auto-open previews the AI presents`,presentAutoOpenDesc:`When the AI presents files with present_files and marks one as 'look at this first', open the file preview dialog automatically. Off (default): the cards stay inline and you open them with one click.`,presentFilesEnabledDesc:`Let the AI push artifacts (screenshots, charts, videos, reports, logs) into the chat as preview cards: images/videos/audio are shown inline, text gets an excerpt plus a one-click preview dialog, and every row carries open-locally / reveal-in-file-manager / download / copy-path actions. The auto-open switch lives on the Chat page.`,presentFilesOffHint:`Disabled: the AI can only tell you the file path — no cards, no open-locally buttons`,skillEnabledDesc:`Load skill bodies by name (the skill catalog stays in the system prompt): the full text is fetched only when a skill is actually needed, instead of making the model guess a path and call read.`,skillOffHint:`Disabled: the AI can no longer load skill bodies by name (the catalog in the prompt is unaffected)`,claimFilesEnabledDesc:`Declare which files you are about to edit so parallel runs in the same project can steer clear (advisory only — it never blocks edits). First-wins; claims expire automatically.`,claimFilesOffHint:`Disabled: the AI can no longer claim files (post-hoc touch reminders still work, only the up-front intent signal is gone)`,planUpdateEnabledDesc:`Structured task plan updates (Plan Mode / Step State Machine): allows the model to break complex tasks into steps and track progress in real time.`,planUpdateOffHint:`Disabled: AI can no longer update the structured plan board`,compactContextEnabledDesc:`Proactively compact context based on the current issue: allows AI to independently specify compression focus, retain core task context, drop irrelevant history, and control retention scope.`,compactContextOffHint:`Disabled: AI cannot proactively invoke context compaction (you can still use /compact or trigger auto-compaction)`,evalEnabledDesc:`Execute Python or JavaScript/TypeScript code in an isolated sandbox with persistent variables; ideal for calculations, data analysis, and algorithm verification (default-off to prevent tool crowding-out).`,evalOffHint:`Disabled: the AI cannot use the persistent code sandbox (can still run scripts via bash)`,patchToolEnabledDesc:`High-reliability structural patch tool (Hashline): line-anchored editing with 4-hex content hashes, syntactic AST block matching, and clipboard registers. Automatically attempts 3-way merge conflict recovery if files diverged.`,patchToolOffHint:`Disabled: AI falls back to basic string replacement via edit`,lspToolEnabledDesc:`Native Language Server Protocol (LSP) tool: IDE-grade semantic code intelligence (definition, references, hover, diagnostics, documentSymbol outline, read_symbol precise slicing, workspaceSymbol search, and cascade impact diagnostics). Multi-agent shared process pool with idle sleep, zero external dependencies.`,lspToolOffHint:`Disabled: AI cannot query LSP semantics and falls back to text search`,codemodeEnabledDesc:`Run JavaScript in a QuickJS WASM sandbox to batch tool calls and filter output: intermediate results never enter LLM context, keeping context concise (default off; requires capable model).`,codemodeOffHint:`Disabled: AI cannot run codemode scripts to batch call tools`,codemodeNestedCalls:`Nested tool calls`,codemodeScript:`JavaScript script`,codemodeFullOutput:`Full output file`,codemodeModeLabel:`Execution Mode`,codemodeModeHint:`In standard mode all tools are directly visible; in strict code mode tools are hidden from the model and must be invoked via sandbox scripts`,codemodeModeOn:`Standard Mode (on)`,codemodeModeOnly:`Strict Code Mode (only)`,codemodeInlineBudgetLabel:`Inline Budget`,codemodeInlineBudgetHint:`Estimated tokens the codemode prompt may spend on tool declarations directly (default: 3000)`,codemodeNestedApprovalBadge:`Nested Call`,codemodeNestedApprovalDesc:`This tool call was triggered by a background codemode sandbox script`,codemodeSavedImages:`Generated Images`,toolSearchEnabledDesc:`BM25-based tool discovery and activation: search and activate tools via natural language queries (ideal for large MCP toolsets to prevent context bloat).`,toolSearchOffHint:`Disabled: AI cannot use tool_search to discover tools`,toolSearchLoaded:`Activated tools`,toolInfoMenuLabel:`Show tool details`,toolInfoTitle:`Tool details`,toolInfoLoading:`Loading tool definition…`,toolInfoUnsupported:`This engine can't show tool definitions`,toolInfoMissing:`No definition found for this tool (it may come from an uninstalled plugin or an older version)`,toolInfoActive:`Enabled`,toolInfoInactive:`Disabled`,toolInfoSource:`Source`,toolInfoDescription:`Description`,toolInfoNoDescription:`This tool has no description`,toolInfoPromptSnippet:`Prompt snippet`,toolInfoGuidelines:`Prompt guidelines`,toolPromptEdit:`Edit description`,toolPromptEdited:`Description customized (click to edit)`,toolPromptHint:`Leave a field empty to use the tool's built-in text. The three fields map to the tool description the model sees, the one-line summary in the system prompt, and the behavioral guidelines.`,toolPromptDescription:`Tool description (how the model understands this tool)`,toolPromptSnippet:`Prompt snippet (the line in the system prompt's Available tools list)`,toolPromptGuidelines:`Behavioral guidelines (Guidelines section, one per line)`,toolPromptDefault:`Built-in text`,toolPromptReset:`Reset to default`,toolPromptSave:`Save`,toolPromptUnavailable:`No definition for this tool (engine unsupported, or the tool is uninstalled) — you can still fill in overrides, but they only apply once the tool exists.`,toolInfoParams:`Parameters`,toolInfoParamsNone:`This tool takes no parameters`,toolInfoSchemaDropped:`The parameter schema is too large and was omitted (see the raw JSON below)`,toolInfoRawSchema:`Raw JSON schema`,toolInfoRequired:`required`,toolInfoFootnote:`This is the tool's definition — not this call's arguments or result.`,elsewhereOfflineBadge:`Offline`,elsewhereOfflineTip:`The page holding this conversation is gone (tab or browser closed) but the run is still on the server — click this row twice to take it over here`},xn=[{code:`zh`,nativeName:`中文`},{code:`en`,nativeName:`English`}],Sn={};function Cn(e){return!e||typeof e.code!=`string`||!e.code||e.code===`zh`||e.code===`en`||!e.strings||typeof e.strings!=`object`?!1:(Sn[e.code]=e,!0)}function wn(e){delete Sn[e]}function Tn(e){return e===`zh`?`中文`:e.toUpperCase()}function En(e){return e===`zh`?`zh-CN`:e===`pt`?`pt-BR`:e}async function Dn(e){let t=await fetch(hn(dn(e)));if(!t.ok)throw Error(`HTTP ${t.status} for ${e}`);return await t.json()}var On=(0,g.createContext)(null);function kn(){try{return localStorage.getItem(vn)}catch{return null}}function An(){return _n(kn(),typeof navigator<`u`?navigator.languages:[],null)}function jn({children:e}){let[t,n]=(0,g.useState)(An),[r,i]=(0,g.useState)(0),a=(0,g.useRef)(t);a.current=t;let o=(0,g.useCallback)(e=>{n(e);try{localStorage.setItem(vn,e)}catch{}try{window.dispatchEvent(new CustomEvent(`pi-web-ui:locale`,{detail:e}))}catch{}},[]),s=(0,g.useCallback)(async()=>{let e,t=null;try{let n=await Dn(`/api/locales`);e=n.packs??[],t=n.defaultLocale??null}catch{return null}return await Promise.all(e.filter(e=>e.installed).map(async e=>{try{let t=await Dn(`/api/locales/${e.code}`);return Cn({code:t.code||e.code,nativeName:t.nativeName||e.nativeName,strings:t.strings}),!0}catch{return!1}})),i(e=>e+1),t},[]);(0,g.useEffect)(()=>{s().then(e=>{if(!kn()?.trim()){let t=_n(null,typeof navigator<`u`?navigator.languages:[],e);t!==a.current&&(a.current=t,n(t))}let t=a.current;if(t!==`zh`&&t!==`en`&&!Sn[t]){let t=_n(null,typeof navigator<`u`?navigator.languages:[],e,[`zh`,`en`]);a.current=t,n(t);try{localStorage.setItem(vn,t)}catch{}}})},[s]);let c=(0,g.useMemo)(()=>[...xn,...Object.values(Sn).map(e=>({code:e.code,nativeName:e.nativeName}))],[r]),l=(0,g.useCallback)((e,n)=>{let r=Sn[t]?.strings[e];r&&t!==`zh`&&t!==`ja`&&/[\u4e00-\u9fff]/.test(r)&&(r=void 0);let i=r??(t===`zh`?yn[e]:bn[e]);if(n)for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[t,r]);(0,g.useEffect)(()=>{document.documentElement.lang=En(t)},[t]);let u=(0,g.useMemo)(()=>({locale:t,setLocale:o,t:l,packs:c,reloadPacks:s}),[t,o,l,c,s]);return(0,X.jsx)(On.Provider,{value:u,children:e})}function Mn(){let e=(0,g.useContext)(On);if(!e)throw Error(`useI18n must be used within LanguageProvider`);return e}function Z(){return Mn().t}var Nn=[{kind:`question`,labelKey:`sound.question`,descKey:`sound.question.desc`},{kind:`done`,labelKey:`sound.done`,descKey:`sound.done.desc`},{kind:`start`,labelKey:`sound.start`,descKey:`sound.start.desc`},{kind:`error`,labelKey:`sound.error`,descKey:`sound.error.desc`},{kind:`approval`,labelKey:`sound.approval`,descKey:`sound.approval.desc`}];function Pn({settings:e,onChange:t,onPreview:n}){let r=Z(),i=n=>t({...e,...n});return(0,X.jsxs)(`div`,{className:`sound-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:r(`soundHeader`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(P,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:r(`enableSound`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>i({enabled:e.target.checked})})]}),Nn.map(({kind:t,labelKey:a,descKey:o})=>(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(a)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(o)})]}),(0,X.jsxs)(`span`,{className:`sound-right`,children:[(0,X.jsx)(`button`,{type:`button`,className:`sound-preview`,title:r(`preview`),disabled:!e.enabled,onClick:e=>{e.preventDefault(),n(t)},children:r(`preview`)}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e[t],disabled:!e.enabled,onChange:e=>i({[t]:e.target.checked})})]})]},t)),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`volume`)}),(0,X.jsx)(`input`,{type:`range`,min:0,max:100,step:5,value:e.volume,disabled:!e.enabled,onChange:e=>i({volume:Number(e.target.value)})}),(0,X.jsxs)(`span`,{className:`sound-vol-num`,children:[e.volume,`%`]})]})]})}function Fn(){let[e,t]=(0,g.useState)([]);return(0,g.useEffect)(()=>{if(!Kt())return;let e=window.speechSynthesis,n=()=>t(e.getVoices().map(e=>({voiceURI:e.voiceURI,lang:e.lang,name:e.name,localService:e.localService})));return n(),e.addEventListener?.(`voiceschanged`,n),()=>e.removeEventListener?.(`voiceschanged`,n)},[]),e}function In({settings:e,onChange:t,onPreview:n}){let r=Z(),i=Fn(),a=Kt(),o=n=>t({...e,...n});return(0,X.jsxs)(`div`,{className:`sound-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:r(`ttsHeader`)}),!a&&(0,X.jsx)(`div`,{className:`sound-desc tts-unavailable`,children:r(`ttsUnavailable`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master ${a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(P,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:r(`ttsEnable`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsEnableDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:!a,onChange:e=>o({enabled:e.target.checked})})]}),(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsAnnounce`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsAnnounceDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.announce,disabled:!e.enabled||!a,onChange:e=>o({announce:e.target.checked})})]}),(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsReadReplies`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsReadRepliesDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.readReplies,disabled:!e.enabled||!a,onChange:e=>o({readReplies:e.target.checked})})]}),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsRate`)}),(0,X.jsx)(`input`,{type:`range`,min:.5,max:2,step:.1,value:e.rate,disabled:!e.enabled||!a,onChange:e=>o({rate:Number(e.target.value)})}),(0,X.jsxs)(`span`,{className:`sound-vol-num`,children:[e.rate.toFixed(1),`×`]})]}),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsVoice`)}),(0,X.jsxs)(`select`,{className:`set-input tts-voice-select`,value:e.voiceURI,disabled:!e.enabled||!a,onChange:e=>o({voiceURI:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:r(`ttsVoiceAuto`)}),i.map(e=>(0,X.jsxs)(`option`,{value:e.voiceURI,children:[e.name,` (`,e.lang,`)`,e.localService?``:` · ${r(`ttsVoiceOnline`)}`]},e.voiceURI))]})]}),(0,X.jsx)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:(0,X.jsx)(`button`,{type:`button`,className:`sound-preview tts-preview`,disabled:!e.enabled||!a,onClick:()=>{if(e.voiceURI&&!qt(e.voiceURI,i,navigator.language)){t({...Ut,...e,voiceURI:``});return}n()},children:r(`preview`)})})]})}function Ln(e){let t=e??(typeof window>`u`?void 0:window);if(!t)return!1;if(t.piDesktop?.isDesktop===!0)return!0;let n=t.navigator?.userAgent;return typeof n==`string`&&n.includes(`Electron/`)}var Rn=()=>window.__piWebUiHost?.pageCall?.bind(window.__piWebUiHost),zn=null,Bn=0;function Vn(){return zn?.available===!0?zn.pages??[]:[]}function Hn(){Date.now()-Bn<5e3||Un().catch(()=>{})}async function Un(){if(Ln())return{available:!1,pages:[],desktop:!0,error:`桌面版不支持浏览器操作:窗口里没有 Chrome 扩展运行时,请改用系统浏览器打开同一个地址(网页版)`};let e=Rn();if(!e)return{available:!1,pages:[],error:`宿主页面桥不可用:这个 pi-web-ui 页面还没装上扩展桥(装/启用 page-picker 后刷新本页)`};try{let t=await e({op:`status`,timeoutMs:5e3});if(!t.ok)return{available:!1,pages:[],error:t.error??`扩展没有返回状态`};let n=t.result??{},r={available:n.installed===!0,aiControl:n.aiControl===!0,allowEval:n.allowEval===!0,pages:Array.isArray(n.pages)?n.pages:[]};return r.available&&(zn=r,Bn=Date.now()),r}catch(e){return{available:!1,pages:[],error:e instanceof Error?e.message:String(e)}}}function Wn(e){return e.length===1?e[0]:null}function Gn(e){return{path:e.origin,name:e.title?.trim()||e.origin,mode:`page`,key:`page:${e.origin}`}}async function Kn(){let e=Rn();if(!e)return!1;try{return(await e({op:`openOptions`,timeoutMs:5e3})).ok===!0}catch{return!1}}function qn(e=45e3){let[t,n]=(0,g.useState)(null),r=(0,g.useRef)(!0),i=(0,g.useCallback)(async e=>{let t=await Un();r.current&&(n(t),e&&!t.available&&setTimeout(()=>{r.current&&i(!1)},1500))},[]);return(0,g.useEffect)(()=>{r.current=!0,i(!0);let t=setInterval(()=>void i(!1),Math.max(5e3,e));return()=>{r.current=!1,clearInterval(t)}},[i,e]),{status:t,refresh:()=>void i(!0)}}var Jn=null,Yn=null,Xn=null,Zn=null,Qn=null;function $n(e){Zn=e}function er(e){Qn=e}function tr(e){return Zn?(Zn(e),!0):!1}function nr(e){return Qn?(Qn(e),!0):!1}function rr(e){Jn=e}function ir(e){Yn=e}function ar(e){Xn=e}function or(){return Xn?(Xn(),!0):!1}function sr(){return!!(Jn||Yn)}function cr(e){let t=typeof e?.text==`string`?e.text:``,n=Array.isArray(e?.attachments)?e.attachments:[],r=t.trim()!==``,i=n.length>0;return!r&&!i||r&&!Jn||i&&!Yn?!1:(i&&Yn?.(n),r&&Jn?.(t),!0)}function lr(){let e=Z(),{status:t,refresh:n}=qn(),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),s=(0,g.useRef)(null),c=t?.pages??[],l=t?.available===!0&&(c.length===0||t.aiControl===!1),u=Wn(c),d=e=>{o(e),s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(()=>o(null),2600)},f=t=>{let n=cr({attachments:[Gn(t)]});d(e(n?`browserControlCited`:`browserControlCiteFailed`))},p=()=>{i(!0),n()};return(0,X.jsxs)(`span`,{className:`bc-anchor`,children:[u?(0,X.jsxs)(`span`,{className:`browser-control-split`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`chip browser-control single${l?` attention`:``}`,"data-tip":e(`browserControlSingleTip`,{name:u.title||u.origin}),title:e(`browserControlSingleTip`,{name:u.title||u.origin}),onClick:()=>f(u),children:[(0,X.jsx)(ge,{size:14,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`bc-chip-label`,children:u.title||u.origin})]}),(0,X.jsx)(`button`,{type:`button`,className:`chip browser-control caret`,"data-tip":e(`browserControlOpenPanel`),title:e(`browserControlOpenPanel`),"aria-label":e(`browserControlOpenPanel`),onClick:p,children:`▾`})]}):(0,X.jsxs)(`button`,{type:`button`,className:`chip browser-control${l?` attention`:``}`,"data-tip":t?.error??e(l?`browserControlEmpty`:`browserControlTip`),title:t?.error??e(l?`browserControlEmpty`:`browserControlTip`),onClick:p,children:[(0,X.jsx)(ge,{size:14,"aria-hidden":!0}),(0,X.jsxs)(`span`,{children:[e(`browserControl`),c.length>0?` · ${c.length}`:``]})]}),a&&(0,X.jsx)(`span`,{className:`bc-flash`,children:a}),r&&(0,X.jsx)(ur,{status:t,onRefresh:n,onCite:f,onClose:()=>i(!1)})]})}function ur({status:e,onRefresh:t,onCite:n,onClose:r}){let i=Z(),[a,o]=(0,g.useState)(!1),s=e?.pages??[],c=async()=>{o(!0);try{await Kn()||t()}finally{o(!1)}};return(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:r,children:(0,X.jsxs)(`div`,{className:`modal browser-control-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(`button`,{type:`button`,className:`modal-close`,"aria-label":i(`close`),onClick:r,children:`✕`}),(0,X.jsxs)(`div`,{className:`modal-head`,children:[(0,X.jsx)(ge,{size:16,"aria-hidden":!0}),(0,X.jsx)(`h2`,{children:i(`browserControl`)})]}),(0,X.jsx)(`div`,{className:`modal-desc`,children:i(`browserControlTip`)}),e===null&&(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlChecking`)}),e?.available===!1&&!e.desktop&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlOffline`)}),e?.desktop===!0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlDesktop`)}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlDesktopLead`)}),(0,X.jsx)(`div`,{className:`bc-actions`,style:{marginTop:0},children:(0,X.jsx)(`a`,{className:`btn primary`,href:window.location.href,target:`_blank`,rel:`noreferrer noopener`,children:i(`browserControlOpenInBrowser`)})})]}),e?.available===!1&&!e.desktop&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlInstall`)}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlInstallLead`)}),(0,X.jsx)(`div`,{className:`bc-actions`,style:{marginTop:0},children:(0,X.jsx)(`a`,{className:`btn primary`,href:`https://github.com/xing-shuyin/pi-web-ui/releases/latest/download/page-picker-extension.zip`,target:`_blank`,rel:`noreferrer noopener`,children:i(`browserControlInstallDownload`)})}),(0,X.jsxs)(`ol`,{className:`bc-steps`,children:[(0,X.jsx)(`li`,{children:i(`browserControlInstallStep1`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep2`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep3`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep4`)})]})]}),e?.available===!0&&e.aiControl===!1&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlDisabled`)}),e?.available===!0&&s.length===0&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlEmpty`)}),s.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlPages`)}),(0,X.jsx)(`ul`,{className:`bc-pages`,children:s.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{className:`bc-title`,title:e.title,children:e.title}),(0,X.jsx)(`span`,{className:`bc-origin`,title:e.origin,children:e.origin}),(0,X.jsx)(`span`,{className:`bc-open${e.open?` on`:``}`,children:e.open?i(`browserControlPageOpen`):i(`browserControlPageClosed`)}),(0,X.jsx)(`button`,{type:`button`,className:`bc-cite`,title:i(`browserControlCiteTip`,{name:e.title||e.origin}),onClick:()=>n(e),children:i(`browserControlCite`)})]},e.origin))}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlCiteNote`)})]}),e?.desktop!==!0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlExamples`)}),(0,X.jsxs)(`ul`,{className:`bc-examples`,children:[(0,X.jsx)(`li`,{children:i(`browserControlExample1`)}),(0,X.jsx)(`li`,{children:i(`browserControlExample2`)})]})]}),(0,X.jsxs)(`div`,{className:`bc-actions`,children:[e?.desktop!==!0&&(0,X.jsx)(`button`,{type:`button`,className:`primary`,disabled:a,onClick:()=>void c(),children:i(`browserControlOpenOptions`)}),(0,X.jsx)(`button`,{type:`button`,onClick:t,children:i(`browserControlRefresh`)})]})]})})}var dr=[`terminal_create`,`terminal_list`,`terminal_close`,`terminal_input`,`terminal_key`,`terminal_read`,`terminal_wait`],fr=[`subagent`],pr=`edit_soft`,mr=`delegate_task`,hr=`ask_user_question`,gr=`todo_list`,_r=`browser_page`,vr=`conversation_read`,yr=`skill`,br=`schedule`,xr=`eval`,Sr=`present_files`,Cr=`claim_files`,wr=`plan_update`,Tr=`compact_context`,Er=`patch`,Dr=`codemode`,Or=`tool_search`,kr=[...dr.map(e=>({name:e,group:`terminal`,defaultOn:!1,dshVisible:!0})),...fr.map(e=>({name:e,group:`subagent`,defaultOn:!0,dshVisible:!1})),{name:pr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`editSoftEnabledDesc`,offHintKey:`editSoftOffHint`},{name:mr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`delegateTaskEnabledDesc`,offHintKey:`delegateTaskOffHint`},{name:hr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`questionnaireEnabledDesc`,offHintKey:`questionnaireOffHint`},{name:_r,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`browserPageEnabledDesc`,offHintKey:`browserPageOffHint`},{name:vr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`conversationReadEnabledDesc`,offHintKey:`conversationReadOffHint`},{name:Cr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`claimFilesEnabledDesc`,offHintKey:`claimFilesOffHint`},{name:wr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`planUpdateEnabledDesc`,offHintKey:`planUpdateOffHint`},{name:Er,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`patchToolEnabledDesc`,offHintKey:`patchToolOffHint`},{name:`lsp`,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`lspToolEnabledDesc`,offHintKey:`lspToolOffHint`},{name:Sr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`presentFilesEnabledDesc`,offHintKey:`presentFilesOffHint`},{name:yr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`skillEnabledDesc`,offHintKey:`skillOffHint`},{name:xr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`evalEnabledDesc`,offHintKey:`evalOffHint`},{name:Dr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`codemodeEnabledDesc`,offHintKey:`codemodeOffHint`},{name:Or,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`toolSearchEnabledDesc`,offHintKey:`toolSearchOffHint`},{name:br,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`scheduleTaskEnabledDesc`,offHintKey:`scheduleTaskOffHint`},{name:Tr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`compactContextEnabledDesc`,offHintKey:`compactContextOffHint`},{name:gr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`todoListEnabledDesc`,offHintKey:`todoListOffHint`}],Ar=[`bash`,`read`,`edit`,`write`,`powershell`,`ls`,`grep`,`find`];new Set(kr.map(e=>e.name));var jr=[...kr.map(e=>e.name),...Ar];function Mr(e){let t=new Set(e);return jr.filter(e=>!t.has(e))}function Nr(e,t){let n=Array.from(e);if(!t||t===`standard`)return n;if(t===`ask`)return[];if(t===`minimal`)return n.filter(e=>e===`bash`||e===`read`);if(t===`code`){let e=new Set([`bash`,`read`,`edit`,`write`,`edit_soft`]);return n.filter(t=>e.has(t))}if(t===`reader`){let e=new Set([`write`,`edit`,`edit_soft`,`bash`,`powershell`,`terminal_create`,`terminal_input`,`terminal_close`,`terminal_key`,`codemode`]);return n.filter(t=>!e.has(t))}return n}function Pr(e){return Nr([yr],e).includes(yr)}var Fr=`pi-web-notify`,Ir={enabled:!1};function Lr(){try{let e=localStorage.getItem(Fr);if(!e)return{...Ir};let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Ir.enabled}}catch{return{...Ir}}}function Rr(e){try{localStorage.setItem(Fr,JSON.stringify(e))}catch{}}function zr(){return typeof window<`u`&&`Notification`in window}function Br(){return zr()?null:typeof window<`u`&&window.isSecureContext===!1?`insecure`:`unsupported`}function Vr(e){let{screenX:t,screenY:n,outerWidth:r,outerHeight:i}=e;return Number.isFinite(t)&&Hr(t)||Number.isFinite(n)&&Hr(n)?!0:r>0&&r<=400&&i>0&&i<=40}function Hr(e){return e<=-1e4}function Ur(e){return!(e.visibility!==`visible`||e.minimized||!e.hasFocus||e.windows&&e.idleMs>12e4)}var Wr=Date.now(),Gr=!1;function Kr(){Wr=Date.now()}function qr(){return Math.max(0,Date.now()-Wr)}function Jr(){if(Gr||typeof window>`u`)return;Gr=!0;let e={passive:!0,capture:!0};for(let t of[`pointerdown`,`pointermove`,`keydown`,`wheel`,`touchstart`,`focus`,`scroll`])window.addEventListener(t,Kr,e);typeof document<`u`&&document.addEventListener(`visibilitychange`,Kr,e)}function Yr(){return typeof navigator>`u`?!1:/windows/i.test(navigator.userAgent??``)}function Xr(){return Jr(),typeof window>`u`||typeof document>`u`?{hasFocus:!0,visibility:`visible`,minimized:!1,idleMs:0,windows:!1}:{hasFocus:typeof document.hasFocus!=`function`||document.hasFocus(),visibility:document.visibilityState??``,minimized:Vr({screenX:window.screenX,screenY:window.screenY,outerWidth:window.outerWidth,outerHeight:window.outerHeight}),idleMs:qr(),windows:Yr()}}function Zr(){return zr()?Notification.permission:`denied`}async function Qr(){if(!zr())return`denied`;try{return await Notification.requestPermission()}catch{return`denied`}}function $r(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}function ei(e,t=!1){return{body:e,requireInteraction:t,icon:dn(`/icons/icon-192.png`),badge:dn(`/icons/icon-192.png`),data:{url:typeof location<`u`?location.href:dn(`/`)}}}async function ti(e,t,n=!1){if(!zr())return{path:`none`,error:`unsupported`};if(Notification.permission!==`granted`)return{path:`none`,error:`permission: ${Notification.permission}`};let r=ei(t,n),i;try{let t=await navigator.serviceWorker?.getRegistration();if(t?.active&&typeof t.showNotification==`function`)return await t.showNotification(e,r),{path:`sw`};i=t?`service worker not active`:`no service worker registration`}catch(e){i=$r(e)}try{return new Notification(e,r),{path:`page`,error:i}}catch(e){return{path:`none`,error:`${i}; page: ${$r(e)}`}}}async function ni(e,t){zr()&&(Ur(Xr())||Lr().enabled&&await ti(e,t))}var ri=!1;function ii(){let e=Z(),[t,n]=(0,g.useState)(Lr),[r,i]=(0,g.useState)(()=>Zr()),[a,o]=(0,g.useState)(null),s=Br(),c=s!==null,l=Yr();(0,g.useEffect)(()=>{let e=()=>i(Zr());return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]);let u=async e=>{let r={...t,enabled:e};if(n(r),Rr(r),e){let e=await Qr();if(i(e),e!==`granted`){let e={...r,enabled:!1};n(e),Rr(e)}}};return(0,X.jsxs)(`div`,{className:`sound-menu notify-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:e(`notifyHeader`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master${c?` disabled`:``}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(gt,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:e(`notifyEnable`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:t.enabled&&!c,disabled:c,onChange:e=>u(e.target.checked)})]}),(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyEnableDesc`)}),s===`insecure`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyInsecure`)}),s===`unsupported`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyUnsupported`)}),!c&&r===`denied`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyDenied`)}),!c&&l&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyWindowsHint`)}),ri]})}var ai=new Set([`svg`,`g`,`path`,`circle`,`rect`,`line`,`polyline`,`polygon`,`ellipse`,`use`,`defs`,`clipPath`,`linearGradient`,`radialGradient`,`stop`]),oi=new Set(`viewBox.xmlns.d.fill.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-dasharray.opacity.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.width.height.points.offset.stop-color.stop-opacity.fill-opacity.stroke-opacity.stroke-miterlimit.fill-rule.clip-rule.vector-effect.preserveAspectRatio.transform.clip-path.id.href.xlink:href.xmlns:xlink.gradientUnits.gradientTransform`.split(`.`)),si=new Set([`script`,`style`,`title`,`desc`,`foreignobject`]),ci=new Set([...ai].map(e=>e.toLowerCase())),Q=new Set([...oi].map(e=>e.toLowerCase()));function li(e){return ci.has(e.toLowerCase())}function ui(e){return Q.has(e.toLowerCase())}function di(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.length>8192||!/^<svg[\s>]/.test(t.startsWith(`<?xml`)?t.slice(t.indexOf(`?>`)+2).trimStart():t))return null;if(typeof DOMParser>`u`)return/<script[\s>]/i.test(t)||/\son\w+\s*=/i.test(t)||/javascript\s*:/i.test(t)?null:t;let n=new DOMParser().parseFromString(t,`image/svg+xml`);if(n.querySelector(`parsererror`))return null;let r=n.documentElement;if(r.tagName.toLowerCase()!==`svg`)return null;let i=e=>{for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();if(!li(e)){si.has(e)?t.remove():(i(t),t.replaceWith(...t.childNodes));continue}for(let e of Array.from(t.attributes)){let n=e.name.toLowerCase();(!ui(n)||/^on/i.test(n)||/^(javascript|data|vbscript):/i.test(e.value.trim()))&&t.removeAttribute(e.name)}i(t)}};for(let e of Array.from(r.attributes)){let t=e.name.toLowerCase();(!ui(t)||/^on/i.test(t))&&r.removeAttribute(e.name)}return i(r),new XMLSerializer().serializeToString(r)}function fi({icon:e,iconSvg:t,className:n}){let r=di(t);return r?(0,X.jsx)(`span`,{className:n??`plugin-icon-svg`,"aria-hidden":!0,dangerouslySetInnerHTML:{__html:r}}):e?(0,X.jsx)(`span`,{className:n?`${n} plugin-icon-glyph`:`plugin-icon-glyph`,"aria-hidden":!0,children:e}):null}var pi={projects:`host:lp-projects`,convs:`host:lp-running`,sessions:`host:lp-history`},mi=[`projects`,`convs`,`sessions`],hi=new Map(Object.keys(pi).map(e=>[pi[e],e])),gi=`plugin:`;function _i(e){return e.startsWith(gi)&&e.length>7}function vi(e){let t=[],n=new Set;for(let r of e??[]){let e=null,i,a=hi.get(r.id);a?e=a:r.source?.startsWith(`plugin:`)&&r.kind===`view`&&(e=`${gi}${r.id}`,i=r),e&&!n.has(e)&&(n.add(e),t.push({key:e,shown:!r.hidden,...i?{entry:i}:{}}))}for(let e of mi)n.has(e)||t.push({key:e,shown:!0});return t}function yi(e,t){return e.filter(e=>e.shown&&t(e.key)).map(e=>e.key)}function bi(e,t){let n=[];for(let r=0;r+1<e.length;r++){let i=e[r],a=e[r+1];!t(i)&&!t(a)&&n.push([i,a])}return n}function xi(e,t){let n={...t};if(!e)return n;try{let r=JSON.parse(e);if(!r||typeof r!=`object`||Array.isArray(r))return n;for(let[e,i]of Object.entries(r))(e in t||_i(e))&&typeof i==`number`&&Number.isFinite(i)&&i>0&&(n[e]=i)}catch{}return n}var Si=new Set([`view`,`action`,`badge`,`menu`,`page`,`organizer`,`divider`,`toggle`,`input`,`progress`,`select`]),Ci=new Set([`disabled`,`always`,`never`,`file.isDir`,`file.isFile`,`session.isRunning`,`message.hasSelection`]),wi=`topbar.primary,topbar.overflow,notice.actions,leftpanel.sections,leftpanel.projects.actions,leftpanel.project,leftpanel.running.actions,leftpanel.running,leftpanel.history.actions,leftpanel.history,leftpanel.sessions,chat.header,chat.empty,message.actions,goalbar.actions,composer.leading,composer.actions,rightpanel.tabs,terminal.toolbar,scm.toolbar,bottombar,file.preview.toolbar,contextmenu.topbar,contextmenu.message,contextmenu.session,contextmenu.project,contextmenu.file,contextmenu.toolcall,settings.pages,tasks.panel,modal.dialog,sidebar.left,sidebar.right`.split(`,`),Ti=wi.map(e=>({slot:e,cardinality:`list`}));function Ei(e){return Ti.find(t=>t.slot===e)?.cardinality??`list`}function Di(e,t){if(t===`list`)return{entries:[...e],conflicts:[]};let n=e.findIndex(e=>!e.hidden);if(n<0)return{entries:[...e],conflicts:[]};let r=e.filter((e,t)=>t!==n&&!e.hidden);return{entries:e.map((e,t)=>t===n||e.hidden?e:{...e,hidden:!0}),winner:e[n],conflicts:r}}var Oi=[{id:`host:lp-projects`,slot:`leftpanel.sections`,labelKey:`recentProjects`,icon:`folder`,kind:`action`,order:10},{id:`host:lp-running`,slot:`leftpanel.sections`,labelKey:`runningConversations`,icon:`activity`,kind:`action`,order:20},{id:`host:lp-history`,slot:`leftpanel.sections`,labelKey:`historySessions`,icon:`clock`,kind:`action`,order:30},{id:`host:brand`,slot:`topbar.primary`,labelKey:`brand`,kind:`badge`,order:1,group:`brand`},{id:`host:open-project`,slot:`topbar.primary`,labelKey:`openProject`,icon:`folder`,kind:`action`,order:3,group:`primary`},{id:`host:history`,slot:`topbar.primary`,labelKey:`openHistory`,icon:`menu`,kind:`action`,order:0,group:`panels`},{id:`host:files`,slot:`topbar.primary`,labelKey:`openFiles`,icon:`folder`,kind:`action`,order:97,group:`panels`,align:`end`},{id:`host:new-chat`,slot:`topbar.primary`,labelKey:`newChat`,icon:`plus`,kind:`action`,order:96,group:`primary`,align:`end`},{id:`host:new-ephemeral-chat`,slot:`topbar.primary`,labelKey:`newChatEphemeral`,icon:`chat`,kind:`action`,order:96.5,group:`primary`,align:`end`},{id:`host:chat`,slot:`topbar.primary`,labelKey:`chat`,icon:`chat`,kind:`view`,view:`chat`,order:20,group:`views`,align:`end`},{id:`host:terminal`,slot:`topbar.primary`,labelKey:`terminal`,icon:`terminal`,kind:`view`,view:`terminal`,order:21,group:`views`,align:`end`},{id:`host:git`,slot:`topbar.primary`,labelKey:`scmTab`,icon:`git`,kind:`view`,view:`git`,order:22,group:`views`,align:`end`},{id:`host:plugins`,slot:`topbar.primary`,labelKey:`pluginMenuTitle`,icon:`🧩`,kind:`action`,order:24,group:`views`,align:`end`},{id:`host:search`,slot:`topbar.primary`,labelKey:`searchGlobal`,icon:`search`,kind:`action`,order:40,group:`tools`,align:`end`},{id:`host:browser`,slot:`topbar.primary`,labelKey:`browserControl`,icon:`browser`,kind:`action`,order:41,group:`tools`,align:`end`,hidden:!0},{id:`host:tasks`,slot:`topbar.primary`,labelKey:`bgTasks`,icon:`layers`,kind:`action`,order:42,group:`tools`,align:`end`},{id:`host:settings`,slot:`topbar.primary`,labelKey:`settingsTitle`,icon:`settings`,kind:`action`,order:60,group:`system`,align:`end`},{id:`host:sound`,slot:`topbar.primary`,labelKey:`sound`,icon:`sound`,kind:`action`,order:70,group:`system`,hidden:!0,align:`end`},{id:`host:language`,slot:`topbar.primary`,labelKey:`language`,icon:`globe`,kind:`action`,order:80,group:`system`,hidden:!0,align:`end`},{id:`host:theme`,slot:`topbar.primary`,labelKey:`theme`,icon:`sun`,kind:`action`,order:82,group:`system`,hidden:!0,align:`end`},{id:`host:update`,slot:`topbar.primary`,labelKey:`update`,icon:`download`,kind:`action`,order:90,group:`system`,align:`end`,hidden:!0},{id:`host:github`,slot:`topbar.primary`,labelKey:`githubRepo`,icon:`github`,kind:`action`,order:200,group:`system`,align:`end`,hidden:!0},{id:`host:conn`,slot:`bottombar`,labelKey:`connected`,icon:`dot`,kind:`badge`,order:5,group:`status`},{id:`host:engine`,slot:`bottombar`,labelKey:`engineBadge`,icon:`cpu`,kind:`badge`,order:6,group:`status`},{id:`host:ctx`,slot:`bottombar`,labelKey:`context`,icon:`gauge`,kind:`badge`,order:10,group:`usage`},{id:`host:cost`,slot:`bottombar`,labelKey:`cumulativeCost`,icon:`coins`,kind:`badge`,order:11,group:`usage`},{id:`host:cache`,slot:`bottombar`,labelKey:`cacheHit`,icon:`database`,kind:`badge`,order:12,group:`usage`},{id:`host:msg-count`,slot:`bottombar`,labelKey:`messages`,icon:`message`,kind:`badge`,order:13,group:`usage`},{id:`host:plugin-status`,slot:`bottombar`,labelKey:`pluginStatus`,icon:`activity`,kind:`badge`,order:14,group:`status`},{id:`host:working`,slot:`bottombar`,labelKey:`working`,icon:`activity`,kind:`badge`,order:15,group:`status`},{id:`host:status-delegate`,slot:`bottombar`,labelKey:`delegateModeBadge`,icon:`eye`,kind:`badge`,order:16,group:`status`},{id:`host:host-metrics`,slot:`bottombar`,labelKey:`hostResources`,icon:`cpu`,kind:`badge`,order:19,group:`host`,align:`end`},{id:`host:cwd`,slot:`bottombar`,labelKey:`cwdTip`,icon:`folder`,kind:`action`,order:20,group:`context`,align:`end`},{id:`host:msg-reask`,slot:`message.actions`,labelKey:`reaskDirectly`,icon:`refresh`,kind:`action`,order:9},{id:`host:msg-edit-reask`,slot:`message.actions`,labelKey:`editReask`,icon:`edit`,kind:`action`,order:10},{id:`host:msg-fork`,slot:`message.actions`,labelKey:`forkSession`,icon:`branch`,kind:`action`,order:15},{id:`host:msg-rollback`,slot:`message.actions`,labelKey:`rollbackSession`,icon:`undo`,kind:`action`,order:16},{id:`host:msg-copy`,slot:`message.actions`,labelKey:`copyMessage`,icon:`copy`,kind:`action`,order:20},{id:`host:msg-copy-text`,slot:`message.actions`,labelKey:`copyText`,icon:`text`,kind:`action`,order:21},{id:`host:msg-copy-markdown`,slot:`message.actions`,labelKey:`copyMarkdown`,icon:`markdown`,kind:`action`,order:22},{id:`host:msg-copy-image`,slot:`message.actions`,labelKey:`copyImage`,icon:`image`,kind:`action`,order:23},{id:`host:msg-speak`,slot:`message.actions`,labelKey:`speakMsg`,icon:`volume`,kind:`action`,order:24},{id:`host:composer-upload`,slot:`composer.actions`,labelKey:`uploadFile`,icon:`upload`,kind:`action`,order:10,align:`start`},{id:`host:composer-templates`,slot:`composer.actions`,labelKey:`tpl.openPicker`,icon:`grid`,kind:`action`,order:110,align:`start`},{id:`host:composer-model`,slot:`composer.actions`,labelKey:`selectModel`,icon:`cpu`,kind:`action`,order:120,align:`start`},{id:`host:composer-thinking`,slot:`composer.actions`,labelKey:`thinkingLevel`,icon:`zap`,kind:`action`,order:130,align:`start`},{id:`host:composer-dsh-perm`,slot:`composer.actions`,labelKey:`dshPerm`,icon:`lock`,kind:`action`,order:140,align:`start`},{id:`host:composer-dsh-preset`,slot:`composer.actions`,labelKey:`dshPreset`,icon:`layers`,kind:`action`,order:150,align:`start`},{id:`host:composer-send`,slot:`composer.actions`,labelKey:`sendTip`,icon:`send`,kind:`action`,order:200,align:`end`},{id:`host:fp-md`,slot:`file.preview.toolbar`,labelKey:`showMarkdownPreview`,icon:`eye`,kind:`action`,order:10},{id:`host:fp-html`,slot:`file.preview.toolbar`,labelKey:`showHtmlPreview`,icon:`code`,kind:`action`,order:20},{id:`host:fp-edit`,slot:`file.preview.toolbar`,labelKey:`editFile`,icon:`edit`,kind:`action`,order:30},{id:`host:fp-wrap`,slot:`file.preview.toolbar`,labelKey:`enableWrap`,icon:`wrap`,kind:`action`,order:40},{id:`host:fp-zoom`,slot:`file.preview.toolbar`,labelKey:`zoomIn`,icon:`zoom`,kind:`action`,order:50},{id:`host:fp-ref`,slot:`file.preview.toolbar`,labelKey:`referenceTip`,icon:`link`,kind:`action`,order:70},{id:`host:fp-full`,slot:`file.preview.toolbar`,labelKey:`fullscreen`,icon:`maximize`,kind:`action`,order:80},{id:`host:fp-close`,slot:`file.preview.toolbar`,labelKey:`close`,icon:`x`,kind:`action`,order:90},{id:`host:goal-pill`,slot:`goalbar.actions`,labelKey:`goalBarTitle`,icon:`target`,kind:`action`,order:5},{id:`host:goal-set`,slot:`goalbar.actions`,labelKey:`goalBarSet`,icon:`check`,kind:`action`,order:10},{id:`host:goal-wizard`,slot:`goalbar.actions`,labelKey:`goalWizardBtn`,icon:`search`,kind:`action`,order:20},{id:`host:goal-lock`,slot:`goalbar.actions`,labelKey:`goalBarLocked`,icon:`lock`,kind:`action`,order:30},{id:`host:goal-plan`,slot:`goalbar.actions`,labelKey:`planMode`,icon:`list`,kind:`action`,order:25},{id:`host:goal-collapse`,slot:`goalbar.actions`,labelKey:`collapsePanel`,icon:`chevron-up`,kind:`action`,order:40},{id:`host:goal-model`,slot:`goalbar.actions`,labelKey:`goalBarReviewModel`,icon:`cpu`,kind:`action`,order:50},{id:`host:goal-rounds`,slot:`goalbar.actions`,labelKey:`goalBarMaxRounds`,icon:`hash`,kind:`action`,order:60},{id:`host:goal-execmodel`,slot:`goalbar.actions`,labelKey:`goalBarExecModel`,icon:`cpu`,kind:`action`,order:55},{id:`host:goal-openrole`,slot:`goalbar.actions`,labelKey:`goalBarOpenExec`,icon:`search`,kind:`action`,order:65},{id:`host:goal-clear`,slot:`goalbar.actions`,labelKey:`goalBarClear`,icon:`x`,kind:`action`,order:70},{id:`host:scm-changes`,slot:`scm.toolbar`,labelKey:`scmChanges`,icon:`file`,kind:`action`,order:10},{id:`host:scm-history`,slot:`scm.toolbar`,labelKey:`scmHistory`,icon:`clock`,kind:`action`,order:20},{id:`host:scm-refresh`,slot:`scm.toolbar`,labelKey:`scmRefreshTip`,icon:`refresh`,kind:`action`,order:30},{id:`host:scm-branch`,slot:`scm.toolbar`,labelKey:`scmSwitchBranch`,icon:`git`,kind:`action`,order:40},{id:`host:scm-switch`,slot:`scm.toolbar`,labelKey:`scmSwitch`,icon:`git`,kind:`action`,order:50},{id:`host:scm-push`,slot:`scm.toolbar`,labelKey:`scmPush`,icon:`upload`,kind:`action`,order:60},{id:`host:scm-pull`,slot:`scm.toolbar`,labelKey:`scmPull`,icon:`download`,kind:`action`,order:70},{id:`host:scm-input`,slot:`scm.toolbar`,labelKey:`scmCommitPlaceholder`,icon:`edit`,kind:`action`,order:80},{id:`host:scm-genmsg`,slot:`scm.toolbar`,labelKey:`scmGenMsg`,icon:`cpu`,kind:`action`,order:85},{id:`host:scm-commit`,slot:`scm.toolbar`,labelKey:`scmCommit`,icon:`check`,kind:`action`,order:90},{id:`host:scm-commit-all`,slot:`scm.toolbar`,labelKey:`scmCommitAll`,icon:`check`,kind:`action`,order:100},{id:`host:scm-term`,slot:`scm.toolbar`,labelKey:`terminal`,icon:`terminal`,kind:`action`,order:110},{id:`host:term-cmd-refresh`,slot:`terminal.toolbar`,labelKey:`rerun`,icon:`refresh`,kind:`action`,order:10},{id:`host:term-cmd-new`,slot:`terminal.toolbar`,labelKey:`newCommand`,icon:`plus`,kind:`action`,order:20},{id:`host:term-tab-new`,slot:`terminal.toolbar`,labelKey:`newTerminal`,icon:`plus`,kind:`action`,order:30},{id:`host:right-files`,slot:`rightpanel.tabs`,labelKey:`openFiles`,icon:`folder`,kind:`view`,view:`files`,order:10},{id:`host:conv-rename`,slot:`contextmenu.session`,labelKey:`renameSession`,icon:`edit`,kind:`action`,context:`session`,order:1},{id:`host:conv-pin`,slot:`contextmenu.session`,labelKey:`pinConversation`,icon:`pin`,kind:`action`,context:`session`,order:2},{id:`host:conv-takeover`,slot:`contextmenu.session`,labelKey:`takeoverConversation`,icon:`chat`,kind:`action`,context:`session`,order:5},{id:`host:conv-dismiss-subagents`,slot:`contextmenu.session`,labelKey:`dismissFinishedSubagents`,icon:`x`,kind:`action`,context:`session`,order:10},{id:`host:conv-force-dismiss`,slot:`contextmenu.session`,labelKey:`forceDismissConversation`,icon:`x`,kind:`action`,context:`session`,order:20},{id:`host:conv-persist`,slot:`contextmenu.session`,labelKey:`persistSubagent`,icon:`save`,kind:`action`,context:`session`,order:25},{id:`host:conv-copy-id`,slot:`contextmenu.session`,labelKey:`copyConversationId`,icon:`copy`,kind:`action`,context:`session`,order:30},{id:`host:conv-copy-path`,slot:`contextmenu.session`,labelKey:`copyConversationPath`,icon:`copy`,kind:`action`,context:`session`,order:40},{id:`host:conv-copy-link`,slot:`contextmenu.session`,labelKey:`copyConversationLink`,icon:`link`,kind:`action`,context:`session`,order:45},{id:`host:conv-quote`,slot:`contextmenu.session`,labelKey:`quoteConversation`,icon:`chat`,kind:`action`,context:`session`,order:50},{id:`host:file-open`,slot:`contextmenu.file`,labelKey:`fileOpenPreview`,icon:`open`,kind:`action`,context:`file`,order:11,group:`open`},{id:`host:file-enter`,slot:`contextmenu.file`,labelKey:`fileEnterDir`,icon:`folder`,kind:`action`,context:`file`,order:12,group:`open`},{id:`host:file-download`,slot:`contextmenu.file`,labelKey:`downloadFile`,icon:`download`,kind:`action`,context:`file`,order:13,group:`open`},{id:`host:file-compress`,slot:`contextmenu.file`,labelKey:`fileCompress`,icon:`file`,kind:`action`,context:`file`,order:16,group:`archive`},{id:`host:file-extract`,slot:`contextmenu.file`,labelKey:`fileExtract`,icon:`folder`,kind:`action`,context:`file`,order:17,group:`archive`},{id:`host:file-compress-download`,slot:`contextmenu.file`,labelKey:`fileCompressDownload`,icon:`download`,kind:`action`,context:`file`,order:18,group:`archive`},{id:`host:file-upload-folder`,slot:`contextmenu.file`,labelKey:`fileUploadFolder`,icon:`upload`,kind:`action`,context:`file`,order:25,group:`new`},{id:`host:file-open-project`,slot:`contextmenu.file`,labelKey:`openAsProject`,icon:`folder`,kind:`action`,context:`file`,order:14,group:`open`},{id:`host:file-add-root`,slot:`contextmenu.file`,labelKey:`addWorkspaceRoot`,icon:`folder`,kind:`action`,context:`file`,order:15,group:`open`},{id:`host:file-reveal`,slot:`contextmenu.file`,labelKey:`fileReveal`,icon:`folder`,kind:`action`,context:`file`,order:16,group:`open`},{id:`host:file-open-default`,slot:`contextmenu.file`,labelKey:`fileOpenDefault`,icon:`open`,kind:`action`,context:`file`,order:17,group:`open`},{id:`host:file-new-file`,slot:`contextmenu.file`,labelKey:`fileNewFile`,icon:`file`,kind:`action`,context:`file`,order:21,group:`new`},{id:`host:file-new-dir`,slot:`contextmenu.file`,labelKey:`fileNewDir`,icon:`folder`,kind:`action`,context:`file`,order:22,group:`new`},{id:`host:file-upload`,slot:`contextmenu.file`,labelKey:`uploadToFolder`,icon:`upload`,kind:`action`,context:`file`,order:23,group:`new`},{id:`host:file-paste`,slot:`contextmenu.file`,labelKey:`filePaste`,icon:`paste`,kind:`action`,context:`file`,order:24,group:`new`},{id:`host:file-attach-ref`,slot:`contextmenu.file`,labelKey:`referenceTip`,icon:`link`,kind:`action`,context:`file`,order:32,group:`chat`},{id:`host:file-attach-folder`,slot:`contextmenu.file`,labelKey:`linkFolderTip`,icon:`link`,kind:`action`,context:`file`,order:33,group:`chat`},{id:`host:file-rename`,slot:`contextmenu.file`,labelKey:`fileRename`,icon:`edit`,kind:`action`,context:`file`,order:41,group:`edit`},{id:`host:file-duplicate`,slot:`contextmenu.file`,labelKey:`fileDuplicate`,icon:`copy`,kind:`action`,context:`file`,order:42,group:`edit`},{id:`host:file-cut`,slot:`contextmenu.file`,labelKey:`fileCut`,icon:`cut`,kind:`action`,context:`file`,order:43,group:`edit`},{id:`host:file-copy`,slot:`contextmenu.file`,labelKey:`fileCopyEntry`,icon:`copy`,kind:`action`,context:`file`,order:44,group:`edit`},{id:`host:file-copy-name`,slot:`contextmenu.file`,labelKey:`copyName`,icon:`copy`,kind:`action`,context:`file`,order:51,group:`clipboard`},{id:`host:file-copy-path`,slot:`contextmenu.file`,labelKey:`copyPath`,icon:`copy`,kind:`action`,context:`file`,order:52,group:`clipboard`},{id:`host:file-copy-rel`,slot:`contextmenu.file`,labelKey:`fileCopyRelPath`,icon:`copy`,kind:`action`,context:`file`,order:53,group:`clipboard`},{id:`host:file-refresh`,slot:`contextmenu.file`,labelKey:`fileRefresh`,icon:`refresh`,kind:`action`,context:`file`,order:54,group:`clipboard`},{id:`host:file-delete`,slot:`contextmenu.file`,labelKey:`fileDelete`,icon:`trash`,kind:`action`,context:`file`,order:61,group:`danger`},{id:`host:msg-ctx-copy-markdown`,slot:`contextmenu.message`,labelKey:`copyMarkdown`,icon:`markdown`,kind:`action`,context:`message`,order:10,group:`copy`},{id:`host:msg-ctx-copy-text`,slot:`contextmenu.message`,labelKey:`copyText`,icon:`text`,kind:`action`,context:`message`,order:11,group:`copy`},{id:`host:msg-ctx-copy-image`,slot:`contextmenu.message`,labelKey:`copyImage`,icon:`image`,kind:`action`,context:`message`,order:12,group:`copy`},{id:`host:msg-ctx-copy-link`,slot:`contextmenu.message`,labelKey:`copyMessageLink`,icon:`link`,kind:`action`,context:`message`,order:13,group:`copy`},{id:`host:msg-ctx-reask`,slot:`contextmenu.message`,labelKey:`reaskDirectly`,icon:`refresh`,kind:`action`,context:`message`,order:19,group:`action`},{id:`host:msg-ctx-edit-reask`,slot:`contextmenu.message`,labelKey:`editReask`,icon:`edit`,kind:`action`,context:`message`,order:20,group:`action`},{id:`host:msg-ctx-fork`,slot:`contextmenu.message`,labelKey:`forkSession`,icon:`branch`,kind:`action`,context:`message`,order:21,group:`action`},{id:`host:msg-ctx-rollback`,slot:`contextmenu.message`,labelKey:`rollbackSession`,icon:`undo`,kind:`action`,context:`message`,order:22,group:`action`},{id:`host:msg-ctx-speak`,slot:`contextmenu.message`,labelKey:`speakMsg`,icon:`volume`,kind:`action`,context:`message`,order:23,group:`action`},{id:`host:tool-info`,slot:`contextmenu.toolcall`,labelKey:`toolInfoMenuLabel`,icon:`info`,kind:`action`,context:`toolcall`,order:10}],ki=`__view`,Ai=new Set([`host:settings`,`host:history`,`host:files`]),ji=new Set([`host:history`,`host:files`]);function Mi(e){return`${e}:${ki}`}function Ni(e){return e.source.startsWith(`plugin:`)?e.id===Mi(e.source.slice(7)):!1}function Pi(e,t,n){let r=Mi(t),i=(e?.hidden??[]).filter(e=>e!==r),a=(e?.shown??[]).filter(e=>e!==r);return n?a.push(r):i.push(r),{...e,hidden:i,shown:a}}function Fi(e,t){let n=t.map(Mi),r=new Set(n),i=(e?.order??[]).filter(e=>!r.has(e));return{...e,order:[...i,...n]}}var Ii=`host:brand`,Li=[`host:brand-logo`,`host:brand-name`];function Ri(e){if(!((e.hidden??[]).some(e=>Li.includes(e))||(e.shown??[]).some(e=>Li.includes(e))||(e.order??[]).some(e=>Li.includes(e))||Li.some(t=>e.align?.[t]!==void 0)||Li.some(t=>e.groups?.[t]!==void 0)||Li.some(t=>e.labels?.[t]!==void 0)||Li.some(t=>e.slots?.[t]!==void 0)))return e;let t=e=>{if(!e)return;let t=[];for(let n of e){let e=Li.includes(n)?Ii:n;t.includes(e)||t.push(e)}return t},n=(e,t)=>{if(!e)return;let n={};for(let[t,r]of Object.entries(e))Li.includes(t)||(n[t]=r);if(n[Ii]===void 0){let r=t?e[Li[0]]??e[Li[1]]:e[Li[1]]??e[Li[0]];r!==void 0&&(n[Ii]=r)}return n},r=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))Li.includes(n)||(t[n]=r);if(t[Ii]===void 0){let n=e[Li[0]]??e[Li[1]];n!==void 0&&(t[Ii]=n)}return t},i=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))Li.includes(n)||(t[n]=r);if(t[Ii]===void 0){let n=e[Li[0]]??e[Li[1]];n!==void 0&&(t[Ii]=n)}return t};return{...e,...e.hidden?{hidden:t(e.hidden)}:{},...e.shown?{shown:t(e.shown)}:{},...e.order?{order:t(e.order)}:{},...e.groups?{groups:n(e.groups,!0)}:{},...e.labels?{labels:n(e.labels,!1)}:{},...e.align?{align:r(e.align)}:{},...e.slots?{slots:i(e.slots)}:{}}}function zi(e){return e.map(e=>{if(e.view===!1)return e;let t=e.ui?.items??[];if(t.some(e=>e.id===`__view`))return e;let n={id:ki,slot:`topbar.primary`,label:e.name,...e.icon?{icon:e.icon}:{},...e.iconSvg?{iconSvg:e.iconSvg}:{},kind:`view`,view:`plugin:${e.id}`,order:23,align:`end`,hidden:!0};return{...e,ui:{items:[...t,n],arrange:e.ui?.arrange??[]}}})}function Bi(e){return typeof e==`string`&&wi.includes(e)}function Vi(e,t){return t?e.label:e.labelEn??e.label}function Hi(e,t){return t?e.hint??e.hintEn:e.hintEn??e.hint}function Ui(e,t,n,r,i){let a=`${e}#${r.id}`,o=Wi(a,t,n,r.children,i),s=Hi(r,i),c=Gi(r.options,i);return{id:a,slot:t,source:n,label:Vi(r,i),labelExplicit:!0,...r.icon?{icon:r.icon}:{},...r.iconSvg?{iconSvg:r.iconSvg}:{},...s?{hint:s}:{},kind:r.kind??`action`,...r.action?{action:r.action}:{},...r.view?{view:r.view}:{},...r.group?{group:r.group}:{},order:r.order??100,align:`start`,hidden:r.hidden??!1,...r.badge?{badge:r.badge}:{},...r.when?{when:r.when}:{},...c?{options:c}:{},...o.length>0?{children:o}:{},userOverrides:[],arrangedBy:[]}}function Wi(e,t,n,r,i){return r?.length?r.map((r,a)=>({entry:Ui(e,t,n,r,i),index:a})).sort((e,t)=>e.entry.order===t.entry.order?e.index-t.index:e.entry.order-t.entry.order).map(e=>e.entry):[]}function Gi(e,t){if(e?.length)return e.slice(0,32).map(e=>({value:e.value,label:t?e.label??e.labelEn??e.value:e.labelEn??e.label??e.value}))}function Ki(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?Math.min(100,Math.max(0,t)):0}function qi(e,t,n,r,i,a){let o=Wi(e,t,n,r.children,i),s=Hi(r,i),c=Ki(r.progress),l=Gi(r.options,i);return{id:e,slot:t,source:n,label:Vi(r,i),labelExplicit:!0,...r.icon?{icon:r.icon}:{},...r.iconSvg?{iconSvg:r.iconSvg}:{},...s?{hint:s}:{},kind:r.kind??(t===`settings.pages`?`page`:`action`),...r.action?{action:r.action}:{},...r.view?{view:r.view}:{},...r.group?{group:r.group}:{},order:r.order??100,align:r.align??`start`,hidden:r.hidden??!1,...r.badge?{badge:r.badge}:{},...typeof r.checked==`boolean`?{checked:r.checked}:{},...typeof r.value==`string`?{value:r.value}:{},...c===void 0?{}:{progress:c},...l?{options:l}:{},...r.when?{when:r.when}:{},...o.length>0?{children:o}:{},userOverrides:[],arrangedBy:[],seq:a}}function Ji(e,t){return[...e].sort((e,n)=>{let r=t.get(e.id),i=t.get(n.id);return r!==void 0||i!==void 0?r!==void 0&&i!==void 0?r-i:r===void 0?1:-1:e.order===n.order?e.seq-n.seq:e.order-n.order})}function Yi(e,t){let n=e.filter(e=>Ni(e)&&!t.has(e.id));if(n.length===0)return e;let r=e.filter(e=>!Ni(e)||t.has(e.id)),i=[`host:git`,`host:terminal`,`host:chat`].map(e=>r.findIndex(t=>t.id===e)).find(e=>e>=0)??-1,a=r.findIndex(e=>e.id===`host:plugins`),o=i+1;return a>=o&&(o=a),o=Math.max(0,Math.min(o,r.length)),[...r.slice(0,o),...n,...r.slice(o)]}function Xi(e,t){let n=t.locale===`zh`,r=new Set(t.disabledPlugins??[]),i=Ri(t.layout??{}),a=e=>{t.diagnostics?.push({level:e.level??`warn`,...e})},o=new Map,s=0;for(let e of Oi)o.set(e.id,{id:e.id,slot:e.slot,source:`host`,label:t.t(e.labelKey),labelKey:e.labelKey,...e.icon?{icon:e.icon}:{},kind:e.kind,...e.view?{view:e.view}:{},...e.group?{group:e.group}:{},order:e.order??100,align:e.align??`start`,hidden:e.hidden??!1,userOverrides:[],arrangedBy:[],seq:s++});for(let t of e){if(r.has(t.id)){a({pluginId:t.id,message:`plugin "${t.id}" is disabled by the user — its ${t.ui?.items?.length??0} UI item(s) are not rendered`});continue}if(t.error){a({level:`error`,pluginId:t.id,message:`plugin "${t.id}" failed to activate (${t.error}) — its UI items are not rendered`});continue}let e=`plugin:${t.id}`;for(let r of t.ui?.items??[]){if(!Bi(r.slot)){a({pluginId:t.id,entryId:r.id,message:`item "${t.id}:${r.id}" declares unknown slot "${String(r.slot)}" — dropped (valid slots: see docs/architecture-plugins.md)`});continue}if(r.slot===`leftpanel.sections`&&r.kind!==`view`){a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" targets leftpanel.sections: only kind="view" (a plugin section) is accepted — dropped`});continue}if(r.kind&&!Si.has(r.kind)&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" declares unknown kind "${r.kind}" — the render layer falls back to a plain button`}),Array.isArray(r.when))for(let e of r.when)Ci.has(e)||a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" declares when:"${e}" which the host does not know — it is ignored (the item still renders)`});else r.when!==void 0&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" has a non-array "when" — ignored`});let i=`${t.id}:${r.id}`,c=o.get(i);c&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item id "${r.id}" is declared more than once — the later declaration wins (order/visibility are inherited from the first)`}),o.set(i,qi(i,r.slot,e,r,n,c?.seq??s++))}}for(let t of e)if(!(t.error||r.has(t.id)))for(let e of t.ui?.arrange??[]){let n=o.get(e.id);Qi(o,e,t.id),n||a({pluginId:t.id,entryId:e.id,message:`arrange target "${e.id}" does not exist — op ignored (is the providing plugin installed / not disabled?)`})}let c=new Map,l=(e,t)=>{let n=c.get(e)??[];n.includes(t)||n.push(t),c.set(e,n)};for(let e of i.hidden??[]){let t=o.get(e);t&&(t.hidden=!0,l(e,`hidden`))}for(let e of i.shown??[]){let t=o.get(e);t&&(t.hidden=!1,l(e,`hidden`))}for(let[e,t]of Object.entries(i.groups??{})){let n=o.get(e);n&&(n.group=t,l(e,`group`))}for(let[e,t]of Object.entries(i.align??{})){let n=o.get(e);!n||t!==`start`&&t!==`center`&&t!==`end`||(n.align=t,l(e,`align`))}for(let[e,t]of Object.entries(i.labels??{})){let n=o.get(e);n&&(n.label=t,n.labelExplicit=!0,l(e,`label`))}for(let[e,t]of Object.entries(i.slots??{})){let n=o.get(e);n&&Bi(t)&&n.slot!==t&&(n.movedFrom=n.movedFrom??n.slot,n.slot=t,l(e,`slot`))}for(let e of Ai){let t=o.get(e);t&&(i.slots?.[e]||(t.slot=`topbar.primary`),t.hidden=!1)}let u=new Map;(i.order??[]).forEach((e,t)=>{o.has(e)&&(u.has(e)||u.set(e,t),l(e,`order`))});for(let e of Object.values(pi)){let t=o.get(e);t&&t.slot!==`leftpanel.sections`&&(a({entryId:e,slot:t.slot,message:`"${e}" must stay in leftpanel.sections — the move is ignored`}),t.slot=`leftpanel.sections`,delete t.movedFrom)}let d=new Map;for(let e of wi)d.set(e,[]);for(let e of o.values())d.get(e.slot)?.push(e);let f={};for(let e of wi){let t=Ji(d.get(e)??[],u),n=Di(e===`topbar.primary`?Yi(t,u):t,Ei(e));if(n.winner&&n.conflicts.length>0)for(let t of n.conflicts)a({level:`error`,pluginId:t.source.startsWith(`plugin:`)?t.source.slice(7):void 0,entryId:t.id,slot:e,message:`slot "${e}" is single-cardinality; "${n.winner.id}" won and "${t.id}" was hidden`});f[e]=n.entries.map(e=>Zi(e,c.get(e.id)??[]))}return f}function Zi(e,t){let n={...e,userOverrides:t};return delete n.seq,n}function Qi(e,t,n){let r=e.get(t.id);if(!r)return;let i=!1;t.hide!==void 0&&(r.hidden=t.hide,i=!0),t.group!==void 0&&(r.group=t.group,i=!0),t.order!==void 0&&(r.order=t.order,i=!0),t.align!==void 0&&(r.align=t.align,i=!0),t.label!==void 0&&(r.label=t.label,r.labelExplicit=!0,i=!0),t.hint!==void 0&&(r.hint=t.hint,i=!0),t.icon!==void 0&&(r.icon=t.icon,i=!0),t.iconSvg!==void 0&&(r.iconSvg=t.iconSvg||void 0,i=!0),t.slot!==void 0&&Bi(t.slot)&&t.slot!==r.slot&&(r.movedFrom=r.movedFrom??r.slot,r.slot=t.slot,i=!0),i&&r.source!==`plugin:${n}`&&!r.arrangedBy.includes(n)&&r.arrangedBy.push(n)}function $i(e){let t=[],n=[],r=[];for(let i of e)i.align===`end`?r.push(i):i.align===`center`?n.push(i):t.push(i);return{start:t,center:n,end:r}}function ea(e,t){let n=e??{},r={},i=t===Ii?[t,...Li]:[t],a=(n.hidden??[]).filter(e=>!i.includes(e)),o=(n.shown??[]).filter(e=>!i.includes(e)),s=(n.order??[]).filter(e=>!i.includes(e));a.length>0&&(r.hidden=a),o.length>0&&(r.shown=o),s.length>0&&(r.order=s);let c=na(n.groups,t),l=na(n.labels,t),u=na(n.align,t),d=na(n.slots,t);if(t===Ii)for(let e of Li)c=na(c,e),l=na(l,e),u=na(u,e),d=na(d,e);return c&&(r.groups=c),l&&(r.labels=l),u&&(r.align=u),d&&(r.slots=d),n.topbarText!==void 0&&(r.topbarText=n.topbarText),n.sideDockFloat!==void 0&&(r.sideDockFloat=n.sideDockFloat),r}function ta(){return{}}function na(e,t){if(!e)return;let n={},r=!1;for(let[i,a]of Object.entries(e))i!==t&&(n[i]=a,r=!0);return r?n:void 0}var ra=new Set([`host:files`]);function ia(e,t){let n=e=>e===`center`?1:e===`end`?2:0;return[...e].sort((e,r)=>n(e.align)-n(r.align)||t(e.id)-t(r.id))}function aa(e,t,n,r,i=new Set){let a=new Set;if(!Number.isFinite(t)||t<=0)return a;let o=e.filter(e=>i.has(e.id)&&e.width>0).reduce((e,t)=>e+t.width+n,0),s=Math.max(0,t-Math.max(0,r)-o),c=0,l=!1;for(let t of e){if(!(t.width>0)||i.has(t.id))continue;let e=t.width+n;if(l||c+e>s){l=!0,a.add(t.id);continue}c+=e}return a}var oa=null,sa=new Set;function ca(){for(let e of sa)e()}function la(e){oa={x:Number.isFinite(e.x)?e.x:0,y:Number.isFinite(e.y)?e.y:0,slot:e.slot,target:e.target??{id:``},entries:Array.isArray(e.entries)?e.entries:[],...typeof e.onHostAction==`function`?{onHostAction:e.onHostAction}:{}},ca()}function ua(){oa!==null&&(oa=null,ca())}function da(e){return sa.add(e),()=>{sa.delete(e)}}function fa(){return oa}function pa(){return(0,g.useSyncExternalStore)(da,fa,fa)}function ma(e){return Number.isFinite(e)?e:0}function ha(e,t,n,r,i,a){let o=Math.max(0,ma(n)),s=Math.max(0,ma(r)),c=Math.max(8,ma(i)-o-8),l=Math.max(8,ma(a)-s-8);return{x:Math.min(Math.max(8,ma(e)),c),y:Math.min(Math.max(8,ma(t)),l)}}function ga(e,t){let n=String(t?.kind??``);if(e===`contextmenu.file`)return{"file.isDir":n===`dir`||n===`list`&&t?.id!==`@root`,"file.isFile":n===`file`};if(e===`contextmenu.session`)return{"session.isRunning":n===`running`};if(e===`contextmenu.message`){let e=!1;try{let t=window.getSelection?.();e=!!t&&!t.isCollapsed&&t.toString().trim().length>0}catch{e=!1}return{"message.hasSelection":e}}return{}}function _a(e,t){if(!Array.isArray(e)||e.length===0)return!1;for(let n of e){if(typeof n!=`string`||!n)continue;let e=n.trim();if(e===`disabled`||e===`never`)return!0;if(e!==`always`){if(e.startsWith(`!`)){let n=e.slice(1).trim();if(!n)continue;if(!t||t[n]!==!0)return!0;continue}if(t&&t[e]===!1)return!0}}return!1}function va(e,t){return!e||_a(e.when,t)}function ya(e){let t=new Map;return{items:(Array.isArray(e)?e:[]).map(e=>{if(!e||e.kind!==`select`||!e.options?.length||e.children?.length)return e;let n=e.options.map((t,n)=>({id:`${e.id}#${n}`,slot:e.slot,source:e.source,label:t.label,kind:`action`,order:100,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}));return n.forEach((n,r)=>t.set(n.id,{parent:e,value:e.options[r].value})),{...e,kind:`menu`,children:n}}),selectParents:t}}function ba(e){if(!Array.isArray(e)||e.length===0)return[];let t=e.filter(e=>e&&e.hidden!==!0),n=t.filter(e=>e.kind!==`divider`),r=new Map,i=new Map;n.forEach((e,t)=>{let n=e.group??``;r.has(n)||r.set(n,t);let a=Number.isFinite(e.order)?e.order:100,o=i.get(n);(o===void 0||a<o)&&i.set(n,a)});let a=[...r.keys()].sort((e,t)=>{let n=i.get(e)??100,a=i.get(t)??100;return n===a?(r.get(e)??0)-(r.get(t)??0):n-a}),o=new Map(a.map((e,t)=>[e,t])),s=new Map;n.forEach((e,t)=>s.set(e,t));let c=[...n].sort((e,t)=>{let n=o.get(e.group??``)??0,r=o.get(t.group??``)??0;if(n!==r)return n-r;let i=Number.isFinite(e.order)?e.order:100,a=Number.isFinite(t.order)?t.order:100;return i===a?(s.get(e)??0)-(s.get(t)??0):i-a}),l=new Map;t.forEach((e,n)=>{if(e.kind!==`divider`)return;let r=t.slice(n+1).find(e=>e.kind!==`divider`);if(!r)return;let i=l.get(r)??[];i.push(e),l.set(r,i)});let u=[];for(let e of c){for(let t of l.get(e)??[])u.push(t);u.push(e)}return u}function xa(e){let t=[],n=null,r=!1;return e.forEach((e,i)=>{if(!e||e.kind===`divider`){r=!0;return}let a=e.group??``;n!==null&&(r||a!==n)&&t.push({kind:`sep`,key:`sep:${i}`}),t.push({kind:`item`,key:`${e.id}#${i}`,index:i,entry:e}),n=a,r=!1}),t}function Sa(e,t){return!e||e.kind===`divider`||e.hidden===!0?!1:!va(e,t)}function Ca(e,t,n,r){let i=Array.isArray(e)?e.length:0;if(i===0)return-1;let a=n>=0?1:-1,o=Number.isFinite(t)?Math.trunc(t):-1;(o<0||o>=i)&&(o=a>0?-1:i);for(let t=0;t<i;t++)if(o=(o+a+i)%i,Sa(e[o],r))return o;return-1}var wa={menu:`☰`,folder:`📁`,plus:`+`,chat:`💬`,terminal:`▙`,git:`⎇`,search:`🔍`,browser:`🌐`,layers:`🗂`,settings:`⚙`,sound:`🔊`,globe:`🌍`,sun:`☀`,download:`⤓`,github:`⌗`,x:`✕`,upload:`⬆`,copy:`⧉`,cut:`✂`,paste:`📋`,trash:`🗑`,file:`📄`,open:`↗`,refresh:`⟳`,link:`🔗`,edit:`✎`,dot:`●`,info:`ⓘ`,cpu:`▣`,gauge:`▤`,coins:`◉`,database:`▥`,message:`✉`,activity:`〜`,markdown:`📄`,text:`≡`,image:`🖼`,branch:`⚚`,undo:`↺`,pin:`📌`,volume:`🔊`};function Ta(e){let t=(e??``).trim();return t?wa[t.toLowerCase()]||(/[^\p{L}\p{N}\s]/u.test(t)&&t.length<=4?t:``):``}var Ea={engine:`pi`,managed:!1,status:`connecting`,ready:!1,cwd:``,workspaceRoots:[],homeDir:``,desktopDir:``},Da=new Set;function Oa(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n])}function ka(e,t){return e.engine===t.engine&&e.managed===t.managed&&e.appVersion===t.appVersion&&e.serverVersion===t.serverVersion&&e.status===t.status&&e.ready===t.ready&&e.cwd===t.cwd&&Oa(e.workspaceRoots,t.workspaceRoots)&&e.homeDir===t.homeDir&&e.desktopDir===t.desktopDir&&Oa(e.tabs,t.tabs)&&e.service?.name===t.service?.name&&e.service?.supervisor===t.service?.supervisor}function Aa(e){let t={...Ea,...e};if(!ka(Ea,t)){Ea=t;for(let e of Da)e()}}function ja(e){return Da.add(e),()=>{Da.delete(e)}}function Ma(){return Ea}function Na(){return(0,g.useSyncExternalStore)(ja,Ma,Ma)}function Pa(e){return(0,g.useSyncExternalStore)(ja,()=>Ea[e],()=>Ea[e])}function Fa(){return Pa(`engine`)===`dsh`}function Ia(){return Pa(`managed`)}function La(){return Pa(`service`)}var Ra=null;function za(e){Ra=e}var $=e=>Ra?Ra(e):!1,Ba=new Set;function Va(e){return Ba.add(e),()=>{Ba.delete(e)}}function Ha(e){for(let t of Ba)try{t(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function Ua(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function Wa(e){return!!(e&&e.startsWith(`ssh://`))}function Ga(e){if(!Wa(e))return null;let t=/^ssh:\/\/([^@]+)@([^:]+):(\d+)(\/.*)$/.exec(e);return t?{username:t[1],host:t[2],port:parseInt(t[3],10),remotePath:t[4]}:null}var Ka=1;function qa(e){let t=`probe_${Date.now()}_${Ka++}`;return new Promise(n=>{let r=Va(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===t&&(r(),n({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall}))});$({type:`remote_ssh_probe`,reqId:t,params:e})||(r(),n({ok:!1,error:`WebSocket 连接不可用,请稍候重试`}))})}function Ja(e,t){let n=`listdir_${Date.now()}_${Ka++}`;return new Promise(r=>{let i=Va(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});$({type:`remote_ssh_list_dir`,reqId:n,connectionId:e,path:t})||(i(),r({ok:!1,connectionId:e,path:t||`/`,items:[],error:`WebSocket 连接不可用`}))})}function Ya(e,t){let n=`install_${Date.now()}_${Ka++}`;return new Promise(r=>{let i=Va(e=>{e.type===`remote_ssh_install_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});$({type:`remote_ssh_install_tools`,reqId:n,connectionId:e,tools:t})||(i(),r({ok:!1,connectionId:e,tool:t[0]||``,error:`WebSocket 连接不可用`}))})}function Xa(){let e=`profiles_${Date.now()}_${Ka++}`;return new Promise(t=>{let n=Va(r=>{r.type===`remote_ssh_profiles_result`&&r.reqId===e&&(n(),t(r.profiles))});$({type:`remote_ssh_list_profiles`,reqId:e})||(n(),t([]))})}function Za(e){$({type:`remote_ssh_delete_profile`,name:e})}var Qa=`@root`,$a=e=>e.endsWith(`/`)?e:e+`/`;function eo(e,t){let n=t.trim(),r=e.replace(/\\/g,`/`);return r.endsWith(`/`)?r+n:(/^[A-Za-z]:$/.test(r),r+`/`+n)}function to(e){let t=e.trim();return!(!t||t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`))}var no=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;if(t===`@root`||t===`/`)return null;let n=t.lastIndexOf(`/`);if(n<0)return/^[A-Za-z]:$/.test(t)?Qa:null;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?r+`/`:r};function ro({currentCwd:e,pathCompletions:t,workspaceRoots:n,onClose:r,onSelectDirectory:i,mode:a=`folder`,onCreateProject:o,className:s,backdropClassName:c,role:l,ariaLabel:u}){let d=Z(),[f,p]=(0,g.useState)(()=>Wa(e)?`remote`:`local`),[m,h]=(0,g.useState)(``),[_,v]=(0,g.useState)(``),[y,b]=(0,g.useState)(!1),[x,S]=(0,g.useState)(``),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(-1),D=(0,g.useRef)(null),O=(0,g.useRef)(null),[k,A]=(0,g.useState)([]),[j,ee]=(0,g.useState)(``),[M,te]=(0,g.useState)(`22`),[ne,P]=(0,g.useState)(``),[F,re]=(0,g.useState)(`password`),[ie,I]=(0,g.useState)(``),[ae,R]=(0,g.useState)(`~/.ssh/id_rsa`),[z,B]=(0,g.useState)(!0),[V,H]=(0,g.useState)(``),[U,W]=(0,g.useState)(!1),[oe,G]=(0,g.useState)(null),[se,K]=(0,g.useState)(null),[le,ue]=(0,g.useState)(null),[de,q]=(0,g.useState)(null),[J,fe]=(0,g.useState)([]),[pe,me]=(0,g.useState)(!1),[Y,he]=(0,g.useState)(`/`),[ge,_e]=(0,g.useState)(`/`),[ve,ye]=(0,g.useState)([]),[be,xe]=(0,g.useState)(!1),Se=t.filter(e=>e.type===`dir`);(0,g.useEffect)(()=>{if(Wa(e)){let t=Ga(e);t&&(ee(t.host),te(String(t.port)),P(t.username),he(t.remotePath),_e(t.remotePath))}else{let t=(e||``).replace(/\\/g,`/`);h(t),v(t)}b(!1),S(``),w(null),E(-1)},[e]),(0,g.useEffect)(()=>{f===`remote`&&Xa().then(e=>A(e))},[f]),(0,g.useEffect)(()=>{let e=requestAnimationFrame(()=>{D.current?.focus()});return()=>cancelAnimationFrame(e)},[f]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(y?(b(!1),S(``),w(null)):r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,r]),(0,g.useEffect)(()=>{if(f!==`local`)return;let e=setTimeout(()=>{$({type:`complete_path`,path:$a(m)})},60);return()=>clearTimeout(e)},[m,f]),(0,g.useEffect)(()=>{if(f!==`local`||_===m)return;let e=setTimeout(()=>{$({type:`complete_path`,path:_})},150);return()=>clearTimeout(e)},[_,m,f]);let Ce=e=>{let t=e.trim();t&&t!==`@root`&&i(t)},we=()=>{let e=x.trim();if(e){if(a===`project`){if(!to(e)){w(d(`invalidProjectName`));return}let t=eo(m,e);o?.(t),b(!1),S(``),w(null),r()}else $({type:`make_dir`,path:`${$a(m)}${e}`}),setTimeout(()=>{$({type:`complete_path`,path:$a(m)})},80),S(``),b(!1)}},Te=e=>{if(e.key===`Escape`)e.stopPropagation(),y?(b(!1),S(``),w(null)):r();else if(e.key===`Enter`&&!e.nativeEvent.isComposing)Ce(_);else if(e.key===`Tab`){if(Se.length===0)return;e.preventDefault();let t=T>=0?(T+1)%Se.length:0;E(t),v(Se[t].path),h(Se[t].path)}},Ee=async e=>{let t=(e?.host??j).trim(),n=e?.port??(parseInt(M,10)||22),r=(e?.username??ne).trim();if(!t||!r){G(`请填写主机地址和用户名`);return}W(!0),G(null);let i=await qa({host:t,port:n,username:r,auth:e?.auth??(F===`password`?{type:`password`,password:ie}:F===`key`?{type:`key`,privateKeyPath:ae}:{type:`agent`}),saveProfile:z,profileName:e?.profileName||V.trim()||void 0});if(W(!1),!i.ok||!i.connectionId){G(i.error||`连接远程服务器失败`);return}K(i.connectionId),ue(i.system??null),q(i.tools??null),fe(i.suggestedInstall??[]);let a=i.system?.homeDir||`/`;he(a),_e(a),De(i.connectionId,a),Xa().then(e=>A(e))},De=async(e,t)=>{xe(!0),G(null);let n=await Ja(e,t);xe(!1),n.ok?(he(n.path),_e(n.path),ye(n.items)):G(n.error||`读取远程目录失败`)},Oe=async e=>{if(!se)return;me(!0),G(null);let t=await Ya(se,[e]);me(!1),t.ok?(fe(t=>t.filter(t=>t!==e)),de&&e===`git`&&q({...de,git:{installed:!0,version:`已安装`}})):G(t.error||`安装 ${e} 失败,可能需要远端 sudo 权限`)},ke=e=>{i(Ua(ne,j,parseInt(M,10)||22,e)),r()},Ae=no(m),je=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);return/^[A-Za-z]:/.test(t)?t.toLowerCase():t},Me=je(m),Ne=!!m&&m!==`@root`&&Me!==je(e)&&!n.some(e=>je(e)===Me);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`status-cwd-backdrop ${c??``}`.trim(),onClick:r}),(0,X.jsxs)(`div`,{className:`cwd-picker ${s??``}`.trim(),role:l,"aria-label":u,children:[(0,X.jsxs)(`div`,{className:`cwd-mode-tabs`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${f===`local`?`active`:``}`,onClick:()=>p(`local`),children:[`💻 `,d(`workspaceModeLocal`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${f===`remote`?`active`:``}`,onClick:()=>p(`remote`),children:[`🌐 `,d(`workspaceModeRemote`)]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-close`,title:d(`close`),"aria-label":d(`close`),onClick:r,children:(0,X.jsx)(N,{})})]}),f===`local`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-picker-head`,children:[(0,X.jsxs)(`span`,{className:`cwd-picker-title`,title:m===`@root`?d(`computer`):m,children:[m===`@root`?`💻`:(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{children:m===`@root`?d(`computer`):m})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-up`,disabled:m===`@root`,title:d(`computer`),onClick:()=>{h(`@root`),v(`@root`),E(-1)},children:`💻`}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:!Ae,title:d(`cwdGoUp`),onClick:()=>{Ae&&(h(Ae),v(Ae),E(-1))},children:[`↑ `,d(`cwdGoUp`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:!Ne,title:d(`addWorkspaceRootHint`),onClick:()=>{Ne&&$({type:`set_workspace_roots`,roots:[...n,m]})},children:[`+ `,d(`addWorkspaceRoot`)]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,X.jsx)(`input`,{ref:D,className:`status-cwd-input cwd-picker-input`,value:_,placeholder:d(`enterPath`),spellCheck:!1,onChange:e=>{v(e.target.value),E(-1)},onKeyDown:Te}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,title:d(`cwdPickCurrent`),disabled:m===`@root`,onClick:()=>Ce(m),children:d(`cwdPickCurrent`)})]}),(0,X.jsxs)(`div`,{className:`cwd-list`,children:[Se.length===0&&(0,X.jsx)(`div`,{className:`cwd-empty`,children:d(`cwdEmpty`)}),Se.map(e=>(0,X.jsxs)(`div`,{className:`cwd-item`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${d(`cwdEnter`)} ${e.path}`,onClick:()=>{h(e.path),v(e.path),E(-1)},children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,title:d(`cwdChoose`),onClick:()=>Ce(e.path),children:d(`cwdChoose`)})]},e.path))]}),(0,X.jsxs)(`div`,{className:`cwd-picker-foot`,children:[y?(0,X.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,X.jsx)(`input`,{ref:O,value:x,autoFocus:!0,spellCheck:!1,placeholder:d(a===`project`?`projectName`:`cwdNewName`),onChange:e=>{S(e.target.value),C&&w(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),we()):e.key===`Escape`&&(e.stopPropagation(),b(!1),S(``),w(null))}}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,onClick:we,children:d(a===`project`?`createAndOpenProject`:`cwdCreate`)}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>{b(!1),S(``),w(null)},children:d(`cwdCancel`)})]}):(0,X.jsxs)(`button`,{type:`button`,className:`cwd-newbtn`,onClick:()=>b(!0),children:[`+ `,d(a===`project`?`newProject`:`cwdNewFolder`)]}),C&&(0,X.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:C})]})]}),f===`remote`&&(0,X.jsx)(`div`,{className:`cwd-ssh-container`,children:se?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-probe-box`,children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-probe-header`,children:[(0,X.jsxs)(`span`,{children:[`🌐 `,ne,`@`,j,` (`,le?.os,` `,le?.arch,`)`]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,onClick:()=>{K(null),ue(null),q(null)},children:d(`sshDisconnect`)})]}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,flexWrap:`wrap`,fontSize:`10px`},children:[(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.git.installed?`ok`:`missing`}`,children:[`Git: `,de?.git.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.node.installed?`ok`:`missing`}`,children:[`Node: `,de?.node.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.bash.installed?`ok`:`missing`}`,children:[`Bash: `,de?.bash.installed?`✓`:`✗`]})]}),J.length>0&&(0,X.jsxs)(`div`,{className:`cwd-ssh-install-box`,children:[(0,X.jsx)(`div`,{children:`⚠️ 远端环境未检测到 Git / 基础工具,SCM 与执行功能可能受限。`}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,marginTop:`2px`},children:[(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:pe,onClick:()=>void Oe(J[0]),children:pe?d(`sshInstalling`):`⚡ ${d(`sshInstallTool`)} ${J[0]}`}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>fe([]),children:d(`sshSkipAndBrowse`)})]})]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-head`,children:[(0,X.jsxs)(`span`,{className:`cwd-picker-title`,title:Y,children:[(0,X.jsx)(Pe,{}),(0,X.jsx)(`span`,{children:Y})]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:Y===`/`||be,title:d(`cwdGoUp`),onClick:()=>{let e=no(Y)||`/`;se&&De(se,e)},children:[`↑ `,d(`cwdGoUp`)]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,X.jsx)(`input`,{className:`status-cwd-input cwd-picker-input`,value:ge,placeholder:d(`enterPath`),spellCheck:!1,onChange:e=>_e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&se&&De(se,ge)}}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,onClick:()=>ke(Y),children:d(`sshOpenRemoteWorkspace`)})]}),(0,X.jsx)(`div`,{className:`cwd-list`,children:be?(0,X.jsx)(`div`,{className:`cwd-empty`,children:`正在加载远程目录…`}):ve.length===0?(0,X.jsx)(`div`,{className:`cwd-empty`,children:d(`cwdEmpty`)}):ve.map(e=>(0,X.jsxs)(`div`,{className:`cwd-item`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${e.type===`dir`?d(`cwdEnter`):``} ${e.path}`,onClick:()=>{e.type===`dir`&&se&&De(se,e.path)},children:[e.type===`dir`?(0,X.jsx)(Le,{}):(0,X.jsx)(`span`,{children:`📄`}),(0,X.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),e.type===`dir`&&(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,title:d(`cwdChoose`),onClick:()=>ke(e.path),children:d(`cwdChoose`)})]},e.path))})]}):(0,X.jsxs)(`div`,{className:`cwd-ssh-form`,children:[k.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-profiles-title`,children:[`📋 `,d(`sshSavedProfiles`)]}),k.map(e=>(0,X.jsxs)(`div`,{className:`cwd-ssh-profile-card`,onClick:()=>{ee(e.host),te(String(e.port)),P(e.username),re(e.authType),e.privateKeyPath&&R(e.privateKeyPath),Ee({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}})},children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-profile-meta`,children:[(0,X.jsxs)(`span`,{className:`cwd-ssh-profile-name`,children:[(0,X.jsx)(ce,{style:{marginRight:`4px`}}),e.name]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-profile-addr`,children:[e.username,`@`,e.host,`:`,e.port]})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,title:d(`delete`),onClick:t=>{t.stopPropagation(),confirm(d(`sshDeleteProfileConfirm`))&&(Za(e.name),A(t=>t.filter(t=>t.name!==e.name)))},children:(0,X.jsx)(L,{})})]},e.name))]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,style:{marginTop:`4px`},children:[(0,X.jsxs)(`label`,{children:[d(`sshHost`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:j,placeholder:`192.168.1.100`,onChange:e=>ee(e.target.value)}),(0,X.jsxs)(`label`,{style:{width:`32px`,textAlign:`right`},children:[d(`sshPort`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,style:{width:`45px`,flex:`none`},value:M,onChange:e=>te(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshUser`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:ne,placeholder:`root / ubuntu`,onChange:e=>P(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshAuthType`),`:`]}),(0,X.jsxs)(`select`,{className:`cwd-ssh-select`,value:F,onChange:e=>re(e.target.value),children:[(0,X.jsx)(`option`,{value:`password`,children:d(`sshPassword`)}),(0,X.jsx)(`option`,{value:`key`,children:d(`sshKeyPath`)}),(0,X.jsx)(`option`,{value:`agent`,children:d(`sshAgent`)})]})]}),F===`password`&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshPassword`),`:`]}),(0,X.jsx)(`input`,{type:`password`,className:`cwd-ssh-input`,value:ie,placeholder:`••••••••`,onChange:e=>I(e.target.value)})]}),F===`key`&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshKeyPath`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:ae,placeholder:`~/.ssh/id_rsa`,onChange:e=>R(e.target.value)})]}),(0,X.jsx)(`div`,{className:`cwd-ssh-row`,style:{fontSize:`11px`,color:`var(--text-dim)`},children:(0,X.jsxs)(`label`,{style:{width:`auto`},children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked),style:{marginRight:`4px`}}),d(`sshSaveProfile`)]})}),z&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshProfileName`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:V,placeholder:`my-server`,onChange:e=>H(e.target.value)})]}),oe&&(0,X.jsxs)(`div`,{style:{color:`var(--red)`,fontSize:`11px`,padding:`2px 0`},children:[`⚠️ `,oe]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,style:{marginTop:`4px`},disabled:U,onClick:()=>void Ee(),children:d(U?`sshConnecting`:`sshConnectAndProbe`)})]})})]})]})}function io({open:e,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:a,onCreateProject:o}){let s=Z();return e?(0,X.jsx)(ro,{currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:e=>{a(e),i()},onCreateProject:o,mode:`project`,className:`project-picker`,backdropClassName:`project-picker-backdrop`,role:`dialog`,ariaLabel:s(`projectPickerTitle`)}):null}function ao(e){return k({tag:`svg`,attr:{viewBox:`0 0 256 256`,fill:`currentColor`},child:[{tag:`path`,attr:{d:`M53.92,34.62A8,8,0,1,0,42.08,45.38L67.37,73.2A69.82,69.82,0,0,0,38,87.63a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33,89.75,89.75,0,0,0,11.58-20.27l21.84,24a8,8,0,1,0,11.84-10.76ZM155.9,208,48,100.08C58.23,91.83,69.2,87.72,80.66,87.81l87.16,95.88C165.59,193.56,160.24,202.23,155.9,208Zm79.42-104-44.64,44.79a8,8,0,1,1-11.33-11.3L224,92.7,163.32,32,122.1,73.35a8,8,0,0,1-11.33-11.29L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.32,104Z`},child:[]}]})(e)}function oo(e){return k({tag:`svg`,attr:{viewBox:`0 0 256 256`,fill:`currentColor`},child:[{tag:`path`,attr:{d:`M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z`},child:[]}]})(e)}function so(e,t,n,r={}){let{align:i=`right`,side:a=`bottom`,gap:o=6,margin:s=8}=r,c=t.width,l=t.height,u=Math.max(0,n.width-c-s),d=Math.max(0,n.height-l-s),f=i===`left`?e.left:e.right-c;f=Math.max(s,Math.min(f,u));let p;return a===`top`?(p=e.top-l-o,p<s&&e.bottom+o+l<=n.height-s&&(p=e.bottom+o)):(p=e.bottom+o,p+l>n.height-s&&e.top-l-o>=s&&(p=e.top-l-o)),p>d&&(p=d),p<s&&(p=s),{x:Math.round(f),y:Math.round(p)}}function co(e){let{open:t=!0,anchor:n,anchorEl:r,onClose:i,isInside:a,align:o=`right`,side:s=`bottom`,gap:c=6,margin:l=8}=e,u=(0,g.useRef)(null),[d,f]=(0,g.useState)(null),p=(0,g.useRef)(i);(0,g.useLayoutEffect)(()=>{p.current=i});let m=()=>{if(!n)return null;if(`current`in n)return n.current?.getBoundingClientRect()??null;if(typeof n.getBoundingClientRect==`function`)return n.getBoundingClientRect();let e=n;return typeof e.left==`number`&&typeof e.right==`number`&&typeof e.top==`number`&&typeof e.bottom==`number`?e:null},h=()=>r||(n&&`current`in n?n.current:n&&typeof n.getBoundingClientRect==`function`?n:null),_=()=>{if(!t)return;let e=u.current;if(!e)return;let n=e.getBoundingClientRect();if(n.width===0&&n.height===0)return;let r=h(),i=r&&r.isConnected?r.getBoundingClientRect():m();if(!i)return;let a=so(i,{width:n.width,height:n.height},{width:window.innerWidth,height:window.innerHeight},{align:o,side:s,gap:c,margin:l});f(e=>e?.x===a.x&&e?.y===a.y?e:a)};return(0,g.useLayoutEffect)(()=>{t?_():f(null)},[t,n,r,o,s,c,l]),Rt(()=>{p.current()},t),(0,g.useEffect)(()=>{if(!t)return;let e=e=>e instanceof Node&&!!(u.current?.contains(e)||h()?.contains(e)||a?.(e)),n=t=>{e(t.target)||p.current()};return document.addEventListener(`mousedown`,n,!0),window.addEventListener(`resize`,_,!0),window.addEventListener(`scroll`,_,!0),()=>{document.removeEventListener(`mousedown`,n,!0),window.removeEventListener(`resize`,_,!0),window.removeEventListener(`scroll`,_,!0)}},[t,n,r]),{panelRef:u,pos:d,style:{position:`fixed`,left:d?.x??-9999,top:d?.y??-9999,visibility:d?`visible`:`hidden`},measure:_}}function lo({anchorRect:e,anchorEl:t,plugins:n,pinnedIds:r,orderedPluginIds:i,onTogglePin:a,onReorder:o,onOpenView:s,onManagePlugins:c,onClose:l}){let{t:u}=Mn(),{panelRef:d,style:f,measure:p}=co({anchor:e,anchorEl:t,onClose:l}),[,m]=(0,g.useState)(null),h=(0,g.useRef)(null),[_,v]=(0,g.useState)(null),y=(0,g.useMemo)(()=>{let e=new Map((i??[]).map((e,t)=>[e,t]));return n.map((e,t)=>({plugin:e,index:t})).sort((t,n)=>(e.get(t.plugin.id)??1e6+t.index)-(e.get(n.plugin.id)??1e6+n.index)).map(({plugin:e})=>e)},[n,i]);(0,g.useLayoutEffect)(()=>{p()},[y,p]);let b=(e,t)=>{let n=y.filter(e=>e.view!==!1&&!e.error).map(e=>e.id),r=n.indexOf(e),i=r+t;if(r<0||i<0||i>=n.length)return;let[a]=n.splice(r,1);a&&(n.splice(i,0,a),o(n))},x=(e,t)=>{if(!e||e===t)return;let n=y.filter(e=>e.view!==!1&&!e.error).map(e=>e.id),r=n.indexOf(e),i=n.indexOf(t);if(r<0||i<0)return;let[a]=n.splice(r,1);a&&(n.splice(i,0,a),o(n))};return(0,j.createPortal)((0,X.jsxs)(`div`,{ref:d,className:`pm-panel`,role:`menu`,"aria-label":u(`pluginMenuTitle`),style:f,children:[(0,X.jsxs)(`div`,{className:`pm-head`,"aria-hidden":`true`,children:[(0,X.jsx)(mt,{className:`pm-head-icon`,"aria-hidden":!0}),u(`pluginMenuTitle`)]}),(0,X.jsx)(`div`,{className:`pm-list`,children:n.length===0?(0,X.jsx)(`div`,{className:`pm-empty`,children:u(`pluginMenuEmpty`)}):y.map(e=>{let t=e.view===!1||!!e.error,n=!t&&r.has(e.id),i=e.error??(e.view===!1?u(`pluginMenuNoView`):void 0),o=e.iconSvg?void 0:e.icon&&!/[a-z]/i.test(e.icon)?e.icon:void 0;return(0,X.jsxs)(`div`,{className:`pm-row${_===e.id?` drop-target`:``}`,role:`none`,onDragOver:n=>{!t&&h.current&&(n.preventDefault(),v(e.id))},onDrop:t=>{t.preventDefault(),x(t.dataTransfer.getData(`text/plain`)||h.current,e.id),h.current=null,m(null),v(null)},children:[!t&&(0,X.jsx)(`button`,{type:`button`,className:`pm-drag`,draggable:!0,"aria-label":u(`pluginMenuReorder`),title:u(`pluginMenuReorderHint`),onDragStart:t=>{m(e.id),h.current=e.id,t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id);let n=document.createElement(`div`);n.style.cssText=`position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;opacity:0`,document.body.appendChild(n),t.dataTransfer.setDragImage(n,0,0),requestAnimationFrame(()=>n.remove())},onDragEnd:()=>{h.current=null,m(null),v(null)},onKeyDown:t=>{(t.key===`ArrowUp`||t.key===`ArrowDown`)&&(t.preventDefault(),b(e.id,t.key===`ArrowUp`?-1:1))},children:(0,X.jsx)(xe,{"aria-hidden":!0})}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`pm-row-main`,disabled:t,title:i,onClick:()=>s(e.id),children:[o||e.iconSvg?(0,X.jsx)(fi,{icon:o,iconSvg:e.iconSvg,className:`pm-icon`}):(0,X.jsx)(mt,{className:`pm-icon`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`pm-name`,children:e.name}),i&&(0,X.jsx)(`span`,{className:`pm-sub`,children:i})]}),!t&&(0,X.jsx)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":n,"aria-label":u(n?`pluginMenuUnpin`:`pluginMenuPin`),className:`pm-pin${n?` on`:``}`,onClick:()=>a(e.id,!n),children:n?(0,X.jsx)(oo,{"aria-hidden":!0}):(0,X.jsx)(ao,{"aria-hidden":!0})})]},e.id)})}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`pm-manage`,onClick:()=>{l(),c()},children:[(0,X.jsx)(se,{"aria-hidden":!0}),(0,X.jsx)(`span`,{children:u(`pluginMenuManage`)})]})]}),document.body)}function uo({onClose:e}){let t=Z(),{locale:n,setLocale:r,reloadPacks:i}=Mn(),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(``),[l,u]=(0,g.useState)(``);async function d(){try{let e=await fetch(hn(dn(`/api/locales`)));if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();o(t.packs??[]),c(``)}catch(e){c(t(`localeListFailed`,{error:e instanceof Error?e.message:String(e)}))}}(0,g.useEffect)(()=>{d()},[]);async function f(e){u(e),c(``);try{let t=await fetch(hn(dn(`/api/locales/${e}/install`)),{method:`POST`});if(!t.ok){let e=`HTTP ${t.status}`;try{e=(await t.json()).error??e}catch{}throw Error(e)}await i(),await d()}catch(e){c(t(`localeInstallFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(``)}}async function p(e){u(e),c(``);try{let t=await fetch(hn(dn(`/api/locales/${e}`)),{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);wn(e),n===e&&r(`zh`),await i(),await d()}catch(e){c(t(`localeInstallFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(``)}}return(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,X.jsxs)(`div`,{className:`bg-task-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`bg-task-head`,children:[(0,X.jsxs)(`span`,{className:`bg-task-title`,children:[(0,X.jsx)(Pe,{}),` `,t(`localePacks`)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:t(`close`),onClick:e,children:(0,X.jsx)(N,{})})]}),s&&(0,X.jsx)(`div`,{className:`bg-task-empty`,children:s}),a===null&&!s?(0,X.jsx)(`div`,{className:`bg-task-empty`,children:t(`loading`)}):(0,X.jsx)(`ul`,{className:`bg-task-list`,children:(a??[]).map(e=>{let n=l===e.code;return(0,X.jsxs)(`li`,{className:`bg-task-item`,children:[(0,X.jsxs)(`div`,{className:`bg-task-info`,children:[(0,X.jsxs)(`div`,{className:`bg-task-line1`,children:[(0,X.jsx)(`span`,{className:`bg-task-port`,children:e.nativeName}),e.installed&&e.version&&(0,X.jsxs)(`span`,{className:`bg-task-name`,children:[`v`,e.version]})]}),(0,X.jsxs)(`div`,{className:`bg-task-line2`,children:[(0,X.jsx)(`span`,{children:e.code}),e.installed?(0,X.jsxs)(`span`,{children:[t(`localeInstalled`),` · `,t(`localeRemoveHint`)]}):(0,X.jsx)(`span`,{children:t(`localeGetMore`)})]})]}),e.installed?(0,X.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,disabled:n,title:t(`localeRemove`),onClick:()=>void p(e.code),children:[(0,X.jsx)(L,{}),(0,X.jsx)(`span`,{children:t(n?`localeRemoving`:`localeRemove`)})]}):(0,X.jsxs)(`button`,{type:`button`,className:`btn`,disabled:n,title:t(`localeInstall`),onClick:()=>void f(e.code),children:[(0,X.jsx)(Ke,{}),(0,X.jsx)(`span`,{children:t(n?`localeDownloading`:`localeInstall`)})]})]},e.code)})}),(0,X.jsx)(`div`,{className:`bg-task-foot`,children:(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:t(`bgTaskRefresh`),onClick:()=>void d(),children:[(0,X.jsx)(J,{}),(0,X.jsx)(`span`,{children:t(`bgTaskRefresh`)})]})})]})})}var fo=`xing-shuyin/pi-web-ui`,po={state:`idle`,version:null,percent:0,message:null};function mo(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function ho(e,t){switch(t.state){case`checking`:return{...e,state:`checking`,message:null};case`available`:return{...e,state:`available`,version:t.version??e.version,message:null};case`up-to-date`:return{...e,state:`up-to-date`,version:t.version??e.version,message:null};case`downloading`:return{...e,state:`downloading`,percent:mo(t.percent),message:null};case`downloaded`:return{...e,state:`downloaded`,version:t.version??e.version,percent:100,message:null};case`error`:return{...e,state:`error`,message:t.message??`unknown error`};default:return e}}function go(e){if(!Ln(e))return null;let t=(e??(typeof window>`u`?void 0:window))?.piDesktop?.updater;return!t||typeof t.check!=`function`||typeof t.download!=`function`?null:t}function _o(e){return e instanceof Error?e.message:String(e)}function vo(e){let t=(e??``).trim().replace(/^v/,``);return t?`https://github.com/${fo}/releases/tag/v${t}`:`https://github.com/${fo}/releases/latest`}function yo(){let[e]=(0,g.useState)(()=>go()),[t,n]=(0,g.useState)(po);(0,g.useEffect)(()=>{if(e)return e.onEvent(e=>n(t=>ho(t,e)))},[e]);let r=(0,g.useCallback)(()=>{e&&(n(e=>({...e,state:`checking`,message:null})),e.check().catch(e=>n(t=>({...t,state:`error`,message:_o(e)}))))},[e]),i=(0,g.useCallback)(()=>{e&&(n(e=>({...e,state:`downloading`,message:null})),e.download().catch(e=>n(t=>({...t,state:`error`,message:_o(e)}))))},[e]),a=(0,g.useCallback)(()=>{e&&e.quitAndInstall().catch(e=>n(t=>({...t,state:`error`,message:_o(e)})))},[e]);return{...t,bridge:e,check:r,download:i,quitAndInstall:a}}function bo(e){let t=Math.max(0,e.input??0),n=Math.max(0,e.cacheRead??0),r=Math.max(0,e.cacheWrite??0),i=t+n+r;return{totalInput:i,miss:t,read:n,write:r,hitRate:i>0?Math.min(n/i,1):0,writeRate:i>0?Math.min(r/i,1):0}}var xo=2e3;function So(e,t,n=xo){return e.filter(e=>t-e.t<=n)}function Co(e,t=xo){if(e.length<2)return 0;let n=e[e.length-1],r=e.find(e=>e.t>=n.t-t)??e[0],i=(n.t-r.t)/1e3;return i<=0?0:Math.max(0,(n.out-r.out)/i)}function wo(e){if(!e)return 0;let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r>=12352&&r<=12543||r>=13312&&r<=19903||r>=19968&&r<=40959||r>=63744&&r<=64255||r>=65280&&r<=65519||r===12288)&&t++}let n=e.length-t;return Math.round(t+n/4)}function To(e){let t=0;for(let n of e)n.type===`text`&&typeof n.text==`string`&&n.text?t+=wo(n.text):n.type===`thinking`&&typeof n.thinking==`string`&&n.thinking&&(t+=wo(n.thinking));return t}function Eo(e){return e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function Do(e){return e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function Oo(e){return e.startsWith(`zh`)?`ZH`:e.startsWith(`ja`)?`JA`:e.startsWith(`ko`)?`KO`:e.startsWith(`fr`)?`FR`:e.startsWith(`de`)?`DE`:e.startsWith(`es`)?`ES`:e.startsWith(`ru`)?`RU`:e.startsWith(`pt`)?`PT`:e.startsWith(`it`)?`IT`:`EN`}function ko({entry:e,bar:t,chat:n,view:r,plugins:i,onViewChange:a,onOpenPanel:o,onOpenSettings:s,onOpenGlobalSearch:c,onOpenBgTasks:l,onOpenProjectPicker:u,onOpenPluginMenu:d,isPluginMenuOpen:f,isProjectPickerOpen:p,onUiAction:m,uiContextEntries:h,dropdownProps:_}){let v=Z(),{locale:y,packs:b,setLocale:x}=Mn(),{engine:S}=Na(),C=S===`dsh`,[w,T]=(0,g.useState)(!1),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(!1),ee=n.settings?.uiLayout,M=n.state,te=M?.stats,ne=M?.isStreaming??!1,N=(0,g.useRef)([]),F=M?.streamingMessage?To(M.streamingMessage.content):0;(0,g.useEffect)(()=>{if(!ne){N.current=[];return}let e=Date.now(),t=N.current,n=t[t.length-1];n&&e-n.t<250||(N.current=So([...t,{t:e,out:F}],e))},[ne,F]);let re=ne?Co(N.current):0,ie=n=>{n.preventDefault(),n.stopPropagation();let r=t=>{let n={...ee?.slots,[e.id]:t};$({type:`set_settings`,uiLayout:{...ee,slots:n}})},i=()=>{let t=new Set(ee?.hidden??[]);t.add(e.id),$({type:`set_settings`,uiLayout:{...ee,hidden:[...t]}})},a=[];t!==`top`&&a.push({id:`host:move-top`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToTop`),kind:`action`,order:10,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`bottom`&&a.push({id:`host:move-bottom`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToBottom`),kind:`action`,order:20,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`left`&&a.push({id:`host:move-left`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToLeft`),kind:`action`,order:30,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`right`&&a.push({id:`host:move-right`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToRight`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),a.push({id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:v(`uiLayoutRestore`),kind:`action`,order:50,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),h&&h.length>0&&a.push(...h),la({x:n.clientX,y:n.clientY,slot:`contextmenu.topbar`,target:{id:e.id,label:e.label},entries:a,onHostAction:e=>{e.id===`host:move-top`?r(`topbar.primary`):e.id===`host:move-bottom`?r(`bottombar`):e.id===`host:move-left`?r(`sidebar.left`):e.id===`host:move-right`?r(`sidebar.right`):e.id===`host:hide-item`&&i()}})},I=e.id,ae=e.labelExplicit?e.label:``,L=e=>ae||e,R=e=>ae?`${ae} ${e}`:e;if(e.kind===`select`&&e.options?.length){let t=e.options.some(t=>t.value===e.value)?e.value:e.options[0].value;return(0,X.jsx)(`select`,{className:`bar-item bar-item-select`,title:e.hint??e.label,"data-tip":e.hint??e.label,"aria-label":e.label,value:t,onChange:t=>m?.(e,t.target.value),onContextMenu:ie,"data-bar-item":I,children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}if(I===`host:brand`)return(0,X.jsxs)(`span`,{className:`bar-item brand bar-item-brand`,title:v(`brand`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`brand-logo bar-item-brand-logo`,children:`π`}),(0,X.jsx)(`span`,{className:`brand-name bar-item-text`,children:L(`pi-web-ui`)})]});if(I===`host:conn`){let e=n.ready?`ok`:n.status===`closed`?`error`:`busy`,t=n.ready?v(`connected`):n.status===`closed`?v(`reconnecting`):v(`connecting`);return(0,X.jsxs)(`span`,{className:`bar-item status-item status-conn ${e} bar-item-conn`,title:t,"data-tip":t,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`status-dot ${e}`}),(0,X.jsx)(`span`,{className:`status-conn-label bar-item-text`,children:R(t)})]})}if(I===`host:engine`)return S===`pi`?null:(0,X.jsx)(`span`,{className:`bar-item status-item engine-badge engine-${S} bar-item-engine`,title:`${v(`engineBadge`)}: ${S}`,"data-tip":`${v(`engineBadge`)}: ${S}`,onContextMenu:ie,"data-bar-item":I,children:R(S===`dsh`?`DSH`:S)});if(I===`host:ctx`){let e=te?.contextUsage,t=e?.softCap??null,n=t!==null&&t>0&&t<(e?.contextWindow??0),r=n?t:e?.contextWindow??0,i=e?.tokens!==null&&e?.tokens!==void 0&&r>0?Math.min(100,Math.round(e.tokens/r*100)):null,a=e?.tokens!==null&&e?.tokens!==void 0?Eo(e.tokens):null,o=r>0?Eo(r):null,s=a!==null&&o!==null&&i!==null?`${a} / ${o}`:`—`,c=i===null?``:i>=80?`warn`:i>=50?`mid`:`ok`,l=n?`${v(`contextUsage`)}: ${Eo(e?.tokens??0)} / ${Eo(t)} (${v(`softCapMarker`)}, max ${Eo(e?.contextWindow??0)})`:t!==null&&t>0?`${v(`contextUsage`)}: ${s} · ${v(`softCapMarker`)}: ${Eo(t)}`:`${v(`contextUsage`)}: ${s}`,u=i!==null&&i>0?+(31.42*(1-Math.min(i,100)/100)).toFixed(2):31.42;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-ctx bar-item-ctx`,title:l,"data-tip":l,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsxs)(`svg`,{className:`ctx-ring ${c}`,viewBox:`0 0 14 14`,width:`13`,height:`13`,"aria-hidden":`true`,children:[(0,X.jsx)(`circle`,{className:`ctx-ring-bg`,cx:`7`,cy:`7`,r:`5`}),i!==null&&i>0&&(0,X.jsx)(`circle`,{className:`ctx-ring-fill`,cx:`7`,cy:`7`,r:`5`,strokeDasharray:31.42,strokeDashoffset:u,"data-percent":i})]}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[ae?`${ae} `:``,a!==null&&o!==null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`ctx-val`,children:a}),(0,X.jsx)(`span`,{className:`status-sep`,children:`/`}),(0,X.jsx)(`span`,{className:`ctx-max`,children:o})]}):s]})]})}if(I===`host:cache`){let e=bo(te?.tokens??{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}),t=e.hitRate*100,n=e.totalInput===0?``:e.hitRate>=.7?`ok`:e.hitRate>=.4?`mid`:`warn`,r=e.totalInput>0?`${t.toFixed(1)}%`:`—`,i=v(`cacheHitTip`,{read:Eo(e.read),write:Eo(e.write),miss:Eo(e.miss),input:Eo(e.totalInput)}),a=e.totalInput>0?`${v(`cacheHit`)}: ${r} · ${i}`:v(`cacheHit`),o=e.totalInput===0;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-cache bar-item-cache${o?` is-zero`:``}`,title:a,"data-tip":a,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Je,{className:`bar-item-icon`}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[ae?`${ae} `:``,(0,X.jsx)(`b`,{className:`cache-pct ${n}`,children:r})]})]})}if(I===`host:cost`){let e=te?.cost??0,t=Do(e),n=v(`cumulativeCost`);return(0,X.jsxs)(`span`,{className:`bar-item status-item status-cost bar-item-cost${e<=0?` is-zero`:``}${ae?` has-name`:``}`,title:n,"data-tip":n,onContextMenu:ie,"data-bar-item":I,children:[ae?(0,X.jsx)(`span`,{className:`bar-item-text`,children:ae}):null,(0,X.jsx)(`span`,{className:`bar-item-char`,children:`$`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:t})]})}if(I===`host:msg-count`){let e=te?.totalMessages??0,t=`${v(`sessionMessages`)}: ${e}`;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-msg-count bar-item-msg-count${e===0?` is-zero`:``}`,title:t,"data-tip":t,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(be,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:R(String(e))})]})}if(I===`host:working`){if(!ne)return null;let e=(M?.queue?.steering?.length??0)+(M?.queue?.followUp?.length??0);return(0,X.jsxs)(`span`,{className:`bar-item status-item working bar-item-working`,title:v(`working`),"data-tip":v(`working`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`working-spin`}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[L(v(`working`)),e>0&&` ⏳ ${e}`]}),(0,X.jsx)(`span`,{className:`status-rate bar-item-rate`,title:v(`rateTip`),children:re>0?`${Math.round(re)}${v(`tps`)}`:`…`})]})}if(I===`host:status-delegate`)return M?.delegateMode?(0,X.jsxs)(`span`,{className:`bar-item status-item delegate-badge bar-item-delegate`,title:M.delegateConvId?v(`delegateModeOpenTip`):v(`delegateModeBadgeTip`),"data-tip":M.delegateConvId?v(`delegateModeOpenTip`):v(`delegateModeBadgeTip`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`bar-item-icon`,children:`🔎`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:L(v(`delegateModeBadge`))}),M.delegateConvId?(0,X.jsx)(`button`,{type:`button`,className:`delegate-badge-open`,title:v(`delegateModeOpenTip`),onClick:()=>$({type:`switch_conversation`,id:M.delegateConvId}),children:`↗`}):null]}):null;if(I===`host:host-metrics`){let e=n.hostMetrics;if(!e)return null;let t=e.cpuPercent===null||!Number.isFinite(e.cpuPercent)?`—`:`${Math.round(e.cpuPercent)}%`,r=Number.isFinite(e.memoryPercent)?`${Math.round(e.memoryPercent)}%`:`—`;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-host-metrics bar-item-host-metrics`,title:`${v(`hostResourcesTip`)}\n${v(`hostProcessor`)}: ${t} · ${v(`hostMemory`)}: ${r}`,"data-tip":`${v(`hostResourcesTip`)}\n${v(`hostProcessor`)}: ${t} · ${v(`hostMemory`)}: ${r}`,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Xe,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:R(`${t} · ${r}`)})]})}if(I===`host:browser`)return n.settings?.disabledAgentTools?.includes(`browser_page`)?null:(0,X.jsx)(`span`,{className:`bar-item-wrap`,onContextMenu:ie,"data-bar-item":I,children:(0,X.jsx)(lr,{})});if(I===`host:sound`)return(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:w,onOpenChange:T,tip:L(v(`sound`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`sound`)),"data-tip":L(v(`sound`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(P,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:L(v(`sound`))})]}),children:[_?.sound&&_?.onSoundChange?(0,X.jsx)(Pn,{settings:_.sound,onChange:_.onSoundChange,onPreview:_.onSoundPreview??(()=>{})}):null,(0,X.jsx)(ii,{})]});if(I===`host:language`)return(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:E,onOpenChange:D,tip:L(v(`language`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`language`)),"data-tip":L(v(`language`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Pe,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(Oo(y))})]}),children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`language`)}),b.map(e=>(0,X.jsx)(Vt,{active:y===e.code,onClick:()=>{x(e.code),D(!1)},children:e.nativeName},e.code)),_?.onLocaleModalOpen?(0,X.jsxs)(Vt,{onClick:()=>{D(!1),_.onLocaleModalOpen?.()},children:[(0,X.jsx)(Ke,{}),` `,v(`localeGetMore`)]}):null]});if(I===`host:theme`){let e=_?.themes??[],n=_?.theme??null;return(0,X.jsx)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:O,onOpenChange:t=>{k(t),t&&e.length===0&&_?.reloadThemes?.()},tip:L(v(`theme`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`theme`)),"data-tip":L(v(`theme`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(V,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:L(v(`theme`))})]}),children:(()=>{let t=e.filter(e=>e.group===`classic`),r=e.filter(e=>e.group!==`classic`),i=e=>{let t=y===`zh`?e.name:e.nameEn??e.name,n=e.scheme===`light`?v(`themeLight`):e.scheme===`dark`?v(`themeDark`):``;return n?y===`zh`?`${t}(${n})`:`${t} (${n})`:t};return(0,X.jsxs)(X.Fragment,{children:[t.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`themeGroupClassics`)}),t.map(e=>(0,X.jsx)(Vt,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),k(!1)},children:i(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:t.length>0?v(`themeGroupBuiltin`):v(`theme`)}),(0,X.jsx)(Vt,{active:n===null,onClick:()=>{_?.onThemeChange?.(null),k(!1)},children:v(`themeDefault`)}),r.map(e=>(0,X.jsx)(Vt,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),k(!1)},children:i(e)},e.id))]})})()})}if(I===`host:update`){let e=_?.updatesCount??0;return _?.managed?(0,X.jsxs)(`span`,{className:`bar-item chip`,title:v(`updatesManaged`),"data-tip":v(`updatesManaged`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Ke,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(`v${_?.appVersion??n.update?.current??`…`}`)})]}):(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:A,onOpenChange:e=>{j(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},tip:L(v(`update`)),fit:!0,caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`update`)),"data-tip":L(v(`update`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Ke,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(`v${n.update?.current??`…`}`)}),n.update&&!n.update.upToDate&&(0,X.jsx)(`span`,{className:`update-dot`}),e>0&&(0,X.jsx)(`span`,{className:`update-badge`,children:e})]}),children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`update`)}),_?.renderUpdateBody?.(),_?.renderAllUpdatesBody?.()]})}let B=null,H=e.label,U=null,W=!1,oe=!1,G=``,ce,K;switch(I){case`host:chat`:B=(0,X.jsx)(be,{className:`bar-item-icon`}),H=L(v(`chat`)),W=r===`chat`,oe=!0,K=()=>a?.(`chat`);break;case`host:terminal`:B=(0,X.jsx)(z,{className:`bar-item-icon`}),H=L(v(`terminal`)),W=r===`terminal`,oe=!0,K=()=>a?.(`terminal`);break;case`host:git`:B=(0,X.jsx)(Ie,{className:`bar-item-icon`}),H=L(v(`scmTab`)),W=r===`git`,oe=!0,K=()=>a?.(`git`);break;case`host:new-chat`:B=(0,X.jsx)(fe,{className:`bar-item-icon`}),H=L(v(`newChat`)),G=`chip newchat`,K=()=>{a?.(`chat`),$({type:`new_chat`}),or()};break;case`host:new-ephemeral-chat`:if(C)return null;B=(0,X.jsx)(Dt,{className:`bar-item-icon`}),H=L(v(`newChatEphemeral`)),G=`chip newchat ephemeral-chat-btn`,K=()=>{a?.(`chat`),$({type:`new_chat`,ephemeral:!0}),or()};break;case`host:history`:if(r&&r!==`chat`)return null;B=(0,X.jsx)(xe,{className:`bar-item-icon`}),H=L(v(`openHistory`)),G=`panel-toggle`,K=()=>o?.(`left`);break;case`host:files`:if(r&&r!==`chat`)return null;B=(0,X.jsx)(Le,{className:`bar-item-icon`}),H=L(v(`openFiles`)),G=`panel-toggle has-label`,K=()=>o?.(`right`);break;case`host:open-project`:B=(0,X.jsx)(Re,{className:`bar-item-icon`}),H=L(v(`openProject`)),G=`chip open-project`,W=!!p,K=()=>u?.();break;case`host:search`:B=(0,X.jsx)(le,{className:`bar-item-icon`}),H=L(v(`searchGlobal`)),G=`chip`,K=()=>c?.();break;case`host:tasks`:B=(0,X.jsx)(Oe,{className:`bar-item-icon`}),H=L(v(`bgTasks`)),G=`chip bg-task-chip`,n.bgServers.length>0&&(U=(0,X.jsx)(`span`,{className:`bg-task-badge bar-item-badge`,children:n.bgServers.length})),K=()=>l?.();break;case`host:settings`:B=(0,X.jsx)(se,{className:`bar-item-icon`}),H=L(v(`settings`)),G=`chip`,K=()=>s?.();break;case`host:plugins`:B=(0,X.jsx)(mt,{className:`bar-item-icon`}),H=L(v(`pluginMenuTitle`)),G=`chip`,K=e=>{d?d(e.currentTarget):s?.(`plugins`)};break;case`host:github`:B=(0,X.jsx)(Fe,{className:`bar-item-icon`}),H=L(`GitHub`),G=`chip github`,K=()=>window.open(`https://github.com/xing-shuyin/pi-web-ui`,`_blank`,`noreferrer,noopener`);break;case`host:cwd`:B=(0,X.jsx)(Le,{className:`bar-item-icon`}),H=R(M?.cwd?M.cwd.split(/[/\\]/).pop()||M.cwd:v(`openProject`)),G=`status-item status-cwd`,W=!!p,K=()=>u?.();break;case`host:plugin-status`:if(n.statuses.length===0)return null;B=(0,X.jsx)(Tt,{className:`bar-item-icon`}),H=R(n.statuses.map(e=>e.text).join(` · `)),G=`status-item ext-status`;break;default:if(e.kind===`view`){let t=e.view??``;W=r===t,oe=!0;let o=(i??n.plugins??[]).find(t=>`plugin:${t.id}`===e.source);G=`plugin-tab${o?.error?` broken`:``}`,o?.error&&(ce=`${e.label}: ${o.error}`);let s=e.iconSvg||o?.iconSvg,c=e.icon||o?.icon;B=s?(0,X.jsx)(fi,{icon:c,iconSvg:s,className:`bar-item-icon plugin-icon-svg`}):c?(0,X.jsx)(`span`,{className:`bar-item-icon bar-item-glyph`,children:c}):null,K=()=>a?.(t)}else{let n=e.iconSvg,r=e.icon;G=t===`bottom`?`status-item status-action chip`:`chip`,B=n?(0,X.jsx)(fi,{icon:r,iconSvg:n,className:`bar-item-icon plugin-icon-svg`}):r?(0,X.jsx)(`span`,{className:`bar-item-icon bar-item-glyph`,children:r}):null,e.badge&&(U=(0,X.jsx)(`span`,{className:`bar-item-badge`,children:e.badge})),K=()=>m?.(e)}}let ue=ce??e.hint??H,de=[`bar-item`,oe?`tb-tab${W?` active`:``}`:``,G,W&&!oe?`active`:``].filter(Boolean).join(` `);return(0,X.jsxs)(`button`,{type:`button`,role:oe?`tab`:void 0,"aria-selected":oe?W:void 0,"aria-haspopup":I===`host:plugins`?`menu`:void 0,"aria-expanded":I===`host:plugins`?!!f:void 0,className:de,title:ue,"data-tip":ue,"aria-label":H,onClick:K,onContextMenu:ie,"data-bar-item":I,children:[B,(0,X.jsx)(`span`,{className:`bar-item-text`,children:H}),U]})}var Ao={name:`@earendil-works/pi-coding-agent`,kind:`pi-core`,current:``,latest:null,upToDate:!1};function jo({anchorRef:e,open:t,onClose:n,children:r}){let{panelRef:i,style:a,measure:o}=co({open:t,anchor:e,onClose:n});return(0,g.useLayoutEffect)(()=>{t&&o()},[t,r,o]),t?(0,j.createPortal)((0,X.jsx)(`div`,{ref:i,className:`plugin-topbar-menu portal`,role:`menu`,style:a,children:r}),document.body):null}function Mo(){let[e,t]=(0,g.useState)(()=>typeof window<`u`&&window.matchMedia!==void 0&&window.matchMedia(`(max-width: 768px)`).matches);return(0,g.useEffect)(()=>{if(typeof window>`u`||window.matchMedia===void 0)return;let e=window.matchMedia(`(max-width: 768px)`),n=e=>t(e.matches);return typeof e.addEventListener==`function`?e.addEventListener(`change`,n):e.addListener(n),()=>{typeof e.removeEventListener==`function`?e.removeEventListener(`change`,n):e.removeListener(n)}},[]),e}function No({chat:e,terminal:t,view:n,plugins:r,uiPrimary:i,uiOverflow:a,uiContextTopbar:o,onUiAction:s,onViewChange:c,onOpenPanel:l,onOpenSettings:u,onManagePlugins:d,onOpenBgTasks:f,onOpenGlobalSearch:p,sound:m,onSoundChange:h,onSoundPreview:_,themes:v,theme:y,onThemeChange:b,reloadThemes:x,onOpenIconEdit:S}){let{locale:C,setLocale:w,t:T,packs:E}=Mn(),[D,O]=(0,g.useState)(!1),[k,A]=(0,g.useState)(!1),[j,ee]=(0,g.useState)(null),M=Pa(`cwd`),te=Pa(`workspaceRoots`),ne=Fa(),N=(0,g.useRef)(null),F=t=>!e.tabs||t===`chat`||e.tabs.includes(t),re=[...a??[]].filter(e=>(e.source!==`host`||e.id!==`host:brand`)&&!Ni(e)),ie=new Set([...i??[],...a??[]].filter(e=>Ni(e)&&!e.hidden).map(e=>e.source.slice(7))),I=new Map((e.settings?.uiLayout?.order??[]).map((e,t)=>[e,t])),ae=r.map((e,t)=>({id:e.id,index:t})).sort((e,t)=>(I.get(`${e.id}:__view`)??1e6+e.index)-(I.get(`${t.id}:__view`)??1e6+t.index)).map(e=>e.id),L=i===void 0?[`host:history`,`host:brand`,`host:open-project`,`host:chat`,`host:terminal`,`host:git`,`host:plugins`,`host:search`,`host:browser`,`host:tasks`,`host:settings`,`host:sound`,`host:language`,`host:theme`,`host:update`,`host:github`,`host:new-chat`,`host:new-ephemeral-chat`,`host:files`].map(e=>({id:e,entry:null})):i.map(e=>({id:e.id,entry:e})),R=(F(`plugins`)?r:[]).filter(e=>e.view!==!1&&e.error&&!L.some(t=>t.id===`${e.id}:__view`)).map(e=>({id:`${e.id}:__view`,slot:`topbar.primary`,source:`plugin:${e.id}`,label:e.name,kind:`view`,view:`plugin:${e.id}`,order:23,align:`end`,hidden:!1,userOverrides:[],arrangedBy:[]})),B=e=>{if(e.source!==`host`)return!1;switch(e.id){case`host:history`:return l(`left`),!0;case`host:files`:return l(`right`),!0;case`host:new-chat`:return c(`chat`),$({type:`new_chat`}),or(),!0;case`host:new-ephemeral-chat`:return c(`chat`),$({type:`new_chat`,ephemeral:!0}),or(),!0;case`host:open-project`:return A(!0),!0;case`host:search`:return p(),!0;case`host:tasks`:return f(),!0;case`host:settings`:return u(),!0;case`host:plugins`:return ee(N.current?{rect:N.current.getBoundingClientRect(),el:N.current}:null),!0;default:return!1}},H=(t,n,r)=>{t.preventDefault(),t.stopPropagation();let i=e.settings?.uiLayout,a=e=>{let t={...i?.slots,[n]:e};$({type:`set_settings`,uiLayout:{...i,slots:t}})},s=()=>{let e=new Set(i?.hidden??[]);e.add(n),$({type:`set_settings`,uiLayout:{...i,hidden:[...e]}})},c=[{id:`host:move-bottom`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToBottom`),kind:`action`,order:10,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-left`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToLeft`),kind:`action`,order:20,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-right`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToRight`),kind:`action`,order:30,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:T(`uiLayoutRestore`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},...o??[]];la({x:t.clientX,y:t.clientY,slot:`contextmenu.topbar`,target:{id:n,label:r},entries:c,onHostAction:e=>{e.id===`host:move-bottom`?a(`bottombar`):e.id===`host:move-left`?a(`sidebar.left`):e.id===`host:move-right`?a(`sidebar.right`):e.id===`host:hide-item`&&s()}})},{appVersion:U}=Na(),W=Ia(),oe=La(),[G,ce]=(0,g.useState)(!1);(0,g.useEffect)(()=>{G&&e.status===`open`&&ce(!1)},[G,e.status]);let[K,ue]=(0,g.useState)(!1),[de,q]=(0,g.useState)(!1),[J,pe]=(0,g.useState)(!1),[me,Y]=(0,g.useState)(!1),he=Ln(),ge=yo(),[_e,ve]=(0,g.useState)(!1),ye=()=>{if(!e.ready)return;let n=T(`updateTabTitle`),r={name:n,command:`npm i -g pi-web-ui@latest`,cwd:"${pwd}"},i=e.terminals.find(e=>e.title===n);i?(t.restart(i.id),$({type:`run_command`,terminalId:i.id,conversationId:i.conversationId,command:r,cols:80,rows:24})):t.create({id:At(),conversationId:e.activeConversationId||e.state?.conversationId||``,title:n,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:r}),Y(!1),c(`terminal`)},Se=(n,r)=>{if(!e.ready||n.length===0)return;let i={name:r,command:Ot(n),cwd:"${pwd}"},a=e.terminals.find(e=>e.title===r);a?(t.restart(a.id),$({type:`run_command`,terminalId:a.id,conversationId:a.conversationId,command:i,cols:80,rows:24})):t.create({id:At(),conversationId:e.activeConversationId||e.state?.conversationId||``,title:r,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:i}),Y(!1),c(`terminal`)},Ce=e.updatesAll??[],we=e.updatesSdk,Te=we&&we.newerInstalled?{running:we.running,installed:we.newerInstalled}:null,Ee=we?.bundledInUse===!0,De=Ce.find(e=>e.kind===`pi-core`&&!e.error),ke=Ee&&(!De||!De.upToDate),Ae=ke&&!De,je=Ce.filter(e=>!e.upToDate&&!e.error).length,Me=Ce.filter(e=>!e.upToDate&&!e.error&&e.kind!==`webui`),Ne=e=>e.kind===`git-extension`&&e.source?e.source:e.name,ze=e=>e.kind===`git-extension`&&e.source&&e.source!==e.name?`${e.source} (${e.name})`:e.name,Be=e=>{let t=e.replace(/ \([0-9a-f]{7}\)$/,``);return/^[0-9a-f]{7}$/.test(t)?``:t},Ve=(e,t)=>{if(!t)return Be(e);let n=Be(e),r=Be(t);return n===r?n:`${n} → ${r}`},He=()=>(0,X.jsxs)(`div`,{className:`dd-updates-all`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`updatesAllTitle`)}),e.updatesAll===null?(0,X.jsx)(`div`,{className:`dd-note`,children:T(`checkingUpdate`)}):Ce.length===0?(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updatesAllUpToDate`)}):(0,X.jsx)(`ul`,{className:`dd-all-list`,children:Ce.map(e=>{let t=Te!=null&&e.kind===`pi-core`,n=!e.error&&(!e.upToDate||t);return(0,X.jsxs)(`li`,{className:`dd-all-item${e.error?` err`:n?` warn`:``}`,children:[e.kind!==`webui`&&!e.upToDate&&!e.error&&(0,X.jsx)(`button`,{type:`button`,className:`dd-update-btn`,onClick:()=>Se([e],T(`updatePkgTabTitle`,{name:e.name})),children:T(`updateBtn`)}),(0,X.jsx)(`span`,{className:`dd-all-name`,title:ze(e),children:Ne(e)}),(0,X.jsxs)(`span`,{className:`dd-all-meta`,children:[(0,X.jsx)(`span`,{className:`dd-all-kind`,children:e.kind===`webui`?T(`kindWebUi`):e.kind===`pi-core`?T(`kindPiCore`):e.kind===`git-extension`?T(`kindGitExtension`):e.kind===`plugin`?T(`kindPlugin`):T(`kindPackage`)}),(0,X.jsx)(`span`,{className:`dd-all-vers`,title:e.error?e.error:e.kind===`git-extension`?e.upToDate?e.current:`${e.current} → ${e.latest}`:void 0,children:e.error?T(`updateCheckFailed`):e.kind===`git-extension`?e.upToDate?Be(e.current):Ve(e.current,e.latest):e.kind===`plugin`?e.upToDate?e.current.startsWith(`v`)?e.current:Be(e.current):Ve(e.current,e.latest):e.upToDate?`v${e.current}`:(0,X.jsxs)(X.Fragment,{children:[`v`,e.current,` → v`,e.latest]})}),t&&!e.error&&(0,X.jsx)(`span`,{className:`dd-split-run`,children:T(`piCoreSplitRun`,{running:Te.running})})]})]},`${e.kind}:${e.name}`)})}),Te&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`piSdkSplitNote`,{running:Te.running,installed:Te.installed})}),ke&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`piSdkBundledNote`,{running:we.running})}),(0,X.jsxs)(`div`,{className:`dd-actions`,children:[Ae&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Se([Ao],T(`installGlobalEngineTabTitle`)),children:T(`installGlobalEngineBtn`)}),Me.length>0&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Se(Me,T(`updateAllTabTitle`)),children:T(`updateAllBtn`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,style:Me.length>0?{flex:1}:void 0,onClick:()=>$({type:`check_updates_all`,force:!0}),children:T(`updatesAllRefresh`)})]})]}),Ue=()=>{let t=vo(e.update?.latest??ge.version),n=(0,X.jsx)(`a`,{className:`dd-refresh dd-more-link`,href:t,target:`_blank`,rel:`noreferrer noopener`,children:T(`updateDesktopManual`)});if(!ge.bridge)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopNoBridge`)}),n]});switch(ge.state){case`checking`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopChecking`)}),n]});case`available`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopAvailable`,{version:ge.version??e.update?.latest??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.download(),children:T(`updateDesktopDownload`)}),n]});case`downloading`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopDownloading`,{n:ge.percent})}),n]});case`downloaded`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`updateDesktopDownloaded`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.quitAndInstall(),children:T(`updateDesktopInstall`)}),n]});case`up-to-date`:return(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`upToDate`)});case`error`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopError`,{error:ge.message??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>ge.check(),children:T(`updateDesktopCheck`)}),n]});default:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.check(),children:T(`updateDesktopCheck`)}),n]})}},We=()=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`dd-update`,children:[(0,X.jsxs)(`div`,{className:`dd-row`,children:[(0,X.jsx)(`span`,{children:T(`currentVersion`)}),(0,X.jsxs)(`b`,{children:[`v`,e.update?.current??`…`]})]}),(0,X.jsxs)(`div`,{className:`dd-row`,children:[(0,X.jsx)(`span`,{children:T(`latestVersion`)}),(0,X.jsx)(`b`,{children:e.update===null?T(`checkingUpdate`):e.update.error?e.update.error:e.update.latest?`v${e.update.latest}`:T(`checkingUpdate`)})]}),e.update&&e.update.upToDate&&(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`upToDate`)}),e.update&&!e.update.upToDate&&e.update.latest&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateAvailable`,{version:e.update.latest})}),e.update?.latestPublishedAt&&Date.now()-new Date(e.update.latestPublishedAt).getTime()<18e5&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateJustPublished`,{version:e.update.latest??``})}),e.update&&!e.update.upToDate&&e.update.latest&&!he&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateTerminalHint`)}),e.update&&!e.update.upToDate&&e.update.latest&&he&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopNote`)})]}),(0,X.jsxs)(`div`,{className:`dd-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>$({type:`check_update`}),children:e.update===null?T(`checkingUpdate`):T(`checkUpdate`)}),e.update&&!e.update.upToDate&&e.update.latest&&!he&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:ye,children:T(`updateNow`)}),e.update&&!e.update.upToDate&&e.update.latest&&he&&Ue(),oe&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,disabled:G,title:T(`restartServiceTip`,{name:oe.name}),onClick:()=>{G||(ce(!0),$({type:`restart_service`}))},children:T(G?`restartingService`:`restartService`)})]})]}),qe=Mo(),Je={"host:brand":(0,X.jsxs)(`span`,{className:`brand`,children:[(0,X.jsx)(`span`,{className:`brand-logo`,children:`π`}),(0,X.jsx)(`span`,{className:`brand-name`,children:`pi-web-ui`})]}),"host:open-project":(0,X.jsxs)(`button`,{type:`button`,className:`chip open-project`,"data-tip":T(`openProject`),onClick:()=>A(!0),children:[(0,X.jsx)(Re,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`openProject`)})]}),"host:history":n===`chat`&&F(`history`)?(0,X.jsx)(`button`,{type:`button`,className:`panel-toggle`,"data-tip":T(`openHistory`),"aria-label":T(`openHistory`),onClick:()=>l(`left`),children:(0,X.jsx)(xe,{})}):null,"host:files":n===`chat`&&F(`files`)?(0,X.jsxs)(`button`,{type:`button`,className:`panel-toggle has-label`,"data-tip":T(`openFiles`),"aria-label":T(`openFiles`),onClick:()=>l(`right`),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{children:T(`openFiles`)})]}):null,"host:new-chat":F(`new-chat`)?(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat`,"data-tip":T(`newChatTip`),onClick:()=>{c(`chat`),$({type:`new_chat`}),or()},children:[(0,X.jsx)(fe,{}),(0,X.jsx)(`span`,{children:T(`newChat`)})]}):null,"host:new-ephemeral-chat":ne?null:(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat ephemeral-chat-btn`,"data-tip":T(`newChatEphemeralTip`),onClick:()=>{c(`chat`),$({type:`new_chat`,ephemeral:!0}),or()},children:[(0,X.jsx)(Dt,{}),(0,X.jsx)(`span`,{children:T(`newChatEphemeral`)})]}),"host:chat":(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`chat`,className:`tb-tab${n===`chat`?` active`:``}`,"data-tip":T(`chat`),onClick:()=>c(`chat`),children:[(0,X.jsx)(be,{}),(0,X.jsx)(`span`,{children:T(`chat`)})]}),"host:terminal":F(`terminal`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`terminal`,className:`tb-tab${n===`terminal`?` active`:``}`,"data-tip":T(`terminal`),onClick:()=>c(`terminal`),children:[(0,X.jsx)(z,{}),(0,X.jsx)(`span`,{children:T(`terminal`)})]}):null,"host:git":F(`git`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`git`,className:`tb-tab${n===`git`?` active`:``}`,"data-tip":T(`scmTab`),onClick:()=>c(`git`),children:[(0,X.jsx)(Ie,{}),(0,X.jsx)(`span`,{children:T(`scmTab`)})]}):null,"host:plugins":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`pluginMenuTitle`),"aria-haspopup":`menu`,"aria-expanded":j!==null,onClick:e=>{let t=e.currentTarget;ee(e=>e?.el===t?null:{rect:t.getBoundingClientRect(),el:t})},children:[(0,X.jsx)(mt,{"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`pluginMenuTitle`)})]}),"host:search":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`searchGlobalTip`),onClick:p,children:[(0,X.jsx)(le,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`searchGlobal`)})]}),"host:browser":e.settings?.disabledAgentTools?.includes(`browser_page`)??!1?null:(0,X.jsx)(lr,{}),"host:tasks":(0,X.jsxs)(`button`,{type:`button`,className:`chip bg-task-chip`,"data-tip":T(`bgTasksTip`),onClick:f,children:[(0,X.jsx)(Oe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`bgTasks`)}),e.bgServers.length>0&&(0,X.jsx)(`span`,{className:`bg-task-badge`,children:e.bgServers.length})]}),"host:settings":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`settingsTitle`),onClick:u,children:[(0,X.jsx)(se,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`settings`)})]}),"host:sound":(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`sound`)})]}),tip:T(`sound`),open:K,onOpenChange:ue,caret:!1,children:[(0,X.jsx)(Pn,{settings:m,onChange:h,onPreview:_}),(0,X.jsx)(ii,{})]}),"host:language":(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Pe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:Tn(C)})]}),tip:T(`language`),open:de,onOpenChange:q,caret:!1,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`language`)}),E.map(e=>(0,X.jsx)(Vt,{active:C===e.code,onClick:()=>{w(e.code),q(!1)},children:e.nativeName},e.code)),(0,X.jsxs)(Vt,{onClick:()=>{q(!1),ve(!0)},children:[(0,X.jsx)(Ke,{}),` `,T(`localeGetMore`)]})]}),"host:theme":(0,X.jsx)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`theme`)})]}),tip:T(`theme`),open:J,caret:!1,onOpenChange:e=>{pe(e),e&&v.length===0&&x()},children:(()=>{let e=v.filter(e=>e.group===`classic`),t=v.filter(e=>e.group!==`classic`),n=e=>{let t=C===`zh`?e.name:e.nameEn??e.name,n=e.scheme===`light`?T(`themeLight`):e.scheme===`dark`?T(`themeDark`):``;return n?C===`zh`?`${t}(${n})`:`${t} (${n})`:t};return(0,X.jsxs)(X.Fragment,{children:[e.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`themeGroupClassics`)}),e.map(e=>(0,X.jsx)(Vt,{active:y===e.id,onClick:()=>{b(e.id),pe(!1)},children:n(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:e.length>0?T(`themeGroupBuiltin`):T(`theme`)}),(0,X.jsx)(Vt,{active:y===null,onClick:()=>{b(null),pe(!1)},children:T(`themeDefault`)}),t.map(e=>(0,X.jsx)(Vt,{active:y===e.id,onClick:()=>{b(e.id),pe(!1)},children:n(e)},e.id))]})})()}),"host:update":W?(0,X.jsxs)(`span`,{className:`chip`,"data-tip":T(`updatesManaged`),children:[(0,X.jsx)(Ke,{}),(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`v`,U??e.update?.current??`…`]})]}):(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ke,{}),(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`v`,e.update?.current??`…`]}),e.update&&!e.update.upToDate&&(0,X.jsx)(`span`,{className:`update-dot`,title:T(`updateAvailable`,{version:e.update.latest??``})}),je>0&&(0,X.jsx)(`span`,{className:`update-badge`,children:T(`updatesAllBadge`,{n:je})})]}),tip:T(`update`),open:me,caret:!1,onOpenChange:e=>{Y(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},fit:!0,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`update`)}),We(),He()]}),"host:github":(0,X.jsx)(`a`,{className:`chip github`,href:`https://github.com/xing-shuyin/pi-web-ui`,target:`_blank`,rel:`noreferrer noopener`,"data-tip":T(`githubRepo`),children:(0,X.jsx)(Fe,{})}),"host:conn":(0,X.jsxs)(`span`,{className:`chip`,"data-tip":e.status,children:[(0,X.jsx)(`span`,{className:`status-dot ${e.status===`open`?`ok`:`busy`}`}),(0,X.jsx)(`span`,{className:`chip-sub`,children:e.status})]}),"host:engine":(0,X.jsx)(`span`,{className:`chip`,"data-tip":`engine`,children:(0,X.jsx)(`span`,{className:`chip-sub`,children:e.engine??`pi`})}),"host:ctx":(0,X.jsx)(`span`,{className:`chip`,"data-tip":T(`contextUsage`),children:(0,X.jsx)(`span`,{className:`chip-sub`,children:(e.state?.stats?.contextUsage?.tokens??0)>0?`${e.state?.stats?.contextUsage?.tokens}`:T(`contextUsage`)})}),"host:cost":(0,X.jsx)(`span`,{className:`chip`,"data-tip":T(`cumulativeCost`),children:(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`$`,(e.state?.stats?.cost??0).toFixed(4)]})}),"host:cwd":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":e.state?.cwd??``,onClick:()=>A(!0),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:e.state?.cwd?.split(/[/\\]/).pop()||e.state?.cwd})]})},Ye=new Set([`host:search`,`host:tasks`,`host:settings`,`host:plugins`]),Xe=new Set([`host:sound`,`host:language`,`host:theme`,`host:update`,`host:browser`]),Ze=e=>Ye.has(e)&&!F(e.slice(5)),Qe=e=>{if(e.kind===`view`){if(!F(`plugins`))return null;let t=e.view??``,i=r.find(t=>`plugin:${t.id}`===e.source),a=i?.error?`${e.label}: ${i.error}`:e.hint??e.label;return(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===t,className:`tb-tab plugin-tab${n===t?` active`:``}${i?.error?` broken`:``}`,"data-tip":a,onClick:()=>c(t),onContextMenu:t=>H(t,e.id,e.label),children:[(0,X.jsx)(fi,{icon:e.icon,iconSvg:e.iconSvg}),(0,X.jsx)(`span`,{children:e.label})]},e.id)}return e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`plugin-topbar-item plugin-topbar-select`,title:e.hint??e.label,"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>s?.(e,t.target.value),onContextMenu:t=>H(t,e.id,e.label),children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.id):(0,X.jsxs)(`button`,{type:`button`,className:`plugin-topbar-item`,"data-tip":e.hint??e.label,onClick:()=>s?.(e),onContextMenu:t=>H(t,e.id,e.label),children:[(0,X.jsx)(fi,{icon:e.icon,iconSvg:e.iconSvg}),(0,X.jsx)(`span`,{children:e.label})]},e.id)},$e=[];for(let t of L){if(t.entry?.hidden||Ze(t.id))continue;let i=null;t.entry?i=(0,X.jsx)(ko,{entry:t.entry,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onOpenPanel:l,onOpenSettings:u,onOpenGlobalSearch:p,onOpenBgTasks:f,onOpenProjectPicker:()=>A(!0),isProjectPickerOpen:k,onOpenPluginMenu:e=>ee(t=>t?.el===e?null:{rect:e.getBoundingClientRect(),el:e}),isPluginMenuOpen:j!==null,onUiAction:s,uiContextEntries:o,dropdownProps:{sound:m,onSoundChange:h,onSoundPreview:_,theme:y,themes:v,onThemeChange:b,reloadThemes:x,onLocaleModalOpen:()=>ve(!0),renderUpdateBody:We,renderAllUpdatesBody:He,updatesCount:je,managed:W,appVersion:U}},t.id):t.id.startsWith(`host:`)&&Je[t.id]&&(i=Je[t.id]),i&&$e.push({id:t.id,entry:t.entry,node:i})}for(let t of R){let i=(0,X.jsx)(ko,{entry:t,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onUiAction:s,uiContextEntries:o},t.id);i&&$e.push({id:t.id,entry:t,node:i})}let et=e=>e.entry?.align??`start`,[tt,nt]=(0,g.useState)(()=>new Set),rt=(0,g.useRef)(null),it=(0,g.useRef)(new Map),at=$e.filter(e=>!tt.has(e.id)),ot=qe?at.filter(e=>ra.has(e.id)):[],st=qe?at.filter(e=>!ra.has(e.id)):at,ct=qe?$e.filter(e=>!ra.has(e.id)):$e,lt=[...ct.filter(e=>et(e)===`start`),...ct.filter(e=>et(e)===`center`),...ct.filter(e=>et(e)===`end`)],ut=lt.filter(e=>!tt.has(e.id)),dt=(0,g.useRef)(lt),ft=(0,g.useRef)(ut);(0,g.useLayoutEffect)(()=>{dt.current=lt,ft.current=ut});let pt=()=>{let e=rt.current;if(!e||typeof ResizeObserver>`u`)return;let t=Array.from(e.children).filter(e=>!e.classList.contains(`tb-spacer`)),n=ft.current;t.length===n.length&&n.forEach((e,n)=>it.current.set(e.id,t[n].offsetWidth));let r=Number.parseFloat(getComputedStyle(e).columnGap)||0,i=dt.current,a=aa(i.map(e=>({id:e.id,width:e.entry?it.current.get(e.id)??0:0})),e.clientWidth,r,0,Ai);nt(e=>e.size===a.size&&[...a].every(t=>e.has(t))?e:a)},ht=`${at.map(e=>`${e.id}:${e.entry?.label??``}`).join(`|`)}|${n}|${(e.tabs??[]).join(`,`)}|${qe?`m`:`d`}`;(0,g.useLayoutEffect)(pt,[ht]),(0,g.useEffect)(()=>{let e=rt.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>pt());return t.observe(e),()=>t.disconnect()},[ht]);let gt=st.filter(e=>et(e)===`start`),_t=st.filter(e=>et(e)===`center`),vt=st.filter(e=>et(e)===`end`),yt=$e.filter(e=>tt.has(e.id)&&e.entry).map(e=>e.entry),bt=new Map;[...i??[],...a??[]].forEach((e,t)=>{bt.has(e.id)||bt.set(e.id,t)});let xt=ia([...re,...yt],e=>bt.get(e)??999999),St=e=>e.icon&&!/[a-z]/i.test(e.icon)?e.icon:null,Ct=e.settings?.uiLayout?.topbarText===!1;return(0,X.jsxs)(`header`,{className:`topbar${Ct?` no-labels`:``}`,"data-pi-anchor":`topbar`,children:[(0,X.jsxs)(`div`,{className:`topbar-flow`,ref:rt,role:`toolbar`,"aria-label":T(`viewSwitch`),children:[gt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),(_t.length>0||vt.length>0)&&(0,X.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),_t.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),_t.length>0&&(0,X.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),vt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id))]}),(xt.length>0||$e.length>0)&&(0,X.jsxs)(`div`,{className:`plugin-topbar-more`,children:[(0,X.jsx)(`button`,{ref:N,type:`button`,className:`plugin-topbar-item`,"aria-haspopup":`menu`,"aria-expanded":D,"aria-label":T(`pluginTopbarMore`),"data-tip":T(`pluginTopbarMore`),onClick:()=>O(e=>!e),children:(0,X.jsx)(Et,{})}),(0,X.jsxs)(jo,{anchorRef:N,open:D,onClose:()=>O(!1),children:[xt.map(e=>{let t=e.source===`host`&&Xe.has(e.id)?Je[e.id]:void 0;if(t!==void 0)return(0,X.jsx)(g.Fragment,{children:t},e.id);if(e.source===`host`&&e.id===`host:github`)return(0,X.jsxs)(`a`,{role:`menuitem`,className:`chip github`,href:`https://github.com/xing-shuyin/pi-web-ui`,target:`_blank`,rel:`noreferrer noopener`,title:T(`githubRepo`),onClick:()=>O(!1),children:[(0,X.jsx)(Fe,{}),(0,X.jsx)(`span`,{children:`GitHub`})]},e.id);if(e.source===`host`){let t=Je[e.id];if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>O(!1),children:t},e.id)}else{let t=Qe(e);if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>O(!1),children:t},e.id)}return e.kind===`select`&&e.options?.length?(0,X.jsxs)(`label`,{className:`plugin-topbar-overflow-select tb-row`,title:e.hint??e.label,children:[St(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:St(e)}):null,(0,X.jsx)(`span`,{className:`tb-row-text`,children:e.label}),(0,X.jsx)(`select`,{"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>{O(!1),B(e)||s?.(e,t.target.value)},children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.id):(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`tb-row`,title:e.hint??e.label,onClick:()=>{O(!1),B(e)||s?.(e)},children:[St(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:St(e)}):null,(0,X.jsx)(`span`,{className:`tb-row-text`,children:e.label})]},e.id)}),(0,X.jsx)(`div`,{className:`tb-menu-divider`,"aria-hidden":`true`}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`tb-row`,onClick:()=>{O(!1),S()},children:[(0,X.jsx)(Ge,{}),(0,X.jsx)(`span`,{className:`tb-row-text`,children:T(`uiIconEdit`)})]})]})]}),ot.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),_e&&(0,X.jsx)(uo,{onClose:()=>ve(!1)}),j&&(0,X.jsx)(lo,{anchorRect:j.rect,anchorEl:j.el,plugins:r,pinnedIds:ie,orderedPluginIds:ae,onTogglePin:(t,n)=>$({type:`set_settings`,uiLayout:Pi(e.settings?.uiLayout,t,n)}),onReorder:t=>$({type:`set_settings`,uiLayout:Fi(e.settings?.uiLayout,t)}),onOpenView:e=>{ee(null),c(`plugin:${e}`)},onManagePlugins:d,onClose:()=>ee(null)}),k&&(0,X.jsx)(io,{open:!0,currentCwd:M,pathCompletions:e.pathCompletions??[],workspaceRoots:te,onClose:()=>A(!1),onSelectDirectory:e=>$({type:`set_cwd`,path:e}),onCreateProject:e=>$({type:`make_dir`,path:e,setAsCwd:!0})})]})}function Po(e,t){let n={...t};if(!e)return n;try{let r=JSON.parse(e);if(r&&typeof r==`object`&&!Array.isArray(r))for(let e of Object.keys(t)){let t=r[e];typeof t==`number`&&Number.isFinite(t)&&t>0&&(n[e]=t)}}catch{}return n}function Fo(e){let t=e.start.above+e.start.below,n=Math.max(1,e.availablePx)/(e.totalWeight>0?e.totalWeight:1),r=e.minAbovePx/n,i=e.minBelowPx/n;if(r+i>=t){let n=e.minAbovePx+e.minBelowPx||1,r=t*e.minAbovePx/n;return{above:r,below:t-r}}let a=Math.min(t-i,Math.max(r,e.start.above+e.deltaPx/n));return{above:a,below:t-a}}function Io(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=e=>e.parentId?r.get(e.parentId)?.cwd??e.cwd:e.cwd,a=e.find(e=>e.id===n),o=a?i(a):t,s=new Map;for(let t of e){let e=i(t),n=s.get(e)??[];n.push(t),s.set(e,n)}let c=[...s.entries()].map(([e,t])=>({cwd:e,isCurrent:e===o,convs:t}));return c.sort((e,t)=>e.isCurrent?-1:t.isCurrent?1:e.cwd<t.cwd?-1:+(e.cwd>t.cwd)),c}function Lo(e,t=new Set){let n=new Map(e.map(e=>[e.id,e])),r=new Map,i=[];for(let t of e)if(t.parentId&&n.has(t.parentId)){let e=r.get(t.parentId)??[];e.push(t),r.set(t.parentId,e)}else i.push(t);let a=e=>{let t=[],n=[...r.get(e)??[]],i=new Set;for(;n.length>0;){let e=n.shift();if(i.has(e.id))continue;i.add(e.id),t.push(e);let a=r.get(e.id);a&&n.push(...a)}return t},o=[],s=new Set,c=new Set,l=(e,n)=>{if(s.has(e.id)||c.has(e.id))return;s.add(e.id);let i=r.get(e.id)??[],u=i.length>0,d=u&&t.has(e.id),f=0,p=!1,m=!1,h=!1;if(u){let t=a(e.id);if(f=t.length,p=t.some(e=>e.isStreaming),m=t.some(e=>!!e.error),h=t.some(e=>!!e.hasQuestion),d)for(let e of t)c.add(e.id)}if(o.push({c:e,depth:n,hasKids:u,isCollapsed:d,descendantCount:f,hasStreaming:p,hasError:m,hasQuestion:h}),!d)for(let e of i)l(e,n+1)};for(let e of i)l(e,0);for(let t of e)l(t,0);return o}function Ro(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;if(!t.trim())return null;let n=new URLSearchParams(t),r=n.get(`s`)?.trim()??``;if(!r)return null;let i=n.get(`m`)?.trim()||void 0;return i?{sessionId:r,messageId:i}:{sessionId:r}}function zo(e){let t=e?.sessionId?.trim()??``;if(!t)return``;let n=e?.messageId?.trim()??``,r=`#s=${encodeURIComponent(t)}`;return n?`${r}&m=${encodeURIComponent(n)}`:r}function Bo(e,t){let n=zo(t);try{let t=new URL(e);return t.searchParams.delete(`token`),t.hash=n,t.toString()}catch{return`${e.split(`#`)[0]??e}${n}`}}function Vo(e){if(!e)return null;let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);if(!t)return null;let n=t.split(`/`),r=n[n.length-1]??``;if(!r)return null;if(r===`session.jsonl`)return(n[n.length-2]?.trim()??``)||null;let i=r.endsWith(`.jsonl`)?r.slice(0,-6):r;if(!i)return null;let a=i.lastIndexOf(`_`);return(a>=0?i.slice(a+1).trim():i.trim())||null}function Ho(e,t){let n=t?.trim()??``;if(!n||e.length===0)return null;let r=e.find(e=>e.id===n);if(r)return r.id;let i=/^([a-z]+-\d+)-\d+$/.exec(n);if(i){let t=`${i[1]}-`,n=e.find(e=>e.id.startsWith(t));if(n)return n.id}return null}function Uo(e,t){let n=t.assistantMessageEvent,r=e.stats.tokens,i=t.usage===null?r:{...r,...t.usage},a=i===r?e.stats:{...e.stats,tokens:i};if(n.type!==`text_delta`&&n.type!==`thinking_delta`)return a===e.stats?e:{...e,stats:a};let o=n.delta??``;if(!o)return a===e.stats?e:{...e,stats:a};let s=e.streamingMessage??null,c=s&&s.id===t.messageId?s:{id:t.messageId,content:[]},l=[...c.content],u=n.type===`thinking_delta`?`thinking`:`text`,d=n.contentIndex??l.length-1;return d>=0&&d<l.length&&l[d].type===u?l[d]=u===`thinking`?{type:`thinking`,thinking:(l[d].thinking??``)+o}:{type:`text`,text:(l[d].text??``)+o}:l.push(u===`thinking`?{type:`thinking`,thinking:o}:{type:`text`,text:o}),{...e,stats:a,streamingMessage:{...c,id:t.messageId,content:l}}}function Wo(e){let{current:t,source:n,snapshot:r,answered:i,activeConversationId:a}=e;return r&&r.id&&!i.has(r.id)?t?.id===r.id?{changed:!1,question:t,source:n}:{changed:!0,question:r,source:`snapshot`}:t&&t.conversationId&&a&&t.conversationId!==a||!r&&t&&n===`snapshot`?{changed:!0,question:null,source:`live`}:{changed:!1,question:t,source:n}}var Go=new Set;function Ko(e){return Go.add(e),()=>{Go.delete(e)}}function qo(e,t){for(let n of Go)try{n(e,t)}catch(e){console.error(`[tui-overlay-bridge] listener error:`,e)}}function Jo(e){let t=typeof e.name==`string`?e.name:``;if(e.unsupported===!0)return{name:t,status:`unsupported`};if(e.found!==!0)return{name:t,status:`missing`};let n={name:t,status:`ready`};return e.label&&(n.label=e.label),e.description&&(n.description=e.description),e.promptSnippet&&(n.promptSnippet=e.promptSnippet),Array.isArray(e.promptGuidelines)&&e.promptGuidelines.length>0&&(n.promptGuidelines=e.promptGuidelines),e.parameters!==void 0&&(n.parameters=e.parameters),e.parametersDropped===!0&&(n.parametersDropped=!0),(e.active===!0||e.active===!1)&&(n.active=e.active),e.source&&(n.source=e.source),e.scope&&(n.scope=e.scope),n}var Yo=null,Xo=new Set;function Zo(){for(let e of Xo)e()}function Qo(e){let t=(e??``).trim();t&&(Yo={name:t,status:`loading`},Zo(),$({type:`get_tool_info`,name:t}))}function $o(){Yo!==null&&(Yo=null,Zo())}function es(e){Yo!==null&&Yo.name===e.name&&(Yo=Jo(e),Zo())}function ts(e){return Xo.add(e),()=>{Xo.delete(e)}}function ns(){return Yo}function rs(){return(0,g.useSyncExternalStore)(ts,ns,ns)}function is(e){let t=typeof e.name==`string`?e.name:``;if(e.unsupported===!0)return{name:t,status:`unsupported`};if(e.found!==!0)return{name:t,status:`missing`};let n={name:t,status:`ready`};return e.defaultDescription&&(n.defaultDescription=e.defaultDescription),e.defaultPromptSnippet&&(n.defaultPromptSnippet=e.defaultPromptSnippet),Array.isArray(e.defaultPromptGuidelines)&&e.defaultPromptGuidelines.length>0&&(n.defaultPromptGuidelines=e.defaultPromptGuidelines),e.override&&(n.override=e.override),n}var as={},os=new Set;function ss(){for(let e of os)e()}function cs(e){let t=(e??``).trim();t&&(as[t]&&as[t].status!==`loading`||(as={...as,[t]:{name:t,status:`loading`}},ss(),$({type:`get_tool_prompt`,name:t})))}function ls(e){let t=typeof e.name==`string`?e.name:``;t&&as[t]&&(as={...as,[t]:is(e)},ss())}function us(e){if(!as[e])return;let t={...as};delete t[e],as=t,ss()}function ds(e){return os.add(e),()=>os.delete(e)}function fs(e){return(0,g.useSyncExternalStore)(ds,()=>e?as[e]??null:null)}var ps=Object.freeze({status:`idle`,messages:[]}),ms=new Map,hs=new Set,gs=16;function _s(){for(;ms.size>gs;){let e=ms.keys().next().value;if(e===void 0)break;ms.delete(e)}}function vs(){for(let e of hs)e()}function ys(e,t){let n=(e??``).trim();if(!n)return;let r=ms.get(n);(!r||r.status!==`loading`&&r.status!==`ready`)&&(ms.set(n,{status:`loading`,messages:r?.messages??[]}),_s(),vs(),$({type:`get_compacted_messages`,compactionMessageId:n,conversationId:t}))}function bs(e){let t=e.compactionMessageId;t&&(e.error?ms.set(t,{status:`error`,messages:[],error:e.error}):ms.set(t,{status:`ready`,messages:e.messages??[]}),_s(),vs())}function xs(e){let t=ms.get(e);return t?(ms.delete(e),ms.set(e,t),t):ps}function Ss(e){return hs.add(e),()=>{hs.delete(e)}}function Cs(e){return(0,g.useSyncExternalStore)(Ss,()=>xs(e),()=>ps)}var ws=`__piWebUiHost`,Ts=e=>new Promise(t=>setTimeout(t,e));async function Es(e=3e3){let t=Date.now()+e;for(;;){let e=window.__piBridge;if(e&&typeof e.call==`function`)return e;if(Date.now()>=t)return null;await Ts(100)}}var Ds=Promise.resolve(),Os=0;function ks(e){let t=Math.max(1,Number(e.pollMs??100)),n=Math.max(t,Number(e.timeoutMs??8e3)),r=async e=>{let r=Date.now()+n;for(;;){if(e())return!0;if(Date.now()>=r)return e();await Ts(t)}},i=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},a=e=>{if(!e)return!0;try{return i().some(t=>t&&t.id===e)}catch{return!1}},o=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await r(()=>e.getCurrentModelId?.()===t))},s=async(t,n)=>{let i=String(n.cwd??``).trim();if(i&&e.getCwd()!==i&&(e.send({type:`set_cwd`,path:i}),await r(()=>e.getCwd()===i)),n.newChat!==!1){let t=e.getConversationId();e.send({type:`new_chat`}),await r(()=>e.getConversationId()!==t||e.isConversationBlank())}let a=String(n.model??``).trim();a&&await o(a),e.send({type:`prompt`,text:t})};return{version:11,setView(t){let n=String(t??``).trim();n&&e.setView(n)},startChat(t){let n=String(t?.prompt??``).trim();if(!n||!e.isReady())return!1;let r=String(t?.model??``).trim();if(r&&!a(r))return!1;let i=()=>s(n,t??{prompt:n}),o;return o=Os>0?Ds.then(i):i(),Os++,Ds=o.then(()=>{Os--},()=>{Os--}),o.catch(()=>{}),!0},models:{list:()=>i(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>ac(e)},compose(e){return sr()?cr({text:typeof e?.text==`string`?e.text:void 0,attachments:Array.isArray(e?.attachments)?e.attachments:void 0}):!1},openModal(t){let n=String(t??``).trim();if(!n||typeof e.openModal!=`function`)return!1;try{return e.openModal(n)}catch{return!1}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let n=Ps,i=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],s=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],c=String(t?.cwd??``).trim(),l=[...new Set([...i,...s])],u=c||l[0]||``;if(!u)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let d=l.filter(e=>e!==u).slice(0,7),f=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]);for(let t of[u,...d])if(!f.has(t)){if(!(e.confirm&&await e.confirm({path:t}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${t}`};e.grantPath?.(t,n)}if(e.getCwd()!==u&&(e.send({type:`set_cwd`,path:u}),!await r(()=>e.getCwd()===u)))return{ok:!1,error:`切换工作目录失败或超时:${u}`};(d.length>0||e.getWorkspaceRoots().length>0)&&e.send({type:`set_workspace_roots`,roots:d});let p=e.getConversationId()??void 0;if(t?.newChat!==!1){let t=p;e.send({type:`new_chat`}),await r(()=>e.getConversationId()!==t||e.isConversationBlank()),p=e.getConversationId()??void 0}let m=String(t?.model??``).trim();if(m){if(!a(m))return{ok:!1,error:`未知模型:${m}(先调 models.list() 取可用列表)`};await o(m),p=e.getConversationId()??p}let h=String(t?.prompt??``).trim();return h&&e.send({type:`prompt`,text:h}),{ok:!0,...p?{sessionId:p}:{}}},sessions:{list:()=>e.listSessions(),async open(t){let n=Ps,i=String(t??``).trim();if(!i)return{ok:!1,error:`sessions.open 需要一个会话 id(先调 list)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=e.listSessions().find(e=>e.id===i);if(!a)return{ok:!1,error:`找不到会话:${i}`};if(a.cwd&&a.cwd!==e.getCwd()){if(!new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]).has(a.cwd)){if(!(e.confirm&&await e.confirm({path:a.cwd}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${a.cwd}`};e.grantPath?.(a.cwd,n)}if(e.send({type:`set_cwd`,path:a.cwd}),!await r(()=>e.getCwd()===a.cwd))return{ok:!1,error:`切换工作目录失败或超时:${a.cwd}`}}let o=e.getConversationId();return a.kind===`running`?e.send({type:`switch_conversation`,id:a.id}):e.send({type:`switch_session`,path:a.id}),await r(()=>e.getConversationId()!==o)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${a.title}`}}},async reloadCatalog(t,n){let r=String(t??``).trim();if(!r)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let i=At();return new Promise(t=>{let a=setTimeout(()=>{pc.delete(i),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));pc.set(i,e=>{clearTimeout(a),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:i,source:r,...n?.install?{install:!0}:{},...n?.replace?{replace:!0}:{}})})},onUiAction(e,t){return Is(Ms,String(e??``).trim(),t)},onTopbarAction(e,t){return Is(Ms,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(Ln())return{ok:!1,error:`桌面版(Electron 外壳)不支持 browser_page:窗口里没有 Chrome 扩展运行时。请让用户改用系统浏览器打开同一个 pi-web-ui 地址(网页版)再试。/ The desktop app cannot run browser_page (no Chrome extension runtime); ask the user to open the same pi-web-ui address in a regular browser instead.`};let r=await Es(e.bridgeWaitMs??3e3);if(!r)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await r.call({op:n,...t.args===void 0?{}:{args:t.args},...t.target?{to:t.target}:{},...t.timeoutMs?{timeoutMs:t.timeoutMs}:{}});return e===void 0?{ok:!0}:{ok:!0,result:e}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},dom:{anchors(){let e=e=>{try{return document.querySelector(`[data-pi-anchor="${e}"]`)}catch{return null}};return{app:e(`app`),topbar:e(`topbar`),composer:e(`composer`)}}},dialogs:{async select(t){try{let n=e.select;if(typeof n!=`function`)return{ok:!1};let r=Array.isArray(t?.options)?t.options:[],i=await n({title:String(t?.title??``),options:r.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`).map(e=>({label:String(e.label),...typeof e.description==`string`?{description:e.description}:{}})),...t?.multi?{multi:!0}:{}});return!i||typeof i!=`object`||i.ok!==!0?{ok:!1,...i&&typeof i==`object`&&typeof i.error==`string`?{error:i.error}:{}}:{ok:!0,selected:Array.isArray(i.selected)?i.selected.filter(e=>typeof e==`string`):[]}}catch{return{ok:!1}}},async confirm(t){let n=String(t?.title??``),r=typeof t?.detail==`string`?t.detail:``;try{if(typeof e.dialogConfirm==`function`)try{return await e.dialogConfirm({title:n,...r?{detail:r}:{}})===!0}catch{}if(typeof window<`u`&&typeof window.confirm==`function`)try{return window.confirm(r?`${n}\n\n${r}`:n)}catch{return!1}return!1}catch{return!1}},async input(t){try{let n=e.input;if(typeof n!=`function`)return{ok:!1};let r=await n({title:String(t?.title??``),...typeof t?.placeholder==`string`?{placeholder:t.placeholder}:{},...typeof t?.initial==`string`?{initial:t.initial}:{}});return!r||typeof r!=`object`||r.ok!==!0?{ok:!1}:typeof r.value==`string`?{ok:!0,value:r.value}:{ok:!0}}catch{return{ok:!1}}}},async notifyAction(t){let n=String(t?.text??``),r=(Array.isArray(t?.actions)?t.actions:[]).filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.label==`string`);try{if(typeof e.notifyAction==`function`){let t=await e.notifyAction({text:n,actions:r});return typeof t==`string`?t:null}}catch{return null}try{typeof window<`u`&&typeof window.dispatchEvent==`function`&&window.dispatchEvent(new CustomEvent(Rs,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ks(String(e??``),t)},searchProviders:{register:e=>Js(e),list:()=>Ys()},composerProviders:{register:e=>Zs(e),list:()=>Qs()},onTheme:e=>sc(e),onLocale:e=>cc(e),onViewChange:e=>lc(e)}}function As(e){try{let t=window;e?t[ws]=e:delete t[ws]}catch{}}var js=new Map,Ms=null;async function Ns(e,t){let n=Ms;Ms=e;try{return await t()}finally{Ms=n}}var Ps=void 0;function Fs(e,t){let n=Ps;Ps=e;try{return t()}finally{Ps=n}}function Is(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=js.get(r);i||(i=new Set,js.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&js.delete(r)}}async function Ls(e,t,n,r){let i=i=>{let a=js.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{Fs(e,()=>i(n,r?.value,r?.target))}catch(n){console.error(`[plugin:${e}] 顶栏动作 ${t} 抛错:`,n)}return!0};if(i(`${e}:${t}`)||i(t))return!0;if(r?.loadBundle&&await r.loadBundle(e).catch(()=>!1)){let n=Date.now()+Math.max(100,Number(r.waitMs??1500));for(;;){if(i(`${e}:${t}`)||i(t))return!0;if(Date.now()>=n)break;await new Promise(e=>setTimeout(e,100))}}return!1}var Rs=`pi-web-ui:toast`,zs=new Map,Bs=!1;function Vs(e){let t=e.split(`+`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(t.length===0)return null;let n=!1,r=!1,i=!1,a=!1;for(let e of t.slice(0,-1))if(e===`ctrl`||e===`control`)n=!0;else if(e===`shift`)r=!0;else if(e===`alt`||e===`option`)i=!0;else if(e===`meta`||e===`cmd`||e===`command`||e===`win`||e===`super`)a=!0;else return null;let o=t[t.length-1]??``;return!o||[`ctrl`,`control`,`shift`,`alt`,`option`,`meta`,`cmd`,`command`,`win`,`super`].includes(o)?null:{combo:`${n?`ctrl+`:``}${r?`shift+`:``}${i?`alt+`:``}${a?`meta+`:``}${o}`,key:o,ctrl:n,shift:r,alt:i,meta:a}}function Hs(){try{if(typeof document>`u`)return!1;let e=document.activeElement;if(!e)return!1;let t=(e.tagName||``).toUpperCase();return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}catch{return!1}}function Us(e){try{if(Hs())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=zs.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function Ws(){if(!Bs)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,Us),Bs=!0}catch{}}function Gs(){if(!(zs.size>0||!Bs))try{window.removeEventListener(`keydown`,Us)}catch{}finally{Bs=!1}}function Ks(e,t){if(typeof t!=`function`)return()=>{};let n=Vs(e);if(!n)return()=>{};let r=zs.get(n.combo);r||(r=new Set,zs.set(n.combo,r));let i=r;return i.add(t),Ws(),()=>{i.delete(t),i.size===0&&zs.delete(n.combo),Gs()}}var qs=new Map;function Js(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return qs.set(t,n),()=>{qs.get(t)===n&&qs.delete(t)}}function Ys(){return[...qs.values()].map(e=>({id:e.id,label:e.label}))}var Xs=new Map;function Zs(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return Xs.set(t,n),()=>{Xs.get(t)===n&&Xs.delete(t)}}function Qs(){return[...Xs.values()].map(e=>({id:e.id,label:e.label}))}function $s(e){return Xs.get(String(e??``))}function ec(e){return qs.get(String(e??``))}var tc=new Set,nc=new Set,rc=new Set,ic=new Set;function ac(e){return ic.add(e),()=>{ic.delete(e)}}function oc(e){for(let t of ic)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function sc(e){return typeof e==`function`?(tc.add(e),()=>{tc.delete(e)}):()=>{}}function cc(e){return typeof e==`function`?(nc.add(e),()=>{nc.delete(e)}):()=>{}}function lc(e){return typeof e==`function`?(rc.add(e),()=>{rc.delete(e)}):()=>{}}function uc(e){let t=String(e??``);for(let e of tc)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function dc(e){let t=String(e??``);for(let e of nc)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function fc(e){let t=String(e??``);for(let e of rc)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var pc=new Map;function mc(e){let t=pc.get(e.requestId);if(t){if(pc.delete(e.requestId),!e.ok){t({ok:!1,error:e.error??`目录同步失败`});return}t({ok:!0,...e.entries?{entries:e.entries}:{},...e.installed?{installed:e.installed}:{}})}}var hc=`modulepreload`,gc=function(e){return`/`+e},_c={},vc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=gc(t,n),t=s(t),t in _c)return;_c[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:hc,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},yc=`pi-web-ui:plugin-data`;function bc(e,t){window.dispatchEvent(new CustomEvent(yc,{detail:{pluginId:e,payload:t}}))}function xc(e){let t=t=>{let n=t.detail;e(n.pluginId,n.payload)};return window.addEventListener(yc,t),()=>window.removeEventListener(yc,t)}var Sc=new Map,Cc=new Set,wc=new Set,Tc=new Set,Ec=new Set,Dc=-1;function Oc(){return[...Sc.values()]}function kc(){let e=Oc();for(let t of wc)t(e)}function Ac(){let e=[...Tc];for(let t of Ec)t(e)}function jc(e){return Ec.add(e),e([...Tc]),()=>Ec.delete(e)}async function Mc(e,t){Tc.delete(e.id),Pc.set(e.id,(Pc.get(e.id)??0)+1),Ac();let n=await zc(e,t);return kc(),n}function Nc(e){return wc.add(e),e(Oc()),()=>wc.delete(e)}var Pc=new Map;function Fc(e,t){let n=Pc.get(e)??0;return dn(`/plugins/${encodeURIComponent(e)}/client/entry.mjs?e=${t}${n>0?`&r=${n}`:``}`)}function Ic(e){let t=Promise.resolve();return(n,r)=>{let i=t.then(()=>Ns(n,()=>e(r)));return t=i.then(()=>void 0,()=>void 0),i}}var Lc=Ic(e=>vc(()=>import(e),[]));async function Rc(e,t){if(!e.hasClient||e.error)return null;try{return(await Lc(e.id,Fc(e.id,t))).default??null}catch(t){return console.error(`[plugin:${e.id}] 客户端 bundle 加载失败:`,t),null}}async function zc(e,t){try{let n=(await Lc(e.id,Fc(e.id,t))).default;return n&&typeof n.mount==`function`?(Sc.set(e.id,{info:e,module:n}),!0):e.preload?(Cc.add(e.id),!0):(Tc.add(e.id),Ac(),console.error(`[plugin:${e.id}] entry.mjs 缺少 default.mount`),!1)}catch(t){return Tc.add(e.id),Ac(),console.error(`[plugin:${e.id}] 客户端加载失败:`,t),!1}}async function Bc(e,t){if(Sc.has(e.id)||Cc.has(e.id))return!0;if(Tc.has(e.id)||!e.hasClient)return!1;let n=await zc(e,t);return kc(),n}async function Vc(e,t){t!==Dc&&(Dc=t,Sc.clear(),Cc.clear(),Tc.clear(),Pc.clear(),Ac());let n=new Set(e.map(e=>e.id));for(let e of[...Sc.keys()])n.has(e)||Sc.delete(e);for(let e of[...Cc])n.has(e)||Cc.delete(e);for(let e of[...Tc])n.has(e)||Tc.delete(e);Ac(),await Promise.all(e.filter(e=>e.hasClient&&(e.view!==!1||e.preload)&&!e.error&&!Sc.has(e.id)&&!Cc.has(e.id)&&!Tc.has(e.id)).map(e=>zc(e,t))),kc()}function Hc(e,t){return{pluginId:e,send:n=>t({type:`plugin_message`,pluginId:e,payload:n}),onData:t=>xc((n,r)=>{n===e&&t(r)})}}var Uc=[`debug`,`info`,`warn`,`error`];function Wc(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`get`}}}function Gc(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`clear`}}}function Kc(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.__host!==`logs`||!Array.isArray(t.logs)?!1:t.logs.every(e=>!!e&&typeof e==`object`&&typeof e.ts==`number`&&typeof e.text==`string`&&Uc.includes(String(e.level)))}var qc=new Map,Jc=new Set;function Yc(){for(let e of[...Jc])try{e()}catch{}}function Xc(e){return Jc.add(e),()=>Jc.delete(e)}function Zc(e){return(qc.get(e)??[]).map(e=>({...e}))}function Qc(e,t){return Kc(t)?(qc.set(e,t.logs.map(e=>({ts:e.ts,level:e.level,text:e.text}))),Yc(),!0):!1}function $c(){return{flows:[],results:{}}}function el(e,t){let n=e.findIndex(e=>e.flowId===t.flowId);return n<0?[...e,t]:e.map((e,r)=>r===n?t:e)}function tl(e,t){switch(t.type){case`provider_oauth_started`:{let n={...e.results};return delete n[t.provider],{flows:[...e.flows.filter(e=>e.provider!==t.provider),{flowId:t.flowId,provider:t.provider}],results:n}}case`provider_oauth_flows`:return{...e,flows:t.flows.map(e=>({...e}))};case`provider_oauth_prompt`:{let n=e.flows.find(e=>e.flowId===t.flowId);return{...e,flows:el(e.flows,{...n,flowId:t.flowId,provider:t.provider,promptId:t.promptId,prompt:t.prompt})}}case`provider_oauth_event`:{let n=e.flows.find(e=>e.flowId===t.flowId);return{...e,flows:el(e.flows,{...n,flowId:t.flowId,provider:t.provider,event:t.event,promptId:void 0,prompt:void 0})}}case`provider_oauth_result`:return{flows:e.flows.filter(e=>e.flowId!==t.flowId),results:{...e.results,[t.provider]:{ok:t.ok,...t.cancelled===void 0?{}:{cancelled:t.cancelled},...t.error===void 0?{}:{error:t.error}}}};case`provider_oauth_logout_result`:return{...e,results:{...e.results,[t.provider]:{ok:t.ok,...t.error===void 0?{}:{error:t.error}}}}}}var nl=`pi-web-ui:lang`;function rl(){try{return(localStorage.getItem(nl)??``).trim()}catch{return``}}var il=`pi-web-ui:locale`,al=2e5,ol=2e5,sl=`LIVE_OMIT`,cl={conversationId:null,goal:null,reviewModel:null,maxRounds:3,locked:!0,reviewing:!1,round:0,status:``,verdict:`pending`,wizard:{active:!1,draft:``,model:null,step:0,maxSteps:6,status:``}};function ll(){let e=new Map,t=new Map,n=(e,t)=>`${e}:${t}`;return{write(r,i,a){let o=n(r,i),s=e.get(o);if(s&&s.size>0){for(let e of s)try{e.write(a)}catch{}return}let c=t.get(o)??``,l=c.length+a.length>ol?a:c+a;t.set(o,l)},register(r,i,a){let o=n(r,i),s=e.get(o);s||(s=new Set,e.set(o,s)),s.add(a);let c=t.get(o);if(c){try{a.write(c)}catch{}t.delete(o)}return()=>{let n=e.get(o);n&&(n.delete(a),n.size===0&&e.delete(o)),t.delete(o)}},clear(){e.clear(),t.clear()}}}function ul(e,t){let n=new Set;for(let e of t.messages)e.role===`toolResult`&&e.toolCallId&&n.add(e.toolCallId),e.role===`bashExecution`&&n.add(`bash-${e.id}`);let r=!1;for(let t of e.keys())n.has(t)&&(e.delete(t),r=!0);return r?new Map(e):e}function dl(e,t){if(e.size===0)return e;let n=new Set;for(let e of t.messages)e.role===`toolResult`&&e.toolCallId&&n.add(e.toolCallId);let r=!1;for(let t of e.keys())n.has(t)&&(e.delete(t),r=!0);return r?new Map(e):e}function fl(e,t){switch(t.type){case`status`:return{...e,status:t.status,ready:t.status===`open`&&e.ready,terminals:t.status===`closed`?[]:e.terminals,hostMetrics:t.status===`closed`?null:e.hostMetrics};case`sync_cached_sessions`:return{...e,sessions:t.sessions};case`host_metrics`:return{...e,hostMetrics:t.metrics};case`ready`:return{...e,serverVersion:t.serverVersion,engine:t.engine,appVersion:t.appVersion,managed:t.managed===!0,tabs:t.tabs,ready:!0,protocolMismatch:t.protocolVersion!==void 0&&t.protocolVersion!==29};case`snapshot`:{let n=e.state?.cwd,r=t.state.cwd,i=e.sessions;return r&&r!==n&&(i=El(r)),{...e,ready:!0,state:t.state,sessions:i,approval:t.state.pendingApproval??null,activeConversationId:t.state.conversationId,liveOutputs:ul(e.liveOutputs,t.state),toolStatuses:dl(e.toolStatuses,t.state)}}case`snapshot_delta`:{let n=e.state,r=t.msg;if(!n||n.conversationId!==r.conversationId||n.rev!==r.baseRev)return e;let i={...n,...r.state,messages:r.appended.length>0?[...n.messages,...r.appended]:n.messages};return{...e,ready:!0,state:i,approval:i.pendingApproval===void 0?e.approval:i.pendingApproval??null,activeConversationId:i.conversationId,liveOutputs:ul(e.liveOutputs,i),toolStatuses:dl(e.toolStatuses,i)}}case`tool_approval`:return{...e,approval:t.approval};case`tool_delta`:{let n=(e.liveOutputs.get(t.toolCallId)?.text??``)+t.delta,r=n.length>al?`…[${sl}:${n.length-al}]…\n`+n.slice(n.length-al):n,i=new Map(e.liveOutputs);return i.set(t.toolCallId,{toolName:t.toolName,text:r}),{...e,liveOutputs:i}}case`message_delta`:{let n=e.state;return!n||n.conversationId!==t.msg.conversationId?e:{...e,state:Uo(n,t.msg)}}case`tool_status`:return{...e,toolStatuses:new Map(e.toolStatuses).set(t.status.toolCallId,t.status)};case`notice`:return{...e,notices:[...e.notices,t.notice].slice(-6)};case`dismiss_notice`:return{...e,notices:e.notices.filter(e=>e.id!==t.id)};case`sessions`:return Dl(e.state?.cwd,t.sessions),{...e,sessions:t.sessions};case`conversations`:return{...e,conversations:t.conversations,elsewhere:t.elsewhere??[],activeConversationId:t.activeId};case`projects`:return Sl(t.projects),{...e,projects:t.projects};case`files`:return{...e,files:t.files};case`file_changed`:return{...e,fileChanged:{path:t.path}};case`file_content`:return{...e,fileContent:t.content};case`models`:return{...e,models:t.models,modelsLoading:t.loading};case`models_config`:return{...e,modelsConfig:t.providers};case`providers_status`:return{...e,providers:t.providers};case`provider_keys`:return{...e,providerKeys:t.keys};case`default_model`:return{...e,defaultModel:t.modelId};case`provider_oauth`:{let n=tl({flows:e.providerOAuthFlows,results:e.providerOAuthResults},t.message);return{...e,providerOAuthFlows:n.flows,providerOAuthResults:n.results}}case`fetch_models_result`:return{...e,fetchModelsResult:t.result};case`test_model_connection_result`:return{...e,testModelConnectionResult:t.result};case`enrich_models_progress`:return{...e,enrichModelsProgress:t.progress};case`enrich_models_result`:return{...e,enrichModelsResult:t.result,enrichModelsProgress:null};case`refresh_provider_result`:return{...e,refreshProviderResult:t.result};case`refresh_builtin_result`:return{...e,refreshBuiltinResult:t.result};case`append_builtin_result`:return{...e,appendBuiltinResult:t.result};case`clone_provider_result`:return{...e,cloneProviderResult:t.result};case`install_result`:return{...e,installResult:t.result};case`scm_data`:return{...e,scmData:t.data};case`file_search_result`:return{...e,fileSearch:t.result};case`session_search_result`:return{...e,sessionSearch:t.result};case`scm_changed`:return{...e,scmDirty:e.scmDirty+1};case`path_completions`:return{...e,pathCompletions:t.completions};case`update_status`:return{...e,update:t.status};case`update_status_all`:return{...e,updatesAll:t.items,updatesSdk:t.piSdk??null};case`updates_check_started`:return{...e,updatesAll:null};case`widgets`:return{...e,widgets:t.widgets};case`statuses`:return{...e,statuses:t.statuses};case`dialog`:return{...e,dialog:t.dialog};case`tui_overlay`:return{...e,tuiOverlay:t.overlay};case`question`:return{...e,question:t.question};case`remote_question`:return{...e,remoteQuestion:t.question};case`commands`:return{...e,commands:t.commands,commandsPath:t.path};case`slash_commands`:return{...e,slashCommands:t.commands};case`goal_status`:return{...e,goal:t.status};case`plan_updated`:{let n=e.state;if(!n)return e;let r=e.activeConversationId||n.conversationId;if(!t.conversationId||t.conversationId!==r)return e;let i={...n,plan:t.plan};return{...e,state:i}}case`settings`:return{...e,settings:t.settings};case`mcp_servers`:return e.settings?{...e,settings:{...e.settings,mcpServers:t.servers,mcpGlobalConfigPath:t.globalConfigPath??e.settings.mcpGlobalConfigPath,mcpProjectConfigPath:t.projectConfigPath??e.settings.mcpProjectConfigPath}}:e;case`mcp_market_result`:return{...e,mcpMarketResult:t.result};case`skill_market_result`:return{...e,skillMarketResult:t.result};case`skill_content_result`:return{...e,skillContentResult:t.result};case`bg_servers`:return{...e,bgServers:t.servers};case`scheduler_tasks`:return{...e,schedulerTasks:t.tasks};case`plugin_panel_items`:return{...e,pluginPanelGroups:t.groups};case`plugins`:return{...e,plugins:t.plugins,pluginsEpoch:t.epoch};case`plugin_updates_check_started`:return{...e,checkingPluginUpdates:!0};case`plugin_updates`:{let n={};for(let e of t.updates)n[e.id]=e;return{...e,pluginUpdates:n,checkingPluginUpdates:!1}}case`plugin_catalog`:return{...e,pluginCatalog:t.entries,pluginCatalogEpoch:t.epoch};case`plugin_grants`:return{...e,pluginGrants:t.grants};case`plugin_permissions`:return{...e,pluginPermissions:t.grants};case`plugin_path_request`:return{...e,pathRequests:[...e.pathRequests.filter(e=>e.id!==t.req.id),t.req]};case`plugin_path_resolved`:return{...e,pathRequests:e.pathRequests.filter(e=>e.id!==t.id)};case`plugin_permission_request`:return{...e,permRequests:[...e.permRequests.filter(e=>e.id!==t.req.id),t.req]};case`plugin_permission_resolved`:return{...e,permRequests:e.permRequests.filter(e=>e.id!==t.id)};case`plugin_job`:{let{pluginId:n,phase:r,ok:i,action:a}=t.job,o=e.pluginUpdates;a===`update`&&r===`done`&&i&&e.pluginUpdates?.[n]&&(o={...e.pluginUpdates,[n]:{...e.pluginUpdates[n],updatable:!1}});let s=e.pluginJobs[t.job.jobId],c=t.line?[...s?.lines??[],t.line].slice(-40):s?.lines??[],l={...s,...t.job,lines:c,startedAt:s?.startedAt??Date.now()};return{...e,pluginUpdates:o,pluginJobs:{...e.pluginJobs,[t.job.jobId]:l}}}case`plugin_catalog_sync_result`:return{...e,catalogSync:{...t.result,receivedAt:Date.now()}};case`preset_export_result`:return{...e,presetExport:{...t.result,receivedAt:Date.now()}};case`preset_import_result`:return{...e,presetImport:{...t.result,source:t.source,receivedAt:Date.now()}};case`preset_catalog_result`:return{...e,presetCatalog:{...t.result,receivedAt:Date.now()}};case`preset_share_result`:return{...e,presetShare:{...t.result,receivedAt:Date.now()}};case`plugin_install_inspect_result`:return{...e,installInspect:t.result};case`dsh_patches`:return{...e,dshPatches:{patchDir:t.patchDir,files:t.files}};case`dsh_presets`:return{...e,dshPresets:{presets:t.presets,defaultPreset:t.defaultPreset}};case`dsh_permission`:return{...e,dshPermission:{options:t.options,defaultPreset:t.defaultPreset}};case`terminal_add`:return{...e,terminals:[...e.terminals,t.meta]};case`terminal_remove`:return{...e,terminals:e.terminals.filter(e=>e.id!==t.id)};case`terminal_exit`:return t.conversationId&&(e.activeConversationId||e.state?.conversationId)&&t.conversationId!==(e.activeConversationId||e.state?.conversationId)?e:{...e,terminals:e.terminals.map(e=>e.id===t.terminalId?{...e,running:!1,exitCode:t.exitCode}:e)};case`terminal_restart`:return{...e,terminals:e.terminals.map(e=>e.id===t.terminalId?{...e,running:!0,exitCode:null}:e)};case`terminal_list`:return t.conversationId&&(e.activeConversationId||e.state?.conversationId)&&t.conversationId!==(e.activeConversationId||e.state?.conversationId)?e:{...e,terminals:t.terminals.map(n=>({...n,conversationId:t.conversationId??e.state?.conversationId??``}))};case`terminal_active`:return{...e,terminalActiveId:t.id};default:return e}}var pl=`pi-web-client-id`,ml=null;function hl(){if(ml)return ml;let e=null;try{e=sessionStorage.getItem(pl),e||(e=At(),sessionStorage.setItem(pl,e))}catch{e??=At()}return ml=e,e}var gl=`pi-web-last-cwd`;function _l(){try{return localStorage.getItem(gl)}catch{return null}}function vl(e){try{localStorage.setItem(gl,e)}catch{}}function yl(e){try{let t=localStorage.getItem(gl);if(!t)return;let n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase();(t===e||n(t)===n(e))&&localStorage.removeItem(gl)}catch{}}var bl=`pi-web-recent-projects`;function xl(){try{let e=localStorage.getItem(bl);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Sl(e){try{localStorage.setItem(bl,JSON.stringify(e.slice(0,20)))}catch{}}function Cl(e){try{let t=xl(),n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),r=n(e);Sl(t.filter(e=>n(e.path)!==r))}catch{}}var wl=`pi-web-recent-sessions:`;function Tl(e){return e?`${wl}${e.trim().replace(/[\\/]+$/,``).toLowerCase()}`:`pi-web-recent-sessions:default`}function El(e){try{let t=Tl(e??_l()),n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function Dl(e,t){try{let n=Tl(e??_l());localStorage.setItem(n,JSON.stringify(t.slice(0,50)))}catch{}}function Ol(e,t){try{let n=El(t),r=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),i=r(e);Dl(t,n.filter(e=>r(e.path)!==i))}catch{}}function kl(){return hn(`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}${dn(`/ws`)}`)}function Al(){let[e,t]=(0,g.useReducer)(fl,{status:`connecting`,ready:!1,state:null,hostMetrics:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:El(),conversations:[],elsewhere:[],activeConversationId:``,projects:xl(),files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],providerKeys:{},defaultModel:null,providerOAuthFlows:[],providerOAuthResults:$c().results,installResult:null,pathCompletions:[],update:null,updatesAll:null,updatesSdk:null,widgets:[],statuses:[],dialog:null,tuiOverlay:null,approval:null,question:null,remoteQuestion:null,commands:[],commandsPath:``,slashCommands:[],terminals:[],terminalActiveId:null,goal:cl,bgServers:[],schedulerTasks:[],pluginPanelGroups:[],settings:null,fetchModelsResult:null,testModelConnectionResult:null,enrichModelsResult:null,enrichModelsProgress:null,refreshProviderResult:null,refreshBuiltinResult:null,appendBuiltinResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,pluginUpdates:null,checkingPluginUpdates:!1,pluginCatalog:[],pluginCatalogEpoch:0,pluginJobs:{},catalogSync:null,presetExport:null,presetImport:null,presetCatalog:null,presetShare:null,installInspect:null,pluginGrants:[],pluginPermissions:[],pathRequests:[],permRequests:[],dshPatches:null,mcpMarketResult:null,skillMarketResult:null,skillContentResult:null,dshPresets:null,dshPermission:null,protocolMismatch:!1}),n=(0,g.useRef)(null),r=(0,g.useRef)(ll()),i=(0,g.useRef)(0),a=(0,g.useRef)(null),o=(0,g.useRef)(!0),s=(0,g.useRef)(0),c=(0,g.useRef)(0),l=(0,g.useRef)(new Map),u=(0,g.useRef)(null),d=(0,g.useRef)(!1),f=(0,g.useRef)(null),p=(0,g.useRef)(new Set),m=(0,g.useRef)(`live`),h=()=>{u.current||=setTimeout(()=>{u.current=null;let e=n.current;e&&e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`get_state`}))},300)},_=(e,t)=>{let n=l.current,r=n.get(e);if(r!==void 0&&t!==r+1){let t=O.current.chat;e===(t.activeConversationId||t.state?.conversationId)&&h()}n.set(e,t)},v=(0,g.useCallback)((e,n)=>{let r=++c.current;t({type:`notice`,notice:{id:r,level:e,text:n}})},[]),y=(0,g.useCallback)(e=>{let r=n.current;if(r&&r.readyState===WebSocket.OPEN){if(e.type===`check_updates_all`&&e.force===!0&&t({type:`updates_check_started`}),e.type===`check_plugin_updates`&&t({type:`plugin_updates_check_started`}),r.send(JSON.stringify(e)),e.type===`question_answer`){if(e.owner){let n=O.current.chat.remoteQuestion;n&&n.id===e.id&&t({type:`remote_question`,question:null})}else{if(p.current.add(e.id),p.current.size>64){let e=p.current.values().next().value;e!==void 0&&p.current.delete(e)}m.current=`live`,t({type:`question`,question:null})}}return!0}return!1},[]),b=(0,g.useCallback)((e,n)=>{let r=Wo({current:O.current.chat.question,source:m.current,snapshot:e,answered:p.current,activeConversationId:n});r.changed&&(m.current=r.source,t({type:`question`,question:r.question}))},[]);za(y);let x=(0,g.useCallback)(()=>{if(!o.current)return;t({type:`status`,status:`connecting`});let e=new WebSocket(kl());n.current=e,e.onopen=()=>{n.current===e&&(t({type:`status`,status:`open`}),i.current=0,s.current=Date.now(),e.send(JSON.stringify({type:`hello`,clientId:hl(),locale:rl()})))},e.onmessage=i=>{if(n.current!==e)return;s.current=Date.now();let a;try{a=JSON.parse(i.data)}catch{return}switch(a.type){case`ready`:if((O.current.chat.settings?.autoReload??!0)&&a.buildId&&a.buildId!==`20261011T00242`){let e=`pi-web-ui-reloaded-${a.buildId}`;if(!sessionStorage.getItem(e)){sessionStorage.setItem(e,`1`),location.reload();return}}Aa({engine:a.engine??`pi`,managed:!!a.managed,tabs:a.tabs,appVersion:a.appVersion,serverVersion:a.serverVersion,service:a.service}),t({type:`ready`,serverVersion:a.serverVersion,protocolVersion:a.protocolVersion,engine:a.engine,appVersion:a.appVersion,managed:a.managed,tabs:a.tabs,service:a.service}),p.current.clear(),t({type:`question`,question:null}),e.send(JSON.stringify({type:`get_state`})),e.send(JSON.stringify({type:`list_files`})),e.send(JSON.stringify({type:`list_models`})),e.send(JSON.stringify({type:`list_commands`})),e.send(JSON.stringify({type:`get_commands`})),a.managed||(e.send(JSON.stringify({type:`check_update`})),e.send(JSON.stringify({type:`check_updates_all`})));break;case`snapshot`:l.current=new Map,t({type:`snapshot`,state:a.state}),b(a.state.pendingQuestion,a.state.conversationId);break;case`snapshot_delta`:{let e=O.current.chat.state;if(e)(e.conversationId!==a.conversationId||e.rev!==a.baseRev)&&h();else{let e=n.current;e&&e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`get_state`}))}t({type:`snapshot_delta`,msg:a}),b(a.state.pendingQuestion,a.conversationId);break}case`tool_delta`:_(a.conversationId,a.seq),t({type:`tool_delta`,toolCallId:a.toolCallId,toolName:a.toolName,delta:a.delta});break;case`tool_status`:t({type:`tool_status`,status:a});break;case`message_delta`:_(a.conversationId,a.seq),t({type:`message_delta`,msg:a});break;case`subagent_handoff`:break;case`notice`:{let e=++c.current;t({type:`notice`,notice:{id:e,level:a.level,text:a.text,textEn:a.textEn}});break}case`sessions`:t({type:`sessions`,sessions:a.sessions});break;case`conversations`:t({type:`conversations`,conversations:a.conversations,activeId:a.activeId,elsewhere:a.elsewhere});break;case`projects`:t({type:`projects`,projects:a.projects});break;case`files`:t({type:`files`,files:a});break;case`file_changed`:t({type:`file_changed`,path:a.path});break;case`file_content`:t({type:`file_content`,content:a});break;case`models`:t({type:`models`,models:a.models,loading:!1});break;case`models_config`:t({type:`models_config`,providers:a.providers});break;case`providers_status`:t({type:`providers_status`,providers:a.providers});break;case`provider_keys`:t({type:`provider_keys`,keys:a.keys});break;case`default_model`:t({type:`default_model`,modelId:a.modelId});break;case`provider_oauth_started`:case`provider_oauth_flows`:case`provider_oauth_prompt`:case`provider_oauth_event`:case`provider_oauth_result`:case`provider_oauth_logout_result`:t({type:`provider_oauth`,message:a});break;case`fetch_models_result`:t({type:`fetch_models_result`,result:{reqId:a.reqId,ok:a.ok,models:a.models,error:a.error}});break;case`test_model_connection_result`:t({type:`test_model_connection_result`,result:{reqId:a.reqId,ok:a.ok,latencyMs:a.latencyMs,error:a.error}});break;case`enrich_models_progress`:t({type:`enrich_models_progress`,progress:{reqId:a.reqId,phase:a.phase,current:a.current,total:a.total,message:a.message}});break;case`enrich_models_result`:t({type:`enrich_models_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results,error:a.error}});break;case`refresh_provider_result`:t({type:`refresh_provider_result`,result:{reqId:a.reqId,ok:a.ok,added:a.added,total:a.total,error:a.error}});break;case`refresh_builtin_result`:t({type:`refresh_builtin_result`,result:{reqId:a.reqId,ok:a.ok,error:a.error}});break;case`append_builtin_result`:t({type:`append_builtin_result`,result:{reqId:a.reqId,ok:a.ok,error:a.error}});break;case`clone_provider_result`:t({type:`clone_provider_result`,result:{reqId:a.reqId,ok:a.ok,config:a.config,configs:a.configs,error:a.error}});break;case`scm_data`:t({type:`scm_data`,data:a});break;case`search_files_result`:t({type:`file_search_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results,truncated:a.truncated}});break;case`session_search_results`:t({type:`session_search_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results}});break;case`scm_changed`:t({type:`scm_changed`});break;case`tool_info`:es(a);break;case`tool_prompt`:ls(a);break;case`compacted_messages_result`:bs(a);break;case`heartbeat`:a.hostMetrics&&t({type:`host_metrics`,metrics:a.hostMetrics});break;case`install_result`:t({type:`install_result`,result:a});break;case`path_completions`:t({type:`path_completions`,completions:a.completions});break;case`update_status`:t({type:`update_status`,status:a});break;case`update_status_all`:t({type:`update_status_all`,items:a.items,piSdk:a.piSdk});break;case`widgets`:t({type:`widgets`,widgets:a.widgets});break;case`statuses`:t({type:`statuses`,statuses:a.statuses});break;case`dialog`:t({type:`dialog`,dialog:{id:a.id,kind:a.kind,title:a.title,args:a.args}});break;case`dialog_closed`:t({type:`dialog`,dialog:null});break;case`tui_overlay_open`:t({type:`tui_overlay`,overlay:{id:a.id,title:a.title,cols:a.cols,rows:a.rows,initialAnsi:a.initialAnsi}});break;case`tui_overlay_render`:qo(a.id,a.ansi);break;case`tui_overlay_close`:t({type:`tui_overlay`,overlay:null});break;case`question_pending`:m.current=`live`,t({type:`question`,question:{id:a.id,...a.deadline===void 0?{}:{deadline:a.deadline},questions:a.questions,...a.conversationId===void 0?{}:{conversationId:a.conversationId},...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`tool_approval_pending`:t({type:`tool_approval`,approval:{id:a.id,toolCallId:a.toolCallId,toolName:a.toolName,params:a.params,reason:a.reason,reasonEn:a.reasonEn,...a.category?{category:a.category}:{},...a.conversationId===void 0?{}:{conversationId:a.conversationId},...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`tool_approval_resolved`:t({type:`tool_approval`,approval:null});break;case`question_retracted`:{let e=O.current.chat.question;if(e&&e.id===a.id){if(p.current.add(a.id),p.current.size>64){let e=p.current.values().next().value;e!==void 0&&p.current.delete(e)}m.current=`live`,t({type:`question`,question:null})}break}case`elsewhere_question`:t({type:`remote_question`,question:{owner:a.owner,convId:a.convId,id:a.id,questions:a.questions,...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`page_request`:(async()=>{let e=window.__piWebUiHost,t;if(!e?.pageCall)t={ok:!1,error:`宿主页面桥不可用(页面版本过旧?)—— 刷新本页后再试`};else try{t=await e.pageCall({op:a.op,...a.args===void 0?{}:{args:a.args},...a.target?{target:a.target}:{},timeoutMs:a.timeoutMs})}catch(e){t={ok:!1,error:e instanceof Error?e.message:String(e)}}y({type:`page_response`,id:a.id,ok:t.ok===!0,...t.ok===!0?t.result===void 0?{}:{result:t.result}:{error:t.error??`页面操作失败`}})})();break;case`terminal_output`:r.current.write(a.conversationId??O.current.chat.activeConversationId,a.terminalId,a.data);break;case`terminal_exit`:t({type:`terminal_exit`,conversationId:a.conversationId,terminalId:a.terminalId,exitCode:a.exitCode});break;case`terminal_list`:t({type:`terminal_list`,conversationId:a.conversationId,terminals:a.terminals});break;case`commands`:t({type:`commands`,commands:a.commands,path:a.path});break;case`slash_commands`:t({type:`slash_commands`,commands:a.commands});break;case`goal_status`:t({type:`goal_status`,status:a.status});break;case`plan_updated`:t({type:`plan_updated`,conversationId:a.conversationId,plan:a.plan});break;case`settings_state`:t({type:`settings`,settings:a.settings});break;case`mcp_servers`:t({type:`mcp_servers`,servers:a.servers,globalConfigPath:a.globalConfigPath,projectConfigPath:a.projectConfigPath});break;case`mcp_market_result`:t({type:`mcp_market_result`,result:a});break;case`skill_market_result`:t({type:`skill_market_result`,result:a});break;case`skill_content_result`:t({type:`skill_content_result`,result:a});break;case`bg_servers`:t({type:`bg_servers`,servers:a.servers});break;case`scheduler_tasks`:t({type:`scheduler_tasks`,tasks:a.tasks});break;case`plugin_panel_items`:t({type:`plugin_panel_items`,groups:a.groups});break;case`plugins`:t({type:`plugins`,plugins:a.plugins,epoch:a.epoch});break;case`plugin_updates`:t({type:`plugin_updates`,updates:a.updates});break;case`plugin_catalog`:t({type:`plugin_catalog`,entries:a.entries,epoch:a.epoch});break;case`plugin_grants`:t({type:`plugin_grants`,grants:a.grants});break;case`plugin_permissions`:t({type:`plugin_permissions`,grants:a.grants});break;case`plugin_permission_request`:t({type:`plugin_permission_request`,req:{id:a.id,pluginId:a.pluginId,family:a.family,...a.hosts?{hosts:a.hosts}:{},...a.models?{models:a.models}:{},...a.reason?{reason:a.reason}:{}}});break;case`plugin_permission_resolved`:t({type:`plugin_permission_resolved`,id:a.id});break;case`plugin_path_request`:t({type:`plugin_path_request`,req:{id:a.id,pluginId:a.pluginId,path:a.path,...a.reason?{reason:a.reason}:{}}});break;case`plugin_dom_consent_request`:a.from===hl()&&e.send(JSON.stringify({type:`plugin_dom_consent_response`,id:a.id,ok:!0}));break;case`plugin_job`:t({type:`plugin_job`,job:{jobId:a.jobId,action:a.action,pluginId:a.pluginId,phase:a.phase,...a.ok===void 0?{}:{ok:a.ok},...a.error?{error:a.error}:{},...a.output?{output:a.output}:{}},...a.line?{line:a.line}:{}});break;case`plugin_install_inspect_result`:t({type:`plugin_install_inspect_result`,result:{requestId:String(a.requestId??``),source:String(a.source??``),kind:a.kind,suggestedId:String(a.suggestedId??``),installed:a.installed===!0,...a.problem?{problem:a.problem}:{},...a.detail?{detail:a.detail}:{},...a.manifest?{manifest:a.manifest}:{}}});break;case`plugin_catalog_sync_result`:mc(a),t({type:`plugin_catalog_sync_result`,result:{requestId:String(a.requestId??``),ok:a.ok===!0,...a.error?{error:a.error}:{},...a.entries?{entryCount:a.entries.length}:{},...a.installed?{installed:a.installed}:{}}});break;case`preset_export_result`:t({type:`preset_export_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,...a.name?{name:a.name}:{},...a.fileName?{fileName:a.fileName}:{},...a.json?{json:a.json}:{},...a.error?{error:a.error}:{}}});break;case`preset_import_result`:{let e=String(a.requestId??``),n=e.startsWith(`url:`)?`url`:e.startsWith(`file:`)?`file`:`paste`;t({type:`preset_import_result`,source:n,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,dryRun:a.dryRun===!0,...a.preview?{preview:a.preview}:{},...a.applied?{applied:!0}:{},...a.error?{error:a.error}:{}}});break}case`preset_catalog_result`:t({type:`preset_catalog_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,entries:a.entries??[],source:a.source??``,cached:a.cached===!0,fetchedAt:a.fetchedAt??0,...a.error?{error:a.error}:{}}});break;case`preset_share_result`:t({type:`preset_share_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,...a.method?{method:a.method}:{},...a.url?{url:a.url}:{},...a.name?{name:a.name}:{},...a.json?{json:a.json}:{},...a.error?{error:a.error}:{}}});break;case`dsh_patches`:t({type:`dsh_patches`,patchDir:a.patchDir,files:a.files});break;case`dsh_presets`:t({type:`dsh_presets`,presets:a.presets,defaultPreset:a.defaultPreset});break;case`dsh_permission`:t({type:`dsh_permission`,options:a.options,defaultPreset:a.defaultPreset});break;case`plugin_data`:Qc(a.pluginId,a.payload)||bc(a.pluginId,a.payload);break;case`remote_ssh_probe_result`:case`remote_ssh_list_dir_result`:case`remote_ssh_install_result`:case`remote_ssh_profiles_result`:Ha(a)}},e.onclose=()=>{if(n.current===e&&(n.current=null),r.current.clear(),!o.current||n.current&&n.current!==e)return;t({type:`status`,status:`closed`});let s=Math.min(1e3*2**i.current,1e4);i.current+=1,a.current=setTimeout(()=>{a.current=null,x()},s)},e.onerror=()=>{}},[]);(0,g.useEffect)(()=>{let e=e=>{let t=e.detail??rl();t&&y({type:`set_locale`,locale:t})};return window.addEventListener(il,e),()=>window.removeEventListener(il,e)},[y]),(0,g.useEffect)(()=>{let n=n=>{let r=e.state?.cwd;r&&n.key&&n.key===Tl(r)&&t({type:`sync_cached_sessions`,sessions:El(r)})};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e.state?.cwd]),(0,g.useEffect)(()=>{o.current=!0,x();let e=setInterval(()=>{if(!o.current)return;let e=n.current;e&&e.readyState===WebSocket.OPEN&&Date.now()-s.current>3e4&&e.close()},5e3),t=()=>{if(!o.current||typeof document<`u`&&document.visibilityState===`hidden`)return;let e=n.current;if(!e||e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING){a.current&&=(clearTimeout(a.current),null),x();return}e.readyState===WebSocket.OPEN&&(Date.now()-s.current>15e3||!O.current.chat.state)&&e.send(JSON.stringify({type:`get_state`}))};return typeof document<`u`&&document.addEventListener(`visibilitychange`,t),typeof window<`u`&&(window.addEventListener(`pageshow`,t),window.addEventListener(`online`,t)),()=>{o.current=!1,clearInterval(e),a.current&&=(clearTimeout(a.current),null),typeof document<`u`&&document.removeEventListener(`visibilitychange`,t),typeof window<`u`&&(window.removeEventListener(`pageshow`,t),window.removeEventListener(`online`,t)),n.current?.close(),n.current=null}},[x]),(0,g.useEffect)(()=>{let t=e.state?.cwd;if(t){if(!d.current){d.current=!0;let e=_l();if(e&&e!==t){y({type:`set_cwd`,path:e});return}}f.current!==t&&(f.current=t,vl(t))}},[e.state?.cwd,y]),(0,g.useEffect)(()=>{Aa({ready:e.ready,status:e.status,cwd:e.state?.cwd??``,workspaceRoots:e.state?.workspaceRoots??[],homeDir:e.state?.homeDir??``,desktopDir:e.state?.desktopDir??``})},[e.ready,e.status,e.state?.cwd,e.state?.workspaceRoots,e.state?.homeDir,e.state?.desktopDir]);let S=(0,g.useCallback)(e=>t({type:`dismiss_notice`,id:e}),[]),C=(0,g.useCallback)(e=>t({type:`terminal_add`,meta:e}),[]),w=(0,g.useCallback)(e=>t({type:`terminal_remove`,id:e}),[]),T=(0,g.useCallback)(e=>t({type:`terminal_restart`,terminalId:e}),[]),E=(0,g.useCallback)(e=>t({type:`terminal_active`,id:e}),[]),D=(0,g.useCallback)((e,t,n)=>r.current.register(e,t,n),[]),O=(0,g.useRef)({chat:e,send:y,pushNotice:v,dismissNotice:S,terminal:{create:C,close:w,register:D,restart:T,select:E}});return O.current={chat:e,send:y,pushNotice:v,dismissNotice:S,terminal:{create:C,close:w,register:D,restart:T,select:E}},O.current}function jl(e){let t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`:`${t.getMonth()+1}/${t.getDate()}`}function Ml(e){let t=e instanceof HTMLElement?e:null;if(!t)return!1;let n=t.tagName;return n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable}var Nl=`pi-web-ui:lp-collapse-projects`,Pl=`pi-web-ui:lp-collapse-convs`,Fl=`pi-web-ui:lp-collapse-sessions`,Il=`pi-web-ui:lp-collapse-subagents`;function Ll(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Il);if(e)return new Set(JSON.parse(e))}catch{}return new Set});return[e,(0,g.useCallback)(e=>{t(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(Il,JSON.stringify([...n]))}catch{}return n})},[])]}function Rl(e,t=!1){let[n,r]=(0,g.useState)(()=>{try{let t=localStorage.getItem(e);if(t===`1`)return!0;if(t===`0`)return!1}catch{}return t});return[n,(0,g.useCallback)(()=>{r(t=>{let n=!t;try{localStorage.setItem(e,n?`1`:`0`)}catch{}return n})},[e])]}var zl=`pi-web-ui:lp-collapse-plugin-sections`;function Bl(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(zl),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}});return[e,(0,g.useCallback)(e=>{t(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(zl,JSON.stringify([...n]))}catch{}return n})},[])]}var Vl=`pi-web-ui:lp-sizes`,Hl={projects:1,convs:1,sessions:1},Ul=32,Wl={running:`pluginRunStatusRunning`,done:`pluginRunStatusDone`,error:`pluginRunStatusError`},Gl=72;function Kl(){try{return xi(localStorage.getItem(Vl),Hl)}catch{return{...Hl}}}var ql=(0,g.memo)(function({sessionFile:e,conversations:t,elsewhere:n,sessions:r,projects:i,activeConversationId:a,panelSend:o,active:s,collapsible:c,onToggleCollapse:l,pathCompletions:u,uiContextSession:d,uiLeftSessions:f,uiContextProject:p,uiProjectsActions:m,uiLeftProject:h,uiRunningActions:_,uiHistoryActions:v,uiSections:y,renderPluginSectionBody:b,uiPluginRunning:x,onPluginRunningAction:S,uiLeftRunning:C,uiLeftHistory:w,onUiAction:T,presetNames:E}){let D=Z(),O=e,k=Pa(`ready`),A=Pa(`status`),j=Pa(`cwd`),ee=Pa(`workspaceRoots`),M=j,[te,ne]=(0,g.useState)(!1),[P,F]=(0,g.useState)(null),[re,ie]=(0,g.useState)(null),[I,ae]=(0,g.useState)(null),[R,z]=(0,g.useState)(``),[B,V]=Rl(Nl,!1),[H,U]=Rl(Pl,!1),[W,oe]=Rl(Fl,!1),[G,se]=Bl(),[ce,K]=Ll(),le=(0,g.useCallback)((e,t)=>{if(!t)return e.filter(e=>e.isSubagent&&!e.isStreaming&&e.id!==a).length;let n=new Map(e.map(e=>[e.id,e])),r=e=>{if(e.id===t)return(n.get(t)?.isSubagent??!1)&&!e.isStreaming&&e.id!==a;let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&!e.isStreaming&&e.id!==a&&r(e)).length},[a]),ue=(0,g.useCallback)((e,t)=>{if(!t)return e.filter(e=>e.isSubagent).length;let n=new Map(e.map(e=>[e.id,e])),r=e=>{if(e.id===t)return n.get(t)?.isSubagent??!1;let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&r(e)).length},[]),de=(0,g.useCallback)((e,t)=>{if(!t)return 0;let n=new Map(e.map(e=>[e.id,e])),r=e=>{let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&e.isStreaming&&r(e)).length},[]),q=(0,g.useRef)(null),J=(0,g.useRef)(null),pe=(0,g.useRef)(()=>{}),me=ba(d??[]).length>0,Y=(0,g.useCallback)((e,n,i)=>{q.current={x:e,y:n,target:i};let a=i.kind===`running`?i.id:void 0,o=i.kind===`elsewhere`,s=a??(o&&i.id||void 0),c=le(t,a),l=c===0?D(`noFinishedSubagents`):D(a?`dismissFinishedSubagentsScoped`:`dismissFinishedSubagents`,{n:c}),u=!!a&&J.current===a;la({x:e,y:n,slot:`contextmenu.session`,target:i,entries:(d??[]).map(e=>{if(e.source!==`host`)return e;if(e.id===`host:conv-rename`)return i.kind===`running`||i.kind===`history`?e:{...e,hidden:!0};if(e.id===`host:conv-takeover`)return o&&s&&i.owner&&!i.pseudo?e:{...e,hidden:!0};if(o&&(e.id===`host:conv-dismiss-subagents`||e.id===`host:conv-force-dismiss`))return{...e,hidden:!0};if(e.id===`host:conv-dismiss-subagents`)return{...e,label:l,...c===0?{when:[...e.when??[],`disabled`]}:{}};if(e.id===`host:conv-force-dismiss`)return a?{...e,...u?{label:D(`forceDismissConfirm`)}:{}}:{...e,hidden:!0};if(e.id===`host:conv-pin`){if(i.kind===`history`)return r.find(e=>e.path===i.id)?.pinned?{...e,label:D(`unpinConversation`)}:e;if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return!n||n.isSubagent?{...e,hidden:!0}:n.pinned?{...e,label:D(`unpinConversation`)}:e}if(e.id===`host:conv-persist`){if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return!n||!n.isSubagent&&n.sessionFile?{...e,hidden:!0}:n?.isEphemeral?{...e,label:D(`saveEphemeral`)}:e}if(e.id===`host:conv-copy-id`)return s?e:{...e,hidden:!0};if(e.id===`host:conv-copy-path`)return i.kind===`history`?e:a?t.some(e=>e.id===a&&e.sessionFile)?e:{...e,when:[...e.when??[],`disabled`]}:{...e,hidden:!0};if(e.id===`host:conv-copy-link`){if(i.kind===`history`)return r.find(e=>e.path===i.id)?.sessionId||Vo(i.id)?e:{...e,hidden:!0};if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return n?.sessionId||Vo(n?.sessionFile)?e:{...e,when:[...e.when??[],`disabled`]}}return e.id===`host:conv-quote`?s||i.kind===`history`?e:{...e,hidden:!0}:e}),onHostAction:(e,t)=>pe.current(e,t)})},[d,t,le,D]);pe.current=(0,g.useCallback)((e,n)=>{let i=n.kind===`running`?n.id:void 0,a=i??(n.kind===`elsewhere`&&n.id||void 0);if(e.id===`host:conv-takeover`){n.kind===`elsewhere`&&a&&n.owner&&o({type:`take_over_conversation`,owner:n.owner,id:a});return}if(e.id===`host:conv-dismiss-subagents`){o(i?{type:`dismiss_finished_subagents`,parentId:i}:{type:`dismiss_finished_subagents`});return}if(e.id===`host:conv-force-dismiss`){let e=q.current;if(!i||!e)return;if(J.current!==i)return J.current=i,Y(e.x,e.y,e.target),!0;J.current=null,o({type:`dismiss_conversation`,id:i,force:!0});return}if(e.id===`host:conv-persist`){i&&o({type:`persist_conversation`,id:i});return}if(e.id===`host:conv-pin`){if(n.kind===`history`){let e=r.find(e=>e.path===n.id);o({type:`pin_session`,path:n.id,pinned:!e?.pinned});return}i&&o({type:`pin_conversation`,id:i,pinned:!t.find(e=>e.id===i)?.pinned});return}if(e.id===`host:conv-copy-id`&&a){navigator.clipboard?.writeText(a).catch(()=>{});return}if(e.id===`host:conv-copy-path`){let e=n.kind===`history`?n.id:i&&t.find(e=>e.id===i)?.sessionFile||void 0;e&&navigator.clipboard?.writeText(e).catch(()=>{});return}if(e.id===`host:conv-copy-link`){let e=n.kind===`history`?r.find(e=>e.path===n.id)?.sessionId||Vo(n.id):i?t.find(e=>e.id===i)?.sessionId||Vo(t.find(e=>e.id===i)?.sessionFile):null;if(e){let t=Bo(window.location.href,{sessionId:e});navigator.clipboard?.writeText(t).catch(()=>{})}return}if(e.id===`host:conv-quote`){n.kind===`history`&&n.id?cr({attachments:[{path:``,key:`conv||${n.id}`,name:n.label||n.id,mode:`conversation`,sessionPath:n.id}]}):a&&cr({attachments:[{path:``,key:`conv|${a}|`,name:n.label||a,mode:`conversation`,conversationId:a}]});return}if(e.id===`host:conv-rename`){if(F(null),i){let e=t.find(e=>e.id===i);z(e?.title??n.label??``),ae(`conv:${i}`)}else if(n.kind===`history`&&n.id){let e=r.find(e=>e.path===n.id);z(e?.name??n.label??``),ae(n.id)}return}},[o,Y,t,r]);let ge=(e,t,n)=>!e||e.length===0?null:(0,X.jsx)(`span`,{className:t,children:e.map((e,t)=>{let r=`${e.id}#${t}`,i=e.label||e.id,a=e.hint||i;return e.kind===`divider`?(0,X.jsx)(`span`,{className:`lp-slot-divider`,"aria-hidden":`true`},r):e.kind===`badge`?(0,X.jsx)(`span`,{className:`lp-slot-badge`,title:a,children:e.badge??i},r):e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`lp-slot-select`,title:a,"aria-label":i,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onClick:e=>e.stopPropagation(),onChange:t=>{t.stopPropagation(),T?.(e,t.target.value)},children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},r):(0,X.jsx)(`button`,{type:`button`,className:`lp-slot-btn`,title:a,"aria-label":i,onClick:t=>{t.stopPropagation(),n?T?.(e,void 0,n):T?.(e)},children:e.icon?(0,X.jsx)(`span`,{"aria-hidden":!0,children:e.icon}):(0,X.jsx)(`span`,{children:i})},r)})}),_e=(0,g.useCallback)((e,t)=>{Ml(e.target)||me&&(e.preventDefault(),e.stopPropagation(),J.current=null,Y(e.clientX,e.clientY,t))},[me,Y]),ve=(0,g.useRef)(null),[ye,xe]=(0,g.useState)(()=>Kl());(0,g.useEffect)(()=>{try{localStorage.setItem(Vl,JSON.stringify(ye))}catch{}},[ye]);let Se=(0,g.useMemo)(()=>{let e=new Set,r=new Set;for(let n of t)n.sessionFile&&e.add(n.sessionFile),r.add(`${n.cwd}\0${n.title}`);let i=[],a=new Set;for(let t of n){if(t.sessionFile&&e.has(t.sessionFile)||r.has(`${t.cwd}\0${t.title}`))continue;let n=t.sessionFile?`file:${t.sessionFile}`:`title:${t.cwd}\0${t.title}`;a.has(n)||(a.add(n),i.push({id:t.sessionFile?`elsewhere:${t.cwd}:${t.sessionFile}`:`elsewhere:${t.cwd}:${t.title}${t.owner?`:${t.owner}`:``}`,title:t.title,cwd:t.cwd,messageCount:0,isStreaming:t.isStreaming,isSubagent:!1,elsewhere:!0,pseudo:!!t.pseudo,ownerOffline:!!t.ownerOffline,sessionFile:t.sessionFile,...t.owner&&t.convId?{owner:t.owner,convId:t.convId}:{},...t.hasQuestion?{hasQuestion:!0}:{}}))}return[...t,...i]},[t,n]),Ce=vi(y),we=Ce.filter(e=>e.shown),Te=e=>e===`projects`?B:e===`convs`?H:e===`sessions`?W:G.has(e),Ee=(x??[]).reduce((e,t)=>e+t.items.length,0),De=Se.length+Ee,Oe=yi(Ce,e=>e===`projects`?i.length>0:e!==`convs`||De>0),ke=()=>{let e=x??[];return e.length===0?null:e.map(e=>(0,X.jsxs)(`div`,{className:`panel-conv-group lp-plugin-group`,children:[(0,X.jsxs)(`div`,{className:`panel-conv-group-title`,title:e.pluginId,children:[D(`leftPanelPluginGroup`),` · `,e.pluginName]}),e.items.map(t=>(0,X.jsx)(`div`,{className:`lp-row lp-plugin-row`,children:(0,X.jsxs)(`button`,{type:`button`,className:`session-item lp-plugin-item${t.action?``:` is-static`}`,title:t.hint?`${t.title} — ${t.hint}`:t.title,onClick:()=>S?.(e,t),children:[(0,X.jsx)(`span`,{className:`lp-plugin-dot st-${t.status}`,title:D(Wl[t.status])}),t.icon?(0,X.jsx)(`span`,{className:`lp-plugin-icon`,"aria-hidden":!0,children:t.icon}):null,(0,X.jsxs)(`span`,{className:`session-info`,children:[(0,X.jsx)(`span`,{className:`session-title`,children:t.title}),t.hint?(0,X.jsx)(`span`,{className:`session-sub`,children:t.hint}):null]})]})},t.id))]},`plugin:${e.pluginId}`))},Ae=(0,g.useMemo)(()=>[...f??[],...C??[]],[f,C]),je=(0,g.useMemo)(()=>[...f??[],...w??[]],[f,w]),Me=(0,g.useCallback)((e,t)=>n=>{n.preventDefault();let r=n.currentTarget,i=n.clientY,a={...ye},o=ve.current;if(!o)return;let s=Oe.filter(e=>Te(e)).length,c=Oe.filter(e=>!Te(e)).reduce((e,t)=>e+(a[t]??1),0)||1,l=Math.max(120,o.clientHeight-s*Ul);r.classList.add(`dragging`),document.body.classList.add(`lp-resizing`);let u=n=>{let{above:r,below:o}=Fo({start:{above:a[e]??1,below:a[t]??1},deltaPx:n.clientY-i,availablePx:l,totalWeight:c,minAbovePx:Gl,minBelowPx:Gl});xe(n=>({...n,[e]:r,[t]:o}))},d=()=>{window.removeEventListener(`pointermove`,u),window.removeEventListener(`pointerup`,d),r.classList.remove(`dragging`),document.body.classList.remove(`lp-resizing`)};window.addEventListener(`pointermove`,u),window.addEventListener(`pointerup`,d)},[ye,Oe,B,H,W]);(0,g.useEffect)(()=>{s&&k&&A===`open`&&j&&(o({type:`list_sessions`}),o({type:`list_projects`}))},[s,k,A,j,o]);let Ne=e=>{let t=e.name||e.firstMessage.trim();return t.length>0?t:D(`emptyChat`)},Pe=e=>e.split(/[\\/]/).pop()||e,Fe=ba(p??[]).length>0,Ie=(0,g.useCallback)((e,t)=>{Ml(e.target)||Fe&&(e.preventDefault(),e.stopPropagation(),la({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.path,kind:`project`,label:Pe(t.path)},entries:p??[]}))},[Fe,p]),ze=(e,t,n,r,i)=>{let a=P===e;return(0,X.jsx)(`button`,{type:`button`,className:`lp-del ${a?`confirm`:``}`,title:a?n:t,onClick:t=>{t.stopPropagation(),a?(F(null),r()):F(e)},children:a?(0,X.jsx)(dt,{}):i??(0,X.jsx)(L,{})})},Be=(e,t,n,r,i,a)=>(0,X.jsxs)(`div`,{className:`lp-section-header`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`lp-section-title panel-section-title`,onClick:n,title:D(t?`expandSection`:`collapseSection`),children:[(0,X.jsxs)(`span`,{className:`lp-section-title-text`,children:[e,r===void 0?``:` (${r})`]}),(0,X.jsx)(`span`,{className:`lp-section-chevron`,children:t?(0,X.jsx)(ut,{}):(0,X.jsx)(st,{})})]}),i||a?(0,X.jsxs)(`div`,{className:`lp-section-actions`,children:[i,a]}):null]}),Ve=Oe.filter(e=>!Te(e)),He=Ve.reduce((e,t)=>e+(ye[t]??1),0)||1,Ue=e=>Ve.length<=1?1:(ye[e]??1)/He*Ve.length,We=new Map(bi(Oe,Te).map(([e,t])=>[e,(0,X.jsx)(`div`,{className:`lp-sash`,onPointerDown:Me(e,t),onDoubleClick:()=>xe({...Hl}),title:D(`dragToResize`)},`sash-${e}`)])),Ke={projects:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section panel-projects ${B||i.length===0?`collapsed`:``}`,style:i.length>0&&!B?{flex:`${Ue(`projects`)} 1 0px`}:void 0,children:[Be(D(`recentProjects`),B,V,i.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action`,title:D(`manageProjects`),"aria-label":D(`manageProjects`),onClick:()=>ne(!0),children:(0,X.jsx)(Re,{})}),ge(m,`lp-slot-section`)),i.length>0&&!B&&(0,X.jsx)(`div`,{className:`lp-section-body projects-scroll`,children:i.map(e=>{let t=M===e.path;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>F(t=>t===`proj:${e.path}`?null:t),onContextMenu:t=>Ie(t,e),children:[(0,X.jsxs)(`button`,{type:`button`,className:`project-item ${t?`active`:``}`,title:e.path,onClick:()=>{t||o({type:`set_cwd`,path:e.path})},children:[(0,X.jsx)(Le,{className:`project-icon`}),(0,X.jsxs)(`span`,{className:`project-info`,children:[(0,X.jsx)(`span`,{className:`project-name`,children:Pe(e.path)}),(0,X.jsx)(`span`,{className:`project-path`,children:e.path})]}),(0,X.jsx)(`span`,{className:`project-time`,children:jl(e.lastUsed)})]}),ze(`proj:${e.path}`,D(`deleteProject`),D(`deleteProjectConfirm`),()=>{yl(e.path),Cl(e.path),o({type:`remove_project`,path:e.path})}),ge(h,`lp-slot-project`,{id:e.path,kind:`project`,label:Pe(e.path)})]},e.path)})})]})}),convs:(0,X.jsx)(X.Fragment,{children:De>0&&(0,X.jsxs)(`div`,{className:`lp-section lp-section-convs panel-convs ${H?`collapsed`:``}`,style:H?void 0:{flex:`${Ue(`convs`)} 1 0px`},onContextMenu:e=>_e(e,{id:``,kind:`section`,label:D(`runningConversations`)}),children:[Be(D(`runningConversations`),H,U,De,void 0,ge(_,`lp-slot-section`)),!H&&(0,X.jsxs)(`div`,{className:`lp-section-body convs-scroll`,children:[Io(Se,j,a).map(e=>(0,X.jsxs)(`div`,{className:`panel-conv-group`,children:[!e.isCurrent&&(0,X.jsx)(`div`,{className:`panel-conv-group-title`,title:e.cwd,children:Pe(e.cwd)}),Lo(e.convs,ce).map(({c:n,depth:r,hasKids:i,isCollapsed:s,descendantCount:c,hasStreaming:l,hasError:u,hasQuestion:d})=>{if(n.elsewhere){let e=n.owner,t=n.convId,r=!!n.pseudo,i=!!n.ownerOffline&&!r,a=!!(e&&t)&&!r,s=re===n.id,c=s?D(`takeoverConfirm`):r?`${D(`elsewherePseudoTip`)}\n${n.cwd}`:`${D(i?`elsewhereOfflineTip`:`elsewhereTip`)}\n${n.cwd}`;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ie(e=>e===n.id?null:e),onContextMenu:i=>_e(i,{id:t??n.id,kind:`elsewhere`,label:n.title,...e?{owner:e}:{},...r?{pseudo:!0}:{}}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item elsewhere-item${a?``:` elsewhere-static`}${s?` confirm`:``}`,title:c,tabIndex:a?0:-1,onClick:a?()=>{if(!s){ie(n.id);return}ie(null),o({type:`take_over_conversation`,owner:e,id:t})}:void 0,children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[(0,X.jsxs)(`span`,{className:`session-title`,children:[(0,X.jsx)(`span`,{className:`elsewhere-badge`,children:D(r?`elsewherePseudoBadge`:`elsewhereBadge`)}),i&&(0,X.jsx)(`span`,{className:`elsewhere-badge offline`,title:D(`elsewhereOfflineTip`),children:D(`elsewhereOfflineBadge`)}),n.hasQuestion&&e&&t&&!r&&(0,X.jsx)(`span`,{className:`question-badge clickable`,title:D(`takeoverHasQuestion`),onClick:n=>{n.stopPropagation(),o({type:`peek_elsewhere_question`,owner:e,id:t})},children:`?`}),s?D(`takeoverConfirm`):n.title]}),(0,X.jsx)(`span`,{className:`session-sub`,children:Pe(n.cwd)})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:D(`streaming`)})]}),me&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-elsewhere-act`,title:D(`elsewhereActions`),onClick:i=>{i.stopPropagation(),J.current=null;let a=i.currentTarget.getBoundingClientRect();Y(a.left,a.bottom+4,{id:t??n.id,kind:`elsewhere`,label:n.title,...e?{owner:e}:{},...r?{pseudo:!0}:{}})},children:(0,X.jsx)(he,{})})]},n.id)}let f=a===n.id;return(0,X.jsxs)(`div`,{className:`lp-row${r>0?` lp-sub`:``}${i?` lp-has-kids`:``}`,style:r>0?{marginLeft:r*18}:void 0,onMouseLeave:()=>F(e=>e===`conv:${n.id}`?null:e),onContextMenu:e=>_e(e,{id:n.id,kind:`running`,label:n.title}),children:[i&&(0,X.jsx)(`button`,{type:`button`,className:`lp-tree-caret${s?` collapsed`:` expanded`}`,title:D(s?`expandSubagents`:`collapseSubagents`),"aria-label":D(s?`expandSubagents`:`collapseSubagents`),onClick:e=>{e.stopPropagation(),K(n.id)},children:s?(0,X.jsx)(ct,{}):(0,X.jsx)(ut,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${f?`active`:``}`,title:`${n.title}${e.isCurrent?``:` — ${e.cwd}`}`,onClick:()=>{f||o({type:`switch_conversation`,id:n.id})},children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[I===`conv:${n.id}`?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:R,placeholder:D(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing){let e=R.trim();e&&o({type:`rename_conversation`,id:n.id,name:e}),ae(null)}else e.key===`Escape`&&ae(null)},onBlur:()=>ae(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[n.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:D(`pinnedConversation`),children:`📌`}),n.isSubagent&&(0,X.jsx)(`span`,{className:`subagent-badge`,children:D(`subagentBadge`)}),n.isEphemeral&&(0,X.jsx)(`span`,{className:`ephemeral-badge`,children:D(`ephemeralBadge`)}),n.forkFrom&&(0,X.jsxs)(`span`,{className:`preset-badge fork-badge`,title:`${D(`forkBadgeTip`)}: ${n.forkFrom.title??n.forkFrom.conversationId}`,children:[`🌿 `,D(`forkBadge`)]}),n.agentPreset&&(0,X.jsx)(`span`,{className:`preset-badge`,title:n.agentPreset,children:E?.[n.agentPreset]??n.agentPreset}),n.title,n.error&&(0,X.jsx)(`span`,{className:`conv-error-badge`,title:D(`convErrorBadge`,{error:n.error})}),n.hasQuestion&&(0,X.jsx)(`span`,{className:`question-badge`,title:D(`waitingQuestionBadge`),children:`?`}),i&&s&&(0,X.jsxs)(`span`,{className:`subagents-collapsed-badge${l?` has-streaming`:d?` has-question`:u?` has-error`:``}`,title:D(l?`subagentsStreamingTip`:d?`subagentsQuestionTip`:u?`subagentsErrorTip`:`subagentsCountTip`,{n:c}),onClick:e=>{e.stopPropagation(),K(n.id)},children:[l&&(0,X.jsx)(`span`,{className:`subagent-dot streaming`}),d&&(0,X.jsx)(`span`,{className:`subagent-dot question`,children:`?`}),u&&(0,X.jsx)(`span`,{className:`subagent-dot error`}),(0,X.jsx)(`span`,{className:`subagents-count-text`,children:D(`subagentBadgeCount`,{n:c})})]})]}),I===`conv:${n.id}`?null:(0,X.jsx)(`span`,{className:`session-sub`,children:f?D(`current`):D(`messageCount`,{n:n.messageCount})})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:D(`streaming`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:D(`renameSession`),onClick:e=>{e.stopPropagation(),F(null),z(n.title),ae(`conv:${n.id}`)},children:(0,X.jsx)(Ge,{})}),(()=>{let e=`conv:${n.id}`,r=P===e,i=le(t,n.id),a=de(t,n.id),s=ue(t,n.id);return s===0&&!n.isStreaming?ze(e,D(`dismissConversation`),D(`dismissConversationConfirm`),()=>o({type:`dismiss_conversation`,id:n.id}),(0,X.jsx)(N,{})):s===0?ze(e,D(`dismissConversation`),D(`dismissStreamingConfirm`),()=>o({type:`dismiss_conversation`,id:n.id,force:!0}),(0,X.jsx)(N,{})):r?(0,X.jsxs)(`span`,{className:`lp-del-group`,children:[i>0&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt`,title:D(`dismissFinishedSubagentsScoped`,{n:i}),onClick:e=>{e.stopPropagation(),F(null),o({type:`dismiss_finished_subagents`,parentId:n.id})},children:D(`dismissFinishedOnly`,{n:i})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt danger`,title:D(`forceDismissTitle`,{n:s,m:a}),onClick:e=>{e.stopPropagation(),F(null),o({type:`dismiss_conversation`,id:n.id,force:!0})},children:D(`dismissForceAll`,{n:s})})]}):(0,X.jsx)(`button`,{type:`button`,className:`lp-del`,title:D(`dismissConversation`),onClick:t=>{t.stopPropagation(),F(e)},children:(0,X.jsx)(N,{})})})(),ge(Ae,`lp-slot-sessions`),n.isStreaming&&(0,X.jsx)(`span`,{className:`lp-row-stalled`,title:D(`streaming`),style:{position:`absolute`,right:28,top:`50%`,transform:`translateY(-50%)`}})]},n.id)})]},e.cwd)),ke()]})]})}),sessions:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section lp-section-sessions panel-sessions ${W?`collapsed`:``}`,style:W?void 0:{flex:`${Ue(`sessions`)} 1 0px`},children:[Be(D(`historySessions`),W,oe,r.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-new-chat-action`,title:D(`newChatTip`),"aria-label":D(`newChat`),onClick:()=>{o({type:`new_chat`}),or()},children:(0,X.jsx)(fe,{})}),ge(v,`lp-slot-section`)),!W&&(0,X.jsxs)(`div`,{className:`lp-section-body sessions-scroll`,children:[r.length===0&&(0,X.jsx)(`div`,{className:`panel-empty`,children:D(`noHistory`)}),r.map(e=>{let t=O===e.path;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>F(t=>t===`sess:${e.path}`?null:t),onContextMenu:t=>_e(t,{id:e.path,kind:`history`,label:Ne(e)}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${t?`active`:``}`,title:e.path,onClick:()=>{I||t||o({type:`switch_session`,path:e.path})},children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[I===e.path?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:R,placeholder:D(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=R.trim();t&&o({type:`rename_session`,path:e.path,name:t}),ae(null)}else t.key===`Escape`&&ae(null)},onBlur:()=>ae(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[e.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:D(`pinnedConversation`),children:`📌`}),Ne(e)]}),I===e.path?null:(0,X.jsxs)(`span`,{className:`session-sub`,children:[t?D(`current`):D(`messageCount`,{n:e.messageCount}),e.source===`tui`&&(0,X.jsx)(`span`,{className:`session-src`,title:D(`tuiTip`),children:`TUI`})]})]}),(0,X.jsx)(`span`,{className:`session-time`,children:jl(e.modified)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:D(`renameSession`),onClick:t=>{t.stopPropagation(),F(null),z(e.name??``),ae(e.path)},children:(0,X.jsx)(Ge,{})}),ze(`sess:${e.path}`,D(`deleteSession`),D(`deleteSessionConfirm`),()=>{Ol(e.path,M),o({type:`delete_session`,path:e.path})}),ge(je,`lp-slot-sessions`)]},e.path)})]})]})})},qe=e=>{let t=we.find(t=>t.key===e)?.entry;if(!t)return null;let n=Te(e);return(0,X.jsxs)(`div`,{className:`lp-section lp-section-plugin ${n?`collapsed`:``}`,style:n?void 0:{flex:`${Ue(e)} 1 0px`},children:[Be(t.label,n,()=>se(e)),!n&&(0,X.jsx)(`div`,{className:`lp-section-body lp-plugin-section-body`,children:b?.(t)??null})]})},Je=e=>e===`projects`||e===`convs`||e===`sessions`?Ke[e]:qe(e);return(0,X.jsxs)(`aside`,{ref:ve,className:`panel panel-left lp-panel`,children:[c&&l&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:D(`collapsePanel`),onClick:l,children:(0,X.jsx)(ot,{})}),we.map(({key:e})=>(0,X.jsxs)(g.Fragment,{children:[Je(e),We.get(e)??null]},e)),(0,X.jsx)(io,{open:te,currentCwd:M,pathCompletions:u??[],workspaceRoots:ee,onClose:()=>ne(!1),onSelectDirectory:e=>o({type:`set_cwd`,path:e}),onCreateProject:e=>o({type:`make_dir`,path:e,setAsCwd:!0})})]})}),Jl=209715200,Yl=/windows/i.test(navigator.userAgent),Xl=/[<>:"/\\|?*\u0000-\u001f]/g,Zl=/[. ]+$/,Ql=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function $l(e){let t=e.replace(Xl,`_`).replace(Zl,``);return t?Ql.test(t)?`_${t}`:t:`_`}function eu(e,t=!0){return hn(dn(`/api/file?${new URLSearchParams({clientId:hl(),path:e,...t?{download:`1`}:{}})}`))}async function tu(e,t){let n=Yl?$l(t):t;try{let t=await fetch(eu(e));if(!t.ok)return{ok:!1,cancelled:!1,error:await t.text().catch(()=>``)||(t.status===404?`FILE_NOT_FOUND`:`HTTP ${t.status}`)};if(Number(t.headers.get(`content-length`)??`0`)>Jl)return window.location.assign(eu(e)),{ok:!0};let r=await t.blob();return window.showSaveFilePicker&&window.isSecureContext?ru(r,n):iu(r,n)}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}async function nu(e,t){let n=Yl?$l(t):t;return window.showSaveFilePicker&&window.isSecureContext?ru(e,n):iu(e,n)}async function ru(e,t){let n,r=window.showSaveFilePicker;if(!r)return iu(e,t);try{n=await r({suggestedName:t})}catch(n){return n instanceof DOMException&&n.name===`AbortError`?{ok:!1,cancelled:!0}:iu(e,t)}try{let t=await n.createWritable();return await t.write(e),await t.close(),{ok:!0}}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}function iu(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);return r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}function au(e,t,n){let r=e.left-8,i=e.bottom+8;return r+t.width>n.width-8&&(r=Math.max(8,e.right+8-t.width)),i+t.height>n.height-8&&(i=Math.max(8,e.top-8-t.height)),{left:r,top:i}}function ou(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}function su({text:e}){let t=(0,g.useRef)(null),n=(0,g.useRef)(null),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)({left:0,top:0}),s=()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},c=()=>i(!1);return(0,g.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=au(i.getBoundingClientRect(),a,{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)},[r,e]),(0,g.useEffect)(()=>{if(!r)return;let e=0,a=()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e=t.current,r=n.current;if(!e||!r)return;let a=e.getBoundingClientRect();if(a.bottom<0||a.top>window.innerHeight||a.right<0||a.left>window.innerWidth){i(!1);return}let s=au(a,r.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)})};return window.addEventListener(`scroll`,a,!0),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(e),window.removeEventListener(`scroll`,a,!0),window.removeEventListener(`resize`,a)}},[r]),(0,X.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:s,onMouseLeave:c,onFocus:s,onBlur:c,onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},children:[`?`,r&&(0,j.createPortal)((0,X.jsx)(`span`,{ref:n,className:`set-tip-bubble open`,role:`tooltip`,style:{position:`fixed`,left:a.left,top:a.top},children:e}),document.body)]})}var cu=e=>/\.(zip|tar|tar\.gz|tgz|gz)$/i.test(e);function lu(e,t={}){let n={archive:dn(`/api/file-transfer/archive`),upload:dn(`/api/file-transfer/upload`)},r=new URL(hn(`${n[e]}?${new URLSearchParams({clientId:hl(),...t})}`),window.location.href);if(r.origin!==window.location.origin||r.pathname!==new URL(n[e],window.location.href).pathname)throw Error(`File transfers must use an allowlisted same-origin endpoint`);return r}async function uu(e,t,n){let r=await fetch(lu(`archive`),{method:`POST`,headers:{"Content-Type":`application/json`,"X-File-Operation":`1`},body:JSON.stringify({action:e,path:t,...n})});if(!r.ok)throw Error(await r.text());if(e===`download`){let e=r.headers.get(`content-disposition`)??``,t=/filename\*=UTF-8''([^;]+)/i.exec(e)?.[1],n=/filename="([^"]+)"/i.exec(e)?.[1],i=t?decodeURIComponent(t):n??`archive.tar.gz`,a=await nu(await r.blob(),i);if(!a.ok&&!a.cancelled)throw Error(a.error)}}async function du(){let e=window.showDirectoryPicker;if(!e)return null;let t=await e.call(window),n=[];async function r(e,t){if(n.length>=2e4)throw Error(`Folder exceeds 20,000 entries`);if(n.push(e.kind===`file`?{path:t,file:await e.getFile()}:{path:t}),e.kind===`directory`)for await(let n of e.values())await r(n,`${t}/${n.name}`)}return await r(t,t.name),n}async function fu(e,t,n){if(t.length>2e4)throw Error(`Folder exceeds 20,000 entries`);for(let e of t)if(e.file&&e.file.size>33554432)throw Error(`File exceeds 32 MiB: ${e.path}`);let r=0;for(let i of t){let t=lu(`upload`,{dir:e,name:i.path,kind:i.file?`file`:`directory`}),a=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/octet-stream`,"X-File-Operation":`1`},body:i.file??new Blob});if(!a.ok)throw Error(`${i.path}: ${await a.text()}`);n?.(++r)}}function pu({request:e,onClose:t,onComplete:n}){let r=Z(),[i,a]=(0,g.useState)(e.dir),[o,s]=(0,g.useState)(`skip`),[c,l]=(0,g.useState)([]),[u,d]=(0,g.useState)(0),f=(0,g.useRef)(null),[p,m]=(0,g.useState)(!1),[h,_]=(0,g.useState)(``),v=(0,g.useRef)(null);(0,g.useEffect)(()=>{v.current?.showModal()},[]);let y=r(e.action===`upload`?`fileUploadFolder`:e.action===`extract`?`fileExtract`:e.action===`download`?`fileCompressDownload`:`fileCompress`);async function b(){try{let e=await du();e?l(e):f.current?.click()}catch(e){e instanceof DOMException&&e.name===`AbortError`||_(String(e))}}async function x(){d(0),m(!0),_(``);try{e.action===`upload`?await fu(e.dir,c,d):await uu(e.action,e.path,{destination:i,policy:o}),n(),t()}catch(e){_(e instanceof Error?e.message:String(e)),n()}finally{m(!1)}}return(0,j.createPortal)((0,X.jsx)(`dialog`,{ref:v,className:`file-transfer-dialog`,"aria-labelledby":`file-transfer-title`,onCancel:e=>{e.preventDefault(),p||t()},children:(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),x()},children:[(0,X.jsxs)(`div`,{className:`file-transfer-head`,children:[(0,X.jsx)(`h3`,{id:`file-transfer-title`,children:y}),(0,X.jsx)(`button`,{type:`button`,className:`file-transfer-close`,title:r(`close`),"aria-label":r(`close`),disabled:p,onClick:t,children:(0,X.jsx)(N,{})})]}),(0,X.jsx)(`p`,{className:`file-transfer-path`,children:(e.action===`upload`?e.dir:e.path)||`.`}),(0,X.jsx)(`p`,{children:r(`fileArchiveLimits`)}),e.action===`extract`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`label`,{children:[r(`fileExtractDestination`),(0,X.jsx)(`input`,{value:i,disabled:p,onChange:e=>a(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[r(`fileConflictPolicy`),(0,X.jsxs)(`select`,{value:o,disabled:p,onChange:e=>s(e.target.value),children:[(0,X.jsx)(`option`,{value:`skip`,children:r(`fileConflictSkip`)}),(0,X.jsx)(`option`,{value:`overwrite`,children:r(`fileConflictOverwrite`)}),(0,X.jsx)(`option`,{value:`error`,children:r(`fileConflictError`)})]})]})]}),e.action===`upload`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{children:r(`fileFolderUploadHint`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:p,onClick:()=>void b(),children:r(`fileChooseFolder`)}),(0,X.jsx)(`input`,{type:`file`,"aria-label":y,multiple:!0,hidden:!0,disabled:p,ref:e=>{f.current=e,e?.setAttribute(`webkitdirectory`,``)},onChange:e=>l(Array.from(e.target.files??[],e=>({path:e.webkitRelativePath||e.name,file:e})))}),(0,X.jsxs)(`p`,{"aria-live":`polite`,children:[u,` / `,c.length]})]}),h&&(0,X.jsx)(`p`,{role:`alert`,children:r(`fileTransferFailed`,{error:h})}),(0,X.jsxs)(`div`,{className:`file-transfer-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:p,onClick:t,children:r(`cancel`)}),(0,X.jsx)(`button`,{type:`submit`,className:`btn primary`,disabled:p||e.action===`upload`&&c.length===0,children:p?r(`fileTransferBusy`):y})]})]})}),document.body)}function mu(e){return e instanceof Error?e.message:String(e)}function hu(e,t,n,r){let i=n===`zh`;switch(e.kind){case`no-client`:return i?`插件 ${t} 没有客户端脚本(client/entry.mjs),无法显示这一页。`:`Plugin ${t} ships no client bundle (client/entry.mjs), so this page cannot be shown.`;case`load`:return i?`插件 ${t} 的页面脚本加载失败:${e.detail}`:`Failed to load plugin ${t}'s page bundle: ${e.detail}`;case`mount`:return`${r(`pluginMountFailed`,{name:t})}:${e.detail}`}}function gu({plugin:e,epoch:t,send:n,className:r}){let i=(0,g.useRef)(null),{locale:a}=Mn(),o=Z(),[s,c]=(0,g.useState)(null),l=(0,g.useRef)(n);(0,g.useEffect)(()=>{l.current=n},[n]),(0,g.useEffect)(()=>{let n=i.current;if(!n)return;let r=!1,a,o=!1;if(c(null),!e.hasClient){c({kind:`no-client`});return}return(async()=>{try{if(await Bc(e,t),r)return;let i=await Ns(e.id,()=>vc(()=>import(Fc(e.id,t)),[]));if(r)return;let s=i.default;if(!s||typeof s.mount!=`function`)throw Error(`client/entry.mjs 没有导出 default.mount()`);o=!0,a=s.mount(n,Hc(e.id,e=>l.current(e)))}catch(t){if(r)return;console.error(`[plugin:${e.id}] 页面${o?`挂载`:`加载`}失败:`,t),c({kind:o?`mount`:`load`,detail:mu(t)})}})(),()=>{if(r=!0,typeof a==`function`)try{a()}catch(t){console.error(`[plugin:${e.id}] cleanup 失败:`,t)}n.textContent=``}},[e.id,e.hasClient,t]);let u=r?`plugin-page ${r}`:`plugin-page`;return(0,X.jsxs)(`div`,{className:u,children:[(0,X.jsx)(`div`,{className:`plugin-page-host`,ref:i}),s&&(0,X.jsx)(`div`,{className:`plugin-page-error`,role:`alert`,children:hu(s,e.name,a,o)})]})}function _u(e){return`pi-web-ui:${e}:tab`}function vu(e,t){try{let n=localStorage.getItem(_u(e));return n&&t.some(e=>e.id===n)?n:null}catch{return null}}function yu(e,t){try{localStorage.setItem(_u(e),t)}catch{}}function bu(e){return e.length>0&&!/[a-z]/i.test(e)}function xu(e){if(e.label)return e.label;let t=e.pluginPage;return t?.entry.label||t?.plugin.name||e.id}function Su({storageKey:e,tabs:t,epoch:n,send:r,extra:i,className:a}){let o=(0,g.useId)(),[s,c]=(0,g.useState)(()=>vu(e,t)??t[0]?.id??``),l=(0,g.useRef)([]),u=(0,g.useRef)(``),d=t.findIndex(e=>e.id===s),f=d>=0?t[d]:t[0],p=f?t.indexOf(f):-1;(0,g.useEffect)(()=>{if(!f)return;s!==f.id&&c(f.id);let t=`${e}:${f.id}`;u.current!==t&&(u.current=t,yu(e,f.id))},[f,s,e]);let m=t=>{c(t.id),u.current=`${e}:${t.id}`,yu(e,t.id)},h=(e,n)=>{let r=t.length,i=-1;if(e.key===`ArrowRight`)i=(n+1)%r;else if(e.key===`ArrowLeft`)i=(n-1+r)%r;else if(e.key===`Home`)i=0;else if(e.key===`End`)i=r-1;else return;let a=t[i];a&&(e.preventDefault(),m(a),l.current[i]?.focus())};if(!f)return null;let _=`${o}-panel-${p}`,v=a?`slot-tabs ${a}`:`slot-tabs`;return(0,X.jsxs)(`div`,{className:v,children:[(0,X.jsxs)(`div`,{className:`slot-tabs-bar`,role:`tablist`,children:[t.map((e,t)=>{let n=t===p;return(0,X.jsxs)(`button`,{type:`button`,role:`tab`,id:`${o}-tab-${t}`,className:n?`slot-tab active`:`slot-tab`,title:e.hint??xu(e),"aria-selected":n,"aria-controls":`${o}-panel-${t}`,tabIndex:n?0:-1,ref:e=>{l.current[t]=e},onClick:()=>m(e),onKeyDown:e=>h(e,t),children:[e.iconSvg?(0,X.jsx)(fi,{iconSvg:e.iconSvg,className:`slot-tab-icon`}):e.icon&&bu(e.icon)?(0,X.jsx)(`span`,{className:`slot-tab-icon`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`slot-tab-label`,children:xu(e)})]},e.id)}),i?(0,X.jsx)(`div`,{className:`slot-tabs-extra`,children:i}):null]}),(0,X.jsx)(`div`,{className:`slot-tabs-body`,id:_,role:`tabpanel`,"aria-labelledby":`${o}-tab-${p}`,children:f.pluginPage?(0,X.jsx)(gu,{plugin:f.pluginPage.plugin,epoch:n,send:r}):f.element??null})]})}function Cu(e){if(typeof document>`u`)return!1;try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,t.style.top=`-9999px`,t.setAttribute(`readonly`,``),document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}async function wu(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return Cu(e)}return Cu(e)}function Tu(e={}){let{duration:t=2e3,onSuccess:n,onError:r}=e,[i,a]=(0,g.useState)(!1),o=(0,g.useRef)(null),s=(0,g.useCallback)(()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},[]),c=(0,g.useCallback)(()=>{s(),a(!1)},[s]);return(0,g.useEffect)(()=>()=>{s()},[s]),{copied:i,copy:(0,g.useCallback)(async e=>{let i=!1;try{i=await wu(e)}catch(e){i=!1,r&&r(e)}return i?(a(!0),s(),o.current=setTimeout(()=>{a(!1),o.current=null},t),n?.(e)):r&&!i&&r(Error(`Copy failed`)),i},[t,n,r,s]),reset:c}}var Eu=`@root`,Du=`pi-web-ui:rp-sizes`,Ou={files:4,widgets:1},ku=120,Au=56;function ju(e,t){return t?Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top):32}var Mu=`files`,Nu=[],Pu=()=>{};function Fu(e){let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n<0?``:n===0?`/`:t.slice(0,n)}function Iu(e){return e===Eu||e===`/`||/^[A-Za-z]:$/.test(e)}function Lu(e){return e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)}var Ru=(0,g.memo)(function({files:e,fileChanged:t,widgets:n,panelSend:r,onAttach:i,onPreview:a,onNotice:o,collapsible:s,onToggleCollapse:c,uiRightPanelTabs:l,uiContextFile:u,plugins:d,pluginsEpoch:f,send:p}){let m=Z(),h=d??Nu,_=Pa(`cwd`),v=Pa(`workspaceRoots`),y=Pa(`homeDir`),b=Pa(`desktopDir`),[x,S]=(0,g.useState)(``),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(!1),D=(0,g.useRef)(null),O=(0,g.useRef)(null),[k,A]=(0,g.useState)(()=>{try{return Po(localStorage.getItem(Du),Ou)}catch{return{...Ou}}});(0,g.useEffect)(()=>{try{localStorage.setItem(Du,JSON.stringify(k))}catch{}},[k]);let j=n.some(e=>e.lines.length>0),ee=(0,g.useCallback)(e=>{e.preventDefault();let t=D.current;if(!t)return;let n=e.currentTarget,r=e.clientY,i={above:k.files,below:k.widgets},a=Math.max(120,t.clientHeight-ju(t,O.current));n.classList.add(`dragging`),document.body.classList.add(`rp-resizing`);let o=e=>{let{above:t,below:n}=Fo({start:i,deltaPx:e.clientY-r,availablePx:a,totalWeight:i.above+i.below,minAbovePx:ku,minBelowPx:Au});A({files:t,widgets:n})},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),n.classList.remove(`dragging`),document.body.classList.remove(`rp-resizing`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},[k.files,k.widgets]),M=(0,g.useRef)(null),te=(0,g.useRef)(0),ne=(0,g.useCallback)(e=>{M.current=e,e&&(e.scrollTop=te.current)},[]),[P,F]=(0,g.useState)(null),re=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]);let ie=(0,g.useCallback)(e=>{F(e),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>F(null),1200)},[]),I=(0,g.useCallback)((e,t)=>{e&&wu(e).then(e=>{e?ie(t):o(`error`,m(`slashCopyFailed`))})},[ie,o,m]),ae=(0,g.useCallback)(e=>{if(!e)return _;if(/^[A-Za-z]:$/.test(e))return`${e}/`;if(e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e))return e;let t=_.replace(/\\/g,`/`).replace(/\/+$/,``);return t?`${t}/${e}`:e},[_]),L=(0,g.useCallback)(e=>!e||e===Eu?null:e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)?e:`${_.replace(/\\/g,`/`).replace(/\/+$/,``)}/${e}`,[_]),R=104857600,z=(0,g.useCallback)((e,t)=>{for(let n of t){if(n.size>R){o(`warning`,m(`fileTooLarge`,{name:n.name,size:R/1024/1024}));continue}let t=new FileReader;t.onload=()=>{let i=t.result,a=i.slice(i.indexOf(`,`)+1);a&&r({type:`upload_file`,dirPath:e,name:n.name,data:a})},t.readAsDataURL(n)}},[r,o,m]),B=(0,g.useRef)(null),[V,H]=(0,g.useState)(null),U=(0,g.useRef)(null),W=(0,g.useCallback)(()=>{let e=B.current?.project;e&&r({type:`set_cwd`,path:e.path})},[r]),oe=(0,g.useCallback)(()=>{U.current&&(U.current.value=``),U.current?.click()},[]),[G,se]=(0,g.useState)(null),[ce,K]=(0,g.useState)(null),[le,ue]=(0,g.useState)(``),[de,q]=(0,g.useState)(null),[J,fe]=(0,g.useState)(``),pe=(0,g.useCallback)((e,t)=>{tu(e,t).then(e=>{e.ok||e.cancelled||o(`error`,m(`downloadFailed`,{error:e.error===`FILE_NOT_FOUND`?m(`fileNotFoundShort`):e.error}))})},[o,m]),me=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&(q(null),ue(e.label),K(e.id))},[]),Y=(0,g.useCallback)(()=>{if(!ce)return;let e=le.trim();K(null),e&&r({type:`file_rename`,path:ce,newName:e})},[ce,le,r]),he=(0,g.useCallback)(e=>{let t=B.current?.dir??x;K(null),fe(``),q({dir:t,kind:e})},[x]),ge=(0,g.useCallback)(()=>{if(!de)return;let e=J.trim();q(null),e&&r({type:`file_create`,dir:de.dir,name:e,kind:de.kind})},[de,J,r]),_e=(e,t,n,r)=>(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:e,placeholder:m(`fileNamePlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>t(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing?n():e.key===`Escape`&&r()},onBlur:r}),ve=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&window.confirm(m(`fileDeleteConfirm`,{name:e.label}))&&(G?.src===e.id&&se(null),ce===e.id&&K(null),r({type:`file_delete`,path:e.id}))},[r,m,G,ce]),ye=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&r({type:`file_copy`,src:e.id,destDir:Fu(e.id)})},[r]),be=(0,g.useCallback)(e=>{let t=B.current?.target;t&&t.kind!==`list`&&!Iu(t.id)&&se({src:t.id,cut:e})},[]),xe=(0,g.useCallback)(()=>{if(!G)return;let e=B.current?.dir??x;G.cut?(r({type:`file_copy`,src:G.src,destDir:e,move:!0}),se(null)):r({type:`file_copy`,src:G.src,destDir:e})},[G,r,x]),Se=(0,g.useCallback)(()=>{r({type:`list_files`,path:x===``?void 0:x})},[r,x]),[we,Te]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(!we)return;let e=e=>{e.target?.closest(`.root-picker`)||Te(!1)},t=e=>{e.key===`Escape`&&Te(!1)};return window.addEventListener(`mousedown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e,!0),window.removeEventListener(`keydown`,t)}},[we]);let Ee=(0,g.useCallback)(e=>{r({type:`set_workspace_roots`,roots:e})},[r]),Oe=(0,g.useCallback)(()=>{let e=B.current?.target;if(!e||e.kind!==`dir`)return;let t=L(e.id);t&&!v.includes(t)&&Ee([...v,t])},[v,L,Ee]),ke=(0,g.useCallback)(e=>{z(B.current?.dir??x,Array.from(e.target.files??[]))},[z,x]),Ae=(0,g.useCallback)(e=>{let t=B.current?.target;switch(e.id){case`host:file-compress`:case`host:file-extract`:case`host:file-compress-download`:case`host:file-upload-folder`:{if(!t)break;let n=e.id===`host:file-compress`?`compress`:e.id===`host:file-extract`?`extract`:e.id===`host:file-compress-download`?`download`:`upload`;H({action:n,path:ae(t.id),dir:ae(n===`upload`?B.current?.dir??x:Fu(t.id))});break}case`host:file-open-project`:W();break;case`host:file-upload`:oe();break;case`host:file-add-root`:Oe();break;case`host:file-open`:t?.kind===`file`&&a(t.id,t.label);break;case`host:file-enter`:t?.kind===`dir`&&Ue(t.id);break;case`host:file-download`:t?.kind===`file`&&pe(t.id,t.label);break;case`host:file-reveal`:t&&r({type:`file_reveal`,path:t.id});break;case`host:file-open-default`:t?.kind===`file`&&r({type:`file_open_default`,path:t.id});break;case`host:file-attach-ref`:t?.kind===`file`&&i(t.id,t.label,`reference`);break;case`host:file-attach-folder`:t?.kind===`dir`&&i(t.id,t.label,`reference`,!0);break;case`host:file-new-file`:he(`file`);break;case`host:file-new-dir`:he(`dir`);break;case`host:file-paste`:xe();break;case`host:file-rename`:me();break;case`host:file-duplicate`:ye();break;case`host:file-cut`:be(!0);break;case`host:file-copy`:be(!1);break;case`host:file-copy-name`:t&&t.kind!==`list`&&I(t.label,`name:${t.id}`);break;case`host:file-copy-path`:t&&t.kind!==`list`&&I(ae(t.id),`path:${t.id}`);break;case`host:file-copy-rel`:t&&t.kind!==`list`&&I(t.id,`rel:${t.id}`);break;case`host:file-refresh`:Se();break;case`host:file-delete`:ve()}},[W,x,oe,Oe,a,i,I,ae,pe,he,xe,me,ye,be,Se,ve]),je=(0,g.useCallback)((e,t)=>{let n=t.kind===`dir`?L(t.id):null,r={target:t,dir:t.kind===`dir`?t.id:x,project:n?{path:n,name:t.label}:null},i=t.kind,a=i===`file`,o=i===`dir`,s=i===`list`,c=!s&&Iu(t.id),l=!s&&Lu(t.id),d=x===Eu,f=(u??[]).map(e=>{if(e.source!==`host`)return e;switch(e.id){case`host:file-upload-folder`:return d?{...e,hidden:!0}:e;case`host:file-compress`:case`host:file-compress-download`:return!s&&!c?e:{...e,hidden:!0};case`host:file-extract`:return a&&cu(t.label)?e:{...e,hidden:!0};case`host:file-upload`:return d?{...e,hidden:!0}:{...e,label:r.dir===x?m(`uploadToCurrentDir`):m(`uploadToFolder`)};case`host:file-open-project`:return n?e:{...e,hidden:!0};case`host:file-add-root`:return n&&n!==_&&!v.includes(n)?e:{...e,hidden:!0};case`host:file-open`:case`host:file-download`:case`host:file-open-default`:case`host:file-attach-ref`:return a?e:{...e,hidden:!0};case`host:file-reveal`:return!d&&t.id!==Eu?e:{...e,hidden:!0};case`host:file-enter`:case`host:file-attach-folder`:return o?e:{...e,hidden:!0};case`host:file-new-file`:case`host:file-new-dir`:return!a&&!d?e:{...e,hidden:!0};case`host:file-paste`:return!a&&!d&&G?e:{...e,hidden:!0};case`host:file-rename`:case`host:file-duplicate`:case`host:file-cut`:case`host:file-copy`:case`host:file-delete`:return!s&&!c?e:{...e,hidden:!0};case`host:file-copy-name`:case`host:file-copy-path`:return s?{...e,hidden:!0}:e;case`host:file-copy-rel`:return!s&&!l?e:{...e,hidden:!0};case`host:file-refresh`:return s?e:{...e,hidden:!0};default:return e}});ba(f).length!==0&&(e.preventDefault(),e.stopPropagation(),B.current=r,la({x:e.clientX,y:e.clientY,slot:`contextmenu.file`,target:t,entries:f,onHostAction:Ae}))},[u,x,L,m,Ae,_,v,G]),Me=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),Ne=(0,g.useCallback)(()=>{M.current?.querySelectorAll(`.file-item.drop-target`).forEach(e=>e.classList.remove(`drop-target`)),M.current?.classList.remove(`drop-root`)},[]),Pe=(0,g.useCallback)(e=>{if(Ne(),e==null)return;let t=M.current?.querySelector(`.file-item[data-path="${CSS.escape(e)}"]`);t?t.classList.add(`drop-target`):M.current?.classList.add(`drop-root`)},[Ne]),Fe=e=>{let t=e instanceof Element?e.closest(`.file-item`):null;return t?.dataset.type===`dir`?t.dataset.path??x:x},Ie=(0,g.useCallback)(()=>{let e=document.querySelector(`.app`);e&&e.dispatchEvent(new DragEvent(`dragleave`,{bubbles:!0}))},[]),Re=(0,g.useRef)(0),Be=(0,g.useRef)(void 0),Ve=(0,g.useCallback)((e,t)=>{let n=++Re.current;S(e),t?.silent||E(!0),r({type:`list_files`,path:e===``?void 0:e})||Re.current===n&&E(!1)},[r]),He=(0,g.useCallback)(e=>{let t=v.filter(t=>t!==e);Ee(t),(x===e||x.startsWith(`${e}/`))&&Ve(``)},[v,Ee,x,Ve]);(0,g.useEffect)(()=>{e&&e.path===x&&E(!1)},[e,x]),(0,g.useEffect)(()=>{if(_!==Be.current){Be.current=_,Ve(``,{silent:!0});return}let e=setInterval(()=>{document.visibilityState!==`hidden`&&Ve(x,{silent:!0})},1e4);return()=>clearInterval(e)},[_,x,Ve]),(0,g.useEffect)(()=>{t&&t.path===x&&Ve(x,{silent:!0})},[t,x,Ve]);let Ue=e=>Ve(e),We=()=>{e?.parent!==null&&e?.parent!==void 0&&Ve(e.parent)},Ge=(()=>{if(x===``||x===Eu)return[];let e=x.split(`/`).filter(e=>!!e&&e!==Eu);return x.startsWith(`/`)?[{label:`/`,path:`/`},...e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`)}))]:e.map((t,n)=>({label:e[n],path:e.slice(0,n+1).join(`/`)}))})(),qe=[];for(let e of l??[]){if(e.source===`host`||e.hidden||e.kind===`divider`)continue;let t=h.find(t=>t.id===e.source.slice(7));t&&qe.push({id:e.id,label:e.label,icon:e.icon,...e.iconSvg?{iconSvg:e.iconSvg}:{},hint:e.hint,pluginPage:{plugin:t,entry:e}})}let Je=(l??[]).some(e=>e.id===`host:right-files`&&e.hidden);return(0,X.jsxs)(`aside`,{className:`panel panel-right`,ref:D,children:[s&&c&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:m(`collapsePanel`),onClick:c,children:(0,X.jsx)(at,{})}),(0,X.jsx)(`div`,{ref:O,style:{display:`flex`,flexDirection:`column`,flex:j?`${k.files} 1 0`:`1 1 0`,minHeight:j?ku:0},children:(0,X.jsx)(Su,{storageKey:`rightpanel`,epoch:f??0,send:p??Pu,tabs:(e=>{let t=(l??[]).filter(e=>!e.hidden);if(t.length===0)return e;let n=new Map(t.map((e,t)=>[e.id,t])),r=e=>n.get(e===Mu?`host:right-files`:e)??1e9;return[...e].sort((e,t)=>r(e.id)-r(t.id))})([...Je?[]:[{id:Mu,label:m(`openFiles`),element:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`panel-crumbs`,children:[(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===``?`active`:``}`,onClick:()=>Ve(``),children:m(`rootDir`)}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===Eu?`active`:``}`,title:m(`computer`),onClick:()=>Ve(Eu),children:`💻`}),y!==``&&(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===y||x.startsWith(`${y}/`)?`active`:``}`,title:m(`homeDir`),onClick:()=>Ve(y),children:`🏠`}),b!==``&&(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===b||x.startsWith(`${b}/`)?`active`:``}`,title:m(`desktopDir`),onClick:()=>Ve(b),children:`🖥️`}),(0,X.jsx)(su,{text:m(`filesHelp`)}),v.length>0&&(0,X.jsxs)(`div`,{className:`root-picker`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`crumb root-picker-trigger`,"aria-haspopup":`menu`,"aria-expanded":we,title:m(`workspaceRoots`),onClick:()=>Te(e=>!e),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`root-picker-label`,children:m(`workspaceRoots`)}),(0,X.jsx)(`span`,{className:`set-count`,children:v.length+1}),`▾`]}),we&&(0,X.jsxs)(`div`,{className:`root-picker-menu`,role:`menu`,children:[(0,X.jsx)(`div`,{className:`root-picker-row`,children:(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:x===``?`root-picker-item active`:`root-picker-item`,title:_,onClick:()=>{Te(!1),Ve(``)},children:[m(`rootDir`),(0,X.jsx)(`span`,{className:`root-picker-path`,children:_})]})}),v.map(e=>(0,X.jsxs)(`div`,{className:`root-picker-row`,children:[(0,X.jsx)(`button`,{type:`button`,role:`menuitem`,className:x===e?`root-picker-item active`:`root-picker-item`,title:e,onClick:()=>{Te(!1),Ve(e)},children:(0,X.jsx)(`span`,{className:`root-picker-path`,children:e})}),(0,X.jsx)(`button`,{type:`button`,className:`root-picker-remove`,title:m(`removeWorkspaceRoot`),"aria-label":m(`removeWorkspaceRoot`),onClick:()=>He(e),children:(0,X.jsx)(N,{})})]},e)),(0,X.jsx)(`div`,{className:`root-picker-hint`,children:m(`workspaceRootsHint`)})]})]}),Ge.map(e=>(0,X.jsxs)(`span`,{className:`crumb-seg`,children:[(0,X.jsx)(ct,{}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${e.path===x?`active`:``}`,onClick:()=>Ve(e.path),children:e.label})]},e.path))]}),(0,X.jsxs)(`div`,{ref:ne,className:`panel-body`,onScroll:e=>{te.current=e.currentTarget.scrollTop},onContextMenu:e=>je(e,{id:x,kind:`list`,label:x===``?m(`rootDir`):x===Eu?m(`computer`):x}),onDragOver:e=>{Me(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,Ie(),Pe(Fe(e.target)))},onDragLeave:e=>{e.relatedTarget&&e.currentTarget.contains(e.relatedTarget)||Ne()},onDrop:e=>{if(Ne(),!Me(e))return;e.preventDefault(),e.stopPropagation(),Ie();let t=Array.from(e.dataTransfer?.files??[]);if(t.length===0){o(`warning`,m(`foldersNotSupported`));return}z(Fe(e.target),t)},onDragEnd:Ne,children:[(0,X.jsx)(`input`,{ref:U,type:`file`,multiple:!0,hidden:!0,onChange:ke}),V&&(0,X.jsx)(pu,{request:V,onClose:()=>H(null),onComplete:Se}),de&&(0,X.jsxs)(`div`,{className:`file-item dir`,children:[de.kind===`dir`?(0,X.jsx)(Le,{className:`file-icon`}):(0,X.jsx)(ze,{className:`file-icon`}),_e(J,fe,ge,()=>q(null))]}),T&&(0,X.jsx)(`div`,{className:`panel-empty`,children:m(`loading`)}),!T&&e&&e.path===x&&(0,X.jsxs)(X.Fragment,{children:[e.parent!=null&&(0,X.jsxs)(`button`,{type:`button`,className:`file-item dir`,onClick:We,children:[(0,X.jsx)(Le,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:`..`})]}),e.entries.map(e=>e.type===`dir`?(0,X.jsxs)(`div`,{className:`file-item dir${G?.cut&&G.src===e.path?` cut`:``}`,"data-type":`dir`,"data-path":e.path,onContextMenu:t=>je(t,{id:e.path,kind:`dir`,label:e.name}),children:[ce===e.path?_e(le,ue,Y,()=>K(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-dir-main`,onClick:()=>Ue(e.path),children:[(0,X.jsx)(Le,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach ref`,"data-tip":m(`linkFolderTip`),"aria-label":m(`linkFolderTip`),onClick:()=>i(e.path,e.name,`reference`,!0),children:(0,X.jsx)(De,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>I(e.name,`name:${e.path}`),children:P===`name:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(et,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>I(ae(e.path),`path:${e.path}`),children:P===`path:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(rt,{})})]},e.path):(0,X.jsxs)(`div`,{className:`file-item file${G?.cut&&G.src===e.path?` cut`:``}`,"data-type":`file`,"data-path":e.path,onContextMenu:t=>je(t,{id:e.path,kind:`file`,label:e.name}),children:[ce===e.path?_e(le,ue,Y,()=>K(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-name`,title:`${e.path} — ${m(`previewFile`)}`,onClick:()=>a(e.path,e.name),children:[(0,X.jsx)(ze,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name-text`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach download`,"data-tip":m(`downloadFile`),onClick:()=>pe(e.path,e.name),children:(0,X.jsx)(Ke,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach ref`,"data-tip":m(`referenceTip`),"aria-label":m(`referenceTip`),onClick:()=>i(e.path,e.name,`reference`),children:(0,X.jsx)(De,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>I(e.name,`name:${e.path}`),children:P===`name:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(et,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>I(ae(e.path),`path:${e.path}`),children:P===`path:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(rt,{})})]},e.path)),e.truncated&&(0,X.jsx)(`div`,{className:`panel-empty files-truncated`,children:m(`filesTruncated`)})]}),!T&&!e&&(0,X.jsx)(`div`,{className:`panel-empty`,children:m(`noFiles`)})]})]})}],...qe])})}),j&&(0,X.jsx)(`div`,{className:`rp-sash`,onPointerDown:ee,onDoubleClick:()=>A({...Ou}),title:m(`dragToResize`)}),j&&(0,X.jsx)(`div`,{className:`panel-widgets`,style:{flexGrow:k.widgets,minHeight:Au},children:n.filter(e=>e.lines.length>0).map(e=>(0,X.jsxs)(`div`,{className:`widget`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`widget-title widget-title-btn`,title:m(`widgetExpand`),onClick:()=>w(e.key),children:[(0,X.jsx)(`span`,{children:e.key}),(0,X.jsx)(Ce,{})]}),(0,X.jsx)(`pre`,{className:`widget-lines`,children:e.lines.join(`
327
+ It only opens after you confirm.`,settingsExtensions:`Extensions`,settingsUiPlugins:`UI plugins`,pluginListTab:`Plugin list`,noUiPlugins:`No UI plugins installed (<dataDir>/plugins/)`,pluginPhaseActive:`Active`,pluginPhaseDisabled:`Disabled`,pluginPhaseFailed:`Failed`,pluginPhaseIdle:`Frontend-only`,pluginRescan:`Rescan`,pluginRescanHint:`Re-scan the plugin directory (picks up new/fixed plugins; failure records are cleared and re-evaluated)`,dshPatches:`DSH user patches`,dshPatchesDesc:`Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.`,dshPatchesRescan:`Rescan`,dshPatchesRescanHint:`Re-scan the patch directory and restart the DSH runtime so new patches take effect`,dshPatchesEmpty:`No patch files yet`,dshPatchesPath:`Patch directory: `,dshPreset:`Agent preset`,dshPresetNewChat:`New chat with this preset`,dshPresetLocked:`Locked`,dshPresetBlankOnly:`Locked after the first message; blank sessions can switch`,dshPresetBroken:` (unavailable)`,dshPresetUser:`custom`,dshPresetDefaultTag:`default`,dshPresetMinimalNote:`Minimal: persistent shell only; host plugin tools and questionnaire unavailable`,dshDefaultPreset:`Default preset`,dshDefaultPresetDesc:`Preset for new chats; blank sessions can switch anytime, locked after the first message`,dshPresetUserNote:`Custom presets come from the user preset directory (trusted like shell access); compositions using bare package names cannot mount here (known limitation)`,"preset.standard":`Full access`,"preset.minimal":`Minimal`,"preset.code":`Code development`,"preset.reader":`Read-only analysis`,"preset.ask":`Chat only`,"preset.standardDesc":`All available tools and extension capabilities (default)`,"preset.minimalDesc":`Keeps only bash and read; plugin tools, skill catalog and terminal guidance are hidden too`,"preset.codeDesc":`Focused on reading, writing and running code (bash, read, edit, write, edit_soft); plugin tools and skill catalog are hidden too`,"preset.readerDesc":`Keeps only read-only tools and forbids writes; plugin tools are hidden too (read/write unknown, handled conservatively)`,"preset.askDesc":`No-tools Q&A: the model never calls a tool; plugin tools and skill catalog are hidden too`,dshPerm:`Permissions`,dshPermReadOnly:`Read Only`,dshPermReadOnlyDesc:`Read files and run read-only commands; writes are always denied, no prompts`,dshPermWorkspaceWrite:`Workspace Write`,dshPermWorkspaceWriteDesc:`Read/write inside the workspace, no prompts; out-of-scope operations are denied directly`,dshPermFullAccess:`Full access`,dshPermFullAccessDesc:`Sandbox off, unrestricted machine access; only for tasks you trust`,dshPermFullAccessTag:`risky`,dshPermCustom:`Custom`,dshPermConfirmFull:`Click again to confirm full access`,dshPermDefault:`Default permission for new chats`,dshPermDefaultDesc:`Initial permission for new chats; the current chat can switch live anytime, no restart`,uiPluginNoSource:`Installed manually — no recorded source, online update unavailable`,uiPluginPerms:`Permissions`,pluginDiagTitle:`Diagnostics`,pluginDiagShow:`Diagnostics`,pluginDiagHide:`Hide`,pluginLogTitle:`Runtime logs`,pluginLogShow:`Logs`,pluginLogHide:`Hide`,pluginLogLevel:`Level`,pluginLogAll:`All`,pluginLogEmpty:`No logs yet`,pluginLogClear:`Clear`,pluginDomNeed:`⚠ Requests full DOM access`,pluginDomDesc:`This plugin can freely read and write the page DOM (bypassing UI layout restrictions). Grant only to plugins from sources you trust; once granted its UI code can touch the topbar, composer and any page element.`,pluginDomGrant:`Grant DOM access`,pluginDomRevoke:`Revoke DOM access`,pluginDomGranted:`Full DOM access granted`,pluginSettingsTitle:`Configuration`,pluginSettingsShow:`Configure`,pluginSettingsHide:`Hide`,pluginSettingsSave:`Save plugin settings`,pluginSettingsSaving:`Saving…`,pluginSettingsReset:`Reset defaults`,pluginSettingsInherit:`Follow global default`,pluginSecretSet:`Set (stored encrypted, leave blank to keep)`,pluginSecretUnset:`Not set (stored encrypted)`,settingsPresets:`Presets`,settingsSubagentTemplates:`Subagent templates`,settingsSubagentTemplatesDesc:`Presets for spawned subagents (role system prompt + skills/extensions whitelist + optional model and thinking level). AI may pick a template (subagent_spawn template param) or spawn without one; disabled templates stay in the panel but are invisible to AI tools.`,noSubagentTemplates:`No subagent templates yet. AI can pick a template when spawning a subagent (role prompt + skills/extensions whitelist + optional model and thinking level), or spawn without a template param for default config.`,subagentTemplateNew:`New template`,subagentTemplateEdit:`Edit`,subagentTemplateClosed:`Disabled`,tplDefaultBadge:`Built-in`,subagentDefaultModelLabel:`Default subagent model`,subagentFollowMain:`Follow the main conversation's current model`,subagentDefaultModelHint:`Fallback model for all subagents (a template's own model and the subagent_spawn model param take priority); does not change the main conversation's model.`,subagentNoModels:`No usable models yet (configure a provider API key first) — subagents will follow the main conversation's model.`,subagentTemplateOffHint:`Disabled templates stay in the panel and can be re-enabled, but AI tools can't see or pick them`,subagentTemplateEnable:`Enable`,subagentTemplateDisable:`Disable`,tplNamePlaceholder:`Template name (referenced by AI via subagent_spawn's template param)…`,tplDescriptionPlaceholder:`Description (AI uses it to judge when to pick this template)…`,tplDescriptionEnPlaceholder:`English description (shown to AI under English UI; falls back to the description above)…`,tplPromptModeLabel:`System prompt mode`,tplModelLabel:`Model (empty = follow main conversation)`,tplThinkingLabel:`Thinking level`,tplThinkingFollowMain:`Follow the main conversation's current thinking level`,tplThinkingHint:`Empty = follow the main conversation's current thinking level (same idea as the model fallback); unsupported levels are clamped to the nearest one the model supports.`,tplSystemPromptLabel:`System prompt`,tplSystemPromptPlaceholder:`Template role system prompt… (may be empty in append mode)`,tplSystemPromptEnPlaceholder:`English system prompt… (used under English UI; falls back to the prompt above)`,tplWhitelistHint:`Whitelist: checked = the subagent only gets these; none checked = follow the main session settings`,tplSkillsLabel:`Skills whitelist`,tplExtensionsLabel:`Extensions whitelist`,tplSave:`Save template`,tplCancel:`Cancel edit`,tplDelete:`Delete template`,settingsScheduler:`Scheduled tasks`,schedulerDesc:`Put the agent on a schedule (dependency audits, test runs, morning briefings…): headless pseudo-client runs, no browser needed; notifies when done, history included.`,schedulerEmpty:`No scheduled tasks yet. Click “New task” above to schedule the first one: a 9 AM daily check or an hourly test run.`,schedulerNew:`New task`,schedulerEdit:`Edit`,schedulerDelete:`Delete`,schedulerRunNow:`Run now`,schedulerRunning:`Running…`,schedulerEnable:`Enable`,schedulerDisable:`Disable`,schedulerEnabled:`Enabled`,schedulerDisabled:`Disabled`,schedulerNamePlaceholder:`E.g. Daily dependency & health check…`,schedulerDescPlaceholder:`Description (optional): what this task does…`,schedulerCwdLabel:`Target project`,schedulerCwdPlaceholder:`/absolute/path/to/project…`,schedulerUseCurrentCwd:`Use current project`,schedulerKindLabel:`Schedule`,schedulerKindCron:`Cron expression`,schedulerKindInterval:`Fixed interval`,schedulerCronPlaceholder:`E.g. 0 9 * * * (daily 9:00 AM)`,schedulerPresetDaily:`Daily 9:00 AM`,schedulerPresetHourly:`Hourly on the hour`,schedulerPresetHalfHour:`Every 30 minutes`,schedulerPresetWorkday:`Weekdays 9:00 AM`,schedulerPresetMonday:`Mondays 9:00 AM`,schedulerPresetCustom:`Custom…`,schedulerIntervalMinutes:`Interval (minutes, min 1)`,schedulerPromptPlaceholder:`The task for the agent, e.g. audit dependencies and report upgrades…`,schedulerModelLabel:`Model (empty = default)`,schedulerThinkingLabel:`Thinking level (empty = default)`,schedulerCatchUp:`Catch up one missed run after restart`,schedulerCatchUpHint:`When checked, a trigger missed during downtime runs once at next startup; otherwise it is skipped.`,schedulerNextFire:`Next`,schedulerLastRun:`Last`,schedulerNeverRun:`Never ran`,schedulerHistory:`History`,schedulerManualBadge:`manual`,schedulerRunOk:`ok`,schedulerRunFail:`failed`,schedulerConfirmDelete:`Delete scheduled task “{name}”? Its history goes with it.`,schedulerSave:`Save task`,schedulerCancelEdit:`Cancel edit`,tplInherit:`Follow main session`,settingsEnabled:`Enabled`,settingsDisabled:`Disabled`,presetNamePlaceholder:`Preset name…`,saveAsPreset:`Save as preset`,applyPreset:`Apply`,deletePreset:`Delete preset`,noSkills:`No skills`,noExtensions:`No extensions`,noPresets:`No presets yet (tune your current settings, then enter a name above to save them as a preset)`,presetShare:`Share presets`,presetShareShareBtn:`Share preset`,presetShareImportBtn:`Import preset`,presetShareBrowseBtn:`Browse shared`,presetShareTabExport:`Export / share`,presetShareTabImport:`Import`,presetShareTabBrowse:`Browse shared`,presetShareSource:`Source`,presetShareSourceCurrent:`Current settings`,presetShareDescription:`Description`,presetShareDescriptionPlaceholder:`What is this preset good for? (optional)`,presetShareTags:`Tags`,presetShareTagsPlaceholder:`Comma separated, e.g. coding, minimal (optional)`,presetShareAuthor:`Author (optional)`,presetExportJson:`Export JSON`,presetExportDownload:`Download file`,presetShareSubmit:`Share to the community repo`,presetShareHint:`Creates a GitHub issue: with the gh CLI or a GitHub token it is submitted for you (the repo bot validates and commits it, and it shows up under "Browse shared" within minutes). With neither, a prefilled new-issue page opens — just hit Submit (for very large presets the JSON is copied to the clipboard instead, so you can paste it).`,presetShareSubmitting:`Submitting…`,presetShareOpenWebTitle:`Submit Issue on GitHub`,presetShareOpenWebBtn:`Open submission page in new window`,presetShareOpenIssueBtn:`View created issue`,presetShareCopyJson:`Copy preset JSON`,presetSharePopupBlocked:`If your browser blocked the popup, click the button below to open:`,presetShareBrowserCopied:`Submission page generated — just hit Submit (for large presets the JSON is on your clipboard, paste it)`,presetImportText:`Paste preset JSON`,presetImportTextPlaceholder:`Paste the exported JSON here (or drop a .json file)…`,presetImportPickFile:`Choose file`,presetImportFromUrl:`Import from URL`,presetImportUrlPlaceholder:`https://raw.githubusercontent.com/…/preset.json`,presetImportPreview:`Preview`,presetImportFields:`{n} fields will be written`,presetImportIgnored:`Unknown fields ignored: {list}`,presetImportRejected:`Dropped (wrong type): {list}`,presetImportReplaces:`A local preset with this name already exists — importing overwrites it`,presetImportApply:`Apply right after importing`,presetImportConfirm:`Import`,presetImportPick:`Import selectively: pick what to write`,presetImportSelectAll:`All`,presetImportSelectNone:`None`,presetImportAllSelected:`All selected`,presetImportNoneSelected:`Select at least one field to import`,presetImportPickHint:`Unchecked fields keep your current values; you can still tweak everything afterwards in Settings.`,presetGroupPrompt:`Prompts`,presetGroupTools:`Tools & switches`,presetGroupTerminal:`Terminal takeover`,presetGroupSkills:`Skills & extensions`,presetGroupAi:`Model behavior & dedicated prompts`,presetGroupUi:`Interface & interaction`,presetGroupEngine:`Engine defaults`,presetGroupOther:`Other`,presetImportImported:`Imported: {name}`,presetBrowseEmpty:`No presets in the shared repo yet`,presetBrowseLoading:`Loading community presets…`,presetBrowseSearch:`Search name / tag / author`,presetBrowseRefresh:`Refresh list`,presetBrowseCached:`List cached at {time} — hit refresh to re-fetch`,presetBrowseImport:`Import`,presetBrowseIssue:`Source issue`,presetBadgeTemplate:`Has template`,presetBadgeReview:`Has review prompt`,loadingSession:`Loading session…`,connectingServer:`Connecting to pi-web-ui server…`,localePacks:`Language packs`,localeGetMore:`Get more languages`,localeInstalled:`Installed`,localeInstall:`Download`,localeRemove:`Remove`,localeDownloading:`Downloading…`,localeRemoving:`Removing…`,localeInstallFailed:`Download failed: {error}`,localeListFailed:`Couldn't load language packs: {error}`,localeRemoveHint:`You can re-download it anytime`,wallpaperTitle:`Chat wallpaper`,wallpaperDesc:`Show a full-window background image (side panels, top and bottom bars included): a theme-provided image applies automatically, a URL here takes precedence; use dim and blur to keep text readable.`,wallpaperUrlPh:`Image URL (https://…, empty = off)`,wallpaperDim:`Dim`,wallpaperBlur:`Blur`,wallpaperClear:`Clear`,wallpaperUpload:`Upload image`,wallpaperUploadFailed:`Couldn't read the image (or it's too big) — try another one`,skillFullTextLabel:`Inject full skill text`,skillFullTextDesc:`Expand skill file contents inline into the system prompt (8KB per file, 32KB total cap); otherwise only a catalog is listed and the model reads files on demand`,skillFullTextShort:`Full`,delegateOpenSubagent:`Open subagent`,delegateSecTask:`Task`,delegateSecExpected:`Expected outcome`,delegateSecTools:`Required tools`,delegateSecMustDo:`Must do`,delegateSecMustNotDo:`Must not do`,delegateSecContext:`Context`,copyConversationId:`Copy conversation ID`,copyConversationPath:`Copy session file path`,copyConversationLink:`Copy link to session`,copyMessageLink:`Copy link to message`,quoteConversation:`Quote into composer (readable by the AI)`,quoteConversationShort:`Quote`,attachConversation:`Conversation reference: {name} (the AI reads it via conversation_read on demand)`,attachConversationShort:`conversation`,quoteSelection:`Quote`,quoteText:`Text quote`,quoteSource:`Source message: {id}`,removeQuote:`Remove quote`,presentOpenLocal:`Open locally`,presentMissing:`File missing or unreadable (moved, deleted, or outside the workspace?)`,presentEmpty:`Nothing to show`,presentAutoOpen:`Auto-open previews the AI presents`,presentAutoOpenDesc:`When the AI presents files with present_files and marks one as 'look at this first', open the file preview dialog automatically. Off (default): the cards stay inline and you open them with one click.`,presentFilesEnabledDesc:`Let the AI push artifacts (screenshots, charts, videos, reports, logs) into the chat as preview cards: images/videos/audio are shown inline, text gets an excerpt plus a one-click preview dialog, and every row carries open-locally / reveal-in-file-manager / download / copy-path actions. The auto-open switch lives on the Chat page.`,presentFilesOffHint:`Disabled: the AI can only tell you the file path — no cards, no open-locally buttons`,skillEnabledDesc:`Load skill bodies by name (the skill catalog stays in the system prompt): the full text is fetched only when a skill is actually needed, instead of making the model guess a path and call read.`,skillOffHint:`Disabled: the AI can no longer load skill bodies by name (the catalog in the prompt is unaffected)`,claimFilesEnabledDesc:`Declare which files you are about to edit so parallel runs in the same project can steer clear (advisory only — it never blocks edits). First-wins; claims expire automatically.`,claimFilesOffHint:`Disabled: the AI can no longer claim files (post-hoc touch reminders still work, only the up-front intent signal is gone)`,planUpdateEnabledDesc:`Structured task plan updates (Plan Mode / Step State Machine): allows the model to break complex tasks into steps and track progress in real time.`,planUpdateOffHint:`Disabled: AI can no longer update the structured plan board`,compactContextEnabledDesc:`Proactively compact context based on the current issue: allows AI to independently specify compression focus, retain core task context, drop irrelevant history, and control retention scope.`,compactContextOffHint:`Disabled: AI cannot proactively invoke context compaction (you can still use /compact or trigger auto-compaction)`,evalEnabledDesc:`Execute Python or JavaScript/TypeScript code in an isolated sandbox with persistent variables; ideal for calculations, data analysis, and algorithm verification (default-off to prevent tool crowding-out).`,evalOffHint:`Disabled: the AI cannot use the persistent code sandbox (can still run scripts via bash)`,patchToolEnabledDesc:`High-reliability structural patch tool (Hashline): line-anchored editing with 4-hex content hashes, syntactic AST block matching, and clipboard registers. Automatically attempts 3-way merge conflict recovery if files diverged.`,patchToolOffHint:`Disabled: AI falls back to basic string replacement via edit`,lspToolEnabledDesc:`Native Language Server Protocol (LSP) tool: IDE-grade semantic code intelligence (definition, references, hover, diagnostics, documentSymbol outline, read_symbol precise slicing, workspaceSymbol search, and cascade impact diagnostics). Multi-agent shared process pool with idle sleep, zero external dependencies.`,lspToolOffHint:`Disabled: AI cannot query LSP semantics and falls back to text search`,codemodeEnabledDesc:`Run JavaScript in a QuickJS WASM sandbox to batch tool calls and filter output: intermediate results never enter LLM context, keeping context concise (default off; requires capable model).`,codemodeOffHint:`Disabled: AI cannot run codemode scripts to batch call tools`,codemodeNestedCalls:`Nested tool calls`,codemodeScript:`JavaScript script`,codemodeFullOutput:`Full output file`,codemodeModeLabel:`Execution Mode`,codemodeModeHint:`In standard mode all tools are directly visible; in strict code mode tools are hidden from the model and must be invoked via sandbox scripts`,codemodeModeOn:`Standard Mode (on)`,codemodeModeOnly:`Strict Code Mode (only)`,codemodeInlineBudgetLabel:`Inline Budget`,codemodeInlineBudgetHint:`Estimated tokens the codemode prompt may spend on tool declarations directly (default: 3000)`,codemodeNestedApprovalBadge:`Nested Call`,codemodeNestedApprovalDesc:`This tool call was triggered by a background codemode sandbox script`,codemodeSavedImages:`Generated Images`,toolSearchEnabledDesc:`BM25-based tool discovery and activation: search and activate tools via natural language queries (ideal for large MCP toolsets to prevent context bloat).`,toolSearchOffHint:`Disabled: AI cannot use tool_search to discover tools`,toolSearchLoaded:`Activated tools`,toolInfoMenuLabel:`Show tool details`,toolInfoTitle:`Tool details`,toolInfoLoading:`Loading tool definition…`,toolInfoUnsupported:`This engine can't show tool definitions`,toolInfoMissing:`No definition found for this tool (it may come from an uninstalled plugin or an older version)`,toolInfoActive:`Enabled`,toolInfoInactive:`Disabled`,toolInfoSource:`Source`,toolInfoDescription:`Description`,toolInfoNoDescription:`This tool has no description`,toolInfoPromptSnippet:`Prompt snippet`,toolInfoGuidelines:`Prompt guidelines`,toolPromptEdit:`Edit description`,toolPromptEdited:`Description customized (click to edit)`,toolPromptHint:`Leave a field empty to use the tool's built-in text. The three fields map to the tool description the model sees, the one-line summary in the system prompt, and the behavioral guidelines.`,toolPromptDescription:`Tool description (how the model understands this tool)`,toolPromptSnippet:`Prompt snippet (the line in the system prompt's Available tools list)`,toolPromptGuidelines:`Behavioral guidelines (Guidelines section, one per line)`,toolPromptDefault:`Built-in text`,toolPromptReset:`Reset to default`,toolPromptSave:`Save`,toolPromptUnavailable:`No definition for this tool (engine unsupported, or the tool is uninstalled) — you can still fill in overrides, but they only apply once the tool exists.`,toolInfoParams:`Parameters`,toolInfoParamsNone:`This tool takes no parameters`,toolInfoSchemaDropped:`The parameter schema is too large and was omitted (see the raw JSON below)`,toolInfoRawSchema:`Raw JSON schema`,toolInfoRequired:`required`,toolInfoFootnote:`This is the tool's definition — not this call's arguments or result.`,elsewhereOfflineBadge:`Offline`,elsewhereOfflineTip:`The page holding this conversation is gone (tab or browser closed) but the run is still on the server — click this row twice to take it over here`},xn=[{code:`zh`,nativeName:`中文`},{code:`en`,nativeName:`English`}],Sn={};function Cn(e){return!e||typeof e.code!=`string`||!e.code||e.code===`zh`||e.code===`en`||!e.strings||typeof e.strings!=`object`?!1:(Sn[e.code]=e,!0)}function wn(e){delete Sn[e]}function Tn(e){return e===`zh`?`中文`:e.toUpperCase()}function En(e){return e===`zh`?`zh-CN`:e===`pt`?`pt-BR`:e}async function Dn(e){let t=await fetch(hn(dn(e)));if(!t.ok)throw Error(`HTTP ${t.status} for ${e}`);return await t.json()}var On=(0,g.createContext)(null);function kn(){try{return localStorage.getItem(vn)}catch{return null}}function An(){return _n(kn(),typeof navigator<`u`?navigator.languages:[],null)}function jn({children:e}){let[t,n]=(0,g.useState)(An),[r,i]=(0,g.useState)(0),a=(0,g.useRef)(t);a.current=t;let o=(0,g.useCallback)(e=>{n(e);try{localStorage.setItem(vn,e)}catch{}try{window.dispatchEvent(new CustomEvent(`pi-web-ui:locale`,{detail:e}))}catch{}},[]),s=(0,g.useCallback)(async()=>{let e,t=null;try{let n=await Dn(`/api/locales`);e=n.packs??[],t=n.defaultLocale??null}catch{return null}return await Promise.all(e.filter(e=>e.installed).map(async e=>{try{let t=await Dn(`/api/locales/${e.code}`);return Cn({code:t.code||e.code,nativeName:t.nativeName||e.nativeName,strings:t.strings}),!0}catch{return!1}})),i(e=>e+1),t},[]);(0,g.useEffect)(()=>{s().then(e=>{if(!kn()?.trim()){let t=_n(null,typeof navigator<`u`?navigator.languages:[],e);t!==a.current&&(a.current=t,n(t))}let t=a.current;if(t!==`zh`&&t!==`en`&&!Sn[t]){let t=_n(null,typeof navigator<`u`?navigator.languages:[],e,[`zh`,`en`]);a.current=t,n(t);try{localStorage.setItem(vn,t)}catch{}}})},[s]);let c=(0,g.useMemo)(()=>[...xn,...Object.values(Sn).map(e=>({code:e.code,nativeName:e.nativeName}))],[r]),l=(0,g.useCallback)((e,n)=>{let r=Sn[t]?.strings[e];r&&t!==`zh`&&t!==`ja`&&/[\u4e00-\u9fff]/.test(r)&&(r=void 0);let i=r??(t===`zh`?yn[e]:bn[e]);if(n)for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[t,r]);(0,g.useEffect)(()=>{document.documentElement.lang=En(t)},[t]);let u=(0,g.useMemo)(()=>({locale:t,setLocale:o,t:l,packs:c,reloadPacks:s}),[t,o,l,c,s]);return(0,X.jsx)(On.Provider,{value:u,children:e})}function Mn(){let e=(0,g.useContext)(On);if(!e)throw Error(`useI18n must be used within LanguageProvider`);return e}function Z(){return Mn().t}var Nn=[{kind:`question`,labelKey:`sound.question`,descKey:`sound.question.desc`},{kind:`done`,labelKey:`sound.done`,descKey:`sound.done.desc`},{kind:`start`,labelKey:`sound.start`,descKey:`sound.start.desc`},{kind:`error`,labelKey:`sound.error`,descKey:`sound.error.desc`},{kind:`approval`,labelKey:`sound.approval`,descKey:`sound.approval.desc`}];function Pn({settings:e,onChange:t,onPreview:n}){let r=Z(),i=n=>t({...e,...n});return(0,X.jsxs)(`div`,{className:`sound-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:r(`soundHeader`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(P,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:r(`enableSound`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>i({enabled:e.target.checked})})]}),Nn.map(({kind:t,labelKey:a,descKey:o})=>(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(a)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(o)})]}),(0,X.jsxs)(`span`,{className:`sound-right`,children:[(0,X.jsx)(`button`,{type:`button`,className:`sound-preview`,title:r(`preview`),disabled:!e.enabled,onClick:e=>{e.preventDefault(),n(t)},children:r(`preview`)}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e[t],disabled:!e.enabled,onChange:e=>i({[t]:e.target.checked})})]})]},t)),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`volume`)}),(0,X.jsx)(`input`,{type:`range`,min:0,max:100,step:5,value:e.volume,disabled:!e.enabled,onChange:e=>i({volume:Number(e.target.value)})}),(0,X.jsxs)(`span`,{className:`sound-vol-num`,children:[e.volume,`%`]})]})]})}function Fn(){let[e,t]=(0,g.useState)([]);return(0,g.useEffect)(()=>{if(!Kt())return;let e=window.speechSynthesis,n=()=>t(e.getVoices().map(e=>({voiceURI:e.voiceURI,lang:e.lang,name:e.name,localService:e.localService})));return n(),e.addEventListener?.(`voiceschanged`,n),()=>e.removeEventListener?.(`voiceschanged`,n)},[]),e}function In({settings:e,onChange:t,onPreview:n}){let r=Z(),i=Fn(),a=Kt(),o=n=>t({...e,...n});return(0,X.jsxs)(`div`,{className:`sound-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:r(`ttsHeader`)}),!a&&(0,X.jsx)(`div`,{className:`sound-desc tts-unavailable`,children:r(`ttsUnavailable`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master ${a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(P,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:r(`ttsEnable`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsEnableDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:!a,onChange:e=>o({enabled:e.target.checked})})]}),(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsAnnounce`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsAnnounceDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.announce,disabled:!e.enabled||!a,onChange:e=>o({announce:e.target.checked})})]}),(0,X.jsxs)(`label`,{className:`sound-row ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsReadReplies`)}),(0,X.jsx)(`span`,{className:`sound-desc`,children:r(`ttsReadRepliesDesc`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:e.readReplies,disabled:!e.enabled||!a,onChange:e=>o({readReplies:e.target.checked})})]}),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsRate`)}),(0,X.jsx)(`input`,{type:`range`,min:.5,max:2,step:.1,value:e.rate,disabled:!e.enabled||!a,onChange:e=>o({rate:Number(e.target.value)})}),(0,X.jsxs)(`span`,{className:`sound-vol-num`,children:[e.rate.toFixed(1),`×`]})]}),(0,X.jsxs)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:[(0,X.jsx)(`span`,{className:`sound-name`,children:r(`ttsVoice`)}),(0,X.jsxs)(`select`,{className:`set-input tts-voice-select`,value:e.voiceURI,disabled:!e.enabled||!a,onChange:e=>o({voiceURI:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:r(`ttsVoiceAuto`)}),i.map(e=>(0,X.jsxs)(`option`,{value:e.voiceURI,children:[e.name,` (`,e.lang,`)`,e.localService?``:` · ${r(`ttsVoiceOnline`)}`]},e.voiceURI))]})]}),(0,X.jsx)(`div`,{className:`sound-volume ${e.enabled&&a?``:`disabled`}`,children:(0,X.jsx)(`button`,{type:`button`,className:`sound-preview tts-preview`,disabled:!e.enabled||!a,onClick:()=>{if(e.voiceURI&&!qt(e.voiceURI,i,navigator.language)){t({...Ut,...e,voiceURI:``});return}n()},children:r(`preview`)})})]})}function Ln(e){let t=e??(typeof window>`u`?void 0:window);if(!t)return!1;if(t.piDesktop?.isDesktop===!0)return!0;let n=t.navigator?.userAgent;return typeof n==`string`&&n.includes(`Electron/`)}var Rn=()=>window.__piWebUiHost?.pageCall?.bind(window.__piWebUiHost),zn=null,Bn=0;function Vn(){return zn?.available===!0?zn.pages??[]:[]}function Hn(){Date.now()-Bn<5e3||Un().catch(()=>{})}async function Un(){if(Ln())return{available:!1,pages:[],desktop:!0,error:`桌面版不支持浏览器操作:窗口里没有 Chrome 扩展运行时,请改用系统浏览器打开同一个地址(网页版)`};let e=Rn();if(!e)return{available:!1,pages:[],error:`宿主页面桥不可用:这个 pi-web-ui 页面还没装上扩展桥(装/启用 page-picker 后刷新本页)`};try{let t=await e({op:`status`,timeoutMs:5e3});if(!t.ok)return{available:!1,pages:[],error:t.error??`扩展没有返回状态`};let n=t.result??{},r={available:n.installed===!0,aiControl:n.aiControl===!0,allowEval:n.allowEval===!0,pages:Array.isArray(n.pages)?n.pages:[]};return r.available&&(zn=r,Bn=Date.now()),r}catch(e){return{available:!1,pages:[],error:e instanceof Error?e.message:String(e)}}}function Wn(e){return e.length===1?e[0]:null}function Gn(e){return{path:e.origin,name:e.title?.trim()||e.origin,mode:`page`,key:`page:${e.origin}`}}async function Kn(){let e=Rn();if(!e)return!1;try{return(await e({op:`openOptions`,timeoutMs:5e3})).ok===!0}catch{return!1}}function qn(e=45e3){let[t,n]=(0,g.useState)(null),r=(0,g.useRef)(!0),i=(0,g.useCallback)(async e=>{let t=await Un();r.current&&(n(t),e&&!t.available&&setTimeout(()=>{r.current&&i(!1)},1500))},[]);return(0,g.useEffect)(()=>{r.current=!0,i(!0);let t=setInterval(()=>void i(!1),Math.max(5e3,e));return()=>{r.current=!1,clearInterval(t)}},[i,e]),{status:t,refresh:()=>void i(!0)}}var Jn=null,Yn=null,Xn=null,Zn=null,Qn=null;function $n(e){Zn=e}function er(e){Qn=e}function tr(e){return Zn?(Zn(e),!0):!1}function nr(e){return Qn?(Qn(e),!0):!1}function rr(e){Jn=e}function ir(e){Yn=e}function ar(e){Xn=e}function or(){return Xn?(Xn(),!0):!1}function sr(){return!!(Jn||Yn)}function cr(e){let t=typeof e?.text==`string`?e.text:``,n=Array.isArray(e?.attachments)?e.attachments:[],r=t.trim()!==``,i=n.length>0;return!r&&!i||r&&!Jn||i&&!Yn?!1:(i&&Yn?.(n),r&&Jn?.(t),!0)}function lr(){let e=Z(),{status:t,refresh:n}=qn(),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),s=(0,g.useRef)(null),c=t?.pages??[],l=t?.available===!0&&(c.length===0||t.aiControl===!1),u=Wn(c),d=e=>{o(e),s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(()=>o(null),2600)},f=t=>{let n=cr({attachments:[Gn(t)]});d(e(n?`browserControlCited`:`browserControlCiteFailed`))},p=()=>{i(!0),n()};return(0,X.jsxs)(`span`,{className:`bc-anchor`,children:[u?(0,X.jsxs)(`span`,{className:`browser-control-split`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`chip browser-control single${l?` attention`:``}`,"data-tip":e(`browserControlSingleTip`,{name:u.title||u.origin}),title:e(`browserControlSingleTip`,{name:u.title||u.origin}),onClick:()=>f(u),children:[(0,X.jsx)(ge,{size:14,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`bc-chip-label`,children:u.title||u.origin})]}),(0,X.jsx)(`button`,{type:`button`,className:`chip browser-control caret`,"data-tip":e(`browserControlOpenPanel`),title:e(`browserControlOpenPanel`),"aria-label":e(`browserControlOpenPanel`),onClick:p,children:`▾`})]}):(0,X.jsxs)(`button`,{type:`button`,className:`chip browser-control${l?` attention`:``}`,"data-tip":t?.error??e(l?`browserControlEmpty`:`browserControlTip`),title:t?.error??e(l?`browserControlEmpty`:`browserControlTip`),onClick:p,children:[(0,X.jsx)(ge,{size:14,"aria-hidden":!0}),(0,X.jsxs)(`span`,{children:[e(`browserControl`),c.length>0?` · ${c.length}`:``]})]}),a&&(0,X.jsx)(`span`,{className:`bc-flash`,children:a}),r&&(0,X.jsx)(ur,{status:t,onRefresh:n,onCite:f,onClose:()=>i(!1)})]})}function ur({status:e,onRefresh:t,onCite:n,onClose:r}){let i=Z(),[a,o]=(0,g.useState)(!1),s=e?.pages??[],c=async()=>{o(!0);try{await Kn()||t()}finally{o(!1)}};return(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:r,children:(0,X.jsxs)(`div`,{className:`modal browser-control-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(`button`,{type:`button`,className:`modal-close`,"aria-label":i(`close`),onClick:r,children:`✕`}),(0,X.jsxs)(`div`,{className:`modal-head`,children:[(0,X.jsx)(ge,{size:16,"aria-hidden":!0}),(0,X.jsx)(`h2`,{children:i(`browserControl`)})]}),(0,X.jsx)(`div`,{className:`modal-desc`,children:i(`browserControlTip`)}),e===null&&(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlChecking`)}),e?.available===!1&&!e.desktop&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlOffline`)}),e?.desktop===!0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlDesktop`)}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlDesktopLead`)}),(0,X.jsx)(`div`,{className:`bc-actions`,style:{marginTop:0},children:(0,X.jsx)(`a`,{className:`btn primary`,href:window.location.href,target:`_blank`,rel:`noreferrer noopener`,children:i(`browserControlOpenInBrowser`)})})]}),e?.available===!1&&!e.desktop&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlInstall`)}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlInstallLead`)}),(0,X.jsx)(`div`,{className:`bc-actions`,style:{marginTop:0},children:(0,X.jsx)(`a`,{className:`btn primary`,href:`https://github.com/xing-shuyin/pi-web-ui/releases/latest/download/page-picker-extension.zip`,target:`_blank`,rel:`noreferrer noopener`,children:i(`browserControlInstallDownload`)})}),(0,X.jsxs)(`ol`,{className:`bc-steps`,children:[(0,X.jsx)(`li`,{children:i(`browserControlInstallStep1`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep2`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep3`)}),(0,X.jsx)(`li`,{children:i(`browserControlInstallStep4`)})]})]}),e?.available===!0&&e.aiControl===!1&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlDisabled`)}),e?.available===!0&&s.length===0&&(0,X.jsx)(`div`,{className:`bc-note warn`,children:i(`browserControlEmpty`)}),s.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlPages`)}),(0,X.jsx)(`ul`,{className:`bc-pages`,children:s.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{className:`bc-title`,title:e.title,children:e.title}),(0,X.jsx)(`span`,{className:`bc-origin`,title:e.origin,children:e.origin}),(0,X.jsx)(`span`,{className:`bc-open${e.open?` on`:``}`,children:e.open?i(`browserControlPageOpen`):i(`browserControlPageClosed`)}),(0,X.jsx)(`button`,{type:`button`,className:`bc-cite`,title:i(`browserControlCiteTip`,{name:e.title||e.origin}),onClick:()=>n(e),children:i(`browserControlCite`)})]},e.origin))}),(0,X.jsx)(`div`,{className:`bc-note`,children:i(`browserControlCiteNote`)})]}),e?.desktop!==!0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`bc-section`,children:i(`browserControlExamples`)}),(0,X.jsxs)(`ul`,{className:`bc-examples`,children:[(0,X.jsx)(`li`,{children:i(`browserControlExample1`)}),(0,X.jsx)(`li`,{children:i(`browserControlExample2`)})]})]}),(0,X.jsxs)(`div`,{className:`bc-actions`,children:[e?.desktop!==!0&&(0,X.jsx)(`button`,{type:`button`,className:`primary`,disabled:a,onClick:()=>void c(),children:i(`browserControlOpenOptions`)}),(0,X.jsx)(`button`,{type:`button`,onClick:t,children:i(`browserControlRefresh`)})]})]})})}var dr=[`terminal_create`,`terminal_list`,`terminal_close`,`terminal_input`,`terminal_key`,`terminal_read`,`terminal_wait`],fr=[`subagent`],pr=`edit_soft`,mr=`delegate_task`,hr=`ask_user_question`,gr=`todo_list`,_r=`browser_page`,vr=`conversation_read`,yr=`skill`,br=`schedule`,xr=`eval`,Sr=`present_files`,Cr=`claim_files`,wr=`plan_update`,Tr=`compact_context`,Er=`patch`,Dr=`codemode`,Or=`tool_search`,kr=[...dr.map(e=>({name:e,group:`terminal`,defaultOn:!1,dshVisible:!0})),...fr.map(e=>({name:e,group:`subagent`,defaultOn:!0,dshVisible:!1})),{name:pr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`editSoftEnabledDesc`,offHintKey:`editSoftOffHint`},{name:mr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`delegateTaskEnabledDesc`,offHintKey:`delegateTaskOffHint`},{name:hr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`questionnaireEnabledDesc`,offHintKey:`questionnaireOffHint`},{name:_r,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`browserPageEnabledDesc`,offHintKey:`browserPageOffHint`},{name:vr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`conversationReadEnabledDesc`,offHintKey:`conversationReadOffHint`},{name:Cr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`claimFilesEnabledDesc`,offHintKey:`claimFilesOffHint`},{name:wr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`planUpdateEnabledDesc`,offHintKey:`planUpdateOffHint`},{name:Er,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`patchToolEnabledDesc`,offHintKey:`patchToolOffHint`},{name:`lsp`,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`lspToolEnabledDesc`,offHintKey:`lspToolOffHint`},{name:Sr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`presentFilesEnabledDesc`,offHintKey:`presentFilesOffHint`},{name:yr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`skillEnabledDesc`,offHintKey:`skillOffHint`},{name:xr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`evalEnabledDesc`,offHintKey:`evalOffHint`},{name:Dr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`codemodeEnabledDesc`,offHintKey:`codemodeOffHint`},{name:Or,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`toolSearchEnabledDesc`,offHintKey:`toolSearchOffHint`},{name:br,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`scheduleTaskEnabledDesc`,offHintKey:`scheduleTaskOffHint`},{name:Tr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`compactContextEnabledDesc`,offHintKey:`compactContextOffHint`},{name:gr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`todoListEnabledDesc`,offHintKey:`todoListOffHint`}],Ar=[`bash`,`read`,`edit`,`write`,`powershell`,`ls`,`grep`,`find`];new Set(kr.map(e=>e.name));var jr=[...kr.map(e=>e.name),...Ar];function Mr(e){let t=new Set(e);return jr.filter(e=>!t.has(e))}function Nr(e,t){let n=Array.from(e);if(!t||t===`standard`)return n;if(t===`ask`)return[];if(t===`minimal`)return n.filter(e=>e===`bash`||e===`read`);if(t===`code`){let e=new Set([`bash`,`read`,`edit`,`write`,`edit_soft`]);return n.filter(t=>e.has(t))}if(t===`reader`){let e=new Set([`write`,`edit`,`edit_soft`,`bash`,`powershell`,`terminal_create`,`terminal_input`,`terminal_close`,`terminal_key`,`codemode`]);return n.filter(t=>!e.has(t))}return n}function Pr(e){return Nr([yr],e).includes(yr)}var Fr=`pi-web-notify`,Ir={enabled:!1};function Lr(){try{let e=localStorage.getItem(Fr);if(!e)return{...Ir};let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:Ir.enabled}}catch{return{...Ir}}}function Rr(e){try{localStorage.setItem(Fr,JSON.stringify(e))}catch{}}function zr(){return typeof window<`u`&&`Notification`in window}function Br(){return zr()?null:typeof window<`u`&&window.isSecureContext===!1?`insecure`:`unsupported`}function Vr(e){let{screenX:t,screenY:n,outerWidth:r,outerHeight:i}=e;return Number.isFinite(t)&&Hr(t)||Number.isFinite(n)&&Hr(n)?!0:r>0&&r<=400&&i>0&&i<=40}function Hr(e){return e<=-1e4}function Ur(e){return!(e.visibility!==`visible`||e.minimized||!e.hasFocus||e.windows&&e.idleMs>12e4)}var Wr=Date.now(),Gr=!1;function Kr(){Wr=Date.now()}function qr(){return Math.max(0,Date.now()-Wr)}function Jr(){if(Gr||typeof window>`u`)return;Gr=!0;let e={passive:!0,capture:!0};for(let t of[`pointerdown`,`pointermove`,`keydown`,`wheel`,`touchstart`,`focus`,`scroll`])window.addEventListener(t,Kr,e);typeof document<`u`&&document.addEventListener(`visibilitychange`,Kr,e)}function Yr(){return typeof navigator>`u`?!1:/windows/i.test(navigator.userAgent??``)}function Xr(){return Jr(),typeof window>`u`||typeof document>`u`?{hasFocus:!0,visibility:`visible`,minimized:!1,idleMs:0,windows:!1}:{hasFocus:typeof document.hasFocus!=`function`||document.hasFocus(),visibility:document.visibilityState??``,minimized:Vr({screenX:window.screenX,screenY:window.screenY,outerWidth:window.outerWidth,outerHeight:window.outerHeight}),idleMs:qr(),windows:Yr()}}function Zr(){return zr()?Notification.permission:`denied`}async function Qr(){if(!zr())return`denied`;try{return await Notification.requestPermission()}catch{return`denied`}}function $r(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}function ei(e,t=!1){return{body:e,requireInteraction:t,icon:dn(`/icons/icon-192.png`),badge:dn(`/icons/icon-192.png`),data:{url:typeof location<`u`?location.href:dn(`/`)}}}async function ti(e,t,n=!1){if(!zr())return{path:`none`,error:`unsupported`};if(Notification.permission!==`granted`)return{path:`none`,error:`permission: ${Notification.permission}`};let r=ei(t,n),i;try{let t=await navigator.serviceWorker?.getRegistration();if(t?.active&&typeof t.showNotification==`function`)return await t.showNotification(e,r),{path:`sw`};i=t?`service worker not active`:`no service worker registration`}catch(e){i=$r(e)}try{return new Notification(e,r),{path:`page`,error:i}}catch(e){return{path:`none`,error:`${i}; page: ${$r(e)}`}}}async function ni(e,t){zr()&&(Ur(Xr())||Lr().enabled&&await ti(e,t))}var ri=!1;function ii(){let e=Z(),[t,n]=(0,g.useState)(Lr),[r,i]=(0,g.useState)(()=>Zr()),[a,o]=(0,g.useState)(null),s=Br(),c=s!==null,l=Yr();(0,g.useEffect)(()=>{let e=()=>i(Zr());return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]);let u=async e=>{let r={...t,enabled:e};if(n(r),Rr(r),e){let e=await Qr();if(i(e),e!==`granted`){let e={...r,enabled:!1};n(e),Rr(e)}}};return(0,X.jsxs)(`div`,{className:`sound-menu notify-menu`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:e(`notifyHeader`)}),(0,X.jsxs)(`label`,{className:`sound-row sound-master${c?` disabled`:``}`,children:[(0,X.jsxs)(`span`,{className:`sound-label`,children:[(0,X.jsx)(gt,{className:`sound-icon`}),(0,X.jsx)(`span`,{children:e(`notifyEnable`)})]}),(0,X.jsx)(`input`,{type:`checkbox`,checked:t.enabled&&!c,disabled:c,onChange:e=>u(e.target.checked)})]}),(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyEnableDesc`)}),s===`insecure`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyInsecure`)}),s===`unsupported`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyUnsupported`)}),!c&&r===`denied`&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyDenied`)}),!c&&l&&(0,X.jsx)(`div`,{className:`sound-hint`,children:e(`notifyWindowsHint`)}),ri]})}var ai=new Set([`svg`,`g`,`path`,`circle`,`rect`,`line`,`polyline`,`polygon`,`ellipse`,`use`,`defs`,`clipPath`,`linearGradient`,`radialGradient`,`stop`]),oi=new Set(`viewBox.xmlns.d.fill.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-dasharray.opacity.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.width.height.points.offset.stop-color.stop-opacity.fill-opacity.stroke-opacity.stroke-miterlimit.fill-rule.clip-rule.vector-effect.preserveAspectRatio.transform.clip-path.id.href.xlink:href.xmlns:xlink.gradientUnits.gradientTransform`.split(`.`)),si=new Set([`script`,`style`,`title`,`desc`,`foreignobject`]),ci=new Set([...ai].map(e=>e.toLowerCase())),Q=new Set([...oi].map(e=>e.toLowerCase()));function li(e){return ci.has(e.toLowerCase())}function ui(e){return Q.has(e.toLowerCase())}function di(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.length>8192||!/^<svg[\s>]/.test(t.startsWith(`<?xml`)?t.slice(t.indexOf(`?>`)+2).trimStart():t))return null;if(typeof DOMParser>`u`)return/<script[\s>]/i.test(t)||/\son\w+\s*=/i.test(t)||/javascript\s*:/i.test(t)?null:t;let n=new DOMParser().parseFromString(t,`image/svg+xml`);if(n.querySelector(`parsererror`))return null;let r=n.documentElement;if(r.tagName.toLowerCase()!==`svg`)return null;let i=e=>{for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();if(!li(e)){si.has(e)?t.remove():(i(t),t.replaceWith(...t.childNodes));continue}for(let e of Array.from(t.attributes)){let n=e.name.toLowerCase();(!ui(n)||/^on/i.test(n)||/^(javascript|data|vbscript):/i.test(e.value.trim()))&&t.removeAttribute(e.name)}i(t)}};for(let e of Array.from(r.attributes)){let t=e.name.toLowerCase();(!ui(t)||/^on/i.test(t))&&r.removeAttribute(e.name)}return i(r),new XMLSerializer().serializeToString(r)}function fi({icon:e,iconSvg:t,className:n}){let r=di(t);return r?(0,X.jsx)(`span`,{className:n??`plugin-icon-svg`,"aria-hidden":!0,dangerouslySetInnerHTML:{__html:r}}):e?(0,X.jsx)(`span`,{className:n?`${n} plugin-icon-glyph`:`plugin-icon-glyph`,"aria-hidden":!0,children:e}):null}var pi={projects:`host:lp-projects`,convs:`host:lp-running`,sessions:`host:lp-history`},mi=[`projects`,`convs`,`sessions`],hi=new Map(Object.keys(pi).map(e=>[pi[e],e])),gi=`plugin:`;function _i(e){return e.startsWith(gi)&&e.length>7}function vi(e){let t=[],n=new Set;for(let r of e??[]){let e=null,i,a=hi.get(r.id);a?e=a:r.source?.startsWith(`plugin:`)&&r.kind===`view`&&(e=`${gi}${r.id}`,i=r),e&&!n.has(e)&&(n.add(e),t.push({key:e,shown:!r.hidden,...i?{entry:i}:{}}))}for(let e of mi)n.has(e)||t.push({key:e,shown:!0});return t}function yi(e,t){return e.filter(e=>e.shown&&t(e.key)).map(e=>e.key)}function bi(e,t){let n=[];for(let r=0;r+1<e.length;r++){let i=e[r],a=e[r+1];!t(i)&&!t(a)&&n.push([i,a])}return n}function xi(e,t){let n={...t};if(!e)return n;try{let r=JSON.parse(e);if(!r||typeof r!=`object`||Array.isArray(r))return n;for(let[e,i]of Object.entries(r))(e in t||_i(e))&&typeof i==`number`&&Number.isFinite(i)&&i>0&&(n[e]=i)}catch{}return n}var Si=new Set([`view`,`action`,`badge`,`menu`,`page`,`organizer`,`divider`,`toggle`,`input`,`progress`,`select`]),Ci=new Set([`disabled`,`always`,`never`,`file.isDir`,`file.isFile`,`session.isRunning`,`message.hasSelection`]),wi=`topbar.primary,topbar.overflow,notice.actions,leftpanel.sections,leftpanel.projects.actions,leftpanel.project,leftpanel.running.actions,leftpanel.running,leftpanel.history.actions,leftpanel.history,leftpanel.sessions,chat.header,chat.empty,message.actions,goalbar.actions,composer.leading,composer.actions,rightpanel.tabs,terminal.toolbar,scm.toolbar,bottombar,file.preview.toolbar,contextmenu.topbar,contextmenu.message,contextmenu.session,contextmenu.project,contextmenu.file,contextmenu.toolcall,settings.pages,tasks.panel,modal.dialog,sidebar.left,sidebar.right`.split(`,`),Ti=wi.map(e=>({slot:e,cardinality:`list`}));function Ei(e){return Ti.find(t=>t.slot===e)?.cardinality??`list`}function Di(e,t){if(t===`list`)return{entries:[...e],conflicts:[]};let n=e.findIndex(e=>!e.hidden);if(n<0)return{entries:[...e],conflicts:[]};let r=e.filter((e,t)=>t!==n&&!e.hidden);return{entries:e.map((e,t)=>t===n||e.hidden?e:{...e,hidden:!0}),winner:e[n],conflicts:r}}var Oi=[{id:`host:lp-projects`,slot:`leftpanel.sections`,labelKey:`recentProjects`,icon:`folder`,kind:`action`,order:10},{id:`host:lp-running`,slot:`leftpanel.sections`,labelKey:`runningConversations`,icon:`activity`,kind:`action`,order:20},{id:`host:lp-history`,slot:`leftpanel.sections`,labelKey:`historySessions`,icon:`clock`,kind:`action`,order:30},{id:`host:brand`,slot:`topbar.primary`,labelKey:`brand`,kind:`badge`,order:1,group:`brand`},{id:`host:open-project`,slot:`topbar.primary`,labelKey:`openProject`,icon:`folder`,kind:`action`,order:3,group:`primary`},{id:`host:history`,slot:`topbar.primary`,labelKey:`openHistory`,icon:`menu`,kind:`action`,order:0,group:`panels`},{id:`host:files`,slot:`topbar.primary`,labelKey:`openFiles`,icon:`folder`,kind:`action`,order:97,group:`panels`,align:`end`},{id:`host:new-chat`,slot:`topbar.primary`,labelKey:`newChat`,icon:`plus`,kind:`action`,order:96,group:`primary`,align:`end`},{id:`host:new-ephemeral-chat`,slot:`topbar.primary`,labelKey:`newChatEphemeral`,icon:`chat`,kind:`action`,order:96.5,group:`primary`,align:`end`},{id:`host:chat`,slot:`topbar.primary`,labelKey:`chat`,icon:`chat`,kind:`view`,view:`chat`,order:20,group:`views`,align:`end`},{id:`host:terminal`,slot:`topbar.primary`,labelKey:`terminal`,icon:`terminal`,kind:`view`,view:`terminal`,order:21,group:`views`,align:`end`},{id:`host:git`,slot:`topbar.primary`,labelKey:`scmTab`,icon:`git`,kind:`view`,view:`git`,order:22,group:`views`,align:`end`},{id:`host:plugins`,slot:`topbar.primary`,labelKey:`pluginMenuTitle`,icon:`🧩`,kind:`action`,order:24,group:`views`,align:`end`},{id:`host:search`,slot:`topbar.primary`,labelKey:`searchGlobal`,icon:`search`,kind:`action`,order:40,group:`tools`,align:`end`},{id:`host:browser`,slot:`topbar.primary`,labelKey:`browserControl`,icon:`browser`,kind:`action`,order:41,group:`tools`,align:`end`,hidden:!0},{id:`host:tasks`,slot:`topbar.primary`,labelKey:`bgTasks`,icon:`layers`,kind:`action`,order:42,group:`tools`,align:`end`},{id:`host:settings`,slot:`topbar.primary`,labelKey:`settingsTitle`,icon:`settings`,kind:`action`,order:60,group:`system`,align:`end`},{id:`host:sound`,slot:`topbar.primary`,labelKey:`sound`,icon:`sound`,kind:`action`,order:70,group:`system`,hidden:!0,align:`end`},{id:`host:language`,slot:`topbar.primary`,labelKey:`language`,icon:`globe`,kind:`action`,order:80,group:`system`,hidden:!0,align:`end`},{id:`host:theme`,slot:`topbar.primary`,labelKey:`theme`,icon:`sun`,kind:`action`,order:82,group:`system`,hidden:!0,align:`end`},{id:`host:update`,slot:`topbar.primary`,labelKey:`update`,icon:`download`,kind:`action`,order:90,group:`system`,align:`end`,hidden:!0},{id:`host:github`,slot:`topbar.primary`,labelKey:`githubRepo`,icon:`github`,kind:`action`,order:200,group:`system`,align:`end`,hidden:!0},{id:`host:conn`,slot:`bottombar`,labelKey:`connected`,icon:`dot`,kind:`badge`,order:5,group:`status`},{id:`host:engine`,slot:`bottombar`,labelKey:`engineBadge`,icon:`cpu`,kind:`badge`,order:6,group:`status`},{id:`host:ctx`,slot:`bottombar`,labelKey:`context`,icon:`gauge`,kind:`badge`,order:10,group:`usage`},{id:`host:cost`,slot:`bottombar`,labelKey:`cumulativeCost`,icon:`coins`,kind:`badge`,order:11,group:`usage`},{id:`host:cache`,slot:`bottombar`,labelKey:`cacheHit`,icon:`database`,kind:`badge`,order:12,group:`usage`},{id:`host:msg-count`,slot:`bottombar`,labelKey:`messages`,icon:`message`,kind:`badge`,order:13,group:`usage`},{id:`host:plugin-status`,slot:`bottombar`,labelKey:`pluginStatus`,icon:`activity`,kind:`badge`,order:14,group:`status`},{id:`host:working`,slot:`bottombar`,labelKey:`working`,icon:`activity`,kind:`badge`,order:15,group:`status`},{id:`host:status-delegate`,slot:`bottombar`,labelKey:`delegateModeBadge`,icon:`eye`,kind:`badge`,order:16,group:`status`},{id:`host:host-metrics`,slot:`bottombar`,labelKey:`hostResources`,icon:`cpu`,kind:`badge`,order:19,group:`host`,align:`end`},{id:`host:cwd`,slot:`bottombar`,labelKey:`cwdTip`,icon:`folder`,kind:`action`,order:20,group:`context`,align:`end`},{id:`host:msg-reask`,slot:`message.actions`,labelKey:`reaskDirectly`,icon:`refresh`,kind:`action`,order:9},{id:`host:msg-edit-reask`,slot:`message.actions`,labelKey:`editReask`,icon:`edit`,kind:`action`,order:10},{id:`host:msg-fork`,slot:`message.actions`,labelKey:`forkSession`,icon:`branch`,kind:`action`,order:15},{id:`host:msg-rollback`,slot:`message.actions`,labelKey:`rollbackSession`,icon:`undo`,kind:`action`,order:16},{id:`host:msg-copy`,slot:`message.actions`,labelKey:`copyMessage`,icon:`copy`,kind:`action`,order:20},{id:`host:msg-copy-text`,slot:`message.actions`,labelKey:`copyText`,icon:`text`,kind:`action`,order:21},{id:`host:msg-copy-markdown`,slot:`message.actions`,labelKey:`copyMarkdown`,icon:`markdown`,kind:`action`,order:22},{id:`host:msg-copy-image`,slot:`message.actions`,labelKey:`copyImage`,icon:`image`,kind:`action`,order:23},{id:`host:msg-speak`,slot:`message.actions`,labelKey:`speakMsg`,icon:`volume`,kind:`action`,order:24},{id:`host:composer-upload`,slot:`composer.actions`,labelKey:`uploadFile`,icon:`upload`,kind:`action`,order:10,align:`start`},{id:`host:composer-templates`,slot:`composer.actions`,labelKey:`tpl.openPicker`,icon:`grid`,kind:`action`,order:110,align:`start`},{id:`host:composer-model`,slot:`composer.actions`,labelKey:`selectModel`,icon:`cpu`,kind:`action`,order:120,align:`start`},{id:`host:composer-thinking`,slot:`composer.actions`,labelKey:`thinkingLevel`,icon:`zap`,kind:`action`,order:130,align:`start`},{id:`host:composer-dsh-perm`,slot:`composer.actions`,labelKey:`dshPerm`,icon:`lock`,kind:`action`,order:140,align:`start`},{id:`host:composer-dsh-preset`,slot:`composer.actions`,labelKey:`dshPreset`,icon:`layers`,kind:`action`,order:150,align:`start`},{id:`host:composer-send`,slot:`composer.actions`,labelKey:`sendTip`,icon:`send`,kind:`action`,order:200,align:`end`},{id:`host:fp-md`,slot:`file.preview.toolbar`,labelKey:`showMarkdownPreview`,icon:`eye`,kind:`action`,order:10},{id:`host:fp-html`,slot:`file.preview.toolbar`,labelKey:`showHtmlPreview`,icon:`code`,kind:`action`,order:20},{id:`host:fp-edit`,slot:`file.preview.toolbar`,labelKey:`editFile`,icon:`edit`,kind:`action`,order:30},{id:`host:fp-wrap`,slot:`file.preview.toolbar`,labelKey:`enableWrap`,icon:`wrap`,kind:`action`,order:40},{id:`host:fp-zoom`,slot:`file.preview.toolbar`,labelKey:`zoomIn`,icon:`zoom`,kind:`action`,order:50},{id:`host:fp-ref`,slot:`file.preview.toolbar`,labelKey:`referenceTip`,icon:`link`,kind:`action`,order:70},{id:`host:fp-full`,slot:`file.preview.toolbar`,labelKey:`fullscreen`,icon:`maximize`,kind:`action`,order:80},{id:`host:fp-close`,slot:`file.preview.toolbar`,labelKey:`close`,icon:`x`,kind:`action`,order:90},{id:`host:goal-pill`,slot:`goalbar.actions`,labelKey:`goalBarTitle`,icon:`target`,kind:`action`,order:5},{id:`host:goal-set`,slot:`goalbar.actions`,labelKey:`goalBarSet`,icon:`check`,kind:`action`,order:10},{id:`host:goal-wizard`,slot:`goalbar.actions`,labelKey:`goalWizardBtn`,icon:`search`,kind:`action`,order:20},{id:`host:goal-lock`,slot:`goalbar.actions`,labelKey:`goalBarLocked`,icon:`lock`,kind:`action`,order:30},{id:`host:goal-plan`,slot:`goalbar.actions`,labelKey:`planMode`,icon:`list`,kind:`action`,order:25},{id:`host:goal-collapse`,slot:`goalbar.actions`,labelKey:`collapsePanel`,icon:`chevron-up`,kind:`action`,order:40},{id:`host:goal-model`,slot:`goalbar.actions`,labelKey:`goalBarReviewModel`,icon:`cpu`,kind:`action`,order:50},{id:`host:goal-rounds`,slot:`goalbar.actions`,labelKey:`goalBarMaxRounds`,icon:`hash`,kind:`action`,order:60},{id:`host:goal-execmodel`,slot:`goalbar.actions`,labelKey:`goalBarExecModel`,icon:`cpu`,kind:`action`,order:55},{id:`host:goal-openrole`,slot:`goalbar.actions`,labelKey:`goalBarOpenExec`,icon:`search`,kind:`action`,order:65},{id:`host:goal-clear`,slot:`goalbar.actions`,labelKey:`goalBarClear`,icon:`x`,kind:`action`,order:70},{id:`host:scm-changes`,slot:`scm.toolbar`,labelKey:`scmChanges`,icon:`file`,kind:`action`,order:10},{id:`host:scm-history`,slot:`scm.toolbar`,labelKey:`scmHistory`,icon:`clock`,kind:`action`,order:20},{id:`host:scm-refresh`,slot:`scm.toolbar`,labelKey:`scmRefreshTip`,icon:`refresh`,kind:`action`,order:30},{id:`host:scm-branch`,slot:`scm.toolbar`,labelKey:`scmSwitchBranch`,icon:`git`,kind:`action`,order:40},{id:`host:scm-switch`,slot:`scm.toolbar`,labelKey:`scmSwitch`,icon:`git`,kind:`action`,order:50},{id:`host:scm-push`,slot:`scm.toolbar`,labelKey:`scmPush`,icon:`upload`,kind:`action`,order:60},{id:`host:scm-pull`,slot:`scm.toolbar`,labelKey:`scmPull`,icon:`download`,kind:`action`,order:70},{id:`host:scm-input`,slot:`scm.toolbar`,labelKey:`scmCommitPlaceholder`,icon:`edit`,kind:`action`,order:80},{id:`host:scm-genmsg`,slot:`scm.toolbar`,labelKey:`scmGenMsg`,icon:`cpu`,kind:`action`,order:85},{id:`host:scm-commit`,slot:`scm.toolbar`,labelKey:`scmCommit`,icon:`check`,kind:`action`,order:90},{id:`host:scm-commit-all`,slot:`scm.toolbar`,labelKey:`scmCommitAll`,icon:`check`,kind:`action`,order:100},{id:`host:scm-term`,slot:`scm.toolbar`,labelKey:`terminal`,icon:`terminal`,kind:`action`,order:110},{id:`host:term-cmd-refresh`,slot:`terminal.toolbar`,labelKey:`rerun`,icon:`refresh`,kind:`action`,order:10},{id:`host:term-cmd-new`,slot:`terminal.toolbar`,labelKey:`newCommand`,icon:`plus`,kind:`action`,order:20},{id:`host:term-tab-new`,slot:`terminal.toolbar`,labelKey:`newTerminal`,icon:`plus`,kind:`action`,order:30},{id:`host:right-files`,slot:`rightpanel.tabs`,labelKey:`openFiles`,icon:`folder`,kind:`view`,view:`files`,order:10},{id:`host:conv-rename`,slot:`contextmenu.session`,labelKey:`renameSession`,icon:`edit`,kind:`action`,context:`session`,order:1},{id:`host:conv-pin`,slot:`contextmenu.session`,labelKey:`pinConversation`,icon:`pin`,kind:`action`,context:`session`,order:2},{id:`host:conv-takeover`,slot:`contextmenu.session`,labelKey:`takeoverConversation`,icon:`chat`,kind:`action`,context:`session`,order:5},{id:`host:conv-dismiss-subagents`,slot:`contextmenu.session`,labelKey:`dismissFinishedSubagents`,icon:`x`,kind:`action`,context:`session`,order:10},{id:`host:conv-force-dismiss`,slot:`contextmenu.session`,labelKey:`forceDismissConversation`,icon:`x`,kind:`action`,context:`session`,order:20},{id:`host:conv-persist`,slot:`contextmenu.session`,labelKey:`persistSubagent`,icon:`save`,kind:`action`,context:`session`,order:25},{id:`host:conv-copy-id`,slot:`contextmenu.session`,labelKey:`copyConversationId`,icon:`copy`,kind:`action`,context:`session`,order:30},{id:`host:conv-copy-path`,slot:`contextmenu.session`,labelKey:`copyConversationPath`,icon:`copy`,kind:`action`,context:`session`,order:40},{id:`host:conv-copy-link`,slot:`contextmenu.session`,labelKey:`copyConversationLink`,icon:`link`,kind:`action`,context:`session`,order:45},{id:`host:conv-quote`,slot:`contextmenu.session`,labelKey:`quoteConversation`,icon:`chat`,kind:`action`,context:`session`,order:50},{id:`host:file-open`,slot:`contextmenu.file`,labelKey:`fileOpenPreview`,icon:`open`,kind:`action`,context:`file`,order:11,group:`open`},{id:`host:file-enter`,slot:`contextmenu.file`,labelKey:`fileEnterDir`,icon:`folder`,kind:`action`,context:`file`,order:12,group:`open`},{id:`host:file-download`,slot:`contextmenu.file`,labelKey:`downloadFile`,icon:`download`,kind:`action`,context:`file`,order:13,group:`open`},{id:`host:file-compress`,slot:`contextmenu.file`,labelKey:`fileCompress`,icon:`file`,kind:`action`,context:`file`,order:16,group:`archive`},{id:`host:file-extract`,slot:`contextmenu.file`,labelKey:`fileExtract`,icon:`folder`,kind:`action`,context:`file`,order:17,group:`archive`},{id:`host:file-compress-download`,slot:`contextmenu.file`,labelKey:`fileCompressDownload`,icon:`download`,kind:`action`,context:`file`,order:18,group:`archive`},{id:`host:file-upload-folder`,slot:`contextmenu.file`,labelKey:`fileUploadFolder`,icon:`upload`,kind:`action`,context:`file`,order:25,group:`new`},{id:`host:file-open-project`,slot:`contextmenu.file`,labelKey:`openAsProject`,icon:`folder`,kind:`action`,context:`file`,order:14,group:`open`},{id:`host:file-add-root`,slot:`contextmenu.file`,labelKey:`addWorkspaceRoot`,icon:`folder`,kind:`action`,context:`file`,order:15,group:`open`},{id:`host:file-reveal`,slot:`contextmenu.file`,labelKey:`fileReveal`,icon:`folder`,kind:`action`,context:`file`,order:16,group:`open`},{id:`host:file-open-default`,slot:`contextmenu.file`,labelKey:`fileOpenDefault`,icon:`open`,kind:`action`,context:`file`,order:17,group:`open`},{id:`host:file-new-file`,slot:`contextmenu.file`,labelKey:`fileNewFile`,icon:`file`,kind:`action`,context:`file`,order:21,group:`new`},{id:`host:file-new-dir`,slot:`contextmenu.file`,labelKey:`fileNewDir`,icon:`folder`,kind:`action`,context:`file`,order:22,group:`new`},{id:`host:file-upload`,slot:`contextmenu.file`,labelKey:`uploadToFolder`,icon:`upload`,kind:`action`,context:`file`,order:23,group:`new`},{id:`host:file-paste`,slot:`contextmenu.file`,labelKey:`filePaste`,icon:`paste`,kind:`action`,context:`file`,order:24,group:`new`},{id:`host:file-attach-ref`,slot:`contextmenu.file`,labelKey:`referenceTip`,icon:`link`,kind:`action`,context:`file`,order:32,group:`chat`},{id:`host:file-attach-folder`,slot:`contextmenu.file`,labelKey:`linkFolderTip`,icon:`link`,kind:`action`,context:`file`,order:33,group:`chat`},{id:`host:file-rename`,slot:`contextmenu.file`,labelKey:`fileRename`,icon:`edit`,kind:`action`,context:`file`,order:41,group:`edit`},{id:`host:file-duplicate`,slot:`contextmenu.file`,labelKey:`fileDuplicate`,icon:`copy`,kind:`action`,context:`file`,order:42,group:`edit`},{id:`host:file-cut`,slot:`contextmenu.file`,labelKey:`fileCut`,icon:`cut`,kind:`action`,context:`file`,order:43,group:`edit`},{id:`host:file-copy`,slot:`contextmenu.file`,labelKey:`fileCopyEntry`,icon:`copy`,kind:`action`,context:`file`,order:44,group:`edit`},{id:`host:file-copy-name`,slot:`contextmenu.file`,labelKey:`copyName`,icon:`copy`,kind:`action`,context:`file`,order:51,group:`clipboard`},{id:`host:file-copy-path`,slot:`contextmenu.file`,labelKey:`copyPath`,icon:`copy`,kind:`action`,context:`file`,order:52,group:`clipboard`},{id:`host:file-copy-rel`,slot:`contextmenu.file`,labelKey:`fileCopyRelPath`,icon:`copy`,kind:`action`,context:`file`,order:53,group:`clipboard`},{id:`host:file-refresh`,slot:`contextmenu.file`,labelKey:`fileRefresh`,icon:`refresh`,kind:`action`,context:`file`,order:54,group:`clipboard`},{id:`host:file-delete`,slot:`contextmenu.file`,labelKey:`fileDelete`,icon:`trash`,kind:`action`,context:`file`,order:61,group:`danger`},{id:`host:msg-ctx-copy-markdown`,slot:`contextmenu.message`,labelKey:`copyMarkdown`,icon:`markdown`,kind:`action`,context:`message`,order:10,group:`copy`},{id:`host:msg-ctx-copy-text`,slot:`contextmenu.message`,labelKey:`copyText`,icon:`text`,kind:`action`,context:`message`,order:11,group:`copy`},{id:`host:msg-ctx-copy-image`,slot:`contextmenu.message`,labelKey:`copyImage`,icon:`image`,kind:`action`,context:`message`,order:12,group:`copy`},{id:`host:msg-ctx-copy-link`,slot:`contextmenu.message`,labelKey:`copyMessageLink`,icon:`link`,kind:`action`,context:`message`,order:13,group:`copy`},{id:`host:msg-ctx-reask`,slot:`contextmenu.message`,labelKey:`reaskDirectly`,icon:`refresh`,kind:`action`,context:`message`,order:19,group:`action`},{id:`host:msg-ctx-edit-reask`,slot:`contextmenu.message`,labelKey:`editReask`,icon:`edit`,kind:`action`,context:`message`,order:20,group:`action`},{id:`host:msg-ctx-fork`,slot:`contextmenu.message`,labelKey:`forkSession`,icon:`branch`,kind:`action`,context:`message`,order:21,group:`action`},{id:`host:msg-ctx-rollback`,slot:`contextmenu.message`,labelKey:`rollbackSession`,icon:`undo`,kind:`action`,context:`message`,order:22,group:`action`},{id:`host:msg-ctx-speak`,slot:`contextmenu.message`,labelKey:`speakMsg`,icon:`volume`,kind:`action`,context:`message`,order:23,group:`action`},{id:`host:tool-info`,slot:`contextmenu.toolcall`,labelKey:`toolInfoMenuLabel`,icon:`info`,kind:`action`,context:`toolcall`,order:10}],ki=`__view`,Ai=new Set([`host:settings`,`host:history`,`host:files`]),ji=new Set([`host:history`,`host:files`]);function Mi(e){return`${e}:${ki}`}function Ni(e){return e.source.startsWith(`plugin:`)?e.id===Mi(e.source.slice(7)):!1}function Pi(e,t,n){let r=Mi(t),i=(e?.hidden??[]).filter(e=>e!==r),a=(e?.shown??[]).filter(e=>e!==r);return n?a.push(r):i.push(r),{...e,hidden:i,shown:a}}function Fi(e,t){let n=t.map(Mi),r=new Set(n),i=(e?.order??[]).filter(e=>!r.has(e));return{...e,order:[...i,...n]}}var Ii=`host:brand`,Li=[`host:brand-logo`,`host:brand-name`];function Ri(e){if(!((e.hidden??[]).some(e=>Li.includes(e))||(e.shown??[]).some(e=>Li.includes(e))||(e.order??[]).some(e=>Li.includes(e))||Li.some(t=>e.align?.[t]!==void 0)||Li.some(t=>e.groups?.[t]!==void 0)||Li.some(t=>e.labels?.[t]!==void 0)||Li.some(t=>e.slots?.[t]!==void 0)))return e;let t=e=>{if(!e)return;let t=[];for(let n of e){let e=Li.includes(n)?Ii:n;t.includes(e)||t.push(e)}return t},n=(e,t)=>{if(!e)return;let n={};for(let[t,r]of Object.entries(e))Li.includes(t)||(n[t]=r);if(n[Ii]===void 0){let r=t?e[Li[0]]??e[Li[1]]:e[Li[1]]??e[Li[0]];r!==void 0&&(n[Ii]=r)}return n},r=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))Li.includes(n)||(t[n]=r);if(t[Ii]===void 0){let n=e[Li[0]]??e[Li[1]];n!==void 0&&(t[Ii]=n)}return t},i=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))Li.includes(n)||(t[n]=r);if(t[Ii]===void 0){let n=e[Li[0]]??e[Li[1]];n!==void 0&&(t[Ii]=n)}return t};return{...e,...e.hidden?{hidden:t(e.hidden)}:{},...e.shown?{shown:t(e.shown)}:{},...e.order?{order:t(e.order)}:{},...e.groups?{groups:n(e.groups,!0)}:{},...e.labels?{labels:n(e.labels,!1)}:{},...e.align?{align:r(e.align)}:{},...e.slots?{slots:i(e.slots)}:{}}}function zi(e){return e.map(e=>{if(e.view===!1)return e;let t=e.ui?.items??[];if(t.some(e=>e.id===`__view`))return e;let n={id:ki,slot:`topbar.primary`,label:e.name,...e.icon?{icon:e.icon}:{},...e.iconSvg?{iconSvg:e.iconSvg}:{},kind:`view`,view:`plugin:${e.id}`,order:23,align:`end`,hidden:!0};return{...e,ui:{items:[...t,n],arrange:e.ui?.arrange??[]}}})}function Bi(e){return typeof e==`string`&&wi.includes(e)}function Vi(e,t){return t?e.label:e.labelEn??e.label}function Hi(e,t){return t?e.hint??e.hintEn:e.hintEn??e.hint}function Ui(e,t,n,r,i){let a=`${e}#${r.id}`,o=Wi(a,t,n,r.children,i),s=Hi(r,i),c=Gi(r.options,i);return{id:a,slot:t,source:n,label:Vi(r,i),labelExplicit:!0,...r.icon?{icon:r.icon}:{},...r.iconSvg?{iconSvg:r.iconSvg}:{},...s?{hint:s}:{},kind:r.kind??`action`,...r.action?{action:r.action}:{},...r.view?{view:r.view}:{},...r.group?{group:r.group}:{},order:r.order??100,align:`start`,hidden:r.hidden??!1,...r.badge?{badge:r.badge}:{},...r.when?{when:r.when}:{},...c?{options:c}:{},...o.length>0?{children:o}:{},userOverrides:[],arrangedBy:[]}}function Wi(e,t,n,r,i){return r?.length?r.map((r,a)=>({entry:Ui(e,t,n,r,i),index:a})).sort((e,t)=>e.entry.order===t.entry.order?e.index-t.index:e.entry.order-t.entry.order).map(e=>e.entry):[]}function Gi(e,t){if(e?.length)return e.slice(0,32).map(e=>({value:e.value,label:t?e.label??e.labelEn??e.value:e.labelEn??e.label??e.value}))}function Ki(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?Math.min(100,Math.max(0,t)):0}function qi(e,t,n,r,i,a){let o=Wi(e,t,n,r.children,i),s=Hi(r,i),c=Ki(r.progress),l=Gi(r.options,i);return{id:e,slot:t,source:n,label:Vi(r,i),labelExplicit:!0,...r.icon?{icon:r.icon}:{},...r.iconSvg?{iconSvg:r.iconSvg}:{},...s?{hint:s}:{},kind:r.kind??(t===`settings.pages`?`page`:`action`),...r.action?{action:r.action}:{},...r.view?{view:r.view}:{},...r.group?{group:r.group}:{},order:r.order??100,align:r.align??`start`,hidden:r.hidden??!1,...r.badge?{badge:r.badge}:{},...typeof r.checked==`boolean`?{checked:r.checked}:{},...typeof r.value==`string`?{value:r.value}:{},...c===void 0?{}:{progress:c},...l?{options:l}:{},...r.when?{when:r.when}:{},...o.length>0?{children:o}:{},userOverrides:[],arrangedBy:[],seq:a}}function Ji(e,t){return[...e].sort((e,n)=>{let r=t.get(e.id),i=t.get(n.id);return r!==void 0||i!==void 0?r!==void 0&&i!==void 0?r-i:r===void 0?1:-1:e.order===n.order?e.seq-n.seq:e.order-n.order})}function Yi(e,t){let n=e.filter(e=>Ni(e)&&!t.has(e.id));if(n.length===0)return e;let r=e.filter(e=>!Ni(e)||t.has(e.id)),i=[`host:git`,`host:terminal`,`host:chat`].map(e=>r.findIndex(t=>t.id===e)).find(e=>e>=0)??-1,a=r.findIndex(e=>e.id===`host:plugins`),o=i+1;return a>=o&&(o=a),o=Math.max(0,Math.min(o,r.length)),[...r.slice(0,o),...n,...r.slice(o)]}function Xi(e,t){let n=t.locale===`zh`,r=new Set(t.disabledPlugins??[]),i=Ri(t.layout??{}),a=e=>{t.diagnostics?.push({level:e.level??`warn`,...e})},o=new Map,s=0;for(let e of Oi)o.set(e.id,{id:e.id,slot:e.slot,source:`host`,label:t.t(e.labelKey),labelKey:e.labelKey,...e.icon?{icon:e.icon}:{},kind:e.kind,...e.view?{view:e.view}:{},...e.group?{group:e.group}:{},order:e.order??100,align:e.align??`start`,hidden:e.hidden??!1,userOverrides:[],arrangedBy:[],seq:s++});for(let t of e){if(r.has(t.id)){a({pluginId:t.id,message:`plugin "${t.id}" is disabled by the user — its ${t.ui?.items?.length??0} UI item(s) are not rendered`});continue}if(t.error){a({level:`error`,pluginId:t.id,message:`plugin "${t.id}" failed to activate (${t.error}) — its UI items are not rendered`});continue}let e=`plugin:${t.id}`;for(let r of t.ui?.items??[]){if(!Bi(r.slot)){a({pluginId:t.id,entryId:r.id,message:`item "${t.id}:${r.id}" declares unknown slot "${String(r.slot)}" — dropped (valid slots: see docs/architecture-plugins.md)`});continue}if(r.slot===`leftpanel.sections`&&r.kind!==`view`){a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" targets leftpanel.sections: only kind="view" (a plugin section) is accepted — dropped`});continue}if(r.kind&&!Si.has(r.kind)&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" declares unknown kind "${r.kind}" — the render layer falls back to a plain button`}),Array.isArray(r.when))for(let e of r.when)Ci.has(e)||a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" declares when:"${e}" which the host does not know — it is ignored (the item still renders)`});else r.when!==void 0&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item "${t.id}:${r.id}" has a non-array "when" — ignored`});let i=`${t.id}:${r.id}`,c=o.get(i);c&&a({pluginId:t.id,entryId:r.id,slot:r.slot,message:`item id "${r.id}" is declared more than once — the later declaration wins (order/visibility are inherited from the first)`}),o.set(i,qi(i,r.slot,e,r,n,c?.seq??s++))}}for(let t of e)if(!(t.error||r.has(t.id)))for(let e of t.ui?.arrange??[]){let n=o.get(e.id);Qi(o,e,t.id),n||a({pluginId:t.id,entryId:e.id,message:`arrange target "${e.id}" does not exist — op ignored (is the providing plugin installed / not disabled?)`})}let c=new Map,l=(e,t)=>{let n=c.get(e)??[];n.includes(t)||n.push(t),c.set(e,n)};for(let e of i.hidden??[]){let t=o.get(e);t&&(t.hidden=!0,l(e,`hidden`))}for(let e of i.shown??[]){let t=o.get(e);t&&(t.hidden=!1,l(e,`hidden`))}for(let[e,t]of Object.entries(i.groups??{})){let n=o.get(e);n&&(n.group=t,l(e,`group`))}for(let[e,t]of Object.entries(i.align??{})){let n=o.get(e);!n||t!==`start`&&t!==`center`&&t!==`end`||(n.align=t,l(e,`align`))}for(let[e,t]of Object.entries(i.labels??{})){let n=o.get(e);n&&(n.label=t,n.labelExplicit=!0,l(e,`label`))}for(let[e,t]of Object.entries(i.slots??{})){let n=o.get(e);n&&Bi(t)&&n.slot!==t&&(n.movedFrom=n.movedFrom??n.slot,n.slot=t,l(e,`slot`))}for(let e of Ai){let t=o.get(e);t&&(i.slots?.[e]||(t.slot=`topbar.primary`),t.hidden=!1)}let u=new Map;(i.order??[]).forEach((e,t)=>{o.has(e)&&(u.has(e)||u.set(e,t),l(e,`order`))});for(let e of Object.values(pi)){let t=o.get(e);t&&t.slot!==`leftpanel.sections`&&(a({entryId:e,slot:t.slot,message:`"${e}" must stay in leftpanel.sections — the move is ignored`}),t.slot=`leftpanel.sections`,delete t.movedFrom)}let d=new Map;for(let e of wi)d.set(e,[]);for(let e of o.values())d.get(e.slot)?.push(e);let f={};for(let e of wi){let t=Ji(d.get(e)??[],u),n=Di(e===`topbar.primary`?Yi(t,u):t,Ei(e));if(n.winner&&n.conflicts.length>0)for(let t of n.conflicts)a({level:`error`,pluginId:t.source.startsWith(`plugin:`)?t.source.slice(7):void 0,entryId:t.id,slot:e,message:`slot "${e}" is single-cardinality; "${n.winner.id}" won and "${t.id}" was hidden`});f[e]=n.entries.map(e=>Zi(e,c.get(e.id)??[]))}return f}function Zi(e,t){let n={...e,userOverrides:t};return delete n.seq,n}function Qi(e,t,n){let r=e.get(t.id);if(!r)return;let i=!1;t.hide!==void 0&&(r.hidden=t.hide,i=!0),t.group!==void 0&&(r.group=t.group,i=!0),t.order!==void 0&&(r.order=t.order,i=!0),t.align!==void 0&&(r.align=t.align,i=!0),t.label!==void 0&&(r.label=t.label,r.labelExplicit=!0,i=!0),t.hint!==void 0&&(r.hint=t.hint,i=!0),t.icon!==void 0&&(r.icon=t.icon,i=!0),t.iconSvg!==void 0&&(r.iconSvg=t.iconSvg||void 0,i=!0),t.slot!==void 0&&Bi(t.slot)&&t.slot!==r.slot&&(r.movedFrom=r.movedFrom??r.slot,r.slot=t.slot,i=!0),i&&r.source!==`plugin:${n}`&&!r.arrangedBy.includes(n)&&r.arrangedBy.push(n)}function $i(e){let t=[],n=[],r=[];for(let i of e)i.align===`end`?r.push(i):i.align===`center`?n.push(i):t.push(i);return{start:t,center:n,end:r}}function ea(e,t){let n=e??{},r={},i=t===Ii?[t,...Li]:[t],a=(n.hidden??[]).filter(e=>!i.includes(e)),o=(n.shown??[]).filter(e=>!i.includes(e)),s=(n.order??[]).filter(e=>!i.includes(e));a.length>0&&(r.hidden=a),o.length>0&&(r.shown=o),s.length>0&&(r.order=s);let c=na(n.groups,t),l=na(n.labels,t),u=na(n.align,t),d=na(n.slots,t);if(t===Ii)for(let e of Li)c=na(c,e),l=na(l,e),u=na(u,e),d=na(d,e);return c&&(r.groups=c),l&&(r.labels=l),u&&(r.align=u),d&&(r.slots=d),n.topbarText!==void 0&&(r.topbarText=n.topbarText),n.sideDockFloat!==void 0&&(r.sideDockFloat=n.sideDockFloat),r}function ta(){return{}}function na(e,t){if(!e)return;let n={},r=!1;for(let[i,a]of Object.entries(e))i!==t&&(n[i]=a,r=!0);return r?n:void 0}var ra=new Set([`host:files`]);function ia(e,t){let n=e=>e===`center`?1:e===`end`?2:0;return[...e].sort((e,r)=>n(e.align)-n(r.align)||t(e.id)-t(r.id))}function aa(e,t,n,r,i=new Set){let a=new Set;if(!Number.isFinite(t)||t<=0)return a;let o=e.filter(e=>i.has(e.id)&&e.width>0).reduce((e,t)=>e+t.width+n,0),s=Math.max(0,t-Math.max(0,r)-o),c=0,l=!1;for(let t of e){if(!(t.width>0)||i.has(t.id))continue;let e=t.width+n;if(l||c+e>s){l=!0,a.add(t.id);continue}c+=e}return a}var oa=null,sa=new Set;function ca(){for(let e of sa)e()}function la(e){oa={x:Number.isFinite(e.x)?e.x:0,y:Number.isFinite(e.y)?e.y:0,slot:e.slot,target:e.target??{id:``},entries:Array.isArray(e.entries)?e.entries:[],...typeof e.onHostAction==`function`?{onHostAction:e.onHostAction}:{}},ca()}function ua(){oa!==null&&(oa=null,ca())}function da(e){return sa.add(e),()=>{sa.delete(e)}}function fa(){return oa}function pa(){return(0,g.useSyncExternalStore)(da,fa,fa)}function ma(e){return Number.isFinite(e)?e:0}function ha(e,t,n,r,i,a){let o=Math.max(0,ma(n)),s=Math.max(0,ma(r)),c=Math.max(8,ma(i)-o-8),l=Math.max(8,ma(a)-s-8);return{x:Math.min(Math.max(8,ma(e)),c),y:Math.min(Math.max(8,ma(t)),l)}}function ga(e,t){let n=String(t?.kind??``);if(e===`contextmenu.file`)return{"file.isDir":n===`dir`||n===`list`&&t?.id!==`@root`,"file.isFile":n===`file`};if(e===`contextmenu.session`)return{"session.isRunning":n===`running`};if(e===`contextmenu.message`){let e=!1;try{let t=window.getSelection?.();e=!!t&&!t.isCollapsed&&t.toString().trim().length>0}catch{e=!1}return{"message.hasSelection":e}}return{}}function _a(e,t){if(!Array.isArray(e)||e.length===0)return!1;for(let n of e){if(typeof n!=`string`||!n)continue;let e=n.trim();if(e===`disabled`||e===`never`)return!0;if(e!==`always`){if(e.startsWith(`!`)){let n=e.slice(1).trim();if(!n)continue;if(!t||t[n]!==!0)return!0;continue}if(t&&t[e]===!1)return!0}}return!1}function va(e,t){return!e||_a(e.when,t)}function ya(e){let t=new Map;return{items:(Array.isArray(e)?e:[]).map(e=>{if(!e||e.kind!==`select`||!e.options?.length||e.children?.length)return e;let n=e.options.map((t,n)=>({id:`${e.id}#${n}`,slot:e.slot,source:e.source,label:t.label,kind:`action`,order:100,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}));return n.forEach((n,r)=>t.set(n.id,{parent:e,value:e.options[r].value})),{...e,kind:`menu`,children:n}}),selectParents:t}}function ba(e){if(!Array.isArray(e)||e.length===0)return[];let t=e.filter(e=>e&&e.hidden!==!0),n=t.filter(e=>e.kind!==`divider`),r=new Map,i=new Map;n.forEach((e,t)=>{let n=e.group??``;r.has(n)||r.set(n,t);let a=Number.isFinite(e.order)?e.order:100,o=i.get(n);(o===void 0||a<o)&&i.set(n,a)});let a=[...r.keys()].sort((e,t)=>{let n=i.get(e)??100,a=i.get(t)??100;return n===a?(r.get(e)??0)-(r.get(t)??0):n-a}),o=new Map(a.map((e,t)=>[e,t])),s=new Map;n.forEach((e,t)=>s.set(e,t));let c=[...n].sort((e,t)=>{let n=o.get(e.group??``)??0,r=o.get(t.group??``)??0;if(n!==r)return n-r;let i=Number.isFinite(e.order)?e.order:100,a=Number.isFinite(t.order)?t.order:100;return i===a?(s.get(e)??0)-(s.get(t)??0):i-a}),l=new Map;t.forEach((e,n)=>{if(e.kind!==`divider`)return;let r=t.slice(n+1).find(e=>e.kind!==`divider`);if(!r)return;let i=l.get(r)??[];i.push(e),l.set(r,i)});let u=[];for(let e of c){for(let t of l.get(e)??[])u.push(t);u.push(e)}return u}function xa(e){let t=[],n=null,r=!1;return e.forEach((e,i)=>{if(!e||e.kind===`divider`){r=!0;return}let a=e.group??``;n!==null&&(r||a!==n)&&t.push({kind:`sep`,key:`sep:${i}`}),t.push({kind:`item`,key:`${e.id}#${i}`,index:i,entry:e}),n=a,r=!1}),t}function Sa(e,t){return!e||e.kind===`divider`||e.hidden===!0?!1:!va(e,t)}function Ca(e,t,n,r){let i=Array.isArray(e)?e.length:0;if(i===0)return-1;let a=n>=0?1:-1,o=Number.isFinite(t)?Math.trunc(t):-1;(o<0||o>=i)&&(o=a>0?-1:i);for(let t=0;t<i;t++)if(o=(o+a+i)%i,Sa(e[o],r))return o;return-1}var wa={menu:`☰`,folder:`📁`,plus:`+`,chat:`💬`,terminal:`▙`,git:`⎇`,search:`🔍`,browser:`🌐`,layers:`🗂`,settings:`⚙`,sound:`🔊`,globe:`🌍`,sun:`☀`,download:`⤓`,github:`⌗`,x:`✕`,upload:`⬆`,copy:`⧉`,cut:`✂`,paste:`📋`,trash:`🗑`,file:`📄`,open:`↗`,refresh:`⟳`,link:`🔗`,edit:`✎`,dot:`●`,info:`ⓘ`,cpu:`▣`,gauge:`▤`,coins:`◉`,database:`▥`,message:`✉`,activity:`〜`,markdown:`📄`,text:`≡`,image:`🖼`,branch:`⚚`,undo:`↺`,pin:`📌`,volume:`🔊`};function Ta(e){let t=(e??``).trim();return t?wa[t.toLowerCase()]||(/[^\p{L}\p{N}\s]/u.test(t)&&t.length<=4?t:``):``}var Ea={engine:`pi`,managed:!1,status:`connecting`,ready:!1,cwd:``,workspaceRoots:[],homeDir:``,desktopDir:``},Da=new Set;function Oa(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n])}function ka(e,t){return e.engine===t.engine&&e.managed===t.managed&&e.appVersion===t.appVersion&&e.serverVersion===t.serverVersion&&e.status===t.status&&e.ready===t.ready&&e.cwd===t.cwd&&Oa(e.workspaceRoots,t.workspaceRoots)&&e.homeDir===t.homeDir&&e.desktopDir===t.desktopDir&&Oa(e.tabs,t.tabs)&&e.service?.name===t.service?.name&&e.service?.supervisor===t.service?.supervisor}function Aa(e){let t={...Ea,...e};if(!ka(Ea,t)){Ea=t;for(let e of Da)e()}}function ja(e){return Da.add(e),()=>{Da.delete(e)}}function Ma(){return Ea}function Na(){return(0,g.useSyncExternalStore)(ja,Ma,Ma)}function Pa(e){return(0,g.useSyncExternalStore)(ja,()=>Ea[e],()=>Ea[e])}function Fa(){return Pa(`engine`)===`dsh`}function Ia(){return Pa(`managed`)}function La(){return Pa(`service`)}var Ra=null;function za(e){Ra=e}var $=e=>Ra?Ra(e):!1,Ba=new Set;function Va(e){return Ba.add(e),()=>{Ba.delete(e)}}function Ha(e){for(let t of Ba)try{t(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function Ua(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function Wa(e){return!!(e&&e.startsWith(`ssh://`))}function Ga(e){if(!Wa(e))return null;let t=/^ssh:\/\/([^@]+)@([^:]+):(\d+)(\/.*)$/.exec(e);return t?{username:t[1],host:t[2],port:parseInt(t[3],10),remotePath:t[4]}:null}var Ka=1;function qa(e){let t=`probe_${Date.now()}_${Ka++}`;return new Promise(n=>{let r=Va(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===t&&(r(),n({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall}))});$({type:`remote_ssh_probe`,reqId:t,params:e})||(r(),n({ok:!1,error:`WebSocket 连接不可用,请稍候重试`}))})}function Ja(e,t){let n=`listdir_${Date.now()}_${Ka++}`;return new Promise(r=>{let i=Va(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});$({type:`remote_ssh_list_dir`,reqId:n,connectionId:e,path:t})||(i(),r({ok:!1,connectionId:e,path:t||`/`,items:[],error:`WebSocket 连接不可用`}))})}function Ya(e,t){let n=`install_${Date.now()}_${Ka++}`;return new Promise(r=>{let i=Va(e=>{e.type===`remote_ssh_install_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});$({type:`remote_ssh_install_tools`,reqId:n,connectionId:e,tools:t})||(i(),r({ok:!1,connectionId:e,tool:t[0]||``,error:`WebSocket 连接不可用`}))})}function Xa(){let e=`profiles_${Date.now()}_${Ka++}`;return new Promise(t=>{let n=Va(r=>{r.type===`remote_ssh_profiles_result`&&r.reqId===e&&(n(),t(r.profiles))});$({type:`remote_ssh_list_profiles`,reqId:e})||(n(),t([]))})}function Za(e){$({type:`remote_ssh_delete_profile`,name:e})}var Qa=`@root`,$a=e=>e.endsWith(`/`)?e:e+`/`;function eo(e,t){let n=t.trim(),r=e.replace(/\\/g,`/`);return r.endsWith(`/`)?r+n:(/^[A-Za-z]:$/.test(r),r+`/`+n)}function to(e){let t=e.trim();return!(!t||t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`))}var no=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;if(t===`@root`||t===`/`)return null;let n=t.lastIndexOf(`/`);if(n<0)return/^[A-Za-z]:$/.test(t)?Qa:null;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?r+`/`:r};function ro({currentCwd:e,pathCompletions:t,workspaceRoots:n,onClose:r,onSelectDirectory:i,mode:a=`folder`,onCreateProject:o,className:s,backdropClassName:c,role:l,ariaLabel:u}){let d=Z(),[f,p]=(0,g.useState)(()=>Wa(e)?`remote`:`local`),[m,h]=(0,g.useState)(``),[_,v]=(0,g.useState)(``),[y,b]=(0,g.useState)(!1),[x,S]=(0,g.useState)(``),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(-1),D=(0,g.useRef)(null),O=(0,g.useRef)(null),[k,A]=(0,g.useState)([]),[j,ee]=(0,g.useState)(``),[M,te]=(0,g.useState)(`22`),[ne,P]=(0,g.useState)(``),[F,re]=(0,g.useState)(`password`),[ie,I]=(0,g.useState)(``),[ae,R]=(0,g.useState)(`~/.ssh/id_rsa`),[z,B]=(0,g.useState)(!0),[V,H]=(0,g.useState)(``),[U,W]=(0,g.useState)(!1),[oe,G]=(0,g.useState)(null),[se,K]=(0,g.useState)(null),[le,ue]=(0,g.useState)(null),[de,q]=(0,g.useState)(null),[J,fe]=(0,g.useState)([]),[pe,me]=(0,g.useState)(!1),[Y,he]=(0,g.useState)(`/`),[ge,_e]=(0,g.useState)(`/`),[ve,ye]=(0,g.useState)([]),[be,xe]=(0,g.useState)(!1),Se=t.filter(e=>e.type===`dir`);(0,g.useEffect)(()=>{if(Wa(e)){let t=Ga(e);t&&(ee(t.host),te(String(t.port)),P(t.username),he(t.remotePath),_e(t.remotePath))}else{let t=(e||``).replace(/\\/g,`/`);h(t),v(t)}b(!1),S(``),w(null),E(-1)},[e]),(0,g.useEffect)(()=>{f===`remote`&&Xa().then(e=>A(e))},[f]),(0,g.useEffect)(()=>{let e=requestAnimationFrame(()=>{D.current?.focus()});return()=>cancelAnimationFrame(e)},[f]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(y?(b(!1),S(``),w(null)):r())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,r]),(0,g.useEffect)(()=>{if(f!==`local`)return;let e=setTimeout(()=>{$({type:`complete_path`,path:$a(m)})},60);return()=>clearTimeout(e)},[m,f]),(0,g.useEffect)(()=>{if(f!==`local`||_===m)return;let e=setTimeout(()=>{$({type:`complete_path`,path:_})},150);return()=>clearTimeout(e)},[_,m,f]);let Ce=e=>{let t=e.trim();t&&t!==`@root`&&i(t)},we=()=>{let e=x.trim();if(e){if(a===`project`){if(!to(e)){w(d(`invalidProjectName`));return}let t=eo(m,e);o?.(t),b(!1),S(``),w(null),r()}else $({type:`make_dir`,path:`${$a(m)}${e}`}),setTimeout(()=>{$({type:`complete_path`,path:$a(m)})},80),S(``),b(!1)}},Te=e=>{if(e.key===`Escape`)e.stopPropagation(),y?(b(!1),S(``),w(null)):r();else if(e.key===`Enter`&&!e.nativeEvent.isComposing)Ce(_);else if(e.key===`Tab`){if(Se.length===0)return;e.preventDefault();let t=T>=0?(T+1)%Se.length:0;E(t),v(Se[t].path),h(Se[t].path)}},Ee=async e=>{let t=(e?.host??j).trim(),n=e?.port??(parseInt(M,10)||22),r=(e?.username??ne).trim();if(!t||!r){G(`请填写主机地址和用户名`);return}W(!0),G(null);let i=await qa({host:t,port:n,username:r,auth:e?.auth??(F===`password`?{type:`password`,password:ie}:F===`key`?{type:`key`,privateKeyPath:ae}:{type:`agent`}),saveProfile:z,profileName:e?.profileName||V.trim()||void 0});if(W(!1),!i.ok||!i.connectionId){G(i.error||`连接远程服务器失败`);return}K(i.connectionId),ue(i.system??null),q(i.tools??null),fe(i.suggestedInstall??[]);let a=i.system?.homeDir||`/`;he(a),_e(a),De(i.connectionId,a),Xa().then(e=>A(e))},De=async(e,t)=>{xe(!0),G(null);let n=await Ja(e,t);xe(!1),n.ok?(he(n.path),_e(n.path),ye(n.items)):G(n.error||`读取远程目录失败`)},Oe=async e=>{if(!se)return;me(!0),G(null);let t=await Ya(se,[e]);me(!1),t.ok?(fe(t=>t.filter(t=>t!==e)),de&&e===`git`&&q({...de,git:{installed:!0,version:`已安装`}})):G(t.error||`安装 ${e} 失败,可能需要远端 sudo 权限`)},ke=e=>{i(Ua(ne,j,parseInt(M,10)||22,e)),r()},Ae=no(m),je=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);return/^[A-Za-z]:/.test(t)?t.toLowerCase():t},Me=je(m),Ne=!!m&&m!==`@root`&&Me!==je(e)&&!n.some(e=>je(e)===Me);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`status-cwd-backdrop ${c??``}`.trim(),onClick:r}),(0,X.jsxs)(`div`,{className:`cwd-picker ${s??``}`.trim(),role:l,"aria-label":u,children:[(0,X.jsxs)(`div`,{className:`cwd-mode-tabs`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${f===`local`?`active`:``}`,onClick:()=>p(`local`),children:[`💻 `,d(`workspaceModeLocal`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${f===`remote`?`active`:``}`,onClick:()=>p(`remote`),children:[`🌐 `,d(`workspaceModeRemote`)]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-close`,title:d(`close`),"aria-label":d(`close`),onClick:r,children:(0,X.jsx)(N,{})})]}),f===`local`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-picker-head`,children:[(0,X.jsxs)(`span`,{className:`cwd-picker-title`,title:m===`@root`?d(`computer`):m,children:[m===`@root`?`💻`:(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{children:m===`@root`?d(`computer`):m})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-up`,disabled:m===`@root`,title:d(`computer`),onClick:()=>{h(`@root`),v(`@root`),E(-1)},children:`💻`}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:!Ae,title:d(`cwdGoUp`),onClick:()=>{Ae&&(h(Ae),v(Ae),E(-1))},children:[`↑ `,d(`cwdGoUp`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:!Ne,title:d(`addWorkspaceRootHint`),onClick:()=>{Ne&&$({type:`set_workspace_roots`,roots:[...n,m]})},children:[`+ `,d(`addWorkspaceRoot`)]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,X.jsx)(`input`,{ref:D,className:`status-cwd-input cwd-picker-input`,value:_,placeholder:d(`enterPath`),spellCheck:!1,onChange:e=>{v(e.target.value),E(-1)},onKeyDown:Te}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,title:d(`cwdPickCurrent`),disabled:m===`@root`,onClick:()=>Ce(m),children:d(`cwdPickCurrent`)})]}),(0,X.jsxs)(`div`,{className:`cwd-list`,children:[Se.length===0&&(0,X.jsx)(`div`,{className:`cwd-empty`,children:d(`cwdEmpty`)}),Se.map(e=>(0,X.jsxs)(`div`,{className:`cwd-item`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${d(`cwdEnter`)} ${e.path}`,onClick:()=>{h(e.path),v(e.path),E(-1)},children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,title:d(`cwdChoose`),onClick:()=>Ce(e.path),children:d(`cwdChoose`)})]},e.path))]}),(0,X.jsxs)(`div`,{className:`cwd-picker-foot`,children:[y?(0,X.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,X.jsx)(`input`,{ref:O,value:x,autoFocus:!0,spellCheck:!1,placeholder:d(a===`project`?`projectName`:`cwdNewName`),onChange:e=>{S(e.target.value),C&&w(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),we()):e.key===`Escape`&&(e.stopPropagation(),b(!1),S(``),w(null))}}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,onClick:we,children:d(a===`project`?`createAndOpenProject`:`cwdCreate`)}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>{b(!1),S(``),w(null)},children:d(`cwdCancel`)})]}):(0,X.jsxs)(`button`,{type:`button`,className:`cwd-newbtn`,onClick:()=>b(!0),children:[`+ `,d(a===`project`?`newProject`:`cwdNewFolder`)]}),C&&(0,X.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:C})]})]}),f===`remote`&&(0,X.jsx)(`div`,{className:`cwd-ssh-container`,children:se?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-probe-box`,children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-probe-header`,children:[(0,X.jsxs)(`span`,{children:[`🌐 `,ne,`@`,j,` (`,le?.os,` `,le?.arch,`)`]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,onClick:()=>{K(null),ue(null),q(null)},children:d(`sshDisconnect`)})]}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,flexWrap:`wrap`,fontSize:`10px`},children:[(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.git.installed?`ok`:`missing`}`,children:[`Git: `,de?.git.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.node.installed?`ok`:`missing`}`,children:[`Node: `,de?.node.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${de?.bash.installed?`ok`:`missing`}`,children:[`Bash: `,de?.bash.installed?`✓`:`✗`]})]}),J.length>0&&(0,X.jsxs)(`div`,{className:`cwd-ssh-install-box`,children:[(0,X.jsx)(`div`,{children:`⚠️ 远端环境未检测到 Git / 基础工具,SCM 与执行功能可能受限。`}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,marginTop:`2px`},children:[(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:pe,onClick:()=>void Oe(J[0]),children:pe?d(`sshInstalling`):`⚡ ${d(`sshInstallTool`)} ${J[0]}`}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>fe([]),children:d(`sshSkipAndBrowse`)})]})]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-head`,children:[(0,X.jsxs)(`span`,{className:`cwd-picker-title`,title:Y,children:[(0,X.jsx)(Pe,{}),(0,X.jsx)(`span`,{children:Y})]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:Y===`/`||be,title:d(`cwdGoUp`),onClick:()=>{let e=no(Y)||`/`;se&&De(se,e)},children:[`↑ `,d(`cwdGoUp`)]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,X.jsx)(`input`,{className:`status-cwd-input cwd-picker-input`,value:ge,placeholder:d(`enterPath`),spellCheck:!1,onChange:e=>_e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&se&&De(se,ge)}}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,onClick:()=>ke(Y),children:d(`sshOpenRemoteWorkspace`)})]}),(0,X.jsx)(`div`,{className:`cwd-list`,children:be?(0,X.jsx)(`div`,{className:`cwd-empty`,children:`正在加载远程目录…`}):ve.length===0?(0,X.jsx)(`div`,{className:`cwd-empty`,children:d(`cwdEmpty`)}):ve.map(e=>(0,X.jsxs)(`div`,{className:`cwd-item`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${e.type===`dir`?d(`cwdEnter`):``} ${e.path}`,onClick:()=>{e.type===`dir`&&se&&De(se,e.path)},children:[e.type===`dir`?(0,X.jsx)(Le,{}):(0,X.jsx)(`span`,{children:`📄`}),(0,X.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),e.type===`dir`&&(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,title:d(`cwdChoose`),onClick:()=>ke(e.path),children:d(`cwdChoose`)})]},e.path))})]}):(0,X.jsxs)(`div`,{className:`cwd-ssh-form`,children:[k.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-profiles-title`,children:[`📋 `,d(`sshSavedProfiles`)]}),k.map(e=>(0,X.jsxs)(`div`,{className:`cwd-ssh-profile-card`,onClick:()=>{ee(e.host),te(String(e.port)),P(e.username),re(e.authType),e.privateKeyPath&&R(e.privateKeyPath),Ee({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}})},children:[(0,X.jsxs)(`div`,{className:`cwd-ssh-profile-meta`,children:[(0,X.jsxs)(`span`,{className:`cwd-ssh-profile-name`,children:[(0,X.jsx)(ce,{style:{marginRight:`4px`}}),e.name]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-profile-addr`,children:[e.username,`@`,e.host,`:`,e.port]})]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,title:d(`delete`),onClick:t=>{t.stopPropagation(),confirm(d(`sshDeleteProfileConfirm`))&&(Za(e.name),A(t=>t.filter(t=>t.name!==e.name)))},children:(0,X.jsx)(L,{})})]},e.name))]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,style:{marginTop:`4px`},children:[(0,X.jsxs)(`label`,{children:[d(`sshHost`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:j,placeholder:`192.168.1.100`,onChange:e=>ee(e.target.value)}),(0,X.jsxs)(`label`,{style:{width:`32px`,textAlign:`right`},children:[d(`sshPort`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,style:{width:`45px`,flex:`none`},value:M,onChange:e=>te(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshUser`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:ne,placeholder:`root / ubuntu`,onChange:e=>P(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshAuthType`),`:`]}),(0,X.jsxs)(`select`,{className:`cwd-ssh-select`,value:F,onChange:e=>re(e.target.value),children:[(0,X.jsx)(`option`,{value:`password`,children:d(`sshPassword`)}),(0,X.jsx)(`option`,{value:`key`,children:d(`sshKeyPath`)}),(0,X.jsx)(`option`,{value:`agent`,children:d(`sshAgent`)})]})]}),F===`password`&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshPassword`),`:`]}),(0,X.jsx)(`input`,{type:`password`,className:`cwd-ssh-input`,value:ie,placeholder:`••••••••`,onChange:e=>I(e.target.value)})]}),F===`key`&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshKeyPath`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:ae,placeholder:`~/.ssh/id_rsa`,onChange:e=>R(e.target.value)})]}),(0,X.jsx)(`div`,{className:`cwd-ssh-row`,style:{fontSize:`11px`,color:`var(--text-dim)`},children:(0,X.jsxs)(`label`,{style:{width:`auto`},children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked),style:{marginRight:`4px`}}),d(`sshSaveProfile`)]})}),z&&(0,X.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,X.jsxs)(`label`,{children:[d(`sshProfileName`),`:`]}),(0,X.jsx)(`input`,{className:`cwd-ssh-input`,value:V,placeholder:`my-server`,onChange:e=>H(e.target.value)})]}),oe&&(0,X.jsxs)(`div`,{style:{color:`var(--red)`,fontSize:`11px`,padding:`2px 0`},children:[`⚠️ `,oe]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,style:{marginTop:`4px`},disabled:U,onClick:()=>void Ee(),children:d(U?`sshConnecting`:`sshConnectAndProbe`)})]})})]})]})}function io({open:e,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:a,onCreateProject:o}){let s=Z();return e?(0,X.jsx)(ro,{currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:e=>{a(e),i()},onCreateProject:o,mode:`project`,className:`project-picker`,backdropClassName:`project-picker-backdrop`,role:`dialog`,ariaLabel:s(`projectPickerTitle`)}):null}function ao(e){return k({tag:`svg`,attr:{viewBox:`0 0 256 256`,fill:`currentColor`},child:[{tag:`path`,attr:{d:`M53.92,34.62A8,8,0,1,0,42.08,45.38L67.37,73.2A69.82,69.82,0,0,0,38,87.63a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33,89.75,89.75,0,0,0,11.58-20.27l21.84,24a8,8,0,1,0,11.84-10.76ZM155.9,208,48,100.08C58.23,91.83,69.2,87.72,80.66,87.81l87.16,95.88C165.59,193.56,160.24,202.23,155.9,208Zm79.42-104-44.64,44.79a8,8,0,1,1-11.33-11.3L224,92.7,163.32,32,122.1,73.35a8,8,0,0,1-11.33-11.29L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.32,104Z`},child:[]}]})(e)}function oo(e){return k({tag:`svg`,attr:{viewBox:`0 0 256 256`,fill:`currentColor`},child:[{tag:`path`,attr:{d:`M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z`},child:[]}]})(e)}function so(e,t,n,r={}){let{align:i=`right`,side:a=`bottom`,gap:o=6,margin:s=8}=r,c=t.width,l=t.height,u=Math.max(0,n.width-c-s),d=Math.max(0,n.height-l-s),f=i===`left`?e.left:e.right-c;f=Math.max(s,Math.min(f,u));let p;return a===`top`?(p=e.top-l-o,p<s&&e.bottom+o+l<=n.height-s&&(p=e.bottom+o)):(p=e.bottom+o,p+l>n.height-s&&e.top-l-o>=s&&(p=e.top-l-o)),p>d&&(p=d),p<s&&(p=s),{x:Math.round(f),y:Math.round(p)}}function co(e){let{open:t=!0,anchor:n,anchorEl:r,onClose:i,isInside:a,align:o=`right`,side:s=`bottom`,gap:c=6,margin:l=8}=e,u=(0,g.useRef)(null),[d,f]=(0,g.useState)(null),p=(0,g.useRef)(i);(0,g.useLayoutEffect)(()=>{p.current=i});let m=()=>{if(!n)return null;if(`current`in n)return n.current?.getBoundingClientRect()??null;if(typeof n.getBoundingClientRect==`function`)return n.getBoundingClientRect();let e=n;return typeof e.left==`number`&&typeof e.right==`number`&&typeof e.top==`number`&&typeof e.bottom==`number`?e:null},h=()=>r||(n&&`current`in n?n.current:n&&typeof n.getBoundingClientRect==`function`?n:null),_=()=>{if(!t)return;let e=u.current;if(!e)return;let n=e.getBoundingClientRect();if(n.width===0&&n.height===0)return;let r=h(),i=r&&r.isConnected?r.getBoundingClientRect():m();if(!i)return;let a=so(i,{width:n.width,height:n.height},{width:window.innerWidth,height:window.innerHeight},{align:o,side:s,gap:c,margin:l});f(e=>e?.x===a.x&&e?.y===a.y?e:a)};return(0,g.useLayoutEffect)(()=>{t?_():f(null)},[t,n,r,o,s,c,l]),Rt(()=>{p.current()},t),(0,g.useEffect)(()=>{if(!t)return;let e=e=>e instanceof Node&&!!(u.current?.contains(e)||h()?.contains(e)||a?.(e)),n=t=>{e(t.target)||p.current()};return document.addEventListener(`mousedown`,n,!0),window.addEventListener(`resize`,_,!0),window.addEventListener(`scroll`,_,!0),()=>{document.removeEventListener(`mousedown`,n,!0),window.removeEventListener(`resize`,_,!0),window.removeEventListener(`scroll`,_,!0)}},[t,n,r]),{panelRef:u,pos:d,style:{position:`fixed`,left:d?.x??-9999,top:d?.y??-9999,visibility:d?`visible`:`hidden`},measure:_}}function lo({anchorRect:e,anchorEl:t,plugins:n,pinnedIds:r,orderedPluginIds:i,onTogglePin:a,onReorder:o,onOpenView:s,onManagePlugins:c,onClose:l}){let{t:u}=Mn(),{panelRef:d,style:f,measure:p}=co({anchor:e,anchorEl:t,onClose:l}),[,m]=(0,g.useState)(null),h=(0,g.useRef)(null),[_,v]=(0,g.useState)(null),y=(0,g.useMemo)(()=>{let e=new Map((i??[]).map((e,t)=>[e,t]));return n.map((e,t)=>({plugin:e,index:t})).sort((t,n)=>(e.get(t.plugin.id)??1e6+t.index)-(e.get(n.plugin.id)??1e6+n.index)).map(({plugin:e})=>e)},[n,i]);(0,g.useLayoutEffect)(()=>{p()},[y,p]);let b=(e,t)=>{let n=y.filter(e=>e.view!==!1&&!e.error).map(e=>e.id),r=n.indexOf(e),i=r+t;if(r<0||i<0||i>=n.length)return;let[a]=n.splice(r,1);a&&(n.splice(i,0,a),o(n))},x=(e,t)=>{if(!e||e===t)return;let n=y.filter(e=>e.view!==!1&&!e.error).map(e=>e.id),r=n.indexOf(e),i=n.indexOf(t);if(r<0||i<0)return;let[a]=n.splice(r,1);a&&(n.splice(i,0,a),o(n))};return(0,j.createPortal)((0,X.jsxs)(`div`,{ref:d,className:`pm-panel`,role:`menu`,"aria-label":u(`pluginMenuTitle`),style:f,children:[(0,X.jsxs)(`div`,{className:`pm-head`,"aria-hidden":`true`,children:[(0,X.jsx)(mt,{className:`pm-head-icon`,"aria-hidden":!0}),u(`pluginMenuTitle`)]}),(0,X.jsx)(`div`,{className:`pm-list`,children:n.length===0?(0,X.jsx)(`div`,{className:`pm-empty`,children:u(`pluginMenuEmpty`)}):y.map(e=>{let t=e.view===!1||!!e.error,n=!t&&r.has(e.id),i=e.error??(e.view===!1?u(`pluginMenuNoView`):void 0),o=e.iconSvg?void 0:e.icon&&!/[a-z]/i.test(e.icon)?e.icon:void 0;return(0,X.jsxs)(`div`,{className:`pm-row${_===e.id?` drop-target`:``}`,role:`none`,onDragOver:n=>{!t&&h.current&&(n.preventDefault(),v(e.id))},onDrop:t=>{t.preventDefault(),x(t.dataTransfer.getData(`text/plain`)||h.current,e.id),h.current=null,m(null),v(null)},children:[!t&&(0,X.jsx)(`button`,{type:`button`,className:`pm-drag`,draggable:!0,"aria-label":u(`pluginMenuReorder`),title:u(`pluginMenuReorderHint`),onDragStart:t=>{m(e.id),h.current=e.id,t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.id);let n=document.createElement(`div`);n.style.cssText=`position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;opacity:0`,document.body.appendChild(n),t.dataTransfer.setDragImage(n,0,0),requestAnimationFrame(()=>n.remove())},onDragEnd:()=>{h.current=null,m(null),v(null)},onKeyDown:t=>{(t.key===`ArrowUp`||t.key===`ArrowDown`)&&(t.preventDefault(),b(e.id,t.key===`ArrowUp`?-1:1))},children:(0,X.jsx)(xe,{"aria-hidden":!0})}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`pm-row-main`,disabled:t,title:i,onClick:()=>s(e.id),children:[o||e.iconSvg?(0,X.jsx)(fi,{icon:o,iconSvg:e.iconSvg,className:`pm-icon`}):(0,X.jsx)(mt,{className:`pm-icon`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`pm-name`,children:e.name}),i&&(0,X.jsx)(`span`,{className:`pm-sub`,children:i})]}),!t&&(0,X.jsx)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":n,"aria-label":u(n?`pluginMenuUnpin`:`pluginMenuPin`),className:`pm-pin${n?` on`:``}`,onClick:()=>a(e.id,!n),children:n?(0,X.jsx)(oo,{"aria-hidden":!0}):(0,X.jsx)(ao,{"aria-hidden":!0})})]},e.id)})}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`pm-manage`,onClick:()=>{l(),c()},children:[(0,X.jsx)(se,{"aria-hidden":!0}),(0,X.jsx)(`span`,{children:u(`pluginMenuManage`)})]})]}),document.body)}function uo({onClose:e}){let t=Z(),{locale:n,setLocale:r,reloadPacks:i}=Mn(),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(``),[l,u]=(0,g.useState)(``);async function d(){try{let e=await fetch(hn(dn(`/api/locales`)));if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();o(t.packs??[]),c(``)}catch(e){c(t(`localeListFailed`,{error:e instanceof Error?e.message:String(e)}))}}(0,g.useEffect)(()=>{d()},[]);async function f(e){u(e),c(``);try{let t=await fetch(hn(dn(`/api/locales/${e}/install`)),{method:`POST`});if(!t.ok){let e=`HTTP ${t.status}`;try{e=(await t.json()).error??e}catch{}throw Error(e)}await i(),await d()}catch(e){c(t(`localeInstallFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(``)}}async function p(e){u(e),c(``);try{let t=await fetch(hn(dn(`/api/locales/${e}`)),{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);wn(e),n===e&&r(`zh`),await i(),await d()}catch(e){c(t(`localeInstallFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(``)}}return(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,X.jsxs)(`div`,{className:`bg-task-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`bg-task-head`,children:[(0,X.jsxs)(`span`,{className:`bg-task-title`,children:[(0,X.jsx)(Pe,{}),` `,t(`localePacks`)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:t(`close`),onClick:e,children:(0,X.jsx)(N,{})})]}),s&&(0,X.jsx)(`div`,{className:`bg-task-empty`,children:s}),a===null&&!s?(0,X.jsx)(`div`,{className:`bg-task-empty`,children:t(`loading`)}):(0,X.jsx)(`ul`,{className:`bg-task-list`,children:(a??[]).map(e=>{let n=l===e.code;return(0,X.jsxs)(`li`,{className:`bg-task-item`,children:[(0,X.jsxs)(`div`,{className:`bg-task-info`,children:[(0,X.jsxs)(`div`,{className:`bg-task-line1`,children:[(0,X.jsx)(`span`,{className:`bg-task-port`,children:e.nativeName}),e.installed&&e.version&&(0,X.jsxs)(`span`,{className:`bg-task-name`,children:[`v`,e.version]})]}),(0,X.jsxs)(`div`,{className:`bg-task-line2`,children:[(0,X.jsx)(`span`,{children:e.code}),e.installed?(0,X.jsxs)(`span`,{children:[t(`localeInstalled`),` · `,t(`localeRemoveHint`)]}):(0,X.jsx)(`span`,{children:t(`localeGetMore`)})]})]}),e.installed?(0,X.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,disabled:n,title:t(`localeRemove`),onClick:()=>void p(e.code),children:[(0,X.jsx)(L,{}),(0,X.jsx)(`span`,{children:t(n?`localeRemoving`:`localeRemove`)})]}):(0,X.jsxs)(`button`,{type:`button`,className:`btn`,disabled:n,title:t(`localeInstall`),onClick:()=>void f(e.code),children:[(0,X.jsx)(Ke,{}),(0,X.jsx)(`span`,{children:t(n?`localeDownloading`:`localeInstall`)})]})]},e.code)})}),(0,X.jsx)(`div`,{className:`bg-task-foot`,children:(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:t(`bgTaskRefresh`),onClick:()=>void d(),children:[(0,X.jsx)(J,{}),(0,X.jsx)(`span`,{children:t(`bgTaskRefresh`)})]})})]})})}var fo=`xing-shuyin/pi-web-ui`,po={state:`idle`,version:null,percent:0,message:null};function mo(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function ho(e,t){switch(t.state){case`checking`:return{...e,state:`checking`,message:null};case`available`:return{...e,state:`available`,version:t.version??e.version,message:null};case`up-to-date`:return{...e,state:`up-to-date`,version:t.version??e.version,message:null};case`downloading`:return{...e,state:`downloading`,percent:mo(t.percent),message:null};case`downloaded`:return{...e,state:`downloaded`,version:t.version??e.version,percent:100,message:null};case`error`:return{...e,state:`error`,message:t.message??`unknown error`};default:return e}}function go(e){if(!Ln(e))return null;let t=(e??(typeof window>`u`?void 0:window))?.piDesktop?.updater;return!t||typeof t.check!=`function`||typeof t.download!=`function`?null:t}function _o(e){return e instanceof Error?e.message:String(e)}function vo(e){let t=(e??``).trim().replace(/^v/,``);return t?`https://github.com/${fo}/releases/tag/v${t}`:`https://github.com/${fo}/releases/latest`}function yo(){let[e]=(0,g.useState)(()=>go()),[t,n]=(0,g.useState)(po);(0,g.useEffect)(()=>{if(e)return e.onEvent(e=>n(t=>ho(t,e)))},[e]);let r=(0,g.useCallback)(()=>{e&&(n(e=>({...e,state:`checking`,message:null})),e.check().catch(e=>n(t=>({...t,state:`error`,message:_o(e)}))))},[e]),i=(0,g.useCallback)(()=>{e&&(n(e=>({...e,state:`downloading`,message:null})),e.download().catch(e=>n(t=>({...t,state:`error`,message:_o(e)}))))},[e]),a=(0,g.useCallback)(()=>{e&&e.quitAndInstall().catch(e=>n(t=>({...t,state:`error`,message:_o(e)})))},[e]);return{...t,bridge:e,check:r,download:i,quitAndInstall:a}}function bo(e){let t=Math.max(0,e.input??0),n=Math.max(0,e.cacheRead??0),r=Math.max(0,e.cacheWrite??0),i=t+n+r;return{totalInput:i,miss:t,read:n,write:r,hitRate:i>0?Math.min(n/i,1):0,writeRate:i>0?Math.min(r/i,1):0}}var xo=2e3;function So(e,t,n=xo){return e.filter(e=>t-e.t<=n)}function Co(e,t=xo){if(e.length<2)return 0;let n=e[e.length-1],r=e.find(e=>e.t>=n.t-t)??e[0],i=(n.t-r.t)/1e3;return i<=0?0:Math.max(0,(n.out-r.out)/i)}function wo(e){if(!e)return 0;let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r>=12352&&r<=12543||r>=13312&&r<=19903||r>=19968&&r<=40959||r>=63744&&r<=64255||r>=65280&&r<=65519||r===12288)&&t++}let n=e.length-t;return Math.round(t+n/4)}function To(e){let t=0;for(let n of e)n.type===`text`&&typeof n.text==`string`&&n.text?t+=wo(n.text):n.type===`thinking`&&typeof n.thinking==`string`&&n.thinking&&(t+=wo(n.thinking));return t}function Eo(e){return e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function Do(e){return e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function Oo(e){return e.startsWith(`zh`)?`ZH`:e.startsWith(`ja`)?`JA`:e.startsWith(`ko`)?`KO`:e.startsWith(`fr`)?`FR`:e.startsWith(`de`)?`DE`:e.startsWith(`es`)?`ES`:e.startsWith(`ru`)?`RU`:e.startsWith(`pt`)?`PT`:e.startsWith(`it`)?`IT`:`EN`}function ko({entry:e,bar:t,chat:n,view:r,plugins:i,onViewChange:a,onOpenPanel:o,onOpenSettings:s,onOpenGlobalSearch:c,onOpenBgTasks:l,onOpenProjectPicker:u,onOpenPluginMenu:d,isPluginMenuOpen:f,isProjectPickerOpen:p,onUiAction:m,uiContextEntries:h,dropdownProps:_}){let v=Z(),{locale:y,packs:b,setLocale:x}=Mn(),{engine:S}=Na(),C=S===`dsh`,[w,T]=(0,g.useState)(!1),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(!1),ee=n.settings?.uiLayout,M=n.state,te=M?.stats,ne=M?.isStreaming??!1,N=(0,g.useRef)([]),F=M?.streamingMessage?To(M.streamingMessage.content):0;(0,g.useEffect)(()=>{if(!ne){N.current=[];return}let e=Date.now(),t=N.current,n=t[t.length-1];n&&e-n.t<250||(N.current=So([...t,{t:e,out:F}],e))},[ne,F]);let re=ne?Co(N.current):0,ie=n=>{n.preventDefault(),n.stopPropagation();let r=t=>{let n={...ee?.slots,[e.id]:t};$({type:`set_settings`,uiLayout:{...ee,slots:n}})},i=()=>{let t=new Set(ee?.hidden??[]);t.add(e.id),$({type:`set_settings`,uiLayout:{...ee,hidden:[...t]}})},a=[];t!==`top`&&a.push({id:`host:move-top`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToTop`),kind:`action`,order:10,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`bottom`&&a.push({id:`host:move-bottom`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToBottom`),kind:`action`,order:20,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`left`&&a.push({id:`host:move-left`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToLeft`),kind:`action`,order:30,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),t!==`right`&&a.push({id:`host:move-right`,slot:`contextmenu.topbar`,source:`host`,label:v(`moveToRight`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),a.push({id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:v(`uiLayoutRestore`),kind:`action`,order:50,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),h&&h.length>0&&a.push(...h),la({x:n.clientX,y:n.clientY,slot:`contextmenu.topbar`,target:{id:e.id,label:e.label},entries:a,onHostAction:e=>{e.id===`host:move-top`?r(`topbar.primary`):e.id===`host:move-bottom`?r(`bottombar`):e.id===`host:move-left`?r(`sidebar.left`):e.id===`host:move-right`?r(`sidebar.right`):e.id===`host:hide-item`&&i()}})},I=e.id,ae=e.labelExplicit?e.label:``,L=e=>ae||e,R=e=>ae?`${ae} ${e}`:e;if(e.kind===`select`&&e.options?.length){let t=e.options.some(t=>t.value===e.value)?e.value:e.options[0].value;return(0,X.jsx)(`select`,{className:`bar-item bar-item-select`,title:e.hint??e.label,"data-tip":e.hint??e.label,"aria-label":e.label,value:t,onChange:t=>m?.(e,t.target.value),onContextMenu:ie,"data-bar-item":I,children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}if(I===`host:brand`)return(0,X.jsxs)(`span`,{className:`bar-item brand bar-item-brand`,title:v(`brand`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`brand-logo bar-item-brand-logo`,children:`π`}),(0,X.jsx)(`span`,{className:`brand-name bar-item-text`,children:L(`pi-web-ui`)})]});if(I===`host:conn`){let e=n.ready?`ok`:n.status===`closed`?`error`:`busy`,t=n.ready?v(`connected`):n.status===`closed`?v(`reconnecting`):v(`connecting`);return(0,X.jsxs)(`span`,{className:`bar-item status-item status-conn ${e} bar-item-conn`,title:t,"data-tip":t,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`status-dot ${e}`}),(0,X.jsx)(`span`,{className:`status-conn-label bar-item-text`,children:R(t)})]})}if(I===`host:engine`)return S===`pi`?null:(0,X.jsx)(`span`,{className:`bar-item status-item engine-badge engine-${S} bar-item-engine`,title:`${v(`engineBadge`)}: ${S}`,"data-tip":`${v(`engineBadge`)}: ${S}`,onContextMenu:ie,"data-bar-item":I,children:R(S===`dsh`?`DSH`:S)});if(I===`host:ctx`){let e=te?.contextUsage,t=e?.softCap??null,n=t!==null&&t>0&&t<(e?.contextWindow??0),r=n?t:e?.contextWindow??0,i=e?.tokens!==null&&e?.tokens!==void 0&&r>0?Math.min(100,Math.round(e.tokens/r*100)):null,a=e?.tokens!==null&&e?.tokens!==void 0?Eo(e.tokens):null,o=r>0?Eo(r):null,s=a!==null&&o!==null&&i!==null?`${a} / ${o}`:`—`,c=i===null?``:i>=80?`warn`:i>=50?`mid`:`ok`,l=n?`${v(`contextUsage`)}: ${Eo(e?.tokens??0)} / ${Eo(t)} (${v(`softCapMarker`)}, max ${Eo(e?.contextWindow??0)})`:t!==null&&t>0?`${v(`contextUsage`)}: ${s} · ${v(`softCapMarker`)}: ${Eo(t)}`:`${v(`contextUsage`)}: ${s}`,u=i!==null&&i>0?+(31.42*(1-Math.min(i,100)/100)).toFixed(2):31.42;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-ctx bar-item-ctx`,title:l,"data-tip":l,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsxs)(`svg`,{className:`ctx-ring ${c}`,viewBox:`0 0 14 14`,width:`13`,height:`13`,"aria-hidden":`true`,children:[(0,X.jsx)(`circle`,{className:`ctx-ring-bg`,cx:`7`,cy:`7`,r:`5`}),i!==null&&i>0&&(0,X.jsx)(`circle`,{className:`ctx-ring-fill`,cx:`7`,cy:`7`,r:`5`,strokeDasharray:31.42,strokeDashoffset:u,"data-percent":i})]}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[ae?`${ae} `:``,a!==null&&o!==null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`ctx-val`,children:a}),(0,X.jsx)(`span`,{className:`status-sep`,children:`/`}),(0,X.jsx)(`span`,{className:`ctx-max`,children:o})]}):s]})]})}if(I===`host:cache`){let e=bo(te?.tokens??{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}),t=e.hitRate*100,n=e.totalInput===0?``:e.hitRate>=.7?`ok`:e.hitRate>=.4?`mid`:`warn`,r=e.totalInput>0?`${t.toFixed(1)}%`:`—`,i=v(`cacheHitTip`,{read:Eo(e.read),write:Eo(e.write),miss:Eo(e.miss),input:Eo(e.totalInput)}),a=e.totalInput>0?`${v(`cacheHit`)}: ${r} · ${i}`:v(`cacheHit`),o=e.totalInput===0;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-cache bar-item-cache${o?` is-zero`:``}`,title:a,"data-tip":a,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Je,{className:`bar-item-icon`}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[ae?`${ae} `:``,(0,X.jsx)(`b`,{className:`cache-pct ${n}`,children:r})]})]})}if(I===`host:cost`){let e=te?.cost??0,t=Do(e),n=v(`cumulativeCost`);return(0,X.jsxs)(`span`,{className:`bar-item status-item status-cost bar-item-cost${e<=0?` is-zero`:``}${ae?` has-name`:``}`,title:n,"data-tip":n,onContextMenu:ie,"data-bar-item":I,children:[ae?(0,X.jsx)(`span`,{className:`bar-item-text`,children:ae}):null,(0,X.jsx)(`span`,{className:`bar-item-char`,children:`$`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:t})]})}if(I===`host:msg-count`){let e=te?.totalMessages??0,t=`${v(`sessionMessages`)}: ${e}`;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-msg-count bar-item-msg-count${e===0?` is-zero`:``}`,title:t,"data-tip":t,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(be,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:R(String(e))})]})}if(I===`host:working`){if(!ne)return null;let e=(M?.queue?.steering?.length??0)+(M?.queue?.followUp?.length??0);return(0,X.jsxs)(`span`,{className:`bar-item status-item working bar-item-working`,title:v(`working`),"data-tip":v(`working`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`working-spin`}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[L(v(`working`)),e>0&&` ⏳ ${e}`]}),(0,X.jsx)(`span`,{className:`status-rate bar-item-rate`,title:v(`rateTip`),children:re>0?`${Math.round(re)}${v(`tps`)}`:`…`})]})}if(I===`host:status-delegate`)return M?.delegateMode?(0,X.jsxs)(`span`,{className:`bar-item status-item delegate-badge bar-item-delegate`,title:M.delegateConvId?v(`delegateModeOpenTip`):v(`delegateModeBadgeTip`),"data-tip":M.delegateConvId?v(`delegateModeOpenTip`):v(`delegateModeBadgeTip`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(`span`,{className:`bar-item-icon`,children:`🔎`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:L(v(`delegateModeBadge`))}),M.delegateConvId?(0,X.jsx)(`button`,{type:`button`,className:`delegate-badge-open`,title:v(`delegateModeOpenTip`),onClick:()=>$({type:`switch_conversation`,id:M.delegateConvId}),children:`↗`}):null]}):null;if(I===`host:host-metrics`){let e=n.hostMetrics;if(!e)return null;let t=e.cpuPercent===null||!Number.isFinite(e.cpuPercent)?`—`:`${Math.round(e.cpuPercent)}%`,r=Number.isFinite(e.memoryPercent)?`${Math.round(e.memoryPercent)}%`:`—`;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-host-metrics bar-item-host-metrics`,title:`${v(`hostResourcesTip`)}\n${v(`hostProcessor`)}: ${t} · ${v(`hostMemory`)}: ${r}`,"data-tip":`${v(`hostResourcesTip`)}\n${v(`hostProcessor`)}: ${t} · ${v(`hostMemory`)}: ${r}`,onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Xe,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:R(`${t} · ${r}`)})]})}if(I===`host:browser`)return n.settings?.disabledAgentTools?.includes(`browser_page`)?null:(0,X.jsx)(`span`,{className:`bar-item-wrap`,onContextMenu:ie,"data-bar-item":I,children:(0,X.jsx)(lr,{})});if(I===`host:sound`)return(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:w,onOpenChange:T,tip:L(v(`sound`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`sound`)),"data-tip":L(v(`sound`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(P,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:L(v(`sound`))})]}),children:[_?.sound&&_?.onSoundChange?(0,X.jsx)(Pn,{settings:_.sound,onChange:_.onSoundChange,onPreview:_.onSoundPreview??(()=>{})}):null,(0,X.jsx)(ii,{})]});if(I===`host:language`)return(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:E,onOpenChange:D,tip:L(v(`language`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`language`)),"data-tip":L(v(`language`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Pe,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(Oo(y))})]}),children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`language`)}),b.map(e=>(0,X.jsx)(Vt,{active:y===e.code,onClick:()=>{x(e.code),D(!1)},children:e.nativeName},e.code)),_?.onLocaleModalOpen?(0,X.jsxs)(Vt,{onClick:()=>{D(!1),_.onLocaleModalOpen?.()},children:[(0,X.jsx)(Ke,{}),` `,v(`localeGetMore`)]}):null]});if(I===`host:theme`){let e=_?.themes??[],n=_?.theme??null;return(0,X.jsx)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:O,onOpenChange:t=>{k(t),t&&e.length===0&&_?.reloadThemes?.()},tip:L(v(`theme`)),caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`theme`)),"data-tip":L(v(`theme`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(V,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:L(v(`theme`))})]}),children:(()=>{let t=e.filter(e=>e.group===`classic`),r=e.filter(e=>e.group!==`classic`),i=e=>{let t=y===`zh`?e.name:e.nameEn??e.name,n=e.scheme===`light`?v(`themeLight`):e.scheme===`dark`?v(`themeDark`):``;return n?y===`zh`?`${t}(${n})`:`${t} (${n})`:t};return(0,X.jsxs)(X.Fragment,{children:[t.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`themeGroupClassics`)}),t.map(e=>(0,X.jsx)(Vt,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),k(!1)},children:i(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:t.length>0?v(`themeGroupBuiltin`):v(`theme`)}),(0,X.jsx)(Vt,{active:n===null,onClick:()=>{_?.onThemeChange?.(null),k(!1)},children:v(`themeDefault`)}),r.map(e=>(0,X.jsx)(Vt,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),k(!1)},children:i(e)},e.id))]})})()})}if(I===`host:update`){let e=_?.updatesCount??0;return _?.managed?(0,X.jsxs)(`span`,{className:`bar-item chip`,title:v(`updatesManaged`),"data-tip":v(`updatesManaged`),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Ke,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(`v${_?.appVersion??n.update?.current??`…`}`)})]}):(0,X.jsxs)(Bt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:A,onOpenChange:e=>{j(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},tip:L(v(`update`)),fit:!0,caret:!1,trigger:(0,X.jsxs)(`button`,{type:`button`,className:`bar-item chip`,title:L(v(`update`)),"data-tip":L(v(`update`)),onContextMenu:ie,"data-bar-item":I,children:[(0,X.jsx)(Ke,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:R(`v${n.update?.current??`…`}`)}),n.update&&!n.update.upToDate&&(0,X.jsx)(`span`,{className:`update-dot`}),e>0&&(0,X.jsx)(`span`,{className:`update-badge`,children:e})]}),children:[(0,X.jsx)(`div`,{className:`dd-header`,children:v(`update`)}),_?.renderUpdateBody?.(),_?.renderAllUpdatesBody?.()]})}let B=null,H=e.label,U=null,W=!1,oe=!1,G=``,ce,K;switch(I){case`host:chat`:B=(0,X.jsx)(be,{className:`bar-item-icon`}),H=L(v(`chat`)),W=r===`chat`,oe=!0,K=()=>a?.(`chat`);break;case`host:terminal`:B=(0,X.jsx)(z,{className:`bar-item-icon`}),H=L(v(`terminal`)),W=r===`terminal`,oe=!0,K=()=>a?.(`terminal`);break;case`host:git`:B=(0,X.jsx)(Ie,{className:`bar-item-icon`}),H=L(v(`scmTab`)),W=r===`git`,oe=!0,K=()=>a?.(`git`);break;case`host:new-chat`:B=(0,X.jsx)(fe,{className:`bar-item-icon`}),H=L(v(`newChat`)),G=`chip newchat`,K=()=>{a?.(`chat`),$({type:`new_chat`}),or()};break;case`host:new-ephemeral-chat`:if(C)return null;B=(0,X.jsx)(Dt,{className:`bar-item-icon`}),H=L(v(`newChatEphemeral`)),G=`chip newchat ephemeral-chat-btn`,K=()=>{a?.(`chat`),$({type:`new_chat`,ephemeral:!0}),or()};break;case`host:history`:if(r&&r!==`chat`)return null;B=(0,X.jsx)(xe,{className:`bar-item-icon`}),H=L(v(`openHistory`)),G=`panel-toggle`,K=()=>o?.(`left`);break;case`host:files`:if(r&&r!==`chat`)return null;B=(0,X.jsx)(Le,{className:`bar-item-icon`}),H=L(v(`openFiles`)),G=`panel-toggle has-label`,K=()=>o?.(`right`);break;case`host:open-project`:B=(0,X.jsx)(Re,{className:`bar-item-icon`}),H=L(v(`openProject`)),G=`chip open-project`,W=!!p,K=()=>u?.();break;case`host:search`:B=(0,X.jsx)(le,{className:`bar-item-icon`}),H=L(v(`searchGlobal`)),G=`chip`,K=()=>c?.();break;case`host:tasks`:B=(0,X.jsx)(Oe,{className:`bar-item-icon`}),H=L(v(`bgTasks`)),G=`chip bg-task-chip`,n.bgServers.length>0&&(U=(0,X.jsx)(`span`,{className:`bg-task-badge bar-item-badge`,children:n.bgServers.length})),K=()=>l?.();break;case`host:settings`:B=(0,X.jsx)(se,{className:`bar-item-icon`}),H=L(v(`settings`)),G=`chip`,K=()=>s?.();break;case`host:plugins`:B=(0,X.jsx)(mt,{className:`bar-item-icon`}),H=L(v(`pluginMenuTitle`)),G=`chip`,K=e=>{d?d(e.currentTarget):s?.(`plugins`)};break;case`host:github`:B=(0,X.jsx)(Fe,{className:`bar-item-icon`}),H=L(`GitHub`),G=`chip github`,K=()=>window.open(`https://github.com/xing-shuyin/pi-web-ui`,`_blank`,`noreferrer,noopener`);break;case`host:cwd`:B=(0,X.jsx)(Le,{className:`bar-item-icon`}),H=R(M?.cwd?M.cwd.split(/[/\\]/).pop()||M.cwd:v(`openProject`)),G=`status-item status-cwd`,W=!!p,K=()=>u?.();break;case`host:plugin-status`:if(n.statuses.length===0)return null;B=(0,X.jsx)(Tt,{className:`bar-item-icon`}),H=R(n.statuses.map(e=>e.text).join(` · `)),G=`status-item ext-status`;break;default:if(e.kind===`view`){let t=e.view??``;W=r===t,oe=!0;let o=(i??n.plugins??[]).find(t=>`plugin:${t.id}`===e.source);G=`plugin-tab${o?.error?` broken`:``}`,o?.error&&(ce=`${e.label}: ${o.error}`);let s=e.iconSvg||o?.iconSvg,c=e.icon||o?.icon;B=s?(0,X.jsx)(fi,{icon:c,iconSvg:s,className:`bar-item-icon plugin-icon-svg`}):c?(0,X.jsx)(`span`,{className:`bar-item-icon bar-item-glyph`,children:c}):null,K=()=>a?.(t)}else{let n=e.iconSvg,r=e.icon;G=t===`bottom`?`status-item status-action chip`:`chip`,B=n?(0,X.jsx)(fi,{icon:r,iconSvg:n,className:`bar-item-icon plugin-icon-svg`}):r?(0,X.jsx)(`span`,{className:`bar-item-icon bar-item-glyph`,children:r}):null,e.badge&&(U=(0,X.jsx)(`span`,{className:`bar-item-badge`,children:e.badge})),K=()=>m?.(e)}}let ue=ce??e.hint??H,de=[`bar-item`,oe?`tb-tab${W?` active`:``}`:``,G,W&&!oe?`active`:``].filter(Boolean).join(` `);return(0,X.jsxs)(`button`,{type:`button`,role:oe?`tab`:void 0,"aria-selected":oe?W:void 0,"aria-haspopup":I===`host:plugins`?`menu`:void 0,"aria-expanded":I===`host:plugins`?!!f:void 0,className:de,title:ue,"data-tip":ue,"aria-label":H,onClick:K,onContextMenu:ie,"data-bar-item":I,children:[B,(0,X.jsx)(`span`,{className:`bar-item-text`,children:H}),U]})}var Ao={name:`@earendil-works/pi-coding-agent`,kind:`pi-core`,current:``,latest:null,upToDate:!1};function jo({anchorRef:e,open:t,onClose:n,children:r}){let{panelRef:i,style:a,measure:o}=co({open:t,anchor:e,onClose:n});return(0,g.useLayoutEffect)(()=>{t&&o()},[t,r,o]),t?(0,j.createPortal)((0,X.jsx)(`div`,{ref:i,className:`plugin-topbar-menu portal`,role:`menu`,style:a,children:r}),document.body):null}function Mo(){let[e,t]=(0,g.useState)(()=>typeof window<`u`&&window.matchMedia!==void 0&&window.matchMedia(`(max-width: 768px)`).matches);return(0,g.useEffect)(()=>{if(typeof window>`u`||window.matchMedia===void 0)return;let e=window.matchMedia(`(max-width: 768px)`),n=e=>t(e.matches);return typeof e.addEventListener==`function`?e.addEventListener(`change`,n):e.addListener(n),()=>{typeof e.removeEventListener==`function`?e.removeEventListener(`change`,n):e.removeListener(n)}},[]),e}function No({chat:e,terminal:t,view:n,plugins:r,uiPrimary:i,uiOverflow:a,uiContextTopbar:o,onUiAction:s,onViewChange:c,onOpenPanel:l,onOpenSettings:u,onManagePlugins:d,onOpenBgTasks:f,onOpenGlobalSearch:p,sound:m,onSoundChange:h,onSoundPreview:_,themes:v,theme:y,onThemeChange:b,reloadThemes:x,onOpenIconEdit:S}){let{locale:C,setLocale:w,t:T,packs:E}=Mn(),[D,O]=(0,g.useState)(!1),[k,A]=(0,g.useState)(!1),[j,ee]=(0,g.useState)(null),M=Pa(`cwd`),te=Pa(`workspaceRoots`),ne=Fa(),N=(0,g.useRef)(null),F=t=>!e.tabs||t===`chat`||e.tabs.includes(t),re=[...a??[]].filter(e=>(e.source!==`host`||e.id!==`host:brand`)&&!Ni(e)),ie=new Set([...i??[],...a??[]].filter(e=>Ni(e)&&!e.hidden).map(e=>e.source.slice(7))),I=new Map((e.settings?.uiLayout?.order??[]).map((e,t)=>[e,t])),ae=r.map((e,t)=>({id:e.id,index:t})).sort((e,t)=>(I.get(`${e.id}:__view`)??1e6+e.index)-(I.get(`${t.id}:__view`)??1e6+t.index)).map(e=>e.id),L=i===void 0?[`host:history`,`host:brand`,`host:open-project`,`host:chat`,`host:terminal`,`host:git`,`host:plugins`,`host:search`,`host:browser`,`host:tasks`,`host:settings`,`host:sound`,`host:language`,`host:theme`,`host:update`,`host:github`,`host:new-chat`,`host:new-ephemeral-chat`,`host:files`].map(e=>({id:e,entry:null})):i.map(e=>({id:e.id,entry:e})),R=(F(`plugins`)?r:[]).filter(e=>e.view!==!1&&e.error&&!L.some(t=>t.id===`${e.id}:__view`)).map(e=>({id:`${e.id}:__view`,slot:`topbar.primary`,source:`plugin:${e.id}`,label:e.name,kind:`view`,view:`plugin:${e.id}`,order:23,align:`end`,hidden:!1,userOverrides:[],arrangedBy:[]})),B=e=>{if(e.source!==`host`)return!1;switch(e.id){case`host:history`:return l(`left`),!0;case`host:files`:return l(`right`),!0;case`host:new-chat`:return c(`chat`),$({type:`new_chat`}),or(),!0;case`host:new-ephemeral-chat`:return c(`chat`),$({type:`new_chat`,ephemeral:!0}),or(),!0;case`host:open-project`:return A(!0),!0;case`host:search`:return p(),!0;case`host:tasks`:return f(),!0;case`host:settings`:return u(),!0;case`host:plugins`:return ee(N.current?{rect:N.current.getBoundingClientRect(),el:N.current}:null),!0;default:return!1}},H=(t,n,r)=>{t.preventDefault(),t.stopPropagation();let i=e.settings?.uiLayout,a=e=>{let t={...i?.slots,[n]:e};$({type:`set_settings`,uiLayout:{...i,slots:t}})},s=()=>{let e=new Set(i?.hidden??[]);e.add(n),$({type:`set_settings`,uiLayout:{...i,hidden:[...e]}})},c=[{id:`host:move-bottom`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToBottom`),kind:`action`,order:10,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-left`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToLeft`),kind:`action`,order:20,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-right`,slot:`contextmenu.topbar`,source:`host`,label:T(`moveToRight`),kind:`action`,order:30,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:T(`uiLayoutRestore`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},...o??[]];la({x:t.clientX,y:t.clientY,slot:`contextmenu.topbar`,target:{id:n,label:r},entries:c,onHostAction:e=>{e.id===`host:move-bottom`?a(`bottombar`):e.id===`host:move-left`?a(`sidebar.left`):e.id===`host:move-right`?a(`sidebar.right`):e.id===`host:hide-item`&&s()}})},{appVersion:U}=Na(),W=Ia(),oe=La(),[G,ce]=(0,g.useState)(!1);(0,g.useEffect)(()=>{G&&e.status===`open`&&ce(!1)},[G,e.status]);let[K,ue]=(0,g.useState)(!1),[de,q]=(0,g.useState)(!1),[J,pe]=(0,g.useState)(!1),[me,Y]=(0,g.useState)(!1),he=Ln(),ge=yo(),[_e,ve]=(0,g.useState)(!1),ye=()=>{if(!e.ready)return;let n=T(`updateTabTitle`),r={name:n,command:`npm i -g pi-web-ui@latest`,cwd:"${pwd}"},i=e.terminals.find(e=>e.title===n);i?(t.restart(i.id),$({type:`run_command`,terminalId:i.id,conversationId:i.conversationId,command:r,cols:80,rows:24})):t.create({id:At(),conversationId:e.activeConversationId||e.state?.conversationId||``,title:n,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:r}),Y(!1),c(`terminal`)},Se=(n,r)=>{if(!e.ready||n.length===0)return;let i={name:r,command:Ot(n),cwd:"${pwd}"},a=e.terminals.find(e=>e.title===r);a?(t.restart(a.id),$({type:`run_command`,terminalId:a.id,conversationId:a.conversationId,command:i,cols:80,rows:24})):t.create({id:At(),conversationId:e.activeConversationId||e.state?.conversationId||``,title:r,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:i}),Y(!1),c(`terminal`)},Ce=e.updatesAll??[],we=e.updatesSdk,Te=we&&we.newerInstalled?{running:we.running,installed:we.newerInstalled}:null,Ee=we?.bundledInUse===!0,De=Ce.find(e=>e.kind===`pi-core`&&!e.error),ke=Ee&&(!De||!De.upToDate),Ae=ke&&!De,je=Ce.filter(e=>!e.upToDate&&!e.error).length,Me=Ce.filter(e=>!e.upToDate&&!e.error&&e.kind!==`webui`),Ne=e=>e.kind===`git-extension`&&e.source?e.source:e.name,ze=e=>e.kind===`git-extension`&&e.source&&e.source!==e.name?`${e.source} (${e.name})`:e.name,Be=e=>{let t=e.replace(/ \([0-9a-f]{7}\)$/,``);return/^[0-9a-f]{7}$/.test(t)?``:t},Ve=(e,t)=>{if(!t)return Be(e);let n=Be(e),r=Be(t);return n===r?n:`${n} → ${r}`},He=()=>(0,X.jsxs)(`div`,{className:`dd-updates-all`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`updatesAllTitle`)}),e.updatesAll===null?(0,X.jsx)(`div`,{className:`dd-note`,children:T(`checkingUpdate`)}):Ce.length===0?(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updatesAllUpToDate`)}):(0,X.jsx)(`ul`,{className:`dd-all-list`,children:Ce.map(e=>{let t=Te!=null&&e.kind===`pi-core`,n=!e.error&&(!e.upToDate||t);return(0,X.jsxs)(`li`,{className:`dd-all-item${e.error?` err`:n?` warn`:``}`,children:[e.kind!==`webui`&&!e.upToDate&&!e.error&&(0,X.jsx)(`button`,{type:`button`,className:`dd-update-btn`,onClick:()=>Se([e],T(`updatePkgTabTitle`,{name:e.name})),children:T(`updateBtn`)}),(0,X.jsx)(`span`,{className:`dd-all-name`,title:ze(e),children:Ne(e)}),(0,X.jsxs)(`span`,{className:`dd-all-meta`,children:[(0,X.jsx)(`span`,{className:`dd-all-kind`,children:e.kind===`webui`?T(`kindWebUi`):e.kind===`pi-core`?T(`kindPiCore`):e.kind===`git-extension`?T(`kindGitExtension`):e.kind===`plugin`?T(`kindPlugin`):T(`kindPackage`)}),(0,X.jsx)(`span`,{className:`dd-all-vers`,title:e.error?e.error:e.kind===`git-extension`?e.upToDate?e.current:`${e.current} → ${e.latest}`:void 0,children:e.error?T(`updateCheckFailed`):e.kind===`git-extension`?e.upToDate?Be(e.current):Ve(e.current,e.latest):e.kind===`plugin`?e.upToDate?e.current.startsWith(`v`)?e.current:Be(e.current):Ve(e.current,e.latest):e.upToDate?`v${e.current}`:(0,X.jsxs)(X.Fragment,{children:[`v`,e.current,` → v`,e.latest]})}),t&&!e.error&&(0,X.jsx)(`span`,{className:`dd-split-run`,children:T(`piCoreSplitRun`,{running:Te.running})})]})]},`${e.kind}:${e.name}`)})}),Te&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`piSdkSplitNote`,{running:Te.running,installed:Te.installed})}),ke&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`piSdkBundledNote`,{running:we.running})}),(0,X.jsxs)(`div`,{className:`dd-actions`,children:[Ae&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Se([Ao],T(`installGlobalEngineTabTitle`)),children:T(`installGlobalEngineBtn`)}),Me.length>0&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Se(Me,T(`updateAllTabTitle`)),children:T(`updateAllBtn`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,style:Me.length>0?{flex:1}:void 0,onClick:()=>$({type:`check_updates_all`,force:!0}),children:T(`updatesAllRefresh`)})]})]}),Ue=()=>{let t=vo(e.update?.latest??ge.version),n=(0,X.jsx)(`a`,{className:`dd-refresh dd-more-link`,href:t,target:`_blank`,rel:`noreferrer noopener`,children:T(`updateDesktopManual`)});if(!ge.bridge)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopNoBridge`)}),n]});switch(ge.state){case`checking`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopChecking`)}),n]});case`available`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopAvailable`,{version:ge.version??e.update?.latest??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.download(),children:T(`updateDesktopDownload`)}),n]});case`downloading`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopDownloading`,{n:ge.percent})}),n]});case`downloaded`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`updateDesktopDownloaded`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.quitAndInstall(),children:T(`updateDesktopInstall`)}),n]});case`up-to-date`:return(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`upToDate`)});case`error`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateDesktopError`,{error:ge.message??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>ge.check(),children:T(`updateDesktopCheck`)}),n]});default:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ge.check(),children:T(`updateDesktopCheck`)}),n]})}},We=()=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`dd-update`,children:[(0,X.jsxs)(`div`,{className:`dd-row`,children:[(0,X.jsx)(`span`,{children:T(`currentVersion`)}),(0,X.jsxs)(`b`,{children:[`v`,e.update?.current??`…`]})]}),(0,X.jsxs)(`div`,{className:`dd-row`,children:[(0,X.jsx)(`span`,{children:T(`latestVersion`)}),(0,X.jsx)(`b`,{children:e.update===null?T(`checkingUpdate`):e.update.error?e.update.error:e.update.latest?`v${e.update.latest}`:T(`checkingUpdate`)})]}),e.update&&e.update.upToDate&&(0,X.jsx)(`div`,{className:`dd-note ok`,children:T(`upToDate`)}),e.update&&!e.update.upToDate&&e.update.latest&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateAvailable`,{version:e.update.latest})}),e.update?.latestPublishedAt&&Date.now()-new Date(e.update.latestPublishedAt).getTime()<18e5&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:T(`updateJustPublished`,{version:e.update.latest??``})}),e.update&&!e.update.upToDate&&e.update.latest&&!he&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateTerminalHint`)}),e.update&&!e.update.upToDate&&e.update.latest&&he&&(0,X.jsx)(`div`,{className:`dd-note`,children:T(`updateDesktopNote`)})]}),(0,X.jsxs)(`div`,{className:`dd-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>$({type:`check_update`}),children:e.update===null?T(`checkingUpdate`):T(`checkUpdate`)}),e.update&&!e.update.upToDate&&e.update.latest&&!he&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:ye,children:T(`updateNow`)}),e.update&&!e.update.upToDate&&e.update.latest&&he&&Ue(),oe&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,disabled:G,title:T(`restartServiceTip`,{name:oe.name}),onClick:()=>{G||(ce(!0),$({type:`restart_service`}))},children:T(G?`restartingService`:`restartService`)})]})]}),qe=Mo(),Je={"host:brand":(0,X.jsxs)(`span`,{className:`brand`,children:[(0,X.jsx)(`span`,{className:`brand-logo`,children:`π`}),(0,X.jsx)(`span`,{className:`brand-name`,children:`pi-web-ui`})]}),"host:open-project":(0,X.jsxs)(`button`,{type:`button`,className:`chip open-project`,"data-tip":T(`openProject`),onClick:()=>A(!0),children:[(0,X.jsx)(Re,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`openProject`)})]}),"host:history":n===`chat`&&F(`history`)?(0,X.jsx)(`button`,{type:`button`,className:`panel-toggle`,"data-tip":T(`openHistory`),"aria-label":T(`openHistory`),onClick:()=>l(`left`),children:(0,X.jsx)(xe,{})}):null,"host:files":n===`chat`&&F(`files`)?(0,X.jsxs)(`button`,{type:`button`,className:`panel-toggle has-label`,"data-tip":T(`openFiles`),"aria-label":T(`openFiles`),onClick:()=>l(`right`),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{children:T(`openFiles`)})]}):null,"host:new-chat":F(`new-chat`)?(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat`,"data-tip":T(`newChatTip`),onClick:()=>{c(`chat`),$({type:`new_chat`}),or()},children:[(0,X.jsx)(fe,{}),(0,X.jsx)(`span`,{children:T(`newChat`)})]}):null,"host:new-ephemeral-chat":ne?null:(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat ephemeral-chat-btn`,"data-tip":T(`newChatEphemeralTip`),onClick:()=>{c(`chat`),$({type:`new_chat`,ephemeral:!0}),or()},children:[(0,X.jsx)(Dt,{}),(0,X.jsx)(`span`,{children:T(`newChatEphemeral`)})]}),"host:chat":(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`chat`,className:`tb-tab${n===`chat`?` active`:``}`,"data-tip":T(`chat`),onClick:()=>c(`chat`),children:[(0,X.jsx)(be,{}),(0,X.jsx)(`span`,{children:T(`chat`)})]}),"host:terminal":F(`terminal`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`terminal`,className:`tb-tab${n===`terminal`?` active`:``}`,"data-tip":T(`terminal`),onClick:()=>c(`terminal`),children:[(0,X.jsx)(z,{}),(0,X.jsx)(`span`,{children:T(`terminal`)})]}):null,"host:git":F(`git`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`git`,className:`tb-tab${n===`git`?` active`:``}`,"data-tip":T(`scmTab`),onClick:()=>c(`git`),children:[(0,X.jsx)(Ie,{}),(0,X.jsx)(`span`,{children:T(`scmTab`)})]}):null,"host:plugins":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`pluginMenuTitle`),"aria-haspopup":`menu`,"aria-expanded":j!==null,onClick:e=>{let t=e.currentTarget;ee(e=>e?.el===t?null:{rect:t.getBoundingClientRect(),el:t})},children:[(0,X.jsx)(mt,{"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`pluginMenuTitle`)})]}),"host:search":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`searchGlobalTip`),onClick:p,children:[(0,X.jsx)(le,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`searchGlobal`)})]}),"host:browser":e.settings?.disabledAgentTools?.includes(`browser_page`)??!1?null:(0,X.jsx)(lr,{}),"host:tasks":(0,X.jsxs)(`button`,{type:`button`,className:`chip bg-task-chip`,"data-tip":T(`bgTasksTip`),onClick:f,children:[(0,X.jsx)(Oe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`bgTasks`)}),e.bgServers.length>0&&(0,X.jsx)(`span`,{className:`bg-task-badge`,children:e.bgServers.length})]}),"host:settings":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":T(`settingsTitle`),onClick:u,children:[(0,X.jsx)(se,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`settings`)})]}),"host:sound":(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`sound`)})]}),tip:T(`sound`),open:K,onOpenChange:ue,caret:!1,children:[(0,X.jsx)(Pn,{settings:m,onChange:h,onPreview:_}),(0,X.jsx)(ii,{})]}),"host:language":(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Pe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:Tn(C)})]}),tip:T(`language`),open:de,onOpenChange:q,caret:!1,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`language`)}),E.map(e=>(0,X.jsx)(Vt,{active:C===e.code,onClick:()=>{w(e.code),q(!1)},children:e.nativeName},e.code)),(0,X.jsxs)(Vt,{onClick:()=>{q(!1),ve(!0)},children:[(0,X.jsx)(Ke,{}),` `,T(`localeGetMore`)]})]}),"host:theme":(0,X.jsx)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:T(`theme`)})]}),tip:T(`theme`),open:J,caret:!1,onOpenChange:e=>{pe(e),e&&v.length===0&&x()},children:(()=>{let e=v.filter(e=>e.group===`classic`),t=v.filter(e=>e.group!==`classic`),n=e=>{let t=C===`zh`?e.name:e.nameEn??e.name,n=e.scheme===`light`?T(`themeLight`):e.scheme===`dark`?T(`themeDark`):``;return n?C===`zh`?`${t}(${n})`:`${t} (${n})`:t};return(0,X.jsxs)(X.Fragment,{children:[e.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`themeGroupClassics`)}),e.map(e=>(0,X.jsx)(Vt,{active:y===e.id,onClick:()=>{b(e.id),pe(!1)},children:n(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:e.length>0?T(`themeGroupBuiltin`):T(`theme`)}),(0,X.jsx)(Vt,{active:y===null,onClick:()=>{b(null),pe(!1)},children:T(`themeDefault`)}),t.map(e=>(0,X.jsx)(Vt,{active:y===e.id,onClick:()=>{b(e.id),pe(!1)},children:n(e)},e.id))]})})()}),"host:update":W?(0,X.jsxs)(`span`,{className:`chip`,"data-tip":T(`updatesManaged`),children:[(0,X.jsx)(Ke,{}),(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`v`,U??e.update?.current??`…`]})]}):(0,X.jsxs)(Bt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ke,{}),(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`v`,e.update?.current??`…`]}),e.update&&!e.update.upToDate&&(0,X.jsx)(`span`,{className:`update-dot`,title:T(`updateAvailable`,{version:e.update.latest??``})}),je>0&&(0,X.jsx)(`span`,{className:`update-badge`,children:T(`updatesAllBadge`,{n:je})})]}),tip:T(`update`),open:me,caret:!1,onOpenChange:e=>{Y(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},fit:!0,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:T(`update`)}),We(),He()]}),"host:github":(0,X.jsx)(`a`,{className:`chip github`,href:`https://github.com/xing-shuyin/pi-web-ui`,target:`_blank`,rel:`noreferrer noopener`,"data-tip":T(`githubRepo`),children:(0,X.jsx)(Fe,{})}),"host:conn":(0,X.jsxs)(`span`,{className:`chip`,"data-tip":e.status,children:[(0,X.jsx)(`span`,{className:`status-dot ${e.status===`open`?`ok`:`busy`}`}),(0,X.jsx)(`span`,{className:`chip-sub`,children:e.status})]}),"host:engine":(0,X.jsx)(`span`,{className:`chip`,"data-tip":`engine`,children:(0,X.jsx)(`span`,{className:`chip-sub`,children:e.engine??`pi`})}),"host:ctx":(0,X.jsx)(`span`,{className:`chip`,"data-tip":T(`contextUsage`),children:(0,X.jsx)(`span`,{className:`chip-sub`,children:(e.state?.stats?.contextUsage?.tokens??0)>0?`${e.state?.stats?.contextUsage?.tokens}`:T(`contextUsage`)})}),"host:cost":(0,X.jsx)(`span`,{className:`chip`,"data-tip":T(`cumulativeCost`),children:(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`$`,(e.state?.stats?.cost??0).toFixed(4)]})}),"host:cwd":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":e.state?.cwd??``,onClick:()=>A(!0),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:e.state?.cwd?.split(/[/\\]/).pop()||e.state?.cwd})]})},Ye=new Set([`host:search`,`host:tasks`,`host:settings`,`host:plugins`]),Xe=new Set([`host:sound`,`host:language`,`host:theme`,`host:update`,`host:browser`]),Ze=e=>Ye.has(e)&&!F(e.slice(5)),Qe=e=>{if(e.kind===`view`){if(!F(`plugins`))return null;let t=e.view??``,i=r.find(t=>`plugin:${t.id}`===e.source),a=i?.error?`${e.label}: ${i.error}`:e.hint??e.label;return(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===t,className:`tb-tab plugin-tab${n===t?` active`:``}${i?.error?` broken`:``}`,"data-tip":a,onClick:()=>c(t),onContextMenu:t=>H(t,e.id,e.label),children:[(0,X.jsx)(fi,{icon:e.icon,iconSvg:e.iconSvg}),(0,X.jsx)(`span`,{children:e.label})]},e.id)}return e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`plugin-topbar-item plugin-topbar-select`,title:e.hint??e.label,"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>s?.(e,t.target.value),onContextMenu:t=>H(t,e.id,e.label),children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.id):(0,X.jsxs)(`button`,{type:`button`,className:`plugin-topbar-item`,"data-tip":e.hint??e.label,onClick:()=>s?.(e),onContextMenu:t=>H(t,e.id,e.label),children:[(0,X.jsx)(fi,{icon:e.icon,iconSvg:e.iconSvg}),(0,X.jsx)(`span`,{children:e.label})]},e.id)},$e=[];for(let t of L){if(t.entry?.hidden||Ze(t.id))continue;let i=null;t.entry?i=(0,X.jsx)(ko,{entry:t.entry,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onOpenPanel:l,onOpenSettings:u,onOpenGlobalSearch:p,onOpenBgTasks:f,onOpenProjectPicker:()=>A(!0),isProjectPickerOpen:k,onOpenPluginMenu:e=>ee(t=>t?.el===e?null:{rect:e.getBoundingClientRect(),el:e}),isPluginMenuOpen:j!==null,onUiAction:s,uiContextEntries:o,dropdownProps:{sound:m,onSoundChange:h,onSoundPreview:_,theme:y,themes:v,onThemeChange:b,reloadThemes:x,onLocaleModalOpen:()=>ve(!0),renderUpdateBody:We,renderAllUpdatesBody:He,updatesCount:je,managed:W,appVersion:U}},t.id):t.id.startsWith(`host:`)&&Je[t.id]&&(i=Je[t.id]),i&&$e.push({id:t.id,entry:t.entry,node:i})}for(let t of R){let i=(0,X.jsx)(ko,{entry:t,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onUiAction:s,uiContextEntries:o},t.id);i&&$e.push({id:t.id,entry:t,node:i})}let et=e=>e.entry?.align??`start`,[tt,nt]=(0,g.useState)(()=>new Set),rt=(0,g.useRef)(null),it=(0,g.useRef)(new Map),at=$e.filter(e=>!tt.has(e.id)),ot=qe?at.filter(e=>ra.has(e.id)):[],st=qe?at.filter(e=>!ra.has(e.id)):at,ct=qe?$e.filter(e=>!ra.has(e.id)):$e,lt=[...ct.filter(e=>et(e)===`start`),...ct.filter(e=>et(e)===`center`),...ct.filter(e=>et(e)===`end`)],ut=lt.filter(e=>!tt.has(e.id)),dt=(0,g.useRef)(lt),ft=(0,g.useRef)(ut);(0,g.useLayoutEffect)(()=>{dt.current=lt,ft.current=ut});let pt=()=>{let e=rt.current;if(!e||typeof ResizeObserver>`u`)return;let t=Array.from(e.children).filter(e=>!e.classList.contains(`tb-spacer`)),n=ft.current;t.length===n.length&&n.forEach((e,n)=>it.current.set(e.id,t[n].offsetWidth));let r=Number.parseFloat(getComputedStyle(e).columnGap)||0,i=dt.current,a=aa(i.map(e=>({id:e.id,width:e.entry?it.current.get(e.id)??0:0})),e.clientWidth,r,0,Ai);nt(e=>e.size===a.size&&[...a].every(t=>e.has(t))?e:a)},ht=`${at.map(e=>`${e.id}:${e.entry?.label??``}`).join(`|`)}|${n}|${(e.tabs??[]).join(`,`)}|${qe?`m`:`d`}`;(0,g.useLayoutEffect)(pt,[ht]),(0,g.useEffect)(()=>{let e=rt.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>pt());return t.observe(e),()=>t.disconnect()},[ht]);let gt=st.filter(e=>et(e)===`start`),_t=st.filter(e=>et(e)===`center`),vt=st.filter(e=>et(e)===`end`),yt=$e.filter(e=>tt.has(e.id)&&e.entry).map(e=>e.entry),bt=new Map;[...i??[],...a??[]].forEach((e,t)=>{bt.has(e.id)||bt.set(e.id,t)});let xt=ia([...re,...yt],e=>bt.get(e)??999999),St=e=>e.icon&&!/[a-z]/i.test(e.icon)?e.icon:null,Ct=e.settings?.uiLayout?.topbarText===!1;return(0,X.jsxs)(`header`,{className:`topbar${Ct?` no-labels`:``}`,"data-pi-anchor":`topbar`,children:[(0,X.jsxs)(`div`,{className:`topbar-flow`,ref:rt,role:`toolbar`,"aria-label":T(`viewSwitch`),children:[gt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),(_t.length>0||vt.length>0)&&(0,X.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),_t.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),_t.length>0&&(0,X.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),vt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id))]}),(xt.length>0||$e.length>0)&&(0,X.jsxs)(`div`,{className:`plugin-topbar-more`,children:[(0,X.jsx)(`button`,{ref:N,type:`button`,className:`plugin-topbar-item`,"aria-haspopup":`menu`,"aria-expanded":D,"aria-label":T(`pluginTopbarMore`),"data-tip":T(`pluginTopbarMore`),onClick:()=>O(e=>!e),children:(0,X.jsx)(Et,{})}),(0,X.jsxs)(jo,{anchorRef:N,open:D,onClose:()=>O(!1),children:[xt.map(e=>{let t=e.source===`host`&&Xe.has(e.id)?Je[e.id]:void 0;if(t!==void 0)return(0,X.jsx)(g.Fragment,{children:t},e.id);if(e.source===`host`&&e.id===`host:github`)return(0,X.jsxs)(`a`,{role:`menuitem`,className:`chip github`,href:`https://github.com/xing-shuyin/pi-web-ui`,target:`_blank`,rel:`noreferrer noopener`,title:T(`githubRepo`),onClick:()=>O(!1),children:[(0,X.jsx)(Fe,{}),(0,X.jsx)(`span`,{children:`GitHub`})]},e.id);if(e.source===`host`){let t=Je[e.id];if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>O(!1),children:t},e.id)}else{let t=Qe(e);if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>O(!1),children:t},e.id)}return e.kind===`select`&&e.options?.length?(0,X.jsxs)(`label`,{className:`plugin-topbar-overflow-select tb-row`,title:e.hint??e.label,children:[St(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:St(e)}):null,(0,X.jsx)(`span`,{className:`tb-row-text`,children:e.label}),(0,X.jsx)(`select`,{"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>{O(!1),B(e)||s?.(e,t.target.value)},children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.id):(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`tb-row`,title:e.hint??e.label,onClick:()=>{O(!1),B(e)||s?.(e)},children:[St(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:St(e)}):null,(0,X.jsx)(`span`,{className:`tb-row-text`,children:e.label})]},e.id)}),(0,X.jsx)(`div`,{className:`tb-menu-divider`,"aria-hidden":`true`}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`tb-row`,onClick:()=>{O(!1),S()},children:[(0,X.jsx)(Ge,{}),(0,X.jsx)(`span`,{className:`tb-row-text`,children:T(`uiIconEdit`)})]})]})]}),ot.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),_e&&(0,X.jsx)(uo,{onClose:()=>ve(!1)}),j&&(0,X.jsx)(lo,{anchorRect:j.rect,anchorEl:j.el,plugins:r,pinnedIds:ie,orderedPluginIds:ae,onTogglePin:(t,n)=>$({type:`set_settings`,uiLayout:Pi(e.settings?.uiLayout,t,n)}),onReorder:t=>$({type:`set_settings`,uiLayout:Fi(e.settings?.uiLayout,t)}),onOpenView:e=>{ee(null),c(`plugin:${e}`)},onManagePlugins:d,onClose:()=>ee(null)}),k&&(0,X.jsx)(io,{open:!0,currentCwd:M,pathCompletions:e.pathCompletions??[],workspaceRoots:te,onClose:()=>A(!1),onSelectDirectory:e=>$({type:`set_cwd`,path:e}),onCreateProject:e=>$({type:`make_dir`,path:e,setAsCwd:!0})})]})}function Po(e,t){let n={...t};if(!e)return n;try{let r=JSON.parse(e);if(r&&typeof r==`object`&&!Array.isArray(r))for(let e of Object.keys(t)){let t=r[e];typeof t==`number`&&Number.isFinite(t)&&t>0&&(n[e]=t)}}catch{}return n}function Fo(e){let t=e.start.above+e.start.below,n=Math.max(1,e.availablePx)/(e.totalWeight>0?e.totalWeight:1),r=e.minAbovePx/n,i=e.minBelowPx/n;if(r+i>=t){let n=e.minAbovePx+e.minBelowPx||1,r=t*e.minAbovePx/n;return{above:r,below:t-r}}let a=Math.min(t-i,Math.max(r,e.start.above+e.deltaPx/n));return{above:a,below:t-a}}function Io(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=e=>e.parentId?r.get(e.parentId)?.cwd??e.cwd:e.cwd,a=e.find(e=>e.id===n),o=a?i(a):t,s=new Map;for(let t of e){let e=i(t),n=s.get(e)??[];n.push(t),s.set(e,n)}let c=[...s.entries()].map(([e,t])=>({cwd:e,isCurrent:e===o,convs:t}));return c.sort((e,t)=>e.isCurrent?-1:t.isCurrent?1:e.cwd<t.cwd?-1:+(e.cwd>t.cwd)),c}function Lo(e,t=new Set){let n=new Map(e.map(e=>[e.id,e])),r=new Map,i=[];for(let t of e)if(t.parentId&&n.has(t.parentId)){let e=r.get(t.parentId)??[];e.push(t),r.set(t.parentId,e)}else i.push(t);let a=e=>{let t=[],n=[...r.get(e)??[]],i=new Set;for(;n.length>0;){let e=n.shift();if(i.has(e.id))continue;i.add(e.id),t.push(e);let a=r.get(e.id);a&&n.push(...a)}return t},o=[],s=new Set,c=new Set,l=(e,n)=>{if(s.has(e.id)||c.has(e.id))return;s.add(e.id);let i=r.get(e.id)??[],u=i.length>0,d=u&&t.has(e.id),f=0,p=!1,m=!1,h=!1;if(u){let t=a(e.id);if(f=t.length,p=t.some(e=>e.isStreaming),m=t.some(e=>!!e.error),h=t.some(e=>!!e.hasQuestion),d)for(let e of t)c.add(e.id)}if(o.push({c:e,depth:n,hasKids:u,isCollapsed:d,descendantCount:f,hasStreaming:p,hasError:m,hasQuestion:h}),!d)for(let e of i)l(e,n+1)};for(let e of i)l(e,0);for(let t of e)l(t,0);return o}function Ro(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;if(!t.trim())return null;let n=new URLSearchParams(t),r=n.get(`s`)?.trim()??``;if(!r)return null;let i=n.get(`m`)?.trim()||void 0;return i?{sessionId:r,messageId:i}:{sessionId:r}}function zo(e){let t=e?.sessionId?.trim()??``;if(!t)return``;let n=e?.messageId?.trim()??``,r=`#s=${encodeURIComponent(t)}`;return n?`${r}&m=${encodeURIComponent(n)}`:r}function Bo(e,t){let n=zo(t);try{let t=new URL(e);return t.searchParams.delete(`token`),t.hash=n,t.toString()}catch{return`${e.split(`#`)[0]??e}${n}`}}function Vo(e){if(!e)return null;let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);if(!t)return null;let n=t.split(`/`),r=n[n.length-1]??``;if(!r)return null;if(r===`session.jsonl`)return(n[n.length-2]?.trim()??``)||null;let i=r.endsWith(`.jsonl`)?r.slice(0,-6):r;if(!i)return null;let a=i.lastIndexOf(`_`);return(a>=0?i.slice(a+1).trim():i.trim())||null}function Ho(e,t){let n=t?.trim()??``;if(!n||e.length===0)return null;let r=e.find(e=>e.id===n);if(r)return r.id;let i=/^([a-z]+-\d+)-\d+$/.exec(n);if(i){let t=`${i[1]}-`,n=e.find(e=>e.id.startsWith(t));if(n)return n.id}return null}function Uo(e,t){let n=t.assistantMessageEvent,r=e.stats.tokens,i=t.usage===null?r:{...r,...t.usage},a=i===r?e.stats:{...e.stats,tokens:i};if(n.type!==`text_delta`&&n.type!==`thinking_delta`)return a===e.stats?e:{...e,stats:a};let o=n.delta??``;if(!o)return a===e.stats?e:{...e,stats:a};let s=e.streamingMessage??null,c=s&&s.id===t.messageId?s:{id:t.messageId,content:[]},l=[...c.content],u=n.type===`thinking_delta`?`thinking`:`text`,d=n.contentIndex??l.length-1;return d>=0&&d<l.length&&l[d].type===u?l[d]=u===`thinking`?{type:`thinking`,thinking:(l[d].thinking??``)+o}:{type:`text`,text:(l[d].text??``)+o}:l.push(u===`thinking`?{type:`thinking`,thinking:o}:{type:`text`,text:o}),{...e,stats:a,streamingMessage:{...c,id:t.messageId,content:l}}}function Wo(e){let{current:t,source:n,snapshot:r,answered:i,activeConversationId:a}=e;return r&&r.id&&!i.has(r.id)?t?.id===r.id?{changed:!1,question:t,source:n}:{changed:!0,question:r,source:`snapshot`}:t&&t.conversationId&&a&&t.conversationId!==a||!r&&t&&n===`snapshot`?{changed:!0,question:null,source:`live`}:{changed:!1,question:t,source:n}}var Go=new Set;function Ko(e){return Go.add(e),()=>{Go.delete(e)}}function qo(e,t){for(let n of Go)try{n(e,t)}catch(e){console.error(`[tui-overlay-bridge] listener error:`,e)}}function Jo(e){let t=typeof e.name==`string`?e.name:``;if(e.unsupported===!0)return{name:t,status:`unsupported`};if(e.found!==!0)return{name:t,status:`missing`};let n={name:t,status:`ready`};return e.label&&(n.label=e.label),e.description&&(n.description=e.description),e.promptSnippet&&(n.promptSnippet=e.promptSnippet),Array.isArray(e.promptGuidelines)&&e.promptGuidelines.length>0&&(n.promptGuidelines=e.promptGuidelines),e.parameters!==void 0&&(n.parameters=e.parameters),e.parametersDropped===!0&&(n.parametersDropped=!0),(e.active===!0||e.active===!1)&&(n.active=e.active),e.source&&(n.source=e.source),e.scope&&(n.scope=e.scope),n}var Yo=null,Xo=new Set;function Zo(){for(let e of Xo)e()}function Qo(e){let t=(e??``).trim();t&&(Yo={name:t,status:`loading`},Zo(),$({type:`get_tool_info`,name:t}))}function $o(){Yo!==null&&(Yo=null,Zo())}function es(e){Yo!==null&&Yo.name===e.name&&(Yo=Jo(e),Zo())}function ts(e){return Xo.add(e),()=>{Xo.delete(e)}}function ns(){return Yo}function rs(){return(0,g.useSyncExternalStore)(ts,ns,ns)}function is(e){let t=typeof e.name==`string`?e.name:``;if(e.unsupported===!0)return{name:t,status:`unsupported`};if(e.found!==!0)return{name:t,status:`missing`};let n={name:t,status:`ready`};return e.defaultDescription&&(n.defaultDescription=e.defaultDescription),e.defaultPromptSnippet&&(n.defaultPromptSnippet=e.defaultPromptSnippet),Array.isArray(e.defaultPromptGuidelines)&&e.defaultPromptGuidelines.length>0&&(n.defaultPromptGuidelines=e.defaultPromptGuidelines),e.override&&(n.override=e.override),n}var as={},os=new Set;function ss(){for(let e of os)e()}function cs(e){let t=(e??``).trim();t&&(as[t]&&as[t].status!==`loading`||(as={...as,[t]:{name:t,status:`loading`}},ss(),$({type:`get_tool_prompt`,name:t})))}function ls(e){let t=typeof e.name==`string`?e.name:``;t&&as[t]&&(as={...as,[t]:is(e)},ss())}function us(e){if(!as[e])return;let t={...as};delete t[e],as=t,ss()}function ds(e){return os.add(e),()=>os.delete(e)}function fs(e){return(0,g.useSyncExternalStore)(ds,()=>e?as[e]??null:null)}var ps=Object.freeze({status:`idle`,messages:[]}),ms=new Map,hs=new Set,gs=16;function _s(){for(;ms.size>gs;){let e=ms.keys().next().value;if(e===void 0)break;ms.delete(e)}}function vs(){for(let e of hs)e()}function ys(e,t){let n=(e??``).trim();if(!n)return;let r=ms.get(n);(!r||r.status!==`loading`&&r.status!==`ready`)&&(ms.set(n,{status:`loading`,messages:r?.messages??[]}),_s(),vs(),$({type:`get_compacted_messages`,compactionMessageId:n,conversationId:t}))}function bs(e){let t=e.compactionMessageId;t&&(e.error?ms.set(t,{status:`error`,messages:[],error:e.error}):ms.set(t,{status:`ready`,messages:e.messages??[]}),_s(),vs())}function xs(e){let t=ms.get(e);return t?(ms.delete(e),ms.set(e,t),t):ps}function Ss(e){return hs.add(e),()=>{hs.delete(e)}}function Cs(e){return(0,g.useSyncExternalStore)(Ss,()=>xs(e),()=>ps)}var ws=`__piWebUiHost`,Ts=e=>new Promise(t=>setTimeout(t,e));async function Es(e=3e3){let t=Date.now()+e;for(;;){let e=window.__piBridge;if(e&&typeof e.call==`function`)return e;if(Date.now()>=t)return null;await Ts(100)}}var Ds=Promise.resolve(),Os=0;function ks(e){let t=Math.max(1,Number(e.pollMs??100)),n=Math.max(t,Number(e.timeoutMs??8e3)),r=async e=>{let r=Date.now()+n;for(;;){if(e())return!0;if(Date.now()>=r)return e();await Ts(t)}},i=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},a=e=>{if(!e)return!0;try{return i().some(t=>t&&t.id===e)}catch{return!1}},o=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await r(()=>e.getCurrentModelId?.()===t))},s=async(t,n)=>{let i=String(n.cwd??``).trim();if(i&&e.getCwd()!==i&&(e.send({type:`set_cwd`,path:i}),await r(()=>e.getCwd()===i)),n.newChat!==!1){let t=e.getConversationId();e.send({type:`new_chat`}),await r(()=>e.getConversationId()!==t||e.isConversationBlank())}let a=String(n.model??``).trim();a&&await o(a),e.send({type:`prompt`,text:t})};return{version:11,setView(t){let n=String(t??``).trim();n&&e.setView(n)},startChat(t){let n=String(t?.prompt??``).trim();if(!n||!e.isReady())return!1;let r=String(t?.model??``).trim();if(r&&!a(r))return!1;let i=()=>s(n,t??{prompt:n}),o;return o=Os>0?Ds.then(i):i(),Os++,Ds=o.then(()=>{Os--},()=>{Os--}),o.catch(()=>{}),!0},models:{list:()=>i(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>ac(e)},compose(e){return sr()?cr({text:typeof e?.text==`string`?e.text:void 0,attachments:Array.isArray(e?.attachments)?e.attachments:void 0}):!1},openModal(t){let n=String(t??``).trim();if(!n||typeof e.openModal!=`function`)return!1;try{return e.openModal(n)}catch{return!1}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let n=Ps,i=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],s=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],c=String(t?.cwd??``).trim(),l=[...new Set([...i,...s])],u=c||l[0]||``;if(!u)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let d=l.filter(e=>e!==u).slice(0,7),f=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]);for(let t of[u,...d])if(!f.has(t)){if(!(e.confirm&&await e.confirm({path:t}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${t}`};e.grantPath?.(t,n)}if(e.getCwd()!==u&&(e.send({type:`set_cwd`,path:u}),!await r(()=>e.getCwd()===u)))return{ok:!1,error:`切换工作目录失败或超时:${u}`};(d.length>0||e.getWorkspaceRoots().length>0)&&e.send({type:`set_workspace_roots`,roots:d});let p=e.getConversationId()??void 0;if(t?.newChat!==!1){let t=p;e.send({type:`new_chat`}),await r(()=>e.getConversationId()!==t||e.isConversationBlank()),p=e.getConversationId()??void 0}let m=String(t?.model??``).trim();if(m){if(!a(m))return{ok:!1,error:`未知模型:${m}(先调 models.list() 取可用列表)`};await o(m),p=e.getConversationId()??p}let h=String(t?.prompt??``).trim();return h&&e.send({type:`prompt`,text:h}),{ok:!0,...p?{sessionId:p}:{}}},sessions:{list:()=>e.listSessions(),async open(t){let n=Ps,i=String(t??``).trim();if(!i)return{ok:!1,error:`sessions.open 需要一个会话 id(先调 list)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=e.listSessions().find(e=>e.id===i);if(!a)return{ok:!1,error:`找不到会话:${i}`};if(a.cwd&&a.cwd!==e.getCwd()){if(!new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]).has(a.cwd)){if(!(e.confirm&&await e.confirm({path:a.cwd}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${a.cwd}`};e.grantPath?.(a.cwd,n)}if(e.send({type:`set_cwd`,path:a.cwd}),!await r(()=>e.getCwd()===a.cwd))return{ok:!1,error:`切换工作目录失败或超时:${a.cwd}`}}let o=e.getConversationId();return a.kind===`running`?e.send({type:`switch_conversation`,id:a.id}):e.send({type:`switch_session`,path:a.id}),await r(()=>e.getConversationId()!==o)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${a.title}`}}},async reloadCatalog(t,n){let r=String(t??``).trim();if(!r)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let i=At();return new Promise(t=>{let a=setTimeout(()=>{pc.delete(i),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));pc.set(i,e=>{clearTimeout(a),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:i,source:r,...n?.install?{install:!0}:{},...n?.replace?{replace:!0}:{}})})},onUiAction(e,t){return Is(Ms,String(e??``).trim(),t)},onTopbarAction(e,t){return Is(Ms,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(Ln())return{ok:!1,error:`桌面版(Electron 外壳)不支持 browser_page:窗口里没有 Chrome 扩展运行时。请让用户改用系统浏览器打开同一个 pi-web-ui 地址(网页版)再试。/ The desktop app cannot run browser_page (no Chrome extension runtime); ask the user to open the same pi-web-ui address in a regular browser instead.`};let r=await Es(e.bridgeWaitMs??3e3);if(!r)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await r.call({op:n,...t.args===void 0?{}:{args:t.args},...t.target?{to:t.target}:{},...t.timeoutMs?{timeoutMs:t.timeoutMs}:{}});return e===void 0?{ok:!0}:{ok:!0,result:e}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},dom:{anchors(){let e=e=>{try{return document.querySelector(`[data-pi-anchor="${e}"]`)}catch{return null}};return{app:e(`app`),topbar:e(`topbar`),composer:e(`composer`)}}},dialogs:{async select(t){try{let n=e.select;if(typeof n!=`function`)return{ok:!1};let r=Array.isArray(t?.options)?t.options:[],i=await n({title:String(t?.title??``),options:r.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`).map(e=>({label:String(e.label),...typeof e.description==`string`?{description:e.description}:{}})),...t?.multi?{multi:!0}:{}});return!i||typeof i!=`object`||i.ok!==!0?{ok:!1,...i&&typeof i==`object`&&typeof i.error==`string`?{error:i.error}:{}}:{ok:!0,selected:Array.isArray(i.selected)?i.selected.filter(e=>typeof e==`string`):[]}}catch{return{ok:!1}}},async confirm(t){let n=String(t?.title??``),r=typeof t?.detail==`string`?t.detail:``;try{if(typeof e.dialogConfirm==`function`)try{return await e.dialogConfirm({title:n,...r?{detail:r}:{}})===!0}catch{}if(typeof window<`u`&&typeof window.confirm==`function`)try{return window.confirm(r?`${n}\n\n${r}`:n)}catch{return!1}return!1}catch{return!1}},async input(t){try{let n=e.input;if(typeof n!=`function`)return{ok:!1};let r=await n({title:String(t?.title??``),...typeof t?.placeholder==`string`?{placeholder:t.placeholder}:{},...typeof t?.initial==`string`?{initial:t.initial}:{}});return!r||typeof r!=`object`||r.ok!==!0?{ok:!1}:typeof r.value==`string`?{ok:!0,value:r.value}:{ok:!0}}catch{return{ok:!1}}}},async notifyAction(t){let n=String(t?.text??``),r=(Array.isArray(t?.actions)?t.actions:[]).filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.label==`string`);try{if(typeof e.notifyAction==`function`){let t=await e.notifyAction({text:n,actions:r});return typeof t==`string`?t:null}}catch{return null}try{typeof window<`u`&&typeof window.dispatchEvent==`function`&&window.dispatchEvent(new CustomEvent(Rs,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ks(String(e??``),t)},searchProviders:{register:e=>Js(e),list:()=>Ys()},composerProviders:{register:e=>Zs(e),list:()=>Qs()},onTheme:e=>sc(e),onLocale:e=>cc(e),onViewChange:e=>lc(e)}}function As(e){try{let t=window;e?t[ws]=e:delete t[ws]}catch{}}var js=new Map,Ms=null;async function Ns(e,t){let n=Ms;Ms=e;try{return await t()}finally{Ms=n}}var Ps=void 0;function Fs(e,t){let n=Ps;Ps=e;try{return t()}finally{Ps=n}}function Is(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=js.get(r);i||(i=new Set,js.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&js.delete(r)}}async function Ls(e,t,n,r){let i=i=>{let a=js.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{Fs(e,()=>i(n,r?.value,r?.target))}catch(n){console.error(`[plugin:${e}] 顶栏动作 ${t} 抛错:`,n)}return!0};if(i(`${e}:${t}`)||i(t))return!0;if(r?.loadBundle&&await r.loadBundle(e).catch(()=>!1)){let n=Date.now()+Math.max(100,Number(r.waitMs??1500));for(;;){if(i(`${e}:${t}`)||i(t))return!0;if(Date.now()>=n)break;await new Promise(e=>setTimeout(e,100))}}return!1}var Rs=`pi-web-ui:toast`,zs=new Map,Bs=!1;function Vs(e){let t=e.split(`+`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(t.length===0)return null;let n=!1,r=!1,i=!1,a=!1;for(let e of t.slice(0,-1))if(e===`ctrl`||e===`control`)n=!0;else if(e===`shift`)r=!0;else if(e===`alt`||e===`option`)i=!0;else if(e===`meta`||e===`cmd`||e===`command`||e===`win`||e===`super`)a=!0;else return null;let o=t[t.length-1]??``;return!o||[`ctrl`,`control`,`shift`,`alt`,`option`,`meta`,`cmd`,`command`,`win`,`super`].includes(o)?null:{combo:`${n?`ctrl+`:``}${r?`shift+`:``}${i?`alt+`:``}${a?`meta+`:``}${o}`,key:o,ctrl:n,shift:r,alt:i,meta:a}}function Hs(){try{if(typeof document>`u`)return!1;let e=document.activeElement;if(!e)return!1;let t=(e.tagName||``).toUpperCase();return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}catch{return!1}}function Us(e){try{if(Hs())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=zs.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function Ws(){if(!Bs)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,Us),Bs=!0}catch{}}function Gs(){if(!(zs.size>0||!Bs))try{window.removeEventListener(`keydown`,Us)}catch{}finally{Bs=!1}}function Ks(e,t){if(typeof t!=`function`)return()=>{};let n=Vs(e);if(!n)return()=>{};let r=zs.get(n.combo);r||(r=new Set,zs.set(n.combo,r));let i=r;return i.add(t),Ws(),()=>{i.delete(t),i.size===0&&zs.delete(n.combo),Gs()}}var qs=new Map;function Js(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return qs.set(t,n),()=>{qs.get(t)===n&&qs.delete(t)}}function Ys(){return[...qs.values()].map(e=>({id:e.id,label:e.label}))}var Xs=new Map;function Zs(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return Xs.set(t,n),()=>{Xs.get(t)===n&&Xs.delete(t)}}function Qs(){return[...Xs.values()].map(e=>({id:e.id,label:e.label}))}function $s(e){return Xs.get(String(e??``))}function ec(e){return qs.get(String(e??``))}var tc=new Set,nc=new Set,rc=new Set,ic=new Set;function ac(e){return ic.add(e),()=>{ic.delete(e)}}function oc(e){for(let t of ic)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function sc(e){return typeof e==`function`?(tc.add(e),()=>{tc.delete(e)}):()=>{}}function cc(e){return typeof e==`function`?(nc.add(e),()=>{nc.delete(e)}):()=>{}}function lc(e){return typeof e==`function`?(rc.add(e),()=>{rc.delete(e)}):()=>{}}function uc(e){let t=String(e??``);for(let e of tc)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function dc(e){let t=String(e??``);for(let e of nc)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function fc(e){let t=String(e??``);for(let e of rc)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var pc=new Map;function mc(e){let t=pc.get(e.requestId);if(t){if(pc.delete(e.requestId),!e.ok){t({ok:!1,error:e.error??`目录同步失败`});return}t({ok:!0,...e.entries?{entries:e.entries}:{},...e.installed?{installed:e.installed}:{}})}}var hc=`modulepreload`,gc=function(e){return`/`+e},_c={},vc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=gc(t,n),t=s(t),t in _c)return;_c[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:hc,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},yc=`pi-web-ui:plugin-data`;function bc(e,t){window.dispatchEvent(new CustomEvent(yc,{detail:{pluginId:e,payload:t}}))}function xc(e){let t=t=>{let n=t.detail;e(n.pluginId,n.payload)};return window.addEventListener(yc,t),()=>window.removeEventListener(yc,t)}var Sc=new Map,Cc=new Set,wc=new Set,Tc=new Set,Ec=new Set,Dc=-1;function Oc(){return[...Sc.values()]}function kc(){let e=Oc();for(let t of wc)t(e)}function Ac(){let e=[...Tc];for(let t of Ec)t(e)}function jc(e){return Ec.add(e),e([...Tc]),()=>Ec.delete(e)}async function Mc(e,t){Tc.delete(e.id),Pc.set(e.id,(Pc.get(e.id)??0)+1),Ac();let n=await zc(e,t);return kc(),n}function Nc(e){return wc.add(e),e(Oc()),()=>wc.delete(e)}var Pc=new Map;function Fc(e,t){let n=Pc.get(e)??0;return dn(`/plugins/${encodeURIComponent(e)}/client/entry.mjs?e=${t}${n>0?`&r=${n}`:``}`)}function Ic(e){let t=Promise.resolve();return(n,r)=>{let i=t.then(()=>Ns(n,()=>e(r)));return t=i.then(()=>void 0,()=>void 0),i}}var Lc=Ic(e=>vc(()=>import(e),[]));async function Rc(e,t){if(!e.hasClient||e.error)return null;try{return(await Lc(e.id,Fc(e.id,t))).default??null}catch(t){return console.error(`[plugin:${e.id}] 客户端 bundle 加载失败:`,t),null}}async function zc(e,t){try{let n=(await Lc(e.id,Fc(e.id,t))).default;return n&&typeof n.mount==`function`?(Sc.set(e.id,{info:e,module:n}),!0):e.preload?(Cc.add(e.id),!0):(Tc.add(e.id),Ac(),console.error(`[plugin:${e.id}] entry.mjs 缺少 default.mount`),!1)}catch(t){return Tc.add(e.id),Ac(),console.error(`[plugin:${e.id}] 客户端加载失败:`,t),!1}}async function Bc(e,t){if(Sc.has(e.id)||Cc.has(e.id))return!0;if(Tc.has(e.id)||!e.hasClient)return!1;let n=await zc(e,t);return kc(),n}async function Vc(e,t){t!==Dc&&(Dc=t,Sc.clear(),Cc.clear(),Tc.clear(),Pc.clear(),Ac());let n=new Set(e.map(e=>e.id));for(let e of[...Sc.keys()])n.has(e)||Sc.delete(e);for(let e of[...Cc])n.has(e)||Cc.delete(e);for(let e of[...Tc])n.has(e)||Tc.delete(e);Ac(),await Promise.all(e.filter(e=>e.hasClient&&(e.view!==!1||e.preload)&&!e.error&&!Sc.has(e.id)&&!Cc.has(e.id)&&!Tc.has(e.id)).map(e=>zc(e,t))),kc()}function Hc(e,t){return{pluginId:e,send:n=>t({type:`plugin_message`,pluginId:e,payload:n}),onData:t=>xc((n,r)=>{n===e&&t(r)})}}var Uc=[`debug`,`info`,`warn`,`error`];function Wc(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`get`}}}function Gc(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`clear`}}}function Kc(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.__host!==`logs`||!Array.isArray(t.logs)?!1:t.logs.every(e=>!!e&&typeof e==`object`&&typeof e.ts==`number`&&typeof e.text==`string`&&Uc.includes(String(e.level)))}var qc=new Map,Jc=new Set;function Yc(){for(let e of[...Jc])try{e()}catch{}}function Xc(e){return Jc.add(e),()=>Jc.delete(e)}function Zc(e){return(qc.get(e)??[]).map(e=>({...e}))}function Qc(e,t){return Kc(t)?(qc.set(e,t.logs.map(e=>({ts:e.ts,level:e.level,text:e.text}))),Yc(),!0):!1}function $c(){return{flows:[],results:{}}}function el(e,t){let n=e.findIndex(e=>e.flowId===t.flowId);return n<0?[...e,t]:e.map((e,r)=>r===n?t:e)}function tl(e,t){switch(t.type){case`provider_oauth_started`:{let n={...e.results};return delete n[t.provider],{flows:[...e.flows.filter(e=>e.provider!==t.provider),{flowId:t.flowId,provider:t.provider}],results:n}}case`provider_oauth_flows`:return{...e,flows:t.flows.map(e=>({...e}))};case`provider_oauth_prompt`:{let n=e.flows.find(e=>e.flowId===t.flowId);return{...e,flows:el(e.flows,{...n,flowId:t.flowId,provider:t.provider,promptId:t.promptId,prompt:t.prompt})}}case`provider_oauth_event`:{let n=e.flows.find(e=>e.flowId===t.flowId);return{...e,flows:el(e.flows,{...n,flowId:t.flowId,provider:t.provider,event:t.event,promptId:void 0,prompt:void 0})}}case`provider_oauth_result`:return{flows:e.flows.filter(e=>e.flowId!==t.flowId),results:{...e.results,[t.provider]:{ok:t.ok,...t.cancelled===void 0?{}:{cancelled:t.cancelled},...t.error===void 0?{}:{error:t.error}}}};case`provider_oauth_logout_result`:return{...e,results:{...e.results,[t.provider]:{ok:t.ok,...t.error===void 0?{}:{error:t.error}}}}}}var nl=`pi-web-ui:lang`;function rl(){try{return(localStorage.getItem(nl)??``).trim()}catch{return``}}var il=`pi-web-ui:locale`,al=2e5,ol=2e5,sl=`LIVE_OMIT`,cl={conversationId:null,goal:null,reviewModel:null,maxRounds:3,locked:!0,reviewing:!1,round:0,status:``,verdict:`pending`,wizard:{active:!1,draft:``,model:null,step:0,maxSteps:6,status:``}};function ll(){let e=new Map,t=new Map,n=(e,t)=>`${e}:${t}`;return{write(r,i,a){let o=n(r,i),s=e.get(o);if(s&&s.size>0){for(let e of s)try{e.write(a)}catch{}return}let c=t.get(o)??``,l=c.length+a.length>ol?a:c+a;t.set(o,l)},register(r,i,a){let o=n(r,i),s=e.get(o);s||(s=new Set,e.set(o,s)),s.add(a);let c=t.get(o);if(c){try{a.write(c)}catch{}t.delete(o)}return()=>{let n=e.get(o);n&&(n.delete(a),n.size===0&&e.delete(o)),t.delete(o)}},clear(){e.clear(),t.clear()}}}function ul(e,t){let n=new Set;for(let e of t.messages)e.role===`toolResult`&&e.toolCallId&&n.add(e.toolCallId),e.role===`bashExecution`&&n.add(`bash-${e.id}`);let r=!1;for(let t of e.keys())n.has(t)&&(e.delete(t),r=!0);return r?new Map(e):e}function dl(e,t){if(e.size===0)return e;let n=new Set;for(let e of t.messages)e.role===`toolResult`&&e.toolCallId&&n.add(e.toolCallId);let r=!1;for(let t of e.keys())n.has(t)&&(e.delete(t),r=!0);return r?new Map(e):e}function fl(e,t){switch(t.type){case`status`:return{...e,status:t.status,ready:t.status===`open`&&e.ready,terminals:t.status===`closed`?[]:e.terminals,hostMetrics:t.status===`closed`?null:e.hostMetrics};case`sync_cached_sessions`:return{...e,sessions:t.sessions};case`host_metrics`:return{...e,hostMetrics:t.metrics};case`ready`:return{...e,serverVersion:t.serverVersion,engine:t.engine,appVersion:t.appVersion,managed:t.managed===!0,tabs:t.tabs,ready:!0,protocolMismatch:t.protocolVersion!==void 0&&t.protocolVersion!==29};case`snapshot`:{let n=e.state?.cwd,r=t.state.cwd,i=e.sessions;return r&&r!==n&&(i=El(r)),{...e,ready:!0,state:t.state,sessions:i,approval:t.state.pendingApproval??null,activeConversationId:t.state.conversationId,liveOutputs:ul(e.liveOutputs,t.state),toolStatuses:dl(e.toolStatuses,t.state)}}case`snapshot_delta`:{let n=e.state,r=t.msg;if(!n||n.conversationId!==r.conversationId||n.rev!==r.baseRev)return e;let i={...n,...r.state,messages:r.appended.length>0?[...n.messages,...r.appended]:n.messages};return{...e,ready:!0,state:i,approval:i.pendingApproval===void 0?e.approval:i.pendingApproval??null,activeConversationId:i.conversationId,liveOutputs:ul(e.liveOutputs,i),toolStatuses:dl(e.toolStatuses,i)}}case`tool_approval`:return{...e,approval:t.approval};case`tool_delta`:{let n=(e.liveOutputs.get(t.toolCallId)?.text??``)+t.delta,r=n.length>al?`…[${sl}:${n.length-al}]…\n`+n.slice(n.length-al):n,i=new Map(e.liveOutputs);return i.set(t.toolCallId,{toolName:t.toolName,text:r}),{...e,liveOutputs:i}}case`message_delta`:{let n=e.state;return!n||n.conversationId!==t.msg.conversationId?e:{...e,state:Uo(n,t.msg)}}case`tool_status`:return{...e,toolStatuses:new Map(e.toolStatuses).set(t.status.toolCallId,t.status)};case`notice`:return{...e,notices:[...e.notices,t.notice].slice(-6)};case`dismiss_notice`:return{...e,notices:e.notices.filter(e=>e.id!==t.id)};case`sessions`:return Dl(e.state?.cwd,t.sessions),{...e,sessions:t.sessions};case`conversations`:return{...e,conversations:t.conversations,elsewhere:t.elsewhere??[],activeConversationId:t.activeId};case`projects`:return Sl(t.projects),{...e,projects:t.projects};case`files`:return{...e,files:t.files};case`file_changed`:return{...e,fileChanged:{path:t.path}};case`file_content`:return{...e,fileContent:t.content};case`models`:return{...e,models:t.models,modelsLoading:t.loading};case`models_config`:return{...e,modelsConfig:t.providers};case`providers_status`:return{...e,providers:t.providers};case`provider_keys`:return{...e,providerKeys:t.keys};case`default_model`:return{...e,defaultModel:t.modelId};case`provider_oauth`:{let n=tl({flows:e.providerOAuthFlows,results:e.providerOAuthResults},t.message);return{...e,providerOAuthFlows:n.flows,providerOAuthResults:n.results}}case`fetch_models_result`:return{...e,fetchModelsResult:t.result};case`test_model_connection_result`:return{...e,testModelConnectionResult:t.result};case`enrich_models_progress`:return{...e,enrichModelsProgress:t.progress};case`enrich_models_result`:return{...e,enrichModelsResult:t.result,enrichModelsProgress:null};case`refresh_provider_result`:return{...e,refreshProviderResult:t.result};case`refresh_builtin_result`:return{...e,refreshBuiltinResult:t.result};case`append_builtin_result`:return{...e,appendBuiltinResult:t.result};case`clone_provider_result`:return{...e,cloneProviderResult:t.result};case`install_result`:return{...e,installResult:t.result};case`scm_data`:return{...e,scmData:t.data};case`file_search_result`:return{...e,fileSearch:t.result};case`session_search_result`:return{...e,sessionSearch:t.result};case`scm_changed`:return{...e,scmDirty:e.scmDirty+1};case`path_completions`:return{...e,pathCompletions:t.completions};case`update_status`:return{...e,update:t.status};case`update_status_all`:return{...e,updatesAll:t.items,updatesSdk:t.piSdk??null};case`updates_check_started`:return{...e,updatesAll:null};case`widgets`:return{...e,widgets:t.widgets};case`statuses`:return{...e,statuses:t.statuses};case`dialog`:return{...e,dialog:t.dialog};case`tui_overlay`:return{...e,tuiOverlay:t.overlay};case`question`:return{...e,question:t.question};case`remote_question`:return{...e,remoteQuestion:t.question};case`commands`:return{...e,commands:t.commands,commandsPath:t.path};case`slash_commands`:return{...e,slashCommands:t.commands};case`goal_status`:return{...e,goal:t.status};case`plan_updated`:{let n=e.state;if(!n)return e;let r=e.activeConversationId||n.conversationId;if(!t.conversationId||t.conversationId!==r)return e;let i={...n,plan:t.plan};return{...e,state:i}}case`settings`:return{...e,settings:t.settings};case`mcp_servers`:return e.settings?{...e,settings:{...e.settings,mcpServers:t.servers,mcpGlobalConfigPath:t.globalConfigPath??e.settings.mcpGlobalConfigPath,mcpProjectConfigPath:t.projectConfigPath??e.settings.mcpProjectConfigPath}}:e;case`mcp_market_result`:return{...e,mcpMarketResult:t.result};case`skill_market_result`:return{...e,skillMarketResult:t.result};case`skill_content_result`:return{...e,skillContentResult:t.result};case`bg_servers`:return{...e,bgServers:t.servers};case`scheduler_tasks`:return{...e,schedulerTasks:t.tasks};case`plugin_panel_items`:return{...e,pluginPanelGroups:t.groups};case`plugins`:return{...e,plugins:t.plugins,pluginsEpoch:t.epoch};case`plugin_updates_check_started`:return{...e,checkingPluginUpdates:!0};case`plugin_updates`:{let n={};for(let e of t.updates)n[e.id]=e;return{...e,pluginUpdates:n,checkingPluginUpdates:!1}}case`plugin_catalog`:return{...e,pluginCatalog:t.entries,pluginCatalogEpoch:t.epoch};case`plugin_grants`:return{...e,pluginGrants:t.grants};case`plugin_permissions`:return{...e,pluginPermissions:t.grants};case`plugin_path_request`:return{...e,pathRequests:[...e.pathRequests.filter(e=>e.id!==t.req.id),t.req]};case`plugin_path_resolved`:return{...e,pathRequests:e.pathRequests.filter(e=>e.id!==t.id)};case`plugin_permission_request`:return{...e,permRequests:[...e.permRequests.filter(e=>e.id!==t.req.id),t.req]};case`plugin_permission_resolved`:return{...e,permRequests:e.permRequests.filter(e=>e.id!==t.id)};case`plugin_job`:{let{pluginId:n,phase:r,ok:i,action:a}=t.job,o=e.pluginUpdates;a===`update`&&r===`done`&&i&&e.pluginUpdates?.[n]&&(o={...e.pluginUpdates,[n]:{...e.pluginUpdates[n],updatable:!1}});let s=e.pluginJobs[t.job.jobId],c=t.line?[...s?.lines??[],t.line].slice(-40):s?.lines??[],l={...s,...t.job,lines:c,startedAt:s?.startedAt??Date.now()};return{...e,pluginUpdates:o,pluginJobs:{...e.pluginJobs,[t.job.jobId]:l}}}case`plugin_catalog_sync_result`:return{...e,catalogSync:{...t.result,receivedAt:Date.now()}};case`preset_export_result`:return{...e,presetExport:{...t.result,receivedAt:Date.now()}};case`preset_import_result`:return{...e,presetImport:{...t.result,source:t.source,receivedAt:Date.now()}};case`preset_catalog_result`:return{...e,presetCatalog:{...t.result,receivedAt:Date.now()}};case`preset_share_result`:return{...e,presetShare:{...t.result,receivedAt:Date.now()}};case`plugin_install_inspect_result`:return{...e,installInspect:t.result};case`dsh_patches`:return{...e,dshPatches:{patchDir:t.patchDir,files:t.files}};case`dsh_presets`:return{...e,dshPresets:{presets:t.presets,defaultPreset:t.defaultPreset}};case`dsh_permission`:return{...e,dshPermission:{options:t.options,defaultPreset:t.defaultPreset}};case`terminal_add`:return{...e,terminals:[...e.terminals,t.meta]};case`terminal_remove`:return{...e,terminals:e.terminals.filter(e=>e.id!==t.id)};case`terminal_exit`:return t.conversationId&&(e.activeConversationId||e.state?.conversationId)&&t.conversationId!==(e.activeConversationId||e.state?.conversationId)?e:{...e,terminals:e.terminals.map(e=>e.id===t.terminalId?{...e,running:!1,exitCode:t.exitCode}:e)};case`terminal_restart`:return{...e,terminals:e.terminals.map(e=>e.id===t.terminalId?{...e,running:!0,exitCode:null}:e)};case`terminal_list`:return t.conversationId&&(e.activeConversationId||e.state?.conversationId)&&t.conversationId!==(e.activeConversationId||e.state?.conversationId)?e:{...e,terminals:t.terminals.map(n=>({...n,conversationId:t.conversationId??e.state?.conversationId??``}))};case`terminal_active`:return{...e,terminalActiveId:t.id};default:return e}}var pl=`pi-web-client-id`,ml=null;function hl(){if(ml)return ml;let e=null;try{e=sessionStorage.getItem(pl),e||(e=At(),sessionStorage.setItem(pl,e))}catch{e??=At()}return ml=e,e}var gl=`pi-web-last-cwd`;function _l(){try{return localStorage.getItem(gl)}catch{return null}}function vl(e){try{localStorage.setItem(gl,e)}catch{}}function yl(e){try{let t=localStorage.getItem(gl);if(!t)return;let n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase();(t===e||n(t)===n(e))&&localStorage.removeItem(gl)}catch{}}var bl=`pi-web-recent-projects`;function xl(){try{let e=localStorage.getItem(bl);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Sl(e){try{localStorage.setItem(bl,JSON.stringify(e.slice(0,20)))}catch{}}function Cl(e){try{let t=xl(),n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),r=n(e);Sl(t.filter(e=>n(e.path)!==r))}catch{}}var wl=`pi-web-recent-sessions:`;function Tl(e){return e?`${wl}${e.trim().replace(/[\\/]+$/,``).toLowerCase()}`:`pi-web-recent-sessions:default`}function El(e){try{let t=Tl(e??_l()),n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function Dl(e,t){try{let n=Tl(e??_l());localStorage.setItem(n,JSON.stringify(t.slice(0,50)))}catch{}}function Ol(e,t){try{let n=El(t),r=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),i=r(e);Dl(t,n.filter(e=>r(e.path)!==i))}catch{}}function kl(){return hn(`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}${dn(`/ws`)}`)}function Al(){let[e,t]=(0,g.useReducer)(fl,{status:`connecting`,ready:!1,state:null,hostMetrics:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:El(),conversations:[],elsewhere:[],activeConversationId:``,projects:xl(),files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],providerKeys:{},defaultModel:null,providerOAuthFlows:[],providerOAuthResults:$c().results,installResult:null,pathCompletions:[],update:null,updatesAll:null,updatesSdk:null,widgets:[],statuses:[],dialog:null,tuiOverlay:null,approval:null,question:null,remoteQuestion:null,commands:[],commandsPath:``,slashCommands:[],terminals:[],terminalActiveId:null,goal:cl,bgServers:[],schedulerTasks:[],pluginPanelGroups:[],settings:null,fetchModelsResult:null,testModelConnectionResult:null,enrichModelsResult:null,enrichModelsProgress:null,refreshProviderResult:null,refreshBuiltinResult:null,appendBuiltinResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,pluginUpdates:null,checkingPluginUpdates:!1,pluginCatalog:[],pluginCatalogEpoch:0,pluginJobs:{},catalogSync:null,presetExport:null,presetImport:null,presetCatalog:null,presetShare:null,installInspect:null,pluginGrants:[],pluginPermissions:[],pathRequests:[],permRequests:[],dshPatches:null,mcpMarketResult:null,skillMarketResult:null,skillContentResult:null,dshPresets:null,dshPermission:null,protocolMismatch:!1}),n=(0,g.useRef)(null),r=(0,g.useRef)(ll()),i=(0,g.useRef)(0),a=(0,g.useRef)(null),o=(0,g.useRef)(!0),s=(0,g.useRef)(0),c=(0,g.useRef)(0),l=(0,g.useRef)(new Map),u=(0,g.useRef)(null),d=(0,g.useRef)(!1),f=(0,g.useRef)(null),p=(0,g.useRef)(new Set),m=(0,g.useRef)(`live`),h=()=>{u.current||=setTimeout(()=>{u.current=null;let e=n.current;e&&e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`get_state`}))},300)},_=(e,t)=>{let n=l.current,r=n.get(e);if(r!==void 0&&t!==r+1){let t=O.current.chat;e===(t.activeConversationId||t.state?.conversationId)&&h()}n.set(e,t)},v=(0,g.useCallback)((e,n)=>{let r=++c.current;t({type:`notice`,notice:{id:r,level:e,text:n}})},[]),y=(0,g.useCallback)(e=>{let r=n.current;if(r&&r.readyState===WebSocket.OPEN){if(e.type===`check_updates_all`&&e.force===!0&&t({type:`updates_check_started`}),e.type===`check_plugin_updates`&&t({type:`plugin_updates_check_started`}),r.send(JSON.stringify(e)),e.type===`question_answer`){if(e.owner){let n=O.current.chat.remoteQuestion;n&&n.id===e.id&&t({type:`remote_question`,question:null})}else{if(p.current.add(e.id),p.current.size>64){let e=p.current.values().next().value;e!==void 0&&p.current.delete(e)}m.current=`live`,t({type:`question`,question:null})}}return!0}return!1},[]),b=(0,g.useCallback)((e,n)=>{let r=Wo({current:O.current.chat.question,source:m.current,snapshot:e,answered:p.current,activeConversationId:n});r.changed&&(m.current=r.source,t({type:`question`,question:r.question}))},[]);za(y);let x=(0,g.useCallback)(()=>{if(!o.current)return;t({type:`status`,status:`connecting`});let e=new WebSocket(kl());n.current=e,e.onopen=()=>{n.current===e&&(t({type:`status`,status:`open`}),i.current=0,s.current=Date.now(),e.send(JSON.stringify({type:`hello`,clientId:hl(),locale:rl()})))},e.onmessage=i=>{if(n.current!==e)return;s.current=Date.now();let a;try{a=JSON.parse(i.data)}catch{return}switch(a.type){case`ready`:if((O.current.chat.settings?.autoReload??!0)&&a.buildId&&a.buildId!==`20261011T00563`){let e=`pi-web-ui-reloaded-${a.buildId}`;if(!sessionStorage.getItem(e)){sessionStorage.setItem(e,`1`),location.reload();return}}Aa({engine:a.engine??`pi`,managed:!!a.managed,tabs:a.tabs,appVersion:a.appVersion,serverVersion:a.serverVersion,service:a.service}),t({type:`ready`,serverVersion:a.serverVersion,protocolVersion:a.protocolVersion,engine:a.engine,appVersion:a.appVersion,managed:a.managed,tabs:a.tabs,service:a.service}),p.current.clear(),t({type:`question`,question:null}),e.send(JSON.stringify({type:`get_state`})),e.send(JSON.stringify({type:`list_files`})),e.send(JSON.stringify({type:`list_models`})),e.send(JSON.stringify({type:`list_commands`})),e.send(JSON.stringify({type:`get_commands`})),a.managed||(e.send(JSON.stringify({type:`check_update`})),e.send(JSON.stringify({type:`check_updates_all`})));break;case`snapshot`:l.current=new Map,t({type:`snapshot`,state:a.state}),b(a.state.pendingQuestion,a.state.conversationId);break;case`snapshot_delta`:{let e=O.current.chat.state;if(e)(e.conversationId!==a.conversationId||e.rev!==a.baseRev)&&h();else{let e=n.current;e&&e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`get_state`}))}t({type:`snapshot_delta`,msg:a}),b(a.state.pendingQuestion,a.conversationId);break}case`tool_delta`:_(a.conversationId,a.seq),t({type:`tool_delta`,toolCallId:a.toolCallId,toolName:a.toolName,delta:a.delta});break;case`tool_status`:t({type:`tool_status`,status:a});break;case`message_delta`:_(a.conversationId,a.seq),t({type:`message_delta`,msg:a});break;case`subagent_handoff`:break;case`notice`:{let e=++c.current;t({type:`notice`,notice:{id:e,level:a.level,text:a.text,textEn:a.textEn}});break}case`sessions`:t({type:`sessions`,sessions:a.sessions});break;case`conversations`:t({type:`conversations`,conversations:a.conversations,activeId:a.activeId,elsewhere:a.elsewhere});break;case`projects`:t({type:`projects`,projects:a.projects});break;case`files`:t({type:`files`,files:a});break;case`file_changed`:t({type:`file_changed`,path:a.path});break;case`file_content`:t({type:`file_content`,content:a});break;case`models`:t({type:`models`,models:a.models,loading:!1});break;case`models_config`:t({type:`models_config`,providers:a.providers});break;case`providers_status`:t({type:`providers_status`,providers:a.providers});break;case`provider_keys`:t({type:`provider_keys`,keys:a.keys});break;case`default_model`:t({type:`default_model`,modelId:a.modelId});break;case`provider_oauth_started`:case`provider_oauth_flows`:case`provider_oauth_prompt`:case`provider_oauth_event`:case`provider_oauth_result`:case`provider_oauth_logout_result`:t({type:`provider_oauth`,message:a});break;case`fetch_models_result`:t({type:`fetch_models_result`,result:{reqId:a.reqId,ok:a.ok,models:a.models,error:a.error}});break;case`test_model_connection_result`:t({type:`test_model_connection_result`,result:{reqId:a.reqId,ok:a.ok,latencyMs:a.latencyMs,error:a.error}});break;case`enrich_models_progress`:t({type:`enrich_models_progress`,progress:{reqId:a.reqId,phase:a.phase,current:a.current,total:a.total,message:a.message}});break;case`enrich_models_result`:t({type:`enrich_models_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results,error:a.error}});break;case`refresh_provider_result`:t({type:`refresh_provider_result`,result:{reqId:a.reqId,ok:a.ok,added:a.added,total:a.total,error:a.error}});break;case`refresh_builtin_result`:t({type:`refresh_builtin_result`,result:{reqId:a.reqId,ok:a.ok,error:a.error}});break;case`append_builtin_result`:t({type:`append_builtin_result`,result:{reqId:a.reqId,ok:a.ok,error:a.error}});break;case`clone_provider_result`:t({type:`clone_provider_result`,result:{reqId:a.reqId,ok:a.ok,config:a.config,configs:a.configs,error:a.error}});break;case`scm_data`:t({type:`scm_data`,data:a});break;case`search_files_result`:t({type:`file_search_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results,truncated:a.truncated}});break;case`session_search_results`:t({type:`session_search_result`,result:{reqId:a.reqId,ok:a.ok,results:a.results}});break;case`scm_changed`:t({type:`scm_changed`});break;case`tool_info`:es(a);break;case`tool_prompt`:ls(a);break;case`compacted_messages_result`:bs(a);break;case`heartbeat`:a.hostMetrics&&t({type:`host_metrics`,metrics:a.hostMetrics});break;case`install_result`:t({type:`install_result`,result:a});break;case`path_completions`:t({type:`path_completions`,completions:a.completions});break;case`update_status`:t({type:`update_status`,status:a});break;case`update_status_all`:t({type:`update_status_all`,items:a.items,piSdk:a.piSdk});break;case`widgets`:t({type:`widgets`,widgets:a.widgets});break;case`statuses`:t({type:`statuses`,statuses:a.statuses});break;case`dialog`:t({type:`dialog`,dialog:{id:a.id,kind:a.kind,title:a.title,args:a.args}});break;case`dialog_closed`:t({type:`dialog`,dialog:null});break;case`tui_overlay_open`:t({type:`tui_overlay`,overlay:{id:a.id,title:a.title,cols:a.cols,rows:a.rows,initialAnsi:a.initialAnsi}});break;case`tui_overlay_render`:qo(a.id,a.ansi);break;case`tui_overlay_close`:t({type:`tui_overlay`,overlay:null});break;case`question_pending`:m.current=`live`,t({type:`question`,question:{id:a.id,...a.deadline===void 0?{}:{deadline:a.deadline},questions:a.questions,...a.conversationId===void 0?{}:{conversationId:a.conversationId},...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`tool_approval_pending`:t({type:`tool_approval`,approval:{id:a.id,toolCallId:a.toolCallId,toolName:a.toolName,params:a.params,reason:a.reason,reasonEn:a.reasonEn,...a.category?{category:a.category}:{},...a.conversationId===void 0?{}:{conversationId:a.conversationId},...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`tool_approval_resolved`:t({type:`tool_approval`,approval:null});break;case`question_retracted`:{let e=O.current.chat.question;if(e&&e.id===a.id){if(p.current.add(a.id),p.current.size>64){let e=p.current.values().next().value;e!==void 0&&p.current.delete(e)}m.current=`live`,t({type:`question`,question:null})}break}case`elsewhere_question`:t({type:`remote_question`,question:{owner:a.owner,convId:a.convId,id:a.id,questions:a.questions,...a.conversationTitle===void 0?{}:{conversationTitle:a.conversationTitle}}});break;case`page_request`:(async()=>{let e=window.__piWebUiHost,t;if(!e?.pageCall)t={ok:!1,error:`宿主页面桥不可用(页面版本过旧?)—— 刷新本页后再试`};else try{t=await e.pageCall({op:a.op,...a.args===void 0?{}:{args:a.args},...a.target?{target:a.target}:{},timeoutMs:a.timeoutMs})}catch(e){t={ok:!1,error:e instanceof Error?e.message:String(e)}}y({type:`page_response`,id:a.id,ok:t.ok===!0,...t.ok===!0?t.result===void 0?{}:{result:t.result}:{error:t.error??`页面操作失败`}})})();break;case`terminal_output`:r.current.write(a.conversationId??O.current.chat.activeConversationId,a.terminalId,a.data);break;case`terminal_exit`:t({type:`terminal_exit`,conversationId:a.conversationId,terminalId:a.terminalId,exitCode:a.exitCode});break;case`terminal_list`:t({type:`terminal_list`,conversationId:a.conversationId,terminals:a.terminals});break;case`commands`:t({type:`commands`,commands:a.commands,path:a.path});break;case`slash_commands`:t({type:`slash_commands`,commands:a.commands});break;case`goal_status`:t({type:`goal_status`,status:a.status});break;case`plan_updated`:t({type:`plan_updated`,conversationId:a.conversationId,plan:a.plan});break;case`settings_state`:t({type:`settings`,settings:a.settings});break;case`mcp_servers`:t({type:`mcp_servers`,servers:a.servers,globalConfigPath:a.globalConfigPath,projectConfigPath:a.projectConfigPath});break;case`mcp_market_result`:t({type:`mcp_market_result`,result:a});break;case`skill_market_result`:t({type:`skill_market_result`,result:a});break;case`skill_content_result`:t({type:`skill_content_result`,result:a});break;case`bg_servers`:t({type:`bg_servers`,servers:a.servers});break;case`scheduler_tasks`:t({type:`scheduler_tasks`,tasks:a.tasks});break;case`plugin_panel_items`:t({type:`plugin_panel_items`,groups:a.groups});break;case`plugins`:t({type:`plugins`,plugins:a.plugins,epoch:a.epoch});break;case`plugin_updates`:t({type:`plugin_updates`,updates:a.updates});break;case`plugin_catalog`:t({type:`plugin_catalog`,entries:a.entries,epoch:a.epoch});break;case`plugin_grants`:t({type:`plugin_grants`,grants:a.grants});break;case`plugin_permissions`:t({type:`plugin_permissions`,grants:a.grants});break;case`plugin_permission_request`:t({type:`plugin_permission_request`,req:{id:a.id,pluginId:a.pluginId,family:a.family,...a.hosts?{hosts:a.hosts}:{},...a.models?{models:a.models}:{},...a.reason?{reason:a.reason}:{}}});break;case`plugin_permission_resolved`:t({type:`plugin_permission_resolved`,id:a.id});break;case`plugin_path_request`:t({type:`plugin_path_request`,req:{id:a.id,pluginId:a.pluginId,path:a.path,...a.reason?{reason:a.reason}:{}}});break;case`plugin_dom_consent_request`:a.from===hl()&&e.send(JSON.stringify({type:`plugin_dom_consent_response`,id:a.id,ok:!0}));break;case`plugin_job`:t({type:`plugin_job`,job:{jobId:a.jobId,action:a.action,pluginId:a.pluginId,phase:a.phase,...a.ok===void 0?{}:{ok:a.ok},...a.error?{error:a.error}:{},...a.output?{output:a.output}:{}},...a.line?{line:a.line}:{}});break;case`plugin_install_inspect_result`:t({type:`plugin_install_inspect_result`,result:{requestId:String(a.requestId??``),source:String(a.source??``),kind:a.kind,suggestedId:String(a.suggestedId??``),installed:a.installed===!0,...a.problem?{problem:a.problem}:{},...a.detail?{detail:a.detail}:{},...a.manifest?{manifest:a.manifest}:{}}});break;case`plugin_catalog_sync_result`:mc(a),t({type:`plugin_catalog_sync_result`,result:{requestId:String(a.requestId??``),ok:a.ok===!0,...a.error?{error:a.error}:{},...a.entries?{entryCount:a.entries.length}:{},...a.installed?{installed:a.installed}:{}}});break;case`preset_export_result`:t({type:`preset_export_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,...a.name?{name:a.name}:{},...a.fileName?{fileName:a.fileName}:{},...a.json?{json:a.json}:{},...a.error?{error:a.error}:{}}});break;case`preset_import_result`:{let e=String(a.requestId??``),n=e.startsWith(`url:`)?`url`:e.startsWith(`file:`)?`file`:`paste`;t({type:`preset_import_result`,source:n,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,dryRun:a.dryRun===!0,...a.preview?{preview:a.preview}:{},...a.applied?{applied:!0}:{},...a.error?{error:a.error}:{}}});break}case`preset_catalog_result`:t({type:`preset_catalog_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,entries:a.entries??[],source:a.source??``,cached:a.cached===!0,fetchedAt:a.fetchedAt??0,...a.error?{error:a.error}:{}}});break;case`preset_share_result`:t({type:`preset_share_result`,result:{...a.requestId?{requestId:a.requestId}:{},ok:a.ok===!0,...a.method?{method:a.method}:{},...a.url?{url:a.url}:{},...a.name?{name:a.name}:{},...a.json?{json:a.json}:{},...a.error?{error:a.error}:{}}});break;case`dsh_patches`:t({type:`dsh_patches`,patchDir:a.patchDir,files:a.files});break;case`dsh_presets`:t({type:`dsh_presets`,presets:a.presets,defaultPreset:a.defaultPreset});break;case`dsh_permission`:t({type:`dsh_permission`,options:a.options,defaultPreset:a.defaultPreset});break;case`plugin_data`:Qc(a.pluginId,a.payload)||bc(a.pluginId,a.payload);break;case`remote_ssh_probe_result`:case`remote_ssh_list_dir_result`:case`remote_ssh_install_result`:case`remote_ssh_profiles_result`:Ha(a)}},e.onclose=()=>{if(n.current===e&&(n.current=null),r.current.clear(),!o.current||n.current&&n.current!==e)return;t({type:`status`,status:`closed`});let s=Math.min(1e3*2**i.current,1e4);i.current+=1,a.current=setTimeout(()=>{a.current=null,x()},s)},e.onerror=()=>{}},[]);(0,g.useEffect)(()=>{let e=e=>{let t=e.detail??rl();t&&y({type:`set_locale`,locale:t})};return window.addEventListener(il,e),()=>window.removeEventListener(il,e)},[y]),(0,g.useEffect)(()=>{let n=n=>{let r=e.state?.cwd;r&&n.key&&n.key===Tl(r)&&t({type:`sync_cached_sessions`,sessions:El(r)})};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e.state?.cwd]),(0,g.useEffect)(()=>{o.current=!0,x();let e=setInterval(()=>{if(!o.current)return;let e=n.current;e&&e.readyState===WebSocket.OPEN&&Date.now()-s.current>3e4&&e.close()},5e3),t=()=>{if(!o.current||typeof document<`u`&&document.visibilityState===`hidden`)return;let e=n.current;if(!e||e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING){a.current&&=(clearTimeout(a.current),null),x();return}e.readyState===WebSocket.OPEN&&(Date.now()-s.current>15e3||!O.current.chat.state)&&e.send(JSON.stringify({type:`get_state`}))};return typeof document<`u`&&document.addEventListener(`visibilitychange`,t),typeof window<`u`&&(window.addEventListener(`pageshow`,t),window.addEventListener(`online`,t)),()=>{o.current=!1,clearInterval(e),a.current&&=(clearTimeout(a.current),null),typeof document<`u`&&document.removeEventListener(`visibilitychange`,t),typeof window<`u`&&(window.removeEventListener(`pageshow`,t),window.removeEventListener(`online`,t)),n.current?.close(),n.current=null}},[x]),(0,g.useEffect)(()=>{let t=e.state?.cwd;if(t){if(!d.current){d.current=!0;let e=_l();if(e&&e!==t){y({type:`set_cwd`,path:e});return}}f.current!==t&&(f.current=t,vl(t))}},[e.state?.cwd,y]),(0,g.useEffect)(()=>{Aa({ready:e.ready,status:e.status,cwd:e.state?.cwd??``,workspaceRoots:e.state?.workspaceRoots??[],homeDir:e.state?.homeDir??``,desktopDir:e.state?.desktopDir??``})},[e.ready,e.status,e.state?.cwd,e.state?.workspaceRoots,e.state?.homeDir,e.state?.desktopDir]);let S=(0,g.useCallback)(e=>t({type:`dismiss_notice`,id:e}),[]),C=(0,g.useCallback)(e=>t({type:`terminal_add`,meta:e}),[]),w=(0,g.useCallback)(e=>t({type:`terminal_remove`,id:e}),[]),T=(0,g.useCallback)(e=>t({type:`terminal_restart`,terminalId:e}),[]),E=(0,g.useCallback)(e=>t({type:`terminal_active`,id:e}),[]),D=(0,g.useCallback)((e,t,n)=>r.current.register(e,t,n),[]),O=(0,g.useRef)({chat:e,send:y,pushNotice:v,dismissNotice:S,terminal:{create:C,close:w,register:D,restart:T,select:E}});return O.current={chat:e,send:y,pushNotice:v,dismissNotice:S,terminal:{create:C,close:w,register:D,restart:T,select:E}},O.current}function jl(e){let t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`:`${t.getMonth()+1}/${t.getDate()}`}function Ml(e){let t=e instanceof HTMLElement?e:null;if(!t)return!1;let n=t.tagName;return n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t.isContentEditable}var Nl=`pi-web-ui:lp-collapse-projects`,Pl=`pi-web-ui:lp-collapse-convs`,Fl=`pi-web-ui:lp-collapse-sessions`,Il=`pi-web-ui:lp-collapse-subagents`;function Ll(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Il);if(e)return new Set(JSON.parse(e))}catch{}return new Set});return[e,(0,g.useCallback)(e=>{t(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(Il,JSON.stringify([...n]))}catch{}return n})},[])]}function Rl(e,t=!1){let[n,r]=(0,g.useState)(()=>{try{let t=localStorage.getItem(e);if(t===`1`)return!0;if(t===`0`)return!1}catch{}return t});return[n,(0,g.useCallback)(()=>{r(t=>{let n=!t;try{localStorage.setItem(e,n?`1`:`0`)}catch{}return n})},[e])]}var zl=`pi-web-ui:lp-collapse-plugin-sections`;function Bl(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(zl),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}});return[e,(0,g.useCallback)(e=>{t(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(zl,JSON.stringify([...n]))}catch{}return n})},[])]}var Vl=`pi-web-ui:lp-sizes`,Hl={projects:1,convs:1,sessions:1},Ul=32,Wl={running:`pluginRunStatusRunning`,done:`pluginRunStatusDone`,error:`pluginRunStatusError`},Gl=72;function Kl(){try{return xi(localStorage.getItem(Vl),Hl)}catch{return{...Hl}}}var ql=(0,g.memo)(function({sessionFile:e,conversations:t,elsewhere:n,sessions:r,projects:i,activeConversationId:a,panelSend:o,active:s,collapsible:c,onToggleCollapse:l,pathCompletions:u,uiContextSession:d,uiLeftSessions:f,uiContextProject:p,uiProjectsActions:m,uiLeftProject:h,uiRunningActions:_,uiHistoryActions:v,uiSections:y,renderPluginSectionBody:b,uiPluginRunning:x,onPluginRunningAction:S,uiLeftRunning:C,uiLeftHistory:w,onUiAction:T,presetNames:E}){let D=Z(),O=e,k=Pa(`ready`),A=Pa(`status`),j=Pa(`cwd`),ee=Pa(`workspaceRoots`),M=j,[te,ne]=(0,g.useState)(!1),[P,F]=(0,g.useState)(null),[re,ie]=(0,g.useState)(null),[I,ae]=(0,g.useState)(null),[R,z]=(0,g.useState)(``),[B,V]=Rl(Nl,!1),[H,U]=Rl(Pl,!1),[W,oe]=Rl(Fl,!1),[G,se]=Bl(),[ce,K]=Ll(),le=(0,g.useCallback)((e,t)=>{if(!t)return e.filter(e=>e.isSubagent&&!e.isStreaming&&e.id!==a).length;let n=new Map(e.map(e=>[e.id,e])),r=e=>{if(e.id===t)return(n.get(t)?.isSubagent??!1)&&!e.isStreaming&&e.id!==a;let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&!e.isStreaming&&e.id!==a&&r(e)).length},[a]),ue=(0,g.useCallback)((e,t)=>{if(!t)return e.filter(e=>e.isSubagent).length;let n=new Map(e.map(e=>[e.id,e])),r=e=>{if(e.id===t)return n.get(t)?.isSubagent??!1;let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&r(e)).length},[]),de=(0,g.useCallback)((e,t)=>{if(!t)return 0;let n=new Map(e.map(e=>[e.id,e])),r=e=>{let r=e,i=new Set;for(;r?.parentId;){if(r.parentId===t)return!0;if(i.has(r.parentId)||(i.add(r.parentId),r=n.get(r.parentId),!r))return!1}return!1};return e.filter(e=>e.isSubagent&&e.isStreaming&&r(e)).length},[]),q=(0,g.useRef)(null),J=(0,g.useRef)(null),pe=(0,g.useRef)(()=>{}),me=ba(d??[]).length>0,Y=(0,g.useCallback)((e,n,i)=>{q.current={x:e,y:n,target:i};let a=i.kind===`running`?i.id:void 0,o=i.kind===`elsewhere`,s=a??(o&&i.id||void 0),c=le(t,a),l=c===0?D(`noFinishedSubagents`):D(a?`dismissFinishedSubagentsScoped`:`dismissFinishedSubagents`,{n:c}),u=!!a&&J.current===a;la({x:e,y:n,slot:`contextmenu.session`,target:i,entries:(d??[]).map(e=>{if(e.source!==`host`)return e;if(e.id===`host:conv-rename`)return i.kind===`running`||i.kind===`history`?e:{...e,hidden:!0};if(e.id===`host:conv-takeover`)return o&&s&&i.owner&&!i.pseudo?e:{...e,hidden:!0};if(o&&(e.id===`host:conv-dismiss-subagents`||e.id===`host:conv-force-dismiss`))return{...e,hidden:!0};if(e.id===`host:conv-dismiss-subagents`)return{...e,label:l,...c===0?{when:[...e.when??[],`disabled`]}:{}};if(e.id===`host:conv-force-dismiss`)return a?{...e,...u?{label:D(`forceDismissConfirm`)}:{}}:{...e,hidden:!0};if(e.id===`host:conv-pin`){if(i.kind===`history`)return r.find(e=>e.path===i.id)?.pinned?{...e,label:D(`unpinConversation`)}:e;if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return!n||n.isSubagent?{...e,hidden:!0}:n.pinned?{...e,label:D(`unpinConversation`)}:e}if(e.id===`host:conv-persist`){if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return!n||!n.isSubagent&&n.sessionFile?{...e,hidden:!0}:n?.isEphemeral?{...e,label:D(`saveEphemeral`)}:e}if(e.id===`host:conv-copy-id`)return s?e:{...e,hidden:!0};if(e.id===`host:conv-copy-path`)return i.kind===`history`?e:a?t.some(e=>e.id===a&&e.sessionFile)?e:{...e,when:[...e.when??[],`disabled`]}:{...e,hidden:!0};if(e.id===`host:conv-copy-link`){if(i.kind===`history`)return r.find(e=>e.path===i.id)?.sessionId||Vo(i.id)?e:{...e,hidden:!0};if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return n?.sessionId||Vo(n?.sessionFile)?e:{...e,when:[...e.when??[],`disabled`]}}return e.id===`host:conv-quote`?s||i.kind===`history`?e:{...e,hidden:!0}:e}),onHostAction:(e,t)=>pe.current(e,t)})},[d,t,le,D]);pe.current=(0,g.useCallback)((e,n)=>{let i=n.kind===`running`?n.id:void 0,a=i??(n.kind===`elsewhere`&&n.id||void 0);if(e.id===`host:conv-takeover`){n.kind===`elsewhere`&&a&&n.owner&&o({type:`take_over_conversation`,owner:n.owner,id:a});return}if(e.id===`host:conv-dismiss-subagents`){o(i?{type:`dismiss_finished_subagents`,parentId:i}:{type:`dismiss_finished_subagents`});return}if(e.id===`host:conv-force-dismiss`){let e=q.current;if(!i||!e)return;if(J.current!==i)return J.current=i,Y(e.x,e.y,e.target),!0;J.current=null,o({type:`dismiss_conversation`,id:i,force:!0});return}if(e.id===`host:conv-persist`){i&&o({type:`persist_conversation`,id:i});return}if(e.id===`host:conv-pin`){if(n.kind===`history`){let e=r.find(e=>e.path===n.id);o({type:`pin_session`,path:n.id,pinned:!e?.pinned});return}i&&o({type:`pin_conversation`,id:i,pinned:!t.find(e=>e.id===i)?.pinned});return}if(e.id===`host:conv-copy-id`&&a){navigator.clipboard?.writeText(a).catch(()=>{});return}if(e.id===`host:conv-copy-path`){let e=n.kind===`history`?n.id:i&&t.find(e=>e.id===i)?.sessionFile||void 0;e&&navigator.clipboard?.writeText(e).catch(()=>{});return}if(e.id===`host:conv-copy-link`){let e=n.kind===`history`?r.find(e=>e.path===n.id)?.sessionId||Vo(n.id):i?t.find(e=>e.id===i)?.sessionId||Vo(t.find(e=>e.id===i)?.sessionFile):null;if(e){let t=Bo(window.location.href,{sessionId:e});navigator.clipboard?.writeText(t).catch(()=>{})}return}if(e.id===`host:conv-quote`){n.kind===`history`&&n.id?cr({attachments:[{path:``,key:`conv||${n.id}`,name:n.label||n.id,mode:`conversation`,sessionPath:n.id}]}):a&&cr({attachments:[{path:``,key:`conv|${a}|`,name:n.label||a,mode:`conversation`,conversationId:a}]});return}if(e.id===`host:conv-rename`){if(F(null),i){let e=t.find(e=>e.id===i);z(e?.title??n.label??``),ae(`conv:${i}`)}else if(n.kind===`history`&&n.id){let e=r.find(e=>e.path===n.id);z(e?.name??n.label??``),ae(n.id)}return}},[o,Y,t,r]);let ge=(e,t,n)=>!e||e.length===0?null:(0,X.jsx)(`span`,{className:t,children:e.map((e,t)=>{let r=`${e.id}#${t}`,i=e.label||e.id,a=e.hint||i;return e.kind===`divider`?(0,X.jsx)(`span`,{className:`lp-slot-divider`,"aria-hidden":`true`},r):e.kind===`badge`?(0,X.jsx)(`span`,{className:`lp-slot-badge`,title:a,children:e.badge??i},r):e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`lp-slot-select`,title:a,"aria-label":i,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onClick:e=>e.stopPropagation(),onChange:t=>{t.stopPropagation(),T?.(e,t.target.value)},children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},r):(0,X.jsx)(`button`,{type:`button`,className:`lp-slot-btn`,title:a,"aria-label":i,onClick:t=>{t.stopPropagation(),n?T?.(e,void 0,n):T?.(e)},children:e.icon?(0,X.jsx)(`span`,{"aria-hidden":!0,children:e.icon}):(0,X.jsx)(`span`,{children:i})},r)})}),_e=(0,g.useCallback)((e,t)=>{Ml(e.target)||me&&(e.preventDefault(),e.stopPropagation(),J.current=null,Y(e.clientX,e.clientY,t))},[me,Y]),ve=(0,g.useRef)(null),[ye,xe]=(0,g.useState)(()=>Kl());(0,g.useEffect)(()=>{try{localStorage.setItem(Vl,JSON.stringify(ye))}catch{}},[ye]);let Se=(0,g.useMemo)(()=>{let e=new Set,r=new Set;for(let n of t)n.sessionFile&&e.add(n.sessionFile),r.add(`${n.cwd}\0${n.title}`);let i=[],a=new Set;for(let t of n){if(t.sessionFile&&e.has(t.sessionFile)||r.has(`${t.cwd}\0${t.title}`))continue;let n=t.sessionFile?`file:${t.sessionFile}`:`title:${t.cwd}\0${t.title}`;a.has(n)||(a.add(n),i.push({id:t.sessionFile?`elsewhere:${t.cwd}:${t.sessionFile}`:`elsewhere:${t.cwd}:${t.title}${t.owner?`:${t.owner}`:``}`,title:t.title,cwd:t.cwd,messageCount:0,isStreaming:t.isStreaming,isSubagent:!1,elsewhere:!0,pseudo:!!t.pseudo,ownerOffline:!!t.ownerOffline,sessionFile:t.sessionFile,...t.owner&&t.convId?{owner:t.owner,convId:t.convId}:{},...t.hasQuestion?{hasQuestion:!0}:{}}))}return[...t,...i]},[t,n]),Ce=vi(y),we=Ce.filter(e=>e.shown),Te=e=>e===`projects`?B:e===`convs`?H:e===`sessions`?W:G.has(e),Ee=(x??[]).reduce((e,t)=>e+t.items.length,0),De=Se.length+Ee,Oe=yi(Ce,e=>e===`projects`?i.length>0:e!==`convs`||De>0),ke=()=>{let e=x??[];return e.length===0?null:e.map(e=>(0,X.jsxs)(`div`,{className:`panel-conv-group lp-plugin-group`,children:[(0,X.jsxs)(`div`,{className:`panel-conv-group-title`,title:e.pluginId,children:[D(`leftPanelPluginGroup`),` · `,e.pluginName]}),e.items.map(t=>(0,X.jsx)(`div`,{className:`lp-row lp-plugin-row`,children:(0,X.jsxs)(`button`,{type:`button`,className:`session-item lp-plugin-item${t.action?``:` is-static`}`,title:t.hint?`${t.title} — ${t.hint}`:t.title,onClick:()=>S?.(e,t),children:[(0,X.jsx)(`span`,{className:`lp-plugin-dot st-${t.status}`,title:D(Wl[t.status])}),t.icon?(0,X.jsx)(`span`,{className:`lp-plugin-icon`,"aria-hidden":!0,children:t.icon}):null,(0,X.jsxs)(`span`,{className:`session-info`,children:[(0,X.jsx)(`span`,{className:`session-title`,children:t.title}),t.hint?(0,X.jsx)(`span`,{className:`session-sub`,children:t.hint}):null]})]})},t.id))]},`plugin:${e.pluginId}`))},Ae=(0,g.useMemo)(()=>[...f??[],...C??[]],[f,C]),je=(0,g.useMemo)(()=>[...f??[],...w??[]],[f,w]),Me=(0,g.useCallback)((e,t)=>n=>{n.preventDefault();let r=n.currentTarget,i=n.clientY,a={...ye},o=ve.current;if(!o)return;let s=Oe.filter(e=>Te(e)).length,c=Oe.filter(e=>!Te(e)).reduce((e,t)=>e+(a[t]??1),0)||1,l=Math.max(120,o.clientHeight-s*Ul);r.classList.add(`dragging`),document.body.classList.add(`lp-resizing`);let u=n=>{let{above:r,below:o}=Fo({start:{above:a[e]??1,below:a[t]??1},deltaPx:n.clientY-i,availablePx:l,totalWeight:c,minAbovePx:Gl,minBelowPx:Gl});xe(n=>({...n,[e]:r,[t]:o}))},d=()=>{window.removeEventListener(`pointermove`,u),window.removeEventListener(`pointerup`,d),r.classList.remove(`dragging`),document.body.classList.remove(`lp-resizing`)};window.addEventListener(`pointermove`,u),window.addEventListener(`pointerup`,d)},[ye,Oe,B,H,W]);(0,g.useEffect)(()=>{s&&k&&A===`open`&&j&&(o({type:`list_sessions`}),o({type:`list_projects`}))},[s,k,A,j,o]);let Ne=e=>{let t=e.name||e.firstMessage.trim();return t.length>0?t:D(`emptyChat`)},Pe=e=>e.split(/[\\/]/).pop()||e,Fe=ba(p??[]).length>0,Ie=(0,g.useCallback)((e,t)=>{Ml(e.target)||Fe&&(e.preventDefault(),e.stopPropagation(),la({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.path,kind:`project`,label:Pe(t.path)},entries:p??[]}))},[Fe,p]),ze=(e,t,n,r,i)=>{let a=P===e;return(0,X.jsx)(`button`,{type:`button`,className:`lp-del ${a?`confirm`:``}`,title:a?n:t,onClick:t=>{t.stopPropagation(),a?(F(null),r()):F(e)},children:a?(0,X.jsx)(dt,{}):i??(0,X.jsx)(L,{})})},Be=(e,t,n,r,i,a)=>(0,X.jsxs)(`div`,{className:`lp-section-header`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`lp-section-title panel-section-title`,onClick:n,title:D(t?`expandSection`:`collapseSection`),children:[(0,X.jsxs)(`span`,{className:`lp-section-title-text`,children:[e,r===void 0?``:` (${r})`]}),(0,X.jsx)(`span`,{className:`lp-section-chevron`,children:t?(0,X.jsx)(ut,{}):(0,X.jsx)(st,{})})]}),i||a?(0,X.jsxs)(`div`,{className:`lp-section-actions`,children:[i,a]}):null]}),Ve=Oe.filter(e=>!Te(e)),He=Ve.reduce((e,t)=>e+(ye[t]??1),0)||1,Ue=e=>Ve.length<=1?1:(ye[e]??1)/He*Ve.length,We=new Map(bi(Oe,Te).map(([e,t])=>[e,(0,X.jsx)(`div`,{className:`lp-sash`,onPointerDown:Me(e,t),onDoubleClick:()=>xe({...Hl}),title:D(`dragToResize`)},`sash-${e}`)])),Ke={projects:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section panel-projects ${B||i.length===0?`collapsed`:``}`,style:i.length>0&&!B?{flex:`${Ue(`projects`)} 1 0px`}:void 0,children:[Be(D(`recentProjects`),B,V,i.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action`,title:D(`manageProjects`),"aria-label":D(`manageProjects`),onClick:()=>ne(!0),children:(0,X.jsx)(Re,{})}),ge(m,`lp-slot-section`)),i.length>0&&!B&&(0,X.jsx)(`div`,{className:`lp-section-body projects-scroll`,children:i.map(e=>{let t=M===e.path;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>F(t=>t===`proj:${e.path}`?null:t),onContextMenu:t=>Ie(t,e),children:[(0,X.jsxs)(`button`,{type:`button`,className:`project-item ${t?`active`:``}`,title:e.path,onClick:()=>{t||o({type:`set_cwd`,path:e.path})},children:[(0,X.jsx)(Le,{className:`project-icon`}),(0,X.jsxs)(`span`,{className:`project-info`,children:[(0,X.jsx)(`span`,{className:`project-name`,children:Pe(e.path)}),(0,X.jsx)(`span`,{className:`project-path`,children:e.path})]}),(0,X.jsx)(`span`,{className:`project-time`,children:jl(e.lastUsed)})]}),ze(`proj:${e.path}`,D(`deleteProject`),D(`deleteProjectConfirm`),()=>{yl(e.path),Cl(e.path),o({type:`remove_project`,path:e.path})}),ge(h,`lp-slot-project`,{id:e.path,kind:`project`,label:Pe(e.path)})]},e.path)})})]})}),convs:(0,X.jsx)(X.Fragment,{children:De>0&&(0,X.jsxs)(`div`,{className:`lp-section lp-section-convs panel-convs ${H?`collapsed`:``}`,style:H?void 0:{flex:`${Ue(`convs`)} 1 0px`},onContextMenu:e=>_e(e,{id:``,kind:`section`,label:D(`runningConversations`)}),children:[Be(D(`runningConversations`),H,U,De,void 0,ge(_,`lp-slot-section`)),!H&&(0,X.jsxs)(`div`,{className:`lp-section-body convs-scroll`,children:[Io(Se,j,a).map(e=>(0,X.jsxs)(`div`,{className:`panel-conv-group`,children:[!e.isCurrent&&(0,X.jsx)(`div`,{className:`panel-conv-group-title`,title:e.cwd,onContextMenu:t=>Ie(t,{path:e.cwd,lastUsed:0}),children:Pe(e.cwd)}),Lo(e.convs,ce).map(({c:n,depth:r,hasKids:i,isCollapsed:s,descendantCount:c,hasStreaming:l,hasError:u,hasQuestion:d})=>{if(n.elsewhere){let e=n.owner,t=n.convId,r=!!n.pseudo,i=!!n.ownerOffline&&!r,a=!!(e&&t)&&!r,s=re===n.id,c=s?D(`takeoverConfirm`):r?`${D(`elsewherePseudoTip`)}\n${n.cwd}`:`${D(i?`elsewhereOfflineTip`:`elsewhereTip`)}\n${n.cwd}`;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ie(e=>e===n.id?null:e),onContextMenu:i=>_e(i,{id:t??n.id,kind:`elsewhere`,label:n.title,...e?{owner:e}:{},...r?{pseudo:!0}:{}}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item elsewhere-item${a?``:` elsewhere-static`}${s?` confirm`:``}`,title:c,tabIndex:a?0:-1,onClick:a?()=>{if(!s){ie(n.id);return}ie(null),o({type:`take_over_conversation`,owner:e,id:t})}:void 0,children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[(0,X.jsxs)(`span`,{className:`session-title`,children:[(0,X.jsx)(`span`,{className:`elsewhere-badge`,children:D(r?`elsewherePseudoBadge`:`elsewhereBadge`)}),i&&(0,X.jsx)(`span`,{className:`elsewhere-badge offline`,title:D(`elsewhereOfflineTip`),children:D(`elsewhereOfflineBadge`)}),n.hasQuestion&&e&&t&&!r&&(0,X.jsx)(`span`,{className:`question-badge clickable`,title:D(`takeoverHasQuestion`),onClick:n=>{n.stopPropagation(),o({type:`peek_elsewhere_question`,owner:e,id:t})},children:`?`}),s?D(`takeoverConfirm`):n.title]}),(0,X.jsx)(`span`,{className:`session-sub`,children:Pe(n.cwd)})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:D(`streaming`)})]}),me&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-elsewhere-act`,title:D(`elsewhereActions`),onClick:i=>{i.stopPropagation(),J.current=null;let a=i.currentTarget.getBoundingClientRect();Y(a.left,a.bottom+4,{id:t??n.id,kind:`elsewhere`,label:n.title,...e?{owner:e}:{},...r?{pseudo:!0}:{}})},children:(0,X.jsx)(he,{})})]},n.id)}let f=a===n.id;return(0,X.jsxs)(`div`,{className:`lp-row${r>0?` lp-sub`:``}${i?` lp-has-kids`:``}`,style:r>0?{marginLeft:r*18}:void 0,onMouseLeave:()=>F(e=>e===`conv:${n.id}`?null:e),onContextMenu:e=>_e(e,{id:n.id,kind:`running`,label:n.title}),children:[i&&(0,X.jsx)(`button`,{type:`button`,className:`lp-tree-caret${s?` collapsed`:` expanded`}`,title:D(s?`expandSubagents`:`collapseSubagents`),"aria-label":D(s?`expandSubagents`:`collapseSubagents`),onClick:e=>{e.stopPropagation(),K(n.id)},children:s?(0,X.jsx)(ct,{}):(0,X.jsx)(ut,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${f?`active`:``}`,title:`${n.title}${e.isCurrent?``:` — ${e.cwd}`}`,onClick:()=>{f||o({type:`switch_conversation`,id:n.id})},children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[I===`conv:${n.id}`?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:R,placeholder:D(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing){let e=R.trim();e&&o({type:`rename_conversation`,id:n.id,name:e}),ae(null)}else e.key===`Escape`&&ae(null)},onBlur:()=>ae(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[n.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:D(`pinnedConversation`),children:`📌`}),n.isSubagent&&(0,X.jsx)(`span`,{className:`subagent-badge`,children:D(`subagentBadge`)}),n.isEphemeral&&(0,X.jsx)(`span`,{className:`ephemeral-badge`,children:D(`ephemeralBadge`)}),n.forkFrom&&(0,X.jsxs)(`span`,{className:`preset-badge fork-badge`,title:`${D(`forkBadgeTip`)}: ${n.forkFrom.title??n.forkFrom.conversationId}`,children:[`🌿 `,D(`forkBadge`)]}),n.agentPreset&&(0,X.jsx)(`span`,{className:`preset-badge`,title:n.agentPreset,children:E?.[n.agentPreset]??n.agentPreset}),n.title,n.error&&(0,X.jsx)(`span`,{className:`conv-error-badge`,title:D(`convErrorBadge`,{error:n.error})}),n.hasQuestion&&(0,X.jsx)(`span`,{className:`question-badge`,title:D(`waitingQuestionBadge`),children:`?`}),i&&s&&(0,X.jsxs)(`span`,{className:`subagents-collapsed-badge${l?` has-streaming`:d?` has-question`:u?` has-error`:``}`,title:D(l?`subagentsStreamingTip`:d?`subagentsQuestionTip`:u?`subagentsErrorTip`:`subagentsCountTip`,{n:c}),onClick:e=>{e.stopPropagation(),K(n.id)},children:[l&&(0,X.jsx)(`span`,{className:`subagent-dot streaming`}),d&&(0,X.jsx)(`span`,{className:`subagent-dot question`,children:`?`}),u&&(0,X.jsx)(`span`,{className:`subagent-dot error`}),(0,X.jsx)(`span`,{className:`subagents-count-text`,children:D(`subagentBadgeCount`,{n:c})})]})]}),I===`conv:${n.id}`?null:(0,X.jsx)(`span`,{className:`session-sub`,children:f?D(`current`):D(`messageCount`,{n:n.messageCount})})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:D(`streaming`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:D(`renameSession`),onClick:e=>{e.stopPropagation(),F(null),z(n.title),ae(`conv:${n.id}`)},children:(0,X.jsx)(Ge,{})}),(()=>{let e=`conv:${n.id}`,r=P===e,i=le(t,n.id),a=de(t,n.id),s=ue(t,n.id);return s===0&&!n.isStreaming?ze(e,D(`dismissConversation`),D(`dismissConversationConfirm`),()=>o({type:`dismiss_conversation`,id:n.id}),(0,X.jsx)(N,{})):s===0?ze(e,D(`dismissConversation`),D(`dismissStreamingConfirm`),()=>o({type:`dismiss_conversation`,id:n.id,force:!0}),(0,X.jsx)(N,{})):r?(0,X.jsxs)(`span`,{className:`lp-del-group`,children:[i>0&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt`,title:D(`dismissFinishedSubagentsScoped`,{n:i}),onClick:e=>{e.stopPropagation(),F(null),o({type:`dismiss_finished_subagents`,parentId:n.id})},children:D(`dismissFinishedOnly`,{n:i})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt danger`,title:D(`forceDismissTitle`,{n:s,m:a}),onClick:e=>{e.stopPropagation(),F(null),o({type:`dismiss_conversation`,id:n.id,force:!0})},children:D(`dismissForceAll`,{n:s})})]}):(0,X.jsx)(`button`,{type:`button`,className:`lp-del`,title:D(`dismissConversation`),onClick:t=>{t.stopPropagation(),F(e)},children:(0,X.jsx)(N,{})})})(),ge(Ae,`lp-slot-sessions`),n.isStreaming&&(0,X.jsx)(`span`,{className:`lp-row-stalled`,title:D(`streaming`),style:{position:`absolute`,right:28,top:`50%`,transform:`translateY(-50%)`}})]},n.id)})]},e.cwd)),ke()]})]})}),sessions:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section lp-section-sessions panel-sessions ${W?`collapsed`:``}`,style:W?void 0:{flex:`${Ue(`sessions`)} 1 0px`},children:[Be(D(`historySessions`),W,oe,r.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-new-chat-action`,title:D(`newChatTip`),"aria-label":D(`newChat`),onClick:()=>{o({type:`new_chat`}),or()},children:(0,X.jsx)(fe,{})}),ge(v,`lp-slot-section`)),!W&&(0,X.jsxs)(`div`,{className:`lp-section-body sessions-scroll`,children:[r.length===0&&(0,X.jsx)(`div`,{className:`panel-empty`,children:D(`noHistory`)}),r.map(e=>{let t=O===e.path;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>F(t=>t===`sess:${e.path}`?null:t),onContextMenu:t=>_e(t,{id:e.path,kind:`history`,label:Ne(e)}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${t?`active`:``}`,title:e.path,onClick:()=>{I||t||o({type:`switch_session`,path:e.path})},children:[(0,X.jsx)(be,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[I===e.path?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:R,placeholder:D(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=R.trim();t&&o({type:`rename_session`,path:e.path,name:t}),ae(null)}else t.key===`Escape`&&ae(null)},onBlur:()=>ae(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[e.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:D(`pinnedConversation`),children:`📌`}),Ne(e)]}),I===e.path?null:(0,X.jsxs)(`span`,{className:`session-sub`,children:[t?D(`current`):D(`messageCount`,{n:e.messageCount}),e.source===`tui`&&(0,X.jsx)(`span`,{className:`session-src`,title:D(`tuiTip`),children:`TUI`})]})]}),(0,X.jsx)(`span`,{className:`session-time`,children:jl(e.modified)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:D(`renameSession`),onClick:t=>{t.stopPropagation(),F(null),z(e.name??``),ae(e.path)},children:(0,X.jsx)(Ge,{})}),ze(`sess:${e.path}`,D(`deleteSession`),D(`deleteSessionConfirm`),()=>{Ol(e.path,M),o({type:`delete_session`,path:e.path})}),ge(je,`lp-slot-sessions`)]},e.path)})]})]})})},qe=e=>{let t=we.find(t=>t.key===e)?.entry;if(!t)return null;let n=Te(e);return(0,X.jsxs)(`div`,{className:`lp-section lp-section-plugin ${n?`collapsed`:``}`,style:n?void 0:{flex:`${Ue(e)} 1 0px`},children:[Be(t.label,n,()=>se(e)),!n&&(0,X.jsx)(`div`,{className:`lp-section-body lp-plugin-section-body`,children:b?.(t)??null})]})},Je=e=>e===`projects`||e===`convs`||e===`sessions`?Ke[e]:qe(e);return(0,X.jsxs)(`aside`,{ref:ve,className:`panel panel-left lp-panel`,children:[c&&l&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:D(`collapsePanel`),onClick:l,children:(0,X.jsx)(ot,{})}),we.map(({key:e})=>(0,X.jsxs)(g.Fragment,{children:[Je(e),We.get(e)??null]},e)),(0,X.jsx)(io,{open:te,currentCwd:M,pathCompletions:u??[],workspaceRoots:ee,onClose:()=>ne(!1),onSelectDirectory:e=>o({type:`set_cwd`,path:e}),onCreateProject:e=>o({type:`make_dir`,path:e,setAsCwd:!0})})]})}),Jl=209715200,Yl=/windows/i.test(navigator.userAgent),Xl=/[<>:"/\\|?*\u0000-\u001f]/g,Zl=/[. ]+$/,Ql=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function $l(e){let t=e.replace(Xl,`_`).replace(Zl,``);return t?Ql.test(t)?`_${t}`:t:`_`}function eu(e,t=!0){return hn(dn(`/api/file?${new URLSearchParams({clientId:hl(),path:e,...t?{download:`1`}:{}})}`))}async function tu(e,t){let n=Yl?$l(t):t;try{let t=await fetch(eu(e));if(!t.ok)return{ok:!1,cancelled:!1,error:await t.text().catch(()=>``)||(t.status===404?`FILE_NOT_FOUND`:`HTTP ${t.status}`)};if(Number(t.headers.get(`content-length`)??`0`)>Jl)return window.location.assign(eu(e)),{ok:!0};let r=await t.blob();return window.showSaveFilePicker&&window.isSecureContext?ru(r,n):iu(r,n)}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}async function nu(e,t){let n=Yl?$l(t):t;return window.showSaveFilePicker&&window.isSecureContext?ru(e,n):iu(e,n)}async function ru(e,t){let n,r=window.showSaveFilePicker;if(!r)return iu(e,t);try{n=await r({suggestedName:t})}catch(n){return n instanceof DOMException&&n.name===`AbortError`?{ok:!1,cancelled:!0}:iu(e,t)}try{let t=await n.createWritable();return await t.write(e),await t.close(),{ok:!0}}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}function iu(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);return r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}function au(e,t,n){let r=e.left-8,i=e.bottom+8;return r+t.width>n.width-8&&(r=Math.max(8,e.right+8-t.width)),i+t.height>n.height-8&&(i=Math.max(8,e.top-8-t.height)),{left:r,top:i}}function ou(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}function su({text:e}){let t=(0,g.useRef)(null),n=(0,g.useRef)(null),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)({left:0,top:0}),s=()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},c=()=>i(!1);return(0,g.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=au(i.getBoundingClientRect(),a,{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)},[r,e]),(0,g.useEffect)(()=>{if(!r)return;let e=0,a=()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e=t.current,r=n.current;if(!e||!r)return;let a=e.getBoundingClientRect();if(a.bottom<0||a.top>window.innerHeight||a.right<0||a.left>window.innerWidth){i(!1);return}let s=au(a,r.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)})};return window.addEventListener(`scroll`,a,!0),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(e),window.removeEventListener(`scroll`,a,!0),window.removeEventListener(`resize`,a)}},[r]),(0,X.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:s,onMouseLeave:c,onFocus:s,onBlur:c,onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},children:[`?`,r&&(0,j.createPortal)((0,X.jsx)(`span`,{ref:n,className:`set-tip-bubble open`,role:`tooltip`,style:{position:`fixed`,left:a.left,top:a.top},children:e}),document.body)]})}var cu=e=>/\.(zip|tar|tar\.gz|tgz|gz)$/i.test(e);function lu(e,t={}){let n={archive:dn(`/api/file-transfer/archive`),upload:dn(`/api/file-transfer/upload`)},r=new URL(hn(`${n[e]}?${new URLSearchParams({clientId:hl(),...t})}`),window.location.href);if(r.origin!==window.location.origin||r.pathname!==new URL(n[e],window.location.href).pathname)throw Error(`File transfers must use an allowlisted same-origin endpoint`);return r}async function uu(e,t,n){let r=await fetch(lu(`archive`),{method:`POST`,headers:{"Content-Type":`application/json`,"X-File-Operation":`1`},body:JSON.stringify({action:e,path:t,...n})});if(!r.ok)throw Error(await r.text());if(e===`download`){let e=r.headers.get(`content-disposition`)??``,t=/filename\*=UTF-8''([^;]+)/i.exec(e)?.[1],n=/filename="([^"]+)"/i.exec(e)?.[1],i=t?decodeURIComponent(t):n??`archive.tar.gz`,a=await nu(await r.blob(),i);if(!a.ok&&!a.cancelled)throw Error(a.error)}}async function du(){let e=window.showDirectoryPicker;if(!e)return null;let t=await e.call(window),n=[];async function r(e,t){if(n.length>=2e4)throw Error(`Folder exceeds 20,000 entries`);if(n.push(e.kind===`file`?{path:t,file:await e.getFile()}:{path:t}),e.kind===`directory`)for await(let n of e.values())await r(n,`${t}/${n.name}`)}return await r(t,t.name),n}async function fu(e,t,n){if(t.length>2e4)throw Error(`Folder exceeds 20,000 entries`);for(let e of t)if(e.file&&e.file.size>33554432)throw Error(`File exceeds 32 MiB: ${e.path}`);let r=0;for(let i of t){let t=lu(`upload`,{dir:e,name:i.path,kind:i.file?`file`:`directory`}),a=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/octet-stream`,"X-File-Operation":`1`},body:i.file??new Blob});if(!a.ok)throw Error(`${i.path}: ${await a.text()}`);n?.(++r)}}function pu({request:e,onClose:t,onComplete:n}){let r=Z(),[i,a]=(0,g.useState)(e.dir),[o,s]=(0,g.useState)(`skip`),[c,l]=(0,g.useState)([]),[u,d]=(0,g.useState)(0),f=(0,g.useRef)(null),[p,m]=(0,g.useState)(!1),[h,_]=(0,g.useState)(``),v=(0,g.useRef)(null);(0,g.useEffect)(()=>{v.current?.showModal()},[]);let y=r(e.action===`upload`?`fileUploadFolder`:e.action===`extract`?`fileExtract`:e.action===`download`?`fileCompressDownload`:`fileCompress`);async function b(){try{let e=await du();e?l(e):f.current?.click()}catch(e){e instanceof DOMException&&e.name===`AbortError`||_(String(e))}}async function x(){d(0),m(!0),_(``);try{e.action===`upload`?await fu(e.dir,c,d):await uu(e.action,e.path,{destination:i,policy:o}),n(),t()}catch(e){_(e instanceof Error?e.message:String(e)),n()}finally{m(!1)}}return(0,j.createPortal)((0,X.jsx)(`dialog`,{ref:v,className:`file-transfer-dialog`,"aria-labelledby":`file-transfer-title`,onCancel:e=>{e.preventDefault(),p||t()},children:(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),x()},children:[(0,X.jsxs)(`div`,{className:`file-transfer-head`,children:[(0,X.jsx)(`h3`,{id:`file-transfer-title`,children:y}),(0,X.jsx)(`button`,{type:`button`,className:`file-transfer-close`,title:r(`close`),"aria-label":r(`close`),disabled:p,onClick:t,children:(0,X.jsx)(N,{})})]}),(0,X.jsx)(`p`,{className:`file-transfer-path`,children:(e.action===`upload`?e.dir:e.path)||`.`}),(0,X.jsx)(`p`,{children:r(`fileArchiveLimits`)}),e.action===`extract`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`label`,{children:[r(`fileExtractDestination`),(0,X.jsx)(`input`,{value:i,disabled:p,onChange:e=>a(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[r(`fileConflictPolicy`),(0,X.jsxs)(`select`,{value:o,disabled:p,onChange:e=>s(e.target.value),children:[(0,X.jsx)(`option`,{value:`skip`,children:r(`fileConflictSkip`)}),(0,X.jsx)(`option`,{value:`overwrite`,children:r(`fileConflictOverwrite`)}),(0,X.jsx)(`option`,{value:`error`,children:r(`fileConflictError`)})]})]})]}),e.action===`upload`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{children:r(`fileFolderUploadHint`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:p,onClick:()=>void b(),children:r(`fileChooseFolder`)}),(0,X.jsx)(`input`,{type:`file`,"aria-label":y,multiple:!0,hidden:!0,disabled:p,ref:e=>{f.current=e,e?.setAttribute(`webkitdirectory`,``)},onChange:e=>l(Array.from(e.target.files??[],e=>({path:e.webkitRelativePath||e.name,file:e})))}),(0,X.jsxs)(`p`,{"aria-live":`polite`,children:[u,` / `,c.length]})]}),h&&(0,X.jsx)(`p`,{role:`alert`,children:r(`fileTransferFailed`,{error:h})}),(0,X.jsxs)(`div`,{className:`file-transfer-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:p,onClick:t,children:r(`cancel`)}),(0,X.jsx)(`button`,{type:`submit`,className:`btn primary`,disabled:p||e.action===`upload`&&c.length===0,children:p?r(`fileTransferBusy`):y})]})]})}),document.body)}function mu(e){return e instanceof Error?e.message:String(e)}function hu(e,t,n,r){let i=n===`zh`;switch(e.kind){case`no-client`:return i?`插件 ${t} 没有客户端脚本(client/entry.mjs),无法显示这一页。`:`Plugin ${t} ships no client bundle (client/entry.mjs), so this page cannot be shown.`;case`load`:return i?`插件 ${t} 的页面脚本加载失败:${e.detail}`:`Failed to load plugin ${t}'s page bundle: ${e.detail}`;case`mount`:return`${r(`pluginMountFailed`,{name:t})}:${e.detail}`}}function gu({plugin:e,epoch:t,send:n,className:r}){let i=(0,g.useRef)(null),{locale:a}=Mn(),o=Z(),[s,c]=(0,g.useState)(null),l=(0,g.useRef)(n);(0,g.useEffect)(()=>{l.current=n},[n]),(0,g.useEffect)(()=>{let n=i.current;if(!n)return;let r=!1,a,o=!1;if(c(null),!e.hasClient){c({kind:`no-client`});return}return(async()=>{try{if(await Bc(e,t),r)return;let i=await Ns(e.id,()=>vc(()=>import(Fc(e.id,t)),[]));if(r)return;let s=i.default;if(!s||typeof s.mount!=`function`)throw Error(`client/entry.mjs 没有导出 default.mount()`);o=!0,a=s.mount(n,Hc(e.id,e=>l.current(e)))}catch(t){if(r)return;console.error(`[plugin:${e.id}] 页面${o?`挂载`:`加载`}失败:`,t),c({kind:o?`mount`:`load`,detail:mu(t)})}})(),()=>{if(r=!0,typeof a==`function`)try{a()}catch(t){console.error(`[plugin:${e.id}] cleanup 失败:`,t)}n.textContent=``}},[e.id,e.hasClient,t]);let u=r?`plugin-page ${r}`:`plugin-page`;return(0,X.jsxs)(`div`,{className:u,children:[(0,X.jsx)(`div`,{className:`plugin-page-host`,ref:i}),s&&(0,X.jsx)(`div`,{className:`plugin-page-error`,role:`alert`,children:hu(s,e.name,a,o)})]})}function _u(e){return`pi-web-ui:${e}:tab`}function vu(e,t){try{let n=localStorage.getItem(_u(e));return n&&t.some(e=>e.id===n)?n:null}catch{return null}}function yu(e,t){try{localStorage.setItem(_u(e),t)}catch{}}function bu(e){return e.length>0&&!/[a-z]/i.test(e)}function xu(e){if(e.label)return e.label;let t=e.pluginPage;return t?.entry.label||t?.plugin.name||e.id}function Su({storageKey:e,tabs:t,epoch:n,send:r,extra:i,className:a}){let o=(0,g.useId)(),[s,c]=(0,g.useState)(()=>vu(e,t)??t[0]?.id??``),l=(0,g.useRef)([]),u=(0,g.useRef)(``),d=t.findIndex(e=>e.id===s),f=d>=0?t[d]:t[0],p=f?t.indexOf(f):-1;(0,g.useEffect)(()=>{if(!f)return;s!==f.id&&c(f.id);let t=`${e}:${f.id}`;u.current!==t&&(u.current=t,yu(e,f.id))},[f,s,e]);let m=t=>{c(t.id),u.current=`${e}:${t.id}`,yu(e,t.id)},h=(e,n)=>{let r=t.length,i=-1;if(e.key===`ArrowRight`)i=(n+1)%r;else if(e.key===`ArrowLeft`)i=(n-1+r)%r;else if(e.key===`Home`)i=0;else if(e.key===`End`)i=r-1;else return;let a=t[i];a&&(e.preventDefault(),m(a),l.current[i]?.focus())};if(!f)return null;let _=`${o}-panel-${p}`,v=a?`slot-tabs ${a}`:`slot-tabs`;return(0,X.jsxs)(`div`,{className:v,children:[(0,X.jsxs)(`div`,{className:`slot-tabs-bar`,role:`tablist`,children:[t.map((e,t)=>{let n=t===p;return(0,X.jsxs)(`button`,{type:`button`,role:`tab`,id:`${o}-tab-${t}`,className:n?`slot-tab active`:`slot-tab`,title:e.hint??xu(e),"aria-selected":n,"aria-controls":`${o}-panel-${t}`,tabIndex:n?0:-1,ref:e=>{l.current[t]=e},onClick:()=>m(e),onKeyDown:e=>h(e,t),children:[e.iconSvg?(0,X.jsx)(fi,{iconSvg:e.iconSvg,className:`slot-tab-icon`}):e.icon&&bu(e.icon)?(0,X.jsx)(`span`,{className:`slot-tab-icon`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`slot-tab-label`,children:xu(e)})]},e.id)}),i?(0,X.jsx)(`div`,{className:`slot-tabs-extra`,children:i}):null]}),(0,X.jsx)(`div`,{className:`slot-tabs-body`,id:_,role:`tabpanel`,"aria-labelledby":`${o}-tab-${p}`,children:f.pluginPage?(0,X.jsx)(gu,{plugin:f.pluginPage.plugin,epoch:n,send:r}):f.element??null})]})}function Cu(e){if(typeof document>`u`)return!1;try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,t.style.top=`-9999px`,t.setAttribute(`readonly`,``),document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}async function wu(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return Cu(e)}return Cu(e)}function Tu(e={}){let{duration:t=2e3,onSuccess:n,onError:r}=e,[i,a]=(0,g.useState)(!1),o=(0,g.useRef)(null),s=(0,g.useCallback)(()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},[]),c=(0,g.useCallback)(()=>{s(),a(!1)},[s]);return(0,g.useEffect)(()=>()=>{s()},[s]),{copied:i,copy:(0,g.useCallback)(async e=>{let i=!1;try{i=await wu(e)}catch(e){i=!1,r&&r(e)}return i?(a(!0),s(),o.current=setTimeout(()=>{a(!1),o.current=null},t),n?.(e)):r&&!i&&r(Error(`Copy failed`)),i},[t,n,r,s]),reset:c}}var Eu=`@root`,Du=`pi-web-ui:rp-sizes`,Ou={files:4,widgets:1},ku=120,Au=56;function ju(e,t){return t?Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top):32}var Mu=`files`,Nu=[],Pu=()=>{};function Fu(e){let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n<0?``:n===0?`/`:t.slice(0,n)}function Iu(e){return e===Eu||e===`/`||/^[A-Za-z]:$/.test(e)}function Lu(e){return e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)}var Ru=(0,g.memo)(function({files:e,fileChanged:t,widgets:n,panelSend:r,onAttach:i,onPreview:a,onNotice:o,collapsible:s,onToggleCollapse:c,uiRightPanelTabs:l,uiContextFile:u,plugins:d,pluginsEpoch:f,send:p}){let m=Z(),h=d??Nu,_=Pa(`cwd`),v=Pa(`workspaceRoots`),y=Pa(`homeDir`),b=Pa(`desktopDir`),[x,S]=(0,g.useState)(``),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(!1),D=(0,g.useRef)(null),O=(0,g.useRef)(null),[k,A]=(0,g.useState)(()=>{try{return Po(localStorage.getItem(Du),Ou)}catch{return{...Ou}}});(0,g.useEffect)(()=>{try{localStorage.setItem(Du,JSON.stringify(k))}catch{}},[k]);let j=n.some(e=>e.lines.length>0),ee=(0,g.useCallback)(e=>{e.preventDefault();let t=D.current;if(!t)return;let n=e.currentTarget,r=e.clientY,i={above:k.files,below:k.widgets},a=Math.max(120,t.clientHeight-ju(t,O.current));n.classList.add(`dragging`),document.body.classList.add(`rp-resizing`);let o=e=>{let{above:t,below:n}=Fo({start:i,deltaPx:e.clientY-r,availablePx:a,totalWeight:i.above+i.below,minAbovePx:ku,minBelowPx:Au});A({files:t,widgets:n})},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),n.classList.remove(`dragging`),document.body.classList.remove(`rp-resizing`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},[k.files,k.widgets]),M=(0,g.useRef)(null),te=(0,g.useRef)(0),ne=(0,g.useCallback)(e=>{M.current=e,e&&(e.scrollTop=te.current)},[]),[P,F]=(0,g.useState)(null),re=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]);let ie=(0,g.useCallback)(e=>{F(e),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>F(null),1200)},[]),I=(0,g.useCallback)((e,t)=>{e&&wu(e).then(e=>{e?ie(t):o(`error`,m(`slashCopyFailed`))})},[ie,o,m]),ae=(0,g.useCallback)(e=>{if(!e)return _;if(/^[A-Za-z]:$/.test(e))return`${e}/`;if(e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e))return e;let t=_.replace(/\\/g,`/`).replace(/\/+$/,``);return t?`${t}/${e}`:e},[_]),L=(0,g.useCallback)(e=>!e||e===Eu?null:e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)?e:`${_.replace(/\\/g,`/`).replace(/\/+$/,``)}/${e}`,[_]),R=104857600,z=(0,g.useCallback)((e,t)=>{for(let n of t){if(n.size>R){o(`warning`,m(`fileTooLarge`,{name:n.name,size:R/1024/1024}));continue}let t=new FileReader;t.onload=()=>{let i=t.result,a=i.slice(i.indexOf(`,`)+1);a&&r({type:`upload_file`,dirPath:e,name:n.name,data:a})},t.readAsDataURL(n)}},[r,o,m]),B=(0,g.useRef)(null),[V,H]=(0,g.useState)(null),U=(0,g.useRef)(null),W=(0,g.useCallback)(()=>{let e=B.current?.project;e&&r({type:`set_cwd`,path:e.path})},[r]),oe=(0,g.useCallback)(()=>{U.current&&(U.current.value=``),U.current?.click()},[]),[G,se]=(0,g.useState)(null),[ce,K]=(0,g.useState)(null),[le,ue]=(0,g.useState)(``),[de,q]=(0,g.useState)(null),[J,fe]=(0,g.useState)(``),pe=(0,g.useCallback)((e,t)=>{tu(e,t).then(e=>{e.ok||e.cancelled||o(`error`,m(`downloadFailed`,{error:e.error===`FILE_NOT_FOUND`?m(`fileNotFoundShort`):e.error}))})},[o,m]),me=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&(q(null),ue(e.label),K(e.id))},[]),Y=(0,g.useCallback)(()=>{if(!ce)return;let e=le.trim();K(null),e&&r({type:`file_rename`,path:ce,newName:e})},[ce,le,r]),he=(0,g.useCallback)(e=>{let t=B.current?.dir??x;K(null),fe(``),q({dir:t,kind:e})},[x]),ge=(0,g.useCallback)(()=>{if(!de)return;let e=J.trim();q(null),e&&r({type:`file_create`,dir:de.dir,name:e,kind:de.kind})},[de,J,r]),_e=(e,t,n,r)=>(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:e,placeholder:m(`fileNamePlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>t(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing?n():e.key===`Escape`&&r()},onBlur:r}),ve=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&window.confirm(m(`fileDeleteConfirm`,{name:e.label}))&&(G?.src===e.id&&se(null),ce===e.id&&K(null),r({type:`file_delete`,path:e.id}))},[r,m,G,ce]),ye=(0,g.useCallback)(()=>{let e=B.current?.target;e&&e.kind!==`list`&&!Iu(e.id)&&r({type:`file_copy`,src:e.id,destDir:Fu(e.id)})},[r]),be=(0,g.useCallback)(e=>{let t=B.current?.target;t&&t.kind!==`list`&&!Iu(t.id)&&se({src:t.id,cut:e})},[]),xe=(0,g.useCallback)(()=>{if(!G)return;let e=B.current?.dir??x;G.cut?(r({type:`file_copy`,src:G.src,destDir:e,move:!0}),se(null)):r({type:`file_copy`,src:G.src,destDir:e})},[G,r,x]),Se=(0,g.useCallback)(()=>{r({type:`list_files`,path:x===``?void 0:x})},[r,x]),[we,Te]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(!we)return;let e=e=>{e.target?.closest(`.root-picker`)||Te(!1)},t=e=>{e.key===`Escape`&&Te(!1)};return window.addEventListener(`mousedown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e,!0),window.removeEventListener(`keydown`,t)}},[we]);let Ee=(0,g.useCallback)(e=>{r({type:`set_workspace_roots`,roots:e})},[r]),Oe=(0,g.useCallback)(()=>{let e=B.current?.target;if(!e||e.kind!==`dir`)return;let t=L(e.id);t&&!v.includes(t)&&Ee([...v,t])},[v,L,Ee]),ke=(0,g.useCallback)(e=>{z(B.current?.dir??x,Array.from(e.target.files??[]))},[z,x]),Ae=(0,g.useCallback)(e=>{let t=B.current?.target;switch(e.id){case`host:file-compress`:case`host:file-extract`:case`host:file-compress-download`:case`host:file-upload-folder`:{if(!t)break;let n=e.id===`host:file-compress`?`compress`:e.id===`host:file-extract`?`extract`:e.id===`host:file-compress-download`?`download`:`upload`;H({action:n,path:ae(t.id),dir:ae(n===`upload`?B.current?.dir??x:Fu(t.id))});break}case`host:file-open-project`:W();break;case`host:file-upload`:oe();break;case`host:file-add-root`:Oe();break;case`host:file-open`:t?.kind===`file`&&a(t.id,t.label);break;case`host:file-enter`:t?.kind===`dir`&&Ue(t.id);break;case`host:file-download`:t?.kind===`file`&&pe(t.id,t.label);break;case`host:file-reveal`:t&&r({type:`file_reveal`,path:t.id});break;case`host:file-open-default`:t?.kind===`file`&&r({type:`file_open_default`,path:t.id});break;case`host:file-attach-ref`:t?.kind===`file`&&i(t.id,t.label,`reference`);break;case`host:file-attach-folder`:t?.kind===`dir`&&i(t.id,t.label,`reference`,!0);break;case`host:file-new-file`:he(`file`);break;case`host:file-new-dir`:he(`dir`);break;case`host:file-paste`:xe();break;case`host:file-rename`:me();break;case`host:file-duplicate`:ye();break;case`host:file-cut`:be(!0);break;case`host:file-copy`:be(!1);break;case`host:file-copy-name`:t&&t.kind!==`list`&&I(t.label,`name:${t.id}`);break;case`host:file-copy-path`:t&&t.kind!==`list`&&I(ae(t.id),`path:${t.id}`);break;case`host:file-copy-rel`:t&&t.kind!==`list`&&I(t.id,`rel:${t.id}`);break;case`host:file-refresh`:Se();break;case`host:file-delete`:ve()}},[W,x,oe,Oe,a,i,I,ae,pe,he,xe,me,ye,be,Se,ve]),je=(0,g.useCallback)((e,t)=>{let n=t.kind===`dir`?L(t.id):null,r={target:t,dir:t.kind===`dir`?t.id:x,project:n?{path:n,name:t.label}:null},i=t.kind,a=i===`file`,o=i===`dir`,s=i===`list`,c=!s&&Iu(t.id),l=!s&&Lu(t.id),d=x===Eu,f=(u??[]).map(e=>{if(e.source!==`host`)return e;switch(e.id){case`host:file-upload-folder`:return d?{...e,hidden:!0}:e;case`host:file-compress`:case`host:file-compress-download`:return!s&&!c?e:{...e,hidden:!0};case`host:file-extract`:return a&&cu(t.label)?e:{...e,hidden:!0};case`host:file-upload`:return d?{...e,hidden:!0}:{...e,label:r.dir===x?m(`uploadToCurrentDir`):m(`uploadToFolder`)};case`host:file-open-project`:return n?e:{...e,hidden:!0};case`host:file-add-root`:return n&&n!==_&&!v.includes(n)?e:{...e,hidden:!0};case`host:file-open`:case`host:file-download`:case`host:file-open-default`:case`host:file-attach-ref`:return a?e:{...e,hidden:!0};case`host:file-reveal`:return!d&&t.id!==Eu?e:{...e,hidden:!0};case`host:file-enter`:case`host:file-attach-folder`:return o?e:{...e,hidden:!0};case`host:file-new-file`:case`host:file-new-dir`:return!a&&!d?e:{...e,hidden:!0};case`host:file-paste`:return!a&&!d&&G?e:{...e,hidden:!0};case`host:file-rename`:case`host:file-duplicate`:case`host:file-cut`:case`host:file-copy`:case`host:file-delete`:return!s&&!c?e:{...e,hidden:!0};case`host:file-copy-name`:case`host:file-copy-path`:return s?{...e,hidden:!0}:e;case`host:file-copy-rel`:return!s&&!l?e:{...e,hidden:!0};case`host:file-refresh`:return s?e:{...e,hidden:!0};default:return e}});ba(f).length!==0&&(e.preventDefault(),e.stopPropagation(),B.current=r,la({x:e.clientX,y:e.clientY,slot:`contextmenu.file`,target:t,entries:f,onHostAction:Ae}))},[u,x,L,m,Ae,_,v,G]),Me=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),Ne=(0,g.useCallback)(()=>{M.current?.querySelectorAll(`.file-item.drop-target`).forEach(e=>e.classList.remove(`drop-target`)),M.current?.classList.remove(`drop-root`)},[]),Pe=(0,g.useCallback)(e=>{if(Ne(),e==null)return;let t=M.current?.querySelector(`.file-item[data-path="${CSS.escape(e)}"]`);t?t.classList.add(`drop-target`):M.current?.classList.add(`drop-root`)},[Ne]),Fe=e=>{let t=e instanceof Element?e.closest(`.file-item`):null;return t?.dataset.type===`dir`?t.dataset.path??x:x},Ie=(0,g.useCallback)(()=>{let e=document.querySelector(`.app`);e&&e.dispatchEvent(new DragEvent(`dragleave`,{bubbles:!0}))},[]),Re=(0,g.useRef)(0),Be=(0,g.useRef)(void 0),Ve=(0,g.useCallback)((e,t)=>{let n=++Re.current;S(e),t?.silent||E(!0),r({type:`list_files`,path:e===``?void 0:e})||Re.current===n&&E(!1)},[r]),He=(0,g.useCallback)(e=>{let t=v.filter(t=>t!==e);Ee(t),(x===e||x.startsWith(`${e}/`))&&Ve(``)},[v,Ee,x,Ve]);(0,g.useEffect)(()=>{e&&e.path===x&&E(!1)},[e,x]),(0,g.useEffect)(()=>{if(_!==Be.current){Be.current=_,Ve(``,{silent:!0});return}let e=setInterval(()=>{document.visibilityState!==`hidden`&&Ve(x,{silent:!0})},1e4);return()=>clearInterval(e)},[_,x,Ve]),(0,g.useEffect)(()=>{t&&t.path===x&&Ve(x,{silent:!0})},[t,x,Ve]);let Ue=e=>Ve(e),We=()=>{e?.parent!==null&&e?.parent!==void 0&&Ve(e.parent)},Ge=(()=>{if(x===``||x===Eu)return[];let e=x.split(`/`).filter(e=>!!e&&e!==Eu);return x.startsWith(`/`)?[{label:`/`,path:`/`},...e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`)}))]:e.map((t,n)=>({label:e[n],path:e.slice(0,n+1).join(`/`)}))})(),qe=[];for(let e of l??[]){if(e.source===`host`||e.hidden||e.kind===`divider`)continue;let t=h.find(t=>t.id===e.source.slice(7));t&&qe.push({id:e.id,label:e.label,icon:e.icon,...e.iconSvg?{iconSvg:e.iconSvg}:{},hint:e.hint,pluginPage:{plugin:t,entry:e}})}let Je=(l??[]).some(e=>e.id===`host:right-files`&&e.hidden);return(0,X.jsxs)(`aside`,{className:`panel panel-right`,ref:D,children:[s&&c&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:m(`collapsePanel`),onClick:c,children:(0,X.jsx)(at,{})}),(0,X.jsx)(`div`,{ref:O,style:{display:`flex`,flexDirection:`column`,flex:j?`${k.files} 1 0`:`1 1 0`,minHeight:j?ku:0},children:(0,X.jsx)(Su,{storageKey:`rightpanel`,epoch:f??0,send:p??Pu,tabs:(e=>{let t=(l??[]).filter(e=>!e.hidden);if(t.length===0)return e;let n=new Map(t.map((e,t)=>[e.id,t])),r=e=>n.get(e===Mu?`host:right-files`:e)??1e9;return[...e].sort((e,t)=>r(e.id)-r(t.id))})([...Je?[]:[{id:Mu,label:m(`openFiles`),element:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`panel-crumbs`,children:[(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===``?`active`:``}`,onClick:()=>Ve(``),children:m(`rootDir`)}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===Eu?`active`:``}`,title:m(`computer`),onClick:()=>Ve(Eu),children:`💻`}),y!==``&&(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===y||x.startsWith(`${y}/`)?`active`:``}`,title:m(`homeDir`),onClick:()=>Ve(y),children:`🏠`}),b!==``&&(0,X.jsx)(`button`,{type:`button`,className:`crumb ${x===b||x.startsWith(`${b}/`)?`active`:``}`,title:m(`desktopDir`),onClick:()=>Ve(b),children:`🖥️`}),(0,X.jsx)(su,{text:m(`filesHelp`)}),v.length>0&&(0,X.jsxs)(`div`,{className:`root-picker`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`crumb root-picker-trigger`,"aria-haspopup":`menu`,"aria-expanded":we,title:m(`workspaceRoots`),onClick:()=>Te(e=>!e),children:[(0,X.jsx)(Le,{}),(0,X.jsx)(`span`,{className:`root-picker-label`,children:m(`workspaceRoots`)}),(0,X.jsx)(`span`,{className:`set-count`,children:v.length+1}),`▾`]}),we&&(0,X.jsxs)(`div`,{className:`root-picker-menu`,role:`menu`,children:[(0,X.jsx)(`div`,{className:`root-picker-row`,children:(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:x===``?`root-picker-item active`:`root-picker-item`,title:_,onClick:()=>{Te(!1),Ve(``)},children:[m(`rootDir`),(0,X.jsx)(`span`,{className:`root-picker-path`,children:_})]})}),v.map(e=>(0,X.jsxs)(`div`,{className:`root-picker-row`,children:[(0,X.jsx)(`button`,{type:`button`,role:`menuitem`,className:x===e?`root-picker-item active`:`root-picker-item`,title:e,onClick:()=>{Te(!1),Ve(e)},children:(0,X.jsx)(`span`,{className:`root-picker-path`,children:e})}),(0,X.jsx)(`button`,{type:`button`,className:`root-picker-remove`,title:m(`removeWorkspaceRoot`),"aria-label":m(`removeWorkspaceRoot`),onClick:()=>He(e),children:(0,X.jsx)(N,{})})]},e)),(0,X.jsx)(`div`,{className:`root-picker-hint`,children:m(`workspaceRootsHint`)})]})]}),Ge.map(e=>(0,X.jsxs)(`span`,{className:`crumb-seg`,children:[(0,X.jsx)(ct,{}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${e.path===x?`active`:``}`,onClick:()=>Ve(e.path),children:e.label})]},e.path))]}),(0,X.jsxs)(`div`,{ref:ne,className:`panel-body`,onScroll:e=>{te.current=e.currentTarget.scrollTop},onContextMenu:e=>je(e,{id:x,kind:`list`,label:x===``?m(`rootDir`):x===Eu?m(`computer`):x}),onDragOver:e=>{Me(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,Ie(),Pe(Fe(e.target)))},onDragLeave:e=>{e.relatedTarget&&e.currentTarget.contains(e.relatedTarget)||Ne()},onDrop:e=>{if(Ne(),!Me(e))return;e.preventDefault(),e.stopPropagation(),Ie();let t=Array.from(e.dataTransfer?.files??[]);if(t.length===0){o(`warning`,m(`foldersNotSupported`));return}z(Fe(e.target),t)},onDragEnd:Ne,children:[(0,X.jsx)(`input`,{ref:U,type:`file`,multiple:!0,hidden:!0,onChange:ke}),V&&(0,X.jsx)(pu,{request:V,onClose:()=>H(null),onComplete:Se}),de&&(0,X.jsxs)(`div`,{className:`file-item dir`,children:[de.kind===`dir`?(0,X.jsx)(Le,{className:`file-icon`}):(0,X.jsx)(ze,{className:`file-icon`}),_e(J,fe,ge,()=>q(null))]}),T&&(0,X.jsx)(`div`,{className:`panel-empty`,children:m(`loading`)}),!T&&e&&e.path===x&&(0,X.jsxs)(X.Fragment,{children:[e.parent!=null&&(0,X.jsxs)(`button`,{type:`button`,className:`file-item dir`,onClick:We,children:[(0,X.jsx)(Le,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:`..`})]}),e.entries.map(e=>e.type===`dir`?(0,X.jsxs)(`div`,{className:`file-item dir${G?.cut&&G.src===e.path?` cut`:``}`,"data-type":`dir`,"data-path":e.path,onContextMenu:t=>je(t,{id:e.path,kind:`dir`,label:e.name}),children:[ce===e.path?_e(le,ue,Y,()=>K(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-dir-main`,onClick:()=>Ue(e.path),children:[(0,X.jsx)(Le,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach ref`,"data-tip":m(`linkFolderTip`),"aria-label":m(`linkFolderTip`),onClick:()=>i(e.path,e.name,`reference`,!0),children:(0,X.jsx)(De,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>I(e.name,`name:${e.path}`),children:P===`name:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(et,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>I(ae(e.path),`path:${e.path}`),children:P===`path:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(rt,{})})]},e.path):(0,X.jsxs)(`div`,{className:`file-item file${G?.cut&&G.src===e.path?` cut`:``}`,"data-type":`file`,"data-path":e.path,onContextMenu:t=>je(t,{id:e.path,kind:`file`,label:e.name}),children:[ce===e.path?_e(le,ue,Y,()=>K(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-name`,title:`${e.path} — ${m(`previewFile`)}`,onClick:()=>a(e.path,e.name),children:[(0,X.jsx)(ze,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name-text`,children:e.name})]}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach download`,"data-tip":m(`downloadFile`),onClick:()=>pe(e.path,e.name),children:(0,X.jsx)(Ke,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach ref`,"data-tip":m(`referenceTip`),"aria-label":m(`referenceTip`),onClick:()=>i(e.path,e.name,`reference`),children:(0,X.jsx)(De,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>I(e.name,`name:${e.path}`),children:P===`name:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(et,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${P===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>I(ae(e.path),`path:${e.path}`),children:P===`path:${e.path}`?(0,X.jsx)(dt,{}):(0,X.jsx)(rt,{})})]},e.path)),e.truncated&&(0,X.jsx)(`div`,{className:`panel-empty files-truncated`,children:m(`filesTruncated`)})]}),!T&&!e&&(0,X.jsx)(`div`,{className:`panel-empty`,children:m(`noFiles`)})]})]})}],...qe])})}),j&&(0,X.jsx)(`div`,{className:`rp-sash`,onPointerDown:ee,onDoubleClick:()=>A({...Ou}),title:m(`dragToResize`)}),j&&(0,X.jsx)(`div`,{className:`panel-widgets`,style:{flexGrow:k.widgets,minHeight:Au},children:n.filter(e=>e.lines.length>0).map(e=>(0,X.jsxs)(`div`,{className:`widget`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`widget-title widget-title-btn`,title:m(`widgetExpand`),onClick:()=>w(e.key),children:[(0,X.jsx)(`span`,{children:e.key}),(0,X.jsx)(Ce,{})]}),(0,X.jsx)(`pre`,{className:`widget-lines`,children:e.lines.join(`
328
328
  `)})]},e.key))}),C&&(()=>{let e=n.find(e=>e.key===C);return e?(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:()=>w(null),children:(0,X.jsxs)(`div`,{className:`widget-expand`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`widget-expand-head`,children:[(0,X.jsx)(`span`,{className:`widget-expand-title`,children:e.key}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:m(`close`),onClick:()=>w(null),children:(0,X.jsx)(N,{})})]}),(0,X.jsx)(`pre`,{className:`widget-expand-lines`,children:e.lines.join(`
329
329
  `)})]})}):null})()]})});function zu(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.text!=`string`||!t.text.trim()||typeof t.messageId!=`string`||!t.messageId||typeof t.role!=`string`||!t.role?null:{text:t.text,messageId:t.messageId,role:t.role,...typeof t.sessionId==`string`&&t.sessionId?{sessionId:t.sessionId}:{}}}function Bu(e){let t=/^<quoted-text>\n([^\n]*)\n<\/quoted-text>$/.exec(e);if(!t)return null;try{return zu(JSON.parse(t[1]))}catch{return null}}function Vu(e){let t=e,n=[];for(;;){let e=/(?:^|\n\n)(<quoted-text>\n[^\n]*\n<\/quoted-text>)$/.exec(t),r=e?Bu(e[1]):null;if(!e||!r)break;n.unshift(r),t=t.slice(0,e.index)}return{text:t,quotes:n}}var Hu=[{id:`builtin.bash.rm-rf`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\brm\\s+((-[a-zA-Z0-9]*[rf][a-zA-Z0-9]*|--recursive|--force)\\s+)+(((\\/)|(~)|(\\.\\.)|(\\*)|(\\.\\/))|[a-zA-Z]:[\\\\/])`,action:`ask`,label:`递归/强制删除 (rm -rf)`,labelEn:`Recursive/force delete (rm -rf)`,reason:`检测到高风险的递归/强制删除大范围路径命令 (rm -rf)`,reasonEn:`Detected high-risk recursive/force deletion of wide paths (rm -rf)`,categoryId:`bash.rm-rf`,builtin:!0},{id:`builtin.bash.win-del`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\b(del|rmdir|rd)\\s+[/\\-][fsq]`,action:`ask`,label:`Windows 强制删除 (del/rmdir/rd)`,labelEn:`Windows force delete (del/rmdir/rd)`,reason:`检测到高风险的 Windows 强制/递归删除目录命令 (del/rmdir/rd /s /q)`,reasonEn:`Detected high-risk Windows force/recursive deletion command (del/rmdir/rd /s /q)`,categoryId:`bash.win-del`,builtin:!0},{id:`builtin.bash.disk`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\b(mkfs|format\\s+[a-zA-Z]:|dd\\s+if=)`,action:`ask`,label:`磁盘格式化/底层写入`,labelEn:`Disk format / raw block write`,reason:`检测到磁盘格式化或底层块写入危险命令 (format/mkfs/dd)`,reasonEn:`Detected dangerous disk formatting or raw block write command (format/mkfs/dd)`,categoryId:`bash.disk`,builtin:!0},{id:`builtin.bash.git-destructive`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\bgit(?:\\.exe)?(?:\\s+(?:-[cC]\\s+\\S+|--[a-zA-Z-]+=\\S+))*\\s+(?:push\\s+(?:[^;&|\\n]*?\\s)?(?:--force|-[a-zA-Z0-9]*f)\\b|push\\s+(?:[^;&|\\n]*?\\s)?(?:\\+\\S+|:[^\\s/]\\S*)|reset\\s+--hard|clean\\s+(?:-[a-zA-Z]+\\s+)*-[a-zA-Z0-9]*f[a-zA-Z0-9]*|branch\\s+-[dD]\\b|checkout\\s+(?:--\\s+)?\\.(?=\\s|$|[;&|])|restore\\s+(?:--(?!staged\\b)\\S+\\s+)*\\.(?=\\s|$|[;&|])|stash\\s+(?:drop|clear)\\b)`,action:`ask`,label:`破坏性 Git 操作`,labelEn:`Destructive git operation`,reason:`检测到不可逆的破坏性 Git 操作 (force push / reset --hard / clean -f / checkout . / stash drop|clear / branch -D)`,reasonEn:`Detected irreversible destructive Git operation (force push / reset --hard / clean -f / checkout . / stash drop|clear / branch -D)`,categoryId:`bash.git-destructive`,builtin:!0},{id:`builtin.bash.chmod`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\bchmod\\s+(-R\\s+)?(777|000)\\b`,action:`ask`,label:`危险权限修改 (chmod)`,labelEn:`Dangerous permission change (chmod)`,reason:`检测到过度开放或全局破坏性的文件权限修改 (chmod 777/000)`,reasonEn:`Detected overly permissive or globally destructive file permission change (chmod 777/000)`,categoryId:`bash.chmod`,builtin:!0},{id:`builtin.bash.system-redirect`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`>\\s*(\\/etc\\/|\\/boot\\/|C:\\\\Windows)`,action:`ask`,label:`写入系统关键目录`,labelEn:`Write into system directories`,reason:`检测到重定向写入系统关键目录的危险操作`,reasonEn:`Detected dangerous redirection writing into critical system directories`,categoryId:`bash.system-redirect`,builtin:!0},{id:`builtin.file.sensitive.env`,enabled:!0,tools:[`write`,`edit`,`edit_soft`],field:`path`,match:`regex`,value:`(^|[\\/\\\\])\\.env(\\.[a-zA-Z0-9_-]+)?$`,action:`ask`,label:`敏感配置 (.env)`,labelEn:`Sensitive config (.env)`,reason:`尝试修改敏感环境变量/密钥配置文件 (.env)`,reasonEn:`Attempting to modify sensitive environment/secret configuration (.env)`,categoryId:`file.sensitive.env`,builtin:!0},{id:`builtin.file.sensitive.ssh`,enabled:!0,tools:[`write`,`edit`,`edit_soft`],field:`path`,match:`regex`,value:`(^|[\\/\\\\])(id_rsa|id_ed25519|authorized_keys|known_hosts)$`,action:`ask`,label:`SSH 密钥/凭据`,labelEn:`SSH keys / credentials`,reason:`尝试修改 SSH 密钥或认证凭据文件`,reasonEn:`Attempting to modify SSH keys or authentication credentials`,categoryId:`file.sensitive.ssh`,builtin:!0},{id:`builtin.file.sensitive.shell`,enabled:!0,tools:[`write`,`edit`,`edit_soft`],field:`path`,match:`regex`,value:`(^|[\\/\\\\])(\\.bashrc|\\.zshrc|\\.profile|\\.bash_profile)$`,action:`ask`,label:`Shell 启动配置`,labelEn:`Shell profile`,reason:`尝试修改用户全局 Shell 启动配置文件`,reasonEn:`Attempting to modify user global Shell profile configuration`,categoryId:`file.sensitive.shell`,builtin:!0},{id:`builtin.file.outside-workspace`,enabled:!0,tools:[`write`,`edit`,`edit_soft`],field:`path`,match:`outside_workspace`,value:``,action:`ask`,label:`工作区外写入`,labelEn:`Write outside workspace`,reason:`尝试在工作区外部写入/修改文件`,reasonEn:`Attempting to write/modify file outside the workspace`,categoryId:`file.outside-workspace`,builtin:!0}].filter(e=>e.enabled&&e.field===`command`&&e.match===`regex`&&e.tools.some(e=>e.trim().toLowerCase()===`bash`));function Uu(e){if(e.length<=1)return e;let t=[...e].sort((e,t)=>e.start-t.start),n=[t[0]];for(let e=1;e<t.length;e++){let r=t[e],i=n[n.length-1];r.start<=i.end?(i.end=Math.max(i.end,r.end),r.label&&(!i.label||!i.label.includes(r.label))&&(i.label=i.label?`${i.label} / ${r.label}`:r.label)):n.push(r)}return n}function Wu(e,t){if(!e||typeof e!=`string`)return[];if(t&&t.length>0){let n=[];for(let r of t)if(r.field===`command`&&r.length>0){let t=Math.max(0,r.index),i=Math.min(e.length,t+r.length);i>t&&n.push({start:t,end:i,label:r.label})}if(n.length>0)return Uu(n)}let n=[];for(let t of Hu){let r;try{r=new RegExp(t.value,`gi`)}catch{continue}for(let i of e.matchAll(r)){let e=i.index??0;i[0].length>0&&n.push({start:e,end:e+i[0].length,label:t.label})}}return Uu(n)}function Gu(e,t){let n=Wu(e,t);if(n.length===0)return e;let r=[],i=0;return n.forEach((t,n)=>{t.start>i&&r.push(e.slice(i,t.start));let a=e.slice(t.start,t.end);r.push((0,X.jsx)(`mark`,{className:`bash-danger-hit`,title:t.label??`高危命令片段`,children:a},n)),i=t.end}),i<e.length&&r.push(e.slice(i)),(0,X.jsx)(X.Fragment,{children:r})}function Ku({quote:e,onRemove:t,forceOpen:n=!1}){let r=Z(),[i,a]=(0,g.useState)(!1),o=e.role===`user`?`role.user`:e.role===`assistant`?`role.assistant`:e.role===`toolResult`?`role.tool`:e.role===`bashExecution`?`role.bash`:`attachment`;return(0,X.jsxs)(`div`,{className:`quote-card`,children:[(0,X.jsxs)(`details`,{open:i||n,onToggle:e=>a(e.currentTarget.open),children:[(0,X.jsxs)(`summary`,{title:r(`quoteSource`,{id:e.messageId}),children:[(0,X.jsxs)(`span`,{className:`quote-source`,children:[`↪ `,r(`quoteText`),` · `,r(o)]}),(0,X.jsx)(`span`,{className:`quote-preview`,children:e.text.replace(/\s+/g,` `).slice(0,80)})]}),(0,X.jsx)(`pre`,{className:`quote-content`,children:e.text})]}),t&&(0,X.jsx)(`button`,{type:`button`,className:`quote-remove`,"aria-label":r(`removeQuote`),title:r(`removeQuote`),onClick:t,children:`×`})]})}var qu=[`ariaDescribedBy`,`ariaLabel`,`ariaLabelledBy`],Ju={ancestors:{tbody:[`table`],td:[`table`],th:[`table`],thead:[`table`],tfoot:[`table`],tr:[`table`]},attributes:{a:[...qu,`dataFootnoteBackref`,`dataFootnoteRef`,[`className`,`data-footnote-backref`],`href`],blockquote:[`cite`],code:[[`className`,/^language-./]],del:[`cite`],div:[`itemScope`,`itemType`],dl:[...qu],h2:[[`className`,`sr-only`]],img:[...qu,`longDesc`,`src`],input:[[`disabled`,!0],[`type`,`checkbox`]],ins:[`cite`],li:[[`className`,`task-list-item`]],ol:[...qu,[`className`,`contains-task-list`]],q:[`cite`],section:[`dataFootnotes`,[`className`,`footnotes`]],source:[`srcSet`],summary:[...qu],table:[...qu],ul:[...qu,[`className`,`contains-task-list`]],"*":`abbr.accept.acceptCharset.accessKey.action.align.alt.axis.border.cellPadding.cellSpacing.char.charOff.charSet.checked.clear.colSpan.color.cols.compact.coords.dateTime.dir.encType.frame.hSpace.headers.height.hrefLang.htmlFor.id.isMap.itemProp.label.lang.maxLength.media.method.multiple.name.noHref.noShade.noWrap.open.prompt.readOnly.rev.rowSpan.rows.rules.scope.selected.shape.size.span.start.summary.tabIndex.title.useMap.vAlign.value.width`.split(`.`)},clobber:[`ariaDescribedBy`,`ariaLabelledBy`,`id`,`name`],clobberPrefix:`user-content-`,protocols:{cite:[`http`,`https`],href:[`http`,`https`,`irc`,`ircs`,`mailto`,`xmpp`],longDesc:[`http`,`https`],src:[`http`,`https`]},required:{input:{disabled:!0,type:`checkbox`}},strip:[`script`],tagNames:`a.b.blockquote.br.code.dd.del.details.div.dl.dt.em.h1.h2.h3.h4.h5.h6.hr.i.img.input.ins.kbd.li.ol.p.picture.pre.q.rp.rt.ruby.s.samp.section.source.span.strike.strong.sub.summary.sup.table.tbody.td.tfoot.th.thead.tr.tt.ul.var`.split(`.`)},Yu={}.hasOwnProperty;function Xu(e,t){let n={type:`root`,children:[]},r=Zu({schema:t?{...Ju,...t}:Ju,stack:[]},e);return r&&(Array.isArray(r)?r.length===1?n=r[0]:n.children=r:n=r),n}function Zu(e,t){if(t&&typeof t==`object`){let n=t;switch(typeof n.type==`string`?n.type:``){case`comment`:return Qu(e,n);case`doctype`:return $u(e,n);case`element`:return ed(e,n);case`root`:return td(e,n);case`text`:return nd(e,n)}}}function Qu(e,t){if(e.schema.allowComments){let e=typeof t.value==`string`?t.value:``,n=e.indexOf(`-->`),r={type:`comment`,value:n<0?e:e.slice(0,n)};return ld(r,t),r}}function $u(e,t){if(e.schema.allowDoctypes){let e={type:`doctype`};return ld(e,t),e}}function ed(e,t){let n=typeof t.tagName==`string`?t.tagName:``;e.stack.push(n);let r=rd(e,t.children),i=id(e,t.properties);e.stack.pop();let a=!1;if(n&&n!==`*`&&(!e.schema.tagNames||e.schema.tagNames.includes(n))&&(a=!0,e.schema.ancestors&&Yu.call(e.schema.ancestors,n))){let t=e.schema.ancestors[n],r=-1;for(a=!1;++r<t.length;)e.stack.includes(t[r])&&(a=!0)}if(!a)return e.schema.strip&&!e.schema.strip.includes(n)?r:void 0;let o={type:`element`,tagName:n,properties:i,children:r};return ld(o,t),o}function td(e,t){let n={type:`root`,children:rd(e,t.children)};return ld(n,t),n}function nd(e,t){let n={type:`text`,value:typeof t.value==`string`?t.value:``};return ld(n,t),n}function rd(e,t){let n=[];if(Array.isArray(t)){let r=t,i=-1;for(;++i<r.length;){let t=Zu(e,r[i]);t&&(Array.isArray(t)?n.push(...t):n.push(t))}}return n}function id(e,t){let n=e.stack[e.stack.length-1],r=e.schema.attributes,i=e.schema.required,a=r&&Yu.call(r,n)?r[n]:void 0,o=r&&Yu.call(r,`*`)?r[`*`]:void 0,s=t&&typeof t==`object`?t:{},c={},l;for(l in s)if(Yu.call(s,l)){let t=s[l],n=ad(e,ud(a,l),l,t);n??=ad(e,ud(o,l),l,t),n!=null&&(c[l]=n)}if(i&&Yu.call(i,n)){let e=i[n];for(l in e)Yu.call(e,l)&&!Yu.call(c,l)&&(c[l]=e[l])}return c}function ad(e,t,n,r){return t?Array.isArray(r)?od(e,t,n,r):sd(e,t,n,r):void 0}function od(e,t,n,r){let i=-1,a=[];for(;++i<r.length;){let o=sd(e,t,n,r[i]);(typeof o==`number`||typeof o==`string`)&&a.push(o)}return a}function sd(e,t,n,r){if((typeof r==`boolean`||typeof r==`number`||typeof r==`string`)&&cd(e,n,r)){if(typeof t==`object`&&t.length>1){let e=!1,n=0;for(;++n<t.length;){let i=t[n];if(i&&typeof i==`object`&&`flags`in i){if(i.test(String(r))){e=!0;break}}else if(i===r){e=!0;break}}if(!e)return}return e.schema.clobber&&e.schema.clobberPrefix&&e.schema.clobber.includes(n)?e.schema.clobberPrefix+r:r}}function cd(e,t,n){let r=e.schema.protocols&&Yu.call(e.schema.protocols,t)?e.schema.protocols[t]:void 0;if(!r||r.length===0)return!0;let i=String(n),a=i.indexOf(`:`),o=i.indexOf(`?`),s=i.indexOf(`#`),c=i.indexOf(`/`);if(a<0||c>-1&&a>c||o>-1&&a>o||s>-1&&a>s)return!0;let l=-1;for(;++l<r.length;){let e=r[l];if(a===e.length&&i.slice(0,e.length)===e)return!0}return!1}function ld(e,t){let n=c(t);t.data&&(e.data=o(t.data)),n&&(e.position=n)}function ud(e,t){let n,r=-1;if(e)for(;++r<e.length;){let i=e[r],a=typeof i==`string`?i:i[0];if(a===t)return i;a===`data*`&&(n=i)}if(t.length>4&&t.slice(0,4).toLowerCase()===`data`)return n}function dd(e){return function(t){return Xu(t,e)}}var fd=(0,g.memo)(function({text:e}){let t=Z(),{copied:n,copy:r}=Tu({duration:1200});return e?(0,X.jsx)(`button`,{type:`button`,className:`copy-btn`,title:t(`copy`),onClick:()=>void r(e),children:n?(0,X.jsx)(dt,{}):(0,X.jsx)(et,{})}):null});function pd(e){let t=e=>{if(typeof e==`string`||typeof e==`number`){let t=String(e);return t===``?[[]]:t.split(`
330
330
  `).map(e=>e===``?[]:[e])}if(Array.isArray(e)){let n=[];for(let r of e){let e=t(r);if(n.length===0)n=e;else{let t=e[0]??[];n[n.length-1].push(...t),n.push(...e.slice(1))}}return n}if(e&&typeof e==`object`&&`props`in e){let n=e,r=n.props?.children,i={...n.props,children:void 0},a=r==null?[]:t(r);return a.length===0?[[(0,g.createElement)(n.type,i)]]:a.map(e=>[(0,g.createElement)(n.type,i,...e)])}return[[e]]},n=t(e);return n.length>1&&n[n.length-1].length===0&&n.pop(),n}function md(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(md).join(``);if(e&&typeof e==`object`&&`props`in e){let t=e.props;return md(t?.children)}return``}function hd(e){let t=Array.isArray(e)?e[0]:e;return!t||typeof t!=`object`||!(`props`in t)?null:t}function gd(e){let t=hd(e)?.props?.className;if(typeof t!=`string`)return null;let n=t.match(/(?:^|\s)language-([A-Za-z0-9_+-]+)(?:\s|$)/);return n?n[1]:null}var _d=`pi-web-ui:plugin-data`,vd=new Map,yd=new Map,bd=new Set,xd=-1,Sd=0,Cd=new Set;function wd(){Sd++;for(let e of Cd)e()}function Td(e){return Cd.add(e),()=>{Cd.delete(e)}}function Ed(){return Sd}var Dd=null;function Od(e){Dd=e}function kd(e,t){t!==xd&&(xd=t,yd.clear(),bd.clear());let n=new Map;for(let t of e)if(!t.error&&t.renderers)for(let e of t.renderers)n.has(e)||n.set(e,t.id);let r=n.size!==vd.size;if(!r){for(let[e,t]of n)if(vd.get(e)!==t){r=!0;break}}if(r){for(let e of yd.keys())n.has(e)||yd.delete(e);for(let e of bd)n.has(e)||bd.delete(e);vd=n,wd()}}async function Ad(e,t){let n=vd.get(e);if(!n)return null;let r=yd.get(e);if(!r&&!bd.has(e))try{let t=(await vc(()=>import(dn(`/plugins/${encodeURIComponent(n)}/client/entry.mjs?e=${xd}`)),[])).default?.renderers?.[e];typeof t==`function`?(r={pluginId:n,renderer:t},yd.set(e,r)):(bd.add(e),console.error(`[plugin:${n}] entry.mjs 未提供 renderers["${e}"]`))}catch(t){bd.add(e),console.error(`[plugin:${n}] renderer 加载失败(${e}):`,t)}if(!r)return null;let i={pluginId:r.pluginId,send:e=>{Dd?.({type:`plugin_message`,pluginId:r.pluginId,payload:e})},onData:e=>{let t=t=>{let n=t.detail;n.pluginId===r.pluginId&&e(n.payload)};return window.addEventListener(_d,t),()=>window.removeEventListener(_d,t)}};try{let e=await r.renderer(t,i);return e instanceof HTMLElement?e:null}catch(t){return console.error(`[plugin:${r.pluginId}] renderer("${e}") 执行失败:`,t),null}}function jd(e){return vd.has(e)}var Md=new Map,Nd=new Map,Pd=new Set,Fd=-1;function Id(e,t){t!==Fd&&(Fd=t,Nd.clear(),Pd.clear());let n=new Map;for(let t of e){if(t.error)continue;let e=t.messageWidgets;if(Array.isArray(e))for(let r of e)typeof r==`string`&&r&&(n.has(r)||n.set(r,t.id))}for(let e of Array.from(Md.keys()))n.has(e)||Md.delete(e);for(let[e,t]of n)Md.set(e,t);for(let e of Nd.keys())n.has(e)||Nd.delete(e);for(let e of Pd)n.has(e)||Pd.delete(e)}function Ld(e){return Md.has(e)}async function Rd(e){let t=Md.get(e);if(!t)return null;let n=Nd.get(e);if(!n&&!Pd.has(e))try{let r=(await vc(()=>import(dn(`/plugins/${encodeURIComponent(t)}/client/entry.mjs?e=${Fd}`)),[])).default?.messageWidgets?.[e];typeof r==`function`?(n={pluginId:t,renderer:r},Nd.set(e,n)):(Pd.add(e),console.error(`[plugin:${t}] entry.mjs 未提供 messageWidgets["${e}"]`))}catch(n){Pd.add(e),console.error(`[plugin:${t}] messageWidget 加载失败(${e}):`,n)}return n?.renderer??null}var zd=`pi-web-ui:theme`,Bd=`dark`,Vd=`theme-stylesheet`,Hd=`pi-web-ui:theme-change`;function Ud(){try{let e=localStorage.getItem(zd);if(e&&e!==Bd)return e}catch{}return null}function Wd(e){try{e?localStorage.setItem(zd,e):localStorage.removeItem(zd)}catch{}}function Gd(e){let t=document.getElementById(Vd);if(!e){t?.remove(),window.dispatchEvent(new CustomEvent(Hd));return}t||(t=document.createElement(`link`),t.id=Vd,t.rel=`stylesheet`,document.head.appendChild(t)),t.href=dn(`/themes/${encodeURIComponent(e)}.css`),t.onload=()=>window.dispatchEvent(new CustomEvent(Hd))}async function Kd(){try{let e=await fetch(hn(dn(`/api/themes`)));if(!e.ok)return[];let t=await e.json();return Array.isArray(t.themes)?t.themes:[]}catch{return[]}}function qd(){let[e,t]=(0,g.useState)([]),[n,r]=(0,g.useState)(()=>Ud());(0,g.useEffect)(()=>{let e=!1;return Kd().then(n=>{e||t(n)}),()=>{e=!0}},[]);let i=(0,g.useCallback)(()=>{Kd().then(t)},[]);return(0,g.useEffect)(()=>{Gd(n),Wd(n)},[n]),{themes:e,theme:n,switchTheme:e=>r(e===Bd?null:e),reloadThemes:i}}function Jd(){let e=getComputedStyle(document.documentElement),t=(t,n)=>e.getPropertyValue(t).trim()||n;return{background:t(`--term-bg`,`#0b0d12`),foreground:t(`--term-fg`,`#e6e8ef`),cursor:t(`--term-cursor`,`#8b5cf6`),cursorAccent:t(`--term-cursor-accent`,`#0b0d12`),selectionBackground:t(`--term-selection`,`rgba(139, 92, 246, 0.35)`),black:t(`--term-black`,`#1a1d26`),red:t(`--term-red`,`#f87171`),green:t(`--term-green`,`#34d399`),yellow:t(`--term-yellow`,`#fbbf24`),blue:t(`--term-blue`,`#60a5fa`),magenta:t(`--term-magenta`,`#c084fc`),cyan:t(`--term-cyan`,`#22d3ee`),white:t(`--term-white`,`#e6e8ef`),brightBlack:t(`--term-bright-black`,`#6b7284`),brightRed:t(`--term-bright-red`,`#f87171`),brightGreen:t(`--term-bright-green`,`#34d399`),brightYellow:t(`--term-bright-yellow`,`#fbbf24`),brightBlue:t(`--term-bright-blue`,`#60a5fa`),brightMagenta:t(`--term-bright-magenta`,`#c084fc`),brightCyan:t(`--term-bright-cyan`,`#22d3ee`),brightWhite:t(`--term-bright-white`,`#ffffff`)}}function Yd({lang:e,code:t}){let n=(0,g.useRef)(null),r=(0,g.useRef)(null),i=(0,g.useRef)(0),a=(0,g.useRef)(new WeakMap),[o,s]=(0,g.useState)(null);return(0,g.useEffect)(()=>{let e=()=>{let e=++i.current,t=r.current;t&&(t.dispatchEvent(new CustomEvent(Hd)),a.current.set(t,e))};return window.addEventListener(Hd,e),()=>window.removeEventListener(Hd,e)},[]),(0,g.useEffect)(()=>{let n=!1,r=i.current;return s(null),Ad(e,t).then(e=>{n||(e&&a.current.set(e,r),s(e))}),()=>{n=!0}},[e,t]),(0,g.useEffect)(()=>{r.current=o;let e=n.current;return e&&(e.replaceChildren(),o&&(e.appendChild(o),(a.current.get(o)??i.current)<i.current&&(o.dispatchEvent(new CustomEvent(Hd)),a.current.set(o,i.current)))),()=>{r.current===o&&(r.current=null)}},[o]),o?(0,X.jsx)(`div`,{className:`plugin-fence`,ref:n}):(0,X.jsxs)(`div`,{className:`codeblock`,children:[(0,X.jsx)(fd,{text:t}),(0,X.jsx)(`pre`,{children:(0,X.jsx)(`code`,{children:t})})]})}var Xd=null,Zd=null;function Qd(e){Xd=e?.open??null,Zd=e?.isOpen??null}function $d(){return Zd?Zd():!1}function ef(e){return!Xd||!e?.path?!1:(Xd(e),!0)}var tf=[u,s],nf=[u,a,s],rf=[[l,{strict:!1,throwOnError:!1}],[d,{detect:!0,ignoreMissing:!0}]];function af(e){if(!e||!e.includes(`@`))return e;let t=e.split(RegExp("(```[\\s\\S]*?```|`[^`\\r\\n]+`)",`g`)),n=/(^|[\s((“"'[])@((?:[\w.-]+\/)*[\w.-]+\.(?:[a-zA-Z0-9]{1,10}))(?=[)\s\],.;:!?,。!?’”"']|$)/g;for(let e=0;e<t.length;e+=2)t[e]&&(t[e]=t[e].replace(n,(e,t,n)=>t+`[@`+n+`](pi-file://`+encodeURIComponent(n)+`)`));return t.join(``)}function of({text:e,rawHtml:t=!1,hardBreaks:n=!1}){let r=t?[p,dd,...rf]:rf,i=(0,g.useMemo)(()=>af(e),[e]);return(0,X.jsx)(f,{remarkPlugins:n?nf:tf,rehypePlugins:r,components:{pre:lf,a:cf},children:i})}var sf=(0,g.memo)(function({text:e,rawHtml:t=!1,hardBreaks:n=!1}){return(0,X.jsx)(`div`,{className:`md`,children:(0,X.jsx)(of,{text:e,rawHtml:t,hardBreaks:n})})});function cf({node:e,href:t,children:n,...r}){let i=String(t??``);if(i.startsWith(`pi-file://`)){let e=i.slice(10),t=e;try{t=decodeURIComponent(e)}catch{t=e}let r=typeof n==`string`&&n.trim()?n.trim():t.split(`/`).pop()??t;return(0,X.jsxs)(`button`,{type:`button`,className:`file-pill`,title:`点击预览文件: `+t,onClick:e=>{e.preventDefault(),e.stopPropagation(),ef({path:t,name:r.replace(/^@/,``)})},children:[(0,X.jsx)(`span`,{className:`file-pill-icon`,"aria-hidden":`true`,children:`📄`}),(0,X.jsx)(`span`,{className:`file-pill-name`,children:r})]})}return/^(https?:|mailto:|tel:)/i.test(i)?(0,X.jsx)(`a`,{...r,href:t,target:`_blank`,rel:`noreferrer noopener`,children:n}):(0,X.jsx)(`a`,{href:t,...r,children:n})}function lf({children:e,...t}){(0,g.useSyncExternalStore)(Td,Ed,Ed);let n=gd(e);return n&&jd(n)?(0,X.jsx)(Yd,{lang:n,code:md(e)}):(0,X.jsx)(uf,{children:e,...t})}function uf({children:e,...t}){let n=pd(e&&typeof e==`object`&&`props`in e?e.props?.children:e),r=n.length>1,i=r?`${String(n.length).length+1}ch`:void 0;return(0,X.jsxs)(`div`,{className:`codeblock`,children:[(0,X.jsx)(fd,{text:df(e)}),(0,X.jsx)(`pre`,{...t,children:n.map((e,t)=>(0,X.jsxs)(`div`,{className:`code-line`,children:[r&&(0,X.jsx)(`span`,{className:`code-num`,style:i?{width:i}:void 0,children:t+1}),(0,X.jsx)(`code`,{className:`code-line-body hljs`,children:e})]},t))})]})}function df(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(df).join(``);if(e&&typeof e==`object`&&`props`in e){let t=e.props;return df(t?.children)}return``}function ff({type:e,code:t,children:n}){let r=(0,g.useRef)(null),[i,a]=(0,g.useState)(null);return(0,g.useEffect)(()=>{let n=!1;if(a(null),Ld(e))return Rd(e).then(async r=>{if(!n&&r)try{let i=await r(t,{pluginId:Md.get(e)??e,send:()=>void 0,onData:()=>()=>void 0});!n&&i instanceof HTMLElement&&a(i)}catch(t){console.error(`[plugin-widget:${e}] 渲染失败:`,t)}}),()=>{n=!0}},[e,t]),(0,g.useEffect)(()=>{let e=r.current;e&&(e.replaceChildren(),i&&e.appendChild(i))},[i]),i?(0,X.jsx)(`div`,{className:`plugin-widget`,ref:r}):(0,X.jsx)(X.Fragment,{children:n})}var pf=/^\s{0,3}(`{3,}|~{3,})/,mf=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function hf(e){return e.trim()===``}function gf(e){let t=pf.exec(e);return t?t[1]:null}function _f(e){let t=e.split(`
@@ -677,4 +677,4 @@ Systematic steps for investigating and resolving software defects:
677
677
  `)})]}):(0,X.jsx)(`div`,{className:`set-catalog-job error`,children:(0,X.jsxs)(`span`,{children:[`✗ `,da.error||u(`pluginJobFailed`)]})}))]}),Yn&&(0,X.jsxs)(`div`,{className:`set-catalog-add`,children:[(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`pluginCatalogSource`),value:zn,onChange:e=>Bn(e.target.value)}),Ni(ua),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`pluginCatalogId`),value:Vn,onChange:e=>Hn(e.target.value)}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`pluginCatalogName`),value:Un,onChange:e=>Wn(e.target.value)}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`pluginCatalogIcon`),value:qn,onChange:e=>Jn(e.target.value)}),(0,X.jsx)(`textarea`,{className:`set-input`,rows:2,placeholder:u(`pluginCatalogDesc`),value:Gn,onChange:e=>Kn(e.target.value)}),(0,X.jsxs)(`div`,{className:`set-catalog-add-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,disabled:!zn.trim(),onClick:aa,children:u(`pluginCatalogAddSubmit`)}),(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,onClick:()=>Xn(!1),children:u(`cancel`)})]})]}),e.pluginCatalog.length===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`noPluginCatalog`)}):(0,X.jsx)(`div`,{className:`set-list set-list-flat`,children:e.pluginCatalog.map(t=>{let n=hi.has(t.id),r=e.pluginUpdates?.[t.id],i=n&&r?.updatable===!0,a=!!(Mi(t.id)&&Mi(t.id)?.phase!==`done`),o=d!==`zh`&&t.nameEn?t.nameEn:t.name,s=d!==`zh`&&t.descriptionEn?t.descriptionEn:t.description;return(0,X.jsxs)(`div`,{className:`set-catalog-row`,children:[(0,X.jsxs)(`div`,{className:`set-catalog-main`,children:[(0,X.jsxs)(`div`,{className:`set-catalog-title`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(fi,{icon:t.icon,iconSvg:t.iconSvg}),` `,o]}),n&&(0,X.jsx)(`span`,{className:`set-catalog-installed`,children:u(`pluginInstalled`)}),!t.builtin&&(0,X.jsx)(`span`,{className:`set-catalog-custom`,children:u(`pluginCatalogCustom`)}),i&&(0,X.jsxs)(`span`,{className:`set-catalog-update-badge`,title:r?.latestVersion?`${r?.version??``} → v${r.latestVersion}`:r?.remoteSha??``,children:[u(`pluginUpdateAvailableBadge`),r?.latestVersion?` v${r.latestVersion}`:``]})]}),s&&(0,X.jsx)(`div`,{className:`set-catalog-desc`,children:s}),(0,X.jsx)(`div`,{className:`set-catalog-source`,children:t.source}),Pi(t.id)]}),(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[ox(t)&&(0,X.jsxs)(`a`,{href:ox(t),target:`_blank`,rel:`noreferrer noopener`,className:`set-uninstall link`,title:u(`pluginOfficialLinkHint`),children:[(0,X.jsx)(Ue,{}),u(`pluginOfficialLink`)]}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall${i?` accent`:``}`,disabled:a,title:i&&r?.latestVersion?u(`pluginUpdateAvailableDetail`,{version:`v${r.latestVersion}`}):u(`pluginUpdateHint`),onClick:()=>na(t.id,t.source),children:[(0,X.jsx)(J,{className:a?`set-job-spin`:``}),u(a?`pluginJobRunning`:`pluginUpdate`)]}),Dn===t.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,disabled:a,title:u(`pluginUninstallHint`),onClick:()=>$i(t.id),children:u(`uninstallConfirm`)}):(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,disabled:a,title:u(`pluginUninstallHint`),onClick:()=>On(t.id),children:[(0,X.jsx)(L,{}),u(`uninstallExt`)]})]}):(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginInstallHint`),disabled:a,onClick:()=>ra(t),children:a?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(J,{className:`set-job-spin`}),u(`pluginJobRunning`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ke,{}),u(`pluginInstall`)]})}),!t.builtin&&(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginCatalogRemoveHint`),onClick:()=>ia(t.id),children:(0,X.jsx)(N,{})})]})]},t.id)})})]}),S===`plugins`&&w===`installed`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(mt,{className:`set-section-icon`}),u(`pluginListTab`),(0,X.jsx)(`span`,{className:`set-count`,children:e.plugins.length}),(0,X.jsxs)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui-plugins`,target:`_blank`,rel:`noreferrer noopener`,className:`set-uninstall link`,title:u(`pluginOfficialMarketHint`),children:[(0,X.jsx)(Ue,{}),u(`pluginOfficialMarket`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginCheckUpdatesHint`),disabled:e.checkingPluginUpdates,onClick:()=>$({type:`check_plugin_updates`}),children:[(0,X.jsx)(J,{className:e.checkingPluginUpdates?`spin`:``}),e.checkingPluginUpdates?u(`checkingUpdate`):u(`pluginCheckUpdates`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginRescanHint`),onClick:()=>$({type:`plugins_reload`}),children:[(0,X.jsx)(J,{}),u(`pluginRescan`)]})]}),e.plugins.length>0&&(0,X.jsx)(sx,{plugins:e.plugins,disabledIds:mi}),e.plugins.length===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`noUiPlugins`)}):(0,X.jsx)(`div`,{className:`set-list set-list-flat`,children:e.plugins.map(t=>{let n=e.pluginUpdates?.[t.id],r=n?.updatable===!0,i=!!(Mi(t.id)&&Mi(t.id)?.phase!==`done`);return(0,X.jsxs)(g.Fragment,{children:[(0,X.jsx)(nx,{title:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ax,{phase:Vb(t,mi.has(t.id)),label:f(ix(Vb(t,mi.has(t.id))))}),(0,X.jsx)(fi,{icon:t.icon,iconSvg:t.iconSvg}),` `,t.name,r&&(0,X.jsxs)(`span`,{className:`set-catalog-update-badge`,title:n?.latestVersion?`v${t.version??`0.0.0`} → v${n.latestVersion}`:n?.remoteSha??``,children:[u(`pluginUpdateAvailableBadge`),n?.latestVersion?` v${n.latestVersion}`:``]})]}),subtitle:(t.error?`${t.id} · ${t.error}`:t.source?`${t.id} · ${t.source}`:`${t.id} · ${u(`uiPluginNoSource`)}`)+(t.permissions?.length?` · ${u(`uiPluginPerms`)}: ${t.permissions.join(`, `)}`:``),enabled:!mi.has(t.id)&&!t.error,onToggle:()=>!t.error&&gi(t),action:(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[(()=>{let n=ox(e.pluginCatalog.find(e=>e.id===t.id))||ox(t);return n?(0,X.jsxs)(`a`,{href:n,target:`_blank`,rel:`noreferrer noopener`,className:`set-uninstall link`,title:u(`pluginOfficialLinkHint`),children:[(0,X.jsx)(Ue,{}),u(`pluginOfficialLink`)]}):null})(),t.source&&(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall${r?` accent`:``}`,disabled:i,title:r&&n?.latestVersion?u(`pluginUpdateAvailableDetail`,{version:`v${n.latestVersion}`}):u(`pluginUpdateHint`),onClick:()=>na(t.id,t.source),children:[(0,X.jsx)(J,{className:i?`set-job-spin`:``}),u(i?`pluginJobRunning`:`pluginUpdate`)]}),Dn===t.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,disabled:i,title:u(`pluginUninstallHint`),onClick:()=>$i(t.id),children:u(`uninstallConfirm`)}):(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,disabled:i,title:u(`pluginUninstallHint`),onClick:()=>On(t.id),children:[(0,X.jsx)(L,{}),u(`uninstallExt`)]})]})},t.id),Pi(t.id),t.agentTools&&t.agentTools.length>0&&!x&&(0,X.jsxs)(`div`,{className:`set-row`,title:u(`pluginToolOffHint`),children:[(0,X.jsxs)(`span`,{className:`set-ui-source`,children:[u(`pluginToolsSection`),` (`,t.agentTools.length,`)`,t.agentTools.some(e=>xi.has(e.name))?` · ${u(`settingsDisabled`)}`:``]}),(0,X.jsx)(`div`,{className:`set-row-actions`,children:(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,onClick:()=>C(`tools`),children:[u(`settingsTools`),` →`]})})]}),(0,X.jsxs)(`div`,{className:`set-row set-log-row`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`set-diag-toggle`,onClick:()=>{jn===t.id?Nn(null):(Nn(t.id),$(Wc(t.id)))},children:[(0,X.jsx)(Be,{}),u(`pluginLogTitle`),` (`,Zc(t.id).length,`) ·`,` `,jn===t.id?u(`pluginLogHide`):u(`pluginLogShow`)]}),jn===t.id&&(0,X.jsx)(ux,{pluginId:t.id})]}),t.diagnostics&&t.diagnostics.length>0&&(0,X.jsxs)(`div`,{className:`set-row set-diag-row`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`set-diag-toggle`,onClick:()=>An(kn===t.id?null:t.id),children:[(0,X.jsx)(Ct,{}),u(`pluginDiagTitle`),` (`,t.diagnostics.length,`) ·`,` `,kn===t.id?u(`pluginDiagHide`):u(`pluginDiagShow`)]}),kn===t.id&&(0,X.jsx)(`ul`,{className:`set-diag-list`,children:t.diagnostics.map((e,n)=>(0,X.jsx)(`li`,{children:e},`${t.id}-${n}`))})]}),t.wantsDom&&(0,X.jsxs)(`div`,{className:`set-row`,title:u(`pluginDomDesc`),children:[(0,X.jsx)(`span`,{className:`set-ui-source`,children:t.domGranted?u(`pluginDomGranted`):u(`pluginDomNeed`)}),(0,X.jsx)(`div`,{className:`set-row-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall${t.domGranted?``:` confirm`}`,title:u(`pluginDomDesc`),onClick:()=>$({type:`plugin_dom_consent`,pluginId:t.id,granted:!t.domGranted}),children:t.domGranted?u(`pluginDomRevoke`):u(`pluginDomGrant`)})})]}),t.settingsSchema&&t.settingsSchema.length>0&&(0,X.jsxs)(`div`,{className:`set-row set-settings-row`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`set-diag-toggle`,onClick:()=>Ln(e=>({...e,[t.id]:!e[t.id]})),children:[(0,X.jsx)(U,{}),u(`pluginSettingsTitle`),` (`,t.settingsSchema.length,`) ·`,` `,Fn[t.id]?u(`pluginSettingsHide`):u(`pluginSettingsShow`)]}),Fn[t.id]&&(0,X.jsx)(gy,{plugin:t,models:_?.subagentModels??[]})]})]},t.id)})})]}),S===`plugins`&&x&&w===`installed`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(mt,{className:`set-section-icon`}),u(`dshPatches`),(0,X.jsx)(su,{text:u(`dshPatchesDesc`)}),(0,X.jsx)(`span`,{className:`set-count`,children:e.dshPatches?.files.length??0}),(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,title:u(`dshPatchesRescanHint`),onClick:()=>$({type:`dsh_patches_rescan`}),children:[(0,X.jsx)(J,{}),u(`dshPatchesRescan`)]})]}),(e.dshPatches?.files.length??0)===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`dshPatchesEmpty`)}):(0,X.jsx)(`div`,{className:`set-list`,children:e.dshPatches.files.map(e=>(0,X.jsx)(`div`,{className:`set-row`,children:(0,X.jsxs)(`div`,{className:`set-row-info`,children:[(0,X.jsx)(`div`,{className:`set-row-name`,children:e.name}),(0,X.jsxs)(`div`,{className:`set-row-desc`,children:[qp(e.size),` · `,new Date(e.mtimeMs).toLocaleString()]})]})},e.name))}),(0,X.jsxs)(`p`,{className:`set-hint`,children:[u(`dshPatchesPath`),` `,e.dshPatches?.patchDir??``]})]}),S===`review`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(ne,{className:`set-section-icon`}),u(`settingsReview`),(0,X.jsx)(su,{text:u(`settingsReviewDesc`)}),(0,X.jsx)(`span`,{className:`set-count`,children:_.reviewSkills.length})]}),(0,X.jsx)(nx,{title:u(`goalModeEnabled`),tip:`${u(`goalModeEnabledDesc`)}\n${u(`goalModeOffHint`)}`,enabled:_.goalModeEnabled,onToggle:()=>Q({goalModeEnabled:!_.goalModeEnabled})}),(0,X.jsx)(nx,{title:u(`delegateMode`),tip:`${u(`delegateModeDesc`)}\n${u(`delegateModeOffHint`)}`,enabled:e.state?.delegateMode===!0,onToggle:()=>$({type:`set_delegate_mode`,enabled:e.state?.delegateMode!==!0})}),(0,X.jsx)(`textarea`,{className:`set-prompt-input`,rows:5,placeholder:u(`reviewPromptPlaceholder`),value:ht,onFocus:()=>_t.current=!0,onBlur:()=>{_t.current=!1,Q({reviewPrompt:ht})},onChange:e=>gt(e.target.value)}),(0,X.jsxs)(`div`,{className:`set-field-label`,children:[u(`settingsReviewSkills`),x&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsx)(su,{text:u(`dshReviewPromptNote`)})]})]}),_.reviewSkills.length===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`noSkills`)}):(0,X.jsx)(`div`,{className:`set-list`,children:_.reviewSkills.map(e=>(0,X.jsx)(nx,{title:e.name,subtitle:e.description,enabled:e.enabled,onToggle:()=>fa(e)},`review-${e.name}`))})]}),S===`vision`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(He,{className:`set-section-icon`}),u(`settingsVisionBridge`)]}),(0,X.jsx)(nx,{title:u(`visionBridgeEnabled`),tip:`${u(`settingsVisionBridgeDesc`)}\n${u(`visionBridgeOffHint`)}`,enabled:_.visionBridgeEnabled,onToggle:()=>Q({visionBridgeEnabled:!_.visionBridgeEnabled})}),_.visionBridgeEnabled&&(0,X.jsx)(cx,{label:u(`visionBridgeModel`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:_.visionBridgeModel??``,onChange:e=>Q({visionBridgeModel:e.target.value||null}),children:[(0,X.jsx)(`option`,{value:``,children:u(`visionBridgeAuto`)}),_.visionModels.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.id}`,children:e.label},`${e.provider}/${e.id}`))]})}),_.visionBridgeEnabled&&(0,X.jsx)(lx,{mode:Ze,onModeChange:Qe,draft:Je,onDraftChange:Ye,defaultPrompt:_.visionBridgeDefaultPrompt,placeholder:u(`visionBridgePromptPlaceholder`),rows:4,onCommit:(e,t)=>{Q({visionBridgePromptMode:e,visionBridgePrompt:t})},hint:_.visionModels.length===0?u(`visionBridgeNoModels`):u(`visionBridgeCurrent`,{model:_.visionBridgeModel??u(`visionBridgeAuto`)}),focusRef:$e})]}),S===`presets`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(U,{className:`set-section-icon`}),u(`settingsPresets`),(0,X.jsx)(su,{text:u(`dshPresetUserNote`)}),(0,X.jsx)(`span`,{className:`set-count`,children:_.presets.length})]}),(0,X.jsxs)(`div`,{className:`set-preset-share-actions`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`set-preset-share-btn primary`,title:u(`presetShareShareBtn`),onClick:()=>St({name:_.presets[0]?.name??``,tab:`export`}),children:[(0,X.jsx)(G,{}),u(`presetShareShareBtn`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-preset-share-btn`,title:u(`presetShareImportBtn`),onClick:()=>St({name:``,tab:`import`}),children:[(0,X.jsx)(re,{}),u(`presetShareImportBtn`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-preset-share-btn`,title:u(`presetShareBrowseBtn`),onClick:()=>St({name:``,tab:`browse`}),children:[(0,X.jsx)(Pe,{}),u(`presetShareBrowseBtn`)]})]}),ti&&(0,X.jsxs)(`div`,{className:`set-preset-config`,children:[e.dshPresets&&e.dshPresets.presets.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`set-mode-row`,children:[(0,X.jsxs)(`label`,{className:`set-field-label`,children:[u(`dshDefaultPreset`),(0,X.jsx)(su,{text:u(`dshDefaultPresetDesc`)})]}),(0,X.jsx)(`select`,{className:`set-select`,value:e.dshPresets.defaultPreset,onChange:e=>$({type:`dsh_preset_default`,preset:e.target.value}),children:k_(e.dshPresets.presets).map(e=>(0,X.jsxs)(`option`,{value:e.id,disabled:!!e.broken,children:[O_(e,d,u).name,e.trust===`user`?` · ${u(`dshPresetUser`)}`:``,e.broken?` · ${u(`dshPresetBroken`)}`:``]},e.id))})]}),$r&&(0,X.jsx)(`p`,{className:`set-preset-config-desc`,children:$r})]}),e.dshPermission&&e.dshPermission.options.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`set-mode-row`,children:[(0,X.jsxs)(`label`,{className:`set-field-label`,children:[u(`dshPermDefault`),(0,X.jsx)(su,{text:u(`dshPermDefaultDesc`)})]}),(0,X.jsx)(`select`,{className:`set-select`,value:e.dshPermission.defaultPreset,onChange:e=>$({type:`dsh_permission_default`,preset:e.target.value}),children:M_.filter(t=>e.dshPermission.options.some(e=>e.value===t)).map(e=>(0,X.jsx)(`option`,{value:e,children:u(N_(e))},e))})]}),(0,X.jsx)(`p`,{className:`set-preset-config-desc`,children:u(P_(e.dshPermission.defaultPreset))})]})]}),ei&&(0,X.jsx)(`p`,{className:`set-hint`,children:u(`dshPresetUserNote`)}),(0,X.jsxs)(`div`,{className:`set-preset-save`,children:[(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`presetNamePlaceholder`),value:vt,onChange:e=>yt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&vt.trim()&&($({type:`save_preset`,name:vt.trim()}),yt(``))}}),(0,X.jsxs)(`button`,{type:`button`,className:`set-save-btn`,disabled:!vt.trim(),onClick:()=>{$({type:`save_preset`,name:vt.trim()}),yt(``)},children:[(0,X.jsx)(fe,{}),` `,u(`saveAsPreset`)]})]}),_.presets.length===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`noPresets`)}):(0,X.jsx)(`div`,{className:`set-list`,children:_.presets.map(e=>(0,X.jsxs)(`div`,{className:`set-row`,children:[(0,X.jsxs)(`div`,{className:`set-row-info`,children:[(0,X.jsx)(`div`,{className:`set-row-name`,children:e.name}),(0,X.jsxs)(`div`,{className:`set-row-desc`,children:[e.promptMode===`replace`?u(`promptModeReplace`):u(`promptModeAppend`),e.disabledSkills.length>0&&` · ${u(`settingsSkills`)} ${e.disabledSkills.length}`,e.disabledExtensions.length>0&&` · ${u(`settingsExtensions`)} ${e.disabledExtensions.length}`]})]}),(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`presetShare`),onClick:()=>St({name:e.name,tab:`export`}),children:(0,X.jsx)(G,{})}),(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,onClick:()=>$({type:`apply_preset`,name:e.name}),children:u(`applyPreset`)}),(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn danger`,title:u(`deletePreset`),onClick:()=>$({type:`delete_preset`,name:e.name}),children:(0,X.jsx)(L,{})})]})]},e.name))})]}),S===`mcp`&&(0,X.jsx)(Ty,{settings:_,chat:e}),S===`subagent-templates`&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(F,{className:`set-section-icon`}),u(`settingsSubagentTemplates`),(0,X.jsx)(su,{text:u(`settingsSubagentTemplatesDesc`)}),(0,X.jsx)(`span`,{className:`set-count`,children:_.subagentTemplates.length}),(0,X.jsxs)(`button`,{type:`button`,className:`set-save-btn`,title:u(`subagentTemplateNew`),onClick:()=>{Tt({name:``,description:``,promptMode:`replace`,systemPrompt:``,enabledSkills:[],enabledExtensions:[],model:``,thinkingLevel:``,enabled:!0}),Dt(!0)},children:[(0,X.jsx)(fe,{}),` `,u(`subagentTemplateNew`)]})]}),(0,X.jsx)(cx,{label:u(`subagentDefaultModelLabel`),tip:u(`subagentDefaultModelHint`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:_.subagentDefaultModel??``,onChange:e=>Q({subagentDefaultModel:e.target.value||null}),children:[(0,X.jsx)(`option`,{value:``,children:u(`subagentFollowMain`)}),_.subagentModels.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.id}`,children:e.label},`${e.provider}/${e.id}`))]})}),_.subagentModels.length===0&&(0,X.jsx)(`p`,{className:`set-hint`,children:u(`subagentNoModels`)}),wt&&(0,X.jsx)(`div`,{className:`modal-backdrop tpl-modal-backdrop`,onClick:()=>Tt(null),children:(0,X.jsxs)(`div`,{className:`modal tpl-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(`button`,{type:`button`,className:`modal-close`,"aria-label":u(`close`),onClick:()=>Tt(null),children:(0,X.jsx)(N,{})}),(0,X.jsxs)(`div`,{className:`modal-head`,children:[(0,X.jsx)(F,{className:`modal-head-icon`}),(0,X.jsx)(`h2`,{children:Et?u(`subagentTemplateNew`):`${u(`subagentTemplateEdit`)} · ${wt.name}`})]}),(0,X.jsxs)(`div`,{className:`modal-body`,children:[(0,X.jsxs)(`div`,{className:`tpl-fields`,children:[(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`tplNamePlaceholder`),value:wt.name,onChange:e=>Tt({...wt,name:e.target.value})}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`tplDescriptionPlaceholder`),value:wt.description,onChange:e=>Tt({...wt,description:e.target.value})}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`tplDescriptionEnPlaceholder`),value:wt.descriptionEn??``,onChange:e=>Tt({...wt,descriptionEn:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`set-mode-row`,children:[(0,X.jsx)(`label`,{className:`set-field-label`,children:u(`tplPromptModeLabel`)}),(0,X.jsxs)(`select`,{className:`set-select`,value:wt.promptMode,onChange:e=>Tt({...wt,promptMode:e.target.value}),children:[(0,X.jsx)(`option`,{value:`replace`,children:u(`promptModeReplace`)}),(0,X.jsx)(`option`,{value:`append`,children:u(`promptModeAppend`)})]})]}),(0,X.jsxs)(`div`,{className:`set-mode-row`,children:[(0,X.jsx)(`label`,{className:`set-field-label`,children:u(`tplModelLabel`)}),(0,X.jsxs)(`select`,{className:`set-select`,value:wt.model??``,onChange:e=>Tt({...wt,model:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:u(`subagentFollowMain`)}),_.subagentModels.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.id}`,children:e.label},`${e.provider}/${e.id}`))]})]}),(0,X.jsxs)(`div`,{className:`set-mode-row`,children:[(0,X.jsxs)(`label`,{className:`set-field-label`,children:[u(`tplThinkingLabel`),` `,(0,X.jsx)(su,{text:u(`tplThinkingHint`)})]}),(0,X.jsxs)(`select`,{className:`set-select`,value:wt.thinkingLevel??``,onChange:e=>Tt({...wt,thinkingLevel:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:u(`tplThinkingFollowMain`)}),x_.map(e=>(0,X.jsx)(`option`,{value:e,children:u(`thinking.${e}`)},e))]})]}),(0,X.jsx)(`textarea`,{className:`set-prompt-input`,rows:4,placeholder:`${u(`tplSystemPromptLabel`)}${d===`zh`?`:`:`: `}${u(`tplSystemPromptPlaceholder`)}`,value:wt.systemPrompt,onChange:e=>Tt({...wt,systemPrompt:e.target.value})}),(0,X.jsx)(`textarea`,{className:`set-prompt-input`,rows:4,placeholder:`${u(`tplSystemPromptLabel`)}: ${u(`tplSystemPromptEnPlaceholder`)}`,value:wt.systemPromptEn??``,onChange:e=>Tt({...wt,systemPromptEn:e.target.value})}),(0,X.jsxs)(`div`,{className:`tpl-pick-block`,children:[(0,X.jsx)(`div`,{className:`tpl-pick-head`,children:(0,X.jsxs)(`span`,{children:[u(`tplSkillsLabel`),` · `,u(`tplWhitelistHint`)]})}),_.skills.length===0?(0,X.jsx)(`p`,{className:`set-hint`,children:u(`noSkills`)}):(0,X.jsx)(`div`,{className:`tpl-pick`,children:_.skills.map(e=>(0,X.jsxs)(`label`,{className:`tpl-chip${wt.enabledSkills.includes(e.name)?` on`:``}`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:wt.enabledSkills.includes(e.name),onChange:t=>{let n=t.target.checked;Tt({...wt,enabledSkills:n?[...wt.enabledSkills,e.name]:wt.enabledSkills.filter(t=>t!==e.name)})}}),e.name]},e.name))})]}),(0,X.jsxs)(`div`,{className:`tpl-pick-block`,children:[(0,X.jsx)(`div`,{className:`tpl-pick-head`,children:(0,X.jsxs)(`span`,{children:[u(`tplExtensionsLabel`),` · `,u(`tplWhitelistHint`)]})}),_.extensions.length===0?(0,X.jsx)(`p`,{className:`set-hint`,children:u(`noExtensions`)}):(0,X.jsx)(`div`,{className:`tpl-pick`,children:_.extensions.map(e=>(0,X.jsxs)(`label`,{className:`tpl-chip${wt.enabledExtensions.includes(e.id)?` on`:``}`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:wt.enabledExtensions.includes(e.id),onChange:t=>{let n=t.target.checked;Tt({...wt,enabledExtensions:n?[...wt.enabledExtensions,e.id]:wt.enabledExtensions.filter(t=>t!==e.id)})}}),e.name]},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`modal-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`set-save-btn`,disabled:!wt.name.trim(),onClick:()=>{$({type:`save_subagent_template`,template:{...wt,name:wt.name.trim()}}),Tt(null)},children:u(`tplSave`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>Tt(null),children:u(`tplCancel`)})]})]})}),_.subagentTemplates.length===0?(0,X.jsx)(`p`,{className:`set-empty`,children:u(`noSubagentTemplates`)}):(0,X.jsx)(`div`,{className:`set-list set-list-flat`,children:_.subagentTemplates.map(e=>(0,X.jsxs)(`div`,{className:`set-row`,children:[(0,X.jsxs)(`div`,{className:`set-row-info`,children:[(0,X.jsxs)(`div`,{className:`set-row-name`,children:[e.name,_.subagentDefaultTemplates.includes(e.name)&&(0,X.jsx)(`span`,{className:`tpl-badge default`,children:u(`tplDefaultBadge`)}),!e.enabled&&(0,X.jsx)(`span`,{className:`tpl-badge`,children:u(`subagentTemplateClosed`)})]}),(0,X.jsxs)(`div`,{className:`set-row-desc`,children:[(d!==`zh`&&e.descriptionEn?e.descriptionEn:e.description)||`${e.promptMode===`replace`?u(`promptModeReplace`):u(`promptModeAppend`)}`,e.model?` · ${u(`tplModelLabel`)} ${e.model}`:` · ${u(`subagentFollowMain`)}`,e.thinkingLevel?` · ${u(`tplThinkingLabel`)} ${f(`thinking.${e.thinkingLevel}`)}`:``,e.enabledSkills.length>0&&` · ${u(`tplSkillsLabel`)} ${e.enabledSkills.length}`,e.enabledExtensions.length>0&&` · ${u(`tplExtensionsLabel`)} ${e.enabledExtensions.length}`,!e.description&&e.enabledSkills.length===0&&e.enabledExtensions.length===0&&` · ${u(`tplInherit`)}`]})]}),(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`set-switch${e.enabled?` on`:``}`,role:`switch`,"aria-checked":e.enabled,title:`${e.enabled?u(`subagentTemplateDisable`):u(`subagentTemplateEnable`)} · ${u(`subagentTemplateOffHint`)}`,onClick:()=>$({type:`save_subagent_template`,template:{...e,enabled:!e.enabled}}),children:(0,X.jsx)(`span`,{className:`set-switch-knob`})}),(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,title:u(`subagentTemplateEdit`),onClick:()=>{Tt({...e}),Dt(!1)},children:u(`subagentTemplateEdit`)}),Ot===e.name?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,title:u(`uninstallConfirmHint`),onClick:()=>{$({type:`delete_subagent_template`,name:e.name}),kt(null)},children:u(`uninstallConfirm`)}):(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn danger`,title:u(`tplDelete`),onClick:()=>kt(e.name),children:(0,X.jsx)(L,{})})]})]},e.name))})]}),S===`approval-rules`&&!x&&(0,X.jsxs)(`div`,{className:`set-section`,children:[(0,X.jsxs)(`div`,{className:`set-section-title`,children:[(0,X.jsx)(oe,{className:`set-section-icon`}),u(`settingsApprovalRules`),(0,X.jsx)(su,{text:u(`settingsApprovalRulesDesc`)}),(0,X.jsx)(`span`,{className:`set-count`,children:_.approvalRules?.length??0}),(0,X.jsxs)(`button`,{type:`button`,className:`set-save-btn`,title:u(`approvalRuleNew`),onClick:()=>{Mt({id:`custom.${At().slice(0,8)}`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:``,action:`ask`,label:``,labelEn:``,reason:``,reasonEn:``}),It(`bash`),Pt(!0),zt(null)},children:[(0,X.jsx)(fe,{}),` `,u(`approvalRuleNew`)]})]}),jt&&(0,X.jsxs)(`div`,{className:`rule-editor`,children:[(0,X.jsx)(`div`,{className:`set-section-title`,style:{fontSize:13,marginBottom:4},children:Nt?u(`approvalRuleNew`):`${u(`approvalRuleEdit`)} · ${jt.label}`}),(0,X.jsx)(cx,{label:u(`approvalRuleLabel`),children:(0,X.jsx)(`input`,{className:`set-input`,value:jt.label,placeholder:`例如:拦截 Docker 危险操作`,onChange:e=>Mt({...jt,label:e.target.value})})}),(0,X.jsx)(cx,{label:u(`approvalRuleLabelEn`),children:(0,X.jsx)(`input`,{className:`set-input`,value:jt.labelEn??``,placeholder:`e.g. Block dangerous Docker commands`,onChange:e=>Mt({...jt,labelEn:e.target.value})})}),(0,X.jsx)(cx,{label:u(`approvalRuleTools`),tip:u(`approvalRuleToolsTip`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ft,placeholder:`bash, write, edit (或 * 通配)`,onChange:e=>{It(e.target.value);let t=e.target.value.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean);Mt({...jt,tools:t.length>0?t:[`*`]})}})}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:10,flexWrap:`wrap`},children:[(0,X.jsx)(`div`,{style:{flex:1,minWidth:160},children:(0,X.jsx)(cx,{label:u(`approvalRuleField`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:jt.field,onChange:e=>Mt({...jt,field:e.target.value}),children:[(0,X.jsx)(`option`,{value:`command`,children:u(`approvalRuleFieldCommand`)}),(0,X.jsx)(`option`,{value:`path`,children:u(`approvalRuleFieldPath`)}),(0,X.jsx)(`option`,{value:`params`,children:u(`approvalRuleFieldParams`)})]})})}),(0,X.jsx)(`div`,{style:{flex:1,minWidth:160},children:(0,X.jsx)(cx,{label:u(`approvalRuleMatch`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:jt.match,onChange:e=>Mt({...jt,match:e.target.value}),children:[(0,X.jsx)(`option`,{value:`regex`,children:u(`approvalRuleMatchRegex`)}),(0,X.jsx)(`option`,{value:`glob`,children:u(`approvalRuleMatchGlob`)}),(0,X.jsx)(`option`,{value:`contains`,children:u(`approvalRuleMatchContains`)}),(0,X.jsx)(`option`,{value:`prefix`,children:u(`approvalRuleMatchPrefix`)}),(0,X.jsx)(`option`,{value:`outside_workspace`,children:u(`approvalRuleMatchOutsideWs`)})]})})}),(0,X.jsx)(`div`,{style:{flex:1,minWidth:160},children:(0,X.jsx)(cx,{label:`命中动作`,children:(0,X.jsxs)(`select`,{className:`set-select`,value:jt.action,onChange:e=>Mt({...jt,action:e.target.value}),children:[(0,X.jsx)(`option`,{value:`ask`,children:u(`approvalRuleActionAsk`)}),(0,X.jsx)(`option`,{value:`deny`,children:u(`approvalRuleActionDeny`)}),(0,X.jsx)(`option`,{value:`allow`,children:u(`approvalRuleActionAllow`)})]})})})]}),jt.match!==`outside_workspace`&&(0,X.jsx)(cx,{label:u(`approvalRuleValue`),tip:u(`approvalRuleValueTip`),children:(0,X.jsx)(`input`,{className:`set-input`,value:jt.value,placeholder:`匹配表达式或关键字…`,onChange:e=>Mt({...jt,value:e.target.value})})}),(0,X.jsx)(cx,{label:u(`approvalRuleReason`),children:(0,X.jsx)(`input`,{className:`set-input`,value:jt.reason??``,placeholder:`例如:检测到删除镜像或容器操作`,onChange:e=>Mt({...jt,reason:e.target.value})})}),(0,X.jsx)(cx,{label:u(`approvalRuleReasonEn`),children:(0,X.jsx)(`input`,{className:`set-input`,value:jt.reasonEn??``,placeholder:`e.g. Detected docker image/container removal`,onChange:e=>Mt({...jt,reasonEn:e.target.value})})}),(0,X.jsx)(`div`,{className:`set-row`,children:(0,X.jsxs)(`label`,{className:`set-checkbox-label`,style:{display:`inline-flex`,alignItems:`center`,gap:6},children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:jt.enabled,onChange:e=>Mt({...jt,enabled:e.target.checked})}),u(`approvalRuleEnabled`)]})}),Lt&&(0,X.jsx)(`div`,{style:{color:`var(--red, #ef4444)`,fontSize:12},children:Lt}),(0,X.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,marginTop:4},children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{Mt(null),zt(null)},children:u(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{if(!jt.label.trim()){zt(`请填写规则名称`);return}if(jt.match===`regex`)try{new RegExp(jt.value)}catch(e){zt(`正则表达式非法:${e.message}`);return}$({type:`save_approval_rule`,rule:jt}),Mt(null),zt(null)},children:u(`save`)})]})]}),(_.approvalRules??[]).length===0?(0,X.jsx)(`p`,{className:`set-hint`,children:u(`approvalRuleEmpty`)}):(0,X.jsx)(`div`,{className:`set-list set-list-flat`,children:(_.approvalRules??[]).map((e,t)=>{let n=e.builtin===!0;return(0,X.jsxs)(`div`,{className:`set-row${e.enabled?``:` rule-row-disabled`}`,style:{alignItems:`flex-start`,padding:`12px 0`},children:[(0,X.jsxs)(`div`,{className:`set-row-info`,children:[(0,X.jsxs)(`div`,{className:`set-row-name`,style:{display:`flex`,alignItems:`center`,flexWrap:`wrap`,gap:6},children:[(0,X.jsx)(`span`,{className:`rule-badge ${e.action}`,children:e.action===`deny`?u(`approvalRuleActionDeny`):e.action===`allow`?u(`approvalRuleActionAllow`):u(`approvalRuleActionAsk`)}),(0,X.jsx)(`strong`,{style:{fontSize:13},children:d===`zh`?e.label:e.labelEn||e.label}),n&&(0,X.jsx)(`span`,{className:`tpl-badge`,children:u(`approvalRuleBuiltin`)}),(0,X.jsx)(`span`,{className:`rule-meta-code`,children:e.tools.join(`, `)})]}),(0,X.jsxs)(`div`,{className:`set-hint`,style:{marginTop:6,display:`flex`,flexDirection:`column`,gap:3},children:[(0,X.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:6,flexWrap:`wrap`},children:[(0,X.jsxs)(`span`,{style:{opacity:.85,fontSize:11,fontFamily:`var(--mono)`},children:[`[`,e.field,` · `,e.match,`]`]}),e.match!==`outside_workspace`&&(0,X.jsx)(`code`,{className:`rule-pattern-code`,children:e.value})]}),(e.reason||e.reasonEn)&&(0,X.jsx)(`div`,{style:{opacity:.75,fontSize:11},children:d===`zh`?e.reason:e.reasonEn||e.reason})]})]}),(0,X.jsxs)(`div`,{className:`set-row-actions`,style:{marginLeft:12,flexShrink:0},children:[(0,X.jsx)(`button`,{type:`button`,className:`set-switch${e.enabled?` on`:``}`,role:`switch`,"aria-checked":e.enabled,title:e.enabled?u(`settingsEnabled`):u(`settingsDisabled`),onClick:()=>$({type:`save_approval_rule`,rule:{...e,enabled:!e.enabled}}),children:(0,X.jsx)(`span`,{className:`set-switch-knob`})}),!n&&t>0&&(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`approvalRuleMoveUp`),onClick:()=>{let e=[..._.approvalRules??[]],n=e[t-1];e[t-1]=e[t],e[t]=n,$({type:`save_approval_rules`,rules:e})},children:(0,X.jsx)(st,{})}),!n&&t<(_.approvalRules?.length??0)-1&&(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`approvalRuleMoveDown`),onClick:()=>{let e=[..._.approvalRules??[]],n=e[t+1];e[t+1]=e[t],e[t]=n,$({type:`save_approval_rules`,rules:e})},children:(0,X.jsx)(ut,{})}),n&&(Ht===e.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,onClick:()=>{$({type:`reset_builtin_approval_rule`,id:e.id}),Ut(null)},children:u(`uninstallConfirm`)}):(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`approvalRuleReset`),onClick:()=>Ut(e.id),children:(0,X.jsx)(J,{})})),(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`approvalRuleEdit`),onClick:()=>{Mt({...e}),It(e.tools.join(`, `)),Pt(!1),zt(null)},children:(0,X.jsx)(We,{})}),!n&&(Bt===e.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,onClick:()=>{$({type:`delete_approval_rule`,id:e.id}),Vt(null)},children:u(`uninstallConfirm`)}):(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn danger`,title:u(`approvalRuleDelete`),onClick:()=>Vt(e.id),children:(0,X.jsx)(L,{})}))]})]},e.id)})})]}),oi&&(0,X.jsx)(gu,{plugin:oi.plugin,epoch:e.pluginsEpoch,send:$,className:`set-plugin-page`}),Jt&&(0,X.jsx)(Sy,{name:Jt,override:Xt[Jt]??null,onApply:$t,onClose:()=>Yt(null)})]})]}),(0,X.jsx)(`div`,{className:`modal-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:xa,children:u(`close`)})})]}),bt!==null&&(0,X.jsx)(Bb,{presets:_.presets.map(e=>e.name),presetExport:e.presetExport,presetImport:e.presetImport,presetCatalog:e.presetCatalog,presetShare:e.presetShare,initialPreset:bt.name,initialTab:bt.tab,onClose:()=>St(null)})]})}function mx(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function hx({servers:e,onClose:t,plugins:n=[],epoch:r=0,send:i,onUiAction:a,autoCleanupMin:o=0}){let s=Z(),{locale:c}=Mn(),[l,u]=(0,g.useState)(new Set),d=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{$({type:`list_bg_servers`})},[]);let f=(0,g.useMemo)(()=>(Xi(zi(n),{locale:c,t:e=>s(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[n,c,s]);return(0,X.jsxs)(xy,{className:`bg-task-modal`,onClose:t,showCloseButton:!1,children:[(0,X.jsxs)(`div`,{className:`bg-task-head`,children:[(0,X.jsxs)(`span`,{className:`bg-task-title`,children:[(0,X.jsx)(Oe,{}),` `,s(`bgTasks`),e.length>0&&(0,X.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:s(`close`),onClick:t,children:(0,X.jsx)(N,{})})]}),e.length===0?(0,X.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,X.jsx)(Oe,{}),(0,X.jsx)(`span`,{children:s(`bgTasksEmpty`)}),(0,X.jsx)(`small`,{children:s(`bgTasksDesc`)})]}):(0,X.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,X.jsxs)(`li`,{className:`bg-task-item`,children:[(0,X.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:s(`bgTaskPort`)}),(0,X.jsxs)(`div`,{className:`bg-task-info`,children:[(0,X.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,X.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,X.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,X.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,X.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,X.jsxs)(`span`,{children:[s(`bgTaskPid`),` `,e.pid]}),(0,X.jsxs)(`span`,{children:[s(`bgTaskSince`),` `,mx(e.since,s)]}),t&&e.status&&(0,X.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,X.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${l.has(n)?`open`:``}`,title:`${s(`bgTaskCommand`)}: ${e.command}`,onClick:()=>d(n),children:[(0,X.jsx)(z,{}),(0,X.jsx)(`code`,{children:e.command})]})]}),!t&&(0,X.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?s(`bgTaskKeepOn`):s(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>$({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,X.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:s(`bgTaskStop`),onClick:()=>$(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,X.jsx)(H,{}),(0,X.jsx)(`span`,{children:s(`bgTaskStop`)})]})]},n)})}),f.map(e=>{let t=n.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,X.jsx)(`div`,{children:(0,X.jsx)(gu,{plugin:t,epoch:r,send:i??(()=>{})})},e.id):null:(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>a?.(e),children:e.label},e.id)}),(0,X.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,X.jsxs)(`label`,{className:`bg-task-cleanup`,title:s(`bgTaskCleanupHint`),children:[(0,X.jsx)(`span`,{children:s(`bgTaskCleanup`)}),(0,X.jsxs)(`select`,{className:`btn`,value:String(o),onChange:e=>$({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,X.jsx)(`option`,{value:`0`,children:s(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,X.jsx)(`option`,{value:String(e),children:s(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:s(`bgTaskCleanNowHint`),onClick:()=>$({type:`clean_bg_leftovers`}),children:[(0,X.jsx)(L,{}),(0,X.jsx)(`span`,{children:s(`bgTaskCleanNow`)})]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:s(`bgTaskRefresh`),onClick:()=>$({type:`list_bg_servers`}),children:[(0,X.jsx)(J,{}),(0,X.jsx)(`span`,{children:s(`bgTaskRefresh`)})]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:s(`bgTaskStopAll`),onClick:()=>$({type:`kill_background_servers`}),children:[(0,X.jsx)(H,{}),(0,X.jsx)(`span`,{children:s(`bgTaskStopAll`)})]})]})]})}function gx(){let e=Z(),t=gm(),[n,r]=(0,g.useState)(!0),i=(0,g.useRef)(null);return(0,g.useEffect)(()=>{t&&r(!0)},[t]),Rt(()=>{t&&mm()},!!t),(0,g.useEffect)(()=>{if(!t)return;let e=e=>{if(e.key!==`Enter`||e.shiftKey||e.ctrlKey||e.metaKey)return;let t=e.target;(!t||t===document.body||i.current?.contains(t))&&(e.preventDefault(),hm(n))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,n]),t?(0,j.createPortal)((0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:mm,children:(0,X.jsxs)(`div`,{ref:i,className:`tool-info-modal rollback-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`rollbackSession`),onClick:e=>e.stopPropagation(),style:{maxWidth:520},children:[(0,X.jsxs)(`div`,{className:`tool-info-head`,children:[(0,X.jsxs)(`span`,{className:`tool-info-title`,style:{color:`var(--amber, #f59e0b)`},children:[(0,X.jsx)(Ct,{}),e(`rollbackSession`)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:e(`cancel`),onClick:mm,children:(0,X.jsx)(N,{})})]}),(0,X.jsxs)(`div`,{className:`tool-info-body`,style:{padding:`16px 20px`},children:[(0,X.jsx)(`p`,{style:{margin:`0 0 16px 0`,fontSize:14,lineHeight:1.6},children:e(`rollbackConfirm`)}),(0,X.jsxs)(`label`,{style:{display:`flex`,alignItems:`flex-start`,gap:10,padding:`12px 14px`,borderRadius:8,backgroundColor:`var(--bg-elev, rgba(255, 255, 255, 0.04))`,border:`1px solid var(--border-subtle, rgba(255, 255, 255, 0.1))`,cursor:`pointer`,marginBottom:20},title:e(`rollbackRestoreWorkspaceTip`),children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked),style:{marginTop:3,cursor:`pointer`}}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{style:{fontWeight:600,fontSize:13,color:`var(--text, #e2e8f0)`},children:e(`rollbackRestoreWorkspace`)}),(0,X.jsx)(`div`,{style:{fontSize:12,color:`var(--text-dim, #9aa1b4)`,marginTop:2},children:e(`rollbackRestoreWorkspaceTip`)})]})]}),(0,X.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:10},children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:mm,children:e(`cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn btn-primary`,style:{display:`inline-flex`,alignItems:`center`,gap:6,backgroundColor:`var(--amber, #f59e0b)`,borderColor:`var(--amber, #f59e0b)`,color:`#000`,fontWeight:600},onClick:()=>hm(n),children:[(0,X.jsx)(dt,{}),e(`confirm`)]})]})]})]})}),document.body):null}function _x({approval:e}){let t=Z(),{locale:n}=Mn(),[r,i]=(0,g.useState)(``),[a,o]=(0,g.useState)(null);if((0,g.useEffect)(()=>{if(e){let t=e.params;i(typeof t==`object`&&t?JSON.stringify(t,null,2):t==null?`{}`:String(t)),o(null)}},[e]),!e)return null;let s=t=>{$({type:`tool_approval_response`,id:e.id,decision:`approve`,...t&&t!==`once`?{scope:t}:{}})},c=()=>{$({type:`tool_approval_response`,id:e.id,decision:`deny`,reason:`Operation rejected by user`})};return(0,j.createPortal)((0,X.jsx)(`div`,{className:`modal-backdrop`,children:(0,X.jsxs)(`div`,{className:`tool-info-modal approval-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`toolApprovalTitle`),style:{maxWidth:640,borderTop:`4px solid var(--amber, #f59e0b)`},onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`tool-info-head`,children:[(0,X.jsxs)(`span`,{className:`tool-info-title`,style:{color:`var(--amber, #f59e0b)`},children:[(0,X.jsx)(Ct,{}),t(`toolApprovalTitle`)]}),(0,X.jsx)(`code`,{className:`tool-info-name`,style:{fontWeight:700},children:e.toolName}),e.parentTool===`codemode`&&(0,X.jsxs)(`span`,{className:`tool-info-label`,style:{backgroundColor:`rgba(245, 158, 11, 0.15)`,color:`var(--amber, #f59e0b)`,border:`1px solid rgba(245, 158, 11, 0.35)`,fontWeight:600},children:[`⚡ `,t(`codemodeNestedApprovalBadge`)]}),e.conversationTitle&&(0,X.jsx)(`span`,{className:`tool-info-label`,children:e.conversationTitle}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:t(`toolApprovalDeny`),onClick:c,children:(0,X.jsx)(N,{})})]}),(0,X.jsxs)(`div`,{className:`tool-info-body`,style:{padding:`16px 20px`},children:[e.parentTool===`codemode`&&(0,X.jsxs)(`div`,{style:{padding:`8px 12px`,borderRadius:6,backgroundColor:`rgba(99, 102, 241, 0.12)`,border:`1px solid rgba(99, 102, 241, 0.25)`,marginBottom:12,color:`var(--text, #e2e8f0)`,fontSize:12.5,display:`flex`,alignItems:`center`,gap:6},children:[(0,X.jsx)(`span`,{style:{fontSize:14},children:`⚡`}),(0,X.jsx)(`span`,{children:t(`codemodeNestedApprovalDesc`)})]}),(e.reason||e.reasonEn)&&(0,X.jsxs)(`div`,{style:{padding:`10px 14px`,borderRadius:6,backgroundColor:`rgba(245, 158, 11, 0.12)`,border:`1px solid rgba(245, 158, 11, 0.3)`,marginBottom:16,color:`var(--amber, #f59e0b)`,fontSize:13,lineHeight:1.5,fontWeight:500},children:[(0,X.jsxs)(`div`,{style:{fontWeight:600,marginBottom:2},children:[t(`toolApprovalRiskAlert`),`:`]}),(0,X.jsx)(`div`,{children:n===`zh`?e.reason||e.reasonEn:e.reasonEn||e.reason}),e.category&&(0,X.jsxs)(`div`,{style:{marginTop:6,fontSize:12,opacity:.85},children:[t(`toolApprovalCategory`),`:`,n===`zh`?e.category.label:e.category.labelEn]}),e.hits&&e.hits.length>0&&(0,X.jsxs)(`div`,{className:`approval-hits-panel`,children:[(0,X.jsxs)(`div`,{className:`approval-hits-title`,children:[t(`toolApprovalHitsTitle`),` (`,e.hits.length,`)`]}),(0,X.jsx)(`div`,{className:`approval-hits-list`,children:e.hits.map((e,r)=>(0,X.jsxs)(`div`,{className:`approval-hit-item`,children:[(0,X.jsxs)(`div`,{className:`approval-hit-header`,children:[(0,X.jsx)(`span`,{className:`approval-hit-badge`,children:n===`zh`?e.label:e.labelEn||e.label}),(0,X.jsx)(`span`,{className:`approval-hit-field`,children:e.field}),(0,X.jsx)(`span`,{className:`approval-hit-pos`,children:t(`approvalHitPos`,{index:e.index+1,length:e.length})})]}),(0,X.jsx)(`div`,{className:`approval-hit-text`,children:(0,X.jsx)(`mark`,{className:`approval-danger-hit`,children:e.text})})]},r))})]})]}),e.toolName===`bash`&&typeof e.params?.command==`string`&&(0,X.jsxs)(`div`,{className:`approval-cmd-preview`,children:[(0,X.jsxs)(`div`,{className:`approval-cmd-preview-label`,children:[t(`approvalCommandPreview`),`:`]}),(0,X.jsxs)(`div`,{className:`approval-cmd-preview-box`,children:[(0,X.jsx)(`span`,{className:`bashblock-prompt`,children:`$`}),(0,X.jsx)(`code`,{children:Gu(e.params.command,e.hits)})]})]}),(0,X.jsxs)(`div`,{style:{marginBottom:16},children:[(0,X.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:6},children:[(0,X.jsx)(`span`,{style:{fontSize:13,fontWeight:600,color:`var(--text, #e2e8f0)`},children:t(`toolApprovalParams`)}),(0,X.jsx)(`span`,{style:{fontSize:11,color:`var(--text-dim, #9aa1b4)`},children:t(`toolApprovalEditPlaceholder`)})]}),(0,X.jsx)(`textarea`,{rows:8,value:r,onChange:e=>{i(e.target.value),a&&o(null)},style:{width:`100%`,fontFamily:`var(--mono, monospace)`,fontSize:12,lineHeight:1.5,padding:10,borderRadius:6,backgroundColor:`var(--bg-elev, #111827)`,color:`var(--text, #f8fafc)`,border:a?`1px solid var(--red, #ef4444)`:`1px solid var(--border-subtle, rgba(255,255,255,0.1))`,boxSizing:`border-box`,resize:`vertical`}}),a&&(0,X.jsx)(`div`,{style:{color:`var(--red, #ef4444)`,fontSize:12,marginTop:4},children:a})]}),(0,X.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,justifyContent:`flex-end`,gap:10},children:[e.category&&(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:t(`toolApprovalAllowCategoryHint`),onClick:()=>s(`category`),children:[(0,X.jsx)(Oe,{}),t(`toolApprovalAllowCategory`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:t(`toolApprovalAllowConversationHint`),onClick:()=>s(`all`),children:[(0,X.jsx)(ft,{}),t(`toolApprovalAllowConversation`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,style:{color:`var(--red, #ef4444)`},onClick:c,children:[(0,X.jsx)(N,{}),t(`toolApprovalDeny`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,onClick:()=>s(),style:{fontWeight:500},children:[(0,X.jsx)(dt,{}),t(`toolApprovalApprove`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn btn-primary`,style:{display:`inline-flex`,alignItems:`center`,gap:6,backgroundColor:`var(--amber, #f59e0b)`,borderColor:`var(--amber, #f59e0b)`,color:`#000`,fontWeight:600},onClick:()=>{try{let t=e.params,n;n=typeof t==`object`&&t||t==null?JSON.parse(r):r,o(null),$({type:`tool_approval_response`,id:e.id,decision:`edit`,editedParams:n})}catch(e){o(`JSON 格式错误:${e.message}`)}},children:[(0,X.jsx)(We,{}),t(`toolApprovalEditAndRun`)]})]})]})]})}),document.body)}function vx({overlay:e}){let t=Z(),n=(0,g.useRef)(null),r=(0,g.useRef)(null),i=(0,g.useCallback)(()=>{$({type:`tui_overlay_cancel`,id:e.id})},[e.id]);(0,g.useEffect)(()=>{let t=n.current;if(!t)return;let i=new m({theme:Jd(),fontFamily:`"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace`,fontSize:13,cursorBlink:!0,scrollback:1e3,cols:e.cols||80,rows:e.rows||24}),a=new h;i.loadAddon(a),i.open(t),r.current={term:i,fit:a},e.initialAnsi&&i.write(e.initialAnsi);let o=i.onData(t=>{$({type:`tui_overlay_input`,id:e.id,data:t})}),s=Ko((t,n)=>{t===e.id&&i.write(n)});try{a.fit(),(i.cols!==e.cols||i.rows!==e.rows)&&$({type:`tui_overlay_resize`,id:e.id,cols:i.cols,rows:i.rows})}catch{}let c=new ResizeObserver(()=>{try{a.fit(),i.cols&&i.rows&&$({type:`tui_overlay_resize`,id:e.id,cols:i.cols,rows:i.rows})}catch{}});c.observe(t);let l=setTimeout(()=>{i.focus()},50);return()=>{clearTimeout(l),c.disconnect(),o.dispose(),s(),i.dispose(),r.current=null}},[e.id,e.cols,e.rows,e.initialAnsi]);let a=e.title||t(`tuiOverlayTitle`);return(0,X.jsx)(xy,{open:!0,onClose:i,title:a,icon:(0,X.jsx)(z,{}),className:`tui-overlay-modal`,closeOnBackdropClick:!1,closeOnEscape:!0,children:(0,X.jsx)(`div`,{className:`tui-overlay-body`,children:(0,X.jsx)(`div`,{className:`tui-overlay-xterm`,ref:n})})})}var yx={pending:`in_progress`,in_progress:`done`,done:`failed`,failed:`pending`};function bx({plan:e}){let t=Z(),[n,r]=(0,g.useState)(!1),{copied:i,copy:a}=Tu({duration:2e3}),[o,s]=(0,g.useState)(null),[c,l]=(0,g.useState)(``),[u,d]=(0,g.useState)(``);if(!e||!e.steps||e.steps.length===0)return null;let f=e.steps,p=f.filter(e=>e.status===`done`).length,m=f.length,h=Math.round(p/m*100),_=f.find(t=>t.id===e.activeStepId)??f.find(e=>e.status===`in_progress`),v=()=>{window.confirm(`确定要清空当前任务计划看板吗?`)&&$({type:`plan_update`,steps:[]})},y=()=>{$({type:`set_plan_mode`,enabled:!1}),$({type:`prompt`,text:t(`planImplementRequest`)})},b=()=>{let e=f.map((e,t)=>`${t+1}. ${e.title}${e.description?` (${e.description})`:``}`).join(`
678
678
  `);$({type:`plan_clean_handoff`,steps:f,prompt:`${t(`planCleanHandoffPrompt`)}\n\n${e}`})},x=async()=>{let e=[`# ${t(`planBoardTitle`)} (${p}/${m})`,``,...f.map((e,t)=>{let n=`${e.status===`done`?`[x]`:e.status===`in_progress`?`[>]`:e.status===`failed`?`[!]`:`[ ]`} ${t+1}. ${e.title}`;return e.description&&(n+=`\n ${e.description}`),n})];await a(e.join(`
679
679
  `))},S=e=>{s(e.id),l(e.title),d(e.description||``)},C=()=>{s(null),l(``),d(``)},w=e=>{let t=c.trim();if(!t)return;let n={title:t};n.description=u.trim()?u.trim():void 0,$({type:`plan_step_update`,stepId:e,patch:n}),s(null)},T=e=>{$({type:`plan_step_delete`,stepId:e})},E=e=>{let t=f.find(t=>t.id===e);t&&$({type:`plan_step_update`,stepId:e,patch:{status:yx[t.status]}})},D=()=>{let e={id:`step-${Date.now()}`,title:t(`planBoardAddStep`),status:`pending`};$({type:`plan_step_add`,step:e}),S(e)},O=(e,n)=>{let r=(()=>{switch(e){case`done`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ft,{}),t(`planBoardCompleted`)]});case`in_progress`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(nt,{}),t(`planBoardInProgress`)]});case`failed`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(wt,{}),t(`planBoardFailed`)]});default:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(it,{}),t(`planBoardPending`)]})}})();return(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),E(n)},title:`点击切换状态 (pending / in_progress / done / failed)`,style:{display:`inline-flex`,alignItems:`center`,gap:4,color:e===`done`?`var(--green, #22c55e)`:e===`in_progress`?`var(--accent, #38bdf8)`:e===`failed`?`var(--red, #ef4444)`:`var(--text-dim, #9aa1b4)`,fontSize:12,fontWeight:e===`pending`?400:600,background:`none`,border:`none`,cursor:`pointer`,padding:`2px 4px`,borderRadius:4},children:r})};return(0,X.jsxs)(`div`,{className:`plan-board ${n?``:`plan-board-collapsed`}`.trim(),children:[(0,X.jsxs)(`div`,{className:`plan-board-head`,onClick:()=>r(!n),children:[(0,X.jsxs)(`div`,{className:`plan-board-head-main`,children:[(0,X.jsx)(Ee,{className:`plan-board-icon`}),(0,X.jsx)(`span`,{className:`plan-board-title`,children:t(`planBoardTitle`)}),(0,X.jsxs)(`span`,{className:`plan-board-count ${h===100?`plan-board-count-done`:``}`.trim(),children:[p,`/`,m]}),!n&&_&&(0,X.jsx)(`span`,{className:`plan-board-active`,title:_.title,children:_.title})]}),(0,X.jsxs)(`div`,{className:`plan-board-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`plan-board-implement`,title:t(`planImplementTip`),onClick:e=>{e.stopPropagation(),y()},children:t(`planImplementBtn`)}),n&&(0,X.jsx)(`button`,{type:`button`,className:`plan-board-clean-handoff`,title:t(`planCleanHandoffTip`),onClick:e=>{e.stopPropagation(),b()},children:t(`planCleanHandoffBtn`)}),n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(i?`planBoardExportSuccess`:`planBoardExportMarkdown`),onClick:e=>{e.stopPropagation(),x()},children:i?(0,X.jsx)(dt,{style:{color:`var(--green, #22c55e)`}}):(0,X.jsx)(et,{})}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(`clear`),onClick:e=>{e.stopPropagation(),v()},children:(0,X.jsx)(L,{})})]}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(n?`collapseSection`:`expandSection`),children:n?(0,X.jsx)(st,{}):(0,X.jsx)(ut,{})})]}),n&&(0,X.jsx)(`div`,{className:`plan-board-head-divider`,children:(0,X.jsx)(`div`,{className:`plan-board-head-divider-fill`,style:{width:`${h}%`,backgroundColor:h===100?`var(--green, #22c55e)`:`var(--accent, #38bdf8)`}})})]}),!n&&(0,X.jsx)(`div`,{className:`plan-board-progress-line`,children:(0,X.jsx)(`div`,{className:`plan-board-progress-line-fill`,style:{width:`${h}%`,backgroundColor:h===100?`var(--green, #22c55e)`:`var(--accent, #38bdf8)`}})}),n&&(0,X.jsxs)(`div`,{className:`plan-board-steps`,style:{marginTop:8,display:`flex`,flexDirection:`column`,gap:8},children:[f.map((n,r)=>{let i=n.id===e.activeStepId||n.status===`in_progress`;return o===n.id?(0,X.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6,padding:`8px 10px`,borderRadius:6,backgroundColor:`var(--bg-elev2, rgba(0, 0, 0, 0.2))`,border:`1px solid var(--accent, #38bdf8)`},children:[(0,X.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:t(`planBoardStepTitlePlaceholder`),style:{width:`100%`,padding:`4px 8px`,borderRadius:4,border:`1px solid var(--border-subtle)`,background:`var(--bg, #0b0f17)`,color:`var(--text, #f1f5f9)`,fontSize:13},autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),w(n.id)):e.key===`Escape`&&C()}}),(0,X.jsx)(`textarea`,{rows:2,value:u,onChange:e=>d(e.target.value),placeholder:t(`planBoardStepDescPlaceholder`),style:{width:`100%`,padding:`4px 8px`,borderRadius:4,border:`1px solid var(--border-subtle)`,background:`var(--bg, #0b0f17)`,color:`var(--text-dim, #9aa1b4)`,fontSize:12,resize:`vertical`},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)?(e.preventDefault(),w(n.id)):e.key===`Escape`&&C()}}),(0,X.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:6,marginTop:2},children:[(0,X.jsxs)(`button`,{type:`button`,className:`plan-board-iconbtn`,onClick:C,title:t(`cancel`),style:{padding:`3px 8px`,fontSize:12},children:[(0,X.jsx)(N,{}),` `,t(`cancel`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`plan-board-implement`,onClick:()=>w(n.id),title:t(`confirm`),style:{padding:`3px 10px`,fontSize:12},children:[(0,X.jsx)(dt,{}),` `,t(`confirm`)]})]})]},n.id||r):(0,X.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,flexWrap:`wrap`,rowGap:4,minWidth:0,padding:`6px 10px`,borderRadius:6,backgroundColor:i?`rgba(56, 189, 248, 0.08)`:`var(--bg-elev2, rgba(0, 0, 0, 0.2))`,border:i?`1px solid rgba(56, 189, 248, 0.25)`:`1px solid transparent`},children:[(0,X.jsxs)(`div`,{style:{flex:`1 1 180px`,minWidth:0,paddingRight:10},children:[(0,X.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:6,minWidth:0},children:[(0,X.jsxs)(`span`,{style:{fontSize:11,fontWeight:700,color:i?`var(--accent, #38bdf8)`:`var(--text-dim, #9aa1b4)`,minWidth:16},children:[r+1,`.`]}),(0,X.jsx)(`span`,{style:{fontWeight:i?600:500,color:n.status===`done`?`var(--text-dim, #9aa1b4)`:`var(--text, #f1f5f9)`,textDecoration:n.status===`done`?`line-through`:`none`,minWidth:0,overflowWrap:`anywhere`,wordBreak:`break-word`},children:n.title})]}),n.description&&(0,X.jsx)(`div`,{style:{fontSize:12,color:`var(--text-dim, #9aa1b4)`,marginTop:2,paddingLeft:22,lineHeight:1.4,overflowWrap:`anywhere`,wordBreak:`break-word`},children:n.description})]}),(0,X.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4,flexShrink:0,marginTop:2},children:[O(n.status,n.id),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(`planBoardEditStep`),onClick:()=>S(n),children:(0,X.jsx)(Ge,{size:12})}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(`planBoardDeleteStep`),onClick:()=>T(n.id),children:(0,X.jsx)(L,{size:12})})]})]},n.id||r)}),(0,X.jsxs)(`button`,{type:`button`,className:`plan-board-add-btn`,onClick:D,children:[(0,X.jsx)(fe,{}),` `,t(`planBoardAddStep`)]})]})]})}var xx=3,Sx=200;function Cx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wx(e){return typeof e==`string`&&e.trim()||void 0}function Tx(e,t){let n=[];for(let r of e){let e=Dx(r,t);if(n.includes(e)||n.push(e),n.length>=4){n.push(`…`);break}}return n.join(` | `)||`any`}function Ex(e){let t=e.slice(0,6).map(e=>typeof e==`string`?e:JSON.stringify(e)??String(e));if(t.length!==0)return`enum: ${t.join(` | `)}${e.length>t.length?` | …`:``}`}function Dx(e,t=0){if(t>6||!Cx(e))return`any`;if(wx(e.$ref))return`ref`;let n=wx(e.type);if(n===`array`){let n=e.items;return`array<${n===void 0?`any`:Dx(n,t+1)}>`}if(n)return n;for(let n of[`anyOf`,`oneOf`,`allOf`]){let r=e[n];if(Array.isArray(r)&&r.length>0)return Tx(r,t+1)}return Cx(e.properties)?`object`:Cx(e.additionalProperties)?`record<${Dx(e.additionalProperties,t+1)}>`:`any`}function Ox(e){let t=[],n=e.enum;if(Array.isArray(n)&&n.length>0){let e=Ex(n);e&&t.push(e)}return e.const!==void 0&&t.push(`const: ${JSON.stringify(e.const)}`),e.default!==void 0&&t.push(`default: ${JSON.stringify(e.default)}`),t.length>0?t.join(` · `):void 0}function kx(e,t={}){let n=t.maxDepth??xx,r=t.maxRows??Sx,i=e;if(!Cx(i))return[];let a=i.properties;if(!Cx(a))return[];let o=[],s=new Set((Array.isArray(i.required)?i.required:[]).filter(e=>typeof e==`string`)),c=(e,t,i,a)=>{if(!(o.length>=r))for(let[s,l]of Object.entries(e)){if(o.length>=r)return;let e=Cx(l)?l:{},u=t?`${t}.${s}`:s,d={name:u,type:Dx(e,i),required:a.has(s),depth:i},f=wx(e.description);f&&(d.description=f);let p=Ox(e);if(p&&(d.hint=p),o.push(d),i+1<n&&Cx(e.properties)){let t=new Set((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`));c(e.properties,u,i+1,t)}}};return c(a,``,0,s),o}function Ax(){let e=Z(),t=rs();return Rt(()=>{$o()},!!t),t?(0,j.createPortal)((0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:$o,children:(0,X.jsxs)(`div`,{className:`tool-info-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`toolInfoTitle`),onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`tool-info-head`,children:[(0,X.jsxs)(`span`,{className:`tool-info-title`,children:[(0,X.jsx)(Ae,{}),e(`toolInfoTitle`)]}),(0,X.jsx)(`code`,{className:`tool-info-name`,children:t.name}),t.label&&t.label!==t.name&&(0,X.jsx)(`span`,{className:`tool-info-label`,children:t.label}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:e(`close`),onClick:$o,children:(0,X.jsx)(N,{})})]}),(0,X.jsx)(`div`,{className:`tool-info-body`,children:(0,X.jsx)(jx,{info:t})})]})}),document.body):null}function jx({info:e}){let t=Z();if(e.status===`loading`)return(0,X.jsxs)(`div`,{className:`tool-info-state`,role:`status`,children:[(0,X.jsx)(`span`,{className:`cursor`}),` `,t(`toolInfoLoading`)]});if(e.status===`unsupported`)return(0,X.jsx)(`div`,{className:`tool-info-state`,children:t(`toolInfoUnsupported`)});if(e.status===`missing`)return(0,X.jsx)(`div`,{className:`tool-info-state`,children:t(`toolInfoMissing`)});let n=e.parameters===void 0?[]:kx(e.parameters),r=e.parameters===void 0?``:Nx(e.parameters);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`tool-info-badges`,children:[e.active!==void 0&&(0,X.jsx)(`span`,{className:`tool-info-badge ${e.active?`on`:`off`}`,children:e.active?t(`toolInfoActive`):t(`toolInfoInactive`)}),e.source&&(0,X.jsxs)(`span`,{className:`tool-info-badge`,children:[t(`toolInfoSource`),`: `,e.source,e.scope?` · ${e.scope}`:``]})]}),(0,X.jsxs)(`section`,{className:`tool-info-sec`,children:[(0,X.jsx)(`div`,{className:`tool-info-sec-label`,children:t(`toolInfoDescription`)}),(0,X.jsx)(`div`,{className:`tool-info-text`,children:e.description||t(`toolInfoNoDescription`)})]}),e.promptSnippet&&(0,X.jsxs)(`section`,{className:`tool-info-sec`,children:[(0,X.jsx)(`div`,{className:`tool-info-sec-label`,children:t(`toolInfoPromptSnippet`)}),(0,X.jsx)(`div`,{className:`tool-info-text dim`,children:e.promptSnippet})]}),e.promptGuidelines&&e.promptGuidelines.length>0&&(0,X.jsxs)(`section`,{className:`tool-info-sec`,children:[(0,X.jsx)(`div`,{className:`tool-info-sec-label`,children:t(`toolInfoGuidelines`)}),(0,X.jsx)(`ul`,{className:`tool-info-list`,children:e.promptGuidelines.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]}),(0,X.jsxs)(`section`,{className:`tool-info-sec`,children:[(0,X.jsx)(`div`,{className:`tool-info-sec-label`,children:t(`toolInfoParams`)}),n.length>0?(0,X.jsx)(Mx,{rows:n}):(0,X.jsx)(`div`,{className:`tool-info-text dim`,children:t(`toolInfoParamsNone`)}),e.parametersDropped&&(0,X.jsx)(`div`,{className:`tool-info-text warn`,children:t(`toolInfoSchemaDropped`)}),r&&(0,X.jsxs)(`details`,{className:`tool-info-raw`,children:[(0,X.jsxs)(`summary`,{children:[t(`toolInfoRawSchema`),(0,X.jsx)(fd,{text:r})]}),(0,X.jsx)(`pre`,{children:r})]})]}),(0,X.jsx)(`div`,{className:`tool-info-foot`,children:t(`toolInfoFootnote`)})]})}function Mx({rows:e}){let t=Z();return(0,X.jsx)(`div`,{className:`tool-schema-table`,role:`table`,children:e.map(e=>(0,X.jsxs)(`div`,{className:`tool-schema-row`,role:`row`,style:{paddingLeft:8+e.depth*14},children:[(0,X.jsxs)(`div`,{className:`tool-schema-name`,children:[(0,X.jsx)(`code`,{children:e.name}),e.required&&(0,X.jsx)(`span`,{className:`tool-schema-req`,children:t(`toolInfoRequired`)})]}),(0,X.jsxs)(`div`,{className:`tool-schema-type`,children:[e.type,e.hint&&(0,X.jsx)(`span`,{className:`tool-schema-hint`,children:e.hint})]}),e.description&&(0,X.jsx)(`div`,{className:`tool-schema-desc`,children:e.description})]},e.name))})}function Nx(e){try{return JSON.stringify(e,null,2)??``}catch{return``}}function Px(e,t){return e.toLowerCase().includes(t)}function Fx({open:e,projects:t,fileSearch:n,sessionSearch:r,onClose:i,onSwitchSession:a,onSwitchProject:o,onPreviewFile:s}){let c=Z(),{locale:l}=Mn(),u=l===`en`?`Plugins`:`插件`,d=Pa(`cwd`),f=(0,g.useRef)(null),[p,m]=(0,g.useState)(``),h=(0,g.useDeferredValue)(p),[_,v]=(0,g.useState)(0),y=(0,g.useRef)(0),b=(0,g.useRef)(null),[x,S]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!e)return;$({type:`list_sessions`}),$({type:`list_projects`});let t=p.trim();if(t){let e=b_();y.current=e,w(!0),$({type:`search_files`,reqId:e,query:t}),$({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>f.current?.select())},[e]);let[C,w]=(0,g.useState)(!1);(0,g.useEffect)(()=>{b.current&&clearTimeout(b.current);let e=h.trim();if(!e){w(!1),S(null);return}return b.current=setTimeout(()=>{let t=b_();y.current=t,w(!0),$({type:`search_files`,reqId:t,query:e}),$({type:`search_sessions`,reqId:t,query:e})},300),()=>{b.current&&clearTimeout(b.current)}},[h]),(0,g.useEffect)(()=>{n&&n.reqId===y.current&&S(n)},[n]);let T=h.trim().toLowerCase(),E=(0,g.useMemo)(()=>!T||!r||r.reqId!==y.current||!r.ok?[]:r.results,[r,T]),D=(0,g.useMemo)(()=>T?t.filter(e=>Px(e.path,T)).slice(0,10):[],[t,T]),O=(0,g.useMemo)(()=>!T||!x||!x.ok?[]:x.results,[x,T]);(0,g.useEffect)(()=>{x&&x.reqId===y.current&&r&&r.reqId===y.current&&y.current!==0&&w(!1)},[x,r]);let k=!!x&&x.ok&&x.truncated,[A,j]=(0,g.useState)([]);(0,g.useEffect)(()=>{if(!e)return;let t=h.trim();if(!t){j([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof Ys==`function`&&(r=Ys())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=ec(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){j([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}j(t.slice(0,20))}),()=>{n=!0}},[e,h]);let ee=(0,g.useMemo)(()=>[...E.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...D.map(e=>({kind:`project`,path:e.path})),...O.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...A.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[E,D,O,A]);(0,g.useEffect)(()=>{v(0)},[h]);let M=(0,g.useCallback)(e=>{if(e){if(e.kind===`session`)a(e.path,e.anchors),i();else if(e.kind===`project`){o(e.path),$({type:`list_sessions`}),$({type:`list_projects`});let t=h.trim();if(t){let e=b_();y.current=e,w(!0),$({type:`search_files`,reqId:e,query:t}),$({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?Ls(e.providerId,e.action,e.action).catch(()=>{}):s(e.path,e.name)}},[a,o,s,h]);(0,g.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),i()):e.key===`ArrowDown`?(e.preventDefault(),v(e=>Math.max(0,Math.min(e+1,ee.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),v(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),M(ee[_]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[ee,_,M,i,e]);let te=E.length+D.length+O.length+A.length,ne=(e,t,n)=>(0,X.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(`em`,{children:t})]}),P=-1;return e?(0,X.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:i,children:(0,X.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`gs-input-row`,children:[(0,X.jsx)(le,{}),(0,X.jsx)(`input`,{ref:f,type:`text`,value:p,placeholder:c(`gsPlaceholder`),onChange:e=>m(e.target.value)}),(0,X.jsx)(`button`,{type:`button`,className:`gs-close`,title:c(`close`),onClick:i,children:(0,X.jsx)(N,{})})]}),(0,X.jsxs)(`div`,{className:`gs-results`,children:[!T&&(0,X.jsx)(`div`,{className:`gs-empty`,children:c(`gsHint`)}),T&&te===0&&!k&&(0,X.jsx)(`div`,{className:`gs-empty`,children:c(C?`gsSearching`:`gsNoResults`)}),E.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[ne(c(`gsSessions`),E.length,(0,X.jsx)(be,{})),E.map(e=>{P++;let t=P,n=e.name||e.path.split(/[\\/]/).pop()||e.path;return(0,X.jsxs)(`div`,{className:`gs-item-wrap`,children:[(0,X.jsxs)(`button`,{type:`button`,className:t===_?`gs-item active`:`gs-item`,onMouseEnter:()=>v(t),onClick:()=>M({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,X.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,X.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,X.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),(0,X.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:c(`quoteConversation`),onClick:t=>{t.stopPropagation(),cr({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,c(`quoteConversationShort`)]})]},e.path)})]}),D.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[ne(c(`gsProjects`),D.length,(0,X.jsx)(Le,{})),D.map(e=>{P++;let t=P,n=d&&e.path===d;return(0,X.jsxs)(`button`,{type:`button`,className:t===_?`gs-item active`:`gs-item`,onMouseEnter:()=>v(t),onClick:()=>M({kind:`project`,path:e.path}),children:[(0,X.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,X.jsx)(`em`,{className:`gs-item-meta`,children:c(`gsCurrentProject`)})]}),(0,X.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(O.length>0||T&&k)&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[ne(c(`gsFiles`),O.length,(0,X.jsx)(Be,{})),O.map(e=>{P++;let t=P;return(0,X.jsxs)(`button`,{type:`button`,className:t===_?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:c(`gsOpenPreview`),onMouseEnter:()=>v(t),onClick:()=>{e.type===`file`&&M({kind:`file`,path:e.path,name:e.name})},children:[(0,X.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,X.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),k&&(0,X.jsx)(`div`,{className:`gs-truncated`,children:c(`gsTruncated`)})]}),A.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[ne(u,A.length,(0,X.jsx)(Y,{})),A.map((e,t)=>{P++;let n=P;return(0,X.jsxs)(`button`,{type:`button`,className:n===_?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>v(n),onClick:()=>M({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,X.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,X.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,X.jsxs)(`div`,{className:`gs-foot`,children:[(0,X.jsxs)(`span`,{children:[`↑↓ `,c(`gsNavigate`)]}),(0,X.jsxs)(`span`,{children:[`Enter `,c(`gsOpen`)]}),(0,X.jsxs)(`span`,{children:[`Esc `,c(`gsCloseHint`)]})]})]})}):null}function Ix({entry:e,pluginView:t,onUiAction:n,onClose:r}){let i=Z(),a=e.label||e.id,o=e.kind===`view`;return(0,X.jsx)(xy,{className:`plugin-modal`,title:a,icon:e.icon,onClose:r,children:(0,X.jsx)(`div`,{className:`modal-body plugin-modal-body`,children:o?t?(0,X.jsx)(Ov,{entry:t}):(0,X.jsx)(`div`,{className:`plugin-modal-loading`,children:i(`loading`)}):e.kind===`divider`?(0,X.jsx)(`hr`,{className:`plugin-modal-divider`}):(0,X.jsx)(`button`,{type:`button`,className:`btn primary plugin-modal-action`,onClick:()=>n?.(e),children:e.badge??a})})})}var Lx=5e3;function Rx({file:e,content:t,onAddLines:n,onAttach:r,onClose:i,uiFilePreviewToolbar:a,onUiAction:o}){let s=Z(),[c,l]=(0,g.useState)(null),[u,d]=(0,g.useState)(!1),[f,p]=(0,g.useState)(null),[m,h]=(0,g.useState)(!1),[_,v]=(0,g.useState)(!1),[y,b]=(0,g.useState)(!1),[x,S]=(0,g.useState)(``),[C,w]=(0,g.useState)(!0),[T,E]=(0,g.useState)(!0),[D,O]=(0,g.useState)(!1),k=(0,g.useRef)(!1),[A,j]=(0,g.useState)(!0),[ee,ne]=(0,g.useState)(!1),[P,F]=(0,g.useState)(100),re=(0,g.useRef)(0),ie=(0,g.useRef)(!1),I=(0,g.useRef)(null),[ae,L]=(0,g.useState)(!1),[R,z]=(0,g.useState)(!1),B=(0,g.useRef)(!1),V=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),V.current&&clearTimeout(V.current)},[]),(0,g.useEffect)(()=>{d(!0),l(null),p(null),b(!1),S(``),w(!0),E(!0),O(!1),k.current=!1,B.current=!1,L(!1),z(!1),V.current&&clearTimeout(V.current),$({type:`read_file`,path:e.path})},[e.path]),(0,g.useEffect)(()=>{t&&t.path===e.path&&(l(t),y||S(t.text),d(!1),B.current&&(B.current=!1,V.current&&clearTimeout(V.current),L(!1),z(!1),b(!1),S(t.text),k.current&&(zx(e.name)&&w(!0),Vx(e.name)&&E(!0)),p(null)))},[t,y,e.path]),(0,g.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){q();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&y){e.preventDefault(),ue();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),G())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i,c,y,x]),(0,g.useEffect)(()=>{let e=()=>{ie.current=!1,h(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let H=(0,g.useMemo)(()=>{if(!c)return[];let e=c.text.split(`
680
- `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,Lx)},[c]),U=c?.lines??0,W=U>Lx,oe=(e,t)=>{if(t){let t=re.current>0?re.current:e;p({start:Math.min(t,e),end:Math.max(t,e)})}else re.current=e,p({start:e,end:e})},G=()=>{H.length!==0&&(re.current=1,p({start:1,end:H.length}))},se=()=>{f&&(n(e.path,e.name,f.start,f.end),v(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>v(!1),1400))},ce=c!==null&&c.kind===`text`&&!c.binary&&!c.truncated&&!Bx(e.name),K=()=>{B.current=!1,V.current&&clearTimeout(V.current),L(!1),z(!1),S(c?.text??``),b(!1),k.current&&(zx(e.name)&&w(!0),Vx(e.name)&&E(!0))},le=()=>{if(y){if(x!==(c?.text??``)&&!window.confirm(s(`discardFileChanges`)))return;K();return}ce&&c&&(k.current=zx(e.name)&&C||Vx(e.name)&&T,zx(e.name)&&w(!1),Vx(e.name)&&E(!1),p(null),S(c.text),b(!0))},ue=()=>{y&&c&&ce&&$({type:`write_file`,path:e.path,text:x})&&(B.current=!0,z(!1),L(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B.current=!1,L(!1),z(!0)},5e3))},q=()=>{(!y||x===(c?.text??``)||window.confirm(s(`discardFileChanges`)))&&i()},J=e=>{F(Math.min(200,Math.max(50,e)))},fe=f?f.end-f.start+1:0,pe=c?.binary??!1,me=c?.truncated??!1,Y=c?.kind??`text`,he=zx(e.name)||Bx(e.name),ge=Vx(e.name),_e=he&&C&&!y&&Y===`text`&&!pe,ye=ge&&T&&!y&&Y===`text`&&!pe,be={"host:fp-md":he&&Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${C?`on`:``}`,"data-tip":s(C?`showMarkdownSource`:`showMarkdownPreview`),disabled:y,onClick:()=>w(e=>!e),children:C?(0,X.jsx)(He,{}):(0,X.jsx)(tt,{})}):null,"host:fp-html":ge&&Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach html ${T?`on`:``}`,"data-tip":s(T?`showHtmlSource`:`showHtmlPreview`),disabled:y,onClick:()=>E(e=>!e),children:T?(0,X.jsx)(tt,{}):(0,X.jsx)(He,{})}):null,"host:fp-edit":Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach edit ${y?`on`:``}`,"data-tip":s(me?`fileEditTruncated`:y?`exitEditFile`:`editFile`),disabled:!ce&&!y,onClick:le,children:(0,X.jsx)(We,{})}):null,"host:fp-wrap":Y===`text`&&!pe&&!_e&&!ye?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${A?`on`:``}`,"data-tip":s(A?`disableWrap`:`enableWrap`),onClick:()=>j(e=>!e),children:(0,X.jsx)($e,{})}):null,"host:fp-zoom":Y===`text`&&c?(0,X.jsxs)(`span`,{className:`fp-zoom`,children:[(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":s(`zoomOut`),disabled:P<=50,onClick:()=>J(P-10),children:(0,X.jsx)(M,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:s(`resetZoom`),onClick:()=>F(100),children:[P,`%`]}),(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":s(`zoomIn`),disabled:P>=200,onClick:()=>J(P+10),children:(0,X.jsx)(te,{})})]}):null,"host:fp-ref":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":s(`referenceTip`),onClick:()=>r(e.path,e.name,`reference`),children:(0,X.jsx)(De,{})}),"host:fp-full":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach full ${ee?`on`:``}`,"data-tip":s(ee?`exitFullscreen`:`fullscreen`),onClick:()=>ne(e=>!e),children:ee?(0,X.jsx)(ve,{}):(0,X.jsx)(Se,{})}),"host:fp-close":null},xe=a===void 0?[`host:fp-md`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):a.filter(e=>!e.hidden&&e.id!==`host:fp-close`),Ce=e=>hn(dn(`/api/file?clientId=${encodeURIComponent(hl())}&path=${encodeURIComponent(e)}`)),we=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return hn(dn(`${/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`}?clientId=${encodeURIComponent(hl())}${D?`&allowJs=1`:``}`))};return(0,X.jsx)(`div`,{className:`fp-overlay ${ee?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&q()},children:(0,X.jsxs)(`div`,{className:`fp ${ee?`fullscreen`:``}`,style:{"--fp-zoom":P/100},children:[(0,X.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&ne(e=>!e)},children:[(0,X.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,X.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,X.jsxs)(`span`,{className:`fp-meta`,children:[c&&Y===`text`&&!pe&&s(`fileLines`,{n:U}),c&&` · ${Jp(c.size)}`]}),(0,X.jsx)(`span`,{className:`fp-head-actions`,children:Ih(xe,be,o)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-close`,title:s(`close`),"aria-label":s(`close`),onClick:q,children:(0,X.jsx)(N,{})})]}),me&&Y===`text`&&!pe&&(0,X.jsx)(`div`,{className:`fp-notice`,children:Bx(e.name)?s(`previewLinesTruncated`,{n:H.length}):s(`previewTruncated`)}),u&&!c&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`loading`)}),!u&&Y===`none`&&!pe&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`previewNotSupported`)}),!u&&Y===`image`&&(0,X.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:q,title:s(`clickToCloseImage`),children:(0,X.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:Ce(e.path),alt:e.name,onClick:q,title:s(`clickToCloseImage`)})}),!u&&Y===`video`&&(0,X.jsx)(`div`,{className:`fp-media-wrap`,children:(0,X.jsx)(`video`,{className:`fp-media`,src:Ce(e.path),controls:!0,preload:`metadata`})}),!u&&ye&&c&&(0,X.jsxs)(`div`,{className:`fp-html`,children:[(0,X.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,X.jsx)(`span`,{className:`fp-html-hint`,title:s(D?`htmlJsOnTip`:`htmlJsOffTip`),children:s(D?`htmlJsOn`:`htmlJsOff`)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-html-js ${D?`on`:``}`,"data-tip":s(D?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>O(e=>!e),children:s(D?`htmlDisableJs`:`htmlEnableJs`)}),(0,X.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:we(e.path),target:`_blank`,rel:`noopener noreferrer`,title:s(`openInNewTab`),children:[(0,X.jsx)(Ue,{}),(0,X.jsx)(`span`,{children:s(`openInNewTab`)})]})]}),(0,X.jsx)(`iframe`,{className:`fp-html-frame`,src:we(e.path),title:e.name,sandbox:D?`allow-scripts`:``,referrerPolicy:`no-referrer`},D?`js`:`nojs`)]}),!u&&_e&&c&&(0,X.jsx)(`div`,{className:Bx(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,X.jsx)(`div`,{className:`fp-markdown-zoom`,children:(0,X.jsx)(sf,{text:c.text})})}),!u&&pe&&Y!==`image`&&Y!==`video`&&c&&(0,X.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,X.jsxs)(`div`,{className:`fp-notice`,children:[s(`binaryFile`),c.truncated&&s(`binaryHexTruncated`)]}),(0,X.jsx)(`pre`,{className:`fp-hex`,children:c.text})]}),!u&&y&&Y===`text`&&!pe&&c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`textarea`,{className:`fp-editor ${A?``:`no-wrap`}`,value:x,onChange:e=>S(e.target.value),wrap:A?`soft`:`off`,spellCheck:!1,autoFocus:!0}),R&&(0,X.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:s(`saveResultUnknown`)})]}),!u&&!_e&&!ye&&!y&&Y===`text`&&!pe&&c&&H.length===0&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`emptyFile`)}),!u&&!_e&&!ye&&!y&&Y===`text`&&!pe&&H.length>0&&(0,X.jsxs)(`div`,{className:`fp-code ${m?`dragging`:``} ${A?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[H.map((e,t)=>{let n=t+1,r=f!==null&&n>=f.start&&n<=f.end;return(0,X.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(oe(n,e.shiftKey),ie.current=!0,h(!0))},onMouseEnter:()=>{ie.current&&oe(n,!0)},children:[(0,X.jsx)(`span`,{className:`fp-num`,children:n}),(0,X.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),W&&(0,X.jsx)(`div`,{className:`fp-lines-note`,children:s(`previewLinesTruncated`,{n:Lx})})]}),(y||!_e&&!ye&&Y===`text`)&&(0,X.jsx)(`div`,{className:`fp-foot`,children:y?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:s(`editFile`)}),(0,X.jsxs)(`div`,{className:`fp-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:le,children:s(`cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:ae||x===(c?.text??``),onClick:ue,children:[(0,X.jsx)(de,{}),` `,s(`saveFile`)]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:f?s(`selectedRange`,{n:fe,start:f.start,end:f.end}):s(`selectLinesHint`)}),(0,X.jsxs)(`div`,{className:`fp-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:H.length===0,onClick:G,children:s(`selectAll`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:!f,onClick:()=>p(null),children:s(`clearSelection`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!f||pe,onClick:se,children:[_?(0,X.jsx)(dt,{}):null,s(_?`addedToChat`:`addToChat`)]})]})]})})]})})}function zx(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function Bx(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)}function Vx(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}function Hx({file:e,plugin:t,declaration:n,epoch:r,send:i,onClose:a,onFallback:o}){let s=Z(),c=(0,g.useRef)(null),[l,u]=(0,g.useState)(null),[d,f]=(0,g.useState)(!1),p=(0,g.useRef)(o);p.current=o;let m=n.label??t.name;return(0,g.useEffect)(()=>{let r=c.current;if(!r)return;let a=!1,o;return u(null),f(!1),(async()=>{try{let s=await ny({plugin:t,declaration:n});if(a)return;if(!s)throw Error(`插件没有提供可用的文件查看器`);let c=`/plugins-api/${encodeURIComponent(t.id)}`,l={...Hc(t.id,i),file:e,apiUrl:(e,t)=>{let n=String(e??``).startsWith(`/`)?String(e):`/${String(e??``)}`,r=new URLSearchParams;for(let[e,n]of Object.entries(t??{}))n!==void 0&&r.set(e,String(n));let i=r.toString();return hn(dn(`${c}${n}${i?`?${i}`:``}`))}};o=s.handler.mount(r,e,l),a||f(!0)}catch(e){a||(console.error(`[plugin:${t.id}] file handler failed:`,e),p.current())}})(),()=>{if(a=!0,typeof o==`function`)try{o()}catch(e){console.error(`[plugin:${t.id}] file handler cleanup failed:`,e)}r.textContent=``}},[e,t,n,r,i]),(0,X.jsx)(xy,{className:`plugin-file-preview`,title:m,icon:t.icon,onClose:a,children:(0,X.jsxs)(`div`,{className:`modal-body plugin-file-preview-body`,children:[(0,X.jsx)(`div`,{className:`plugin-file-preview-file`,title:e.path,children:e.name}),l?(0,X.jsx)(`div`,{className:`plugin-file-preview-error`,children:l}):null,!l&&!d?(0,X.jsx)(`div`,{children:s(`loading`)}):null,(0,X.jsx)(`div`,{ref:c,className:`plugin-file-preview-host`})]})})}var Ux=.4,Wx=1.05;function Gx(e){return Math.min(300,e*.86)}function Kx(e,t,n){return n||(t<=144?null:e<=72?`left`:t-e<=72?`right`:null)}function qx(e,t){let n=Math.abs(e),r=Math.abs(t);return n<12&&r<12?`none`:n>r*1.2?`horizontal`:`vertical`}function Jx(e,t){return e===`left`?t:-t}function Yx(e,t){return Math.max(-e,Math.min(0,-e+t))}function Xx(e,t,n){let r=n?e+t:t;return Math.max(0,Math.min(1,r/e))}function Zx(e){let{wasOpen:t,pull:n,width:r,durationMs:i}=e;return i<=320&&Math.abs(n)>=48?n>0:Xx(r*Wx,n,t)>=Ux}var Qx=new Set([`auto`,`scroll`,`overlay`]);function $x(e,t){let n=e instanceof Element?e:null;for(;n;){if(n instanceof HTMLElement&&n.scrollWidth>n.clientWidth+4&&Qx.has(getComputedStyle(n).overflowX))return!0;if(n===t)break;n=n.parentElement}return!1}function eS(){let e=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener(`click`,e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener(`click`,e,{capture:!0}),400)}function tS(e){let{enabled:t,open:n,onOpenChange:r,container:i}=e,{panelSelector:a,backdropSelector:o}=e;(0,g.useEffect)(()=>{let e=i.current;if(!t||!e)return;let s=null,c=`none`,l=0,u=0,d=0,f=0,p=!1,m=0,h=0,g=null,_=null,v=()=>{g&&(g.classList.remove(`drawer-dragging`),g.style.transform=``),_&&(_.style.opacity=``),s=null,c=`none`,g=null,_=null,f=0,p=!1},y=t=>{if(v(),t.touches.length!==1)return;let r=t.touches[0],i=Kx(r.clientX,window.innerWidth,n);i&&!$x(t.target,e)&&(s=i,l=r.clientX,u=r.clientY,d=Date.now())},b=t=>{let r=s;if(!r||t.touches.length!==1)return;let i=t.touches[0],d=i.clientX-l,v=i.clientY-u;if(c===`none`){let t=qx(d,v);if(t===`none`)return;if(t===`vertical`){s=null;return}c=`horizontal`,p=n===r,m=Gx(window.innerWidth),h=m*Wx;let i=e.querySelector(a?a(r):`.panel-drawer.drawer-${r}`);if(!i){s=null;return}g=i,_=o===null?null:e.querySelector(o??`.drawer-backdrop`),i.classList.add(`drawer-dragging`)}let y=g;if(!y)return;f=Jx(r,d);let b=Yx(h,f);y.style.transform=`translateX(${r===`left`?b:-b}px)`,_&&(_.style.opacity=String(Xx(h,f,p))),t.preventDefault()},x=()=>{let e=s,t=c===`horizontal`&&e!==null&&g!==null,i=f,a=Date.now()-d,o=t?Zx({wasOpen:p,pull:i,width:m,durationMs:a}):!1;v(),t&&e&&o!==(n===e)&&(eS(),r(o?e:null))},S=()=>v();return e.addEventListener(`touchstart`,y,{passive:!0}),e.addEventListener(`touchmove`,b,{passive:!1}),e.addEventListener(`touchend`,x),e.addEventListener(`touchcancel`,S),()=>{v(),e.removeEventListener(`touchstart`,y),e.removeEventListener(`touchmove`,b),e.removeEventListener(`touchend`,x),e.removeEventListener(`touchcancel`,S)}},[t,n,r,i,a,o])}function nS(e,t,n,r,i){let a=new Map;for(let e of r)a.set(e.id,!!e.isStreaming);if(t&&a.set(t,n),e===null)return{startCue:!1,finishedConvs:[],nextMap:a};let o=!1;if(t&&(i===void 0||i===t)){let n=e.get(t),r=a.get(t)??!1;n===!1&&r===!0&&(o=!0)}let s=[];for(let[n,i]of e.entries())if(i&&a.has(n)&&!a.get(n)){let e=r.find(e=>e.id===n);s.push({id:n,title:e?.title,isActive:n===t})}return{startCue:o,finishedConvs:s,nextMap:a}}var rS=(0,g.lazy)(()=>vc(()=>import(`./TerminalPanel-PIx1pMZ0.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([0,1,2,3,4])));function iS({notice:e,onDismiss:t}){let n=Z(),{locale:r}=Mn(),i=r!==`zh`&&e.textEn?e.textEn:e.text,[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(a)return;let n=setTimeout(()=>t(e.id),e.level===`error`?12e3:7e3);return()=>clearTimeout(n)},[a,e.id,e.level,t]);let s=e.level===`error`?wt:e.level===`warning`?Ct:Ae;return(0,X.jsxs)(`div`,{className:`notice notice-${e.level}${a?` paused`:``}`,role:`status`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,X.jsx)(s,{className:`notice-icon`}),(0,X.jsx)(`span`,{className:`notice-text`,children:i}),(0,X.jsx)(`button`,{type:`button`,className:`notice-close`,title:n(`close`),onClick:()=>t(e.id),children:(0,X.jsx)(N,{})})]})}var aS=[],oS=180,sS=520,cS=240,lS=e=>`pi-web-ui:${e}-panel-width`;function uS(e){try{let t=Number(localStorage.getItem(lS(e)));return Number.isFinite(t)&&t>=oS&&t<=sS?t:cS}catch{return cS}}var dS=e=>`pi-web-ui:${e}-panel-collapsed`;function fS(e){try{return localStorage.getItem(dS(e))===`1`}catch{return!1}}function pS({side:e,width:t,onResize:n}){let r=Z(),i=(0,g.useCallback)(r=>{r.preventDefault();let i=r.clientX,a=t,o=a,s=t=>{let r=e===`left`?t.clientX-i:i-t.clientX;o=Math.min(sS,Math.max(oS,Math.round(a+r))),n(o)},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),document.body.classList.remove(`panel-resizing`);try{localStorage.setItem(lS(e),String(o))}catch{}};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c),document.body.classList.add(`panel-resizing`)},[e,t,n]);return(0,X.jsx)(`div`,{className:`resize-handle resize-${e}`,title:r(`dragToResize`),onPointerDown:i,onDoubleClick:()=>n(cS)})}function mS({side:e,onClick:t}){let n=Z();return(0,X.jsx)(`button`,{type:`button`,className:`panel-rail panel-rail-${e}`,title:n(`expandPanel`),onClick:t,children:e===`left`?(0,X.jsx)(at,{}):(0,X.jsx)(ot,{})})}var hS=`pi-web-ui:plugin-path-grants`,gS=e=>e?`${hS}:${e}`:hS;function _S(e){if(e===null)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function vS(e){try{let t=gS(e);if(localStorage.getItem(t)!==null)return _S(localStorage.getItem(t));if(!e)return[];let n=_S(localStorage.getItem(hS));return localStorage.setItem(t,JSON.stringify(n)),n}catch{return[]}}function yS(e,t){try{let n=[...new Set([...vS(t),e])];localStorage.setItem(gS(t),JSON.stringify(n))}catch{}}function bS(){let e=Z(),{locale:t}=Mn(),{chat:n,send:r,dismissNotice:i,pushNotice:a,terminal:o}=Al(),s=(0,g.useRef)(!1);(0,g.useEffect)(()=>{n.ready&&n.settings&&(s.current||n.settings.quickPhrasesSeeded||(s.current=!0,n.settings.quickPhrases.length===0&&r({type:`set_settings`,quickPhrases:Ub[t]??Ub.en,quickPhrasesSeeded:!0})))},[n.ready,n.settings,r,t]);let c=n.state?.cwd??``,l=ub();(0,g.useEffect)(()=>{let t=l?rb(c):``;document.title=t?`${t} — pi-web-ui`:e(`docTitle`)},[c,l,e]);let[u,d]=(0,g.useState)([]);(0,g.useEffect)(()=>(ir(e=>d(t=>jg(t,e))),()=>ir(null)),[]);let[f,p]=(0,g.useState)(null),[m,h]=(0,g.useState)(null),_=(0,g.useRef)(!1),v=(0,g.useRef)(null);(0,g.useEffect)(()=>{_.current=f!==null,v.current=m},[f,m]);let y=(0,g.useCallback)((e,t)=>{let n=ty(t);if(n){p(null),h({file:{path:e,name:t},plugin:n.plugin,declaration:n.declaration});return}h(null),p({path:e,name:t})},[]);(0,g.useEffect)(()=>(Qd({open:e=>y(e.path,e.name),isOpen:()=>_.current||v.current!==null}),()=>Qd(null)),[y]);let[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let e=()=>x(!1);return window.addEventListener(`drop`,e,!0),()=>window.removeEventListener(`drop`,e,!0)},[]);let[S,C]=(0,g.useState)(`chat`),w=(e=>!n.tabs||e===`chat`||n.tabs.includes(e))(S.startsWith(`plugin:`)?`plugins`:S)?S:`chat`,T=(0,g.useMemo)(()=>n.plugins.filter(e=>!n.settings?.disabledPlugins?.includes(e.id)),[n.plugins,n.settings?.disabledPlugins]),E=(0,g.useMemo)(()=>{let r=[],i=Xi(zi(n.plugins),{locale:t,t:t=>e(t),disabledPlugins:n.settings?.disabledPlugins??[],layout:n.settings?.uiLayout,diagnostics:r});for(let e of r)console.warn(`[ui-slot] ${e.pluginId?`[${e.pluginId}] `:``}${e.message}`);return i},[n.plugins,n.settings?.disabledPlugins,n.settings?.uiLayout,t,e]),D=(0,g.useMemo)(()=>E[`topbar.primary`].filter(e=>!e.hidden),[E]),O=(0,g.useMemo)(()=>[...E[`topbar.primary`].filter(e=>e.hidden),...E[`topbar.overflow`]],[E]),k=(0,g.useMemo)(()=>E[`leftpanel.sessions`].filter(e=>!e.hidden),[E]),A=(0,g.useMemo)(()=>E[`leftpanel.projects.actions`].filter(e=>!e.hidden),[E]),j=(0,g.useMemo)(()=>E[`leftpanel.project`].filter(e=>!e.hidden),[E]),ee=(0,g.useMemo)(()=>E[`leftpanel.running.actions`].filter(e=>!e.hidden),[E]),M=(0,g.useMemo)(()=>E[`leftpanel.history.actions`].filter(e=>!e.hidden),[E]),te=E[`leftpanel.sections`],ne=(0,g.useMemo)(()=>E[`leftpanel.running`].filter(e=>!e.hidden),[E]),P=(0,g.useMemo)(()=>E[`leftpanel.history`].filter(e=>!e.hidden),[E]),F=(0,g.useMemo)(()=>E[`terminal.toolbar`].filter(e=>!e.hidden),[E]),re=(0,g.useMemo)(()=>E[`scm.toolbar`].filter(e=>!e.hidden),[E]),ie=(0,g.useMemo)(()=>E[`goalbar.actions`].filter(e=>!e.hidden),[E]),I=(0,g.useMemo)(()=>E[`chat.header`].filter(e=>!e.hidden),[E]),ae=(0,g.useMemo)(()=>E[`chat.empty`].filter(e=>!e.hidden),[E]),L=(0,g.useMemo)(()=>E[`file.preview.toolbar`].filter(e=>!e.hidden),[E]),R=(0,g.useMemo)(()=>Object.fromEntries((n.dshPresets?.presets??[]).map(n=>[n.id,O_(n,t,e).name])),[n.dshPresets,t]),z=(0,g.useMemo)(()=>E[`notice.actions`].filter(e=>!e.hidden),[E]),B=(0,g.useMemo)(()=>E[`sidebar.left`]??[],[E]),V=(0,g.useMemo)(()=>E[`sidebar.right`]??[],[E]),H=(0,g.useCallback)((t,n,i)=>{if(t.id===`host:msg-fork`){i?.id&&r({type:`fork_session`,messageId:i.id,position:`before`});return}if(t.id===`host:msg-rollback`){i?.id&&pm({messageId:i.id});return}let o=(t.action??``).trim();if(t.kind===`view`||(!o||o===`view`)&&t.source!==`host`){C(t.view??`plugin:${t.source.startsWith(`plugin:`)?t.source.slice(7):``}`);return}o&&Ls(t.source.startsWith(`plugin:`)?t.source.slice(7):``,o,t.id,{...n===void 0?{}:{value:n},...i===void 0?{}:{target:i},loadBundle:async e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),U=(0,g.useCallback)(e=>{let t=n.plugins.find(t=>t.id===e.source.slice(7));return t?(0,X.jsx)(gu,{plugin:t,epoch:n.pluginsEpoch,send:r,className:`lp-plugin-page`}):null},[n.plugins,n.pluginsEpoch,r]),W=(0,g.useCallback)((t,n)=>{n.action&&Ls(t.pluginId,n.action,n.id,{target:{id:n.id,kind:`plugin-running`,label:n.title},loadBundle:async e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),[oe,G]=(0,g.useState)([]);(0,g.useEffect)(()=>Nc(G),[]);let[se,ce]=(0,g.useState)([]);(0,g.useEffect)(()=>jc(ce),[]);let[K,le]=(0,g.useState)(null),ue=K?E[`modal.dialog`].find(e=>e.id===K&&!e.hidden):void 0,de=(0,g.useMemo)(()=>{if(!ue||ue.kind!==`view`)return``;let e=ue.view??``;return e.startsWith(`plugin:`)?e.slice(7):ue.source.startsWith(`plugin:`)?ue.source.slice(7):``},[ue]);(0,g.useEffect)(()=>{if(!ue||!de||oe.some(e=>e.info.id===de))return;let e=q.current.plugins.find(e=>e.id===de);e&&Bc(e,q.current.pluginsEpoch)},[ue,de,oe,n.pluginsEpoch]),(0,g.useEffect)(()=>{Od(r),kd(T,n.pluginsEpoch),Id(T,n.pluginsEpoch),ey(T,n.pluginsEpoch),Vc(T,n.pluginsEpoch)},[T,n.pluginsEpoch,r]);let q=(0,g.useRef)(n);q.current=n;let fe=(0,g.useRef)(C);fe.current=C;let pe=(0,g.useRef)(E);pe.current=E,(0,g.useEffect)(()=>(As(ks({send:r,isReady:()=>!!q.current.state,setView:e=>fe.current(e),getCwd:()=>q.current.state?.cwd??``,getWorkspaceRoots:()=>q.current.state?.workspaceRoots??[],listSessions:()=>{let e=q.current,t=e.state?.cwd??``;return[...e.conversations.map(e=>({id:e.id,title:e.title,cwd:e.cwd||t,kind:`running`,isStreaming:e.isStreaming})),...e.sessions.map(e=>({id:e.path,title:e.name||e.firstMessage||e.path,cwd:t,kind:`history`}))]},getConversationId:()=>q.current.state?.conversationId??null,isConversationBlank:()=>(q.current.state?.messages.length??0)===0,listModels:()=>q.current.models.map(e=>({id:e.id,provider:e.provider,name:e.name,vision:e.vision,reasoning:e.reasoning})),getCurrentModelId:()=>{let e=q.current.state?.model;return e?`${e.provider}/${e.id}`:null},listProjects:()=>q.current.projects.map(e=>e.path),grantedPaths:vS,grantPath:yS,confirm:e=>new Promise(t=>{if(Be.current){t(!1);return}let n={path:e.path,resolve:t};Be.current=n,ze(n)}),openModal:e=>{let t=String(e??``).trim();if(!t)return!1;let n=pe.current[`modal.dialog`].find(e=>e.id===t);return!n||n.hidden?!1:(le(t),!0)},closeModal:()=>le(null),dialogConfirm:e=>new Promise(t=>{if(Ue.current){t(!1);return}let n={kind:`confirm`,title:e.title,resolve:t};Ue.current=n,He(n)}),select:e=>new Promise(t=>{if(Ue.current){t({ok:!1,error:`busy`});return}let n={kind:`select`,title:e.title,options:e.options,...e.multi?{multi:!0}:{},resolve:t};Ue.current=n,Ge([]),He(n)}),input:e=>new Promise(t=>{if(Ue.current){t({ok:!1,error:`busy`});return}let n={kind:`input`,title:e.title,...typeof e.placeholder==`string`?{placeholder:e.placeholder}:{},...typeof e.initial==`string`?{initial:e.initial}:{},resolve:t};Ue.current=n,qe(e.initial??``),He(n)}),notifyAction:e=>new Promise(t=>{try{let n=Xe.current;Xe.current=null,Ye(null);try{n?.resolve(null)}catch{}let r={text:e.text,actions:e.actions,resolve:t};Xe.current=r,Ye(r)}catch{t(null)}}),loadPluginBundle:e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):Promise.resolve(!1)}})),()=>As(null)),[r]);let[me,Y]=(0,g.useState)(()=>uS(`left`)),[he,ge]=(0,g.useState)(()=>uS(`right`)),_e=(0,g.useCallback)(e=>Y(e),[]),ve=(0,g.useCallback)(e=>ge(e),[]),[ye,be]=(0,g.useState)(()=>fS(`left`)),[xe,Se]=(0,g.useState)(()=>fS(`right`)),Ce=(0,g.useCallback)(()=>{be(e=>{try{localStorage.setItem(dS(`left`),e?`0`:`1`)}catch{}return!e})},[]),we=(0,g.useCallback)(()=>{Se(e=>{try{localStorage.setItem(dS(`right`),e?`0`:`1`)}catch{}return!e})},[]),[Te,Ee]=(0,g.useState)(null),De=(0,g.useRef)(null),[Oe,ke]=(0,g.useState)(()=>window.matchMedia(`(max-width: 768px)`).matches);(0,g.useEffect)(()=>{let e=window.matchMedia(`(max-width: 768px)`),t=e=>ke(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),tS({enabled:Oe&&w===`chat`,open:Te,onOpenChange:Ee,container:De,backdropSelector:`.drawer-backdrop.persistent`});let[Ae,je]=(0,g.useState)(!1),[Me,Ne]=(0,g.useState)(!1),[Pe,Fe]=(0,g.useState)(!1),[Ie,Le]=(0,g.useState)(),[Re,ze]=(0,g.useState)(null),Be=(0,g.useRef)(null),[Ve,He]=(0,g.useState)(null),Ue=(0,g.useRef)(null),[We,Ge]=(0,g.useState)([]),[Ke,qe]=(0,g.useState)(``),[Je,Ye]=(0,g.useState)(null),Xe=(0,g.useRef)(null),[Ze,Qe]=(0,g.useState)(()=>new Set),$e=(e,t)=>{r({type:`plugin_path_response`,id:e,ok:t}),Qe(t=>new Set(t).add(e))},et=n.pathRequests.find(e=>!Ze.has(e.id))??null,[tt,nt]=(0,g.useState)(()=>new Set),rt=(e,t,n=!1)=>{r({type:`plugin_permission_response`,id:e,ok:t,...n?{remember:!0}:{}}),nt(t=>new Set(t).add(e))},it=n.permRequests.find(e=>!tt.has(e.id))??null,at=$y(),[ot,st]=(0,g.useState)(!1),[ct,lt]=(0,g.useState)(!1),[ut,dt]=(0,g.useState)(!1),[ft,pt]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!ft)return;let e=setTimeout(()=>pt(null),15e3);return()=>clearTimeout(e)},[ft]);let[mt,ht]=(0,g.useState)(null),gt=(0,g.useRef)(null),_t=(0,g.useRef)(null),vt=n.state?.sessionId??``,yt=(0,g.useRef)(vt);yt.current=vt;let bt=(0,g.useRef)(n.ready);bt.current=n.ready,(0,g.useEffect)(()=>{let e=()=>{let e=Ro(window.location.hash);if(e){if(e.messageId?ht({sessionId:e.sessionId,messageId:e.messageId}):ht(null),!bt.current||!yt.current){gt.current=e.sessionId;return}yt.current!==e.sessionId&&(_t.current=e.sessionId,C(`chat`),r({type:`switch_session`,path:``,sessionId:e.sessionId}))}};return e(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[r]),(0,g.useEffect)(()=>{let e=_t.current;if(e&&n.notices.some(t=>t.text.includes(e)&&(t.text.includes(`未找到会话`)||t.text.includes(`Session not found`)))&&(_t.current=null,ht(null),vt)){let e=zo({sessionId:vt});window.location.hash!==e&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${e}`)}},[n.notices,vt]),(0,g.useEffect)(()=>{if(!n.ready||!vt)return;if(gt.current){let e=gt.current;if(gt.current=null,e!==vt){_t.current=e,C(`chat`),r({type:`switch_session`,path:``,sessionId:e});return}}if(_t.current){if(vt===_t.current)_t.current=null;else return}let e=Ro(window.location.hash),t=e?.sessionId===vt?e.messageId:void 0,i=zo({sessionId:vt,...t?{messageId:t}:{}});window.location.hash!==i&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${i}`)},[n.ready,vt,r]),(0,g.useEffect)(()=>{let t=t=>{let i=t.detail,a=i?.title||e(`pluginCommandFallback`),s=i?.command;if(!s||!n.ready)return;let c={name:a,command:s,cwd:"${pwd}"},l=n.terminals.find(e=>e.title===a);if(l)o.restart(l.id),r({type:`run_command`,terminalId:l.id,conversationId:l.conversationId,command:c,cols:80,rows:24});else{let e=At();o.create({id:e,conversationId:n.activeConversationId||n.state?.conversationId||``,title:a,cwd:n.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:c})}C(`terminal`)};window.addEventListener(`pi-web-ui:plugin-run-command`,t);let i=e=>{let t=e.detail;typeof t==`string`&&t&&r({type:`switch_conversation`,id:t})};return window.addEventListener(`pi-web-ui:switch-conversation`,i),()=>{window.removeEventListener(`pi-web-ui:plugin-run-command`,t),window.removeEventListener(`pi-web-ui:switch-conversation`,i)}},[n,o,r]),(0,g.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),lt(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let[xt,St]=(0,g.useState)(Fy),[Ct,wt]=(0,g.useState)(Wt),{themes:Tt,theme:Et,switchTheme:Dt,reloadThemes:Ot}=qd();kb(),(0,g.useEffect)(()=>{try{typeof uc==`function`&&uc(Et??``)}catch{}},[Et]),(0,g.useEffect)(()=>{try{typeof dc==`function`&&dc(t)}catch{}},[t]),(0,g.useEffect)(()=>{try{typeof fc==`function`&&fc(w)}catch{}},[w]),(0,g.useEffect)(()=>{try{let e=n.state?.model,t=e?`${e.provider}/${e.id}`:null;typeof oc==`function`&&oc(t)}catch{}},[n.state?.model?.provider,n.state?.model?.id]),(0,g.useEffect)(()=>{if(!Ve)return;let e=e=>{if(e.key!==`Escape`)return;let t=Ue.current;Ue.current=null,He(null);try{if(!t)return;t.kind===`confirm`?t.resolve(!1):t.resolve({ok:!1})}catch{}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Ve]),(0,g.useEffect)(()=>{if(!Je)return;let e=setTimeout(()=>{let e=Xe.current;Xe.current=null,Ye(null);try{e?.resolve(null)}catch{}},8e3);return()=>clearTimeout(e)},[Je]);let kt=(0,g.useRef)(null),jt=(0,g.useRef)(null),Mt=(0,g.useRef)(n.state?.messages);Mt.current=n.state?.messages;let Nt=(0,g.useRef)(new Set),Pt=(0,g.useRef)(new Set),Ft=(0,g.useRef)(new Set),It=(0,g.useRef)(0),Lt=(0,g.useRef)(!1),Rt=(0,g.useRef)(n.terminals);(0,g.useEffect)(()=>{Iy(xt)},[xt]),(0,g.useEffect)(()=>{Gt(Ct)},[Ct]),(0,g.useEffect)(()=>{let e=Rt.current;Rt.current=n.terminals;for(let t of n.terminals){let n=t.command?.command??``;e.find(e=>e.id===t.id)?.running&&!t.running&&(n.startsWith(`pi remove `)?r({type:`extensions_reload`}):n.startsWith(`pi-web-ui install `)||n.startsWith(`pi-web-ui uninstall `)?r({type:`plugins_reload`}):n.startsWith(`npm i -g `)&&(r({type:`extensions_reload`}),r({type:`plugins_reload`}),r({type:`check_updates_all`,force:!0})))}},[n.terminals,r]),(0,g.useEffect)(()=>{let t=n.state?.conversationId??null,r=nS(kt.current,t,n.state?.isStreaming??!1,n.conversations,jt.current);if(kt.current=r.nextMap,jt.current=t,r.startCue&&Vy(`start`,xt),r.finishedConvs.length>0){Vy(`done`,xt);let t=r.finishedConvs.find(e=>e.isActive);if(t&&(ni(e(`notifyDoneTitle`),e(`notifyDoneBody`)),Ct.enabled&&!Ur(Xr()))){if(Ct.readReplies){let t=Yt(Mt.current);t?an(t,Ct):Ct.announce&&an(e(`ttsAnnounceDone`),Ct)}else Ct.announce&&an(e(`ttsAnnounceDone`),Ct)}for(let t of r.finishedConvs.filter(e=>!e.isActive)){let n=t.title?`${t.title}:${e(`notifyDoneBody`)}`:e(`notifyDoneBody`);ni(e(`notifyDoneTitle`),n)}!t&&Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceDone`),Ct)}},[n.state?.conversationId,n.state?.isStreaming,n.conversations,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.dialog?.id??null;if(t!==null&&!Nt.current.has(t)){if(Nt.current.add(t),Nt.current.size>64){let e=Nt.current.values().next().value;e!==void 0&&Nt.current.delete(e)}Vy(`question`,xt),ni(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceQuestion`),Ct)}},[n.dialog,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.question?.id??null,r=n.remoteQuestion?`${n.remoteQuestion.owner}:${n.remoteQuestion.id}`:null,i=!1;t!==null&&!Pt.current.has(t)&&(Pt.current.add(t),i=!0),r!==null&&!Pt.current.has(r)&&(Pt.current.add(r),i=!0);for(let e of n.conversations){if(!e.hasQuestion)continue;let n=e.questionId?`q:${e.questionId}`:`conv-q:${e.id}`;Pt.current.has(n)||(Pt.current.add(n),e.questionId&&Pt.current.add(e.questionId),t!==e.questionId&&(i=!0))}if(Pt.current.size>64){let e=Pt.current.values().next().value;e!==void 0&&Pt.current.delete(e)}i&&(Vy(`question`,xt),ni(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceQuestion`),Ct))},[n.question,n.remoteQuestion,n.conversations,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.approval,r=t?.id??null;if(r!==null&&!Ft.current.has(r)){if(Ft.current.add(r),Ft.current.size>64){let e=Ft.current.values().next().value;e!==void 0&&Ft.current.delete(e)}Vy(`approval`,xt);let n=typeof t?.toolName==`string`?t.toolName:``;ni(e(`notifyApprovalTitle`),n?e(`notifyApprovalBodyTool`,{tool:n}):e(`notifyApprovalBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceApproval`),Ct)}},[n.approval,xt,Ct,e]),(0,g.useEffect)(()=>{let t=[...n.notices].reverse().find(e=>e.level===`error`);t&&t.id!==It.current&&(It.current=t.id,Vy(`error`,xt),ni(e(`notifyErrorTitle`),e(`notifyErrorBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceError`),Ct))},[n.notices,xt,Ct,e]);let zt=(0,g.useRef)(new Set);(0,g.useEffect)(()=>{let e=n.state?.messages??[];for(let t of e){if(t.toolName!==`live_preview`||zt.current.has(t.id))continue;zt.current.add(t.id);let e=``;for(let n of t.content??[]){if(n.type!==`text`)continue;let t=/🔗 已自动在浏览器打开\]\((\/(?!\/)[^)\s]+)\)/.exec(n.text??``);if(t?.[1]){e=t[1];break}}if(!e)continue;let n=null;try{let t=new URL(dn(e),window.location.href);t.origin===window.location.origin&&document.hasFocus()&&(n=window.open(t.href,`_blank`,`noopener`))}catch{n=null}n||a(`info`,e)}},[n.state?.messages,a]);let Bt=(e,t,n,r=!1,i,a=!1)=>{let o=`${e}|${n}|${i?`${i.start}-${i.end}`:``}`;d(a=>a.some(e=>`${e.path}|${e.mode}|${e.lines?`${e.lines.start}-${e.lines.end}`:``}`===o)?a:[...a,{path:e,name:t,mode:n,isDir:r,...i?{lines:i}:{}}]);let s=n===`page`?t:e;!a&&s&&tr(`@${s} `)},Vt=e=>{let t=``;d(n=>n.filter(n=>{let r=n.key?n.key===e:n.mode===`conversation`?`conv|${n.conversationId??``}|${n.sessionPath??``}`===e:n.path===e;return r&&!t&&(t=n.mode===`page`||n.mode===`conversation`?n.name:n.path),!r})),t&&nr(`@${t}`)},Ht=(0,g.useCallback)(e=>(!e.type.startsWith(`list_`)&&!e.type.startsWith(`get_`)&&Ee(null),(e.type===`new_chat`||e.type===`switch_conversation`||e.type===`switch_session`)&&C(e=>e===`chat`?e:`chat`),r(e)),[r]),Ut=(0,g.useRef)(new Set),Kt=n.activeConversationId||n.state?.conversationId||``;(0,g.useEffect)(()=>{let t=n.conversations.filter(e=>e.hasQuestion),r=new Set(t.map(e=>e.id)),i=new Set(t.map(e=>e.questionId).filter(Boolean));for(let e of Ut.current)i.has(e)||Ut.current.delete(e);for(let n of t){let t=`question-${n.id}`;if(n.id===Kt){Rv(t,{silent:!0});continue}n.questionId&&Ut.current.has(n.questionId)||Lv({id:t,type:`question`,title:n.title||e(`chat`),message:n.questionTitle||e(`waitingQuestionBadge`),persistent:!0,dismissible:!0,data:{conversationId:n.id,questionId:n.questionId},onClose:()=>{n.questionId&&Ut.current.add(n.questionId)},onClick:()=>{Ht({type:`switch_conversation`,id:n.id}),Rv(t,{silent:!0})}})}zv(e=>{let t=e.data?.conversationId;return t?!r.has(t)||t===Kt:!1},{silent:!0})},[n.conversations,Kt,Ht,e]);let qt=(0,g.useRef)(0),Jt=(0,g.useRef)(0),Xt=(0,g.useCallback)(t=>{let r=Date.now();n.state?.model&&!n.state.model.vision&&r-Jt.current>1e4&&(Jt.current=r,a(`warning`,e(`imageNotSupported`)));let i=`paste-${++qt.current}`;d(e=>[...e,{path:``,key:i,name:t.name,imageData:t.data,mimeType:t.mimeType}])},[n.state?.model,a,e]),Zt=(0,g.useCallback)(async t=>{for(let n of t){let t=await Hp(n);if(!t){a(`error`,e(`imageLoadFailed`,{name:n.name}));continue}Xt(t)}},[Xt,a,e]),Qt=20971520,$t=(0,g.useRef)(0),en=(0,g.useCallback)(async t=>{if(t.size>Qt){a(`warning`,e(`fileTooLarge`,{name:t.name,size:Qt/1024/1024}));return}let n;try{n=(await new Promise((e,n)=>{let r=new FileReader;r.onload=()=>e(r.result),r.onerror=()=>n(r.error??Error(`read failed`)),r.readAsDataURL(t)})).replace(/^data:[^;]*;base64,/,``)}catch{a(`error`,e(`fileLoadFailed`,{name:t.name}));return}let r=`upload-${++$t.current}`;d(e=>[...e,{path:``,key:r,name:t.name,fileData:n,size:t.size,mimeType:t.type||void 0}])},[Qt,a,e]),tn=(0,g.useCallback)(async e=>{for(let t of e)Vp(t.type)?await Zt([t]):await en(t)},[Zt,en]),nn=(0,g.useCallback)((e,t,n)=>{r({type:`edit_message`,messageId:e,text:t,attachments:n})},[r]),rn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n})},[r]),[on,sn]=(0,g.useState)([]),cn=(0,g.useRef)(0),ln=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n}),cn.current+=1;let i=Vu(t),a={text:i.text,seq:cn.current};i.quotes.length&&d(e=>jg(e,i.quotes.map(e=>({path:``,name:``,mode:`quote`,quote:e,key:At()})))),sn(e=>[...e.slice(-9),a])},[r]),un=(0,g.useCallback)(()=>Ne(!0),[]),fn=(0,g.useCallback)(()=>d([]),[]);Yv(n.state?.sessionId??``,fn);let pn=(0,g.useCallback)(Vt,[]),mn=Zt,hn=tn,gn=(0,g.useCallback)((e,t)=>r({type:`search_files`,reqId:e,query:t}),[r]),_n=(0,g.useCallback)(e=>Bt(e.path,e.name,e.mode??`reference`,e.isDir??!1,e.lines,e.silent??!1),[]),vn=n.state?.model,yn=n.state?.thinkingLevel,bn=n.state?.availableThinkingLevels,xn=(0,g.useMemo)(()=>vn?{model:vn,thinkingLevel:yn??`off`,availableThinkingLevels:bn??[]}:null,[vn,yn,bn]),Sn=(0,g.useCallback)(()=>!n.ready||n.terminals.length!==0?!1:(o.create({id:At(),conversationId:n.activeConversationId||n.state?.conversationId||``,title:e(`terminalTitle`,{n:1}),cwd:n.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null}),!0),[n.ready,n.state?.cwd,n.terminals.length,e,o]);return(0,g.useEffect)(()=>{if(Lt.current){if(w!==`terminal`||n.terminals.length!==0){Lt.current=!1;return}Sn()&&(Lt.current=!1)}},[n.terminals.length,Sn,w]),(0,X.jsxs)(`div`,{className:`app`,"data-pi-anchor":`app`,onDragOver:e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),x(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||x(!1)},onDrop:t=>{if(x(!1),!Array.from(t.dataTransfer?.types??[]).includes(`Files`))return;t.preventDefault();let n=Array.from(t.dataTransfer?.files??[]);if(n.length===0){a(`warning`,e(`foldersNotSupported`));return}let r=n.filter(e=>Vp(e.type)),i=n.filter(e=>!Vp(e.type));r.length>0&&Zt(r),i.length>0&&tn(i)},children:[b&&(0,X.jsx)(`div`,{className:`app-drop-overlay`,"aria-hidden":!0,children:(0,X.jsxs)(`span`,{children:[`📎 `,e(`dropHereToAttach`)]})}),(0,X.jsx)(No,{chat:n,terminal:o,view:w,plugins:T,uiPrimary:D,uiOverflow:O,uiContextTopbar:E[`contextmenu.topbar`],onUiAction:H,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:()=>{Le(void 0),Fe(!0)},onManagePlugins:()=>{Le(`plugins`),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onOpenIconEdit:()=>dt(!0),sound:xt,onSoundChange:St,onSoundPreview:e=>Vy(e,xt),themes:Tt,theme:Et,onThemeChange:Dt,reloadThemes:Ot}),ut&&(0,X.jsx)(Jv,{slots:E,layout:n.settings?.uiLayout,exclude:ji,onClose:()=>dt(!1)}),n.protocolMismatch&&(0,X.jsxs)(`div`,{className:`protocol-banner`,children:[`⚠ `,e(`protocolMismatch`)]}),(0,X.jsxs)(`div`,{className:`notices`,children:[n.notices.map(e=>(0,X.jsx)(iS,{notice:e,onDismiss:i},e.id)),Je&&(0,X.jsxs)(`div`,{className:`notice notice-info`,role:`status`,children:[(0,X.jsx)(`span`,{className:`notice-text`,children:Je.text}),Je.actions.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let t=Xe.current;Xe.current=null,Ye(null);try{t?.resolve(e.id)}catch{}},children:e.label},e.id)),(0,X.jsx)(`button`,{type:`button`,className:`notice-close`,title:e(`close`),onClick:()=>{let e=Xe.current;Xe.current=null,Ye(null);try{e?.resolve(null)}catch{}},children:(0,X.jsx)(N,{})})]}),z.length>0&&(0,X.jsx)(`div`,{className:`notice-actions`,role:`toolbar`,children:z.map(e=>e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`btn btn-slot notice-select`,title:e.hint??e.label,"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>H(e,t.target.value),children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.id):(0,X.jsxs)(`button`,{type:`button`,className:`btn btn-slot`,title:e.hint??e.label,onClick:()=>H(e),children:[e.icon?`${e.icon} `:``,e.badge??e.label]},e.id))})]}),(0,X.jsx)(Oh,{currentModelId:vn?`${vn.provider}/${vn.id}`:null,children:(0,X.jsxs)(`div`,{ref:De,className:`layout`,style:{"--left-w":`${me}px`,"--right-w":`${he}px`},children:[Oe?(0,X.jsx)(`div`,{className:`drawer-backdrop persistent${Te?` on`:``}`,onClick:()=>Ee(null)}):Te&&(0,X.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>Ee(null)}),(0,X.jsx)(nv,{side:`left`,items:B,chat:n,view:w,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:e=>{Le(e),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onUiAction:H,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Dt(Et===`light`?null:`light`),onSoundToggle:()=>St({...xt,enabled:!xt.enabled})}),(0,X.jsxs)(`div`,{className:`view-pane ${w===`chat`?``:`hidden`}`,children:[!Oe&&ye&&(0,X.jsx)(mS,{side:`left`,onClick:Ce}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-left ${Te===`left`?`open`:``}${Oe?``:ye?` hidden`:``}`,children:(0,X.jsx)(ql,{collapsible:!Oe,onToggleCollapse:Ce,panelSend:Ht,active:!Oe||Te===`left`,sessionFile:n.state?.sessionFile??null,conversations:n.conversations,elsewhere:n.elsewhere,sessions:n.sessions,projects:n.projects,pathCompletions:n.pathCompletions,activeConversationId:n.activeConversationId,uiContextSession:E[`contextmenu.session`],uiLeftSessions:k,uiContextProject:E[`contextmenu.project`],uiProjectsActions:A,uiLeftProject:j,uiRunningActions:ee,uiHistoryActions:M,uiSections:te,renderPluginSectionBody:U,uiLeftRunning:ne,uiLeftHistory:P,uiPluginRunning:n.pluginPanelGroups,onPluginRunningAction:W,onUiAction:H,presetNames:R})}),!Oe&&(0,X.jsx)(pS,{side:`left`,width:me,onResize:_e}),(0,X.jsxs)(`main`,{className:at?`main wide-chat`:`main`,children:[I.length>0&&(0,X.jsx)(`div`,{className:`chat-header`,role:`toolbar`,children:Ph(I,H)}),n.state?(0,X.jsxs)(X.Fragment,{children:[n.state.isEphemeral&&(0,X.jsxs)(`div`,{className:`ephemeral-banner`,children:[(0,X.jsxs)(`span`,{children:[`🎭 `,e(`ephemeralBannerText`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`ephemeral-save`,onClick:()=>r({type:`persist_conversation`,id:Kt}),children:[`💾 `,e(`saveEphemeral`)]})]}),(0,X.jsx)(Eg,{uiMessageActions:E[`message.actions`],uiContextMessage:E[`contextmenu.message`],uiContextToolCall:E[`contextmenu.toolcall`],uiChatEmpty:ae,onUiAction:H,state:n.state,liveOutputs:n.liveOutputs,toolStatuses:n.toolStatuses,onEdit:nn,onKillBash:()=>r({type:`abort_bash`}),onRetry:()=>{if(r({type:`retry_last`})){let e=n.state?.model;e&&bh(`${e.provider}/${e.id}`)}},onRemoveQueued:rn,onRecallQueued:ln,thinkingWrap:n.settings?.thinkingWrap??!0,toolsWrap:n.settings?.toolsWrap??!0,toolImages:n.settings?.toolImagesEnabled??!0,keepRecent:n.settings?.keepRecentMessages,jumpTarget:ft,onJumpDone:()=>pt(null),urlJumpMessageId:mt&&mt.sessionId===n.state.sessionId?mt.messageId:null,onUrlJumpDone:()=>ht(null)},n.state.conversationId??`boot`)]}):(0,X.jsx)(`div`,{className:`boot-wait`,children:n.ready?e(`loadingSession`):e(`connectingServer`)}),n.settings?.goalModeEnabled!==!1&&(0,X.jsx)(`div`,{className:`goalbar-slot`,children:(0,X.jsx)(H_,{goal:n.goal,models:n.models,modelsLoading:n.modelsLoading,activeConversationId:n.activeConversationId,uiGoalbarActions:ie,onUiAction:H})}),(0,X.jsx)(Av,{onAction:(e,t,n)=>H(e,n,t)}),n.dialog&&(0,X.jsx)(rv,{dialog:n.dialog}),Ve&&(0,X.jsxs)(`div`,{className:`dialog-inline`,"data-dialog-kind":Ve.kind,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),Ve.title&&(0,X.jsx)(`span`,{className:`dialog-title`,children:Ve.title}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.kind===`confirm`?e.resolve(!1):e?.resolve({ok:!1})}catch{}},children:`✕`})]}),Ve.kind===`select`&&(0,X.jsxs)(`div`,{className:`dialog-options`,children:[(Ve.options??[]).map((e,t)=>{let n=Ve.multi?We.includes(t):!1;return(0,X.jsxs)(`button`,{type:`button`,className:`dialog-option ${n?`sel`:``}`,title:e.description,onClick:()=>{if(Ve.multi){Ge(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);return}let n=Ue.current;Ue.current=null,He(null);try{n?.resolve({ok:!0,selected:[e.label]})}catch{}},children:[e.label,e.description&&(0,X.jsx)(`span`,{className:`dialog-hint`,children:e.description})]},t)}),(Ve.options??[]).length===0&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:e(`noOptions`)}),Ve.multi&&(0,X.jsx)(`div`,{className:`dialog-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current,t=(e?.options??[]).filter((e,t)=>We.includes(t)).map(e=>e.label);Ue.current=null,He(null);try{e?.resolve({ok:!0,selected:t})}catch{}},children:e(`ok`)})})]}),Ve.kind===`confirm`&&(0,X.jsx)(`div`,{className:`dialog-body`,children:(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve(!1)}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve(!0)}catch{}},children:e(`ok`)})]})}),Ve.kind===`input`&&(0,X.jsxs)(`div`,{className:`dialog-body`,children:[(0,X.jsx)(`input`,{className:`dialog-input`,value:Ke,placeholder:Ve.placeholder||e(`inputPlaceholder`),autoFocus:!0,onChange:e=>qe(e.target.value),onKeyDown:e=>{if(e.key===`Enter`&&!e.nativeEvent.isComposing){let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!0,value:Ke})}catch{}}}}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!1})}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!0,value:Ke})}catch{}},children:e(`ok`)})]})]})]}),n.question&&(0,X.jsx)(pv,{question:n.question,conversationTitle:n.question.conversationTitle||n.conversations.find(e=>e.id===(n.question?.conversationId||Kt))?.title}),n.remoteQuestion&&(0,X.jsx)(pv,{question:n.remoteQuestion,owner:n.remoteQuestion.owner,conversationTitle:n.remoteQuestion.conversationTitle||n.conversations.find(e=>e.id===n.remoteQuestion?.convId)?.title}),(0,X.jsx)(bx,{plan:n.activeConversationId&&n.state?.conversationId!==n.activeConversationId?null:n.state?.plan}),(0,X.jsx)(V_,{composerLeading:E[`composer.leading`],composerActions:E[`composer.actions`],onUiAction:H,streaming:n.state?.isStreaming??!1,planMode:n.state?.planMode??!1,messages:n.state?.messages??aS,slashCommands:n.slashCommands,modelState:xn,models:n.models,modelsLoading:n.modelsLoading,providerKeys:n.providerKeys,defaultModel:n.engine===`pi`?n.defaultModel:void 0,attachments:u,onRemoveAttachment:pn,onAddImageFiles:mn,onAddLocalFiles:hn,onAddPathAttachment:_n,fileSearch:n.fileSearch,onSearchFiles:gn,onNotice:a,onManageModels:un,onSent:fn,quickPhrases:n.settings?.quickPhrases??[],quickPhrasesEnabled:n.settings?.quickPhrasesEnabled??!0,recallDrafts:on,dshPermCurrent:n.state?.permission??null,dshPermOptions:n.dshPermission?.options??void 0,dshPermDefault:n.dshPermission?.defaultPreset,dshPreset:n.state?.agentPreset??null,dshPresets:n.dshPresets?.presets??void 0,dshPresetDefault:n.dshPresets?.defaultPreset,dshBlank:(n.state?.messages?.length??0)===0,conversationId:n.activeConversationId||n.state?.conversationId||``,sessionDraft:n.engine===`pi`?n.state?.draft??null:null,sessionId:n.state?.sessionId??``})]}),!Oe&&(0,X.jsx)(pS,{side:`right`,width:he,onResize:ve}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-right ${Te===`right`?`open`:``}${Oe?``:xe?` hidden`:``}`,children:(0,X.jsx)(Ru,{collapsible:!Oe,onToggleCollapse:we,panelSend:Ht,files:n.files,fileChanged:n.fileChanged,widgets:n.widgets,onAttach:(e,t,n,r)=>{Ee(null),Bt(e,t,n,r)},onPreview:(e,t)=>{Ee(null),y(e,t)},onNotice:(e,t)=>a(e,t),uiRightPanelTabs:E[`rightpanel.tabs`],uiContextFile:E[`contextmenu.file`],plugins:T,pluginsEpoch:n.pluginsEpoch,send:r})}),!Oe&&xe&&(0,X.jsx)(mS,{side:`right`,onClick:we})]}),(0,X.jsx)(`div`,{className:`view-pane ${w===`terminal`?``:`hidden`}`,children:(0,X.jsx)(g.Suspense,{fallback:null,children:(0,X.jsx)(rS,{chat:n,terminal:o,uiTerminalToolbar:F,onUiAction:H})})}),(0,X.jsx)(`div`,{className:`view-pane ${w===`git`?``:`hidden`}`,children:(0,X.jsx)(Dv,{chat:n,terminal:o,active:w===`git`,onSwitchToTerminal:()=>C(`terminal`),uiScmToolbar:re,onUiAction:H})}),oe.map(e=>{let t=`plugin:${e.info.id}`;return(0,X.jsx)(`div`,{className:`view-pane ${w===t?``:`hidden`}`,children:(0,X.jsx)(Ov,{entry:e})},e.info.id)}),w.startsWith(`plugin:`)&&!oe.some(e=>`plugin:${e.info.id}`===w)&&(0,X.jsx)(kv,{pluginId:w.slice(7),info:n.plugins.find(e=>`plugin:${e.id}`===w),epoch:n.pluginsEpoch,failed:se.includes(w.slice(7))}),(0,X.jsx)(nv,{side:`right`,items:V,chat:n,view:w,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:e=>{Le(e),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onUiAction:H,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Dt(Et===`light`?null:`light`),onSoundToggle:()=>St({...xt,enabled:!xt.enabled})})]})}),(0,X.jsx)(W_,{chat:n,bottombarItems:E.bottombar,onUiAction:H,onOpenSettings:()=>{Le(void 0),Fe(!0)},onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenGlobalSearch:()=>lt(!0),onOpenBgTasks:()=>st(!0)}),f&&(0,X.jsx)(Rx,{file:f,content:n.fileContent,onAddLines:(e,t,n,r)=>Bt(e,t,`lines`,!1,{start:n,end:r}),onAttach:(e,t,n)=>Bt(e,t,n),onClose:()=>p(null),uiFilePreviewToolbar:L,onUiAction:H}),m&&(0,X.jsx)(Hx,{file:m.file,plugin:m.plugin,declaration:m.declaration,epoch:n.pluginsEpoch,send:r,onClose:()=>h(null),onFallback:()=>{h(null),p(m.file)}}),n.ready&&n.state&&n.state.piConfigured===!1&&!Ae&&!Me&&(0,X.jsx)(iy,{piConfigured:n.state.piConfigured,piAgentInstalled:n.state.piAgentInstalled,providers:n.providers,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,installResult:n.installResult,onClose:()=>je(!0)}),Me&&(0,X.jsx)(my,{providers:n.modelsConfig,providerStatus:n.providers,providerKeys:n.providerKeys,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,fetchModelsResult:n.fetchModelsResult,testModelConnectionResult:n.testModelConnectionResult,enrichModelsResult:n.enrichModelsResult,enrichModelsProgress:n.enrichModelsProgress,refreshBuiltinResult:n.refreshBuiltinResult,refreshProviderResult:n.refreshProviderResult,appendBuiltinResult:n.appendBuiltinResult,cloneProviderResult:n.cloneProviderResult,defaultModel:n.defaultModel,onClose:()=>Ne(!1)}),Pe&&(0,X.jsx)(px,{chat:n,terminal:o,initialSection:Ie,onSwitchToTerminal:()=>C(`terminal`),onClose:()=>Fe(!1),onOpenIconEdit:()=>dt(!0),sound:xt,onSoundChange:St,tts:Ct,onTtsChange:wt}),ot&&(0,X.jsx)(hx,{servers:n.bgServers,plugins:n.plugins,epoch:n.pluginsEpoch,send:r,onUiAction:H,autoCleanupMin:n.settings?.bgAutoCleanupMin??0,onClose:()=>st(!1)}),(0,X.jsx)(Ax,{}),(0,X.jsx)(gx,{}),(0,X.jsx)(_x,{approval:n.approval}),n.tuiOverlay&&(0,X.jsx)(vx,{overlay:n.tuiOverlay}),ue&&(0,X.jsx)(Ix,{entry:ue,pluginView:de?oe.find(e=>e.info.id===de):void 0,onUiAction:(e,t)=>{H(e,t),le(null)},onClose:()=>le(null)}),(0,X.jsx)(Fx,{open:ct,projects:n.projects,fileSearch:n.fileSearch,sessionSearch:n.sessionSearch,onClose:()=>lt(!1),onSwitchSession:(e,t)=>{r({type:`switch_session`,path:e});let n=t&&t[0];pt(n?{path:e,role:n.role,timestamp:n.timestamp}:null)},onSwitchProject:e=>{r({type:`set_cwd`,path:e})},onPreviewFile:(e,t)=>{y(e,t)}}),(it||et||Re)&&(0,X.jsxs)(`div`,{className:`modal-backdrop perm-modal-backdrop`,children:[it&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginPermTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>rt(it.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[it.family===`net`?e(`pluginPermBodyNet`).replace(`{plugin}`,it.pluginId).replace(`{hosts}`,(it.hosts??[]).join(`, `)):e(`pluginPermBodyLlm`).replace(`{plugin}`,it.pluginId).replace(`{models}`,(it.models??[]).length>0?` ${(it.models??[]).join(`, `)}`:``),it.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:it.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>rt(it.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>rt(it.id,!0),children:e(`pluginPermOnce`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>rt(it.id,!0,!0),children:e(`pluginPermAlways`)})]})]})]}),et&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginGrantRequestTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>$e(et.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginGrantRequestBody`).replace(`{plugin}`,et.pluginId).replace(`{path}`,et.path),et.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:et.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>$e(et.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>$e(et.id,!0),children:e(`pluginGrantAllow`)})]})]})]}),Re&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginSessionGrantTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{Be.current=null,Re.resolve(!1),ze(null)},children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginSessionGrantBody`).replace(`{path}`,Re.path),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{Be.current=null,Re.resolve(!1),ze(null)},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{Be.current=null,Re.resolve(!0),ze(null)},children:e(`ok`)})]})]})]})]}),!Pe&&Object.values(n.pluginJobs??{}).some(e=>e.phase!==`done`)&&(0,X.jsxs)(`div`,{className:`active-plugin-jobs-bar`,onClick:()=>{Le(`plugins`),Fe(!0)},title:e(`pluginJobRunning`),children:[(0,X.jsx)(J,{className:`spin`}),(0,X.jsxs)(`span`,{className:`active-plugin-jobs-title`,children:[e(`pluginJobRunning`),`:`,` `,Object.values(n.pluginJobs??{}).filter(e=>e.phase!==`done`).map(e=>e.pluginId).join(`, `)]}),(()=>{let e=Object.values(n.pluginJobs??{}).find(e=>e.phase!==`done`),t=e?.lines[e.lines.length-1];return t?(0,X.jsx)(`span`,{className:`active-plugin-jobs-line`,children:t}):null})()]}),(0,X.jsx)(Gv,{})]})}function xS(){typeof document<`u`&&(SS(CS()),TS())}function SS(e){!Number.isFinite(e)||e<0||document.documentElement.style.setProperty(`--msgs-gutter`,`${Math.round(e*100)/100}px`)}function CS(){let e=document.createElement(`div`);e.style.cssText=`position:fixed;top:-9999px;left:0;width:100px;height:100px;overflow-y:auto;scrollbar-gutter:stable both-edges;visibility:hidden;pointer-events:none;`,document.body.appendChild(e);let t=(e.offsetWidth-e.clientWidth)/2;return e.remove(),t}function wS(e){let t=document.createElement(`div`);t.style.cssText=`width:0;height:0;pointer-events:none;`,e.appendChild(t);let n=getComputedStyle(e),r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=Number.parseFloat(n.borderLeftWidth)||0,o=Number.parseFloat(n.paddingLeft)||0,s=i.left-(r.left+a+o);return t.remove(),s}function TS(){let e=()=>{let e=document.querySelector(`.messages`);return e?(SS(wS(e)),!0):!1},t=0;if(window.addEventListener(`resize`,()=>{t||=window.requestAnimationFrame(()=>{t=0,e()})}),e())return;let n=new MutationObserver(()=>{e()&&n.disconnect()});n.observe(document.documentElement,{childList:!0,subtree:!0}),window.setTimeout(()=>n.disconnect(),6e4)}pn(),Gd(Ud()),xS(),(0,ee.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(g.StrictMode,{children:(0,X.jsx)(jn,{children:(0,X.jsx)(bS,{})})})),`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{let e=ln();navigator.serviceWorker.register(`${e}sw.js`,{scope:e}).catch(e=>{console.warn(`Service worker registration failed:`,e)})});export{$ as a,At as c,pe as d,fe as f,N as g,L as h,Jd as i,Ge as l,z as m,Ph as n,Mn as o,J as p,Hd as r,Z as s,Ih as t,xe as u};
680
+ `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,Lx)},[c]),U=c?.lines??0,W=U>Lx,oe=(e,t)=>{if(t){let t=re.current>0?re.current:e;p({start:Math.min(t,e),end:Math.max(t,e)})}else re.current=e,p({start:e,end:e})},G=()=>{H.length!==0&&(re.current=1,p({start:1,end:H.length}))},se=()=>{f&&(n(e.path,e.name,f.start,f.end),v(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>v(!1),1400))},ce=c!==null&&c.kind===`text`&&!c.binary&&!c.truncated&&!Bx(e.name),K=()=>{B.current=!1,V.current&&clearTimeout(V.current),L(!1),z(!1),S(c?.text??``),b(!1),k.current&&(zx(e.name)&&w(!0),Vx(e.name)&&E(!0))},le=()=>{if(y){if(x!==(c?.text??``)&&!window.confirm(s(`discardFileChanges`)))return;K();return}ce&&c&&(k.current=zx(e.name)&&C||Vx(e.name)&&T,zx(e.name)&&w(!1),Vx(e.name)&&E(!1),p(null),S(c.text),b(!0))},ue=()=>{y&&c&&ce&&$({type:`write_file`,path:e.path,text:x})&&(B.current=!0,z(!1),L(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B.current=!1,L(!1),z(!0)},5e3))},q=()=>{(!y||x===(c?.text??``)||window.confirm(s(`discardFileChanges`)))&&i()},J=e=>{F(Math.min(200,Math.max(50,e)))},fe=f?f.end-f.start+1:0,pe=c?.binary??!1,me=c?.truncated??!1,Y=c?.kind??`text`,he=zx(e.name)||Bx(e.name),ge=Vx(e.name),_e=he&&C&&!y&&Y===`text`&&!pe,ye=ge&&T&&!y&&Y===`text`&&!pe,be={"host:fp-md":he&&Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${C?`on`:``}`,"data-tip":s(C?`showMarkdownSource`:`showMarkdownPreview`),disabled:y,onClick:()=>w(e=>!e),children:C?(0,X.jsx)(He,{}):(0,X.jsx)(tt,{})}):null,"host:fp-html":ge&&Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach html ${T?`on`:``}`,"data-tip":s(T?`showHtmlSource`:`showHtmlPreview`),disabled:y,onClick:()=>E(e=>!e),children:T?(0,X.jsx)(tt,{}):(0,X.jsx)(He,{})}):null,"host:fp-edit":Y===`text`&&!pe&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach edit ${y?`on`:``}`,"data-tip":s(me?`fileEditTruncated`:y?`exitEditFile`:`editFile`),disabled:!ce&&!y,onClick:le,children:(0,X.jsx)(We,{})}):null,"host:fp-wrap":Y===`text`&&!pe&&!_e&&!ye?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${A?`on`:``}`,"data-tip":s(A?`disableWrap`:`enableWrap`),onClick:()=>j(e=>!e),children:(0,X.jsx)($e,{})}):null,"host:fp-zoom":Y===`text`&&c?(0,X.jsxs)(`span`,{className:`fp-zoom`,children:[(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":s(`zoomOut`),disabled:P<=50,onClick:()=>J(P-10),children:(0,X.jsx)(M,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:s(`resetZoom`),onClick:()=>F(100),children:[P,`%`]}),(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":s(`zoomIn`),disabled:P>=200,onClick:()=>J(P+10),children:(0,X.jsx)(te,{})})]}):null,"host:fp-ref":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":s(`referenceTip`),onClick:()=>r(e.path,e.name,`reference`),children:(0,X.jsx)(De,{})}),"host:fp-full":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach full ${ee?`on`:``}`,"data-tip":s(ee?`exitFullscreen`:`fullscreen`),onClick:()=>ne(e=>!e),children:ee?(0,X.jsx)(ve,{}):(0,X.jsx)(Se,{})}),"host:fp-close":null},xe=a===void 0?[`host:fp-md`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):a.filter(e=>!e.hidden&&e.id!==`host:fp-close`),Ce=e=>hn(dn(`/api/file?clientId=${encodeURIComponent(hl())}&path=${encodeURIComponent(e)}`)),we=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return hn(dn(`${/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`}?clientId=${encodeURIComponent(hl())}${D?`&allowJs=1`:``}`))};return(0,X.jsx)(`div`,{className:`fp-overlay ${ee?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&q()},children:(0,X.jsxs)(`div`,{className:`fp ${ee?`fullscreen`:``}`,style:{"--fp-zoom":P/100},children:[(0,X.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&ne(e=>!e)},children:[(0,X.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,X.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,X.jsxs)(`span`,{className:`fp-meta`,children:[c&&Y===`text`&&!pe&&s(`fileLines`,{n:U}),c&&` · ${Jp(c.size)}`]}),(0,X.jsx)(`span`,{className:`fp-head-actions`,children:Ih(xe,be,o)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-close`,title:s(`close`),"aria-label":s(`close`),onClick:q,children:(0,X.jsx)(N,{})})]}),me&&Y===`text`&&!pe&&(0,X.jsx)(`div`,{className:`fp-notice`,children:Bx(e.name)?s(`previewLinesTruncated`,{n:H.length}):s(`previewTruncated`)}),u&&!c&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`loading`)}),!u&&Y===`none`&&!pe&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`previewNotSupported`)}),!u&&Y===`image`&&(0,X.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:q,title:s(`clickToCloseImage`),children:(0,X.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:Ce(e.path),alt:e.name,onClick:q,title:s(`clickToCloseImage`)})}),!u&&Y===`video`&&(0,X.jsx)(`div`,{className:`fp-media-wrap`,children:(0,X.jsx)(`video`,{className:`fp-media`,src:Ce(e.path),controls:!0,preload:`metadata`})}),!u&&ye&&c&&(0,X.jsxs)(`div`,{className:`fp-html`,children:[(0,X.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,X.jsx)(`span`,{className:`fp-html-hint`,title:s(D?`htmlJsOnTip`:`htmlJsOffTip`),children:s(D?`htmlJsOn`:`htmlJsOff`)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-html-js ${D?`on`:``}`,"data-tip":s(D?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>O(e=>!e),children:s(D?`htmlDisableJs`:`htmlEnableJs`)}),(0,X.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:we(e.path),target:`_blank`,rel:`noopener noreferrer`,title:s(`openInNewTab`),children:[(0,X.jsx)(Ue,{}),(0,X.jsx)(`span`,{children:s(`openInNewTab`)})]})]}),(0,X.jsx)(`iframe`,{className:`fp-html-frame`,src:we(e.path),title:e.name,sandbox:D?`allow-scripts`:``,referrerPolicy:`no-referrer`},D?`js`:`nojs`)]}),!u&&_e&&c&&(0,X.jsx)(`div`,{className:Bx(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,X.jsx)(`div`,{className:`fp-markdown-zoom`,children:(0,X.jsx)(sf,{text:c.text})})}),!u&&pe&&Y!==`image`&&Y!==`video`&&c&&(0,X.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,X.jsxs)(`div`,{className:`fp-notice`,children:[s(`binaryFile`),c.truncated&&s(`binaryHexTruncated`)]}),(0,X.jsx)(`pre`,{className:`fp-hex`,children:c.text})]}),!u&&y&&Y===`text`&&!pe&&c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`textarea`,{className:`fp-editor ${A?``:`no-wrap`}`,value:x,onChange:e=>S(e.target.value),wrap:A?`soft`:`off`,spellCheck:!1,autoFocus:!0}),R&&(0,X.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:s(`saveResultUnknown`)})]}),!u&&!_e&&!ye&&!y&&Y===`text`&&!pe&&c&&H.length===0&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`emptyFile`)}),!u&&!_e&&!ye&&!y&&Y===`text`&&!pe&&H.length>0&&(0,X.jsxs)(`div`,{className:`fp-code ${m?`dragging`:``} ${A?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[H.map((e,t)=>{let n=t+1,r=f!==null&&n>=f.start&&n<=f.end;return(0,X.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(oe(n,e.shiftKey),ie.current=!0,h(!0))},onMouseEnter:()=>{ie.current&&oe(n,!0)},children:[(0,X.jsx)(`span`,{className:`fp-num`,children:n}),(0,X.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),W&&(0,X.jsx)(`div`,{className:`fp-lines-note`,children:s(`previewLinesTruncated`,{n:Lx})})]}),(y||!_e&&!ye&&Y===`text`)&&(0,X.jsx)(`div`,{className:`fp-foot`,children:y?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:s(`editFile`)}),(0,X.jsxs)(`div`,{className:`fp-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:le,children:s(`cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:ae||x===(c?.text??``),onClick:ue,children:[(0,X.jsx)(de,{}),` `,s(`saveFile`)]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:f?s(`selectedRange`,{n:fe,start:f.start,end:f.end}):s(`selectLinesHint`)}),(0,X.jsxs)(`div`,{className:`fp-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:H.length===0,onClick:G,children:s(`selectAll`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:!f,onClick:()=>p(null),children:s(`clearSelection`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!f||pe,onClick:se,children:[_?(0,X.jsx)(dt,{}):null,s(_?`addedToChat`:`addToChat`)]})]})]})})]})})}function zx(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function Bx(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)}function Vx(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}function Hx({file:e,plugin:t,declaration:n,epoch:r,send:i,onClose:a,onFallback:o}){let s=Z(),c=(0,g.useRef)(null),[l,u]=(0,g.useState)(null),[d,f]=(0,g.useState)(!1),p=(0,g.useRef)(o);p.current=o;let m=n.label??t.name;return(0,g.useEffect)(()=>{let r=c.current;if(!r)return;let a=!1,o;return u(null),f(!1),(async()=>{try{let s=await ny({plugin:t,declaration:n});if(a)return;if(!s)throw Error(`插件没有提供可用的文件查看器`);let c=`/plugins-api/${encodeURIComponent(t.id)}`,l={...Hc(t.id,i),file:e,apiUrl:(e,t)=>{let n=String(e??``).startsWith(`/`)?String(e):`/${String(e??``)}`,r=new URLSearchParams;for(let[e,n]of Object.entries(t??{}))n!==void 0&&r.set(e,String(n));let i=r.toString();return hn(dn(`${c}${n}${i?`?${i}`:``}`))}};o=s.handler.mount(r,e,l),a||f(!0)}catch(e){a||(console.error(`[plugin:${t.id}] file handler failed:`,e),p.current())}})(),()=>{if(a=!0,typeof o==`function`)try{o()}catch(e){console.error(`[plugin:${t.id}] file handler cleanup failed:`,e)}r.textContent=``}},[e,t,n,r,i]),(0,X.jsx)(xy,{className:`plugin-file-preview`,title:m,icon:t.icon,onClose:a,children:(0,X.jsxs)(`div`,{className:`modal-body plugin-file-preview-body`,children:[(0,X.jsx)(`div`,{className:`plugin-file-preview-file`,title:e.path,children:e.name}),l?(0,X.jsx)(`div`,{className:`plugin-file-preview-error`,children:l}):null,!l&&!d?(0,X.jsx)(`div`,{children:s(`loading`)}):null,(0,X.jsx)(`div`,{ref:c,className:`plugin-file-preview-host`})]})})}var Ux=.4,Wx=1.05;function Gx(e){return Math.min(300,e*.86)}function Kx(e,t,n){return n||(t<=144?null:e<=72?`left`:t-e<=72?`right`:null)}function qx(e,t){let n=Math.abs(e),r=Math.abs(t);return n<12&&r<12?`none`:n>r*1.2?`horizontal`:`vertical`}function Jx(e,t){return e===`left`?t:-t}function Yx(e,t){return Math.max(-e,Math.min(0,-e+t))}function Xx(e,t,n){let r=n?e+t:t;return Math.max(0,Math.min(1,r/e))}function Zx(e){let{wasOpen:t,pull:n,width:r,durationMs:i}=e;return i<=320&&Math.abs(n)>=48?n>0:Xx(r*Wx,n,t)>=Ux}var Qx=new Set([`auto`,`scroll`,`overlay`]);function $x(e,t){let n=e instanceof Element?e:null;for(;n;){if(n instanceof HTMLElement&&n.scrollWidth>n.clientWidth+4&&Qx.has(getComputedStyle(n).overflowX))return!0;if(n===t)break;n=n.parentElement}return!1}function eS(){let e=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener(`click`,e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener(`click`,e,{capture:!0}),400)}function tS(e){let{enabled:t,open:n,onOpenChange:r,container:i}=e,{panelSelector:a,backdropSelector:o}=e;(0,g.useEffect)(()=>{let e=i.current;if(!t||!e)return;let s=null,c=`none`,l=0,u=0,d=0,f=0,p=!1,m=0,h=0,g=null,_=null,v=()=>{g&&(g.classList.remove(`drawer-dragging`),g.style.transform=``),_&&(_.style.opacity=``),s=null,c=`none`,g=null,_=null,f=0,p=!1},y=t=>{if(v(),t.touches.length!==1)return;let r=t.touches[0],i=Kx(r.clientX,window.innerWidth,n);i&&!$x(t.target,e)&&(s=i,l=r.clientX,u=r.clientY,d=Date.now())},b=t=>{let r=s;if(!r||t.touches.length!==1)return;let i=t.touches[0],d=i.clientX-l,v=i.clientY-u;if(c===`none`){let t=qx(d,v);if(t===`none`)return;if(t===`vertical`){s=null;return}c=`horizontal`,p=n===r,m=Gx(window.innerWidth),h=m*Wx;let i=e.querySelector(a?a(r):`.panel-drawer.drawer-${r}`);if(!i){s=null;return}g=i,_=o===null?null:e.querySelector(o??`.drawer-backdrop`),i.classList.add(`drawer-dragging`)}let y=g;if(!y)return;f=Jx(r,d);let b=Yx(h,f);y.style.transform=`translateX(${r===`left`?b:-b}px)`,_&&(_.style.opacity=String(Xx(h,f,p))),t.preventDefault()},x=()=>{let e=s,t=c===`horizontal`&&e!==null&&g!==null,i=f,a=Date.now()-d,o=t?Zx({wasOpen:p,pull:i,width:m,durationMs:a}):!1;v(),t&&e&&o!==(n===e)&&(eS(),r(o?e:null))},S=()=>v();return e.addEventListener(`touchstart`,y,{passive:!0}),e.addEventListener(`touchmove`,b,{passive:!1}),e.addEventListener(`touchend`,x),e.addEventListener(`touchcancel`,S),()=>{v(),e.removeEventListener(`touchstart`,y),e.removeEventListener(`touchmove`,b),e.removeEventListener(`touchend`,x),e.removeEventListener(`touchcancel`,S)}},[t,n,r,i,a,o])}function nS(e,t,n,r,i){let a=new Map;for(let e of r)a.set(e.id,!!e.isStreaming);if(t&&a.set(t,n),e===null)return{startCue:!1,finishedConvs:[],nextMap:a};let o=!1;if(t&&(i===void 0||i===t)){let n=e.get(t),r=a.get(t)??!1;n===!1&&r===!0&&(o=!0)}let s=[];for(let[n,i]of e.entries())if(i&&a.has(n)&&!a.get(n)){let e=r.find(e=>e.id===n);s.push({id:n,title:e?.title,isActive:n===t})}return{startCue:o,finishedConvs:s,nextMap:a}}var rS=(0,g.lazy)(()=>vc(()=>import(`./TerminalPanel-DQFDRz0A.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([0,1,2,3,4])));function iS({notice:e,onDismiss:t}){let n=Z(),{locale:r}=Mn(),i=r!==`zh`&&e.textEn?e.textEn:e.text,[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(a)return;let n=setTimeout(()=>t(e.id),e.level===`error`?12e3:7e3);return()=>clearTimeout(n)},[a,e.id,e.level,t]);let s=e.level===`error`?wt:e.level===`warning`?Ct:Ae;return(0,X.jsxs)(`div`,{className:`notice notice-${e.level}${a?` paused`:``}`,role:`status`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,X.jsx)(s,{className:`notice-icon`}),(0,X.jsx)(`span`,{className:`notice-text`,children:i}),(0,X.jsx)(`button`,{type:`button`,className:`notice-close`,title:n(`close`),onClick:()=>t(e.id),children:(0,X.jsx)(N,{})})]})}var aS=[],oS=180,sS=520,cS=240,lS=e=>`pi-web-ui:${e}-panel-width`;function uS(e){try{let t=Number(localStorage.getItem(lS(e)));return Number.isFinite(t)&&t>=oS&&t<=sS?t:cS}catch{return cS}}var dS=e=>`pi-web-ui:${e}-panel-collapsed`;function fS(e){try{return localStorage.getItem(dS(e))===`1`}catch{return!1}}function pS({side:e,width:t,onResize:n}){let r=Z(),i=(0,g.useCallback)(r=>{r.preventDefault();let i=r.clientX,a=t,o=a,s=t=>{let r=e===`left`?t.clientX-i:i-t.clientX;o=Math.min(sS,Math.max(oS,Math.round(a+r))),n(o)},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),document.body.classList.remove(`panel-resizing`);try{localStorage.setItem(lS(e),String(o))}catch{}};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c),document.body.classList.add(`panel-resizing`)},[e,t,n]);return(0,X.jsx)(`div`,{className:`resize-handle resize-${e}`,title:r(`dragToResize`),onPointerDown:i,onDoubleClick:()=>n(cS)})}function mS({side:e,onClick:t}){let n=Z();return(0,X.jsx)(`button`,{type:`button`,className:`panel-rail panel-rail-${e}`,title:n(`expandPanel`),onClick:t,children:e===`left`?(0,X.jsx)(at,{}):(0,X.jsx)(ot,{})})}var hS=`pi-web-ui:plugin-path-grants`,gS=e=>e?`${hS}:${e}`:hS;function _S(e){if(e===null)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function vS(e){try{let t=gS(e);if(localStorage.getItem(t)!==null)return _S(localStorage.getItem(t));if(!e)return[];let n=_S(localStorage.getItem(hS));return localStorage.setItem(t,JSON.stringify(n)),n}catch{return[]}}function yS(e,t){try{let n=[...new Set([...vS(t),e])];localStorage.setItem(gS(t),JSON.stringify(n))}catch{}}function bS(){let e=Z(),{locale:t}=Mn(),{chat:n,send:r,dismissNotice:i,pushNotice:a,terminal:o}=Al(),s=(0,g.useRef)(!1);(0,g.useEffect)(()=>{n.ready&&n.settings&&(s.current||n.settings.quickPhrasesSeeded||(s.current=!0,n.settings.quickPhrases.length===0&&r({type:`set_settings`,quickPhrases:Ub[t]??Ub.en,quickPhrasesSeeded:!0})))},[n.ready,n.settings,r,t]);let c=n.state?.cwd??``,l=ub();(0,g.useEffect)(()=>{let t=l?rb(c):``;document.title=t?`${t} — pi-web-ui`:e(`docTitle`)},[c,l,e]);let[u,d]=(0,g.useState)([]);(0,g.useEffect)(()=>(ir(e=>d(t=>jg(t,e))),()=>ir(null)),[]);let[f,p]=(0,g.useState)(null),[m,h]=(0,g.useState)(null),_=(0,g.useRef)(!1),v=(0,g.useRef)(null);(0,g.useEffect)(()=>{_.current=f!==null,v.current=m},[f,m]);let y=(0,g.useCallback)((e,t)=>{let n=ty(t);if(n){p(null),h({file:{path:e,name:t},plugin:n.plugin,declaration:n.declaration});return}h(null),p({path:e,name:t})},[]);(0,g.useEffect)(()=>(Qd({open:e=>y(e.path,e.name),isOpen:()=>_.current||v.current!==null}),()=>Qd(null)),[y]);let[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let e=()=>x(!1);return window.addEventListener(`drop`,e,!0),()=>window.removeEventListener(`drop`,e,!0)},[]);let[S,C]=(0,g.useState)(`chat`),w=(e=>!n.tabs||e===`chat`||n.tabs.includes(e))(S.startsWith(`plugin:`)?`plugins`:S)?S:`chat`,T=(0,g.useMemo)(()=>n.plugins.filter(e=>!n.settings?.disabledPlugins?.includes(e.id)),[n.plugins,n.settings?.disabledPlugins]),E=(0,g.useMemo)(()=>{let r=[],i=Xi(zi(n.plugins),{locale:t,t:t=>e(t),disabledPlugins:n.settings?.disabledPlugins??[],layout:n.settings?.uiLayout,diagnostics:r});for(let e of r)console.warn(`[ui-slot] ${e.pluginId?`[${e.pluginId}] `:``}${e.message}`);return i},[n.plugins,n.settings?.disabledPlugins,n.settings?.uiLayout,t,e]),D=(0,g.useMemo)(()=>E[`topbar.primary`].filter(e=>!e.hidden),[E]),O=(0,g.useMemo)(()=>[...E[`topbar.primary`].filter(e=>e.hidden),...E[`topbar.overflow`]],[E]),k=(0,g.useMemo)(()=>E[`leftpanel.sessions`].filter(e=>!e.hidden),[E]),A=(0,g.useMemo)(()=>E[`leftpanel.projects.actions`].filter(e=>!e.hidden),[E]),j=(0,g.useMemo)(()=>E[`leftpanel.project`].filter(e=>!e.hidden),[E]),ee=(0,g.useMemo)(()=>E[`leftpanel.running.actions`].filter(e=>!e.hidden),[E]),M=(0,g.useMemo)(()=>E[`leftpanel.history.actions`].filter(e=>!e.hidden),[E]),te=E[`leftpanel.sections`],ne=(0,g.useMemo)(()=>E[`leftpanel.running`].filter(e=>!e.hidden),[E]),P=(0,g.useMemo)(()=>E[`leftpanel.history`].filter(e=>!e.hidden),[E]),F=(0,g.useMemo)(()=>E[`terminal.toolbar`].filter(e=>!e.hidden),[E]),re=(0,g.useMemo)(()=>E[`scm.toolbar`].filter(e=>!e.hidden),[E]),ie=(0,g.useMemo)(()=>E[`goalbar.actions`].filter(e=>!e.hidden),[E]),I=(0,g.useMemo)(()=>E[`chat.header`].filter(e=>!e.hidden),[E]),ae=(0,g.useMemo)(()=>E[`chat.empty`].filter(e=>!e.hidden),[E]),L=(0,g.useMemo)(()=>E[`file.preview.toolbar`].filter(e=>!e.hidden),[E]),R=(0,g.useMemo)(()=>Object.fromEntries((n.dshPresets?.presets??[]).map(n=>[n.id,O_(n,t,e).name])),[n.dshPresets,t]),z=(0,g.useMemo)(()=>E[`notice.actions`].filter(e=>!e.hidden),[E]),B=(0,g.useMemo)(()=>E[`sidebar.left`]??[],[E]),V=(0,g.useMemo)(()=>E[`sidebar.right`]??[],[E]),H=(0,g.useCallback)((t,n,i)=>{if(t.id===`host:msg-fork`){i?.id&&r({type:`fork_session`,messageId:i.id,position:`before`});return}if(t.id===`host:msg-rollback`){i?.id&&pm({messageId:i.id});return}let o=(t.action??``).trim();if(t.kind===`view`||(!o||o===`view`)&&t.source!==`host`){C(t.view??`plugin:${t.source.startsWith(`plugin:`)?t.source.slice(7):``}`);return}o&&Ls(t.source.startsWith(`plugin:`)?t.source.slice(7):``,o,t.id,{...n===void 0?{}:{value:n},...i===void 0?{}:{target:i},loadBundle:async e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),U=(0,g.useCallback)(e=>{let t=n.plugins.find(t=>t.id===e.source.slice(7));return t?(0,X.jsx)(gu,{plugin:t,epoch:n.pluginsEpoch,send:r,className:`lp-plugin-page`}):null},[n.plugins,n.pluginsEpoch,r]),W=(0,g.useCallback)((t,n)=>{n.action&&Ls(t.pluginId,n.action,n.id,{target:{id:n.id,kind:`plugin-running`,label:n.title},loadBundle:async e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),[oe,G]=(0,g.useState)([]);(0,g.useEffect)(()=>Nc(G),[]);let[se,ce]=(0,g.useState)([]);(0,g.useEffect)(()=>jc(ce),[]);let[K,le]=(0,g.useState)(null),ue=K?E[`modal.dialog`].find(e=>e.id===K&&!e.hidden):void 0,de=(0,g.useMemo)(()=>{if(!ue||ue.kind!==`view`)return``;let e=ue.view??``;return e.startsWith(`plugin:`)?e.slice(7):ue.source.startsWith(`plugin:`)?ue.source.slice(7):``},[ue]);(0,g.useEffect)(()=>{if(!ue||!de||oe.some(e=>e.info.id===de))return;let e=q.current.plugins.find(e=>e.id===de);e&&Bc(e,q.current.pluginsEpoch)},[ue,de,oe,n.pluginsEpoch]),(0,g.useEffect)(()=>{Od(r),kd(T,n.pluginsEpoch),Id(T,n.pluginsEpoch),ey(T,n.pluginsEpoch),Vc(T,n.pluginsEpoch)},[T,n.pluginsEpoch,r]);let q=(0,g.useRef)(n);q.current=n;let fe=(0,g.useRef)(C);fe.current=C;let pe=(0,g.useRef)(E);pe.current=E,(0,g.useEffect)(()=>(As(ks({send:r,isReady:()=>!!q.current.state,setView:e=>fe.current(e),getCwd:()=>q.current.state?.cwd??``,getWorkspaceRoots:()=>q.current.state?.workspaceRoots??[],listSessions:()=>{let e=q.current,t=e.state?.cwd??``;return[...e.conversations.map(e=>({id:e.id,title:e.title,cwd:e.cwd||t,kind:`running`,isStreaming:e.isStreaming})),...e.sessions.map(e=>({id:e.path,title:e.name||e.firstMessage||e.path,cwd:t,kind:`history`}))]},getConversationId:()=>q.current.state?.conversationId??null,isConversationBlank:()=>(q.current.state?.messages.length??0)===0,listModels:()=>q.current.models.map(e=>({id:e.id,provider:e.provider,name:e.name,vision:e.vision,reasoning:e.reasoning})),getCurrentModelId:()=>{let e=q.current.state?.model;return e?`${e.provider}/${e.id}`:null},listProjects:()=>q.current.projects.map(e=>e.path),grantedPaths:vS,grantPath:yS,confirm:e=>new Promise(t=>{if(Be.current){t(!1);return}let n={path:e.path,resolve:t};Be.current=n,ze(n)}),openModal:e=>{let t=String(e??``).trim();if(!t)return!1;let n=pe.current[`modal.dialog`].find(e=>e.id===t);return!n||n.hidden?!1:(le(t),!0)},closeModal:()=>le(null),dialogConfirm:e=>new Promise(t=>{if(Ue.current){t(!1);return}let n={kind:`confirm`,title:e.title,resolve:t};Ue.current=n,He(n)}),select:e=>new Promise(t=>{if(Ue.current){t({ok:!1,error:`busy`});return}let n={kind:`select`,title:e.title,options:e.options,...e.multi?{multi:!0}:{},resolve:t};Ue.current=n,Ge([]),He(n)}),input:e=>new Promise(t=>{if(Ue.current){t({ok:!1,error:`busy`});return}let n={kind:`input`,title:e.title,...typeof e.placeholder==`string`?{placeholder:e.placeholder}:{},...typeof e.initial==`string`?{initial:e.initial}:{},resolve:t};Ue.current=n,qe(e.initial??``),He(n)}),notifyAction:e=>new Promise(t=>{try{let n=Xe.current;Xe.current=null,Ye(null);try{n?.resolve(null)}catch{}let r={text:e.text,actions:e.actions,resolve:t};Xe.current=r,Ye(r)}catch{t(null)}}),loadPluginBundle:e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Bc(t,q.current.pluginsEpoch):Promise.resolve(!1)}})),()=>As(null)),[r]);let[me,Y]=(0,g.useState)(()=>uS(`left`)),[he,ge]=(0,g.useState)(()=>uS(`right`)),_e=(0,g.useCallback)(e=>Y(e),[]),ve=(0,g.useCallback)(e=>ge(e),[]),[ye,be]=(0,g.useState)(()=>fS(`left`)),[xe,Se]=(0,g.useState)(()=>fS(`right`)),Ce=(0,g.useCallback)(()=>{be(e=>{try{localStorage.setItem(dS(`left`),e?`0`:`1`)}catch{}return!e})},[]),we=(0,g.useCallback)(()=>{Se(e=>{try{localStorage.setItem(dS(`right`),e?`0`:`1`)}catch{}return!e})},[]),[Te,Ee]=(0,g.useState)(null),De=(0,g.useRef)(null),[Oe,ke]=(0,g.useState)(()=>window.matchMedia(`(max-width: 768px)`).matches);(0,g.useEffect)(()=>{let e=window.matchMedia(`(max-width: 768px)`),t=e=>ke(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),tS({enabled:Oe&&w===`chat`,open:Te,onOpenChange:Ee,container:De,backdropSelector:`.drawer-backdrop.persistent`});let[Ae,je]=(0,g.useState)(!1),[Me,Ne]=(0,g.useState)(!1),[Pe,Fe]=(0,g.useState)(!1),[Ie,Le]=(0,g.useState)(),[Re,ze]=(0,g.useState)(null),Be=(0,g.useRef)(null),[Ve,He]=(0,g.useState)(null),Ue=(0,g.useRef)(null),[We,Ge]=(0,g.useState)([]),[Ke,qe]=(0,g.useState)(``),[Je,Ye]=(0,g.useState)(null),Xe=(0,g.useRef)(null),[Ze,Qe]=(0,g.useState)(()=>new Set),$e=(e,t)=>{r({type:`plugin_path_response`,id:e,ok:t}),Qe(t=>new Set(t).add(e))},et=n.pathRequests.find(e=>!Ze.has(e.id))??null,[tt,nt]=(0,g.useState)(()=>new Set),rt=(e,t,n=!1)=>{r({type:`plugin_permission_response`,id:e,ok:t,...n?{remember:!0}:{}}),nt(t=>new Set(t).add(e))},it=n.permRequests.find(e=>!tt.has(e.id))??null,at=$y(),[ot,st]=(0,g.useState)(!1),[ct,lt]=(0,g.useState)(!1),[ut,dt]=(0,g.useState)(!1),[ft,pt]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!ft)return;let e=setTimeout(()=>pt(null),15e3);return()=>clearTimeout(e)},[ft]);let[mt,ht]=(0,g.useState)(null),gt=(0,g.useRef)(null),_t=(0,g.useRef)(null),vt=n.state?.sessionId??``,yt=(0,g.useRef)(vt);yt.current=vt;let bt=(0,g.useRef)(n.ready);bt.current=n.ready,(0,g.useEffect)(()=>{let e=()=>{let e=Ro(window.location.hash);if(e){if(e.messageId?ht({sessionId:e.sessionId,messageId:e.messageId}):ht(null),!bt.current||!yt.current){gt.current=e.sessionId;return}yt.current!==e.sessionId&&(_t.current=e.sessionId,C(`chat`),r({type:`switch_session`,path:``,sessionId:e.sessionId}))}};return e(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[r]),(0,g.useEffect)(()=>{let e=_t.current;if(e&&n.notices.some(t=>t.text.includes(e)&&(t.text.includes(`未找到会话`)||t.text.includes(`Session not found`)))&&(_t.current=null,ht(null),vt)){let e=zo({sessionId:vt});window.location.hash!==e&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${e}`)}},[n.notices,vt]),(0,g.useEffect)(()=>{if(!n.ready||!vt)return;if(gt.current){let e=gt.current;if(gt.current=null,e!==vt){_t.current=e,C(`chat`),r({type:`switch_session`,path:``,sessionId:e});return}}if(_t.current){if(vt===_t.current)_t.current=null;else return}let e=Ro(window.location.hash),t=e?.sessionId===vt?e.messageId:void 0,i=zo({sessionId:vt,...t?{messageId:t}:{}});window.location.hash!==i&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${i}`)},[n.ready,vt,r]),(0,g.useEffect)(()=>{let t=t=>{let i=t.detail,a=i?.title||e(`pluginCommandFallback`),s=i?.command;if(!s||!n.ready)return;let c={name:a,command:s,cwd:"${pwd}"},l=n.terminals.find(e=>e.title===a);if(l)o.restart(l.id),r({type:`run_command`,terminalId:l.id,conversationId:l.conversationId,command:c,cols:80,rows:24});else{let e=At();o.create({id:e,conversationId:n.activeConversationId||n.state?.conversationId||``,title:a,cwd:n.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:c})}C(`terminal`)};window.addEventListener(`pi-web-ui:plugin-run-command`,t);let i=e=>{let t=e.detail;typeof t==`string`&&t&&r({type:`switch_conversation`,id:t})};return window.addEventListener(`pi-web-ui:switch-conversation`,i),()=>{window.removeEventListener(`pi-web-ui:plugin-run-command`,t),window.removeEventListener(`pi-web-ui:switch-conversation`,i)}},[n,o,r]),(0,g.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),lt(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let[xt,St]=(0,g.useState)(Fy),[Ct,wt]=(0,g.useState)(Wt),{themes:Tt,theme:Et,switchTheme:Dt,reloadThemes:Ot}=qd();kb(),(0,g.useEffect)(()=>{try{typeof uc==`function`&&uc(Et??``)}catch{}},[Et]),(0,g.useEffect)(()=>{try{typeof dc==`function`&&dc(t)}catch{}},[t]),(0,g.useEffect)(()=>{try{typeof fc==`function`&&fc(w)}catch{}},[w]),(0,g.useEffect)(()=>{try{let e=n.state?.model,t=e?`${e.provider}/${e.id}`:null;typeof oc==`function`&&oc(t)}catch{}},[n.state?.model?.provider,n.state?.model?.id]),(0,g.useEffect)(()=>{if(!Ve)return;let e=e=>{if(e.key!==`Escape`)return;let t=Ue.current;Ue.current=null,He(null);try{if(!t)return;t.kind===`confirm`?t.resolve(!1):t.resolve({ok:!1})}catch{}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Ve]),(0,g.useEffect)(()=>{if(!Je)return;let e=setTimeout(()=>{let e=Xe.current;Xe.current=null,Ye(null);try{e?.resolve(null)}catch{}},8e3);return()=>clearTimeout(e)},[Je]);let kt=(0,g.useRef)(null),jt=(0,g.useRef)(null),Mt=(0,g.useRef)(n.state?.messages);Mt.current=n.state?.messages;let Nt=(0,g.useRef)(new Set),Pt=(0,g.useRef)(new Set),Ft=(0,g.useRef)(new Set),It=(0,g.useRef)(0),Lt=(0,g.useRef)(!1),Rt=(0,g.useRef)(n.terminals);(0,g.useEffect)(()=>{Iy(xt)},[xt]),(0,g.useEffect)(()=>{Gt(Ct)},[Ct]),(0,g.useEffect)(()=>{let e=Rt.current;Rt.current=n.terminals;for(let t of n.terminals){let n=t.command?.command??``;e.find(e=>e.id===t.id)?.running&&!t.running&&(n.startsWith(`pi remove `)?r({type:`extensions_reload`}):n.startsWith(`pi-web-ui install `)||n.startsWith(`pi-web-ui uninstall `)?r({type:`plugins_reload`}):n.startsWith(`npm i -g `)&&(r({type:`extensions_reload`}),r({type:`plugins_reload`}),r({type:`check_updates_all`,force:!0})))}},[n.terminals,r]),(0,g.useEffect)(()=>{let t=n.state?.conversationId??null,r=nS(kt.current,t,n.state?.isStreaming??!1,n.conversations,jt.current);if(kt.current=r.nextMap,jt.current=t,r.startCue&&Vy(`start`,xt),r.finishedConvs.length>0){Vy(`done`,xt);let t=r.finishedConvs.find(e=>e.isActive);if(t&&(ni(e(`notifyDoneTitle`),e(`notifyDoneBody`)),Ct.enabled&&!Ur(Xr()))){if(Ct.readReplies){let t=Yt(Mt.current);t?an(t,Ct):Ct.announce&&an(e(`ttsAnnounceDone`),Ct)}else Ct.announce&&an(e(`ttsAnnounceDone`),Ct)}for(let t of r.finishedConvs.filter(e=>!e.isActive)){let n=t.title?`${t.title}:${e(`notifyDoneBody`)}`:e(`notifyDoneBody`);ni(e(`notifyDoneTitle`),n)}!t&&Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceDone`),Ct)}},[n.state?.conversationId,n.state?.isStreaming,n.conversations,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.dialog?.id??null;if(t!==null&&!Nt.current.has(t)){if(Nt.current.add(t),Nt.current.size>64){let e=Nt.current.values().next().value;e!==void 0&&Nt.current.delete(e)}Vy(`question`,xt),ni(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceQuestion`),Ct)}},[n.dialog,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.question?.id??null,r=n.remoteQuestion?`${n.remoteQuestion.owner}:${n.remoteQuestion.id}`:null,i=!1;t!==null&&!Pt.current.has(t)&&(Pt.current.add(t),i=!0),r!==null&&!Pt.current.has(r)&&(Pt.current.add(r),i=!0);for(let e of n.conversations){if(!e.hasQuestion)continue;let n=e.questionId?`q:${e.questionId}`:`conv-q:${e.id}`;Pt.current.has(n)||(Pt.current.add(n),e.questionId&&Pt.current.add(e.questionId),t!==e.questionId&&(i=!0))}if(Pt.current.size>64){let e=Pt.current.values().next().value;e!==void 0&&Pt.current.delete(e)}i&&(Vy(`question`,xt),ni(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceQuestion`),Ct))},[n.question,n.remoteQuestion,n.conversations,xt,Ct,e]),(0,g.useEffect)(()=>{let t=n.approval,r=t?.id??null;if(r!==null&&!Ft.current.has(r)){if(Ft.current.add(r),Ft.current.size>64){let e=Ft.current.values().next().value;e!==void 0&&Ft.current.delete(e)}Vy(`approval`,xt);let n=typeof t?.toolName==`string`?t.toolName:``;ni(e(`notifyApprovalTitle`),n?e(`notifyApprovalBodyTool`,{tool:n}):e(`notifyApprovalBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceApproval`),Ct)}},[n.approval,xt,Ct,e]),(0,g.useEffect)(()=>{let t=[...n.notices].reverse().find(e=>e.level===`error`);t&&t.id!==It.current&&(It.current=t.id,Vy(`error`,xt),ni(e(`notifyErrorTitle`),e(`notifyErrorBody`)),Ct.enabled&&Ct.announce&&!Ur(Xr())&&an(e(`ttsAnnounceError`),Ct))},[n.notices,xt,Ct,e]);let zt=(0,g.useRef)(new Set);(0,g.useEffect)(()=>{let e=n.state?.messages??[];for(let t of e){if(t.toolName!==`live_preview`||zt.current.has(t.id))continue;zt.current.add(t.id);let e=``;for(let n of t.content??[]){if(n.type!==`text`)continue;let t=/🔗 已自动在浏览器打开\]\((\/(?!\/)[^)\s]+)\)/.exec(n.text??``);if(t?.[1]){e=t[1];break}}if(!e)continue;let n=null;try{let t=new URL(dn(e),window.location.href);t.origin===window.location.origin&&document.hasFocus()&&(n=window.open(t.href,`_blank`,`noopener`))}catch{n=null}n||a(`info`,e)}},[n.state?.messages,a]);let Bt=(e,t,n,r=!1,i,a=!1)=>{let o=`${e}|${n}|${i?`${i.start}-${i.end}`:``}`;d(a=>a.some(e=>`${e.path}|${e.mode}|${e.lines?`${e.lines.start}-${e.lines.end}`:``}`===o)?a:[...a,{path:e,name:t,mode:n,isDir:r,...i?{lines:i}:{}}]);let s=n===`page`?t:e;!a&&s&&tr(`@${s} `)},Vt=e=>{let t=``;d(n=>n.filter(n=>{let r=n.key?n.key===e:n.mode===`conversation`?`conv|${n.conversationId??``}|${n.sessionPath??``}`===e:n.path===e;return r&&!t&&(t=n.mode===`page`||n.mode===`conversation`?n.name:n.path),!r})),t&&nr(`@${t}`)},Ht=(0,g.useCallback)(e=>(!e.type.startsWith(`list_`)&&!e.type.startsWith(`get_`)&&Ee(null),(e.type===`new_chat`||e.type===`switch_conversation`||e.type===`switch_session`)&&C(e=>e===`chat`?e:`chat`),r(e)),[r]),Ut=(0,g.useRef)(new Set),Kt=n.activeConversationId||n.state?.conversationId||``;(0,g.useEffect)(()=>{let t=n.conversations.filter(e=>e.hasQuestion),r=new Set(t.map(e=>e.id)),i=new Set(t.map(e=>e.questionId).filter(Boolean));for(let e of Ut.current)i.has(e)||Ut.current.delete(e);for(let n of t){let t=`question-${n.id}`;if(n.id===Kt){Rv(t,{silent:!0});continue}n.questionId&&Ut.current.has(n.questionId)||Lv({id:t,type:`question`,title:n.title||e(`chat`),message:n.questionTitle||e(`waitingQuestionBadge`),persistent:!0,dismissible:!0,data:{conversationId:n.id,questionId:n.questionId},onClose:()=>{n.questionId&&Ut.current.add(n.questionId)},onClick:()=>{Ht({type:`switch_conversation`,id:n.id}),Rv(t,{silent:!0})}})}zv(e=>{let t=e.data?.conversationId;return t?!r.has(t)||t===Kt:!1},{silent:!0})},[n.conversations,Kt,Ht,e]);let qt=(0,g.useRef)(0),Jt=(0,g.useRef)(0),Xt=(0,g.useCallback)(t=>{let r=Date.now();n.state?.model&&!n.state.model.vision&&r-Jt.current>1e4&&(Jt.current=r,a(`warning`,e(`imageNotSupported`)));let i=`paste-${++qt.current}`;d(e=>[...e,{path:``,key:i,name:t.name,imageData:t.data,mimeType:t.mimeType}])},[n.state?.model,a,e]),Zt=(0,g.useCallback)(async t=>{for(let n of t){let t=await Hp(n);if(!t){a(`error`,e(`imageLoadFailed`,{name:n.name}));continue}Xt(t)}},[Xt,a,e]),Qt=20971520,$t=(0,g.useRef)(0),en=(0,g.useCallback)(async t=>{if(t.size>Qt){a(`warning`,e(`fileTooLarge`,{name:t.name,size:Qt/1024/1024}));return}let n;try{n=(await new Promise((e,n)=>{let r=new FileReader;r.onload=()=>e(r.result),r.onerror=()=>n(r.error??Error(`read failed`)),r.readAsDataURL(t)})).replace(/^data:[^;]*;base64,/,``)}catch{a(`error`,e(`fileLoadFailed`,{name:t.name}));return}let r=`upload-${++$t.current}`;d(e=>[...e,{path:``,key:r,name:t.name,fileData:n,size:t.size,mimeType:t.type||void 0}])},[Qt,a,e]),tn=(0,g.useCallback)(async e=>{for(let t of e)Vp(t.type)?await Zt([t]):await en(t)},[Zt,en]),nn=(0,g.useCallback)((e,t,n)=>{r({type:`edit_message`,messageId:e,text:t,attachments:n})},[r]),rn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n})},[r]),[on,sn]=(0,g.useState)([]),cn=(0,g.useRef)(0),ln=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n}),cn.current+=1;let i=Vu(t),a={text:i.text,seq:cn.current};i.quotes.length&&d(e=>jg(e,i.quotes.map(e=>({path:``,name:``,mode:`quote`,quote:e,key:At()})))),sn(e=>[...e.slice(-9),a])},[r]),un=(0,g.useCallback)(()=>Ne(!0),[]),fn=(0,g.useCallback)(()=>d([]),[]);Yv(n.state?.sessionId??``,fn);let pn=(0,g.useCallback)(Vt,[]),mn=Zt,hn=tn,gn=(0,g.useCallback)((e,t)=>r({type:`search_files`,reqId:e,query:t}),[r]),_n=(0,g.useCallback)(e=>Bt(e.path,e.name,e.mode??`reference`,e.isDir??!1,e.lines,e.silent??!1),[]),vn=n.state?.model,yn=n.state?.thinkingLevel,bn=n.state?.availableThinkingLevels,xn=(0,g.useMemo)(()=>vn?{model:vn,thinkingLevel:yn??`off`,availableThinkingLevels:bn??[]}:null,[vn,yn,bn]),Sn=(0,g.useCallback)(()=>!n.ready||n.terminals.length!==0?!1:(o.create({id:At(),conversationId:n.activeConversationId||n.state?.conversationId||``,title:e(`terminalTitle`,{n:1}),cwd:n.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null}),!0),[n.ready,n.state?.cwd,n.terminals.length,e,o]);return(0,g.useEffect)(()=>{if(Lt.current){if(w!==`terminal`||n.terminals.length!==0){Lt.current=!1;return}Sn()&&(Lt.current=!1)}},[n.terminals.length,Sn,w]),(0,X.jsxs)(`div`,{className:`app`,"data-pi-anchor":`app`,onDragOver:e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),x(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||x(!1)},onDrop:t=>{if(x(!1),!Array.from(t.dataTransfer?.types??[]).includes(`Files`))return;t.preventDefault();let n=Array.from(t.dataTransfer?.files??[]);if(n.length===0){a(`warning`,e(`foldersNotSupported`));return}let r=n.filter(e=>Vp(e.type)),i=n.filter(e=>!Vp(e.type));r.length>0&&Zt(r),i.length>0&&tn(i)},children:[b&&(0,X.jsx)(`div`,{className:`app-drop-overlay`,"aria-hidden":!0,children:(0,X.jsxs)(`span`,{children:[`📎 `,e(`dropHereToAttach`)]})}),(0,X.jsx)(No,{chat:n,terminal:o,view:w,plugins:T,uiPrimary:D,uiOverflow:O,uiContextTopbar:E[`contextmenu.topbar`],onUiAction:H,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:()=>{Le(void 0),Fe(!0)},onManagePlugins:()=>{Le(`plugins`),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onOpenIconEdit:()=>dt(!0),sound:xt,onSoundChange:St,onSoundPreview:e=>Vy(e,xt),themes:Tt,theme:Et,onThemeChange:Dt,reloadThemes:Ot}),ut&&(0,X.jsx)(Jv,{slots:E,layout:n.settings?.uiLayout,exclude:ji,onClose:()=>dt(!1)}),n.protocolMismatch&&(0,X.jsxs)(`div`,{className:`protocol-banner`,children:[`⚠ `,e(`protocolMismatch`)]}),(0,X.jsxs)(`div`,{className:`notices`,children:[n.notices.map(e=>(0,X.jsx)(iS,{notice:e,onDismiss:i},e.id)),Je&&(0,X.jsxs)(`div`,{className:`notice notice-info`,role:`status`,children:[(0,X.jsx)(`span`,{className:`notice-text`,children:Je.text}),Je.actions.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let t=Xe.current;Xe.current=null,Ye(null);try{t?.resolve(e.id)}catch{}},children:e.label},e.id)),(0,X.jsx)(`button`,{type:`button`,className:`notice-close`,title:e(`close`),onClick:()=>{let e=Xe.current;Xe.current=null,Ye(null);try{e?.resolve(null)}catch{}},children:(0,X.jsx)(N,{})})]}),z.length>0&&(0,X.jsx)(`div`,{className:`notice-actions`,role:`toolbar`,children:z.map(e=>e.kind===`select`&&e.options?.length?(0,X.jsx)(`select`,{className:`btn btn-slot notice-select`,title:e.hint??e.label,"aria-label":e.label,value:e.options.some(t=>t.value===e.value)?e.value:e.options[0].value,onChange:t=>H(e,t.target.value),children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.id):(0,X.jsxs)(`button`,{type:`button`,className:`btn btn-slot`,title:e.hint??e.label,onClick:()=>H(e),children:[e.icon?`${e.icon} `:``,e.badge??e.label]},e.id))})]}),(0,X.jsx)(Oh,{currentModelId:vn?`${vn.provider}/${vn.id}`:null,children:(0,X.jsxs)(`div`,{ref:De,className:`layout`,style:{"--left-w":`${me}px`,"--right-w":`${he}px`},children:[Oe?(0,X.jsx)(`div`,{className:`drawer-backdrop persistent${Te?` on`:``}`,onClick:()=>Ee(null)}):Te&&(0,X.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>Ee(null)}),(0,X.jsx)(nv,{side:`left`,items:B,chat:n,view:w,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:e=>{Le(e),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onUiAction:H,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Dt(Et===`light`?null:`light`),onSoundToggle:()=>St({...xt,enabled:!xt.enabled})}),(0,X.jsxs)(`div`,{className:`view-pane ${w===`chat`?``:`hidden`}`,children:[!Oe&&ye&&(0,X.jsx)(mS,{side:`left`,onClick:Ce}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-left ${Te===`left`?`open`:``}${Oe?``:ye?` hidden`:``}`,children:(0,X.jsx)(ql,{collapsible:!Oe,onToggleCollapse:Ce,panelSend:Ht,active:!Oe||Te===`left`,sessionFile:n.state?.sessionFile??null,conversations:n.conversations,elsewhere:n.elsewhere,sessions:n.sessions,projects:n.projects,pathCompletions:n.pathCompletions,activeConversationId:n.activeConversationId,uiContextSession:E[`contextmenu.session`],uiLeftSessions:k,uiContextProject:E[`contextmenu.project`],uiProjectsActions:A,uiLeftProject:j,uiRunningActions:ee,uiHistoryActions:M,uiSections:te,renderPluginSectionBody:U,uiLeftRunning:ne,uiLeftHistory:P,uiPluginRunning:n.pluginPanelGroups,onPluginRunningAction:W,onUiAction:H,presetNames:R})}),!Oe&&(0,X.jsx)(pS,{side:`left`,width:me,onResize:_e}),(0,X.jsxs)(`main`,{className:at?`main wide-chat`:`main`,children:[I.length>0&&(0,X.jsx)(`div`,{className:`chat-header`,role:`toolbar`,children:Ph(I,H)}),n.state?(0,X.jsxs)(X.Fragment,{children:[n.state.isEphemeral&&(0,X.jsxs)(`div`,{className:`ephemeral-banner`,children:[(0,X.jsxs)(`span`,{children:[`🎭 `,e(`ephemeralBannerText`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`ephemeral-save`,onClick:()=>r({type:`persist_conversation`,id:Kt}),children:[`💾 `,e(`saveEphemeral`)]})]}),(0,X.jsx)(Eg,{uiMessageActions:E[`message.actions`],uiContextMessage:E[`contextmenu.message`],uiContextToolCall:E[`contextmenu.toolcall`],uiChatEmpty:ae,onUiAction:H,state:n.state,liveOutputs:n.liveOutputs,toolStatuses:n.toolStatuses,onEdit:nn,onKillBash:()=>r({type:`abort_bash`}),onRetry:()=>{if(r({type:`retry_last`})){let e=n.state?.model;e&&bh(`${e.provider}/${e.id}`)}},onRemoveQueued:rn,onRecallQueued:ln,thinkingWrap:n.settings?.thinkingWrap??!0,toolsWrap:n.settings?.toolsWrap??!0,toolImages:n.settings?.toolImagesEnabled??!0,keepRecent:n.settings?.keepRecentMessages,jumpTarget:ft,onJumpDone:()=>pt(null),urlJumpMessageId:mt&&mt.sessionId===n.state.sessionId?mt.messageId:null,onUrlJumpDone:()=>ht(null)},n.state.conversationId??`boot`)]}):(0,X.jsx)(`div`,{className:`boot-wait`,children:n.ready?e(`loadingSession`):e(`connectingServer`)}),n.settings?.goalModeEnabled!==!1&&(0,X.jsx)(`div`,{className:`goalbar-slot`,children:(0,X.jsx)(H_,{goal:n.goal,models:n.models,modelsLoading:n.modelsLoading,activeConversationId:n.activeConversationId,uiGoalbarActions:ie,onUiAction:H})}),(0,X.jsx)(Av,{onAction:(e,t,n)=>H(e,n,t)}),n.dialog&&(0,X.jsx)(rv,{dialog:n.dialog}),Ve&&(0,X.jsxs)(`div`,{className:`dialog-inline`,"data-dialog-kind":Ve.kind,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),Ve.title&&(0,X.jsx)(`span`,{className:`dialog-title`,children:Ve.title}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.kind===`confirm`?e.resolve(!1):e?.resolve({ok:!1})}catch{}},children:`✕`})]}),Ve.kind===`select`&&(0,X.jsxs)(`div`,{className:`dialog-options`,children:[(Ve.options??[]).map((e,t)=>{let n=Ve.multi?We.includes(t):!1;return(0,X.jsxs)(`button`,{type:`button`,className:`dialog-option ${n?`sel`:``}`,title:e.description,onClick:()=>{if(Ve.multi){Ge(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);return}let n=Ue.current;Ue.current=null,He(null);try{n?.resolve({ok:!0,selected:[e.label]})}catch{}},children:[e.label,e.description&&(0,X.jsx)(`span`,{className:`dialog-hint`,children:e.description})]},t)}),(Ve.options??[]).length===0&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:e(`noOptions`)}),Ve.multi&&(0,X.jsx)(`div`,{className:`dialog-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current,t=(e?.options??[]).filter((e,t)=>We.includes(t)).map(e=>e.label);Ue.current=null,He(null);try{e?.resolve({ok:!0,selected:t})}catch{}},children:e(`ok`)})})]}),Ve.kind===`confirm`&&(0,X.jsx)(`div`,{className:`dialog-body`,children:(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve(!1)}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve(!0)}catch{}},children:e(`ok`)})]})}),Ve.kind===`input`&&(0,X.jsxs)(`div`,{className:`dialog-body`,children:[(0,X.jsx)(`input`,{className:`dialog-input`,value:Ke,placeholder:Ve.placeholder||e(`inputPlaceholder`),autoFocus:!0,onChange:e=>qe(e.target.value),onKeyDown:e=>{if(e.key===`Enter`&&!e.nativeEvent.isComposing){let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!0,value:Ke})}catch{}}}}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!1})}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ue.current;Ue.current=null,He(null);try{e?.resolve({ok:!0,value:Ke})}catch{}},children:e(`ok`)})]})]})]}),n.question&&(0,X.jsx)(pv,{question:n.question,conversationTitle:n.question.conversationTitle||n.conversations.find(e=>e.id===(n.question?.conversationId||Kt))?.title}),n.remoteQuestion&&(0,X.jsx)(pv,{question:n.remoteQuestion,owner:n.remoteQuestion.owner,conversationTitle:n.remoteQuestion.conversationTitle||n.conversations.find(e=>e.id===n.remoteQuestion?.convId)?.title}),(0,X.jsx)(bx,{plan:n.activeConversationId&&n.state?.conversationId!==n.activeConversationId?null:n.state?.plan}),(0,X.jsx)(V_,{composerLeading:E[`composer.leading`],composerActions:E[`composer.actions`],onUiAction:H,streaming:n.state?.isStreaming??!1,planMode:n.state?.planMode??!1,messages:n.state?.messages??aS,slashCommands:n.slashCommands,modelState:xn,models:n.models,modelsLoading:n.modelsLoading,providerKeys:n.providerKeys,defaultModel:n.engine===`pi`?n.defaultModel:void 0,attachments:u,onRemoveAttachment:pn,onAddImageFiles:mn,onAddLocalFiles:hn,onAddPathAttachment:_n,fileSearch:n.fileSearch,onSearchFiles:gn,onNotice:a,onManageModels:un,onSent:fn,quickPhrases:n.settings?.quickPhrases??[],quickPhrasesEnabled:n.settings?.quickPhrasesEnabled??!0,recallDrafts:on,dshPermCurrent:n.state?.permission??null,dshPermOptions:n.dshPermission?.options??void 0,dshPermDefault:n.dshPermission?.defaultPreset,dshPreset:n.state?.agentPreset??null,dshPresets:n.dshPresets?.presets??void 0,dshPresetDefault:n.dshPresets?.defaultPreset,dshBlank:(n.state?.messages?.length??0)===0,conversationId:n.activeConversationId||n.state?.conversationId||``,sessionDraft:n.engine===`pi`?n.state?.draft??null:null,sessionId:n.state?.sessionId??``})]}),!Oe&&(0,X.jsx)(pS,{side:`right`,width:he,onResize:ve}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-right ${Te===`right`?`open`:``}${Oe?``:xe?` hidden`:``}`,children:(0,X.jsx)(Ru,{collapsible:!Oe,onToggleCollapse:we,panelSend:Ht,files:n.files,fileChanged:n.fileChanged,widgets:n.widgets,onAttach:(e,t,n,r)=>{Ee(null),Bt(e,t,n,r)},onPreview:(e,t)=>{Ee(null),y(e,t)},onNotice:(e,t)=>a(e,t),uiRightPanelTabs:E[`rightpanel.tabs`],uiContextFile:E[`contextmenu.file`],plugins:T,pluginsEpoch:n.pluginsEpoch,send:r})}),!Oe&&xe&&(0,X.jsx)(mS,{side:`right`,onClick:we})]}),(0,X.jsx)(`div`,{className:`view-pane ${w===`terminal`?``:`hidden`}`,children:(0,X.jsx)(g.Suspense,{fallback:null,children:(0,X.jsx)(rS,{chat:n,terminal:o,uiTerminalToolbar:F,onUiAction:H})})}),(0,X.jsx)(`div`,{className:`view-pane ${w===`git`?``:`hidden`}`,children:(0,X.jsx)(Dv,{chat:n,terminal:o,active:w===`git`,onSwitchToTerminal:()=>C(`terminal`),uiScmToolbar:re,onUiAction:H})}),oe.map(e=>{let t=`plugin:${e.info.id}`;return(0,X.jsx)(`div`,{className:`view-pane ${w===t?``:`hidden`}`,children:(0,X.jsx)(Ov,{entry:e})},e.info.id)}),w.startsWith(`plugin:`)&&!oe.some(e=>`plugin:${e.info.id}`===w)&&(0,X.jsx)(kv,{pluginId:w.slice(7),info:n.plugins.find(e=>`plugin:${e.id}`===w),epoch:n.pluginsEpoch,failed:se.includes(w.slice(7))}),(0,X.jsx)(nv,{side:`right`,items:V,chat:n,view:w,onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenPanel:Ee,onOpenSettings:e=>{Le(e),Fe(!0)},onOpenBgTasks:()=>st(!0),onOpenGlobalSearch:()=>lt(!0),onUiAction:H,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Dt(Et===`light`?null:`light`),onSoundToggle:()=>St({...xt,enabled:!xt.enabled})})]})}),(0,X.jsx)(W_,{chat:n,bottombarItems:E.bottombar,onUiAction:H,onOpenSettings:()=>{Le(void 0),Fe(!0)},onViewChange:e=>{Lt.current=e===`terminal`&&n.terminals.length===0,Lt.current&&Sn()&&(Lt.current=!1),C(e),Ee(null)},onOpenGlobalSearch:()=>lt(!0),onOpenBgTasks:()=>st(!0)}),f&&(0,X.jsx)(Rx,{file:f,content:n.fileContent,onAddLines:(e,t,n,r)=>Bt(e,t,`lines`,!1,{start:n,end:r}),onAttach:(e,t,n)=>Bt(e,t,n),onClose:()=>p(null),uiFilePreviewToolbar:L,onUiAction:H}),m&&(0,X.jsx)(Hx,{file:m.file,plugin:m.plugin,declaration:m.declaration,epoch:n.pluginsEpoch,send:r,onClose:()=>h(null),onFallback:()=>{h(null),p(m.file)}}),n.ready&&n.state&&n.state.piConfigured===!1&&!Ae&&!Me&&(0,X.jsx)(iy,{piConfigured:n.state.piConfigured,piAgentInstalled:n.state.piAgentInstalled,providers:n.providers,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,installResult:n.installResult,onClose:()=>je(!0)}),Me&&(0,X.jsx)(my,{providers:n.modelsConfig,providerStatus:n.providers,providerKeys:n.providerKeys,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,fetchModelsResult:n.fetchModelsResult,testModelConnectionResult:n.testModelConnectionResult,enrichModelsResult:n.enrichModelsResult,enrichModelsProgress:n.enrichModelsProgress,refreshBuiltinResult:n.refreshBuiltinResult,refreshProviderResult:n.refreshProviderResult,appendBuiltinResult:n.appendBuiltinResult,cloneProviderResult:n.cloneProviderResult,defaultModel:n.defaultModel,onClose:()=>Ne(!1)}),Pe&&(0,X.jsx)(px,{chat:n,terminal:o,initialSection:Ie,onSwitchToTerminal:()=>C(`terminal`),onClose:()=>Fe(!1),onOpenIconEdit:()=>dt(!0),sound:xt,onSoundChange:St,tts:Ct,onTtsChange:wt}),ot&&(0,X.jsx)(hx,{servers:n.bgServers,plugins:n.plugins,epoch:n.pluginsEpoch,send:r,onUiAction:H,autoCleanupMin:n.settings?.bgAutoCleanupMin??0,onClose:()=>st(!1)}),(0,X.jsx)(Ax,{}),(0,X.jsx)(gx,{}),(0,X.jsx)(_x,{approval:n.approval}),n.tuiOverlay&&(0,X.jsx)(vx,{overlay:n.tuiOverlay}),ue&&(0,X.jsx)(Ix,{entry:ue,pluginView:de?oe.find(e=>e.info.id===de):void 0,onUiAction:(e,t)=>{H(e,t),le(null)},onClose:()=>le(null)}),(0,X.jsx)(Fx,{open:ct,projects:n.projects,fileSearch:n.fileSearch,sessionSearch:n.sessionSearch,onClose:()=>lt(!1),onSwitchSession:(e,t)=>{r({type:`switch_session`,path:e});let n=t&&t[0];pt(n?{path:e,role:n.role,timestamp:n.timestamp}:null)},onSwitchProject:e=>{r({type:`set_cwd`,path:e})},onPreviewFile:(e,t)=>{y(e,t)}}),(it||et||Re)&&(0,X.jsxs)(`div`,{className:`modal-backdrop perm-modal-backdrop`,children:[it&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginPermTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>rt(it.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[it.family===`net`?e(`pluginPermBodyNet`).replace(`{plugin}`,it.pluginId).replace(`{hosts}`,(it.hosts??[]).join(`, `)):e(`pluginPermBodyLlm`).replace(`{plugin}`,it.pluginId).replace(`{models}`,(it.models??[]).length>0?` ${(it.models??[]).join(`, `)}`:``),it.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:it.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>rt(it.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>rt(it.id,!0),children:e(`pluginPermOnce`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>rt(it.id,!0,!0),children:e(`pluginPermAlways`)})]})]})]}),et&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginGrantRequestTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>$e(et.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginGrantRequestBody`).replace(`{plugin}`,et.pluginId).replace(`{path}`,et.path),et.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:et.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>$e(et.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>$e(et.id,!0),children:e(`pluginGrantAllow`)})]})]})]}),Re&&(0,X.jsxs)(`div`,{className:`dialog-inline perm-dialog-card`,"data-dialog-kind":`confirm`,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),(0,X.jsx)(`span`,{className:`dialog-title`,children:e(`pluginSessionGrantTitle`)}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{Be.current=null,Re.resolve(!1),ze(null)},children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginSessionGrantBody`).replace(`{path}`,Re.path),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{Be.current=null,Re.resolve(!1),ze(null)},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{Be.current=null,Re.resolve(!0),ze(null)},children:e(`ok`)})]})]})]})]}),!Pe&&Object.values(n.pluginJobs??{}).some(e=>e.phase!==`done`)&&(0,X.jsxs)(`div`,{className:`active-plugin-jobs-bar`,onClick:()=>{Le(`plugins`),Fe(!0)},title:e(`pluginJobRunning`),children:[(0,X.jsx)(J,{className:`spin`}),(0,X.jsxs)(`span`,{className:`active-plugin-jobs-title`,children:[e(`pluginJobRunning`),`:`,` `,Object.values(n.pluginJobs??{}).filter(e=>e.phase!==`done`).map(e=>e.pluginId).join(`, `)]}),(()=>{let e=Object.values(n.pluginJobs??{}).find(e=>e.phase!==`done`),t=e?.lines[e.lines.length-1];return t?(0,X.jsx)(`span`,{className:`active-plugin-jobs-line`,children:t}):null})()]}),(0,X.jsx)(Gv,{})]})}function xS(){typeof document<`u`&&(SS(CS()),TS())}function SS(e){!Number.isFinite(e)||e<0||document.documentElement.style.setProperty(`--msgs-gutter`,`${Math.round(e*100)/100}px`)}function CS(){let e=document.createElement(`div`);e.style.cssText=`position:fixed;top:-9999px;left:0;width:100px;height:100px;overflow-y:auto;scrollbar-gutter:stable both-edges;visibility:hidden;pointer-events:none;`,document.body.appendChild(e);let t=(e.offsetWidth-e.clientWidth)/2;return e.remove(),t}function wS(e){let t=document.createElement(`div`);t.style.cssText=`width:0;height:0;pointer-events:none;`,e.appendChild(t);let n=getComputedStyle(e),r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=Number.parseFloat(n.borderLeftWidth)||0,o=Number.parseFloat(n.paddingLeft)||0,s=i.left-(r.left+a+o);return t.remove(),s}function TS(){let e=()=>{let e=document.querySelector(`.messages`);return e?(SS(wS(e)),!0):!1},t=0;if(window.addEventListener(`resize`,()=>{t||=window.requestAnimationFrame(()=>{t=0,e()})}),e())return;let n=new MutationObserver(()=>{e()&&n.disconnect()});n.observe(document.documentElement,{childList:!0,subtree:!0}),window.setTimeout(()=>n.disconnect(),6e4)}pn(),Gd(Ud()),xS(),(0,ee.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(g.StrictMode,{children:(0,X.jsx)(jn,{children:(0,X.jsx)(bS,{})})})),`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{let e=ln();navigator.serviceWorker.register(`${e}sw.js`,{scope:e}).catch(e=>{console.warn(`Service worker registration failed:`,e)})});export{$ as a,At as c,pe as d,fe as f,N as g,L as h,Jd as i,Ge as l,z as m,Ph as n,Mn as o,J as p,Hd as r,Z as s,Ih as t,xe as u};