pi-web-ui 0.105.0 → 0.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/server/client-state.js +10 -2
- package/package.json +1 -1
- package/web/dist/assets/{TerminalPanel-B9exeXrl.js → TerminalPanel-Mk4laCAL.js} +1 -1
- package/web/dist/assets/{index-D79IKG33.js → index-BDLVjBeK.js} +3 -3
- package/web/dist/index.html +1 -1
- package/web/dist/sw.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-Mk4laCAL.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 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:`8`,y1:`11`,x2:`14`,y2:`11`},child:[]}]})(e)}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:`11`,y1:`8`,x2:`11`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`8`,y1:`11`,x2:`14`,y2:`11`},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:`polygon`,attr:{points:`13 2 3 14 12 14 11 22 21 10 12 10 13 2`},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:`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 F(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 I(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 L(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 ne(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 re(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 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:`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 R(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 z(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 B(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 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:`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:`path`,attr:{d:`M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z`},child:[]},{tag:`line`,attr:{x1:`7`,y1:`7`,x2:`7.01`,y2:`7`},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:`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 oe(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 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:`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 ce(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 W(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 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:`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 ue(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 de(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 fe(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 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:`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 G(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 K(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 me(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 q(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 he(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 J(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 ge(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 _e(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 ve(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 ye(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 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:`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 Y(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 14 10 14 10 20`},child:[]},{tag:`polyline`,attr:{points:`20 10 14 10 14 4`},child:[]},{tag:`line`,attr:{x1:`14`,y1:`10`,x2:`21`,y2:`3`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`21`,x2:`10`,y2:`14`},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:`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 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:`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 Ce(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 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:`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 Te(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 Ee(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:`M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z`},child:[]},{tag:`polyline`,attr:{points:`22,6 12,13 2,6`},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:`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 Oe(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 ke(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 Ae(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 je(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 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 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 Ne(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 Pe(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 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:`M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`},child:[]},{tag:`polyline`,attr:{points:`9 22 9 12 15 12 15 22`},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:`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 Le(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:`12`,x2:`2`,y2:`12`},child:[]},{tag:`path`,attr:{d:`M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`16`,x2:`6.01`,y2:`16`},child:[]},{tag:`line`,attr:{x1:`10`,y1:`16`,x2:`10.01`,y2:`16`},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:`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 ze(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 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:`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 Ve(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 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:`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 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:`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 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:`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 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:`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 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:`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 qe(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:`M20.24 12.24a6 6 0 0 0-8.49-8.49L5 10.5V19h8.5z`},child:[]},{tag:`line`,attr:{x1:`16`,y1:`8`,x2:`2`,y2:`22`},child:[]},{tag:`line`,attr:{x1:`17.5`,y1:`15`,x2:`9`,y2:`15`},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:`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 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:`M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`1`,x2:`23`,y2:`23`},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:`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 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:`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 Qe(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 $e(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 et(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 tt(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 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:`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 rt(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 it(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 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:`15 10 20 15 15 20`},child:[]},{tag:`path`,attr:{d:`M4 4v7a4 4 0 0 0 4 4h12`},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:`9 10 4 15 9 20`},child:[]},{tag:`path`,attr:{d:`M20 4v7a4 4 0 0 1-4 4H4`},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:`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 ct(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:`polygon`,attr:{points:`16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76`},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:`16 18 22 12 16 6`},child:[]},{tag:`polyline`,attr:{points:`8 6 2 12 8 18`},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:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`polyline`,attr:{points:`12 6 12 12 16 14`},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:`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 ft(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 pt(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 mt(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 ht(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 gt(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 _t(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 vt(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 yt(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 bt(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 11 12 14 22 4`},child:[]},{tag:`path`,attr:{d:`M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11`},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:`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 St(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 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:`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 wt(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 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`},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:`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 Et(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 Dt(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 Ot(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 kt(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 At(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 jt(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 Mt(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:`14.31`,y1:`8`,x2:`20.05`,y2:`17.94`},child:[]},{tag:`line`,attr:{x1:`9.69`,y1:`8`,x2:`21.17`,y2:`8`},child:[]},{tag:`line`,attr:{x1:`7.38`,y1:`12`,x2:`13.12`,y2:`2.06`},child:[]},{tag:`line`,attr:{x1:`9.69`,y1:`16`,x2:`3.95`,y2:`6.06`},child:[]},{tag:`line`,attr:{x1:`14.31`,y1:`16`,x2:`2.83`,y2:`16`},child:[]},{tag:`line`,attr:{x1:`16.62`,y1:`12`,x2:`10.88`,y2:`21.94`},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:`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 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:`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 Ft(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 It(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 Lt(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 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:`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 zt(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 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2`},child:[]},{tag:`path`,attr:{d:`M8.5 2h7`},child:[]},{tag:`path`,attr:{d:`M7 16h10`},child:[]}]})(e)}function Bt(e){return e.map(e=>e.kind===`package`?`pi update npm:${e.name}`:e.kind===`git-extension`?`pi update ${Vt(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 Vt(e){return e.startsWith(`git:`)?e:`git:${e}`}function Ht(){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 Ut(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 Wt=[],Gt=!1;function Kt(e){if(e.key===`Escape`&&Wt.length!==0)for(let t=Wt.length-1;t>=0;t--){let n=Wt[t];if(n()!==!1){e.preventDefault(),e.stopPropagation();break}}}function qt(){!Gt&&typeof document<`u`&&(document.addEventListener(`keydown`,Kt,!0),Gt=!0)}function Jt(){Gt&&Wt.length===0&&typeof document<`u`&&(document.removeEventListener(`keydown`,Kt,!0),Gt=!1)}function Yt(e){return Wt.push(e),qt(),()=>{let t=Wt.lastIndexOf(e);t>=0&&Wt.splice(t,1),Jt()}}function Xt(e,t=!0){let n=(0,g.useRef)(e);(0,g.useLayoutEffect)(()=>{n.current=e}),(0,g.useEffect)(()=>{if(t)return Yt(()=>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 Qt({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,onContextMenu:d,dataBarItem:f,menuRef:p,menuStyle:m}){let h=(0,g.useRef)(null),_=(0,g.useRef)(null),[v,y]=(0,g.useState)(0),b=e=>{_.current=e,typeof p==`function`?p(e):p&&`current`in p&&(p.current=e)},x=()=>{let e=h.current,t=_.current;if(!e||!t)return;if(window.innerWidth<=768){v!==0&&y(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){v!==0&&y(0);return}let a=n.width,o=Zt({align:i,triggerLeft:r.left,triggerRight:r.right,menuWidth:a,viewportWidth:window.innerWidth,margin:8});o!==v&&y(o)};return(0,g.useLayoutEffect)(()=>{t?x():v!==0&&y(0)}),(0,g.useEffect)(()=>{if(t)return window.addEventListener(`resize`,x),()=>window.removeEventListener(`resize`,x)},[t,v]),Ut(h,()=>n(!1),{enabled:t}),Xt(()=>n(!1),t),(0,X.jsxs)(`div`,{className:`dropdown ${i} ${a?`fit`:``} ${o===`up`?`dd-up`:``}`,ref:h,children:[(0,X.jsxs)(`button`,{type:`button`,className:u??`chip`,onClick:()=>n(!t),onContextMenu:d,"aria-expanded":t,"data-tip":s,"data-bar-item":f,children:[e,c&&(0,X.jsx)(vt,{className:`dd-caret ${t?`up`:``}`})]}),t&&(0,X.jsx)(`div`,{className:`dd-menu ${l??``}`,ref:b,style:v===0?m:{...m,transform:m?.transform?`${m.transform} translateX(${v}px)`:`translateX(${v}px)`},children:r})]})}function $t({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 en=`pi-web-tts`,tn={enabled:!1,announce:!0,readReplies:!1,rate:1,voiceURI:``};function nn(){try{let e=localStorage.getItem(en);if(!e)return{...tn};let t={...tn,...JSON.parse(e)};for(let e of[`enabled`,`announce`,`readReplies`])typeof t[e]!=`boolean`&&(t[e]=tn[e]);return t.rate=typeof t.rate!=`number`||!Number.isFinite(t.rate)?tn.rate:Math.round(Math.max(.5,Math.min(2,t.rate))*10)/10,typeof t.voiceURI!=`string`&&(t.voiceURI=tn.voiceURI),t}catch{return{...tn}}}function rn(e){try{localStorage.setItem(en,JSON.stringify(e))}catch{}}function an(){return typeof window<`u`&&`speechSynthesis`in window}function on(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 sn(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 cn(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 sn((n.content??[]).filter(e=>e?.type===`text`&&typeof e.text==`string`).map(e=>e.text??``).join(`
|
|
3
3
|
`))}return``}var ln=!1,un=null,dn=null,fn=new Set;function pn(e,t=null){e?(ln=!0,un=t):(ln=!1,un=null);for(let t of fn)try{t(e)}catch{}}function mn(){return ln}function hn(){return ln?un:null}function gn(e){return fn.add(e),()=>fn.delete(e)}function _n(e,t=nn(),n){if(e&&an())try{let r=window.speechSynthesis;r.cancel();let i=new SpeechSynthesisUtterance(e);i.rate=t.rate;let a=on(t.voiceURI,r.getVoices(),navigator.language);a&&(i.voice=a),i.onend=()=>{dn===i&&pn(!1)},i.onerror=()=>{dn===i&&pn(!1)},dn=i,pn(!0,n??null),r.speak(i)}catch{dn=null,pn(!1)}}function vn(){if(an()){try{window.speechSynthesis.cancel()}catch{}dn=null,pn(!1)}}var yn=null;function bn(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 xn(){return yn===null&&(yn=bn()),yn}function Sn(e,t){return t===`/`?e:t+e.replace(/^\/+/,``)}function Cn(e){return Sn(e,xn())}var wn=`pi-web-ui:token`;function Tn(){try{let e=new URL(window.location.href),t=e.searchParams.get(`token`);t&&(localStorage.setItem(wn,t.trim()),e.searchParams.delete(`token`),window.history.replaceState(null,``,e.toString()))}catch{}}function En(){try{return localStorage.getItem(wn)??``}catch{return``}}function Dn(e){let t=En();return t?`${e}${e.includes(`?`)?`&`:`?`}token=${encodeURIComponent(t)}`:e}var On=[`zh`,`en`,`de`,`es`,`fr`,`it`,`ja`,`ko`,`pt`,`ru`,`zh-Hant`,`zh-HK`,`zh-TW`];function kn(e){let t=jn(e);return t===`zh`||t.startsWith(`zh-`)}function An(e,t){let n=e.split(`-`);if(n[0]!==`zh`||n.includes(`hans`))return null;let r=n.includes(`tw`),i=n.includes(`hk`)||n.includes(`mo`),a=n.includes(`hant`);if(!r&&!i&&!a)return null;let o;o=r?[`zh-tw`,`zh-hant`,`zh-hk`]:i?[`zh-hk`,`zh-hant`,`zh-tw`]:[`zh-hant`,`zh-tw`,`zh-hk`];for(let e of o){let n=Mn(e,t);if(n)return n}return null}function jn(e){return String(e??``).trim().toLowerCase().replace(/_/g,`-`)}function Mn(e,t){return t.find(t=>t.toLowerCase()===e)??null}function Nn(e,t){return e?Mn(e,t)??An(e,t)??Mn(e.split(`-`)[0]??``,t):null}function Pn(e,t,n,r=On){let i=(e??``).trim();if(i)return i;for(let e of t??[]){let t=Nn(jn(e),r);if(t)return t}return Nn(jn(n),r)??`en`}var Fn=`pi-web-ui:lang`,In={docTitle:`pi-web-ui — pi 编码智能体`,cancel:`取消`,ok:`确定`,save:`保存`,close:`关闭`,widgetExpand:`点击放大查看完整输出`,collapsePanel:`收起面板`,expandPanel:`展开面板`,dragToResize:`拖拽调整宽度 · 双击复位`,loading:`加载中…`,connected:`已连接`,connecting:`连接中…`,reconnecting:`重连中…`,networkLatency:`网络延迟`,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:`引擎`,engineSwitchTip:`点击切换智能体引擎(零重启秒级热切)`,engineTagFull:`完整生态`,engineTagFast:`极速补丁`,enginePickerDesc:`零重启热切换智能体引擎,不同标签页可同时运行不同引擎`,settingsEngineSection:`智能体引擎`,settingsEngineHint:`支持零重启秒级热切换:切换后本标签页立即接入目标引擎,原引擎后台运行中的对话不会中断;也可打开多个浏览器标签页同时分别进行 pi 与 DSH 对话。`,settingsEnginePiTitle:`pi 引擎(标准)`,settingsEnginePiDesc:`完整插件生态、扩展与技能、工具延迟加载、审批门禁、目标模式 2.0 与子代理`,settingsEngineDshTitle:`DSH 引擎(DeepSeek Harness)`,settingsEngineDshDesc:`轻量级代码编辑循环、hashline 补丁引擎、Agent 预设与三档权限控制`,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:`停止`,zenMode:`极简模式`,zenModeTip:`极简模式 (Alt+Z)`,zenModeExit:`退出极简模式`,zenModeExitTip:`退出极简模式 (Alt+Z / Esc)`,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)中的对话`,forkedSessionBadge:`分支`,forkedSessionTip:`分支自:{parent}`,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:`检查失败`,piCoreUndetected:`无法检测`,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:`桌面`,filesShowHidden:`显示以 . 开头的隐藏文件`,filesHideHidden:`隐藏以 . 开头的文件`,filesHelp:`浏览:点文件夹进入、点文件预览,「..」返回上级;「根目录」回当前项目根,「此电脑」浏览全盘换盘符,「🏠」直达用户目录,「🖥️」直达桌面。
|
|
4
4
|
文件操作:右键可新建文件/文件夹、重命名、复制/剪切/粘贴、创建副本、删除、上传文件;文件可下载,行尾按钮可复制名称/路径。
|
|
@@ -326,7 +326,7 @@ Avoid three test anti-patterns: tests coupled to the implementation, tautologica
|
|
|
326
326
|
|
|
327
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)`,mcpManageEnabledDesc:`MCP server inspection and installation (list / check / install / remove / reload): allows AI to check whether an MCP server is installed and conveniently install/configure npm or remote MCP servers with live hot-reload.`,mcpManageOffHint:`Disabled: AI cannot invoke mcp_manage to check or install MCP servers`,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`,sandboxNewBtn:`Launch Sandbox Project (isolated workspace)`,sandboxModalTitle:`Launch Sandbox Project`,sandboxModalSubtitle:`Experiment freely inside a hard-jailed copy — no changes ever touch your original files.`,sandboxModeLabel:`Initial Content`,sandboxModeBlank:`Blank Sandbox`,sandboxModeBlankDesc:`Clean empty directory for quick prototypes, scripts, or file processing`,sandboxModeImport:`Import Existing Project`,sandboxModeImportDesc:`Clone source project files (auto-skips node_modules/caches); original stays untouched`,sandboxSourceLabel:`Source Project Path`,sandboxSourcePlaceholder:`Enter or select a local project path to import`,sandboxLifecycleLabel:`Lifecycle`,sandboxLifecycleEphemeral:`Temporary (Use & Discard)`,sandboxLifecycleEphemeralDesc:`Ideal for one-off experiments; destroy anytime or convert to permanent`,sandboxLifecyclePermanent:`Permanent Sandbox`,sandboxLifecyclePermanentDesc:`Kept in your projects list for ongoing experimentation`,sandboxNameLabel:`Sandbox Name (optional)`,sandboxNamePlaceholder:`Leave blank to auto-generate`,sandboxCreateSubmit:`Launch Sandbox`,sandboxBadgeEphemeral:`Temp Sandbox`,sandboxBadgePermanent:`Sandbox`,sandboxBannerTitle:`Sandbox Isolation: {name}`,sandboxBannerSourceDesc:`Source: {source} (read-only protected; all edits stay inside this sandbox)`,sandboxBannerBlankDesc:`Isolated workspace (hard jail active; writing outside sandbox is blocked)`,sandboxActionPersist:`Keep Permanently`,sandboxActionPersistTip:`Convert this temporary sandbox into a permanent sandbox project`,sandboxActionApplySource:`Sync to Source`,sandboxActionApplySourceTip:`Sync modified files from this sandbox back to the source project (preserves .git)`,sandboxActionApplyConfirm:`Sync modified files from sandbox "{name}" back to source project ({source})?`,sandboxActionReset:`Reset`,sandboxActionResetTip:`Wipe sandbox and restore initial state (re-clones clean copy from source if imported)`,sandboxActionResetConfirm:`Reset sandbox "{name}"? Unexported changes in the sandbox will be wiped and restored to initial state.`,sandboxActionPromote:`Save as Project`,sandboxActionPromoteTip:`Export this sandbox to a formal project directory outside sandboxes`,sandboxActionDestroy:`Destroy`,sandboxActionDestroyTip:`Permanently delete this sandbox directory and switch back`,sandboxActionDestroyConfirm:`Permanently destroy sandbox "{name}" and delete all its files? This cannot be undone.`,toolsWorktreeDesc:`Manage Git worktrees for isolated PR/branch work while keeping the UI workspace synchronized`,toolsWorktreeOffHint:`When disabled, AI cannot use the worktree tool and must use manual terminal commands`,worktreeBadgeLinked:`Worktree`,worktreeBadgeDirtyCount:`{count} with edits`,worktreeBannerActiveTitle:`Active Git Worktree: {branch}`,worktreeBannerActiveDesc:`Linked main repository: {main} [{mainBranch}]`,worktreeBannerUncleanedTitle:`Found {count} linked Git worktree(s)`,worktreeBannerUncleanedDesc:`{names} (check if changes need to be merged or pruned)`,worktreeActionSwitchMain:`Switch to Main`,worktreeActionSwitchMainTip:`Switch active workspace back to the main repository root`,worktreeActionSwitchTo:`Switch to {name}`,worktreeActionSwitchToTip:`Switch workspace to worktree {name}`,worktreeActionRemove:`Remove Worktree`,worktreeActionRemoveTip:`Clean up and remove this Git worktree`,worktreeActionRemoveConfirm:`Are you sure you want to remove worktree "{path}"? Uncommitted changes may be lost.`,worktreeActionCollapse:`Collapse`,worktreeActionMore:`More ({count})`,sandboxPromoteTitle:`Save Sandbox as Formal Project`,sandboxPromoteSubtitle:`Export files from sandbox "{name}" to a new directory outside the sandbox jail.`,sandboxPromoteTargetLabel:`Target Directory Path (must be a new or empty directory)`,sandboxPromoteTargetPlaceholder:`e.g. ~/projects/my-new-app`,sandboxPromoteSwitchLabel:`Switch to the exported project immediately`,sandboxPromoteSubmit:`Export Project`,sandboxApplyTitle:`Sync Sandbox Changes to Source Project`,sandboxDiffStats:`+{added} added · ~{modified} modified · -{deleted} deleted in sandbox · {unchanged} unchanged`,sandboxDiffEmpty:`This sandbox is identical to the source project — no modified or added files to sync.`,sandboxDiffDeletedNote:`Note: Syncing writes added/modified files and prunes removed files in the source project (preserves source .git and dependency caches).`,sandboxApplySubmit:`Confirm Sync ({count} files)`,sandboxEnabledDesc:`Allow AI to create blank or imported copy-on-write sandbox projects (skipping node_modules/caches), inspect diffs, reset, or destroy; syncing changes back to the source project requires user approval.`,sandboxOffHint:`Disabled: AI cannot invoke the sandbox tool to create or manage isolated sandboxes`},Rn=[{code:`zh`,nativeName:`简体中文`},{code:`en`,nativeName:`English`}],zn={};function Bn(e){return!e||typeof e.code!=`string`||!e.code||e.code===`zh`||e.code===`en`||!e.strings||typeof e.strings!=`object`?!1:(zn[e.code]=e,!0)}function Vn(e){delete zn[e]}function Hn(e){return e===`zh`?`中文`:e===`zh-TW`?`台繁`:e===`zh-HK`?`港繁`:e===`zh-Hant`?`繁中`:e.toUpperCase()}function Un(e){return e===`zh`?`zh-CN`:e===`pt`?`pt-BR`:e}async function Wn(e){let t=await fetch(Dn(Cn(e)));if(!t.ok)throw Error(`HTTP ${t.status} for ${e}`);return await t.json()}var Gn=(0,g.createContext)(null);function Kn(){try{return localStorage.getItem(Fn)}catch{return null}}function qn(){return Pn(Kn(),typeof navigator<`u`?navigator.languages:[],null)}function Jn({children:e}){let[t,n]=(0,g.useState)(qn),[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(Fn,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 Wn(`/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 Wn(`/api/locales/${e.code}`);return Bn({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=Pn(null,typeof navigator<`u`?navigator.languages:[],e);t!==a.current&&(a.current=t,n(t))}let t=a.current;if(t!==`zh`&&t!==`en`&&!zn[t]){let t=Pn(null,typeof navigator<`u`?navigator.languages:[],e,[`zh`,`en`]);a.current=t,n(t);try{localStorage.setItem(Fn,t)}catch{}}})},[s]);let c=(0,g.useMemo)(()=>[...Rn,...Object.values(zn).map(e=>({code:e.code,nativeName:e.nativeName}))],[r]),l=(0,g.useCallback)((e,n)=>{let r=zn[t]?.strings[e],i=kn(t);r&&!i&&t!==`ja`&&/[\u4e00-\u9fff]/.test(r)&&(r=void 0);let a=r??(i?In[e]:Ln[e]);if(n)for(let[e,t]of Object.entries(n))a=a.replaceAll(`{${e}}`,String(t));return a},[t,r]);(0,g.useEffect)(()=>{document.documentElement.lang=Un(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)(Gn.Provider,{value:u,children:e})}var Yn={locale:`en`,setLocale:()=>{},t:(e,t)=>{let n=Ln[e]??In[e]??e;return t?Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{${t}}`,String(n)),n):n},packs:[],reloadPacks:async()=>null};function Xn(){return(0,g.useContext)(Gn)||Yn}function Z(){return Xn().t}var Zn=[{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 Qn({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)(F,{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})})]}),Zn.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 $n(){let[e,t]=(0,g.useState)([]);return(0,g.useEffect)(()=>{if(!an())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 er({settings:e,onChange:t,onPreview:n}){let r=Z(),i=$n(),a=an(),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)(F,{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&&!on(e.voiceURI,i,navigator.language)){t({...tn,...e,voiceURI:``});return}n()},children:r(`preview`)})})]})}function tr(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 nr=()=>window.__piWebUiHost?.pageCall?.bind(window.__piWebUiHost),rr=null,ir=0;function ar(){return rr?.available===!0?rr.pages??[]:[]}function or(){Date.now()-ir<5e3||sr().catch(()=>{})}async function sr(){if(tr())return{available:!1,pages:[],desktop:!0,error:`桌面版不支持浏览器操作:窗口里没有 Chrome 扩展运行时,请改用系统浏览器打开同一个地址(网页版)`};let e=nr();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&&(rr=r,ir=Date.now()),r}catch(e){return{available:!1,pages:[],error:e instanceof Error?e.message:String(e)}}}function cr(e){return e.length===1?e[0]:null}function lr(e){return{path:e.origin,name:e.title?.trim()||e.origin,mode:`page`,key:`page:${e.origin}`}}async function ur(){let e=nr();if(!e)return!1;try{return(await e({op:`openOptions`,timeoutMs:5e3})).ok===!0}catch{return!1}}function dr(e=45e3){let[t,n]=(0,g.useState)(null),r=(0,g.useRef)(!0),i=(0,g.useCallback)(async e=>{let t=await sr();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 fr=null,pr=null,mr=null,hr=null,gr=null;function _r(e){hr=e}function vr(e){gr=e}function yr(e){return hr?(hr(e),!0):!1}function br(e){return gr?(gr(e),!0):!1}function xr(e){fr=e}function Sr(e){pr=e}function Cr(e){mr=e}function wr(){return mr?(mr(),!0):!1}function Tr(){return!!(fr||pr)}function Er(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&&!fr||i&&!pr?!1:(i&&pr?.(n),r&&fr?.(t),!0)}function Dr(){let e=Z(),{status:t,refresh:n}=dr(),[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=cr(c),d=e=>{o(e),s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(()=>o(null),2600)},f=t=>{let n=Er({attachments:[lr(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)(ve,{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)(ve,{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)(Or,{status:t,onRefresh:n,onCite:f,onClose:()=>i(!1)})]})}function Or({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 ur()||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)(ve,{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 kr=[`terminal_create`,`terminal_list`,`terminal_close`,`terminal_input`,`terminal_key`,`terminal_read`,`terminal_wait`],Ar=[`subagent`],jr=`edit_soft`,Mr=`delegate_task`,Nr=`ask_user_question`,Pr=`todo_list`,Fr=`browser_page`,Ir=`conversation_read`,Lr=`skill`,Rr=`schedule`,zr=`eval`,Br=`present_files`,Vr=`claim_files`,Hr=`plan_update`,Ur=`compact_context`,Wr=`patch`,Gr=`mcp_manage`,Kr=`sandbox`,qr=`worktree`,Jr=`codemode`,Yr=`tool_search`,Xr=[...kr.map(e=>({name:e,group:`terminal`,defaultOn:!1,dshVisible:!0})),...Ar.map(e=>({name:e,group:`subagent`,defaultOn:!0,dshVisible:!1})),{name:jr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`editSoftEnabledDesc`,offHintKey:`editSoftOffHint`},{name:Mr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`delegateTaskEnabledDesc`,offHintKey:`delegateTaskOffHint`},{name:Nr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`questionnaireEnabledDesc`,offHintKey:`questionnaireOffHint`},{name:Fr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`browserPageEnabledDesc`,offHintKey:`browserPageOffHint`},{name:Ir,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`conversationReadEnabledDesc`,offHintKey:`conversationReadOffHint`},{name:Vr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`claimFilesEnabledDesc`,offHintKey:`claimFilesOffHint`},{name:Hr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`planUpdateEnabledDesc`,offHintKey:`planUpdateOffHint`},{name:Wr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`patchToolEnabledDesc`,offHintKey:`patchToolOffHint`},{name:`lsp`,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`lspToolEnabledDesc`,offHintKey:`lspToolOffHint`},{name:Br,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`presentFilesEnabledDesc`,offHintKey:`presentFilesOffHint`},{name:Lr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`skillEnabledDesc`,offHintKey:`skillOffHint`},{name:zr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`evalEnabledDesc`,offHintKey:`evalOffHint`},{name:Jr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`codemodeEnabledDesc`,offHintKey:`codemodeOffHint`},{name:Yr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`toolSearchEnabledDesc`,offHintKey:`toolSearchOffHint`},{name:Rr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`scheduleTaskEnabledDesc`,offHintKey:`scheduleTaskOffHint`},{name:Ur,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`compactContextEnabledDesc`,offHintKey:`compactContextOffHint`},{name:Gr,group:`other`,defaultOn:!1,dshVisible:!1,descKey:`mcpManageEnabledDesc`,offHintKey:`mcpManageOffHint`},{name:Kr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`sandboxEnabledDesc`,offHintKey:`sandboxOffHint`},{name:qr,group:`other`,defaultOn:!0,dshVisible:!1,descKey:`toolsWorktreeDesc`,offHintKey:`toolsWorktreeOffHint`},{name:Pr,group:`other`,defaultOn:!0,dshVisible:!0,descKey:`todoListEnabledDesc`,offHintKey:`todoListOffHint`}],Zr=[`bash`,`read`,`edit`,`write`,`powershell`,`ls`,`grep`,`find`];new Set(Xr.map(e=>e.name));var Qr=[...Xr.map(e=>e.name),...Zr];function $r(e){let t=new Set(e);return Qr.filter(e=>!t.has(e))}function ei(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 ti(e){return ei([Lr],e).includes(Lr)}var ni=`pi-web-notify`,ri={enabled:!1};function ii(){try{let e=localStorage.getItem(ni);if(!e)return{...ri};let t=JSON.parse(e);return{enabled:typeof t.enabled==`boolean`?t.enabled:ri.enabled}}catch{return{...ri}}}function ai(e){try{localStorage.setItem(ni,JSON.stringify(e))}catch{}}function oi(){return typeof window<`u`&&`Notification`in window}function si(){return oi()?null:typeof window<`u`&&window.isSecureContext===!1?`insecure`:`unsupported`}function ci(e){let{screenX:t,screenY:n,outerWidth:r,outerHeight:i}=e;return Number.isFinite(t)&&li(t)||Number.isFinite(n)&&li(n)?!0:r>0&&r<=400&&i>0&&i<=40}function li(e){return e<=-1e4}function ui(e){return!(e.visibility!==`visible`||e.minimized||!e.hasFocus||e.windows&&e.idleMs>12e4)}var di=Date.now(),Q=!1;function fi(){di=Date.now()}function pi(){return Math.max(0,Date.now()-di)}function mi(){if(Q||typeof window>`u`)return;Q=!0;let e={passive:!0,capture:!0};for(let t of[`pointerdown`,`pointermove`,`keydown`,`wheel`,`touchstart`,`focus`,`scroll`])window.addEventListener(t,fi,e);typeof document<`u`&&document.addEventListener(`visibilitychange`,fi,e)}function hi(){return typeof navigator>`u`?!1:/windows/i.test(navigator.userAgent??``)}function gi(){return mi(),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:ci({screenX:window.screenX,screenY:window.screenY,outerWidth:window.outerWidth,outerHeight:window.outerHeight}),idleMs:pi(),windows:hi()}}function _i(){return oi()?Notification.permission:`denied`}async function vi(){if(!oi())return`denied`;try{return await Notification.requestPermission()}catch{return`denied`}}function yi(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}function bi(e,t=!1){return{body:e,requireInteraction:t,icon:Cn(`/icons/icon-192.png`),badge:Cn(`/icons/icon-192.png`),data:{url:typeof location<`u`?location.href:Cn(`/`)}}}async function xi(e,t,n=!1){if(!oi())return{path:`none`,error:`unsupported`};if(Notification.permission!==`granted`)return{path:`none`,error:`permission: ${Notification.permission}`};let r=bi(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=yi(e)}try{return new Notification(e,r),{path:`page`,error:i}}catch(e){return{path:`none`,error:`${i}; page: ${yi(e)}`}}}async function Si(e,t){oi()&&(ui(gi())||ii().enabled&&await xi(e,t))}var Ci=!1;function wi(){let e=Z(),[t,n]=(0,g.useState)(ii),[r,i]=(0,g.useState)(()=>_i()),[a,o]=(0,g.useState)(null),s=si(),c=s!==null,l=hi();(0,g.useEffect)(()=>{let e=()=>i(_i());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),ai(r),e){let e=await vi();if(i(e),e!==`granted`){let e={...r,enabled:!1};n(e),ai(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)(Et,{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`)}),Ci]})}var Ti=new Set([`svg`,`g`,`path`,`circle`,`rect`,`line`,`polyline`,`polygon`,`ellipse`,`use`,`defs`,`clipPath`,`linearGradient`,`radialGradient`,`stop`]),Ei=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(`.`)),Di=new Set([`script`,`style`,`title`,`desc`,`foreignobject`]),Oi=new Set([...Ti].map(e=>e.toLowerCase())),ki=new Set([...Ei].map(e=>e.toLowerCase()));function Ai(e){return Oi.has(e.toLowerCase())}function ji(e){return ki.has(e.toLowerCase())}function Mi(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(!Ai(e)){Di.has(e)?t.remove():(i(t),t.replaceWith(...t.childNodes));continue}for(let e of Array.from(t.attributes)){let n=e.name.toLowerCase();(!ji(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();(!ji(t)||/^on/i.test(t))&&r.removeAttribute(e.name)}return i(r),new XMLSerializer().serializeToString(r)}function Ni({icon:e,iconSvg:t,className:n}){let r=Mi(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=`pi-web-ui:cost-currency`,Fi=null,Ii=0,Li=new Set;function Ri(){Ii+=1;for(let e of[...Li])try{e()}catch{}}function zi(e){return Li.add(e),()=>{Li.delete(e)}}function Bi(){return Ii}function Vi(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function Hi(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(Pi);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function Ui(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(Pi):localStorage.setItem(Pi,t)}}catch{}Ri()}function Wi(e){return typeof e==`function`?(Fi=e,Ri(),()=>{Fi===e&&(Fi=null,Ri())}):(Fi=null,Ri(),()=>{})}function Gi(e,t){let n=String(e??``).trim();if(!n)return{symbol:t,value:`0`};let r=n.match(/^([^\d<>+-]+)\s*(.+)$/);return r?{symbol:r[1],value:r[2]}:{symbol:``,value:n}}function Ki(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=Hi(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):Vi(n);if(Fi)try{let e=Fi(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return Gi(e,r);if(e&&typeof e==`object`&&typeof e.value==`string`)return{symbol:typeof e.symbol==`string`?e.symbol:r,value:e.value,tooltip:typeof e.tooltip==`string`?e.tooltip:void 0}}catch(e){console.error(`[cost-format] custom cost formatter threw:`,e)}return{symbol:r,value:i}}function qi(e,t){return(0,g.useSyncExternalStore)(zi,Bi,Bi),Ki(e,t)}var Ji={projects:`host:lp-projects`,convs:`host:lp-running`,sessions:`host:lp-history`},Yi=[`projects`,`convs`,`sessions`],Xi=new Map(Object.keys(Ji).map(e=>[Ji[e],e])),Zi=`plugin:`;function Qi(e){return e.startsWith(Zi)&&e.length>7}function $i(e){let t=[],n=new Set;for(let r of e??[]){let e=null,i,a=Xi.get(r.id);a?e=a:r.source?.startsWith(`plugin:`)&&r.kind===`view`&&(e=`${Zi}${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 Yi)n.has(e)||t.push({key:e,shown:!0});return t}function ea(e,t){return e.filter(e=>e.shown&&t(e.key)).map(e=>e.key)}function ta(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 na(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||Qi(e))&&typeof i==`number`&&Number.isFinite(i)&&i>0&&(n[e]=i)}catch{}return n}var ra=new Set([`view`,`action`,`badge`,`menu`,`page`,`organizer`,`divider`,`toggle`,`input`,`progress`,`select`]),ia=new Set([`disabled`,`always`,`never`,`file.isDir`,`file.isFile`,`session.isRunning`,`message.hasSelection`]),aa=`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(`,`),oa=aa.map(e=>({slot:e,cardinality:`list`}));function sa(e){return oa.find(t=>t.slot===e)?.cardinality??`list`}function ca(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 la=[{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:zen-mode`,slot:`topbar.primary`,labelKey:`zenMode`,icon:`feather`,kind:`action`,order:43,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:`aperture`,kind:`action`,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-toc`,slot:`file.preview.toolbar`,labelKey:`previewTocLabel`,icon:`list`,kind:`action`,order:15},{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}],ua=`__view`,da=new Set([`host:settings`,`host:history`,`host:files`]),fa=new Set([`host:history`,`host:files`]);function pa(e){return`${e}:${ua}`}function ma(e){return e.source.startsWith(`plugin:`)?e.id===pa(e.source.slice(7)):!1}function ha(e,t,n){let r=pa(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 ga(e,t){let n=t.map(pa),r=new Set(n),i=(e?.order??[]).filter(e=>!r.has(e));return{...e,order:[...i,...n]}}var _a=`host:brand`,va=[`host:brand-logo`,`host:brand-name`];function ya(e){if(!((e.hidden??[]).some(e=>va.includes(e))||(e.shown??[]).some(e=>va.includes(e))||(e.order??[]).some(e=>va.includes(e))||va.some(t=>e.align?.[t]!==void 0)||va.some(t=>e.groups?.[t]!==void 0)||va.some(t=>e.labels?.[t]!==void 0)||va.some(t=>e.slots?.[t]!==void 0)))return e;let t=e=>{if(!e)return;let t=[];for(let n of e){let e=va.includes(n)?_a: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))va.includes(t)||(n[t]=r);if(n[_a]===void 0){let r=t?e[va[0]]??e[va[1]]:e[va[1]]??e[va[0]];r!==void 0&&(n[_a]=r)}return n},r=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))va.includes(n)||(t[n]=r);if(t[_a]===void 0){let n=e[va[0]]??e[va[1]];n!==void 0&&(t[_a]=n)}return t},i=e=>{if(!e)return;let t={};for(let[n,r]of Object.entries(e))va.includes(n)||(t[n]=r);if(t[_a]===void 0){let n=e[va[0]]??e[va[1]];n!==void 0&&(t[_a]=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 ba(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:ua,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 xa(e){return typeof e==`string`&&aa.includes(e)}function Sa(e,t){return t?e.label:e.labelEn??e.label}function Ca(e,t){return t?e.hint??e.hintEn:e.hintEn??e.hint}function wa(e,t,n,r,i){let a=`${e}#${r.id}`,o=Ta(a,t,n,r.children,i),s=Ca(r,i),c=Ea(r.options,i);return{id:a,slot:t,source:n,label:Sa(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 Ta(e,t,n,r,i){return r?.length?r.map((r,a)=>({entry:wa(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 Ea(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 Da(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?Math.min(100,Math.max(0,t)):0}function Oa(e,t,n,r,i,a){let o=Ta(e,t,n,r.children,i),s=Ca(r,i),c=Da(r.progress),l=Ea(r.options,i);return{id:e,slot:t,source:n,label:Sa(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 ka(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 Aa(e,t){let n=e.filter(e=>ma(e)&&!t.has(e.id));if(n.length===0)return e;let r=e.filter(e=>!ma(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 ja(e,t){let n=kn(t.locale),r=new Set(t.disabledPlugins??[]),i=ya(t.layout??{}),a=e=>{t.diagnostics?.push({level:e.level??`warn`,...e})},o=new Map,s=0;for(let e of la)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(!xa(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&&!ra.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)ia.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,Oa(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);Na(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&&xa(t)&&n.slot!==t&&(n.movedFrom=n.movedFrom??n.slot,n.slot=t,l(e,`slot`))}for(let e of da){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(Ji)){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 aa)d.set(e,[]);for(let e of o.values())d.get(e.slot)?.push(e);let f={};for(let e of aa){let t=ka(d.get(e)??[],u),n=ca(e===`topbar.primary`?Aa(t,u):t,sa(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=>Ma(e,c.get(e.id)??[]))}return f}function Ma(e,t){let n={...e,userOverrides:t};return delete n.seq,n}function Na(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&&xa(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 Pa(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 Fa(e,t){let n=e??{},r={},i=t===_a?[t,...va]:[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=La(n.groups,t),l=La(n.labels,t),u=La(n.align,t),d=La(n.slots,t);if(t===_a)for(let e of va)c=La(c,e),l=La(l,e),u=La(u,e),d=La(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 Ia(){return{}}function La(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 za(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 Ba(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 Va=null,Ha=new Set;function Ua(){for(let e of Ha)e()}function Wa(e){Va={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}:{}},Ua()}function Ga(){Va!==null&&(Va=null,Ua())}function Ka(e){return Ha.add(e),()=>{Ha.delete(e)}}function qa(){return Va}function Ja(){return(0,g.useSyncExternalStore)(Ka,qa,qa)}function Ya(e){return Number.isFinite(e)?e:0}function Xa(e,t,n,r,i,a){let o=Math.max(0,Ya(n)),s=Math.max(0,Ya(r)),c=Math.max(8,Ya(i)-o-8),l=Math.max(8,Ya(a)-s-8);return{x:Math.min(Math.max(8,Ya(e)),c),y:Math.min(Math.max(8,Ya(t)),l)}}function Za(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 Qa(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 $a(e,t){return!e||Qa(e.when,t)}function eo(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 to(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 no(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 ro(e,t){return!e||e.kind===`divider`||e.hidden===!0?!1:!$a(e,t)}function io(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,ro(e[o],r))return o;return-1}var ao={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 oo(e){let t=(e??``).trim();return t?ao[t.toLowerCase()]||(/[^\p{L}\p{N}\s]/u.test(t)&&t.length<=4?t:``):``}var so={engine:`pi`,managed:!1,status:`connecting`,ready:!1,cwd:``,workspaceRoots:[],homeDir:``,desktopDir:``},co=new Set;function lo(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n])}function uo(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&&lo(e.workspaceRoots,t.workspaceRoots)&&e.homeDir===t.homeDir&&e.desktopDir===t.desktopDir&&lo(e.tabs,t.tabs)&&e.service?.name===t.service?.name&&e.service?.supervisor===t.service?.supervisor}function fo(e){let t={...so,...e};if(!uo(so,t)){so=t;for(let e of co)e()}}function po(e){return co.add(e),()=>{co.delete(e)}}function mo(){return so}function ho(){return(0,g.useSyncExternalStore)(po,mo,mo)}function go(e){return(0,g.useSyncExternalStore)(po,()=>so[e],()=>so[e])}function _o(){return go(`engine`)===`dsh`}function vo(){return go(`managed`)}function yo(){return go(`service`)}var bo=null;function xo(e){bo=e}var $=e=>bo?bo(e):!1,So=new Set;function Co(e){return So.add(e),()=>{So.delete(e)}}function wo(e){for(let t of So)try{t(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function To(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function Eo(e){return!!(e&&e.startsWith(`ssh://`))}function Do(e){if(!Eo(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 Oo=1;function ko(e){let t=`probe_${Date.now()}_${Oo++}`;return new Promise(n=>{let r=Co(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 Ao(e,t){let n=`listdir_${Date.now()}_${Oo++}`;return new Promise(r=>{let i=Co(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 jo(e,t){let n=`install_${Date.now()}_${Oo++}`;return new Promise(r=>{let i=Co(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 Mo(){let e=`profiles_${Date.now()}_${Oo++}`;return new Promise(t=>{let n=Co(r=>{r.type===`remote_ssh_profiles_result`&&r.reqId===e&&(n(),t(r.profiles))});$({type:`remote_ssh_list_profiles`,reqId:e})||(n(),t([]))})}function No(e){$({type:`remote_ssh_delete_profile`,name:e})}var Po=`@root`,Fo=e=>e.endsWith(`/`)?e:e+`/`;function Io(e,t){let n=t.trim(),r=e.replace(/\\/g,`/`);return r.endsWith(`/`)?r+n:(/^[A-Za-z]:$/.test(r),r+`/`+n)}function Lo(e){let t=e.trim();return!(!t||t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`))}var Ro=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)?Po:null;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?r+`/`:r};function zo({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)(()=>Eo(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)(``),[te,M]=(0,g.useState)(`22`),[N,F]=(0,g.useState)(``),[I,L]=(0,g.useState)(`password`),[ne,re]=(0,g.useState)(``),[ie,z]=(0,g.useState)(`~/.ssh/id_rsa`),[B,ae]=(0,g.useState)(!0),[V,H]=(0,g.useState)(``),[oe,U]=(0,g.useState)(!1),[se,ce]=(0,g.useState)(null),[W,le]=(0,g.useState)(null),[de,fe]=(0,g.useState)(null),[pe,G]=(0,g.useState)(null),[K,me]=(0,g.useState)([]),[q,he]=(0,g.useState)(!1),[J,ge]=(0,g.useState)(`/`),[_e,ve]=(0,g.useState)(`/`),[ye,be]=(0,g.useState)([]),[Y,xe]=(0,g.useState)(!1),Se=t.filter(e=>e.type===`dir`);(0,g.useEffect)(()=>{if(Eo(e)){let t=Do(e);t&&(ee(t.host),M(String(t.port)),F(t.username),ge(t.remotePath),ve(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`&&Mo().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:Fo(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(!Lo(e)){w(d(`invalidProjectName`));return}let t=Io(m,e);o?.(t),b(!1),S(``),w(null),r()}else $({type:`make_dir`,path:`${Fo(m)}${e}`}),setTimeout(()=>{$({type:`complete_path`,path:Fo(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(te,10)||22),r=(e?.username??N).trim();if(!t||!r){ce(`请填写主机地址和用户名`);return}U(!0),ce(null);let i=await ko({host:t,port:n,username:r,auth:e?.auth??(I===`password`?{type:`password`,password:ne}:I===`key`?{type:`key`,privateKeyPath:ie}:{type:`agent`}),saveProfile:B,profileName:e?.profileName||V.trim()||void 0});if(U(!1),!i.ok||!i.connectionId){ce(i.error||`连接远程服务器失败`);return}le(i.connectionId),fe(i.system??null),G(i.tools??null),me(i.suggestedInstall??[]);let a=i.system?.homeDir||`/`;ge(a),ve(a),De(i.connectionId,a),Mo().then(e=>A(e))},De=async(e,t)=>{xe(!0),ce(null);let n=await Ao(e,t);xe(!1),n.ok?(ge(n.path),ve(n.path),be(n.items)):ce(n.error||`读取远程目录失败`)},Oe=async e=>{if(!W)return;he(!0),ce(null);let t=await jo(W,[e]);he(!1),t.ok?(me(t=>t.filter(t=>t!==e)),pe&&e===`git`&&G({...pe,git:{installed:!0,version:`已安装`}})):ce(t.error||`安装 ${e} 失败,可能需要远端 sudo 权限`)},ke=e=>{let t=parseInt(te,10)||22,n=de?.homeDir||`/`,a=(e||``).trim()||J||`/`;a===`~`?a=n:(a.startsWith(`~/`)||a.startsWith(`~\\`))&&(a=`${n.replace(/\/+$/,``)}/${a.slice(2).replace(/\\/g,`/`)}`),i(To(N,j,t,a)),r()},Ae=Ro(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)(P,{})})]}),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)(He,{}),(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`),"aria-label":d(`computer`),onClick:()=>{h(`@root`),v(`@root`),E(-1)},children:(0,X.jsx)(Le,{})}),(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)(He,{}),(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:W?(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:[`🌐 `,N,`@`,j,` (`,de?.os,` `,de?.arch,`)`]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,onClick:()=>{le(null),fe(null),G(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 ${pe?.git.installed?`ok`:`missing`}`,children:[`Git: `,pe?.git.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${pe?.node.installed?`ok`:`missing`}`,children:[`Node: `,pe?.node.installed?`✓`:`✗`]}),(0,X.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${pe?.bash.installed?`ok`:`missing`}`,children:[`Bash: `,pe?.bash.installed?`✓`:`✗`]})]}),K.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:q,onClick:()=>void Oe(K[0]),children:q?d(`sshInstalling`):`⚡ ${d(`sshInstallTool`)} ${K[0]}`}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>me([]),children:d(`sshSkipAndBrowse`)})]})]})]}),(0,X.jsxs)(`div`,{className:`cwd-picker-head`,children:[(0,X.jsxs)(`span`,{className:`cwd-picker-title`,title:J,children:[(0,X.jsx)(ze,{}),(0,X.jsx)(`span`,{children:J})]}),(0,X.jsxs)(`button`,{type:`button`,className:`cwd-up`,disabled:J===`/`||Y,title:d(`cwdGoUp`),onClick:()=>{let e=Ro(J)||`/`;W&&De(W,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:_e,placeholder:d(`enterPath`),spellCheck:!1,onChange:e=>ve(e.target.value),onKeyDown:e=>{e.key===`Enter`&&W&&De(W,_e)}}),_e.trim()&&_e.trim()!==J&&W&&(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,disabled:Y,onClick:()=>void De(W,_e),children:d(`cwdEnter`)}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,onClick:()=>ke(_e.trim()||J),children:d(`sshOpenRemoteWorkspace`)})]}),(0,X.jsx)(`div`,{className:`cwd-list`,children:Y?(0,X.jsx)(`div`,{className:`cwd-empty`,children:`正在加载远程目录…`}):ye.length===0?(0,X.jsx)(`div`,{className:`cwd-empty`,children:d(`cwdEmpty`)}):ye.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`&&W&&De(W,e.path)},children:[e.type===`dir`?(0,X.jsx)(He,{}):(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),M(String(e.port)),F(e.username),L(e.authType),e.privateKeyPath&&z(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)(ue,{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`))&&(No(e.name),A(t=>t.filter(t=>t.name!==e.name)))},children:(0,X.jsx)(R,{})})]},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:te,onChange:e=>M(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:N,placeholder:`root / ubuntu`,onChange:e=>F(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:I,onChange:e=>L(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`)})]})]}),I===`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:ne,placeholder:`••••••••`,onChange:e=>re(e.target.value)})]}),I===`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:ie,placeholder:`~/.ssh/id_rsa`,onChange:e=>z(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:B,onChange:e=>ae(e.target.checked),style:{marginRight:`4px`}}),d(`sshSaveProfile`)]})}),B&&(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)})]}),se&&(0,X.jsxs)(`div`,{style:{color:`var(--red)`,fontSize:`11px`,padding:`2px 0`},children:[`⚠️ `,se]}),(0,X.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,style:{marginTop:`4px`},disabled:oe,onClick:()=>void Ee(),children:d(oe?`sshConnecting`:`sshConnectAndProbe`)})]})})]})]})}function Bo({open:e,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:a,onCreateProject:o}){let s=Z();return e?(0,X.jsx)(zo,{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 Vo(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 Ho(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 Uo(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 Wo(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=Uo(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]),Xt(()=>{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 Go({anchorRect:e,anchorEl:t,plugins:n,pinnedIds:r,orderedPluginIds:i,onTogglePin:a,onReorder:o,onOpenView:s,onManagePlugins:c,onClose:l}){let{t:u}=Xn(),{panelRef:d,style:f,measure:p}=Wo({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)(Ct,{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)(Ce,{"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)(Ni,{icon:o,iconSvg:e.iconSvg,className:`pm-icon`}):(0,X.jsx)(Ct,{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)(Ho,{"aria-hidden":!0}):(0,X.jsx)(Vo,{"aria-hidden":!0})})]},e.id)})}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`pm-manage`,onClick:()=>{l(),c()},children:[(0,X.jsx)(le,{"aria-hidden":!0}),(0,X.jsx)(`span`,{children:u(`pluginMenuManage`)})]})]}),document.body)}function Ko({onClose:e}){let t=Z(),{locale:n,setLocale:r,reloadPacks:i}=Xn(),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(``),[l,u]=(0,g.useState)(``);async function d(){try{let e=await fetch(Dn(Cn(`/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(Dn(Cn(`/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(Dn(Cn(`/api/locales/${e}`)),{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);Vn(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)(ze,{}),` `,t(`localePacks`)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:t(`close`),onClick:e,children:(0,X.jsx)(P,{})})]}),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)(R,{}),(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)($e,{}),(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)(me,{}),(0,X.jsx)(`span`,{children:t(`bgTaskRefresh`)})]})})]})})}var qo=`xing-shuyin/pi-web-ui`,Jo={state:`idle`,version:null,percent:0,message:null};function Yo(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function Xo(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:Yo(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 Zo(e){if(!tr(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 Qo(e){return e instanceof Error?e.message:String(e)}function $o(e){let t=(e??``).trim().replace(/^v/,``);return t?`https://github.com/${qo}/releases/tag/v${t}`:`https://github.com/${qo}/releases/latest`}function es(){let[e]=(0,g.useState)(()=>Zo()),[t,n]=(0,g.useState)(Jo);(0,g.useEffect)(()=>{if(e)return e.onEvent(e=>n(t=>Xo(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:Qo(e)}))))},[e]),i=(0,g.useCallback)(()=>{e&&(n(e=>({...e,state:`downloading`,message:null})),e.download().catch(e=>n(t=>({...t,state:`error`,message:Qo(e)}))))},[e]),a=(0,g.useCallback)(()=>{e&&e.quitAndInstall().catch(e=>n(t=>({...t,state:`error`,message:Qo(e)})))},[e]);return{...t,bridge:e,check:r,download:i,quitAndInstall:a}}function ts(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 ns=2e3;function rs(e,t,n=ns){return e.filter(e=>t-e.t<=n)}function is(e,t=ns){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 as(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 os(e){let t=0;for(let n of e)n.type===`text`&&typeof n.text==`string`&&n.text?t+=as(n.text):n.type===`thinking`&&typeof n.thinking==`string`&&n.thinking&&(t+=as(n.thinking));return t}var ss=[{id:`pi`,titleKey:`settingsEnginePiTitle`,badge:`PI`,tagKey:`engineTagFull`,descKey:`settingsEnginePiDesc`,colorClass:`engine-pi`},{id:`dsh`,titleKey:`settingsEngineDshTitle`,badge:`DSH`,tagKey:`engineTagFast`,descKey:`settingsEngineDshDesc`,colorClass:`engine-dsh`}];function cs({direction:e=`down`,align:t=`left`,className:n,label:r,caret:i=!1}){let{engine:a}=ho(),{t:o}=Xn(),[s,c]=(0,g.useState)(!1),l=ss.find(e=>e.id===a)??{id:a,titleKey:`settingsEnginePiTitle`,badge:a.toUpperCase(),tagKey:`engineTagFull`,descKey:`settingsEnginePiDesc`,colorClass:`engine-${a}`},u=o(l.titleKey),d=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Mt,{className:`bar-item-icon engine-picker-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text engine-picker-name`,children:r??u}),(0,X.jsx)(`span`,{className:`engine-badge ${l.colorClass}`,children:l.badge})]});return(0,X.jsx)(`div`,{className:`engine-picker-wrap ${l.colorClass} ${n??``}`,"data-bar-item":`host:engine`,children:(0,X.jsxs)(Qt,{trigger:d,open:s,onOpenChange:c,direction:e,align:t,fit:!0,caret:i,triggerClassName:`bar-item chip engine-picker-btn ${l.colorClass}`,menuClassName:`engine-picker-menu`,tip:`${o(`engineBadge`)}: ${r??u} — ${o(`engineSwitchTip`)}`,children:[(0,X.jsxs)(`div`,{className:`engine-picker-header`,children:[(0,X.jsxs)(`div`,{className:`engine-picker-title`,children:[(0,X.jsx)(Mt,{}),(0,X.jsx)(`span`,{children:o(`settingsEngineSection`)})]}),(0,X.jsx)(`div`,{className:`engine-picker-subtitle`,children:o(`enginePickerDesc`)})]}),(0,X.jsx)(`div`,{className:`engine-picker-list`,role:`menu`,children:ss.map(e=>{let t=e.id===a;return(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`engine-picker-item ${e.colorClass}${t?` active`:``}`,onClick:()=>{c(!1),t||$({type:`switch_engine`,engine:e.id})},children:[(0,X.jsxs)(`div`,{className:`engine-picker-item-head`,children:[(0,X.jsx)(Mt,{className:`engine-picker-item-icon`}),(0,X.jsx)(`span`,{className:`engine-badge ${e.colorClass}`,children:e.badge}),(0,X.jsx)(`span`,{className:`engine-picker-item-name`,children:o(e.titleKey)}),(0,X.jsx)(`span`,{className:`engine-picker-item-tag`,children:o(e.tagKey)}),t&&(0,X.jsx)(yt,{className:`engine-picker-check`})]}),(0,X.jsx)(`div`,{className:`engine-picker-item-desc`,children:o(e.descKey)})]},e.id)})})]})})}function ls(e){return e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function us(e){return e===`zh-TW`?`TW`: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 ds({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:_,zenMode:v,onToggleZenMode:y}){let b=Z(),{locale:x,packs:S,setLocale:C}=Xn(),{engine:w}=ho(),T=w===`dsh`,[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(!1),[ee,te]=(0,g.useState)(!1),M=n.settings?.uiLayout,N=n.state,P=N?.stats,I=N?.isStreaming??!1,L=qi(P?.cost??0),ne=(0,g.useRef)([]),re=N?.streamingMessage?os(N.streamingMessage.content):0;(0,g.useEffect)(()=>{if(!I){ne.current=[];return}let e=Date.now(),t=ne.current,n=t[t.length-1];n&&e-n.t<250||(ne.current=rs([...t,{t:e,out:re}],e))},[I,re]);let ie=I?is(ne.current):0,R=n=>{n.preventDefault(),n.stopPropagation();let r=t=>{let n={...M?.slots,[e.id]:t};$({type:`set_settings`,uiLayout:{...M,slots:n}})},i=()=>{let t=new Set(M?.hidden??[]);t.add(e.id),$({type:`set_settings`,uiLayout:{...M,hidden:[...t]}})},a=[];t!==`top`&&a.push({id:`host:move-top`,slot:`contextmenu.topbar`,source:`host`,label:b(`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:b(`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:b(`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:b(`moveToRight`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),a.push({id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:b(`uiLayoutRestore`),kind:`action`,order:50,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}),h&&h.length>0&&a.push(...h),Wa({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()}})},z=e.id,ae=e.labelExplicit?e.label:``,V=e=>ae||e,oe=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:R,"data-bar-item":z,children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})}if(z===`host:brand`)return(0,X.jsxs)(`span`,{className:`bar-item brand bar-item-brand`,title:b(`brand`),onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)(`span`,{className:`brand-logo bar-item-brand-logo`,children:`π`}),(0,X.jsx)(`span`,{className:`brand-name bar-item-text`,children:V(`pi-web-ui`)})]});if(z===`host:conn`){let e=n.ready?`ok`:n.status===`closed`?`error`:`busy`,t=n.ready?b(`connected`):n.status===`closed`?b(`reconnecting`):b(`connecting`),r=n.ready&&typeof n.latencyMs==`number`&&Number.isFinite(n.latencyMs)&&n.latencyMs>=0?Math.round(n.latencyMs):null,i=r===null?null:`${r}ms`,a=r===null?``:r<100?`ok`:r<300?`mid`:`warn`,o=i?`${t} · ${b(`networkLatency`)}: ${i}`:t;return(0,X.jsxs)(`span`,{className:`bar-item status-item status-conn ${e} bar-item-conn`,title:o,"data-tip":o,onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)(`span`,{className:`status-dot ${e}`}),(0,X.jsx)(`span`,{className:`status-conn-label bar-item-text`,children:oe(t)}),i&&(0,X.jsx)(`span`,{className:`status-latency ${a}`,children:i})]})}if(z===`host:engine`)return(0,X.jsx)(`span`,{onContextMenu:R,"data-bar-item":z,className:`bar-item-engine-wrap`,style:{display:`inline-flex`,alignItems:`center`},children:(0,X.jsx)(cs,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,caret:!1,bar:t,label:e.labelExplicit?e.label:void 0})});if(z===`host:ctx`){let e=P?.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?ls(e.tokens):null,o=r>0?ls(r):null,s=a!==null&&o!==null&&i!==null?`${a} / ${o}`:`—`,c=i===null?``:i>=80?`warn`:i>=50?`mid`:`ok`,l=n?`${b(`contextUsage`)}: ${ls(e?.tokens??0)} / ${ls(t)} (${b(`softCapMarker`)}, max ${ls(e?.contextWindow??0)})`:t!==null&&t>0?`${b(`contextUsage`)}: ${s} · ${b(`softCapMarker`)}: ${ls(t)}`:`${b(`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:R,"data-bar-item":z,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(z===`host:cache`){let e=ts(P?.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=b(`cacheHitTip`,{read:ls(e.read),write:ls(e.write),miss:ls(e.miss),input:ls(e.totalInput)}),a=e.totalInput>0?`${b(`cacheHit`)}: ${r} · ${i}`:b(`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:R,"data-bar-item":z,children:[(0,X.jsx)(tt,{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(z===`host:cost`){let e=P?.cost??0,t=L.tooltip||b(`cumulativeCost`);return(0,X.jsxs)(`span`,{className:`bar-item status-item status-cost bar-item-cost${e<=0?` is-zero`:``}${ae?` has-name`:``}`,title:t,"data-tip":t,onContextMenu:R,"data-bar-item":z,children:[ae?(0,X.jsx)(`span`,{className:`bar-item-text`,children:ae}):null,L.symbol?(0,X.jsx)(`span`,{className:`bar-item-char`,children:L.symbol}):null,(0,X.jsx)(`span`,{className:`bar-item-text`,children:L.value})]})}if(z===`host:msg-count`){let e=P?.totalMessages??0,t=`${b(`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:R,"data-bar-item":z,children:[(0,X.jsx)(Se,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:oe(String(e))})]})}if(z===`host:working`){if(!I)return null;let e=(N?.queue?.steering?.length??0)+(N?.queue?.followUp?.length??0);return(0,X.jsxs)(`span`,{className:`bar-item status-item working bar-item-working`,title:b(`working`),"data-tip":b(`working`),onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)(`span`,{className:`working-spin`}),(0,X.jsxs)(`span`,{className:`bar-item-text`,children:[V(b(`working`)),e>0&&` ⏳ ${e}`]}),(0,X.jsx)(`span`,{className:`status-rate bar-item-rate`,title:b(`rateTip`),children:ie>0?`${Math.round(ie)}${b(`tps`)}`:`…`})]})}if(z===`host:status-delegate`)return N?.delegateMode?(0,X.jsxs)(`span`,{className:`bar-item status-item delegate-badge bar-item-delegate`,title:N.delegateConvId?b(`delegateModeOpenTip`):b(`delegateModeBadgeTip`),"data-tip":N.delegateConvId?b(`delegateModeOpenTip`):b(`delegateModeBadgeTip`),onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)(`span`,{className:`bar-item-icon`,children:`🔎`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:V(b(`delegateModeBadge`))}),N.delegateConvId?(0,X.jsx)(`button`,{type:`button`,className:`delegate-badge-open`,title:b(`delegateModeOpenTip`),onClick:()=>$({type:`switch_conversation`,id:N.delegateConvId}),children:`↗`}):null]}):null;if(z===`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:`${b(`hostResourcesTip`)}\n${b(`hostProcessor`)}: ${t} · ${b(`hostMemory`)}: ${r}`,"data-tip":`${b(`hostResourcesTip`)}\n${b(`hostProcessor`)}: ${t} · ${b(`hostMemory`)}: ${r}`,onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)(rt,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`bar-item-text`,children:oe(`${t} · ${r}`)})]})}if(z===`host:browser`)return n.settings?.disabledAgentTools?.includes(`browser_page`)?null:(0,X.jsx)(`span`,{className:`bar-item-wrap`,onContextMenu:R,"data-bar-item":z,children:(0,X.jsx)(Dr,{})});if(z===`host:sound`)return(0,X.jsxs)(Qt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:E,onOpenChange:D,tip:V(b(`sound`)),caret:!1,triggerClassName:`bar-item chip`,onContextMenu:R,dataBarItem:z,trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:V(b(`sound`))})]}),children:[_?.sound&&_?.onSoundChange?(0,X.jsx)(Qn,{settings:_.sound,onChange:_.onSoundChange,onPreview:_.onSoundPreview??(()=>{})}):null,(0,X.jsx)(wi,{})]});if(z===`host:language`)return(0,X.jsxs)(Qt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:O,onOpenChange:k,tip:V(b(`language`)),caret:!1,triggerClassName:`bar-item chip`,onContextMenu:R,dataBarItem:z,trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ze,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:oe(us(x))})]}),children:[(0,X.jsx)(`div`,{className:`dd-header`,children:b(`language`)}),S.map(e=>(0,X.jsx)($t,{active:x===e.code,onClick:()=>{C(e.code),k(!1)},children:e.nativeName},e.code)),_?.onLocaleModalOpen?(0,X.jsxs)($t,{onClick:()=>{k(!1),_.onLocaleModalOpen?.()},children:[(0,X.jsx)($e,{}),` `,b(`localeGetMore`)]}):null]});if(z===`host:theme`){let e=_?.themes??[],n=_?.theme??null;return(0,X.jsx)(Qt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:A,onOpenChange:t=>{j(t),t&&e.length===0&&_?.reloadThemes?.()},tip:V(b(`theme`)),caret:!1,triggerClassName:`bar-item chip`,onContextMenu:R,dataBarItem:z,trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(H,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:V(b(`theme`))})]}),children:(()=>{let t=e.filter(e=>e.group===`classic`),r=e.filter(e=>e.group!==`classic`),i=e=>{let t=kn(x)?e.name:e.nameEn??e.name,n=e.scheme===`light`?b(`themeLight`):e.scheme===`dark`?b(`themeDark`):``;return n?kn(x)?`${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:b(`themeGroupClassics`)}),t.map(e=>(0,X.jsx)($t,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),j(!1)},children:i(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:t.length>0?b(`themeGroupBuiltin`):b(`theme`)}),(0,X.jsx)($t,{active:n===null,onClick:()=>{_?.onThemeChange?.(null),j(!1)},children:b(`themeDefault`)}),r.map(e=>(0,X.jsx)($t,{active:n===e.id,onClick:()=>{_?.onThemeChange?.(e.id),j(!1)},children:i(e)},e.id))]})})()})}if(z===`host:update`){let e=_?.updatesCount??0;return _?.managed?(0,X.jsxs)(`span`,{className:`bar-item chip`,title:b(`updatesManaged`),"data-tip":b(`updatesManaged`),onContextMenu:R,"data-bar-item":z,children:[(0,X.jsx)($e,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:oe(`v${_?.appVersion??n.update?.current??`…`}`)})]}):(0,X.jsxs)(Qt,{direction:t===`bottom`?`up`:`down`,align:t===`right`?`right`:`left`,open:ee,onOpenChange:e=>{te(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},tip:V(b(`update`)),fit:!0,caret:!1,triggerClassName:`bar-item chip`,onContextMenu:R,dataBarItem:z,trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($e,{className:`bar-item-icon`}),(0,X.jsx)(`span`,{className:`chip-sub bar-item-text`,children:oe(`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:b(`update`)}),_?.renderUpdateBody?.(),_?.renderAllUpdatesBody?.()]})}let U=null,se=e.label,ce=null,W=!1,ue=!1,de=``,pe,G;switch(z){case`host:chat`:U=(0,X.jsx)(Se,{className:`bar-item-icon`}),se=V(b(`chat`)),W=r===`chat`,ue=!0,G=()=>a?.(`chat`);break;case`host:terminal`:U=(0,X.jsx)(B,{className:`bar-item-icon`}),se=V(b(`terminal`)),W=r===`terminal`,ue=!0,G=()=>a?.(`terminal`);break;case`host:git`:U=(0,X.jsx)(Ve,{className:`bar-item-icon`}),se=V(b(`scmTab`)),W=r===`git`,ue=!0,G=()=>a?.(`git`);break;case`host:new-chat`:U=(0,X.jsx)(q,{className:`bar-item-icon`}),se=V(b(`newChat`)),de=`chip newchat`,G=()=>{a?.(`chat`),$({type:`new_chat`}),wr()};break;case`host:new-ephemeral-chat`:if(T)return null;U=(0,X.jsx)(Rt,{className:`bar-item-icon`}),se=V(b(`newChatEphemeral`)),de=`chip newchat ephemeral-chat-btn`,G=()=>{a?.(`chat`),$({type:`new_chat`,ephemeral:!0}),wr()};break;case`host:history`:if(r&&r!==`chat`)return null;U=(0,X.jsx)(Ce,{className:`bar-item-icon`}),se=V(b(`openHistory`)),de=`panel-toggle`,G=()=>o?.(`left`);break;case`host:files`:if(r&&r!==`chat`)return null;U=(0,X.jsx)(He,{className:`bar-item-icon`}),se=V(b(`openFiles`)),de=`panel-toggle has-label`,G=()=>o?.(`right`);break;case`host:open-project`:U=(0,X.jsx)(Ue,{className:`bar-item-icon`}),se=V(b(`openProject`)),de=`chip open-project`,W=!!p,G=()=>u?.();break;case`host:search`:U=(0,X.jsx)(fe,{className:`bar-item-icon`}),se=V(b(`searchGlobal`)),de=`chip`,G=()=>c?.();break;case`host:tasks`:U=(0,X.jsx)(je,{className:`bar-item-icon`}),se=V(b(`bgTasks`)),de=`chip bg-task-chip`,n.bgServers.length>0&&(ce=(0,X.jsx)(`span`,{className:`bg-task-badge bar-item-badge`,children:n.bgServers.length})),G=()=>l?.();break;case`host:zen-mode`:U=(0,X.jsx)(qe,{className:`bar-item-icon`}),se=V(b(`zenMode`)),de=`chip chip-zen`,W=!!v,pe=b(`zenModeTip`),G=()=>y?.();break;case`host:settings`:U=(0,X.jsx)(le,{className:`bar-item-icon`}),se=V(b(`settings`)),de=`chip`,G=()=>s?.();break;case`host:plugins`:U=(0,X.jsx)(Ct,{className:`bar-item-icon`}),se=V(b(`pluginMenuTitle`)),de=`chip`,G=e=>{d?d(e.currentTarget):s?.(`plugins`)};break;case`host:github`:U=(0,X.jsx)(Be,{className:`bar-item-icon`}),se=V(`GitHub`),de=`chip github`,G=()=>window.open(`https://github.com/xing-shuyin/pi-web-ui`,`_blank`,`noreferrer,noopener`);break;case`host:cwd`:U=(0,X.jsx)(He,{className:`bar-item-icon`}),se=oe(N?.cwd?N.cwd.split(/[/\\]/).pop()||N.cwd:b(`openProject`)),de=`status-item status-cwd`,W=!!p,G=()=>u?.();break;case`host:plugin-status`:if(n.statuses.length===0)return null;U=(0,X.jsx)(It,{className:`bar-item-icon`}),se=oe(n.statuses.map(e=>e.text).join(` · `)),de=`status-item ext-status`;break;default:if(e.kind===`view`){let t=e.view??``;W=r===t,ue=!0;let o=(i??n.plugins??[]).find(t=>`plugin:${t.id}`===e.source);de=`plugin-tab${o?.error?` broken`:``}`,o?.error&&(pe=`${e.label}: ${o.error}`);let s=e.iconSvg||o?.iconSvg,c=e.icon||o?.icon;U=s?(0,X.jsx)(Ni,{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,G=()=>a?.(t)}else{let n=e.iconSvg,r=e.icon;de=t===`bottom`?`status-item status-action chip`:`chip`,U=n?(0,X.jsx)(Ni,{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&&(ce=(0,X.jsx)(`span`,{className:`bar-item-badge`,children:e.badge})),G=()=>m?.(e)}}let K=pe??e.hint??se,me=[`bar-item`,ue?`tb-tab${W?` active`:``}`:``,de,W&&!ue?`active`:``].filter(Boolean).join(` `);return(0,X.jsxs)(`button`,{type:`button`,role:ue?`tab`:void 0,"aria-selected":ue?W:void 0,"aria-haspopup":z===`host:plugins`?`menu`:void 0,"aria-expanded":z===`host:plugins`?!!f:void 0,className:me,title:K,"data-tip":K,"aria-label":se,onClick:G,onContextMenu:R,"data-bar-item":z,children:[U,(0,X.jsx)(`span`,{className:`bar-item-text`,children:se}),ce]})}var fs={name:`@earendil-works/pi-coding-agent`,kind:`pi-core`,current:``,latest:null,upToDate:!1};function ps({anchorRef:e,open:t,onClose:n,children:r}){let{panelRef:i,style:a,measure:o}=Wo({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 ms(){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 hs({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,zenMode:C,onToggleZenMode:w}){let{locale:T,setLocale:E,t:D,packs:O}=Xn(),[k,A]=(0,g.useState)(!1),[j,ee]=(0,g.useState)(!1),[te,M]=(0,g.useState)(null),N=go(`cwd`),P=go(`workspaceRoots`),I=_o(),L=(0,g.useRef)(null),ne=t=>!e.tabs||t===`chat`||e.tabs.includes(t),re=[...a??[]].filter(e=>(e.source!==`host`||e.id!==`host:brand`)&&!ma(e)),ie=new Set([...i??[],...a??[]].filter(e=>ma(e)&&!e.hidden).map(e=>e.source.slice(7))),R=new Map((e.settings?.uiLayout?.order??[]).map((e,t)=>[e,t])),z=r.map((e,t)=>({id:e.id,index:t})).sort((e,t)=>(R.get(`${e.id}:__view`)??1e6+e.index)-(R.get(`${t.id}:__view`)??1e6+t.index)).map(e=>e.id),ae=i===void 0?[`host:history`,`host:brand`,`host:engine`,`host:open-project`,`host:chat`,`host:terminal`,`host:git`,`host:plugins`,`host:search`,`host:browser`,`host:tasks`,`host:zen-mode`,`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})),V=(ne(`plugins`)?r:[]).filter(e=>e.view!==!1&&e.error&&!ae.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:[]})),oe=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`}),wr(),!0;case`host:new-ephemeral-chat`:return c(`chat`),$({type:`new_chat`,ephemeral:!0}),wr(),!0;case`host:open-project`:return ee(!0),!0;case`host:search`:return p(),!0;case`host:tasks`:return f(),!0;case`host:zen-mode`:return w?.(),!0;case`host:settings`:return u(),!0;case`host:plugins`:return M(L.current?{rect:L.current.getBoundingClientRect(),el:L.current}:null),!0;default:return!1}},U=(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:D(`moveToBottom`),kind:`action`,order:10,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-left`,slot:`contextmenu.topbar`,source:`host`,label:D(`moveToLeft`),kind:`action`,order:20,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:move-right`,slot:`contextmenu.topbar`,source:`host`,label:D(`moveToRight`),kind:`action`,order:30,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},{id:`host:hide-item`,slot:`contextmenu.topbar`,source:`host`,label:D(`uiLayoutRestore`),kind:`action`,order:40,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]},...o??[]];Wa({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:se}=ho(),ce=vo(),W=yo(),[ue,de]=(0,g.useState)(!1);(0,g.useEffect)(()=>{ue&&e.status===`open`&&de(!1)},[ue,e.status]);let[pe,G]=(0,g.useState)(!1),[K,me]=(0,g.useState)(!1),[he,J]=(0,g.useState)(!1),[ge,_e]=(0,g.useState)(!1),ve=tr(),ye=es(),[be,Y]=(0,g.useState)(!1),xe=(0,g.useRef)(new Set);(0,g.useEffect)(()=>{if(xe.current.size===0)return;let t=!1;for(let n of Array.from(xe.current)){let r=e.terminals.find(e=>e.id===n);r&&!r.running&&(xe.current.delete(n),t=!0)}t&&e.ready&&($({type:`check_update`}),$({type:`check_updates_all`,force:!0}))},[e.terminals,e.ready]);let we=()=>{if(!e.ready)return;let n=D(`updateTabTitle`),r={name:n,command:`npm i -g pi-web-ui@latest`,cwd:"${pwd}"},i=e.terminals.find(e=>e.title===n);if(i)xe.current.add(i.id),t.restart(i.id),$({type:`run_command`,terminalId:i.id,conversationId:i.conversationId,command:r,cols:80,rows:24});else{let i=Ht();xe.current.add(i),t.create({id:i,conversationId:e.activeConversationId||e.state?.conversationId||``,title:n,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:r})}_e(!1),c(`terminal`)},Te=(n,r)=>{if(!e.ready||n.length===0)return;let i={name:r,command:Bt(n),cwd:"${pwd}"},a=e.terminals.find(e=>e.title===r);if(a)xe.current.add(a.id),t.restart(a.id),$({type:`run_command`,terminalId:a.id,conversationId:a.conversationId,command:i,cols:80,rows:24});else{let n=Ht();xe.current.add(n),t.create({id:n,conversationId:e.activeConversationId||e.state?.conversationId||``,title:r,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:i})}_e(!1),c(`terminal`)},Ee=e.updatesAll??[],De=e.updatesSdk,Oe=De&&De.newerInstalled?{running:De.running,installed:De.newerInstalled}:null,ke=De?.bundledInUse===!0,Ae=Ee.find(e=>e.kind===`pi-core`&&!e.error),Me=ke&&(!Ae||!Ae.upToDate),Ne=Me&&!Ae,Pe=Ee.filter(e=>!e.upToDate&&!e.error).length,Fe=Ee.filter(e=>!e.upToDate&&!e.error&&e.kind!==`webui`),Ie=e=>e.kind===`git-extension`&&e.source?e.source:e.name,Le=e=>e.kind===`git-extension`&&e.source&&e.source!==e.name?`${e.source} (${e.name})`:e.name,Re=e=>{let t=e.replace(/ \([0-9a-f]{7}\)$/,``);return/^[0-9a-f]{7}$/.test(t)?``:t},We=e=>(e.match(/\(([0-9a-f]{7})\)$/)??e.match(/^([0-9a-f]{7})$/))?.[1]??null,Ge=(e,t)=>{if(!t)return Re(e);let n=Re(e),r=Re(t);if(n!==r)return`${n} → ${r}`;let i=We(e),a=We(t);return i&&a&&i!==a?n?`${n} (${i} → ${a})`:`${i} → ${a}`:n},Ke=()=>(0,X.jsxs)(`div`,{className:`dd-updates-all`,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:D(`updatesAllTitle`)}),e.updatesAll===null?(0,X.jsx)(`div`,{className:`dd-note`,children:D(`checkingUpdate`)}):Ee.length===0?(0,X.jsx)(`div`,{className:`dd-note`,children:D(`updatesAllUpToDate`)}):(0,X.jsx)(`ul`,{className:`dd-all-list`,children:Ee.map(e=>{let t=Oe!=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:()=>Te([e],D(`updatePkgTabTitle`,{name:e.name})),children:D(`updateBtn`)}),(0,X.jsx)(`span`,{className:`dd-all-name`,title:Le(e),children:Ie(e)}),(0,X.jsxs)(`span`,{className:`dd-all-meta`,children:[(0,X.jsx)(`span`,{className:`dd-all-kind`,children:e.kind===`webui`?D(`kindWebUi`):e.kind===`pi-core`?D(`kindPiCore`):e.kind===`git-extension`?D(`kindGitExtension`):e.kind===`plugin`?D(`kindPlugin`):D(`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?e.kind===`pi-core`&&e.current===`unknown`?D(`piCoreUndetected`):D(`updateCheckFailed`):e.kind===`git-extension`?e.upToDate?Re(e.current):Ge(e.current,e.latest):e.kind===`plugin`?e.upToDate?e.current.startsWith(`v`)?e.current:Re(e.current):Ge(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:D(`piCoreSplitRun`,{running:Oe.running})})]})]},`${e.kind}:${e.name}`)})}),Oe&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:D(`piSdkSplitNote`,{running:Oe.running,installed:Oe.installed})}),Me&&(0,X.jsx)(`div`,{className:`dd-note`,children:D(`piSdkBundledNote`,{running:De.running})}),(0,X.jsxs)(`div`,{className:`dd-actions`,children:[Ne&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Te([fs],D(`installGlobalEngineTabTitle`)),children:D(`installGlobalEngineBtn`)}),Fe.length>0&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,style:{flex:1},onClick:()=>Te(Fe,D(`updateAllTabTitle`)),children:D(`updateAllBtn`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,style:Fe.length>0?{flex:1}:void 0,onClick:()=>$({type:`check_updates_all`,force:!0}),children:D(`updatesAllRefresh`)})]})]}),Je=()=>{let t=$o(e.update?.latest??ye.version),n=(0,X.jsx)(`a`,{className:`dd-refresh dd-more-link`,href:t,target:`_blank`,rel:`noreferrer noopener`,children:D(`updateDesktopManual`)});if(!ye.bridge)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:D(`updateDesktopNoBridge`)}),n]});switch(ye.state){case`checking`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:D(`updateDesktopChecking`)}),n]});case`available`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:D(`updateDesktopAvailable`,{version:ye.version??e.update?.latest??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ye.download(),children:D(`updateDesktopDownload`)}),n]});case`downloading`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note`,children:D(`updateDesktopDownloading`,{n:ye.percent})}),n]});case`downloaded`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note ok`,children:D(`updateDesktopDownloaded`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ye.quitAndInstall(),children:D(`updateDesktopInstall`)}),n]});case`up-to-date`:return(0,X.jsx)(`div`,{className:`dd-note ok`,children:D(`upToDate`)});case`error`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dd-note warn`,children:D(`updateDesktopError`,{error:ye.message??``})}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>ye.check(),children:D(`updateDesktopCheck`)}),n]});default:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:()=>ye.check(),children:D(`updateDesktopCheck`)}),n]})}},Ye=()=>(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:D(`currentVersion`)}),(0,X.jsxs)(`b`,{children:[`v`,e.update?.current??`…`]})]}),(0,X.jsxs)(`div`,{className:`dd-row`,children:[(0,X.jsx)(`span`,{children:D(`latestVersion`)}),(0,X.jsx)(`b`,{children:e.update===null?D(`checkingUpdate`):e.update.error?e.update.error:e.update.latest?`v${e.update.latest}`:D(`checkingUpdate`)})]}),e.update&&e.update.upToDate&&(0,X.jsx)(`div`,{className:`dd-note ok`,children:D(`upToDate`)}),e.update&&!e.update.upToDate&&e.update.latest&&(0,X.jsx)(`div`,{className:`dd-note warn`,children:D(`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:D(`updateJustPublished`,{version:e.update.latest??``})}),e.update&&!e.update.upToDate&&e.update.latest&&!ve&&(0,X.jsx)(`div`,{className:`dd-note`,children:D(`updateTerminalHint`)}),e.update&&!e.update.upToDate&&e.update.latest&&ve&&(0,X.jsx)(`div`,{className:`dd-note`,children:D(`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?D(`checkingUpdate`):D(`checkUpdate`)}),e.update&&!e.update.upToDate&&e.update.latest&&!ve&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,onClick:we,children:D(`updateNow`)}),e.update&&!e.update.upToDate&&e.update.latest&&ve&&Je(),W&&(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh accent`,disabled:ue,title:D(`restartServiceTip`,{name:W.name}),onClick:()=>{ue||(de(!0),$({type:`restart_service`}))},children:D(ue?`restartingService`:`restartService`)})]})]}),Xe=ms(),Ze={"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":D(`openProject`),onClick:()=>ee(!0),children:[(0,X.jsx)(Ue,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`openProject`)})]}),"host:history":n===`chat`&&ne(`history`)?(0,X.jsx)(`button`,{type:`button`,className:`panel-toggle`,"data-tip":D(`openHistory`),"aria-label":D(`openHistory`),onClick:()=>l(`left`),children:(0,X.jsx)(Ce,{})}):null,"host:files":n===`chat`&&ne(`files`)?(0,X.jsxs)(`button`,{type:`button`,className:`panel-toggle has-label`,"data-tip":D(`openFiles`),"aria-label":D(`openFiles`),onClick:()=>l(`right`),children:[(0,X.jsx)(He,{}),(0,X.jsx)(`span`,{children:D(`openFiles`)})]}):null,"host:new-chat":ne(`new-chat`)?(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat`,"data-tip":D(`newChatTip`),onClick:()=>{c(`chat`),$({type:`new_chat`}),wr()},children:[(0,X.jsx)(q,{}),(0,X.jsx)(`span`,{children:D(`newChat`)})]}):null,"host:new-ephemeral-chat":I?null:(0,X.jsxs)(`button`,{type:`button`,className:`chip newchat ephemeral-chat-btn`,"data-tip":D(`newChatEphemeralTip`),onClick:()=>{c(`chat`),$({type:`new_chat`,ephemeral:!0}),wr()},children:[(0,X.jsx)(Rt,{}),(0,X.jsx)(`span`,{children:D(`newChatEphemeral`)})]}),"host:chat":(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`chat`,className:`tb-tab${n===`chat`?` active`:``}`,"data-tip":D(`chat`),onClick:()=>c(`chat`),children:[(0,X.jsx)(Se,{}),(0,X.jsx)(`span`,{children:D(`chat`)})]}),"host:terminal":ne(`terminal`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`terminal`,className:`tb-tab${n===`terminal`?` active`:``}`,"data-tip":D(`terminal`),onClick:()=>c(`terminal`),children:[(0,X.jsx)(B,{}),(0,X.jsx)(`span`,{children:D(`terminal`)})]}):null,"host:git":ne(`git`)?(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n===`git`,className:`tb-tab${n===`git`?` active`:``}`,"data-tip":D(`scmTab`),onClick:()=>c(`git`),children:[(0,X.jsx)(Ve,{}),(0,X.jsx)(`span`,{children:D(`scmTab`)})]}):null,"host:plugins":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":D(`pluginMenuTitle`),"aria-haspopup":`menu`,"aria-expanded":te!==null,onClick:e=>{let t=e.currentTarget;M(e=>e?.el===t?null:{rect:t.getBoundingClientRect(),el:t})},children:[(0,X.jsx)(Ct,{"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`pluginMenuTitle`)})]}),"host:search":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":D(`searchGlobalTip`),onClick:p,children:[(0,X.jsx)(fe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`searchGlobal`)})]}),"host:browser":e.settings?.disabledAgentTools?.includes(`browser_page`)??!1?null:(0,X.jsx)(Dr,{}),"host:tasks":(0,X.jsxs)(`button`,{type:`button`,className:`chip bg-task-chip`,"data-tip":D(`bgTasksTip`),onClick:f,children:[(0,X.jsx)(je,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`bgTasks`)}),e.bgServers.length>0&&(0,X.jsx)(`span`,{className:`bg-task-badge`,children:e.bgServers.length})]}),"host:zen-mode":(0,X.jsxs)(`button`,{type:`button`,className:`chip chip-zen${C?` active`:``}`,"data-tip":D(`zenModeTip`),onClick:w,"aria-label":D(`zenMode`),"aria-pressed":C,children:[(0,X.jsx)(qe,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`zenMode`)})]}),"host:settings":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":D(`settingsTitle`),onClick:u,children:[(0,X.jsx)(le,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`settings`)})]}),"host:sound":(0,X.jsxs)(Qt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`sound`)})]}),tip:D(`sound`),open:pe,onOpenChange:G,caret:!1,children:[(0,X.jsx)(Qn,{settings:m,onChange:h,onPreview:_}),(0,X.jsx)(wi,{})]}),"host:language":(0,X.jsxs)(Qt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ze,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:Hn(T)})]}),tip:D(`language`),open:K,onOpenChange:me,caret:!1,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:D(`language`)}),O.map(e=>(0,X.jsx)($t,{active:T===e.code,onClick:()=>{E(e.code),me(!1)},children:e.nativeName},e.code)),(0,X.jsxs)($t,{onClick:()=>{me(!1),Y(!0)},children:[(0,X.jsx)($e,{}),` `,D(`localeGetMore`)]})]}),"host:theme":(0,X.jsx)(Qt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(H,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:D(`theme`)})]}),tip:D(`theme`),open:he,caret:!1,onOpenChange:e=>{J(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=kn(T)?e.name:e.nameEn??e.name,n=e.scheme===`light`?D(`themeLight`):e.scheme===`dark`?D(`themeDark`):``;return n?kn(T)?`${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:D(`themeGroupClassics`)}),e.map(e=>(0,X.jsx)($t,{active:y===e.id,onClick:()=>{b(e.id),J(!1)},children:n(e)},e.id))]}),(0,X.jsx)(`div`,{className:`dd-header`,children:e.length>0?D(`themeGroupBuiltin`):D(`theme`)}),(0,X.jsx)($t,{active:y===null,onClick:()=>{b(null),J(!1)},children:D(`themeDefault`)}),t.map(e=>(0,X.jsx)($t,{active:y===e.id,onClick:()=>{b(e.id),J(!1)},children:n(e)},e.id))]})})()}),"host:update":ce?(0,X.jsxs)(`span`,{className:`chip`,"data-tip":D(`updatesManaged`),children:[(0,X.jsx)($e,{}),(0,X.jsxs)(`span`,{className:`chip-sub`,children:[`v`,se??e.update?.current??`…`]})]}):(0,X.jsxs)(Qt,{trigger:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($e,{}),(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:D(`updateAvailable`,{version:e.update.latest??``})}),Pe>0&&(0,X.jsx)(`span`,{className:`update-badge`,children:D(`updatesAllBadge`,{n:Pe})})]}),tip:D(`update`),open:ge,caret:!1,onOpenChange:e=>{_e(e),e&&($({type:`check_update`}),$({type:`check_updates_all`}))},fit:!0,children:[(0,X.jsx)(`div`,{className:`dd-header`,children:D(`update`)}),Ye(),Ke()]}),"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":D(`githubRepo`),children:(0,X.jsx)(Be,{})}),"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)(cs,{direction:`down`,align:`left`,caret:!1,bar:`top`}),"host:ctx":(0,X.jsx)(`span`,{className:`chip`,"data-tip":D(`contextUsage`),children:(0,X.jsx)(`span`,{className:`chip-sub`,children:(e.state?.stats?.contextUsage?.tokens??0)>0?`${e.state?.stats?.contextUsage?.tokens}`:D(`contextUsage`)})}),"host:cost":(()=>{let t=Ki(e.state?.stats?.cost??0,{fixedDigits:4});return(0,X.jsx)(`span`,{className:`chip`,"data-tip":t.tooltip||D(`cumulativeCost`),children:(0,X.jsxs)(`span`,{className:`chip-sub`,children:[t.symbol,t.value]})})})(),"host:cwd":(0,X.jsxs)(`button`,{type:`button`,className:`chip`,"data-tip":e.state?.cwd??``,onClick:()=>ee(!0),children:[(0,X.jsx)(He,{}),(0,X.jsx)(`span`,{className:`chip-sub`,children:e.state?.cwd?.split(/[/\\]/).pop()||e.state?.cwd})]})},et=new Set([`host:search`,`host:tasks`,`host:settings`,`host:plugins`]),tt=new Set([`host:sound`,`host:language`,`host:theme`,`host:update`,`host:browser`,`host:engine`]),nt=e=>et.has(e)&&!ne(e.slice(5)),rt=e=>{if(e.kind===`view`){if(!ne(`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=>U(t,e.id,e.label),children:[(0,X.jsx)(Ni,{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=>U(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=>U(t,e.id,e.label),children:[(0,X.jsx)(Ni,{icon:e.icon,iconSvg:e.iconSvg}),(0,X.jsx)(`span`,{children:e.label})]},e.id)},it=[];for(let t of ae){if(t.entry?.hidden||nt(t.id))continue;let i=null;t.entry?i=(0,X.jsx)(ds,{entry:t.entry,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onOpenPanel:l,onOpenSettings:u,onOpenGlobalSearch:p,onOpenBgTasks:f,onOpenProjectPicker:()=>ee(!0),isProjectPickerOpen:j,onOpenPluginMenu:e=>M(t=>t?.el===e?null:{rect:e.getBoundingClientRect(),el:e}),isPluginMenuOpen:te!==null,onUiAction:s,uiContextEntries:o,zenMode:C,onToggleZenMode:w,dropdownProps:{sound:m,onSoundChange:h,onSoundPreview:_,theme:y,themes:v,onThemeChange:b,reloadThemes:x,onLocaleModalOpen:()=>Y(!0),renderUpdateBody:Ye,renderAllUpdatesBody:Ke,updatesCount:Pe,managed:ce,appVersion:se}},t.id):t.id.startsWith(`host:`)&&Ze[t.id]&&(i=Ze[t.id]),i&&it.push({id:t.id,entry:t.entry,node:i})}for(let t of V){let i=(0,X.jsx)(ds,{entry:t,bar:`top`,chat:e,view:n,plugins:r,onViewChange:c,onUiAction:s,uiContextEntries:o},t.id);i&&it.push({id:t.id,entry:t,node:i})}let at=e=>e.entry?.align??`start`,[ot,st]=(0,g.useState)(()=>new Set),ct=(0,g.useRef)(null),lt=(0,g.useRef)(new Map),ut=it.filter(e=>!ot.has(e.id)),dt=Xe?ut.filter(e=>Ra.has(e.id)):[],ft=Xe?ut.filter(e=>!Ra.has(e.id)):ut,pt=Xe?it.filter(e=>!Ra.has(e.id)):it,mt=[...pt.filter(e=>at(e)===`start`),...pt.filter(e=>at(e)===`center`),...pt.filter(e=>at(e)===`end`)],ht=mt.filter(e=>!ot.has(e.id)),gt=(0,g.useRef)(mt),_t=(0,g.useRef)(ht);(0,g.useLayoutEffect)(()=>{gt.current=mt,_t.current=ht});let vt=()=>{let e=ct.current;if(!e||typeof ResizeObserver>`u`)return;let t=Array.from(e.children).filter(e=>!e.classList.contains(`tb-spacer`)),n=_t.current;t.length===n.length&&n.forEach((e,n)=>lt.current.set(e.id,t[n].offsetWidth));for(let n of t){let t=n;t.offsetWidth>0&&e.clientWidth>0&&t.offsetLeft+t.offsetWidth/2<Math.min(220,e.clientWidth/2)?t.setAttribute(`data-tip-align`,`right`):t.removeAttribute(`data-tip-align`)}let r=Number.parseFloat(getComputedStyle(e).columnGap)||0,i=gt.current,a=Ba(i.map(e=>({id:e.id,width:e.entry?lt.current.get(e.id)??0:0})),e.clientWidth,r,0,da);st(e=>e.size===a.size&&[...a].every(t=>e.has(t))?e:a)},yt=`${ut.map(e=>`${e.id}:${e.entry?.label??``}`).join(`|`)}|${n}|${(e.tabs??[]).join(`,`)}|${Xe?`m`:`d`}`;(0,g.useLayoutEffect)(vt,[yt]),(0,g.useEffect)(()=>{let e=ct.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>vt());return t.observe(e),()=>t.disconnect()},[yt]);let bt=ft.filter(e=>at(e)===`start`),xt=ft.filter(e=>at(e)===`center`),St=ft.filter(e=>at(e)===`end`),wt=it.filter(e=>ot.has(e.id)&&e.entry).map(e=>e.entry),Tt=new Map;[...i??[],...a??[]].forEach((e,t)=>{Tt.has(e.id)||Tt.set(e.id,t)});let Et=za([...re,...wt],e=>Tt.get(e)??999999),Dt=e=>e.icon&&!/[a-z]/i.test(e.icon)?e.icon:null,Ot=e.settings?.uiLayout?.topbarText===!1;return(0,X.jsxs)(`header`,{className:`topbar${Ot?` no-labels`:``}`,"data-pi-anchor":`topbar`,children:[(0,X.jsxs)(`div`,{className:`topbar-flow`,ref:ct,role:`toolbar`,"aria-label":D(`viewSwitch`),children:[bt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),(xt.length>0||St.length>0)&&(0,X.jsx)(`span`,{className:`tb-spacer${xt.length===0&&St.length>0?` tb-spacer-end`:``}`,"aria-hidden":`true`}),xt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),xt.length>0&&(0,X.jsx)(`span`,{className:`tb-spacer${St.length>0?` tb-spacer-end`:``}`,"aria-hidden":`true`}),St.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id))]}),(Et.length>0||it.length>0)&&(0,X.jsxs)(`div`,{className:`plugin-topbar-more`,children:[(0,X.jsx)(`button`,{ref:L,type:`button`,className:`plugin-topbar-item`,"aria-haspopup":`menu`,"aria-expanded":k,"aria-label":D(`pluginTopbarMore`),"data-tip":D(`pluginTopbarMore`),onClick:()=>A(e=>!e),children:(0,X.jsx)(Lt,{})}),(0,X.jsxs)(ps,{anchorRef:L,open:k,onClose:()=>A(!1),children:[Et.map(e=>{let t=e.source===`host`&&tt.has(e.id)?Ze[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:D(`githubRepo`),onClick:()=>A(!1),children:[(0,X.jsx)(Be,{}),(0,X.jsx)(`span`,{children:`GitHub`})]},e.id);if(e.source===`host`){let t=Ze[e.id];if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>A(!1),children:t},e.id)}else{let t=rt(e);if(t)return(0,X.jsx)(`div`,{className:`plugin-topbar-menu-keep`,onClick:()=>A(!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:[Dt(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:Dt(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=>{A(!1),oe(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:()=>{A(!1),oe(e)||s?.(e)},children:[Dt(e)?(0,X.jsx)(`span`,{className:`plugin-icon-glyph`,children:Dt(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:()=>{A(!1),S()},children:[(0,X.jsx)(Qe,{}),(0,X.jsx)(`span`,{className:`tb-row-text`,children:D(`uiIconEdit`)})]})]})]}),dt.map(e=>(0,X.jsx)(g.Fragment,{children:e.node},e.id)),be&&(0,X.jsx)(Ko,{onClose:()=>Y(!1)}),te&&(0,X.jsx)(Go,{anchorRect:te.rect,anchorEl:te.el,plugins:r,pinnedIds:ie,orderedPluginIds:z,onTogglePin:(t,n)=>$({type:`set_settings`,uiLayout:ha(e.settings?.uiLayout,t,n)}),onReorder:t=>$({type:`set_settings`,uiLayout:ga(e.settings?.uiLayout,t)}),onOpenView:e=>{M(null),c(`plugin:${e}`)},onManagePlugins:d,onClose:()=>M(null)}),j&&(0,X.jsx)(Bo,{open:!0,currentCwd:N,pathCompletions:e.pathCompletions??[],workspaceRoots:P,onClose:()=>ee(!1),onSelectDirectory:e=>$({type:`set_cwd`,path:e}),onCreateProject:e=>$({type:`make_dir`,path:e,setAsCwd:!0})})]})}function gs(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 _s(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 vs(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 ys(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 bs(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 xs(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 Ss(e,t){let n=xs(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 Cs(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 ws(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 Ts(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 Es(e,t){let n=e.indexOf(t);return n<0?[...e]:[...e.slice(0,n),...e.slice(n+1)]}function Ds(e,t,n){return typeof n==`number`&&Number.isInteger(n)&&n>=0&&n<e.length&&e[n]===t?[...e.slice(0,n),...e.slice(n+1)]:Es(e,t)}function Os(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 ks(e){return`<quoted-text>\n${JSON.stringify(e)}\n</quoted-text>`}function As(e){let t=/^<quoted-text>\n([^\n]*)\n<\/quoted-text>$/.exec(e);if(!t)return null;try{return Os(JSON.parse(t[1]))}catch{return null}}function js(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function Ms(e,t=[],n=[],r=[]){let i=[],a=(e??``).trim();a&&i.push(a);for(let e of r)e&&i.push(`<attached-image name="${js(e)}" />`);for(let e of t){let t=(e??``).trim();t&&i.push(t)}for(let e of n)i.push(ks(e));return i.join(`
|
|
328
328
|
|
|
329
|
-
`)}function Ns(e){let t=e,n=[];for(;;){let e=/(?:^|\n\n)(<quoted-text>\n[^\n]*\n<\/quoted-text>)$/.exec(t),r=e?As(e[1]):null;if(!e||!r)break;n.unshift(r),t=t.slice(0,e.index)}let r=[];return t=t.replace(/(?:^|\n\n)?<attached-image name="([^"]*)"\s*\/>/g,(e,t)=>(r.push({type:`image`,name:t}),``)),t=t.replace(/(?:^|\n\n)?<file path="([^"]*)"(?:\s+size="[^"]*")?(?:\s+lines="(\d+)-(\d+)")?\s*\/>/g,(e,t,n,i)=>{let a=t.split(/[\\/]/).pop()??t,o=n&&i?{start:Number(n),end:Number(i)}:void 0;return r.push({type:`file`,name:a,path:t,lines:o}),``}),t=t.replace(/(?:^|\n\n)?<folder path="([^"]*)"\s*\/>/g,(e,t)=>{let n=t.split(/[\\/]/).pop()??t;return r.push({type:`folder`,name:n,path:t}),``}),t=t.replace(/(?:^|\n\n)?<browser-page url="([^"]*)" title="([^"]*)">[\s\S]*?<\/browser-page>/g,(e,t,n)=>(r.push({type:`page`,name:n||t,url:t}),``)),t=t.replace(/(?:^|\n\n)?<conversation-ref[^>]*title="([^"]*)"[^>]*>[\s\S]*?<\/conversation-ref>/g,(e,t)=>(r.push({type:`conversation`,name:t}),``)),t=t.replace(/(?:^|\n\n)?<vision-bridge>[\s\S]*?<\/vision-bridge>/g,()=>(r.push({type:`vision-bridge`,name:`视觉转写`}),``)),r.length>0&&(t=t.trim()),{text:t,quotes:n,...r.length?{attachments:r}:{}}}function Ps(){return{adds:[],removes:[]}}function Fs(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function Is(e,t){let n=(t??[]).filter(e=>e.mode===`quote`).map(e=>Os(e.quote)).filter(e=>e!==null),r=[],i=[];for(let e of t??[])if(e.mode!==`quote`){if(e.imageData){r.push(e.name||`image.png`);continue}if(e.fileData){let t=e.name||`file`;i.push(`<file path="${Fs(t)}" />`);continue}if(e.mode===`page`){let t=e.path||``,n=e.name||t;i.push(`<browser-page url="${Fs(t)}" title="${Fs(n)}"></browser-page>`);continue}if(e.mode===`conversation`){let t=e.name||e.conversationId||e.sessionPath||`conversation`;i.push(`<conversation-ref title="${Fs(t)}"></conversation-ref>`);continue}if(e.path){let t=e.lines?` lines="${e.lines.start}-${e.lines.end}"`:``;i.push(`<file path="${Fs(e.path)}"${t} />`)}}return Ms(e,i,n,r)}function Ls(e){let t=Ns(e);return`${t.text.trim()}\u0000${t.quotes.map(e=>`${e.role}:${e.messageId}:${e.text.trim()}`).join(`|`)}`}function Rs(e,t){return e===t||Ls(e)===Ls(t)}function zs(e,t){let n=0;for(let r of e)Rs(r,t)&&(n+=1);return n}function Bs(e,t){let n=t.trim(),r=0;for(let t of e)t.role===`user`&&(t.content.find(e=>e.type===`text`)?.text??``).trim()===n&&(r+=1);return r}function Vs(e){let{state:t,text:n,attachments:r,queue:i=!1,goalReviewing:a=!1}=e;if(!t||!t.isStreaming||t.delegateMode===!0)return!1;let o=(n??``).trim(),s=!!(r&&r.length>0);return!(!o&&!s||o.startsWith(`/`)||a&&!i)}function Hs(e,t,n){let r=n.now??Date.now();if(!Vs({state:t,text:n.text,attachments:n.attachments,queue:n.queue,goalReviewing:n.goalReviewing})||!t)return{tracker:e,state:t};let i=n.queue||n.engine===`dsh`?`followUp`:`steer`,a=Is(n.text,n.attachments),o=Ns(a).text.trim(),s=i===`steer`?t.queue.steering:t.queue.followUp,c=e.adds.filter(e=>e.conversationId===t.conversationId&&e.kind===i&&Rs(e.formattedText,a)).length,l=zs(s,a),u=Math.max(0,l-c),d=Bs(t.messages,o),f={conversationId:t.conversationId,kind:i,rawText:o,formattedText:a,baselineQueueMatches:u,baselineUserMsgMatches:d,createdAt:r},p=i===`steer`?{...t.queue,steering:[...t.queue.steering,a]}:{...t.queue,followUp:[...t.queue.followUp,a]};return{tracker:{adds:[...e.adds,f],removes:e.removes},state:{...t,queue:p}}}function Us(e,t,n){if(!t)return{tracker:e,state:t};let r=n.now??Date.now(),{kind:i,text:a,index:o}=n,s=Ds(i===`steer`?t.queue.steering:t.queue.followUp,a,o),c=e.adds,l=c.findIndex(e=>e.conversationId===t.conversationId&&e.kind===i&&Rs(e.formattedText,a));l>=0&&(c=[...c.slice(0,l),...c.slice(l+1)]);let u=zs(s,a),d={conversationId:t.conversationId,kind:i,text:a,index:o,expectedRemainingMatches:u,createdAt:r},f=i===`steer`?{...t.queue,steering:s}:{...t.queue,followUp:s};return{tracker:{adds:c,removes:[...e.removes,d]},state:{...t,queue:f}}}function Ws(e,t,n=Date.now()){if(e.adds.length===0&&e.removes.length===0)return{tracker:e,state:t};let r=t.conversationId;if(!t.isStreaming){let i=e.adds.filter(e=>e.conversationId!==r&&n-e.createdAt<15e3),a=e.removes.filter(e=>e.conversationId!==r&&n-e.createdAt<3e3);return i.length===e.adds.length&&a.length===e.removes.length?{tracker:e,state:t}:{tracker:{adds:i,removes:a},state:t}}let i=[...t.queue.steering],a=[...t.queue.followUp],o=!1,s=[];for(let t of e.removes){if(n-t.createdAt>=3e3)continue;if(t.conversationId!==r){s.push(t);continue}let e=t.kind===`steer`?i:a;if(zs(e,t.text)>t.expectedRemainingMatches){let n=Ds(e,t.text,t.index);if(n.length===e.length){let r=e.findIndex(e=>Rs(e,t.text));r>=0&&(n=[...e.slice(0,r),...e.slice(r+1)])}t.kind===`steer`?i=n:a=n,o=!0,s.push(t)}}let c=[],l=new Map;for(let s of e.adds){if(n-s.createdAt>=15e3)continue;if(s.conversationId!==r){c.push(s);continue}let e=s.kind===`steer`?i:a,u=`${s.kind}:${Ls(s.formattedText)}`,d=l.get(u)??0,f=zs(e,s.formattedText),p=Bs(t.messages,s.rawText),m=f>s.baselineQueueMatches+d,h=p>s.baselineUserMsgMatches;if(m){l.set(u,d+1);continue}h||(s.kind===`steer`?i.push(s.formattedText):a.push(s.formattedText),l.set(u,d+1),o=!0,c.push(s))}let u=c.length===e.adds.length&&s.length===e.removes.length?e:{adds:c,removes:s};return o?{tracker:u,state:{...t,queue:{steering:i,followUp:a}}}:{tracker:u,state:t}}function Gs(e,t){if(!t||e.adds.length===0)return{tracker:e,state:t};let n=t.conversationId,r=e.adds.filter(e=>e.conversationId===n);if(r.length===0)return{tracker:e,state:t};let i=[...t.queue.steering],a=[...t.queue.followUp];for(let e of r)e.kind===`steer`?i=Ds(i,e.formattedText):a=Ds(a,e.formattedText);return{tracker:{adds:e.adds.filter(e=>e.conversationId!==n),removes:e.removes},state:{...t,queue:{steering:i,followUp:a}}}}function Ks(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 qs=new Set;function Js(e){return qs.add(e),()=>{qs.delete(e)}}function Ys(e,t){for(let n of qs)try{n(e,t)}catch(e){console.error(`[tui-overlay-bridge] listener error:`,e)}}function Xs(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 Zs=null,Qs=new Set;function $s(){for(let e of Qs)e()}function ec(e){let t=(e??``).trim();t&&(Zs={name:t,status:`loading`},$s(),$({type:`get_tool_info`,name:t}))}function tc(){Zs!==null&&(Zs=null,$s())}function nc(e){Zs!==null&&Zs.name===e.name&&(Zs=Xs(e),$s())}function rc(e){return Qs.add(e),()=>{Qs.delete(e)}}function ic(){return Zs}function ac(){return(0,g.useSyncExternalStore)(rc,ic,ic)}function oc(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 sc={},cc=new Set;function lc(){for(let e of cc)e()}function uc(e){let t=(e??``).trim();t&&(sc[t]&&sc[t].status!==`loading`||(sc={...sc,[t]:{name:t,status:`loading`}},lc(),$({type:`get_tool_prompt`,name:t})))}function dc(e){let t=typeof e.name==`string`?e.name:``;t&&sc[t]&&(sc={...sc,[t]:oc(e)},lc())}function fc(e){if(!sc[e])return;let t={...sc};delete t[e],sc=t,lc()}function pc(e){return cc.add(e),()=>cc.delete(e)}function mc(e){return(0,g.useSyncExternalStore)(pc,()=>e?sc[e]??null:null)}var hc=Object.freeze({status:`idle`,messages:[]}),gc=new Map,_c=new Set,vc=16;function yc(){for(;gc.size>vc;){let e=gc.keys().next().value;if(e===void 0)break;gc.delete(e)}}function bc(){for(let e of _c)e()}function xc(e,t){let n=(e??``).trim();if(!n)return;let r=gc.get(n);(!r||r.status!==`loading`&&r.status!==`ready`)&&(gc.set(n,{status:`loading`,messages:r?.messages??[]}),yc(),bc(),$({type:`get_compacted_messages`,compactionMessageId:n,conversationId:t}))}function Sc(e){let t=e.compactionMessageId;t&&(e.error?gc.set(t,{status:`error`,messages:[],error:e.error}):gc.set(t,{status:`ready`,messages:e.messages??[]}),yc(),bc())}function Cc(e){let t=gc.get(e);return t?(gc.delete(e),gc.set(e,t),t):hc}function wc(e){return _c.add(e),()=>{_c.delete(e)}}function Tc(e){return(0,g.useSyncExternalStore)(wc,()=>Cc(e),()=>hc)}var Ec=`__piWebUiHost`,Dc=e=>new Promise(t=>setTimeout(t,e));async function Oc(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 Dc(100)}}var kc=Promise.resolve(),Ac=0;function jc(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 Dc(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=Ac>0?kc.then(i):i(),Ac++,kc=o.then(()=>{Ac--},()=>{Ac--}),o.catch(()=>{}),!0},models:{list:()=>i(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>sl(e)},compose(e){return Tr()?Er({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=Ic,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=Ic,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=Ht();return new Promise(t=>{let a=setTimeout(()=>{hl.delete(i),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));hl.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 Rc(Pc,String(e??``).trim(),t)},onTopbarAction(e,t){return Rc(Pc,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(tr())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 Oc(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(Bc,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Jc(String(e??``),t)},searchProviders:{register:e=>Xc(e),list:()=>Zc()},composerProviders:{register:e=>$c(e),list:()=>el()},onTheme:e=>ll(e),onLocale:e=>ul(e),onViewChange:e=>dl(e),setCostFormatter:e=>Wi(e),setCostCurrency:e=>Ui(e),getCostCurrency:()=>Hi()}}function Mc(e){try{let t=window;e?t[Ec]=e:delete t[Ec]}catch{}}var Nc=new Map,Pc=null;async function Fc(e,t){let n=Pc;Pc=e;try{return await t()}finally{Pc=n}}var Ic=void 0;function Lc(e,t){let n=Ic;Ic=e;try{return t()}finally{Ic=n}}function Rc(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=Nc.get(r);i||(i=new Set,Nc.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&Nc.delete(r)}}async function zc(e,t,n,r){let i=i=>{let a=Nc.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{Lc(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 Bc=`pi-web-ui:toast`,Vc=new Map,Hc=!1;function Uc(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 Wc(){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 Gc(e){try{if(Wc())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=Vc.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function Kc(){if(!Hc)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,Gc),Hc=!0}catch{}}function qc(){if(!(Vc.size>0||!Hc))try{window.removeEventListener(`keydown`,Gc)}catch{}finally{Hc=!1}}function Jc(e,t){if(typeof t!=`function`)return()=>{};let n=Uc(e);if(!n)return()=>{};let r=Vc.get(n.combo);r||(r=new Set,Vc.set(n.combo,r));let i=r;return i.add(t),Kc(),()=>{i.delete(t),i.size===0&&Vc.delete(n.combo),qc()}}var Yc=new Map;function Xc(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 Yc.set(t,n),()=>{Yc.get(t)===n&&Yc.delete(t)}}function Zc(){return[...Yc.values()].map(e=>({id:e.id,label:e.label}))}var Qc=new Map;function $c(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 Qc.set(t,n),()=>{Qc.get(t)===n&&Qc.delete(t)}}function el(){return[...Qc.values()].map(e=>({id:e.id,label:e.label}))}function tl(e){return Qc.get(String(e??``))}function nl(e){return Yc.get(String(e??``))}var rl=new Set,il=new Set,al=new Set,ol=new Set;function sl(e){return ol.add(e),()=>{ol.delete(e)}}function cl(e){for(let t of ol)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function ll(e){return typeof e==`function`?(rl.add(e),()=>{rl.delete(e)}):()=>{}}function ul(e){return typeof e==`function`?(il.add(e),()=>{il.delete(e)}):()=>{}}function dl(e){return typeof e==`function`?(al.add(e),()=>{al.delete(e)}):()=>{}}function fl(e){let t=String(e??``);for(let e of rl)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function pl(e){let t=String(e??``);for(let e of il)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function ml(e){let t=String(e??``);for(let e of al)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var hl=new Map;function gl(e){let t=hl.get(e.requestId);if(t){if(hl.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 _l=`modulepreload`,vl=function(e){return`/`+e},yl={},bl=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=vl(t,n),t=s(t),t in yl)return;yl[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`:_l,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)})},xl=`pi-web-ui:plugin-data`;function Sl(e,t){window.dispatchEvent(new CustomEvent(xl,{detail:{pluginId:e,payload:t}}))}function Cl(e){let t=t=>{let n=t.detail;e(n.pluginId,n.payload)};return window.addEventListener(xl,t),()=>window.removeEventListener(xl,t)}var wl=new Map,Tl=new Set,El=new Set,Dl=new Set,Ol=new Set,kl=-1;function Al(){return[...wl.values()]}function jl(){let e=Al();for(let t of El)t(e)}function Ml(){let e=[...Dl];for(let t of Ol)t(e)}function Nl(e){return Ol.add(e),e([...Dl]),()=>Ol.delete(e)}async function Pl(e,t){Dl.delete(e.id),Il.set(e.id,(Il.get(e.id)??0)+1),Ml();let n=await Vl(e,t);return jl(),n}function Fl(e){return El.add(e),e(Al()),()=>El.delete(e)}var Il=new Map;function Ll(e,t){let n=Il.get(e)??0;return Cn(`/plugins/${encodeURIComponent(e)}/client/entry.mjs?e=${t}${n>0?`&r=${n}`:``}`)}function Rl(e){let t=Promise.resolve();return(n,r)=>{let i=t.then(()=>Fc(n,()=>e(r)));return t=i.then(()=>void 0,()=>void 0),i}}var zl=Rl(e=>bl(()=>import(e),[]));async function Bl(e,t){if(!e.hasClient||e.error)return null;try{return(await zl(e.id,Ll(e.id,t))).default??null}catch(t){return console.error(`[plugin:${e.id}] 客户端 bundle 加载失败:`,t),null}}async function Vl(e,t){try{let n=(await zl(e.id,Ll(e.id,t))).default;return n&&typeof n.mount==`function`?(wl.set(e.id,{info:e,module:n}),!0):e.preload?(Tl.add(e.id),!0):(Dl.add(e.id),Ml(),console.error(`[plugin:${e.id}] entry.mjs 缺少 default.mount`),!1)}catch(t){return Dl.add(e.id),Ml(),console.error(`[plugin:${e.id}] 客户端加载失败:`,t),!1}}async function Hl(e,t){if(wl.has(e.id)||Tl.has(e.id))return!0;if(Dl.has(e.id)||!e.hasClient)return!1;let n=await Vl(e,t);return jl(),n}async function Ul(e,t){t!==kl&&(kl=t,wl.clear(),Tl.clear(),Dl.clear(),Il.clear(),Ml());let n=new Set(e.map(e=>e.id));for(let e of[...wl.keys()])n.has(e)||wl.delete(e);for(let e of[...Tl])n.has(e)||Tl.delete(e);for(let e of[...Dl])n.has(e)||Dl.delete(e);Ml(),await Promise.all(e.filter(e=>e.hasClient&&(e.view!==!1||e.preload)&&!e.error&&!wl.has(e.id)&&!Tl.has(e.id)&&!Dl.has(e.id)).map(e=>Vl(e,t))),jl()}function Wl(e,t){return{pluginId:e,send:n=>t({type:`plugin_message`,pluginId:e,payload:n}),onData:t=>Cl((n,r)=>{n===e&&t(r)})}}var Gl=[`debug`,`info`,`warn`,`error`];function Kl(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`get`}}}function ql(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`clear`}}}function Jl(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`&&Gl.includes(String(e.level)))}var Yl=new Map,Xl=new Set;function Zl(){for(let e of[...Xl])try{e()}catch{}}function Ql(e){return Xl.add(e),()=>Xl.delete(e)}function $l(e){return(Yl.get(e)??[]).map(e=>({...e}))}function eu(e,t){return Jl(t)?(Yl.set(e,t.logs.map(e=>({ts:e.ts,level:e.level,text:e.text}))),Zl(),!0):!1}function tu(e){switch(e){case`error`:return 6500;case`warning`:return 4200;default:return 2400}}var nu=[/^(已在工作目录|正在切换到工作目录|已切换到工作目录)[::]/,/^(Already in directory|Switching to directory|Switched to directory):/i,/该项目最近的对话.*(为你停在了空白新对话|为你停在了新对话)/,/The most recent conversation .* landed on a (blank|new) chat/i,/^分层上下文预算裁剪生效/,/^Tiered context budget pruning/i,/^发现 \d+ 个内置插件有更新可用/,/^\d+ built-in plugin\(s\) have updates available/i,/^已(创建文件|创建文件夹|重命名|删除|移动|复制)[::]/,/^(Created file|Created folder|Renamed|Deleted|Moved|Copied):/i,/^已重命名当前会话为/,/^Renamed current session to/i,/的消息正在投递,已为你保留该对话$/,/is still sending your message — kept in the running list$/i,/^(计划模式已开启|计划模式已关闭|已进入计划模式|已退出计划模式|审查者模式已开启|审查者模式已关闭)/,/^(Plan mode (enabled|disabled)|Entered plan mode|Exited plan mode|Delegate mode (enabled|disabled))/i,/^已切换(智能体预设|权限预设)/,/^Switched (agent|permission) preset/i];function ru(e){if(e.level!==`info`)return!1;let t=(e.text??``).trim(),n=(e.textEn??``).trim();return nu.some(e=>t&&e.test(t)||n&&e.test(n))}function iu(e,t,n=2){if(ru(t))return e;let r=`${t.level}:${(t.text??``).trim()}`,i=[...e.filter(e=>`${e.level}:${(e.text??``).trim()}`!==r),t];for(;i.length>n;){let e=i.findIndex(e=>e.level!==`error`);e>=0?i.splice(e,1):i.shift()}return i}function au(){return{flows:[],results:{}}}function ou(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 su(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:ou(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:ou(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 cu=`pi-web-ui:lang`;function lu(){try{return(localStorage.getItem(cu)??``).trim()}catch{return``}}var uu=`pi-web-ui:locale`,du=typeof WebSocket<`u`&&WebSocket.OPEN!==void 0?WebSocket.OPEN:1,fu=typeof WebSocket<`u`&&WebSocket.CLOSING!==void 0?WebSocket.CLOSING:2,pu=typeof WebSocket<`u`&&WebSocket.CLOSED!==void 0?WebSocket.CLOSED:3,mu=e=>!!(e&&e.readyState===du),hu=2e5,gu=2e5,_u=`LIVE_OMIT`,vu={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 yu(){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>gu?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 bu(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 xu(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 Su(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,latencyMs:t.status===`open`?e.latencyMs:null};case`sync_cached_sessions`:return{...e,sessions:t.sessions};case`host_metrics`:return{...e,...t.metrics===void 0?{}:{hostMetrics:t.metrics},...t.latencyMs===void 0?{}:{latencyMs:t.latencyMs}};case`ready`:{let n=!!(e.engine&&t.engine&&e.engine!==t.engine);return{...e,serverVersion:t.serverVersion,engine:t.engine,appVersion:t.appVersion,managed:t.managed===!0,tabs:t.tabs,ready:!0,...n?{terminals:[],dshPatches:null,dshAgentPresets:null,dshPermissionPresets:null}:{},...typeof t.latencyMs==`number`&&e.latencyMs==null?{latencyMs:t.latencyMs}:{},protocolMismatch:t.protocolVersion!==void 0&&t.protocolVersion!==29}}case`snapshot`:{let n=e.state?.cwd,r=e.state?.conversationId,i=t.state.cwd,a=e.sessions;i&&i!==n&&(a=Iu(i));let o=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),s=e.transition;s&&(s.phase===`done`||s.phase===`error`||s.kind===`cwd`&&o(t.state.cwd)===o(s.target)||s.kind===`session`&&o(t.state.sessionFile)===o(s.target)||s.kind===`conversation`&&t.state.conversationId===s.target||s.kind===`new_chat`&&(!r||t.state.conversationId!==r||t.state.messages.length===0))&&(s=null);let c=Ws(e.optimisticQueue,t.state);return{...e,ready:!0,state:c.state,optimisticQueue:c.tracker,transition:s,sessions:a,approval:c.state.pendingApproval??null,activeConversationId:c.state.conversationId,liveOutputs:bu(e.liveOutputs,c.state),toolStatuses:xu(e.toolStatuses,c.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},a=Ws(e.optimisticQueue,i),o=a.state;return{...e,ready:!0,state:o,optimisticQueue:a.tracker,approval:o.pendingApproval===void 0?e.approval:o.pendingApproval??null,activeConversationId:o.conversationId,liveOutputs:bu(e.liveOutputs,o),toolStatuses:xu(e.toolStatuses,o)}}case`optimistic_queue_add`:{let n=e.goal.reviewing&&!!(e.state?.conversationId&&e.goal.conversationId===e.state.conversationId),r=Hs(e.optimisticQueue,e.state,{text:t.text,attachments:t.attachments,queue:t.queue,engine:e.engine,goalReviewing:n});return r.tracker===e.optimisticQueue&&r.state===e.state?e:{...e,optimisticQueue:r.tracker,state:r.state}}case`optimistic_queue_remove`:{let n=Us(e.optimisticQueue,e.state,{kind:t.kind,text:t.text,index:t.index});return n.tracker===e.optimisticQueue&&n.state===e.state?e:{...e,optimisticQueue:n.tracker,state:n.state}}case`tool_approval`:return{...e,approval:t.approval};case`tool_delta`:{let n=(e.liveOutputs.get(t.toolCallId)?.text??``)+t.delta,r=n.length>hu?`…[${_u}:${n.length-hu}]…\n`+n.slice(n.length-hu):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:Ts(n,t.msg)}}case`tool_status`:return{...e,toolStatuses:new Map(e.toolStatuses).set(t.status.toolCallId,t.status)};case`notice`:{let n=iu(e.notices,t.notice),r=(t.notice.level===`error`||t.notice.level===`warning`)&&e.optimisticQueue.adds.length>0?Gs(e.optimisticQueue,e.state):{tracker:e.optimisticQueue,state:e.state};return n===e.notices&&r.tracker===e.optimisticQueue?e:{...e,notices:n,optimisticQueue:r.tracker,state:r.state}}case`dismiss_notice`:return{...e,notices:e.notices.filter(e=>e.id!==t.id)};case`sessions`:return Lu(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 Mu(t.projects),{...e,projects:t.projects};case`sandbox_diff`:return{...e,sandboxDiff:t.diff};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=su({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};case`transition_start`:{let n=t.kind===`cwd`?Iu(t.target):null;return{...e,...n&&n.length>0?{sessions:n}:{},transition:{kind:t.kind,target:t.target,phase:`start`,progress:t.progress,text:t.text,textEn:t.textEn,startedAt:Date.now()}}}case`transition_progress`:{let n=t.msg;if(n.phase===`done`||n.phase===`error`)return{...e,transition:e.transition?{...e.transition,phase:n.phase,progress:100,text:n.text,textEn:n.textEn}:null};let r=e.transition;return{...e,transition:{kind:n.kind,target:n.target,phase:n.phase,progress:Math.max(r?.target===n.target?r.progress:0,n.progress),text:n.text,textEn:n.textEn,totalMessages:n.totalMessages??r?.totalMessages,previewMessages:n.previewMessages??r?.previewMessages,startedAt:r?.startedAt??Date.now()}}}case`transition_tick`:{let t=e.transition;if(!t||t.phase===`done`||t.phase===`error`)return e;let n=t.phase===`start`?26:t.phase===`fs`?56:92;if(t.progress>=n)return e;let r=Math.max(1,Math.round((n-t.progress)*.16));return{...e,transition:{...t,progress:Math.min(n,t.progress+r)}}}case`transition_clear`:return e.transition?{...e,transition:null}:e;default:return e}}var Cu=`pi-web-client-id`,wu=null;function Tu(){if(wu)return wu;let e=null;try{e=sessionStorage.getItem(Cu),e||(e=Ht(),sessionStorage.setItem(Cu,e))}catch{e??=Ht()}return wu=e,e}var Eu=`pi-web-last-cwd`;function Du(){try{return localStorage.getItem(Eu)}catch{return null}}function Ou(e){try{localStorage.setItem(Eu,e)}catch{}}function ku(e){try{let t=localStorage.getItem(Eu);if(!t)return;let n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase();(t===e||n(t)===n(e))&&localStorage.removeItem(Eu)}catch{}}var Au=`pi-web-recent-projects`;function ju(){try{let e=localStorage.getItem(Au);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Mu(e){try{localStorage.setItem(Au,JSON.stringify(e.slice(0,20)))}catch{}}function Nu(e){try{let t=ju(),n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),r=n(e);Mu(t.filter(e=>n(e.path)!==r))}catch{}}var Pu=`pi-web-recent-sessions:`;function Fu(e){return e?`${Pu}${e.trim().replace(/[\\/]+$/,``).toLowerCase()}`:`pi-web-recent-sessions:default`}function Iu(e){try{let t=Fu(e??Du()),n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function Lu(e,t){try{let n=Fu(e??Du());localStorage.setItem(n,JSON.stringify(t.slice(0,50)))}catch{}}function Ru(e,t){try{let n=Iu(t),r=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),i=r(e);Lu(t,n.filter(e=>r(e.path)!==i))}catch{}}function zu(){return Dn(`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}${Cn(`/ws`)}`)}function Bu(){let[e,t]=(0,g.useReducer)(Su,{status:`connecting`,ready:!1,state:null,hostMetrics:null,latencyMs:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:Iu(),conversations:[],elsewhere:[],activeConversationId:``,projects:ju(),files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],providerKeys:{},defaultModel:null,providerOAuthFlows:[],providerOAuthResults:au().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:vu,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,transition:null,sandboxDiff:null,optimisticQueue:Ps()}),n=(0,g.useRef)(null),r=(0,g.useRef)(yu()),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;mu(e)&&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}})},[]);(0,g.useEffect)(()=>{if(!e.transition)return;if(e.transition.phase===`done`||e.transition.phase===`error`){let e=setTimeout(()=>t({type:`transition_clear`}),180);return()=>clearTimeout(e)}let n=setInterval(()=>{if(Date.now()-(e.transition?.startedAt??0)>2e4){t({type:`transition_clear`});return}t({type:`transition_tick`})},160);return()=>clearInterval(n)},[e.transition]);let y=(0,g.useCallback)(e=>{let r=O.current.chat.state;if(e.type===`set_cwd`&&e.path){let n=(r?.cwd??``).trim().replace(/[\\/]+$/,``).toLowerCase(),i=e.path.trim().replace(/[\\/]+$/,``).toLowerCase();i&&i!==n&&t({type:`transition_start`,kind:`cwd`,target:e.path,progress:14,text:`正在切换到工作目录:${e.path}`,textEn:`Switching to workspace: ${e.path}`})}else if(e.type===`switch_session`&&e.path){let n=(r?.sessionFile??``).trim().replace(/[\\/]+$/,``).toLowerCase(),i=e.path.trim().replace(/[\\/]+$/,``).toLowerCase();i&&i!==n&&t({type:`transition_start`,kind:`session`,target:e.path,progress:14,text:`正在流式载入历史会话…`,textEn:`Streaming session history…`})}else e.type===`new_chat`?r&&(r.messages.length>0||r.isStreaming)&&t({type:`transition_start`,kind:`new_chat`,target:r.cwd,progress:22,text:`正在初始化新对话…`,textEn:`Initializing new chat…`}):e.type===`switch_conversation`&&e.id&&r&&e.id!==r.conversationId&&t({type:`transition_start`,kind:`conversation`,target:e.id,progress:35,text:`正在切换对话…`,textEn:`Switching conversation…`});let i=n.current;if(mu(i)){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`}),i.send(JSON.stringify(e)),e.type===`prompt`?t({type:`optimistic_queue_add`,text:e.text,attachments:e.attachments,queue:e.queue}):e.type===`queue_remove`&&t({type:`optimistic_queue_remove`,kind:e.kind,text:e.text,index:e.index}),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=Ks({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}))},[]);xo(y);let x=(0,g.useCallback)(()=>{if(!o.current)return;t({type:`status`,status:`connecting`});let e=new WebSocket(zu());n.current=e;let u=0;e.onopen=()=>{n.current===e&&(t({type:`status`,status:`open`}),i.current=0,s.current=Date.now(),u=performance.now(),e.send(JSON.stringify({type:`hello`,clientId:Tu(),locale:lu()})))},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!==`20261013T02584`){let e=`pi-web-ui-reloaded-${a.buildId}`;if(!sessionStorage.getItem(e)){sessionStorage.setItem(e,`1`),location.reload();return}}let n=O.current.chat.engine;n&&a.engine&&n!==a.engine&&r.current.clear(),fo({engine:a.engine??`pi`,managed:!!a.managed,tabs:a.tabs,appVersion:a.appVersion,serverVersion:a.serverVersion,service:a.service});let i=u>0?Math.max(0,Math.round(performance.now()-u)):null;t({type:`ready`,serverVersion:a.serverVersion,protocolVersion:a.protocolVersion,engine:a.engine,appVersion:a.appVersion,managed:a.managed,tabs:a.tabs,service:a.service,latencyMs:i}),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;mu(e)&&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;(a.level===`error`||a.level===`warning`)&&t({type:`transition_clear`}),t({type:`notice`,notice:{id:e,level:a.level,text:a.text,textEn:a.textEn}});break}case`transition_progress`:t({type:`transition_progress`,msg:a});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`sandbox_diff`:t({type:`sandbox_diff`,diff:a.diff});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`:nc(a);break;case`tool_prompt`:dc(a);break;case`compacted_messages_result`:Sc(a);break;case`heartbeat`:(a.hostMetrics||typeof a.latencyMs==`number`)&&t({type:`host_metrics`,metrics:a.hostMetrics,latencyMs:typeof a.latencyMs==`number`?a.latencyMs:void 0});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`:Ys(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===Tu()&&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`:gl(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`:eu(a.pluginId,a.payload)||Sl(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`:wo(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??lu();t&&y({type:`set_locale`,locale:t})};return window.addEventListener(uu,e),()=>window.removeEventListener(uu,e)},[y]),(0,g.useEffect)(()=>{let n=n=>{let r=e.state?.cwd;r&&n.key&&n.key===Fu(r)&&t({type:`sync_cached_sessions`,sessions:Iu(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;mu(e)&&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===pu||e.readyState===fu){a.current&&=(clearTimeout(a.current),null),x();return}mu(e)&&(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=Du();if(e&&e!==t){y({type:`set_cwd`,path:e});return}}f.current!==t&&(f.current=t,Ou(t))}},[e.state?.cwd,y]),(0,g.useEffect)(()=>{fo({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 Vu(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 Hu(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 Uu=`pi-web-ui:lp-collapse-projects`,Wu=`pi-web-ui:lp-collapse-convs`,Gu=`pi-web-ui:lp-collapse-sessions`,Ku=`pi-web-ui:lp-collapse-subagents`;function qu(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Ku);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(Ku,JSON.stringify([...n]))}catch{}return n})},[])]}function Ju(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 Yu=`pi-web-ui:lp-collapse-plugin-sections`;function Xu(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Yu),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(Yu,JSON.stringify([...n]))}catch{}return n})},[])]}var Zu=`pi-web-ui:lp-sizes`,Qu={projects:1,convs:1,sessions:1},$u=32,ed={running:`pluginRunStatusRunning`,done:`pluginRunStatusDone`,error:`pluginRunStatusError`},td=72;function nd(){try{return na(localStorage.getItem(Zu),Qu)}catch{return{...Qu}}}var rd=(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,transition:D,onOpenSandboxModal:O}){let k=Z(),A=e,j=go(`ready`),ee=go(`status`),te=go(`cwd`),M=go(`workspaceRoots`),N=te,[F,I]=(0,g.useState)(!1),[L,ne]=(0,g.useState)(null),[re,ie]=(0,g.useState)(null),[z,B]=(0,g.useState)(null),[ae,V]=(0,g.useState)(``),[H,oe]=Ju(Uu,!1),[U,se]=Ju(Wu,!1),[ce,W]=Ju(Gu,!1),[le,ue]=Xu(),[de,fe]=qu(),[pe,G]=(0,g.useState)(60);(0,g.useEffect)(()=>{G(60)},[N]);let K=(0,g.useMemo)(()=>{if(r.length<=pe)return r;let e=A?r.findIndex(e=>e.path===A):-1,t=e>=pe?e+10:pe;return r.slice(0,t)},[r,pe,A]),me=(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]),he=(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},[]),J=(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},[]),ge=(0,g.useRef)(null),ve=(0,g.useRef)(null),ye=(0,g.useRef)(()=>{}),be=to(d??[]).length>0,Y=(0,g.useCallback)((e,n,i)=>{ge.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=me(t,a),l=c===0?k(`noFinishedSubagents`):k(a?`dismissFinishedSubagentsScoped`:`dismissFinishedSubagents`,{n:c}),u=!!a&&ve.current===a;Wa({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:k(`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:k(`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:k(`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:k(`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||Cs(i.id)?e:{...e,hidden:!0};if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return n?.sessionId||Cs(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)=>ye.current(e,t)})},[d,t,me,k]);ye.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=ge.current;if(!i||!e)return;if(ve.current!==i)return ve.current=i,Y(e.x,e.y,e.target),!0;ve.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||Cs(n.id):i?t.find(e=>e.id===i)?.sessionId||Cs(t.find(e=>e.id===i)?.sessionFile):null;if(e){let t=Ss(window.location.href,{sessionId:e});navigator.clipboard?.writeText(t).catch(()=>{})}return}if(e.id===`host:conv-quote`){n.kind===`history`&&n.id?Er({attachments:[{path:``,key:`conv||${n.id}`,name:n.label||n.id,mode:`conversation`,sessionPath:n.id}]}):a&&Er({attachments:[{path:``,key:`conv|${a}|`,name:n.label||a,mode:`conversation`,conversationId:a}]});return}if(e.id===`host:conv-rename`){if(ne(null),i){let e=t.find(e=>e.id===i);V(e?.title??n.label??``),B(`conv:${i}`)}else if(n.kind===`history`&&n.id){let e=r.find(e=>e.path===n.id);V(e?.name??n.label??``),B(n.id)}return}},[o,Y,t,r]);let xe=(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)})}),Ce=(0,g.useCallback)((e,t)=>{Hu(e.target)||be&&(e.preventDefault(),e.stopPropagation(),ve.current=null,Y(e.clientX,e.clientY,t))},[be,Y]),we=(0,g.useRef)(null),[Te,Ee]=(0,g.useState)(()=>nd());(0,g.useEffect)(()=>{try{localStorage.setItem(Zu,JSON.stringify(Te))}catch{}},[Te]);let De=(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]),ke=$i(y),Ae=ke.filter(e=>e.shown),je=e=>e===`projects`?H:e===`convs`?U:e===`sessions`?ce:le.has(e),Me=(x??[]).reduce((e,t)=>e+t.items.length,0),Ne=De.length+Me,Pe=ea(ke,e=>e===`projects`?i.length>0:e!==`convs`||Ne>0),Fe=()=>{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:[k(`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:k(ed[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}`))},Ie=(0,g.useMemo)(()=>[...f??[],...C??[]],[f,C]),Le=(0,g.useMemo)(()=>[...f??[],...w??[]],[f,w]),Re=(0,g.useCallback)((e,t)=>n=>{n.preventDefault();let r=n.currentTarget,i=n.clientY,a={...Te},o=we.current;if(!o)return;let s=Pe.filter(e=>je(e)).length,c=Pe.filter(e=>!je(e)).reduce((e,t)=>e+(a[t]??1),0)||1,l=Math.max(120,o.clientHeight-s*$u);r.classList.add(`dragging`),document.body.classList.add(`lp-resizing`);let u=n=>{let{above:r,below:o}=_s({start:{above:a[e]??1,below:a[t]??1},deltaPx:n.clientY-i,availablePx:l,totalWeight:c,minAbovePx:td,minBelowPx:td});Ee(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)},[Te,Pe,H,U,ce]);(0,g.useEffect)(()=>{s&&j&&ee===`open`&&te&&(o({type:`list_sessions`}),o({type:`list_projects`}))},[s,j,ee,te,o]);let ze=e=>{let t=e.name||e.firstMessage.trim();return t.length>0?t:k(`emptyChat`)},Be=e=>e.split(/[\\/]/).pop()||e,Ve=to(p??[]).length>0,We=(0,g.useCallback)((e,t)=>{Hu(e.target)||Ve&&(e.preventDefault(),e.stopPropagation(),Wa({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.path,kind:`project`,label:Be(t.path)},entries:p??[]}))},[Ve,p]),Ge=(e,t,n,r,i)=>{let a=L===e;return(0,X.jsx)(`button`,{type:`button`,className:`lp-del ${a?`confirm`:``}`,title:a?n:t,onClick:t=>{t.stopPropagation(),a?(ne(null),r()):ne(e)},children:a?(0,X.jsx)(yt,{}):i??(0,X.jsx)(R,{})})},Ke=(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:k(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)(vt,{}):(0,X.jsx)(ht,{})})]}),i||a?(0,X.jsxs)(`div`,{className:`lp-section-actions`,children:[i,a]}):null]}),qe=Pe.filter(e=>!je(e)),Je=qe.reduce((e,t)=>e+(Te[t]??1),0)||1,Ye=e=>qe.length<=1?1:(Te[e]??1)/Je*qe.length,Xe=new Map(ta(Pe,je).map(([e,t])=>[e,(0,X.jsx)(`div`,{className:`lp-sash`,onPointerDown:Re(e,t),onDoubleClick:()=>Ee({...Qu}),title:k(`dragToResize`)},`sash-${e}`)])),Ze={projects:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section panel-projects ${H||i.length===0?`collapsed`:``}`,style:i.length>0&&!H?{flex:`${Ye(`projects`)} 1 0px`}:void 0,children:[Ke(k(`recentProjects`),H,oe,i.length,(0,X.jsxs)(X.Fragment,{children:[O&&(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action lp-sandbox-action`,title:k(`sandboxNewBtn`),"aria-label":k(`sandboxNewBtn`),onClick:()=>O(),children:(0,X.jsx)(zt,{})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action`,title:k(`manageProjects`),"aria-label":k(`manageProjects`),onClick:()=>I(!0),children:(0,X.jsx)(Ue,{})})]}),xe(m,`lp-slot-section`)),i.length>0&&!H&&(0,X.jsx)(`div`,{className:`lp-section-body projects-scroll`,children:i.map(e=>{let t=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),n=N===e.path,r=D?.kind===`cwd`&&t(D.target)===t(e.path),i=e.sandbox,a=i?i.name:Be(e.path);return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ne(t=>t===`proj:${e.path}`?null:t),onContextMenu:t=>We(t,e),children:[(0,X.jsxs)(`button`,{type:`button`,className:`project-item ${n?`active`:``} ${r?`switching`:``}`,title:i?.sourcePath?`${a}\n${k(`sandboxSourceLabel`)}: ${i.sourcePath}\n${e.path}`:e.path,disabled:r,onClick:()=>{!n&&!r&&o({type:`set_cwd`,path:e.path})},children:[r?(0,X.jsx)(Oe,{className:`project-icon spin`}):i?(0,X.jsx)(zt,{className:`project-icon sandbox-icon`}):(0,X.jsx)(He,{className:`project-icon`}),(0,X.jsxs)(`span`,{className:`project-info`,children:[(0,X.jsxs)(`span`,{className:`project-name`,children:[a,i&&(0,X.jsx)(`span`,{className:`lp-sandbox-badge ${i.ephemeral?`ephemeral`:`permanent`}`,children:i.ephemeral?k(`sandboxBadgeEphemeral`):k(`sandboxBadgePermanent`)})]}),(0,X.jsx)(`span`,{className:`project-path`,children:i?.sourcePath?`← ${Be(i.sourcePath)} · ${e.path}`:e.path})]}),(0,X.jsx)(`span`,{className:`project-time ${r?`switching-pct`:``}`,children:r?`${D.progress}%`:Vu(e.lastUsed)})]}),Ge(`proj:${e.path}`,k(i?`sandboxActionDestroyTip`:`deleteProject`),k(i?`sandboxActionDestroy`:`deleteProjectConfirm`),()=>{ku(e.path),Nu(e.path),o(i?{type:`destroy_sandbox`,path:e.path}:{type:`remove_project`,path:e.path})}),xe(h,`lp-slot-project`,{id:e.path,kind:`project`,label:a})]},e.path)})})]})}),convs:(0,X.jsx)(X.Fragment,{children:Ne>0&&(0,X.jsxs)(`div`,{className:`lp-section lp-section-convs panel-convs ${U?`collapsed`:``}`,style:U?void 0:{flex:`${Ye(`convs`)} 1 0px`},onContextMenu:e=>Ce(e,{id:``,kind:`section`,label:k(`runningConversations`)}),children:[Ke(k(`runningConversations`),U,se,Ne,void 0,xe(_,`lp-slot-section`)),!U&&(0,X.jsxs)(`div`,{className:`lp-section-body convs-scroll`,children:[vs(De,te,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=>We(t,{path:e.cwd,lastUsed:0}),children:Be(e.cwd)}),ys(e.convs,de).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?k(`takeoverConfirm`):r?`${k(`elsewherePseudoTip`)}\n${n.cwd}`:`${k(i?`elsewhereOfflineTip`:`elsewhereTip`)}\n${n.cwd}`;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ie(e=>e===n.id?null:e),onContextMenu:i=>Ce(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)(Se,{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:k(r?`elsewherePseudoBadge`:`elsewhereBadge`)}),i&&(0,X.jsx)(`span`,{className:`elsewhere-badge offline`,title:k(`elsewhereOfflineTip`),children:k(`elsewhereOfflineBadge`)}),n.hasQuestion&&e&&t&&!r&&(0,X.jsx)(`span`,{className:`question-badge clickable`,title:k(`takeoverHasQuestion`),onClick:n=>{n.stopPropagation(),o({type:`peek_elsewhere_question`,owner:e,id:t})},children:`?`}),s?k(`takeoverConfirm`):n.title]}),(0,X.jsx)(`span`,{className:`session-sub`,children:Be(n.cwd)})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:k(`streaming`)})]}),be&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-elsewhere-act`,title:k(`elsewhereActions`),onClick:i=>{i.stopPropagation(),ve.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)(_e,{})})]},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:()=>ne(e=>e===`conv:${n.id}`?null:e),onContextMenu:e=>Ce(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:k(s?`expandSubagents`:`collapseSubagents`),"aria-label":k(s?`expandSubagents`:`collapseSubagents`),onClick:e=>{e.stopPropagation(),fe(n.id)},children:s?(0,X.jsx)(gt,{}):(0,X.jsx)(vt,{})}),(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)(Se,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[z===`conv:${n.id}`?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:ae,placeholder:k(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>V(e.target.value),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing){let e=ae.trim();e&&o({type:`rename_conversation`,id:n.id,name:e}),B(null)}else e.key===`Escape`&&B(null)},onBlur:()=>B(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[n.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:k(`pinnedConversation`),children:`📌`}),n.isSubagent&&(0,X.jsx)(`span`,{className:`subagent-badge`,children:k(`subagentBadge`)}),n.isEphemeral&&(0,X.jsx)(`span`,{className:`ephemeral-badge`,children:k(`ephemeralBadge`)}),n.forkFrom&&(0,X.jsxs)(`span`,{className:`preset-badge fork-badge`,title:`${k(`forkBadgeTip`)}: ${n.forkFrom.title??n.forkFrom.conversationId}`,children:[`🌿 `,k(`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:k(`convErrorBadge`,{error:n.error})}),n.hasQuestion&&(0,X.jsx)(`span`,{className:`question-badge`,title:k(`waitingQuestionBadge`),children:`?`}),i&&s&&(0,X.jsxs)(`span`,{className:`subagents-collapsed-badge${l?` has-streaming`:d?` has-question`:u?` has-error`:``}`,title:k(l?`subagentsStreamingTip`:d?`subagentsQuestionTip`:u?`subagentsErrorTip`:`subagentsCountTip`,{n:c}),onClick:e=>{e.stopPropagation(),fe(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:k(`subagentBadgeCount`,{n:c})})]})]}),z===`conv:${n.id}`?null:(0,X.jsx)(`span`,{className:`session-sub`,children:f?k(`current`):k(`messageCount`,{n:n.messageCount})})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:k(`streaming`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:k(`renameSession`),onClick:e=>{e.stopPropagation(),ne(null),V(n.title),B(`conv:${n.id}`)},children:(0,X.jsx)(Qe,{})}),(()=>{let e=`conv:${n.id}`,r=L===e,i=me(t,n.id),a=J(t,n.id),s=he(t,n.id);return s===0&&!n.isStreaming?Ge(e,k(`dismissConversation`),k(`dismissConversationConfirm`),()=>o({type:`dismiss_conversation`,id:n.id}),(0,X.jsx)(P,{})):s===0?Ge(e,k(`dismissConversation`),k(`dismissStreamingConfirm`),()=>o({type:`dismiss_conversation`,id:n.id,force:!0}),(0,X.jsx)(P,{})):r?(0,X.jsxs)(`span`,{className:`lp-del-group`,children:[i>0&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt`,title:k(`dismissFinishedSubagentsScoped`,{n:i}),onClick:e=>{e.stopPropagation(),ne(null),o({type:`dismiss_finished_subagents`,parentId:n.id})},children:k(`dismissFinishedOnly`,{n:i})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt danger`,title:k(`forceDismissTitle`,{n:s,m:a}),onClick:e=>{e.stopPropagation(),ne(null),o({type:`dismiss_conversation`,id:n.id,force:!0})},children:k(`dismissForceAll`,{n:s})})]}):(0,X.jsx)(`button`,{type:`button`,className:`lp-del`,title:k(`dismissConversation`),onClick:t=>{t.stopPropagation(),ne(e)},children:(0,X.jsx)(P,{})})})(),xe(Ie,`lp-slot-sessions`),n.isStreaming&&(0,X.jsx)(`span`,{className:`lp-row-stalled`,title:k(`streaming`),style:{position:`absolute`,right:28,top:`50%`,transform:`translateY(-50%)`}})]},n.id)})]},e.cwd)),Fe()]})]})}),sessions:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section lp-section-sessions panel-sessions ${ce?`collapsed`:``}`,style:ce?void 0:{flex:`${Ye(`sessions`)} 1 0px`},children:[Ke(k(`historySessions`),ce,W,r.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-new-chat-action`,title:k(`newChatTip`),"aria-label":k(`newChat`),onClick:()=>{o({type:`new_chat`}),wr()},children:(0,X.jsx)(q,{})}),xe(v,`lp-slot-section`)),!ce&&(0,X.jsxs)(`div`,{className:`lp-section-body sessions-scroll`,onScroll:e=>{if(K.length>=r.length)return;let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<180&&G(e=>Math.min(r.length,e+60))},children:[r.length===0&&(0,X.jsx)(`div`,{className:`panel-empty`,children:k(`noHistory`)}),K.map(e=>{let t=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),n=A===e.path,i=D?.kind===`session`&&t(D.target)===t(e.path);return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ne(t=>t===`sess:${e.path}`?null:t),onContextMenu:t=>Ce(t,{id:e.path,kind:`history`,label:ze(e)}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${n?`active`:``} ${i?`switching`:``}`,title:e.path,disabled:i,onClick:()=>{z||i||n||o({type:`switch_session`,path:e.path})},children:[i?(0,X.jsx)(Oe,{className:`session-icon spin`}):(0,X.jsx)(Se,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[z===e.path?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:ae,placeholder:k(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>V(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=ae.trim();t&&o({type:`rename_session`,path:e.path,name:t}),B(null)}else t.key===`Escape`&&B(null)},onBlur:()=>B(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[e.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:k(`pinnedConversation`),children:`📌`}),ze(e)]}),z===e.path?null:(0,X.jsxs)(`span`,{className:`session-sub`,children:[n?k(`current`):k(`messageCount`,{n:e.messageCount}),e.source===`tui`&&(0,X.jsx)(`span`,{className:`session-src`,title:k(`tuiTip`),children:`TUI`}),e.parentSessionPath&&(0,X.jsx)(`span`,{className:`session-src session-fork-badge`,title:k(`forkedSessionTip`,{parent:(()=>{let n=t(e.parentSessionPath).replace(/\\/g,`/`),i=r.find(e=>t(e.path).replace(/\\/g,`/`)===n);return i?ze(i):(e.parentSessionPath.replace(/\\/g,`/`).split(`/`).pop()??e.parentSessionPath).replace(/\.jsonl$/i,``)})()}),children:k(`forkedSessionBadge`)})]})]}),(0,X.jsx)(`span`,{className:`session-time ${i?`switching-pct`:``}`,children:i?`${D.progress}%`:Vu(e.modified)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:k(`renameSession`),onClick:t=>{t.stopPropagation(),ne(null),V(e.name??``),B(e.path)},children:(0,X.jsx)(Qe,{})}),Ge(`sess:${e.path}`,k(`deleteSession`),k(`deleteSessionConfirm`),()=>{Ru(e.path,N),o({type:`delete_session`,path:e.path})}),xe(Le,`lp-slot-sessions`)]},e.path)})]})]})})},$e=e=>{let t=Ae.find(t=>t.key===e)?.entry;if(!t)return null;let n=je(e);return(0,X.jsxs)(`div`,{className:`lp-section lp-section-plugin ${n?`collapsed`:``}`,style:n?void 0:{flex:`${Ye(e)} 1 0px`},children:[Ke(t.label,n,()=>ue(e)),!n&&(0,X.jsx)(`div`,{className:`lp-section-body lp-plugin-section-body`,children:b?.(t)??null})]})},et=e=>e===`projects`||e===`convs`||e===`sessions`?Ze[e]:$e(e);return(0,X.jsxs)(`aside`,{ref:we,className:`panel panel-left lp-panel`,children:[c&&l&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:k(`collapsePanel`),onClick:l,children:(0,X.jsx)(mt,{})}),Ae.map(({key:e})=>(0,X.jsxs)(g.Fragment,{children:[et(e),Xe.get(e)??null]},e)),(0,X.jsx)(Bo,{open:F,currentCwd:N,pathCompletions:u??[],workspaceRoots:M,onClose:()=>I(!1),onSelectDirectory:e=>o({type:`set_cwd`,path:e}),onCreateProject:e=>o({type:`make_dir`,path:e,setAsCwd:!0})})]})}),id=209715200,ad=/windows/i.test(navigator.userAgent),od=/[<>:"/\\|?*\u0000-\u001f]/g,sd=/[. ]+$/,cd=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function ld(e){let t=e.replace(od,`_`).replace(sd,``);return t?cd.test(t)?`_${t}`:t:`_`}function ud(e,t=!0){return Dn(Cn(`/api/file?${new URLSearchParams({clientId:Tu(),path:e,...t?{download:`1`}:{}})}`))}async function dd(e,t){let n=ad?ld(t):t;try{let t=await fetch(ud(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`)>id)return window.location.assign(ud(e)),{ok:!0};let r=await t.blob();return window.showSaveFilePicker&&window.isSecureContext?pd(r,n):md(r,n)}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}async function fd(e,t){let n=ad?ld(t):t;return window.showSaveFilePicker&&window.isSecureContext?pd(e,n):md(e,n)}async function pd(e,t){let n,r=window.showSaveFilePicker;if(!r)return md(e,t);try{n=await r({suggestedName:t})}catch(n){return n instanceof DOMException&&n.name===`AbortError`?{ok:!1,cancelled:!0}:md(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 md(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 hd(e,t,n){let r=Math.max(8,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 gd(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}function _d(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});return(0,g.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=hd(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=hd(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]),{anchorRef:t,show:()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},hide:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},tipPortal: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)}}function vd({text:e}){let{anchorRef:t,show:n,hide:r,onKeyDown:i,tipPortal:a}=_d(e);return(0,X.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:n,onMouseLeave:r,onFocus:n,onBlur:r,onKeyDown:i,children:[(0,X.jsx)(Ie,{}),a]})}function yd({tip:e,children:t,onMouseEnter:n,onMouseLeave:r,onFocus:i,onBlur:a,onKeyDown:o,...s}){let{anchorRef:c,show:l,hide:u,onKeyDown:d,tipPortal:f}=_d(e);return(0,X.jsxs)(`button`,{ref:c,type:`button`,"aria-label":s[`aria-label`]??e,...s,onMouseEnter:e=>{l(),n?.(e)},onMouseLeave:e=>{u(),r?.(e)},onFocus:e=>{l(),i?.(e)},onBlur:e=>{u(),a?.(e)},onKeyDown:e=>{d(e),o?.(e)},children:[t,f]})}var bd=e=>/\.(zip|tar|tar\.gz|tgz|gz)$/i.test(e);function xd(e,t={}){let n={archive:Cn(`/api/file-transfer/archive`),upload:Cn(`/api/file-transfer/upload`)},r=new URL(Dn(`${n[e]}?${new URLSearchParams({clientId:Tu(),...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 Sd(e,t,n){let r=await fetch(xd(`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 fd(await r.blob(),i);if(!a.ok&&!a.cancelled)throw Error(a.error)}}async function Cd(){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 wd(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=xd(`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 Td({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 Cd();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 wd(e.dir,c,d):await Sd(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)(P,{})})]}),(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 Ed(e){return e.startsWith(`.`)&&e!==`..`}function Dd(e,t){return t?e:e.filter(e=>!Ed(e.name))}function Od(e){return e instanceof Error?e.message:String(e)}function kd(e,t,n,r){let i=kn(n);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 Ad({plugin:e,epoch:t,send:n,className:r}){let i=(0,g.useRef)(null),{locale:a}=Xn(),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 Hl(e,t),r)return;let i=await Fc(e.id,()=>bl(()=>import(Ll(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,Wl(e.id,e=>l.current(e)))}catch(t){if(r)return;console.error(`[plugin:${e.id}] 页面${o?`挂载`:`加载`}失败:`,t),c({kind:o?`mount`:`load`,detail:Od(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:kd(s,e.name,a,o)})]})}function jd(e){return`pi-web-ui:${e}:tab`}function Md(e,t){try{let n=localStorage.getItem(jd(e));return n&&t.some(e=>e.id===n)?n:null}catch{return null}}function Nd(e,t){try{localStorage.setItem(jd(e),t)}catch{}}function Pd(e){return e.length>0&&!/[a-z]/i.test(e)}function Fd(e){if(e.label)return e.label;let t=e.pluginPage;return t?.entry.label||t?.plugin.name||e.id}function Id({storageKey:e,tabs:t,epoch:n,send:r,extra:i,className:a}){let o=(0,g.useId)(),[s,c]=(0,g.useState)(()=>Md(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,Nd(e,f.id))},[f,s,e]);let m=t=>{c(t.id),u.current=`${e}:${t.id}`,Nd(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??Fd(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)(Ni,{iconSvg:e.iconSvg,className:`slot-tab-icon`}):e.icon&&Pd(e.icon)?(0,X.jsx)(`span`,{className:`slot-tab-icon`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`slot-tab-label`,children:Fd(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)(Ad,{plugin:f.pluginPage.plugin,epoch:n,send:r}):f.element??null})]})}function Ld(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 Rd(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return Ld(e)}return Ld(e)}function zd(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 Rd(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 Bd=`@root`,Vd=`pi-web-ui:rp-sizes`,Hd=`pi-web-ui:files-show-hidden`,Ud={files:4,widgets:1},Wd=120,Gd=56;function Kd(e,t){return t?Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top):32}var qd=`files`,Jd=[],Yd=()=>{};function Xd(e){let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n<0?``:n===0?`/`:t.slice(0,n)}function Zd(e){return e===Bd||e===`/`||/^[A-Za-z]:$/.test(e)}function Qd(e){return e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)}var $d=(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??Jd,_=go(`cwd`),v=go(`workspaceRoots`),y=go(`homeDir`),b=go(`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 gs(localStorage.getItem(Vd),Ud)}catch{return{...Ud}}});(0,g.useEffect)(()=>{try{localStorage.setItem(Vd,JSON.stringify(k))}catch{}},[k]);let[j,ee]=(0,g.useState)(()=>{try{return localStorage.getItem(Hd)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{localStorage.setItem(Hd,j?`1`:`0`)}catch{}},[j]);let te=n.some(e=>e.lines.length>0),M=(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-Kd(t,O.current));n.classList.add(`dragging`),document.body.classList.add(`rp-resizing`);let o=e=>{let{above:t,below:n}=_s({start:i,deltaPx:e.clientY-r,availablePx:a,totalWeight:i.above+i.below,minAbovePx:Wd,minBelowPx:Gd});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]),N=(0,g.useRef)(null),F=(0,g.useRef)(0),I=(0,g.useCallback)(e=>{N.current=e,e&&(e.scrollTop=F.current)},[]),[L,ne]=(0,g.useState)(null),re=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]);let ie=(0,g.useCallback)(e=>{ne(e),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>ne(null),1200)},[]),R=(0,g.useCallback)((e,t)=>{e&&Rd(e).then(e=>{e?ie(t):o(`error`,m(`slashCopyFailed`))})},[ie,o,m]),z=(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},[_]),B=(0,g.useCallback)(e=>!e||e===Bd?null:e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)?e:`${_.replace(/\\/g,`/`).replace(/\/+$/,``)}/${e}`,[_]),ae=104857600,V=(0,g.useCallback)((e,t)=>{for(let n of t){if(n.size>ae){o(`warning`,m(`fileTooLarge`,{name:n.name,size:ae/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]),H=(0,g.useRef)(null),[oe,U]=(0,g.useState)(null),se=(0,g.useRef)(null),ce=(0,g.useCallback)(()=>{let e=H.current?.project;e&&r({type:`set_cwd`,path:e.path})},[r]),W=(0,g.useCallback)(()=>{se.current&&(se.current.value=``),se.current?.click()},[]),[le,ue]=(0,g.useState)(null),[de,fe]=(0,g.useState)(null),[pe,G]=(0,g.useState)(``),[K,me]=(0,g.useState)(null),[q,he]=(0,g.useState)(``),J=(0,g.useCallback)((e,t)=>{dd(e,t).then(e=>{e.ok||e.cancelled||o(`error`,m(`downloadFailed`,{error:e.error===`FILE_NOT_FOUND`?m(`fileNotFoundShort`):e.error}))})},[o,m]),ge=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&(me(null),G(e.label),fe(e.id))},[]),_e=(0,g.useCallback)(()=>{if(!de)return;let e=pe.trim();fe(null),e&&r({type:`file_rename`,path:de,newName:e})},[de,pe,r]),ye=(0,g.useCallback)(e=>{let t=H.current?.dir??x;fe(null),he(``),me({dir:t,kind:e})},[x]),be=(0,g.useCallback)(()=>{if(!K)return;let e=q.trim();me(null),e&&r({type:`file_create`,dir:K.dir,name:e,kind:K.kind})},[K,q,r]),Y=(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}),xe=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&window.confirm(m(`fileDeleteConfirm`,{name:e.label}))&&(le?.src===e.id&&ue(null),de===e.id&&fe(null),r({type:`file_delete`,path:e.id}))},[r,m,le,de]),Se=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&r({type:`file_copy`,src:e.id,destDir:Xd(e.id)})},[r]),Ce=(0,g.useCallback)(e=>{let t=H.current?.target;t&&t.kind!==`list`&&!Zd(t.id)&&ue({src:t.id,cut:e})},[]),we=(0,g.useCallback)(()=>{if(!le)return;let e=H.current?.dir??x;le.cut?(r({type:`file_copy`,src:le.src,destDir:e,move:!0}),ue(null)):r({type:`file_copy`,src:le.src,destDir:e})},[le,r,x]),Ee=(0,g.useCallback)(()=>{r({type:`list_files`,path:x===``?void 0:x})},[r,x]),[De,Oe]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(!De)return;let e=e=>{e.target?.closest(`.root-picker`)||Oe(!1)},t=e=>{e.key===`Escape`&&Oe(!1)};return window.addEventListener(`mousedown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e,!0),window.removeEventListener(`keydown`,t)}},[De]);let ke=(0,g.useCallback)(e=>{r({type:`set_workspace_roots`,roots:e})},[r]),je=(0,g.useCallback)(()=>{let e=H.current?.target;if(!e||e.kind!==`dir`)return;let t=B(e.id);t&&!v.includes(t)&&ke([...v,t])},[v,B,ke]),Me=(0,g.useCallback)(e=>{V(H.current?.dir??x,Array.from(e.target.files??[]))},[V,x]),Ne=(0,g.useCallback)(e=>{let t=H.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`;U({action:n,path:z(t.id),dir:z(n===`upload`?H.current?.dir??x:Xd(t.id))});break}case`host:file-open-project`:ce();break;case`host:file-upload`:W();break;case`host:file-add-root`:je();break;case`host:file-open`:t?.kind===`file`&&a(t.id,t.label);break;case`host:file-enter`:t?.kind===`dir`&&Xe(t.id);break;case`host:file-download`:t?.kind===`file`&&J(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`:ye(`file`);break;case`host:file-new-dir`:ye(`dir`);break;case`host:file-paste`:we();break;case`host:file-rename`:ge();break;case`host:file-duplicate`:Se();break;case`host:file-cut`:Ce(!0);break;case`host:file-copy`:Ce(!1);break;case`host:file-copy-name`:t&&t.kind!==`list`&&R(t.label,`name:${t.id}`);break;case`host:file-copy-path`:t&&t.kind!==`list`&&R(z(t.id),`path:${t.id}`);break;case`host:file-copy-rel`:t&&t.kind!==`list`&&R(t.id,`rel:${t.id}`);break;case`host:file-refresh`:Ee();break;case`host:file-delete`:xe()}},[ce,x,W,je,a,i,R,z,J,ye,we,ge,Se,Ce,Ee,xe]),Pe=(0,g.useCallback)((e,t)=>{let n=t.kind===`dir`?B(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&&Zd(t.id),l=!s&&Qd(t.id),d=x===Bd,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&&bd(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!==Bd?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&&le?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}});to(f).length!==0&&(e.preventDefault(),e.stopPropagation(),H.current=r,Wa({x:e.clientX,y:e.clientY,slot:`contextmenu.file`,target:t,entries:f,onHostAction:Ne}))},[u,x,B,m,Ne,_,v,le]),Ie=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),Re=(0,g.useCallback)(()=>{N.current?.querySelectorAll(`.file-item.drop-target`).forEach(e=>e.classList.remove(`drop-target`)),N.current?.classList.remove(`drop-root`)},[]),ze=(0,g.useCallback)(e=>{if(Re(),e==null)return;let t=N.current?.querySelector(`.file-item[data-path="${CSS.escape(e)}"]`);t?t.classList.add(`drop-target`):N.current?.classList.add(`drop-root`)},[Re]),Be=e=>{let t=e instanceof Element?e.closest(`.file-item`):null;return t?.dataset.type===`dir`?t.dataset.path??x:x},Ve=(0,g.useCallback)(()=>{let e=document.querySelector(`.app`);e&&e.dispatchEvent(new DragEvent(`dragleave`,{bubbles:!0}))},[]),Ue=(0,g.useRef)(0),Ge=(0,g.useRef)(void 0),Ke=(0,g.useCallback)((e,t)=>{let n=++Ue.current;S(e),t?.silent||E(!0),r({type:`list_files`,path:e===``?void 0:e})||Ue.current===n&&E(!1)},[r]),qe=(0,g.useCallback)(e=>{let t=v.filter(t=>t!==e);ke(t),(x===e||x.startsWith(`${e}/`))&&Ke(``)},[v,ke,x,Ke]);(0,g.useEffect)(()=>{e&&e.path===x&&E(!1)},[e,x]),(0,g.useEffect)(()=>{if(_!==Ge.current){let e=Ge.current===void 0;Ge.current=_,e?Ke(``,{silent:!0}):S(``);return}let e=setInterval(()=>{document.visibilityState!==`hidden`&&Ke(x,{silent:!0})},1e4);return()=>clearInterval(e)},[_,x,Ke]),(0,g.useEffect)(()=>{t&&t.path===x&&Ke(x,{silent:!0})},[t,x,Ke]);let Xe=e=>Ke(e),Ze=()=>{e?.parent!==null&&e?.parent!==void 0&&Ke(e.parent)},Qe=(()=>{if(x===``||x===Bd)return[];let e=x.split(`/`).filter(e=>!!e&&e!==Bd);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(`/`)}))})(),et=[];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&&et.push({id:e.id,label:e.label,icon:e.icon,...e.iconSvg?{iconSvg:e.iconSvg}:{},hint:e.hint,pluginPage:{plugin:t,entry:e}})}let tt=(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)(pt,{})}),(0,X.jsx)(`div`,{ref:O,style:{display:`flex`,flexDirection:`column`,flex:te?`${k.files} 1 0`:`1 1 0`,minHeight:te?Wd:0},children:(0,X.jsx)(Id,{storageKey:`rightpanel`,epoch:f??0,send:p??Yd,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===qd?`host:right-files`:e)??1e9;return[...e].sort((e,t)=>r(e.id)-r(t.id))})([...tt?[]:[{id:qd,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:()=>Ke(``),children:m(`rootDir`)}),(0,X.jsx)(yd,{className:`crumb ${x===Bd?`active`:``}`,tip:m(`computer`),onClick:()=>Ke(Bd),children:(0,X.jsx)(Le,{})}),y!==``&&(0,X.jsx)(yd,{className:`crumb ${x===y||x.startsWith(`${y}/`)?`active`:``}`,tip:m(`homeDir`),onClick:()=>Ke(y),children:(0,X.jsx)(Fe,{})}),b!==``&&(0,X.jsx)(yd,{className:`crumb ${x===b||x.startsWith(`${b}/`)?`active`:``}`,tip:m(`desktopDir`),onClick:()=>Ke(b),children:(0,X.jsx)(ve,{})}),(0,X.jsx)(yd,{className:`crumb ${j?`active`:``}`,tip:m(j?`filesHideHidden`:`filesShowHidden`),"aria-pressed":j,onClick:()=>ee(e=>!e),children:j?(0,X.jsx)(Je,{}):(0,X.jsx)(Ye,{})}),(0,X.jsx)(vd,{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":De,title:m(`workspaceRoots`),onClick:()=>Oe(e=>!e),children:[(0,X.jsx)(He,{}),(0,X.jsx)(`span`,{className:`root-picker-label`,children:m(`workspaceRoots`)}),(0,X.jsx)(`span`,{className:`set-count`,children:v.length+1}),`▾`]}),De&&(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:()=>{Oe(!1),Ke(``)},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:()=>{Oe(!1),Ke(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:()=>qe(e),children:(0,X.jsx)(P,{})})]},e)),(0,X.jsx)(`div`,{className:`root-picker-hint`,children:m(`workspaceRootsHint`)})]})]}),Qe.map(e=>(0,X.jsxs)(`span`,{className:`crumb-seg`,children:[(0,X.jsx)(gt,{}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${e.path===x?`active`:``}`,onClick:()=>Ke(e.path),children:e.label})]},e.path))]}),(0,X.jsxs)(`div`,{ref:I,className:`panel-body`,onScroll:e=>{F.current=e.currentTarget.scrollTop},onContextMenu:e=>Pe(e,{id:x,kind:`list`,label:x===``?m(`rootDir`):x===Bd?m(`computer`):x}),onDragOver:e=>{Ie(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,Ve(),ze(Be(e.target)))},onDragLeave:e=>{e.relatedTarget&&e.currentTarget.contains(e.relatedTarget)||Re()},onDrop:e=>{if(Re(),!Ie(e))return;e.preventDefault(),e.stopPropagation(),Ve();let t=Array.from(e.dataTransfer?.files??[]);if(t.length===0){o(`warning`,m(`foldersNotSupported`));return}V(Be(e.target),t)},onDragEnd:Re,children:[(0,X.jsx)(`input`,{ref:se,type:`file`,multiple:!0,hidden:!0,onChange:Me}),oe&&(0,X.jsx)(Td,{request:oe,onClose:()=>U(null),onComplete:Ee}),K&&(0,X.jsxs)(`div`,{className:`file-item dir`,children:[K.kind===`dir`?(0,X.jsx)(He,{className:`file-icon`}):(0,X.jsx)(We,{className:`file-icon`}),Y(q,he,be,()=>me(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:Ze,children:[(0,X.jsx)(He,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:`..`})]}),Dd(e.entries,j).map(e=>e.type===`dir`?(0,X.jsxs)(`div`,{className:`file-item dir${le?.cut&&le.src===e.path?` cut`:``}`,"data-type":`dir`,"data-path":e.path,onContextMenu:t=>Pe(t,{id:e.path,kind:`dir`,label:e.name}),children:[de===e.path?Y(pe,G,_e,()=>fe(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-dir-main`,onClick:()=>Xe(e.path),children:[(0,X.jsx)(He,{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)(Ae,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>R(e.name,`name:${e.path}`),children:L===`name:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(st,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>R(z(e.path),`path:${e.path}`),children:L===`path:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(dt,{})})]},e.path):(0,X.jsxs)(`div`,{className:`file-item file${le?.cut&&le.src===e.path?` cut`:``}`,"data-type":`file`,"data-path":e.path,onContextMenu:t=>Pe(t,{id:e.path,kind:`file`,label:e.name}),children:[de===e.path?Y(pe,G,_e,()=>fe(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)(We,{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:()=>J(e.path,e.name),children:(0,X.jsx)($e,{})}),(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)(Ae,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>R(e.name,`name:${e.path}`),children:L===`name:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(st,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>R(z(e.path),`path:${e.path}`),children:L===`path:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(dt,{})})]},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`)})]})]})}],...et])})}),te&&(0,X.jsx)(`div`,{className:`rp-sash`,onPointerDown:M,onDoubleClick:()=>A({...Ud}),title:m(`dragToResize`)}),te&&(0,X.jsx)(`div`,{className:`panel-widgets`,style:{flexGrow:k.widgets,minHeight:Gd},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)(Te,{})]}),(0,X.jsx)(`pre`,{className:`widget-lines`,children:e.lines.join(`
|
|
329
|
+
`)}function Ns(e){let t=e,n=[];for(;;){let e=/(?:^|\n\n)(<quoted-text>\n[^\n]*\n<\/quoted-text>)$/.exec(t),r=e?As(e[1]):null;if(!e||!r)break;n.unshift(r),t=t.slice(0,e.index)}let r=[];return t=t.replace(/(?:^|\n\n)?<attached-image name="([^"]*)"\s*\/>/g,(e,t)=>(r.push({type:`image`,name:t}),``)),t=t.replace(/(?:^|\n\n)?<file path="([^"]*)"(?:\s+size="[^"]*")?(?:\s+lines="(\d+)-(\d+)")?\s*\/>/g,(e,t,n,i)=>{let a=t.split(/[\\/]/).pop()??t,o=n&&i?{start:Number(n),end:Number(i)}:void 0;return r.push({type:`file`,name:a,path:t,lines:o}),``}),t=t.replace(/(?:^|\n\n)?<folder path="([^"]*)"\s*\/>/g,(e,t)=>{let n=t.split(/[\\/]/).pop()??t;return r.push({type:`folder`,name:n,path:t}),``}),t=t.replace(/(?:^|\n\n)?<browser-page url="([^"]*)" title="([^"]*)">[\s\S]*?<\/browser-page>/g,(e,t,n)=>(r.push({type:`page`,name:n||t,url:t}),``)),t=t.replace(/(?:^|\n\n)?<conversation-ref[^>]*title="([^"]*)"[^>]*>[\s\S]*?<\/conversation-ref>/g,(e,t)=>(r.push({type:`conversation`,name:t}),``)),t=t.replace(/(?:^|\n\n)?<vision-bridge>[\s\S]*?<\/vision-bridge>/g,()=>(r.push({type:`vision-bridge`,name:`视觉转写`}),``)),r.length>0&&(t=t.trim()),{text:t,quotes:n,...r.length?{attachments:r}:{}}}function Ps(){return{adds:[],removes:[]}}function Fs(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function Is(e,t){let n=(t??[]).filter(e=>e.mode===`quote`).map(e=>Os(e.quote)).filter(e=>e!==null),r=[],i=[];for(let e of t??[])if(e.mode!==`quote`){if(e.imageData){r.push(e.name||`image.png`);continue}if(e.fileData){let t=e.name||`file`;i.push(`<file path="${Fs(t)}" />`);continue}if(e.mode===`page`){let t=e.path||``,n=e.name||t;i.push(`<browser-page url="${Fs(t)}" title="${Fs(n)}"></browser-page>`);continue}if(e.mode===`conversation`){let t=e.name||e.conversationId||e.sessionPath||`conversation`;i.push(`<conversation-ref title="${Fs(t)}"></conversation-ref>`);continue}if(e.path){let t=e.lines?` lines="${e.lines.start}-${e.lines.end}"`:``;i.push(`<file path="${Fs(e.path)}"${t} />`)}}return Ms(e,i,n,r)}function Ls(e){let t=Ns(e);return`${t.text.trim()}\u0000${t.quotes.map(e=>`${e.role}:${e.messageId}:${e.text.trim()}`).join(`|`)}`}function Rs(e,t){return e===t||Ls(e)===Ls(t)}function zs(e,t){let n=0;for(let r of e)Rs(r,t)&&(n+=1);return n}function Bs(e,t){let n=t.trim(),r=0;for(let t of e)t.role===`user`&&(t.content.find(e=>e.type===`text`)?.text??``).trim()===n&&(r+=1);return r}function Vs(e){let{state:t,text:n,attachments:r,queue:i=!1,goalReviewing:a=!1}=e;if(!t||!t.isStreaming||t.delegateMode===!0)return!1;let o=(n??``).trim(),s=!!(r&&r.length>0);return!(!o&&!s||o.startsWith(`/`)||a&&!i)}function Hs(e,t,n){let r=n.now??Date.now();if(!Vs({state:t,text:n.text,attachments:n.attachments,queue:n.queue,goalReviewing:n.goalReviewing})||!t)return{tracker:e,state:t};let i=n.queue||n.engine===`dsh`?`followUp`:`steer`,a=Is(n.text,n.attachments),o=Ns(a).text.trim(),s=i===`steer`?t.queue.steering:t.queue.followUp,c=e.adds.filter(e=>e.conversationId===t.conversationId&&e.kind===i&&Rs(e.formattedText,a)).length,l=zs(s,a),u=Math.max(0,l-c),d=Bs(t.messages,o),f={conversationId:t.conversationId,kind:i,rawText:o,formattedText:a,baselineQueueMatches:u,baselineUserMsgMatches:d,createdAt:r},p=i===`steer`?{...t.queue,steering:[...t.queue.steering,a]}:{...t.queue,followUp:[...t.queue.followUp,a]};return{tracker:{adds:[...e.adds,f],removes:e.removes},state:{...t,queue:p}}}function Us(e,t,n){if(!t)return{tracker:e,state:t};let r=n.now??Date.now(),{kind:i,text:a,index:o}=n,s=Ds(i===`steer`?t.queue.steering:t.queue.followUp,a,o),c=e.adds,l=c.findIndex(e=>e.conversationId===t.conversationId&&e.kind===i&&Rs(e.formattedText,a));l>=0&&(c=[...c.slice(0,l),...c.slice(l+1)]);let u=zs(s,a),d={conversationId:t.conversationId,kind:i,text:a,index:o,expectedRemainingMatches:u,createdAt:r},f=i===`steer`?{...t.queue,steering:s}:{...t.queue,followUp:s};return{tracker:{adds:c,removes:[...e.removes,d]},state:{...t,queue:f}}}function Ws(e,t,n=Date.now()){if(e.adds.length===0&&e.removes.length===0)return{tracker:e,state:t};let r=t.conversationId;if(!t.isStreaming){let i=e.adds.filter(e=>e.conversationId!==r&&n-e.createdAt<15e3),a=e.removes.filter(e=>e.conversationId!==r&&n-e.createdAt<3e3);return i.length===e.adds.length&&a.length===e.removes.length?{tracker:e,state:t}:{tracker:{adds:i,removes:a},state:t}}let i=[...t.queue.steering],a=[...t.queue.followUp],o=!1,s=[];for(let t of e.removes){if(n-t.createdAt>=3e3)continue;if(t.conversationId!==r){s.push(t);continue}let e=t.kind===`steer`?i:a;if(zs(e,t.text)>t.expectedRemainingMatches){let n=Ds(e,t.text,t.index);if(n.length===e.length){let r=e.findIndex(e=>Rs(e,t.text));r>=0&&(n=[...e.slice(0,r),...e.slice(r+1)])}t.kind===`steer`?i=n:a=n,o=!0,s.push(t)}}let c=[],l=new Map;for(let s of e.adds){if(n-s.createdAt>=15e3)continue;if(s.conversationId!==r){c.push(s);continue}let e=s.kind===`steer`?i:a,u=`${s.kind}:${Ls(s.formattedText)}`,d=l.get(u)??0,f=zs(e,s.formattedText),p=Bs(t.messages,s.rawText),m=f>s.baselineQueueMatches+d,h=p>s.baselineUserMsgMatches;if(m){l.set(u,d+1);continue}h||(s.kind===`steer`?i.push(s.formattedText):a.push(s.formattedText),l.set(u,d+1),o=!0,c.push(s))}let u=c.length===e.adds.length&&s.length===e.removes.length?e:{adds:c,removes:s};return o?{tracker:u,state:{...t,queue:{steering:i,followUp:a}}}:{tracker:u,state:t}}function Gs(e,t){if(!t||e.adds.length===0)return{tracker:e,state:t};let n=t.conversationId,r=e.adds.filter(e=>e.conversationId===n);if(r.length===0)return{tracker:e,state:t};let i=[...t.queue.steering],a=[...t.queue.followUp];for(let e of r)e.kind===`steer`?i=Ds(i,e.formattedText):a=Ds(a,e.formattedText);return{tracker:{adds:e.adds.filter(e=>e.conversationId!==n),removes:e.removes},state:{...t,queue:{steering:i,followUp:a}}}}function Ks(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 qs=new Set;function Js(e){return qs.add(e),()=>{qs.delete(e)}}function Ys(e,t){for(let n of qs)try{n(e,t)}catch(e){console.error(`[tui-overlay-bridge] listener error:`,e)}}function Xs(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 Zs=null,Qs=new Set;function $s(){for(let e of Qs)e()}function ec(e){let t=(e??``).trim();t&&(Zs={name:t,status:`loading`},$s(),$({type:`get_tool_info`,name:t}))}function tc(){Zs!==null&&(Zs=null,$s())}function nc(e){Zs!==null&&Zs.name===e.name&&(Zs=Xs(e),$s())}function rc(e){return Qs.add(e),()=>{Qs.delete(e)}}function ic(){return Zs}function ac(){return(0,g.useSyncExternalStore)(rc,ic,ic)}function oc(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 sc={},cc=new Set;function lc(){for(let e of cc)e()}function uc(e){let t=(e??``).trim();t&&(sc[t]&&sc[t].status!==`loading`||(sc={...sc,[t]:{name:t,status:`loading`}},lc(),$({type:`get_tool_prompt`,name:t})))}function dc(e){let t=typeof e.name==`string`?e.name:``;t&&sc[t]&&(sc={...sc,[t]:oc(e)},lc())}function fc(e){if(!sc[e])return;let t={...sc};delete t[e],sc=t,lc()}function pc(e){return cc.add(e),()=>cc.delete(e)}function mc(e){return(0,g.useSyncExternalStore)(pc,()=>e?sc[e]??null:null)}var hc=Object.freeze({status:`idle`,messages:[]}),gc=new Map,_c=new Set,vc=16;function yc(){for(;gc.size>vc;){let e=gc.keys().next().value;if(e===void 0)break;gc.delete(e)}}function bc(){for(let e of _c)e()}function xc(e,t){let n=(e??``).trim();if(!n)return;let r=gc.get(n);(!r||r.status!==`loading`&&r.status!==`ready`)&&(gc.set(n,{status:`loading`,messages:r?.messages??[]}),yc(),bc(),$({type:`get_compacted_messages`,compactionMessageId:n,conversationId:t}))}function Sc(e){let t=e.compactionMessageId;t&&(e.error?gc.set(t,{status:`error`,messages:[],error:e.error}):gc.set(t,{status:`ready`,messages:e.messages??[]}),yc(),bc())}function Cc(e){let t=gc.get(e);return t?(gc.delete(e),gc.set(e,t),t):hc}function wc(e){return _c.add(e),()=>{_c.delete(e)}}function Tc(e){return(0,g.useSyncExternalStore)(wc,()=>Cc(e),()=>hc)}var Ec=`__piWebUiHost`,Dc=e=>new Promise(t=>setTimeout(t,e));async function Oc(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 Dc(100)}}var kc=Promise.resolve(),Ac=0;function jc(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 Dc(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=Ac>0?kc.then(i):i(),Ac++,kc=o.then(()=>{Ac--},()=>{Ac--}),o.catch(()=>{}),!0},models:{list:()=>i(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>sl(e)},compose(e){return Tr()?Er({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=Ic,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=Ic,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=Ht();return new Promise(t=>{let a=setTimeout(()=>{hl.delete(i),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));hl.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 Rc(Pc,String(e??``).trim(),t)},onTopbarAction(e,t){return Rc(Pc,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(tr())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 Oc(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(Bc,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Jc(String(e??``),t)},searchProviders:{register:e=>Xc(e),list:()=>Zc()},composerProviders:{register:e=>$c(e),list:()=>el()},onTheme:e=>ll(e),onLocale:e=>ul(e),onViewChange:e=>dl(e),setCostFormatter:e=>Wi(e),setCostCurrency:e=>Ui(e),getCostCurrency:()=>Hi()}}function Mc(e){try{let t=window;e?t[Ec]=e:delete t[Ec]}catch{}}var Nc=new Map,Pc=null;async function Fc(e,t){let n=Pc;Pc=e;try{return await t()}finally{Pc=n}}var Ic=void 0;function Lc(e,t){let n=Ic;Ic=e;try{return t()}finally{Ic=n}}function Rc(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=Nc.get(r);i||(i=new Set,Nc.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&Nc.delete(r)}}async function zc(e,t,n,r){let i=i=>{let a=Nc.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{Lc(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 Bc=`pi-web-ui:toast`,Vc=new Map,Hc=!1;function Uc(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 Wc(){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 Gc(e){try{if(Wc())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=Vc.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function Kc(){if(!Hc)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,Gc),Hc=!0}catch{}}function qc(){if(!(Vc.size>0||!Hc))try{window.removeEventListener(`keydown`,Gc)}catch{}finally{Hc=!1}}function Jc(e,t){if(typeof t!=`function`)return()=>{};let n=Uc(e);if(!n)return()=>{};let r=Vc.get(n.combo);r||(r=new Set,Vc.set(n.combo,r));let i=r;return i.add(t),Kc(),()=>{i.delete(t),i.size===0&&Vc.delete(n.combo),qc()}}var Yc=new Map;function Xc(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 Yc.set(t,n),()=>{Yc.get(t)===n&&Yc.delete(t)}}function Zc(){return[...Yc.values()].map(e=>({id:e.id,label:e.label}))}var Qc=new Map;function $c(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 Qc.set(t,n),()=>{Qc.get(t)===n&&Qc.delete(t)}}function el(){return[...Qc.values()].map(e=>({id:e.id,label:e.label}))}function tl(e){return Qc.get(String(e??``))}function nl(e){return Yc.get(String(e??``))}var rl=new Set,il=new Set,al=new Set,ol=new Set;function sl(e){return ol.add(e),()=>{ol.delete(e)}}function cl(e){for(let t of ol)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function ll(e){return typeof e==`function`?(rl.add(e),()=>{rl.delete(e)}):()=>{}}function ul(e){return typeof e==`function`?(il.add(e),()=>{il.delete(e)}):()=>{}}function dl(e){return typeof e==`function`?(al.add(e),()=>{al.delete(e)}):()=>{}}function fl(e){let t=String(e??``);for(let e of rl)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function pl(e){let t=String(e??``);for(let e of il)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function ml(e){let t=String(e??``);for(let e of al)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var hl=new Map;function gl(e){let t=hl.get(e.requestId);if(t){if(hl.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 _l=`modulepreload`,vl=function(e){return`/`+e},yl={},bl=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=vl(t,n),t=s(t),t in yl)return;yl[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`:_l,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)})},xl=`pi-web-ui:plugin-data`;function Sl(e,t){window.dispatchEvent(new CustomEvent(xl,{detail:{pluginId:e,payload:t}}))}function Cl(e){let t=t=>{let n=t.detail;e(n.pluginId,n.payload)};return window.addEventListener(xl,t),()=>window.removeEventListener(xl,t)}var wl=new Map,Tl=new Set,El=new Set,Dl=new Set,Ol=new Set,kl=-1;function Al(){return[...wl.values()]}function jl(){let e=Al();for(let t of El)t(e)}function Ml(){let e=[...Dl];for(let t of Ol)t(e)}function Nl(e){return Ol.add(e),e([...Dl]),()=>Ol.delete(e)}async function Pl(e,t){Dl.delete(e.id),Il.set(e.id,(Il.get(e.id)??0)+1),Ml();let n=await Vl(e,t);return jl(),n}function Fl(e){return El.add(e),e(Al()),()=>El.delete(e)}var Il=new Map;function Ll(e,t){let n=Il.get(e)??0;return Cn(`/plugins/${encodeURIComponent(e)}/client/entry.mjs?e=${t}${n>0?`&r=${n}`:``}`)}function Rl(e){let t=Promise.resolve();return(n,r)=>{let i=t.then(()=>Fc(n,()=>e(r)));return t=i.then(()=>void 0,()=>void 0),i}}var zl=Rl(e=>bl(()=>import(e),[]));async function Bl(e,t){if(!e.hasClient||e.error)return null;try{return(await zl(e.id,Ll(e.id,t))).default??null}catch(t){return console.error(`[plugin:${e.id}] 客户端 bundle 加载失败:`,t),null}}async function Vl(e,t){try{let n=(await zl(e.id,Ll(e.id,t))).default;return n&&typeof n.mount==`function`?(wl.set(e.id,{info:e,module:n}),!0):e.preload?(Tl.add(e.id),!0):(Dl.add(e.id),Ml(),console.error(`[plugin:${e.id}] entry.mjs 缺少 default.mount`),!1)}catch(t){return Dl.add(e.id),Ml(),console.error(`[plugin:${e.id}] 客户端加载失败:`,t),!1}}async function Hl(e,t){if(wl.has(e.id)||Tl.has(e.id))return!0;if(Dl.has(e.id)||!e.hasClient)return!1;let n=await Vl(e,t);return jl(),n}async function Ul(e,t){t!==kl&&(kl=t,wl.clear(),Tl.clear(),Dl.clear(),Il.clear(),Ml());let n=new Set(e.map(e=>e.id));for(let e of[...wl.keys()])n.has(e)||wl.delete(e);for(let e of[...Tl])n.has(e)||Tl.delete(e);for(let e of[...Dl])n.has(e)||Dl.delete(e);Ml(),await Promise.all(e.filter(e=>e.hasClient&&(e.view!==!1||e.preload)&&!e.error&&!wl.has(e.id)&&!Tl.has(e.id)&&!Dl.has(e.id)).map(e=>Vl(e,t))),jl()}function Wl(e,t){return{pluginId:e,send:n=>t({type:`plugin_message`,pluginId:e,payload:n}),onData:t=>Cl((n,r)=>{n===e&&t(r)})}}var Gl=[`debug`,`info`,`warn`,`error`];function Kl(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`get`}}}function ql(e){return{type:`plugin_message`,pluginId:e,payload:{__host:`logs`,op:`clear`}}}function Jl(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`&&Gl.includes(String(e.level)))}var Yl=new Map,Xl=new Set;function Zl(){for(let e of[...Xl])try{e()}catch{}}function Ql(e){return Xl.add(e),()=>Xl.delete(e)}function $l(e){return(Yl.get(e)??[]).map(e=>({...e}))}function eu(e,t){return Jl(t)?(Yl.set(e,t.logs.map(e=>({ts:e.ts,level:e.level,text:e.text}))),Zl(),!0):!1}function tu(e){switch(e){case`error`:return 6500;case`warning`:return 4200;default:return 2400}}var nu=[/^(已在工作目录|正在切换到工作目录|已切换到工作目录)[::]/,/^(Already in directory|Switching to directory|Switched to directory):/i,/该项目最近的对话.*(为你停在了空白新对话|为你停在了新对话)/,/The most recent conversation .* landed on a (blank|new) chat/i,/^分层上下文预算裁剪生效/,/^Tiered context budget pruning/i,/^发现 \d+ 个内置插件有更新可用/,/^\d+ built-in plugin\(s\) have updates available/i,/^已(创建文件|创建文件夹|重命名|删除|移动|复制)[::]/,/^(Created file|Created folder|Renamed|Deleted|Moved|Copied):/i,/^已重命名当前会话为/,/^Renamed current session to/i,/的消息正在投递,已为你保留该对话$/,/is still sending your message — kept in the running list$/i,/^(计划模式已开启|计划模式已关闭|已进入计划模式|已退出计划模式|审查者模式已开启|审查者模式已关闭)/,/^(Plan mode (enabled|disabled)|Entered plan mode|Exited plan mode|Delegate mode (enabled|disabled))/i,/^已切换(智能体预设|权限预设)/,/^Switched (agent|permission) preset/i];function ru(e){if(e.level!==`info`)return!1;let t=(e.text??``).trim(),n=(e.textEn??``).trim();return nu.some(e=>t&&e.test(t)||n&&e.test(n))}function iu(e,t,n=2){if(ru(t))return e;let r=`${t.level}:${(t.text??``).trim()}`,i=[...e.filter(e=>`${e.level}:${(e.text??``).trim()}`!==r),t];for(;i.length>n;){let e=i.findIndex(e=>e.level!==`error`);e>=0?i.splice(e,1):i.shift()}return i}function au(){return{flows:[],results:{}}}function ou(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 su(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:ou(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:ou(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 cu=`pi-web-ui:lang`;function lu(){try{return(localStorage.getItem(cu)??``).trim()}catch{return``}}var uu=`pi-web-ui:locale`,du=typeof WebSocket<`u`&&WebSocket.OPEN!==void 0?WebSocket.OPEN:1,fu=typeof WebSocket<`u`&&WebSocket.CLOSING!==void 0?WebSocket.CLOSING:2,pu=typeof WebSocket<`u`&&WebSocket.CLOSED!==void 0?WebSocket.CLOSED:3,mu=e=>!!(e&&e.readyState===du),hu=2e5,gu=2e5,_u=`LIVE_OMIT`,vu={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 yu(){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>gu?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 bu(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 xu(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 Su(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,latencyMs:t.status===`open`?e.latencyMs:null};case`sync_cached_sessions`:return{...e,sessions:t.sessions};case`host_metrics`:return{...e,...t.metrics===void 0?{}:{hostMetrics:t.metrics},...t.latencyMs===void 0?{}:{latencyMs:t.latencyMs}};case`ready`:{let n=!!(e.engine&&t.engine&&e.engine!==t.engine);return{...e,serverVersion:t.serverVersion,engine:t.engine,appVersion:t.appVersion,managed:t.managed===!0,tabs:t.tabs,ready:!0,...n?{terminals:[],dshPatches:null,dshAgentPresets:null,dshPermissionPresets:null}:{},...typeof t.latencyMs==`number`&&e.latencyMs==null?{latencyMs:t.latencyMs}:{},protocolMismatch:t.protocolVersion!==void 0&&t.protocolVersion!==29}}case`snapshot`:{let n=e.state?.cwd,r=e.state?.conversationId,i=t.state.cwd,a=e.sessions;i&&i!==n&&(a=Iu(i));let o=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),s=e.transition;s&&(s.phase===`done`||s.phase===`error`||s.kind===`cwd`&&o(t.state.cwd)===o(s.target)||s.kind===`session`&&o(t.state.sessionFile)===o(s.target)||s.kind===`conversation`&&t.state.conversationId===s.target||s.kind===`new_chat`&&(!r||t.state.conversationId!==r||t.state.messages.length===0))&&(s=null);let c=Ws(e.optimisticQueue,t.state);return{...e,ready:!0,state:c.state,optimisticQueue:c.tracker,transition:s,sessions:a,approval:c.state.pendingApproval??null,activeConversationId:c.state.conversationId,liveOutputs:bu(e.liveOutputs,c.state),toolStatuses:xu(e.toolStatuses,c.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},a=Ws(e.optimisticQueue,i),o=a.state;return{...e,ready:!0,state:o,optimisticQueue:a.tracker,approval:o.pendingApproval===void 0?e.approval:o.pendingApproval??null,activeConversationId:o.conversationId,liveOutputs:bu(e.liveOutputs,o),toolStatuses:xu(e.toolStatuses,o)}}case`optimistic_queue_add`:{let n=e.goal.reviewing&&!!(e.state?.conversationId&&e.goal.conversationId===e.state.conversationId),r=Hs(e.optimisticQueue,e.state,{text:t.text,attachments:t.attachments,queue:t.queue,engine:e.engine,goalReviewing:n});return r.tracker===e.optimisticQueue&&r.state===e.state?e:{...e,optimisticQueue:r.tracker,state:r.state}}case`optimistic_queue_remove`:{let n=Us(e.optimisticQueue,e.state,{kind:t.kind,text:t.text,index:t.index});return n.tracker===e.optimisticQueue&&n.state===e.state?e:{...e,optimisticQueue:n.tracker,state:n.state}}case`tool_approval`:return{...e,approval:t.approval};case`tool_delta`:{let n=(e.liveOutputs.get(t.toolCallId)?.text??``)+t.delta,r=n.length>hu?`…[${_u}:${n.length-hu}]…\n`+n.slice(n.length-hu):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:Ts(n,t.msg)}}case`tool_status`:return{...e,toolStatuses:new Map(e.toolStatuses).set(t.status.toolCallId,t.status)};case`notice`:{let n=iu(e.notices,t.notice),r=(t.notice.level===`error`||t.notice.level===`warning`)&&e.optimisticQueue.adds.length>0?Gs(e.optimisticQueue,e.state):{tracker:e.optimisticQueue,state:e.state};return n===e.notices&&r.tracker===e.optimisticQueue?e:{...e,notices:n,optimisticQueue:r.tracker,state:r.state}}case`dismiss_notice`:return{...e,notices:e.notices.filter(e=>e.id!==t.id)};case`sessions`:return Lu(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 Mu(t.projects),{...e,projects:t.projects};case`sandbox_diff`:return{...e,sandboxDiff:t.diff};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=su({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};case`transition_start`:{let n=t.kind===`cwd`?Iu(t.target):null;return{...e,...n&&n.length>0?{sessions:n}:{},transition:{kind:t.kind,target:t.target,phase:`start`,progress:t.progress,text:t.text,textEn:t.textEn,startedAt:Date.now()}}}case`transition_progress`:{let n=t.msg;if(n.phase===`done`||n.phase===`error`)return{...e,transition:e.transition?{...e.transition,phase:n.phase,progress:100,text:n.text,textEn:n.textEn}:null};let r=e.transition;return{...e,transition:{kind:n.kind,target:n.target,phase:n.phase,progress:Math.max(r?.target===n.target?r.progress:0,n.progress),text:n.text,textEn:n.textEn,totalMessages:n.totalMessages??r?.totalMessages,previewMessages:n.previewMessages??r?.previewMessages,startedAt:r?.startedAt??Date.now()}}}case`transition_tick`:{let t=e.transition;if(!t||t.phase===`done`||t.phase===`error`)return e;let n=t.phase===`start`?26:t.phase===`fs`?56:92;if(t.progress>=n)return e;let r=Math.max(1,Math.round((n-t.progress)*.16));return{...e,transition:{...t,progress:Math.min(n,t.progress+r)}}}case`transition_clear`:return e.transition?{...e,transition:null}:e;default:return e}}var Cu=`pi-web-client-id`,wu=null;function Tu(){if(wu)return wu;let e=null;try{e=sessionStorage.getItem(Cu),e||(e=Ht(),sessionStorage.setItem(Cu,e))}catch{e??=Ht()}return wu=e,e}var Eu=`pi-web-last-cwd`;function Du(){try{return localStorage.getItem(Eu)}catch{return null}}function Ou(e){try{localStorage.setItem(Eu,e)}catch{}}function ku(e){try{let t=localStorage.getItem(Eu);if(!t)return;let n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase();(t===e||n(t)===n(e))&&localStorage.removeItem(Eu)}catch{}}var Au=`pi-web-recent-projects`;function ju(){try{let e=localStorage.getItem(Au);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Mu(e){try{localStorage.setItem(Au,JSON.stringify(e.slice(0,20)))}catch{}}function Nu(e){try{let t=ju(),n=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),r=n(e);Mu(t.filter(e=>n(e.path)!==r))}catch{}}var Pu=`pi-web-recent-sessions:`;function Fu(e){return e?`${Pu}${e.trim().replace(/[\\/]+$/,``).toLowerCase()}`:`pi-web-recent-sessions:default`}function Iu(e){try{let t=Fu(e??Du()),n=localStorage.getItem(t);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function Lu(e,t){try{let n=Fu(e??Du());localStorage.setItem(n,JSON.stringify(t.slice(0,50)))}catch{}}function Ru(e,t){try{let n=Iu(t),r=e=>e.trim().replace(/[\\/]+$/,``).toLowerCase(),i=r(e);Lu(t,n.filter(e=>r(e.path)!==i))}catch{}}function zu(){return Dn(`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}${Cn(`/ws`)}`)}function Bu(){let[e,t]=(0,g.useReducer)(Su,{status:`connecting`,ready:!1,state:null,hostMetrics:null,latencyMs:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:Iu(),conversations:[],elsewhere:[],activeConversationId:``,projects:ju(),files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],providerKeys:{},defaultModel:null,providerOAuthFlows:[],providerOAuthResults:au().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:vu,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,transition:null,sandboxDiff:null,optimisticQueue:Ps()}),n=(0,g.useRef)(null),r=(0,g.useRef)(yu()),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;mu(e)&&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}})},[]);(0,g.useEffect)(()=>{if(!e.transition)return;if(e.transition.phase===`done`||e.transition.phase===`error`){let e=setTimeout(()=>t({type:`transition_clear`}),180);return()=>clearTimeout(e)}let n=setInterval(()=>{if(Date.now()-(e.transition?.startedAt??0)>2e4){t({type:`transition_clear`});return}t({type:`transition_tick`})},160);return()=>clearInterval(n)},[e.transition]);let y=(0,g.useCallback)(e=>{let r=O.current.chat.state;if(e.type===`set_cwd`&&e.path){let n=(r?.cwd??``).trim().replace(/[\\/]+$/,``).toLowerCase(),i=e.path.trim().replace(/[\\/]+$/,``).toLowerCase();i&&i!==n&&t({type:`transition_start`,kind:`cwd`,target:e.path,progress:14,text:`正在切换到工作目录:${e.path}`,textEn:`Switching to workspace: ${e.path}`})}else if(e.type===`switch_session`&&e.path){let n=(r?.sessionFile??``).trim().replace(/[\\/]+$/,``).toLowerCase(),i=e.path.trim().replace(/[\\/]+$/,``).toLowerCase();i&&i!==n&&t({type:`transition_start`,kind:`session`,target:e.path,progress:14,text:`正在流式载入历史会话…`,textEn:`Streaming session history…`})}else e.type===`new_chat`?r&&(r.messages.length>0||r.isStreaming)&&t({type:`transition_start`,kind:`new_chat`,target:r.cwd,progress:22,text:`正在初始化新对话…`,textEn:`Initializing new chat…`}):e.type===`switch_conversation`&&e.id&&r&&e.id!==r.conversationId&&t({type:`transition_start`,kind:`conversation`,target:e.id,progress:35,text:`正在切换对话…`,textEn:`Switching conversation…`});let i=n.current;if(mu(i)){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`}),i.send(JSON.stringify(e)),e.type===`prompt`?t({type:`optimistic_queue_add`,text:e.text,attachments:e.attachments,queue:e.queue}):e.type===`queue_remove`&&t({type:`optimistic_queue_remove`,kind:e.kind,text:e.text,index:e.index}),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=Ks({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}))},[]);xo(y);let x=(0,g.useCallback)(()=>{if(!o.current)return;t({type:`status`,status:`connecting`});let e=new WebSocket(zu());n.current=e;let u=0;e.onopen=()=>{n.current===e&&(t({type:`status`,status:`open`}),i.current=0,s.current=Date.now(),u=performance.now(),e.send(JSON.stringify({type:`hello`,clientId:Tu(),locale:lu()})))},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!==`20261013T03105`){let e=`pi-web-ui-reloaded-${a.buildId}`;if(!sessionStorage.getItem(e)){sessionStorage.setItem(e,`1`),location.reload();return}}let n=O.current.chat.engine;n&&a.engine&&n!==a.engine&&r.current.clear(),fo({engine:a.engine??`pi`,managed:!!a.managed,tabs:a.tabs,appVersion:a.appVersion,serverVersion:a.serverVersion,service:a.service});let i=u>0?Math.max(0,Math.round(performance.now()-u)):null;t({type:`ready`,serverVersion:a.serverVersion,protocolVersion:a.protocolVersion,engine:a.engine,appVersion:a.appVersion,managed:a.managed,tabs:a.tabs,service:a.service,latencyMs:i}),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;mu(e)&&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;(a.level===`error`||a.level===`warning`)&&t({type:`transition_clear`}),t({type:`notice`,notice:{id:e,level:a.level,text:a.text,textEn:a.textEn}});break}case`transition_progress`:t({type:`transition_progress`,msg:a});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`sandbox_diff`:t({type:`sandbox_diff`,diff:a.diff});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`:nc(a);break;case`tool_prompt`:dc(a);break;case`compacted_messages_result`:Sc(a);break;case`heartbeat`:(a.hostMetrics||typeof a.latencyMs==`number`)&&t({type:`host_metrics`,metrics:a.hostMetrics,latencyMs:typeof a.latencyMs==`number`?a.latencyMs:void 0});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`:Ys(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===Tu()&&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`:gl(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`:eu(a.pluginId,a.payload)||Sl(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`:wo(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??lu();t&&y({type:`set_locale`,locale:t})};return window.addEventListener(uu,e),()=>window.removeEventListener(uu,e)},[y]),(0,g.useEffect)(()=>{let n=n=>{let r=e.state?.cwd;r&&n.key&&n.key===Fu(r)&&t({type:`sync_cached_sessions`,sessions:Iu(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;mu(e)&&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===pu||e.readyState===fu){a.current&&=(clearTimeout(a.current),null),x();return}mu(e)&&(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=Du();if(e&&e!==t){y({type:`set_cwd`,path:e});return}}f.current!==t&&(f.current=t,Ou(t))}},[e.state?.cwd,y]),(0,g.useEffect)(()=>{fo({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 Vu(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 Hu(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 Uu=`pi-web-ui:lp-collapse-projects`,Wu=`pi-web-ui:lp-collapse-convs`,Gu=`pi-web-ui:lp-collapse-sessions`,Ku=`pi-web-ui:lp-collapse-subagents`;function qu(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Ku);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(Ku,JSON.stringify([...n]))}catch{}return n})},[])]}function Ju(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 Yu=`pi-web-ui:lp-collapse-plugin-sections`;function Xu(){let[e,t]=(0,g.useState)(()=>{try{let e=localStorage.getItem(Yu),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(Yu,JSON.stringify([...n]))}catch{}return n})},[])]}var Zu=`pi-web-ui:lp-sizes`,Qu={projects:1,convs:1,sessions:1},$u=32,ed={running:`pluginRunStatusRunning`,done:`pluginRunStatusDone`,error:`pluginRunStatusError`},td=72;function nd(){try{return na(localStorage.getItem(Zu),Qu)}catch{return{...Qu}}}var rd=(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,transition:D,onOpenSandboxModal:O}){let k=Z(),A=e,j=go(`ready`),ee=go(`status`),te=go(`cwd`),M=go(`workspaceRoots`),N=te,[F,I]=(0,g.useState)(!1),[L,ne]=(0,g.useState)(null),[re,ie]=(0,g.useState)(null),[z,B]=(0,g.useState)(null),[ae,V]=(0,g.useState)(``),[H,oe]=Ju(Uu,!1),[U,se]=Ju(Wu,!1),[ce,W]=Ju(Gu,!1),[le,ue]=Xu(),[de,fe]=qu(),[pe,G]=(0,g.useState)(60);(0,g.useEffect)(()=>{G(60)},[N]);let K=(0,g.useMemo)(()=>{if(r.length<=pe)return r;let e=A?r.findIndex(e=>e.path===A):-1,t=e>=pe?e+10:pe;return r.slice(0,t)},[r,pe,A]),me=(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]),he=(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},[]),J=(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},[]),ge=(0,g.useRef)(null),ve=(0,g.useRef)(null),ye=(0,g.useRef)(()=>{}),be=to(d??[]).length>0,Y=(0,g.useCallback)((e,n,i)=>{ge.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=me(t,a),l=c===0?k(`noFinishedSubagents`):k(a?`dismissFinishedSubagentsScoped`:`dismissFinishedSubagents`,{n:c}),u=!!a&&ve.current===a;Wa({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:k(`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:k(`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:k(`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:k(`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||Cs(i.id)?e:{...e,hidden:!0};if(!a)return{...e,hidden:!0};let n=t.find(e=>e.id===a);return n?.sessionId||Cs(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)=>ye.current(e,t)})},[d,t,me,k]);ye.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=ge.current;if(!i||!e)return;if(ve.current!==i)return ve.current=i,Y(e.x,e.y,e.target),!0;ve.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||Cs(n.id):i?t.find(e=>e.id===i)?.sessionId||Cs(t.find(e=>e.id===i)?.sessionFile):null;if(e){let t=Ss(window.location.href,{sessionId:e});navigator.clipboard?.writeText(t).catch(()=>{})}return}if(e.id===`host:conv-quote`){n.kind===`history`&&n.id?Er({attachments:[{path:``,key:`conv||${n.id}`,name:n.label||n.id,mode:`conversation`,sessionPath:n.id}]}):a&&Er({attachments:[{path:``,key:`conv|${a}|`,name:n.label||a,mode:`conversation`,conversationId:a}]});return}if(e.id===`host:conv-rename`){if(ne(null),i){let e=t.find(e=>e.id===i);V(e?.title??n.label??``),B(`conv:${i}`)}else if(n.kind===`history`&&n.id){let e=r.find(e=>e.path===n.id);V(e?.name??n.label??``),B(n.id)}return}},[o,Y,t,r]);let xe=(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)})}),Ce=(0,g.useCallback)((e,t)=>{Hu(e.target)||be&&(e.preventDefault(),e.stopPropagation(),ve.current=null,Y(e.clientX,e.clientY,t))},[be,Y]),we=(0,g.useRef)(null),[Te,Ee]=(0,g.useState)(()=>nd());(0,g.useEffect)(()=>{try{localStorage.setItem(Zu,JSON.stringify(Te))}catch{}},[Te]);let De=(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]),ke=$i(y),Ae=ke.filter(e=>e.shown),je=e=>e===`projects`?H:e===`convs`?U:e===`sessions`?ce:le.has(e),Me=(x??[]).reduce((e,t)=>e+t.items.length,0),Ne=De.length+Me,Pe=ea(ke,e=>e===`projects`?i.length>0:e!==`convs`||Ne>0),Fe=()=>{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:[k(`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:k(ed[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}`))},Ie=(0,g.useMemo)(()=>[...f??[],...C??[]],[f,C]),Le=(0,g.useMemo)(()=>[...f??[],...w??[]],[f,w]),Re=(0,g.useCallback)((e,t)=>n=>{n.preventDefault();let r=n.currentTarget,i=n.clientY,a={...Te},o=we.current;if(!o)return;let s=Pe.filter(e=>je(e)).length,c=Pe.filter(e=>!je(e)).reduce((e,t)=>e+(a[t]??1),0)||1,l=Math.max(120,o.clientHeight-s*$u);r.classList.add(`dragging`),document.body.classList.add(`lp-resizing`);let u=n=>{let{above:r,below:o}=_s({start:{above:a[e]??1,below:a[t]??1},deltaPx:n.clientY-i,availablePx:l,totalWeight:c,minAbovePx:td,minBelowPx:td});Ee(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)},[Te,Pe,H,U,ce]);(0,g.useEffect)(()=>{s&&j&&ee===`open`&&te&&(o({type:`list_sessions`}),o({type:`list_projects`}))},[s,j,ee,te,o]);let ze=e=>{let t=e.name||e.firstMessage.trim();return t.length>0?t:k(`emptyChat`)},Be=e=>e.split(/[\\/]/).pop()||e,Ve=to(p??[]).length>0,We=(0,g.useCallback)((e,t)=>{Hu(e.target)||Ve&&(e.preventDefault(),e.stopPropagation(),Wa({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.path,kind:`project`,label:Be(t.path)},entries:p??[]}))},[Ve,p]),Ge=(e,t,n,r,i)=>{let a=L===e;return(0,X.jsx)(`button`,{type:`button`,className:`lp-del ${a?`confirm`:``}`,title:a?n:t,onClick:t=>{t.stopPropagation(),a?(ne(null),r()):ne(e)},children:a?(0,X.jsx)(yt,{}):i??(0,X.jsx)(R,{})})},Ke=(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:k(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)(vt,{}):(0,X.jsx)(ht,{})})]}),i||a?(0,X.jsxs)(`div`,{className:`lp-section-actions`,children:[i,a]}):null]}),qe=Pe.filter(e=>!je(e)),Je=qe.reduce((e,t)=>e+(Te[t]??1),0)||1,Ye=e=>qe.length<=1?1:(Te[e]??1)/Je*qe.length,Xe=new Map(ta(Pe,je).map(([e,t])=>[e,(0,X.jsx)(`div`,{className:`lp-sash`,onPointerDown:Re(e,t),onDoubleClick:()=>Ee({...Qu}),title:k(`dragToResize`)},`sash-${e}`)])),Ze={projects:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section panel-projects ${H||i.length===0?`collapsed`:``}`,style:i.length>0&&!H?{flex:`${Ye(`projects`)} 1 0px`}:void 0,children:[Ke(k(`recentProjects`),H,oe,i.length,(0,X.jsxs)(X.Fragment,{children:[O&&(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action lp-sandbox-action`,title:k(`sandboxNewBtn`),"aria-label":k(`sandboxNewBtn`),onClick:()=>O(),children:(0,X.jsx)(zt,{})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-project-action`,title:k(`manageProjects`),"aria-label":k(`manageProjects`),onClick:()=>I(!0),children:(0,X.jsx)(Ue,{})})]}),xe(m,`lp-slot-section`)),i.length>0&&!H&&(0,X.jsx)(`div`,{className:`lp-section-body projects-scroll`,children:i.map(e=>{let t=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),n=N===e.path,r=D?.kind===`cwd`&&t(D.target)===t(e.path),i=e.sandbox,a=i?i.name:Be(e.path);return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ne(t=>t===`proj:${e.path}`?null:t),onContextMenu:t=>We(t,e),children:[(0,X.jsxs)(`button`,{type:`button`,className:`project-item ${n?`active`:``} ${r?`switching`:``}`,title:i?.sourcePath?`${a}\n${k(`sandboxSourceLabel`)}: ${i.sourcePath}\n${e.path}`:e.path,disabled:r,onClick:()=>{!n&&!r&&o({type:`set_cwd`,path:e.path})},children:[r?(0,X.jsx)(Oe,{className:`project-icon spin`}):i?(0,X.jsx)(zt,{className:`project-icon sandbox-icon`}):(0,X.jsx)(He,{className:`project-icon`}),(0,X.jsxs)(`span`,{className:`project-info`,children:[(0,X.jsxs)(`span`,{className:`project-name`,children:[a,i&&(0,X.jsx)(`span`,{className:`lp-sandbox-badge ${i.ephemeral?`ephemeral`:`permanent`}`,children:i.ephemeral?k(`sandboxBadgeEphemeral`):k(`sandboxBadgePermanent`)})]}),(0,X.jsx)(`span`,{className:`project-path`,children:i?.sourcePath?`← ${Be(i.sourcePath)} · ${e.path}`:e.path})]}),(0,X.jsx)(`span`,{className:`project-time ${r?`switching-pct`:``}`,children:r?`${D.progress}%`:Vu(e.lastUsed)})]}),Ge(`proj:${e.path}`,k(i?`sandboxActionDestroyTip`:`deleteProject`),k(i?`sandboxActionDestroy`:`deleteProjectConfirm`),()=>{ku(e.path),Nu(e.path),o(i?{type:`destroy_sandbox`,path:e.path}:{type:`remove_project`,path:e.path})}),xe(h,`lp-slot-project`,{id:e.path,kind:`project`,label:a})]},e.path)})})]})}),convs:(0,X.jsx)(X.Fragment,{children:Ne>0&&(0,X.jsxs)(`div`,{className:`lp-section lp-section-convs panel-convs ${U?`collapsed`:``}`,style:U?void 0:{flex:`${Ye(`convs`)} 1 0px`},onContextMenu:e=>Ce(e,{id:``,kind:`section`,label:k(`runningConversations`)}),children:[Ke(k(`runningConversations`),U,se,Ne,void 0,xe(_,`lp-slot-section`)),!U&&(0,X.jsxs)(`div`,{className:`lp-section-body convs-scroll`,children:[vs(De,te,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=>We(t,{path:e.cwd,lastUsed:0}),children:Be(e.cwd)}),ys(e.convs,de).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?k(`takeoverConfirm`):r?`${k(`elsewherePseudoTip`)}\n${n.cwd}`:`${k(i?`elsewhereOfflineTip`:`elsewhereTip`)}\n${n.cwd}`;return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ie(e=>e===n.id?null:e),onContextMenu:i=>Ce(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)(Se,{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:k(r?`elsewherePseudoBadge`:`elsewhereBadge`)}),i&&(0,X.jsx)(`span`,{className:`elsewhere-badge offline`,title:k(`elsewhereOfflineTip`),children:k(`elsewhereOfflineBadge`)}),n.hasQuestion&&e&&t&&!r&&(0,X.jsx)(`span`,{className:`question-badge clickable`,title:k(`takeoverHasQuestion`),onClick:n=>{n.stopPropagation(),o({type:`peek_elsewhere_question`,owner:e,id:t})},children:`?`}),s?k(`takeoverConfirm`):n.title]}),(0,X.jsx)(`span`,{className:`session-sub`,children:Be(n.cwd)})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:k(`streaming`)})]}),be&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-elsewhere-act`,title:k(`elsewhereActions`),onClick:i=>{i.stopPropagation(),ve.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)(_e,{})})]},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:()=>ne(e=>e===`conv:${n.id}`?null:e),onContextMenu:e=>Ce(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:k(s?`expandSubagents`:`collapseSubagents`),"aria-label":k(s?`expandSubagents`:`collapseSubagents`),onClick:e=>{e.stopPropagation(),fe(n.id)},children:s?(0,X.jsx)(gt,{}):(0,X.jsx)(vt,{})}),(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)(Se,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[z===`conv:${n.id}`?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:ae,placeholder:k(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>V(e.target.value),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Enter`&&!e.nativeEvent.isComposing){let e=ae.trim();e&&o({type:`rename_conversation`,id:n.id,name:e}),B(null)}else e.key===`Escape`&&B(null)},onBlur:()=>B(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[n.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:k(`pinnedConversation`),children:`📌`}),n.isSubagent&&(0,X.jsx)(`span`,{className:`subagent-badge`,children:k(`subagentBadge`)}),n.isEphemeral&&(0,X.jsx)(`span`,{className:`ephemeral-badge`,children:k(`ephemeralBadge`)}),n.forkFrom&&(0,X.jsxs)(`span`,{className:`preset-badge fork-badge`,title:`${k(`forkBadgeTip`)}: ${n.forkFrom.title??n.forkFrom.conversationId}`,children:[`🌿 `,k(`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:k(`convErrorBadge`,{error:n.error})}),n.hasQuestion&&(0,X.jsx)(`span`,{className:`question-badge`,title:k(`waitingQuestionBadge`),children:`?`}),i&&s&&(0,X.jsxs)(`span`,{className:`subagents-collapsed-badge${l?` has-streaming`:d?` has-question`:u?` has-error`:``}`,title:k(l?`subagentsStreamingTip`:d?`subagentsQuestionTip`:u?`subagentsErrorTip`:`subagentsCountTip`,{n:c}),onClick:e=>{e.stopPropagation(),fe(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:k(`subagentBadgeCount`,{n:c})})]})]}),z===`conv:${n.id}`?null:(0,X.jsx)(`span`,{className:`session-sub`,children:f?k(`current`):k(`messageCount`,{n:n.messageCount})})]}),n.isStreaming&&(0,X.jsx)(`span`,{className:`conv-streaming`,title:k(`streaming`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:k(`renameSession`),onClick:e=>{e.stopPropagation(),ne(null),V(n.title),B(`conv:${n.id}`)},children:(0,X.jsx)(Qe,{})}),(()=>{let e=`conv:${n.id}`,r=L===e,i=me(t,n.id),a=J(t,n.id),s=he(t,n.id);return s===0&&!n.isStreaming?Ge(e,k(`dismissConversation`),k(`dismissConversationConfirm`),()=>o({type:`dismiss_conversation`,id:n.id}),(0,X.jsx)(P,{})):s===0?Ge(e,k(`dismissConversation`),k(`dismissStreamingConfirm`),()=>o({type:`dismiss_conversation`,id:n.id,force:!0}),(0,X.jsx)(P,{})):r?(0,X.jsxs)(`span`,{className:`lp-del-group`,children:[i>0&&(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt`,title:k(`dismissFinishedSubagentsScoped`,{n:i}),onClick:e=>{e.stopPropagation(),ne(null),o({type:`dismiss_finished_subagents`,parentId:n.id})},children:k(`dismissFinishedOnly`,{n:i})}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del-opt danger`,title:k(`forceDismissTitle`,{n:s,m:a}),onClick:e=>{e.stopPropagation(),ne(null),o({type:`dismiss_conversation`,id:n.id,force:!0})},children:k(`dismissForceAll`,{n:s})})]}):(0,X.jsx)(`button`,{type:`button`,className:`lp-del`,title:k(`dismissConversation`),onClick:t=>{t.stopPropagation(),ne(e)},children:(0,X.jsx)(P,{})})})(),xe(Ie,`lp-slot-sessions`),n.isStreaming&&(0,X.jsx)(`span`,{className:`lp-row-stalled`,title:k(`streaming`),style:{position:`absolute`,right:28,top:`50%`,transform:`translateY(-50%)`}})]},n.id)})]},e.cwd)),Fe()]})]})}),sessions:(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`lp-section lp-section-sessions panel-sessions ${ce?`collapsed`:``}`,style:ce?void 0:{flex:`${Ye(`sessions`)} 1 0px`},children:[Ke(k(`historySessions`),ce,W,r.length,(0,X.jsx)(`button`,{type:`button`,className:`lp-section-action lp-new-chat-action`,title:k(`newChatTip`),"aria-label":k(`newChat`),onClick:()=>{o({type:`new_chat`}),wr()},children:(0,X.jsx)(q,{})}),xe(v,`lp-slot-section`)),!ce&&(0,X.jsxs)(`div`,{className:`lp-section-body sessions-scroll`,onScroll:e=>{if(K.length>=r.length)return;let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<180&&G(e=>Math.min(r.length,e+60))},children:[r.length===0&&(0,X.jsx)(`div`,{className:`panel-empty`,children:k(`noHistory`)}),K.map(e=>{let t=e=>(e??``).trim().replace(/[\\/]+$/,``).toLowerCase(),n=A===e.path,i=D?.kind===`session`&&t(D.target)===t(e.path);return(0,X.jsxs)(`div`,{className:`lp-row`,onMouseLeave:()=>ne(t=>t===`sess:${e.path}`?null:t),onContextMenu:t=>Ce(t,{id:e.path,kind:`history`,label:ze(e)}),children:[(0,X.jsxs)(`button`,{type:`button`,className:`session-item ${n?`active`:``} ${i?`switching`:``}`,title:e.path,disabled:i,onClick:()=>{z||i||n||o({type:`switch_session`,path:e.path})},children:[i?(0,X.jsx)(Oe,{className:`session-icon spin`}):(0,X.jsx)(Se,{className:`session-icon`}),(0,X.jsxs)(`span`,{className:`session-info`,children:[z===e.path?(0,X.jsx)(`input`,{autoFocus:!0,className:`session-rename-input`,value:ae,placeholder:k(`renameSessionPlaceholder`),onClick:e=>e.stopPropagation(),onChange:e=>V(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=ae.trim();t&&o({type:`rename_session`,path:e.path,name:t}),B(null)}else t.key===`Escape`&&B(null)},onBlur:()=>B(null)}):(0,X.jsxs)(`span`,{className:`session-title`,children:[e.pinned&&(0,X.jsx)(`span`,{className:`pin-badge`,title:k(`pinnedConversation`),children:`📌`}),ze(e)]}),z===e.path?null:(0,X.jsxs)(`span`,{className:`session-sub`,children:[n?k(`current`):k(`messageCount`,{n:e.messageCount}),e.source===`tui`&&(0,X.jsx)(`span`,{className:`session-src`,title:k(`tuiTip`),children:`TUI`}),e.parentSessionPath&&(0,X.jsx)(`span`,{className:`session-src session-fork-badge`,title:k(`forkedSessionTip`,{parent:(()=>{let n=t(e.parentSessionPath).replace(/\\/g,`/`),i=r.find(e=>t(e.path).replace(/\\/g,`/`)===n);return i?ze(i):(e.parentSessionPath.replace(/\\/g,`/`).split(`/`).pop()??e.parentSessionPath).replace(/\.jsonl$/i,``)})()}),children:k(`forkedSessionBadge`)})]})]}),(0,X.jsx)(`span`,{className:`session-time ${i?`switching-pct`:``}`,children:i?`${D.progress}%`:Vu(e.modified)})]}),(0,X.jsx)(`button`,{type:`button`,className:`lp-del lp-rename`,title:k(`renameSession`),onClick:t=>{t.stopPropagation(),ne(null),V(e.name??``),B(e.path)},children:(0,X.jsx)(Qe,{})}),Ge(`sess:${e.path}`,k(`deleteSession`),k(`deleteSessionConfirm`),()=>{Ru(e.path,N),o({type:`delete_session`,path:e.path})}),xe(Le,`lp-slot-sessions`)]},e.path)})]})]})})},$e=e=>{let t=Ae.find(t=>t.key===e)?.entry;if(!t)return null;let n=je(e);return(0,X.jsxs)(`div`,{className:`lp-section lp-section-plugin ${n?`collapsed`:``}`,style:n?void 0:{flex:`${Ye(e)} 1 0px`},children:[Ke(t.label,n,()=>ue(e)),!n&&(0,X.jsx)(`div`,{className:`lp-section-body lp-plugin-section-body`,children:b?.(t)??null})]})},et=e=>e===`projects`||e===`convs`||e===`sessions`?Ze[e]:$e(e);return(0,X.jsxs)(`aside`,{ref:we,className:`panel panel-left lp-panel`,children:[c&&l&&(0,X.jsx)(`button`,{type:`button`,className:`panel-collapse-btn`,title:k(`collapsePanel`),onClick:l,children:(0,X.jsx)(mt,{})}),Ae.map(({key:e})=>(0,X.jsxs)(g.Fragment,{children:[et(e),Xe.get(e)??null]},e)),(0,X.jsx)(Bo,{open:F,currentCwd:N,pathCompletions:u??[],workspaceRoots:M,onClose:()=>I(!1),onSelectDirectory:e=>o({type:`set_cwd`,path:e}),onCreateProject:e=>o({type:`make_dir`,path:e,setAsCwd:!0})})]})}),id=209715200,ad=/windows/i.test(navigator.userAgent),od=/[<>:"/\\|?*\u0000-\u001f]/g,sd=/[. ]+$/,cd=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function ld(e){let t=e.replace(od,`_`).replace(sd,``);return t?cd.test(t)?`_${t}`:t:`_`}function ud(e,t=!0){return Dn(Cn(`/api/file?${new URLSearchParams({clientId:Tu(),path:e,...t?{download:`1`}:{}})}`))}async function dd(e,t){let n=ad?ld(t):t;try{let t=await fetch(ud(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`)>id)return window.location.assign(ud(e)),{ok:!0};let r=await t.blob();return window.showSaveFilePicker&&window.isSecureContext?pd(r,n):md(r,n)}catch(e){return{ok:!1,cancelled:!1,error:e instanceof Error?e.message:String(e)}}}async function fd(e,t){let n=ad?ld(t):t;return window.showSaveFilePicker&&window.isSecureContext?pd(e,n):md(e,n)}async function pd(e,t){let n,r=window.showSaveFilePicker;if(!r)return md(e,t);try{n=await r({suggestedName:t})}catch(n){return n instanceof DOMException&&n.name===`AbortError`?{ok:!1,cancelled:!0}:md(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 md(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 hd(e,t,n){let r=Math.max(8,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 gd(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}function _d(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});return(0,g.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=hd(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=hd(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]),{anchorRef:t,show:()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},hide:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},tipPortal: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)}}function vd({text:e}){let{anchorRef:t,show:n,hide:r,onKeyDown:i,tipPortal:a}=_d(e);return(0,X.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:n,onMouseLeave:r,onFocus:n,onBlur:r,onKeyDown:i,children:[(0,X.jsx)(Ie,{}),a]})}function yd({tip:e,children:t,onMouseEnter:n,onMouseLeave:r,onFocus:i,onBlur:a,onKeyDown:o,...s}){let{anchorRef:c,show:l,hide:u,onKeyDown:d,tipPortal:f}=_d(e);return(0,X.jsxs)(`button`,{ref:c,type:`button`,"aria-label":s[`aria-label`]??e,...s,onMouseEnter:e=>{l(),n?.(e)},onMouseLeave:e=>{u(),r?.(e)},onFocus:e=>{l(),i?.(e)},onBlur:e=>{u(),a?.(e)},onKeyDown:e=>{d(e),o?.(e)},children:[t,f]})}var bd=e=>/\.(zip|tar|tar\.gz|tgz|gz)$/i.test(e);function xd(e,t={}){let n={archive:Cn(`/api/file-transfer/archive`),upload:Cn(`/api/file-transfer/upload`)},r=new URL(Dn(`${n[e]}?${new URLSearchParams({clientId:Tu(),...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 Sd(e,t,n){let r=await fetch(xd(`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 fd(await r.blob(),i);if(!a.ok&&!a.cancelled)throw Error(a.error)}}async function Cd(){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 wd(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=xd(`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 Td({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 Cd();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 wd(e.dir,c,d):await Sd(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)(P,{})})]}),(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 Ed(e){return e.startsWith(`.`)&&e!==`..`}function Dd(e,t){return t?e:e.filter(e=>!Ed(e.name))}function Od(e){return e instanceof Error?e.message:String(e)}function kd(e,t,n,r){let i=kn(n);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 Ad({plugin:e,epoch:t,send:n,className:r}){let i=(0,g.useRef)(null),{locale:a}=Xn(),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 Hl(e,t),r)return;let i=await Fc(e.id,()=>bl(()=>import(Ll(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,Wl(e.id,e=>l.current(e)))}catch(t){if(r)return;console.error(`[plugin:${e.id}] 页面${o?`挂载`:`加载`}失败:`,t),c({kind:o?`mount`:`load`,detail:Od(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:kd(s,e.name,a,o)})]})}function jd(e){return`pi-web-ui:${e}:tab`}function Md(e,t){try{let n=localStorage.getItem(jd(e));return n&&t.some(e=>e.id===n)?n:null}catch{return null}}function Nd(e,t){try{localStorage.setItem(jd(e),t)}catch{}}function Pd(e){return e.length>0&&!/[a-z]/i.test(e)}function Fd(e){if(e.label)return e.label;let t=e.pluginPage;return t?.entry.label||t?.plugin.name||e.id}function Id({storageKey:e,tabs:t,epoch:n,send:r,extra:i,className:a}){let o=(0,g.useId)(),[s,c]=(0,g.useState)(()=>Md(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,Nd(e,f.id))},[f,s,e]);let m=t=>{c(t.id),u.current=`${e}:${t.id}`,Nd(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??Fd(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)(Ni,{iconSvg:e.iconSvg,className:`slot-tab-icon`}):e.icon&&Pd(e.icon)?(0,X.jsx)(`span`,{className:`slot-tab-icon`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`slot-tab-label`,children:Fd(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)(Ad,{plugin:f.pluginPage.plugin,epoch:n,send:r}):f.element??null})]})}function Ld(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 Rd(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return Ld(e)}return Ld(e)}function zd(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 Rd(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 Bd=`@root`,Vd=`pi-web-ui:rp-sizes`,Hd=`pi-web-ui:files-show-hidden`,Ud={files:4,widgets:1},Wd=120,Gd=56;function Kd(e,t){return t?Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top):32}var qd=`files`,Jd=[],Yd=()=>{};function Xd(e){let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n<0?``:n===0?`/`:t.slice(0,n)}function Zd(e){return e===Bd||e===`/`||/^[A-Za-z]:$/.test(e)}function Qd(e){return e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)}var $d=(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??Jd,_=go(`cwd`),v=go(`workspaceRoots`),y=go(`homeDir`),b=go(`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 gs(localStorage.getItem(Vd),Ud)}catch{return{...Ud}}});(0,g.useEffect)(()=>{try{localStorage.setItem(Vd,JSON.stringify(k))}catch{}},[k]);let[j,ee]=(0,g.useState)(()=>{try{return localStorage.getItem(Hd)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{localStorage.setItem(Hd,j?`1`:`0`)}catch{}},[j]);let te=n.some(e=>e.lines.length>0),M=(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-Kd(t,O.current));n.classList.add(`dragging`),document.body.classList.add(`rp-resizing`);let o=e=>{let{above:t,below:n}=_s({start:i,deltaPx:e.clientY-r,availablePx:a,totalWeight:i.above+i.below,minAbovePx:Wd,minBelowPx:Gd});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]),N=(0,g.useRef)(null),F=(0,g.useRef)(0),I=(0,g.useCallback)(e=>{N.current=e,e&&(e.scrollTop=F.current)},[]),[L,ne]=(0,g.useState)(null),re=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]);let ie=(0,g.useCallback)(e=>{ne(e),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>ne(null),1200)},[]),R=(0,g.useCallback)((e,t)=>{e&&Rd(e).then(e=>{e?ie(t):o(`error`,m(`slashCopyFailed`))})},[ie,o,m]),z=(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},[_]),B=(0,g.useCallback)(e=>!e||e===Bd?null:e.startsWith(`/`)||/^[A-Za-z]:([/]|$)/.test(e)?e:`${_.replace(/\\/g,`/`).replace(/\/+$/,``)}/${e}`,[_]),ae=104857600,V=(0,g.useCallback)((e,t)=>{for(let n of t){if(n.size>ae){o(`warning`,m(`fileTooLarge`,{name:n.name,size:ae/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]),H=(0,g.useRef)(null),[oe,U]=(0,g.useState)(null),se=(0,g.useRef)(null),ce=(0,g.useCallback)(()=>{let e=H.current?.project;e&&r({type:`set_cwd`,path:e.path})},[r]),W=(0,g.useCallback)(()=>{se.current&&(se.current.value=``),se.current?.click()},[]),[le,ue]=(0,g.useState)(null),[de,fe]=(0,g.useState)(null),[pe,G]=(0,g.useState)(``),[K,me]=(0,g.useState)(null),[q,he]=(0,g.useState)(``),J=(0,g.useCallback)((e,t)=>{dd(e,t).then(e=>{e.ok||e.cancelled||o(`error`,m(`downloadFailed`,{error:e.error===`FILE_NOT_FOUND`?m(`fileNotFoundShort`):e.error}))})},[o,m]),ge=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&(me(null),G(e.label),fe(e.id))},[]),_e=(0,g.useCallback)(()=>{if(!de)return;let e=pe.trim();fe(null),e&&r({type:`file_rename`,path:de,newName:e})},[de,pe,r]),ye=(0,g.useCallback)(e=>{let t=H.current?.dir??x;fe(null),he(``),me({dir:t,kind:e})},[x]),be=(0,g.useCallback)(()=>{if(!K)return;let e=q.trim();me(null),e&&r({type:`file_create`,dir:K.dir,name:e,kind:K.kind})},[K,q,r]),Y=(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}),xe=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&window.confirm(m(`fileDeleteConfirm`,{name:e.label}))&&(le?.src===e.id&&ue(null),de===e.id&&fe(null),r({type:`file_delete`,path:e.id}))},[r,m,le,de]),Se=(0,g.useCallback)(()=>{let e=H.current?.target;e&&e.kind!==`list`&&!Zd(e.id)&&r({type:`file_copy`,src:e.id,destDir:Xd(e.id)})},[r]),Ce=(0,g.useCallback)(e=>{let t=H.current?.target;t&&t.kind!==`list`&&!Zd(t.id)&&ue({src:t.id,cut:e})},[]),we=(0,g.useCallback)(()=>{if(!le)return;let e=H.current?.dir??x;le.cut?(r({type:`file_copy`,src:le.src,destDir:e,move:!0}),ue(null)):r({type:`file_copy`,src:le.src,destDir:e})},[le,r,x]),Ee=(0,g.useCallback)(()=>{r({type:`list_files`,path:x===``?void 0:x})},[r,x]),[De,Oe]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(!De)return;let e=e=>{e.target?.closest(`.root-picker`)||Oe(!1)},t=e=>{e.key===`Escape`&&Oe(!1)};return window.addEventListener(`mousedown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e,!0),window.removeEventListener(`keydown`,t)}},[De]);let ke=(0,g.useCallback)(e=>{r({type:`set_workspace_roots`,roots:e})},[r]),je=(0,g.useCallback)(()=>{let e=H.current?.target;if(!e||e.kind!==`dir`)return;let t=B(e.id);t&&!v.includes(t)&&ke([...v,t])},[v,B,ke]),Me=(0,g.useCallback)(e=>{V(H.current?.dir??x,Array.from(e.target.files??[]))},[V,x]),Ne=(0,g.useCallback)(e=>{let t=H.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`;U({action:n,path:z(t.id),dir:z(n===`upload`?H.current?.dir??x:Xd(t.id))});break}case`host:file-open-project`:ce();break;case`host:file-upload`:W();break;case`host:file-add-root`:je();break;case`host:file-open`:t?.kind===`file`&&a(t.id,t.label);break;case`host:file-enter`:t?.kind===`dir`&&Xe(t.id);break;case`host:file-download`:t?.kind===`file`&&J(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`:ye(`file`);break;case`host:file-new-dir`:ye(`dir`);break;case`host:file-paste`:we();break;case`host:file-rename`:ge();break;case`host:file-duplicate`:Se();break;case`host:file-cut`:Ce(!0);break;case`host:file-copy`:Ce(!1);break;case`host:file-copy-name`:t&&t.kind!==`list`&&R(t.label,`name:${t.id}`);break;case`host:file-copy-path`:t&&t.kind!==`list`&&R(z(t.id),`path:${t.id}`);break;case`host:file-copy-rel`:t&&t.kind!==`list`&&R(t.id,`rel:${t.id}`);break;case`host:file-refresh`:Ee();break;case`host:file-delete`:xe()}},[ce,x,W,je,a,i,R,z,J,ye,we,ge,Se,Ce,Ee,xe]),Pe=(0,g.useCallback)((e,t)=>{let n=t.kind===`dir`?B(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&&Zd(t.id),l=!s&&Qd(t.id),d=x===Bd,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&&bd(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!==Bd?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&&le?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}});to(f).length!==0&&(e.preventDefault(),e.stopPropagation(),H.current=r,Wa({x:e.clientX,y:e.clientY,slot:`contextmenu.file`,target:t,entries:f,onHostAction:Ne}))},[u,x,B,m,Ne,_,v,le]),Ie=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),Re=(0,g.useCallback)(()=>{N.current?.querySelectorAll(`.file-item.drop-target`).forEach(e=>e.classList.remove(`drop-target`)),N.current?.classList.remove(`drop-root`)},[]),ze=(0,g.useCallback)(e=>{if(Re(),e==null)return;let t=N.current?.querySelector(`.file-item[data-path="${CSS.escape(e)}"]`);t?t.classList.add(`drop-target`):N.current?.classList.add(`drop-root`)},[Re]),Be=e=>{let t=e instanceof Element?e.closest(`.file-item`):null;return t?.dataset.type===`dir`?t.dataset.path??x:x},Ve=(0,g.useCallback)(()=>{let e=document.querySelector(`.app`);e&&e.dispatchEvent(new DragEvent(`dragleave`,{bubbles:!0}))},[]),Ue=(0,g.useRef)(0),Ge=(0,g.useRef)(void 0),Ke=(0,g.useCallback)((e,t)=>{let n=++Ue.current;S(e),t?.silent||E(!0),r({type:`list_files`,path:e===``?void 0:e})||Ue.current===n&&E(!1)},[r]),qe=(0,g.useCallback)(e=>{let t=v.filter(t=>t!==e);ke(t),(x===e||x.startsWith(`${e}/`))&&Ke(``)},[v,ke,x,Ke]);(0,g.useEffect)(()=>{e&&e.path===x&&E(!1)},[e,x]),(0,g.useEffect)(()=>{if(_!==Ge.current){let e=Ge.current===void 0;Ge.current=_,e?Ke(``,{silent:!0}):S(``);return}let e=setInterval(()=>{document.visibilityState!==`hidden`&&Ke(x,{silent:!0})},1e4);return()=>clearInterval(e)},[_,x,Ke]),(0,g.useEffect)(()=>{t&&t.path===x&&Ke(x,{silent:!0})},[t,x,Ke]);let Xe=e=>Ke(e),Ze=()=>{e?.parent!==null&&e?.parent!==void 0&&Ke(e.parent)},Qe=(()=>{if(x===``||x===Bd)return[];let e=x.split(`/`).filter(e=>!!e&&e!==Bd);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(`/`)}))})(),et=[];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&&et.push({id:e.id,label:e.label,icon:e.icon,...e.iconSvg?{iconSvg:e.iconSvg}:{},hint:e.hint,pluginPage:{plugin:t,entry:e}})}let tt=(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)(pt,{})}),(0,X.jsx)(`div`,{ref:O,style:{display:`flex`,flexDirection:`column`,flex:te?`${k.files} 1 0`:`1 1 0`,minHeight:te?Wd:0},children:(0,X.jsx)(Id,{storageKey:`rightpanel`,epoch:f??0,send:p??Yd,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===qd?`host:right-files`:e)??1e9;return[...e].sort((e,t)=>r(e.id)-r(t.id))})([...tt?[]:[{id:qd,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:()=>Ke(``),children:m(`rootDir`)}),(0,X.jsx)(yd,{className:`crumb ${x===Bd?`active`:``}`,tip:m(`computer`),onClick:()=>Ke(Bd),children:(0,X.jsx)(Le,{})}),y!==``&&(0,X.jsx)(yd,{className:`crumb ${x===y||x.startsWith(`${y}/`)?`active`:``}`,tip:m(`homeDir`),onClick:()=>Ke(y),children:(0,X.jsx)(Fe,{})}),b!==``&&(0,X.jsx)(yd,{className:`crumb ${x===b||x.startsWith(`${b}/`)?`active`:``}`,tip:m(`desktopDir`),onClick:()=>Ke(b),children:(0,X.jsx)(ve,{})}),(0,X.jsx)(yd,{className:`crumb ${j?`active`:``}`,tip:m(j?`filesHideHidden`:`filesShowHidden`),"aria-pressed":j,onClick:()=>ee(e=>!e),children:j?(0,X.jsx)(Je,{}):(0,X.jsx)(Ye,{})}),(0,X.jsx)(vd,{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":De,title:m(`workspaceRoots`),onClick:()=>Oe(e=>!e),children:[(0,X.jsx)(He,{}),(0,X.jsx)(`span`,{className:`root-picker-label`,children:m(`workspaceRoots`)}),(0,X.jsx)(`span`,{className:`set-count`,children:v.length+1}),`▾`]}),De&&(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:()=>{Oe(!1),Ke(``)},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:()=>{Oe(!1),Ke(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:()=>qe(e),children:(0,X.jsx)(P,{})})]},e)),(0,X.jsx)(`div`,{className:`root-picker-hint`,children:m(`workspaceRootsHint`)})]})]}),Qe.map(e=>(0,X.jsxs)(`span`,{className:`crumb-seg`,children:[(0,X.jsx)(gt,{}),(0,X.jsx)(`button`,{type:`button`,className:`crumb ${e.path===x?`active`:``}`,onClick:()=>Ke(e.path),children:e.label})]},e.path))]}),(0,X.jsxs)(`div`,{ref:I,className:`panel-body`,onScroll:e=>{F.current=e.currentTarget.scrollTop},onContextMenu:e=>Pe(e,{id:x,kind:`list`,label:x===``?m(`rootDir`):x===Bd?m(`computer`):x}),onDragOver:e=>{Ie(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,Ve(),ze(Be(e.target)))},onDragLeave:e=>{e.relatedTarget&&e.currentTarget.contains(e.relatedTarget)||Re()},onDrop:e=>{if(Re(),!Ie(e))return;e.preventDefault(),e.stopPropagation(),Ve();let t=Array.from(e.dataTransfer?.files??[]);if(t.length===0){o(`warning`,m(`foldersNotSupported`));return}V(Be(e.target),t)},onDragEnd:Re,children:[(0,X.jsx)(`input`,{ref:se,type:`file`,multiple:!0,hidden:!0,onChange:Me}),oe&&(0,X.jsx)(Td,{request:oe,onClose:()=>U(null),onComplete:Ee}),K&&(0,X.jsxs)(`div`,{className:`file-item dir`,children:[K.kind===`dir`?(0,X.jsx)(He,{className:`file-icon`}):(0,X.jsx)(We,{className:`file-icon`}),Y(q,he,be,()=>me(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:Ze,children:[(0,X.jsx)(He,{className:`file-icon`}),(0,X.jsx)(`span`,{className:`file-name`,children:`..`})]}),Dd(e.entries,j).map(e=>e.type===`dir`?(0,X.jsxs)(`div`,{className:`file-item dir${le?.cut&&le.src===e.path?` cut`:``}`,"data-type":`dir`,"data-path":e.path,onContextMenu:t=>Pe(t,{id:e.path,kind:`dir`,label:e.name}),children:[de===e.path?Y(pe,G,_e,()=>fe(null)):(0,X.jsxs)(`button`,{type:`button`,className:`file-dir-main`,onClick:()=>Xe(e.path),children:[(0,X.jsx)(He,{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)(Ae,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>R(e.name,`name:${e.path}`),children:L===`name:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(st,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>R(z(e.path),`path:${e.path}`),children:L===`path:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(dt,{})})]},e.path):(0,X.jsxs)(`div`,{className:`file-item file${le?.cut&&le.src===e.path?` cut`:``}`,"data-type":`file`,"data-path":e.path,onContextMenu:t=>Pe(t,{id:e.path,kind:`file`,label:e.name}),children:[de===e.path?Y(pe,G,_e,()=>fe(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)(We,{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:()=>J(e.path,e.name),children:(0,X.jsx)($e,{})}),(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)(Ae,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`name:${e.path}`?` copied`:``}`,"data-tip":m(`copyName`),"aria-label":m(`copyName`),onClick:()=>R(e.name,`name:${e.path}`),children:L===`name:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(st,{})}),(0,X.jsx)(`button`,{type:`button`,className:`file-attach copy${L===`path:${e.path}`?` copied`:``}`,"data-tip":m(`copyPath`),"aria-label":m(`copyPath`),onClick:()=>R(z(e.path),`path:${e.path}`),children:L===`path:${e.path}`?(0,X.jsx)(yt,{}):(0,X.jsx)(dt,{})})]},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`)})]})]})}],...et])})}),te&&(0,X.jsx)(`div`,{className:`rp-sash`,onPointerDown:M,onDoubleClick:()=>A({...Ud}),title:m(`dragToResize`)}),te&&(0,X.jsx)(`div`,{className:`panel-widgets`,style:{flexGrow:k.widgets,minHeight:Gd},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)(Te,{})]}),(0,X.jsx)(`pre`,{className:`widget-lines`,children:e.lines.join(`
|
|
330
330
|
`)})]},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)(P,{})})]}),(0,X.jsx)(`pre`,{className:`widget-expand-lines`,children:e.lines.join(`
|
|
331
331
|
`)})]})}):null})()]})}),ef=[{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.git-worktree`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:`\\bgit(?:\\.exe)?(?:\\s+(?:-[cC]\\s+\\S+|--[a-zA-Z-]+=\\S+))*\\s+worktree\\s+(add|remove|prune)\\b`,action:`ask`,label:`Git 工作树操作 (git worktree)`,labelEn:`Git worktree operation (git worktree)`,reason:`检测到通过 Bash 执行 git worktree 操作;建议使用专门的 worktree 工具以确保界面感知与工作区同步`,reasonEn:`Detected git worktree via Bash; prefer using the dedicated worktree tool to keep the UI synchronized`,categoryId:`bash.git-worktree`,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 tf(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 nf(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 tf(n)}let n=[];for(let t of ef){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 tf(n)}function rf(e,t){let n=nf(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 af({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 of=function(){let e=this.data();(e.micromarkExtensions??=[]).push({flow:{92:sf(!0)},text:{92:sf(!1)}});let t={enter:{backslashMathInline:cf,backslashMathDisplay:cf,backslashMathBlock:cf},exit:{backslashMathInline:lf,backslashMathDisplay:lf,backslashMathBlock:lf}};(e.fromMarkdownExtensions??=[]).push(t)};function sf(e){return{tokenize:function(t,n,r){let i=this,a=93,o=e?`backslashMathBlock`:`backslashMathDisplay`,s;return c;function c(e){return e===92?(s=t.enter(o),t.consume(e),l):r(e)}function l(n){return n!==91&&(e||n!==40)?r(n):(a=n===91?93:41,!e&&n===40&&(s.type=o=`backslashMathInline`),t.consume(n),u)}function u(n){return n===null||e&&i.parser.lazy[i.now().line]?r(n):n===-5||n===-4||n===-3?(t.enter(`lineEnding`),t.consume(n),t.exit(`lineEnding`),u):(f(n),n===92?d:u)}function d(i){return i===a?(f(i),t.exit(o),e?p:n):i===null?r(i):i===-5||i===-4||i===-3?u(i):(f(i),u)}function f(e){t.enter(`backslashMathData`),t.consume(e),t.exit(`backslashMathData`)}function p(e){return e===null||e===-5||e===-4||e===-3?n(e):e===32||e===-2||e===-1?(t.enter(`whitespace`),t.consume(e),t.exit(`whitespace`),p):r(e)}},concrete:e,name:e?`backslashMathBlock`:`backslashMathText`}}var cf=function(e){let t=e.type===`backslashMathBlock`,n=e.type!==`backslashMathInline`,r=this.sliceSerialize(e).slice(2,-2).trim(),i={type:`element`,tagName:`code`,properties:{className:[`language-math`,n?`math-display`:`math-inline`]},children:[{type:`text`,value:r}]},a=t?{type:`math`,meta:null,value:r,data:{hName:`pre`,hChildren:[i]}}:{type:`inlineMath`,value:r,data:{hName:`code`,hProperties:i.properties,hChildren:i.children}};this.enter(a,e)},lf=function(e){this.exit(e)},uf=[`ariaDescribedBy`,`ariaLabel`,`ariaLabelledBy`],df={ancestors:{tbody:[`table`],td:[`table`],th:[`table`],thead:[`table`],tfoot:[`table`],tr:[`table`]},attributes:{a:[...uf,`dataFootnoteBackref`,`dataFootnoteRef`,[`className`,`data-footnote-backref`],`href`],blockquote:[`cite`],code:[[`className`,/^language-./]],del:[`cite`],div:[`itemScope`,`itemType`],dl:[...uf],h2:[[`className`,`sr-only`]],img:[...uf,`longDesc`,`src`],input:[[`disabled`,!0],[`type`,`checkbox`]],ins:[`cite`],li:[[`className`,`task-list-item`]],ol:[...uf,[`className`,`contains-task-list`]],q:[`cite`],section:[`dataFootnotes`,[`className`,`footnotes`]],source:[`srcSet`],summary:[...uf],table:[...uf],ul:[...uf,[`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(`.`)},ff={}.hasOwnProperty;function pf(e,t){let n={type:`root`,children:[]},r=mf({schema:t?{...df,...t}:df,stack:[]},e);return r&&(Array.isArray(r)?r.length===1?n=r[0]:n.children=r:n=r),n}function mf(e,t){if(t&&typeof t==`object`){let n=t;switch(typeof n.type==`string`?n.type:``){case`comment`:return hf(e,n);case`doctype`:return gf(e,n);case`element`:return _f(e,n);case`root`:return vf(e,n);case`text`:return yf(e,n)}}}function hf(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 Ef(r,t),r}}function gf(e,t){if(e.schema.allowDoctypes){let e={type:`doctype`};return Ef(e,t),e}}function _f(e,t){let n=typeof t.tagName==`string`?t.tagName:``;e.stack.push(n);let r=bf(e,t.children),i=xf(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&&ff.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 Ef(o,t),o}function vf(e,t){let n={type:`root`,children:bf(e,t.children)};return Ef(n,t),n}function yf(e,t){let n={type:`text`,value:typeof t.value==`string`?t.value:``};return Ef(n,t),n}function bf(e,t){let n=[];if(Array.isArray(t)){let r=t,i=-1;for(;++i<r.length;){let t=mf(e,r[i]);t&&(Array.isArray(t)?n.push(...t):n.push(t))}}return n}function xf(e,t){let n=e.stack[e.stack.length-1],r=e.schema.attributes,i=e.schema.required,a=r&&ff.call(r,n)?r[n]:void 0,o=r&&ff.call(r,`*`)?r[`*`]:void 0,s=t&&typeof t==`object`?t:{},c={},l;for(l in s)if(ff.call(s,l)){let t=s[l],n=Sf(e,Df(a,l),l,t);n??=Sf(e,Df(o,l),l,t),n!=null&&(c[l]=n)}if(i&&ff.call(i,n)){let e=i[n];for(l in e)ff.call(e,l)&&!ff.call(c,l)&&(c[l]=e[l])}return c}function Sf(e,t,n,r){return t?Array.isArray(r)?Cf(e,t,n,r):wf(e,t,n,r):void 0}function Cf(e,t,n,r){let i=-1,a=[];for(;++i<r.length;){let o=wf(e,t,n,r[i]);(typeof o==`number`||typeof o==`string`)&&a.push(o)}return a}function wf(e,t,n,r){if((typeof r==`boolean`||typeof r==`number`||typeof r==`string`)&&Tf(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 Tf(e,t,n){let r=e.schema.protocols&&ff.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 Ef(e,t){let n=c(t);t.data&&(e.data=o(t.data)),n&&(e.position=n)}function Df(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 Of(e){return function(t){return pf(t,e)}}var kf=(0,g.memo)(function({text:e}){let t=Z(),{copied:n,copy:r}=zd({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)(yt,{}):(0,X.jsx)(st,{})}):null});function Af(e){let t=e=>{if(typeof e==`string`||typeof e==`number`){let t=String(e);return t===``?[[]]:t.split(`
|
|
332
332
|
`).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 jf(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(jf).join(``);if(e&&typeof e==`object`&&`props`in e){let t=e.props;return jf(t?.children)}return``}function Mf(e){let t=Array.isArray(e)?e[0]:e;return!t||typeof t!=`object`||!(`props`in t)?null:t}function Nf(e){let t=Mf(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 Pf=`pi-web-ui:plugin-data`,Ff=new Map,If=new Map,Lf=new Set,Rf=-1,zf=0,Bf=new Set;function Vf(){zf++;for(let e of Bf)e()}function Hf(e){return Bf.add(e),()=>{Bf.delete(e)}}function Uf(){return zf}var Wf=null;function Gf(e){Wf=e}function Kf(e,t){t!==Rf&&(Rf=t,If.clear(),Lf.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!==Ff.size;if(!r){for(let[e,t]of n)if(Ff.get(e)!==t){r=!0;break}}if(r){for(let e of If.keys())n.has(e)||If.delete(e);for(let e of Lf)n.has(e)||Lf.delete(e);Ff=n,Vf()}}async function qf(e,t){let n=Ff.get(e);if(!n)return null;let r=If.get(e);if(!r&&!Lf.has(e))try{let t=(await bl(()=>import(Cn(`/plugins/${encodeURIComponent(n)}/client/entry.mjs?e=${Rf}`)),[])).default?.renderers?.[e];typeof t==`function`?(r={pluginId:n,renderer:t},If.set(e,r)):(Lf.add(e),console.error(`[plugin:${n}] entry.mjs 未提供 renderers["${e}"]`))}catch(t){Lf.add(e),console.error(`[plugin:${n}] renderer 加载失败(${e}):`,t)}if(!r)return null;let i={pluginId:r.pluginId,send:e=>{Wf?.({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(Pf,t),()=>window.removeEventListener(Pf,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 Jf(e){return Ff.has(e)}var Yf=new Map,Xf=new Map,Zf=new Set,Qf=-1;function $f(e,t){t!==Qf&&(Qf=t,Xf.clear(),Zf.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(Yf.keys()))n.has(e)||Yf.delete(e);for(let[e,t]of n)Yf.set(e,t);for(let e of Xf.keys())n.has(e)||Xf.delete(e);for(let e of Zf)n.has(e)||Zf.delete(e)}function ep(e){return Yf.has(e)}async function tp(e){let t=Yf.get(e);if(!t)return null;let n=Xf.get(e);if(!n&&!Zf.has(e))try{let r=(await bl(()=>import(Cn(`/plugins/${encodeURIComponent(t)}/client/entry.mjs?e=${Qf}`)),[])).default?.messageWidgets?.[e];typeof r==`function`?(n={pluginId:t,renderer:r},Xf.set(e,n)):(Zf.add(e),console.error(`[plugin:${t}] entry.mjs 未提供 messageWidgets["${e}"]`))}catch(n){Zf.add(e),console.error(`[plugin:${t}] messageWidget 加载失败(${e}):`,n)}return n?.renderer??null}var np=`pi-web-ui:theme`,rp=`dark`,ip=`theme-stylesheet`,ap=`pi-web-ui:theme-change`;function op(){try{let e=localStorage.getItem(np);if(e&&e!==rp)return e}catch{}return null}function sp(e){try{e?localStorage.setItem(np,e):localStorage.removeItem(np)}catch{}}function cp(e){let t=document.getElementById(ip);if(!e){t?.remove(),window.dispatchEvent(new CustomEvent(ap));return}t||(t=document.createElement(`link`),t.id=ip,t.rel=`stylesheet`,document.head.appendChild(t)),t.href=Cn(`/themes/${encodeURIComponent(e)}.css`),t.onload=()=>window.dispatchEvent(new CustomEvent(ap))}async function lp(){try{let e=await fetch(Dn(Cn(`/api/themes`)));if(!e.ok)return[];let t=await e.json();return Array.isArray(t.themes)?t.themes:[]}catch{return[]}}function up(){let[e,t]=(0,g.useState)([]),[n,r]=(0,g.useState)(()=>op());(0,g.useEffect)(()=>{let e=!1;return lp().then(n=>{e||t(n)}),()=>{e=!0}},[]);let i=(0,g.useCallback)(()=>{lp().then(t)},[]);return(0,g.useEffect)(()=>{cp(n),sp(n)},[n]),{themes:e,theme:n,switchTheme:e=>r(e===rp?null:e),reloadThemes:i}}function dp(){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 fp({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(ap)),a.current.set(t,e))};return window.addEventListener(ap,e),()=>window.removeEventListener(ap,e)},[]),(0,g.useEffect)(()=>{let n=!1,r=i.current;return s(null),qf(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(ap)),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)(kf,{text:t}),(0,X.jsx)(`pre`,{children:(0,X.jsx)(`code`,{children:t})})]})}var pp=null,mp=null;function hp(e){pp=e?.open??null,mp=e?.isOpen??null}function gp(){return mp?mp():!1}function _p(e){return!pp||!e?.path?!1:(pp(e),!0)}var vp=[u,s,of],yp=[u,a,s,of],bp=[[l,{strict:!1,throwOnError:!1}],[d,{detect:!0,ignoreMissing:!0}]];function xp(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 Sp({text:e,rawHtml:t=!1,hardBreaks:n=!1}){let r=t?[p,Of,...bp]:bp,i=(0,g.useMemo)(()=>xp(e),[e]);return(0,X.jsx)(f,{remarkPlugins:n?yp:vp,rehypePlugins:r,components:{pre:Tp,a:wp},children:i})}var Cp=(0,g.memo)(function({text:e,rawHtml:t=!1,hardBreaks:n=!1}){return(0,X.jsx)(`div`,{className:`md`,children:(0,X.jsx)(Sp,{text:e,rawHtml:t,hardBreaks:n})})});function wp({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(),_p({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 Tp({children:e,...t}){(0,g.useSyncExternalStore)(Hf,Uf,Uf);let n=Nf(e);return n&&Jf(n)?(0,X.jsx)(fp,{lang:n,code:jf(e)}):(0,X.jsx)(Ep,{children:e,...t})}function Ep({children:e,...t}){let n=Af(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)(kf,{text:Dp(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 Dp(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(Dp).join(``);if(e&&typeof e==`object`&&`props`in e){let t=e.props;return Dp(t?.children)}return``}function Op({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),ep(e))return tp(e).then(async r=>{if(!n&&r)try{let i=await r(t,{pluginId:Yf.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 kp=/^\s{0,3}(`{3,}|~{3,})/,Ap=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function jp(e){return e.trim()===``}function Mp(e){let t=kp.exec(e);return t?t[1]:null}function Np(e){let t=e.split(`
|
|
@@ -687,4 +687,4 @@ Systematic steps for investigating and resolving software defects:
|
|
|
687
687
|
`)})]}):(0,X.jsx)(`div`,{className:`set-catalog-job error`,children:(0,X.jsxs)(`span`,{children:[`✗ `,ca.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)}),Pi(sa),(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:na,children:u(`pluginCatalogAddSubmit`)}),(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,onClick:()=>Zn(!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=_i.has(t.id),r=e.pluginUpdates?.[t.id],i=n&&r?.updatable===!0,a=!!(Mi(t.id)&&Mi(t.id)?.phase!==`done`),o=!kn(d)&&t.nameEn?t.nameEn:t.name,s=!kn(d)&&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)(Ni,{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}),Fi(t.id)]}),(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[tC(t)&&(0,X.jsxs)(`a`,{href:tC(t),target:`_blank`,rel:`noreferrer noopener`,className:`set-uninstall link`,title:u(`pluginOfficialLinkHint`),children:[(0,X.jsx)(Xe,{}),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:()=>$i(t.id,t.source),children:[(0,X.jsx)(me,{className:a?`set-job-spin`:``}),u(a?`pluginJobRunning`:`pluginUpdate`)]}),An===t.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,disabled:a,title:u(`pluginUninstallHint`),onClick:()=>Qi(t.id),children:u(`uninstallConfirm`)}):(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,disabled:a,title:u(`pluginUninstallHint`),onClick:()=>jn(t.id),children:[(0,X.jsx)(R,{}),u(`uninstallExt`)]})]}):(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginInstallHint`),disabled:a,onClick:()=>ea(t),children:a?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(me,{className:`set-job-spin`}),u(`pluginJobRunning`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($e,{}),u(`pluginInstall`)]})}),!t.builtin&&(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall`,title:u(`pluginCatalogRemoveHint`),onClick:()=>ta(t.id),children:(0,X.jsx)(P,{})})]})]},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)(Ct,{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)(Xe,{}),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)(me,{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)(me,{}),u(`pluginRescan`)]})]}),e.plugins.length>0&&(0,X.jsx)(nC,{plugins:e.plugins,disabledIds:gi}),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)(ZS,{title:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eC,{phase:IS(t,gi.has(t.id)),label:f($S(IS(t,gi.has(t.id))))}),(0,X.jsx)(Ni,{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:!gi.has(t.id)&&!t.error,onToggle:()=>!t.error&&vi(t),action:(0,X.jsxs)(`div`,{className:`set-row-actions`,children:[(()=>{let n=tC(e.pluginCatalog.find(e=>e.id===t.id))||tC(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)(Xe,{}),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:()=>$i(t.id,t.source),children:[(0,X.jsx)(me,{className:i?`set-job-spin`:``}),u(i?`pluginJobRunning`:`pluginUpdate`)]}),An===t.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,disabled:i,title:u(`pluginUninstallHint`),onClick:()=>Qi(t.id),children:u(`uninstallConfirm`)}):(0,X.jsxs)(`button`,{type:`button`,className:`set-uninstall`,disabled:i,title:u(`pluginUninstallHint`),onClick:()=>jn(t.id),children:[(0,X.jsx)(R,{}),u(`uninstallExt`)]})]})},t.id),Fi(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=>Ci.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:()=>{Pn===t.id?Fn(null):(Fn(t.id),$(Kl(t.id)))},children:[(0,X.jsx)(Ge,{}),u(`pluginLogTitle`),` (`,$l(t.id).length,`) ·`,` `,Pn===t.id?u(`pluginLogHide`):u(`pluginLogShow`)]}),Pn===t.id&&(0,X.jsx)(aC,{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:()=>Nn(Mn===t.id?null:t.id),children:[(0,X.jsx)(Pt,{}),u(`pluginDiagTitle`),` (`,t.diagnostics.length,`) ·`,` `,Mn===t.id?u(`pluginDiagHide`):u(`pluginDiagShow`)]}),Mn===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,`) ·`,` `,In[t.id]?u(`pluginSettingsHide`):u(`pluginSettingsShow`)]}),In[t.id]&&(0,X.jsx)(tx,{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)(Ct,{className:`set-section-icon`}),u(`dshPatches`),(0,X.jsx)(vd,{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)(me,{}),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:[Sh(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)(N,{className:`set-section-icon`}),u(`settingsReview`),(0,X.jsx)(vd,{text:u(`settingsReviewDesc`)}),(0,X.jsx)(`span`,{className:`set-count`,children:_.reviewSkills.length})]}),(0,X.jsx)(ZS,{title:u(`goalModeEnabled`),tip:`${u(`goalModeEnabledDesc`)}\n${u(`goalModeOffHint`)}`,enabled:_.goalModeEnabled,onToggle:()=>Q({goalModeEnabled:!_.goalModeEnabled})}),(0,X.jsx)(ZS,{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:dt,onFocus:()=>pt.current=!0,onBlur:()=>{pt.current=!1,Q({reviewPrompt:dt})},onChange:e=>ft(e.target.value)}),(0,X.jsxs)(`div`,{className:`set-field-label`,children:[u(`settingsReviewSkills`),x&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsx)(vd,{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)(ZS,{title:e.name,subtitle:e.description,enabled:e.enabled,onToggle:()=>la(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)(Je,{className:`set-section-icon`}),u(`settingsVisionBridge`)]}),(0,X.jsx)(ZS,{title:u(`visionBridgeEnabled`),tip:`${u(`settingsVisionBridgeDesc`)}\n${u(`visionBridgeOffHint`)}`,enabled:_.visionBridgeEnabled,onToggle:()=>Q({visionBridgeEnabled:!_.visionBridgeEnabled})}),_.visionBridgeEnabled&&(0,X.jsx)(rC,{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)(iC,{mode:We,onModeChange:Ke,draft:Be,onDraftChange:Ue,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:qe})]}),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)(vd,{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:()=>bt({name:_.presets[0]?.name??``,tab:`export`}),children:[(0,X.jsx)(W,{}),u(`presetShareShareBtn`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-preset-share-btn`,title:u(`presetShareImportBtn`),onClick:()=>bt({name:``,tab:`import`}),children:[(0,X.jsx)(L,{}),u(`presetShareImportBtn`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`set-preset-share-btn`,title:u(`presetShareBrowseBtn`),onClick:()=>bt({name:``,tab:`browse`}),children:[(0,X.jsx)(ze,{}),u(`presetShareBrowseBtn`)]})]}),ii&&(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)(vd,{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:dy(e.dshPresets.presets).map(e=>(0,X.jsxs)(`option`,{value:e.id,disabled:!!e.broken,children:[uy(e,d,u).name,e.trust===`user`?` · ${u(`dshPresetUser`)}`:``,e.broken?` · ${u(`dshPresetBroken`)}`:``]},e.id))})]}),ni&&(0,X.jsx)(`p`,{className:`set-preset-config-desc`,children:ni})]}),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)(vd,{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:my.filter(t=>e.dshPermission.options.some(e=>e.value===t)).map(e=>(0,X.jsx)(`option`,{value:e,children:u(hy(e))},e))})]}),(0,X.jsx)(`p`,{className:`set-preset-config-desc`,children:u(gy(e.dshPermission.defaultPreset))})]})]}),ri&&(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:mt,onChange:e=>gt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&mt.trim()&&($({type:`save_preset`,name:mt.trim()}),gt(``))}}),(0,X.jsxs)(`button`,{type:`button`,className:`set-save-btn`,disabled:!mt.trim(),onClick:()=>{$({type:`save_preset`,name:mt.trim()}),gt(``)},children:[(0,X.jsx)(q,{}),` `,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:()=>bt({name:e.name,tab:`export`}),children:(0,X.jsx)(W,{})}),(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)(R,{})})]})]},e.name))})]}),S===`mcp`&&(0,X.jsx)(ux,{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)(I,{className:`set-section-icon`}),u(`settingsSubagentTemplates`),(0,X.jsx)(vd,{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:()=>{St({name:``,description:``,promptMode:`replace`,systemPrompt:``,enabledSkills:[],enabledExtensions:[],model:``,thinkingLevel:``,enabled:!0}),Tt(!0)},children:[(0,X.jsx)(q,{}),` `,u(`subagentTemplateNew`)]})]}),(0,X.jsx)(rC,{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`)}),xt&&(0,X.jsx)(`div`,{className:`modal-backdrop tpl-modal-backdrop`,onClick:()=>St(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:()=>St(null),children:(0,X.jsx)(P,{})}),(0,X.jsxs)(`div`,{className:`modal-head`,children:[(0,X.jsx)(I,{className:`modal-head-icon`}),(0,X.jsx)(`h2`,{children:wt?u(`subagentTemplateNew`):`${u(`subagentTemplateEdit`)} · ${xt.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:xt.name,onChange:e=>St({...xt,name:e.target.value})}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`tplDescriptionPlaceholder`),value:xt.description,onChange:e=>St({...xt,description:e.target.value})}),(0,X.jsx)(`input`,{className:`set-input`,placeholder:u(`tplDescriptionEnPlaceholder`),value:xt.descriptionEn??``,onChange:e=>St({...xt,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:xt.promptMode,onChange:e=>St({...xt,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:xt.model??``,onChange:e=>St({...xt,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)(vd,{text:u(`tplThinkingHint`)})]}),(0,X.jsxs)(`select`,{className:`set-select`,value:xt.thinkingLevel??``,onChange:e=>St({...xt,thinkingLevel:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:u(`tplThinkingFollowMain`)}),ry.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`)}${kn(d)?`:`:`: `}${u(`tplSystemPromptPlaceholder`)}`,value:xt.systemPrompt,onChange:e=>St({...xt,systemPrompt:e.target.value})}),(0,X.jsx)(`textarea`,{className:`set-prompt-input`,rows:4,placeholder:`${u(`tplSystemPromptLabel`)}: ${u(`tplSystemPromptEnPlaceholder`)}`,value:xt.systemPromptEn??``,onChange:e=>St({...xt,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${xt.enabledSkills.includes(e.name)?` on`:``}`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:xt.enabledSkills.includes(e.name),onChange:t=>{let n=t.target.checked;St({...xt,enabledSkills:n?[...xt.enabledSkills,e.name]:xt.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${xt.enabledExtensions.includes(e.id)?` on`:``}`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:xt.enabledExtensions.includes(e.id),onChange:t=>{let n=t.target.checked;St({...xt,enabledExtensions:n?[...xt.enabledExtensions,e.id]:xt.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:!xt.name.trim(),onClick:()=>{$({type:`save_subagent_template`,template:{...xt,name:xt.name.trim()}}),St(null)},children:u(`tplSave`)}),(0,X.jsx)(`button`,{type:`button`,className:`dd-refresh`,onClick:()=>St(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:[(!kn(d)&&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:()=>{St({...e}),Tt(!1)},children:u(`subagentTemplateEdit`)}),Et===e.name?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,title:u(`uninstallConfirmHint`),onClick:()=>{$({type:`delete_subagent_template`,name:e.name}),Dt(null)},children:u(`uninstallConfirm`)}):(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn danger`,title:u(`tplDelete`),onClick:()=>Dt(e.name),children:(0,X.jsx)(R,{})})]})]},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)(ce,{className:`set-section-icon`}),u(`settingsApprovalRules`),(0,X.jsx)(vd,{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:()=>{kt({id:`custom.${Ht().slice(0,8)}`,enabled:!0,tools:[`bash`],field:`command`,match:`regex`,value:``,action:`ask`,label:``,labelEn:``,reason:``,reasonEn:``}),It(`bash`),Nt(!0),Rt(null)},children:[(0,X.jsx)(q,{}),` `,u(`approvalRuleNew`)]})]}),Ot&&(0,X.jsxs)(`div`,{className:`rule-editor`,children:[(0,X.jsx)(`div`,{className:`set-section-title`,style:{fontSize:13,marginBottom:4},children:At?u(`approvalRuleNew`):`${u(`approvalRuleEdit`)} · ${Ot.label}`}),(0,X.jsx)(rC,{label:u(`approvalRuleLabel`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ot.label,placeholder:`例如:拦截 Docker 危险操作`,onChange:e=>kt({...Ot,label:e.target.value})})}),(0,X.jsx)(rC,{label:u(`approvalRuleLabelEn`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ot.labelEn??``,placeholder:`e.g. Block dangerous Docker commands`,onChange:e=>kt({...Ot,labelEn:e.target.value})})}),(0,X.jsx)(rC,{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);kt({...Ot,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)(rC,{label:u(`approvalRuleField`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:Ot.field,onChange:e=>kt({...Ot,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)(rC,{label:u(`approvalRuleMatch`),children:(0,X.jsxs)(`select`,{className:`set-select`,value:Ot.match,onChange:e=>kt({...Ot,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)(rC,{label:`命中动作`,children:(0,X.jsxs)(`select`,{className:`set-select`,value:Ot.action,onChange:e=>kt({...Ot,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`)})]})})})]}),Ot.match!==`outside_workspace`&&(0,X.jsx)(rC,{label:u(`approvalRuleValue`),tip:u(`approvalRuleValueTip`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ot.value,placeholder:`匹配表达式或关键字…`,onChange:e=>kt({...Ot,value:e.target.value})})}),(0,X.jsx)(rC,{label:u(`approvalRuleReason`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ot.reason??``,placeholder:`例如:检测到删除镜像或容器操作`,onChange:e=>kt({...Ot,reason:e.target.value})})}),(0,X.jsx)(rC,{label:u(`approvalRuleReasonEn`),children:(0,X.jsx)(`input`,{className:`set-input`,value:Ot.reasonEn??``,placeholder:`e.g. Detected docker image/container removal`,onChange:e=>kt({...Ot,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:Ot.enabled,onChange:e=>kt({...Ot,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:()=>{kt(null),Rt(null)},children:u(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{if(!Ot.label.trim()){Rt(`请填写规则名称`);return}if(Ot.match===`regex`)try{new RegExp(Ot.value)}catch(e){Rt(`正则表达式非法:${e.message}`);return}$({type:`save_approval_rule`,rule:Ot}),kt(null),Rt(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:kn(d)?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:kn(d)?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)(ht,{})}),!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)(vt,{})}),n&&(Vt===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)(me,{})})),(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn`,title:u(`approvalRuleEdit`),onClick:()=>{kt({...e}),It(e.tools.join(`, `)),Nt(!1),Rt(null)},children:(0,X.jsx)(Ze,{})}),!n&&(zt===e.id?(0,X.jsx)(`button`,{type:`button`,className:`set-uninstall confirm`,onClick:()=>{$({type:`delete_approval_rule`,id:e.id}),Bt(null)},children:u(`uninstallConfirm`)}):(0,X.jsx)(`button`,{type:`button`,className:`set-icon-btn danger`,title:u(`approvalRuleDelete`),onClick:()=>Bt(e.id),children:(0,X.jsx)(R,{})}))]})]},e.id)})})]}),li&&(0,X.jsx)(Ad,{plugin:li.plugin,epoch:e.pluginsEpoch,send:$,className:`set-plugin-page`}),Jt&&(0,X.jsx)(sx,{name:Jt,override:Zt[Jt]??null,onApply:en,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`)})})]}),_t!==null&&(0,X.jsx)(FS,{presets:_.presets.map(e=>e.name),presetExport:e.presetExport,presetImport:e.presetImport,presetCatalog:e.presetCatalog,presetShare:e.presetShare,initialPreset:_t.name,initialTab:_t.tab,onClose:()=>bt(null)})]})}function lC(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 uC({servers:e,onClose:t,plugins:n=[],epoch:r=0,send:i,onUiAction:a,autoCleanupMin:o=0}){let s=Z(),{locale:c}=Xn(),[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)(()=>(ja(ba(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)(ox,{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)(je,{}),` `,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)(P,{})})]}),e.length===0?(0,X.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,X.jsx)(je,{}),(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`),` `,lC(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)(B,{}),(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)(oe,{}),(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)(Ad,{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)(R,{}),(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)(me,{}),(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)(oe,{}),(0,X.jsx)(`span`,{children:s(`bgTaskStopAll`)})]})]})]})}function dC(){let e=Z(),t=Gh(),[n,r]=(0,g.useState)(!0),i=(0,g.useRef)(null);return(0,g.useEffect)(()=>{t&&r(!0)},[t]),Xt(()=>{t&&Uh()},!!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(),Wh(n))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,n]),t?(0,j.createPortal)((0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:Uh,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)(Pt,{}),e(`rollbackSession`)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,title:e(`cancel`),onClick:Uh,children:(0,X.jsx)(P,{})})]}),(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:Uh,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:()=>Wh(n),children:[(0,X.jsx)(yt,{}),e(`confirm`)]})]})]})]})}),document.body):null}function fC({approval:e}){let t=Z(),{locale:n}=Xn(),[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)(Pt,{}),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)(P,{})})]}),(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:kn(n)?e.reason||e.reasonEn:e.reasonEn||e.reason}),e.category&&(0,X.jsxs)(`div`,{style:{marginTop:6,fontSize:12,opacity:.85},children:[t(`toolApprovalCategory`),`:`,kn(n)?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:kn(n)?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:rf(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)(je,{}),t(`toolApprovalAllowCategory`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,title:t(`toolApprovalAllowConversationHint`),onClick:()=>s(`all`),children:[(0,X.jsx)(xt,{}),t(`toolApprovalAllowConversation`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,style:{color:`var(--red, #ef4444)`},onClick:c,children:[(0,X.jsx)(P,{}),t(`toolApprovalDeny`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn`,onClick:()=>s(),style:{fontWeight:500},children:[(0,X.jsx)(yt,{}),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)(Ze,{}),t(`toolApprovalEditAndRun`)]})]})]})]})}),document.body)}function pC({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:dp(),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=Js((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)(ox,{open:!0,onClose:i,title:a,icon:(0,X.jsx)(B,{}),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 mC={pending:`in_progress`,in_progress:`done`,done:`failed`,failed:`pending`};function hC({plan:e}){let t=Z(),[n,r]=(0,g.useState)(!1),{copied:i,copy:a}=zd({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(`
|
|
688
688
|
`);$({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(`
|
|
689
689
|
`))},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:mC[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)(xt,{}),t(`planBoardCompleted`)]});case`in_progress`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ut,{}),t(`planBoardInProgress`)]});case`failed`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ft,{}),t(`planBoardFailed`)]});default:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ft,{}),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)(ke,{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)(yt,{style:{color:`var(--green, #22c55e)`}}):(0,X.jsx)(st,{})}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(`clear`),onClick:e=>{e.stopPropagation(),v()},children:(0,X.jsx)(R,{})})]}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(n?`collapseSection`:`expandSection`),children:n?(0,X.jsx)(ht,{}):(0,X.jsx)(vt,{})})]}),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)(P,{}),` `,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)(yt,{}),` `,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)(Qe,{size:12})}),(0,X.jsx)(`button`,{type:`button`,className:`plan-board-iconbtn`,title:t(`planBoardDeleteStep`),onClick:()=>T(n.id),children:(0,X.jsx)(R,{size:12})})]})]},n.id||r)}),(0,X.jsxs)(`button`,{type:`button`,className:`plan-board-add-btn`,onClick:D,children:[(0,X.jsx)(q,{}),` `,t(`planBoardAddStep`)]})]})]})}var gC=3,_C=200;function vC(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yC(e){return typeof e==`string`&&e.trim()||void 0}function bC(e,t){let n=[];for(let r of e){let e=SC(r,t);if(n.includes(e)||n.push(e),n.length>=4){n.push(`…`);break}}return n.join(` | `)||`any`}function xC(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 SC(e,t=0){if(t>6||!vC(e))return`any`;if(yC(e.$ref))return`ref`;let n=yC(e.type);if(n===`array`){let n=e.items;return`array<${n===void 0?`any`:SC(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 bC(r,t+1)}return vC(e.properties)?`object`:vC(e.additionalProperties)?`record<${SC(e.additionalProperties,t+1)}>`:`any`}function CC(e){let t=[],n=e.enum;if(Array.isArray(n)&&n.length>0){let e=xC(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 wC(e,t={}){let n=t.maxDepth??gC,r=t.maxRows??_C,i=e;if(!vC(i))return[];let a=i.properties;if(!vC(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=vC(l)?l:{},u=t?`${t}.${s}`:s,d={name:u,type:SC(e,i),required:a.has(s),depth:i},f=yC(e.description);f&&(d.description=f);let p=CC(e);if(p&&(d.hint=p),o.push(d),i+1<n&&vC(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 TC(){let e=Z(),t=ac();return Xt(()=>{tc()},!!t),t?(0,j.createPortal)((0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:tc,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)(Ne,{}),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:tc,children:(0,X.jsx)(P,{})})]}),(0,X.jsx)(`div`,{className:`tool-info-body`,children:(0,X.jsx)(EC,{info:t})})]})}),document.body):null}function EC({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?[]:wC(e.parameters),r=e.parameters===void 0?``:OC(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)(DC,{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)(kf,{text:r})]}),(0,X.jsx)(`pre`,{children:r})]})]}),(0,X.jsx)(`div`,{className:`tool-info-foot`,children:t(`toolInfoFootnote`)})]})}function DC({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 OC(e){try{return JSON.stringify(e,null,2)??``}catch{return``}}function kC(e,t){return e.toLowerCase().includes(t)}function AC({open:e,projects:t,fileSearch:n,sessionSearch:r,onClose:i,onSwitchSession:a,onSwitchProject:o,onPreviewFile:s}){let c=Z(),l=c(`pluginMenuTitle`),u=go(`cwd`),d=(0,g.useRef)(null),[f,p]=(0,g.useState)(``),m=(0,g.useDeferredValue)(f),[h,_]=(0,g.useState)(0),v=(0,g.useRef)(0),y=(0,g.useRef)(null),[b,x]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!e)return;$({type:`list_sessions`}),$({type:`list_projects`});let t=f.trim();if(t){let e=ny();v.current=e,C(!0),$({type:`search_files`,reqId:e,query:t}),$({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>d.current?.select())},[e]);let[S,C]=(0,g.useState)(!1);(0,g.useEffect)(()=>{y.current&&clearTimeout(y.current);let e=m.trim();if(!e){C(!1),x(null);return}return y.current=setTimeout(()=>{let t=ny();v.current=t,C(!0),$({type:`search_files`,reqId:t,query:e}),$({type:`search_sessions`,reqId:t,query:e})},300),()=>{y.current&&clearTimeout(y.current)}},[m]),(0,g.useEffect)(()=>{n&&n.reqId===v.current&&x(n)},[n]);let w=m.trim().toLowerCase(),T=(0,g.useMemo)(()=>!w||!r||r.reqId!==v.current||!r.ok?[]:r.results,[r,w]),E=(0,g.useMemo)(()=>w?t.filter(e=>kC(e.path,w)).slice(0,10):[],[t,w]),D=(0,g.useMemo)(()=>!w||!b||!b.ok?[]:b.results,[b,w]);(0,g.useEffect)(()=>{b&&b.reqId===v.current&&r&&r.reqId===v.current&&v.current!==0&&C(!1)},[b,r]);let O=!!b&&b.ok&&b.truncated,[k,A]=(0,g.useState)([]);(0,g.useEffect)(()=>{if(!e)return;let t=m.trim();if(!t){A([]);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 Zc==`function`&&(r=Zc())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=nl(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){A([]);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})}A(t.slice(0,20))}),()=>{n=!0}},[e,m]);let j=(0,g.useMemo)(()=>[...T.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...E.map(e=>({kind:`project`,path:e.path})),...D.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...k.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[T,E,D,k]);(0,g.useEffect)(()=>{_(0)},[m]);let ee=(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=m.trim();if(t){let e=ny();v.current=e,C(!0),$({type:`search_files`,reqId:e,query:t}),$({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?zc(e.providerId,e.action,e.action).catch(()=>{}):s(e.path,e.name)}},[a,o,s,m]);(0,g.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),i()):e.key===`ArrowDown`?(e.preventDefault(),_(e=>Math.max(0,Math.min(e+1,j.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),_(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),ee(j[h]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[j,h,ee,i,e]);let te=T.length+E.length+D.length+k.length,M=(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})]}),N=-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)(fe,{}),(0,X.jsx)(`input`,{ref:d,type:`text`,value:f,placeholder:c(`gsPlaceholder`),onChange:e=>p(e.target.value)}),(0,X.jsx)(`button`,{type:`button`,className:`gs-close`,title:c(`close`),onClick:i,children:(0,X.jsx)(P,{})})]}),(0,X.jsxs)(`div`,{className:`gs-results`,children:[!w&&(0,X.jsx)(`div`,{className:`gs-empty`,children:c(`gsHint`)}),w&&te===0&&!O&&(0,X.jsx)(`div`,{className:`gs-empty`,children:c(S?`gsSearching`:`gsNoResults`)}),T.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[M(c(`gsSessions`),T.length,(0,X.jsx)(Se,{})),T.map(e=>{N++;let t=N,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===h?`gs-item active`:`gs-item`,onMouseEnter:()=>_(t),onClick:()=>ee({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(),Er({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,c(`quoteConversationShort`)]})]},e.path)})]}),E.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[M(c(`gsProjects`),E.length,(0,X.jsx)(He,{})),E.map(e=>{N++;let t=N,n=u&&e.path===u;return(0,X.jsxs)(`button`,{type:`button`,className:t===h?`gs-item active`:`gs-item`,onMouseEnter:()=>_(t),onClick:()=>ee({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)})]}),(D.length>0||w&&O)&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[M(c(`gsFiles`),D.length,(0,X.jsx)(Ge,{})),D.map(e=>{N++;let t=N;return(0,X.jsxs)(`button`,{type:`button`,className:t===h?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:c(`gsOpenPreview`),onMouseEnter:()=>_(t),onClick:()=>{e.type===`file`&&ee({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}`)}),O&&(0,X.jsx)(`div`,{className:`gs-truncated`,children:c(`gsTruncated`)})]}),k.length>0&&(0,X.jsxs)(`div`,{className:`gs-section`,children:[M(l,k.length,(0,X.jsx)(ge,{})),k.map((e,t)=>{N++;let n=N;return(0,X.jsxs)(`button`,{type:`button`,className:n===h?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>_(n),onClick:()=>ee({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 jC({entry:e,pluginView:t,onUiAction:n,onClose:r}){let i=Z(),a=e.label||e.id,o=e.kind===`view`;return(0,X.jsx)(ox,{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)(pb,{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 MC=`未命名章节`;function NC(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function PC(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=NC(r||MC),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||MC}})}function FC(e){return e.length>=2}var IC=5e3,LC=`pi-web-ui:preview-toc`;function RC({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,N]=(0,g.useState)(!1),[F,I]=(0,g.useState)(100),L=(0,g.useRef)(0),ne=(0,g.useRef)(!1),re=(0,g.useRef)(null),[ie,R]=(0,g.useState)(!1),[z,B]=(0,g.useState)(!1),ae=(0,g.useRef)(!1),V=(0,g.useRef)(null);(0,g.useEffect)(()=>()=>{re.current&&clearTimeout(re.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,ae.current=!1,R(!1),B(!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),ae.current&&(ae.current=!1,V.current&&clearTimeout(V.current),R(!1),B(!1),b(!1),S(t.text),k.current&&(zC(e.name)&&w(!0),VC(e.name)&&E(!0)),p(null)))},[t,y,e.path]),(0,g.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){pe();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&y){e.preventDefault(),fe();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(),ce())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i,c,y,x]),(0,g.useEffect)(()=>{let e=()=>{ne.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(`
|
|
690
|
-
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,IC)},[c]),oe=c?.lines??0,U=oe>IC,se=(e,t)=>{if(t){let t=L.current>0?L.current:e;p({start:Math.min(t,e),end:Math.max(t,e)})}else L.current=e,p({start:e,end:e})},ce=()=>{H.length!==0&&(L.current=1,p({start:1,end:H.length}))},W=()=>{f&&(n(e.path,e.name,f.start,f.end),v(!0),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>v(!1),1400))},le=c!==null&&c.kind===`text`&&!c.binary&&!c.truncated&&!BC(e.name),ue=()=>{ae.current=!1,V.current&&clearTimeout(V.current),R(!1),B(!1),S(c?.text??``),b(!1),k.current&&(zC(e.name)&&w(!0),VC(e.name)&&E(!0))},de=()=>{if(y){if(x!==(c?.text??``)&&!window.confirm(s(`discardFileChanges`)))return;ue();return}le&&c&&(k.current=zC(e.name)&&C||VC(e.name)&&T,zC(e.name)&&w(!1),VC(e.name)&&E(!1),p(null),S(c.text),b(!0))},fe=()=>{y&&c&&le&&$({type:`write_file`,path:e.path,text:x})&&(ae.current=!0,B(!1),R(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{ae.current=!1,R(!1),B(!0)},5e3))},pe=()=>{(!y||x===(c?.text??``)||window.confirm(s(`discardFileChanges`)))&&i()},K=e=>{I(Math.min(200,Math.max(50,e)))},me=f?f.end-f.start+1:0,q=c?.binary??!1,he=c?.truncated??!1,J=c?.kind??`text`,ge=zC(e.name)||BC(e.name),_e=VC(e.name),ve=ge&&C&&!y&&J===`text`&&!q,ye=_e&&T&&!y&&J===`text`&&!q,[Y,xe]=(0,g.useState)(()=>{try{return localStorage.getItem(LC)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{localStorage.setItem(LC,Y?`1`:`0`)}catch{}},[Y]);let[Se,Ce]=(0,g.useState)([]),[Te,Ee]=(0,g.useState)(``),De=(0,g.useRef)(null);(0,g.useEffect)(()=>{let e=De.current;if(!e||!ve){Ce([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=PC(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ce(n)},[ve,c?.text,e.path]),(0,g.useEffect)(()=>{let e=De.current;if(!e||!Y||!FC(Se))return;let t=Se.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ee(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Se,Y]);let Oe={"host:fp-md":ge&&J===`text`&&!q&&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)(Je,{}):(0,X.jsx)(lt,{})}):null,"host:fp-toc":ve&&FC(Se)?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":s(Y?`previewTocHide`:`previewTocShow`),onClick:()=>xe(e=>!e),children:(0,X.jsx)(ke,{})}):null,"host:fp-html":_e&&J===`text`&&!q&&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)(lt,{}):(0,X.jsx)(Je,{})}):null,"host:fp-edit":J===`text`&&!q&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach edit ${y?`on`:``}`,"data-tip":s(he?`fileEditTruncated`:y?`exitEditFile`:`editFile`),disabled:!le&&!y,onClick:de,children:(0,X.jsx)(Ze,{})}):null,"host:fp-wrap":J===`text`&&!q&&!ve&&!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)(ot,{})}):null,"host:fp-zoom":J===`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:F<=50,onClick:()=>K(F-10),children:(0,X.jsx)(te,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:s(`resetZoom`),onClick:()=>I(100),children:[F,`%`]}),(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":s(`zoomIn`),disabled:F>=200,onClick:()=>K(F+10),children:(0,X.jsx)(M,{})})]}):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)(Ae,{})}),"host:fp-full":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach full ${ee?`on`:``}`,"data-tip":s(ee?`exitFullscreen`:`fullscreen`),onClick:()=>N(e=>!e),children:ee?(0,X.jsx)(be,{}):(0,X.jsx)(we,{})}),"host:fp-close":null},je=a===void 0?[`host:fp-md`,`host:fp-toc`,`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`),Me=e=>Dn(Cn(`/api/file?clientId=${encodeURIComponent(Tu())}&path=${encodeURIComponent(e)}`)),Ne=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return Dn(Cn(`${/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`}?clientId=${encodeURIComponent(Tu())}${D?`&allowJs=1`:``}`))};return(0,X.jsx)(`div`,{className:`fp-overlay ${ee?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&pe()},children:(0,X.jsxs)(`div`,{className:`fp ${ee?`fullscreen`:``}`,style:{"--fp-zoom":F/100},children:[(0,X.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&N(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&&J===`text`&&!q&&s(`fileLines`,{n:oe}),c&&` · ${Ch(c.size)}`]}),(0,X.jsx)(`span`,{className:`fp-head-actions`,children:g_(je,Oe,o)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-close`,title:s(`close`),"aria-label":s(`close`),onClick:pe,children:(0,X.jsx)(P,{})})]}),he&&J===`text`&&!q&&(0,X.jsx)(`div`,{className:`fp-notice`,children:BC(e.name)?s(`previewLinesTruncated`,{n:H.length}):s(`previewTruncated`)}),u&&!c&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`loading`)}),!u&&J===`none`&&!q&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`previewNotSupported`)}),!u&&J===`image`&&(0,X.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:pe,title:s(`clickToCloseImage`),children:(0,X.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:Me(e.path),alt:e.name,onClick:pe,title:s(`clickToCloseImage`)})}),!u&&J===`video`&&(0,X.jsx)(`div`,{className:`fp-media-wrap`,children:(0,X.jsx)(`video`,{className:`fp-media`,src:Me(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:Ne(e.path),target:`_blank`,rel:`noopener noreferrer`,title:s(`openInNewTab`),children:[(0,X.jsx)(Xe,{}),(0,X.jsx)(`span`,{children:s(`openInNewTab`)})]})]}),(0,X.jsx)(`iframe`,{className:`fp-html-frame`,src:Ne(e.path),title:e.name,sandbox:D?`allow-scripts`:``,referrerPolicy:`no-referrer`},D?`js`:`nojs`)]}),!u&&ve&&c&&(0,X.jsx)(`div`,{className:BC(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,X.jsxs)(`div`,{className:Y&&FC(Se)?`fp-toc-layout`:void 0,children:[Y&&FC(Se)&&(0,X.jsx)(`nav`,{className:`fp-toc`,"aria-label":s(`previewTocLabel`),children:Se.map(e=>(0,X.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Te?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),De.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,X.jsx)(`div`,{className:`fp-markdown-zoom`,ref:De,children:(0,X.jsx)(Cp,{text:c.text})})]})}),!u&&q&&J!==`image`&&J!==`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&&J===`text`&&!q&&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}),z&&(0,X.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:s(`saveResultUnknown`)})]}),!u&&!ve&&!ye&&!y&&J===`text`&&!q&&c&&H.length===0&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`emptyFile`)}),!u&&!ve&&!ye&&!y&&J===`text`&&!q&&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&&(se(n,e.shiftKey),ne.current=!0,h(!0))},onMouseEnter:()=>{ne.current&&se(n,!0)},children:[(0,X.jsx)(`span`,{className:`fp-num`,children:n}),(0,X.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),U&&(0,X.jsx)(`div`,{className:`fp-lines-note`,children:s(`previewLinesTruncated`,{n:IC})})]}),(y||!ve&&!ye&&J===`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:de,children:s(`cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:ie||x===(c?.text??``),onClick:fe,children:[(0,X.jsx)(G,{}),` `,s(`saveFile`)]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:f?s(`selectedRange`,{n:me,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:ce,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||q,onClick:W,children:[_?(0,X.jsx)(yt,{}):null,s(_?`addedToChat`:`addToChat`)]})]})]})})]})})}function zC(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function BC(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)}function VC(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}function HC({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 Vb({plugin:t,declaration:n});if(a)return;if(!s)throw Error(`插件没有提供可用的文件查看器`);let c=`/plugins-api/${encodeURIComponent(t.id)}`,l={...Wl(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 Dn(Cn(`${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)(ox,{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 UC=.4,WC=1.05;function GC(e){return Math.min(300,e*.86)}function KC(e,t,n){return n||(t<=144?null:e<=72?`left`:t-e<=72?`right`:null)}function qC(e,t){let n=Math.abs(e),r=Math.abs(t);return n<12&&r<12?`none`:n>r*1.2?`horizontal`:`vertical`}function JC(e,t){return e===`left`?t:-t}function YC(e,t){return Math.max(-e,Math.min(0,-e+t))}function XC(e,t,n){let r=n?e+t:t;return Math.max(0,Math.min(1,r/e))}function ZC(e){let{wasOpen:t,pull:n,width:r,durationMs:i}=e;return i<=320&&Math.abs(n)>=48?n>0:XC(r*WC,n,t)>=UC}var QC=new Set([`auto`,`scroll`,`overlay`]);function $C(e,t){let n=e instanceof Element?e:null;for(;n;){if(n instanceof HTMLElement&&n.scrollWidth>n.clientWidth+4&&QC.has(getComputedStyle(n).overflowX))return!0;if(n===t)break;n=n.parentElement}return!1}function ew(){let e=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener(`click`,e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener(`click`,e,{capture:!0}),400)}function tw(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=KC(r.clientX,window.innerWidth,n);i&&!$C(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=qC(d,v);if(t===`none`)return;if(t===`vertical`){s=null;return}c=`horizontal`,p=n===r,m=GC(window.innerWidth),h=m*WC;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=JC(r,d);let b=YC(h,f);y.style.transform=`translateX(${r===`left`?b:-b}px)`,_&&(_.style.opacity=String(XC(h,f,p))),t.preventDefault()},x=()=>{let e=s,t=c===`horizontal`&&e!==null&&g!==null,i=f,a=Date.now()-d,o=t?ZC({wasOpen:p,pull:i,width:m,durationMs:a}):!1;v(),t&&e&&o!==(n===e)&&(ew(),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 nw(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 rw=(0,g.lazy)(()=>bl(()=>import(`./TerminalPanel-B9exeXrl.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([0,1,2,3,4])));function iw({notice:e,onDismiss:t}){let n=Z(),{locale:r}=Xn(),i=!kn(r)&&e.textEn?e.textEn:e.text,[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(a)return;let n=setTimeout(()=>t(e.id),tu(e.level));return()=>clearTimeout(n)},[a,e.id,e.level,t]);let s=e.level===`error`?Ft:e.level===`warning`?Pt:Ne;return(0,X.jsxs)(`div`,{className:`notice notice-${e.level}${a?` paused`:``}`,role:`status`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onClick:()=>{window.getSelection?.()?.toString()||t(e.id)},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:n=>{n.stopPropagation(),t(e.id)},children:(0,X.jsx)(P,{})})]})}var aw=[],ow=180,sw=520,cw=240,lw=e=>`pi-web-ui:${e}-panel-width`;function uw(e){try{let t=Number(localStorage.getItem(lw(e)));return Number.isFinite(t)&&t>=ow&&t<=sw?t:cw}catch{return cw}}var dw=e=>`pi-web-ui:${e}-panel-collapsed`;function fw(e){try{return localStorage.getItem(dw(e))===`1`}catch{return!1}}function pw({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(sw,Math.max(ow,Math.round(a+r))),n(o)},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),document.body.classList.remove(`panel-resizing`);try{localStorage.setItem(lw(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(cw)})}function mw({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)(pt,{}):(0,X.jsx)(mt,{})})}var hw=`pi-web-ui:plugin-path-grants`,gw=e=>e?`${hw}:${e}`:hw;function _w(e){if(e===null)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function vw(e){try{let t=gw(e);if(localStorage.getItem(t)!==null)return _w(localStorage.getItem(t));if(!e)return[];let n=_w(localStorage.getItem(hw));return localStorage.setItem(t,JSON.stringify(n)),n}catch{return[]}}function yw(e,t){try{let n=[...new Set([...vw(t),e])];localStorage.setItem(gw(t),JSON.stringify(n))}catch{}}function bw(){let e=Z(),{locale:t}=Xn(),{chat:n,send:r,dismissNotice:i,pushNotice:a,terminal:o}=Bu(),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:RS[t]??RS.en,quickPhrasesSeeded:!0})))},[n.ready,n.settings,r,t]);let c=n.state?.cwd??``,l=aS();(0,g.useEffect)(()=>{let t=l?Qx(c):``;document.title=t?`${t} — pi-web-ui`:e(`docTitle`)},[c,l,e]);let[u,d]=(0,g.useState)([]);(0,g.useEffect)(()=>(Sr(e=>d(t=>pv(t,e))),()=>Sr(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=Bb(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)(()=>(hp({open:e=>y(e.path,e.name),isOpen:()=>_.current||v.current!==null}),()=>hp(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=ja(ba(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]),te=(0,g.useMemo)(()=>E[`leftpanel.history.actions`].filter(e=>!e.hidden),[E]),M=E[`leftpanel.sections`],N=(0,g.useMemo)(()=>E[`leftpanel.running`].filter(e=>!e.hidden),[E]),F=(0,g.useMemo)(()=>E[`leftpanel.history`].filter(e=>!e.hidden),[E]),I=(0,g.useMemo)(()=>E[`terminal.toolbar`].filter(e=>!e.hidden),[E]),ne=(0,g.useMemo)(()=>E[`scm.toolbar`].filter(e=>!e.hidden),[E]),re=(0,g.useMemo)(()=>E[`goalbar.actions`].filter(e=>!e.hidden),[E]),ie=(0,g.useMemo)(()=>E[`chat.header`].filter(e=>!e.hidden),[E]),z=(0,g.useMemo)(()=>E[`chat.empty`].filter(e=>!e.hidden),[E]),B=(0,g.useMemo)(()=>E[`file.preview.toolbar`].filter(e=>!e.hidden),[E]),ae=(0,g.useMemo)(()=>Object.fromEntries((n.dshPresets?.presets??[]).map(n=>[n.id,uy(n,t,e).name])),[n.dshPresets,t]),V=(0,g.useMemo)(()=>E[`notice.actions`].filter(e=>!e.hidden),[E]),H=(0,g.useMemo)(()=>E[`sidebar.left`]??[],[E]),oe=(0,g.useMemo)(()=>E[`sidebar.right`]??[],[E]),U=(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&&Hh({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&&zc(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?Hl(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),se=(0,g.useCallback)(e=>{let t=n.plugins.find(t=>t.id===e.source.slice(7));return t?(0,X.jsx)(Ad,{plugin:t,epoch:n.pluginsEpoch,send:r,className:`lp-plugin-page`}):null},[n.plugins,n.pluginsEpoch,r]),ce=(0,g.useCallback)((t,n)=>{n.action&&zc(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?Hl(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),[W,le]=(0,g.useState)([]);(0,g.useEffect)(()=>Fl(le),[]);let[ue,de]=(0,g.useState)([]);(0,g.useEffect)(()=>Nl(de),[]);let[fe,pe]=(0,g.useState)(null),G=fe?E[`modal.dialog`].find(e=>e.id===fe&&!e.hidden):void 0,K=(0,g.useMemo)(()=>{if(!G||G.kind!==`view`)return``;let e=G.view??``;return e.startsWith(`plugin:`)?e.slice(7):G.source.startsWith(`plugin:`)?G.source.slice(7):``},[G]);(0,g.useEffect)(()=>{if(!G||!K||W.some(e=>e.info.id===K))return;let e=q.current.plugins.find(e=>e.id===K);e&&Hl(e,q.current.pluginsEpoch)},[G,K,W,n.pluginsEpoch]),(0,g.useEffect)(()=>{Gf(r),Kf(T,n.pluginsEpoch),$f(T,n.pluginsEpoch),zb(T,n.pluginsEpoch),Ul(T,n.pluginsEpoch)},[T,n.pluginsEpoch,r]);let q=(0,g.useRef)(n);q.current=n;let he=(0,g.useRef)(C);he.current=C;let J=(0,g.useRef)(E);J.current=E,(0,g.useEffect)(()=>(Mc(jc({send:r,isReady:()=>!!q.current.state,setView:e=>he.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:vw,grantPath:yw,confirm:e=>new Promise(t=>{if(Ge.current){t(!1);return}let n={path:e.path,resolve:t};Ge.current=n,We(n)}),openModal:e=>{let t=String(e??``).trim();if(!t)return!1;let n=J.current[`modal.dialog`].find(e=>e.id===t);return!n||n.hidden?!1:(pe(t),!0)},closeModal:()=>pe(null),dialogConfirm:e=>new Promise(t=>{if(Ye.current){t(!1);return}let n={kind:`confirm`,title:e.title,resolve:t};Ye.current=n,Je(n)}),select:e=>new Promise(t=>{if(Ye.current){t({ok:!1,error:`busy`});return}let n={kind:`select`,title:e.title,options:e.options,...e.multi?{multi:!0}:{},resolve:t};Ye.current=n,Ze([]),Je(n)}),input:e=>new Promise(t=>{if(Ye.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};Ye.current=n,$e(e.initial??``),Je(n)}),notifyAction:e=>new Promise(t=>{try{let n=nt.current;nt.current=null,tt(null);try{n?.resolve(null)}catch{}let r={text:e.text,actions:e.actions,resolve:t};nt.current=r,tt(r)}catch{t(null)}}),loadPluginBundle:e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Hl(t,q.current.pluginsEpoch):Promise.resolve(!1)}})),()=>Mc(null)),[r]);let[ge,_e]=(0,g.useState)(()=>uw(`left`)),[ve,ye]=(0,g.useState)(()=>uw(`right`)),be=(0,g.useCallback)(e=>_e(e),[]),Y=(0,g.useCallback)(e=>ye(e),[]),[xe,Se]=(0,g.useState)(()=>fw(`left`)),[Ce,we]=(0,g.useState)(()=>fw(`right`)),Te=(0,g.useCallback)(()=>{Se(e=>{try{localStorage.setItem(dw(`left`),e?`0`:`1`)}catch{}return!e})},[]),Ee=(0,g.useCallback)(()=>{we(e=>{try{localStorage.setItem(dw(`right`),e?`0`:`1`)}catch{}return!e})},[]),[De,Oe]=(0,g.useState)(null),ke=(0,g.useRef)(null),[Ae,je]=(0,g.useState)(()=>window.matchMedia(`(max-width: 768px)`).matches);(0,g.useEffect)(()=>{let e=window.matchMedia(`(max-width: 768px)`),t=e=>je(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),tw({enabled:Ae&&w===`chat`,open:De,onOpenChange:Oe,container:ke,backdropSelector:`.drawer-backdrop.persistent`});let[Me,Ne]=(0,g.useState)(()=>{try{return localStorage.getItem(`pi_web_setup_dismissed`)===`1`}catch{return!1}}),Pe=()=>{Ne(!0);try{localStorage.setItem(`pi_web_setup_dismissed`,`1`)}catch{}},[Fe,Ie]=(0,g.useState)(!1),[Le,Re]=(0,g.useState)(!1),[ze,Be]=(0,g.useState)(),[Ve,He]=(0,g.useState)(null),[Ue,We]=(0,g.useState)(null),Ge=(0,g.useRef)(null),[Ke,Je]=(0,g.useState)(null),Ye=(0,g.useRef)(null),[Xe,Ze]=(0,g.useState)([]),[Qe,$e]=(0,g.useState)(``),[et,tt]=(0,g.useState)(null),nt=(0,g.useRef)(null),[rt,it]=(0,g.useState)(()=>new Set),at=(e,t)=>{r({type:`plugin_path_response`,id:e,ok:t}),it(t=>new Set(t).add(e))},ot=n.pathRequests.find(e=>!rt.has(e.id))??null,[st,ct]=(0,g.useState)(()=>new Set),lt=(e,t,n=!1)=>{r({type:`plugin_permission_response`,id:e,ok:t,...n?{remember:!0}:{}}),ct(t=>new Set(t).add(e))},ut=n.permRequests.find(e=>!st.has(e.id))??null,dt=Rx(),ft=Jx(),[pt,mt]=(0,g.useState)(!1),[ht,gt]=(0,g.useState)(!1),[_t,vt]=(0,g.useState)(!1),[bt,xt]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!bt)return;let e=setTimeout(()=>xt(null),15e3);return()=>clearTimeout(e)},[bt]);let[St,Ct]=(0,g.useState)(null),Tt=(0,g.useRef)(null),Et=(0,g.useRef)(null),Dt=n.state?.sessionId??``,Ot=(0,g.useRef)(Dt);Ot.current=Dt;let kt=(0,g.useRef)(n.ready);kt.current=n.ready,(0,g.useEffect)(()=>{let e=()=>{let e=bs(window.location.hash);if(e){if(e.messageId?Ct({sessionId:e.sessionId,messageId:e.messageId}):Ct(null),!kt.current||!Ot.current){Tt.current=e.sessionId;return}Ot.current!==e.sessionId&&(Et.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=Et.current;if(e&&n.notices.some(t=>t.text.includes(e)&&(t.text.includes(`未找到会话`)||t.text.includes(`Session not found`)))&&(Et.current=null,Ct(null),Dt)){let e=xs({sessionId:Dt});window.location.hash!==e&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${e}`)}},[n.notices,Dt]),(0,g.useEffect)(()=>{if(!n.ready||!Dt)return;if(Tt.current){let e=Tt.current;if(Tt.current=null,e!==Dt){Et.current=e,C(`chat`),r({type:`switch_session`,path:``,sessionId:e});return}}if(Et.current){if(Dt===Et.current)Et.current=null;else return}let e=bs(window.location.hash),t=e?.sessionId===Dt?e.messageId:void 0,i=xs({sessionId:Dt,...t?{messageId:t}:{}});window.location.hash!==i&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${i}`)},[n.ready,Dt,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=Ht();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(),gt(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let[At,jt]=(0,g.useState)(()=>{try{return localStorage.getItem(`pi_zen_mode`)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{At?localStorage.setItem(`pi_zen_mode`,`1`):localStorage.removeItem(`pi_zen_mode`)}catch{}},[At]);let Mt=(0,g.useCallback)(()=>{jt(e=>{let t=!e;return t&&w!==`chat`&&C(`chat`),t})},[w]);Xt(()=>At?(jt(!1),!0):!1,At),(0,g.useEffect)(()=>{let e=e=>{let t=e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.toLowerCase()===`z`,n=(e.ctrlKey||e.metaKey)&&e.shiftKey&&e.key.toLowerCase()===`f`;(t||n)&&(e.preventDefault(),Mt())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Mt]);let[Nt,Pt]=(0,g.useState)(bx),[Ft,It]=(0,g.useState)(nn),{themes:Lt,theme:Rt,switchTheme:Bt,reloadThemes:Vt}=up();wS(),(0,g.useEffect)(()=>{try{typeof fl==`function`&&fl(Rt??``)}catch{}},[Rt]),(0,g.useEffect)(()=>{try{typeof pl==`function`&&pl(t)}catch{}},[t]),(0,g.useEffect)(()=>{try{typeof ml==`function`&&ml(w)}catch{}},[w]),(0,g.useEffect)(()=>{try{let e=n.state?.model,t=e?`${e.provider}/${e.id}`:null;typeof cl==`function`&&cl(t)}catch{}},[n.state?.model?.provider,n.state?.model?.id]),(0,g.useEffect)(()=>{if(!Ke)return;let e=e=>{if(e.key!==`Escape`)return;let t=Ye.current;Ye.current=null,Je(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)},[Ke]),(0,g.useEffect)(()=>{if(!et)return;let e=setTimeout(()=>{let e=nt.current;nt.current=null,tt(null);try{e?.resolve(null)}catch{}},8e3);return()=>clearTimeout(e)},[et]);let Ut=(0,g.useRef)(null),Wt=(0,g.useRef)(null),Gt=(0,g.useRef)(n.state?.messages);Gt.current=n.state?.messages;let Kt=(0,g.useRef)(new Set),qt=(0,g.useRef)(new Set),Jt=(0,g.useRef)(new Set),Yt=(0,g.useRef)(0),Zt=(0,g.useRef)(!1),Qt=(0,g.useRef)(n.terminals);(0,g.useEffect)(()=>{xx(Nt)},[Nt]),(0,g.useEffect)(()=>{rn(Ft)},[Ft]),(0,g.useEffect)(()=>{let e=Qt.current;Qt.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=nw(Ut.current,t,n.state?.isStreaming??!1,n.conversations,Wt.current);if(Ut.current=r.nextMap,Wt.current=t,r.startCue&&Ex(`start`,Nt),r.finishedConvs.length>0){Ex(`done`,Nt);let t=r.finishedConvs.find(e=>e.isActive);if(t&&(Si(e(`notifyDoneTitle`),e(`notifyDoneBody`)),Ft.enabled&&!ui(gi()))){if(Ft.readReplies){let t=cn(Gt.current);t?_n(t,Ft):Ft.announce&&_n(e(`ttsAnnounceDone`),Ft)}else Ft.announce&&_n(e(`ttsAnnounceDone`),Ft)}for(let t of r.finishedConvs.filter(e=>!e.isActive)){let n=t.title?`${t.title}:${e(`notifyDoneBody`)}`:e(`notifyDoneBody`);Si(e(`notifyDoneTitle`),n)}!t&&Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceDone`),Ft)}},[n.state?.conversationId,n.state?.isStreaming,n.conversations,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.dialog?.id??null;if(t!==null&&!Kt.current.has(t)){if(Kt.current.add(t),Kt.current.size>64){let e=Kt.current.values().next().value;e!==void 0&&Kt.current.delete(e)}Ex(`question`,Nt),Si(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceQuestion`),Ft)}},[n.dialog,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.question?.id??null,r=n.remoteQuestion?`${n.remoteQuestion.owner}:${n.remoteQuestion.id}`:null,i=!1;t!==null&&!qt.current.has(t)&&(qt.current.add(t),i=!0),r!==null&&!qt.current.has(r)&&(qt.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}`;qt.current.has(n)||(qt.current.add(n),e.questionId&&qt.current.add(e.questionId),t!==e.questionId&&(i=!0))}if(qt.current.size>64){let e=qt.current.values().next().value;e!==void 0&&qt.current.delete(e)}i&&(Ex(`question`,Nt),Si(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceQuestion`),Ft))},[n.question,n.remoteQuestion,n.conversations,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.approval,r=t?.id??null;if(r!==null&&!Jt.current.has(r)){if(Jt.current.add(r),Jt.current.size>64){let e=Jt.current.values().next().value;e!==void 0&&Jt.current.delete(e)}Ex(`approval`,Nt);let n=typeof t?.toolName==`string`?t.toolName:``;Si(e(`notifyApprovalTitle`),n?e(`notifyApprovalBodyTool`,{tool:n}):e(`notifyApprovalBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceApproval`),Ft)}},[n.approval,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=[...n.notices].reverse().find(e=>e.level===`error`);t&&t.id!==Yt.current&&(Yt.current=t.id,Ex(`error`,Nt),Si(e(`notifyErrorTitle`),e(`notifyErrorBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceError`),Ft))},[n.notices,Nt,Ft,e]);let $t=(0,g.useRef)(new Set);(0,g.useEffect)(()=>{let e=n.state?.messages??[];for(let t of e){if(t.toolName!==`live_preview`||$t.current.has(t.id))continue;$t.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(Cn(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 en=(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&&yr(`@${s} `)},tn=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&&br(`@${t}`)},an=(0,g.useCallback)(e=>(!e.type.startsWith(`list_`)&&!e.type.startsWith(`get_`)&&Oe(null),(e.type===`new_chat`||e.type===`switch_conversation`||e.type===`switch_session`)&&C(e=>e===`chat`?e:`chat`),r(e)),[r]),on=(0,g.useRef)(new Set),sn=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 on.current)i.has(e)||on.current.delete(e);for(let n of t){let t=`question-${n.id}`;if(n.id===sn){Cb(t,{silent:!0});continue}n.questionId&&on.current.has(n.questionId)||Sb({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&&on.current.add(n.questionId)},onClick:()=>{an({type:`switch_conversation`,id:n.id}),Cb(t,{silent:!0})}})}wb(e=>{let t=e.data?.conversationId;return t?!r.has(t)||t===sn:!1},{silent:!0})},[n.conversations,sn,an,e]);let ln=(0,g.useRef)(0),un=(0,g.useRef)(0),dn=(0,g.useCallback)(t=>{let r=Date.now();n.state?.model&&!n.state.model.vision&&r-un.current>1e4&&(un.current=r,a(`warning`,e(`imageNotSupported`)));let i=`paste-${++ln.current}`;d(e=>[...e,{path:``,key:i,name:t.name,imageData:t.data,mimeType:t.mimeType}])},[n.state?.model,a,e]),fn=(0,g.useCallback)(async t=>{for(let n of t){let t=await _h(n);if(!t){a(`error`,e(`imageLoadFailed`,{name:n.name}));continue}dn(t)}},[dn,a,e]),pn=20971520,mn=(0,g.useRef)(0),hn=(0,g.useCallback)(async t=>{if(t.size>pn){a(`warning`,e(`fileTooLarge`,{name:t.name,size:pn/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-${++mn.current}`;d(e=>[...e,{path:``,key:r,name:t.name,fileData:n,size:t.size,mimeType:t.type||void 0}])},[pn,a,e]),gn=(0,g.useCallback)(async e=>{for(let t of e)gh(t.type)?await fn([t]):await hn(t)},[fn,hn]),vn=(0,g.useCallback)((e,t,n)=>{r({type:`edit_message`,messageId:e,text:t,attachments:n})},[r]),yn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n})},[r]),[bn,xn]=(0,g.useState)([]),Sn=(0,g.useRef)(0),wn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n}),Sn.current+=1;let i=Ns(t),a={text:i.text,seq:Sn.current};if(i.quotes.length&&d(e=>pv(e,i.quotes.map(e=>({path:``,name:``,mode:`quote`,quote:e,key:Ht()})))),i.attachments?.length){let e=i.attachments.filter(e=>e.type!==`vision-bridge`).map(e=>({path:e.path||e.url||``,name:e.name,mode:e.type===`page`?`page`:e.type===`conversation`?`conversation`:e.lines?`lines`:`reference`,lines:e.lines,key:Ht()}));e.length&&d(t=>pv(t,e))}xn(e=>[...e.slice(-9),a])},[r]),Tn=(0,g.useCallback)(()=>Ie(!0),[]),En=(0,g.useCallback)(()=>d([]),[]);Pb(n.state?.sessionId??``,En);let Dn=(0,g.useCallback)(tn,[]),On=fn,An=gn,jn=(0,g.useCallback)((e,t)=>r({type:`search_files`,reqId:e,query:t}),[r]),Mn=(0,g.useCallback)(e=>en(e.path,e.name,e.mode??`reference`,e.isDir??!1,e.lines,e.silent??!1),[]),Nn=n.state?.model,Pn=n.state?.thinkingLevel,Fn=n.state?.availableThinkingLevels,In=(0,g.useMemo)(()=>Nn?{model:Nn,thinkingLevel:Pn??`off`,availableThinkingLevels:Fn??[]}:null,[Nn,Pn,Fn]),Ln=(0,g.useCallback)(()=>!n.ready||n.terminals.length!==0?!1:(o.create({id:Ht(),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(Zt.current){if(w!==`terminal`||n.terminals.length!==0){Zt.current=!1;return}Ln()&&(Zt.current=!1)}},[n.terminals.length,Ln,w]),(0,X.jsxs)(`div`,{className:`app${At?` zen-mode`:``}`,"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=>gh(e.type)),i=n.filter(e=>!gh(e.type));r.length>0&&fn(r),i.length>0&&gn(i)},children:[At&&(0,X.jsxs)(`button`,{type:`button`,className:`zen-exit-pill`,onClick:Mt,title:e(`zenModeExitTip`),"aria-label":e(`zenModeExit`),children:[(0,X.jsx)(qe,{}),(0,X.jsx)(`span`,{children:e(`zenModeExit`)})]}),b&&(0,X.jsx)(`div`,{className:`app-drop-overlay`,"aria-hidden":!0,children:(0,X.jsxs)(`span`,{children:[`📎 `,e(`dropHereToAttach`)]})}),(0,X.jsx)(hs,{chat:n,terminal:o,view:w,plugins:T,uiPrimary:D,uiOverflow:O,uiContextTopbar:E[`contextmenu.topbar`],onUiAction:U,zenMode:At,onToggleZenMode:Mt,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:()=>{Be(void 0),Re(!0)},onManagePlugins:()=>{Be(`plugins`),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onOpenIconEdit:()=>vt(!0),sound:Nt,onSoundChange:Pt,onSoundPreview:e=>Ex(e,Nt),themes:Lt,theme:Rt,onThemeChange:Bt,reloadThemes:Vt}),_t&&(0,X.jsx)(Nb,{slots:E,layout:n.settings?.uiLayout,exclude:fa,onClose:()=>vt(!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)(iw,{notice:e,onDismiss:i},e.id)),et&&(0,X.jsxs)(`div`,{className:`notice notice-info`,role:`status`,children:[(0,X.jsx)(`span`,{className:`notice-text`,children:et.text}),et.actions.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let t=nt.current;nt.current=null,tt(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=nt.current;nt.current=null,tt(null);try{e?.resolve(null)}catch{}},children:(0,X.jsx)(P,{})})]}),V.length>0&&(0,X.jsx)(`div`,{className:`notice-actions`,role:`toolbar`,children:V.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=>U(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:()=>U(e),children:[e.icon?`${e.icon} `:``,e.badge??e.label]},e.id))})]}),(0,X.jsx)(c_,{currentModelId:Nn?`${Nn.provider}/${Nn.id}`:null,children:(0,X.jsxs)(`div`,{ref:ke,className:`layout`,style:{"--left-w":`${ge}px`,"--right-w":`${ve}px`},children:[Ae?(0,X.jsx)(`div`,{className:`drawer-backdrop persistent${De?` on`:``}`,onClick:()=>Oe(null)}):De&&(0,X.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>Oe(null)}),(0,X.jsx)(Vy,{side:`left`,items:H,chat:n,view:w,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:e=>{Be(e),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onUiAction:U,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Bt(Rt===`light`?null:`light`),onSoundToggle:()=>Pt({...Nt,enabled:!Nt.enabled}),zenMode:At,onToggleZenMode:Mt}),(0,X.jsxs)(`div`,{className:`view-pane ${w===`chat`?``:`hidden`}`,children:[!Ae&&xe&&(0,X.jsx)(mw,{side:`left`,onClick:Te}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-left ${De===`left`?`open`:``}${Ae?``:xe?` hidden`:``}`,children:(0,X.jsx)(rd,{collapsible:!Ae,onToggleCollapse:Te,panelSend:an,active:!Ae||De===`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:te,uiSections:M,renderPluginSectionBody:se,uiLeftRunning:N,uiLeftHistory:F,uiPluginRunning:n.pluginPanelGroups,onPluginRunningAction:ce,onUiAction:U,presetNames:ae,transition:n.transition,onOpenSandboxModal:()=>He(`create`)})}),!Ae&&(0,X.jsx)(pw,{side:`left`,width:ge,onResize:be}),(0,X.jsxs)(`main`,{className:`${dt?`main wide-chat`:`main`}${ft?` hide-model-row`:``}${n.transition&&!n.transition.previewMessages?.length?` main-transitioning`:``}`,children:[n.transition&&(0,X.jsxs)(`div`,{className:`workspace-transition-bar phase-${n.transition.phase}`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(`div`,{className:`workspace-transition-track`,children:(0,X.jsx)(`div`,{className:`workspace-transition-fill`,style:{width:`${Math.min(100,Math.max(8,n.transition.progress))}%`}})}),(0,X.jsxs)(`div`,{className:`workspace-transition-pill`,children:[(0,X.jsx)(`span`,{className:`workspace-transition-spinner`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`workspace-transition-text`,children:!kn(t)&&n.transition.textEn?n.transition.textEn:n.transition.text}),(0,X.jsxs)(`span`,{className:`workspace-transition-pct`,children:[n.transition.progress,`%`]})]})]}),ie.length>0&&(0,X.jsx)(`div`,{className:`chat-header`,role:`toolbar`,children:m_(ie,U)}),n.state?(0,X.jsxs)(X.Fragment,{children:[n.state.sandbox&&(0,X.jsxs)(`div`,{className:`sandbox-banner`,role:`region`,"aria-label":n.state.sandbox.name,children:[(0,X.jsxs)(`div`,{className:`sandbox-banner-info`,children:[(0,X.jsxs)(`span`,{className:`sandbox-banner-title`,children:[(0,X.jsx)(zt,{className:`sandbox-banner-icon`,"aria-hidden":!0}),e(`sandboxBannerTitle`,{name:n.state.sandbox.name}),(0,X.jsx)(`span`,{className:`lp-sandbox-badge ${n.state.sandbox.ephemeral?`ephemeral`:`permanent`}`,children:n.state.sandbox.ephemeral?e(`sandboxBadgeEphemeral`):e(`sandboxBadgePermanent`)})]}),(0,X.jsx)(`span`,{className:`sandbox-banner-desc`,children:n.state.sandbox.sourcePath?e(`sandboxBannerSourceDesc`,{source:n.state.sandbox.sourcePath}):e(`sandboxBannerBlankDesc`)})]}),(0,X.jsxs)(`div`,{className:`sandbox-banner-actions`,children:[n.state.sandbox.ephemeral&&(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionPersistTip`),onClick:()=>r({type:`persist_sandbox`,path:n.state?.sandbox?.path}),children:[(0,X.jsx)(wt,{"aria-hidden":!0}),` `,e(`sandboxActionPersist`)]}),n.state.sandbox.sourcePath&&(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn primary`,title:e(`sandboxActionApplySourceTip`),onClick:()=>He(`apply`),children:[(0,X.jsx)(yt,{"aria-hidden":!0}),` `,e(`sandboxActionApplySource`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionPromoteTip`),onClick:()=>He(`promote`),children:[(0,X.jsx)(L,{"aria-hidden":!0}),` `,e(`sandboxActionPromote`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionResetTip`),onClick:()=>{let t=n.state?.sandbox;t&&window.confirm(e(`sandboxActionResetConfirm`,{name:t.name}))&&r({type:`reset_sandbox`,path:t.path})},children:[(0,X.jsx)(me,{"aria-hidden":!0}),` `,e(`sandboxActionReset`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn danger`,title:e(`sandboxActionDestroyTip`),onClick:()=>{let t=n.state?.sandbox;t&&window.confirm(e(`sandboxActionDestroyConfirm`,{name:t.name}))&&r({type:`destroy_sandbox`,path:t.path})},children:[(0,X.jsx)(R,{"aria-hidden":!0}),` `,e(`sandboxActionDestroy`)]})]})]}),n.state.worktree&&(0,X.jsx)(Dy,{worktree:n.state.worktree,onSwitch:e=>r({type:`switch_worktree`,path:e}),onRemove:(e,t)=>r({type:`remove_worktree`,path:e,force:t})}),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:sn}),children:[`💾 `,e(`saveEphemeral`)]})]}),(0,X.jsx)(cv,{uiMessageActions:E[`message.actions`],uiContextMessage:E[`contextmenu.message`],uiContextToolCall:E[`contextmenu.toolcall`],uiChatEmpty:z,onUiAction:U,state:n.transition?.previewMessages?.length?{...n.state,messages:n.transition.previewMessages,streamingMessage:null,isStreaming:!1}:n.state,liveOutputs:n.liveOutputs,toolStatuses:n.toolStatuses,onEdit:vn,onKillBash:()=>r({type:`abort_bash`}),onRetry:()=>{if(r({type:`retry_last`})){let e=n.state?.model;e&&e_(`${e.provider}/${e.id}`)}},onRemoveQueued:yn,onRecallQueued:wn,thinkingWrap:n.settings?.thinkingWrap??!0,toolsWrap:n.settings?.toolsWrap??!0,toolImages:n.settings?.toolImagesEnabled??!0,keepRecent:n.settings?.keepRecentMessages,jumpTarget:bt,onJumpDone:()=>xt(null),urlJumpMessageId:St&&St.sessionId===n.state.sessionId?St.messageId:null,onUrlJumpDone:()=>Ct(null)},n.transition?.previewMessages?.length?`preview:${n.transition.target}`: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)(wy,{goal:n.goal,models:n.models,modelsLoading:n.modelsLoading,activeConversationId:n.activeConversationId,uiGoalbarActions:re,onUiAction:U})}),(0,X.jsx)(hb,{onAction:(e,t,n)=>U(e,n,t)}),n.dialog&&(0,X.jsx)(Hy,{dialog:n.dialog}),Ke&&(0,X.jsxs)(`div`,{className:`dialog-inline`,"data-dialog-kind":Ke.kind,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),Ke.title&&(0,X.jsx)(`span`,{className:`dialog-title`,children:Ke.title}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.kind===`confirm`?e.resolve(!1):e?.resolve({ok:!1})}catch{}},children:`✕`})]}),Ke.kind===`select`&&(0,X.jsxs)(`div`,{className:`dialog-options`,children:[(Ke.options??[]).map((e,t)=>{let n=Ke.multi?Xe.includes(t):!1;return(0,X.jsxs)(`button`,{type:`button`,className:`dialog-option ${n?`sel`:``}`,title:e.description,onClick:()=>{if(Ke.multi){Ze(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);return}let n=Ye.current;Ye.current=null,Je(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)}),(Ke.options??[]).length===0&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:e(`noOptions`)}),Ke.multi&&(0,X.jsx)(`div`,{className:`dialog-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current,t=(e?.options??[]).filter((e,t)=>Xe.includes(t)).map(e=>e.label);Ye.current=null,Je(null);try{e?.resolve({ok:!0,selected:t})}catch{}},children:e(`ok`)})})]}),Ke.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=Ye.current;Ye.current=null,Je(null);try{e?.resolve(!1)}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve(!0)}catch{}},children:e(`ok`)})]})}),Ke.kind===`input`&&(0,X.jsxs)(`div`,{className:`dialog-body`,children:[(0,X.jsx)(`input`,{className:`dialog-input`,value:Qe,placeholder:Ke.placeholder||e(`inputPlaceholder`),autoFocus:!0,onChange:e=>$e(e.target.value),onKeyDown:e=>{if(e.key===`Enter`&&!e.nativeEvent.isComposing){let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!0,value:Qe})}catch{}}}}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!1})}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!0,value:Qe})}catch{}},children:e(`ok`)})]})]})]}),n.question&&(0,X.jsx)(Qy,{question:n.question,conversationTitle:n.question.conversationTitle||n.conversations.find(e=>e.id===(n.question?.conversationId||sn))?.title}),n.remoteQuestion&&(0,X.jsx)(Qy,{question:n.remoteQuestion,owner:n.remoteQuestion.owner,conversationTitle:n.remoteQuestion.conversationTitle||n.conversations.find(e=>e.id===n.remoteQuestion?.convId)?.title}),(0,X.jsx)(hC,{plan:n.activeConversationId&&n.state?.conversationId!==n.activeConversationId?null:n.state?.plan}),(0,X.jsx)(Cy,{composerLeading:E[`composer.leading`],composerActions:E[`composer.actions`],onUiAction:U,streaming:n.state?.isStreaming??!1,planMode:n.state?.planMode??!1,messages:n.state?.messages??aw,slashCommands:n.slashCommands,modelState:In,models:n.models,modelsLoading:n.modelsLoading,providerKeys:n.providerKeys,defaultModel:n.engine===`pi`?n.defaultModel:void 0,attachments:u,onRemoveAttachment:Dn,onAddImageFiles:On,onAddLocalFiles:An,onAddPathAttachment:Mn,fileSearch:n.fileSearch,onSearchFiles:jn,onNotice:a,onManageModels:Tn,onSent:En,quickPhrases:n.settings?.quickPhrases??[],quickPhrasesEnabled:At?!1:n.settings?.quickPhrasesEnabled??!0,recallDrafts:bn,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??``})]}),!Ae&&(0,X.jsx)(pw,{side:`right`,width:ve,onResize:Y}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-right ${De===`right`?`open`:``}${Ae?``:Ce?` hidden`:``}`,children:(0,X.jsx)($d,{collapsible:!Ae,onToggleCollapse:Ee,panelSend:an,files:n.files,fileChanged:n.fileChanged,widgets:n.widgets,onAttach:(e,t,n,r)=>{Oe(null),en(e,t,n,r)},onPreview:(e,t)=>{Oe(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})}),!Ae&&Ce&&(0,X.jsx)(mw,{side:`right`,onClick:Ee})]}),(0,X.jsx)(`div`,{className:`view-pane ${w===`terminal`?``:`hidden`}`,children:(0,X.jsx)(g.Suspense,{fallback:null,children:(0,X.jsx)(rw,{chat:n,terminal:o,uiTerminalToolbar:I,onUiAction:U})})}),(0,X.jsx)(`div`,{className:`view-pane ${w===`git`?``:`hidden`}`,children:(0,X.jsx)(fb,{chat:n,terminal:o,active:w===`git`,onSwitchToTerminal:()=>C(`terminal`),uiScmToolbar:ne,onUiAction:U})}),W.map(e=>{let t=`plugin:${e.info.id}`;return(0,X.jsx)(`div`,{className:`view-pane ${w===t?``:`hidden`}`,children:(0,X.jsx)(pb,{entry:e})},e.info.id)}),w.startsWith(`plugin:`)&&!W.some(e=>`plugin:${e.info.id}`===w)&&(0,X.jsx)(mb,{pluginId:w.slice(7),info:n.plugins.find(e=>`plugin:${e.id}`===w),epoch:n.pluginsEpoch,failed:ue.includes(w.slice(7))}),(0,X.jsx)(Vy,{side:`right`,items:oe,chat:n,view:w,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:e=>{Be(e),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onUiAction:U,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Bt(Rt===`light`?null:`light`),onSoundToggle:()=>Pt({...Nt,enabled:!Nt.enabled}),zenMode:At,onToggleZenMode:Mt})]})}),(0,X.jsx)(ky,{chat:n,bottombarItems:E.bottombar,onUiAction:U,onOpenSettings:()=>{Be(void 0),Re(!0)},onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenGlobalSearch:()=>gt(!0),onOpenBgTasks:()=>mt(!0)}),f&&(0,X.jsx)(RC,{file:f,content:n.fileContent,onAddLines:(e,t,n,r)=>en(e,t,`lines`,!1,{start:n,end:r}),onAttach:(e,t,n)=>en(e,t,n),onClose:()=>p(null),uiFilePreviewToolbar:B,onUiAction:U}),m&&(0,X.jsx)(HC,{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&&!Me&&!Fe&&!tr()&&(0,X.jsx)(Ub,{piConfigured:n.state.piConfigured,piAgentInstalled:n.state.piAgentInstalled,providers:n.providers,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,installResult:n.installResult,onClose:Pe}),Fe&&(0,X.jsx)($b,{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:()=>Ie(!1)}),Le&&(0,X.jsx)(cC,{chat:n,terminal:o,initialSection:ze,onSwitchToTerminal:()=>C(`terminal`),onClose:()=>Re(!1),onOpenIconEdit:()=>vt(!0),sound:Nt,onSoundChange:Pt,tts:Ft,onTtsChange:It}),pt&&(0,X.jsx)(uC,{servers:n.bgServers,plugins:n.plugins,epoch:n.pluginsEpoch,send:r,onUiAction:U,autoCleanupMin:n.settings?.bgAutoCleanupMin??0,onClose:()=>mt(!1)}),(0,X.jsx)(TC,{}),(0,X.jsx)(dC,{}),(0,X.jsx)(fC,{approval:n.approval}),n.tuiOverlay&&(0,X.jsx)(pC,{overlay:n.tuiOverlay}),G&&(0,X.jsx)(jC,{entry:G,pluginView:K?W.find(e=>e.info.id===K):void 0,onUiAction:(e,t)=>{U(e,t),pe(null)},onClose:()=>pe(null)}),(0,X.jsx)(AC,{open:ht,projects:n.projects,fileSearch:n.fileSearch,sessionSearch:n.sessionSearch,onClose:()=>gt(!1),onSwitchSession:(e,t)=>{r({type:`switch_session`,path:e});let n=t&&t[0];xt(n?{path:e,role:n.role,timestamp:n.timestamp}:null)},onSwitchProject:e=>{r({type:`set_cwd`,path:e})},onPreviewFile:(e,t)=>{y(e,t)}}),(ut||ot||Ue)&&(0,X.jsxs)(`div`,{className:`modal-backdrop perm-modal-backdrop`,children:[ut&&(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:()=>lt(ut.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[ut.family===`net`?e(`pluginPermBodyNet`).replace(`{plugin}`,ut.pluginId).replace(`{hosts}`,(ut.hosts??[]).join(`, `)):e(`pluginPermBodyLlm`).replace(`{plugin}`,ut.pluginId).replace(`{models}`,(ut.models??[]).length>0?` ${(ut.models??[]).join(`, `)}`:``),ut.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:ut.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>lt(ut.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>lt(ut.id,!0),children:e(`pluginPermOnce`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>lt(ut.id,!0,!0),children:e(`pluginPermAlways`)})]})]})]}),ot&&(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:()=>at(ot.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginGrantRequestBody`).replace(`{plugin}`,ot.pluginId).replace(`{path}`,ot.path),ot.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:ot.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>at(ot.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>at(ot.id,!0),children:e(`pluginGrantAllow`)})]})]})]}),Ue&&(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:()=>{Ge.current=null,Ue.resolve(!1),We(null)},children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginSessionGrantBody`).replace(`{path}`,Ue.path),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{Ge.current=null,Ue.resolve(!1),We(null)},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{Ge.current=null,Ue.resolve(!0),We(null)},children:e(`ok`)})]})]})]})]}),!Le&&Object.values(n.pluginJobs??{}).some(e=>e.phase!==`done`)&&(0,X.jsxs)(`div`,{className:`active-plugin-jobs-bar`,onClick:()=>{Be(`plugins`),Re(!0)},title:e(`pluginJobRunning`),children:[(0,X.jsx)(me,{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})()]}),Ve&&(0,X.jsx)(Ey,{mode:Ve,currentCwd:n.state?.cwd,currentSandbox:n.state?.sandbox,sandboxDiff:n.sandboxDiff,projects:n.projects,send:r,onClose:()=>He(null)}),(0,X.jsx)(Ab,{})]})}function xw(){typeof document<`u`&&(Sw(Cw()),Tw())}function Sw(e){!Number.isFinite(e)||e<0||document.documentElement.style.setProperty(`--msgs-gutter`,`${Math.round(e*100)/100}px`)}function Cw(){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 ww(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 Tw(){let e=()=>{let e=document.querySelector(`.messages`);return e?(Sw(ww(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)}var Ew=class extends g.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`RootErrorBoundary caught error:`,e,t)}render(){return this.state.error?(0,X.jsxs)(`div`,{style:{minHeight:`100vh`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:`24px`,background:`var(--bg, rgb(13, 14, 18))`,color:`var(--text, #e2e8f0)`,fontFamily:`system-ui, -apple-system, sans-serif`,textAlign:`center`},children:[(0,X.jsx)(`h2`,{style:{fontSize:`18px`,marginBottom:`12px`,color:`var(--red, #f43f5e)`},children:`页面加载出现异常 / App Failed to Render`}),(0,X.jsx)(`pre`,{style:{maxWidth:`600px`,overflow:`auto`,padding:`12px 16px`,background:`rgba(0, 0, 0, 0.4)`,borderRadius:`8px`,fontSize:`12px`,lineHeight:`1.5`,marginBottom:`20px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,color:`#94a3b8`},children:this.state.error.message||String(this.state.error)}),(0,X.jsx)(`button`,{type:`button`,style:{padding:`8px 20px`,background:`var(--accent, #38bdf8)`,color:`#0f172a`,border:`none`,borderRadius:`6px`,fontWeight:600,cursor:`pointer`,fontSize:`13px`},onClick:()=>window.location.reload(),children:`刷新重试 / Reload`})]}):this.props.children}};Tn(),cp(op()),xw(),(0,ee.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(g.StrictMode,{children:(0,X.jsx)(Ew,{children:(0,X.jsx)(Jn,{children:(0,X.jsx)(bw,{})})})})),`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{let e=xn();navigator.serviceWorker.register(`${e}sw.js`,{scope:e}).catch(e=>{console.warn(`Service worker registration failed:`,e)})});export{$ as a,Ht as c,he as d,q as f,P as g,R as h,dp as i,Qe as l,B as m,m_ as n,Xn as o,me as p,ap as r,Z as s,g_ as t,Ce as u};
|
|
690
|
+
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,IC)},[c]),oe=c?.lines??0,U=oe>IC,se=(e,t)=>{if(t){let t=L.current>0?L.current:e;p({start:Math.min(t,e),end:Math.max(t,e)})}else L.current=e,p({start:e,end:e})},ce=()=>{H.length!==0&&(L.current=1,p({start:1,end:H.length}))},W=()=>{f&&(n(e.path,e.name,f.start,f.end),v(!0),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>v(!1),1400))},le=c!==null&&c.kind===`text`&&!c.binary&&!c.truncated&&!BC(e.name),ue=()=>{ae.current=!1,V.current&&clearTimeout(V.current),R(!1),B(!1),S(c?.text??``),b(!1),k.current&&(zC(e.name)&&w(!0),VC(e.name)&&E(!0))},de=()=>{if(y){if(x!==(c?.text??``)&&!window.confirm(s(`discardFileChanges`)))return;ue();return}le&&c&&(k.current=zC(e.name)&&C||VC(e.name)&&T,zC(e.name)&&w(!1),VC(e.name)&&E(!1),p(null),S(c.text),b(!0))},fe=()=>{y&&c&&le&&$({type:`write_file`,path:e.path,text:x})&&(ae.current=!0,B(!1),R(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{ae.current=!1,R(!1),B(!0)},5e3))},pe=()=>{(!y||x===(c?.text??``)||window.confirm(s(`discardFileChanges`)))&&i()},K=e=>{I(Math.min(200,Math.max(50,e)))},me=f?f.end-f.start+1:0,q=c?.binary??!1,he=c?.truncated??!1,J=c?.kind??`text`,ge=zC(e.name)||BC(e.name),_e=VC(e.name),ve=ge&&C&&!y&&J===`text`&&!q,ye=_e&&T&&!y&&J===`text`&&!q,[Y,xe]=(0,g.useState)(()=>{try{return localStorage.getItem(LC)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{localStorage.setItem(LC,Y?`1`:`0`)}catch{}},[Y]);let[Se,Ce]=(0,g.useState)([]),[Te,Ee]=(0,g.useState)(``),De=(0,g.useRef)(null);(0,g.useEffect)(()=>{let e=De.current;if(!e||!ve){Ce([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=PC(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ce(n)},[ve,c?.text,e.path]),(0,g.useEffect)(()=>{let e=De.current;if(!e||!Y||!FC(Se))return;let t=Se.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ee(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Se,Y]);let Oe={"host:fp-md":ge&&J===`text`&&!q&&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)(Je,{}):(0,X.jsx)(lt,{})}):null,"host:fp-toc":ve&&FC(Se)?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":s(Y?`previewTocHide`:`previewTocShow`),onClick:()=>xe(e=>!e),children:(0,X.jsx)(ke,{})}):null,"host:fp-html":_e&&J===`text`&&!q&&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)(lt,{}):(0,X.jsx)(Je,{})}):null,"host:fp-edit":J===`text`&&!q&&c?(0,X.jsx)(`button`,{type:`button`,className:`fp-attach edit ${y?`on`:``}`,"data-tip":s(he?`fileEditTruncated`:y?`exitEditFile`:`editFile`),disabled:!le&&!y,onClick:de,children:(0,X.jsx)(Ze,{})}):null,"host:fp-wrap":J===`text`&&!q&&!ve&&!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)(ot,{})}):null,"host:fp-zoom":J===`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:F<=50,onClick:()=>K(F-10),children:(0,X.jsx)(te,{})}),(0,X.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:s(`resetZoom`),onClick:()=>I(100),children:[F,`%`]}),(0,X.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":s(`zoomIn`),disabled:F>=200,onClick:()=>K(F+10),children:(0,X.jsx)(M,{})})]}):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)(Ae,{})}),"host:fp-full":(0,X.jsx)(`button`,{type:`button`,className:`fp-attach full ${ee?`on`:``}`,"data-tip":s(ee?`exitFullscreen`:`fullscreen`),onClick:()=>N(e=>!e),children:ee?(0,X.jsx)(be,{}):(0,X.jsx)(we,{})}),"host:fp-close":null},je=a===void 0?[`host:fp-md`,`host:fp-toc`,`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`),Me=e=>Dn(Cn(`/api/file?clientId=${encodeURIComponent(Tu())}&path=${encodeURIComponent(e)}`)),Ne=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return Dn(Cn(`${/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`}?clientId=${encodeURIComponent(Tu())}${D?`&allowJs=1`:``}`))};return(0,X.jsx)(`div`,{className:`fp-overlay ${ee?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&pe()},children:(0,X.jsxs)(`div`,{className:`fp ${ee?`fullscreen`:``}`,style:{"--fp-zoom":F/100},children:[(0,X.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&N(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&&J===`text`&&!q&&s(`fileLines`,{n:oe}),c&&` · ${Ch(c.size)}`]}),(0,X.jsx)(`span`,{className:`fp-head-actions`,children:g_(je,Oe,o)}),(0,X.jsx)(`button`,{type:`button`,className:`fp-close`,title:s(`close`),"aria-label":s(`close`),onClick:pe,children:(0,X.jsx)(P,{})})]}),he&&J===`text`&&!q&&(0,X.jsx)(`div`,{className:`fp-notice`,children:BC(e.name)?s(`previewLinesTruncated`,{n:H.length}):s(`previewTruncated`)}),u&&!c&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`loading`)}),!u&&J===`none`&&!q&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`previewNotSupported`)}),!u&&J===`image`&&(0,X.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:pe,title:s(`clickToCloseImage`),children:(0,X.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:Me(e.path),alt:e.name,onClick:pe,title:s(`clickToCloseImage`)})}),!u&&J===`video`&&(0,X.jsx)(`div`,{className:`fp-media-wrap`,children:(0,X.jsx)(`video`,{className:`fp-media`,src:Me(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:Ne(e.path),target:`_blank`,rel:`noopener noreferrer`,title:s(`openInNewTab`),children:[(0,X.jsx)(Xe,{}),(0,X.jsx)(`span`,{children:s(`openInNewTab`)})]})]}),(0,X.jsx)(`iframe`,{className:`fp-html-frame`,src:Ne(e.path),title:e.name,sandbox:D?`allow-scripts`:``,referrerPolicy:`no-referrer`},D?`js`:`nojs`)]}),!u&&ve&&c&&(0,X.jsx)(`div`,{className:BC(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,X.jsxs)(`div`,{className:Y&&FC(Se)?`fp-toc-layout`:void 0,children:[Y&&FC(Se)&&(0,X.jsx)(`nav`,{className:`fp-toc`,"aria-label":s(`previewTocLabel`),children:Se.map(e=>(0,X.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Te?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),De.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,X.jsx)(`div`,{className:`fp-markdown-zoom`,ref:De,children:(0,X.jsx)(Cp,{text:c.text})})]})}),!u&&q&&J!==`image`&&J!==`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&&J===`text`&&!q&&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}),z&&(0,X.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:s(`saveResultUnknown`)})]}),!u&&!ve&&!ye&&!y&&J===`text`&&!q&&c&&H.length===0&&(0,X.jsx)(`div`,{className:`fp-empty`,children:s(`emptyFile`)}),!u&&!ve&&!ye&&!y&&J===`text`&&!q&&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&&(se(n,e.shiftKey),ne.current=!0,h(!0))},onMouseEnter:()=>{ne.current&&se(n,!0)},children:[(0,X.jsx)(`span`,{className:`fp-num`,children:n}),(0,X.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),U&&(0,X.jsx)(`div`,{className:`fp-lines-note`,children:s(`previewLinesTruncated`,{n:IC})})]}),(y||!ve&&!ye&&J===`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:de,children:s(`cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:ie||x===(c?.text??``),onClick:fe,children:[(0,X.jsx)(G,{}),` `,s(`saveFile`)]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`fp-hint`,children:f?s(`selectedRange`,{n:me,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:ce,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||q,onClick:W,children:[_?(0,X.jsx)(yt,{}):null,s(_?`addedToChat`:`addToChat`)]})]})]})})]})})}function zC(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function BC(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)}function VC(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}function HC({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 Vb({plugin:t,declaration:n});if(a)return;if(!s)throw Error(`插件没有提供可用的文件查看器`);let c=`/plugins-api/${encodeURIComponent(t.id)}`,l={...Wl(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 Dn(Cn(`${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)(ox,{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 UC=.4,WC=1.05;function GC(e){return Math.min(300,e*.86)}function KC(e,t,n){return n||(t<=144?null:e<=72?`left`:t-e<=72?`right`:null)}function qC(e,t){let n=Math.abs(e),r=Math.abs(t);return n<12&&r<12?`none`:n>r*1.2?`horizontal`:`vertical`}function JC(e,t){return e===`left`?t:-t}function YC(e,t){return Math.max(-e,Math.min(0,-e+t))}function XC(e,t,n){let r=n?e+t:t;return Math.max(0,Math.min(1,r/e))}function ZC(e){let{wasOpen:t,pull:n,width:r,durationMs:i}=e;return i<=320&&Math.abs(n)>=48?n>0:XC(r*WC,n,t)>=UC}var QC=new Set([`auto`,`scroll`,`overlay`]);function $C(e,t){let n=e instanceof Element?e:null;for(;n;){if(n instanceof HTMLElement&&n.scrollWidth>n.clientWidth+4&&QC.has(getComputedStyle(n).overflowX))return!0;if(n===t)break;n=n.parentElement}return!1}function ew(){let e=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener(`click`,e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener(`click`,e,{capture:!0}),400)}function tw(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=KC(r.clientX,window.innerWidth,n);i&&!$C(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=qC(d,v);if(t===`none`)return;if(t===`vertical`){s=null;return}c=`horizontal`,p=n===r,m=GC(window.innerWidth),h=m*WC;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=JC(r,d);let b=YC(h,f);y.style.transform=`translateX(${r===`left`?b:-b}px)`,_&&(_.style.opacity=String(XC(h,f,p))),t.preventDefault()},x=()=>{let e=s,t=c===`horizontal`&&e!==null&&g!==null,i=f,a=Date.now()-d,o=t?ZC({wasOpen:p,pull:i,width:m,durationMs:a}):!1;v(),t&&e&&o!==(n===e)&&(ew(),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 nw(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 rw=(0,g.lazy)(()=>bl(()=>import(`./TerminalPanel-Mk4laCAL.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([0,1,2,3,4])));function iw({notice:e,onDismiss:t}){let n=Z(),{locale:r}=Xn(),i=!kn(r)&&e.textEn?e.textEn:e.text,[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(a)return;let n=setTimeout(()=>t(e.id),tu(e.level));return()=>clearTimeout(n)},[a,e.id,e.level,t]);let s=e.level===`error`?Ft:e.level===`warning`?Pt:Ne;return(0,X.jsxs)(`div`,{className:`notice notice-${e.level}${a?` paused`:``}`,role:`status`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onClick:()=>{window.getSelection?.()?.toString()||t(e.id)},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:n=>{n.stopPropagation(),t(e.id)},children:(0,X.jsx)(P,{})})]})}var aw=[],ow=180,sw=520,cw=240,lw=e=>`pi-web-ui:${e}-panel-width`;function uw(e){try{let t=Number(localStorage.getItem(lw(e)));return Number.isFinite(t)&&t>=ow&&t<=sw?t:cw}catch{return cw}}var dw=e=>`pi-web-ui:${e}-panel-collapsed`;function fw(e){try{return localStorage.getItem(dw(e))===`1`}catch{return!1}}function pw({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(sw,Math.max(ow,Math.round(a+r))),n(o)},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),document.body.classList.remove(`panel-resizing`);try{localStorage.setItem(lw(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(cw)})}function mw({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)(pt,{}):(0,X.jsx)(mt,{})})}var hw=`pi-web-ui:plugin-path-grants`,gw=e=>e?`${hw}:${e}`:hw;function _w(e){if(e===null)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function vw(e){try{let t=gw(e);if(localStorage.getItem(t)!==null)return _w(localStorage.getItem(t));if(!e)return[];let n=_w(localStorage.getItem(hw));return localStorage.setItem(t,JSON.stringify(n)),n}catch{return[]}}function yw(e,t){try{let n=[...new Set([...vw(t),e])];localStorage.setItem(gw(t),JSON.stringify(n))}catch{}}function bw(){let e=Z(),{locale:t}=Xn(),{chat:n,send:r,dismissNotice:i,pushNotice:a,terminal:o}=Bu(),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:RS[t]??RS.en,quickPhrasesSeeded:!0})))},[n.ready,n.settings,r,t]);let c=n.state?.cwd??``,l=aS();(0,g.useEffect)(()=>{let t=l?Qx(c):``;document.title=t?`${t} — pi-web-ui`:e(`docTitle`)},[c,l,e]);let[u,d]=(0,g.useState)([]);(0,g.useEffect)(()=>(Sr(e=>d(t=>pv(t,e))),()=>Sr(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=Bb(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)(()=>(hp({open:e=>y(e.path,e.name),isOpen:()=>_.current||v.current!==null}),()=>hp(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=ja(ba(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]),te=(0,g.useMemo)(()=>E[`leftpanel.history.actions`].filter(e=>!e.hidden),[E]),M=E[`leftpanel.sections`],N=(0,g.useMemo)(()=>E[`leftpanel.running`].filter(e=>!e.hidden),[E]),F=(0,g.useMemo)(()=>E[`leftpanel.history`].filter(e=>!e.hidden),[E]),I=(0,g.useMemo)(()=>E[`terminal.toolbar`].filter(e=>!e.hidden),[E]),ne=(0,g.useMemo)(()=>E[`scm.toolbar`].filter(e=>!e.hidden),[E]),re=(0,g.useMemo)(()=>E[`goalbar.actions`].filter(e=>!e.hidden),[E]),ie=(0,g.useMemo)(()=>E[`chat.header`].filter(e=>!e.hidden),[E]),z=(0,g.useMemo)(()=>E[`chat.empty`].filter(e=>!e.hidden),[E]),B=(0,g.useMemo)(()=>E[`file.preview.toolbar`].filter(e=>!e.hidden),[E]),ae=(0,g.useMemo)(()=>Object.fromEntries((n.dshPresets?.presets??[]).map(n=>[n.id,uy(n,t,e).name])),[n.dshPresets,t]),V=(0,g.useMemo)(()=>E[`notice.actions`].filter(e=>!e.hidden),[E]),H=(0,g.useMemo)(()=>E[`sidebar.left`]??[],[E]),oe=(0,g.useMemo)(()=>E[`sidebar.right`]??[],[E]),U=(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&&Hh({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&&zc(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?Hl(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),se=(0,g.useCallback)(e=>{let t=n.plugins.find(t=>t.id===e.source.slice(7));return t?(0,X.jsx)(Ad,{plugin:t,epoch:n.pluginsEpoch,send:r,className:`lp-plugin-page`}):null},[n.plugins,n.pluginsEpoch,r]),ce=(0,g.useCallback)((t,n)=>{n.action&&zc(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?Hl(t,q.current.pluginsEpoch):!1}}).then(t=>{t||a(`info`,e(`pluginUiNoHandler`))})},[e,a]),[W,le]=(0,g.useState)([]);(0,g.useEffect)(()=>Fl(le),[]);let[ue,de]=(0,g.useState)([]);(0,g.useEffect)(()=>Nl(de),[]);let[fe,pe]=(0,g.useState)(null),G=fe?E[`modal.dialog`].find(e=>e.id===fe&&!e.hidden):void 0,K=(0,g.useMemo)(()=>{if(!G||G.kind!==`view`)return``;let e=G.view??``;return e.startsWith(`plugin:`)?e.slice(7):G.source.startsWith(`plugin:`)?G.source.slice(7):``},[G]);(0,g.useEffect)(()=>{if(!G||!K||W.some(e=>e.info.id===K))return;let e=q.current.plugins.find(e=>e.id===K);e&&Hl(e,q.current.pluginsEpoch)},[G,K,W,n.pluginsEpoch]),(0,g.useEffect)(()=>{Gf(r),Kf(T,n.pluginsEpoch),$f(T,n.pluginsEpoch),zb(T,n.pluginsEpoch),Ul(T,n.pluginsEpoch)},[T,n.pluginsEpoch,r]);let q=(0,g.useRef)(n);q.current=n;let he=(0,g.useRef)(C);he.current=C;let J=(0,g.useRef)(E);J.current=E,(0,g.useEffect)(()=>(Mc(jc({send:r,isReady:()=>!!q.current.state,setView:e=>he.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:vw,grantPath:yw,confirm:e=>new Promise(t=>{if(Ge.current){t(!1);return}let n={path:e.path,resolve:t};Ge.current=n,We(n)}),openModal:e=>{let t=String(e??``).trim();if(!t)return!1;let n=J.current[`modal.dialog`].find(e=>e.id===t);return!n||n.hidden?!1:(pe(t),!0)},closeModal:()=>pe(null),dialogConfirm:e=>new Promise(t=>{if(Ye.current){t(!1);return}let n={kind:`confirm`,title:e.title,resolve:t};Ye.current=n,Je(n)}),select:e=>new Promise(t=>{if(Ye.current){t({ok:!1,error:`busy`});return}let n={kind:`select`,title:e.title,options:e.options,...e.multi?{multi:!0}:{},resolve:t};Ye.current=n,Ze([]),Je(n)}),input:e=>new Promise(t=>{if(Ye.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};Ye.current=n,$e(e.initial??``),Je(n)}),notifyAction:e=>new Promise(t=>{try{let n=nt.current;nt.current=null,tt(null);try{n?.resolve(null)}catch{}let r={text:e.text,actions:e.actions,resolve:t};nt.current=r,tt(r)}catch{t(null)}}),loadPluginBundle:e=>{let t=q.current.plugins.find(t=>t.id===e);return t?Hl(t,q.current.pluginsEpoch):Promise.resolve(!1)}})),()=>Mc(null)),[r]);let[ge,_e]=(0,g.useState)(()=>uw(`left`)),[ve,ye]=(0,g.useState)(()=>uw(`right`)),be=(0,g.useCallback)(e=>_e(e),[]),Y=(0,g.useCallback)(e=>ye(e),[]),[xe,Se]=(0,g.useState)(()=>fw(`left`)),[Ce,we]=(0,g.useState)(()=>fw(`right`)),Te=(0,g.useCallback)(()=>{Se(e=>{try{localStorage.setItem(dw(`left`),e?`0`:`1`)}catch{}return!e})},[]),Ee=(0,g.useCallback)(()=>{we(e=>{try{localStorage.setItem(dw(`right`),e?`0`:`1`)}catch{}return!e})},[]),[De,Oe]=(0,g.useState)(null),ke=(0,g.useRef)(null),[Ae,je]=(0,g.useState)(()=>window.matchMedia(`(max-width: 768px)`).matches);(0,g.useEffect)(()=>{let e=window.matchMedia(`(max-width: 768px)`),t=e=>je(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),tw({enabled:Ae&&w===`chat`,open:De,onOpenChange:Oe,container:ke,backdropSelector:`.drawer-backdrop.persistent`});let[Me,Ne]=(0,g.useState)(()=>{try{return localStorage.getItem(`pi_web_setup_dismissed`)===`1`}catch{return!1}}),Pe=()=>{Ne(!0);try{localStorage.setItem(`pi_web_setup_dismissed`,`1`)}catch{}},[Fe,Ie]=(0,g.useState)(!1),[Le,Re]=(0,g.useState)(!1),[ze,Be]=(0,g.useState)(),[Ve,He]=(0,g.useState)(null),[Ue,We]=(0,g.useState)(null),Ge=(0,g.useRef)(null),[Ke,Je]=(0,g.useState)(null),Ye=(0,g.useRef)(null),[Xe,Ze]=(0,g.useState)([]),[Qe,$e]=(0,g.useState)(``),[et,tt]=(0,g.useState)(null),nt=(0,g.useRef)(null),[rt,it]=(0,g.useState)(()=>new Set),at=(e,t)=>{r({type:`plugin_path_response`,id:e,ok:t}),it(t=>new Set(t).add(e))},ot=n.pathRequests.find(e=>!rt.has(e.id))??null,[st,ct]=(0,g.useState)(()=>new Set),lt=(e,t,n=!1)=>{r({type:`plugin_permission_response`,id:e,ok:t,...n?{remember:!0}:{}}),ct(t=>new Set(t).add(e))},ut=n.permRequests.find(e=>!st.has(e.id))??null,dt=Rx(),ft=Jx(),[pt,mt]=(0,g.useState)(!1),[ht,gt]=(0,g.useState)(!1),[_t,vt]=(0,g.useState)(!1),[bt,xt]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!bt)return;let e=setTimeout(()=>xt(null),15e3);return()=>clearTimeout(e)},[bt]);let[St,Ct]=(0,g.useState)(null),Tt=(0,g.useRef)(null),Et=(0,g.useRef)(null),Dt=n.state?.sessionId??``,Ot=(0,g.useRef)(Dt);Ot.current=Dt;let kt=(0,g.useRef)(n.ready);kt.current=n.ready,(0,g.useEffect)(()=>{let e=()=>{let e=bs(window.location.hash);if(e){if(e.messageId?Ct({sessionId:e.sessionId,messageId:e.messageId}):Ct(null),!kt.current||!Ot.current){Tt.current=e.sessionId;return}Ot.current!==e.sessionId&&(Et.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=Et.current;if(e&&n.notices.some(t=>t.text.includes(e)&&(t.text.includes(`未找到会话`)||t.text.includes(`Session not found`)))&&(Et.current=null,Ct(null),Dt)){let e=xs({sessionId:Dt});window.location.hash!==e&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${e}`)}},[n.notices,Dt]),(0,g.useEffect)(()=>{if(!n.ready||!Dt)return;if(Tt.current){let e=Tt.current;if(Tt.current=null,e!==Dt){Et.current=e,C(`chat`),r({type:`switch_session`,path:``,sessionId:e});return}}if(Et.current){if(Dt===Et.current)Et.current=null;else return}let e=bs(window.location.hash),t=e?.sessionId===Dt?e.messageId:void 0,i=xs({sessionId:Dt,...t?{messageId:t}:{}});window.location.hash!==i&&window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${i}`)},[n.ready,Dt,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=Ht();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(),gt(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let[At,jt]=(0,g.useState)(()=>{try{return localStorage.getItem(`pi_zen_mode`)===`1`}catch{return!1}});(0,g.useEffect)(()=>{try{At?localStorage.setItem(`pi_zen_mode`,`1`):localStorage.removeItem(`pi_zen_mode`)}catch{}},[At]);let Mt=(0,g.useCallback)(()=>{jt(e=>{let t=!e;return t&&w!==`chat`&&C(`chat`),t})},[w]);Xt(()=>At?(jt(!1),!0):!1,At),(0,g.useEffect)(()=>{let e=e=>{let t=e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.toLowerCase()===`z`,n=(e.ctrlKey||e.metaKey)&&e.shiftKey&&e.key.toLowerCase()===`f`;(t||n)&&(e.preventDefault(),Mt())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Mt]);let[Nt,Pt]=(0,g.useState)(bx),[Ft,It]=(0,g.useState)(nn),{themes:Lt,theme:Rt,switchTheme:Bt,reloadThemes:Vt}=up();wS(),(0,g.useEffect)(()=>{try{typeof fl==`function`&&fl(Rt??``)}catch{}},[Rt]),(0,g.useEffect)(()=>{try{typeof pl==`function`&&pl(t)}catch{}},[t]),(0,g.useEffect)(()=>{try{typeof ml==`function`&&ml(w)}catch{}},[w]),(0,g.useEffect)(()=>{try{let e=n.state?.model,t=e?`${e.provider}/${e.id}`:null;typeof cl==`function`&&cl(t)}catch{}},[n.state?.model?.provider,n.state?.model?.id]),(0,g.useEffect)(()=>{if(!Ke)return;let e=e=>{if(e.key!==`Escape`)return;let t=Ye.current;Ye.current=null,Je(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)},[Ke]),(0,g.useEffect)(()=>{if(!et)return;let e=setTimeout(()=>{let e=nt.current;nt.current=null,tt(null);try{e?.resolve(null)}catch{}},8e3);return()=>clearTimeout(e)},[et]);let Ut=(0,g.useRef)(null),Wt=(0,g.useRef)(null),Gt=(0,g.useRef)(n.state?.messages);Gt.current=n.state?.messages;let Kt=(0,g.useRef)(new Set),qt=(0,g.useRef)(new Set),Jt=(0,g.useRef)(new Set),Yt=(0,g.useRef)(0),Zt=(0,g.useRef)(!1),Qt=(0,g.useRef)(n.terminals);(0,g.useEffect)(()=>{xx(Nt)},[Nt]),(0,g.useEffect)(()=>{rn(Ft)},[Ft]),(0,g.useEffect)(()=>{let e=Qt.current;Qt.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=nw(Ut.current,t,n.state?.isStreaming??!1,n.conversations,Wt.current);if(Ut.current=r.nextMap,Wt.current=t,r.startCue&&Ex(`start`,Nt),r.finishedConvs.length>0){Ex(`done`,Nt);let t=r.finishedConvs.find(e=>e.isActive);if(t&&(Si(e(`notifyDoneTitle`),e(`notifyDoneBody`)),Ft.enabled&&!ui(gi()))){if(Ft.readReplies){let t=cn(Gt.current);t?_n(t,Ft):Ft.announce&&_n(e(`ttsAnnounceDone`),Ft)}else Ft.announce&&_n(e(`ttsAnnounceDone`),Ft)}for(let t of r.finishedConvs.filter(e=>!e.isActive)){let n=t.title?`${t.title}:${e(`notifyDoneBody`)}`:e(`notifyDoneBody`);Si(e(`notifyDoneTitle`),n)}!t&&Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceDone`),Ft)}},[n.state?.conversationId,n.state?.isStreaming,n.conversations,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.dialog?.id??null;if(t!==null&&!Kt.current.has(t)){if(Kt.current.add(t),Kt.current.size>64){let e=Kt.current.values().next().value;e!==void 0&&Kt.current.delete(e)}Ex(`question`,Nt),Si(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceQuestion`),Ft)}},[n.dialog,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.question?.id??null,r=n.remoteQuestion?`${n.remoteQuestion.owner}:${n.remoteQuestion.id}`:null,i=!1;t!==null&&!qt.current.has(t)&&(qt.current.add(t),i=!0),r!==null&&!qt.current.has(r)&&(qt.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}`;qt.current.has(n)||(qt.current.add(n),e.questionId&&qt.current.add(e.questionId),t!==e.questionId&&(i=!0))}if(qt.current.size>64){let e=qt.current.values().next().value;e!==void 0&&qt.current.delete(e)}i&&(Ex(`question`,Nt),Si(e(`notifyQuestionTitle`),e(`notifyQuestionBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceQuestion`),Ft))},[n.question,n.remoteQuestion,n.conversations,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=n.approval,r=t?.id??null;if(r!==null&&!Jt.current.has(r)){if(Jt.current.add(r),Jt.current.size>64){let e=Jt.current.values().next().value;e!==void 0&&Jt.current.delete(e)}Ex(`approval`,Nt);let n=typeof t?.toolName==`string`?t.toolName:``;Si(e(`notifyApprovalTitle`),n?e(`notifyApprovalBodyTool`,{tool:n}):e(`notifyApprovalBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceApproval`),Ft)}},[n.approval,Nt,Ft,e]),(0,g.useEffect)(()=>{let t=[...n.notices].reverse().find(e=>e.level===`error`);t&&t.id!==Yt.current&&(Yt.current=t.id,Ex(`error`,Nt),Si(e(`notifyErrorTitle`),e(`notifyErrorBody`)),Ft.enabled&&Ft.announce&&!ui(gi())&&_n(e(`ttsAnnounceError`),Ft))},[n.notices,Nt,Ft,e]);let $t=(0,g.useRef)(new Set);(0,g.useEffect)(()=>{let e=n.state?.messages??[];for(let t of e){if(t.toolName!==`live_preview`||$t.current.has(t.id))continue;$t.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(Cn(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 en=(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&&yr(`@${s} `)},tn=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&&br(`@${t}`)},an=(0,g.useCallback)(e=>(!e.type.startsWith(`list_`)&&!e.type.startsWith(`get_`)&&Oe(null),(e.type===`new_chat`||e.type===`switch_conversation`||e.type===`switch_session`)&&C(e=>e===`chat`?e:`chat`),r(e)),[r]),on=(0,g.useRef)(new Set),sn=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 on.current)i.has(e)||on.current.delete(e);for(let n of t){let t=`question-${n.id}`;if(n.id===sn){Cb(t,{silent:!0});continue}n.questionId&&on.current.has(n.questionId)||Sb({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&&on.current.add(n.questionId)},onClick:()=>{an({type:`switch_conversation`,id:n.id}),Cb(t,{silent:!0})}})}wb(e=>{let t=e.data?.conversationId;return t?!r.has(t)||t===sn:!1},{silent:!0})},[n.conversations,sn,an,e]);let ln=(0,g.useRef)(0),un=(0,g.useRef)(0),dn=(0,g.useCallback)(t=>{let r=Date.now();n.state?.model&&!n.state.model.vision&&r-un.current>1e4&&(un.current=r,a(`warning`,e(`imageNotSupported`)));let i=`paste-${++ln.current}`;d(e=>[...e,{path:``,key:i,name:t.name,imageData:t.data,mimeType:t.mimeType}])},[n.state?.model,a,e]),fn=(0,g.useCallback)(async t=>{for(let n of t){let t=await _h(n);if(!t){a(`error`,e(`imageLoadFailed`,{name:n.name}));continue}dn(t)}},[dn,a,e]),pn=20971520,mn=(0,g.useRef)(0),hn=(0,g.useCallback)(async t=>{if(t.size>pn){a(`warning`,e(`fileTooLarge`,{name:t.name,size:pn/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-${++mn.current}`;d(e=>[...e,{path:``,key:r,name:t.name,fileData:n,size:t.size,mimeType:t.type||void 0}])},[pn,a,e]),gn=(0,g.useCallback)(async e=>{for(let t of e)gh(t.type)?await fn([t]):await hn(t)},[fn,hn]),vn=(0,g.useCallback)((e,t,n)=>{r({type:`edit_message`,messageId:e,text:t,attachments:n})},[r]),yn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n})},[r]),[bn,xn]=(0,g.useState)([]),Sn=(0,g.useRef)(0),wn=(0,g.useCallback)((e,t,n)=>{r({type:`queue_remove`,kind:e,text:t,index:n}),Sn.current+=1;let i=Ns(t),a={text:i.text,seq:Sn.current};if(i.quotes.length&&d(e=>pv(e,i.quotes.map(e=>({path:``,name:``,mode:`quote`,quote:e,key:Ht()})))),i.attachments?.length){let e=i.attachments.filter(e=>e.type!==`vision-bridge`).map(e=>({path:e.path||e.url||``,name:e.name,mode:e.type===`page`?`page`:e.type===`conversation`?`conversation`:e.lines?`lines`:`reference`,lines:e.lines,key:Ht()}));e.length&&d(t=>pv(t,e))}xn(e=>[...e.slice(-9),a])},[r]),Tn=(0,g.useCallback)(()=>Ie(!0),[]),En=(0,g.useCallback)(()=>d([]),[]);Pb(n.state?.sessionId??``,En);let Dn=(0,g.useCallback)(tn,[]),On=fn,An=gn,jn=(0,g.useCallback)((e,t)=>r({type:`search_files`,reqId:e,query:t}),[r]),Mn=(0,g.useCallback)(e=>en(e.path,e.name,e.mode??`reference`,e.isDir??!1,e.lines,e.silent??!1),[]),Nn=n.state?.model,Pn=n.state?.thinkingLevel,Fn=n.state?.availableThinkingLevels,In=(0,g.useMemo)(()=>Nn?{model:Nn,thinkingLevel:Pn??`off`,availableThinkingLevels:Fn??[]}:null,[Nn,Pn,Fn]),Ln=(0,g.useCallback)(()=>!n.ready||n.terminals.length!==0?!1:(o.create({id:Ht(),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(Zt.current){if(w!==`terminal`||n.terminals.length!==0){Zt.current=!1;return}Ln()&&(Zt.current=!1)}},[n.terminals.length,Ln,w]),(0,X.jsxs)(`div`,{className:`app${At?` zen-mode`:``}`,"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=>gh(e.type)),i=n.filter(e=>!gh(e.type));r.length>0&&fn(r),i.length>0&&gn(i)},children:[At&&(0,X.jsxs)(`button`,{type:`button`,className:`zen-exit-pill`,onClick:Mt,title:e(`zenModeExitTip`),"aria-label":e(`zenModeExit`),children:[(0,X.jsx)(qe,{}),(0,X.jsx)(`span`,{children:e(`zenModeExit`)})]}),b&&(0,X.jsx)(`div`,{className:`app-drop-overlay`,"aria-hidden":!0,children:(0,X.jsxs)(`span`,{children:[`📎 `,e(`dropHereToAttach`)]})}),(0,X.jsx)(hs,{chat:n,terminal:o,view:w,plugins:T,uiPrimary:D,uiOverflow:O,uiContextTopbar:E[`contextmenu.topbar`],onUiAction:U,zenMode:At,onToggleZenMode:Mt,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:()=>{Be(void 0),Re(!0)},onManagePlugins:()=>{Be(`plugins`),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onOpenIconEdit:()=>vt(!0),sound:Nt,onSoundChange:Pt,onSoundPreview:e=>Ex(e,Nt),themes:Lt,theme:Rt,onThemeChange:Bt,reloadThemes:Vt}),_t&&(0,X.jsx)(Nb,{slots:E,layout:n.settings?.uiLayout,exclude:fa,onClose:()=>vt(!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)(iw,{notice:e,onDismiss:i},e.id)),et&&(0,X.jsxs)(`div`,{className:`notice notice-info`,role:`status`,children:[(0,X.jsx)(`span`,{className:`notice-text`,children:et.text}),et.actions.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let t=nt.current;nt.current=null,tt(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=nt.current;nt.current=null,tt(null);try{e?.resolve(null)}catch{}},children:(0,X.jsx)(P,{})})]}),V.length>0&&(0,X.jsx)(`div`,{className:`notice-actions`,role:`toolbar`,children:V.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=>U(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:()=>U(e),children:[e.icon?`${e.icon} `:``,e.badge??e.label]},e.id))})]}),(0,X.jsx)(c_,{currentModelId:Nn?`${Nn.provider}/${Nn.id}`:null,children:(0,X.jsxs)(`div`,{ref:ke,className:`layout`,style:{"--left-w":`${ge}px`,"--right-w":`${ve}px`},children:[Ae?(0,X.jsx)(`div`,{className:`drawer-backdrop persistent${De?` on`:``}`,onClick:()=>Oe(null)}):De&&(0,X.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>Oe(null)}),(0,X.jsx)(Vy,{side:`left`,items:H,chat:n,view:w,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:e=>{Be(e),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onUiAction:U,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Bt(Rt===`light`?null:`light`),onSoundToggle:()=>Pt({...Nt,enabled:!Nt.enabled}),zenMode:At,onToggleZenMode:Mt}),(0,X.jsxs)(`div`,{className:`view-pane ${w===`chat`?``:`hidden`}`,children:[!Ae&&xe&&(0,X.jsx)(mw,{side:`left`,onClick:Te}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-left ${De===`left`?`open`:``}${Ae?``:xe?` hidden`:``}`,children:(0,X.jsx)(rd,{collapsible:!Ae,onToggleCollapse:Te,panelSend:an,active:!Ae||De===`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:te,uiSections:M,renderPluginSectionBody:se,uiLeftRunning:N,uiLeftHistory:F,uiPluginRunning:n.pluginPanelGroups,onPluginRunningAction:ce,onUiAction:U,presetNames:ae,transition:n.transition,onOpenSandboxModal:()=>He(`create`)})}),!Ae&&(0,X.jsx)(pw,{side:`left`,width:ge,onResize:be}),(0,X.jsxs)(`main`,{className:`${dt?`main wide-chat`:`main`}${ft?` hide-model-row`:``}${n.transition&&!n.transition.previewMessages?.length?` main-transitioning`:``}`,children:[n.transition&&(0,X.jsxs)(`div`,{className:`workspace-transition-bar phase-${n.transition.phase}`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(`div`,{className:`workspace-transition-track`,children:(0,X.jsx)(`div`,{className:`workspace-transition-fill`,style:{width:`${Math.min(100,Math.max(8,n.transition.progress))}%`}})}),(0,X.jsxs)(`div`,{className:`workspace-transition-pill`,children:[(0,X.jsx)(`span`,{className:`workspace-transition-spinner`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`workspace-transition-text`,children:!kn(t)&&n.transition.textEn?n.transition.textEn:n.transition.text}),(0,X.jsxs)(`span`,{className:`workspace-transition-pct`,children:[n.transition.progress,`%`]})]})]}),ie.length>0&&(0,X.jsx)(`div`,{className:`chat-header`,role:`toolbar`,children:m_(ie,U)}),n.state?(0,X.jsxs)(X.Fragment,{children:[n.state.sandbox&&(0,X.jsxs)(`div`,{className:`sandbox-banner`,role:`region`,"aria-label":n.state.sandbox.name,children:[(0,X.jsxs)(`div`,{className:`sandbox-banner-info`,children:[(0,X.jsxs)(`span`,{className:`sandbox-banner-title`,children:[(0,X.jsx)(zt,{className:`sandbox-banner-icon`,"aria-hidden":!0}),e(`sandboxBannerTitle`,{name:n.state.sandbox.name}),(0,X.jsx)(`span`,{className:`lp-sandbox-badge ${n.state.sandbox.ephemeral?`ephemeral`:`permanent`}`,children:n.state.sandbox.ephemeral?e(`sandboxBadgeEphemeral`):e(`sandboxBadgePermanent`)})]}),(0,X.jsx)(`span`,{className:`sandbox-banner-desc`,children:n.state.sandbox.sourcePath?e(`sandboxBannerSourceDesc`,{source:n.state.sandbox.sourcePath}):e(`sandboxBannerBlankDesc`)})]}),(0,X.jsxs)(`div`,{className:`sandbox-banner-actions`,children:[n.state.sandbox.ephemeral&&(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionPersistTip`),onClick:()=>r({type:`persist_sandbox`,path:n.state?.sandbox?.path}),children:[(0,X.jsx)(wt,{"aria-hidden":!0}),` `,e(`sandboxActionPersist`)]}),n.state.sandbox.sourcePath&&(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn primary`,title:e(`sandboxActionApplySourceTip`),onClick:()=>He(`apply`),children:[(0,X.jsx)(yt,{"aria-hidden":!0}),` `,e(`sandboxActionApplySource`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionPromoteTip`),onClick:()=>He(`promote`),children:[(0,X.jsx)(L,{"aria-hidden":!0}),` `,e(`sandboxActionPromote`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn`,title:e(`sandboxActionResetTip`),onClick:()=>{let t=n.state?.sandbox;t&&window.confirm(e(`sandboxActionResetConfirm`,{name:t.name}))&&r({type:`reset_sandbox`,path:t.path})},children:[(0,X.jsx)(me,{"aria-hidden":!0}),` `,e(`sandboxActionReset`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`sandbox-banner-btn danger`,title:e(`sandboxActionDestroyTip`),onClick:()=>{let t=n.state?.sandbox;t&&window.confirm(e(`sandboxActionDestroyConfirm`,{name:t.name}))&&r({type:`destroy_sandbox`,path:t.path})},children:[(0,X.jsx)(R,{"aria-hidden":!0}),` `,e(`sandboxActionDestroy`)]})]})]}),n.state.worktree&&(0,X.jsx)(Dy,{worktree:n.state.worktree,onSwitch:e=>r({type:`switch_worktree`,path:e}),onRemove:(e,t)=>r({type:`remove_worktree`,path:e,force:t})}),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:sn}),children:[`💾 `,e(`saveEphemeral`)]})]}),(0,X.jsx)(cv,{uiMessageActions:E[`message.actions`],uiContextMessage:E[`contextmenu.message`],uiContextToolCall:E[`contextmenu.toolcall`],uiChatEmpty:z,onUiAction:U,state:n.transition?.previewMessages?.length?{...n.state,messages:n.transition.previewMessages,streamingMessage:null,isStreaming:!1}:n.state,liveOutputs:n.liveOutputs,toolStatuses:n.toolStatuses,onEdit:vn,onKillBash:()=>r({type:`abort_bash`}),onRetry:()=>{if(r({type:`retry_last`})){let e=n.state?.model;e&&e_(`${e.provider}/${e.id}`)}},onRemoveQueued:yn,onRecallQueued:wn,thinkingWrap:n.settings?.thinkingWrap??!0,toolsWrap:n.settings?.toolsWrap??!0,toolImages:n.settings?.toolImagesEnabled??!0,keepRecent:n.settings?.keepRecentMessages,jumpTarget:bt,onJumpDone:()=>xt(null),urlJumpMessageId:St&&St.sessionId===n.state.sessionId?St.messageId:null,onUrlJumpDone:()=>Ct(null)},n.transition?.previewMessages?.length?`preview:${n.transition.target}`: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)(wy,{goal:n.goal,models:n.models,modelsLoading:n.modelsLoading,activeConversationId:n.activeConversationId,uiGoalbarActions:re,onUiAction:U})}),(0,X.jsx)(hb,{onAction:(e,t,n)=>U(e,n,t)}),n.dialog&&(0,X.jsx)(Hy,{dialog:n.dialog}),Ke&&(0,X.jsxs)(`div`,{className:`dialog-inline`,"data-dialog-kind":Ke.kind,children:[(0,X.jsxs)(`div`,{className:`dialog-head`,children:[(0,X.jsx)(`span`,{className:`dialog-badge`,children:e(`pluginRequest`)}),Ke.title&&(0,X.jsx)(`span`,{className:`dialog-title`,children:Ke.title}),(0,X.jsx)(`button`,{type:`button`,className:`dialog-dismiss`,title:e(`cancel`),onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.kind===`confirm`?e.resolve(!1):e?.resolve({ok:!1})}catch{}},children:`✕`})]}),Ke.kind===`select`&&(0,X.jsxs)(`div`,{className:`dialog-options`,children:[(Ke.options??[]).map((e,t)=>{let n=Ke.multi?Xe.includes(t):!1;return(0,X.jsxs)(`button`,{type:`button`,className:`dialog-option ${n?`sel`:``}`,title:e.description,onClick:()=>{if(Ke.multi){Ze(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);return}let n=Ye.current;Ye.current=null,Je(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)}),(Ke.options??[]).length===0&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:e(`noOptions`)}),Ke.multi&&(0,X.jsx)(`div`,{className:`dialog-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current,t=(e?.options??[]).filter((e,t)=>Xe.includes(t)).map(e=>e.label);Ye.current=null,Je(null);try{e?.resolve({ok:!0,selected:t})}catch{}},children:e(`ok`)})})]}),Ke.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=Ye.current;Ye.current=null,Je(null);try{e?.resolve(!1)}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve(!0)}catch{}},children:e(`ok`)})]})}),Ke.kind===`input`&&(0,X.jsxs)(`div`,{className:`dialog-body`,children:[(0,X.jsx)(`input`,{className:`dialog-input`,value:Qe,placeholder:Ke.placeholder||e(`inputPlaceholder`),autoFocus:!0,onChange:e=>$e(e.target.value),onKeyDown:e=>{if(e.key===`Enter`&&!e.nativeEvent.isComposing){let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!0,value:Qe})}catch{}}}}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!1})}catch{}},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{let e=Ye.current;Ye.current=null,Je(null);try{e?.resolve({ok:!0,value:Qe})}catch{}},children:e(`ok`)})]})]})]}),n.question&&(0,X.jsx)(Qy,{question:n.question,conversationTitle:n.question.conversationTitle||n.conversations.find(e=>e.id===(n.question?.conversationId||sn))?.title}),n.remoteQuestion&&(0,X.jsx)(Qy,{question:n.remoteQuestion,owner:n.remoteQuestion.owner,conversationTitle:n.remoteQuestion.conversationTitle||n.conversations.find(e=>e.id===n.remoteQuestion?.convId)?.title}),(0,X.jsx)(hC,{plan:n.activeConversationId&&n.state?.conversationId!==n.activeConversationId?null:n.state?.plan}),(0,X.jsx)(Cy,{composerLeading:E[`composer.leading`],composerActions:E[`composer.actions`],onUiAction:U,streaming:n.state?.isStreaming??!1,planMode:n.state?.planMode??!1,messages:n.state?.messages??aw,slashCommands:n.slashCommands,modelState:In,models:n.models,modelsLoading:n.modelsLoading,providerKeys:n.providerKeys,defaultModel:n.engine===`pi`?n.defaultModel:void 0,attachments:u,onRemoveAttachment:Dn,onAddImageFiles:On,onAddLocalFiles:An,onAddPathAttachment:Mn,fileSearch:n.fileSearch,onSearchFiles:jn,onNotice:a,onManageModels:Tn,onSent:En,quickPhrases:n.settings?.quickPhrases??[],quickPhrasesEnabled:At?!1:n.settings?.quickPhrasesEnabled??!0,recallDrafts:bn,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??``})]}),!Ae&&(0,X.jsx)(pw,{side:`right`,width:ve,onResize:Y}),(0,X.jsx)(`div`,{className:`panel-drawer drawer-right ${De===`right`?`open`:``}${Ae?``:Ce?` hidden`:``}`,children:(0,X.jsx)($d,{collapsible:!Ae,onToggleCollapse:Ee,panelSend:an,files:n.files,fileChanged:n.fileChanged,widgets:n.widgets,onAttach:(e,t,n,r)=>{Oe(null),en(e,t,n,r)},onPreview:(e,t)=>{Oe(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})}),!Ae&&Ce&&(0,X.jsx)(mw,{side:`right`,onClick:Ee})]}),(0,X.jsx)(`div`,{className:`view-pane ${w===`terminal`?``:`hidden`}`,children:(0,X.jsx)(g.Suspense,{fallback:null,children:(0,X.jsx)(rw,{chat:n,terminal:o,uiTerminalToolbar:I,onUiAction:U})})}),(0,X.jsx)(`div`,{className:`view-pane ${w===`git`?``:`hidden`}`,children:(0,X.jsx)(fb,{chat:n,terminal:o,active:w===`git`,onSwitchToTerminal:()=>C(`terminal`),uiScmToolbar:ne,onUiAction:U})}),W.map(e=>{let t=`plugin:${e.info.id}`;return(0,X.jsx)(`div`,{className:`view-pane ${w===t?``:`hidden`}`,children:(0,X.jsx)(pb,{entry:e})},e.info.id)}),w.startsWith(`plugin:`)&&!W.some(e=>`plugin:${e.info.id}`===w)&&(0,X.jsx)(mb,{pluginId:w.slice(7),info:n.plugins.find(e=>`plugin:${e.id}`===w),epoch:n.pluginsEpoch,failed:ue.includes(w.slice(7))}),(0,X.jsx)(Vy,{side:`right`,items:oe,chat:n,view:w,onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenPanel:Oe,onOpenSettings:e=>{Be(e),Re(!0)},onOpenBgTasks:()=>mt(!0),onOpenGlobalSearch:()=>gt(!0),onUiAction:U,uiContextTopbar:E[`contextmenu.topbar`],onThemeToggle:()=>Bt(Rt===`light`?null:`light`),onSoundToggle:()=>Pt({...Nt,enabled:!Nt.enabled}),zenMode:At,onToggleZenMode:Mt})]})}),(0,X.jsx)(ky,{chat:n,bottombarItems:E.bottombar,onUiAction:U,onOpenSettings:()=>{Be(void 0),Re(!0)},onViewChange:e=>{Zt.current=e===`terminal`&&n.terminals.length===0,Zt.current&&Ln()&&(Zt.current=!1),C(e),Oe(null)},onOpenGlobalSearch:()=>gt(!0),onOpenBgTasks:()=>mt(!0)}),f&&(0,X.jsx)(RC,{file:f,content:n.fileContent,onAddLines:(e,t,n,r)=>en(e,t,`lines`,!1,{start:n,end:r}),onAttach:(e,t,n)=>en(e,t,n),onClose:()=>p(null),uiFilePreviewToolbar:B,onUiAction:U}),m&&(0,X.jsx)(HC,{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&&!Me&&!Fe&&!tr()&&(0,X.jsx)(Ub,{piConfigured:n.state.piConfigured,piAgentInstalled:n.state.piAgentInstalled,providers:n.providers,providerOAuthFlows:n.providerOAuthFlows,providerOAuthResults:n.providerOAuthResults,installResult:n.installResult,onClose:Pe}),Fe&&(0,X.jsx)($b,{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:()=>Ie(!1)}),Le&&(0,X.jsx)(cC,{chat:n,terminal:o,initialSection:ze,onSwitchToTerminal:()=>C(`terminal`),onClose:()=>Re(!1),onOpenIconEdit:()=>vt(!0),sound:Nt,onSoundChange:Pt,tts:Ft,onTtsChange:It}),pt&&(0,X.jsx)(uC,{servers:n.bgServers,plugins:n.plugins,epoch:n.pluginsEpoch,send:r,onUiAction:U,autoCleanupMin:n.settings?.bgAutoCleanupMin??0,onClose:()=>mt(!1)}),(0,X.jsx)(TC,{}),(0,X.jsx)(dC,{}),(0,X.jsx)(fC,{approval:n.approval}),n.tuiOverlay&&(0,X.jsx)(pC,{overlay:n.tuiOverlay}),G&&(0,X.jsx)(jC,{entry:G,pluginView:K?W.find(e=>e.info.id===K):void 0,onUiAction:(e,t)=>{U(e,t),pe(null)},onClose:()=>pe(null)}),(0,X.jsx)(AC,{open:ht,projects:n.projects,fileSearch:n.fileSearch,sessionSearch:n.sessionSearch,onClose:()=>gt(!1),onSwitchSession:(e,t)=>{r({type:`switch_session`,path:e});let n=t&&t[0];xt(n?{path:e,role:n.role,timestamp:n.timestamp}:null)},onSwitchProject:e=>{r({type:`set_cwd`,path:e})},onPreviewFile:(e,t)=>{y(e,t)}}),(ut||ot||Ue)&&(0,X.jsxs)(`div`,{className:`modal-backdrop perm-modal-backdrop`,children:[ut&&(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:()=>lt(ut.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[ut.family===`net`?e(`pluginPermBodyNet`).replace(`{plugin}`,ut.pluginId).replace(`{hosts}`,(ut.hosts??[]).join(`, `)):e(`pluginPermBodyLlm`).replace(`{plugin}`,ut.pluginId).replace(`{models}`,(ut.models??[]).length>0?` ${(ut.models??[]).join(`, `)}`:``),ut.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:ut.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>lt(ut.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>lt(ut.id,!0),children:e(`pluginPermOnce`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>lt(ut.id,!0,!0),children:e(`pluginPermAlways`)})]})]})]}),ot&&(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:()=>at(ot.id,!1),children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginGrantRequestBody`).replace(`{plugin}`,ot.pluginId).replace(`{path}`,ot.path),ot.reason&&(0,X.jsx)(`div`,{className:`dialog-hint`,children:ot.reason}),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>at(ot.id,!1),children:e(`pluginGrantDeny`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>at(ot.id,!0),children:e(`pluginGrantAllow`)})]})]})]}),Ue&&(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:()=>{Ge.current=null,Ue.resolve(!1),We(null)},children:`✕`})]}),(0,X.jsxs)(`div`,{className:`dialog-body`,children:[e(`pluginSessionGrantBody`).replace(`{path}`,Ue.path),(0,X.jsxs)(`div`,{className:`dialog-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{Ge.current=null,Ue.resolve(!1),We(null)},children:e(`cancel`)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,onClick:()=>{Ge.current=null,Ue.resolve(!0),We(null)},children:e(`ok`)})]})]})]})]}),!Le&&Object.values(n.pluginJobs??{}).some(e=>e.phase!==`done`)&&(0,X.jsxs)(`div`,{className:`active-plugin-jobs-bar`,onClick:()=>{Be(`plugins`),Re(!0)},title:e(`pluginJobRunning`),children:[(0,X.jsx)(me,{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})()]}),Ve&&(0,X.jsx)(Ey,{mode:Ve,currentCwd:n.state?.cwd,currentSandbox:n.state?.sandbox,sandboxDiff:n.sandboxDiff,projects:n.projects,send:r,onClose:()=>He(null)}),(0,X.jsx)(Ab,{})]})}function xw(){typeof document<`u`&&(Sw(Cw()),Tw())}function Sw(e){!Number.isFinite(e)||e<0||document.documentElement.style.setProperty(`--msgs-gutter`,`${Math.round(e*100)/100}px`)}function Cw(){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 ww(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 Tw(){let e=()=>{let e=document.querySelector(`.messages`);return e?(Sw(ww(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)}var Ew=class extends g.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`RootErrorBoundary caught error:`,e,t)}render(){return this.state.error?(0,X.jsxs)(`div`,{style:{minHeight:`100vh`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:`24px`,background:`var(--bg, rgb(13, 14, 18))`,color:`var(--text, #e2e8f0)`,fontFamily:`system-ui, -apple-system, sans-serif`,textAlign:`center`},children:[(0,X.jsx)(`h2`,{style:{fontSize:`18px`,marginBottom:`12px`,color:`var(--red, #f43f5e)`},children:`页面加载出现异常 / App Failed to Render`}),(0,X.jsx)(`pre`,{style:{maxWidth:`600px`,overflow:`auto`,padding:`12px 16px`,background:`rgba(0, 0, 0, 0.4)`,borderRadius:`8px`,fontSize:`12px`,lineHeight:`1.5`,marginBottom:`20px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,color:`#94a3b8`},children:this.state.error.message||String(this.state.error)}),(0,X.jsx)(`button`,{type:`button`,style:{padding:`8px 20px`,background:`var(--accent, #38bdf8)`,color:`#0f172a`,border:`none`,borderRadius:`6px`,fontWeight:600,cursor:`pointer`,fontSize:`13px`},onClick:()=>window.location.reload(),children:`刷新重试 / Reload`})]}):this.props.children}};Tn(),cp(op()),xw(),(0,ee.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(g.StrictMode,{children:(0,X.jsx)(Ew,{children:(0,X.jsx)(Jn,{children:(0,X.jsx)(bw,{})})})})),`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{let e=xn();navigator.serviceWorker.register(`${e}sw.js`,{scope:e}).catch(e=>{console.warn(`Service worker registration failed:`,e)})});export{$ as a,Ht as c,he as d,q as f,P as g,R as h,dp as i,Qe as l,B as m,m_ as n,Xn as o,me as p,ap as r,Z as s,g_ as t,Ce as u};
|