pi-web-ui 0.34.1 → 0.34.3
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,19 +1,19 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-
|
|
2
|
-
import{R as Pe,a as i,j as e,M as fs,b as Ys,c as Xs}from"./markdown-DRBrS2Nf.js";import{r as xs}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"]'))o(c);new MutationObserver(c=>{for(const r of c)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function n(c){const r={};return c.integrity&&(r.integrity=c.integrity),c.referrerPolicy&&(r.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?r.credentials="include":c.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function o(c){if(c.ep)return;c.ep=!0;const r=n(c);fetch(c.href,r)}})();var Ge={},At;function Zs(){if(At)return Ge;At=1;var t=xs();return Ge.createRoot=t.createRoot,Ge.hydrateRoot=t.hydrateRoot,Ge}var en=Zs();const tn="modulepreload",sn=function(t){return"/"+t},Ot={},vs=function(s,n,o){let c=Promise.resolve();if(n&&n.length>0){let a=function(m){return Promise.all(m.map(f=>Promise.resolve(f).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));c=a(n.map(m=>{if(m=sn(m),m in Ot)return;Ot[m]=!0;const f=m.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${h}`))return;const k=document.createElement("link");if(k.rel=f?"stylesheet":tn,f||(k.as="script"),k.crossOrigin="",k.href=m,u&&k.setAttribute("nonce",u),document.head.appendChild(k),f)return new Promise((N,M)=>{k.addEventListener("load",N),k.addEventListener("error",()=>M(new Error(`Unable to preload CSS for ${m}`)))})}))}function r(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return c.then(a=>{for(const l of a||[])l.status==="rejected"&&r(l.reason);return s().catch(r)})};var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ht=Pe.createContext&&Pe.createContext(ys),nn=["attr","size","title"];function an(t,s){if(t==null)return{};var n,o,c=rn(t,s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(o=0;o<r.length;o++)n=r[o],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(c[n]=t[n])}return c}function rn(t,s){if(t==null)return{};var n={};for(var o in t)if({}.hasOwnProperty.call(t,o)){if(s.indexOf(o)!==-1)continue;n[o]=t[o]}return n}function Xe(){return Xe=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Xe.apply(null,arguments)}function Wt(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);s&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),n.push.apply(n,o)}return n}function Ze(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Wt(Object(n),!0).forEach(function(o){on(t,o,n[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wt(Object(n)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(n,o))})}return t}function on(t,s,n){return(s=ln(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function ln(t){var s=cn(t,"string");return typeof s=="symbol"?s:s+""}function cn(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var o=n.call(t,s);if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function js(t){return t&&t.map((s,n)=>Pe.createElement(s.tag,Ze({key:n},s.attr),js(s.child)))}function q(t){return s=>Pe.createElement(dn,Xe({attr:Ze({},t.attr)},s),js(t.child))}function dn(t){var s=n=>{var o=t.attr,c=t.size,r=t.title,a=an(t,nn),l=c||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),Pe.createElement("svg",Xe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,o,a,{className:u,style:Ze(Ze({color:t.color||n.color},n.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),r&&Pe.createElement("title",null,r),t.children)};return Ht!==void 0?Pe.createElement(Ht.Consumer,null,n=>s(n)):s(ys)}function un(t){return q({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 mn(t){return q({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 xt(t){return q({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 Se(t){return q({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 bs(t){return q({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 pn(t){return q({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 Fe(t){return q({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 Ve(t){return q({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 qt(t){return q({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 hn(t){return q({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 et(t){return q({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 tt(t){return q({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 gn(t){return q({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 st(t){return q({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 fn(t){return q({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 St(t){return q({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 q({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 Pi(t){return q({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 Ut(t){return q({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 xn(t){return q({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 vn(t){return q({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 yn(t){return q({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 nt(t){return q({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 jn(t){return q({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 bn(t){return q({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 kn(t){return q({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 wn(t){return q({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 vt(t){return q({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 at(t){return q({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 Nn(t){return q({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"},child:[]}]})(t)}function Cn(t){return q({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 Sn(t){return q({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 zt(t){return q({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 Qe(t){return q({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 Oe(t){return q({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 ks(t){return q({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 Tn(t){return q({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 ws(t){return q({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 yt(t){return q({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 Kt(t){return q({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 Tt(t){return q({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 it(t){return q({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 Mn(t){return q({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 Mt(t){return q({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 En(t){return q({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 rt(t){return q({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 ot(t){return q({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 Ie(t){return q({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 lt(t){return q({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 Rn(t){return q({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 Ns(t){return q({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 Ln(t){return q({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 Cs(t){return q({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 Ss(t){return q({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 Pn(t){return q({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 In(t){return q({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 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 n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.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 Re({trigger:t,open:s,onOpenChange:n,children:o,align:c="right",fit:r=!1,direction:a="down",menuClassName:l}){const u=i.useRef(null);return i.useEffect(()=>{if(!s)return;const m=h=>{u.current&&!u.current.contains(h.target)&&n(!1)},f=h=>{h.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",f)}},[s,n]),e.jsxs("div",{className:`dropdown ${c} ${r?"fit":""} ${a==="up"?"dd-up":""}`,ref:u,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(Ie,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${l??""}`,children:o})]})}function we({active:t,disabled:s=!1,title:n,onClick:o,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:o,children:c})}const Ts="pi-web-ui:lang",Bn={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",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:"插件状态",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",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:"排队",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/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)。",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",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:"插件请求",noOptions:"(无选项)",inputPlaceholder:"输入内容",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 密钥即可开始对话:",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":"上下文已压缩",welcomeTitle:"pi 编码智能体",welcomeSub:"检查、编辑、运行 —— 随时待命",directory:"目录",clickToFill:"点击填入输入框",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:同时搜索历史对话、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索文件…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","ex.understand":"了解这个项目","ex.understand.prompt":"介绍一下这个项目:整体结构、主要模块和如何运行?","ex.debug":"排查一个问题","ex.debug.prompt":"帮我排查一个 bug,请先说明问题现象,我会补充细节。","ex.test":"编写测试","ex.test.prompt":"为项目的核心模块编写单元测试。","ex.review":"代码审查","ex.review.prompt":"审查最近改动的代码,指出潜在问题和改进建议。",error:"出错",done:"完成",running:"执行中…",toolQueued:"排队中",copyArgs:"复制参数",errorOutput:"错误输出",output:"输出",waitingOutput:"等待输出…",toolDoneWaitingModel:"已结束 · 等模型",waitingModel:"等待模型响应…",thinkingNow:"思考中",thinkingPreview:"思考:{preview}",commands:"命令",newCommand:"新建命令",newTerminal:"新建终端",name:"名称",command:"命令",cwdHint:"(${pwd} = 当前工作目录)",noCommands:"还没有命令,点 + 添加一个",clickToRun:"点击运行",edit:"编辑",delete:"删除",confirmQ:"确认?",builtinTerminal:"内置终端",termEmptySub:"点击左侧命令运行,或点右侧 + 新建终端",noTerminal:"暂无终端",exited:"(已退出{code})",closeTerminal:"关闭终端",rerun:"重新读取 .pi/commands.json",terminalTitle:"终端 {n}",exampleName:"例如:启动开发服务器",exampleCommand:"例如:npm run dev",scmTab:"Git",scmTitle:"源代码管理",scmRefreshTip:"重新查询 Git 状态与差异",scmCurrentBranch:"当前分支",scmUpstreamGone:"上游已删除",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"分离 HEAD",scmSelectBranch:"选择分支…",scmRemoteBranches:"远程分支",scmStageTip:"暂存 {path}",scmUnstageTip:"取消暂存 {path}",scmSwitch:"切换",scmSwitchBranch:"切换分支",scmSwitchBranchTip:"在终端中执行 git checkout {branch}",scmPush:"推送",scmPushTip:"在终端中执行 git push",scmPull:"拉取",scmPullTip:"在终端中执行 git pull",scmCommit:"提交",scmCommitTip:'在终端中执行 git add -A && git commit -m "…"(提交全部更改,含未跟踪)',scmCommitPlaceholder:"输入提交信息…",scmChanges:"更改",scmHistory:"提交树",scmCommitDetail:"提交详情",scmSelectCommitHint:"点击左侧提交查看详情",scmNoHistory:"暂无提交记录",scmNoChanges:"工作区干净,没有更改",scmNotGitRepo:"当前目录不是 Git 仓库",scmLoading:"查询中…",scmConnecting:"等待连接…",scmDiff:"差异",scmSelectFileHint:"点击左侧文件查看差异",scmNoDiff:"(无差异)",scmStaged:"已暂存",scmUnstaged:"未暂存",scmStagedUnstaged:"已暂存 + 未暂存",scmUntracked:"未跟踪",scmUntrackedNote:"未跟踪文件:差异不显示,提交时会一并包含",scmQueryFailed:"Git 查询失败:{error}",scmTooManyFailures:"Git 查询连续失败,请点击刷新重试",scmRunsInTerminal:"提交 / 切换分支 / 推送 / 拉取在终端中执行",scmViewTerminal:"去终端",editProvider:"编辑服务商",builtinProviders:"内置服务商",hintKeyOnly:"只需填入 API 密钥",configuredBadge:"✓ 已配置",keyReady:"密钥已就绪",replaceKey:"更换密钥",replaceKeyTitle:"替换已保存的密钥",clearKey:"清空",clearKeyTitle:"清除该服务商保存在 auth.json 的密钥,回到未配置状态(环境变量来源的无法在此清除)",clearKeyConfirm:"清空 {id} 已保存的密钥?其模型将从列表消失,直到重新配置。",cloneProvider:"复制为自定义",cloning:"复制中",cloneProviderTitle:"复制该内置供应商(baseUrl + 模型列表)为自定义供应商,填入另一个 API 密钥即可双 key 并存",pasteKey:"粘贴 API 密钥…",savingKey:"保存中",saveKey:"保存密钥",customProviders:"自定义服务商",customDesc:"用于 Ollama / vLLM / 兼容 OpenAI 的代理等,写入 pi 的 models.json,保存后热重载、立即生效。",noCustomProviders:"还没有自定义服务商",modelsCount:"{n} 个模型",addProvider:"新增服务商",providerId:"服务商 ID",providerIdHint:"(必填,如 ollama / my-proxy)",displayName:"显示名",displayNamePh:"我的代理",apiType:"API 类型",baseUrlHint:"(OpenAI 兼容端点)",apiKeyHint:"sk-…(可留空,用 auth.json 的密钥)",authHeader:"自动添加 Authorization 请求头",modelsTitle:"模型",modelIdReq:"模型 ID(必填)",text:"文本",textImage:"文本+图片",contextWindow:"上下文",maxOutput:"最大输出",removeModel:"移除模型",addModel:"添加模型",deleteProviderConfirm:"删除服务商 {id} 及其 {n} 个模型?",fetchModels:"自动获取模型列表",fetchModelsHint:"从 baseUrl 的 /models 接口自动拉取模型 ID(服务端请求,不受 CORS 限制)",fetchingModels:"获取中…",fetchModelsOk:"已获取 {n} 个模型",fetchModelsEmpty:"接口未返回任何模型",fetchModelsErr:"获取失败:{msg}",fetchModelsNeedBaseUrl:"请先填写 baseUrl 再获取",goalBarTitle:"目标",goalBarPlaceholder:"设定一个目标,agent 完成后自动审查…",goalBarSet:"开始",goalBarClear:"取消",goalBarLocked:"锁定:应用到后续所有回合",goalBarUnlocked:"仅本回合(改完自动清除)",goalBarReviewModel:"审查模型",goalBarUseMainModel:"使用主模型",goalBarMaxRounds:"最大轮数",goalBarMaxRoundsTip:"最大审查重改轮数;0 或不填 = 不限(持续改到通过)",goalBarUnlimitedShort:"不限",goalBarReviewing:"审查中…",goalBarRound:"第 {n} 轮",goalBarActive:"目标生效中",goalBarPassed:"已通过",goalBarFailed:"未通过",goalBarStatusPending:"等待生成…",goalWizardBtn:"AI 提炼",goalWizardTip:"让 AI 通过问卷调研细化需求,收敛为目标",goalWizardRunning:"目标调研中",goalWizardAnswer:"回答",goalWizardCard:"目标调研",settings:"设置",settingsTitle:"设置",settingsDesc:"修改立即生效:系统提示词、技能与插件开关会重建当前会话;审查提示词与审查技能只影响后续目标审查(回复进行中则主会话变更自动延迟)。",settingsSystemPrompt:"系统提示词",settingsPromptMode:"模式",promptModeAppend:"追加",promptModeReplace:"替换",promptAppendHint:"追加模式:自定义内容拼接到默认系统提示词末尾(推荐,保留默认行为约束)。",promptReplaceHint:"替换模式:完全用自定义内容替换系统提示词(项目上下文与技能段仍会自动附加)。切换后输入框会显示原本的默认提示词,可直接修改;不改动失焦则仍使用默认。",promptPlaceholder:"输入自定义系统提示词…(失焦后自动应用)",settingsViewPrompt:"查看当前完整提示词",settingsViewPromptHint:"当前会话实际生效的完整系统提示词(含自定义追加/替换内容、项目上下文、技能说明与工具引导),只读。",settingsViewPromptEmpty:"会话尚未就绪,暂无系统提示词。",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",settingsTerminalTools:"终端工具",terminalToolsEnabled:"启用持久终端工具",settingsTerminalToolsDesc:"让 AI 在交互式程序(REPL/vim)、长驻服务、需要持续观察输出或你要求在可见终端操作时,使用内置终端;普通命令仍走一次性 bash 工具",terminalToolsOffHint:"已关闭:AI 无法使用 terminal_* 工具,也不会收到相关使用引导",terminalBashTakeover:"终端接管 bash",terminalBashTakeoverDesc:"bash 命令改在持久可见终端里执行:完整输出自动返回、shell 状态跨调用保留(cd/venv/ssh);命令静默超时自动转后台并在结束后主动通知 AI",terminalBashIdleMs:"静默转后台阈值(毫秒)",terminalBashIdleMsDesc:"命令连续无输出达到该时长即不再阻塞等待,转入后台继续运行并通知 AI;0 = 一直等到命令结束(默认 15000)",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",uninstallExt:"卸载",uninstallConfirm:"确认卸载?",uninstallConfirmHint:"再次点击确认,将在终端执行 pi remove",uninstallHint:"通过可见终端执行 pi remove 卸载此包,完成后自动刷新列表",uninstallTitle:"卸载",settingsExtensions:"插件",settingsUiPlugins:"界面插件",noUiPlugins:"未安装界面组件(<dataDir>/plugins/)",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},Dn={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",widgetExpand:"Click to view full output",dragToResize:"Drag to resize · double-click to reset",loading:"Loading…",connected:"Connected",connecting:"Connecting…",reconnecting:"Reconnecting…",language:"Language",langZh:"中文",langEn:"English",githubRepo:"GitHub repository (xing-shuyin/pi-web-ui)",copy:"Copy",viewSwitch:"Switch view",chat:"Chat",terminal:"Terminal",selectModel:"Select model",availableModels:"Available models",noModels:"No models available (configure an API key first)",reasoning:"reasoning",vision:"vision",refreshModels:"Refresh model list (keeps manual rows, merges new ones)",manageModels:"⚙ Manage models (add / edit)",manageModelsTitle:"Manage models",thinkingLevel:"Thinking level",thinking:"Thinking",thinkingChip:"Thinking: {level}",sound:"Sound",theme:"Theme",themeDefault:"Dark (default)",newChat:"New chat",more:"More",newChatTip:"New chat (sessions are saved per browser)","thinking.off":"Off","thinking.minimal":"Minimal","thinking.low":"Low","thinking.medium":"Medium","thinking.high":"High","thinking.xhigh":"Extra high","thinking.max":"Max",thinkingUnsupported:"Not supported by this model — snapped to the nearest supported level",context:"Context",contextUsage:"Context usage",cumulativeCost:"Cumulative cost",sessionMessages:"Session messages",messages:"messages",pluginStatus:"Plugin status",working:"Working",queued:"queued",enterPath:"Type a path, Enter to switch",cwdTip:"Working directory: {path} (click to switch)",folderRef:"Folder reference: {path}",refOnly:"Reference only: {path}",attachContent:"Attached content: {path}",attachLines:"Attached selected lines: {path} (lines {start}-{end})",attachImage:"Image: {name}",attachFile:"File: {name}",removeAttachment:"Remove attachment",attachHint:"Will be sent with the next message",uploadFile:"Add files (images / text / any file — or drag in / paste a screenshot)",dropHereToAttach:"Release to attach file",imageNotSupported:"The current model doesn't support vision — images will be transcribed by the vision bridge (may be ignored if no vision model is configured)",imageLoadFailed:"Couldn't read image: {name}",fileLoadFailed:"Couldn't read file: {name}",fileTooLarge:"File too large, skipped (> {size}MB): {name}",foldersNotSupported:"Folders can't be dropped directly — expand and pick files instead",placeholderStreaming:"The agent is working… press Enter to steer, or click Queue to send after the reply finishes",placeholderIdle:"Message pi — Enter to send, / for commands",placeholderConnecting:"Connecting to server…",stopAgent:"Stop agent",stop:"Stop",bgTasks:"Background tasks",bgTasksTip:"Servers the AI started in the background (npm run dev & etc.) — stop them individually or all at once; they survive the conversation",bgTasksEmpty:"No background tasks",bgTasksDesc:"Processes the AI started that are still listening (detected by port)",bgTaskPort:"Port",bgTaskPid:"PID",bgTaskSince:"Started",bgTaskStop:"Stop",bgTaskStopAll:"Stop all",bgTaskRefresh:"Refresh",bgTaskJustNow:"just now",bgTaskMinutes:"{n} min ago",bgTaskHours:"{n} hr ago",bgTaskDays:"{n} days ago",stopBash:"Stop",stopBashTip:"Stop the running bash command (conversation continues)",supplement:"Queue",supplementTip:"Add to queue: sent only after the whole run finishes (no interruption)",queueSteerTag:"Steer",queueFollowTag:"Queued",sendTip:"Send (Enter)",slashCommands:"Commands",slashMenuHint:"↑↓ select · Enter/Tab complete",slashHelpTitle:"pi commands",slashHelpHint:"Type / anytime to open the command list",slashLoading:"Loading commands… (available once connected)",slashBuiltin:"Builtin",slashExtension:"Extension",slashPrompt:"Template",slashSkill:"Skill",slashCopied:"Copied the last assistant reply",slashCopyFailed:"Copy failed — please copy manually",slashCopyEmpty:"No assistant reply to copy yet",recentProjects:"Recent projects",runningConversations:"Running chats",historySessions:"History",openHistory:"History",openFiles:"Files",streaming:"Streaming…",noHistory:"No previous chats",current:"Current",messageCount:"{n} messages",tuiTip:"Chat in the pi terminal (TUI)",deleteProject:"Remove from recent projects",deleteProjectConfirm:"Confirm remove",deleteSession:"Delete this chat transcript permanently",deleteSessionConfirm:"Confirm delete",emptyChat:"Empty chat",editReask:"Edit & re-ask",editReaskTip:"Edit this question and re-ask from here (forks a new conversation; the original is kept)",reaskFromHere:"Re-ask from here",editPlaceholder:"Edit the question…",editHint:"⌘/Ctrl+Enter to submit · Esc to cancel",expandMsg:"Expand",collapseMsg:"Collapse",toolCalls:"tool calls",bashRuns:"bash runs",images:"images",update:"Update",updateTip:"Check & update pi-web-ui",currentVersion:"Current version",latestVersion:"Latest version",checkingUpdate:"Checking…",checkUpdate:"Check for updates",upToDate:"You're up to date",updateAvailable:"New version v{version} available",updateJustPublished:"v{version} was just published — npm cache may lag; if the new version isn't detected yet, re-check in a moment",updateNow:"Update in terminal",updateTabTitle:"Update pi-web-ui",updateTerminalHint:"Clicking runs npm i -g pi-web-ui@latest in a visible terminal; restart the service afterwards to take effect (pi-web-ui server restart).",rootDir:"Root",noFiles:"No files",filesTruncated:"Directory too large — list truncated (first 2000 shown)",linkFolderTip:"Link folder path to chat",attachInlineTip:"Attach content to chat",referenceTip:"Reference path only (AI reads on demand)",previewFile:"Preview",downloadFile:"Download file",downloadFailed:"Download failed: {error}",protocolMismatch:"Page version differs from the server (the app was just updated). Refresh the page to restore full functionality.",selectLinesHint:"Click a line to select; drag or Shift+click for a range",enableWrap:"Enable line wrap",disableWrap:"Disable line wrap",selectedRange:"Selected {n} lines (lines {start}-{end})",fileLines:"{n} lines",selectAll:"Select all",clearSelection:"Clear",addToChat:"Add to chat",addedToChat:"Added",previewTruncated:"⚠ File too large — previewing the first 512KB",previewLinesTruncated:"… too many lines — showing the first {n}",binaryFile:"🔣 Binary file — first 4KB shown as hex",binaryHexTruncated:" (file larger — download for the full file)",previewNotSupported:"This file type can't be previewed (only images / videos / text)",emptyFile:"(empty file)",editFile:"Edit file",exitEditFile:"Exit editing",saveFile:"Save file",discardFileChanges:"Discard unsaved changes?",fileSaved:"Saved",fileEditTruncated:"The preview is incomplete, so this file can't be edited",showMarkdownSource:"Show Markdown source",showMarkdownPreview:"Show Markdown preview",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",zoomIn:"Increase font size",zoomOut:"Decrease font size",resetZoom:"Reset zoom",pluginRequest:"Plugin request",noOptions:"(no options)",inputPlaceholder:"Enter content",soundHeader:"Sound notifications",enableSound:"Enable sound",preview:"Preview",volume:"Volume","sound.question":"Question popup","sound.question.desc":"When ask_user_question appears","sound.done":"Reply finished","sound.done.desc":"When the agent finishes a turn","sound.start":"Reply started","sound.start.desc":"When the agent starts a new turn","sound.error":"Error","sound.error.desc":"When an error notice appears",setupTitle:"pi agent config not detected",setupDesc:"pi-web-ui needs pi's config directory (~/.pi/agent) and at least one API key to run the agent. pi has built-in providers such as openai, anthropic, and deepseek — just pick one and enter a key, no terminal needed.",installFailed:"✖ pi agent installation failed:",retryInstall:"Retry install",skip:"Skip",installDone:"✅ pi agent CLI installed. Pick a provider and enter an API key to start chatting:",provider:"Provider",configured:"configured",providerKeyReady:"This provider already has a key — use it or replace it.",apiKey:"API key",saving:"Saving…",saveAndStart:"Save and start using",recheck:"Recheck",installing:"Installing pi agent CLI…",autoInstall:"Auto-install pi agent",attachment:"Attachment",plugin:"plugin",unknown:"unknown",thinkingWait:"Thinking",exitCode:"Exit code {code}",cancelled:"Cancelled",truncated:"… content too long, truncated in this view",outputTruncated:"… output too long, truncated in this view",refOnlyShort:"Reference only",folderRefShort:"Folder · reference only",inlineLines:"Inline · {n} lines",inlineLinesRange:"Lines {start}-{end}",image:"🖼 Image",bridgedVision:"👁 Transcribed",bridgedVisionDetail:"Image transcribed by the vision bridge (current model can't see images)",folderNotExpanded:"Folder — content not expanded, the agent will browse it as needed",fileNotExpanded:"Large file ({size}) — content not expanded, the agent will read it as needed","role.user":"You","role.assistant":"pi","role.tool":"Tool","role.bash":"Terminal","role.branch":"Branch summary","role.compaction":"Context compacted",welcomeTitle:"pi coding agent",welcomeSub:"Inspect, edit, run — always ready",directory:"Directory",clickToFill:"Click to fill input",waitingResponse:"Waiting for model response…",backToBottom:"Back to bottom",questionNavTitle:"Questions",searchPlaceholder:"Search in conversation…",searchNoResults:"No results",searchModels:"Filter models…",noModelMatches:"No matching models",searchGlobal:"Search",searchGlobalTip:"Global search: sessions / projects / files (Ctrl+K)",gsPlaceholder:"Search projects, past conversations, workspace files…",gsHint:"Type to search session history, recent projects and file names in the current workspace at once",gsSessions:"Conversations",gsProjects:"Projects",gsFiles:"Files",gsNoResults:"No matches",gsSearching:"Searching files…",gsTruncated:"Too many matches — showing a subset",gsCurrentProject:"current",gsOpenPreview:"Open file preview",gsNavigate:"select",gsOpen:"open",gsCloseHint:"close",bgTaskCommand:"Command",searchPrev:"Previous (Shift+Enter)",searchNext:"Next (Enter)",searchClose:"Close (Esc)",questionNavTip:"All questions in this conversation — hover to expand, click to jump","ex.understand":"Understand this project","ex.understand.prompt":"Introduce this project: overall structure, main modules, and how to run it?","ex.debug":"Debug an issue","ex.debug.prompt":"Help me debug a bug — describe the symptom first, and I'll add details.","ex.test":"Write tests","ex.test.prompt":"Write unit tests for the core modules.","ex.review":"Code review","ex.review.prompt":"Review the recently changed code and point out potential issues and improvements.",error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"Run bash commands inside the persistent visible terminal: full output returned automatically, shell state retained across calls (cd/venv/ssh); silent commands move to the background and notify the AI when they finish",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"When a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",settingsPresets:"Presets",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},Ms=i.createContext(null);function _n(){try{const t=localStorage.getItem(Ts);if(t==="zh"||t==="en")return t}catch{}return"zh"}function $n({children:t}){const[s,n]=i.useState(_n),o=i.useCallback(a=>{n(a);try{localStorage.setItem(Ts,a)}catch{}},[]),c=i.useCallback((a,l)=>{let u=Dn[a];if(s==="zh"&&(u=Bn[a]),l)for(const[m,f]of Object.entries(l))u=u.replaceAll(`{${m}}`,String(f));return u},[s]);i.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const r=i.useMemo(()=>({locale:s,setLocale:o,t:c}),[s,o,c]);return e.jsx(Ms.Provider,{value:r,children:t})}function Et(){const t=i.useContext(Ms);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function he(){return Et().t}const Fn=["off","minimal","low","medium","high","xhigh","max"],Es=i.memo(function({state:s,models:n,modelsLoading:o,send:c,onManageModels:r,compact:a=!1}){const l=he(),u=s==null?void 0:s.model,m=u?`${u.provider}/${u.id}`:null,[f,h]=i.useState(!1),[k,N]=i.useState(!1),[M,D]=i.useState("");i.useEffect(()=>{f||D("")},[f]);const S=i.useMemo(()=>{const v=M.trim().toLowerCase();return v?n.filter(w=>w.name.toLowerCase().includes(v)||w.provider.toLowerCase().includes(v)||w.id.toLowerCase().includes(v)):n},[n,M]),[I,$]=i.useState(!1),p=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,C=Fn.map(v=>({value:v,label:l(`thinking.${v}`),supported:p?p.has(v):!0})),T=v=>{var w;return((w=C.find(d=>d.value===v))==null?void 0:w.label)??v};return i.useEffect(()=>{f&&n.length===0&&!I&&!o&&($(!0),c({type:"list_models"}))},[f,n.length,I,o,c]),i.useEffect(()=>{n.length>0&&$(!1)},[n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(it,{}),e.jsx("span",{className:"chip-model",children:u?u.name:l("selectModel")}),!a&&(u==null?void 0:u.vision)&&e.jsx("span",{className:"chip-vision",title:l("vision"),children:"🖼"}),!a&&u&&e.jsx("span",{className:"chip-sub",children:u.provider})]}),open:f,onOpenChange:h,menuClassName:"dd-menu-model",children:[e.jsx("div",{className:"dd-header",children:l("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(st,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:l("searchModels"),value:M,onChange:v=>D(v.target.value)})]}),e.jsxs("div",{className:"dd-model-scroll",children:[(I||o)&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.length===0&&!I&&!o&&e.jsx("div",{className:"dd-loading",children:l("noModels")}),S.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:l("noModelMatches")}),S.map(v=>e.jsx(we,{active:m===v.id,onClick:()=>{m!==v.id&&c({type:"set_model",modelId:v.id}),h(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:v.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:v.provider}),(v.reasoning||v.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[v.reasoning&&e.jsx("span",{className:"dd-model-badge",children:l("reasoning")}),v.vision&&e.jsx("span",{className:"dd-model-badge",children:l("vision")})]})]})]})},v.id))]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:l("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{h(!1),r()},children:l("manageModels")})]})]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(xt,{}),e.jsx("span",{className:"chip-sub",children:l("thinkingChip",{level:s?T(s.thinkingLevel):"—"})})]}),open:k,onOpenChange:N,children:[e.jsx("div",{className:"dd-header",children:l("thinkingLevel")}),C.map(v=>e.jsx(we,{active:(s==null?void 0:s.thinkingLevel)===v.value,disabled:!v.supported,title:v.supported?void 0:l("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==v.value&&c({type:"set_thinking",level:v.value}),N(!1)},children:v.label},v.value))]})]})}),An=[{kind:"question",labelKey:"sound.question",descKey:"sound.question.desc"},{kind:"done",labelKey:"sound.done",descKey:"sound.done.desc"},{kind:"start",labelKey:"sound.start",descKey:"sound.start.desc"},{kind:"error",labelKey:"sound.error",descKey:"sound.error.desc"}];function Vt({settings:t,onChange:s,onPreview:n}){const o=he(),c=r=>s({...t,...r});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:o("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(bs,{className:"sound-icon"}),e.jsx("span",{children:o("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:r=>c({enabled:r.target.checked})})]}),An.map(({kind:r,labelKey:a,descKey:l})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:o(a)}),e.jsx("span",{className:"sound-desc",children:o(l)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:o("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),n(r)},children:o("preview")}),e.jsx("input",{type:"checkbox",checked:t[r],disabled:!t.enabled,onChange:u=>c({[r]:u.target.checked})})]})]},r)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:o("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:r=>c({volume:Number(r.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function On({chat:t,send:s,terminal:n,view:o,plugins:c,onViewChange:r,onOpenPanel:a,onManageModels:l,onOpenSettings:u,onOpenBgTasks:m,onOpenGlobalSearch:f,sound:h,onSoundChange:k,onSoundPreview:N,themes:M,theme:D,onThemeChange:S}){var ne;const{locale:I,setLocale:$,t:p}=Et(),[C,T]=i.useState(!1),[v,w]=i.useState(!1),[d,R]=i.useState(!1),[F,z]=i.useState(!1),[W,G]=i.useState(!1),V=[{value:"zh",label:p("langZh")},{value:"en",label:p("langEn")}],L=t.ready?p("connected"):t.status==="closed"?p("reconnecting"):p("connecting"),O=t.ready?"ok":"busy",A=()=>{var B,te;if(!t.ready)return;const P=p("updateTabTitle"),j={name:P,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},x=t.terminals.find(ue=>ue.title===P);x?(n.restart(x.id),s({type:"run_command",terminalId:x.id,conversationId:x.conversationId,command:j,cols:80,rows:24})):n.create({id:He(),conversationId:t.activeConversationId||((B=t.state)==null?void 0:B.conversationId)||"",title:P,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:j}),z(!1),G(!1),r("terminal")},re=()=>{var P,j;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:p("currentVersion")}),e.jsxs("b",{children:["v",((P=t.update)==null?void 0:P.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:p("latestVersion")}),e.jsx("b",{children:t.update===null?p("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:p("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:p("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:p("updateAvailable",{version:t.update.latest})}),((j=t.update)==null?void 0:j.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:p("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:p("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?p("checkingUpdate"):p("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:A,children:p("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:p("openHistory"),onClick:()=>a("left"),children:e.jsx(jn,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${O}`,title:L}),e.jsx("span",{className:"conn-label",children:L})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":p("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="chat",className:o==="chat"?"active":"",onClick:()=>r("chat"),children:[e.jsx(nt,{}),e.jsx("span",{children:p("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="terminal",className:o==="terminal"?"active":"",onClick:()=>r("terminal"),children:[e.jsx(Ve,{}),e.jsx("span",{children:p("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="git",className:o==="git"?"active":"",onClick:()=>r("git"),children:[e.jsx(Qe,{}),e.jsx("span",{children:p("scmTab")})]}),c.map(P=>{const j=P.error?`${P.name}: ${P.error}`:P.description?`${P.name} — ${P.description}`:P.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":o===`plugin:${P.id}`,className:`plugin-tab${o===`plugin:${P.id}`?" active":""}${P.error?" broken":""}`,title:j,onClick:()=>r(`plugin:${P.id}`),children:[P.icon?e.jsx("span",{"aria-hidden":!0,children:P.icon}):e.jsx(Ns,{}),e.jsx("span",{children:P.name})]},P.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:p("searchGlobalTip"),onClick:f,children:[e.jsx(st,{}),e.jsx("span",{className:"chip-sub",children:p("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":p("bgTasksTip"),onClick:m,children:[e.jsx(at,{}),e.jsx("span",{className:"chip-sub",children:p("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(Es,{state:t.state?{model:t.state.model,thinkingLevel:t.state.thinkingLevel,availableThinkingLevels:t.state.availableThinkingLevels}:null,models:t.models,modelsLoading:t.modelsLoading,send:s,onManageModels:l}),e.jsxs("button",{type:"button",className:"chip",title:p("settingsTitle"),onClick:u,children:[e.jsx(tt,{}),e.jsx("span",{className:"chip-sub",children:p("settings")})]}),e.jsx(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(bs,{}),e.jsx("span",{className:"chip-sub",children:p("sound")})]}),open:C,onOpenChange:T,children:e.jsx(Vt,{settings:h,onChange:k,onPreview:N})}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Sn,{}),e.jsx("span",{className:"chip-sub",children:I==="zh"?p("langZh"):"EN"})]}),open:v,onOpenChange:w,children:[e.jsx("div",{className:"dd-header",children:p("language")}),V.map(P=>e.jsx(we,{active:I===P.value,onClick:()=>{$(P.value),w(!1)},children:P.label},P.value))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(hn,{}),e.jsx("span",{className:"chip-sub",children:p("theme")})]}),open:d,onOpenChange:R,children:[e.jsx("div",{className:"dd-header",children:p("theme")}),e.jsx(we,{active:D===null,onClick:()=>{S(null),R(!1)},children:p("themeDefault")}),M.map(P=>e.jsx(we,{active:D===P.id,onClick:()=>{S(P.id),R(!1)},children:P.name},P.id))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Tt,{}),e.jsxs("span",{className:"chip-sub",children:["v",((ne=t.update)==null?void 0:ne.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:p("updateAvailable",{version:t.update.latest??""})})]}),open:F,onOpenChange:P=>{z(P),P&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:p("update")}),re()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:p("githubRepo"),children:e.jsx(zt,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":p("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(Ae,{}),e.jsx("span",{children:p("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(vn,{}),e.jsx("span",{className:"chip-sub",children:p("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:W,onOpenChange:P=>{G(P),P&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:p("sound")}),e.jsx("div",{className:"dd-header",children:p("settings")}),e.jsxs(we,{onClick:()=>{G(!1),u()},children:[e.jsx(tt,{})," ",p("settingsTitle")]}),e.jsxs(we,{onClick:()=>{G(!1),f()},children:[e.jsx(st,{})," ",p("searchGlobal")]}),e.jsxs(we,{onClick:()=>{G(!1),m()},children:[e.jsx(at,{})," ",p("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(Vt,{settings:h,onChange:k,onPreview:N}),e.jsx("div",{className:"dd-header",children:p("language")}),V.map(P=>e.jsx(we,{active:I===P.value,onClick:()=>$(P.value),children:P.label},P.value)),e.jsx("div",{className:"dd-header",children:p("theme")}),e.jsx(we,{active:D===null,onClick:()=>{S(null),G(!1)},children:p("themeDefault")}),M.map(P=>e.jsx(we,{active:D===P.id,onClick:()=>{S(P.id),G(!1)},children:P.name},P.id)),e.jsx("div",{className:"dd-header",children:p("update")}),re(),e.jsxs("a",{className:"dd-refresh dd-more-link",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",children:[e.jsx(zt,{})," ",p("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:p("openFiles"),onClick:()=>a("right"),children:e.jsx(Oe,{})})]})]})}function Gt(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}const Hn=i.memo(function({ready:s,status:n,cwd:o,sessionFile:c,conversations:r,sessions:a,projects:l,activeConversationId:u,send:m,active:f}){const h=he(),k=c,N=o,[M,D]=i.useState(null);i.useEffect(()=>{!f||!s||n!=="open"||o&&(m({type:"list_sessions"}),m({type:"list_projects"}))},[f,s,n,o,m]);const S=p=>{const C=p.name||p.firstMessage.trim();return C.length>0?C:h("emptyChat")},I=p=>p.split(/[\\/]/).pop()||p,$=(p,C,T,v)=>{const w=M===p;return e.jsx("button",{type:"button",className:`lp-del ${w?"confirm":""}`,title:w?T:C,onClick:d=>{d.stopPropagation(),w?(D(null),v()):D(p)},children:w?e.jsx(lt,{}):e.jsx(Fe,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[l.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:h("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:l.map(p=>{const C=N===p.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(T=>T===`proj:${p.path}`?null:T),children:[e.jsxs("button",{type:"button",className:`project-item ${C?"active":""}`,title:p.path,onClick:()=>{C||m({type:"set_cwd",path:p.path})},children:[e.jsx(Oe,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:I(p.path)}),e.jsx("span",{className:"project-path",children:p.path})]}),e.jsx("span",{className:"project-time",children:Gt(p.lastUsed)})]}),$(`proj:${p.path}`,h("deleteProject"),h("deleteProjectConfirm"),()=>m({type:"remove_project",path:p.path}))]},p.path)})})]}),r.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:h("runningConversations")}),r.map(p=>{const C=u===p.id;return e.jsxs("button",{type:"button",className:`session-item ${C?"active":""}`,title:p.title,onClick:()=>{C||m({type:"switch_conversation",id:p.id})},children:[e.jsx(nt,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:p.title}),e.jsx("span",{className:"session-sub",children:C?h("current"):h("messageCount",{n:p.messageCount})})]}),p.isStreaming&&e.jsx("span",{className:"conv-streaming",title:h("streaming")})]},p.id)}),e.jsx("div",{className:"panel-section-divider"})]}),e.jsxs("div",{className:"panel-sessions",children:[e.jsx("div",{className:"panel-section-title",children:h("historySessions")}),e.jsxs("div",{className:"sessions-scroll",children:[a.length===0&&e.jsx("div",{className:"panel-empty",children:h("noHistory")}),a.map(p=>{const C=k===p.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(T=>T===`sess:${p.path}`?null:T),children:[e.jsxs("button",{type:"button",className:`session-item ${C?"active":""}`,title:p.path,onClick:()=>{C||m({type:"switch_session",path:p.path})},children:[e.jsx(nt,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:S(p)}),e.jsxs("span",{className:"session-sub",children:[C?h("current"):h("messageCount",{n:p.messageCount}),p.source==="tui"&&e.jsx("span",{className:"session-src",title:h("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:Gt(p.modified)})]}),$(`sess:${p.path}`,h("deleteSession"),h("deleteSessionConfirm"),()=>m({type:"delete_session",path:p.path}))]},p.path)})]})]})]})}),Rs="pi-web-ui:token";function Wn(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Rs,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function qn(){try{return localStorage.getItem(Rs)??""}catch{return""}}function ct(t){const s=qn();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function Un(t,s){const n=s.assistantMessageEvent,o=t.stats.tokens,c=s.usage!==null?{...o,...s.usage}:o,r=c===o?t.stats:{...t.stats,tokens:c};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return r===t.stats?t:{...t,stats:r};const a=n.delta??"";if(!a)return r===t.stats?t:{...t,stats:r};const l=t.streamingMessage??null,u=l&&l.id===s.messageId?l:{id:s.messageId,content:[]},m=[...u.content],f=n.type==="thinking_delta"?"thinking":"text",h=n.contentIndex??m.length-1;return h>=0&&h<m.length&&m[h].type===f?m[h]=f==="thinking"?{type:"thinking",thinking:(m[h].thinking??"")+a}:{type:"text",text:(m[h].text??"")+a}:m.push(f==="thinking"?{type:"thinking",thinking:a}:{type:"text",text:a}),{...t,stats:r,streamingMessage:{...u,id:s.messageId,content:m}}}const jt="pi-web-ui:plugin-data";function zn(t,s){window.dispatchEvent(new CustomEvent(jt,{detail:{pluginId:t,payload:s}}))}function Kn(t){const s=n=>{const o=n.detail;t(o.pluginId,o.payload)};return window.addEventListener(jt,s),()=>window.removeEventListener(jt,s)}const $e=new Map,bt=new Set,De=new Set;let Jt=-1;function Ls(){return[...$e.values()]}function Vn(){const t=Ls();for(const s of bt)s(t)}function Gn(t){return bt.add(t),t(Ls()),()=>bt.delete(t)}async function Jn(t,s){s!==Jt&&(Jt=s,$e.clear(),De.clear());const n=new Set(t.map(o=>o.id));for(const o of[...$e.keys()])n.has(o)||$e.delete(o);for(const o of[...De])n.has(o)||De.delete(o);await Promise.all(t.filter(o=>o.hasClient&&!o.error&&!$e.has(o.id)&&!De.has(o.id)).map(async o=>{try{const r=(await vs(()=>import(`/plugins/${encodeURIComponent(o.id)}/client/entry.mjs?e=${s}`),[])).default;r&&typeof r.mount=="function"?$e.set(o.id,{info:o,module:r}):(De.add(o.id),console.error(`[plugin:${o.id}] entry.mjs 缺少 default.mount`))}catch(c){De.add(o.id),console.error(`[plugin:${o.id}] 客户端加载失败:`,c)}})),Vn()}function Qn(t,s){return{pluginId:t,send:n=>s({type:"plugin_message",pluginId:t,payload:n}),onData:n=>Kn((o,c)=>{o===t&&n(c)})}}const Yn=7,mt=2e5,Xn=2e5,Zn={conversationId:null,goal:null,reviewModel:null,maxRounds:3,locked:!0,reviewing:!1,round:0,status:"",verdict:"pending",wizard:{active:!1,draft:"",model:null,step:0,maxSteps:6,status:""}};function ea(){const t=new Map,s=new Map,n=(o,c)=>`${o}:${c}`;return{write(o,c,r){const a=n(o,c),l=t.get(a);if(l&&l.size>0){for(const f of l)try{f.write(r)}catch{}return}const u=s.get(a)??"",m=u.length+r.length>Xn?r:u+r;s.set(a,m)},register(o,c,r){const a=n(o,c);let l=t.get(a);l||(l=new Set,t.set(a,l)),l.add(r);const u=s.get(a);if(u){try{r.write(u)}catch{}s.delete(a)}return()=>{const m=t.get(a);m&&(m.delete(r),m.size===0&&t.delete(a)),s.delete(a)}},clear(){t.clear(),s.clear()}}}function Qt(t,s){const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId),c.role==="bashExecution"&&n.add(`bash-${c.id}`);let o=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),o=!0);return o?new Map(t):t}function Yt(t,s){if(t.size===0)return t;const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId);let o=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),o=!0);return o?new Map(t):t}function ta(t,s){var n,o,c,r;switch(s.type){case"status":return{...t,status:s.status,ready:s.status==="open"?t.ready:!1,terminals:s.status==="closed"?[]:t.terminals};case"ready":return{...t,serverVersion:s.serverVersion,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==Yn};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Qt(t.liveOutputs,s.state),toolStatuses:Yt(t.toolStatuses,s.state)};case"snapshot_delta":{const a=t.state,l=s.msg;if(!a||a.conversationId!==l.conversationId||a.rev!==l.baseRev)return t;const u={...a,...l.state,messages:l.appended.length>0?[...a.messages,...l.appended]:a.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:Qt(t.liveOutputs,u),toolStatuses:Yt(t.toolStatuses,u)}}case"tool_delta":{const a=t.liveOutputs.get(s.toolCallId),l=((a==null?void 0:a.text)??"")+s.delta,u=l.length>mt?`…[前 ${l.length-mt} 字符已省略]…
|
|
3
|
-
`+l.slice(l.length-mt):l,m=new Map(t.liveOutputs);return m.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:m}}case"message_delta":{const a=t.state;return!a||a.conversationId!==s.msg.conversationId?t:{...t,state:Un(a,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(a=>a.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(a=>a.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(n=t.state)!=null&&n.conversationId)&&s.conversationId!==(t.activeConversationId||((o=t.state)==null?void 0:o.conversationId))?t:{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!1,exitCode:s.exitCode}:a)};case"terminal_restart":return{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!0,exitCode:null}:a)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:s.terminals.map(a=>{var l;return{...a,conversationId:s.conversationId??((l=t.state)==null?void 0:l.conversationId)??""}})};default:return t}}const Xt="pi-web-client-id";let pt=null;function Rt(){if(pt)return pt;let t=null;try{t=sessionStorage.getItem(Xt),t||(t=He(),sessionStorage.setItem(Xt,t))}catch{t=t??He()}return pt=t,t}function sa(){const t=location.protocol==="https:"?"wss:":"ws:";return ct(`${t}//${location.host}/ws`)}function na(){const[t,s]=i.useReducer(ta,{status:"connecting",ready:!1,state:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:[],conversations:[],activeConversationId:"",projects:[],files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],installResult:null,pathCompletions:[],update:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:Zn,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,protocolMismatch:!1}),n=i.useRef(null),o=i.useRef(ea()),c=i.useRef(0),r=i.useRef(null),a=i.useRef(!0),l=i.useRef(0),u=i.useRef(0),m=i.useRef(new Map),f=i.useRef(null),h=()=>{f.current||(f.current=setTimeout(()=>{f.current=null;const v=n.current;v&&v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:"get_state"}))},300))},k=(v,w)=>{var F;const d=m.current,R=d.get(v);if(R!==void 0&&w!==R+1){const z=T.current.chat,W=z.activeConversationId||((F=z.state)==null?void 0:F.conversationId);v===W&&h()}d.set(v,w)},N=i.useCallback((v,w)=>{const d=++u.current;s({type:"notice",notice:{id:d,level:v,text:w}})},[]),M=i.useCallback(v=>{const w=n.current;return w&&w.readyState===WebSocket.OPEN?(w.send(JSON.stringify(v)),!0):!1},[]),D=i.useCallback(()=>{if(!a.current)return;s({type:"status",status:"connecting"});const v=new WebSocket(sa());n.current=v,v.onopen=()=>{n.current===v&&(s({type:"status",status:"open"}),c.current=0,l.current=Date.now(),v.send(JSON.stringify({type:"hello",clientId:Rt()})))},v.onmessage=w=>{if(n.current!==v)return;l.current=Date.now();let d;try{d=JSON.parse(w.data)}catch{return}switch(d.type){case"ready":s({type:"ready",serverVersion:d.serverVersion,protocolVersion:d.protocolVersion}),v.send(JSON.stringify({type:"get_state"})),v.send(JSON.stringify({type:"list_files"})),v.send(JSON.stringify({type:"list_models"})),v.send(JSON.stringify({type:"list_commands"})),v.send(JSON.stringify({type:"get_commands"})),v.send(JSON.stringify({type:"check_update"}));break;case"snapshot":m.current=new Map,s({type:"snapshot",state:d.state});break;case"snapshot_delta":{const R=T.current.chat.state;(!R||R.conversationId!==d.conversationId||R.rev!==d.baseRev)&&h(),s({type:"snapshot_delta",msg:d});break}case"tool_delta":k(d.conversationId,d.seq),s({type:"tool_delta",toolCallId:d.toolCallId,toolName:d.toolName,delta:d.delta});break;case"tool_status":s({type:"tool_status",status:d});break;case"message_delta":{k(d.conversationId,d.seq),s({type:"message_delta",msg:d});break}case"notice":{const R=++u.current;s({type:"notice",notice:{id:R,level:d.level,text:d.text}});break}case"sessions":s({type:"sessions",sessions:d.sessions});break;case"conversations":s({type:"conversations",conversations:d.conversations,activeId:d.activeId});break;case"projects":s({type:"projects",projects:d.projects});break;case"files":s({type:"files",files:d});break;case"file_changed":s({type:"file_changed",path:d.path});break;case"file_content":s({type:"file_content",content:d});break;case"models":s({type:"models",models:d.models,loading:!1});break;case"models_config":s({type:"models_config",providers:d.providers});break;case"providers_status":s({type:"providers_status",providers:d.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:d.reqId,ok:d.ok,models:d.models,error:d.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:d.reqId,ok:d.ok,added:d.added,total:d.total,error:d.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:d.reqId,ok:d.ok,config:d.config,error:d.error}});break;case"scm_data":s({type:"scm_data",data:d});break;case"search_files_result":s({type:"file_search_result",result:{reqId:d.reqId,ok:d.ok,results:d.results,truncated:d.truncated}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:d});break;case"path_completions":s({type:"path_completions",completions:d.completions});break;case"update_status":s({type:"update_status",status:d});break;case"widgets":s({type:"widgets",widgets:d.widgets});break;case"statuses":s({type:"statuses",statuses:d.statuses});break;case"dialog":s({type:"dialog",dialog:{id:d.id,kind:d.kind,title:d.title,args:d.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"terminal_output":o.current.write(d.conversationId??T.current.chat.activeConversationId,d.terminalId,d.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:d.conversationId,terminalId:d.terminalId,exitCode:d.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:d.conversationId,terminals:d.terminals});break;case"commands":s({type:"commands",commands:d.commands,path:d.path});break;case"slash_commands":s({type:"slash_commands",commands:d.commands});break;case"goal_status":s({type:"goal_status",status:d.status});break;case"settings_state":s({type:"settings",settings:d.settings});break;case"bg_servers":s({type:"bg_servers",servers:d.servers});break;case"plugins":s({type:"plugins",plugins:d.plugins,epoch:d.epoch});break;case"plugin_data":zn(d.pluginId,d.payload);break}},v.onclose=()=>{if(n.current===v&&(n.current=null),o.current.clear(),!a.current||n.current&&n.current!==v)return;s({type:"status",status:"closed"});const w=Math.min(1e3*2**c.current,1e4);c.current+=1,r.current=setTimeout(()=>{r.current=null,D()},w)},v.onerror=()=>{}},[]);i.useEffect(()=>{a.current=!0,D();const v=setInterval(()=>{if(!a.current)return;const w=n.current;w&&w.readyState===WebSocket.OPEN&&Date.now()-l.current>3e4&&w.close()},5e3);return()=>{var w;a.current=!1,clearInterval(v),r.current&&(clearTimeout(r.current),r.current=null),(w=n.current)==null||w.close(),n.current=null}},[D]);const S=i.useCallback(v=>s({type:"dismiss_notice",id:v}),[]),I=i.useCallback(v=>s({type:"terminal_add",meta:v}),[]),$=i.useCallback(v=>s({type:"terminal_remove",id:v}),[]),p=i.useCallback(v=>s({type:"terminal_restart",terminalId:v}),[]),C=i.useCallback((v,w,d)=>o.current.register(v,w,d),[]),T=i.useRef({chat:t,send:M,pushNotice:N,dismissNotice:S,terminal:{create:I,close:$,register:C,restart:p}});return T.current={chat:t,send:M,pushNotice:N,dismissNotice:S,terminal:{create:I,close:$,register:C,restart:p}},T.current}const aa=200*1024*1024,ia=/windows/i.test(navigator.userAgent),ra=/[<>:"/\\|?*\u0000-\u001f]/g,oa=/[. ]+$/,la=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function ca(t){const s=t.replace(ra,"_").replace(oa,"");return s?la.test(s)?`_${s}`:s:"_"}function Zt(t,s=!0){const n=new URLSearchParams({clientId:Rt(),path:t,...s?{download:"1"}:{}});return ct(`/api/file?${n}`)}async function da(t,s){const n=ia?ca(s):s;try{const o=await fetch(Zt(t));if(!o.ok)return{ok:!1,cancelled:!1,error:await o.text().catch(()=>"")||(o.status===404?"文件不存在":`HTTP ${o.status}`)};if(Number(o.headers.get("content-length")??"0")>aa)return window.location.assign(Zt(t)),{ok:!0};const r=await o.blob();return window.showSaveFilePicker&&window.isSecureContext?ua(r,n):kt(r,n)}catch(o){return{ok:!1,cancelled:!1,error:o instanceof Error?o.message:String(o)}}}async function ua(t,s){let n;const o=window.showSaveFilePicker;if(!o)return kt(t,s);try{n=await o({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:kt(t,s)}try{const c=await n.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function kt(t,s){const n=URL.createObjectURL(t),o=document.createElement("a");return o.href=n,o.download=s,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const ma=i.memo(function({files:s,fileChanged:n,widgets:o,cwd:c,send:r,onAttach:a,onPreview:l,onNotice:u}){const m=he(),[f,h]=i.useState(""),[k,N]=i.useState(null),[M,D]=i.useState(!1),S=1e4,I=i.useRef(0),$=i.useRef(void 0),p=i.useCallback((w,d)=>{const R=++I.current;h(w),d!=null&&d.silent||D(!0),r({type:"list_files",path:w===""?void 0:w})||I.current===R&&D(!1)},[r]);i.useEffect(()=>{s&&s.path===f&&D(!1)},[s,f]),i.useEffect(()=>{if(c!==$.current){$.current=c,p("",{silent:!0});return}const w=setInterval(()=>{document.visibilityState!=="hidden"&&p(f,{silent:!0})},S);return()=>clearInterval(w)},[c,f,p]),i.useEffect(()=>{n&&n.path===f&&p(f,{silent:!0})},[n,f,p]);const C=w=>p(w),T=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&p(s.parent)},v=f.split("/").filter(Boolean);return e.jsxs("aside",{className:"panel panel-right",children:[e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${f===""?"active":""}`,onClick:()=>p(""),children:m("rootDir")}),v.map((w,d)=>{const R=v.slice(0,d+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(ot,{}),e.jsx("button",{type:"button",className:`crumb ${R===f?"active":""}`,onClick:()=>p(R),children:w})]},R)})]}),e.jsxs("div",{className:"panel-body",children:[M&&e.jsx("div",{className:"panel-empty",children:m("loading")}),!M&&s&&s.path===f&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:T,children:[e.jsx(Oe,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(w=>w.type==="dir"?e.jsxs("div",{className:"file-item dir",children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>C(w.path),children:[e.jsx(Oe,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("linkFolderTip"),onClick:()=>a(w.path,w.name,"reference",!0),children:e.jsx(vt,{})})]},w.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${w.path} — ${m("previewFile")}`,onClick:()=>l(w.path,w.name),children:[e.jsx(ks,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":m("downloadFile"),onClick:()=>{da(w.path,w.name).then(d=>{d.ok||d.cancelled||u("error",m("downloadFailed",{error:d.error}))})},children:e.jsx(Tt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":m("attachInlineTip"),onClick:()=>a(w.path,w.name,"inline"),children:e.jsx(Ae,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("referenceTip"),onClick:()=>a(w.path,w.name,"reference"),children:e.jsx(vt,{})})]},w.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:m("filesTruncated")})]}),!M&&!s&&e.jsx("div",{className:"panel-empty",children:m("noFiles")})]}),o.filter(w=>w.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:o.filter(w=>w.lines.length>0).map(w=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:m("widgetExpand"),onClick:()=>N(w.key),children:[e.jsx("span",{children:w.key}),e.jsx(kn,{})]}),e.jsx("pre",{className:"widget-lines",children:w.lines.join(`
|
|
4
|
-
`)})]},w.key))}),k&&(()=>{const w=o.find(d=>d.key===k);return w?e.jsx("div",{className:"modal-backdrop",onClick:()=>N(null),children:e.jsxs("div",{className:"widget-expand",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:w.key}),e.jsx("button",{type:"button",className:"btn",title:m("close"),onClick:()=>N(null),children:e.jsx(
|
|
5
|
-
`)})]})}):null})()]})});var
|
|
6
|
-
`),n=[];let o=[],c=null;for(let r=0;r<s.length;r++){const a=s[r];if(c!==null){const u=
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-__4r1Djg.js","assets/markdown-DRBrS2Nf.js","assets/xterm-D1D2FVe3.js","assets/react-C9ovnpIm.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as Pe,a as i,j as e,M as vs,b as Zs,c as en}from"./markdown-DRBrS2Nf.js";import{r as ys}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"]'))o(c);new MutationObserver(c=>{for(const r of c)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function n(c){const r={};return c.integrity&&(r.integrity=c.integrity),c.referrerPolicy&&(r.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?r.credentials="include":c.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function o(c){if(c.ep)return;c.ep=!0;const r=n(c);fetch(c.href,r)}})();var Je={},Ht;function tn(){if(Ht)return Je;Ht=1;var t=ys();return Je.createRoot=t.createRoot,Je.hydrateRoot=t.hydrateRoot,Je}var sn=tn();const nn="modulepreload",an=function(t){return"/"+t},Wt={},js=function(s,n,o){let c=Promise.resolve();if(n&&n.length>0){let a=function(m){return Promise.all(m.map(f=>Promise.resolve(f).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),u=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));c=a(n.map(m=>{if(m=an(m),m in Wt)return;Wt[m]=!0;const f=m.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${h}`))return;const k=document.createElement("link");if(k.rel=f?"stylesheet":nn,f||(k.as="script"),k.crossOrigin="",k.href=m,u&&k.setAttribute("nonce",u),document.head.appendChild(k),f)return new Promise((N,M)=>{k.addEventListener("load",N),k.addEventListener("error",()=>M(new Error(`Unable to preload CSS for ${m}`)))})}))}function r(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return c.then(a=>{for(const l of a||[])l.status==="rejected"&&r(l.reason);return s().catch(r)})};var bs={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},qt=Pe.createContext&&Pe.createContext(bs),rn=["attr","size","title"];function on(t,s){if(t==null)return{};var n,o,c=ln(t,s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(o=0;o<r.length;o++)n=r[o],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(c[n]=t[n])}return c}function ln(t,s){if(t==null)return{};var n={};for(var o in t)if({}.hasOwnProperty.call(t,o)){if(s.indexOf(o)!==-1)continue;n[o]=t[o]}return n}function Ze(){return Ze=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},Ze.apply(null,arguments)}function Ut(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);s&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),n.push.apply(n,o)}return n}function et(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Ut(Object(n),!0).forEach(function(o){cn(t,o,n[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ut(Object(n)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(n,o))})}return t}function cn(t,s,n){return(s=dn(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function dn(t){var s=un(t,"string");return typeof s=="symbol"?s:s+""}function un(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var o=n.call(t,s);if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function ks(t){return t&&t.map((s,n)=>Pe.createElement(s.tag,et({key:n},s.attr),ks(s.child)))}function q(t){return s=>Pe.createElement(mn,Ze({attr:et({},t.attr)},s),ks(t.child))}function mn(t){var s=n=>{var o=t.attr,c=t.size,r=t.title,a=on(t,rn),l=c||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),Pe.createElement("svg",Ze({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,o,a,{className:u,style:et(et({color:t.color||n.color},n.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),r&&Pe.createElement("title",null,r),t.children)};return qt!==void 0?Pe.createElement(qt.Consumer,null,n=>s(n)):s(bs)}function pn(t){return q({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 hn(t){return q({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 vt(t){return q({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 Te(t){return q({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 ws(t){return q({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 gn(t){return q({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 He(t){return q({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 Ge(t){return q({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 zt(t){return q({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 fn(t){return q({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 tt(t){return q({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 st(t){return q({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 xn(t){return q({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 nt(t){return q({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 vn(t){return q({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 Tt(t){return q({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 We(t){return q({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 Bi(t){return q({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 Kt(t){return q({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 yn(t){return q({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 jn(t){return q({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 bn(t){return q({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 at(t){return q({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 kn(t){return q({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 wn(t){return q({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 Nn(t){return q({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 Cn(t){return q({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 yt(t){return q({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 it(t){return q({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 Sn(t){return q({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"},child:[]}]})(t)}function Tn(t){return q({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 En(t){return q({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 Vt(t){return q({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 Ye(t){return q({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 qe(t){return q({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 Ns(t){return q({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 Mn(t){return q({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 Cs(t){return q({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 jt(t){return q({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 Gt(t){return q({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 Et(t){return q({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 q({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 Rn(t){return q({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 Mt(t){return q({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 Ln(t){return q({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 ot(t){return q({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 lt(t){return q({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 De(t){return q({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 q({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 In(t){return q({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 Ss(t){return q({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 Pn(t){return q({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 Ts(t){return q({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 Es(t){return q({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 Bn(t){return q({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 Dn(t){return q({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 Be(){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 n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.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 Le({trigger:t,open:s,onOpenChange:n,children:o,align:c="right",fit:r=!1,direction:a="down",menuClassName:l}){const u=i.useRef(null);return i.useEffect(()=>{if(!s)return;const m=h=>{u.current&&!u.current.contains(h.target)&&n(!1)},f=h=>{h.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",f)}},[s,n]),e.jsxs("div",{className:`dropdown ${c} ${r?"fit":""} ${a==="up"?"dd-up":""}`,ref:u,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(De,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${l??""}`,children:o})]})}function Ce({active:t,disabled:s=!1,title:n,onClick:o,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:o,children:c})}const Ms="pi-web-ui:lang",_n={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",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:"插件状态",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",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:"排队",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/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)。",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",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:"插件请求",noOptions:"(无选项)",inputPlaceholder:"输入内容",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 密钥即可开始对话:",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":"上下文已压缩",welcomeTitle:"pi 编码智能体",welcomeSub:"检查、编辑、运行 —— 随时待命",directory:"目录",clickToFill:"点击填入输入框",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:同时搜索历史对话、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索文件…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","ex.understand":"了解这个项目","ex.understand.prompt":"介绍一下这个项目:整体结构、主要模块和如何运行?","ex.debug":"排查一个问题","ex.debug.prompt":"帮我排查一个 bug,请先说明问题现象,我会补充细节。","ex.test":"编写测试","ex.test.prompt":"为项目的核心模块编写单元测试。","ex.review":"代码审查","ex.review.prompt":"审查最近改动的代码,指出潜在问题和改进建议。",error:"出错",done:"完成",running:"执行中…",toolQueued:"排队中",copyArgs:"复制参数",errorOutput:"错误输出",output:"输出",waitingOutput:"等待输出…",toolDoneWaitingModel:"已结束 · 等模型",waitingModel:"等待模型响应…",thinkingNow:"思考中",thinkingPreview:"思考:{preview}",commands:"命令",newCommand:"新建命令",newTerminal:"新建终端",name:"名称",command:"命令",cwdHint:"(${pwd} = 当前工作目录)",noCommands:"还没有命令,点 + 添加一个",clickToRun:"点击运行",edit:"编辑",delete:"删除",confirmQ:"确认?",builtinTerminal:"内置终端",termEmptySub:"点击左侧命令运行,或点右侧 + 新建终端",noTerminal:"暂无终端",exited:"(已退出{code})",closeTerminal:"关闭终端",rerun:"重新读取 .pi/commands.json",terminalTitle:"终端 {n}",exampleName:"例如:启动开发服务器",exampleCommand:"例如:npm run dev",scmTab:"Git",scmTitle:"源代码管理",scmRefreshTip:"重新查询 Git 状态与差异",scmCurrentBranch:"当前分支",scmUpstreamGone:"上游已删除",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"分离 HEAD",scmSelectBranch:"选择分支…",scmRemoteBranches:"远程分支",scmStageTip:"暂存 {path}",scmUnstageTip:"取消暂存 {path}",scmSwitch:"切换",scmSwitchBranch:"切换分支",scmSwitchBranchTip:"在终端中执行 git checkout {branch}",scmPush:"推送",scmPushTip:"在终端中执行 git push",scmPull:"拉取",scmPullTip:"在终端中执行 git pull",scmCommit:"提交",scmCommitTip:'在终端中执行 git add -A && git commit -m "…"(提交全部更改,含未跟踪)',scmCommitPlaceholder:"输入提交信息…",scmChanges:"更改",scmHistory:"提交树",scmCommitDetail:"提交详情",scmSelectCommitHint:"点击左侧提交查看详情",scmNoHistory:"暂无提交记录",scmNoChanges:"工作区干净,没有更改",scmNotGitRepo:"当前目录不是 Git 仓库",scmLoading:"查询中…",scmConnecting:"等待连接…",scmDiff:"差异",scmSelectFileHint:"点击左侧文件查看差异",scmNoDiff:"(无差异)",scmStaged:"已暂存",scmUnstaged:"未暂存",scmStagedUnstaged:"已暂存 + 未暂存",scmUntracked:"未跟踪",scmUntrackedNote:"未跟踪文件:差异不显示,提交时会一并包含",scmQueryFailed:"Git 查询失败:{error}",scmTooManyFailures:"Git 查询连续失败,请点击刷新重试",scmRunsInTerminal:"提交 / 切换分支 / 推送 / 拉取在终端中执行",scmViewTerminal:"去终端",editProvider:"编辑服务商",builtinProviders:"内置服务商",hintKeyOnly:"只需填入 API 密钥",configuredBadge:"✓ 已配置",keyReady:"密钥已就绪",replaceKey:"更换密钥",replaceKeyTitle:"替换已保存的密钥",clearKey:"清空",clearKeyTitle:"清除该服务商保存在 auth.json 的密钥,回到未配置状态(环境变量来源的无法在此清除)",clearKeyConfirm:"清空 {id} 已保存的密钥?其模型将从列表消失,直到重新配置。",cloneProvider:"复制为自定义",cloning:"复制中",cloneProviderTitle:"复制该内置供应商(baseUrl + 模型列表)为自定义供应商,填入另一个 API 密钥即可双 key 并存",pasteKey:"粘贴 API 密钥…",savingKey:"保存中",saveKey:"保存密钥",customProviders:"自定义服务商",customDesc:"用于 Ollama / vLLM / 兼容 OpenAI 的代理等,写入 pi 的 models.json,保存后热重载、立即生效。",noCustomProviders:"还没有自定义服务商",modelsCount:"{n} 个模型",addProvider:"新增服务商",providerId:"服务商 ID",providerIdHint:"(必填,如 ollama / my-proxy)",displayName:"显示名",displayNamePh:"我的代理",apiType:"API 类型",baseUrlHint:"(OpenAI 兼容端点)",apiKeyHint:"sk-…(可留空,用 auth.json 的密钥)",authHeader:"自动添加 Authorization 请求头",modelsTitle:"模型",modelIdReq:"模型 ID(必填)",text:"文本",textImage:"文本+图片",contextWindow:"上下文",maxOutput:"最大输出",removeModel:"移除模型",addModel:"添加模型",deleteProviderConfirm:"删除服务商 {id} 及其 {n} 个模型?",fetchModels:"自动获取模型列表",fetchModelsHint:"从 baseUrl 的 /models 接口自动拉取模型 ID(服务端请求,不受 CORS 限制)",fetchingModels:"获取中…",fetchModelsOk:"已获取 {n} 个模型",fetchModelsEmpty:"接口未返回任何模型",fetchModelsErr:"获取失败:{msg}",fetchModelsNeedBaseUrl:"请先填写 baseUrl 再获取",goalBarTitle:"目标",goalBarPlaceholder:"设定一个目标,agent 完成后自动审查…",goalBarSet:"开始",goalBarClear:"取消",goalBarLocked:"锁定:应用到后续所有回合",goalBarUnlocked:"仅本回合(改完自动清除)",goalBarReviewModel:"审查模型",goalBarUseMainModel:"使用主模型",goalBarMaxRounds:"最大轮数",goalBarMaxRoundsTip:"最大审查重改轮数;0 或不填 = 不限(持续改到通过)",goalBarUnlimitedShort:"不限",goalBarReviewing:"审查中…",goalBarRound:"第 {n} 轮",goalBarActive:"目标生效中",goalBarPassed:"已通过",goalBarFailed:"未通过",goalBarStatusPending:"等待生成…",goalWizardBtn:"AI 提炼",goalWizardTip:"让 AI 通过问卷调研细化需求,收敛为目标",goalWizardRunning:"目标调研中",goalWizardAnswer:"回答",goalWizardCard:"目标调研",settings:"设置",settingsTitle:"设置",settingsDesc:"修改立即生效:系统提示词、技能与插件开关会重建当前会话;审查提示词与审查技能只影响后续目标审查(回复进行中则主会话变更自动延迟)。",settingsSystemPrompt:"系统提示词",settingsPromptMode:"模式",promptModeAppend:"追加",promptModeReplace:"替换",promptAppendHint:"追加模式:自定义内容拼接到默认系统提示词末尾(推荐,保留默认行为约束)。",promptReplaceHint:"替换模式:完全用自定义内容替换系统提示词(项目上下文与技能段仍会自动附加)。切换后输入框会显示原本的默认提示词,可直接修改;不改动失焦则仍使用默认。",promptPlaceholder:"输入自定义系统提示词…(失焦后自动应用)",settingsViewPrompt:"查看当前完整提示词",settingsViewPromptHint:"当前会话实际生效的完整系统提示词(含自定义追加/替换内容、项目上下文、技能说明与工具引导),只读。",settingsViewPromptEmpty:"会话尚未就绪,暂无系统提示词。",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",settingsTerminalTools:"终端工具",terminalToolsEnabled:"启用持久终端工具",settingsTerminalToolsDesc:"让 AI 在交互式程序(REPL/vim)、长驻服务、需要持续观察输出或你要求在可见终端操作时,使用内置终端;普通命令仍走一次性 bash 工具",terminalToolsOffHint:"已关闭:AI 无法使用 terminal_* 工具,也不会收到相关使用引导",terminalBashTakeover:"终端接管 bash",terminalBashTakeoverDesc:"bash 命令改在持久可见终端里执行:完整输出自动返回、shell 状态跨调用保留(cd/venv/ssh);命令静默超时自动转后台并在结束后主动通知 AI",terminalBashIdleMs:"静默转后台阈值(毫秒)",terminalBashIdleMsDesc:"命令连续无输出达到该时长即不再阻塞等待,转入后台继续运行并通知 AI;0 = 一直等到命令结束(默认 15000)",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",uninstallExt:"卸载",uninstallConfirm:"确认卸载?",uninstallConfirmHint:"再次点击确认,将在终端执行 pi remove",uninstallHint:"通过可见终端执行 pi remove 卸载此包,完成后自动刷新列表",uninstallTitle:"卸载",settingsExtensions:"插件",settingsUiPlugins:"界面插件",noUiPlugins:"未安装界面组件(<dataDir>/plugins/)",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},$n={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",widgetExpand:"Click to view full output",dragToResize:"Drag to resize · double-click to reset",loading:"Loading…",connected:"Connected",connecting:"Connecting…",reconnecting:"Reconnecting…",language:"Language",langZh:"中文",langEn:"English",githubRepo:"GitHub repository (xing-shuyin/pi-web-ui)",copy:"Copy",viewSwitch:"Switch view",chat:"Chat",terminal:"Terminal",selectModel:"Select model",availableModels:"Available models",noModels:"No models available (configure an API key first)",reasoning:"reasoning",vision:"vision",refreshModels:"Refresh model list (keeps manual rows, merges new ones)",manageModels:"⚙ Manage models (add / edit)",manageModelsTitle:"Manage models",thinkingLevel:"Thinking level",thinking:"Thinking",thinkingChip:"Thinking: {level}",sound:"Sound",theme:"Theme",themeDefault:"Dark (default)",newChat:"New chat",more:"More",newChatTip:"New chat (sessions are saved per browser)","thinking.off":"Off","thinking.minimal":"Minimal","thinking.low":"Low","thinking.medium":"Medium","thinking.high":"High","thinking.xhigh":"Extra high","thinking.max":"Max",thinkingUnsupported:"Not supported by this model — snapped to the nearest supported level",context:"Context",contextUsage:"Context usage",cumulativeCost:"Cumulative cost",sessionMessages:"Session messages",messages:"messages",pluginStatus:"Plugin status",working:"Working",queued:"queued",enterPath:"Type a path, Enter to switch",cwdTip:"Working directory: {path} (click to switch)",folderRef:"Folder reference: {path}",refOnly:"Reference only: {path}",attachContent:"Attached content: {path}",attachLines:"Attached selected lines: {path} (lines {start}-{end})",attachImage:"Image: {name}",attachFile:"File: {name}",removeAttachment:"Remove attachment",attachHint:"Will be sent with the next message",uploadFile:"Add files (images / text / any file — or drag in / paste a screenshot)",dropHereToAttach:"Release to attach file",imageNotSupported:"The current model doesn't support vision — images will be transcribed by the vision bridge (may be ignored if no vision model is configured)",imageLoadFailed:"Couldn't read image: {name}",fileLoadFailed:"Couldn't read file: {name}",fileTooLarge:"File too large, skipped (> {size}MB): {name}",foldersNotSupported:"Folders can't be dropped directly — expand and pick files instead",placeholderStreaming:"The agent is working… press Enter to steer, or click Queue to send after the reply finishes",placeholderIdle:"Message pi — Enter to send, / for commands",placeholderConnecting:"Connecting to server…",stopAgent:"Stop agent",stop:"Stop",bgTasks:"Background tasks",bgTasksTip:"Servers the AI started in the background (npm run dev & etc.) — stop them individually or all at once; they survive the conversation",bgTasksEmpty:"No background tasks",bgTasksDesc:"Processes the AI started that are still listening (detected by port)",bgTaskPort:"Port",bgTaskPid:"PID",bgTaskSince:"Started",bgTaskStop:"Stop",bgTaskStopAll:"Stop all",bgTaskRefresh:"Refresh",bgTaskJustNow:"just now",bgTaskMinutes:"{n} min ago",bgTaskHours:"{n} hr ago",bgTaskDays:"{n} days ago",stopBash:"Stop",stopBashTip:"Stop the running bash command (conversation continues)",supplement:"Queue",supplementTip:"Add to queue: sent only after the whole run finishes (no interruption)",queueSteerTag:"Steer",queueFollowTag:"Queued",sendTip:"Send (Enter)",slashCommands:"Commands",slashMenuHint:"↑↓ select · Enter/Tab complete",slashHelpTitle:"pi commands",slashHelpHint:"Type / anytime to open the command list",slashLoading:"Loading commands… (available once connected)",slashBuiltin:"Builtin",slashExtension:"Extension",slashPrompt:"Template",slashSkill:"Skill",slashCopied:"Copied the last assistant reply",slashCopyFailed:"Copy failed — please copy manually",slashCopyEmpty:"No assistant reply to copy yet",recentProjects:"Recent projects",runningConversations:"Running chats",historySessions:"History",openHistory:"History",openFiles:"Files",streaming:"Streaming…",noHistory:"No previous chats",current:"Current",messageCount:"{n} messages",tuiTip:"Chat in the pi terminal (TUI)",deleteProject:"Remove from recent projects",deleteProjectConfirm:"Confirm remove",deleteSession:"Delete this chat transcript permanently",deleteSessionConfirm:"Confirm delete",emptyChat:"Empty chat",editReask:"Edit & re-ask",editReaskTip:"Edit this question and re-ask from here (forks a new conversation; the original is kept)",reaskFromHere:"Re-ask from here",editPlaceholder:"Edit the question…",editHint:"⌘/Ctrl+Enter to submit · Esc to cancel",expandMsg:"Expand",collapseMsg:"Collapse",toolCalls:"tool calls",bashRuns:"bash runs",images:"images",update:"Update",updateTip:"Check & update pi-web-ui",currentVersion:"Current version",latestVersion:"Latest version",checkingUpdate:"Checking…",checkUpdate:"Check for updates",upToDate:"You're up to date",updateAvailable:"New version v{version} available",updateJustPublished:"v{version} was just published — npm cache may lag; if the new version isn't detected yet, re-check in a moment",updateNow:"Update in terminal",updateTabTitle:"Update pi-web-ui",updateTerminalHint:"Clicking runs npm i -g pi-web-ui@latest in a visible terminal; restart the service afterwards to take effect (pi-web-ui server restart).",rootDir:"Root",noFiles:"No files",filesTruncated:"Directory too large — list truncated (first 2000 shown)",linkFolderTip:"Link folder path to chat",attachInlineTip:"Attach content to chat",referenceTip:"Reference path only (AI reads on demand)",previewFile:"Preview",downloadFile:"Download file",downloadFailed:"Download failed: {error}",protocolMismatch:"Page version differs from the server (the app was just updated). Refresh the page to restore full functionality.",selectLinesHint:"Click a line to select; drag or Shift+click for a range",enableWrap:"Enable line wrap",disableWrap:"Disable line wrap",selectedRange:"Selected {n} lines (lines {start}-{end})",fileLines:"{n} lines",selectAll:"Select all",clearSelection:"Clear",addToChat:"Add to chat",addedToChat:"Added",previewTruncated:"⚠ File too large — previewing the first 512KB",previewLinesTruncated:"… too many lines — showing the first {n}",binaryFile:"🔣 Binary file — first 4KB shown as hex",binaryHexTruncated:" (file larger — download for the full file)",previewNotSupported:"This file type can't be previewed (only images / videos / text)",emptyFile:"(empty file)",editFile:"Edit file",exitEditFile:"Exit editing",saveFile:"Save file",discardFileChanges:"Discard unsaved changes?",fileSaved:"Saved",fileEditTruncated:"The preview is incomplete, so this file can't be edited",showMarkdownSource:"Show Markdown source",showMarkdownPreview:"Show Markdown preview",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",zoomIn:"Increase font size",zoomOut:"Decrease font size",resetZoom:"Reset zoom",pluginRequest:"Plugin request",noOptions:"(no options)",inputPlaceholder:"Enter content",soundHeader:"Sound notifications",enableSound:"Enable sound",preview:"Preview",volume:"Volume","sound.question":"Question popup","sound.question.desc":"When ask_user_question appears","sound.done":"Reply finished","sound.done.desc":"When the agent finishes a turn","sound.start":"Reply started","sound.start.desc":"When the agent starts a new turn","sound.error":"Error","sound.error.desc":"When an error notice appears",setupTitle:"pi agent config not detected",setupDesc:"pi-web-ui needs pi's config directory (~/.pi/agent) and at least one API key to run the agent. pi has built-in providers such as openai, anthropic, and deepseek — just pick one and enter a key, no terminal needed.",installFailed:"✖ pi agent installation failed:",retryInstall:"Retry install",skip:"Skip",installDone:"✅ pi agent CLI installed. Pick a provider and enter an API key to start chatting:",provider:"Provider",configured:"configured",providerKeyReady:"This provider already has a key — use it or replace it.",apiKey:"API key",saving:"Saving…",saveAndStart:"Save and start using",recheck:"Recheck",installing:"Installing pi agent CLI…",autoInstall:"Auto-install pi agent",attachment:"Attachment",plugin:"plugin",unknown:"unknown",thinkingWait:"Thinking",exitCode:"Exit code {code}",cancelled:"Cancelled",truncated:"… content too long, truncated in this view",outputTruncated:"… output too long, truncated in this view",refOnlyShort:"Reference only",folderRefShort:"Folder · reference only",inlineLines:"Inline · {n} lines",inlineLinesRange:"Lines {start}-{end}",image:"🖼 Image",bridgedVision:"👁 Transcribed",bridgedVisionDetail:"Image transcribed by the vision bridge (current model can't see images)",folderNotExpanded:"Folder — content not expanded, the agent will browse it as needed",fileNotExpanded:"Large file ({size}) — content not expanded, the agent will read it as needed","role.user":"You","role.assistant":"pi","role.tool":"Tool","role.bash":"Terminal","role.branch":"Branch summary","role.compaction":"Context compacted",welcomeTitle:"pi coding agent",welcomeSub:"Inspect, edit, run — always ready",directory:"Directory",clickToFill:"Click to fill input",waitingResponse:"Waiting for model response…",backToBottom:"Back to bottom",questionNavTitle:"Questions",searchPlaceholder:"Search in conversation…",searchNoResults:"No results",searchModels:"Filter models…",noModelMatches:"No matching models",searchGlobal:"Search",searchGlobalTip:"Global search: sessions / projects / files (Ctrl+K)",gsPlaceholder:"Search projects, past conversations, workspace files…",gsHint:"Type to search session history, recent projects and file names in the current workspace at once",gsSessions:"Conversations",gsProjects:"Projects",gsFiles:"Files",gsNoResults:"No matches",gsSearching:"Searching files…",gsTruncated:"Too many matches — showing a subset",gsCurrentProject:"current",gsOpenPreview:"Open file preview",gsNavigate:"select",gsOpen:"open",gsCloseHint:"close",bgTaskCommand:"Command",searchPrev:"Previous (Shift+Enter)",searchNext:"Next (Enter)",searchClose:"Close (Esc)",questionNavTip:"All questions in this conversation — hover to expand, click to jump","ex.understand":"Understand this project","ex.understand.prompt":"Introduce this project: overall structure, main modules, and how to run it?","ex.debug":"Debug an issue","ex.debug.prompt":"Help me debug a bug — describe the symptom first, and I'll add details.","ex.test":"Write tests","ex.test.prompt":"Write unit tests for the core modules.","ex.review":"Code review","ex.review.prompt":"Review the recently changed code and point out potential issues and improvements.",error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"Run bash commands inside the persistent visible terminal: full output returned automatically, shell state retained across calls (cd/venv/ssh); silent commands move to the background and notify the AI when they finish",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"When a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",settingsPresets:"Presets",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},Rs=i.createContext(null);function Fn(){try{const t=localStorage.getItem(Ms);if(t==="zh"||t==="en")return t}catch{}return"zh"}function An({children:t}){const[s,n]=i.useState(Fn),o=i.useCallback(a=>{n(a);try{localStorage.setItem(Ms,a)}catch{}},[]),c=i.useCallback((a,l)=>{let u=$n[a];if(s==="zh"&&(u=_n[a]),l)for(const[m,f]of Object.entries(l))u=u.replaceAll(`{${m}}`,String(f));return u},[s]);i.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const r=i.useMemo(()=>({locale:s,setLocale:o,t:c}),[s,o,c]);return e.jsx(Rs.Provider,{value:r,children:t})}function Rt(){const t=i.useContext(Rs);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function he(){return Rt().t}const On=["off","minimal","low","medium","high","xhigh","max"],Ls=i.memo(function({state:s,models:n,modelsLoading:o,send:c,onManageModels:r,compact:a=!1}){const l=he(),u=s==null?void 0:s.model,m=u?`${u.provider}/${u.id}`:null,[f,h]=i.useState(!1),[k,N]=i.useState(!1),[M,D]=i.useState("");i.useEffect(()=>{f||D("")},[f]);const S=i.useMemo(()=>{const v=M.trim().toLowerCase();return v?n.filter(w=>w.name.toLowerCase().includes(v)||w.provider.toLowerCase().includes(v)||w.id.toLowerCase().includes(v)):n},[n,M]),[P,$]=i.useState(!1),p=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,C=On.map(v=>({value:v,label:l(`thinking.${v}`),supported:p?p.has(v):!0})),T=v=>{var w;return((w=C.find(d=>d.value===v))==null?void 0:w.label)??v};return i.useEffect(()=>{f&&n.length===0&&!P&&!o&&($(!0),c({type:"list_models"}))},[f,n.length,P,o,c]),i.useEffect(()=>{n.length>0&&$(!1)},[n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(rt,{}),e.jsx("span",{className:"chip-model",children:u?u.name:l("selectModel")}),!a&&(u==null?void 0:u.vision)&&e.jsx("span",{className:"chip-vision",title:l("vision"),children:"🖼"}),!a&&u&&e.jsx("span",{className:"chip-sub",children:u.provider})]}),open:f,onOpenChange:h,menuClassName:"dd-menu-model",children:[e.jsx("div",{className:"dd-header",children:l("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(nt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:l("searchModels"),value:M,onChange:v=>D(v.target.value)})]}),e.jsxs("div",{className:"dd-model-scroll",children:[(P||o)&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.length===0&&!P&&!o&&e.jsx("div",{className:"dd-loading",children:l("noModels")}),S.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:l("noModelMatches")}),S.map(v=>e.jsx(Ce,{active:m===v.id,onClick:()=>{m!==v.id&&c({type:"set_model",modelId:v.id}),h(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:v.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:v.provider}),(v.reasoning||v.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[v.reasoning&&e.jsx("span",{className:"dd-model-badge",children:l("reasoning")}),v.vision&&e.jsx("span",{className:"dd-model-badge",children:l("vision")})]})]})]})},v.id))]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:l("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{h(!1),r()},children:l("manageModels")})]})]}),e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(vt,{}),e.jsx("span",{className:"chip-sub",children:l("thinkingChip",{level:s?T(s.thinkingLevel):"—"})})]}),open:k,onOpenChange:N,children:[e.jsx("div",{className:"dd-header",children:l("thinkingLevel")}),C.map(v=>e.jsx(Ce,{active:(s==null?void 0:s.thinkingLevel)===v.value,disabled:!v.supported,title:v.supported?void 0:l("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==v.value&&c({type:"set_thinking",level:v.value}),N(!1)},children:v.label},v.value))]})]})}),Hn=[{kind:"question",labelKey:"sound.question",descKey:"sound.question.desc"},{kind:"done",labelKey:"sound.done",descKey:"sound.done.desc"},{kind:"start",labelKey:"sound.start",descKey:"sound.start.desc"},{kind:"error",labelKey:"sound.error",descKey:"sound.error.desc"}];function Jt({settings:t,onChange:s,onPreview:n}){const o=he(),c=r=>s({...t,...r});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:o("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(ws,{className:"sound-icon"}),e.jsx("span",{children:o("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:r=>c({enabled:r.target.checked})})]}),Hn.map(({kind:r,labelKey:a,descKey:l})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:o(a)}),e.jsx("span",{className:"sound-desc",children:o(l)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:o("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),n(r)},children:o("preview")}),e.jsx("input",{type:"checkbox",checked:t[r],disabled:!t.enabled,onChange:u=>c({[r]:u.target.checked})})]})]},r)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:o("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:r=>c({volume:Number(r.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function Wn({chat:t,send:s,terminal:n,view:o,plugins:c,onViewChange:r,onOpenPanel:a,onManageModels:l,onOpenSettings:u,onOpenBgTasks:m,onOpenGlobalSearch:f,sound:h,onSoundChange:k,onSoundPreview:N,themes:M,theme:D,onThemeChange:S}){var ae;const{locale:P,setLocale:$,t:p}=Rt(),[C,T]=i.useState(!1),[v,w]=i.useState(!1),[d,R]=i.useState(!1),[F,z]=i.useState(!1),[W,G]=i.useState(!1),V=[{value:"zh",label:p("langZh")},{value:"en",label:p("langEn")}],L=t.ready?p("connected"):t.status==="closed"?p("reconnecting"):p("connecting"),H=t.ready?"ok":"busy",A=()=>{var B,te;if(!t.ready)return;const I=p("updateTabTitle"),j={name:I,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},x=t.terminals.find(ue=>ue.title===I);x?(n.restart(x.id),s({type:"run_command",terminalId:x.id,conversationId:x.conversationId,command:j,cols:80,rows:24})):n.create({id:Be(),conversationId:t.activeConversationId||((B=t.state)==null?void 0:B.conversationId)||"",title:I,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:j}),z(!1),G(!1),r("terminal")},oe=()=>{var I,j;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:p("currentVersion")}),e.jsxs("b",{children:["v",((I=t.update)==null?void 0:I.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:p("latestVersion")}),e.jsx("b",{children:t.update===null?p("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:p("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:p("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:p("updateAvailable",{version:t.update.latest})}),((j=t.update)==null?void 0:j.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:p("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:p("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?p("checkingUpdate"):p("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:A,children:p("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:p("openHistory"),onClick:()=>a("left"),children:e.jsx(kn,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${H}`,title:L}),e.jsx("span",{className:"conn-label",children:L})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":p("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="chat",className:o==="chat"?"active":"",onClick:()=>r("chat"),children:[e.jsx(at,{}),e.jsx("span",{children:p("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="terminal",className:o==="terminal"?"active":"",onClick:()=>r("terminal"),children:[e.jsx(Ge,{}),e.jsx("span",{children:p("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":o==="git",className:o==="git"?"active":"",onClick:()=>r("git"),children:[e.jsx(Ye,{}),e.jsx("span",{children:p("scmTab")})]}),c.map(I=>{const j=I.error?`${I.name}: ${I.error}`:I.description?`${I.name} — ${I.description}`:I.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":o===`plugin:${I.id}`,className:`plugin-tab${o===`plugin:${I.id}`?" active":""}${I.error?" broken":""}`,title:j,onClick:()=>r(`plugin:${I.id}`),children:[I.icon?e.jsx("span",{"aria-hidden":!0,children:I.icon}):e.jsx(Ss,{}),e.jsx("span",{children:I.name})]},I.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:p("searchGlobalTip"),onClick:f,children:[e.jsx(nt,{}),e.jsx("span",{className:"chip-sub",children:p("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":p("bgTasksTip"),onClick:m,children:[e.jsx(it,{}),e.jsx("span",{className:"chip-sub",children:p("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(Ls,{state:t.state?{model:t.state.model,thinkingLevel:t.state.thinkingLevel,availableThinkingLevels:t.state.availableThinkingLevels}:null,models:t.models,modelsLoading:t.modelsLoading,send:s,onManageModels:l}),e.jsxs("button",{type:"button",className:"chip",title:p("settingsTitle"),onClick:u,children:[e.jsx(st,{}),e.jsx("span",{className:"chip-sub",children:p("settings")})]}),e.jsx(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ws,{}),e.jsx("span",{className:"chip-sub",children:p("sound")})]}),open:C,onOpenChange:T,children:e.jsx(Jt,{settings:h,onChange:k,onPreview:N})}),e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(En,{}),e.jsx("span",{className:"chip-sub",children:P==="zh"?p("langZh"):"EN"})]}),open:v,onOpenChange:w,children:[e.jsx("div",{className:"dd-header",children:p("language")}),V.map(I=>e.jsx(Ce,{active:P===I.value,onClick:()=>{$(I.value),w(!1)},children:I.label},I.value))]}),e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(fn,{}),e.jsx("span",{className:"chip-sub",children:p("theme")})]}),open:d,onOpenChange:R,children:[e.jsx("div",{className:"dd-header",children:p("theme")}),e.jsx(Ce,{active:D===null,onClick:()=>{S(null),R(!1)},children:p("themeDefault")}),M.map(I=>e.jsx(Ce,{active:D===I.id,onClick:()=>{S(I.id),R(!1)},children:I.name},I.id))]}),e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Et,{}),e.jsxs("span",{className:"chip-sub",children:["v",((ae=t.update)==null?void 0:ae.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:p("updateAvailable",{version:t.update.latest??""})})]}),open:F,onOpenChange:I=>{z(I),I&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:p("update")}),oe()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:p("githubRepo"),children:e.jsx(Vt,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":p("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(We,{}),e.jsx("span",{children:p("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Le,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(jn,{}),e.jsx("span",{className:"chip-sub",children:p("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:W,onOpenChange:I=>{G(I),I&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:p("sound")}),e.jsx("div",{className:"dd-header",children:p("settings")}),e.jsxs(Ce,{onClick:()=>{G(!1),u()},children:[e.jsx(st,{})," ",p("settingsTitle")]}),e.jsxs(Ce,{onClick:()=>{G(!1),f()},children:[e.jsx(nt,{})," ",p("searchGlobal")]}),e.jsxs(Ce,{onClick:()=>{G(!1),m()},children:[e.jsx(it,{})," ",p("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(Jt,{settings:h,onChange:k,onPreview:N}),e.jsx("div",{className:"dd-header",children:p("language")}),V.map(I=>e.jsx(Ce,{active:P===I.value,onClick:()=>$(I.value),children:I.label},I.value)),e.jsx("div",{className:"dd-header",children:p("theme")}),e.jsx(Ce,{active:D===null,onClick:()=>{S(null),G(!1)},children:p("themeDefault")}),M.map(I=>e.jsx(Ce,{active:D===I.id,onClick:()=>{S(I.id),G(!1)},children:I.name},I.id)),e.jsx("div",{className:"dd-header",children:p("update")}),oe(),e.jsxs("a",{className:"dd-refresh dd-more-link",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",children:[e.jsx(Vt,{})," ",p("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:p("openFiles"),onClick:()=>a("right"),children:e.jsx(qe,{})})]})]})}function Qt(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}const qn=i.memo(function({ready:s,status:n,cwd:o,sessionFile:c,conversations:r,sessions:a,projects:l,activeConversationId:u,send:m,active:f}){const h=he(),k=c,N=o,[M,D]=i.useState(null);i.useEffect(()=>{!f||!s||n!=="open"||o&&(m({type:"list_sessions"}),m({type:"list_projects"}))},[f,s,n,o,m]);const S=p=>{const C=p.name||p.firstMessage.trim();return C.length>0?C:h("emptyChat")},P=p=>p.split(/[\\/]/).pop()||p,$=(p,C,T,v)=>{const w=M===p;return e.jsx("button",{type:"button",className:`lp-del ${w?"confirm":""}`,title:w?T:C,onClick:d=>{d.stopPropagation(),w?(D(null),v()):D(p)},children:w?e.jsx(ct,{}):e.jsx(He,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[l.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:h("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:l.map(p=>{const C=N===p.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(T=>T===`proj:${p.path}`?null:T),children:[e.jsxs("button",{type:"button",className:`project-item ${C?"active":""}`,title:p.path,onClick:()=>{C||m({type:"set_cwd",path:p.path})},children:[e.jsx(qe,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:P(p.path)}),e.jsx("span",{className:"project-path",children:p.path})]}),e.jsx("span",{className:"project-time",children:Qt(p.lastUsed)})]}),$(`proj:${p.path}`,h("deleteProject"),h("deleteProjectConfirm"),()=>m({type:"remove_project",path:p.path}))]},p.path)})})]}),r.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:h("runningConversations")}),r.map(p=>{const C=u===p.id;return e.jsxs("button",{type:"button",className:`session-item ${C?"active":""}`,title:p.title,onClick:()=>{C||m({type:"switch_conversation",id:p.id})},children:[e.jsx(at,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:p.title}),e.jsx("span",{className:"session-sub",children:C?h("current"):h("messageCount",{n:p.messageCount})})]}),p.isStreaming&&e.jsx("span",{className:"conv-streaming",title:h("streaming")})]},p.id)}),e.jsx("div",{className:"panel-section-divider"})]}),e.jsxs("div",{className:"panel-sessions",children:[e.jsx("div",{className:"panel-section-title",children:h("historySessions")}),e.jsxs("div",{className:"sessions-scroll",children:[a.length===0&&e.jsx("div",{className:"panel-empty",children:h("noHistory")}),a.map(p=>{const C=k===p.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(T=>T===`sess:${p.path}`?null:T),children:[e.jsxs("button",{type:"button",className:`session-item ${C?"active":""}`,title:p.path,onClick:()=>{C||m({type:"switch_session",path:p.path})},children:[e.jsx(at,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:S(p)}),e.jsxs("span",{className:"session-sub",children:[C?h("current"):h("messageCount",{n:p.messageCount}),p.source==="tui"&&e.jsx("span",{className:"session-src",title:h("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:Qt(p.modified)})]}),$(`sess:${p.path}`,h("deleteSession"),h("deleteSessionConfirm"),()=>m({type:"delete_session",path:p.path}))]},p.path)})]})]})]})}),Is="pi-web-ui:token";function Un(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Is,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function zn(){try{return localStorage.getItem(Is)??""}catch{return""}}function dt(t){const s=zn();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function Kn(t,s){const n=s.assistantMessageEvent,o=t.stats.tokens,c=s.usage!==null?{...o,...s.usage}:o,r=c===o?t.stats:{...t.stats,tokens:c};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return r===t.stats?t:{...t,stats:r};const a=n.delta??"";if(!a)return r===t.stats?t:{...t,stats:r};const l=t.streamingMessage??null,u=l&&l.id===s.messageId?l:{id:s.messageId,content:[]},m=[...u.content],f=n.type==="thinking_delta"?"thinking":"text",h=n.contentIndex??m.length-1;return h>=0&&h<m.length&&m[h].type===f?m[h]=f==="thinking"?{type:"thinking",thinking:(m[h].thinking??"")+a}:{type:"text",text:(m[h].text??"")+a}:m.push(f==="thinking"?{type:"thinking",thinking:a}:{type:"text",text:a}),{...t,stats:r,streamingMessage:{...u,id:s.messageId,content:m}}}const bt="pi-web-ui:plugin-data";function Vn(t,s){window.dispatchEvent(new CustomEvent(bt,{detail:{pluginId:t,payload:s}}))}function Gn(t){const s=n=>{const o=n.detail;t(o.pluginId,o.payload)};return window.addEventListener(bt,s),()=>window.removeEventListener(bt,s)}const Oe=new Map,kt=new Set,Fe=new Set;let Yt=-1;function Ps(){return[...Oe.values()]}function Jn(){const t=Ps();for(const s of kt)s(t)}function Qn(t){return kt.add(t),t(Ps()),()=>kt.delete(t)}async function Yn(t,s){s!==Yt&&(Yt=s,Oe.clear(),Fe.clear());const n=new Set(t.map(o=>o.id));for(const o of[...Oe.keys()])n.has(o)||Oe.delete(o);for(const o of[...Fe])n.has(o)||Fe.delete(o);await Promise.all(t.filter(o=>o.hasClient&&!o.error&&!Oe.has(o.id)&&!Fe.has(o.id)).map(async o=>{try{const r=(await js(()=>import(`/plugins/${encodeURIComponent(o.id)}/client/entry.mjs?e=${s}`),[])).default;r&&typeof r.mount=="function"?Oe.set(o.id,{info:o,module:r}):(Fe.add(o.id),console.error(`[plugin:${o.id}] entry.mjs 缺少 default.mount`))}catch(c){Fe.add(o.id),console.error(`[plugin:${o.id}] 客户端加载失败:`,c)}})),Jn()}function Xn(t,s){return{pluginId:t,send:n=>s({type:"plugin_message",pluginId:t,payload:n}),onData:n=>Gn((o,c)=>{o===t&&n(c)})}}const Zn=7,pt=2e5,ea=2e5,ta={conversationId:null,goal:null,reviewModel:null,maxRounds:3,locked:!0,reviewing:!1,round:0,status:"",verdict:"pending",wizard:{active:!1,draft:"",model:null,step:0,maxSteps:6,status:""}};function sa(){const t=new Map,s=new Map,n=(o,c)=>`${o}:${c}`;return{write(o,c,r){const a=n(o,c),l=t.get(a);if(l&&l.size>0){for(const f of l)try{f.write(r)}catch{}return}const u=s.get(a)??"",m=u.length+r.length>ea?r:u+r;s.set(a,m)},register(o,c,r){const a=n(o,c);let l=t.get(a);l||(l=new Set,t.set(a,l)),l.add(r);const u=s.get(a);if(u){try{r.write(u)}catch{}s.delete(a)}return()=>{const m=t.get(a);m&&(m.delete(r),m.size===0&&t.delete(a)),s.delete(a)}},clear(){t.clear(),s.clear()}}}function Xt(t,s){const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId),c.role==="bashExecution"&&n.add(`bash-${c.id}`);let o=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),o=!0);return o?new Map(t):t}function Zt(t,s){if(t.size===0)return t;const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId);let o=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),o=!0);return o?new Map(t):t}function na(t,s){var n,o,c,r;switch(s.type){case"status":return{...t,status:s.status,ready:s.status==="open"?t.ready:!1,terminals:s.status==="closed"?[]:t.terminals};case"ready":return{...t,serverVersion:s.serverVersion,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==Zn};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Xt(t.liveOutputs,s.state),toolStatuses:Zt(t.toolStatuses,s.state)};case"snapshot_delta":{const a=t.state,l=s.msg;if(!a||a.conversationId!==l.conversationId||a.rev!==l.baseRev)return t;const u={...a,...l.state,messages:l.appended.length>0?[...a.messages,...l.appended]:a.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:Xt(t.liveOutputs,u),toolStatuses:Zt(t.toolStatuses,u)}}case"tool_delta":{const a=t.liveOutputs.get(s.toolCallId),l=((a==null?void 0:a.text)??"")+s.delta,u=l.length>pt?`…[前 ${l.length-pt} 字符已省略]…
|
|
3
|
+
`+l.slice(l.length-pt):l,m=new Map(t.liveOutputs);return m.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:m}}case"message_delta":{const a=t.state;return!a||a.conversationId!==s.msg.conversationId?t:{...t,state:Kn(a,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(a=>a.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(a=>a.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(n=t.state)!=null&&n.conversationId)&&s.conversationId!==(t.activeConversationId||((o=t.state)==null?void 0:o.conversationId))?t:{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!1,exitCode:s.exitCode}:a)};case"terminal_restart":return{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!0,exitCode:null}:a)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:s.terminals.map(a=>{var l;return{...a,conversationId:s.conversationId??((l=t.state)==null?void 0:l.conversationId)??""}})};default:return t}}const es="pi-web-client-id";let ht=null;function Lt(){if(ht)return ht;let t=null;try{t=sessionStorage.getItem(es),t||(t=Be(),sessionStorage.setItem(es,t))}catch{t=t??Be()}return ht=t,t}function aa(){const t=location.protocol==="https:"?"wss:":"ws:";return dt(`${t}//${location.host}/ws`)}function ia(){const[t,s]=i.useReducer(na,{status:"connecting",ready:!1,state:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:[],conversations:[],activeConversationId:"",projects:[],files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],installResult:null,pathCompletions:[],update:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:ta,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,protocolMismatch:!1}),n=i.useRef(null),o=i.useRef(sa()),c=i.useRef(0),r=i.useRef(null),a=i.useRef(!0),l=i.useRef(0),u=i.useRef(0),m=i.useRef(new Map),f=i.useRef(null),h=()=>{f.current||(f.current=setTimeout(()=>{f.current=null;const v=n.current;v&&v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:"get_state"}))},300))},k=(v,w)=>{var F;const d=m.current,R=d.get(v);if(R!==void 0&&w!==R+1){const z=T.current.chat,W=z.activeConversationId||((F=z.state)==null?void 0:F.conversationId);v===W&&h()}d.set(v,w)},N=i.useCallback((v,w)=>{const d=++u.current;s({type:"notice",notice:{id:d,level:v,text:w}})},[]),M=i.useCallback(v=>{const w=n.current;return w&&w.readyState===WebSocket.OPEN?(w.send(JSON.stringify(v)),!0):!1},[]),D=i.useCallback(()=>{if(!a.current)return;s({type:"status",status:"connecting"});const v=new WebSocket(aa());n.current=v,v.onopen=()=>{n.current===v&&(s({type:"status",status:"open"}),c.current=0,l.current=Date.now(),v.send(JSON.stringify({type:"hello",clientId:Lt()})))},v.onmessage=w=>{if(n.current!==v)return;l.current=Date.now();let d;try{d=JSON.parse(w.data)}catch{return}switch(d.type){case"ready":s({type:"ready",serverVersion:d.serverVersion,protocolVersion:d.protocolVersion}),v.send(JSON.stringify({type:"get_state"})),v.send(JSON.stringify({type:"list_files"})),v.send(JSON.stringify({type:"list_models"})),v.send(JSON.stringify({type:"list_commands"})),v.send(JSON.stringify({type:"get_commands"})),v.send(JSON.stringify({type:"check_update"}));break;case"snapshot":m.current=new Map,s({type:"snapshot",state:d.state});break;case"snapshot_delta":{const R=T.current.chat.state;(!R||R.conversationId!==d.conversationId||R.rev!==d.baseRev)&&h(),s({type:"snapshot_delta",msg:d});break}case"tool_delta":k(d.conversationId,d.seq),s({type:"tool_delta",toolCallId:d.toolCallId,toolName:d.toolName,delta:d.delta});break;case"tool_status":s({type:"tool_status",status:d});break;case"message_delta":{k(d.conversationId,d.seq),s({type:"message_delta",msg:d});break}case"notice":{const R=++u.current;s({type:"notice",notice:{id:R,level:d.level,text:d.text}});break}case"sessions":s({type:"sessions",sessions:d.sessions});break;case"conversations":s({type:"conversations",conversations:d.conversations,activeId:d.activeId});break;case"projects":s({type:"projects",projects:d.projects});break;case"files":s({type:"files",files:d});break;case"file_changed":s({type:"file_changed",path:d.path});break;case"file_content":s({type:"file_content",content:d});break;case"models":s({type:"models",models:d.models,loading:!1});break;case"models_config":s({type:"models_config",providers:d.providers});break;case"providers_status":s({type:"providers_status",providers:d.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:d.reqId,ok:d.ok,models:d.models,error:d.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:d.reqId,ok:d.ok,added:d.added,total:d.total,error:d.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:d.reqId,ok:d.ok,config:d.config,error:d.error}});break;case"scm_data":s({type:"scm_data",data:d});break;case"search_files_result":s({type:"file_search_result",result:{reqId:d.reqId,ok:d.ok,results:d.results,truncated:d.truncated}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:d});break;case"path_completions":s({type:"path_completions",completions:d.completions});break;case"update_status":s({type:"update_status",status:d});break;case"widgets":s({type:"widgets",widgets:d.widgets});break;case"statuses":s({type:"statuses",statuses:d.statuses});break;case"dialog":s({type:"dialog",dialog:{id:d.id,kind:d.kind,title:d.title,args:d.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"terminal_output":o.current.write(d.conversationId??T.current.chat.activeConversationId,d.terminalId,d.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:d.conversationId,terminalId:d.terminalId,exitCode:d.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:d.conversationId,terminals:d.terminals});break;case"commands":s({type:"commands",commands:d.commands,path:d.path});break;case"slash_commands":s({type:"slash_commands",commands:d.commands});break;case"goal_status":s({type:"goal_status",status:d.status});break;case"settings_state":s({type:"settings",settings:d.settings});break;case"bg_servers":s({type:"bg_servers",servers:d.servers});break;case"plugins":s({type:"plugins",plugins:d.plugins,epoch:d.epoch});break;case"plugin_data":Vn(d.pluginId,d.payload);break}},v.onclose=()=>{if(n.current===v&&(n.current=null),o.current.clear(),!a.current||n.current&&n.current!==v)return;s({type:"status",status:"closed"});const w=Math.min(1e3*2**c.current,1e4);c.current+=1,r.current=setTimeout(()=>{r.current=null,D()},w)},v.onerror=()=>{}},[]);i.useEffect(()=>{a.current=!0,D();const v=setInterval(()=>{if(!a.current)return;const w=n.current;w&&w.readyState===WebSocket.OPEN&&Date.now()-l.current>3e4&&w.close()},5e3);return()=>{var w;a.current=!1,clearInterval(v),r.current&&(clearTimeout(r.current),r.current=null),(w=n.current)==null||w.close(),n.current=null}},[D]);const S=i.useCallback(v=>s({type:"dismiss_notice",id:v}),[]),P=i.useCallback(v=>s({type:"terminal_add",meta:v}),[]),$=i.useCallback(v=>s({type:"terminal_remove",id:v}),[]),p=i.useCallback(v=>s({type:"terminal_restart",terminalId:v}),[]),C=i.useCallback((v,w,d)=>o.current.register(v,w,d),[]),T=i.useRef({chat:t,send:M,pushNotice:N,dismissNotice:S,terminal:{create:P,close:$,register:C,restart:p}});return T.current={chat:t,send:M,pushNotice:N,dismissNotice:S,terminal:{create:P,close:$,register:C,restart:p}},T.current}const ra=200*1024*1024,oa=/windows/i.test(navigator.userAgent),la=/[<>:"/\\|?*\u0000-\u001f]/g,ca=/[. ]+$/,da=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function ua(t){const s=t.replace(la,"_").replace(ca,"");return s?da.test(s)?`_${s}`:s:"_"}function ts(t,s=!0){const n=new URLSearchParams({clientId:Lt(),path:t,...s?{download:"1"}:{}});return dt(`/api/file?${n}`)}async function ma(t,s){const n=oa?ua(s):s;try{const o=await fetch(ts(t));if(!o.ok)return{ok:!1,cancelled:!1,error:await o.text().catch(()=>"")||(o.status===404?"文件不存在":`HTTP ${o.status}`)};if(Number(o.headers.get("content-length")??"0")>ra)return window.location.assign(ts(t)),{ok:!0};const r=await o.blob();return window.showSaveFilePicker&&window.isSecureContext?pa(r,n):wt(r,n)}catch(o){return{ok:!1,cancelled:!1,error:o instanceof Error?o.message:String(o)}}}async function pa(t,s){let n;const o=window.showSaveFilePicker;if(!o)return wt(t,s);try{n=await o({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:wt(t,s)}try{const c=await n.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function wt(t,s){const n=URL.createObjectURL(t),o=document.createElement("a");return o.href=n,o.download=s,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const ha=i.memo(function({files:s,fileChanged:n,widgets:o,cwd:c,send:r,onAttach:a,onPreview:l,onNotice:u}){const m=he(),[f,h]=i.useState(""),[k,N]=i.useState(null),[M,D]=i.useState(!1),S=1e4,P=i.useRef(0),$=i.useRef(void 0),p=i.useCallback((w,d)=>{const R=++P.current;h(w),d!=null&&d.silent||D(!0),r({type:"list_files",path:w===""?void 0:w})||P.current===R&&D(!1)},[r]);i.useEffect(()=>{s&&s.path===f&&D(!1)},[s,f]),i.useEffect(()=>{if(c!==$.current){$.current=c,p("",{silent:!0});return}const w=setInterval(()=>{document.visibilityState!=="hidden"&&p(f,{silent:!0})},S);return()=>clearInterval(w)},[c,f,p]),i.useEffect(()=>{n&&n.path===f&&p(f,{silent:!0})},[n,f,p]);const C=w=>p(w),T=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&p(s.parent)},v=f.split("/").filter(Boolean);return e.jsxs("aside",{className:"panel panel-right",children:[e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${f===""?"active":""}`,onClick:()=>p(""),children:m("rootDir")}),v.map((w,d)=>{const R=v.slice(0,d+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(lt,{}),e.jsx("button",{type:"button",className:`crumb ${R===f?"active":""}`,onClick:()=>p(R),children:w})]},R)})]}),e.jsxs("div",{className:"panel-body",children:[M&&e.jsx("div",{className:"panel-empty",children:m("loading")}),!M&&s&&s.path===f&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:T,children:[e.jsx(qe,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(w=>w.type==="dir"?e.jsxs("div",{className:"file-item dir",children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>C(w.path),children:[e.jsx(qe,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("linkFolderTip"),onClick:()=>a(w.path,w.name,"reference",!0),children:e.jsx(yt,{})})]},w.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${w.path} — ${m("previewFile")}`,onClick:()=>l(w.path,w.name),children:[e.jsx(Ns,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":m("downloadFile"),onClick:()=>{ma(w.path,w.name).then(d=>{d.ok||d.cancelled||u("error",m("downloadFailed",{error:d.error}))})},children:e.jsx(Et,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":m("attachInlineTip"),onClick:()=>a(w.path,w.name,"inline"),children:e.jsx(We,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("referenceTip"),onClick:()=>a(w.path,w.name,"reference"),children:e.jsx(yt,{})})]},w.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:m("filesTruncated")})]}),!M&&!s&&e.jsx("div",{className:"panel-empty",children:m("noFiles")})]}),o.filter(w=>w.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:o.filter(w=>w.lines.length>0).map(w=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:m("widgetExpand"),onClick:()=>N(w.key),children:[e.jsx("span",{children:w.key}),e.jsx(Nn,{})]}),e.jsx("pre",{className:"widget-lines",children:w.lines.join(`
|
|
4
|
+
`)})]},w.key))}),k&&(()=>{const w=o.find(d=>d.key===k);return w?e.jsx("div",{className:"modal-backdrop",onClick:()=>N(null),children:e.jsxs("div",{className:"widget-expand",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:w.key}),e.jsx("button",{type:"button",className:"btn",title:m("close"),onClick:()=>N(null),children:e.jsx(Te,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:w.lines.join(`
|
|
5
|
+
`)})]})}):null})()]})});var ss=ys();const Bs=i.memo(function({text:s}){const n=he(),[o,c]=i.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:n("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{c(!0),setTimeout(()=>c(!1),1200)})},children:o?e.jsx(ct,{}):e.jsx(Mt,{})}):null}),Ds=[en],_s=[[Zs,{detect:!0,ignoreMissing:!0}]];function $s({text:t}){return e.jsx(vs,{remarkPlugins:Ds,rehypePlugins:_s,components:{pre:ga},children:t})}const ut=i.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx($s,{text:s})})});function ga({children:t,...s}){return e.jsxs("div",{className:"codeblock",children:[e.jsx(Bs,{text:Nt(t)}),e.jsx("pre",{...s,children:t})]})}function Nt(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(Nt).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return Nt(s==null?void 0:s.children)}return""}const fa=/^\s{0,3}(`{3,}|~{3,})/,xa=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function gt(t){return t.trim()===""}function ns(t){const s=fa.exec(t);return s?s[1]:null}function va(t){const s=t.split(`
|
|
6
|
+
`),n=[];let o=[],c=null;for(let r=0;r<s.length;r++){const a=s[r];if(c!==null){const u=ns(a);u&&u[0]===c[0]&&u.length>=c.length&&(c=null),o.push(a);continue}const l=ns(a);if(l&&!gt(a)){c=l,o.push(a);continue}if(gt(a)){let u=r;for(;u<s.length&>(s[u]);)u++;if(!(u<s.length&&xa.test(s[u]))&&o.length>0){n.push(o.join(`
|
|
7
7
|
`)),o=[];continue}o.push(a);continue}o.push(a)}return{frozen:n,active:o.join(`
|
|
8
|
-
`),inFence:c!==null}}const
|
|
9
|
-
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${o?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>c(a=>!a),children:[o?e.jsx(
|
|
10
|
-
`),C=s.role==="user"?
|
|
11
|
-
`).join(" ").trim(),v=r&&a&&s.content.length===0,w=s.role==="user"&&!r&&!v&&!!l,d=()=>{
|
|
12
|
-
`)),D(!0)},R=()=>{const W=S.trim();W&&(l==null||l(s.id,W),D(!1))},F=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),z=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${F?" msg-goal-review":""}`,"data-role":s.role,"data-msg-id":s.id,children:[e.jsxs("div",{className:"msg-meta",children:[e.jsx("span",{className:"msg-role",children:s.role==="custom"?z?N("goalWizardCard"):F?N("goalBarTitle"):s.customType==="file"?N("attachment"):`${N("plugin")} · ${s.customType??N("unknown")}`:
|
|
13
|
-
`).length+1)),onChange:W=>
|
|
14
|
-
`),f=
|
|
15
|
-
`).length;return e.jsxs("div",{className:`attachcard ${l?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>o(N=>!N),children:[e.jsx("span",{className:"attachcard-icon",children:a?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:r}),c.path&&e.jsx("span",{className:"attachcard-path",children:c.path}),e.jsx("span",{className:`attachcard-mode ${c.mode==="lines"?"lines":l?"ref":u?"bridged":"inline"}`,children:l?a?s("folderRefShort"):`${s("refOnlyShort")} · ${
|
|
16
|
-
`)}function Fa(t,s){if(typeof t.text=="string"){s.push(t.text);return}switch(t.type){case"thinking":typeof t.thinking=="string"&&s.push(t.thinking);break;case"toolCall":{typeof t.name=="string"&&s.push(t.name),typeof t.argumentsText=="string"&&s.push(t.argumentsText);break}case"bash":typeof t.command=="string"&&s.push(t.command),typeof t.output=="string"&&s.push(t.output);break}}function Aa(t,s){const n=s.trim().toLowerCase();if(!n)return 0;const o=t.toLowerCase();let c=0,r=o.indexOf(n);for(;r!==-1;)c++,r=o.indexOf(n,r+n.length);return c}function Oa(t,s){const n=s.trim().toLowerCase();if(!n)return[];const o=[];for(const c of t){const r=$a(c);if(!r)continue;const a=Aa(r,n);for(let l=0;l<a;l++)o.push({messageId:c.id,occurrence:l})}return o}function Ha(t,s){var a;const n=new Map,o=[],c=s.toLowerCase();if(!c)return{byMsg:n,all:o};const r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(l){const u=l.parentElement;return!u||u.closest(".search-bar")?NodeFilter.FILTER_REJECT:(l.textContent??"").toLowerCase().includes(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let l=r.nextNode();l;l=r.nextNode()){const u=(l.textContent??"").toLowerCase(),m=(a=l.parentElement)==null?void 0:a.closest("[data-msg-id]");if(!m)continue;const f=m.getAttribute("data-msg-id")??"";let h=u.indexOf(c);for(;h!==-1;){const k=document.createRange();k.setStart(l,h),k.setEnd(l,h+c.length),o.push(k);const N=n.get(f);N?N.push(k):n.set(f,[k]),h=u.indexOf(c,h+c.length)}}return{byMsg:n,all:o}}function _e(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const o=window.Highlight;o&&n.highlights.set(t,new o(...s))}function Wa({containerRef:t,messages:s,open:n,onClose:o,onEnsureExpanded:c}){const r=he(),a=i.useRef(null),[l,u]=i.useState(""),[m,f]=i.useState(0),h=i.useDeferredValue(l),k=n?h.trim():"",N=i.useMemo(()=>n?Oa(s,k):[],[s,k,n]),M=i.useRef(N);M.current=N;const D=i.useRef(m);D.current=m,i.useEffect(()=>{n&&(f(0),requestAnimationFrame(()=>{var p;return(p=a.current)==null?void 0:p.select()}))},[n]),i.useEffect(()=>{if(!n)return;const p=C=>{C.key==="Escape"&&(C.preventDefault(),C.stopPropagation(),o())};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)},[n,o]),i.useEffect(()=>(n||(_e("msg-search",[]),_e("msg-search-active",[])),()=>{_e("msg-search",[]),_e("msg-search-active",[])}),[n]);const S=i.useCallback(p=>{const C=t.current;if(!C)return;const T=C.querySelector(`[data-msg-id="${p}"]`);T&&(T.classList.remove("msg-flash"),T.offsetWidth,T.classList.add("msg-flash"))},[t]);i.useLayoutEffect(()=>{if(!n||!k)return;const p=t.current;if(!p)return;let C=!1,T=0;return T=requestAnimationFrame(()=>{var z;if(C)return;const{byMsg:v,all:w}=Ha(p,k);_e("msg-search",w);const d=M.current,R=d[Math.min(D.current,d.length-1)];if(!R)return;const F=(z=v.get(R.messageId))==null?void 0:z[R.occurrence];if(F){_e("msg-search-active",[F]);const W=F.startContainer.parentElement??p.querySelector(`[data-msg-id="${R.messageId}"]`);W==null||W.scrollIntoView({block:"center"})}else S(R.messageId)}),()=>{C=!0,cancelAnimationFrame(T)}},[n,k,N,t,S]);const I=i.useCallback(p=>{const C=M.current;if(C.length===0)return;const T=(D.current+p+C.length)%C.length;f(T),c(C[T].messageId)},[c]);if(!n)return null;const $=N.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:a,className:"search-input",type:"text",value:l,placeholder:r("searchPlaceholder"),onChange:p=>{u(p.target.value),f(0)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),I(p.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${$===0?"empty":""}`,children:$===0?r("searchNoResults"):`${Math.min(m+1,$)}/${$}`}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchPrev"),disabled:$===0,onClick:()=>I(-1),children:e.jsx(rt,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchNext"),disabled:$===0,onClick:()=>I(1),children:e.jsx(Ie,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchClose"),onClick:o,children:e.jsx(Se,{})})]})}const rs=new Map,qa=15,os=30,ls=1200,Ua=1600;function cs(t){return t.content.some(s=>s.type==="toolCall")}const za=[{key:"ex.understand",icon:"🔍"},{key:"ex.debug",icon:"🐛"},{key:"ex.test",icon:"🧪"},{key:"ex.review",icon:"🧹"}];function Ka(t){return za.map(({key:s,icon:n})=>({icon:n,text:t(s),prompt:t(`${s}.prompt`)}))}function Va({state:t,liveOutputs:s,toolStatuses:n,onEdit:o,onKillBash:c}){const r=he(),a=i.useRef(null),[l,u]=i.useState(!0),m=i.useRef(!0),f=i.useRef(0),h=i.useRef(!1),[k,N]=i.useState(()=>new Set),[M,D]=i.useState(!1),S=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,I=i.useMemo(()=>{const b=new Map;for(const _ of t.messages)_.role==="toolResult"&&_.toolCallId&&b.set(_.toolCallId,_);return b},[t.messages]),$=S.length>0?S[S.length-1].id:null,p=t.messages.length>os?Math.max(0,t.messages.length-qa):0,[C,T]=i.useState(()=>new Set),[v,w]=i.useState(()=>new Set),d=i.useRef(new Map),R=i.useRef(new Map),F=i.useRef(0),z=i.useRef(C);z.current=C;const W=t.messages.length>os&&!M,G=i.useRef(W);G.current=W;const V=_a(t.messages,d.current,Ua),L=i.useRef(V);L.current=V;const O=i.useCallback(()=>{const b=a.current;if(!b)return;if(!G.current){T(de=>de.size?new Set:de);return}const _=b.getBoundingClientRect(),se={top:_.top-ls,bottom:_.bottom+ls},Q=[];for(const[de,ve]of R.current){const Ne=ve.getBoundingClientRect();Q.push({id:de,top:Ne.top,bottom:Ne.bottom}),z.current.has(de)||d.current.set(de,Ne.bottom-Ne.top)}const ce=Ba(Q,se,L.current,z.current);for(const de of ce.hide){const ve=R.current.get(de);ve&&d.current.set(de,ve.offsetHeight)}T(de=>Da(de,ce))},[]),A=i.useCallback(()=>{F.current||(F.current=requestAnimationFrame(()=>{F.current=0,O()}))},[O]);i.useLayoutEffect(()=>{O()},[O]);const re=i.useRef(M);i.useLayoutEffect(()=>{re.current&&!M&&O(),re.current=M},[M,O]);const ne=i.useCallback((b,_)=>{d.current.set(b,_)},[]),P=i.useCallback(b=>{b&&R.current.set(b.dataset.lazyId??"",b)},[]);i.useEffect(()=>{const b=new Set(t.messages.map(_=>_.id));for(const[_,se]of R.current)b.has(_)||(R.current.delete(_),d.current.delete(_));T(_=>{let se=!1;const Q=new Set;for(const ce of _)b.has(ce)?Q.add(ce):se=!0;return se?Q:_})},[t.messages,k]),i.useEffect(()=>()=>cancelAnimationFrame(F.current),[]);const j=i.useMemo(()=>{const b=[];for(const _ of t.messages){if(_.role!=="user")continue;const se=_.content.map(de=>{var ve;return((ve=Ke(de))==null?void 0:ve.text)??""}).filter(Boolean).join(" "),Q=Lt(se),ce=Q?Q.userMessage??`skill:${Q.name}`:se.trim();ce&&b.push({id:_.id,text:ce})}return b},[t.messages]),x=i.useMemo(()=>{const b=new Map;return j.forEach((_,se)=>b.set(_.id,se)),b},[j]),[B,te]=i.useState(-1),ue=i.useRef(-1),fe=i.useRef(j);i.useEffect(()=>{fe.current=j},[j]);const me=i.useCallback(()=>{const b=a.current,_=fe.current;if(!b||_.length===0)return;const se=b.getBoundingClientRect().top,Q=140;let ce=-1;for(let de=0;de<_.length;de++){const ve=b.querySelector(`[data-msg-id="${_[de].id}"]`);if(ve)if(ve.getBoundingClientRect().top<=se+Q)ce=de;else break}ce!==ue.current&&(ue.current=ce,te(ce))},[]);i.useEffect(()=>{me()},[j,me]);const X=i.useCallback(b=>{N(_=>_.has(b)?_:new Set(_).add(b))},[]),ge=i.useCallback(b=>{const _=t.messages.findIndex(se=>se.id===b);_>=0&&_<p&&!k.has(b)&&es.flushSync(()=>X(b))},[t.messages,p,k,X]);i.useEffect(()=>{const b=_=>{if(!(_.ctrlKey||_.metaKey)||_.key.toLowerCase()!=="f")return;const se=_.target;se&&(se.tagName==="INPUT"||se.tagName==="TEXTAREA"||se.isContentEditable)||(_.preventDefault(),D(!0))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]);const g=i.useCallback(b=>{N(_=>{if(!_.has(b))return _;const se=new Set(_);return se.delete(b),se})},[]),U=i.useCallback(b=>{const _=t.messages.findIndex(Q=>Q.id===b);es.flushSync(()=>{_>=0&&_<p&&!k.has(b)&&X(b),w(Q=>Q.has(b)?Q:new Set(Q).add(b))});const se=fe.current.findIndex(Q=>Q.id===b);ue.current=se,te(se),requestAnimationFrame(()=>{var ce,de,ve;const Q=(ce=a.current)==null?void 0:ce.querySelector(`[data-msg-id="${b}"]`);Q&&((de=a.current)==null||de.querySelectorAll(".msg-flash").forEach(Ne=>Ne.classList.remove("msg-flash")),Q.scrollIntoView({block:"start"}),Q.classList.remove("msg-flash"),Q.offsetWidth,Q.classList.add("msg-flash"),Q!==((ve=a.current)==null?void 0:ve.lastElementChild)&&(h.current=!0))})},[t.messages,p,k,X]),J=i.useCallback(()=>{const b=a.current;if(!b)return;const _=b.scrollTop-f.current;f.current=b.scrollTop;const se=b.scrollHeight-b.scrollTop-b.clientHeight<80;_<-4&&_>-500?h.current=!0:se&&_>=0&&(h.current=!1),m.current=se&&!h.current,u(m.current),me(),A()},[me,A]),Z=i.useRef(!1);i.useEffect(()=>{const b=Z.current;if(Z.current=!!t.isStreaming,b&&!t.isStreaming&&!h.current){const _=()=>{const Q=a.current;Q&&!h.current&&(Q.scrollTop=Q.scrollHeight,m.current=!0,u(!0))};requestAnimationFrame(()=>requestAnimationFrame(_));const se=setTimeout(_,180);return()=>clearTimeout(se)}},[t.isStreaming]),i.useEffect(()=>{const b=a.current;b&&m.current&&(b.scrollTop=b.scrollHeight)},[S,t.isStreaming,s]);const le=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");i.useEffect(()=>{const b=a.current;b&&m.current&&(b.scrollTop=b.scrollHeight)},[le]);const xe=i.useCallback(()=>{const b=a.current;b&&(b.scrollTop=b.scrollHeight),m.current=!0,h.current=!1,u(!0)},[]),K=i.useRef(null);i.useEffect(()=>{const b=K.current,_=a.current;if(!b||!_)return;const se=Q=>{Q.preventDefault();const ce=b.querySelector(".qn-list");if(ce&&ce.contains(Q.target)&&ce.scrollHeight>ce.clientHeight){ce.scrollTop+=Q.deltaY;return}_.scrollTop+=Q.deltaY};return b.addEventListener("wheel",se,{passive:!1}),()=>b.removeEventListener("wheel",se)},[]);const[ae,ee]=i.useState(0);i.useEffect(()=>{const b=()=>{var _;ee(((_=a.current)==null?void 0:_.clientHeight)??0),A()};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[A]);const ke=j.length,Me=i.useMemo(()=>ke===0?27:Math.max(4,Math.min(27,Math.floor(((ae||600)-16)/ke)-3)),[ke,ae]),Be=Me<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:"messages",ref:a,onScroll:J,children:[t.messages.length===0&&!t.streamingMessage&&e.jsxs("div",{className:"empty-state",children:[e.jsx("div",{className:"empty-logo-wrap",children:e.jsx("div",{className:"empty-logo",children:"π"})}),e.jsx("h2",{className:"empty-title",children:r("welcomeTitle")}),e.jsx("p",{className:"empty-sub",children:r("welcomeSub")}),e.jsxs("div",{className:"empty-cwd",children:[e.jsx("span",{className:"empty-cwd-label",children:r("directory")}),e.jsx("span",{className:"empty-cwd-path",children:t.cwd})]}),e.jsx("div",{className:"empty-examples",children:Ka(r).map(b=>e.jsxs("button",{type:"button",className:"empty-example",title:r("clickToFill"),onClick:()=>window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:b.prompt})),children:[e.jsx("span",{className:"empty-example-icon",children:b.icon}),e.jsx("span",{className:"empty-example-text",children:b.text})]},b.prompt))})]}),t.messages.map((b,_)=>{const se=_<p,Q=se&&k.has(b.id);if(se&&!Q)return b.role==="toolResult"?null:e.jsx(La,{message:b,onExpand:X},b.id);const ce=b.role==="user"?x.get(b.id):void 0,de=!W||V.has(b.id)||v.has(b.id)||!C.has(b.id);return e.jsx(Ia,{id:b.id,show:de,height:d.current.get(b.id)??Hs(b.role,b.customType),containerRef:a,onMeasured:ne,lazyRef:P,children:e.jsx(ns,{message:b,qnIndex:ce,qnActive:ce!==void 0?ce===B:void 0,onJump:U,toolResults:I,liveOutputs:cs(b)?s:rs,toolStatuses:n,streaming:t.isStreaming,onKillBash:c,isLast:b.id===$,onEdit:o,onCollapse:Q?g:void 0},b.id)},b.id)}),t.streamingMessage&&e.jsx(ns,{message:t.streamingMessage,toolResults:I,liveOutputs:cs(t.streamingMessage)?s:rs,toolStatuses:n,streaming:!0,isLast:!0,onEdit:o,onKillBash:c},t.streamingMessage.id),t.isStreaming&&S.length===0&&e.jsx("div",{className:"streaming-wait",children:r("waitingResponse")}),t.queue.steering.map((b,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:r("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-steer-${_}`)),t.queue.followUp.map((b,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:r("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-fu-${_}`))]}),!l&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:xe,children:[e.jsx(Ss,{})," ",r("backToBottom")]}),e.jsx(Wa,{containerRef:a,messages:S,open:M,onClose:()=>D(!1),onEnsureExpanded:ge}),j.length>0&&e.jsxs("div",{className:`qn-rail ${Be?"many":""}`,ref:K,"aria-label":r("questionNavTitle"),style:{"--rail-gap":`${Me}px`},children:[j.map((b,_)=>e.jsx("button",{type:"button",className:`qn-bar ${_===B?"active":""}`,"aria-label":`${_+1}. ${b.text}`,onClick:()=>U(b.id),children:e.jsxs("span",{className:"qn-bar-text",children:[_+1,". ",b.text]})},b.id)),Be&&e.jsx("div",{className:"qn-list",children:j.map((b,_)=>e.jsxs("button",{type:"button",className:`qn-list-item ${_===B?"active":""}`,"aria-label":`${_+1}. ${b.text}`,onClick:()=>U(b.id),children:[e.jsx("span",{className:"qn-list-idx",children:_+1}),e.jsx("span",{className:"qn-list-text",children:b.text})]},b.id))})]})]})}const Ga=1568,Ja=2*1024*1024;function Ye(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function Qa(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const n=Math.min(1,Ga/Math.max(s.width,s.height)),o=Math.max(1,Math.round(s.width*n)),c=Math.max(1,Math.round(s.height*n)),r=t.type==="image/jpeg"||t.type==="image/jpg"?[["image/jpeg",.85],["image/jpeg",.6],["image/webp",.8]]:[["image/png",1],["image/jpeg",.85],["image/jpeg",.6]];let a=null;for(const[l,u]of r){const m=document.createElement("canvas");m.width=o,m.height=c;const f=m.getContext("2d");if(!f)continue;l!=="image/png"&&(f.fillStyle="#ffffff",f.fillRect(0,0,o,c)),f.drawImage(s,0,0,o,c);const h=m.toDataURL(l,u),k=h.match(/^data:([^;]+);base64,/),N=k?k[1]:l,M=h.replace(/^data:[^;]*;base64,/,""),D=Math.floor(M.length*3/4);if(a={data:M,mimeType:N,name:t.name,size:D},D<=Ja)return a}return a}finally{s.close()}}const Ya=i.memo(function({ready:s,streaming:n,messages:o,slashCommands:c,modelState:r,models:a,modelsLoading:l,send:u,attachments:m,onRemoveAttachment:f,onAddImageFiles:h,onAddLocalFiles:k,onNotice:N,onSent:M,onManageModels:D}){const S=he(),{locale:I}=Et(),$=g=>I==="en"&&g.descriptionEn?g.descriptionEn:g.description??"",p=g=>I==="en"&&g.argumentHintEn?g.argumentHintEn:g.argumentHint??"",[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null),[F,z]=i.useState(0),[W,G]=i.useState(!1),[V,L]=i.useState(void 0),O=i.useRef(null),A=i.useRef(null),re=i.useRef(null),ne={builtin:S("slashBuiltin"),extension:S("slashExtension"),prompt:S("slashPrompt"),skill:S("slashSkill")},P=g=>{const U=g.match(/^\/([^\s]*)$/);if(U&&s){const J=U[1].toLowerCase(),Z=c.filter(le=>le.name.toLowerCase().startsWith(J));R(Z.length>0?Z:null),z(0)}else R(null)};i.useEffect(()=>{var U;const g=(U=re.current)==null?void 0:U.querySelector(".slash-item.active");g==null||g.scrollIntoView({block:"nearest"})},[F,d]);const j=g=>{var xe;const U=d??[],J=g??U[F%Math.max(U.length,1)];if(!J){R(null);return}const Z=C.match(/^\/([^\s]*)([\s\S]*)$/),le=Z?Z[2]:"";T(`/${J.name} ${le}`),R(null),(xe=O.current)==null||xe.focus()},x=async()=>{const U=[...o].reverse().find(Z=>Z.role==="assistant"&&Z.content.some(le=>le.type==="text"&&le.text)),J=U==null?void 0:U.content.filter(Z=>Z.type==="text").map(Z=>Z.text).join(`
|
|
17
|
-
`);if(!J){N("warning",S("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(J),N("info",S("slashCopied"))}catch{N("error",S("slashCopyFailed"))}},B=g=>{if(!g||g.length===0){N("warning",S("foldersNotSupported"));return}const U=Array.from(g).filter(Z=>Ye(Z.type)),J=Array.from(g).filter(Z=>!Ye(Z.type));U.length>0&&h(U),J.length>0&&k(J)},te=g=>{var Z;const U=(Z=g.clipboardData)==null?void 0:Z.items;if(!U)return;const J=[];for(const le of U)if(le.kind==="file"&&Ye(le.type)){const xe=le.getAsFile();xe&&J.push(xe)}J.length!==0&&(g.preventDefault(),h(J))},ue=s,fe=i.useRef(C);i.useEffect(()=>{fe.current=C},[C]),i.useEffect(()=>{P(fe.current)},[c]),i.useEffect(()=>{const g=U=>{var Z;const J=U.detail;T(J),(Z=O.current)==null||Z.focus()};return window.addEventListener("pi-web:fill",g),()=>window.removeEventListener("pi-web:fill",g)},[]),i.useEffect(()=>{if(!W)return;const g=U=>{U.key==="Escape"&&G(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[W]),i.useEffect(()=>{const g=O.current;if(!g)return;g.style.height="auto";const U=g.scrollHeight>220;g.style.height=`${Math.min(g.scrollHeight,220)}px`,g.style.overflowY=U?"auto":"hidden"},[C]);const me=(g=!1)=>{var Z,le,xe,K,ae;const U=C.trim(),J=m.some(ee=>ee.imageData||ee.fileData);if(!(!ue||!U&&!J)){if(U==="/help"){const ee=(le=(Z=O.current)==null?void 0:Z.closest(".inputbox"))==null?void 0:le.getBoundingClientRect();L(ee==null?void 0:ee.width),G(!0),T(""),(xe=O.current)==null||xe.focus();return}if(U==="/copy"){T(""),(K=O.current)==null||K.focus(),x();return}u({type:"prompt",text:U,queue:g,attachments:m.map(ee=>ee.imageData?{path:"",imageData:ee.imageData,mimeType:ee.mimeType,name:ee.name}:ee.fileData?{path:"",fileData:ee.fileData,mimeType:ee.mimeType,name:ee.name,size:ee.size}:{path:ee.path,mode:ee.mode,...ee.lines?{lines:ee.lines}:{}})})&&(T(""),M(),(ae=O.current)==null||ae.focus())}},X=g=>{if(!g.nativeEvent.isComposing){if(d&&d.length>0)switch(g.key){case"ArrowDown":g.preventDefault(),z(U=>(U+1)%d.length);return;case"ArrowUp":g.preventDefault(),z(U=>(U-1+d.length)%d.length);return;case"Tab":case"Enter":g.preventDefault(),j();return;case"Escape":g.preventDefault(),R(null);return}g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),me())}},ge=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[C.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:S("supplementTip"),onClick:()=>me(!0),children:[e.jsx(gn,{})," ",S("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:S("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(et,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:S("sendTip"),disabled:!ue||!C.trim()&&!m.some(g=>g.imageData||g.fileData),onClick:()=>me(),children:e.jsx(Cs,{})})});return e.jsxs("div",{className:`inputbar${v?" drop-active":""}`,onDragOver:g=>{g.preventDefault(),g.stopPropagation(),w(!0)},onDragLeave:g=>{g.currentTarget.contains(g.relatedTarget)||w(!1)},onDrop:g=>{var U;g.preventDefault(),g.stopPropagation(),w(!1),B(((U=g.dataTransfer)==null?void 0:U.files)??null)},children:[v&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",S("dropHereToAttach")]})}),m.length>0&&e.jsxs("div",{className:"attach-row",children:[m.map(g=>e.jsxs("span",{className:`attach-chip ${g.imageData?"image":g.fileData?"file":g.mode}`,title:g.imageData?S("attachImage",{name:g.name}):g.fileData?S("attachFile",{name:g.name}):g.isDir?S("folderRef",{path:g.path}):g.mode==="reference"?S("refOnly",{path:g.path}):g.mode==="lines"&&g.lines?S("attachLines",{path:g.path,start:g.lines.start,end:g.lines.end}):S("attachContent",{path:g.path}),children:[g.imageData?"🖼":g.fileData?"📄":g.isDir?"📁":g.mode==="reference"?"🔗":"📎"," ",g.name,g.mode==="lines"&&g.lines&&e.jsxs("span",{className:"attach-range",children:["L",g.lines.start,"-",g.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:S("removeAttachment"),onClick:()=>f(g.key??g.path),children:"×"})]},g.key??`${g.path}|${g.mode}|${g.lines?`${g.lines.start}-${g.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:S("attachHint")})]}),d&&d.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:re,"aria-label":S("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:S("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>R(null),children:"Esc"})]}),d.map((g,U)=>e.jsxs("button",{type:"button",className:`slash-item${U===F?" active":""}`,onMouseEnter:()=>z(U),onClick:()=>j(g),children:[e.jsxs("span",{className:"slash-name",children:["/",g.name]}),e.jsx("span",{className:`slash-source ${g.source}`,children:ne[g.source]}),e.jsxs("span",{className:"slash-desc",children:[$(g),g.argumentHint&&e.jsx("span",{className:"slash-hint",children:p(g)})]})]},g.name))]}),W&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:V?{width:V}:void 0,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",S("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:S("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:S("slashLoading")}):c.map(g=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",g.name]}),e.jsx("span",{className:`slash-source ${g.source}`,children:ne[g.source]}),e.jsxs("span",{className:"slash-help-desc",children:[$(g),g.argumentHint&&e.jsx("span",{className:"slash-hint",children:p(g)})]})]},g.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:A,type:"file",multiple:!0,hidden:!0,onChange:g=>{B(g.target.files),g.target.value=""}}),e.jsxs("div",{className:"inputbox-row",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var g;return(g=A.current)==null?void 0:g.click()},children:e.jsx(Ut,{})}),e.jsx("textarea",{ref:O,value:C,rows:1,placeholder:S(ue?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!ue,onChange:g=>{T(g.target.value),P(g.target.value)},onKeyDown:X,onPaste:te}),ge()]}),e.jsxs("div",{className:"input-tools",children:[e.jsx("div",{className:"input-tools-left",children:e.jsx(Es,{state:r,models:a,modelsLoading:l,send:u,onManageModels:D,compact:!0})}),e.jsxs("div",{className:"input-tools-right",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var g;return(g=A.current)==null?void 0:g.click()},children:e.jsx(Ut,{})}),ge()]})]})]})]})}),Xa=i.memo(function({goal:s,models:n,modelsLoading:o,activeConversationId:c,send:r}){var z,W,G,V,L,O;const a=he(),l=!s.conversationId||s.conversationId===c,u=s.goal!==null&&l,[m,f]=i.useState(""),[h,k]=i.useState(s.reviewModel??""),[N,M]=i.useState(s.maxRounds),[D,S]=i.useState(s.locked),[I,$]=i.useState(!1),[p,C]=i.useState(!1),[T,v]=i.useState(!0);i.useEffect(()=>{k(s.reviewModel??""),M(s.maxRounds||0),S(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),i.useEffect(()=>{I&&n.length===0&&!p&&!o&&(C(!0),r({type:"list_models"}))},[I,n.length,p,o,r]),i.useEffect(()=>{n.length>0&&C(!1)},[n.length]);const w=()=>{var A;return h?((A=n.find(re=>re.id===h))==null?void 0:A.name)??h:a("goalBarUseMainModel")},d=()=>{const A=m.trim();A&&(r({type:"set_goal",goal:A,...h?{reviewModel:h}:{},maxRounds:N,locked:D}),f(""),v(!1))},R=()=>{const A=m.trim();A&&(r({type:"start_goal_wizard",text:A,...h?{wizardModel:h}:{},maxRounds:N,locked:D}),f(""),v(!1))},F=(((z=s.wizard)==null?void 0:z.active)??!1)&&l;return F?e.jsx("div",{className:`goalbar goalbar-active ${F?"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:((W=s.wizard)==null?void 0:W.draft)??"",children:[a("goalWizardRunning"),": ",(G=s.wizard)==null?void 0:G.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[a("goalBarRound",{n:(((V=s.wizard)==null?void 0:V.step)??0)+1})," ","/ ",((L=s.wizard)==null?void 0:L.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((O=s.wizard)==null?void 0:O.status)||a("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),onClick:()=>{r({type:"clear_goal"}),v(!0)},children:e.jsx(Se,{})})]})}):u?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:[a("goalBarReviewing")," ",a("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?a("goalBarPassed"):s.verdict==="fail"?a("goalBarFailed"):`${a("goalBarRound",{n:s.round||1})} · ${s.locked?a("goalBarLocked"):a("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:s.status}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),disabled:s.reviewing,onClick:()=>{r({type:"clear_goal"}),v(!0)},children:e.jsx(Se,{})})]})}):T?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:a("goalBarPlaceholder"),onClick:()=>v(!1),children:[e.jsx(qt,{})," ",e.jsx("span",{children:a("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(qt,{})}),e.jsx("input",{className:"goalbar-input",value:m,placeholder:a("goalBarPlaceholder"),onChange:A=>f(A.target.value),onKeyDown:A=>{A.key==="Enter"&&d()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!m.trim(),onClick:d,children:a("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!m.trim(),title:a("goalWizardTip"),onClick:R,children:["🔍 ",a("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a(D?"goalBarLocked":"goalBarUnlocked"),onClick:()=>S(A=>(r({type:"set_goal_prefs",locked:!A}),!A)),children:D?e.jsx(wn,{}):e.jsx(pn,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a("goalBarClear"),onClick:()=>v(!0),children:e.jsx(rt,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Re,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[a("goalBarReviewModel"),": ",e.jsx("b",{children:w()})]}),open:I,onOpenChange:$,direction:"up",children:[e.jsx("div",{className:"dd-header",children:a("goalBarReviewModel")}),(p||o)&&e.jsx("div",{className:"dd-loading",children:a("loading")}),n.length===0&&!p&&!o&&e.jsx("div",{className:"dd-loading",children:a("noModels")}),e.jsx(we,{active:h==="",onClick:()=>{k(""),$(!1),r({type:"set_goal_prefs",reviewModel:""})},children:a("goalBarUseMainModel")}),n.map(A=>e.jsx(we,{active:h===A.id,onClick:()=>{k(A.id),$(!1),r({type:"set_goal_prefs",reviewModel:A.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:A.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:A.provider})})]})},A.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>r({type:"list_models"}),children:a("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:a("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:a("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:N,placeholder:a("goalBarUnlimitedShort"),onChange:A=>{const re=parseInt(A.target.value,10);if(Number.isNaN(re)||re<0){M(0);return}M(re)},onBlur:()=>r({type:"set_goal_prefs",maxRounds:N}),onKeyDown:A=>{A.key==="Enter"&&(r({type:"set_goal_prefs",maxRounds:N}),A.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:a(D?"goalBarLocked":"goalBarUnlocked")})]})]})});function Za({chat:t,send:s}){const n=he(),o=t.state,[c,r]=i.useState(!1),[a,l]=i.useState(""),[u,m]=i.useState(0),f=i.useRef(null),h=t.pathCompletions;if(i.useEffect(()=>{if(!c)return;const d=setTimeout(()=>{s({type:"complete_path",path:a})},150);return()=>clearTimeout(d)},[a,c,s]),i.useEffect(()=>m(0),[h]),i.useEffect(()=>{const d=document.querySelector(`.status-completions .pc-item[data-idx="${u}"]`);d==null||d.scrollIntoView({block:"nearest"})},[u]),!o)return null;const k=o.stats,N=t.ready?"ok":"busy",M=t.ready?n("connected"):n("connecting"),D=k.contextUsage,S=D.tokens!==null&&D.percent!==null?`${ds(D.tokens)} / ${ds(D.contextWindow)}`:"—",I=D.percent??null,$=I===null?"":I>=80?"warn":I>=50?"mid":"ok",p=o.queue.steering.length+o.queue.followUp.length,C=()=>{l(o.cwd),r(!0)},T=(d,R)=>{var z;const F=d.includes("\\")?"\\":"/";l(R?`${d}${F}`:d),m(0),(z=f.current)==null||z.focus()},v=d=>{const R=d.trim();R&&R!==o.cwd&&s({type:"set_cwd",path:R}),r(!1)},w=d=>{if(d.key==="ArrowDown")d.preventDefault(),m(R=>Math.min(R+1,h.length-1));else if(d.key==="ArrowUp")d.preventDefault(),m(R=>Math.max(R-1,0));else if(d.key==="Tab"&&h.length>0){d.preventDefault();const R=h[Math.min(u,h.length-1)];T(R.path,R.type==="dir")}else if(d.key==="Enter"&&!d.nativeEvent.isComposing){const R=a.trim();if(R.endsWith("/")||R.endsWith("\\"))v(R);else if(h.some(F=>F.path===R))v(R);else if(h.length>0&&h[u]){d.preventDefault();const F=h[u];T(F.path,F.type==="dir")}else v(R)}else d.key==="Escape"&&(h.length>0?(d.stopPropagation(),s({type:"complete_path",path:""})):r(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${N}`,title:M}),e.jsx("span",{className:"status-item",children:M}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${$}`,children:I!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(I,100)}%`}})}),S]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",ei(k.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("sessionMessages"),children:[n("messages")," ",k.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:n("pluginStatus"),children:t.statuses.map(d=>d.text).join(" · ")})]}),o.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"}),n("working"),p>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",p," ",n("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:f,className:"status-cwd-input",value:a,autoFocus:!0,placeholder:n("enterPath"),onChange:d=>l(d.target.value),onKeyDown:w,onBlur:()=>r(!1)}),h.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:d=>d.preventDefault(),children:h.map((d,R)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":R,className:`pc-item ${R===u?"sel":""}`,onMouseEnter:()=>m(R),onClick:()=>T(d.path,d.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:d.type==="dir"?e.jsx(Oe,{}):e.jsx(ks,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:d.name}),e.jsx("span",{className:"pc-path",children:d.path})]})]})},d.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:n("cwdTip",{path:o.cwd}),onClick:C,children:["📁 ",o.cwd]})]})}function ds(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function ei(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function ti({dialog:t,send:s}){const n=he(),[o,c]=i.useState(""),[r,a]=i.useState(0),l=f=>{s({type:"dialog_response",id:t.id,value:f})};i.useEffect(()=>{c(""),a(0);const f=h=>{h.key==="Escape"&&l(null)};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],m=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:n("pluginRequest")}),t.title&&t.title!==n("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>l(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((f,h)=>e.jsx("button",{type:"button",className:`dialog-option ${h===r?"sel":""}`,onMouseEnter:()=>a(h),onClick:()=>l(f),children:f},h)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:n("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:m}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>l(!1),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>l(!0),children:n("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:o,placeholder:m||n("inputPlaceholder"),autoFocus:!0,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&l(o)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>l(null),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>l(o),children:n("ok")})]})]})]})}function si(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",n=t.y!==" "&&t.y!=="?";return s&&n?"both":s?"staged":"unstaged"}function ni({chat:t,send:s,terminal:n,active:o,onSwitchToTerminal:c}){var ve,Ne;const r=he(),[a,l]=i.useState(null),[u,m]=i.useState([]),[f,h]=i.useState(""),[k,N]=i.useState(new Map),[M,D]=i.useState("changes"),[S,I]=i.useState([]),[$,p]=i.useState(null),[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null),[F,z]=i.useState(null),[W,G]=i.useState(!1),[V,L]=i.useState(!1),[O,A]=i.useState(!1),[re,ne]=i.useState(null),[P,j]=i.useState(!1),[x,B]=i.useState(""),te=i.useRef(0),ue=i.useRef(-1),fe=i.useRef(-1),me=i.useRef(-1),X=i.useRef(-1),ge=i.useRef(void 0),g=i.useRef(null),U=i.useRef([]),J=i.useCallback(y=>{if(y.reqId===ue.current){if(ue.current=-1,L(!1),ne(null),!y.ok){ne(y.error??"查询失败");return}if(y.notRepo){j(!0),l(null),m([]),N(new Map),I([]),p(null),T(""),z(null);return}j(!1);const ie={branch:y.branch??"",detached:!!y.detached,upstream:y.upstream??null,ahead:y.ahead??0,behind:y.behind??0,upstreamGone:!!y.upstreamGone,files:(y.files??[]).map(pe=>({...pe}))},Y=(y.branches??[]).map(pe=>({...pe})),ye=new Map;for(const[pe,je]of Object.entries(y.stats??{}))ye.set(pe,{add:je[0],del:je[1]});l(ie),m(Y),N(ye),h(pe=>{var je;return ie.detached?pe||"":ie.branch&&Y.some(Te=>Te.name===ie.branch)?ie.branch:pe&&Y.some(Te=>Te.name===pe)?pe:((je=Y[0])==null?void 0:je.name)??""}),z(pe=>pe&&!ie.files.some(je=>je.path===pe.file.path)?null:pe)}else if(y.reqId===fe.current){if(fe.current=-1,G(!1),!y.ok){ne(y.error??"查询失败");return}const ie=g.current;if(!ie)return;z({file:ie,staged:y.stagedText??"",worktree:y.worktreeText??"",untracked:!1})}else if(y.reqId===X.current){if(X.current=-1,A(!1),!y.ok){ne(y.error??"查询失败");return}I((y.history??[]).map(ie=>({...ie})))}else if(y.reqId===me.current){if(me.current=-1,w(!1),!y.ok){ne(y.error??"查询失败");return}T(y.text??"")}},[]);i.useEffect(()=>{const y=t.scmData;y&&y.type==="scm_data"&&J(y)},[t.scmData,J]);const Z=i.useCallback((y,ie)=>{if(!t.ready||t.status!=="open")return!1;const Y=++te.current;return s({...y,reqId:Y})?(ie.current=Y,!0):(te.current-=1,!1)},[t.ready,t.status,s]),le=i.useCallback((y=!1,ie=!1)=>{var Y;!t.ready||t.status!=="open"||(Y=t.state)!=null&&Y.cwd&&(ge.current!==void 0&&ge.current!==t.state.cwd&&(l(null),m([]),N(new Map),I([]),A(!1),X.current=-1,p(null),T(""),z(null),R(null)),ge.current=t.state.cwd,ne(null),Z({type:"scm_status"},ue)&&(ie||L(!0)))},[t.ready,(ve=t.state)==null?void 0:ve.cwd,t.status,Z]),xe=i.useCallback(y=>{if(R(y),p(null),g.current=y,y.x==="?"&&y.y==="?"){z({file:y,staged:"",worktree:"",untracked:!0});return}G(!0),ne(null),Z({type:"scm_filediff",path:y.path},fe)||G(!1)},[Z]),K=i.useCallback(y=>{p(y),R(null),z(null),T(""),w(!0),ne(null),Z({type:"scm_commit",hash:y.hash},me)||w(!1)},[Z]),ae=i.useCallback((y,ie)=>{var pe,je;if(!t.ready)return;const Y={name:y,command:ie,cwd:"${pwd}"},ye=t.terminals.find(Te=>Te.title===y);if(ye)n.restart(ye.id),s({type:"run_command",terminalId:ye.id,conversationId:ye.conversationId,command:Y,cols:80,rows:24});else{const Te=He();n.create({id:Te,conversationId:t.activeConversationId||((pe=t.state)==null?void 0:pe.conversationId)||"",title:y,cwd:((je=t.state)==null?void 0:je.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Y})}c()},[t.ready,(Ne=t.state)==null?void 0:Ne.cwd,t.terminals,c,s,n]),ee=i.useCallback(()=>{const y=x.trim();if(!y||P)return;const ie=y.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ae("git commit",`git add -A && git commit -m "${ie}"`),B("")},[x,P,ae]),ke=y=>`'${y.replace(/'/g,"'\\''")}`,Me=i.useCallback(y=>{P||ae("git add",`git add -- ${ke(y.path)}`)},[P,ae]),Be=i.useCallback(y=>{P||ae("git reset",`git reset HEAD -- ${ke(y.path)}`)},[P,ae]),b=i.useCallback(()=>{if(!f||P)return;const y=u.find(ie=>ie.name===f);if(y!=null&&y.remote&&typeof y.remote=="string"){const ie=f.slice(y.remote.length+1);ae("git checkout",`git checkout -b ${ie} ${f} || git checkout ${f}`)}else ae("git checkout",`git checkout ${f}`)},[f,u,P,ae]),_=i.useCallback(()=>ae("git push","git push"),[ae]),se=i.useCallback(()=>ae("git pull","git pull"),[ae]),Q=i.useCallback(()=>{Z({type:"scm_history"},X)||(X.current=-1)},[Z]);i.useEffect(()=>{o&&le()},[o,le]),i.useEffect(()=>{M==="history"&&a&&Q()},[M,a,Q]),i.useEffect(()=>{t.scmDirty>0&&o&&le(!1,!0)},[t.scmDirty]),i.useEffect(()=>{if(!o||!t.ready||t.status!=="open")return;const y=setInterval(()=>{document.visibilityState!=="hidden"&&le(!1,!0)},3e4);return()=>clearInterval(y)},[o,t.ready,t.status,le]),i.useEffect(()=>{const y=U.current;if(U.current=t.terminals,!o)return;t.terminals.some(Y=>{var pe;return Y.running!==!1?!1:((pe=y.find(je=>je.id===Y.id))==null?void 0:pe.running)===!0&&/^git /.test(Y.title)})&&t.ready&&t.status==="open"&&(le(!1,!0),M==="history"&&a&&Q())},[t.terminals,o,t.ready,t.status,le,M,a,Q]);const ce={staged:r("scmStaged"),unstaged:r("scmUnstaged"),untracked:r("scmUntracked"),both:r("scmStagedUnstaged")},de=y=>{const ie=y.split(`
|
|
18
|
-
`);return e.jsx("pre",{className:"scm-diff-pre",children:ie.map((Y,ye)=>{let pe="";return Y.startsWith("diff --git")||Y.startsWith("index ")||Y.startsWith("new file")||Y.startsWith("deleted file")||Y.startsWith("old mode")||Y.startsWith("new mode")||Y.startsWith("similarity index")||Y.startsWith("rename ")||Y.startsWith("copy ")||Y.startsWith("Binary files")||Y.startsWith("---")||Y.startsWith("+++")?pe="hdr":Y.startsWith("@@")?pe="hunk":Y.startsWith("+")?pe="add":Y.startsWith("-")&&(pe="del"),e.jsx("div",{className:`scm-diff-line ${pe}`,children:Y||" "},ye)})})};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(Qe,{}),r("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":M==="changes",className:M==="changes"?"active":"",onClick:()=>{D("changes"),ne(null)},children:r("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":M==="history",className:M==="history"?"active":"",onClick:()=>{D("history"),ne(null)},children:r("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:r("scmRefreshTip"),disabled:V,onClick:()=>le(!0),children:e.jsx(St,{className:V?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:r("scmCurrentBranch"),children:[e.jsx(Qe,{}),a?a.detached?r("scmDetached"):a.branch:"…",(a==null?void 0:a.upstream)&&e.jsx("span",{className:"scm-upstream",children:a.upstreamGone?r("scmUpstreamGone"):a.ahead>0||a.behind>0?r("scmAheadBehind",{ahead:a.ahead,behind:a.behind}):a.upstream})]}),e.jsxs("select",{className:"scm-select",value:f,disabled:P||u.length===0,title:r("scmSwitchBranch"),onChange:y=>h(y.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("scmSelectBranch")}),u.filter(y=>!y.remote).map(y=>e.jsx("option",{value:y.name,children:y.current?`* ${y.name}`:y.name},y.name)),u.some(y=>y.remote)&&e.jsx("optgroup",{label:r("scmRemoteBranches"),children:u.filter(y=>y.remote).map(y=>e.jsx("option",{value:y.name,children:y.name},y.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!f||f===(a==null?void 0:a.branch)||P,title:r("scmSwitchBranchTip",{branch:f}),onClick:b,children:[e.jsx(Qe,{}),r("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||P,title:r("scmPushTip"),onClick:_,children:[e.jsx(Cs,{}),r("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||P,title:r("scmPullTip"),onClick:se,children:[e.jsx(Ss,{}),r("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:x,placeholder:r("scmCommitPlaceholder"),disabled:P,onChange:y=>B(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&ee()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!x.trim()||P,title:r("scmCommitTip"),onClick:ee,children:[e.jsx(lt,{}),r("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[M==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmHistory")}),S.length>0&&e.jsx("span",{className:"scm-files-count",children:S.length})]}),e.jsx("div",{className:"scm-history-list",children:P?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):!a||O?e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")}):S.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoHistory")}):S.map(y=>e.jsxs("button",{type:"button",className:`scm-commit ${($==null?void 0:$.hash)===y.hash?"active":""}`,onClick:()=>K(y),title:y.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:y.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:y.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[y.shortHash," · ",y.author," · ",y.date]}),y.decorations&&e.jsx("span",{className:"scm-commit-refs",children:y.decorations})]})]},y.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmChanges")}),a&&a.files.length>0&&e.jsx("span",{className:"scm-files-count",children:a.files.length})]}),e.jsx("div",{className:"scm-files-list",children:P?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):a?a.files.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoChanges")}):a.files.map(y=>{const ie=si(y),Y=k.get(y.path);return e.jsxs("div",{className:`scm-file ${(d==null?void 0:d.path)===y.path?"active":""}`,title:ce[ie],onClick:()=>xe(y),children:[e.jsx("span",{className:`scm-file-xy ${ie==="untracked"?"q":"x"}`,children:y.x!==" "?y.x:" "}),e.jsx("span",{className:`scm-file-xy ${ie==="untracked"?"q":"y"}`,children:y.y!==" "?y.y:" "}),e.jsx("span",{className:"scm-file-path",children:y.path}),Y&&(Y.add>0||Y.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[Y.add>0&&e.jsxs("span",{className:"add",children:["+",Y.add]}),Y.del>0&&e.jsxs("span",{className:"del",children:["-",Y.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(y.y!==" "||ie==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:r("scmStageTip",{path:y.path}),onClick:ye=>{ye.stopPropagation(),Me(y)},children:"+"}),ie==="staged"||ie==="both"?e.jsx("button",{type:"button",className:"scm-act",title:r("scmUnstageTip",{path:y.path}),onClick:ye=>{ye.stopPropagation(),Be(y)},children:"−"}):null]})]},y.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:M==="history"?$?`${$.shortHash} ${$.subject}`:r("scmCommitDetail"):d?d.path:r("scmDiff")}),(M==="history"?v:W)&&e.jsx("span",{className:"scm-diff-loading",children:r("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:M==="history"?e.jsxs(e.Fragment,{children:[re&&e.jsx("div",{className:"scm-error",children:re}),!$&&!re&&e.jsx("div",{className:"scm-empty",children:r("scmSelectCommitHint")}),$&&v&&!re&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),$&&!v&&!re&&C?de(C):null]}):e.jsxs(e.Fragment,{children:[re&&e.jsx("div",{className:"scm-error",children:re}),!d&&!re&&e.jsx("div",{className:"scm-empty",children:r("scmSelectFileHint")}),d&&!F&&!re&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),d&&F&&F.untracked&&e.jsx("div",{className:"scm-empty",children:r("scmUntrackedNote")}),d&&F&&!F.untracked&&e.jsxs(e.Fragment,{children:[F.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmStaged")}),de(F.staged)]}),F.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmUnstaged")}),de(F.worktree)]}),!F.staged&&!F.worktree&&e.jsx("div",{className:"scm-empty",children:r("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ve,{}),e.jsx("span",{children:r("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:r("scmViewTerminal")})]})]})}function ai({entry:t,send:s}){const n=i.useRef(null);return i.useEffect(()=>{const o=n.current;if(!o)return;let c;try{c=t.module.mount(o,Qn(t.info.id,r=>s(r)))}catch(r){console.error(`[plugin:${t.info.id}] mount failed:`,r),o.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(r){console.error(`[plugin:${t.info.id}] cleanup failed:`,r)}o.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:n})}function ii({send:t,piConfigured:s,providers:n,installResult:o,onClose:c}){const r=he(),[a,l]=i.useState(!1),[u,m]=i.useState(""),[f,h]=i.useState(""),[k,N]=i.useState(!1);i.useEffect(()=>{t({type:"list_providers"})},[t]),i.useEffect(()=>{s&&c()},[s,c]),i.useEffect(()=>{o&&l(!1)},[o]),i.useEffect(()=>{var p;!u&&n.length>0&&m(((p=n.find(C=>!C.configured))==null?void 0:p.id)??n[0].id)},[n,u]);const M=()=>{a||(l(!0),t({type:"install_pi_agent"}))},D=()=>{!f.trim()||k||(N(!0),t({type:"set_provider_api_key",provider:u.trim(),apiKey:f.trim()}),setTimeout(()=>N(!1),3e3))},S=()=>{t({type:"get_state"}),t({type:"list_providers"})},I=n.find(p=>p.id===u),$=o!==null&&!o.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":r("close"),onClick:c,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(it,{className:"modal-head-icon"}),e.jsx("h2",{children:r("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("setupDesc")}),$?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:r("installFailed")}),e.jsx("pre",{className:"setup-detail",children:o.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:r("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]}):o!=null&&o.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:r("installDone")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("provider")}),e.jsxs("select",{value:u,onChange:p=>m(p.target.value),children:[n.length===0&&e.jsx("option",{value:"",children:r("loading")}),n.map(p=>e.jsxs("option",{value:p.id,children:[p.name,"(",p.id,")",p.configured?` · ${r("configured")}`:""]},p.id))]}),(I==null?void 0:I.configured)&&e.jsx("div",{className:"field-hint",children:r("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("apiKey")}),e.jsx("input",{type:"password",value:f,onChange:p=>h(p.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!f.trim()||k||!u,onClick:D,children:r(k?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:S,children:[e.jsx(St,{})," ",r("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:r(a?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]})})}const ri=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],Pt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),oi=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[Pt()]});function us(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:[Pt()]).map(s=>{var n;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(n=s.input)!=null&&n.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function li({send:t,providers:s,providerStatus:n,fetchModelsResult:o,refreshProviderResult:c,cloneProviderResult:r,onClose:a}){const l=he(),[u,m]=i.useState(null),[f,h]=i.useState({}),[k,N]=i.useState(null),[M,D]=i.useState({}),[S,I]=i.useState(!1),[$,p]=i.useState(0),[C,T]=i.useState(null),v=i.useRef(0),[w,d]=i.useState({});i.useRef(0);const R=i.useRef(0),[F,z]=i.useState(null),W=i.useRef(0),G=i.useRef(0);i.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const V=()=>{if(!u)return;const j=u.baseUrl.trim();if(!j){T({ok:!1,text:l("fetchModelsNeedBaseUrl")});return}if(S)return;I(!0),T(null);const x=$+1;p(x),t({type:"fetch_models",reqId:x,baseUrl:j,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};i.useEffect(()=>{var j;if(!(!o||o.reqId===v.current))if(v.current=o.reqId,I(!1),o.ok&&((j=o.models)!=null&&j.length)){const x=o.models;m(B=>{if(!B)return B;const te=B.models.map(X=>{var U;if(!X.id.trim())return X;const ge=x.find(J=>J.id===X.id.trim());if(!ge)return X;const g={...X};return!g.name&&ge.name&&(g.name=ge.name),!g.contextWindow&&ge.contextWindow&&(g.contextWindow=String(ge.contextWindow)),!g.maxTokens&&ge.maxTokens&&(g.maxTokens=String(ge.maxTokens)),g.input==="text"&&((U=ge.input)!=null&&U.includes("image"))&&(g.input="text-image"),!g.reasoning&&ge.reasoning&&(g.reasoning=!0),g}),ue=new Set(te.map(X=>X.id.trim()).filter(Boolean)),fe=x.filter(X=>!ue.has(X.id)).map(X=>{var ge;return{id:X.id,name:X.name??"",reasoning:X.reasoning??!1,input:(ge=X.input)!=null&&ge.includes("image")?"text-image":"text",contextWindow:X.contextWindow?String(X.contextWindow):"",maxTokens:X.maxTokens?String(X.maxTokens):""}}),me=[...te,...fe];return me.some(X=>X.id.trim())?{...B,models:me.filter(X=>X.id.trim())}:B}),T({ok:!0,text:l("fetchModelsOk",{n:x.length})})}else T({ok:!1,text:o.error||l("fetchModelsEmpty")})},[o]);const L=j=>{const x=(f[j.id]??"").trim();!x||k||(N(j.id),t({type:"set_provider_api_key",provider:j.id,apiKey:x}),setTimeout(()=>{N(null),h(B=>({...B,[j.id]:""})),D(B=>({...B,[j.id]:!1})),t({type:"list_providers"})},1500))},O=()=>{if(!u)return;const j=u.providerId.trim(),x=u.models.filter(te=>te.id.trim()).map(te=>({id:te.id.trim(),name:te.name.trim()||void 0,reasoning:te.reasoning||void 0,input:te.input==="text-image"?["text","image"]:void 0,contextWindow:te.contextWindow?Number(te.contextWindow):void 0,maxTokens:te.maxTokens?Number(te.maxTokens):void 0})),B={providerId:j,name:u.name.trim()||void 0,api:u.api.trim()||void 0,baseUrl:u.baseUrl.trim()||void 0,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader||void 0,models:x};t({type:"save_model_config",providerId:j,config:B}),a()};i.useEffect(()=>{!c||c.reqId===R.current||(R.current=c.reqId,d({}))},[c]);const A=j=>{if(F)return;z(j.id);const x=++W.current+Date.now();t({type:"clone_provider",provider:j.id,reqId:x})};i.useEffect(()=>{!r||r.reqId===G.current||(G.current=r.reqId,z(null),r.ok&&r.config&&m(us({...r.config,apiKey:""})))},[r]);const re=j=>{window.confirm(l("clearKeyConfirm",{id:j}))&&t({type:"clear_provider_api_key",provider:j})},ne=j=>{window.confirm(l("deleteProviderConfirm",{id:j.providerId,n:j.models.length}))&&t({type:"delete_model_config",providerId:j.providerId})},P=(j,x)=>{u&&m({...u,models:u.models.map((B,te)=>te===j?{...B,...x}:B)})};return e.jsx("div",{className:"modal-backdrop",onClick:a,children:e.jsxs("div",{className:"modal model-modal",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":l("close"),onClick:a,children:e.jsx(Se,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:l(u?"editProvider":"manageModelsTitle")})}),u?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:[l("providerId")," ",e.jsx("em",{children:l("providerIdHint")})]}),e.jsx("input",{type:"text",value:u.providerId,disabled:s.some(j=>j.providerId===u.providerId),onChange:j=>m({...u,providerId:j.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("displayName")}),e.jsx("input",{type:"text",value:u.name,onChange:j=>m({...u,name:j.target.value}),placeholder:l("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("apiType")}),e.jsx("select",{value:u.api,onChange:j=>m({...u,api:j.target.value}),children:ri.map(j=>e.jsx("option",{value:j,children:j},j))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:l("baseUrlHint")})]}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:j=>m({...u,baseUrl:j.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("apiKey")}),e.jsx("input",{type:"password",value:u.apiKey,onChange:j=>m({...u,apiKey:j.target.value}),placeholder:l("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:j=>m({...u,authHeader:j.target.checked})}),e.jsx("span",{children:l("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:l("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[C&&e.jsx("span",{className:`fetch-msg ${C.ok?"ok":"err"}`,title:C.text,children:C.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:S||!u.baseUrl.trim(),title:l("fetchModelsHint"),onClick:V,children:[e.jsx(Tt,{})," ",l(S?"fetchingModels":"fetchModels")]})]})]}),u.models.map((j,x)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:j.id,onChange:B=>P(x,{id:B.target.value}),placeholder:l("modelIdReq")}),e.jsx("input",{type:"text",value:j.name,onChange:B=>P(x,{name:B.target.value}),placeholder:l("displayName")}),e.jsxs("select",{value:j.input,onChange:B=>P(x,{input:B.target.value}),children:[e.jsx("option",{value:"text",children:l("text")}),e.jsx("option",{value:"text-image",children:l("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:j.reasoning,onChange:B=>P(x,{reasoning:B.target.checked})}),e.jsx("span",{children:l("reasoning")})]}),e.jsx("input",{type:"number",value:j.contextWindow,onChange:B=>P(x,{contextWindow:B.target.value}),placeholder:l("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:j.maxTokens,onChange:B=>P(x,{maxTokens:B.target.value}),placeholder:l("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:l("removeModel"),onClick:()=>m({...u,models:u.models.filter((B,te)=>te!==x)}),children:e.jsx(Fe,{})})]},x)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>m({...u,models:[...u.models,Pt()]}),children:[e.jsx(Ae,{})," ",l("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>m(null),children:l("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(j=>j.id.trim()),onClick:O,children:l("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[l("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:l("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.map(j=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:j.name}),e.jsxs("span",{className:"provider-sub",children:[j.id,j.configured&&e.jsx("span",{className:"auth-badge",children:l("configuredBadge")}),j.source&&!j.configured&&e.jsx("span",{className:"auth-badge dim",children:j.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[j.configured&&!M[j.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:l("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:l("replaceKeyTitle"),onClick:()=>D(x=>({...x,[j.id]:!0})),children:[e.jsx(Kt,{})," ",l("replaceKey")]}),j.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:l("clearKeyTitle"),onClick:()=>re(j.id),children:[e.jsx(Fe,{})," ",l("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:l("pasteKey"),value:f[j.id]??"",onChange:x=>h(B=>({...B,[j.id]:x.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(f[j.id]??"").trim()||k===j.id,onClick:()=>L(j),children:[e.jsx(Nn,{})," ",k===j.id?l("savingKey"):l("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:F!==null,title:l("cloneProviderTitle"),onClick:()=>A(j),children:[e.jsx(Mt,{})," ",F===j.id?l("cloning"):l("cloneProvider")]})]})]},j.id))]}),e.jsx("div",{className:"form-section-title",children:l("customProviders")}),e.jsx("p",{className:"modal-desc",children:l("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:l("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(j=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:j.providerId}),e.jsxs("span",{className:"provider-sub",children:[j.api??"—",j.baseUrl?` · ${j.baseUrl}`:"",j.models.length>0&&` · ${l("modelsCount",{n:j.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:l("edit"),onClick:()=>m(us(j)),children:e.jsx(Kt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:l("delete"),onClick:()=>ne(j),children:e.jsx(Fe,{})})]})]},j.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>m(oi()),children:[e.jsx(Ae,{})," ",l("addProvider")]})})]})]})})}function Nt({text:t}){const s=i.useRef(null),[n,o]=i.useState(!1),c=()=>{var a;const r=(a=s.current)==null?void 0:a.getBoundingClientRect();r&&o(window.innerWidth-r.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${n?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Le({title:t,subtitle:s,tip:n,enabled:o,onToggle:c,action:r}){const a=he();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,n&&e.jsx(Nt,{text:n})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),r,e.jsx("button",{type:"button",className:`set-switch ${o?"on":""}`,role:"switch","aria-checked":o,title:a(o?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function ci({chat:t,send:s,terminal:n,onSwitchToTerminal:o,onClose:c}){const r=he(),a=t.settings,[l,u]=i.useState(""),[m,f]=i.useState("append"),h=i.useRef(!1),[k,N]=i.useState(""),[M,D]=i.useState("append"),S=i.useRef(!1),[I,$]=i.useState(""),p=i.useRef(!1),[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null);i.useEffect(()=>{a&&(f(a.promptMode),!h.current&&(u(m==="append"||a.customSystemPrompt?a.customSystemPrompt:a.defaultSystemPrompt||""),D(a.visionBridgePromptMode),!S.current&&(N(M==="append"||a.visionBridgePrompt?a.visionBridgePrompt:a.visionBridgeDefaultPrompt||""),p.current||$(a.reviewPrompt))))},[a,m,M]);const[F,z]=i.useState(String((a==null?void 0:a.terminalBashIdleMs)??15e3));if(i.useEffect(()=>{z(String((a==null?void 0:a.terminalBashIdleMs)??15e3))},[a==null?void 0:a.terminalBashIdleMs]),!a)return null;const W=new Set(a.disabledSkills),G=new Set(a.disabledExtensions),V=x=>s({type:"set_settings",...x}),L=x=>{const B=new Set(W);B.has(x.name)?B.delete(x.name):B.add(x.name),V({disabledSkills:[...B]})},O=new Set(a.disabledPlugins??[]),A=x=>{const B=new Set(O);B.has(x.id)?B.delete(x.id):B.add(x.id),V({disabledPlugins:[...B]})},re=x=>{const B=new Set(G);B.has(x.id)?B.delete(x.id):B.add(x.id),V({disabledExtensions:[...B]})},ne=x=>{var fe,me;R(null);const B=`${r("uninstallTitle")} ${x}`,te={name:B,command:`pi remove npm:${x}`,cwd:"${pwd}"},ue=t.terminals.find(X=>X.title===B);ue?(n.restart(ue.id),s({type:"run_command",terminalId:ue.id,conversationId:ue.conversationId,command:te,cols:80,rows:24})):n.create({id:He(),conversationId:t.activeConversationId||((fe=t.state)==null?void 0:fe.conversationId)||"",title:B,cwd:((me=t.state)==null?void 0:me.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:te}),o(),c()},P=x=>{const B=new Set(a.reviewSkills.filter(te=>!te.enabled).map(te=>te.name));B.has(x.name)?B.delete(x.name):B.add(x.name),V({reviewDisabledSkills:[...B]})},j=()=>{const x=m==="replace"&&a.defaultSystemPrompt&&l===a.defaultSystemPrompt?"":l;V({promptMode:m,customSystemPrompt:x})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:c,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(tt,{className:"modal-head-icon"}),e.jsx("h2",{children:r("settingsTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("settingsDesc")}),e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{className:"set-section-icon"}),r("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:m,onChange:x=>{const B=x.target.value;f(B),V({promptMode:B})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]}),e.jsx(Nt,{text:r(m==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:r("promptPlaceholder"),value:l,onFocus:()=>h.current=!0,onBlur:()=>{h.current=!1,j()},onChange:x=>u(x.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":v,onClick:()=>w(x=>!x),children:[r("settingsViewPrompt")," ",v?"▴":"▾"]}),v&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:r("settingsViewPromptHint")}),e.jsx(Ps,{text:a.effectiveSystemPrompt})]}),a.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:a.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:r("settingsViewPromptEmpty")})]})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ve,{className:"set-section-icon"}),r("settingsTerminalTools")]}),e.jsx(Le,{title:r("terminalToolsEnabled"),tip:r("settingsTerminalToolsDesc"),enabled:a.terminalToolsEnabled,onToggle:()=>V({terminalToolsEnabled:!a.terminalToolsEnabled})}),!a.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:r("terminalToolsOffHint")}),e.jsx(Le,{title:r("terminalBashTakeover"),tip:r("terminalBashTakeoverDesc"),enabled:a.terminalBash,onToggle:()=>V({terminalBash:!a.terminalBash})}),a.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:r("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:F,onChange:x=>z(x.target.value),onBlur:()=>{const x=Math.max(0,Math.floor(Number(F)||0));z(String(x)),x!==a.terminalBashIdleMs&&V({terminalBashIdleMs:x})}})]})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(it,{className:"set-section-icon"}),r("settingsSkills"),e.jsx("span",{className:"set-count",children:a.skills.length})]}),a.skills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:a.skills.map(x=>e.jsx(Le,{title:x.name,subtitle:x.description,enabled:x.enabled,onToggle:()=>L(x)},x.name))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xn,{className:"set-section-icon"}),r("settingsExtensions"),e.jsx("span",{className:"set-count",children:a.extensions.length})]}),a.extensions.length===0?e.jsx("p",{className:"set-empty",children:r("noExtensions")}):e.jsx("div",{className:"set-list",children:a.extensions.map(x=>{const B=x.id.startsWith("npm:")?x.id.slice(4):null;return e.jsx(Le,{title:x.name,subtitle:x.path,enabled:x.enabled,onToggle:()=>re(x),action:B?d===x.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:r("uninstallConfirmHint"),onClick:()=>ne(B),children:r("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:r("uninstallHint"),onClick:()=>R(x.id),children:[e.jsx(Fe,{}),r("uninstallExt")]}):void 0},x.id)})})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ns,{className:"set-section-icon"}),r("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:r("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(x=>e.jsx(Le,{title:`${x.icon?`${x.icon} `:""}${x.name}`,subtitle:x.error?`${x.id} · ${x.error}`:x.description??x.id,enabled:!O.has(x.id)&&!x.error,onToggle:()=>!x.error&&A(x)},x.id))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{className:"set-section-icon"}),r("settingsReview"),e.jsx(Nt,{text:r("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:a.reviewSkills.length})]}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:r("reviewPromptPlaceholder"),value:I,onFocus:()=>p.current=!0,onBlur:()=>{p.current=!1,V({reviewPrompt:I})},onChange:x=>$(x.target.value)}),e.jsx("div",{className:"set-field-label",children:r("settingsReviewSkills")}),a.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:a.reviewSkills.map(x=>e.jsx(Le,{title:x.name,subtitle:x.description,enabled:x.enabled,onToggle:()=>P(x)},`review-${x.name}`))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ws,{className:"set-section-icon"}),r("settingsVisionBridge")]}),e.jsx(Le,{title:r("visionBridgeEnabled"),tip:r("settingsVisionBridgeDesc"),enabled:a.visionBridgeEnabled,onToggle:()=>V({visionBridgeEnabled:!a.visionBridgeEnabled})}),!a.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r("visionBridgeOffHint")}),a.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:a.visionBridgeModel??"",onChange:x=>V({visionBridgeModel:x.target.value||null}),children:[e.jsx("option",{value:"",children:r("visionBridgeAuto")}),a.visionModels.map(x=>e.jsx("option",{value:`${x.provider}/${x.id}`,children:x.label},`${x.provider}/${x.id}`))]})]}),a.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:M,onChange:x=>{const B=x.target.value;D(B),V({visionBridgePromptMode:B})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),a.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:r("visionBridgePromptPlaceholder"),value:k,onFocus:()=>S.current=!0,onBlur:()=>{S.current=!1;const x=M==="replace"&&a.visionBridgeDefaultPrompt&&k===a.visionBridgeDefaultPrompt?"":k;V({visionBridgePromptMode:M,visionBridgePrompt:x})},onChange:x=>N(x.target.value)}),a.visionBridgeEnabled&&(a.visionModels.length===0?e.jsx("p",{className:"set-hint",children:r("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:r("visionBridgeCurrent",{model:a.visionBridgeModel??r("visionBridgeAuto")})}))]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(tt,{className:"set-section-icon"}),r("settingsPresets"),e.jsx("span",{className:"set-count",children:a.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:r("presetNamePlaceholder"),value:C,onChange:x=>T(x.target.value),onKeyDown:x=>{x.key==="Enter"&&C.trim()&&(s({type:"save_preset",name:C.trim()}),T(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!C.trim(),onClick:()=>{s({type:"save_preset",name:C.trim()}),T("")},children:[e.jsx(Ae,{})," ",r("saveAsPreset")]})]}),a.presets.length===0?e.jsx("p",{className:"set-empty",children:r("noPresets")}):e.jsx("div",{className:"set-list",children:a.presets.map(x=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:x.name}),e.jsxs("div",{className:"set-row-desc",children:[x.promptMode==="replace"?r("promptModeReplace"):r("promptModeAppend"),x.disabledSkills.length>0&&` · ${r("settingsSkills")} ${x.disabledSkills.length}`,x.disabledExtensions.length>0&&` · ${r("settingsExtensions")} ${x.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:x.name}),children:r("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:r("deletePreset"),onClick:()=>s({type:"delete_preset",name:x.name}),children:e.jsx(Fe,{})})]})]},x.name))})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:r("close")})})]})})}function di(t,s){const n=Math.max(0,Date.now()-t),o=Math.floor(n/6e4);if(o<1)return s("bgTaskJustNow");if(o<60)return s("bgTaskMinutes",{n:o});const c=Math.floor(o/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function ui({servers:t,send:s,onClose:n}){const o=he(),[c,r]=i.useState(new Set),a=l=>r(u=>{const m=new Set(u);return m.has(l)?m.delete(l):m.add(l),m});return i.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"bg-task-modal",onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(at,{})," ",o("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:o("close"),onClick:n,children:e.jsx(Se,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(at,{}),e.jsx("span",{children:o("bgTasksEmpty")}),e.jsx("small",{children:o("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(l=>e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:o("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[e.jsxs("span",{className:"bg-task-port",children:[":",l.port]}),l.name&&e.jsx("span",{className:"bg-task-name",children:l.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[e.jsxs("span",{children:[o("bgTaskPid")," ",l.pid]}),e.jsxs("span",{children:[o("bgTaskSince")," ",di(l.since,o)]})]}),l.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(l.port)?"open":""}`,title:`${o("bgTaskCommand")}: ${l.command}`,onClick:()=>a(l.port),children:[e.jsx(Ve,{}),e.jsx("code",{children:l.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:o("bgTaskStop"),onClick:()=>s({type:"kill_background_server",port:l.port}),children:[e.jsx(et,{}),e.jsx("span",{children:o("bgTaskStop")})]})]},l.port))}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:o("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(St,{}),e.jsx("span",{children:o("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:o("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(et,{}),e.jsx("span",{children:o("bgTaskStopAll")})]})]})]})})}function Je(t,s){return t.toLowerCase().includes(s)}function mi({send:t,sessions:s,projects:n,cwd:o,fileSearch:c,onClose:r,onSwitchSession:a,onSwitchProject:l,onPreviewFile:u}){const m=he(),f=i.useRef(null),[h,k]=i.useState(""),N=i.useDeferredValue(h),[M,D]=i.useState(0),S=i.useRef(1),I=i.useRef(0),$=i.useRef(null);i.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var L;return(L=f.current)==null?void 0:L.focus()})},[]);const[p,C]=i.useState(!1);i.useEffect(()=>{$.current&&clearTimeout($.current);const L=N.trim();if(L)return $.current=setTimeout(()=>{const O=++S.current;I.current=O,C(!0),t({type:"search_files",reqId:O,query:L})},300),()=>{$.current&&clearTimeout($.current)}},[N]);const T=N.trim().toLowerCase(),v=i.useMemo(()=>T?s.filter(L=>Je(L.firstMessage??"",T)||Je(L.name??"",T)||Je(L.path.split(/[\\/]/).pop()??"",T)).slice(0,20):[],[s,T]),w=i.useMemo(()=>T?n.filter(L=>Je(L.path,T)).slice(0,10):[],[n,T]),d=i.useMemo(()=>!T||!c||c.reqId!==I.current||!c.ok?[]:c.results,[c,T]);i.useEffect(()=>{c&&c.reqId===I.current&&I.current!==0&&C(!1)},[c]);const R=!!c&&c.ok&&c.truncated,F=i.useMemo(()=>[...v.map(L=>({kind:"session",path:L.path})),...w.map(L=>({kind:"project",path:L.path})),...d.filter(L=>L.type==="file").map(L=>({kind:"file",path:L.path,name:L.name}))],[v,w,d]);i.useEffect(()=>{D(0)},[N]);const z=i.useCallback(L=>{L&&(L.kind==="session"?a(L.path):L.kind==="project"?l(L.path):u(L.path,L.name),r())},[a,l,u,r]);i.useEffect(()=>{const L=O=>{O.key==="Escape"?(O.preventDefault(),O.stopPropagation(),r()):O.key==="ArrowDown"?(O.preventDefault(),D(A=>Math.min(A+1,F.length-1))):O.key==="ArrowUp"?(O.preventDefault(),D(A=>Math.max(A-1,0))):O.key==="Enter"&&(O.preventDefault(),z(F[M]))};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[F,M,z,r]);const W=v.length+w.length+d.length,G=(L,O,A)=>e.jsxs("div",{className:"gs-section-head",children:[A,e.jsx("span",{children:L}),e.jsx("em",{children:O})]});let V=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:r,children:e.jsxs("div",{className:"gs-modal",onClick:L=>L.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(st,{}),e.jsx("input",{ref:f,type:"text",value:h,placeholder:m("gsPlaceholder"),onChange:L=>k(L.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:m("close"),onClick:r,children:e.jsx(Se,{})})]}),e.jsxs("div",{className:"gs-results",children:[!T&&e.jsx("div",{className:"gs-empty",children:m("gsHint")}),T&&W===0&&!R&&e.jsx("div",{className:"gs-empty",children:m(p?"gsSearching":"gsNoResults")}),v.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsSessions"),v.length,e.jsx(nt,{})),v.map(L=>{V++;const O=V;return e.jsxs("button",{type:"button",className:O===M?"gs-item active":"gs-item",onMouseEnter:()=>D(O),onClick:()=>z({kind:"session",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.name||L.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:L.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:L.firstMessage})]},L.path)})]}),w.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsProjects"),w.length,e.jsx(Oe,{})),w.map(L=>{V++;const O=V,A=o&&L.path===o;return e.jsxs("button",{type:"button",className:O===M?"gs-item active":"gs-item",onMouseEnter:()=>D(O),onClick:()=>z({kind:"project",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.path.split(/[\\/]/).pop(),A&&e.jsx("em",{className:"gs-item-meta",children:m("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},L.path)})]}),(d.length>0||T&&R)&&e.jsxs("div",{className:"gs-section",children:[G(m("gsFiles"),d.length,e.jsx(Tn,{})),d.map(L=>{V++;const O=V;return e.jsxs("button",{type:"button",className:O===M?"gs-item active":"gs-item",disabled:L.type==="dir",title:L.type==="dir"?void 0:m("gsOpenPreview"),onMouseEnter:()=>D(O),onClick:()=>{L.type==="file"&&z({kind:"file",path:L.path,name:L.name})},children:[e.jsx("span",{className:"gs-item-title",children:L.name}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},`${L.type}:${L.path}`)}),R&&e.jsx("div",{className:"gs-truncated",children:m("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",m("gsNavigate")]}),e.jsxs("span",{children:["Enter ",m("gsOpen")]}),e.jsxs("span",{children:["Esc ",m("gsCloseHint")]})]})]})})}const gt=5e3;function pi({file:t,content:s,send:n,onAddLines:o,onAttach:c,onClose:r}){const a=he(),[l,u]=i.useState(null),[m,f]=i.useState(!1),[h,k]=i.useState(null),[N,M]=i.useState(!1),[D,S]=i.useState(!1),[I,$]=i.useState(!1),[p,C]=i.useState(""),[T,v]=i.useState(!0),w=i.useRef(!1),[d,R]=i.useState(!0),[F,z]=i.useState(!1),[W,G]=i.useState(100),V=i.useRef(0),L=i.useRef(!1),O=i.useRef(null);i.useEffect(()=>{f(!0),u(null),k(null),$(!1),C(""),v(!0),w.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),i.useEffect(()=>{s&&s.path===t.path&&(u(s),I||C(s.text),f(!1))},[s,I,t.path]),i.useEffect(()=>{const K=ae=>{if(ae.key==="Escape"){me();return}if((ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="s"&&I){ae.preventDefault(),fe();return}const ee=ae.target,ke=ee&&(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable);(ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="a"&&!ke&&(ae.preventDefault(),j())};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},[r,l,I,p]),i.useEffect(()=>{const K=()=>{L.current=!1,M(!1)};return window.addEventListener("mouseup",K),()=>window.removeEventListener("mouseup",K)},[]);const A=i.useMemo(()=>{if(!l)return[];const K=l.text.split(`
|
|
19
|
-
`);return K.length>0&&K[K.length-1]===""&&K.pop(),K.slice(0,gt)},[l]),re=(l==null?void 0:l.lines)??0,ne=re>gt,P=(K,ae)=>{if(ae){const ee=V.current>0?V.current:K;k({start:Math.min(ee,K),end:Math.max(ee,K)})}else V.current=K,k({start:K,end:K})},j=()=>{A.length!==0&&(V.current=1,k({start:1,end:A.length}))},x=()=>{h&&(o(t.path,t.name,h.start,h.end),S(!0),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>S(!1),1400))},B=l!==null&&l.kind==="text"&&!l.binary&&!l.truncated,te=()=>{C((l==null?void 0:l.text)??""),$(!1),w.current&&v(!0)},ue=()=>{if(I){if(p!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges")))return;te();return}!B||!l||(w.current=ft(t.name)&&T,ft(t.name)&&v(!1),k(null),C(l.text),$(!0))},fe=()=>{!I||!l||!B||n({type:"write_file",path:t.path,text:p})&&($(!1),w.current&&v(!0),k(null))},me=()=>{I&&p!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges"))||r()},X=K=>{G(Math.min(200,Math.max(50,K)))},ge=h?h.end-h.start+1:0,g=(l==null?void 0:l.binary)??!1,U=(l==null?void 0:l.truncated)??!1,J=(l==null?void 0:l.kind)??"text",Z=ft(t.name),le=Z&&T&&!I&&J==="text"&&!g,xe=K=>ct(`/api/file?clientId=${encodeURIComponent(Rt())}&path=${encodeURIComponent(K)}`);return e.jsx("div",{className:`fp-overlay ${F?"fullscreen":""}`,onMouseDown:K=>{K.target===K.currentTarget&&me()},children:e.jsxs("div",{className:`fp ${F?"fullscreen":""}`,style:{"--fp-zoom":W/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:[l&&J==="text"&&!g&&a("fileLines",{n:re}),l&&` · ${hi(l.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[Z&&J==="text"&&!g&&l&&e.jsx("button",{type:"button",className:`fp-attach markdown ${T?"on":""}`,"data-tip":a(T?"showMarkdownSource":"showMarkdownPreview"),disabled:I,onClick:()=>v(K=>!K),children:T?e.jsx(ws,{}):e.jsx(En,{})}),J==="text"&&!g&&l&&e.jsx("button",{type:"button",className:`fp-attach edit ${I?"on":""}`,"data-tip":a(U?"fileEditTruncated":I?"exitEditFile":"editFile"),disabled:!B&&!I,onClick:ue,children:e.jsx(yt,{})}),J==="text"&&!g&&!le&&e.jsx("button",{type:"button",className:`fp-attach wrap ${d?"on":""}`,"data-tip":a(d?"disableWrap":"enableWrap"),onClick:()=>R(K=>!K),children:e.jsx(Mn,{})}),J==="text"&&l&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":a("zoomOut"),disabled:W<=50,onClick:()=>X(W-10),children:e.jsx(un,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:a("resetZoom"),onClick:()=>G(100),children:[W,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":a("zoomIn"),disabled:W>=200,onClick:()=>X(W+10),children:e.jsx(mn,{})})]}),J!=="video"&&J!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":a("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(Ae,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":a("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(vt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${F?"on":""}`,"data-tip":a(F?"exitFullscreen":"fullscreen"),onClick:()=>z(K=>!K),children:F?e.jsx(yn,{}):e.jsx(bn,{})}),e.jsx("button",{type:"button",className:"fp-close",title:a("close"),onClick:me,children:e.jsx(Se,{})})]})]}),U&&J==="text"&&!g&&e.jsx("div",{className:"fp-notice",children:a("previewTruncated")}),m&&!l&&e.jsx("div",{className:"fp-empty",children:a("loading")}),!m&&J==="none"&&!g&&e.jsx("div",{className:"fp-empty",children:a("previewNotSupported")}),!m&&J==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:xe(t.path),alt:t.name})}),!m&&J==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:xe(t.path),controls:!0,preload:"metadata"})}),!m&&le&&l&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(dt,{text:l.text})})}),!m&&g&&J!=="image"&&J!=="video"&&l&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[a("binaryFile"),l.truncated&&a("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:l.text})]}),!m&&I&&J==="text"&&!g&&l&&e.jsx("textarea",{className:`fp-editor ${d?"":"no-wrap"}`,value:p,onChange:K=>C(K.target.value),wrap:d?"soft":"off",spellCheck:!1,autoFocus:!0}),!m&&!le&&!I&&J==="text"&&!g&&l&&A.length===0&&e.jsx("div",{className:"fp-empty",children:a("emptyFile")}),!m&&!le&&!I&&J==="text"&&!g&&A.length>0&&e.jsxs("div",{className:`fp-code ${N?"dragging":""} ${d?"":"no-wrap"}`,onMouseDown:K=>{K.button===0&&K.preventDefault()},children:[A.map((K,ae)=>{const ee=ae+1,ke=h!==null&&ee>=h.start&&ee<=h.end;return e.jsxs("div",{className:`fp-line ${ke?"sel":""}`,onMouseDown:Me=>{Me.button===0&&(P(ee,Me.shiftKey),L.current=!0,M(!0))},onMouseEnter:()=>{L.current&&P(ee,!0)},children:[e.jsx("span",{className:"fp-num",children:ee}),e.jsx("span",{className:"fp-code-text",children:K})]},ee)}),ne&&e.jsx("div",{className:"fp-lines-note",children:a("previewLinesTruncated",{n:gt})})]}),e.jsx("div",{className:"fp-foot",children:I?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:a("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:ue,children:a("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:p===((l==null?void 0:l.text)??""),onClick:fe,children:[e.jsx(fn,{})," ",a("saveFile")]})]})]}):!le&&J==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:h?a("selectedRange",{n:ge,start:h.start,end:h.end}):a("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:A.length===0,onClick:j,children:a("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!h,onClick:()=>k(null),children:a("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!h||g,onClick:x,children:[D?e.jsx(lt,{}):null,a(D?"addedToChat":"addToChat")]})]})]})})]})})}function ft(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function hi(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Ws="pi-web-sounds",qe={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function qs(){try{const t=localStorage.getItem(Ws);if(!t)return{...qe};const s=JSON.parse(t),n={...qe,...s};for(const o of["enabled","question","done","start","error"])typeof n[o]!="boolean"&&(n[o]=qe[o]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=qe.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...qe}}}function gi(t){try{localStorage.setItem(Ws,JSON.stringify(t))}catch{}}let Ue=null;function fi(){try{if(!Ue){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;Ue=new t}return Ue.state==="suspended"&&Ue.resume(),Ue}catch{return null}}const xi=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],vi=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],yi=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],ji=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],bi={question:xi,done:vi,start:yi,error:ji};function ki(t,s,n){const o=t.createOscillator(),c=t.createGain();o.type=s.type,o.frequency.value=s.freq;const r=t.currentTime+s.start,a=Math.max(1e-4,s.peak*n);c.gain.setValueAtTime(1e-4,r),c.gain.exponentialRampToValueAtTime(a,r+.012),c.gain.exponentialRampToValueAtTime(1e-4,r+s.dur),o.connect(c),c.connect(t.destination),o.start(r),o.stop(r+s.dur+.05)}function ze(t,s=qs()){if(!s.enabled||!s[t])return;const n=fi();if(!n)return;const o=Math.max(0,Math.min(1,s.volume/100));for(const c of bi[t])ki(n,c,o)}const Ct="pi-web-ui:theme",Us="dark",ms="theme-stylesheet",ps="pi-web-ui:theme-change";function zs(){try{const t=localStorage.getItem(Ct);if(t&&t!==Us)return t}catch{}return null}function wi(t){try{t?localStorage.setItem(Ct,t):localStorage.removeItem(Ct)}catch{}}function Ks(t){let s=document.getElementById(ms);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(ps));return}s||(s=document.createElement("link"),s.id=ms,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(ps))}async function Ni(){try{const t=await fetch(ct("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Ci(){const[t,s]=i.useState([]),[n,o]=i.useState(()=>zs());return i.useEffect(()=>{let r=!1;return Ni().then(a=>{r||s(a)}),()=>{r=!0}},[]),i.useEffect(()=>{Ks(n),wi(n)},[n]),{themes:t,theme:n,switchTheme:r=>o(r===Us?null:r)}}function Ii(){const t=getComputedStyle(document.documentElement),s=(n,o)=>t.getPropertyValue(n).trim()||o;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 Si=i.lazy(()=>vs(()=>import("./TerminalPanel-DXxlbXLf.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function Ti({notice:t,onDismiss:s}){const n=he(),[o,c]=i.useState(!1);i.useEffect(()=>{if(o)return;const a=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(a)},[o,t.id,t.level,s]);const r=t.level==="error"?In:t.level==="warning"?Pn:Cn;return e.jsxs("div",{className:`notice notice-${t.level}${o?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(r,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:n("close"),onClick:()=>s(t.id),children:e.jsx(Se,{})})]})}const Mi=[],Vs=180,Gs=520,Js=240,Qs=t=>`pi-web-ui:${t}-panel-width`;function hs(t){const s=Number(localStorage.getItem(Qs(t)));return Number.isFinite(s)&&s>=Vs&&s<=Gs?s:Js}function gs({side:t,width:s,onResize:n}){const o=he(),c=i.useCallback(r=>{r.preventDefault();const a=r.clientX,l=s;let u=l;const m=h=>{const k=t==="left"?h.clientX-a:a-h.clientX;u=Math.min(Gs,Math.max(Vs,Math.round(l+k))),n(u)},f=()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",f),document.body.classList.remove("panel-resizing"),localStorage.setItem(Qs(t),String(u))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",f),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:o("dragToResize"),onPointerDown:c,onDoubleClick:()=>n(Js)})}function Ei(){var ie,Y,ye,pe,je,Te,It,Bt,Dt,_t,$t,Ft;const t=he(),{chat:s,send:n,dismissNotice:o,pushNotice:c,terminal:r}=na(),[a,l]=i.useState([]),[u,m]=i.useState(null),[f,h]=i.useState("chat"),k=i.useMemo(()=>s.plugins.filter(E=>{var H,oe;return!((oe=(H=s.settings)==null?void 0:H.disabledPlugins)!=null&&oe.includes(E.id))}),[s.plugins,(ie=s.settings)==null?void 0:ie.disabledPlugins]),[N,M]=i.useState([]);i.useEffect(()=>Gn(M),[]),i.useEffect(()=>{Jn(k,s.pluginsEpoch)},[k,s.pluginsEpoch]);const[D,S]=i.useState(()=>hs("left")),[I,$]=i.useState(()=>hs("right")),p=i.useCallback(E=>S(E),[]),C=i.useCallback(E=>$(E),[]),[T,v]=i.useState(null),[w,d]=i.useState(()=>window.matchMedia("(max-width: 768px)").matches);i.useEffect(()=>{const E=window.matchMedia("(max-width: 768px)"),H=oe=>d(oe.matches);return E.addEventListener("change",H),()=>E.removeEventListener("change",H)},[]);const[R,F]=i.useState(!1),[z,W]=i.useState(!1),[G,V]=i.useState(!1),[L,O]=i.useState(!1),[A,re]=i.useState(!1);i.useEffect(()=>{const E=H=>{!(H.ctrlKey||H.metaKey)||H.key.toLowerCase()!=="k"||(H.preventDefault(),re(oe=>!oe))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[]);const[ne,P]=i.useState(qs),{themes:j,theme:x,switchTheme:B}=Ci(),te=i.useRef(null),ue=i.useRef(null),fe=i.useRef(0),me=i.useRef(!1),X=i.useRef(s.terminals);i.useEffect(()=>{gi(ne)},[ne]),i.useEffect(()=>{var H;const E=X.current;X.current=s.terminals;for(const oe of s.terminals){if(!((H=oe.command)!=null&&H.command.startsWith("pi remove ")))continue;const be=E.find(Ce=>Ce.id===oe.id);be!=null&&be.running&&!oe.running&&n({type:"extensions_reload"})}},[s.terminals,n]),i.useEffect(()=>{var oe;const E=((oe=s.state)==null?void 0:oe.isStreaming)??!1,H=te.current;te.current=E,H!==null&&(!H&&E?ze("start",ne):H&&!E&&ze("done",ne))},[(Y=s.state)==null?void 0:Y.isStreaming,ne]),i.useEffect(()=>{var H;const E=((H=s.dialog)==null?void 0:H.id)??null;E!==null&&E!==ue.current&&ze("question",ne),ue.current=E},[s.dialog,ne]),i.useEffect(()=>{const E=[...s.notices].reverse().find(H=>H.level==="error");E&&E.id!==fe.current&&(fe.current=E.id,ze("error",ne))},[s.notices,ne]);const ge=(E,H,oe,be=!1,Ce)=>{const ut=`${E}|${oe}|${Ce?`${Ce.start}-${Ce.end}`:""}`;l(Ee=>Ee.some(We=>`${We.path}|${We.mode}|${We.lines?`${We.lines.start}-${We.lines.end}`:""}`===ut)?Ee:[...Ee,{path:E,name:H,mode:oe,isDir:be,...Ce?{lines:Ce}:{}}])},g=E=>l(H=>H.filter(oe=>oe.key?oe.key!==E:oe.path!==E)),U=i.useCallback(E=>(!E.type.startsWith("list_")&&!E.type.startsWith("get_")&&v(null),n(E)),[n]),J=i.useRef(0),Z=i.useRef(0),le=E=>{var be;const H=Date.now();(be=s.state)!=null&&be.model&&!s.state.model.vision&&H-Z.current>1e4&&(Z.current=H,c("warning",t("imageNotSupported")));const oe=`paste-${++J.current}`;l(Ce=>[...Ce,{path:"",key:oe,name:E.name,mode:"inline",imageData:E.data,mimeType:E.mimeType}])},xe=async E=>{for(const H of E){const oe=await Qa(H);if(!oe){c("error",t("imageLoadFailed",{name:H.name}));continue}le(oe)}},K=20*1024*1024,ae=i.useRef(0),ee=async E=>{if(E.size>K){c("warning",t("fileTooLarge",{name:E.name,size:K/1024/1024}));return}let H;try{H=(await new Promise((Ce,ut)=>{const Ee=new FileReader;Ee.onload=()=>Ce(Ee.result),Ee.onerror=()=>ut(Ee.error??new Error("read failed")),Ee.readAsDataURL(E)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:E.name}));return}const oe=`upload-${++ae.current}`;l(be=>[...be,{path:"",key:oe,name:E.name,mode:"inline",fileData:H,size:E.size,mimeType:E.type||void 0}])},ke=async E=>{for(const H of E)Ye(H.type)?await xe([H]):await ee(H)},Me=i.useCallback((E,H)=>{n({type:"edit_message",messageId:E,text:H})},[n]),Be=i.useCallback(()=>W(!0),[]),b=i.useCallback(()=>l([]),[]),_=i.useCallback(g,[]),se=i.useCallback(xe,[xe]),Q=i.useCallback(ke,[ke]),ce=(ye=s.state)==null?void 0:ye.model,de=(pe=s.state)==null?void 0:pe.thinkingLevel,ve=(je=s.state)==null?void 0:je.availableThinkingLevels,Ne=i.useMemo(()=>ce?{model:ce,thinkingLevel:de??"off",availableThinkingLevels:ve??[]}:null,[ce,de,ve]),y=i.useCallback(()=>{var E,H;return!s.ready||s.terminals.length!==0?!1:(r.create({id:He(),conversationId:s.activeConversationId||((E=s.state)==null?void 0:E.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((H=s.state)==null?void 0:H.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Te=s.state)==null?void 0:Te.cwd,s.terminals.length,t,r]);return i.useEffect(()=>{if(me.current){if(f!=="terminal"||s.terminals.length!==0){me.current=!1;return}y()&&(me.current=!1)}},[s.terminals.length,y,f]),e.jsxs("div",{className:"app",onDragOver:E=>E.preventDefault(),onDrop:E=>E.preventDefault(),children:[e.jsx(On,{chat:s,send:n,terminal:r,view:f,plugins:k,onViewChange:E=>{me.current=E==="terminal"&&s.terminals.length===0,me.current&&y()&&(me.current=!1),h(E),v(null)},onOpenPanel:v,onManageModels:()=>W(!0),onOpenSettings:()=>V(!0),onOpenBgTasks:()=>O(!0),onOpenGlobalSearch:()=>re(!0),sound:ne,onSoundChange:P,onSoundPreview:E=>ze(E,ne),themes:j,theme:x,onThemeChange:B}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(E=>e.jsx(Ti,{notice:E,onDismiss:o},E.id))}),e.jsxs("div",{className:"layout",style:{"--left-w":`${D}px`,"--right-w":`${I}px`},children:[T&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>v(null)}),e.jsxs("div",{className:`view-pane ${f==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${T==="left"?"open":""}`,children:e.jsx(Hn,{send:U,active:!w||T==="left",ready:s.ready,status:s.status,cwd:((It=s.state)==null?void 0:It.cwd)??"",sessionFile:((Bt=s.state)==null?void 0:Bt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!w&&e.jsx(gs,{side:"left",width:D,onResize:p}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Va,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:Me,onKillBash:()=>n({type:"abort_bash"})},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(Xa,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(ti,{dialog:s.dialog,send:n}),e.jsx(Ya,{send:n,ready:s.ready,streaming:((Dt=s.state)==null?void 0:Dt.isStreaming)??!1,messages:((_t=s.state)==null?void 0:_t.messages)??Mi,slashCommands:s.slashCommands,modelState:Ne,models:s.models,modelsLoading:s.modelsLoading,attachments:a,onRemoveAttachment:_,onAddImageFiles:se,onAddLocalFiles:Q,onNotice:c,onManageModels:Be,onSent:b})]}),!w&&e.jsx(gs,{side:"right",width:I,onResize:C}),e.jsx("div",{className:`panel-drawer drawer-right ${T==="right"?"open":""}`,children:e.jsx(ma,{send:U,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:(($t=s.state)==null?void 0:$t.cwd)??"",onAttach:(E,H,oe,be)=>{v(null),ge(E,H,oe,be)},onPreview:(E,H)=>{v(null),m({path:E,name:H})},onNotice:(E,H)=>c(E,H)})})]}),e.jsx("div",{className:`view-pane ${f==="terminal"?"":"hidden"}`,children:e.jsx(i.Suspense,{fallback:null,children:e.jsx(Si,{chat:s,send:n,terminal:r})})}),e.jsx("div",{className:`view-pane ${f==="git"?"":"hidden"}`,children:e.jsx(ni,{chat:s,send:n,terminal:r,active:f==="git",onSwitchToTerminal:()=>h("terminal")})}),N.map(E=>{const H=`plugin:${E.info.id}`;return e.jsx("div",{className:`view-pane ${f===H?"":"hidden"}`,children:e.jsx(ai,{entry:E,send:n})},E.info.id)})]}),e.jsx(Za,{chat:s,send:n}),u&&e.jsx(pi,{file:u,content:s.fileContent,send:n,onAddLines:(E,H,oe,be)=>ge(E,H,"lines",!1,{start:oe,end:be}),onAttach:(E,H,oe)=>ge(E,H,oe),onClose:()=>m(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!R&&!z&&e.jsx(ii,{send:n,piConfigured:s.state.piConfigured,providers:s.providers,installResult:s.installResult,onClose:()=>F(!0)}),z&&e.jsx(li,{send:n,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>W(!1)}),G&&e.jsx(ci,{chat:s,send:n,terminal:r,onSwitchToTerminal:()=>h("terminal"),onClose:()=>V(!1)}),L&&e.jsx(ui,{servers:s.bgServers,send:n,onClose:()=>O(!1)}),A&&e.jsx(mi,{send:n,sessions:s.sessions,projects:s.projects,cwd:((Ft=s.state)==null?void 0:Ft.cwd)??"",fileSearch:s.fileSearch,onClose:()=>re(!1),onSwitchSession:E=>{n({type:"switch_session",path:E})},onSwitchProject:E=>{n({type:"set_cwd",path:E})},onPreviewFile:(E,H)=>{m({path:E,name:H})}})]})}Wn();Ks(zs());en.createRoot(document.getElementById("root")).render(e.jsx(i.StrictMode,{children:e.jsx($n,{children:e.jsx(Ei,{})})}));export{St as F,ps as T,Ae as a,Ii as b,Pi as c,Kt as d,Fe as e,Se as f,jn as g,Ve as h,He as r,he as u};
|
|
8
|
+
`),inFence:c!==null}}const ya=i.memo(function({text:s}){return e.jsx(vs,{remarkPlugins:Ds,rehypePlugins:_s,children:s})}),as=200;function ja({text:t,inFence:s}){const[n,o]=i.useState(t),c=i.useRef(0),r=i.useRef(null);return i.useEffect(()=>{if(s)return;const a=Date.now()-c.current,l=()=>{c.current=Date.now(),o(t)};if(a>=as){l();return}return r.current=setTimeout(l,as-a),()=>{r.current&&clearTimeout(r.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx($s,{text:n})}const ba=i.memo(function({text:s}){const{frozen:n,active:o,inFence:c}=i.useMemo(()=>va(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((r,a)=>e.jsx(ya,{text:r},a)),o.length>0&&e.jsx(ja,{text:o,inFence:c},n.length)]})});function ka({thinking:t,streaming:s}){const n=he(),[o,c]=i.useState(s),r=t.split(`
|
|
9
|
+
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${o?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>c(a=>!a),children:[o?e.jsx(De,{}):e.jsx(lt,{}),e.jsx(rt,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s?e.jsxs("span",{className:"thinking-live-label",children:[n("thinkingNow"),e.jsx("span",{className:"dots"})]}):o?n("thinking"):n("thinkingPreview",{preview:r})})]}),o&&e.jsx("div",{className:"thinking-body",children:t})]})}const wa={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function Na(t){return wa[t]??"🛠"}const Ca=i.memo(function({block:s,view:n,onKillBash:o}){var C,T,v,w;const c=he(),[r,a]=i.useState(!0),[l,u]=i.useState(!1),m=!n.result&&n.streaming&&!n.status,f=s.name==="bash"&&m,h=n.result!==void 0,k=!n.result&&!!n.status,N=((C=n.result)==null?void 0:C.isError)??((T=n.status)==null?void 0:T.isError)??!1,M=n.result?n.result.content.map(d=>d.type==="text"?d.text:"").join(""):n.liveOutput??"",D=N?"err":h?"ok":m||k?"run":"idle";let S=c(N?"error":h?"done":m?"running":k?"toolDoneWaitingModel":"toolQueued");const P=k&&((v=n.status)==null?void 0:v.durationMs)!==void 0?Ta(n.status.durationMs):"";k&&P&&(S=`${S} · ${P}`);const $=k&&((w=n.status)==null?void 0:w.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",p=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),u(!0),setTimeout(()=>u(!1),1200))};return e.jsxs("div",{className:`toolcall ${D}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:Na(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[S,$&&e.jsx("em",{className:"toolcall-exit",children:$})]}),e.jsx("span",{className:"toolcall-spacer"}),f&&o&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:c("stopBashTip"),onClick:o,children:[e.jsx(tt,{}),e.jsx("span",{children:c("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:c("copyArgs"),onClick:p,children:l?e.jsx(In,{}):e.jsx(Mt,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>a(d=>!d),children:r?e.jsx(De,{}):e.jsx(lt,{})})]}),r&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(Sa,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),M.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[c(N?"errorOutput":"output"),(m||k)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:M})]}),m&&M.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",c("waitingOutput")]}),k&&M.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",c("waitingModel")]})]})]})});function Sa({args:t}){let s=null;try{s=JSON.parse(t)}catch{return e.jsx("pre",{children:t})}return typeof s.command!="string"?e.jsx("pre",{children:t}):e.jsxs("div",{className:"termline",children:[e.jsx(Ge,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function Ta(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),o=Math.round(s%60);return`${n}m ${String(o).padStart(2,"0")}s`}const Ea=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function It(t){var n;const s=t.match(Ea);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}function Ve(t){return t.type==="text"&&typeof t.text=="string"?t:null}function Fs(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function As(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function Os(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function Hs(t){return t.type==="bash"&&typeof t.command=="string"?t:null}const is=i.memo(function({message:s,toolResults:n,liveOutputs:o,toolStatuses:c,streaming:r,isLast:a,onEdit:l,onKillBash:u,onCollapse:m,qnIndex:f,qnActive:h,onJump:k}){const N=he(),[M,D]=i.useState(!1),[S,P]=i.useState("");if(s.role==="toolResult")return null;const $=s.role==="custom"&&s.customType==="file",p=s.content.map(W=>{var G;return((G=Ve(W))==null?void 0:G.text)??""}).filter(Boolean).join(`
|
|
10
|
+
`),C=s.role==="user"?It(p):null,T=C?C.userMessage??`skill:${C.name}`:p.split(`
|
|
11
|
+
`).join(" ").trim(),v=r&&a&&s.content.length===0,w=s.role==="user"&&!r&&!v&&!!l,d=()=>{P(C?`/skill:${C.name}${C.userMessage?` ${C.userMessage}`:""}`:s.content.map(W=>{var G;return((G=Ve(W))==null?void 0:G.text)??""}).filter(Boolean).join(`
|
|
12
|
+
`)),D(!0)},R=()=>{const W=S.trim();W&&(l==null||l(s.id,W),D(!1))},F=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),z=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${F?" msg-goal-review":""}`,"data-role":s.role,"data-msg-id":s.id,children:[e.jsxs("div",{className:"msg-meta",children:[e.jsx("span",{className:"msg-role",children:s.role==="custom"?z?N("goalWizardCard"):F?N("goalBarTitle"):s.customType==="file"?N("attachment"):`${N("plugin")} · ${s.customType??N("unknown")}`:Ws(s.role,N)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:Ia(s.timestamp)}),m&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:N("collapseMsg"),onClick:()=>m(s.id),children:[e.jsx(ot,{})," ",N("collapseMsg")]}),f!==void 0&&k&&e.jsxs("button",{type:"button",className:`qn-tag ${h?"active":""}`,title:`${f+1}. ${T}`,"aria-label":`${f+1}. ${T}`,onClick:()=>k(s.id),children:[e.jsx("span",{className:"qn-tag-bar"}),e.jsx("span",{className:"qn-tag-idx",children:f+1})]})]}),e.jsx("div",{className:"msg-body",children:M?e.jsxs("div",{className:"msg-editor",children:[e.jsx("textarea",{className:"msg-editor-input",value:S,autoFocus:!0,placeholder:N("editPlaceholder"),rows:Math.max(2,Math.min(10,S.split(`
|
|
13
|
+
`).length+1)),onChange:W=>P(W.target.value),onKeyDown:W=>{W.key==="Enter"&&(W.metaKey||W.ctrlKey)?(W.preventDefault(),R()):W.key==="Escape"&&D(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsx("span",{className:"msg-editor-hint",children:N("editHint")}),e.jsx("button",{type:"button",className:"chip",onClick:()=>D(!1),children:N("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!S.trim(),title:N("reaskFromHere"),onClick:R,children:[e.jsx(jt,{})," ",N("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),$?e.jsx(Ma,{message:s}):C?e.jsxs(e.Fragment,{children:[e.jsx(La,{block:C}),C.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(ut,{text:C.userMessage})}),s.content.map((W,G)=>W.type==="text"?null:e.jsx(os,{block:W,toolResults:n,liveOutputs:o,toolStatuses:c,streaming:r,isLast:a,onKillBash:u},`${s.id}-${G}`))]}):s.content.map((W,G)=>e.jsx(os,{block:W,toolResults:n,liveOutputs:o,toolStatuses:c,streaming:r,isLast:a,onKillBash:u},`${s.id}-${G}`)),v&&e.jsxs("div",{className:"thinking-wait",children:[N("thinkingWait"),e.jsx("span",{className:"dot"})]}),r&&a&&!v&&e.jsx("span",{className:"stream-cursor"})]})}),w&&!M&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:N("editReaskTip"),onClick:d,children:[e.jsx(jt,{})," ",N("editReask")]})})]})});function Ma({message:t}){const s=he(),[n,o]=i.useState(!1),c=t.details??{},r=c.name??c.path??s("attachment"),a=c.type==="folder",l=c.mode==="reference",u=c.mode==="bridged",m=t.content.filter(N=>N.type==="text").map(N=>N.text).join(`
|
|
14
|
+
`),f=Ra(m),h=t.content.find(N=>N.type==="image"),k=f.split(`
|
|
15
|
+
`).length;return e.jsxs("div",{className:`attachcard ${l?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>o(N=>!N),children:[e.jsx("span",{className:"attachcard-icon",children:a?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:r}),c.path&&e.jsx("span",{className:"attachcard-path",children:c.path}),e.jsx("span",{className:`attachcard-mode ${c.mode==="lines"?"lines":l?"ref":u?"bridged":"inline"}`,children:l?a?s("folderRefShort"):`${s("refOnlyShort")} · ${rs(c.size)}`:u?s("bridgedVision"):h?s("image"):c.mode==="lines"?s("inlineLinesRange",{start:c.startLine??1,end:c.endLine??c.lines??1}):s("inlineLines",{n:c.lines??k})}),!l&&(n?e.jsx(De,{}):e.jsx(lt,{}))]}),!l&&n&&(u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"attachcard-bridgenote",children:s("bridgedVisionDetail")}),(h==null?void 0:h.dataUrl)&&e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:h.dataUrl,alt:r})}),f&&e.jsx("pre",{className:"attachcard-content",children:f})]}):h!=null&&h.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:h.dataUrl,alt:r})}):e.jsx("pre",{className:"attachcard-content",children:f})),l&&e.jsx("div",{className:"attachcard-refnote",children:a?s("folderNotExpanded"):s("fileNotExpanded",{size:rs(c.size)})})]})}function rs(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function Ra(t){const s=t.match(/^\s*<file path="[^"]*"(?:\s+lines="[^"]*")?>\s*```\s*\n?([\s\S]*?)\n?```\s*<\/file>\s*$/);if(s)return s[1].trim();const n=t.match(/^\s*<vision-bridge>\s*([\s\S]*?)\s*<\/vision-bridge>\s*$/);return n?n[1].trim():t.trim()}function La({block:t}){const s=he(),[n,o]=i.useState(!1);return e.jsxs("div",{className:`skillcard${n?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>o(c=>!c),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(Pn,{})}),e.jsx("span",{className:"skillcard-name",children:t.name}),e.jsx("span",{className:"skillcard-path",children:t.location}),e.jsxs("span",{className:"skillcard-action",children:[n?e.jsx(ot,{}):e.jsx(De,{}),s(n?"collapseMsg":"expandMsg")]})]}),n&&e.jsx("div",{className:"skillcard-body",children:e.jsx(ut,{text:t.content})})]})}function os({block:t,toolResults:s,liveOutputs:n,toolStatuses:o,streaming:c,isLast:r,onKillBash:a}){const l=he(),u=Ve(t);if(u){const N=c&&r;return e.jsxs("div",{className:"msg-text",children:[N?e.jsx(ba,{text:u.text}):e.jsx(ut,{text:u.text}),u.truncated&&e.jsx("div",{className:"trunc-note",children:l("truncated")})]})}const m=Fs(t);if(m)return e.jsx(ka,{thinking:m.thinking,streaming:c&&r});const f=As(t);if(f){const N=s.get(f.id),M=n.get(f.id),D={result:N,liveOutput:M==null?void 0:M.text,streaming:c,status:o.get(f.id)};return e.jsx(Ca,{block:f,view:D,onKillBash:a})}const h=Os(t);if(h&&h.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:h.dataUrl,alt:"attachment"})});const k=Hs(t);return k?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:k.command}),k.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${k.exitCode===0?"ok":"err"}`,children:l("exitCode",{code:k.exitCode})}),k.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:l("cancelled")})]}),k.output&&e.jsx("pre",{className:"bashblock-output",children:k.output}),k.truncated&&e.jsx("div",{className:"trunc-note",children:l("outputTruncated")})]}):null}function Ws(t,s){switch(t){case"user":return s("role.user");case"assistant":return s("role.assistant");case"toolResult":return s("role.tool");case"bashExecution":return s("role.bash");case"branchSummary":return s("role.branch");case"compactionSummary":return s("role.compaction");default:return t}}function Ia(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${n}:${o}`}const Pa=i.memo(function({message:s,onExpand:n}){const o=he();let c="";for(const h of s.content){const k=Ve(h);if(k&&k.text.trim()){const N=It(k.text);N?c=`skill:${N.name}`+(N.userMessage?` · ${N.userMessage.replace(/\s+/g," ").trim()}`:""):c=k.text.replace(/\s+/g," ").trim();break}}if(!c&&s.role==="custom"&&s.customType==="file"){const h=s.details??{};c=h.name??h.path??""}c.length>90&&(c=`${c.slice(0,90)}…`);let a=0,l=0,u=0,m=0;for(const h of s.content)Fs(h)?a++:As(h)?l++:Hs(h)?u++:Os(h)&&m++;const f=[];return a&&f.push(`${o("thinking")} ${a}`),l&&f.push(`${o("toolCalls")} ${l}`),u&&f.push(`${o("bashRuns")} ${u}`),m&&f.push(`${o("images")} ${m}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${o("expandMsg")} · ${c||f.join(" · ")||s.role}`,onClick:()=>n(s.id),children:[e.jsx("span",{className:`msg-collapsed-role role-${s.role}`,children:s.role==="custom"&&s.customType==="file"?o("attachment"):Ws(s.role,o)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),f.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:f.map((h,k)=>e.jsx("span",{className:"msg-collapsed-chip",children:h},k))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:Ba(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(De,{})," ",o("expandMsg")]})]})});function Ba(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${n}:${o}`}const Da=i.memo(function({id:s,show:n,height:o,containerRef:c,onMeasured:r,lazyRef:a,children:l}){const u=i.useRef(null),m=i.useRef(null);return i.useLayoutEffect(()=>{const f=m.current;if(m.current=n,!n||f!==!1)return;const h=u.current,k=c.current;if(!h||!k)return;const N=h.offsetHeight;r==null||r(s,N);const M=N-o;if(M!==0){const D=h.parentElement;D&&D.getBoundingClientRect().bottom<=k.getBoundingClientRect().top&&(k.scrollTop+=M)}},[n]),n?e.jsx("div",{ref:a,"data-lazy-id":s,children:e.jsx("div",{ref:u,children:l})}):e.jsx("div",{ref:a,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:o},"aria-hidden":"true"})});function _a(t,s,n,o){const c=[],r=[];let a=0;for(const l of t){if(n.has(l.id))continue;l.top<s.bottom&&l.bottom>s.top?o.has(l.id)&&c.push(l.id):o.has(l.id)||(r.push(l.id),l.bottom<=s.top&&(a+=l.bottom-l.top))}return{show:c,hide:r,shrinkAbove:a}}function $a(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const o of s.show)n.delete(o);for(const o of s.hide)n.add(o);return n}function Fa(t,s,n){const o=new Set;let c=0;for(let r=t.length-1;r>=0&&!(r<t.length-1&&c>=n);r--){const a=t[r];o.add(a.id),c+=s.get(a.id)??qs(a.role,a.customType)}return o}function qs(t,s){switch(t){case"user":return 72;case"assistant":return 280;case"toolResult":return 8;case"custom":return s==="file"?96:72;default:return 60}}function Aa(t){if(t.role==="toolResult")return"";const s=[];for(const n of t.content)Oa(n,s);return t.errorMessage&&s.push(t.errorMessage),s.join(`
|
|
16
|
+
`)}function Oa(t,s){if(typeof t.text=="string"){s.push(t.text);return}switch(t.type){case"thinking":typeof t.thinking=="string"&&s.push(t.thinking);break;case"toolCall":{typeof t.name=="string"&&s.push(t.name),typeof t.argumentsText=="string"&&s.push(t.argumentsText);break}case"bash":typeof t.command=="string"&&s.push(t.command),typeof t.output=="string"&&s.push(t.output);break}}function Ha(t,s){const n=s.trim().toLowerCase();if(!n)return 0;const o=t.toLowerCase();let c=0,r=o.indexOf(n);for(;r!==-1;)c++,r=o.indexOf(n,r+n.length);return c}function Wa(t,s){const n=s.trim().toLowerCase();if(!n)return[];const o=[];for(const c of t){const r=Aa(c);if(!r)continue;const a=Ha(r,n);for(let l=0;l<a;l++)o.push({messageId:c.id,occurrence:l})}return o}function qa(t,s){var a;const n=new Map,o=[],c=s.toLowerCase();if(!c)return{byMsg:n,all:o};const r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(l){const u=l.parentElement;return!u||u.closest(".search-bar")?NodeFilter.FILTER_REJECT:(l.textContent??"").toLowerCase().includes(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let l=r.nextNode();l;l=r.nextNode()){const u=(l.textContent??"").toLowerCase(),m=(a=l.parentElement)==null?void 0:a.closest("[data-msg-id]");if(!m)continue;const f=m.getAttribute("data-msg-id")??"";let h=u.indexOf(c);for(;h!==-1;){const k=document.createRange();k.setStart(l,h),k.setEnd(l,h+c.length),o.push(k);const N=n.get(f);N?N.push(k):n.set(f,[k]),h=u.indexOf(c,h+c.length)}}return{byMsg:n,all:o}}function Ae(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const o=window.Highlight;o&&n.highlights.set(t,new o(...s))}function Ua({containerRef:t,messages:s,open:n,onClose:o,onEnsureExpanded:c}){const r=he(),a=i.useRef(null),[l,u]=i.useState(""),[m,f]=i.useState(0),h=i.useDeferredValue(l),k=n?h.trim():"",N=i.useMemo(()=>n?Wa(s,k):[],[s,k,n]),M=i.useRef(N);M.current=N;const D=i.useRef(m);D.current=m,i.useEffect(()=>{n&&(f(0),requestAnimationFrame(()=>{var p;return(p=a.current)==null?void 0:p.select()}))},[n]),i.useEffect(()=>{if(!n)return;const p=C=>{C.key==="Escape"&&(C.preventDefault(),C.stopPropagation(),o())};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)},[n,o]),i.useEffect(()=>(n||(Ae("msg-search",[]),Ae("msg-search-active",[])),()=>{Ae("msg-search",[]),Ae("msg-search-active",[])}),[n]);const S=i.useCallback(p=>{const C=t.current;if(!C)return;const T=C.querySelector(`[data-msg-id="${p}"]`);T&&(T.classList.remove("msg-flash"),T.offsetWidth,T.classList.add("msg-flash"))},[t]);i.useLayoutEffect(()=>{if(!n||!k)return;const p=t.current;if(!p)return;let C=!1,T=0;return T=requestAnimationFrame(()=>{var z;if(C)return;const{byMsg:v,all:w}=qa(p,k);Ae("msg-search",w);const d=M.current,R=d[Math.min(D.current,d.length-1)];if(!R)return;const F=(z=v.get(R.messageId))==null?void 0:z[R.occurrence];if(F){Ae("msg-search-active",[F]);const W=F.startContainer.parentElement??p.querySelector(`[data-msg-id="${R.messageId}"]`);W==null||W.scrollIntoView({block:"center"})}else S(R.messageId)}),()=>{C=!0,cancelAnimationFrame(T)}},[n,k,N,t,S]);const P=i.useCallback(p=>{const C=M.current;if(C.length===0)return;const T=(D.current+p+C.length)%C.length;f(T),c(C[T].messageId)},[c]);if(!n)return null;const $=N.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:a,className:"search-input",type:"text",value:l,placeholder:r("searchPlaceholder"),onChange:p=>{u(p.target.value),f(0)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),P(p.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${$===0?"empty":""}`,children:$===0?r("searchNoResults"):`${Math.min(m+1,$)}/${$}`}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchPrev"),disabled:$===0,onClick:()=>P(-1),children:e.jsx(ot,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchNext"),disabled:$===0,onClick:()=>P(1),children:e.jsx(De,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchClose"),onClick:o,children:e.jsx(Te,{})})]})}const ls=new Map,za=15,cs=30,ds=1200,Ka=1600;function us(t){return t.content.some(s=>s.type==="toolCall")}const Va=[{key:"ex.understand",icon:"🔍"},{key:"ex.debug",icon:"🐛"},{key:"ex.test",icon:"🧪"},{key:"ex.review",icon:"🧹"}];function Ga(t){return Va.map(({key:s,icon:n})=>({icon:n,text:t(s),prompt:t(`${s}.prompt`)}))}function Ja({state:t,liveOutputs:s,toolStatuses:n,onEdit:o,onKillBash:c}){const r=he(),a=i.useRef(null),[l,u]=i.useState(!0),m=i.useRef(!0),f=i.useRef(0),h=i.useRef(!1),[k,N]=i.useState(()=>new Set),[M,D]=i.useState(!1),S=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,P=i.useMemo(()=>{const b=new Map;for(const _ of t.messages)_.role==="toolResult"&&_.toolCallId&&b.set(_.toolCallId,_);return b},[t.messages]),$=S.length>0?S[S.length-1].id:null,p=t.messages.length>cs?Math.max(0,t.messages.length-za):0,[C,T]=i.useState(()=>new Set),[v,w]=i.useState(()=>new Set),d=i.useRef(new Map),R=i.useRef(new Map),F=i.useRef(0),z=i.useRef(C);z.current=C;const W=t.messages.length>cs&&!M,G=i.useRef(W);G.current=W;const V=Fa(t.messages,d.current,Ka),L=i.useRef(V);L.current=V;const H=i.useCallback(()=>{const b=a.current;if(!b)return;if(!G.current){T(de=>de.size?new Set:de);return}const _=b.getBoundingClientRect(),se={top:_.top-ds,bottom:_.bottom+ds},Q=[];for(const[de,ve]of R.current){const Se=ve.getBoundingClientRect();Q.push({id:de,top:Se.top,bottom:Se.bottom}),z.current.has(de)||d.current.set(de,Se.bottom-Se.top)}const ce=_a(Q,se,L.current,z.current);for(const de of ce.hide){const ve=R.current.get(de);ve&&d.current.set(de,ve.offsetHeight)}T(de=>$a(de,ce))},[]),A=i.useCallback(()=>{F.current||(F.current=requestAnimationFrame(()=>{F.current=0,H()}))},[H]);i.useLayoutEffect(()=>{H()},[H]);const oe=i.useRef(M);i.useLayoutEffect(()=>{oe.current&&!M&&H(),oe.current=M},[M,H]);const ae=i.useCallback((b,_)=>{d.current.set(b,_)},[]),I=i.useCallback(b=>{b&&R.current.set(b.dataset.lazyId??"",b)},[]);i.useEffect(()=>{const b=new Set(t.messages.map(_=>_.id));for(const[_,se]of R.current)b.has(_)||(R.current.delete(_),d.current.delete(_));T(_=>{let se=!1;const Q=new Set;for(const ce of _)b.has(ce)?Q.add(ce):se=!0;return se?Q:_})},[t.messages,k]),i.useEffect(()=>()=>cancelAnimationFrame(F.current),[]);const j=i.useMemo(()=>{const b=[];for(const _ of t.messages){if(_.role!=="user")continue;const se=_.content.map(de=>{var ve;return((ve=Ve(de))==null?void 0:ve.text)??""}).filter(Boolean).join(" "),Q=It(se),ce=Q?Q.userMessage??`skill:${Q.name}`:se.trim();ce&&b.push({id:_.id,text:ce})}return b},[t.messages]),x=i.useMemo(()=>{const b=new Map;return j.forEach((_,se)=>b.set(_.id,se)),b},[j]),[B,te]=i.useState(-1),ue=i.useRef(-1),fe=i.useRef(j);i.useEffect(()=>{fe.current=j},[j]);const me=i.useCallback(()=>{const b=a.current,_=fe.current;if(!b||_.length===0)return;const se=b.getBoundingClientRect().top,Q=140;let ce=-1;for(let de=0;de<_.length;de++){const ve=b.querySelector(`[data-msg-id="${_[de].id}"]`);if(ve)if(ve.getBoundingClientRect().top<=se+Q)ce=de;else break}ce!==ue.current&&(ue.current=ce,te(ce))},[]);i.useEffect(()=>{me()},[j,me]);const X=i.useCallback(b=>{N(_=>_.has(b)?_:new Set(_).add(b))},[]),ge=i.useCallback(b=>{const _=t.messages.findIndex(se=>se.id===b);_>=0&&_<p&&!k.has(b)&&ss.flushSync(()=>X(b))},[t.messages,p,k,X]);i.useEffect(()=>{const b=_=>{if(!(_.ctrlKey||_.metaKey)||_.key.toLowerCase()!=="f")return;const se=_.target;se&&(se.tagName==="INPUT"||se.tagName==="TEXTAREA"||se.isContentEditable)||(_.preventDefault(),D(!0))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]);const g=i.useCallback(b=>{N(_=>{if(!_.has(b))return _;const se=new Set(_);return se.delete(b),se})},[]),U=i.useCallback(b=>{const _=t.messages.findIndex(Q=>Q.id===b);ss.flushSync(()=>{_>=0&&_<p&&!k.has(b)&&X(b),w(Q=>Q.has(b)?Q:new Set(Q).add(b))});const se=fe.current.findIndex(Q=>Q.id===b);ue.current=se,te(se),requestAnimationFrame(()=>{var ce,de,ve;const Q=(ce=a.current)==null?void 0:ce.querySelector(`[data-msg-id="${b}"]`);Q&&((de=a.current)==null||de.querySelectorAll(".msg-flash").forEach(Se=>Se.classList.remove("msg-flash")),Q.scrollIntoView({block:"start"}),Q.classList.remove("msg-flash"),Q.offsetWidth,Q.classList.add("msg-flash"),Q!==((ve=a.current)==null?void 0:ve.lastElementChild)&&(h.current=!0))})},[t.messages,p,k,X]),J=i.useCallback(()=>{const b=a.current;if(!b)return;const _=b.scrollTop-f.current;f.current=b.scrollTop;const se=b.scrollHeight-b.scrollTop-b.clientHeight<80;_<-4&&_>-500?h.current=!0:se&&_>=0&&(h.current=!1),m.current=se&&!h.current,u(m.current),me(),A()},[me,A]),Z=i.useRef(!1);i.useEffect(()=>{const b=Z.current;if(Z.current=!!t.isStreaming,b&&!t.isStreaming&&!h.current){const _=()=>{const Q=a.current;Q&&!h.current&&(Q.scrollTop=Q.scrollHeight,m.current=!0,u(!0))};requestAnimationFrame(()=>requestAnimationFrame(_));const se=setTimeout(_,180);return()=>clearTimeout(se)}},[t.isStreaming]),i.useEffect(()=>{const b=a.current;b&&m.current&&(b.scrollTop=b.scrollHeight)},[S,t.isStreaming,s]);const le=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");i.useEffect(()=>{const b=a.current;b&&m.current&&(b.scrollTop=b.scrollHeight)},[le]);const xe=i.useCallback(()=>{const b=a.current;b&&(b.scrollTop=b.scrollHeight),m.current=!0,h.current=!1,u(!0)},[]),K=i.useRef(null);i.useEffect(()=>{const b=K.current,_=a.current;if(!b||!_)return;const se=Q=>{Q.preventDefault();const ce=b.querySelector(".qn-list");if(ce&&ce.contains(Q.target)&&ce.scrollHeight>ce.clientHeight){ce.scrollTop+=Q.deltaY;return}_.scrollTop+=Q.deltaY};return b.addEventListener("wheel",se,{passive:!1}),()=>b.removeEventListener("wheel",se)},[]);const[ie,ee]=i.useState(0);i.useEffect(()=>{const b=()=>{var _;ee(((_=a.current)==null?void 0:_.clientHeight)??0),A()};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[A]);const Ne=j.length,Me=i.useMemo(()=>Ne===0?27:Math.max(4,Math.min(27,Math.floor(((ie||600)-16)/Ne)-3)),[Ne,ie]),_e=Me<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:"messages",ref:a,onScroll:J,children:[t.messages.length===0&&!t.streamingMessage&&e.jsxs("div",{className:"empty-state",children:[e.jsx("div",{className:"empty-logo-wrap",children:e.jsx("div",{className:"empty-logo",children:"π"})}),e.jsx("h2",{className:"empty-title",children:r("welcomeTitle")}),e.jsx("p",{className:"empty-sub",children:r("welcomeSub")}),e.jsxs("div",{className:"empty-cwd",children:[e.jsx("span",{className:"empty-cwd-label",children:r("directory")}),e.jsx("span",{className:"empty-cwd-path",children:t.cwd})]}),e.jsx("div",{className:"empty-examples",children:Ga(r).map(b=>e.jsxs("button",{type:"button",className:"empty-example",title:r("clickToFill"),onClick:()=>window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:b.prompt})),children:[e.jsx("span",{className:"empty-example-icon",children:b.icon}),e.jsx("span",{className:"empty-example-text",children:b.text})]},b.prompt))})]}),t.messages.map((b,_)=>{const se=_<p,Q=se&&k.has(b.id);if(se&&!Q)return b.role==="toolResult"?null:e.jsx(Pa,{message:b,onExpand:X},b.id);const ce=b.role==="user"?x.get(b.id):void 0,de=!W||V.has(b.id)||v.has(b.id)||!C.has(b.id);return e.jsx(Da,{id:b.id,show:de,height:d.current.get(b.id)??qs(b.role,b.customType),containerRef:a,onMeasured:ae,lazyRef:I,children:e.jsx(is,{message:b,qnIndex:ce,qnActive:ce!==void 0?ce===B:void 0,onJump:U,toolResults:P,liveOutputs:us(b)?s:ls,toolStatuses:n,streaming:t.isStreaming,onKillBash:c,isLast:b.id===$,onEdit:o,onCollapse:Q?g:void 0},b.id)},b.id)}),t.streamingMessage&&e.jsx(is,{message:t.streamingMessage,toolResults:P,liveOutputs:us(t.streamingMessage)?s:ls,toolStatuses:n,streaming:!0,isLast:!0,onEdit:o,onKillBash:c},t.streamingMessage.id),t.isStreaming&&S.length===0&&e.jsx("div",{className:"streaming-wait",children:r("waitingResponse")}),t.queue.steering.map((b,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:r("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-steer-${_}`)),t.queue.followUp.map((b,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:r("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-fu-${_}`))]}),!l&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:xe,children:[e.jsx(Es,{})," ",r("backToBottom")]}),e.jsx(Ua,{containerRef:a,messages:S,open:M,onClose:()=>D(!1),onEnsureExpanded:ge}),j.length>0&&e.jsxs("div",{className:`qn-rail ${_e?"many":""}`,ref:K,"aria-label":r("questionNavTitle"),style:{"--rail-gap":`${Me}px`},children:[j.map((b,_)=>e.jsx("button",{type:"button",className:`qn-bar ${_===B?"active":""}`,"aria-label":`${_+1}. ${b.text}`,onClick:()=>U(b.id),children:e.jsxs("span",{className:"qn-bar-text",children:[_+1,". ",b.text]})},b.id)),_e&&e.jsx("div",{className:"qn-list",children:j.map((b,_)=>e.jsxs("button",{type:"button",className:`qn-list-item ${_===B?"active":""}`,"aria-label":`${_+1}. ${b.text}`,onClick:()=>U(b.id),children:[e.jsx("span",{className:"qn-list-idx",children:_+1}),e.jsx("span",{className:"qn-list-text",children:b.text})]},b.id))})]})]})}const Qa=1568,Ya=2*1024*1024;function Xe(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function Xa(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const n=Math.min(1,Qa/Math.max(s.width,s.height)),o=Math.max(1,Math.round(s.width*n)),c=Math.max(1,Math.round(s.height*n)),r=t.type==="image/jpeg"||t.type==="image/jpg"?[["image/jpeg",.85],["image/jpeg",.6],["image/webp",.8]]:[["image/png",1],["image/jpeg",.85],["image/jpeg",.6]];let a=null;for(const[l,u]of r){const m=document.createElement("canvas");m.width=o,m.height=c;const f=m.getContext("2d");if(!f)continue;l!=="image/png"&&(f.fillStyle="#ffffff",f.fillRect(0,0,o,c)),f.drawImage(s,0,0,o,c);const h=m.toDataURL(l,u),k=h.match(/^data:([^;]+);base64,/),N=k?k[1]:l,M=h.replace(/^data:[^;]*;base64,/,""),D=Math.floor(M.length*3/4);if(a={data:M,mimeType:N,name:t.name,size:D},D<=Ya)return a}return a}finally{s.close()}}const Za=i.memo(function({ready:s,streaming:n,messages:o,slashCommands:c,modelState:r,models:a,modelsLoading:l,send:u,attachments:m,onRemoveAttachment:f,onAddImageFiles:h,onAddLocalFiles:k,onNotice:N,onSent:M,onManageModels:D}){const S=he(),{locale:P}=Rt(),$=g=>P==="en"&&g.descriptionEn?g.descriptionEn:g.description??"",p=g=>P==="en"&&g.argumentHintEn?g.argumentHintEn:g.argumentHint??"",[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null),[F,z]=i.useState(0),[W,G]=i.useState(!1),[V,L]=i.useState(void 0),H=i.useRef(null),A=i.useRef(null),oe=i.useRef(null),ae={builtin:S("slashBuiltin"),extension:S("slashExtension"),prompt:S("slashPrompt"),skill:S("slashSkill")},I=g=>{const U=g.match(/^\/([^\s]*)$/);if(U&&s){const J=U[1].toLowerCase(),Z=c.filter(le=>le.name.toLowerCase().startsWith(J));R(Z.length>0?Z:null),z(0)}else R(null)};i.useEffect(()=>{var U;const g=(U=oe.current)==null?void 0:U.querySelector(".slash-item.active");g==null||g.scrollIntoView({block:"nearest"})},[F,d]);const j=g=>{var xe;const U=d??[],J=g??U[F%Math.max(U.length,1)];if(!J){R(null);return}const Z=C.match(/^\/([^\s]*)([\s\S]*)$/),le=Z?Z[2]:"";T(`/${J.name} ${le}`),R(null),(xe=H.current)==null||xe.focus()},x=async()=>{const U=[...o].reverse().find(Z=>Z.role==="assistant"&&Z.content.some(le=>le.type==="text"&&le.text)),J=U==null?void 0:U.content.filter(Z=>Z.type==="text").map(Z=>Z.text).join(`
|
|
17
|
+
`);if(!J){N("warning",S("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(J),N("info",S("slashCopied"))}catch{N("error",S("slashCopyFailed"))}},B=g=>{if(!g||g.length===0){N("warning",S("foldersNotSupported"));return}const U=Array.from(g).filter(Z=>Xe(Z.type)),J=Array.from(g).filter(Z=>!Xe(Z.type));U.length>0&&h(U),J.length>0&&k(J)},te=g=>{var Z;const U=(Z=g.clipboardData)==null?void 0:Z.items;if(!U)return;const J=[];for(const le of U)if(le.kind==="file"&&Xe(le.type)){const xe=le.getAsFile();xe&&J.push(xe)}J.length!==0&&(g.preventDefault(),h(J))},ue=s,fe=i.useRef(C);i.useEffect(()=>{fe.current=C},[C]),i.useEffect(()=>{I(fe.current)},[c]),i.useEffect(()=>{const g=U=>{var Z;const J=U.detail;T(J),(Z=H.current)==null||Z.focus()};return window.addEventListener("pi-web:fill",g),()=>window.removeEventListener("pi-web:fill",g)},[]),i.useEffect(()=>{if(!W)return;const g=U=>{U.key==="Escape"&&G(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[W]),i.useEffect(()=>{const g=H.current;if(!g)return;g.style.height="auto";const U=g.scrollHeight>220;g.style.height=`${Math.min(g.scrollHeight,220)}px`,g.style.overflowY=U?"auto":"hidden"},[C]);const me=(g=!1)=>{var Z,le,xe,K,ie;const U=C.trim(),J=m.some(ee=>ee.imageData||ee.fileData);if(!(!ue||!U&&!J)){if(U==="/help"){const ee=(le=(Z=H.current)==null?void 0:Z.closest(".inputbox"))==null?void 0:le.getBoundingClientRect();L(ee==null?void 0:ee.width),G(!0),T(""),(xe=H.current)==null||xe.focus();return}if(U==="/copy"){T(""),(K=H.current)==null||K.focus(),x();return}u({type:"prompt",text:U,queue:g,attachments:m.map(ee=>ee.imageData?{path:"",imageData:ee.imageData,mimeType:ee.mimeType,name:ee.name}:ee.fileData?{path:"",fileData:ee.fileData,mimeType:ee.mimeType,name:ee.name,size:ee.size}:{path:ee.path,mode:ee.mode,...ee.lines?{lines:ee.lines}:{}})})&&(T(""),M(),(ie=H.current)==null||ie.focus())}},X=g=>{if(!g.nativeEvent.isComposing){if(d&&d.length>0)switch(g.key){case"ArrowDown":g.preventDefault(),z(U=>(U+1)%d.length);return;case"ArrowUp":g.preventDefault(),z(U=>(U-1+d.length)%d.length);return;case"Tab":case"Enter":g.preventDefault(),j();return;case"Escape":g.preventDefault(),R(null);return}g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),me())}},ge=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[C.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:S("supplementTip"),onClick:()=>me(!0),children:[e.jsx(xn,{})," ",S("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:S("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(tt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:S("sendTip"),disabled:!ue||!C.trim()&&!m.some(g=>g.imageData||g.fileData),onClick:()=>me(),children:e.jsx(Ts,{})})});return e.jsxs("div",{className:`inputbar${v?" drop-active":""}`,onDragOver:g=>{g.preventDefault(),g.stopPropagation(),w(!0)},onDragLeave:g=>{g.currentTarget.contains(g.relatedTarget)||w(!1)},onDrop:g=>{var U;g.preventDefault(),g.stopPropagation(),w(!1),B(((U=g.dataTransfer)==null?void 0:U.files)??null)},children:[v&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",S("dropHereToAttach")]})}),m.length>0&&e.jsxs("div",{className:"attach-row",children:[m.map(g=>e.jsxs("span",{className:`attach-chip ${g.imageData?"image":g.fileData?"file":g.mode}`,title:g.imageData?S("attachImage",{name:g.name}):g.fileData?S("attachFile",{name:g.name}):g.isDir?S("folderRef",{path:g.path}):g.mode==="reference"?S("refOnly",{path:g.path}):g.mode==="lines"&&g.lines?S("attachLines",{path:g.path,start:g.lines.start,end:g.lines.end}):S("attachContent",{path:g.path}),children:[g.imageData?"🖼":g.fileData?"📄":g.isDir?"📁":g.mode==="reference"?"🔗":"📎"," ",g.name,g.mode==="lines"&&g.lines&&e.jsxs("span",{className:"attach-range",children:["L",g.lines.start,"-",g.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:S("removeAttachment"),onClick:()=>f(g.key??g.path),children:"×"})]},g.key??`${g.path}|${g.mode}|${g.lines?`${g.lines.start}-${g.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:S("attachHint")})]}),d&&d.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:oe,"aria-label":S("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:S("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>R(null),children:"Esc"})]}),d.map((g,U)=>e.jsxs("button",{type:"button",className:`slash-item${U===F?" active":""}`,onMouseEnter:()=>z(U),onClick:()=>j(g),children:[e.jsxs("span",{className:"slash-name",children:["/",g.name]}),e.jsx("span",{className:`slash-source ${g.source}`,children:ae[g.source]}),e.jsxs("span",{className:"slash-desc",children:[$(g),g.argumentHint&&e.jsx("span",{className:"slash-hint",children:p(g)})]})]},g.name))]}),W&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:V?{width:V}:void 0,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",S("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:S("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:S("slashLoading")}):c.map(g=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",g.name]}),e.jsx("span",{className:`slash-source ${g.source}`,children:ae[g.source]}),e.jsxs("span",{className:"slash-help-desc",children:[$(g),g.argumentHint&&e.jsx("span",{className:"slash-hint",children:p(g)})]})]},g.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:A,type:"file",multiple:!0,hidden:!0,onChange:g=>{B(g.target.files),g.target.value=""}}),e.jsxs("div",{className:"inputbox-row",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var g;return(g=A.current)==null?void 0:g.click()},children:e.jsx(Kt,{})}),e.jsx("textarea",{ref:H,value:C,rows:1,placeholder:S(ue?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!ue,onChange:g=>{T(g.target.value),I(g.target.value)},onKeyDown:X,onPaste:te}),ge()]}),e.jsxs("div",{className:"input-tools",children:[e.jsx("div",{className:"input-tools-left",children:e.jsx(Ls,{state:r,models:a,modelsLoading:l,send:u,onManageModels:D,compact:!0})}),e.jsxs("div",{className:"input-tools-right",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var g;return(g=A.current)==null?void 0:g.click()},children:e.jsx(Kt,{})}),ge()]})]})]})]})}),ei=i.memo(function({goal:s,models:n,modelsLoading:o,activeConversationId:c,send:r}){var z,W,G,V,L,H;const a=he(),l=!s.conversationId||s.conversationId===c,u=s.goal!==null&&l,[m,f]=i.useState(""),[h,k]=i.useState(s.reviewModel??""),[N,M]=i.useState(s.maxRounds),[D,S]=i.useState(s.locked),[P,$]=i.useState(!1),[p,C]=i.useState(!1),[T,v]=i.useState(!0);i.useEffect(()=>{k(s.reviewModel??""),M(s.maxRounds||0),S(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),i.useEffect(()=>{P&&n.length===0&&!p&&!o&&(C(!0),r({type:"list_models"}))},[P,n.length,p,o,r]),i.useEffect(()=>{n.length>0&&C(!1)},[n.length]);const w=()=>{var A;return h?((A=n.find(oe=>oe.id===h))==null?void 0:A.name)??h:a("goalBarUseMainModel")},d=()=>{const A=m.trim();A&&(r({type:"set_goal",goal:A,...h?{reviewModel:h}:{},maxRounds:N,locked:D}),f(""),v(!1))},R=()=>{const A=m.trim();A&&(r({type:"start_goal_wizard",text:A,...h?{wizardModel:h}:{},maxRounds:N,locked:D}),f(""),v(!1))},F=(((z=s.wizard)==null?void 0:z.active)??!1)&&l;return F?e.jsx("div",{className:`goalbar goalbar-active ${F?"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:((W=s.wizard)==null?void 0:W.draft)??"",children:[a("goalWizardRunning"),": ",(G=s.wizard)==null?void 0:G.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[a("goalBarRound",{n:(((V=s.wizard)==null?void 0:V.step)??0)+1})," ","/ ",((L=s.wizard)==null?void 0:L.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((H=s.wizard)==null?void 0:H.status)||a("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),onClick:()=>{r({type:"clear_goal"}),v(!0)},children:e.jsx(Te,{})})]})}):u?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:[a("goalBarReviewing")," ",a("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?a("goalBarPassed"):s.verdict==="fail"?a("goalBarFailed"):`${a("goalBarRound",{n:s.round||1})} · ${s.locked?a("goalBarLocked"):a("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:s.status}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),disabled:s.reviewing,onClick:()=>{r({type:"clear_goal"}),v(!0)},children:e.jsx(Te,{})})]})}):T?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:a("goalBarPlaceholder"),onClick:()=>v(!1),children:[e.jsx(zt,{})," ",e.jsx("span",{children:a("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(zt,{})}),e.jsx("input",{className:"goalbar-input",value:m,placeholder:a("goalBarPlaceholder"),onChange:A=>f(A.target.value),onKeyDown:A=>{A.key==="Enter"&&d()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!m.trim(),onClick:d,children:a("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!m.trim(),title:a("goalWizardTip"),onClick:R,children:["🔍 ",a("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a(D?"goalBarLocked":"goalBarUnlocked"),onClick:()=>S(A=>(r({type:"set_goal_prefs",locked:!A}),!A)),children:D?e.jsx(Cn,{}):e.jsx(gn,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a("goalBarClear"),onClick:()=>v(!0),children:e.jsx(ot,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Le,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[a("goalBarReviewModel"),": ",e.jsx("b",{children:w()})]}),open:P,onOpenChange:$,direction:"up",children:[e.jsx("div",{className:"dd-header",children:a("goalBarReviewModel")}),(p||o)&&e.jsx("div",{className:"dd-loading",children:a("loading")}),n.length===0&&!p&&!o&&e.jsx("div",{className:"dd-loading",children:a("noModels")}),e.jsx(Ce,{active:h==="",onClick:()=>{k(""),$(!1),r({type:"set_goal_prefs",reviewModel:""})},children:a("goalBarUseMainModel")}),n.map(A=>e.jsx(Ce,{active:h===A.id,onClick:()=>{k(A.id),$(!1),r({type:"set_goal_prefs",reviewModel:A.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:A.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:A.provider})})]})},A.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>r({type:"list_models"}),children:a("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:a("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:a("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:N,placeholder:a("goalBarUnlimitedShort"),onChange:A=>{const oe=parseInt(A.target.value,10);if(Number.isNaN(oe)||oe<0){M(0);return}M(oe)},onBlur:()=>r({type:"set_goal_prefs",maxRounds:N}),onKeyDown:A=>{A.key==="Enter"&&(r({type:"set_goal_prefs",maxRounds:N}),A.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:a(D?"goalBarLocked":"goalBarUnlocked")})]})]})});function ti({chat:t,send:s}){const n=he(),o=t.state,[c,r]=i.useState(!1),[a,l]=i.useState(""),[u,m]=i.useState(0),f=i.useRef(null),h=t.pathCompletions;if(i.useEffect(()=>{if(!c)return;const d=setTimeout(()=>{s({type:"complete_path",path:a})},150);return()=>clearTimeout(d)},[a,c,s]),i.useEffect(()=>m(0),[h]),i.useEffect(()=>{const d=document.querySelector(`.status-completions .pc-item[data-idx="${u}"]`);d==null||d.scrollIntoView({block:"nearest"})},[u]),!o)return null;const k=o.stats,N=t.ready?"ok":"busy",M=t.ready?n("connected"):n("connecting"),D=k.contextUsage,S=D.tokens!==null&&D.percent!==null?`${ms(D.tokens)} / ${ms(D.contextWindow)}`:"—",P=D.percent??null,$=P===null?"":P>=80?"warn":P>=50?"mid":"ok",p=o.queue.steering.length+o.queue.followUp.length,C=()=>{l(o.cwd),r(!0)},T=(d,R)=>{var z;const F=d.includes("\\")?"\\":"/";l(R?`${d}${F}`:d),m(0),(z=f.current)==null||z.focus()},v=d=>{const R=d.trim();R&&R!==o.cwd&&s({type:"set_cwd",path:R}),r(!1)},w=d=>{if(d.key==="ArrowDown")d.preventDefault(),m(R=>Math.min(R+1,h.length-1));else if(d.key==="ArrowUp")d.preventDefault(),m(R=>Math.max(R-1,0));else if(d.key==="Tab"&&h.length>0){d.preventDefault();const R=h[Math.min(u,h.length-1)];T(R.path,R.type==="dir")}else if(d.key==="Enter"&&!d.nativeEvent.isComposing){const R=a.trim();if(R.endsWith("/")||R.endsWith("\\"))v(R);else if(h.some(F=>F.path===R))v(R);else if(h.length>0&&h[u]){d.preventDefault();const F=h[u];T(F.path,F.type==="dir")}else v(R)}else d.key==="Escape"&&(h.length>0?(d.stopPropagation(),s({type:"complete_path",path:""})):r(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${N}`,title:M}),e.jsx("span",{className:"status-item",children:M}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${$}`,children:P!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(P,100)}%`}})}),S]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",si(k.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("sessionMessages"),children:[n("messages")," ",k.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:n("pluginStatus"),children:t.statuses.map(d=>d.text).join(" · ")})]}),o.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"}),n("working"),p>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",p," ",n("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:f,className:"status-cwd-input",value:a,autoFocus:!0,placeholder:n("enterPath"),onChange:d=>l(d.target.value),onKeyDown:w,onBlur:()=>r(!1)}),h.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:d=>d.preventDefault(),children:h.map((d,R)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":R,className:`pc-item ${R===u?"sel":""}`,onMouseEnter:()=>m(R),onClick:()=>T(d.path,d.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:d.type==="dir"?e.jsx(qe,{}):e.jsx(Ns,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:d.name}),e.jsx("span",{className:"pc-path",children:d.path})]})]})},d.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:n("cwdTip",{path:o.cwd}),onClick:C,children:["📁 ",o.cwd]})]})}function ms(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function si(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function ni({dialog:t,send:s}){const n=he(),[o,c]=i.useState(""),[r,a]=i.useState(0),l=f=>{s({type:"dialog_response",id:t.id,value:f})};i.useEffect(()=>{c(""),a(0);const f=h=>{h.key==="Escape"&&l(null)};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],m=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:n("pluginRequest")}),t.title&&t.title!==n("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>l(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((f,h)=>e.jsx("button",{type:"button",className:`dialog-option ${h===r?"sel":""}`,onMouseEnter:()=>a(h),onClick:()=>l(f),children:f},h)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:n("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:m}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>l(!1),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>l(!0),children:n("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:o,placeholder:m||n("inputPlaceholder"),autoFocus:!0,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&l(o)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>l(null),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>l(o),children:n("ok")})]})]})]})}function ai(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",n=t.y!==" "&&t.y!=="?";return s&&n?"both":s?"staged":"unstaged"}function ii({chat:t,send:s,terminal:n,active:o,onSwitchToTerminal:c}){var ve,Se;const r=he(),[a,l]=i.useState(null),[u,m]=i.useState([]),[f,h]=i.useState(""),[k,N]=i.useState(new Map),[M,D]=i.useState("changes"),[S,P]=i.useState([]),[$,p]=i.useState(null),[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null),[F,z]=i.useState(null),[W,G]=i.useState(!1),[V,L]=i.useState(!1),[H,A]=i.useState(!1),[oe,ae]=i.useState(null),[I,j]=i.useState(!1),[x,B]=i.useState(""),te=i.useRef(0),ue=i.useRef(-1),fe=i.useRef(-1),me=i.useRef(-1),X=i.useRef(-1),ge=i.useRef(void 0),g=i.useRef(null),U=i.useRef([]),J=i.useCallback(y=>{if(y.reqId===ue.current){if(ue.current=-1,L(!1),ae(null),!y.ok){ae(y.error??"查询失败");return}if(y.notRepo){j(!0),l(null),m([]),N(new Map),P([]),p(null),T(""),z(null);return}j(!1);const re={branch:y.branch??"",detached:!!y.detached,upstream:y.upstream??null,ahead:y.ahead??0,behind:y.behind??0,upstreamGone:!!y.upstreamGone,files:(y.files??[]).map(pe=>({...pe}))},Y=(y.branches??[]).map(pe=>({...pe})),je=new Map;for(const[pe,be]of Object.entries(y.stats??{}))je.set(pe,{add:be[0],del:be[1]});l(re),m(Y),N(je),h(pe=>{var be;return re.detached?pe||"":re.branch&&Y.some(Ee=>Ee.name===re.branch)?re.branch:pe&&Y.some(Ee=>Ee.name===pe)?pe:((be=Y[0])==null?void 0:be.name)??""}),z(pe=>pe&&!re.files.some(be=>be.path===pe.file.path)?null:pe)}else if(y.reqId===fe.current){if(fe.current=-1,G(!1),!y.ok){ae(y.error??"查询失败");return}const re=g.current;if(!re)return;z({file:re,staged:y.stagedText??"",worktree:y.worktreeText??"",untracked:!1})}else if(y.reqId===X.current){if(X.current=-1,A(!1),!y.ok){ae(y.error??"查询失败");return}P((y.history??[]).map(re=>({...re})))}else if(y.reqId===me.current){if(me.current=-1,w(!1),!y.ok){ae(y.error??"查询失败");return}T(y.text??"")}},[]);i.useEffect(()=>{const y=t.scmData;y&&y.type==="scm_data"&&J(y)},[t.scmData,J]);const Z=i.useCallback((y,re)=>{if(!t.ready||t.status!=="open")return!1;const Y=++te.current;return s({...y,reqId:Y})?(re.current=Y,!0):(te.current-=1,!1)},[t.ready,t.status,s]),le=i.useCallback((y=!1,re=!1)=>{var Y;!t.ready||t.status!=="open"||(Y=t.state)!=null&&Y.cwd&&(ge.current!==void 0&&ge.current!==t.state.cwd&&(l(null),m([]),N(new Map),P([]),A(!1),X.current=-1,p(null),T(""),z(null),R(null)),ge.current=t.state.cwd,ae(null),Z({type:"scm_status"},ue)&&(re||L(!0)))},[t.ready,(ve=t.state)==null?void 0:ve.cwd,t.status,Z]),xe=i.useCallback(y=>{if(R(y),p(null),g.current=y,y.x==="?"&&y.y==="?"){z({file:y,staged:"",worktree:"",untracked:!0});return}G(!0),ae(null),Z({type:"scm_filediff",path:y.path},fe)||G(!1)},[Z]),K=i.useCallback(y=>{p(y),R(null),z(null),T(""),w(!0),ae(null),Z({type:"scm_commit",hash:y.hash},me)||w(!1)},[Z]),ie=i.useCallback((y,re)=>{var pe,be;if(!t.ready)return;const Y={name:y,command:re,cwd:"${pwd}"},je=t.terminals.find(Ee=>Ee.title===y);if(je)n.restart(je.id),s({type:"run_command",terminalId:je.id,conversationId:je.conversationId,command:Y,cols:80,rows:24});else{const Ee=Be();n.create({id:Ee,conversationId:t.activeConversationId||((pe=t.state)==null?void 0:pe.conversationId)||"",title:y,cwd:((be=t.state)==null?void 0:be.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Y})}c()},[t.ready,(Se=t.state)==null?void 0:Se.cwd,t.terminals,c,s,n]),ee=i.useCallback(()=>{const y=x.trim();if(!y||I)return;const re=y.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ie("git commit",`git add -A && git commit -m "${re}"`),B("")},[x,I,ie]),Ne=y=>`'${y.replace(/'/g,"'\\''")}`,Me=i.useCallback(y=>{I||ie("git add",`git add -- ${Ne(y.path)}`)},[I,ie]),_e=i.useCallback(y=>{I||ie("git reset",`git reset HEAD -- ${Ne(y.path)}`)},[I,ie]),b=i.useCallback(()=>{if(!f||I)return;const y=u.find(re=>re.name===f);if(y!=null&&y.remote&&typeof y.remote=="string"){const re=f.slice(y.remote.length+1);ie("git checkout",`git checkout -b ${re} ${f} || git checkout ${f}`)}else ie("git checkout",`git checkout ${f}`)},[f,u,I,ie]),_=i.useCallback(()=>ie("git push","git push"),[ie]),se=i.useCallback(()=>ie("git pull","git pull"),[ie]),Q=i.useCallback(()=>{Z({type:"scm_history"},X)||(X.current=-1)},[Z]);i.useEffect(()=>{o&&le()},[o,le]),i.useEffect(()=>{M==="history"&&a&&Q()},[M,a,Q]),i.useEffect(()=>{t.scmDirty>0&&o&&le(!1,!0)},[t.scmDirty]),i.useEffect(()=>{if(!o||!t.ready||t.status!=="open")return;const y=setInterval(()=>{document.visibilityState!=="hidden"&&le(!1,!0)},3e4);return()=>clearInterval(y)},[o,t.ready,t.status,le]),i.useEffect(()=>{const y=U.current;if(U.current=t.terminals,!o)return;t.terminals.some(Y=>{var pe;return Y.running!==!1?!1:((pe=y.find(be=>be.id===Y.id))==null?void 0:pe.running)===!0&&/^git /.test(Y.title)})&&t.ready&&t.status==="open"&&(le(!1,!0),M==="history"&&a&&Q())},[t.terminals,o,t.ready,t.status,le,M,a,Q]);const ce={staged:r("scmStaged"),unstaged:r("scmUnstaged"),untracked:r("scmUntracked"),both:r("scmStagedUnstaged")},de=y=>{const re=y.split(`
|
|
18
|
+
`);return e.jsx("pre",{className:"scm-diff-pre",children:re.map((Y,je)=>{let pe="";return Y.startsWith("diff --git")||Y.startsWith("index ")||Y.startsWith("new file")||Y.startsWith("deleted file")||Y.startsWith("old mode")||Y.startsWith("new mode")||Y.startsWith("similarity index")||Y.startsWith("rename ")||Y.startsWith("copy ")||Y.startsWith("Binary files")||Y.startsWith("---")||Y.startsWith("+++")?pe="hdr":Y.startsWith("@@")?pe="hunk":Y.startsWith("+")?pe="add":Y.startsWith("-")&&(pe="del"),e.jsx("div",{className:`scm-diff-line ${pe}`,children:Y||" "},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(Ye,{}),r("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":M==="changes",className:M==="changes"?"active":"",onClick:()=>{D("changes"),ae(null)},children:r("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":M==="history",className:M==="history"?"active":"",onClick:()=>{D("history"),ae(null)},children:r("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:r("scmRefreshTip"),disabled:V,onClick:()=>le(!0),children:e.jsx(Tt,{className:V?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:r("scmCurrentBranch"),children:[e.jsx(Ye,{}),a?a.detached?r("scmDetached"):a.branch:"…",(a==null?void 0:a.upstream)&&e.jsx("span",{className:"scm-upstream",children:a.upstreamGone?r("scmUpstreamGone"):a.ahead>0||a.behind>0?r("scmAheadBehind",{ahead:a.ahead,behind:a.behind}):a.upstream})]}),e.jsxs("select",{className:"scm-select",value:f,disabled:I||u.length===0,title:r("scmSwitchBranch"),onChange:y=>h(y.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("scmSelectBranch")}),u.filter(y=>!y.remote).map(y=>e.jsx("option",{value:y.name,children:y.current?`* ${y.name}`:y.name},y.name)),u.some(y=>y.remote)&&e.jsx("optgroup",{label:r("scmRemoteBranches"),children:u.filter(y=>y.remote).map(y=>e.jsx("option",{value:y.name,children:y.name},y.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!f||f===(a==null?void 0:a.branch)||I,title:r("scmSwitchBranchTip",{branch:f}),onClick:b,children:[e.jsx(Ye,{}),r("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||I,title:r("scmPushTip"),onClick:_,children:[e.jsx(Ts,{}),r("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||I,title:r("scmPullTip"),onClick:se,children:[e.jsx(Es,{}),r("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:x,placeholder:r("scmCommitPlaceholder"),disabled:I,onChange:y=>B(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&ee()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!x.trim()||I,title:r("scmCommitTip"),onClick:ee,children:[e.jsx(ct,{}),r("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[M==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmHistory")}),S.length>0&&e.jsx("span",{className:"scm-files-count",children:S.length})]}),e.jsx("div",{className:"scm-history-list",children:I?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):!a||H?e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")}):S.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoHistory")}):S.map(y=>e.jsxs("button",{type:"button",className:`scm-commit ${($==null?void 0:$.hash)===y.hash?"active":""}`,onClick:()=>K(y),title:y.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:y.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:y.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[y.shortHash," · ",y.author," · ",y.date]}),y.decorations&&e.jsx("span",{className:"scm-commit-refs",children:y.decorations})]})]},y.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmChanges")}),a&&a.files.length>0&&e.jsx("span",{className:"scm-files-count",children:a.files.length})]}),e.jsx("div",{className:"scm-files-list",children:I?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):a?a.files.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoChanges")}):a.files.map(y=>{const re=ai(y),Y=k.get(y.path);return e.jsxs("div",{className:`scm-file ${(d==null?void 0:d.path)===y.path?"active":""}`,title:ce[re],onClick:()=>xe(y),children:[e.jsx("span",{className:`scm-file-xy ${re==="untracked"?"q":"x"}`,children:y.x!==" "?y.x:" "}),e.jsx("span",{className:`scm-file-xy ${re==="untracked"?"q":"y"}`,children:y.y!==" "?y.y:" "}),e.jsx("span",{className:"scm-file-path",children:y.path}),Y&&(Y.add>0||Y.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[Y.add>0&&e.jsxs("span",{className:"add",children:["+",Y.add]}),Y.del>0&&e.jsxs("span",{className:"del",children:["-",Y.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(y.y!==" "||re==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:r("scmStageTip",{path:y.path}),onClick:je=>{je.stopPropagation(),Me(y)},children:"+"}),re==="staged"||re==="both"?e.jsx("button",{type:"button",className:"scm-act",title:r("scmUnstageTip",{path:y.path}),onClick:je=>{je.stopPropagation(),_e(y)},children:"−"}):null]})]},y.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:M==="history"?$?`${$.shortHash} ${$.subject}`:r("scmCommitDetail"):d?d.path:r("scmDiff")}),(M==="history"?v:W)&&e.jsx("span",{className:"scm-diff-loading",children:r("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:M==="history"?e.jsxs(e.Fragment,{children:[oe&&e.jsx("div",{className:"scm-error",children:oe}),!$&&!oe&&e.jsx("div",{className:"scm-empty",children:r("scmSelectCommitHint")}),$&&v&&!oe&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),$&&!v&&!oe&&C?de(C):null]}):e.jsxs(e.Fragment,{children:[oe&&e.jsx("div",{className:"scm-error",children:oe}),!d&&!oe&&e.jsx("div",{className:"scm-empty",children:r("scmSelectFileHint")}),d&&!F&&!oe&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),d&&F&&F.untracked&&e.jsx("div",{className:"scm-empty",children:r("scmUntrackedNote")}),d&&F&&!F.untracked&&e.jsxs(e.Fragment,{children:[F.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmStaged")}),de(F.staged)]}),F.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmUnstaged")}),de(F.worktree)]}),!F.staged&&!F.worktree&&e.jsx("div",{className:"scm-empty",children:r("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ge,{}),e.jsx("span",{children:r("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:r("scmViewTerminal")})]})]})}function ri({entry:t,send:s}){const n=i.useRef(null);return i.useEffect(()=>{const o=n.current;if(!o)return;let c;try{c=t.module.mount(o,Xn(t.info.id,r=>s(r)))}catch(r){console.error(`[plugin:${t.info.id}] mount failed:`,r),o.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(r){console.error(`[plugin:${t.info.id}] cleanup failed:`,r)}o.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:n})}function oi({send:t,piConfigured:s,providers:n,installResult:o,onClose:c}){const r=he(),[a,l]=i.useState(!1),[u,m]=i.useState(""),[f,h]=i.useState(""),[k,N]=i.useState(!1);i.useEffect(()=>{t({type:"list_providers"})},[t]),i.useEffect(()=>{s&&c()},[s,c]),i.useEffect(()=>{o&&l(!1)},[o]),i.useEffect(()=>{var p;!u&&n.length>0&&m(((p=n.find(C=>!C.configured))==null?void 0:p.id)??n[0].id)},[n,u]);const M=()=>{a||(l(!0),t({type:"install_pi_agent"}))},D=()=>{!f.trim()||k||(N(!0),t({type:"set_provider_api_key",provider:u.trim(),apiKey:f.trim()}),setTimeout(()=>N(!1),3e3))},S=()=>{t({type:"get_state"}),t({type:"list_providers"})},P=n.find(p=>p.id===u),$=o!==null&&!o.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":r("close"),onClick:c,children:e.jsx(Te,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(rt,{className:"modal-head-icon"}),e.jsx("h2",{children:r("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("setupDesc")}),$?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:r("installFailed")}),e.jsx("pre",{className:"setup-detail",children:o.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:r("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]}):o!=null&&o.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:r("installDone")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("provider")}),e.jsxs("select",{value:u,onChange:p=>m(p.target.value),children:[n.length===0&&e.jsx("option",{value:"",children:r("loading")}),n.map(p=>e.jsxs("option",{value:p.id,children:[p.name,"(",p.id,")",p.configured?` · ${r("configured")}`:""]},p.id))]}),(P==null?void 0:P.configured)&&e.jsx("div",{className:"field-hint",children:r("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("apiKey")}),e.jsx("input",{type:"password",value:f,onChange:p=>h(p.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!f.trim()||k||!u,onClick:D,children:r(k?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:S,children:[e.jsx(Tt,{})," ",r("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:r(a?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]})})}const li=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],Pt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),ci=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[Pt()]});function ps(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:[Pt()]).map(s=>{var n;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(n=s.input)!=null&&n.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function di({send:t,providers:s,providerStatus:n,fetchModelsResult:o,refreshProviderResult:c,cloneProviderResult:r,onClose:a}){const l=he(),[u,m]=i.useState(null),[f,h]=i.useState({}),[k,N]=i.useState(null),[M,D]=i.useState({}),[S,P]=i.useState(!1),[$,p]=i.useState(0),[C,T]=i.useState(null),v=i.useRef(0),[w,d]=i.useState({});i.useRef(0);const R=i.useRef(0),[F,z]=i.useState(null),W=i.useRef(0),G=i.useRef(0);i.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const V=()=>{if(!u)return;const j=u.baseUrl.trim();if(!j){T({ok:!1,text:l("fetchModelsNeedBaseUrl")});return}if(S)return;P(!0),T(null);const x=$+1;p(x),t({type:"fetch_models",reqId:x,baseUrl:j,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};i.useEffect(()=>{var j;if(!(!o||o.reqId===v.current))if(v.current=o.reqId,P(!1),o.ok&&((j=o.models)!=null&&j.length)){const x=o.models;m(B=>{if(!B)return B;const te=B.models.map(X=>{var U;if(!X.id.trim())return X;const ge=x.find(J=>J.id===X.id.trim());if(!ge)return X;const g={...X};return!g.name&&ge.name&&(g.name=ge.name),!g.contextWindow&&ge.contextWindow&&(g.contextWindow=String(ge.contextWindow)),!g.maxTokens&&ge.maxTokens&&(g.maxTokens=String(ge.maxTokens)),g.input==="text"&&((U=ge.input)!=null&&U.includes("image"))&&(g.input="text-image"),!g.reasoning&&ge.reasoning&&(g.reasoning=!0),g}),ue=new Set(te.map(X=>X.id.trim()).filter(Boolean)),fe=x.filter(X=>!ue.has(X.id)).map(X=>{var ge;return{id:X.id,name:X.name??"",reasoning:X.reasoning??!1,input:(ge=X.input)!=null&&ge.includes("image")?"text-image":"text",contextWindow:X.contextWindow?String(X.contextWindow):"",maxTokens:X.maxTokens?String(X.maxTokens):""}}),me=[...te,...fe];return me.some(X=>X.id.trim())?{...B,models:me.filter(X=>X.id.trim())}:B}),T({ok:!0,text:l("fetchModelsOk",{n:x.length})})}else T({ok:!1,text:o.error||l("fetchModelsEmpty")})},[o]);const L=j=>{const x=(f[j.id]??"").trim();!x||k||(N(j.id),t({type:"set_provider_api_key",provider:j.id,apiKey:x}),setTimeout(()=>{N(null),h(B=>({...B,[j.id]:""})),D(B=>({...B,[j.id]:!1})),t({type:"list_providers"})},1500))},H=()=>{if(!u)return;const j=u.providerId.trim(),x=u.models.filter(te=>te.id.trim()).map(te=>({id:te.id.trim(),name:te.name.trim()||void 0,reasoning:te.reasoning||void 0,input:te.input==="text-image"?["text","image"]:void 0,contextWindow:te.contextWindow?Number(te.contextWindow):void 0,maxTokens:te.maxTokens?Number(te.maxTokens):void 0})),B={providerId:j,name:u.name.trim()||void 0,api:u.api.trim()||void 0,baseUrl:u.baseUrl.trim()||void 0,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader||void 0,models:x};t({type:"save_model_config",providerId:j,config:B}),a()};i.useEffect(()=>{!c||c.reqId===R.current||(R.current=c.reqId,d({}))},[c]);const A=j=>{if(F)return;z(j.id);const x=++W.current+Date.now();t({type:"clone_provider",provider:j.id,reqId:x})};i.useEffect(()=>{!r||r.reqId===G.current||(G.current=r.reqId,z(null),r.ok&&r.config&&m(ps({...r.config,apiKey:""})))},[r]);const oe=j=>{window.confirm(l("clearKeyConfirm",{id:j}))&&t({type:"clear_provider_api_key",provider:j})},ae=j=>{window.confirm(l("deleteProviderConfirm",{id:j.providerId,n:j.models.length}))&&t({type:"delete_model_config",providerId:j.providerId})},I=(j,x)=>{u&&m({...u,models:u.models.map((B,te)=>te===j?{...B,...x}:B)})};return e.jsx("div",{className:"modal-backdrop",onClick:a,children:e.jsxs("div",{className:"modal model-modal",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":l("close"),onClick:a,children:e.jsx(Te,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:l(u?"editProvider":"manageModelsTitle")})}),u?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:[l("providerId")," ",e.jsx("em",{children:l("providerIdHint")})]}),e.jsx("input",{type:"text",value:u.providerId,disabled:s.some(j=>j.providerId===u.providerId),onChange:j=>m({...u,providerId:j.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("displayName")}),e.jsx("input",{type:"text",value:u.name,onChange:j=>m({...u,name:j.target.value}),placeholder:l("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("apiType")}),e.jsx("select",{value:u.api,onChange:j=>m({...u,api:j.target.value}),children:li.map(j=>e.jsx("option",{value:j,children:j},j))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:l("baseUrlHint")})]}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:j=>m({...u,baseUrl:j.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:l("apiKey")}),e.jsx("input",{type:"password",value:u.apiKey,onChange:j=>m({...u,apiKey:j.target.value}),placeholder:l("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:j=>m({...u,authHeader:j.target.checked})}),e.jsx("span",{children:l("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:l("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[C&&e.jsx("span",{className:`fetch-msg ${C.ok?"ok":"err"}`,title:C.text,children:C.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:S||!u.baseUrl.trim(),title:l("fetchModelsHint"),onClick:V,children:[e.jsx(Et,{})," ",l(S?"fetchingModels":"fetchModels")]})]})]}),u.models.map((j,x)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:j.id,onChange:B=>I(x,{id:B.target.value}),placeholder:l("modelIdReq")}),e.jsx("input",{type:"text",value:j.name,onChange:B=>I(x,{name:B.target.value}),placeholder:l("displayName")}),e.jsxs("select",{value:j.input,onChange:B=>I(x,{input:B.target.value}),children:[e.jsx("option",{value:"text",children:l("text")}),e.jsx("option",{value:"text-image",children:l("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:j.reasoning,onChange:B=>I(x,{reasoning:B.target.checked})}),e.jsx("span",{children:l("reasoning")})]}),e.jsx("input",{type:"number",value:j.contextWindow,onChange:B=>I(x,{contextWindow:B.target.value}),placeholder:l("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:j.maxTokens,onChange:B=>I(x,{maxTokens:B.target.value}),placeholder:l("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:l("removeModel"),onClick:()=>m({...u,models:u.models.filter((B,te)=>te!==x)}),children:e.jsx(He,{})})]},x)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>m({...u,models:[...u.models,Pt()]}),children:[e.jsx(We,{})," ",l("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>m(null),children:l("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(j=>j.id.trim()),onClick:H,children:l("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[l("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:l("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.map(j=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:j.name}),e.jsxs("span",{className:"provider-sub",children:[j.id,j.configured&&e.jsx("span",{className:"auth-badge",children:l("configuredBadge")}),j.source&&!j.configured&&e.jsx("span",{className:"auth-badge dim",children:j.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[j.configured&&!M[j.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:l("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:l("replaceKeyTitle"),onClick:()=>D(x=>({...x,[j.id]:!0})),children:[e.jsx(Gt,{})," ",l("replaceKey")]}),j.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:l("clearKeyTitle"),onClick:()=>oe(j.id),children:[e.jsx(He,{})," ",l("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:l("pasteKey"),value:f[j.id]??"",onChange:x=>h(B=>({...B,[j.id]:x.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(f[j.id]??"").trim()||k===j.id,onClick:()=>L(j),children:[e.jsx(Sn,{})," ",k===j.id?l("savingKey"):l("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:F!==null,title:l("cloneProviderTitle"),onClick:()=>A(j),children:[e.jsx(Mt,{})," ",F===j.id?l("cloning"):l("cloneProvider")]})]})]},j.id))]}),e.jsx("div",{className:"form-section-title",children:l("customProviders")}),e.jsx("p",{className:"modal-desc",children:l("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:l("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(j=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:j.providerId}),e.jsxs("span",{className:"provider-sub",children:[j.api??"—",j.baseUrl?` · ${j.baseUrl}`:"",j.models.length>0&&` · ${l("modelsCount",{n:j.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:l("edit"),onClick:()=>m(ps(j)),children:e.jsx(Gt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:l("delete"),onClick:()=>ae(j),children:e.jsx(He,{})})]})]},j.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>m(ci()),children:[e.jsx(We,{})," ",l("addProvider")]})})]})]})})}function Ct({text:t}){const s=i.useRef(null),[n,o]=i.useState(!1),c=()=>{var a;const r=(a=s.current)==null?void 0:a.getBoundingClientRect();r&&o(window.innerWidth-r.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${n?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Ie({title:t,subtitle:s,tip:n,enabled:o,onToggle:c,action:r}){const a=he();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,n&&e.jsx(Ct,{text:n})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),r,e.jsx("button",{type:"button",className:`set-switch ${o?"on":""}`,role:"switch","aria-checked":o,title:a(o?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function ui({chat:t,send:s,terminal:n,onSwitchToTerminal:o,onClose:c}){const r=he(),a=t.settings,[l,u]=i.useState(""),[m,f]=i.useState("append"),h=i.useRef(!1),[k,N]=i.useState(""),[M,D]=i.useState("append"),S=i.useRef(!1),[P,$]=i.useState(""),p=i.useRef(!1),[C,T]=i.useState(""),[v,w]=i.useState(!1),[d,R]=i.useState(null);i.useEffect(()=>{a&&(f(a.promptMode),!h.current&&(u(m==="append"||a.customSystemPrompt?a.customSystemPrompt:a.defaultSystemPrompt||""),D(a.visionBridgePromptMode),!S.current&&(N(M==="append"||a.visionBridgePrompt?a.visionBridgePrompt:a.visionBridgeDefaultPrompt||""),p.current||$(a.reviewPrompt))))},[a,m,M]);const[F,z]=i.useState(String((a==null?void 0:a.terminalBashIdleMs)??15e3));if(i.useEffect(()=>{z(String((a==null?void 0:a.terminalBashIdleMs)??15e3))},[a==null?void 0:a.terminalBashIdleMs]),!a)return null;const W=new Set(a.disabledSkills),G=new Set(a.disabledExtensions),V=x=>s({type:"set_settings",...x}),L=x=>{const B=new Set(W);B.has(x.name)?B.delete(x.name):B.add(x.name),V({disabledSkills:[...B]})},H=new Set(a.disabledPlugins??[]),A=x=>{const B=new Set(H);B.has(x.id)?B.delete(x.id):B.add(x.id),V({disabledPlugins:[...B]})},oe=x=>{const B=new Set(G);B.has(x.id)?B.delete(x.id):B.add(x.id),V({disabledExtensions:[...B]})},ae=x=>{var fe,me;R(null);const B=`${r("uninstallTitle")} ${x}`,te={name:B,command:`pi remove npm:${x}`,cwd:"${pwd}"},ue=t.terminals.find(X=>X.title===B);ue?(n.restart(ue.id),s({type:"run_command",terminalId:ue.id,conversationId:ue.conversationId,command:te,cols:80,rows:24})):n.create({id:Be(),conversationId:t.activeConversationId||((fe=t.state)==null?void 0:fe.conversationId)||"",title:B,cwd:((me=t.state)==null?void 0:me.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:te}),o(),c()},I=x=>{const B=new Set(a.reviewSkills.filter(te=>!te.enabled).map(te=>te.name));B.has(x.name)?B.delete(x.name):B.add(x.name),V({reviewDisabledSkills:[...B]})},j=()=>{const x=m==="replace"&&a.defaultSystemPrompt&&l===a.defaultSystemPrompt?"":l;V({promptMode:m,customSystemPrompt:x})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:c,children:e.jsx(Te,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(st,{className:"modal-head-icon"}),e.jsx("h2",{children:r("settingsTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("settingsDesc")}),e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(vt,{className:"set-section-icon"}),r("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:m,onChange:x=>{const B=x.target.value;f(B),V({promptMode:B})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]}),e.jsx(Ct,{text:r(m==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:r("promptPlaceholder"),value:l,onFocus:()=>h.current=!0,onBlur:()=>{h.current=!1,j()},onChange:x=>u(x.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":v,onClick:()=>w(x=>!x),children:[r("settingsViewPrompt")," ",v?"▴":"▾"]}),v&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:r("settingsViewPromptHint")}),e.jsx(Bs,{text:a.effectiveSystemPrompt})]}),a.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:a.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:r("settingsViewPromptEmpty")})]})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ge,{className:"set-section-icon"}),r("settingsTerminalTools")]}),e.jsx(Ie,{title:r("terminalToolsEnabled"),tip:r("settingsTerminalToolsDesc"),enabled:a.terminalToolsEnabled,onToggle:()=>V({terminalToolsEnabled:!a.terminalToolsEnabled})}),!a.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:r("terminalToolsOffHint")}),e.jsx(Ie,{title:r("terminalBashTakeover"),tip:r("terminalBashTakeoverDesc"),enabled:a.terminalBash,onToggle:()=>V({terminalBash:!a.terminalBash})}),a.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:r("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:F,onChange:x=>z(x.target.value),onBlur:()=>{const x=Math.max(0,Math.floor(Number(F)||0));z(String(x)),x!==a.terminalBashIdleMs&&V({terminalBashIdleMs:x})}})]})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(rt,{className:"set-section-icon"}),r("settingsSkills"),e.jsx("span",{className:"set-count",children:a.skills.length})]}),a.skills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:a.skills.map(x=>e.jsx(Ie,{title:x.name,subtitle:x.description,enabled:x.enabled,onToggle:()=>L(x)},x.name))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(yn,{className:"set-section-icon"}),r("settingsExtensions"),e.jsx("span",{className:"set-count",children:a.extensions.length})]}),a.extensions.length===0?e.jsx("p",{className:"set-empty",children:r("noExtensions")}):e.jsx("div",{className:"set-list",children:a.extensions.map(x=>{const B=x.id.startsWith("npm:")?x.id.slice(4):null;return e.jsx(Ie,{title:x.name,subtitle:x.path,enabled:x.enabled,onToggle:()=>oe(x),action:B?d===x.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:r("uninstallConfirmHint"),onClick:()=>ae(B),children:r("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:r("uninstallHint"),onClick:()=>R(x.id),children:[e.jsx(He,{}),r("uninstallExt")]}):void 0},x.id)})})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ss,{className:"set-section-icon"}),r("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:r("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(x=>e.jsx(Ie,{title:`${x.icon?`${x.icon} `:""}${x.name}`,subtitle:x.error?`${x.id} · ${x.error}`:x.description??x.id,enabled:!H.has(x.id)&&!x.error,onToggle:()=>!x.error&&A(x)},x.id))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(vt,{className:"set-section-icon"}),r("settingsReview"),e.jsx(Ct,{text:r("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:a.reviewSkills.length})]}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:r("reviewPromptPlaceholder"),value:P,onFocus:()=>p.current=!0,onBlur:()=>{p.current=!1,V({reviewPrompt:P})},onChange:x=>$(x.target.value)}),e.jsx("div",{className:"set-field-label",children:r("settingsReviewSkills")}),a.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:a.reviewSkills.map(x=>e.jsx(Ie,{title:x.name,subtitle:x.description,enabled:x.enabled,onToggle:()=>I(x)},`review-${x.name}`))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Cs,{className:"set-section-icon"}),r("settingsVisionBridge")]}),e.jsx(Ie,{title:r("visionBridgeEnabled"),tip:r("settingsVisionBridgeDesc"),enabled:a.visionBridgeEnabled,onToggle:()=>V({visionBridgeEnabled:!a.visionBridgeEnabled})}),!a.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r("visionBridgeOffHint")}),a.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:a.visionBridgeModel??"",onChange:x=>V({visionBridgeModel:x.target.value||null}),children:[e.jsx("option",{value:"",children:r("visionBridgeAuto")}),a.visionModels.map(x=>e.jsx("option",{value:`${x.provider}/${x.id}`,children:x.label},`${x.provider}/${x.id}`))]})]}),a.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:M,onChange:x=>{const B=x.target.value;D(B),V({visionBridgePromptMode:B})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),a.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:r("visionBridgePromptPlaceholder"),value:k,onFocus:()=>S.current=!0,onBlur:()=>{S.current=!1;const x=M==="replace"&&a.visionBridgeDefaultPrompt&&k===a.visionBridgeDefaultPrompt?"":k;V({visionBridgePromptMode:M,visionBridgePrompt:x})},onChange:x=>N(x.target.value)}),a.visionBridgeEnabled&&(a.visionModels.length===0?e.jsx("p",{className:"set-hint",children:r("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:r("visionBridgeCurrent",{model:a.visionBridgeModel??r("visionBridgeAuto")})}))]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(st,{className:"set-section-icon"}),r("settingsPresets"),e.jsx("span",{className:"set-count",children:a.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:r("presetNamePlaceholder"),value:C,onChange:x=>T(x.target.value),onKeyDown:x=>{x.key==="Enter"&&C.trim()&&(s({type:"save_preset",name:C.trim()}),T(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!C.trim(),onClick:()=>{s({type:"save_preset",name:C.trim()}),T("")},children:[e.jsx(We,{})," ",r("saveAsPreset")]})]}),a.presets.length===0?e.jsx("p",{className:"set-empty",children:r("noPresets")}):e.jsx("div",{className:"set-list",children:a.presets.map(x=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:x.name}),e.jsxs("div",{className:"set-row-desc",children:[x.promptMode==="replace"?r("promptModeReplace"):r("promptModeAppend"),x.disabledSkills.length>0&&` · ${r("settingsSkills")} ${x.disabledSkills.length}`,x.disabledExtensions.length>0&&` · ${r("settingsExtensions")} ${x.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:x.name}),children:r("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:r("deletePreset"),onClick:()=>s({type:"delete_preset",name:x.name}),children:e.jsx(He,{})})]})]},x.name))})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:r("close")})})]})})}function mi(t,s){const n=Math.max(0,Date.now()-t),o=Math.floor(n/6e4);if(o<1)return s("bgTaskJustNow");if(o<60)return s("bgTaskMinutes",{n:o});const c=Math.floor(o/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function pi({servers:t,send:s,onClose:n}){const o=he(),[c,r]=i.useState(new Set),a=l=>r(u=>{const m=new Set(u);return m.has(l)?m.delete(l):m.add(l),m});return i.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"bg-task-modal",onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(it,{})," ",o("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:o("close"),onClick:n,children:e.jsx(Te,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(it,{}),e.jsx("span",{children:o("bgTasksEmpty")}),e.jsx("small",{children:o("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(l=>e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:o("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[e.jsxs("span",{className:"bg-task-port",children:[":",l.port]}),l.name&&e.jsx("span",{className:"bg-task-name",children:l.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[e.jsxs("span",{children:[o("bgTaskPid")," ",l.pid]}),e.jsxs("span",{children:[o("bgTaskSince")," ",mi(l.since,o)]})]}),l.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(l.port)?"open":""}`,title:`${o("bgTaskCommand")}: ${l.command}`,onClick:()=>a(l.port),children:[e.jsx(Ge,{}),e.jsx("code",{children:l.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:o("bgTaskStop"),onClick:()=>s({type:"kill_background_server",port:l.port}),children:[e.jsx(tt,{}),e.jsx("span",{children:o("bgTaskStop")})]})]},l.port))}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:o("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(Tt,{}),e.jsx("span",{children:o("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:o("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(tt,{}),e.jsx("span",{children:o("bgTaskStopAll")})]})]})]})})}function Qe(t,s){return t.toLowerCase().includes(s)}function hi({send:t,sessions:s,projects:n,cwd:o,fileSearch:c,onClose:r,onSwitchSession:a,onSwitchProject:l,onPreviewFile:u}){const m=he(),f=i.useRef(null),[h,k]=i.useState(""),N=i.useDeferredValue(h),[M,D]=i.useState(0),S=i.useRef(1),P=i.useRef(0),$=i.useRef(null);i.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var L;return(L=f.current)==null?void 0:L.focus()})},[]);const[p,C]=i.useState(!1);i.useEffect(()=>{$.current&&clearTimeout($.current);const L=N.trim();if(L)return $.current=setTimeout(()=>{const H=++S.current;P.current=H,C(!0),t({type:"search_files",reqId:H,query:L})},300),()=>{$.current&&clearTimeout($.current)}},[N]);const T=N.trim().toLowerCase(),v=i.useMemo(()=>T?s.filter(L=>Qe(L.firstMessage??"",T)||Qe(L.name??"",T)||Qe(L.path.split(/[\\/]/).pop()??"",T)).slice(0,20):[],[s,T]),w=i.useMemo(()=>T?n.filter(L=>Qe(L.path,T)).slice(0,10):[],[n,T]),d=i.useMemo(()=>!T||!c||c.reqId!==P.current||!c.ok?[]:c.results,[c,T]);i.useEffect(()=>{c&&c.reqId===P.current&&P.current!==0&&C(!1)},[c]);const R=!!c&&c.ok&&c.truncated,F=i.useMemo(()=>[...v.map(L=>({kind:"session",path:L.path})),...w.map(L=>({kind:"project",path:L.path})),...d.filter(L=>L.type==="file").map(L=>({kind:"file",path:L.path,name:L.name}))],[v,w,d]);i.useEffect(()=>{D(0)},[N]);const z=i.useCallback(L=>{L&&(L.kind==="session"?a(L.path):L.kind==="project"?l(L.path):u(L.path,L.name),r())},[a,l,u,r]);i.useEffect(()=>{const L=H=>{H.key==="Escape"?(H.preventDefault(),H.stopPropagation(),r()):H.key==="ArrowDown"?(H.preventDefault(),D(A=>Math.min(A+1,F.length-1))):H.key==="ArrowUp"?(H.preventDefault(),D(A=>Math.max(A-1,0))):H.key==="Enter"&&(H.preventDefault(),z(F[M]))};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[F,M,z,r]);const W=v.length+w.length+d.length,G=(L,H,A)=>e.jsxs("div",{className:"gs-section-head",children:[A,e.jsx("span",{children:L}),e.jsx("em",{children:H})]});let V=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:r,children:e.jsxs("div",{className:"gs-modal",onClick:L=>L.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(nt,{}),e.jsx("input",{ref:f,type:"text",value:h,placeholder:m("gsPlaceholder"),onChange:L=>k(L.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:m("close"),onClick:r,children:e.jsx(Te,{})})]}),e.jsxs("div",{className:"gs-results",children:[!T&&e.jsx("div",{className:"gs-empty",children:m("gsHint")}),T&&W===0&&!R&&e.jsx("div",{className:"gs-empty",children:m(p?"gsSearching":"gsNoResults")}),v.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsSessions"),v.length,e.jsx(at,{})),v.map(L=>{V++;const H=V;return e.jsxs("button",{type:"button",className:H===M?"gs-item active":"gs-item",onMouseEnter:()=>D(H),onClick:()=>z({kind:"session",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.name||L.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:L.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:L.firstMessage})]},L.path)})]}),w.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsProjects"),w.length,e.jsx(qe,{})),w.map(L=>{V++;const H=V,A=o&&L.path===o;return e.jsxs("button",{type:"button",className:H===M?"gs-item active":"gs-item",onMouseEnter:()=>D(H),onClick:()=>z({kind:"project",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.path.split(/[\\/]/).pop(),A&&e.jsx("em",{className:"gs-item-meta",children:m("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},L.path)})]}),(d.length>0||T&&R)&&e.jsxs("div",{className:"gs-section",children:[G(m("gsFiles"),d.length,e.jsx(Mn,{})),d.map(L=>{V++;const H=V;return e.jsxs("button",{type:"button",className:H===M?"gs-item active":"gs-item",disabled:L.type==="dir",title:L.type==="dir"?void 0:m("gsOpenPreview"),onMouseEnter:()=>D(H),onClick:()=>{L.type==="file"&&z({kind:"file",path:L.path,name:L.name})},children:[e.jsx("span",{className:"gs-item-title",children:L.name}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},`${L.type}:${L.path}`)}),R&&e.jsx("div",{className:"gs-truncated",children:m("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",m("gsNavigate")]}),e.jsxs("span",{children:["Enter ",m("gsOpen")]}),e.jsxs("span",{children:["Esc ",m("gsCloseHint")]})]})]})})}const ft=5e3;function gi({file:t,content:s,send:n,onAddLines:o,onAttach:c,onClose:r}){const a=he(),[l,u]=i.useState(null),[m,f]=i.useState(!1),[h,k]=i.useState(null),[N,M]=i.useState(!1),[D,S]=i.useState(!1),[P,$]=i.useState(!1),[p,C]=i.useState(""),[T,v]=i.useState(!0),w=i.useRef(!1),[d,R]=i.useState(!0),[F,z]=i.useState(!1),[W,G]=i.useState(100),V=i.useRef(0),L=i.useRef(!1),H=i.useRef(null);i.useEffect(()=>{f(!0),u(null),k(null),$(!1),C(""),v(!0),w.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),i.useEffect(()=>{s&&s.path===t.path&&(u(s),P||C(s.text),f(!1))},[s,P,t.path]),i.useEffect(()=>{const K=ie=>{if(ie.key==="Escape"){me();return}if((ie.ctrlKey||ie.metaKey)&&ie.key.toLowerCase()==="s"&&P){ie.preventDefault(),fe();return}const ee=ie.target,Ne=ee&&(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable);(ie.ctrlKey||ie.metaKey)&&ie.key.toLowerCase()==="a"&&!Ne&&(ie.preventDefault(),j())};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},[r,l,P,p]),i.useEffect(()=>{const K=()=>{L.current=!1,M(!1)};return window.addEventListener("mouseup",K),()=>window.removeEventListener("mouseup",K)},[]);const A=i.useMemo(()=>{if(!l)return[];const K=l.text.split(`
|
|
19
|
+
`);return K.length>0&&K[K.length-1]===""&&K.pop(),K.slice(0,ft)},[l]),oe=(l==null?void 0:l.lines)??0,ae=oe>ft,I=(K,ie)=>{if(ie){const ee=V.current>0?V.current:K;k({start:Math.min(ee,K),end:Math.max(ee,K)})}else V.current=K,k({start:K,end:K})},j=()=>{A.length!==0&&(V.current=1,k({start:1,end:A.length}))},x=()=>{h&&(o(t.path,t.name,h.start,h.end),S(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>S(!1),1400))},B=l!==null&&l.kind==="text"&&!l.binary&&!l.truncated,te=()=>{C((l==null?void 0:l.text)??""),$(!1),w.current&&v(!0)},ue=()=>{if(P){if(p!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges")))return;te();return}!B||!l||(w.current=xt(t.name)&&T,xt(t.name)&&v(!1),k(null),C(l.text),$(!0))},fe=()=>{!P||!l||!B||n({type:"write_file",path:t.path,text:p})&&($(!1),w.current&&v(!0),k(null))},me=()=>{P&&p!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges"))||r()},X=K=>{G(Math.min(200,Math.max(50,K)))},ge=h?h.end-h.start+1:0,g=(l==null?void 0:l.binary)??!1,U=(l==null?void 0:l.truncated)??!1,J=(l==null?void 0:l.kind)??"text",Z=xt(t.name),le=Z&&T&&!P&&J==="text"&&!g,xe=K=>dt(`/api/file?clientId=${encodeURIComponent(Lt())}&path=${encodeURIComponent(K)}`);return e.jsx("div",{className:`fp-overlay ${F?"fullscreen":""}`,onMouseDown:K=>{K.target===K.currentTarget&&me()},children:e.jsxs("div",{className:`fp ${F?"fullscreen":""}`,style:{"--fp-zoom":W/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:[l&&J==="text"&&!g&&a("fileLines",{n:oe}),l&&` · ${fi(l.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[Z&&J==="text"&&!g&&l&&e.jsx("button",{type:"button",className:`fp-attach markdown ${T?"on":""}`,"data-tip":a(T?"showMarkdownSource":"showMarkdownPreview"),disabled:P,onClick:()=>v(K=>!K),children:T?e.jsx(Cs,{}):e.jsx(Ln,{})}),J==="text"&&!g&&l&&e.jsx("button",{type:"button",className:`fp-attach edit ${P?"on":""}`,"data-tip":a(U?"fileEditTruncated":P?"exitEditFile":"editFile"),disabled:!B&&!P,onClick:ue,children:e.jsx(jt,{})}),J==="text"&&!g&&!le&&e.jsx("button",{type:"button",className:`fp-attach wrap ${d?"on":""}`,"data-tip":a(d?"disableWrap":"enableWrap"),onClick:()=>R(K=>!K),children:e.jsx(Rn,{})}),J==="text"&&l&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":a("zoomOut"),disabled:W<=50,onClick:()=>X(W-10),children:e.jsx(pn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:a("resetZoom"),onClick:()=>G(100),children:[W,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":a("zoomIn"),disabled:W>=200,onClick:()=>X(W+10),children:e.jsx(hn,{})})]}),J!=="video"&&J!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":a("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(We,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":a("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(yt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${F?"on":""}`,"data-tip":a(F?"exitFullscreen":"fullscreen"),onClick:()=>z(K=>!K),children:F?e.jsx(bn,{}):e.jsx(wn,{})}),e.jsx("button",{type:"button",className:"fp-close",title:a("close"),onClick:me,children:e.jsx(Te,{})})]})]}),U&&J==="text"&&!g&&e.jsx("div",{className:"fp-notice",children:a("previewTruncated")}),m&&!l&&e.jsx("div",{className:"fp-empty",children:a("loading")}),!m&&J==="none"&&!g&&e.jsx("div",{className:"fp-empty",children:a("previewNotSupported")}),!m&&J==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:xe(t.path),alt:t.name})}),!m&&J==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:xe(t.path),controls:!0,preload:"metadata"})}),!m&&le&&l&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(ut,{text:l.text})})}),!m&&g&&J!=="image"&&J!=="video"&&l&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[a("binaryFile"),l.truncated&&a("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:l.text})]}),!m&&P&&J==="text"&&!g&&l&&e.jsx("textarea",{className:`fp-editor ${d?"":"no-wrap"}`,value:p,onChange:K=>C(K.target.value),wrap:d?"soft":"off",spellCheck:!1,autoFocus:!0}),!m&&!le&&!P&&J==="text"&&!g&&l&&A.length===0&&e.jsx("div",{className:"fp-empty",children:a("emptyFile")}),!m&&!le&&!P&&J==="text"&&!g&&A.length>0&&e.jsxs("div",{className:`fp-code ${N?"dragging":""} ${d?"":"no-wrap"}`,onMouseDown:K=>{K.button===0&&K.preventDefault()},children:[A.map((K,ie)=>{const ee=ie+1,Ne=h!==null&&ee>=h.start&&ee<=h.end;return e.jsxs("div",{className:`fp-line ${Ne?"sel":""}`,onMouseDown:Me=>{Me.button===0&&(I(ee,Me.shiftKey),L.current=!0,M(!0))},onMouseEnter:()=>{L.current&&I(ee,!0)},children:[e.jsx("span",{className:"fp-num",children:ee}),e.jsx("span",{className:"fp-code-text",children:K})]},ee)}),ae&&e.jsx("div",{className:"fp-lines-note",children:a("previewLinesTruncated",{n:ft})})]}),e.jsx("div",{className:"fp-foot",children:P?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:a("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:ue,children:a("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:p===((l==null?void 0:l.text)??""),onClick:fe,children:[e.jsx(vn,{})," ",a("saveFile")]})]})]}):!le&&J==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:h?a("selectedRange",{n:ge,start:h.start,end:h.end}):a("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:A.length===0,onClick:j,children:a("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!h,onClick:()=>k(null),children:a("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!h||g,onClick:x,children:[D?e.jsx(ct,{}):null,a(D?"addedToChat":"addToChat")]})]})]})})]})})}function xt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function fi(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Us="pi-web-sounds",Ue={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function zs(){try{const t=localStorage.getItem(Us);if(!t)return{...Ue};const s=JSON.parse(t),n={...Ue,...s};for(const o of["enabled","question","done","start","error"])typeof n[o]!="boolean"&&(n[o]=Ue[o]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=Ue.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...Ue}}}function xi(t){try{localStorage.setItem(Us,JSON.stringify(t))}catch{}}let ze=null;function vi(){try{if(!ze){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;ze=new t}return ze.state==="suspended"&&ze.resume(),ze}catch{return null}}const yi=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],ji=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],bi=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],ki=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],wi={question:yi,done:ji,start:bi,error:ki};function Ni(t,s,n){const o=t.createOscillator(),c=t.createGain();o.type=s.type,o.frequency.value=s.freq;const r=t.currentTime+s.start,a=Math.max(1e-4,s.peak*n);c.gain.setValueAtTime(1e-4,r),c.gain.exponentialRampToValueAtTime(a,r+.012),c.gain.exponentialRampToValueAtTime(1e-4,r+s.dur),o.connect(c),c.connect(t.destination),o.start(r),o.stop(r+s.dur+.05)}function Ke(t,s=zs()){if(!s.enabled||!s[t])return;const n=vi();if(!n)return;const o=Math.max(0,Math.min(1,s.volume/100));for(const c of wi[t])Ni(n,c,o)}const St="pi-web-ui:theme",Ks="dark",hs="theme-stylesheet",gs="pi-web-ui:theme-change";function Vs(){try{const t=localStorage.getItem(St);if(t&&t!==Ks)return t}catch{}return null}function Ci(t){try{t?localStorage.setItem(St,t):localStorage.removeItem(St)}catch{}}function Gs(t){let s=document.getElementById(hs);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(gs));return}s||(s=document.createElement("link"),s.id=hs,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(gs))}async function Si(){try{const t=await fetch(dt("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Ti(){const[t,s]=i.useState([]),[n,o]=i.useState(()=>Vs());return i.useEffect(()=>{let r=!1;return Si().then(a=>{r||s(a)}),()=>{r=!0}},[]),i.useEffect(()=>{Gs(n),Ci(n)},[n]),{themes:t,theme:n,switchTheme:r=>o(r===Ks?null:r)}}function Di(){const t=getComputedStyle(document.documentElement),s=(n,o)=>t.getPropertyValue(n).trim()||o;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 Ei=i.lazy(()=>js(()=>import("./TerminalPanel-__4r1Djg.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function Mi({notice:t,onDismiss:s}){const n=he(),[o,c]=i.useState(!1);i.useEffect(()=>{if(o)return;const a=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(a)},[o,t.id,t.level,s]);const r=t.level==="error"?Dn:t.level==="warning"?Bn:Tn;return e.jsxs("div",{className:`notice notice-${t.level}${o?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(r,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:n("close"),onClick:()=>s(t.id),children:e.jsx(Te,{})})]})}const Ri=[],Js=180,Qs=520,Ys=240,Xs=t=>`pi-web-ui:${t}-panel-width`;function fs(t){const s=Number(localStorage.getItem(Xs(t)));return Number.isFinite(s)&&s>=Js&&s<=Qs?s:Ys}function xs({side:t,width:s,onResize:n}){const o=he(),c=i.useCallback(r=>{r.preventDefault();const a=r.clientX,l=s;let u=l;const m=h=>{const k=t==="left"?h.clientX-a:a-h.clientX;u=Math.min(Qs,Math.max(Js,Math.round(l+k))),n(u)},f=()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",f),document.body.classList.remove("panel-resizing"),localStorage.setItem(Xs(t),String(u))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",f),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:o("dragToResize"),onPointerDown:c,onDoubleClick:()=>n(Ys)})}function Li(){var re,Y,je,pe,be,Ee,Bt,Dt,_t,$t,Ft,At;const t=he(),{chat:s,send:n,dismissNotice:o,pushNotice:c,terminal:r}=ia(),[a,l]=i.useState([]),[u,m]=i.useState(null),[f,h]=i.useState("chat"),k=i.useMemo(()=>s.plugins.filter(E=>{var O,ne;return!((ne=(O=s.settings)==null?void 0:O.disabledPlugins)!=null&&ne.includes(E.id))}),[s.plugins,(re=s.settings)==null?void 0:re.disabledPlugins]),[N,M]=i.useState([]);i.useEffect(()=>Qn(M),[]),i.useEffect(()=>{Yn(k,s.pluginsEpoch)},[k,s.pluginsEpoch]);const[D,S]=i.useState(()=>fs("left")),[P,$]=i.useState(()=>fs("right")),p=i.useCallback(E=>S(E),[]),C=i.useCallback(E=>$(E),[]),[T,v]=i.useState(null),[w,d]=i.useState(()=>window.matchMedia("(max-width: 768px)").matches);i.useEffect(()=>{const E=window.matchMedia("(max-width: 768px)"),O=ne=>d(ne.matches);return E.addEventListener("change",O),()=>E.removeEventListener("change",O)},[]);const[R,F]=i.useState(!1),[z,W]=i.useState(!1),[G,V]=i.useState(!1),[L,H]=i.useState(!1),[A,oe]=i.useState(!1);i.useEffect(()=>{const E=O=>{var Re,Ot;const ne=O.detail,ye=(ne==null?void 0:ne.title)||"插件命令",ke=ne==null?void 0:ne.command;if(!ke||!s.ready)return;const $e={name:ye,command:ke,cwd:"${pwd}"},we=s.terminals.find(mt=>mt.title===ye);if(we)r.restart(we.id),n({type:"run_command",terminalId:we.id,conversationId:we.conversationId,command:$e,cols:80,rows:24});else{const mt=Be();r.create({id:mt,conversationId:s.activeConversationId||((Re=s.state)==null?void 0:Re.conversationId)||"",title:ye,cwd:((Ot=s.state)==null?void 0:Ot.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:$e})}h("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",E),()=>window.removeEventListener("pi-web-ui:plugin-run-command",E)},[s,r,n]),i.useEffect(()=>{const E=O=>{!(O.ctrlKey||O.metaKey)||O.key.toLowerCase()!=="k"||(O.preventDefault(),oe(ne=>!ne))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[]);const[ae,I]=i.useState(zs),{themes:j,theme:x,switchTheme:B}=Ti(),te=i.useRef(null),ue=i.useRef(null),fe=i.useRef(0),me=i.useRef(!1),X=i.useRef(s.terminals);i.useEffect(()=>{xi(ae)},[ae]),i.useEffect(()=>{var O;const E=X.current;X.current=s.terminals;for(const ne of s.terminals){if(!((O=ne.command)!=null&&O.command.startsWith("pi remove ")))continue;const ye=E.find(ke=>ke.id===ne.id);ye!=null&&ye.running&&!ne.running&&n({type:"extensions_reload"})}},[s.terminals,n]),i.useEffect(()=>{var ne;const E=((ne=s.state)==null?void 0:ne.isStreaming)??!1,O=te.current;te.current=E,O!==null&&(!O&&E?Ke("start",ae):O&&!E&&Ke("done",ae))},[(Y=s.state)==null?void 0:Y.isStreaming,ae]),i.useEffect(()=>{var O;const E=((O=s.dialog)==null?void 0:O.id)??null;E!==null&&E!==ue.current&&Ke("question",ae),ue.current=E},[s.dialog,ae]),i.useEffect(()=>{const E=[...s.notices].reverse().find(O=>O.level==="error");E&&E.id!==fe.current&&(fe.current=E.id,Ke("error",ae))},[s.notices,ae]);const ge=(E,O,ne,ye=!1,ke)=>{const $e=`${E}|${ne}|${ke?`${ke.start}-${ke.end}`:""}`;l(we=>we.some(Re=>`${Re.path}|${Re.mode}|${Re.lines?`${Re.lines.start}-${Re.lines.end}`:""}`===$e)?we:[...we,{path:E,name:O,mode:ne,isDir:ye,...ke?{lines:ke}:{}}])},g=E=>l(O=>O.filter(ne=>ne.key?ne.key!==E:ne.path!==E)),U=i.useCallback(E=>(!E.type.startsWith("list_")&&!E.type.startsWith("get_")&&v(null),n(E)),[n]),J=i.useRef(0),Z=i.useRef(0),le=E=>{var ye;const O=Date.now();(ye=s.state)!=null&&ye.model&&!s.state.model.vision&&O-Z.current>1e4&&(Z.current=O,c("warning",t("imageNotSupported")));const ne=`paste-${++J.current}`;l(ke=>[...ke,{path:"",key:ne,name:E.name,mode:"inline",imageData:E.data,mimeType:E.mimeType}])},xe=async E=>{for(const O of E){const ne=await Xa(O);if(!ne){c("error",t("imageLoadFailed",{name:O.name}));continue}le(ne)}},K=20*1024*1024,ie=i.useRef(0),ee=async E=>{if(E.size>K){c("warning",t("fileTooLarge",{name:E.name,size:K/1024/1024}));return}let O;try{O=(await new Promise((ke,$e)=>{const we=new FileReader;we.onload=()=>ke(we.result),we.onerror=()=>$e(we.error??new Error("read failed")),we.readAsDataURL(E)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:E.name}));return}const ne=`upload-${++ie.current}`;l(ye=>[...ye,{path:"",key:ne,name:E.name,mode:"inline",fileData:O,size:E.size,mimeType:E.type||void 0}])},Ne=async E=>{for(const O of E)Xe(O.type)?await xe([O]):await ee(O)},Me=i.useCallback((E,O)=>{n({type:"edit_message",messageId:E,text:O})},[n]),_e=i.useCallback(()=>W(!0),[]),b=i.useCallback(()=>l([]),[]),_=i.useCallback(g,[]),se=i.useCallback(xe,[xe]),Q=i.useCallback(Ne,[Ne]),ce=(je=s.state)==null?void 0:je.model,de=(pe=s.state)==null?void 0:pe.thinkingLevel,ve=(be=s.state)==null?void 0:be.availableThinkingLevels,Se=i.useMemo(()=>ce?{model:ce,thinkingLevel:de??"off",availableThinkingLevels:ve??[]}:null,[ce,de,ve]),y=i.useCallback(()=>{var E,O;return!s.ready||s.terminals.length!==0?!1:(r.create({id:Be(),conversationId:s.activeConversationId||((E=s.state)==null?void 0:E.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((O=s.state)==null?void 0:O.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Ee=s.state)==null?void 0:Ee.cwd,s.terminals.length,t,r]);return i.useEffect(()=>{if(me.current){if(f!=="terminal"||s.terminals.length!==0){me.current=!1;return}y()&&(me.current=!1)}},[s.terminals.length,y,f]),e.jsxs("div",{className:"app",onDragOver:E=>E.preventDefault(),onDrop:E=>E.preventDefault(),children:[e.jsx(Wn,{chat:s,send:n,terminal:r,view:f,plugins:k,onViewChange:E=>{me.current=E==="terminal"&&s.terminals.length===0,me.current&&y()&&(me.current=!1),h(E),v(null)},onOpenPanel:v,onManageModels:()=>W(!0),onOpenSettings:()=>V(!0),onOpenBgTasks:()=>H(!0),onOpenGlobalSearch:()=>oe(!0),sound:ae,onSoundChange:I,onSoundPreview:E=>Ke(E,ae),themes:j,theme:x,onThemeChange:B}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(E=>e.jsx(Mi,{notice:E,onDismiss:o},E.id))}),e.jsxs("div",{className:"layout",style:{"--left-w":`${D}px`,"--right-w":`${P}px`},children:[T&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>v(null)}),e.jsxs("div",{className:`view-pane ${f==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${T==="left"?"open":""}`,children:e.jsx(qn,{send:U,active:!w||T==="left",ready:s.ready,status:s.status,cwd:((Bt=s.state)==null?void 0:Bt.cwd)??"",sessionFile:((Dt=s.state)==null?void 0:Dt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!w&&e.jsx(xs,{side:"left",width:D,onResize:p}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ja,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:Me,onKillBash:()=>n({type:"abort_bash"})},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(ei,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(ni,{dialog:s.dialog,send:n}),e.jsx(Za,{send:n,ready:s.ready,streaming:((_t=s.state)==null?void 0:_t.isStreaming)??!1,messages:(($t=s.state)==null?void 0:$t.messages)??Ri,slashCommands:s.slashCommands,modelState:Se,models:s.models,modelsLoading:s.modelsLoading,attachments:a,onRemoveAttachment:_,onAddImageFiles:se,onAddLocalFiles:Q,onNotice:c,onManageModels:_e,onSent:b})]}),!w&&e.jsx(xs,{side:"right",width:P,onResize:C}),e.jsx("div",{className:`panel-drawer drawer-right ${T==="right"?"open":""}`,children:e.jsx(ha,{send:U,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((Ft=s.state)==null?void 0:Ft.cwd)??"",onAttach:(E,O,ne,ye)=>{v(null),ge(E,O,ne,ye)},onPreview:(E,O)=>{v(null),m({path:E,name:O})},onNotice:(E,O)=>c(E,O)})})]}),e.jsx("div",{className:`view-pane ${f==="terminal"?"":"hidden"}`,children:e.jsx(i.Suspense,{fallback:null,children:e.jsx(Ei,{chat:s,send:n,terminal:r})})}),e.jsx("div",{className:`view-pane ${f==="git"?"":"hidden"}`,children:e.jsx(ii,{chat:s,send:n,terminal:r,active:f==="git",onSwitchToTerminal:()=>h("terminal")})}),N.map(E=>{const O=`plugin:${E.info.id}`;return e.jsx("div",{className:`view-pane ${f===O?"":"hidden"}`,children:e.jsx(ri,{entry:E,send:n})},E.info.id)})]}),e.jsx(ti,{chat:s,send:n}),u&&e.jsx(gi,{file:u,content:s.fileContent,send:n,onAddLines:(E,O,ne,ye)=>ge(E,O,"lines",!1,{start:ne,end:ye}),onAttach:(E,O,ne)=>ge(E,O,ne),onClose:()=>m(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!R&&!z&&e.jsx(oi,{send:n,piConfigured:s.state.piConfigured,providers:s.providers,installResult:s.installResult,onClose:()=>F(!0)}),z&&e.jsx(di,{send:n,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>W(!1)}),G&&e.jsx(ui,{chat:s,send:n,terminal:r,onSwitchToTerminal:()=>h("terminal"),onClose:()=>V(!1)}),L&&e.jsx(pi,{servers:s.bgServers,send:n,onClose:()=>H(!1)}),A&&e.jsx(hi,{send:n,sessions:s.sessions,projects:s.projects,cwd:((At=s.state)==null?void 0:At.cwd)??"",fileSearch:s.fileSearch,onClose:()=>oe(!1),onSwitchSession:E=>{n({type:"switch_session",path:E})},onSwitchProject:E=>{n({type:"set_cwd",path:E})},onPreviewFile:(E,O)=>{m({path:E,name:O})}})]})}Un();Gs(Vs());sn.createRoot(document.getElementById("root")).render(e.jsx(i.StrictMode,{children:e.jsx(An,{children:e.jsx(Li,{})})}));export{Tt as F,gs as T,We as a,Di as b,Bi as c,Gt as d,He as e,Te as f,kn as g,Ge as h,Be as r,he as u};
|