pi-web-ui 0.63.0 → 0.63.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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-B9vcI7-_.js","assets/markdown-DRBrS2Nf.js","assets/xterm-D1D2FVe3.js","assets/react-C9ovnpIm.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-DwutHqgi.js","assets/markdown-DRBrS2Nf.js","assets/xterm-D1D2FVe3.js","assets/react-C9ovnpIm.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
2
  import{R as qe,a as l,j as e,M as Us,b as Fn,c as $n}from"./markdown-DRBrS2Nf.js";import{r as Ws}from"./react-C9ovnpIm.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))r(c);new MutationObserver(c=>{for(const a of c)if(a.type==="childList")for(const n of a.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&r(n)}).observe(document,{childList:!0,subtree:!0});function i(c){const a={};return c.integrity&&(a.integrity=c.integrity),c.referrerPolicy&&(a.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?a.credentials="include":c.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(c){if(c.ep)return;c.ep=!0;const a=i(c);fetch(c.href,a)}})();var ut={},cs;function On(){if(cs)return ut;cs=1;var t=Ws();return ut.createRoot=t.createRoot,ut.hydrateRoot=t.hydrateRoot,ut}var Hn=On();const Kn="modulepreload",Un=function(t){return"/"+t},ds={},Wn=function(s,i,r){let c=Promise.resolve();if(i&&i.length>0){let n=function(p){return Promise.all(p.map(f=>Promise.resolve(f).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),d=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=n(i.map(p=>{if(p=Un(p),p in ds)return;ds[p]=!0;const f=p.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${h}`))return;const g=document.createElement("link");if(g.rel=f?"stylesheet":Kn,f||(g.as="script"),g.crossOrigin="",g.href=p,d&&g.setAttribute("nonce",d),document.head.appendChild(g),f)return new Promise((y,C)=>{g.addEventListener("load",y),g.addEventListener("error",()=>C(new Error(`Unable to preload CSS for ${p}`)))})}))}function a(n){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=n,window.dispatchEvent(o),!o.defaultPrevented)throw n}return c.then(n=>{for(const o of n||[])o.status==="rejected"&&a(o.reason);return s().catch(a)})};var qs={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},us=qe.createContext&&qe.createContext(qs),qn=["attr","size","title"];function zn(t,s){if(t==null)return{};var i,r,c=Vn(t,s);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r<a.length;r++)i=a[r],s.indexOf(i)===-1&&{}.propertyIsEnumerable.call(t,i)&&(c[i]=t[i])}return c}function Vn(t,s){if(t==null)return{};var i={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;i[r]=t[r]}return i}function gt(){return gt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var i=arguments[s];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},gt.apply(null,arguments)}function ps(t,s){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),i.push.apply(i,r)}return i}function ft(t){for(var s=1;s<arguments.length;s++){var i=arguments[s]!=null?arguments[s]:{};s%2?ps(Object(i),!0).forEach(function(r){Gn(t,r,i[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ps(Object(i)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(i,r))})}return t}function Gn(t,s,i){return(s=Qn(s))in t?Object.defineProperty(t,s,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[s]=i,t}function Qn(t){var s=Yn(t,"string");return typeof s=="symbol"?s:s+""}function Yn(t,s){if(typeof t!="object"||!t)return t;var i=t[Symbol.toPrimitive];if(i!==void 0){var r=i.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function zs(t){return t&&t.map((s,i)=>qe.createElement(s.tag,ft({key:i},s.attr),zs(s.child)))}function te(t){return s=>qe.createElement(Jn,gt({attr:ft({},t.attr)},s),zs(t.child))}function Jn(t){var s=i=>{var r=t.attr,c=t.size,a=t.title,n=zn(t,qn),o=c||i.size||"1em",d;return i.className&&(d=i.className),t.className&&(d=(d?d+" ":"")+t.className),qe.createElement("svg",gt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},i.attr,r,n,{className:d,style:ft(ft({color:t.color||i.color},i.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),a&&qe.createElement("title",null,a),t.children)};return us!==void 0?qe.createElement(us.Consumer,null,i=>s(i)):s(qs)}function Xn(t){return te({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:[]}]})(t)}function Zn(t){return te({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:[]}]})(t)}function mt(t){return te({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:[]}]})(t)}function Ee(t){return te({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:[]}]})(t)}function Vs(t){return te({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:[]}]})(t)}function ms(t){return te({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:[]}]})(t)}function ei(t){return te({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:[]}]})(t)}function ti(t){return te({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:[]}]})(t)}function _e(t){return te({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:[]}]})(t)}function Xe(t){return te({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:[]}]})(t)}function hs(t){return te({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:[]}]})(t)}function si(t){return te({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:[]}]})(t)}function xt(t){return te({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:[]}]})(t)}function ni(t){return te({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:[]}]})(t)}function vt(t){return te({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:[]}]})(t)}function Gs(t){return te({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:[]}]})(t)}function yt(t){return te({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:[]}]})(t)}function ii(t){return te({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:[]}]})(t)}function Qs(t){return te({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:[]}]})(t)}function at(t){return te({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:[]}]})(t)}function Ae(t){return te({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:[]}]})(t)}function il(t){return te({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:[]}]})(t)}function ai(t){return te({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:[]}]})(t)}function gs(t){return te({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:[]}]})(t)}function ri(t){return te({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:"19",cy:"12",r:"1"},child:[]},{tag:"circle",attr:{cx:"5",cy:"12",r:"1"},child:[]}]})(t)}function li(t){return te({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:[]}]})(t)}function Ze(t){return te({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:[]}]})(t)}function oi(t){return te({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:[]}]})(t)}function ci(t){return te({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:[]}]})(t)}function di(t){return te({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:[]}]})(t)}function ui(t){return te({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:[]}]})(t)}function _t(t){return te({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:[]}]})(t)}function kt(t){return te({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:[]}]})(t)}function pi(t){return te({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:[]}]})(t)}function mi(t){return te({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:[]}]})(t)}function hi(t){return te({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:[]}]})(t)}function gi(t){return te({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:[]}]})(t)}function fs(t){return te({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:[]}]})(t)}function ht(t){return te({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:[]}]})(t)}function et(t){return te({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:[]}]})(t)}function Ys(t){return te({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:[]}]})(t)}function Js(t){return te({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:[]}]})(t)}function At(t){return te({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:[]}]})(t)}function Ft(t){return te({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:[]}]})(t)}function Xs(t){return te({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:[]}]})(t)}function qt(t){return te({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:[]}]})(t)}function rt(t){return te({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:[]}]})(t)}function fi(t){return te({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:[]}]})(t)}function Zs(t){return te({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:[]}]})(t)}function xi(t){return te({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:[]}]})(t)}function en(t){return te({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:[]}]})(t)}function tn(t){return te({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:[]}]})(t)}function ot(t){return te({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:[]}]})(t)}function bt(t){return te({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:[]}]})(t)}function We(t){return te({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:[]}]})(t)}function ct(t){return te({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:[]}]})(t)}function vi(t){return te({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:[]}]})(t)}function Ct(t){return te({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:[]}]})(t)}function yi(t){return te({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:[]}]})(t)}function sn(t){return te({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:[]}]})(t)}function nn(t){return te({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:[]}]})(t)}function ki(t){return te({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:[]}]})(t)}function bi(t){return te({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:[]}]})(t)}function ji(t){return t.map(s=>s.kind==="package"?`pi update npm:${s.name}`:`npm i -g ${s.name}@latest`).join("; ")}function He(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let i=0;i<16;i++)t[i]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function Ue({trigger:t,open:s,onOpenChange:i,children:r,align:c="right",fit:a=!1,direction:n="down",menuClassName:o,menuRef:d,menuStyle:p}){const f=l.useRef(null);return l.useEffect(()=>{if(!s)return;const h=y=>{f.current&&!f.current.contains(y.target)&&i(!1)},g=y=>{y.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",h),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",g)}},[s,i]),e.jsxs("div",{className:`dropdown ${c} ${a?"fit":""} ${n==="up"?"dd-up":""}`,ref:f,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>i(!s),"aria-expanded":s,children:[t,e.jsx(We,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:d,style:p,children:r})]})}function Re({active:t,disabled:s=!1,title:i,onClick:r,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:i,onClick:r,children:c})}const an="pi-web-ui:lang",wi={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",collapsePanel:"收起面板",expandPanel:"展开面板",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",engineBadge:"引擎",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",cacheHit:"缓存命中",cacheHitTip:"缓存读取 {read} · 缓存写入 {write} · 未命中 {miss}(共 {input} 输入 token)",tps:"t/s",rateTip:"实时生成速率(估算)",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:"智能体正在工作中…回车插队发送,或点「排队」等回答结束后发送",placeholderIdle:"给 pi 发送消息 — Enter 发送,/ 查看命令",placeholderConnecting:"正在连接服务器…",stopAgent:"停止智能体",stop:"停止",bgTasks:"后台任务",bgTasksTip:"AI 在后台启动的服务(npm run dev & 等)——可逐个停止或全部关闭,对话结束后仍保留",bgTasksEmpty:"暂无后台任务",bgTasksDesc:"AI 运行中启动并仍在监听的进程(按监听端口检测)",bgTaskPort:"端口",bgTaskPid:"PID",bgTaskSince:"启动",bgTaskStop:"停止",bgTaskStopAll:"全部关闭",bgTaskRefresh:"刷新",bgTaskJustNow:"刚刚",bgTaskMinutes:"{n} 分钟前",bgTaskHours:"{n} 小时前",bgTaskDays:"{n} 天前",stopBash:"停止",stopBashTip:"停止正在运行的 bash 命令(对话继续)",supplement:"排队",supplementTip:"加入队列:AI 回答完全结束后才发送(不打断)",queueSteerTag:"插队",queueFollowTag:"排队",queueRemoveTip:"移除此排队消息",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",subagentBadge:"子代理",subagentTitle:"子代理 · {title}",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",dismissConversation:"从运行列表移出(历史记录保留)",dismissConversationConfirm:"确认移出",collapseSection:"折叠",expandSection:"展开",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",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)。",updatesAllTitle:"全部组件更新",updatesAllBadge:"{n} 个更新",updatesAllUpToDate:"全部组件均为最新",kindWebUi:"Web 界面",kindPiCore:"核心",kindPackage:"组件",updatesAllRefresh:"重新检查全部",updateCheckFailed:"检查失败",updateBtn:"更新",updateAllBtn:"全部更新",updatePkgTabTitle:"更新 {name}",updateAllTabTitle:"更新全部组件",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",fileNotFoundShort:"文件不存在",pluginMountFailed:"插件 {name} 挂载失败",liveOutputOmitted:`…[前 {n} 字符已省略]…
3
3
  `,uploadToFolder:"上传文件到此文件夹",uploadToCurrentDir:"上传文件到当前目录",protocolMismatch:"页面版本与服务器不一致(应用刚更新过),请刷新页面以恢复全部功能。",selectLinesHint:"点击选择行;拖拽或 Shift+点击选择范围",enableWrap:"开启自动换行",disableWrap:"关闭自动换行",selectedRange:"已选 {n} 行(第 {start}-{end} 行)",fileLines:"{n} 行",selectAll:"全选",clearSelection:"清除",addToChat:"添加到对话",addedToChat:"已添加",previewTruncated:"⚠ 文件过大,仅预览前 512KB",previewLinesTruncated:"… 文件行数过多,仅显示前 {n} 行",binaryFile:"🔣 二进制文件,已显示前 4KB 十六进制",binaryHexTruncated:"(文件更大,可下载完整文件)",previewNotSupported:"该类型文件不支持预览(仅图片 / 视频 / 文本)",emptyFile:"(空文件)",editFile:"编辑文件",exitEditFile:"退出编辑",saveFile:"保存文件",discardFileChanges:"放弃未保存的修改?",fileSaved:"已保存",fileEditTruncated:"文件过大,预览不完整,无法编辑",showMarkdownSource:"显示 Markdown 原文",showMarkdownPreview:"显示 Markdown 预览",fullscreen:"全屏",exitFullscreen:"退出全屏",zoomIn:"放大字号",zoomOut:"缩小字号",resetZoom:"重置缩放",pluginRequest:"插件请求",modelQuestion:"模型提问",modelQuestionCustom:"补充回答(可选)",modelQuestionSubmit:"提交回答",noOptions:"(无选项)",inputPlaceholder:"输入内容",questionTimeout:"⏳ 剩余 {s} 秒,超时将自动取消",questionTimeoutExpired:"提问已超时,正在恢复对话…",modelNoVision:"当前模型 {name} 不支持图片,请切换到 DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH 引擎使用运行时内置技能(dsh-skill),暂不支持在设置面板启停",dshExtensionsNote:"DSH 引擎无 pi 扩展体系,能力由运行时内置(MCP/subagent/goal/plan/skill 等)",dshReviewPromptNote:"DSH 无独立审查会话:此指令将随目标轮次附加到系统提示词,供模型在目标轮次中遵守",dshVisionHiddenNote:"DSH 引擎直接支持图片输入(仅 DeepSeek V4 Flash Vision (exp) 模型),无需视觉桥转写",dshNoReviewModel:"DSH 无独立审查模型:目标由模型自判定完成/受阻,轮次上限即自动迭代次数",soundHeader:"声音提示",enableSound:"启用声音",preview:"试听",volume:"音量","sound.question":"问卷弹出","sound.question.desc":"ask_user_question 出现时","sound.done":"回复结束","sound.done.desc":"智能体完成一轮回答时","sound.start":"回复开始","sound.start.desc":"智能体开始新一轮时","sound.error":"出错","sound.error.desc":"出现错误提示时",setupTitle:"未检测到 pi agent 配置",setupDesc:"pi-web-ui 需要 pi 的配置目录(~/.pi/agent)和至少一个 API 密钥才能运行智能体。pi 内置了 openai、anthropic、deepseek 等服务商——选一个填密钥即可,全程无需打开终端。",installFailed:"✖ pi agent 安装失败:",retryInstall:"重试安装",skip:"跳过",installDone:"✅ pi agent CLI 已安装。选择服务商并填入 API 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:搜索历史对话全文(含 AI 回复)、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
4
4
 
@@ -320,4 +320,4 @@ Avoid three test anti-patterns: tests coupled to the implementation, tautologica
320
320
  `)}function za(t,s){let i=0,r=t.indexOf(s);for(;r!==-1;)i++,r=t.indexOf(s,r+s.length);return i}function Va(t,s,i,r){const c=new Map,a=i.toLowerCase();if(!a)return c;for(const n of t){if(!s.has(n.id))continue;const o=za(qa(n,r).toLowerCase(),a);o>0&&c.set(n.id,o)}return c}function Ga(t,s){var a;const i=[],r=s.toLowerCase();if(!r)return i;const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(n){const o=n.parentElement;return!o||o.closest(".search-bar")||o.closest(".msg-collapsed")?NodeFilter.FILTER_REJECT:(n.textContent??"").toLowerCase().includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let n=c.nextNode();n;n=c.nextNode()){const o=(n.textContent??"").toLowerCase();if(!((a=n.parentElement)!=null&&a.closest("[data-msg-id]")))continue;let d=o.indexOf(r);for(;d!==-1;){const p=document.createRange();p.setStart(n,d),p.setEnd(n,d+r.length),i.push(p),d=o.indexOf(r,d+r.length)}}return i}function Qa(t,s,i,r,c){var d;const a=Va(i,r,s,c),n=new Map;for(const p of Ga(t,s)){const f=(d=p.startContainer.parentElement)==null?void 0:d.closest("[data-msg-id]");if(!(f!=null&&f.dataset.msgId))continue;const h=n.get(f.dataset.msgId);h?h.push(p):n.set(f.dataset.msgId,[p])}const o=[];for(const p of i){const f=n.get(p.id);if(f)for(let g=0;g<f.length;g++)o.push({kind:"dom",range:f[g],msgId:p.id,k:g});const h=a.get(p.id);if(h)for(let g=0;g<h;g++)o.push({kind:"folded",msgId:p.id,k:g})}return o}function Rt(t,s){return t.findIndex(i=>i.msgId===s.msgId&&i.k===s.k)}function Be(t,s){const i=CSS;if(!i.highlights)return;if(s.length===0){i.highlights.delete(t);return}const r=window.Highlight;r&&i.highlights.set(t,new r(...s))}function Ya(t,s){const i=[];let r=t;for(;r&&r!==s;){const c=getComputedStyle(r);/(auto|scroll|hidden)/.test(c.overflowY+c.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&i.push(r),r=r.parentElement}return i}function Ja(t,s){const i=s.startContainer.parentElement;for(const o of Ya(i,t)){const d=s.getBoundingClientRect(),p=o.getBoundingClientRect();if(d.height<=0||d.width<=0)return;d.top>=p.top+4&&d.bottom<=p.bottom-4||(o.scrollTop+=d.top-p.top-(o.clientHeight-d.height)/2),d.left>=p.left+4&&d.right<=p.right-4||(o.scrollLeft+=d.left-p.left-(o.clientWidth-d.width)/2)}const r=s.getBoundingClientRect(),c=t.getBoundingClientRect();if(r.height<=0||r.width<=0)return;const a=r.top>=c.top+6&&r.bottom<=c.bottom-6,n=r.left>=c.left+6&&r.right<=c.right-6;a&&n||(a||(t.scrollTop+=r.top-c.top-(c.height-r.height)/2),n||(t.scrollLeft+=r.left-c.left-(c.width-r.width)/2))}function Xa({containerRef:t,messages:s,collapsedIds:i,toolResults:r,onExpand:c,onProgrammaticScroll:a,open:n,onClose:o}){const d=me(),p=l.useRef(null),[f,h]=l.useState(""),[g,y]=l.useState(null),[C,L]=l.useState(0),[,O]=l.useState(0),j=l.useDeferredValue(f),b=n?j.trim():"",X=l.useRef(null);X.current=g;const q=l.useRef([]),J=l.useRef({key:null}),z=l.useRef("");l.useEffect(()=>{n&&(y(null),requestAnimationFrame(()=>{var x;return(x=p.current)==null?void 0:x.select()}))},[n]),l.useEffect(()=>{if(!n)return;const x=_=>{_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),o())};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[n,o]),l.useEffect(()=>(n||(Be("msg-search",[]),Be("msg-search-active",[])),()=>{Be("msg-search",[]),Be("msg-search-active",[])}),[n]),l.useLayoutEffect(()=>{const x=()=>{L(0),y(null),O(0),q.current=[],Be("msg-search",[]),Be("msg-search-active",[]),J.current={key:null},z.current=""};if(!n||!b){x();return}const _=t.current;if(!_)return;let A=!1,D=0;return D=requestAnimationFrame(()=>{var ue,v;if(A)return;const M=Qa(_,b,s,i,r);q.current=M;const K=M.length;if(L(K),K===0){y(null),O(0),Be("msg-search",[]),Be("msg-search-active",[]),J.current={key:null},z.current=b;return}const W=X.current;let k;if(W){if(k=Rt(M,W),k===-1){const B=[];for(let u=0;u<M.length;u++)M[u].msgId===W.msgId&&B.push(u);if(B.length>0){const u=Math.min(W.k,B.length-1);k=B[u]}else k=0}}else k=0;k<0&&(k=0),k>=K&&(k=K-1),(!W||W.msgId!==M[k].msgId||W.k!==M[k].k)&&y({msgId:M[k].msgId,k:M[k].k}),O(k);const S=M[k],w=J.current,U=((ue=w.key)==null?void 0:ue.msgId)!==S.msgId||((v=w.key)==null?void 0:v.k)!==S.k||w.kind==="folded"&&S.kind==="dom"||b!==z.current;J.current={key:{msgId:S.msgId,k:S.k},kind:S.kind},z.current=b;const G=M.filter(B=>B.kind==="dom").map(B=>B.range);if(Be("msg-search",G),S.kind==="folded"){Be("msg-search-active",[]),U&&c(S.msgId);return}Be("msg-search-active",[S.range]),U&&(a==null||a(),Ja(_,S.range))}),()=>{A=!0,cancelAnimationFrame(D)}},[n,b,s,t,g,i,r,c,a]);const E=l.useCallback(x=>{const _=q.current,A=_.length;if(A===0)return;const D=X.current,M=D?Rt(_,D):0,K=_[(M+x+A)%A];y(K.kind==="dom"||K.kind==="folded"?{msgId:K.msgId,k:K.k}:null)},[]);if(!n)return null;const H=g?(()=>{const x=Rt(q.current,g);return x===-1?0:x})():0;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:p,className:"search-input",type:"text",value:f,placeholder:d("searchPlaceholder"),onChange:x=>{h(x.target.value)},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),E(x.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${C===0?"empty":""}`,children:C===0?d("searchNoResults"):`${Math.min(H+1,C)}/${C}`}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchPrev"),disabled:C===0,onClick:()=>E(-1),children:e.jsx(ot,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchNext"),disabled:C===0,onClick:()=>E(1),children:e.jsx(We,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchClose"),onClick:o,children:e.jsx(Ee,{})})]})}function Za(t){const{dSt:s,dSh:i,escaped:r,graceActive:c,stuck:a}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:i<0?{flipEscape:!1,reassert:a&&!r}:{flipEscape:!0,reassert:!1}}const bn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],jn="pi-web-ui:prompt-templates";function er(){try{const t=localStorage.getItem(jn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(i=>!!i&&typeof i=="object"&&typeof i.id=="string"):[]}catch{return[]}}function Ms(t){return bn.some(s=>s.id===t)}function pt(t){return typeof t.title=="string"}const wn=l.createContext(null);function Nn(){const t=l.useContext(wn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function tr({send:t,children:s}){const i=me(),[r,c]=l.useState(er),[a,n]=l.useState(!1),[o,d]=l.useState(null),[p,f]=l.useState(!1),[h,g]=l.useState(!1),[y,C]=l.useState(!1);l.useEffect(()=>{try{localStorage.setItem(jn,JSON.stringify(r))}catch{}},[r]);const L=l.useMemo(()=>{const M=new Map,K=new Set;for(const S of r)S.hidden?K.add(S.id):(pt(S)&&!Ms(S.id)||pt(S))&&M.set(S.id,S);const W=bn.filter(S=>!K.has(S.id)).map(S=>{const w=M.get(S.id);return{id:S.id,icon:(w==null?void 0:w.icon)??S.icon,title:(w==null?void 0:w.title)??i(S.titleKey),desc:(w==null?void 0:w.desc)??i(S.descKey),prompt:(w==null?void 0:w.prompt)??i(S.promptKey),builtin:!0}}),k=r.filter(S=>pt(S)&&!Ms(S.id)).map(S=>({id:S.id,icon:S.icon??"📌",title:S.title??"",desc:S.desc??"",prompt:S.prompt??""}));return[...W,...k]},[r,i]),O=l.useCallback(()=>n(!0),[]),j=l.useCallback(M=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:M}))},[]),b=l.useCallback((M,K=!1)=>{C(K),M?(f(!1),d({...M})):(f(!0),d({id:He(),icon:"📌",title:"",desc:"",prompt:""}))},[]),X=l.useCallback(()=>{n(!1),d(null),C(!1)},[]),q=l.useCallback(()=>{h?(c([]),g(!1)):(g(!0),setTimeout(()=>g(!1),5e3))},[h]),J=l.useCallback(M=>{n(!1),j(M.prompt)},[j]),z=l.useCallback(M=>{n(!1),b(M,!0)},[b]),E=l.useCallback(()=>{n(!1),b(void 0,!0)},[b]),H=l.useCallback(M=>{c(K=>{const W=K.findIndex(k=>k.id===M.id);if(W>=0){const k=[...K];return k[W]=M,k}return[...K,M]}),d(null),y&&(n(!0),C(!1))},[y]),x=l.useCallback(M=>{c(K=>M.builtin?[...K.filter(k=>k.id!==M.id),{id:M.id,hidden:!0}]:K.filter(W=>W.id!==M.id)),d(null),y&&(n(!0),C(!1))},[y]),_=l.useCallback(M=>{c(K=>K.filter(W=>W.id!==M.id||W.hidden)),d(null),y&&(n(!0),C(!1))},[y]),A=l.useMemo(()=>({templates:L,fill:j,openPicker:O,openEdit:b,resetConfirm:h,toggleReset:q}),[L,j,O,b,h,q]),D=o?r.some(M=>M.id===o.id&&!M.hidden&&pt(M)):!1;return e.jsxs(wn.Provider,{value:A,children:[s,a&&e.jsx(nr,{templates:L,resetConfirm:h,onFill:J,onEditTpl:z,onNew:E,onResetToggle:q,onClose:X}),o&&e.jsx(ir,{editing:o,isNew:p,hasOverride:D,onDraft:d,onSave:H,onRestore:()=>_(o),onRemove:()=>x(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),X()},onSend:()=>{const M=o.prompt.trim();M&&t({type:"prompt",text:M,queue:!1})&&X()},onClose:X})]})}function sr(){const t=me(),{templates:s,fill:i,openEdit:r,toggleReset:c,resetConfirm:a}=Nn();return e.jsxs("div",{className:"empty-templates",children:[e.jsxs("div",{className:"empty-templates-head",children:[e.jsx("span",{className:"empty-templates-title",children:t("tpl.title")}),e.jsx("span",{className:"empty-templates-hint",children:t("tpl.hint")})]}),e.jsxs("div",{className:"empty-templates-grid",children:[s.map(n=>e.jsx(Cn,{tpl:n,title:t("tpl.clickCard"),onFill:()=>i(n.prompt),onEdit:()=>r(n),editTitle:t("tpl.editTpl")},n.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>r(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Ae,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(Qs,{}),t(a?"tpl.resetConfirm":"tpl.reset")]})})]})}function Cn({tpl:t,title:s,onFill:i,onEdit:r,editTitle:c}){const a=me();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:i,children:[e.jsx("span",{className:"empty-template-icon",children:t.icon}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t.title}),e.jsx("span",{className:"empty-template-desc",children:t.desc})]}),e.jsx("span",{className:"template-card-ops",role:"button",title:c??a("tpl.editTpl"),onClick:n=>{n.stopPropagation(),r()},children:e.jsx(Xs,{})})]})}function nr({templates:t,resetConfirm:s,onFill:i,onEditTpl:r,onNew:c,onResetToggle:a,onClose:n}){const o=me();return l.useEffect(()=>{const d=p=>{p.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal template-picker",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"template-picker-head",children:[e.jsx("span",{className:"template-picker-title",children:o("tpl.pickerTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:o("close"),onClick:n,children:e.jsx(Ee,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(d=>e.jsx(Cn,{tpl:d,title:o("tpl.clickCard"),onFill:()=>i(d),onEdit:()=>r(d),editTitle:o("tpl.editTpl")},d.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:c,title:o("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Ae,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:a,children:[e.jsx(Qs,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function ir({editing:t,isNew:s,hasOverride:i,onDraft:r,onSave:c,onRestore:a,onRemove:n,onFill:o,onSend:d,onClose:p}){const f=me(),h=l.useRef(null);l.useEffect(()=>{const C=L=>{L.key==="Escape"&&p()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[p]),l.useEffect(()=>{const C=h.current;if(!C)return;C.style.height="auto";const L=C.scrollHeight>300;C.style.height=`${Math.min(C.scrollHeight,300)}px`,C.style.overflowY=L?"auto":"hidden"},[t.prompt]);const g=()=>{const C=t.title.trim(),L=t.prompt.trim();if(!C||!L){r({...t,error:f("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:C,desc:t.desc.trim(),prompt:L})},y=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:p,children:e.jsxs("div",{className:"modal template-modal",onClick:C=>C.stopPropagation(),children:[e.jsxs("div",{className:"template-modal-head",children:[e.jsx("span",{className:"template-modal-icon",children:t.icon}),e.jsx("span",{className:"template-modal-badge",children:f(y?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:f(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:f("close"),onClick:p,children:e.jsx(Ee,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:f("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:C=>r({...t,icon:C.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:f("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:f("tpl.fieldTitlePh"),onChange:C=>r({...t,title:C.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:f("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:f("tpl.fieldDescPh"),onChange:C=>r({...t,desc:C.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:f("tpl.fieldPrompt")}),e.jsx("textarea",{ref:h,className:"template-field-prompt",value:t.prompt,placeholder:f("tpl.fieldPromptPh"),onChange:C=>r({...t,prompt:C.target.value})})]}),t.error&&e.jsx("div",{className:"template-error",children:t.error}),e.jsxs("div",{className:"template-modal-actions",children:[e.jsxs("div",{className:"template-modal-actions-left",children:[!s&&y&&i&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:f("tpl.restoreTip"),onClick:a,children:f("tpl.restore")}),!s&&y&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:f("tpl.removeTip"),onClick:n,children:[e.jsx(_e,{})," ",f("tpl.remove")]}),!s&&!y&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:f("tpl.deleteTip"),onClick:n,children:[e.jsx(_e,{})," ",f("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:g,children:f("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:f("tpl.fillTip"),children:f("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:d,title:f("tpl.sendTip"),children:[e.jsx(Gs,{})," ",f("tpl.sendNow")]})]})]})]})})}const Rs=new Map,ar=15,Is=30,It=250,Ls=1200,rr=1600;function Ds(t){return t.content.some(s=>s.type==="toolCall")}function lr({state:t,liveOutputs:s,toolStatuses:i,onEdit:r,onKillBash:c,onRemoveQueued:a,thinkingWrap:n,toolsWrap:o,jumpTarget:d,onJumpDone:p}){const f=me(),h=l.useRef(null),[g,y]=l.useState(!0),C=l.useRef(!0),L=l.useRef(0),O=l.useRef(0),j=l.useRef(!1),b=l.useRef(0),[X,q]=l.useState(()=>new Set),[J,z]=l.useState(!1),E=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,H=l.useMemo(()=>{const T=new Map;for(const $ of t.messages)$.role==="toolResult"&&$.toolCallId&&T.set($.toolCallId,$);return T},[t.messages]),x=l.useMemo(()=>Da(t.messages),[t.messages]),_=E.length>0?E[E.length-1].id:null,A=t.messages.length>Is?Math.max(0,t.messages.length-ar):0,D=l.useMemo(()=>{const T=new Set;for(let $=0;$<A;$++){const re=t.messages[$];re.role!=="toolResult"&&(X.has(re.id)||T.add(re.id))}return T},[t.messages,A,X]),[M,K]=l.useState(()=>new Set),[W,k]=l.useState(()=>new Set),S=l.useRef(new Map),w=l.useRef(new Map),U=l.useRef(new Map),G=l.useRef(0),ue=l.useMemo(()=>{const T=new Map;for(const $ of t.messages)T.set($.id,Ka($));return T},[t.messages]),v=l.useRef(ue);v.current=ue;const B=l.useRef(M);B.current=M;const u=t.messages.length>Is&&!J,P=l.useRef(u);P.current=u;const R=Oa(t.messages,S.current,rr),V=l.useRef(R);V.current=R;const se=l.useCallback(()=>{const T=h.current;if(!T)return;if(!P.current){K(ke=>ke.size?new Set:ke);return}const $=T.getBoundingClientRect(),re={top:$.top-Ls,bottom:$.bottom+Ls},le=[];for(const[ke,Se]of U.current){const Fe=Se.getBoundingClientRect();le.push({id:ke,top:Fe.top,bottom:Fe.bottom}),B.current.has(ke)||ge(ke,Fe.bottom-Fe.top,v.current.get(ke))}const ye=Fa(le,re,V.current,B.current);for(const ke of ye.hide){const Se=U.current.get(ke);Se&&ge(ke,Se.offsetHeight,v.current.get(ke))}K(ke=>$a(ke,ye))},[]),Z=l.useCallback(()=>{G.current||(G.current=requestAnimationFrame(()=>{G.current=0,se()}))},[se]);l.useLayoutEffect(()=>{se()},[se]);const ae=l.useRef(J);l.useLayoutEffect(()=>{ae.current&&!J&&se(),ae.current=J},[J,se]);const ge=l.useCallback((T,$,re)=>{re!==void 0&&(w.current.set(T,{h:$,len:re}),S.current.set(T,$))},[]),fe=l.useCallback((T,$)=>{ge(T,$,v.current.get(T))},[ge]),N=l.useCallback(T=>{T&&U.current.set(T.dataset.lazyId??"",T)},[]);l.useEffect(()=>{const T=new Set(t.messages.map($=>$.id));for(const $ of U.current.keys())T.has($)||(U.current.delete($),S.current.delete($),w.current.delete($));K($=>{let re=!1;const le=new Set;for(const ye of $)T.has(ye)?le.add(ye):re=!0;return re?le:$})},[t.messages,X]),l.useEffect(()=>()=>cancelAnimationFrame(G.current),[]);const Q=l.useMemo(()=>{const T=[];for(const $ of t.messages){if($.role!=="user")continue;const re=$.content.map(ke=>{var Se;return((Se=lt(ke))==null?void 0:Se.text)??""}).filter(Boolean).join(" "),le=Vt(re),ye=le?le.userMessage??`skill:${le.name}`:re.trim();ye&&T.push({id:$.id,text:ye})}return T},[t.messages]),ve=l.useMemo(()=>{const T=new Map;return Q.forEach(($,re)=>T.set($.id,re)),T},[Q]),[Y,ne]=l.useState(-1),he=l.useRef(-1),m=l.useRef(Q);l.useEffect(()=>{m.current=Q},[Q]);const ie=l.useCallback(()=>{const T=h.current,$=m.current;if(!T||$.length===0)return;const re=T.getBoundingClientRect().top,le=140;let ye=-1;for(let ke=0;ke<$.length;ke++){const Se=T.querySelector(`[data-msg-id="${$[ke].id}"]`);if(Se)if(Se.getBoundingClientRect().top<=re+le)ye=ke;else break}ye!==he.current&&(he.current=ye,ne(ye))},[]);l.useEffect(()=>{ie()},[Q,ie]);const de=l.useCallback(T=>{q($=>$.has(T)?$:new Set($).add(T))},[]);l.useEffect(()=>{const T=$=>{if(!($.ctrlKey||$.metaKey)||$.key.toLowerCase()!=="f")return;const re=$.target;re&&(re.tagName==="INPUT"||re.tagName==="TEXTAREA"||re.isContentEditable)||($.preventDefault(),z(!0))};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const Pe=l.useCallback(T=>{q($=>{if(!$.has(T))return $;const re=new Set($);return re.delete(T),re})},[]),Te=l.useCallback(T=>{const $=t.messages.findIndex(le=>le.id===T);ca.flushSync(()=>{$>=0&&$<A&&!X.has(T)&&de(T),k(le=>le.has(T)?le:new Set(le).add(T))});const re=m.current.findIndex(le=>le.id===T);he.current=re,ne(re),requestAnimationFrame(()=>{var ye,ke,Se;const le=(ye=h.current)==null?void 0:ye.querySelector(`[data-msg-id="${T}"]`);le&&((ke=h.current)==null||ke.querySelectorAll(".msg-flash").forEach(Fe=>Fe.classList.remove("msg-flash")),le.scrollIntoView({block:"start"}),le.classList.remove("msg-flash"),le.offsetWidth,le.classList.add("msg-flash"),le!==((Se=h.current)==null?void 0:Se.lastElementChild)&&(j.current=!0))})},[t.messages,A,X,de]),Me=l.useMemo(()=>{var T;return d?((T=t.messages.find($=>$.role===d.role&&$.timestamp===d.timestamp))==null?void 0:T.id)??null:null},[t.messages,d]);l.useEffect(()=>{if(d){if(Me){Te(Me),p==null||p();return}t.sessionFile===d.path&&t.messages.length>0&&(p==null||p())}},[Me,Te,p,d,t.sessionFile,t.messages.length]);const Ie=l.useCallback(()=>{const T=h.current;if(!T)return;const $=T.scrollTop-L.current,re=T.scrollHeight-O.current;L.current=T.scrollTop,O.current=T.scrollHeight;const le=T.scrollHeight-T.scrollTop-T.clientHeight<80,ye=Date.now()<b.current,ke=Za({dSt:$,dSh:re,escaped:j.current,graceActive:ye,stuck:C.current});ke.reassert&&(b.current=Date.now()+It,T.scrollTop=T.scrollHeight),ke.flipEscape&&(j.current=!0),le&&$>=0&&(j.current=!1),ye||($<0?C.current=le&&!j.current:le&&(C.current=!0)),y(C.current),ie(),Z()},[ie,Z]),Le=l.useRef(!1);l.useEffect(()=>{const T=Le.current;if(Le.current=!!t.isStreaming,T&&!t.isStreaming&&!j.current){const $=()=>{const le=h.current;le&&!j.current&&(le.scrollTop=le.scrollHeight,C.current=!0,y(!0))};requestAnimationFrame(()=>requestAnimationFrame($));const re=setTimeout($,180);return()=>clearTimeout(re)}},[t.isStreaming]),l.useEffect(()=>{const T=h.current;T&&C.current&&(T.scrollTop=T.scrollHeight)},[E,t.isStreaming,s]);const ze=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");l.useEffect(()=>{const T=h.current;T&&C.current&&(T.scrollTop=T.scrollHeight)},[ze]),l.useEffect(()=>{const T=h.current;if(!T||typeof ResizeObserver>"u")return;const $=new ResizeObserver(()=>{C.current&&!j.current&&(T.scrollTop=T.scrollHeight,y(!0))});return $.observe(T),()=>$.disconnect()},[]),l.useEffect(()=>{const T=h.current;if(!T||typeof MutationObserver>"u")return;let $=!1;const re=new MutationObserver(()=>{$||($=!0,requestAnimationFrame(()=>{$=!1;const le=h.current;le&&C.current&&!j.current&&(le.scrollTop=le.scrollHeight,y(!0))}))});return re.observe(T,{childList:!0,subtree:!0,characterData:!0}),()=>re.disconnect()},[]);const Ve=l.useCallback(()=>{if(!h.current)return;C.current=!0,j.current=!1,y(!0),b.current=Date.now()+It;const $=()=>{const re=h.current;!re||!C.current||j.current||(b.current=Date.now()+It,re.scrollTop=re.scrollHeight)};$(),requestAnimationFrame(()=>requestAnimationFrame($)),setTimeout($,120),setTimeout($,300),setTimeout($,600)},[]),I=l.useRef(null);l.useEffect(()=>{const T=I.current,$=h.current;if(!T||!$)return;const re=le=>{le.preventDefault();const ye=T.querySelector(".qn-list");if(ye&&ye.contains(le.target)&&ye.scrollHeight>ye.clientHeight){ye.scrollTop+=le.deltaY;return}$.scrollTop+=le.deltaY};return T.addEventListener("wheel",re,{passive:!1}),()=>T.removeEventListener("wheel",re)},[]);const[pe,ce]=l.useState(0);l.useEffect(()=>{const T=()=>{var $;ce((($=h.current)==null?void 0:$.clientHeight)??0),Z()};return T(),window.addEventListener("resize",T),()=>window.removeEventListener("resize",T)},[Z]);const je=Q.length,xe=l.useMemo(()=>je===0?27:Math.max(4,Math.min(27,Math.floor(((pe||600)-16)/je)-3)),[je,pe]),Ce=xe<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${J||g?"":" anchor-live"}`,ref:h,onScroll:Ie,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(sr,{})}),t.messages.map((T,$)=>{const re=$<A,le=re&&X.has(T.id);if(re&&!le)return T.role==="toolResult"?null:e.jsx(Ba,{message:T,onExpand:de},T.id);const ye=T.role==="user"?ve.get(T.id):void 0,ke=!u||R.has(T.id)||W.has(T.id)||!M.has(T.id);return e.jsx(Aa,{id:T.id,show:ke,height:Ua(T.id,ue.get(T.id)??-1,w.current,kn(T.role,T.customType)),containerRef:h,onMeasured:fe,lazyRef:N,children:e.jsx(Ss,{message:T,qnIndex:ye,qnActive:ye!==void 0?ye===Y:void 0,onJump:Te,toolResults:H,liveOutputs:Ds(T)?s:Rs,toolStatuses:i,streaming:t.isStreaming,onKillBash:c,toolsWrap:o,thinkingWrap:n,isLast:T.id===_,onEdit:r,questionAttachments:x.get(T.id),onCollapse:le?Pe:void 0,searchActive:J},T.id)},T.id)}),t.streamingMessage&&e.jsx(Ss,{message:t.streamingMessage,toolResults:H,liveOutputs:Ds(t.streamingMessage)?s:Rs,toolStatuses:i,streaming:!0,isLast:!0,onEdit:r,onKillBash:c,toolsWrap:o,thinkingWrap:n,searchActive:J},t.streamingMessage.id),t.isStreaming&&E.length===0&&e.jsx("div",{className:"streaming-wait",children:f("waitingResponse")}),t.queue.steering.map((T,$)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:f("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:T}),a&&e.jsx("button",{type:"button",className:"queued-remove",title:f("queueRemoveTip"),onClick:()=>a("steer",T),children:"✕"})]})},`q-steer-${$}`)),t.queue.followUp.map((T,$)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:f("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:T}),a&&e.jsx("button",{type:"button",className:"queued-remove",title:f("queueRemoveTip"),onClick:()=>a("followUp",T),children:"✕"})]})},`q-fu-${$}`))]}),!g&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Ve,children:[e.jsx(nn,{})," ",f("backToBottom")]}),e.jsx(Xa,{containerRef:h,messages:E,collapsedIds:D,toolResults:H,onExpand:de,onProgrammaticScroll:()=>{j.current=!0,C.current=!1,y(!1)},open:J,onClose:()=>z(!1)}),Q.length>0&&e.jsxs("div",{className:`qn-rail ${Ce?"many":""}`,ref:I,"aria-label":f("questionNavTitle"),style:{"--rail-gap":`${xe}px`},children:[Q.map((T,$)=>e.jsx("button",{type:"button",className:`qn-bar ${$===Y?"active":""}`,"aria-label":`${$+1}. ${T.text}`,onClick:()=>Te(T.id),children:e.jsxs("span",{className:"qn-bar-text",children:[$+1,". ",T.text]})},T.id)),Ce&&e.jsx("div",{className:"qn-list",children:Q.map((T,$)=>e.jsxs("button",{type:"button",className:`qn-list-item ${$===Y?"active":""}`,"aria-label":`${$+1}. ${T.text}`,onClick:()=>Te(T.id),children:[e.jsx("span",{className:"qn-list-idx",children:$+1}),e.jsx("span",{className:"qn-list-text",children:T.text})]},T.id))})]})]})}const Sn="pi-web-model-usage";function or(t){if(!t||typeof t!="object")return{};const s={};for(const[i,r]of Object.entries(t)){const c=typeof r=="number"?Math.floor(r):0;Number.isFinite(c)&&c>0&&(s[i]=c)}return s}function cr(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function dr(t,s){const i=s;return t.map((r,c)=>({m:r,i:c,count:i[r.id]??0})).sort((r,c)=>c.count-r.count||r.i-c.i).map(r=>r.m)}function Tn(){try{const t=localStorage.getItem(Sn);return t?or(JSON.parse(t)):{}}catch{return{}}}function ur(t){try{localStorage.setItem(Sn,JSON.stringify(t))}catch{}}function pr(t){const s=cr(Tn(),t);return ur(s),s}const mr=["off","minimal","low","medium","high","xhigh","max"],hr=l.memo(function({state:s,models:i,modelsLoading:r,send:c,onManageModels:a,providerKeys:n,compact:o=!1}){const d=me(),p=s==null?void 0:s.model,f=p?`${p.provider}/${p.id}`:null,[h,g]=l.useState(!1),[y,C]=l.useState(!1),[L,O]=l.useState(""),[j,b]=l.useState(null),[X,q]=l.useState({}),J=l.useRef(null),z=l.useRef(null),[E,H]=l.useState(null);l.useEffect(()=>{if(!h){H(null);return}if(i.length===0)return;const w=requestAnimationFrame(()=>{const U=z.current;U&&H(U.offsetWidth)});return()=>cancelAnimationFrame(w)},[h,i.length]),l.useEffect(()=>{h&&q(Tn())},[h]),l.useEffect(()=>{h||(O(""),b(null))},[h]);const x=l.useMemo(()=>{const w=new Map;for(const G of i)w.set(G.provider,(w.get(G.provider)??0)+1);const U=[];for(const[G,ue]of[...w.entries()].sort((v,B)=>v[0].localeCompare(B[0]))){const v=n[G];if(v&&v.length>1)for(const B of v)U.push({provider:G,keyName:B.name,count:ue});else U.push({provider:G,keyName:null,count:ue})}return U},[i,n]),_=l.useMemo(()=>dr(i,X),[i,X]),A=l.useMemo(()=>{let w=_;j&&(w=w.filter(G=>G.provider===j.provider));const U=L.trim().toLowerCase();return U?w.filter(G=>G.name.toLowerCase().includes(U)||G.provider.toLowerCase().includes(U)||G.id.toLowerCase().includes(U)):w},[_,L,j]),D=l.useMemo(()=>{const w=[];for(const U of A){const G=n[U.provider];if(!G||G.length<=1){w.push({model:U,key:null});continue}let ue=G.find(v=>v.active)??G[0];if((j==null?void 0:j.provider)===U.provider&&j.keyName){const v=G.find(B=>B.name===j.keyName);v&&(ue=v)}w.push({model:U,key:ue})}return w},[A,n,j]),[M,K]=l.useState(!1),W=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,k=mr.map(w=>({value:w,label:d(`thinking.${w}`),supported:W?W.has(w):!0})),S=w=>{var U;return((U=k.find(G=>G.value===w))==null?void 0:U.label)??w};return l.useEffect(()=>{h&&i.length===0&&!M&&!r&&(K(!0),c({type:"list_models"}))},[h,i.length,M,r,c]),l.useEffect(()=>{i.length>0&&K(!1)},[i.length]),l.useEffect(()=>{var U;if(!h)return;const w=(U=J.current)==null?void 0:U.querySelector(".dd-item.active");w==null||w.scrollIntoView({block:"nearest"})},[h,f,i.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Ue,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx("span",{className:"chip-model",children:p?p.name:d("selectModel")}),!o&&(p==null?void 0:p.vision)&&e.jsx("span",{className:"chip-vision",title:d("vision"),children:"🖼"}),!o&&p&&e.jsx("span",{className:"chip-sub",children:p.provider})]}),open:h,onOpenChange:g,menuClassName:"dd-menu-model",menuRef:z,menuStyle:E!=null?{width:E}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:d("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(yt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:d("searchModels"),value:L,onChange:w=>O(w.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[x.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:d("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${j===null?"active":""}`,onClick:()=>b(null),children:e.jsx("span",{children:d("allProviders")})}),x.map(w=>{const U=(j==null?void 0:j.provider)===w.provider&&(j==null?void 0:j.keyName)===w.keyName;return e.jsxs("button",{type:"button",className:`dd-provider-item ${U?"active":""}`,onClick:()=>b(U?null:{provider:w.provider,keyName:w.keyName}),title:w.keyName?`${w.provider} · ${w.keyName}`:`${w.provider} · ${w.count}`,children:[e.jsxs("span",{className:"dd-provider-txt",children:[e.jsx("span",{className:"dd-provider-name",children:w.provider}),w.keyName&&e.jsx("span",{className:"dd-provider-key",children:w.keyName})]}),e.jsx("span",{className:"dd-provider-count",children:w.count})]},w.keyName?`${w.provider}::${w.keyName}`:w.provider)})]}),e.jsxs("div",{className:"dd-model-scroll",ref:J,children:[(M||r)&&e.jsx("div",{className:"dd-loading",children:d("loading")}),i.length===0&&!M&&!r&&e.jsx("div",{className:"dd-loading",children:d("noModels")}),A.length===0&&i.length>0&&e.jsx("div",{className:"dd-loading",children:d("noModelMatches")}),D.map(w=>{const U=w.model,G=f===U.id&&(!w.key||w.key.active);return e.jsx(Re,{active:G,onClick:()=>{w.key&&!w.key.active&&c({type:"activate_provider_key",provider:U.provider,keyName:w.key.name}),f!==U.id&&c({type:"set_model",modelId:U.id}),g(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:U.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:U.provider}),w.key&&e.jsxs("span",{className:`dd-model-key ${w.key.active?"active":""}`,children:[w.key.active?"●":"○"," ",w.key.name]}),(X[U.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:d("modelUsedCount",{n:X[U.id]})}),(U.reasoning||U.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[U.reasoning&&e.jsx("span",{className:"dd-model-badge",children:d("reasoning")}),U.vision&&e.jsx("span",{className:"dd-model-badge",children:d("vision")})]})]})]})},w.key?`${U.id}::${w.key.name}`:U.id)})]})]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:d("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{g(!1),a()},children:d("manageModels")})]})]}),e.jsxs(Ue,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(mt,{}),e.jsx("span",{className:"chip-sub",children:d("thinkingChip",{level:s?S(s.thinkingLevel):"—"})})]}),open:y,onOpenChange:C,direction:"up",children:[e.jsx("div",{className:"dd-header",children:d("thinkingLevel")}),k.map(w=>e.jsx(Re,{active:(s==null?void 0:s.thinkingLevel)===w.value,disabled:!w.supported,title:w.supported?void 0:d("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==w.value&&c({type:"set_thinking",level:w.value}),C(!1)},children:w.label},w.value))]})]})}),gr=l.memo(function({ready:s,streaming:i,messages:r,slashCommands:c,modelState:a,models:n,modelsLoading:o,send:d,attachments:p,onRemoveAttachment:f,onAddImageFiles:h,onAddLocalFiles:g,onNotice:y,onSent:C,onManageModels:L,providerKeys:O}){const j=me(),{locale:b}=dt(),{openPicker:X}=Nn(),q=N=>b==="en"&&N.descriptionEn?N.descriptionEn:N.description??"",J=N=>b==="en"&&N.argumentHintEn?N.argumentHintEn:N.argumentHint??"",[z,E]=l.useState(""),[H,x]=l.useState(!1),[_,A]=l.useState(null),[D,M]=l.useState(0),[K,W]=l.useState(!1),[k,S]=l.useState(void 0),w=l.useRef(null),U=l.useRef(null),G=l.useRef(null),ue={builtin:j("slashBuiltin"),extension:j("slashExtension"),prompt:j("slashPrompt"),skill:j("slashSkill"),plugin:j("slashPlugin")},v=N=>{const Q=N.match(/^\/([^\s]*)$/);if(Q&&s){const ve=Q[1].toLowerCase(),Y=c.filter(ne=>ne.name.toLowerCase().startsWith(ve));A(Y.length>0?Y:null),M(0)}else A(null)};l.useEffect(()=>{var Q;const N=(Q=G.current)==null?void 0:Q.querySelector(".slash-item.active");N==null||N.scrollIntoView({block:"nearest"})},[D,_]);const B=N=>{var he;const Q=_??[],ve=N??Q[D%Math.max(Q.length,1)];if(!ve){A(null);return}const Y=z.match(/^\/([^\s]*)([\s\S]*)$/),ne=Y?Y[2]:"";E(`/${ve.name} ${ne}`),A(null),(he=w.current)==null||he.focus()},u=async()=>{const Q=[...r].reverse().find(Y=>Y.role==="assistant"&&Y.content.some(ne=>ne.type==="text"&&ne.text)),ve=Q==null?void 0:Q.content.filter(Y=>Y.type==="text").map(Y=>Y.text).join(`
321
321
  `);if(!ve){y("warning",j("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(ve),y("info",j("slashCopied"))}catch{y("error",j("slashCopyFailed"))}},P=N=>{if(!N||N.length===0){y("warning",j("foldersNotSupported"));return}const Q=Array.from(N).filter(ne=>Oe(ne.type)),ve=Array.from(N).filter(ne=>!Oe(ne.type)),Y=V();Q.length>0&&Y?y("warning",Y):Q.length>0&&h(Q),ve.length>0&&g(ve)},R=N=>{var ne;const Q=(ne=N.clipboardData)==null?void 0:ne.items;if(!Q)return;const ve=[];for(const he of Q)if(he.kind==="file"&&Oe(he.type)){const m=he.getAsFile();m&&ve.push(m)}if(ve.length===0)return;N.preventDefault();const Y=V();if(Y){y("warning",Y);return}h(ve)},V=()=>{const N=a==null?void 0:a.model;if(!(N!=null&&N.id))return null;const Q=n.find(ve=>ve.id===N.id);return Q&&Q.vision===!1?j("modelNoVision",{name:Q.name}):null},se=s,Z=l.useRef(z);l.useEffect(()=>{Z.current=z},[z]),l.useEffect(()=>{v(Z.current)},[c]),l.useEffect(()=>{const N=Q=>{var Y;const ve=Q.detail;E(ve),(Y=w.current)==null||Y.focus()};return window.addEventListener("pi-web:fill",N),()=>window.removeEventListener("pi-web:fill",N)},[]),l.useEffect(()=>{if(!K)return;const N=Q=>{Q.key==="Escape"&&W(!1)};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[K]),l.useEffect(()=>{const N=w.current;if(!N)return;N.style.height="auto";const Q=N.scrollHeight>220;N.style.height=`${Math.min(N.scrollHeight,220)}px`,N.style.overflowY=Q?"auto":"hidden"},[z]);const ae=(N=!1)=>{var Y,ne,he,m,ie;const Q=z.trim(),ve=p.some(de=>de.imageData||de.fileData);if(!(!se||!Q&&!ve)){if(Q==="/help"){const de=(ne=(Y=w.current)==null?void 0:Y.closest(".inputbox"))==null?void 0:ne.getBoundingClientRect();S(de==null?void 0:de.width),W(!0),E(""),(he=w.current)==null||he.focus();return}if(Q==="/copy"){E(""),(m=w.current)==null||m.focus(),u();return}if(d({type:"prompt",text:Q,queue:N,attachments:p.map(de=>de.imageData?{path:"",imageData:de.imageData,mimeType:de.mimeType,name:de.name}:de.fileData?{path:"",fileData:de.fileData,mimeType:de.mimeType,name:de.name,size:de.size}:{path:de.path,mode:de.mode,...de.lines?{lines:de.lines}:{}})})){E(""),C();const de=a==null?void 0:a.model;de&&pr(`${de.provider}/${de.id}`),(ie=w.current)==null||ie.focus()}}},ge=N=>{if(!N.nativeEvent.isComposing){if(_&&_.length>0)switch(N.key){case"ArrowDown":N.preventDefault(),M(Q=>(Q+1)%_.length);return;case"ArrowUp":N.preventDefault(),M(Q=>(Q-1+_.length)%_.length);return;case"Tab":case"Enter":N.preventDefault(),B();return;case"Escape":N.preventDefault(),A(null);return}N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),ae())}},fe=()=>e.jsx("div",{className:"inputbox-actions",children:i?e.jsxs(e.Fragment,{children:[z.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:j("supplementTip"),onClick:()=>ae(!0),children:[e.jsx(Gs,{})," ",j("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:j("stopAgent"),onClick:()=>d({type:"abort"}),children:e.jsx(xt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:j("sendTip"),disabled:!se||!z.trim()&&!p.some(N=>N.imageData||N.fileData),onClick:()=>ae(),children:e.jsx(sn,{})})});return e.jsxs("div",{className:`inputbar${H?" drop-active":""}`,onDragOver:N=>{N.preventDefault(),N.stopPropagation(),x(!0)},onDragLeave:N=>{N.currentTarget.contains(N.relatedTarget)||x(!1)},onDrop:N=>{var Q;N.preventDefault(),N.stopPropagation(),x(!1),P(((Q=N.dataTransfer)==null?void 0:Q.files)??null)},children:[H&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",j("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(N=>e.jsxs("span",{className:`attach-chip ${N.imageData?"image":N.fileData?"file":N.mode}`,title:N.imageData?j("attachImage",{name:N.name}):N.fileData?j("attachFile",{name:N.name}):N.isDir?j("folderRef",{path:N.path}):N.mode==="reference"?j("refOnly",{path:N.path}):N.mode==="lines"&&N.lines?j("attachLines",{path:N.path,start:N.lines.start,end:N.lines.end}):j("attachContent",{path:N.path}),children:[N.imageData?"🖼":N.fileData?"📄":N.isDir?"📁":N.mode==="reference"?"🔗":"📎"," ",N.name,N.mode==="lines"&&N.lines&&e.jsxs("span",{className:"attach-range",children:["L",N.lines.start,"-",N.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:j("removeAttachment"),onClick:()=>f(N.key??N.path),children:"×"})]},N.key??`${N.path}|${N.mode}|${N.lines?`${N.lines.start}-${N.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:j("attachHint")})]}),_&&_.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:G,"aria-label":j("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:j("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>A(null),children:"Esc"})]}),_.map((N,Q)=>e.jsxs("button",{type:"button",className:`slash-item${Q===D?" active":""}`,onMouseEnter:()=>M(Q),onClick:()=>B(N),children:[e.jsxs("span",{className:"slash-name",children:["/",N.name]}),e.jsx("span",{className:`slash-source ${N.source}`,children:ue[N.source]}),e.jsxs("span",{className:"slash-desc",children:[q(N),N.argumentHint&&e.jsx("span",{className:"slash-hint",children:J(N)})]})]},N.name))]}),K&&e.jsx("div",{className:"modal-backdrop",onClick:()=>W(!1),children:e.jsxs("div",{className:"slash-help",style:k?{width:k}:void 0,onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",j("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>W(!1),children:j("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:j("slashLoading")}):c.map(N=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",N.name]}),e.jsx("span",{className:`slash-source ${N.source}`,children:ue[N.source]}),e.jsxs("span",{className:"slash-help-desc",children:[q(N),N.argumentHint&&e.jsx("span",{className:"slash-hint",children:J(N)})]})]},N.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,onChange:N=>{P(N.target.files),N.target.value=""}}),e.jsx("textarea",{ref:w,value:z,rows:1,placeholder:j(se?i?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!se,onChange:N=>{E(N.target.value),v(N.target.value)},onKeyDown:ge,onPaste:R}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:j("uploadFile"),disabled:!se,onClick:()=>{var N;return(N=U.current)==null?void 0:N.click()},children:e.jsx(ai,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:j("tpl.openPicker"),onClick:X,children:e.jsx(hi,{})}),e.jsx(hr,{state:a,models:n,modelsLoading:o,send:d,onManageModels:L,providerKeys:O,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:fe()})]})]})]})}),fr=l.memo(function({goal:s,models:i,modelsLoading:r,activeConversationId:c,engine:a,send:n}){var k,S,w,U,G,ue,v;const o=me(),{locale:d}=dt(),p=d==="en"&&s.statusEn?s.statusEn:s.status||"",f=d==="en"&&((k=s.wizard)!=null&&k.statusEn)?s.wizard.statusEn:((S=s.wizard)==null?void 0:S.status)||"",h=a==="dsh",g=!s.conversationId||s.conversationId===c,y=s.goal!==null&&g,[C,L]=l.useState(""),[O,j]=l.useState(s.reviewModel??""),[b,X]=l.useState(s.maxRounds),[q,J]=l.useState(s.locked),[z,E]=l.useState(!1),[H,x]=l.useState(!1),[_,A]=l.useState(!0);l.useEffect(()=>{j(s.reviewModel??""),X(s.maxRounds||0),J(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),l.useEffect(()=>{z&&i.length===0&&!H&&!r&&(x(!0),n({type:"list_models"}))},[z,i.length,H,r,n]),l.useEffect(()=>{i.length>0&&x(!1)},[i.length]);const D=()=>{var B;return O?((B=i.find(u=>u.id===O))==null?void 0:B.name)??O:o("goalBarUseMainModel")},M=()=>{const B=C.trim();B&&(n({type:"set_goal",goal:B,...O?{reviewModel:O}:{},maxRounds:b,locked:q}),L(""),A(!1))},K=()=>{const B=C.trim();B&&(n({type:"start_goal_wizard",text:B,...O?{wizardModel:O}:{},maxRounds:b,locked:q}),L(""),A(!1))},W=(((w=s.wizard)==null?void 0:w.active)??!1)&&g;return W?e.jsx("div",{className:`goalbar goalbar-active ${W?"wizard":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx("span",{className:"goalbar-spin",children:"🔍"})}),e.jsxs("span",{className:"goalbar-text",title:((U=s.wizard)==null?void 0:U.draft)??"",children:[o("goalWizardRunning"),": ",(G=s.wizard)==null?void 0:G.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarRound",{n:(((ue=s.wizard)==null?void 0:ue.step)??0)+1})," / ",((v=s.wizard)==null?void 0:v.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:f||o("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),onClick:()=>{n({type:"clear_goal"}),A(!0)},children:e.jsx(Ee,{})})]})}):y?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarReviewing")," ",o("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?o("goalBarPassed"):s.verdict==="fail"?o("goalBarFailed"):`${o("goalBarRound",{n:s.round||1})} · ${s.locked?o("goalBarLocked"):o("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:p}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),disabled:s.reviewing,onClick:()=>{n({type:"clear_goal"}),A(!0)},children:e.jsx(Ee,{})})]})}):_?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:o("goalBarPlaceholder"),onClick:()=>A(!1),children:[e.jsx(hs,{})," ",e.jsx("span",{children:o("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(hs,{})}),e.jsx("input",{className:"goalbar-input",value:C,placeholder:o("goalBarPlaceholder"),onChange:B=>L(B.target.value),onKeyDown:B=>{B.key==="Enter"&&M()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!C.trim(),onClick:M,children:o("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!C.trim(),title:o("goalWizardTip"),onClick:K,children:["🔍 ",o("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o(q?"goalBarLocked":"goalBarUnlocked"),onClick:()=>J(B=>(n({type:"set_goal_prefs",locked:!B}),!B)),children:q?e.jsx(ui,{}):e.jsx(ti,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o("goalBarClear"),onClick:()=>A(!0),children:e.jsx(ot,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[h?e.jsx("p",{className:"goalbar-dsh-note",children:o("dshNoReviewModel")}):e.jsxs(Ue,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[o("goalBarReviewModel"),": ",e.jsx("b",{children:D()})]}),open:z,onOpenChange:E,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("goalBarReviewModel")}),(H||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!H&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),e.jsx(Re,{active:O==="",onClick:()=>{j(""),E(!1),n({type:"set_goal_prefs",reviewModel:""})},children:o("goalBarUseMainModel")}),i.map(B=>e.jsx(Re,{active:O===B.id,onClick:()=>{j(B.id),E(!1),n({type:"set_goal_prefs",reviewModel:B.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:B.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:B.provider})})]})},B.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>n({type:"list_models"}),children:o("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:o("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:o("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:b,placeholder:o("goalBarUnlimitedShort"),onChange:B=>{const u=parseInt(B.target.value,10);if(Number.isNaN(u)||u<0){X(0);return}X(u)},onBlur:()=>n({type:"set_goal_prefs",maxRounds:b}),onKeyDown:B=>{B.key==="Enter"&&(n({type:"set_goal_prefs",maxRounds:b}),B.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:o(q?"goalBarLocked":"goalBarUnlocked")})]})]})});function xr(t){const s=Math.max(0,t.input??0),i=Math.max(0,t.cacheRead??0),r=Math.max(0,t.cacheWrite??0),c=s+i+r;return{totalInput:c,miss:s,read:i,write:r,hitRate:c>0?Math.min(i/c,1):0,writeRate:c>0?Math.min(r/c,1):0}}const En=2e3;function vr(t,s,i=En){return t.filter(r=>s-r.t<=i)}function yr(t,s=En){if(t.length<2)return 0;const i=t[t.length-1],r=t.find(a=>a.t>=i.t-s)??t[0],c=(i.t-r.t)/1e3;return c<=0?0:Math.max(0,(i.out-r.out)/c)}function Bs(t){if(!t)return 0;let s=0;for(let r=0;r<t.length;r++){const c=t.charCodeAt(r);(c>=12352&&c<=12543||c>=13312&&c<=19903||c>=19968&&c<=40959||c>=63744&&c<=64255||c>=65280&&c<=65519||c===12288)&&s++}const i=t.length-s;return Math.round(s+i/4)}function kr(t){let s=0;for(const i of t)i.type==="text"&&typeof i.text=="string"&&i.text?s+=Bs(i.text):i.type==="thinking"&&typeof i.thinking=="string"&&i.thinking&&(s+=Bs(i.thinking));return s}function br({chat:t,send:s}){const i=me(),r=t.state,[c,a]=l.useState(!1),[n,o]=l.useState(""),[d,p]=l.useState(0),f=l.useRef(null),h=t.pathCompletions;l.useEffect(()=>{if(!c)return;const k=setTimeout(()=>{s({type:"complete_path",path:n})},150);return()=>clearTimeout(k)},[n,c,s]),l.useEffect(()=>p(0),[h]),l.useEffect(()=>{const k=document.querySelector(`.status-completions .pc-item[data-idx="${d}"]`);k==null||k.scrollIntoView({block:"nearest"})},[d]);const g=l.useRef([]),y=(r==null?void 0:r.isStreaming)??!1,C=r!=null&&r.streamingMessage?kr(r.streamingMessage.content):0;if(l.useEffect(()=>{if(!y){g.current=[];return}const k=Date.now(),S=g.current,w=S[S.length-1];w&&k-w.t<250||(g.current=vr([...S,{t:k,out:C}],k))},[y,C]),!r)return null;const L=r.stats,O=xr(L.tokens),j=O.hitRate*100,b=O.totalInput===0?"":O.hitRate>=.7?"ok":O.hitRate>=.4?"mid":"warn",X=O.totalInput>0?`${j.toFixed(1)}%`:"—",q=y?yr(g.current):0,J=t.ready?"ok":"busy",z=t.ready?i("connected"):i("connecting"),E=L.contextUsage,H=E.tokens!==null&&E.percent!==null?`${Qe(E.tokens)} / ${Qe(E.contextWindow)}`:"—",x=E.percent??null,_=x===null?"":x>=80?"warn":x>=50?"mid":"ok",A=r.queue.steering.length+r.queue.followUp.length,D=()=>{o(r.cwd),a(!0)},M=(k,S)=>{var U;const w=k.includes("\\")?"\\":"/";o(S?`${k}${w}`:k),p(0),(U=f.current)==null||U.focus()},K=k=>{const S=k.trim();S&&S!==r.cwd&&s({type:"set_cwd",path:S}),a(!1)},W=k=>{if(k.key==="ArrowDown")k.preventDefault(),p(S=>Math.min(S+1,h.length-1));else if(k.key==="ArrowUp")k.preventDefault(),p(S=>Math.max(S-1,0));else if(k.key==="Tab"&&h.length>0){k.preventDefault();const S=h[Math.min(d,h.length-1)];M(S.path,S.type==="dir")}else if(k.key==="Enter"&&!k.nativeEvent.isComposing){const S=n.trim();if(S.endsWith("/")||S.endsWith("\\"))K(S);else if(h.some(w=>w.path===S))K(S);else if(h.length>0&&h[d]){k.preventDefault();const w=h[d];M(w.path,w.type==="dir")}else K(S)}else k.key==="Escape"&&(h.length>0?(k.stopPropagation(),s({type:"complete_path",path:""})):a(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${J}`,title:z}),e.jsx("span",{className:"status-item",children:z}),e.jsx("span",{className:"status-sep",children:"·"}),t.engine&&t.engine!=="pi"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`status-item engine-badge engine-${t.engine}`,title:`${i("engineBadge")}: ${t.engine}`,children:t.engine==="dsh"?"DSH":t.engine}),e.jsx("span",{className:"status-sep",children:"·"})]}),e.jsxs("span",{className:"status-item status-ctx",title:i("contextUsage"),children:[i("context"),e.jsx("span",{className:`ctx-bar ${_}`,children:x!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(x,100)}%`}})}),H]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("cumulativeCost"),children:["$",jr(L.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-cache",title:i("cacheHitTip",{read:Qe(O.read),write:Qe(O.write),miss:Qe(O.miss),input:Qe(O.totalInput)}),children:[i("cacheHit"),e.jsx("b",{className:`cache-pct ${b}`,children:X})]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("sessionMessages"),children:[i("messages")," ",L.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:i("pluginStatus"),children:t.statuses.map(k=>k.text).join(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),i("working"),A>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",A," ",i("queued")]})]}),e.jsx("span",{className:"status-item status-rate",title:i("rateTip"),children:q>0?`${Math.round(q)}${i("tps")}`:"…"})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:f,className:"status-cwd-input",value:n,autoFocus:!0,placeholder:i("enterPath"),onChange:k=>o(k.target.value),onKeyDown:W,onBlur:()=>a(!1)}),h.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:k=>k.preventDefault(),children:h.map((k,S)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":S,className:`pc-item ${S===d?"sel":""}`,onMouseEnter:()=>p(S),onClick:()=>M(k.path,k.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:k.type==="dir"?e.jsx(et,{}):e.jsx(Ys,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:k.name}),e.jsx("span",{className:"pc-path",children:k.path})]})]})},k.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:i("cwdTip",{path:r.cwd}),onClick:D,children:["📁 ",r.cwd]})]})}function Qe(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function jr(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function wr({dialog:t,send:s}){const i=me(),[r,c]=l.useState(""),[a,n]=l.useState(0),o=f=>{s({type:"dialog_response",id:t.id,value:f})};l.useEffect(()=>{c(""),n(0);const f=h=>{h.key==="Escape"&&o(null)};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t.id]);const d=Array.isArray(t.args[0])?t.args[0]:[],p=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("pluginRequest")}),t.title&&t.title!==i("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[d.map((f,h)=>e.jsx("button",{type:"button",className:`dialog-option ${h===a?"sel":""}`,onMouseEnter:()=>n(h),onClick:()=>o(f),children:f},h)),d.length===0&&e.jsx("div",{className:"dialog-hint",children:i("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:p}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:i("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:r,placeholder:p||i("inputPlaceholder"),autoFocus:!0,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&o(r)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(r),children:i("ok")})]})]})]})}function Nr({question:t,send:s}){const i=me(),[r,c]=l.useState({}),[a,n]=l.useState({}),[o,d]=l.useState(()=>t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1);l.useEffect(()=>{c({}),n({}),d(t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1)},[t.id,t.deadline]),l.useEffect(()=>{if(!t.deadline)return;const g=setInterval(()=>{d(y=>{const C=Math.max(0,Math.ceil((t.deadline-Date.now())/1e3));return C<=0&&y>0&&s({type:"question_answer",id:t.id,answers:[],cancelled:!0}),C})},1e3);return()=>clearInterval(g)},[t.id,t.deadline]);const p=g=>{if(g){s({type:"question_answer",id:t.id,answers:[],cancelled:!0});return}const y=t.questions.map(C=>{const L=r[C.id]??[],O=(a[C.id]??"").trim();return{id:C.id,selected:L,...O?{custom:O}:{}}});s({type:"question_answer",id:t.id,answers:y})};l.useEffect(()=>{const g=y=>{y.key==="Escape"&&p(!0)};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t.id]);const f=(g,y,C)=>{c(L=>{const O=L[g]??[];return C?{...L,[g]:O.includes(y)?O.filter(j=>j!==y):[...O,y]}:{...L,[g]:[y]}})},h=t.questions.every(g=>{var y;return(((y=r[g.id])==null?void 0:y.length)??0)>0||(a[g.id]??"").trim()!==""});return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":"select",children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("modelQuestion")}),o>=0&&e.jsx("span",{className:"question-timer",children:o>0?i("questionTimeout",{s:o}):i("questionTimeoutExpired")}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>p(!0),children:"✕"})]}),t.questions.map((g,y)=>{var C;return e.jsxs("div",{className:"set-section",children:[e.jsx("div",{className:"set-section-title",children:g.header??`${i("modelQuestion")} ${y+1}`}),e.jsx("p",{className:"set-row-desc",children:g.question}),g.detail&&e.jsx("p",{className:"set-hint",children:g.detail}),(((C=g.options)==null?void 0:C.length)??0)>0&&e.jsx("div",{className:"set-list",children:g.options.map(L=>{const O=(r[g.id]??[]).includes(L.label);return e.jsxs("button",{type:"button",className:`set-row question-option${O?" active":""}`,onClick:()=>f(g.id,L.label,!!g.multiSelect),children:[e.jsxs("span",{className:"set-row-name",children:[g.multiSelect?O?"☑ ":"☐ ":O?"● ":"○ ",L.label]}),L.description&&e.jsx("span",{className:"set-row-desc",children:L.description})]},L.label)})}),e.jsx("input",{className:"set-prompt-input question-custom",placeholder:i("modelQuestionCustom"),value:a[g.id]??"",onChange:L=>n(O=>({...O,[g.id]:L.target.value}))})]},g.id)}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"dialog-submit",disabled:!h,onClick:()=>p(!1),children:i("modelQuestionSubmit")}),e.jsx("button",{type:"button",className:"dialog-dismiss-inline",onClick:()=>p(!0),children:i("cancel")})]})]})}const _s=t=>`'${t.replace(/'/g,"'\\''")}'`;function Cr(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",i=t.y!==" "&&t.y!=="?";return s&&i?"both":s?"staged":"unstaged"}function Sr({chat:t,send:s,terminal:i,active:r,onSwitchToTerminal:c}){var ze,Ve;const a=me(),[n,o]=l.useState(null),[d,p]=l.useState([]),[f,h]=l.useState(""),[g,y]=l.useState(new Map),[C,L]=l.useState("changes"),[O,j]=l.useState([]),[b,X]=l.useState(null),[q,J]=l.useState(""),[z,E]=l.useState(!1),[H,x]=l.useState(null),[_,A]=l.useState(null),[D,M]=l.useState(!1),[K,W]=l.useState(!1),[k,S]=l.useState(!1),[w,U]=l.useState(null),[G,ue]=l.useState(!1),[v,B]=l.useState(""),u=l.useRef(0),P=l.useRef(-1),R=l.useRef(-1),V=l.useRef(-1),se=l.useRef(-1),Z=l.useRef(void 0),ae=l.useRef(null),ge=l.useRef([]),fe=l.useCallback(I=>{if(I.reqId===P.current){if(P.current=-1,W(!1),U(null),!I.ok){U(I.error??a("scmQueryFailedShort"));return}if(I.notRepo){ue(!0),o(null),p([]),y(new Map),j([]),X(null),J(""),A(null);return}ue(!1);const pe={branch:I.branch??"",detached:!!I.detached,upstream:I.upstream??null,ahead:I.ahead??0,behind:I.behind??0,upstreamGone:!!I.upstreamGone,files:(I.files??[]).map(xe=>({...xe}))},ce=(I.branches??[]).map(xe=>({...xe})),je=new Map;for(const[xe,Ce]of Object.entries(I.stats??{}))je.set(xe,{add:Ce[0],del:Ce[1]});o(pe),p(ce),y(je),h(xe=>{var Ce;return pe.detached?xe||"":pe.branch&&ce.some(T=>T.name===pe.branch)?pe.branch:xe&&ce.some(T=>T.name===xe)?xe:((Ce=ce[0])==null?void 0:Ce.name)??""}),A(xe=>xe&&!pe.files.some(Ce=>Ce.path===xe.file.path)?null:xe)}else if(I.reqId===R.current){if(R.current=-1,M(!1),!I.ok){U(I.error??a("scmQueryFailedShort"));return}const pe=ae.current;if(!pe)return;A({file:pe,staged:I.stagedText??"",worktree:I.worktreeText??"",untracked:!1})}else if(I.reqId===se.current){if(se.current=-1,S(!1),!I.ok){U(I.error??a("scmQueryFailedShort"));return}j((I.history??[]).map(pe=>({...pe})))}else if(I.reqId===V.current){if(V.current=-1,E(!1),!I.ok){U(I.error??a("scmQueryFailedShort"));return}J(I.text??"")}},[]);l.useEffect(()=>{const I=t.scmData;I&&I.type==="scm_data"&&fe(I)},[t.scmData,fe]);const N=l.useCallback((I,pe)=>{if(!t.ready||t.status!=="open")return!1;const ce=++u.current;return s({...I,reqId:ce})?(pe.current=ce,!0):(u.current-=1,!1)},[t.ready,t.status,s]),Q=l.useCallback((I=!1,pe=!1)=>{var ce;!t.ready||t.status!=="open"||(ce=t.state)!=null&&ce.cwd&&(Z.current!==void 0&&Z.current!==t.state.cwd&&(o(null),p([]),y(new Map),j([]),S(!1),se.current=-1,X(null),J(""),A(null),x(null)),Z.current=t.state.cwd,U(null),N({type:"scm_status"},P)&&(pe||W(!0)))},[t.ready,(ze=t.state)==null?void 0:ze.cwd,t.status,N]),ve=l.useCallback(I=>{if(x(I),X(null),ae.current=I,I.x==="?"&&I.y==="?"){A({file:I,staged:"",worktree:"",untracked:!0});return}M(!0),U(null),N({type:"scm_filediff",path:I.path},R)||M(!1)},[N]),Y=l.useCallback(I=>{X(I),x(null),A(null),J(""),E(!0),U(null),N({type:"scm_commit",hash:I.hash},V)||E(!1)},[N]),ne=l.useCallback((I,pe)=>{var Ce,T;if(!t.ready)return;const ce={name:I,command:pe,cwd:"${pwd}"};let je;const xe=t.terminals.find($=>$.title===I);xe?(i.restart(xe.id),s({type:"run_command",terminalId:xe.id,conversationId:xe.conversationId,command:ce,cols:80,rows:24}),je=xe.id):(je=He(),i.create({id:je,conversationId:t.activeConversationId||((Ce=t.state)==null?void 0:Ce.conversationId)||"",title:I,cwd:((T=t.state)==null?void 0:T.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ce})),i.select(je),c()},[t.ready,(Ve=t.state)==null?void 0:Ve.cwd,t.terminals,c,s,i]),he=l.useCallback(()=>{const I=v.trim();if(!I||G)return;const pe=I.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ne("git commit",`git add -A && git commit -m "${pe}"`),B("")},[v,G,ne]),m=l.useCallback(I=>{G||ne("git add",`git add -- ${_s(I.path)}`)},[G,ne]),ie=l.useCallback(I=>{G||ne("git reset",`git reset HEAD -- ${_s(I.path)}`)},[G,ne]),de=l.useCallback(()=>{if(!f||G)return;const I=d.find(pe=>pe.name===f);if(I!=null&&I.remote&&typeof I.remote=="string"){const pe=f.slice(I.remote.length+1);ne("git checkout",`git checkout -b ${pe} ${f} || git checkout ${f}`)}else ne("git checkout",`git checkout ${f}`)},[f,d,G,ne]),Pe=l.useCallback(()=>ne("git push","git push"),[ne]),Te=l.useCallback(()=>ne("git pull","git pull"),[ne]),Me=l.useCallback(()=>{N({type:"scm_history"},se)||(se.current=-1)},[N]);l.useEffect(()=>{r&&Q()},[r,Q]),l.useEffect(()=>{C==="history"&&n&&Me()},[C,n,Me]),l.useEffect(()=>{t.scmDirty>0&&r&&Q(!1,!0)},[t.scmDirty]),l.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const I=setInterval(()=>{document.visibilityState!=="hidden"&&Q(!1,!0)},3e4);return()=>clearInterval(I)},[r,t.ready,t.status,Q]),l.useEffect(()=>{const I=ge.current;if(ge.current=t.terminals,!r)return;t.terminals.some(ce=>{var xe;return ce.running!==!1?!1:((xe=I.find(Ce=>Ce.id===ce.id))==null?void 0:xe.running)===!0&&ce.title.startsWith("git ")})&&t.ready&&t.status==="open"&&(Q(!1,!0),C==="history"&&n&&Me())},[t.terminals,r,t.ready,t.status,Q,C,n,Me]);const Ie={staged:a("scmStaged"),unstaged:a("scmUnstaged"),untracked:a("scmUntracked"),both:a("scmStagedUnstaged")},Le=I=>{const pe=I.split(`
322
322
  `);return e.jsx("pre",{className:"scm-diff-pre",children:pe.map((ce,je)=>{let xe="";return ce.startsWith("diff --git")||ce.startsWith("index ")||ce.startsWith("new file")||ce.startsWith("deleted file")||ce.startsWith("old mode")||ce.startsWith("new mode")||ce.startsWith("similarity index")||ce.startsWith("rename ")||ce.startsWith("copy ")||ce.startsWith("Binary files")||ce.startsWith("---")||ce.startsWith("+++")?xe="hdr":ce.startsWith("@@")?xe="hunk":ce.startsWith("+")?xe="add":ce.startsWith("-")&&(xe="del"),e.jsx("div",{className:`scm-diff-line ${xe}`,children:ce||" "},je)})})};return e.jsxs("div",{className:"scm-view",children:[e.jsxs("div",{className:"scm-header",children:[e.jsxs("div",{className:"scm-title-row",children:[e.jsxs("span",{className:"scm-title",children:[e.jsx(ht,{}),a("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":C==="changes",className:C==="changes"?"active":"",onClick:()=>{L("changes"),U(null)},children:a("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":C==="history",className:C==="history"?"active":"",onClick:()=>{L("history"),U(null)},children:a("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:a("scmRefreshTip"),disabled:K,onClick:()=>Q(!0),children:e.jsx(at,{className:K?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:a("scmCurrentBranch"),children:[e.jsx(ht,{}),n?n.detached?a("scmDetached"):n.branch:"…",(n==null?void 0:n.upstream)&&e.jsx("span",{className:"scm-upstream",children:n.upstreamGone?a("scmUpstreamGone"):n.ahead>0||n.behind>0?a("scmAheadBehind",{ahead:n.ahead,behind:n.behind}):n.upstream})]}),e.jsxs("select",{className:"scm-select",value:f,disabled:G||d.length===0,title:a("scmSwitchBranch"),onChange:I=>h(I.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:a("scmSelectBranch")}),d.filter(I=>!I.remote).map(I=>e.jsx("option",{value:I.name,children:I.current?`* ${I.name}`:I.name},I.name)),d.some(I=>I.remote)&&e.jsx("optgroup",{label:a("scmRemoteBranches"),children:d.filter(I=>I.remote).map(I=>e.jsx("option",{value:I.name,children:I.name},I.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!f||f===(n==null?void 0:n.branch)||G,title:a("scmSwitchBranchTip",{branch:f}),onClick:de,children:[e.jsx(ht,{}),a("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||G,title:a("scmPushTip"),onClick:Pe,children:[e.jsx(sn,{}),a("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||G,title:a("scmPullTip"),onClick:Te,children:[e.jsx(nn,{}),a("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:v,placeholder:a("scmCommitPlaceholder"),disabled:G,onChange:I=>B(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!I.nativeEvent.isComposing&&he()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!v.trim()||G,title:a("scmCommitTip"),onClick:he,children:[e.jsx(ct,{}),a("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[C==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:a("scmHistory")}),O.length>0&&e.jsx("span",{className:"scm-files-count",children:O.length})]}),e.jsx("div",{className:"scm-history-list",children:G?e.jsx("div",{className:"scm-empty",children:a("scmNotGitRepo")}):!n||k?e.jsx("div",{className:"scm-empty",children:t.status==="open"?a("scmLoading"):a("scmConnecting")}):O.length===0?e.jsx("div",{className:"scm-empty",children:a("scmNoHistory")}):O.map(I=>e.jsxs("button",{type:"button",className:`scm-commit ${(b==null?void 0:b.hash)===I.hash?"active":""}`,onClick:()=>Y(I),title:I.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:I.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:I.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[I.shortHash," · ",I.author," · ",I.date]}),I.decorations&&e.jsx("span",{className:"scm-commit-refs",children:I.decorations})]})]},I.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:a("scmChanges")}),n&&n.files.length>0&&e.jsx("span",{className:"scm-files-count",children:n.files.length})]}),e.jsx("div",{className:"scm-files-list",children:G?e.jsx("div",{className:"scm-empty",children:a("scmNotGitRepo")}):n?n.files.length===0?e.jsx("div",{className:"scm-empty",children:a("scmNoChanges")}):n.files.map(I=>{const pe=Cr(I),ce=g.get(I.path);return e.jsxs("div",{className:`scm-file ${(H==null?void 0:H.path)===I.path?"active":""}`,title:Ie[pe],onClick:()=>ve(I),children:[e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"x"}`,children:I.x!==" "?I.x:" "}),e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"y"}`,children:I.y!==" "?I.y:" "}),e.jsx("span",{className:"scm-file-path",children:I.path}),ce&&(ce.add>0||ce.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[ce.add>0&&e.jsxs("span",{className:"add",children:["+",ce.add]}),ce.del>0&&e.jsxs("span",{className:"del",children:["-",ce.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(I.y!==" "||pe==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:a("scmStageTip",{path:I.path}),onClick:je=>{je.stopPropagation(),m(I)},children:"+"}),pe==="staged"||pe==="both"?e.jsx("button",{type:"button",className:"scm-act",title:a("scmUnstageTip",{path:I.path}),onClick:je=>{je.stopPropagation(),ie(I)},children:"−"}):null]})]},I.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?a("scmLoading"):a("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:C==="history"?b?`${b.shortHash} ${b.subject}`:a("scmCommitDetail"):H?H.path:a("scmDiff")}),(C==="history"?z:D)&&e.jsx("span",{className:"scm-diff-loading",children:a("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:C==="history"?e.jsxs(e.Fragment,{children:[w&&e.jsx("div",{className:"scm-error",children:w}),!b&&!w&&e.jsx("div",{className:"scm-empty",children:a("scmSelectCommitHint")}),b&&z&&!w&&e.jsx("div",{className:"scm-empty",children:a("scmLoading")}),b&&!z&&!w&&q?Le(q):null]}):e.jsxs(e.Fragment,{children:[w&&e.jsx("div",{className:"scm-error",children:w}),!H&&!w&&e.jsx("div",{className:"scm-empty",children:a("scmSelectFileHint")}),H&&!_&&!w&&e.jsx("div",{className:"scm-empty",children:a("scmLoading")}),H&&_&&_.untracked&&e.jsx("div",{className:"scm-empty",children:a("scmUntrackedNote")}),H&&_&&!_.untracked&&e.jsxs(e.Fragment,{children:[_.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:a("scmStaged")}),Le(_.staged)]}),_.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:a("scmUnstaged")}),Le(_.worktree)]}),!_.staged&&!_.worktree&&e.jsx("div",{className:"scm-empty",children:a("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Xe,{}),e.jsx("span",{children:a("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:a("scmViewTerminal")})]})]})}function Tr({entry:t,send:s}){const i=l.useRef(null),r=me();return l.useEffect(()=>{const c=i.current;if(!c)return;let a;try{a=t.module.mount(c,qi(t.info.id,n=>s(n)))}catch(n){console.error(`[plugin:${t.info.id}] mount failed:`,n),c.textContent=r("pluginMountFailed",{name:t.info.name})}return()=>{if(typeof a=="function")try{a()}catch(n){console.error(`[plugin:${t.info.id}] cleanup failed:`,n)}c.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:i})}function Er({send:t,piConfigured:s,piAgentInstalled:i,providers:r,installResult:c,onClose:a}){const n=me(),[o,d]=l.useState(!1),[p,f]=l.useState(""),[h,g]=l.useState(""),[y,C]=l.useState(!1);l.useEffect(()=>{t({type:"list_providers"})},[t]),l.useEffect(()=>{s&&a()},[s,a]),l.useEffect(()=>{c&&d(!1)},[c]),l.useEffect(()=>{var q;!p&&r.length>0&&f(((q=r.find(J=>!J.configured))==null?void 0:q.id)??r[0].id)},[r,p]);const L=()=>{o||(d(!0),t({type:"install_pi_agent"}))},O=()=>{!h.trim()||y||(C(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:h.trim()}),setTimeout(()=>C(!1),3e3))},j=()=>{t({type:"get_state"}),t({type:"list_providers"})},b=r.find(q=>q.id===p),X=c!==null&&!c.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":n("close"),onClick:a,children:e.jsx(Ee,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(rt,{className:"modal-head-icon"}),e.jsx("h2",{children:n("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:n("setupDesc")}),X?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:n("installFailed")}),e.jsx("pre",{className:"setup-detail",children:c.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:L,children:n("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:a,children:n("skip")})]})]}):i||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?n("installDone"):n("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("provider")}),e.jsxs("select",{value:p,onChange:q=>f(q.target.value),children:[r.length===0&&e.jsx("option",{value:"",children:n("loading")}),r.map(q=>e.jsxs("option",{value:q.id,children:[q.name,"(",q.id,")",q.configured?` · ${n("configured")}`:""]},q.id))]}),(b==null?void 0:b.configured)&&e.jsx("div",{className:"field-hint",children:n("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("apiKey")}),e.jsx("input",{type:"password",value:h,onChange:q=>g(q.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!h.trim()||y||!p,onClick:O,children:n(y?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:j,children:[e.jsx(at,{})," ",n("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:L,children:n(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:a,children:n("skip")})]})]})})}const Pr=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],Gt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Mr=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[Gt()]});function Lt(t){return{providerId:t.providerId,name:t.name??"",api:t.api??"openai-completions",baseUrl:t.baseUrl??"",apiKey:t.apiKey??"",authHeader:t.authHeader??!1,models:(t.models.length?t.models:[Gt()]).map(s=>{var i;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(i=s.input)!=null&&i.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function Rr({send:t,providers:s,providerStatus:i,providerKeys:r,fetchModelsResult:c,cloneProviderResult:a,onClose:n}){const o=me(),[d,p]=l.useState(null),[f,h]=l.useState({}),[g,y]=l.useState({}),[C,L]=l.useState(null),[O,j]=l.useState(!1),[b,X]=l.useState(0),[q,J]=l.useState(null),z=l.useRef(0),[E,H]=l.useState(null),[x,_]=l.useState(""),[A,D]=l.useState(null);l.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"}),t({type:"list_provider_keys"})},[t]);const M=()=>{if(!d)return;const v=d.baseUrl.trim();if(!v){J({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(O)return;j(!0),J(null);const B=b+1;X(B),t({type:"fetch_models",reqId:B,baseUrl:v,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader,api:d.api})};l.useEffect(()=>{var v;if(!(!c||c.reqId===z.current))if(z.current=c.reqId,j(!1),c.ok&&((v=c.models)!=null&&v.length)){const B=c.models;p(u=>{if(!u)return u;const P=u.models.map(Z=>{var fe;if(!Z.id.trim())return Z;const ae=B.find(N=>N.id===Z.id.trim());if(!ae)return Z;const ge={...Z};return!ge.name&&ae.name&&(ge.name=ae.name),!ge.contextWindow&&ae.contextWindow&&(ge.contextWindow=String(ae.contextWindow)),!ge.maxTokens&&ae.maxTokens&&(ge.maxTokens=String(ae.maxTokens)),ge.input==="text"&&((fe=ae.input)!=null&&fe.includes("image"))&&(ge.input="text-image"),!ge.reasoning&&ae.reasoning&&(ge.reasoning=!0),ge}),R=new Set(P.map(Z=>Z.id.trim()).filter(Boolean)),V=B.filter(Z=>!R.has(Z.id)).map(Z=>{var ae;return{id:Z.id,name:Z.name??"",reasoning:Z.reasoning??!1,input:(ae=Z.input)!=null&&ae.includes("image")?"text-image":"text",contextWindow:Z.contextWindow?String(Z.contextWindow):"",maxTokens:Z.maxTokens?String(Z.maxTokens):""}}),se=[...P,...V];return se.some(Z=>Z.id.trim())?{...u,models:se.filter(Z=>Z.id.trim())}:u}),J({ok:!0,text:o("fetchModelsOk",{n:B.length})})}else J({ok:!1,text:c.error||o("fetchModelsEmpty")})},[c]);const K=v=>{const B=(f[v.id]??"").trim();!B||C||(L(v.id),t({type:"add_provider_key",provider:v.id,apiKey:B,name:(g[v.id]??"").trim()||void 0}),setTimeout(()=>{L(null),h(u=>({...u,[v.id]:""})),y(u=>({...u,[v.id]:""})),t({type:"list_providers"}),t({type:"list_provider_keys"})},1500))},W=(v,B)=>{t({type:"activate_provider_key",provider:v,keyName:B}),t({type:"list_provider_keys"})},k=(v,B)=>{window.confirm(o("removeKeyConfirm"))&&(t({type:"remove_provider_key",provider:v,keyName:B}),t({type:"list_provider_keys"}))},S=()=>{if(!A)return;const v=A.providerId.trim();if(!v||!A.apiKey.trim())return;const B=A.models.filter(P=>P.id.trim()).map(P=>({id:P.id.trim(),name:P.name.trim()||void 0,reasoning:P.reasoning||void 0,input:P.input==="text-image"?["text","image"]:void 0,contextWindow:P.contextWindow?Number(P.contextWindow):void 0,maxTokens:P.maxTokens?Number(P.maxTokens):void 0})),u={providerId:v,name:A.name.trim()||void 0,api:A.api.trim()||void 0,baseUrl:A.baseUrl.trim()||void 0,apiKey:A.apiKey.trim()||void 0,authHeader:A.authHeader||void 0,models:B};t({type:"save_model_config",providerId:v,config:u}),D(null),n()},w=()=>{if(!d)return;const v=d.providerId.trim(),B=d.models.filter(P=>P.id.trim()).map(P=>({id:P.id.trim(),name:P.name.trim()||void 0,reasoning:P.reasoning||void 0,input:P.input==="text-image"?["text","image"]:void 0,contextWindow:P.contextWindow?Number(P.contextWindow):void 0,maxTokens:P.maxTokens?Number(P.maxTokens):void 0})),u={providerId:v,name:d.name.trim()||void 0,api:d.api.trim()||void 0,baseUrl:d.baseUrl.trim()||void 0,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader||void 0,models:B};t({type:"save_model_config",providerId:v,config:u}),n()};l.useEffect(()=>{if(a&&a.ok){const v=a.configs;if(v&&v.length>1){H(v.map(B=>Lt({...B,apiKey:""}))),_("");return}if(a.config){D(Lt({...a.config,apiKey:""}));return}}},[a]);const U=v=>{window.confirm(o("clearKeyConfirm",{id:v}))&&t({type:"clear_provider_api_key",provider:v})},G=v=>{window.confirm(o("deleteProviderConfirm",{id:v.providerId,n:v.models.length}))&&t({type:"delete_model_config",providerId:v.providerId})},ue=(v,B)=>{d&&p({...d,models:d.models.map((u,P)=>P===v?{...u,...B}:u)})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal model-modal",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:n,children:e.jsx(Ee,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:A?o("addKey"):E?o("batchCreateProviders",{n:E.length}):o(d?"editProvider":"manageModelsTitle")})}),A?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("secondKeyTitle",{api:A.api,baseUrl:A.baseUrl||o("noBaseUrlShort"),n:A.models.length})}),e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerNameLabel")," ",e.jsx("em",{children:o("providerNameHint")})]}),e.jsx("input",{type:"text",value:A.providerId,onChange:v=>D({...A,providerId:v.target.value}),placeholder:"opencode-2"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKeyLabel")}),e.jsx("input",{type:"password",value:A.apiKey,onChange:v=>D({...A,apiKey:v.target.value}),placeholder:o("secondKeyPlaceholder")})]})]}),e.jsxs("div",{style:{fontSize:12,opacity:.6,marginTop:8},children:[A.models.slice(0,5).map(v=>v.id).join(", "),A.models.length>5?` … +${A.models.length-5}`:""]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>D(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn",onClick:()=>{const v=A;D(null),p(v)},children:o("advancedEdit")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!A.providerId.trim()||!A.apiKey.trim(),onClick:S,children:o("save")})]})]}):E?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("batchDesc",{apis:E.map(v=>v.api).join("、"),n:E.length})}),e.jsxs("label",{className:"field",style:{marginBottom:16},children:[e.jsx("span",{className:"field-label",children:o("batchKeyLabel",{n:E.length})}),e.jsx("input",{type:"password",value:x,onChange:v=>_(v.target.value),placeholder:o("secondKeyPlaceholder")})]}),e.jsx("div",{className:"provider-list",style:{marginBottom:16},children:E.map((v,B)=>e.jsxs("div",{className:"provider-row",style:{flexDirection:"column",alignItems:"stretch",gap:6},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:13},children:[e.jsx("strong",{children:v.providerId}),e.jsx("span",{style:{opacity:.7},children:v.api})]}),e.jsxs("div",{className:"provider-sub",style:{fontSize:12,opacity:.7},children:[v.baseUrl||o("noBaseUrlShort")," · ",o("modelsCountShort",{n:v.models.length}),v.models.slice(0,3).map(u=>u.id).join(", "),v.models.length>3?` … +${v.models.length-3}`:""]}),e.jsx("input",{type:"text",value:v.providerId,onChange:u=>H(P=>P.map((R,V)=>V===B?{...R,providerId:u.target.value}:R)),placeholder:o("providerIdPlaceholder"),style:{fontSize:12}}),e.jsx("input",{type:"text",value:v.baseUrl,onChange:u=>H(P=>P.map((R,V)=>V===B?{...R,baseUrl:u.target.value}:R)),placeholder:o("baseUrlExamplePh"),style:{fontSize:12}})]},B))})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>H(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!x.trim(),onClick:()=>{for(const v of E){const B=v.providerId.trim();if(!B)continue;const u=v.models.filter(R=>R.id.trim()).map(R=>({id:R.id.trim(),name:R.name.trim()||void 0,reasoning:R.reasoning||void 0,input:R.input==="text-image"?["text","image"]:void 0,contextWindow:R.contextWindow?Number(R.contextWindow):void 0,maxTokens:R.maxTokens?Number(R.maxTokens):void 0})),P={providerId:B,name:v.name.trim()||void 0,api:v.api.trim()||void 0,baseUrl:v.baseUrl.trim()||void 0,apiKey:x.trim()||void 0,authHeader:v.authHeader||void 0,models:u};t({type:"save_model_config",providerId:B,config:P})}H(null),n()},children:o("saveAllBatch",{n:E.length})})]})]}):d?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:d.providerId,disabled:s.some(v=>v.providerId===d.providerId),onChange:v=>p({...d,providerId:v.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:d.name,onChange:v=>p({...d,name:v.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:d.api,onChange:v=>p({...d,api:v.target.value}),children:Pr.map(v=>e.jsx("option",{value:v,children:v},v))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:d.baseUrl,onChange:v=>p({...d,baseUrl:v.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:d.apiKey,onChange:v=>p({...d,apiKey:v.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:d.authHeader,onChange:v=>p({...d,authHeader:v.target.checked})}),e.jsx("span",{children:o("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:o("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[q&&e.jsx("span",{className:`fetch-msg ${q.ok?"ok":"err"}`,title:q.text,children:q.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:O||!d.baseUrl.trim(),title:o("fetchModelsHint"),onClick:M,children:[e.jsx(qt,{})," ",o(O?"fetchingModels":"fetchModels")]})]})]}),d.models.map((v,B)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:v.id,onChange:u=>ue(B,{id:u.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:v.name,onChange:u=>ue(B,{name:u.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:v.input,onChange:u=>ue(B,{input:u.target.value}),children:[e.jsx("option",{value:"text",children:o("text")}),e.jsx("option",{value:"text-image",children:o("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:v.reasoning,onChange:u=>ue(B,{reasoning:u.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:v.contextWindow,onChange:u=>ue(B,{contextWindow:u.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:v.maxTokens,onChange:u=>ue(B,{maxTokens:u.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>p({...d,models:d.models.filter((u,P)=>P!==B)}),children:e.jsx(_e,{})})]},B)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...d,models:[...d.models,Gt()]}),children:[e.jsx(Ae,{})," ",o("addModel")]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!d.providerId.trim()||!d.models.some(v=>v.id.trim()),onClick:w,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-fixed-hint",children:e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]})}),e.jsxs("div",{className:"model-modal-body",children:[e.jsxs("div",{className:"provider-list",children:[i.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.map(v=>{const B=r[v.id]??[];return e.jsxs("div",{className:"provider-row provider-key-row",children:[e.jsxs("div",{className:"provider-key-head",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.name}),e.jsxs("span",{className:"provider-sub",children:[v.id,v.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),v.source&&!v.configured&&e.jsx("span",{className:"auth-badge dim",children:v.source})]})]}),v.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>U(v.id),children:[e.jsx(_e,{})," ",o("clearKey")]})]}),e.jsxs("div",{className:"provider-keys",children:[B.length===0&&e.jsx("div",{className:"provider-key-empty",children:o("noKeyYet")}),B.map(u=>e.jsxs("div",{className:`provider-key-item ${u.active?"active":""}`,children:[e.jsx("span",{className:"provider-key-dot",children:u.active?"●":"○"}),e.jsx("span",{className:"provider-key-label",children:u.name}),!u.active&&e.jsx("button",{type:"button",className:"iconbtn",title:o("activateKey"),onClick:()=>W(v.id,u.name),children:e.jsx(ct,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeKey"),onClick:()=>k(v.id,u.name),children:e.jsx(_e,{})})]},u.name)),e.jsxs("div",{className:"provider-add-key",children:[e.jsx("input",{type:"text",className:"key-input key-input-name",placeholder:o("keyNamePh"),value:g[v.id]??"",onChange:u=>y(P=>({...P,[v.id]:u.target.value}))}),e.jsx("input",{type:"password",className:"key-input key-input-value",placeholder:o("addKeyPlaceholder"),value:f[v.id]??"",onChange:u=>h(P=>({...P,[v.id]:u.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(f[v.id]??"").trim()||C===v.id,onClick:()=>K(v),children:[e.jsx(Ae,{})," ",C===v.id?o("savingKey"):o("addKey")]})]})]})]},v.id)})]}),e.jsx("div",{className:"form-section-title",children:o("customProviders")}),e.jsx("p",{className:"modal-desc",children:o("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:o("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(v=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.providerId}),e.jsxs("span",{className:"provider-sub",children:[v.api??"—",v.baseUrl?` · ${v.baseUrl}`:"",v.models.length>0&&` · ${o("modelsCount",{n:v.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>p(Lt(v)),children:e.jsx(Xs,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>G(v),children:e.jsx(_e,{})})]})]},v.providerId))})]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(Mr()),children:[e.jsx(Ae,{})," ",o("addProvider")]})})]})]})})}function Ir({plugin:t,send:s}){const i=me(),r=t.settingsSchema??[],[c,a]=l.useState(()=>({...t.settingsValues})),[n,o]=l.useState(!1);if(r.length===0)return null;const d=(g,y)=>a(C=>({...C,[g]:y})),p=r.some(g=>{var y;return c[g.key]!==((y=t.settingsValues)==null?void 0:y[g.key])}),f=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},h=()=>a({...t.settingsValues});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:r.map(g=>e.jsxs("label",{className:"plugin-settings-field",title:g.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:g.label}),g.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[g.key],onChange:y=>d(g.key,y.target.checked)}):g.type==="select"?e.jsx("select",{value:String(c[g.key]??""),onChange:y=>d(g.key,y.target.value),children:(g.options??[]).map(y=>e.jsx("option",{value:y,children:y},y))}):e.jsx("input",{type:g.type==="password"?"password":g.type==="number"?"number":"text",value:String(c[g.key]??""),min:g.min,max:g.max,onChange:y=>d(g.key,g.type==="number"?Number(y.target.value):y.target.value)})]},g.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!p||n,onClick:f,children:i(n?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:h,children:i("pluginSettingsReset")})]})]})}function Lr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Je({text:t}){const s=l.useRef(null),[i,r]=l.useState(!1),c=()=>{var n;const a=(n=s.current)==null?void 0:n.getBoundingClientRect();a&&r(window.innerWidth-a.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${i?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function $e({title:t,subtitle:s,tip:i,enabled:r,onToggle:c,action:a}){const n=me();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[t,i&&e.jsx(Je,{text:i})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),a,e.jsx("button",{type:"button",className:`set-switch ${r?"on":""}`,role:"switch","aria-checked":r,title:n(r?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Dr({chat:t,send:s,terminal:i,onSwitchToTerminal:r,onClose:c}){var Y,ne,he;const a=me(),n=t.settings,o=t.engine==="dsh",[d,p]=l.useState("prompt"),f=l.useRef(null);l.useEffect(()=>{var m;(m=f.current)==null||m.scrollTo({top:0})},[d]),l.useEffect(()=>{d==="plugins"&&t.engine==="dsh"&&s({type:"dsh_patches_list"})},[d,t.engine,s]);const[h,g]=l.useState(""),[y,C]=l.useState("append"),L=l.useRef(!1),[O,j]=l.useState(""),[b,X]=l.useState("append"),q=l.useRef(!1),[J,z]=l.useState(""),E=l.useRef(!1),[H,x]=l.useState(""),[_,A]=l.useState(null),[D,M]=l.useState(null),[K,W]=l.useState(!1),[k,S]=l.useState(null),[w,U]=l.useState(null);l.useEffect(()=>{n&&(C(n.promptMode),!L.current&&(g(y==="append"||n.customSystemPrompt?n.customSystemPrompt:n.defaultSystemPrompt||""),X(n.visionBridgePromptMode),!q.current&&(j(b==="append"||n.visionBridgePrompt?n.visionBridgePrompt:n.visionBridgeDefaultPrompt||""),E.current||z(n.reviewPrompt))))},[n,y,b]);const[G,ue]=l.useState(String((n==null?void 0:n.terminalBashIdleMs)??15e3));if(l.useEffect(()=>{ue(String((n==null?void 0:n.terminalBashIdleMs)??15e3))},[n==null?void 0:n.terminalBashIdleMs]),!n)return null;const v=[{id:"prompt",icon:e.jsx(Js,{}),label:a("settingsSystemPrompt")},{id:"terminal",icon:e.jsx(Xe,{}),label:a("settingsTerminalTools")},{id:"display",icon:e.jsx(Ze,{}),label:a("settingsMessageDisplay")},{id:"skills",icon:e.jsx(rt,{}),label:a("settingsSkills"),count:n.skills.length},{id:"extensions",icon:e.jsx(gs,{}),label:a("settingsExtensions"),count:n.extensions.length},{id:"plugins",icon:e.jsx(Ct,{}),label:a("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(mt,{}),label:a("settingsReview"),count:n.reviewSkills.length},...o?[]:[{id:"vision",icon:e.jsx(At,{}),label:a("settingsVisionBridge")}],{id:"presets",icon:e.jsx(ni,{}),label:a("settingsPresets"),count:n.presets.length},...o?[]:[{id:"subagent-templates",icon:e.jsx(ms,{}),label:a("settingsSubagentTemplates"),count:n.subagentTemplates.length}]],B=new Set(n.disabledSkills),u=new Set(n.disabledExtensions),P=m=>s({type:"set_settings",...m}),R=m=>{const ie=new Set(B);ie.has(m.name)?ie.delete(m.name):ie.add(m.name),P({disabledSkills:[...ie]})},V=new Set(n.disabledPlugins??[]),se=m=>{const ie=new Set(V);ie.has(m.id)?ie.delete(m.id):ie.add(m.id),P({disabledPlugins:[...ie]})},Z=m=>{const ie=new Set(u);ie.has(m.id)?ie.delete(m.id):ie.add(m.id),P({disabledExtensions:[...ie]})},ae=(m,ie)=>{var Me,Ie;const de={name:m,command:ie,cwd:"${pwd}"};let Pe;const Te=t.terminals.find(Le=>Le.title===m);Te?(i.restart(Te.id),s({type:"run_command",terminalId:Te.id,conversationId:Te.conversationId,command:de,cols:80,rows:24}),Pe=Te.id):(Pe=He(),i.create({id:Pe,conversationId:t.activeConversationId||((Me=t.state)==null?void 0:Me.conversationId)||"",title:m,cwd:((Ie=t.state)==null?void 0:Ie.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:de})),i.select(Pe),r(),c()},ge=m=>{S(null),ae(`${a("uninstallTitle")} ${m}`,`pi remove npm:${m}`)},fe=m=>{U(null),ae(`${a("uninstallTitle")} ${m}`,`pi-web-ui uninstall ${m}`)},N=(m,ie)=>{ae(`${a("pluginUpdate")} ${m}`,`pi-web-ui install ${ie} --name ${m} --force`)},Q=m=>{const ie=new Set(n.reviewSkills.filter(de=>!de.enabled).map(de=>de.name));ie.has(m.name)?ie.delete(m.name):ie.add(m.name),P({reviewDisabledSkills:[...ie]})},ve=()=>{const m=y==="replace"&&n.defaultSystemPrompt&&h===n.defaultSystemPrompt?"":h;P({promptMode:y,customSystemPrompt:m})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:m=>m.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":a("close"),onClick:c,children:e.jsx(Ee,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(vt,{className:"modal-head-icon"}),e.jsx("h2",{children:a("settingsTitle")}),e.jsx(Je,{text:a("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":a("settingsTitle"),children:v.map(m=>e.jsxs("button",{type:"button",className:`settings-tab${d===m.id?" active":""}`,"aria-current":d===m.id?"true":void 0,title:m.label,onClick:()=>p(m.id),children:[e.jsx("span",{className:"settings-tab-icon",children:m.icon}),e.jsx("span",{className:"settings-tab-label",children:m.label}),m.count!==void 0&&e.jsx("span",{className:"set-count",children:m.count})]},m.id))}),e.jsxs("div",{className:"modal-body",ref:f,children:[d==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(mt,{className:"set-section-icon"}),a("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:y,onChange:m=>{const ie=m.target.value;C(ie),P({promptMode:ie})},children:[e.jsx("option",{value:"append",children:a("promptModeAppend")}),e.jsx("option",{value:"replace",children:a("promptModeReplace")})]}),e.jsx(Je,{text:a(y==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:a("promptPlaceholder"),value:h,onFocus:()=>L.current=!0,onBlur:()=>{L.current=!1,ve()},onChange:m=>g(m.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":K,onClick:()=>W(m=>!m),children:[a("settingsViewPrompt")," ",K?"▴":"▾"]}),K&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:a("settingsViewPromptHint")}),e.jsx(dn,{text:n.effectiveSystemPrompt})]}),n.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:n.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:a("settingsViewPromptEmpty")})]})]}),d==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Xe,{className:"set-section-icon"}),a("settingsTerminalTools")]}),e.jsx($e,{title:a("terminalToolsEnabled"),tip:a("settingsTerminalToolsDesc"),enabled:n.terminalToolsEnabled,onToggle:()=>P({terminalToolsEnabled:!n.terminalToolsEnabled})}),!n.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:a("terminalToolsOffHint")}),e.jsx($e,{title:a("terminalBashTakeover"),tip:a("terminalBashTakeoverDesc"),enabled:n.terminalBash,onToggle:()=>P({terminalBash:!n.terminalBash})}),n.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:a("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:G,onChange:m=>ue(m.target.value),onBlur:()=>{const m=Math.max(0,Math.floor(Number(G)||0));ue(String(m)),m!==n.terminalBashIdleMs&&P({terminalBashIdleMs:m})}})]})]}),d==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ze,{className:"set-section-icon"}),a("settingsMessageDisplay")]}),e.jsx($e,{title:a("thinkingWrap"),tip:a("thinkingWrapDesc"),enabled:n.thinkingWrap??!0,onToggle:()=>P({thinkingWrap:!(n.thinkingWrap??!0)})}),e.jsx($e,{title:a("toolsWrap"),tip:a("toolsWrapDesc"),enabled:n.toolsWrap??!0,onToggle:()=>P({toolsWrap:!(n.toolsWrap??!0)})})]}),d==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(rt,{className:"set-section-icon"}),a("settingsSkills"),e.jsx("span",{className:"set-count",children:n.skills.length})]}),n.skills.length===0?e.jsx("p",{className:"set-empty",children:a(o?"dshSkillsNote":"noSkills")}):e.jsx("div",{className:"set-list",children:n.skills.map(m=>e.jsx($e,{title:m.name,subtitle:m.description,enabled:m.enabled,onToggle:()=>R(m)},m.name))})]}),d==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(gs,{className:"set-section-icon"}),a("settingsExtensions"),e.jsx("span",{className:"set-count",children:n.extensions.length})]}),n.extensions.length===0?e.jsx("p",{className:"set-empty",children:a(o?"dshExtensionsNote":"noExtensions")}):e.jsx("div",{className:"set-list",children:n.extensions.map(m=>{const ie=m.id.startsWith("npm:")?m.id.slice(4):null;return e.jsx($e,{title:m.name,subtitle:m.path,enabled:m.enabled,onToggle:()=>Z(m),action:ie?k===m.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("uninstallConfirmHint"),onClick:()=>ge(ie),children:a("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:a("uninstallHint"),onClick:()=>S(m.id),children:[e.jsx(_e,{}),a("uninstallExt")]}):void 0},m.id)})})]}),d==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ct,{className:"set-section-icon"}),a("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:a("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(m=>{var ie;return e.jsxs(e.Fragment,{children:[e.jsx($e,{title:`${m.icon?`${m.icon} `:""}${m.name}`,subtitle:(m.error?`${m.id} · ${m.error}`:m.source?`${m.id} · ${m.source}`:`${m.id} · ${a("uiPluginNoSource")}`)+((ie=m.permissions)!=null&&ie.length?` · ${a("uiPluginPerms")}: ${m.permissions.join(", ")}`:""),enabled:!V.has(m.id)&&!m.error,onToggle:()=>!m.error&&se(m),action:e.jsxs("div",{className:"set-row-actions",children:[m.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:a("pluginUpdateHint"),onClick:()=>N(m.id,m.source),children:[e.jsx(at,{}),a("pluginUpdate")]}),w===m.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("pluginUninstallHint"),onClick:()=>fe(m.id),children:a("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:a("pluginUninstallHint"),onClick:()=>U(m.id),children:[e.jsx(_e,{}),a("uninstallExt")]})]})},m.id),m.settingsSchema&&m.settingsSchema.length>0&&e.jsx(Ir,{plugin:m,send:s})]})})})]}),d==="plugins"&&t.engine==="dsh"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ct,{className:"set-section-icon"}),a("dshPatches"),e.jsx(Je,{text:a("dshPatchesDesc")}),e.jsx("span",{className:"set-count",children:((Y=t.dshPatches)==null?void 0:Y.files.length)??0}),e.jsxs("button",{type:"button",className:"set-uninstall",title:a("dshPatchesRescanHint"),onClick:()=>s({type:"dsh_patches_rescan"}),children:[e.jsx(at,{}),a("dshPatchesRescan")]})]}),(((ne=t.dshPatches)==null?void 0:ne.files.length)??0)===0?e.jsx("p",{className:"set-empty",children:a("dshPatchesEmpty")}):e.jsx("div",{className:"set-list",children:t.dshPatches.files.map(m=>e.jsx("div",{className:"set-row",children:e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:m.name}),e.jsxs("div",{className:"set-row-desc",children:[Lr(m.size)," · ",new Date(m.mtimeMs).toLocaleString()]})]})},m.name))}),e.jsxs("p",{className:"set-hint",children:[a("dshPatchesPath")," ",((he=t.dshPatches)==null?void 0:he.patchDir)??""]})]}),d==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(mt,{className:"set-section-icon"}),a("settingsReview"),e.jsx(Je,{text:a("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:n.reviewSkills.length})]}),o&&e.jsx("p",{className:"set-hint",children:a("dshReviewPromptNote")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:a("reviewPromptPlaceholder"),value:J,onFocus:()=>E.current=!0,onBlur:()=>{E.current=!1,P({reviewPrompt:J})},onChange:m=>z(m.target.value)}),e.jsx("div",{className:"set-field-label",children:a("settingsReviewSkills")}),n.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:a("noSkills")}):e.jsx("div",{className:"set-list",children:n.reviewSkills.map(m=>e.jsx($e,{title:m.name,subtitle:m.description,enabled:m.enabled,onToggle:()=>Q(m)},`review-${m.name}`))})]}),d==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(At,{className:"set-section-icon"}),a("settingsVisionBridge")]}),e.jsx($e,{title:a("visionBridgeEnabled"),tip:a("settingsVisionBridgeDesc"),enabled:n.visionBridgeEnabled,onToggle:()=>P({visionBridgeEnabled:!n.visionBridgeEnabled})}),!n.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:a("visionBridgeOffHint")}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:n.visionBridgeModel??"",onChange:m=>P({visionBridgeModel:m.target.value||null}),children:[e.jsx("option",{value:"",children:a("visionBridgeAuto")}),n.visionModels.map(m=>e.jsx("option",{value:`${m.provider}/${m.id}`,children:m.label},`${m.provider}/${m.id}`))]})]}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:b,onChange:m=>{const ie=m.target.value;X(ie),P({visionBridgePromptMode:ie})},children:[e.jsx("option",{value:"append",children:a("promptModeAppend")}),e.jsx("option",{value:"replace",children:a("promptModeReplace")})]})]}),n.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:a("visionBridgePromptPlaceholder"),value:O,onFocus:()=>q.current=!0,onBlur:()=>{q.current=!1;const m=b==="replace"&&n.visionBridgeDefaultPrompt&&O===n.visionBridgeDefaultPrompt?"":O;P({visionBridgePromptMode:b,visionBridgePrompt:m})},onChange:m=>j(m.target.value)}),n.visionBridgeEnabled&&(n.visionModels.length===0?e.jsx("p",{className:"set-hint",children:a("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:a("visionBridgeCurrent",{model:n.visionBridgeModel??a("visionBridgeAuto")})}))]}),d==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(vt,{className:"set-section-icon"}),a("settingsPresets"),e.jsx("span",{className:"set-count",children:n.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:a("presetNamePlaceholder"),value:H,onChange:m=>x(m.target.value),onKeyDown:m=>{m.key==="Enter"&&H.trim()&&(s({type:"save_preset",name:H.trim()}),x(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!H.trim(),onClick:()=>{s({type:"save_preset",name:H.trim()}),x("")},children:[e.jsx(Ae,{})," ",a("saveAsPreset")]})]}),n.presets.length===0?e.jsx("p",{className:"set-empty",children:a("noPresets")}):e.jsx("div",{className:"set-list",children:n.presets.map(m=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:m.name}),e.jsxs("div",{className:"set-row-desc",children:[m.promptMode==="replace"?a("promptModeReplace"):a("promptModeAppend"),m.disabledSkills.length>0&&` · ${a("settingsSkills")} ${m.disabledSkills.length}`,m.disabledExtensions.length>0&&` · ${a("settingsExtensions")} ${m.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:m.name}),children:a("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:a("deletePreset"),onClick:()=>s({type:"delete_preset",name:m.name}),children:e.jsx(_e,{})})]})]},m.name))})]}),d==="subagent-templates"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ms,{className:"set-section-icon"}),a("settingsSubagentTemplates"),e.jsx(Je,{text:a("settingsSubagentTemplatesDesc")}),e.jsx("span",{className:"set-count",children:n.subagentTemplates.length}),e.jsxs("button",{type:"button",className:"set-save-btn",title:a("subagentTemplateNew"),onClick:()=>A({name:"",description:"",promptMode:"replace",systemPrompt:"",enabledSkills:[],enabledExtensions:[],enabled:!0}),children:[e.jsx(Ae,{})," ",a("subagentTemplateNew")]})]}),_&&e.jsxs("div",{className:"tpl-editor",children:[e.jsxs("div",{className:"tpl-fields",children:[e.jsx("input",{className:"set-input",placeholder:a("tplNamePlaceholder"),value:_.name,onChange:m=>A({..._,name:m.target.value})}),e.jsx("input",{className:"set-input",placeholder:a("tplDescriptionPlaceholder"),value:_.description,onChange:m=>A({..._,description:m.target.value})})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("tplPromptModeLabel")}),e.jsxs("select",{className:"set-select",value:_.promptMode,onChange:m=>A({..._,promptMode:m.target.value}),children:[e.jsx("option",{value:"replace",children:a("promptModeReplace")}),e.jsx("option",{value:"append",children:a("promptModeAppend")})]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:`${a("tplSystemPromptLabel")}:${a("tplSystemPromptPlaceholder")}`,value:_.systemPrompt,onChange:m=>A({..._,systemPrompt:m.target.value})}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[a("tplSkillsLabel")," · ",a("tplWhitelistHint")]})}),n.skills.length===0?e.jsx("p",{className:"set-hint",children:a("noSkills")}):e.jsx("div",{className:"tpl-pick",children:n.skills.map(m=>e.jsxs("label",{className:`tpl-chip${_.enabledSkills.includes(m.name)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:_.enabledSkills.includes(m.name),onChange:ie=>{const de=ie.target.checked;A({..._,enabledSkills:de?[..._.enabledSkills,m.name]:_.enabledSkills.filter(Pe=>Pe!==m.name)})}}),m.name]},m.name))})]}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[a("tplExtensionsLabel")," · ",a("tplWhitelistHint")]})}),n.extensions.length===0?e.jsx("p",{className:"set-hint",children:a("noExtensions")}):e.jsx("div",{className:"tpl-pick",children:n.extensions.map(m=>e.jsxs("label",{className:`tpl-chip${_.enabledExtensions.includes(m.id)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:_.enabledExtensions.includes(m.id),onChange:ie=>{const de=ie.target.checked;A({..._,enabledExtensions:de?[..._.enabledExtensions,m.id]:_.enabledExtensions.filter(Pe=>Pe!==m.id)})}}),m.name]},m.id))})]}),e.jsxs("div",{className:"tpl-actions",children:[e.jsx("button",{type:"button",className:"set-save-btn",disabled:!_.name.trim(),onClick:()=>{s({type:"save_subagent_template",template:{..._,name:_.name.trim()}}),A(null)},children:a("tplSave")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>A(null),children:a("tplCancel")})]})]}),n.subagentTemplates.length===0?e.jsx("p",{className:"set-empty",children:a("noSubagentTemplates")}):e.jsx("div",{className:"set-list",children:n.subagentTemplates.map(m=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[m.name,n.subagentDefaultTemplates.includes(m.name)&&e.jsx("span",{className:"tpl-badge default",children:a("tplDefaultBadge")}),!m.enabled&&e.jsx("span",{className:"tpl-badge",children:a("subagentTemplateClosed")})]}),e.jsxs("div",{className:"set-row-desc",children:[m.description||`${m.promptMode==="replace"?a("promptModeReplace"):a("promptModeAppend")}`,m.enabledSkills.length>0&&` · ${a("tplSkillsLabel")} ${m.enabledSkills.length}`,m.enabledExtensions.length>0&&` · ${a("tplExtensionsLabel")} ${m.enabledExtensions.length}`,!m.description&&m.enabledSkills.length===0&&m.enabledExtensions.length===0&&` · ${a("tplInherit")}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:`set-switch${m.enabled?" on":""}`,role:"switch","aria-checked":m.enabled,title:`${m.enabled?a("subagentTemplateDisable"):a("subagentTemplateEnable")} · ${a("subagentTemplateOffHint")}`,onClick:()=>s({type:"save_subagent_template",template:{...m,enabled:!m.enabled}}),children:e.jsx("span",{className:"set-switch-knob"})}),e.jsx("button",{type:"button",className:"dd-refresh",title:a("subagentTemplateEdit"),onClick:()=>A({...m}),children:a("subagentTemplateEdit")}),D===m.name?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("uninstallConfirmHint"),onClick:()=>{s({type:"delete_subagent_template",name:m.name}),M(null)},children:a("uninstallConfirm")}):e.jsx("button",{type:"button",className:"set-icon-btn danger",title:a("tplDelete"),onClick:()=>M(m.name),children:e.jsx(_e,{})})]})]},m.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:a("close")})})]})})}function Br(t,s){const i=Math.max(0,Date.now()-t),r=Math.floor(i/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const c=Math.floor(r/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function _r({servers:t,send:s,onClose:i}){const r=me(),[c,a]=l.useState(new Set),n=o=>a(d=>{const p=new Set(d);return p.has(o)?p.delete(o):p.add(o),p});return l.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(kt,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:i,children:e.jsx(Ee,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(kt,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const d=!!o.taskId,p=o.taskId??String(o.port);return e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:d?o.plugin:r("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[d?e.jsxs("span",{className:"bg-task-port",title:o.taskId,children:["🧩 ",o.plugin]}):e.jsxs("span",{className:"bg-task-port",children:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[!d&&e.jsxs("span",{children:[r("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",Br(o.since,r)]}),d&&o.status&&e.jsx("span",{className:"bg-task-status",children:o.status})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(p)?"open":""}`,title:`${r("bgTaskCommand")}: ${o.command}`,onClick:()=>n(p),children:[e.jsx(Xe,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s(d?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(xt,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},p)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(at,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(xt,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function Ar(t,s){return t.toLowerCase().includes(s)}function Fr({open:t,send:s,projects:i,cwd:r,fileSearch:c,sessionSearch:a,onClose:n,onSwitchSession:o,onSwitchProject:d,onPreviewFile:p}){const f=me(),h=l.useRef(null),[g,y]=l.useState(""),C=l.useDeferredValue(g),[L,O]=l.useState(0),j=l.useRef(1),b=l.useRef(0),X=l.useRef(null);l.useEffect(()=>{if(!t)return;s({type:"list_sessions"}),s({type:"list_projects"});const k=g.trim();if(k){const S=++j.current;b.current=S,J(!0),s({type:"search_files",reqId:S,query:k}),s({type:"search_sessions",reqId:S,query:k})}requestAnimationFrame(()=>{var S;return(S=h.current)==null?void 0:S.select()})},[t]);const[q,J]=l.useState(!1);l.useEffect(()=>{X.current&&clearTimeout(X.current);const k=C.trim();if(!k){J(!1);return}return X.current=setTimeout(()=>{const S=++j.current;b.current=S,J(!0),s({type:"search_files",reqId:S,query:k}),s({type:"search_sessions",reqId:S,query:k})},300),()=>{X.current&&clearTimeout(X.current)}},[C]);const z=C.trim().toLowerCase(),E=l.useMemo(()=>!z||!a||a.reqId!==b.current||!a.ok?[]:a.results,[a,z]),H=l.useMemo(()=>z?i.filter(k=>Ar(k.path,z)).slice(0,10):[],[i,z]),x=l.useMemo(()=>!z||!c||c.reqId!==b.current||!c.ok?[]:c.results,[c,z]);l.useEffect(()=>{c&&c.reqId===b.current&&a&&a.reqId===b.current&&b.current!==0&&J(!1)},[c,a]);const _=!!c&&c.ok&&c.truncated,A=l.useMemo(()=>[...E.map(k=>({kind:"session",path:k.path,anchors:k.anchors})),...H.map(k=>({kind:"project",path:k.path})),...x.filter(k=>k.type==="file").map(k=>({kind:"file",path:k.path,name:k.name}))],[E,H,x]);l.useEffect(()=>{O(0)},[C]);const D=l.useCallback(k=>{if(k)if(k.kind==="session")o(k.path,k.anchors),n();else if(k.kind==="project"){d(k.path),s({type:"list_sessions"}),s({type:"list_projects"});const S=C.trim();if(S){const w=++j.current;b.current=w,J(!0),s({type:"search_files",reqId:w,query:S}),s({type:"search_sessions",reqId:w,query:S})}}else p(k.path,k.name)},[o,d,p,s,C]);l.useEffect(()=>{if(!t)return;const k=S=>{S.key==="Escape"?(S.preventDefault(),S.stopPropagation(),n()):S.key==="ArrowDown"?(S.preventDefault(),O(w=>Math.min(w+1,A.length-1))):S.key==="ArrowUp"?(S.preventDefault(),O(w=>Math.max(w-1,0))):S.key==="Enter"&&(S.preventDefault(),D(A[L]))};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[A,L,D,n,t]);const M=E.length+H.length+x.length,K=(k,S,w)=>e.jsxs("div",{className:"gs-section-head",children:[w,e.jsx("span",{children:k}),e.jsx("em",{children:S})]});let W=-1;return t?e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:n,children:e.jsxs("div",{className:"gs-modal",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(yt,{}),e.jsx("input",{ref:h,type:"text",value:g,placeholder:f("gsPlaceholder"),onChange:k=>y(k.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:f("close"),onClick:n,children:e.jsx(Ee,{})})]}),e.jsxs("div",{className:"gs-results",children:[!z&&e.jsx("div",{className:"gs-empty",children:f("gsHint")}),z&&M===0&&!_&&e.jsx("div",{className:"gs-empty",children:f(q?"gsSearching":"gsNoResults")}),E.length>0&&e.jsxs("div",{className:"gs-section",children:[K(f("gsSessions"),E.length,e.jsx(Ze,{})),E.map(k=>{W++;const S=W;return e.jsxs("button",{type:"button",className:S===L?"gs-item active":"gs-item",onMouseEnter:()=>O(S),onClick:()=>D({kind:"session",path:k.path,anchors:k.anchors}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.name||k.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:k.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:k.firstMessage})]},k.path)})]}),H.length>0&&e.jsxs("div",{className:"gs-section",children:[K(f("gsProjects"),H.length,e.jsx(et,{})),H.map(k=>{W++;const S=W,w=r&&k.path===r;return e.jsxs("button",{type:"button",className:S===L?"gs-item active":"gs-item",onMouseEnter:()=>O(S),onClick:()=>D({kind:"project",path:k.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.path.split(/[\\/]/).pop(),w&&e.jsx("em",{className:"gs-item-meta",children:f("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},k.path)})]}),(x.length>0||z&&_)&&e.jsxs("div",{className:"gs-section",children:[K(f("gsFiles"),x.length,e.jsx(Js,{})),x.map(k=>{W++;const S=W;return e.jsxs("button",{type:"button",className:S===L?"gs-item active":"gs-item",disabled:k.type==="dir",title:k.type==="dir"?void 0:f("gsOpenPreview"),onMouseEnter:()=>O(S),onClick:()=>{k.type==="file"&&D({kind:"file",path:k.path,name:k.name})},children:[e.jsx("span",{className:"gs-item-title",children:k.name}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},`${k.type}:${k.path}`)}),_&&e.jsx("div",{className:"gs-truncated",children:f("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",f("gsNavigate")]}),e.jsxs("span",{children:["Enter ",f("gsOpen")]}),e.jsxs("span",{children:["Esc ",f("gsCloseHint")]})]})]})}):null}const Dt=5e3;function $r({file:t,content:s,send:i,onAddLines:r,onAttach:c,onClose:a}){const n=me(),[o,d]=l.useState(null),[p,f]=l.useState(!1),[h,g]=l.useState(null),[y,C]=l.useState(!1),[L,O]=l.useState(!1),[j,b]=l.useState(!1),[X,q]=l.useState(""),[J,z]=l.useState(!0),E=l.useRef(!1),[H,x]=l.useState(!0),[_,A]=l.useState(!1),[D,M]=l.useState(100),K=l.useRef(0),W=l.useRef(!1),k=l.useRef(null);l.useEffect(()=>{f(!0),d(null),g(null),b(!1),q(""),z(!0),E.current=!1,i({type:"read_file",path:t.path})},[t.path,i]),l.useEffect(()=>{s&&s.path===t.path&&(d(s),j||q(s.text),f(!1))},[s,j,t.path]),l.useEffect(()=>{const Y=ne=>{if(ne.key==="Escape"){V();return}if((ne.ctrlKey||ne.metaKey)&&ne.key.toLowerCase()==="s"&&j){ne.preventDefault(),R();return}const he=ne.target,m=he&&(he.tagName==="INPUT"||he.tagName==="TEXTAREA"||he.isContentEditable);(ne.ctrlKey||ne.metaKey)&&ne.key.toLowerCase()==="a"&&!m&&(ne.preventDefault(),ue())};return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[a,o,j,X]),l.useEffect(()=>{const Y=()=>{W.current=!1,C(!1)};return window.addEventListener("mouseup",Y),()=>window.removeEventListener("mouseup",Y)},[]);const S=l.useMemo(()=>{if(!o)return[];const Y=o.text.split(`
323
- `);return Y.length>0&&Y[Y.length-1]===""&&Y.pop(),Y.slice(0,Dt)},[o]),w=(o==null?void 0:o.lines)??0,U=w>Dt,G=(Y,ne)=>{if(ne){const he=K.current>0?K.current:Y;g({start:Math.min(he,Y),end:Math.max(he,Y)})}else K.current=Y,g({start:Y,end:Y})},ue=()=>{S.length!==0&&(K.current=1,g({start:1,end:S.length}))},v=()=>{h&&(r(t.path,t.name,h.start,h.end),O(!0),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>O(!1),1400))},B=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,u=()=>{q((o==null?void 0:o.text)??""),b(!1),E.current&&z(!0)},P=()=>{if(j){if(X!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;u();return}!B||!o||(E.current=Bt(t.name)&&J,Bt(t.name)&&z(!1),g(null),q(o.text),b(!0))},R=()=>{!j||!o||!B||i({type:"write_file",path:t.path,text:X})&&(b(!1),E.current&&z(!0),g(null))},V=()=>{j&&X!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||a()},se=Y=>{M(Math.min(200,Math.max(50,Y)))},Z=h?h.end-h.start+1:0,ae=(o==null?void 0:o.binary)??!1,ge=(o==null?void 0:o.truncated)??!1,fe=(o==null?void 0:o.kind)??"text",N=Bt(t.name),Q=N&&J&&!j&&fe==="text"&&!ae,ve=Y=>jt(tt(`/api/file?clientId=${encodeURIComponent(zt())}&path=${encodeURIComponent(Y)}`));return e.jsx("div",{className:`fp-overlay ${_?"fullscreen":""}`,onMouseDown:Y=>{Y.target===Y.currentTarget&&V()},children:e.jsxs("div",{className:`fp ${_?"fullscreen":""}`,style:{"--fp-zoom":D/100},children:[e.jsxs("div",{className:"fp-head",children:[e.jsx("span",{className:"fp-name",title:t.path,children:t.name}),e.jsx("span",{className:"fp-path",children:t.path}),e.jsxs("span",{className:"fp-meta",children:[o&&fe==="text"&&!ae&&n("fileLines",{n:w}),o&&` · ${Or(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[N&&fe==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${J?"on":""}`,"data-tip":n(J?"showMarkdownSource":"showMarkdownPreview"),disabled:j,onClick:()=>z(Y=>!Y),children:J?e.jsx(At,{}):e.jsx(xi,{})}),fe==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${j?"on":""}`,"data-tip":n(ge?"fileEditTruncated":j?"exitEditFile":"editFile"),disabled:!B&&!j,onClick:P,children:e.jsx(Ft,{})}),fe==="text"&&!ae&&!Q&&e.jsx("button",{type:"button",className:`fp-attach wrap ${H?"on":""}`,"data-tip":n(H?"disableWrap":"enableWrap"),onClick:()=>x(Y=>!Y),children:e.jsx(fi,{})}),fe==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:D<=50,onClick:()=>se(D-10),children:e.jsx(Xn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>M(100),children:[D,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:D>=200,onClick:()=>se(D+10),children:e.jsx(Zn,{})})]}),fe!=="video"&&fe!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(Ae,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(_t,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${_?"on":""}`,"data-tip":n(_?"exitFullscreen":"fullscreen"),onClick:()=>A(Y=>!Y),children:_?e.jsx(li,{}):e.jsx(ci,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:V,children:e.jsx(Ee,{})})]})]}),ge&&fe==="text"&&!ae&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&fe==="none"&&!ae&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&fe==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:ve(t.path),alt:t.name})}),!p&&fe==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:ve(t.path),controls:!0,preload:"metadata"})}),!p&&Q&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(wt,{text:o.text})})}),!p&&ae&&fe!=="image"&&fe!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&j&&fe==="text"&&!ae&&o&&e.jsx("textarea",{className:`fp-editor ${H?"":"no-wrap"}`,value:X,onChange:Y=>q(Y.target.value),wrap:H?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!Q&&!j&&fe==="text"&&!ae&&o&&S.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!Q&&!j&&fe==="text"&&!ae&&S.length>0&&e.jsxs("div",{className:`fp-code ${y?"dragging":""} ${H?"":"no-wrap"}`,onMouseDown:Y=>{Y.button===0&&Y.preventDefault()},children:[S.map((Y,ne)=>{const he=ne+1,m=h!==null&&he>=h.start&&he<=h.end;return e.jsxs("div",{className:`fp-line ${m?"sel":""}`,onMouseDown:ie=>{ie.button===0&&(G(he,ie.shiftKey),W.current=!0,C(!0))},onMouseEnter:()=>{W.current&&G(he,!0)},children:[e.jsx("span",{className:"fp-num",children:he}),e.jsx("span",{className:"fp-code-text",children:Y})]},he)}),U&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:Dt})})]}),e.jsx("div",{className:"fp-foot",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:n("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:P,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:X===((o==null?void 0:o.text)??""),onClick:R,children:[e.jsx(ii,{})," ",n("saveFile")]})]})]}):!Q&&fe==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:h?n("selectedRange",{n:Z,start:h.start,end:h.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:S.length===0,onClick:ue,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!h,onClick:()=>g(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!h||ae,onClick:v,children:[L?e.jsx(ct,{}):null,n(L?"addedToChat":"addToChat")]})]})]})})]})})}function Bt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Or(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Pn="pi-web-sounds",st={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function Mn(){try{const t=localStorage.getItem(Pn);if(!t)return{...st};const s=JSON.parse(t),i={...st,...s};for(const r of["enabled","question","done","start","error"])typeof i[r]!="boolean"&&(i[r]=st[r]);return typeof i.volume!="number"||!Number.isFinite(i.volume)?i.volume=st.volume:i.volume=Math.round(Math.max(0,Math.min(100,i.volume))/5)*5,i}catch{return{...st}}}function Hr(t){try{localStorage.setItem(Pn,JSON.stringify(t))}catch{}}let nt=null;function Kr(){try{if(!nt){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;nt=new t}return nt.state==="suspended"&&nt.resume(),nt}catch{return null}}const Ur=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Wr=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],qr=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],zr=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Vr={question:Ur,done:Wr,start:qr,error:zr};function Gr(t,s,i){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const a=t.currentTime+s.start,n=Math.max(1e-4,s.peak*i);c.gain.setValueAtTime(1e-4,a),c.gain.exponentialRampToValueAtTime(n,a+.012),c.gain.exponentialRampToValueAtTime(1e-4,a+s.dur),r.connect(c),c.connect(t.destination),r.start(a),r.stop(a+s.dur+.05)}function it(t,s=Mn()){if(!s.enabled||!s[t])return;const i=Kr();if(!i)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Vr[t])Gr(i,c,r)}const Ut="pi-web-ui:theme",Rn="dark",As="theme-stylesheet",Fs="pi-web-ui:theme-change";function In(){try{const t=localStorage.getItem(Ut);if(t&&t!==Rn)return t}catch{}return null}function Qr(t){try{t?localStorage.setItem(Ut,t):localStorage.removeItem(Ut)}catch{}}function Ln(t){let s=document.getElementById(As);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Fs));return}s||(s=document.createElement("link"),s.id=As,s.rel="stylesheet",document.head.appendChild(s)),s.href=tt(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(Fs))}async function Yr(){try{const t=await fetch(jt(tt("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Jr(){const[t,s]=l.useState([]),[i,r]=l.useState(()=>In());return l.useEffect(()=>{let a=!1;return Yr().then(n=>{a||s(n)}),()=>{a=!0}},[]),l.useEffect(()=>{Ln(i),Qr(i)},[i]),{themes:t,theme:i,switchTheme:a=>r(a===Rn?null:a)}}function al(){const t=getComputedStyle(document.documentElement),s=(i,r)=>t.getPropertyValue(i).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Xr=l.lazy(()=>Wn(()=>import("./TerminalPanel-B9vcI7-_.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function Zr({notice:t,onDismiss:s}){const i=me(),{locale:r}=dt(),c=r==="en"&&t.textEn?t.textEn:t.text,[a,n]=l.useState(!1);l.useEffect(()=>{if(a)return;const d=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(d)},[a,t.id,t.level,s]);const o=t.level==="error"?bi:t.level==="warning"?ki:pi;return e.jsxs("div",{className:`notice notice-${t.level}${a?" paused":""}`,role:"status",onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[e.jsx(o,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:c}),e.jsx("button",{type:"button",className:"notice-close",title:i("close"),onClick:()=>s(t.id),children:e.jsx(Ee,{})})]})}const el=[],Dn=180,Bn=520,_n=240,An=t=>`pi-web-ui:${t}-panel-width`;function $s(t){const s=Number(localStorage.getItem(An(t)));return Number.isFinite(s)&&s>=Dn&&s<=Bn?s:_n}const Wt=t=>`pi-web-ui:${t}-panel-collapsed`;function Os(t){return localStorage.getItem(Wt(t))==="1"}function Hs({side:t,width:s,onResize:i}){const r=me(),c=l.useCallback(a=>{a.preventDefault();const n=a.clientX,o=s;let d=o;const p=h=>{const g=t==="left"?h.clientX-n:n-h.clientX;d=Math.min(Bn,Math.max(Dn,Math.round(o+g))),i(d)},f=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",f),document.body.classList.remove("panel-resizing"),localStorage.setItem(An(t),String(d))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",f),document.body.classList.add("panel-resizing")},[t,s,i]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>i(_n)})}function Ks({side:t,onClick:s}){const i=me();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:i("expandPanel"),onClick:s,children:t==="left"?e.jsx(en,{}):e.jsx(tn,{})})}function tl(){var Fe,Qt,Yt,Jt,Xt,Zt,es,ts,ss,ns,is,as,rs,ls;const t=me(),{chat:s,send:i,dismissNotice:r,pushNotice:c,terminal:a}=Zi(),[n,o]=l.useState([]),[d,p]=l.useState(null),[f,h]=l.useState(!1),[g,y]=l.useState("chat"),C=l.useMemo(()=>s.plugins.filter(F=>{var ee,oe;return!((oe=(ee=s.settings)==null?void 0:ee.disabledPlugins)!=null&&oe.includes(F.id))}),[s.plugins,(Fe=s.settings)==null?void 0:Fe.disabledPlugins]),[L,O]=l.useState([]);l.useEffect(()=>Ui(O),[]),l.useEffect(()=>{Wi(C,s.pluginsEpoch)},[C,s.pluginsEpoch]);const[j,b]=l.useState(()=>$s("left")),[X,q]=l.useState(()=>$s("right")),J=l.useCallback(F=>b(F),[]),z=l.useCallback(F=>q(F),[]),[E,H]=l.useState(()=>Os("left")),[x,_]=l.useState(()=>Os("right")),A=l.useCallback(()=>{H(F=>(localStorage.setItem(Wt("left"),F?"0":"1"),!F))},[]),D=l.useCallback(()=>{_(F=>(localStorage.setItem(Wt("right"),F?"0":"1"),!F))},[]),[M,K]=l.useState(null),[W,k]=l.useState(()=>window.matchMedia("(max-width: 768px)").matches);l.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),ee=oe=>k(oe.matches);return F.addEventListener("change",ee),()=>F.removeEventListener("change",ee)},[]);const[S,w]=l.useState(!1),[U,G]=l.useState(!1),[ue,v]=l.useState(!1),[B,u]=l.useState(!1),[P,R]=l.useState(!1),[V,se]=l.useState(null);l.useEffect(()=>{if(!V)return;const F=setTimeout(()=>se(null),15e3);return()=>clearTimeout(F)},[V]),l.useEffect(()=>{const F=ee=>{var Ke,os;const oe=ee.detail,be=(oe==null?void 0:oe.title)||t("pluginCommandFallback"),we=oe==null?void 0:oe.command;if(!we||!s.ready)return;const De={name:be,command:we,cwd:"${pwd}"},Ne=s.terminals.find(Nt=>Nt.title===be);if(Ne)a.restart(Ne.id),i({type:"run_command",terminalId:Ne.id,conversationId:Ne.conversationId,command:De,cols:80,rows:24});else{const Nt=He();a.create({id:Nt,conversationId:s.activeConversationId||((Ke=s.state)==null?void 0:Ke.conversationId)||"",title:be,cwd:((os=s.state)==null?void 0:os.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:De})}y("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,a,i]),l.useEffect(()=>{const F=ee=>{!(ee.ctrlKey||ee.metaKey)||ee.key.toLowerCase()!=="k"||(ee.preventDefault(),R(oe=>!oe))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[Z,ae]=l.useState(Mn),{themes:ge,theme:fe,switchTheme:N}=Jr(),Q=l.useRef(null),ve=l.useRef(null),Y=l.useRef(0),ne=l.useRef(!1),he=l.useRef(s.terminals);l.useEffect(()=>{Hr(Z)},[Z]),l.useEffect(()=>{var ee;const F=he.current;he.current=s.terminals;for(const oe of s.terminals){const be=((ee=oe.command)==null?void 0:ee.command)??"",we=F.find(De=>De.id===oe.id);!(we!=null&&we.running)||oe.running||(be.startsWith("pi remove ")?i({type:"extensions_reload"}):be.startsWith("pi-web-ui install ")||be.startsWith("pi-web-ui uninstall ")?i({type:"plugins_reload"}):be.startsWith("npm i -g ")&&(i({type:"extensions_reload"}),i({type:"plugins_reload"}),i({type:"check_updates_all",force:!0})))}},[s.terminals,i]),l.useEffect(()=>{var oe;const F=((oe=s.state)==null?void 0:oe.isStreaming)??!1,ee=Q.current;Q.current=F,ee!==null&&(!ee&&F?it("start",Z):ee&&!F&&it("done",Z))},[(Qt=s.state)==null?void 0:Qt.isStreaming,Z]),l.useEffect(()=>{var ee;const F=((ee=s.dialog)==null?void 0:ee.id)??null;F!==null&&F!==ve.current&&it("question",Z),ve.current=F},[s.dialog,Z]),l.useEffect(()=>{const F=[...s.notices].reverse().find(ee=>ee.level==="error");F&&F.id!==Y.current&&(Y.current=F.id,it("error",Z))},[s.notices,Z]);const m=(F,ee,oe,be=!1,we)=>{const De=`${F}|${oe}|${we?`${we.start}-${we.end}`:""}`;o(Ne=>Ne.some(Ke=>`${Ke.path}|${Ke.mode}|${Ke.lines?`${Ke.lines.start}-${Ke.lines.end}`:""}`===De)?Ne:[...Ne,{path:F,name:ee,mode:oe,isDir:be,...we?{lines:we}:{}}])},ie=F=>o(ee=>ee.filter(oe=>oe.key?oe.key!==F:oe.path!==F)),de=l.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&K(null),i(F)),[i]),Pe=l.useRef(0),Te=l.useRef(0),Me=F=>{var be;const ee=Date.now();(be=s.state)!=null&&be.model&&!s.state.model.vision&&ee-Te.current>1e4&&(Te.current=ee,c("warning",t("imageNotSupported")));const oe=`paste-${++Pe.current}`;o(we=>[...we,{path:"",key:oe,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},Ie=async F=>{for(const ee of F){const oe=await hn(ee);if(!oe){c("error",t("imageLoadFailed",{name:ee.name}));continue}Me(oe)}},Le=20*1024*1024,ze=l.useRef(0),Ve=async F=>{if(F.size>Le){c("warning",t("fileTooLarge",{name:F.name,size:Le/1024/1024}));return}let ee;try{ee=(await new Promise((we,De)=>{const Ne=new FileReader;Ne.onload=()=>we(Ne.result),Ne.onerror=()=>De(Ne.error??new Error("read failed")),Ne.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const oe=`upload-${++ze.current}`;o(be=>[...be,{path:"",key:oe,name:F.name,mode:"inline",fileData:ee,size:F.size,mimeType:F.type||void 0}])},I=async F=>{for(const ee of F)Oe(ee.type)?await Ie([ee]):await Ve(ee)},pe=l.useCallback((F,ee,oe)=>{i({type:"edit_message",messageId:F,text:ee,attachments:oe})},[i]),ce=l.useCallback((F,ee)=>{i({type:"queue_remove",kind:F,text:ee})},[i]),je=l.useCallback(()=>G(!0),[]),xe=l.useCallback(()=>o([]),[]),Ce=l.useCallback(ie,[]),T=l.useCallback(Ie,[Ie]),$=l.useCallback(I,[I]),re=(Yt=s.state)==null?void 0:Yt.model,le=(Jt=s.state)==null?void 0:Jt.thinkingLevel,ye=(Xt=s.state)==null?void 0:Xt.availableThinkingLevels,ke=l.useMemo(()=>re?{model:re,thinkingLevel:le??"off",availableThinkingLevels:ye??[]}:null,[re,le,ye]),Se=l.useCallback(()=>{var F,ee;return!s.ready||s.terminals.length!==0?!1:(a.create({id:He(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((ee=s.state)==null?void 0:ee.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Zt=s.state)==null?void 0:Zt.cwd,s.terminals.length,t,a]);return l.useEffect(()=>{if(ne.current){if(g!=="terminal"||s.terminals.length!==0){ne.current=!1;return}Se()&&(ne.current=!1)}},[s.terminals.length,Se,g]),e.jsxs("div",{className:"app",onDragOver:F=>{var ee;Array.from(((ee=F.dataTransfer)==null?void 0:ee.types)??[]).includes("Files")&&(F.preventDefault(),h(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||h(!1)},onDrop:F=>{var we,De;if(h(!1),!Array.from(((we=F.dataTransfer)==null?void 0:we.types)??[]).includes("Files"))return;F.preventDefault();const ee=Array.from(((De=F.dataTransfer)==null?void 0:De.files)??[]);if(ee.length===0){c("warning",t("foldersNotSupported"));return}const oe=ee.filter(Ne=>Oe(Ne.type)),be=ee.filter(Ne=>!Oe(Ne.type));oe.length>0&&Ie(oe),be.length>0&&I(be)},children:[f&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(Ei,{chat:s,send:i,terminal:a,view:g,plugins:C,onViewChange:F=>{ne.current=F==="terminal"&&s.terminals.length===0,ne.current&&Se()&&(ne.current=!1),y(F),K(null)},onOpenPanel:K,onOpenSettings:()=>v(!0),onOpenBgTasks:()=>u(!0),onOpenGlobalSearch:()=>R(!0),sound:Z,onSoundChange:ae,onSoundPreview:F=>it(F,Z),themes:ge,theme:fe,onThemeChange:N}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(Zr,{notice:F,onDismiss:r},F.id))}),e.jsx(tr,{send:i,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${j}px`,"--right-w":`${X}px`},children:[M&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>K(null)}),e.jsxs("div",{className:`view-pane ${g==="chat"?"":"hidden"}`,children:[!W&&E&&e.jsx(Ks,{side:"left",onClick:A}),e.jsx("div",{className:`panel-drawer drawer-left ${M==="left"?"open":""}${W?"":E?" hidden":""}`,children:e.jsx(Li,{collapsible:!W,onToggleCollapse:A,send:de,active:!W||M==="left",ready:s.ready,status:s.status,cwd:((es=s.state)==null?void 0:es.cwd)??"",sessionFile:((ts=s.state)==null?void 0:ts.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!W&&e.jsx(Hs,{side:"left",width:j,onResize:J}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(lr,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:pe,onKillBash:()=>i({type:"abort_bash"}),onRemoveQueued:ce,thinkingWrap:((ss=s.settings)==null?void 0:ss.thinkingWrap)??!0,toolsWrap:((ns=s.settings)==null?void 0:ns.toolsWrap)??!0,jumpTarget:V,onJumpDone:()=>se(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(fr,{send:i,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(wr,{dialog:s.dialog,send:i}),s.question&&e.jsx(Nr,{question:s.question,send:i}),e.jsx(gr,{send:i,ready:s.ready,streaming:((is=s.state)==null?void 0:is.isStreaming)??!1,messages:((as=s.state)==null?void 0:as.messages)??el,slashCommands:s.slashCommands,modelState:ke,models:s.models,modelsLoading:s.modelsLoading,providerKeys:s.providerKeys,attachments:n,onRemoveAttachment:Ce,onAddImageFiles:T,onAddLocalFiles:$,onNotice:c,onManageModels:je,onSent:xe})]}),!W&&e.jsx(Hs,{side:"right",width:X,onResize:z}),e.jsx("div",{className:`panel-drawer drawer-right ${M==="right"?"open":""}${W?"":x?" hidden":""}`,children:e.jsx(oa,{collapsible:!W,onToggleCollapse:D,send:de,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((rs=s.state)==null?void 0:rs.cwd)??"",onAttach:(F,ee,oe,be)=>{K(null),m(F,ee,oe,be)},onPreview:(F,ee)=>{K(null),p({path:F,name:ee})},onNotice:(F,ee)=>c(F,ee)})}),!W&&x&&e.jsx(Ks,{side:"right",onClick:D})]}),e.jsx("div",{className:`view-pane ${g==="terminal"?"":"hidden"}`,children:e.jsx(l.Suspense,{fallback:null,children:e.jsx(Xr,{chat:s,send:i,terminal:a})})}),e.jsx("div",{className:`view-pane ${g==="git"?"":"hidden"}`,children:e.jsx(Sr,{chat:s,send:i,terminal:a,active:g==="git",onSwitchToTerminal:()=>y("terminal")})}),L.map(F=>{const ee=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${g===ee?"":"hidden"}`,children:e.jsx(Tr,{entry:F,send:i})},F.info.id)})]})}),e.jsx(br,{chat:s,send:i}),d&&e.jsx($r,{file:d,content:s.fileContent,send:i,onAddLines:(F,ee,oe,be)=>m(F,ee,"lines",!1,{start:oe,end:be}),onAttach:(F,ee,oe)=>m(F,ee,oe),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!S&&!U&&e.jsx(Er,{send:i,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>w(!0)}),U&&e.jsx(Rr,{send:i,providers:s.modelsConfig,providerStatus:s.providers,providerKeys:s.providerKeys,fetchModelsResult:s.fetchModelsResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>G(!1)}),ue&&e.jsx(Dr,{chat:s,send:i,terminal:a,onSwitchToTerminal:()=>y("terminal"),onClose:()=>v(!1)}),B&&e.jsx(_r,{servers:s.bgServers,send:i,onClose:()=>u(!1)}),e.jsx(Fr,{open:P,send:i,projects:s.projects,cwd:((ls=s.state)==null?void 0:ls.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>R(!1),onSwitchSession:(F,ee)=>{i({type:"switch_session",path:F});const oe=ee&&ee[0];se(oe?{path:F,role:oe.role,timestamp:oe.timestamp}:null)},onSwitchProject:F=>{i({type:"set_cwd",path:F})},onPreviewFile:(F,ee)=>{p({path:F,name:ee})}})]})}Di();Ln(In());Hn.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(Si,{children:e.jsx(tl,{})})}));export{at as F,Fs as T,me as a,al as b,Ae as c,il as d,Xs as e,_e as f,oi as g,Xe as h,Ee as i,He as r,dt as u};
323
+ `);return Y.length>0&&Y[Y.length-1]===""&&Y.pop(),Y.slice(0,Dt)},[o]),w=(o==null?void 0:o.lines)??0,U=w>Dt,G=(Y,ne)=>{if(ne){const he=K.current>0?K.current:Y;g({start:Math.min(he,Y),end:Math.max(he,Y)})}else K.current=Y,g({start:Y,end:Y})},ue=()=>{S.length!==0&&(K.current=1,g({start:1,end:S.length}))},v=()=>{h&&(r(t.path,t.name,h.start,h.end),O(!0),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>O(!1),1400))},B=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,u=()=>{q((o==null?void 0:o.text)??""),b(!1),E.current&&z(!0)},P=()=>{if(j){if(X!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;u();return}!B||!o||(E.current=Bt(t.name)&&J,Bt(t.name)&&z(!1),g(null),q(o.text),b(!0))},R=()=>{!j||!o||!B||i({type:"write_file",path:t.path,text:X})&&(b(!1),E.current&&z(!0),g(null))},V=()=>{j&&X!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||a()},se=Y=>{M(Math.min(200,Math.max(50,Y)))},Z=h?h.end-h.start+1:0,ae=(o==null?void 0:o.binary)??!1,ge=(o==null?void 0:o.truncated)??!1,fe=(o==null?void 0:o.kind)??"text",N=Bt(t.name),Q=N&&J&&!j&&fe==="text"&&!ae,ve=Y=>jt(tt(`/api/file?clientId=${encodeURIComponent(zt())}&path=${encodeURIComponent(Y)}`));return e.jsx("div",{className:`fp-overlay ${_?"fullscreen":""}`,onMouseDown:Y=>{Y.target===Y.currentTarget&&V()},children:e.jsxs("div",{className:`fp ${_?"fullscreen":""}`,style:{"--fp-zoom":D/100},children:[e.jsxs("div",{className:"fp-head",children:[e.jsx("span",{className:"fp-name",title:t.path,children:t.name}),e.jsx("span",{className:"fp-path",children:t.path}),e.jsxs("span",{className:"fp-meta",children:[o&&fe==="text"&&!ae&&n("fileLines",{n:w}),o&&` · ${Or(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[N&&fe==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${J?"on":""}`,"data-tip":n(J?"showMarkdownSource":"showMarkdownPreview"),disabled:j,onClick:()=>z(Y=>!Y),children:J?e.jsx(At,{}):e.jsx(xi,{})}),fe==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${j?"on":""}`,"data-tip":n(ge?"fileEditTruncated":j?"exitEditFile":"editFile"),disabled:!B&&!j,onClick:P,children:e.jsx(Ft,{})}),fe==="text"&&!ae&&!Q&&e.jsx("button",{type:"button",className:`fp-attach wrap ${H?"on":""}`,"data-tip":n(H?"disableWrap":"enableWrap"),onClick:()=>x(Y=>!Y),children:e.jsx(fi,{})}),fe==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:D<=50,onClick:()=>se(D-10),children:e.jsx(Xn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>M(100),children:[D,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:D>=200,onClick:()=>se(D+10),children:e.jsx(Zn,{})})]}),fe!=="video"&&fe!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(Ae,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(_t,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${_?"on":""}`,"data-tip":n(_?"exitFullscreen":"fullscreen"),onClick:()=>A(Y=>!Y),children:_?e.jsx(li,{}):e.jsx(ci,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:V,children:e.jsx(Ee,{})})]})]}),ge&&fe==="text"&&!ae&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&fe==="none"&&!ae&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&fe==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:ve(t.path),alt:t.name})}),!p&&fe==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:ve(t.path),controls:!0,preload:"metadata"})}),!p&&Q&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(wt,{text:o.text})})}),!p&&ae&&fe!=="image"&&fe!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&j&&fe==="text"&&!ae&&o&&e.jsx("textarea",{className:`fp-editor ${H?"":"no-wrap"}`,value:X,onChange:Y=>q(Y.target.value),wrap:H?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!Q&&!j&&fe==="text"&&!ae&&o&&S.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!Q&&!j&&fe==="text"&&!ae&&S.length>0&&e.jsxs("div",{className:`fp-code ${y?"dragging":""} ${H?"":"no-wrap"}`,onMouseDown:Y=>{Y.button===0&&Y.preventDefault()},children:[S.map((Y,ne)=>{const he=ne+1,m=h!==null&&he>=h.start&&he<=h.end;return e.jsxs("div",{className:`fp-line ${m?"sel":""}`,onMouseDown:ie=>{ie.button===0&&(G(he,ie.shiftKey),W.current=!0,C(!0))},onMouseEnter:()=>{W.current&&G(he,!0)},children:[e.jsx("span",{className:"fp-num",children:he}),e.jsx("span",{className:"fp-code-text",children:Y})]},he)}),U&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:Dt})})]}),e.jsx("div",{className:"fp-foot",children:j?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:n("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:P,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:X===((o==null?void 0:o.text)??""),onClick:R,children:[e.jsx(ii,{})," ",n("saveFile")]})]})]}):!Q&&fe==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:h?n("selectedRange",{n:Z,start:h.start,end:h.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:S.length===0,onClick:ue,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!h,onClick:()=>g(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!h||ae,onClick:v,children:[L?e.jsx(ct,{}):null,n(L?"addedToChat":"addToChat")]})]})]})})]})})}function Bt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Or(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Pn="pi-web-sounds",st={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function Mn(){try{const t=localStorage.getItem(Pn);if(!t)return{...st};const s=JSON.parse(t),i={...st,...s};for(const r of["enabled","question","done","start","error"])typeof i[r]!="boolean"&&(i[r]=st[r]);return typeof i.volume!="number"||!Number.isFinite(i.volume)?i.volume=st.volume:i.volume=Math.round(Math.max(0,Math.min(100,i.volume))/5)*5,i}catch{return{...st}}}function Hr(t){try{localStorage.setItem(Pn,JSON.stringify(t))}catch{}}let nt=null;function Kr(){try{if(!nt){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;nt=new t}return nt.state==="suspended"&&nt.resume(),nt}catch{return null}}const Ur=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Wr=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],qr=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],zr=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Vr={question:Ur,done:Wr,start:qr,error:zr};function Gr(t,s,i){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const a=t.currentTime+s.start,n=Math.max(1e-4,s.peak*i);c.gain.setValueAtTime(1e-4,a),c.gain.exponentialRampToValueAtTime(n,a+.012),c.gain.exponentialRampToValueAtTime(1e-4,a+s.dur),r.connect(c),c.connect(t.destination),r.start(a),r.stop(a+s.dur+.05)}function it(t,s=Mn()){if(!s.enabled||!s[t])return;const i=Kr();if(!i)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Vr[t])Gr(i,c,r)}const Ut="pi-web-ui:theme",Rn="dark",As="theme-stylesheet",Fs="pi-web-ui:theme-change";function In(){try{const t=localStorage.getItem(Ut);if(t&&t!==Rn)return t}catch{}return null}function Qr(t){try{t?localStorage.setItem(Ut,t):localStorage.removeItem(Ut)}catch{}}function Ln(t){let s=document.getElementById(As);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Fs));return}s||(s=document.createElement("link"),s.id=As,s.rel="stylesheet",document.head.appendChild(s)),s.href=tt(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(Fs))}async function Yr(){try{const t=await fetch(jt(tt("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Jr(){const[t,s]=l.useState([]),[i,r]=l.useState(()=>In());return l.useEffect(()=>{let a=!1;return Yr().then(n=>{a||s(n)}),()=>{a=!0}},[]),l.useEffect(()=>{Ln(i),Qr(i)},[i]),{themes:t,theme:i,switchTheme:a=>r(a===Rn?null:a)}}function al(){const t=getComputedStyle(document.documentElement),s=(i,r)=>t.getPropertyValue(i).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Xr=l.lazy(()=>Wn(()=>import("./TerminalPanel-DwutHqgi.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function Zr({notice:t,onDismiss:s}){const i=me(),{locale:r}=dt(),c=r==="en"&&t.textEn?t.textEn:t.text,[a,n]=l.useState(!1);l.useEffect(()=>{if(a)return;const d=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(d)},[a,t.id,t.level,s]);const o=t.level==="error"?bi:t.level==="warning"?ki:pi;return e.jsxs("div",{className:`notice notice-${t.level}${a?" paused":""}`,role:"status",onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[e.jsx(o,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:c}),e.jsx("button",{type:"button",className:"notice-close",title:i("close"),onClick:()=>s(t.id),children:e.jsx(Ee,{})})]})}const el=[],Dn=180,Bn=520,_n=240,An=t=>`pi-web-ui:${t}-panel-width`;function $s(t){const s=Number(localStorage.getItem(An(t)));return Number.isFinite(s)&&s>=Dn&&s<=Bn?s:_n}const Wt=t=>`pi-web-ui:${t}-panel-collapsed`;function Os(t){return localStorage.getItem(Wt(t))==="1"}function Hs({side:t,width:s,onResize:i}){const r=me(),c=l.useCallback(a=>{a.preventDefault();const n=a.clientX,o=s;let d=o;const p=h=>{const g=t==="left"?h.clientX-n:n-h.clientX;d=Math.min(Bn,Math.max(Dn,Math.round(o+g))),i(d)},f=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",f),document.body.classList.remove("panel-resizing"),localStorage.setItem(An(t),String(d))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",f),document.body.classList.add("panel-resizing")},[t,s,i]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>i(_n)})}function Ks({side:t,onClick:s}){const i=me();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:i("expandPanel"),onClick:s,children:t==="left"?e.jsx(en,{}):e.jsx(tn,{})})}function tl(){var Fe,Qt,Yt,Jt,Xt,Zt,es,ts,ss,ns,is,as,rs,ls;const t=me(),{chat:s,send:i,dismissNotice:r,pushNotice:c,terminal:a}=Zi(),[n,o]=l.useState([]),[d,p]=l.useState(null),[f,h]=l.useState(!1),[g,y]=l.useState("chat"),C=l.useMemo(()=>s.plugins.filter(F=>{var ee,oe;return!((oe=(ee=s.settings)==null?void 0:ee.disabledPlugins)!=null&&oe.includes(F.id))}),[s.plugins,(Fe=s.settings)==null?void 0:Fe.disabledPlugins]),[L,O]=l.useState([]);l.useEffect(()=>Ui(O),[]),l.useEffect(()=>{Wi(C,s.pluginsEpoch)},[C,s.pluginsEpoch]);const[j,b]=l.useState(()=>$s("left")),[X,q]=l.useState(()=>$s("right")),J=l.useCallback(F=>b(F),[]),z=l.useCallback(F=>q(F),[]),[E,H]=l.useState(()=>Os("left")),[x,_]=l.useState(()=>Os("right")),A=l.useCallback(()=>{H(F=>(localStorage.setItem(Wt("left"),F?"0":"1"),!F))},[]),D=l.useCallback(()=>{_(F=>(localStorage.setItem(Wt("right"),F?"0":"1"),!F))},[]),[M,K]=l.useState(null),[W,k]=l.useState(()=>window.matchMedia("(max-width: 768px)").matches);l.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),ee=oe=>k(oe.matches);return F.addEventListener("change",ee),()=>F.removeEventListener("change",ee)},[]);const[S,w]=l.useState(!1),[U,G]=l.useState(!1),[ue,v]=l.useState(!1),[B,u]=l.useState(!1),[P,R]=l.useState(!1),[V,se]=l.useState(null);l.useEffect(()=>{if(!V)return;const F=setTimeout(()=>se(null),15e3);return()=>clearTimeout(F)},[V]),l.useEffect(()=>{const F=ee=>{var Ke,os;const oe=ee.detail,be=(oe==null?void 0:oe.title)||t("pluginCommandFallback"),we=oe==null?void 0:oe.command;if(!we||!s.ready)return;const De={name:be,command:we,cwd:"${pwd}"},Ne=s.terminals.find(Nt=>Nt.title===be);if(Ne)a.restart(Ne.id),i({type:"run_command",terminalId:Ne.id,conversationId:Ne.conversationId,command:De,cols:80,rows:24});else{const Nt=He();a.create({id:Nt,conversationId:s.activeConversationId||((Ke=s.state)==null?void 0:Ke.conversationId)||"",title:be,cwd:((os=s.state)==null?void 0:os.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:De})}y("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,a,i]),l.useEffect(()=>{const F=ee=>{!(ee.ctrlKey||ee.metaKey)||ee.key.toLowerCase()!=="k"||(ee.preventDefault(),R(oe=>!oe))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[Z,ae]=l.useState(Mn),{themes:ge,theme:fe,switchTheme:N}=Jr(),Q=l.useRef(null),ve=l.useRef(null),Y=l.useRef(0),ne=l.useRef(!1),he=l.useRef(s.terminals);l.useEffect(()=>{Hr(Z)},[Z]),l.useEffect(()=>{var ee;const F=he.current;he.current=s.terminals;for(const oe of s.terminals){const be=((ee=oe.command)==null?void 0:ee.command)??"",we=F.find(De=>De.id===oe.id);!(we!=null&&we.running)||oe.running||(be.startsWith("pi remove ")?i({type:"extensions_reload"}):be.startsWith("pi-web-ui install ")||be.startsWith("pi-web-ui uninstall ")?i({type:"plugins_reload"}):be.startsWith("npm i -g ")&&(i({type:"extensions_reload"}),i({type:"plugins_reload"}),i({type:"check_updates_all",force:!0})))}},[s.terminals,i]),l.useEffect(()=>{var oe;const F=((oe=s.state)==null?void 0:oe.isStreaming)??!1,ee=Q.current;Q.current=F,ee!==null&&(!ee&&F?it("start",Z):ee&&!F&&it("done",Z))},[(Qt=s.state)==null?void 0:Qt.isStreaming,Z]),l.useEffect(()=>{var ee;const F=((ee=s.dialog)==null?void 0:ee.id)??null;F!==null&&F!==ve.current&&it("question",Z),ve.current=F},[s.dialog,Z]),l.useEffect(()=>{const F=[...s.notices].reverse().find(ee=>ee.level==="error");F&&F.id!==Y.current&&(Y.current=F.id,it("error",Z))},[s.notices,Z]);const m=(F,ee,oe,be=!1,we)=>{const De=`${F}|${oe}|${we?`${we.start}-${we.end}`:""}`;o(Ne=>Ne.some(Ke=>`${Ke.path}|${Ke.mode}|${Ke.lines?`${Ke.lines.start}-${Ke.lines.end}`:""}`===De)?Ne:[...Ne,{path:F,name:ee,mode:oe,isDir:be,...we?{lines:we}:{}}])},ie=F=>o(ee=>ee.filter(oe=>oe.key?oe.key!==F:oe.path!==F)),de=l.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&K(null),i(F)),[i]),Pe=l.useRef(0),Te=l.useRef(0),Me=F=>{var be;const ee=Date.now();(be=s.state)!=null&&be.model&&!s.state.model.vision&&ee-Te.current>1e4&&(Te.current=ee,c("warning",t("imageNotSupported")));const oe=`paste-${++Pe.current}`;o(we=>[...we,{path:"",key:oe,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},Ie=async F=>{for(const ee of F){const oe=await hn(ee);if(!oe){c("error",t("imageLoadFailed",{name:ee.name}));continue}Me(oe)}},Le=20*1024*1024,ze=l.useRef(0),Ve=async F=>{if(F.size>Le){c("warning",t("fileTooLarge",{name:F.name,size:Le/1024/1024}));return}let ee;try{ee=(await new Promise((we,De)=>{const Ne=new FileReader;Ne.onload=()=>we(Ne.result),Ne.onerror=()=>De(Ne.error??new Error("read failed")),Ne.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const oe=`upload-${++ze.current}`;o(be=>[...be,{path:"",key:oe,name:F.name,mode:"inline",fileData:ee,size:F.size,mimeType:F.type||void 0}])},I=async F=>{for(const ee of F)Oe(ee.type)?await Ie([ee]):await Ve(ee)},pe=l.useCallback((F,ee,oe)=>{i({type:"edit_message",messageId:F,text:ee,attachments:oe})},[i]),ce=l.useCallback((F,ee)=>{i({type:"queue_remove",kind:F,text:ee})},[i]),je=l.useCallback(()=>G(!0),[]),xe=l.useCallback(()=>o([]),[]),Ce=l.useCallback(ie,[]),T=l.useCallback(Ie,[Ie]),$=l.useCallback(I,[I]),re=(Yt=s.state)==null?void 0:Yt.model,le=(Jt=s.state)==null?void 0:Jt.thinkingLevel,ye=(Xt=s.state)==null?void 0:Xt.availableThinkingLevels,ke=l.useMemo(()=>re?{model:re,thinkingLevel:le??"off",availableThinkingLevels:ye??[]}:null,[re,le,ye]),Se=l.useCallback(()=>{var F,ee;return!s.ready||s.terminals.length!==0?!1:(a.create({id:He(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((ee=s.state)==null?void 0:ee.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Zt=s.state)==null?void 0:Zt.cwd,s.terminals.length,t,a]);return l.useEffect(()=>{if(ne.current){if(g!=="terminal"||s.terminals.length!==0){ne.current=!1;return}Se()&&(ne.current=!1)}},[s.terminals.length,Se,g]),e.jsxs("div",{className:"app",onDragOver:F=>{var ee;Array.from(((ee=F.dataTransfer)==null?void 0:ee.types)??[]).includes("Files")&&(F.preventDefault(),h(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||h(!1)},onDrop:F=>{var we,De;if(h(!1),!Array.from(((we=F.dataTransfer)==null?void 0:we.types)??[]).includes("Files"))return;F.preventDefault();const ee=Array.from(((De=F.dataTransfer)==null?void 0:De.files)??[]);if(ee.length===0){c("warning",t("foldersNotSupported"));return}const oe=ee.filter(Ne=>Oe(Ne.type)),be=ee.filter(Ne=>!Oe(Ne.type));oe.length>0&&Ie(oe),be.length>0&&I(be)},children:[f&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(Ei,{chat:s,send:i,terminal:a,view:g,plugins:C,onViewChange:F=>{ne.current=F==="terminal"&&s.terminals.length===0,ne.current&&Se()&&(ne.current=!1),y(F),K(null)},onOpenPanel:K,onOpenSettings:()=>v(!0),onOpenBgTasks:()=>u(!0),onOpenGlobalSearch:()=>R(!0),sound:Z,onSoundChange:ae,onSoundPreview:F=>it(F,Z),themes:ge,theme:fe,onThemeChange:N}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(Zr,{notice:F,onDismiss:r},F.id))}),e.jsx(tr,{send:i,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${j}px`,"--right-w":`${X}px`},children:[M&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>K(null)}),e.jsxs("div",{className:`view-pane ${g==="chat"?"":"hidden"}`,children:[!W&&E&&e.jsx(Ks,{side:"left",onClick:A}),e.jsx("div",{className:`panel-drawer drawer-left ${M==="left"?"open":""}${W?"":E?" hidden":""}`,children:e.jsx(Li,{collapsible:!W,onToggleCollapse:A,send:de,active:!W||M==="left",ready:s.ready,status:s.status,cwd:((es=s.state)==null?void 0:es.cwd)??"",sessionFile:((ts=s.state)==null?void 0:ts.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!W&&e.jsx(Hs,{side:"left",width:j,onResize:J}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(lr,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:pe,onKillBash:()=>i({type:"abort_bash"}),onRemoveQueued:ce,thinkingWrap:((ss=s.settings)==null?void 0:ss.thinkingWrap)??!0,toolsWrap:((ns=s.settings)==null?void 0:ns.toolsWrap)??!0,jumpTarget:V,onJumpDone:()=>se(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(fr,{send:i,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(wr,{dialog:s.dialog,send:i}),s.question&&e.jsx(Nr,{question:s.question,send:i}),e.jsx(gr,{send:i,ready:s.ready,streaming:((is=s.state)==null?void 0:is.isStreaming)??!1,messages:((as=s.state)==null?void 0:as.messages)??el,slashCommands:s.slashCommands,modelState:ke,models:s.models,modelsLoading:s.modelsLoading,providerKeys:s.providerKeys,attachments:n,onRemoveAttachment:Ce,onAddImageFiles:T,onAddLocalFiles:$,onNotice:c,onManageModels:je,onSent:xe})]}),!W&&e.jsx(Hs,{side:"right",width:X,onResize:z}),e.jsx("div",{className:`panel-drawer drawer-right ${M==="right"?"open":""}${W?"":x?" hidden":""}`,children:e.jsx(oa,{collapsible:!W,onToggleCollapse:D,send:de,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((rs=s.state)==null?void 0:rs.cwd)??"",onAttach:(F,ee,oe,be)=>{K(null),m(F,ee,oe,be)},onPreview:(F,ee)=>{K(null),p({path:F,name:ee})},onNotice:(F,ee)=>c(F,ee)})}),!W&&x&&e.jsx(Ks,{side:"right",onClick:D})]}),e.jsx("div",{className:`view-pane ${g==="terminal"?"":"hidden"}`,children:e.jsx(l.Suspense,{fallback:null,children:e.jsx(Xr,{chat:s,send:i,terminal:a})})}),e.jsx("div",{className:`view-pane ${g==="git"?"":"hidden"}`,children:e.jsx(Sr,{chat:s,send:i,terminal:a,active:g==="git",onSwitchToTerminal:()=>y("terminal")})}),L.map(F=>{const ee=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${g===ee?"":"hidden"}`,children:e.jsx(Tr,{entry:F,send:i})},F.info.id)})]})}),e.jsx(br,{chat:s,send:i}),d&&e.jsx($r,{file:d,content:s.fileContent,send:i,onAddLines:(F,ee,oe,be)=>m(F,ee,"lines",!1,{start:oe,end:be}),onAttach:(F,ee,oe)=>m(F,ee,oe),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!S&&!U&&e.jsx(Er,{send:i,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>w(!0)}),U&&e.jsx(Rr,{send:i,providers:s.modelsConfig,providerStatus:s.providers,providerKeys:s.providerKeys,fetchModelsResult:s.fetchModelsResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>G(!1)}),ue&&e.jsx(Dr,{chat:s,send:i,terminal:a,onSwitchToTerminal:()=>y("terminal"),onClose:()=>v(!1)}),B&&e.jsx(_r,{servers:s.bgServers,send:i,onClose:()=>u(!1)}),e.jsx(Fr,{open:P,send:i,projects:s.projects,cwd:((ls=s.state)==null?void 0:ls.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>R(!1),onSwitchSession:(F,ee)=>{i({type:"switch_session",path:F});const oe=ee&&ee[0];se(oe?{path:F,role:oe.role,timestamp:oe.timestamp}:null)},onSwitchProject:F=>{i({type:"set_cwd",path:F})},onPreviewFile:(F,ee)=>{p({path:F,name:ee})}})]})}Di();Ln(In());Hn.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(Si,{children:e.jsx(tl,{})})}));export{at as F,Fs as T,me as a,al as b,Ae as c,il as d,Xs as e,_e as f,oi as g,Xe as h,Ee as i,He as r,dt as u};