pi-web-ui 0.29.2 → 0.30.0

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.
@@ -0,0 +1,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-CMBWruhs.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 Le,a as i,j as e,M as is,b as _s,c as As}from"./markdown-DRBrS2Nf.js";import{r as rs}from"./react-C9ovnpIm.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const c of o)if(c.type==="childList")for(const a of c.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(o){const c={};return o.integrity&&(c.integrity=o.integrity),o.referrerPolicy&&(c.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?c.credentials="include":o.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(o){if(o.ep)return;o.ep=!0;const c=n(o);fetch(o.href,c)}})();var He={},Rt;function $s(){if(Rt)return He;Rt=1;var t=rs();return He.createRoot=t.createRoot,He.hydrateRoot=t.hydrateRoot,He}var Os=$s();const Ws="modulepreload",Hs=function(t){return"/"+t},Lt={},Us=function(s,n,r){let o=Promise.resolve();if(n&&n.length>0){let a=function(u){return Promise.all(u.map(g=>Promise.resolve(g).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),p=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));o=a(n.map(u=>{if(u=Hs(u),u in Lt)return;Lt[u]=!0;const g=u.endsWith(".css"),h=g?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${h}`))return;const k=document.createElement("link");if(k.rel=g?"stylesheet":Ws,g||(k.as="script"),k.crossOrigin="",k.href=u,p&&k.setAttribute("nonce",p),document.head.appendChild(k),g)return new Promise((w,T)=>{k.addEventListener("load",w),k.addEventListener("error",()=>T(new Error(`Unable to preload CSS for ${u}`)))})}))}function c(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return o.then(a=>{for(const l of a||[])l.status==="rejected"&&c(l.reason);return s().catch(c)})};var os={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},It=Le.createContext&&Le.createContext(os),qs=["attr","size","title"];function zs(t,s){if(t==null)return{};var n,r,o=Ks(t,s);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);for(r=0;r<c.length;r++)n=c[r],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function Ks(t,s){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;n[r]=t[r]}return n}function Ge(){return Ge=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Ge.apply(null,arguments)}function Pt(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function Je(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Pt(Object(n),!0).forEach(function(r){Vs(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Pt(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Vs(t,s,n){return(s=Gs(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Gs(t){var s=Js(t,"string");return typeof s=="symbol"?s:s+""}function Js(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function ls(t){return t&&t.map((s,n)=>Le.createElement(s.tag,Je({key:n},s.attr),ls(s.child)))}function W(t){return s=>Le.createElement(Qs,Ge({attr:Je({},t.attr)},s),ls(t.child))}function Qs(t){var s=n=>{var r=t.attr,o=t.size,c=t.title,a=zs(t,qs),l=o||n.size||"1em",p;return n.className&&(p=n.className),t.className&&(p=(p?p+" ":"")+t.className),Le.createElement("svg",Ge({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,a,{className:p,style:Je(Je({color:t.color||n.color},n.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),c&&Le.createElement("title",null,c),t.children)};return It!==void 0?Le.createElement(It.Consumer,null,n=>s(n)):s(os)}function Ys(t){return W({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 Xs(t){return W({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 ht(t){return W({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 W({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 cs(t){return W({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 Zs(t){return W({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 ze(t){return W({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 st(t){return W({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 Bt(t){return W({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 en(t){return W({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 Qe(t){return W({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 Ye(t){return W({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 tn(t){return W({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 Xe(t){return W({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 sn(t){return W({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 jt(t){return W({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 Be(t){return W({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 hi(t){return W({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 Dt(t){return W({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 nn(t){return W({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 an(t){return W({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 rn(t){return W({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"},child:[]}]})(t)}function Ze(t){return W({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 on(t){return W({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 ln(t){return W({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 cn(t){return W({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 dn(t){return W({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 gt(t){return W({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 et(t){return W({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 un(t){return W({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 mn(t){return W({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 pn(t){return W({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 Ft(t){return W({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 Ke(t){return W({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 De(t){return W({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 ds(t){return W({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 hn(t){return W({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 us(t){return W({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"},child:[]},{tag:"circle",attr:{cx:"12",cy:"12",r:"3"},child:[]}]})(t)}function ft(t){return W({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 _t(t){return W({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 bt(t){return W({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 nt(t){return W({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 gn(t){return W({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 ms(t){return W({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 fn(t){return W({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 at(t){return W({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 it(t){return W({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 W({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 kt(t){return W({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 xn(t){return W({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 vn(t){return W({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 ps(t){return W({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 hs(t){return W({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 yn(t){return W({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 jn(t){return W({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 Re({trigger:t,open:s,onOpenChange:n,children:r,align:o="right",fit:c=!1,direction:a="down",menuClassName:l}){const p=i.useRef(null);return i.useEffect(()=>{if(!s)return;const u=h=>{p.current&&!p.current.contains(h.target)&&n(!1)},g=h=>{h.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",g)}},[s,n]),e.jsxs("div",{className:`dropdown ${o} ${c?"fit":""} ${a==="up"?"dd-up":""}`,ref:p,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:r})]})}function ke({active:t,disabled:s=!1,title:n,onClick:r,children:o}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:r,children:o})}const gs="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:"不支持直接拖入文件夹,请展开后选择文件",followUpQueued:"⏳ {n} 条跟进消息排队中",steeringQueued:"⏳ {n} 条转向消息排队中",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:"等当前回复全部生成完后再发送(不打断)",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)中的对话",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:"立即更新",confirmUpdate:"确认更新(覆盖全局安装)",updateSuccess:"✅ 已更新,正在重启…",updateFailed:"更新失败:{detail}",restartHint:"重启: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} 已保存的密钥?其模型将从列表消失,直到重新配置。",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:"输入自定义系统提示词…(失焦后自动应用)",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",settingsExtensions:"插件",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},kn={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",followUpQueued:"⏳ {n} follow-up message(s) queued",steeringQueued:"⏳ {n} steering message(s) queued",placeholderStreaming:"The agent is working… (messages will queue)",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:"Follow-up",supplementTip:"Send after the current reply has fully finished (no interruption)",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)",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 now",confirmUpdate:"Confirm (replaces global install)",updateSuccess:"✅ Updated — restarting…",updateFailed:"Update failed: {detail}",restartHint:"Restart: 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.",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)",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",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.",settingsExtensions:"Extensions",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…"},fs=i.createContext(null);function Nn(){try{const t=localStorage.getItem(gs);if(t==="zh"||t==="en")return t}catch{}return"zh"}function wn({children:t}){const[s,n]=i.useState(Nn),r=i.useCallback(a=>{n(a);try{localStorage.setItem(gs,a)}catch{}},[]),o=i.useCallback((a,l)=>{let p=kn[a];if(s==="zh"&&(p=bn[a]),l)for(const[u,g]of Object.entries(l))p=p.replaceAll(`{${u}}`,String(g));return p},[s]);i.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const c=i.useMemo(()=>({locale:s,setLocale:r,t:o}),[s,r,o]);return e.jsx(fs.Provider,{value:c,children:t})}function Nt(){const t=i.useContext(fs);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function oe(){return Nt().t}const Cn=["off","minimal","low","medium","high","xhigh","max"],xs=i.memo(function({state:s,models:n,modelsLoading:r,send:o,onManageModels:c,compact:a=!1}){const l=oe(),p=s==null?void 0:s.model,u=p?`${p.provider}/${p.id}`:null,[g,h]=i.useState(!1),[k,w]=i.useState(!1),[T,P]=i.useState("");i.useEffect(()=>{g||P("")},[g]);const M=i.useMemo(()=>{const v=T.trim().toLowerCase();return v?n.filter(N=>N.name.toLowerCase().includes(v)||N.provider.toLowerCase().includes(v)||N.id.toLowerCase().includes(v)):n},[n,T]),[x,S]=i.useState(!1),C=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,D=Cn.map(v=>({value:v,label:l(`thinking.${v}`),supported:C?C.has(v):!0})),_=v=>{var N;return((N=D.find(d=>d.value===v))==null?void 0:N.label)??v};return i.useEffect(()=>{g&&n.length===0&&!x&&!r&&(S(!0),o({type:"list_models"}))},[g,n.length,x,r,o]),i.useEffect(()=>{n.length>0&&S(!1)},[n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(nt,{}),e.jsx("span",{className:"chip-model",children:p?p.name:l("selectModel")}),!a&&(p==null?void 0:p.vision)&&e.jsx("span",{className:"chip-vision",title:l("vision"),children:"🖼"}),!a&&p&&e.jsx("span",{className:"chip-sub",children:p.provider})]}),open:g,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(Xe,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:l("searchModels"),value:T,onChange:v=>P(v.target.value)})]}),e.jsxs("div",{className:"dd-model-scroll",children:[(x||r)&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.length===0&&!x&&!r&&e.jsx("div",{className:"dd-loading",children:l("noModels")}),M.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:l("noModelMatches")}),M.map(v=>e.jsx(ke,{active:u===v.id,onClick:()=>{u!==v.id&&o({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:()=>o({type:"list_models"}),children:l("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{h(!1),c()},children:l("manageModels")})]})]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ht,{}),e.jsx("span",{className:"chip-sub",children:l("thinkingChip",{level:s?_(s.thinkingLevel):"—"})})]}),open:k,onOpenChange:w,children:[e.jsx("div",{className:"dd-header",children:l("thinkingLevel")}),D.map(v=>e.jsx(ke,{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&&o({type:"set_thinking",level:v.value}),w(!1)},children:v.label},v.value))]})]})}),Sn=[{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 At({settings:t,onChange:s,onPreview:n}){const r=oe(),o=c=>s({...t,...c});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:r("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(cs,{className:"sound-icon"}),e.jsx("span",{children:r("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:c=>o({enabled:c.target.checked})})]}),Sn.map(({kind:c,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:r(a)}),e.jsx("span",{className:"sound-desc",children:r(l)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:r("preview"),disabled:!t.enabled,onClick:p=>{p.preventDefault(),n(c)},children:r("preview")}),e.jsx("input",{type:"checkbox",checked:t[c],disabled:!t.enabled,onChange:p=>o({[c]:p.target.checked})})]})]},c)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:r("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:c=>o({volume:Number(c.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function Tn({chat:t,send:s,view:n,onViewChange:r,onOpenPanel:o,onManageModels:c,onOpenSettings:a,onOpenBgTasks:l,onOpenGlobalSearch:p,sound:u,onSoundChange:g,onSoundPreview:h,themes:k,theme:w,onThemeChange:T}){var H;const{locale:P,setLocale:M,t:x}=Nt(),[S,C]=i.useState(!1),[D,_]=i.useState(!1),[v,N]=i.useState(!1),[d,L]=i.useState(!1),[$,j]=i.useState(!1),[F,K]=i.useState(!1),Y=[{value:"zh",label:x("langZh")},{value:"en",label:x("langEn")}],m=t.ready?x("connected"):t.status==="closed"?x("reconnecting"):x("connecting"),R=t.ready?"ok":"busy",E=()=>{var U,te,le,Q;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:x("currentVersion")}),e.jsxs("b",{children:["v",((U=t.update)==null?void 0:U.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:x("latestVersion")}),e.jsx("b",{children:t.update===null?x("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:x("checkingUpdate")})]}),((te=t.update)==null?void 0:te.pendingRestart)&&e.jsx("div",{className:"dd-note ok",children:x("updateSuccess")}),t.update&&!t.update.pendingRestart&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:x("upToDate")}),t.update&&!t.update.pendingRestart&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:x("updateAvailable",{version:t.update.latest})}),((le=t.update)==null?void 0:le.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:x("updateJustPublished",{version:t.update.latest??""})}),t.updateResult&&!t.updateResult.ok&&e.jsx("div",{className:"dd-note err",children:x("updateFailed",{detail:t.updateResult.detail})}),((Q=t.update)==null?void 0:Q.pendingRestart)&&e.jsx("div",{className:"dd-note",children:x("restartHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?x("checkingUpdate"):x("checkUpdate")}),t.update&&!t.update.pendingRestart&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:`dd-refresh accent ${F?"armed":""}`,onClick:()=>{if(!F){K(!0);return}K(!1),L(!1),j(!1),s({type:"update_app"})},children:x(F?"confirmUpdate":"updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:x("openHistory"),onClick:()=>o("left"),children:e.jsx(on,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${R}`,title:m}),e.jsx("span",{className:"conn-label",children:m})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":x("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="chat",className:n==="chat"?"active":"",onClick:()=>r("chat"),children:[e.jsx(Ze,{}),e.jsx("span",{children:x("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="terminal",className:n==="terminal"?"active":"",onClick:()=>r("terminal"),children:[e.jsx(st,{}),e.jsx("span",{children:x("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="git",className:n==="git"?"active":"",onClick:()=>r("git"),children:[e.jsx(Ke,{}),e.jsx("span",{children:x("scmTab")})]})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:x("searchGlobalTip"),onClick:p,children:[e.jsx(Xe,{}),e.jsx("span",{className:"chip-sub",children:x("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":x("bgTasksTip"),onClick:l,children:[e.jsx(et,{}),e.jsx("span",{className:"chip-sub",children:x("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(xs,{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:c}),e.jsxs("button",{type:"button",className:"chip",title:x("settingsTitle"),onClick:a,children:[e.jsx(Ye,{}),e.jsx("span",{className:"chip-sub",children:x("settings")})]}),e.jsx(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(cs,{}),e.jsx("span",{className:"chip-sub",children:x("sound")})]}),open:S,onOpenChange:C,children:e.jsx(At,{settings:u,onChange:g,onPreview:h})}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(pn,{}),e.jsx("span",{className:"chip-sub",children:P==="zh"?x("langZh"):"EN"})]}),open:D,onOpenChange:_,children:[e.jsx("div",{className:"dd-header",children:x("language")}),Y.map(U=>e.jsx(ke,{active:P===U.value,onClick:()=>{M(U.value),_(!1)},children:U.label},U.value))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(en,{}),e.jsx("span",{className:"chip-sub",children:x("theme")})]}),open:v,onOpenChange:N,children:[e.jsx("div",{className:"dd-header",children:x("theme")}),e.jsx(ke,{active:w===null,onClick:()=>{T(null),N(!1)},children:x("themeDefault")}),k.map(U=>e.jsx(ke,{active:w===U.id,onClick:()=>{T(U.id),N(!1)},children:U.name},U.id))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(bt,{}),e.jsxs("span",{className:"chip-sub",children:["v",((H=t.update)==null?void 0:H.current)??"…"]}),t.update&&!t.update.upToDate&&!t.update.pendingRestart&&e.jsx("span",{className:"update-dot",title:x("updateAvailable",{version:t.update.latest??""})})]}),open:d,onOpenChange:U=>{L(U),K(!1),U&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:x("update")}),E()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:x("githubRepo"),children:e.jsx(Ft,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":x("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(Be,{}),e.jsx("span",{children:x("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(an,{}),e.jsx("span",{className:"chip-sub",children:x("more")}),t.update&&!t.update.upToDate&&!t.update.pendingRestart&&e.jsx("span",{className:"update-dot"})]}),open:$,onOpenChange:U=>{j(U),K(!1),U&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:x("sound")}),e.jsx("div",{className:"dd-header",children:x("settings")}),e.jsxs(ke,{onClick:()=>{j(!1),a()},children:[e.jsx(Ye,{})," ",x("settingsTitle")]}),e.jsxs(ke,{onClick:()=>{j(!1),p()},children:[e.jsx(Xe,{})," ",x("searchGlobal")]}),e.jsxs(ke,{onClick:()=>{j(!1),l()},children:[e.jsx(et,{})," ",x("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(At,{settings:u,onChange:g,onPreview:h}),e.jsx("div",{className:"dd-header",children:x("language")}),Y.map(U=>e.jsx(ke,{active:P===U.value,onClick:()=>M(U.value),children:U.label},U.value)),e.jsx("div",{className:"dd-header",children:x("theme")}),e.jsx(ke,{active:w===null,onClick:()=>{T(null),j(!1)},children:x("themeDefault")}),k.map(U=>e.jsx(ke,{active:w===U.id,onClick:()=>{T(U.id),j(!1)},children:U.name},U.id)),e.jsx("div",{className:"dd-header",children:x("update")}),E(),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(Ft,{})," ",x("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:x("openFiles"),onClick:()=>o("right"),children:e.jsx(De,{})})]})]})}function $t(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 Mn=i.memo(function({ready:s,status:n,cwd:r,sessionFile:o,conversations:c,sessions:a,projects:l,activeConversationId:p,send:u,active:g}){const h=oe(),k=o,w=r;i.useEffect(()=>{!g||!s||n!=="open"||r&&(u({type:"list_sessions"}),u({type:"list_projects"}))},[g,s,n,r,u]);const T=M=>{const x=M.name||M.firstMessage.trim();return x.length>0?x:h("emptyChat")},P=M=>M.split(/[\\/]/).pop()||M;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(M=>{const x=w===M.path;return e.jsxs("button",{type:"button",className:`project-item ${x?"active":""}`,title:M.path,onClick:()=>{x||u({type:"set_cwd",path:M.path})},children:[e.jsx(De,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:P(M.path)}),e.jsx("span",{className:"project-path",children:M.path})]}),e.jsx("span",{className:"project-time",children:$t(M.lastUsed)})]},M.path)})})]}),c.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:h("runningConversations")}),c.map(M=>{const x=p===M.id;return e.jsxs("button",{type:"button",className:`session-item ${x?"active":""}`,title:M.title,onClick:()=>{x||u({type:"switch_conversation",id:M.id})},children:[e.jsx(Ze,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:M.title}),e.jsx("span",{className:"session-sub",children:x?h("current"):h("messageCount",{n:M.messageCount})})]}),M.isStreaming&&e.jsx("span",{className:"conv-streaming",title:h("streaming")})]},M.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(M=>{const x=k===M.path;return e.jsxs("button",{type:"button",className:`session-item ${x?"active":""}`,title:M.path,onClick:()=>{x||u({type:"switch_session",path:M.path})},children:[e.jsx(Ze,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:T(M)}),e.jsxs("span",{className:"session-sub",children:[x?h("current"):h("messageCount",{n:M.messageCount}),M.source==="tui"&&e.jsx("span",{className:"session-src",title:h("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:$t(M.modified)})]},M.path)})]})]})]})});function tt(){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)}`}const vs="pi-web-ui:token";function En(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(vs,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function Rn(){try{return localStorage.getItem(vs)??""}catch{return""}}function rt(t){const s=Rn();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function Ln(t,s){const n=s.assistantMessageEvent,r=t.stats.tokens,o=s.usage!==null?{...r,...s.usage}:r,c=o===r?t.stats:{...t.stats,tokens:o};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return c===t.stats?t:{...t,stats:c};const a=n.delta??"";if(!a)return c===t.stats?t:{...t,stats:c};const l=t.streamingMessage??null,p=l&&l.id===s.messageId?l:{id:s.messageId,content:[]},u=[...p.content],g=n.type==="thinking_delta"?"thinking":"text",h=n.contentIndex??u.length-1;return h>=0&&h<u.length&&u[h].type===g?u[h]=g==="thinking"?{type:"thinking",thinking:(u[h].thinking??"")+a}:{type:"text",text:(u[h].text??"")+a}:u.push(g==="thinking"?{type:"thinking",thinking:a}:{type:"text",text:a}),{...t,stats:c,streamingMessage:{...p,id:s.messageId,content:u}}}const In=3,ct=2e5,Pn=2e5,Bn={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 Dn(){const t=new Map,s=new Map,n=(r,o)=>`${r}:${o}`;return{write(r,o,c){const a=n(r,o),l=t.get(a);if(l&&l.size>0){for(const g of l)try{g.write(c)}catch{}return}const p=s.get(a)??"",u=p.length+c.length>Pn?c:p+c;s.set(a,u)},register(r,o,c){const a=n(r,o);let l=t.get(a);l||(l=new Set,t.set(a,l)),l.add(c);const p=s.get(a);if(p){try{c.write(p)}catch{}s.delete(a)}return()=>{const u=t.get(a);u&&(u.delete(c),u.size===0&&t.delete(a)),s.delete(a)}},clear(){t.clear(),s.clear()}}}function Ot(t,s){const n=new Set;for(const o of s.messages)o.role==="toolResult"&&o.toolCallId&&n.add(o.toolCallId),o.role==="bashExecution"&&n.add(`bash-${o.id}`);let r=!1;for(const o of t.keys())n.has(o)&&(t.delete(o),r=!0);return r?new Map(t):t}function Wt(t,s){if(t.size===0)return t;const n=new Set;for(const o of s.messages)o.role==="toolResult"&&o.toolCallId&&n.add(o.toolCallId);let r=!1;for(const o of t.keys())n.has(o)&&(t.delete(o),r=!0);return r?new Map(t):t}function Fn(t,s){var n,r,o,c;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!==In};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Ot(t.liveOutputs,s.state),toolStatuses:Wt(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 p={...a,...l.state,messages:l.appended.length>0?[...a.messages,...l.appended]:a.messages};return{...t,ready:!0,state:p,activeConversationId:p.conversationId,liveOutputs:Ot(t.liveOutputs,p),toolStatuses:Wt(t.toolStatuses,p)}}case"tool_delta":{const a=t.liveOutputs.get(s.toolCallId),l=((a==null?void 0:a.text)??"")+s.delta,p=l.length>ct?`…[前 ${l.length-ct} 字符已省略]…
3
+ `+l.slice(l.length-ct):l,u=new Map(t.liveOutputs);return u.set(s.toolCallId,{toolName:s.toolName,text:p}),{...t,liveOutputs:u}}case"message_delta":{const a=t.state;return!a||a.conversationId!==s.msg.conversationId?t:{...t,state:Ln(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"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"update_result":return{...t,updateResult:s.result};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"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||((r=t.state)==null?void 0:r.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||(o=t.state)!=null&&o.conversationId)&&s.conversationId!==(t.activeConversationId||((c=t.state)==null?void 0:c.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 Ht="pi-web-client-id";let dt=null;function wt(){if(dt)return dt;let t=null;try{t=sessionStorage.getItem(Ht),t||(t=tt(),sessionStorage.setItem(Ht,t))}catch{t=t??tt()}return dt=t,t}function _n(){const t=location.protocol==="https:"?"wss:":"ws:";return rt(`${t}//${location.host}/ws`)}function An(){const[t,s]=i.useReducer(Fn,{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,updateResult:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:Bn,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,protocolMismatch:!1}),n=i.useRef(null),r=i.useRef(Dn()),o=i.useRef(0),c=i.useRef(null),a=i.useRef(!0),l=i.useRef(0),p=i.useRef(0),u=i.useRef(new Map),g=i.useRef(null),h=()=>{g.current||(g.current=setTimeout(()=>{g.current=null;const v=n.current;v&&v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:"get_state"}))},300))},k=(v,N)=>{var $;const d=u.current,L=d.get(v);if(L!==void 0&&N!==L+1){const j=_.current.chat,F=j.activeConversationId||(($=j.state)==null?void 0:$.conversationId);v===F&&h()}d.set(v,N)},w=i.useCallback((v,N)=>{const d=++p.current;s({type:"notice",notice:{id:d,level:v,text:N}})},[]),T=i.useCallback(v=>{const N=n.current;return N&&N.readyState===WebSocket.OPEN?(N.send(JSON.stringify(v)),!0):!1},[]),P=i.useCallback(()=>{if(!a.current)return;s({type:"status",status:"connecting"});const v=new WebSocket(_n());n.current=v,v.onopen=()=>{n.current===v&&(s({type:"status",status:"open"}),o.current=0,l.current=Date.now(),v.send(JSON.stringify({type:"hello",clientId:wt()})))},v.onmessage=N=>{if(n.current!==v)return;l.current=Date.now();let d;try{d=JSON.parse(N.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":u.current=new Map,s({type:"snapshot",state:d.state});break;case"snapshot_delta":{const L=_.current.chat.state;(!L||L.conversationId!==d.conversationId||L.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 L=++p.current;s({type:"notice",notice:{id:L,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"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"update_result":s({type:"update_result",result: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":r.current.write(d.conversationId??_.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}},v.onclose=()=>{if(n.current===v&&(n.current=null),r.current.clear(),!a.current||n.current&&n.current!==v)return;s({type:"status",status:"closed"});const N=Math.min(1e3*2**o.current,1e4);o.current+=1,c.current=setTimeout(()=>{c.current=null,P()},N)},v.onerror=()=>{}},[]);i.useEffect(()=>{a.current=!0,P();const v=setInterval(()=>{if(!a.current)return;const N=n.current;N&&N.readyState===WebSocket.OPEN&&Date.now()-l.current>3e4&&N.close()},5e3);return()=>{var N;a.current=!1,clearInterval(v),c.current&&(clearTimeout(c.current),c.current=null),(N=n.current)==null||N.close(),n.current=null}},[P]);const M=i.useCallback(v=>s({type:"dismiss_notice",id:v}),[]),x=i.useCallback(v=>s({type:"terminal_add",meta:v}),[]),S=i.useCallback(v=>s({type:"terminal_remove",id:v}),[]),C=i.useCallback(v=>s({type:"terminal_restart",terminalId:v}),[]),D=i.useCallback((v,N,d)=>r.current.register(v,N,d),[]),_=i.useRef({chat:t,send:T,pushNotice:w,dismissNotice:M,terminal:{create:x,close:S,register:D,restart:C}});return _.current={chat:t,send:T,pushNotice:w,dismissNotice:M,terminal:{create:x,close:S,register:D,restart:C}},_.current}const $n=200*1024*1024,On=/windows/i.test(navigator.userAgent),Wn=/[<>:"/\\|?*\u0000-\u001f]/g,Hn=/[. ]+$/,Un=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function qn(t){const s=t.replace(Wn,"_").replace(Hn,"");return s?Un.test(s)?`_${s}`:s:"_"}function Ut(t,s=!0){const n=new URLSearchParams({clientId:wt(),path:t,...s?{download:"1"}:{}});return rt(`/api/file?${n}`)}async function zn(t,s){const n=On?qn(s):s;try{const r=await fetch(Ut(t));if(!r.ok)return{ok:!1,cancelled:!1,error:await r.text().catch(()=>"")||(r.status===404?"文件不存在":`HTTP ${r.status}`)};if(Number(r.headers.get("content-length")??"0")>$n)return window.location.assign(Ut(t)),{ok:!0};const c=await r.blob();return window.showSaveFilePicker&&window.isSecureContext?Kn(c,n):xt(c,n)}catch(r){return{ok:!1,cancelled:!1,error:r instanceof Error?r.message:String(r)}}}async function Kn(t,s){let n;const r=window.showSaveFilePicker;if(!r)return xt(t,s);try{n=await r({suggestedName:s})}catch(o){return o instanceof DOMException&&o.name==="AbortError"?{ok:!1,cancelled:!0}:xt(t,s)}try{const o=await n.createWritable();return await o.write(t),await o.close(),{ok:!0}}catch(o){return{ok:!1,cancelled:!1,error:o instanceof Error?o.message:String(o)}}}function xt(t,s){const n=URL.createObjectURL(t),r=document.createElement("a");return r.href=n,r.download=s,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const Vn=i.memo(function({files:s,fileChanged:n,widgets:r,cwd:o,send:c,onAttach:a,onPreview:l,onNotice:p}){const u=oe(),[g,h]=i.useState(""),[k,w]=i.useState(null),[T,P]=i.useState(!1),M=1e4,x=i.useRef(0),S=i.useRef(void 0),C=i.useCallback((N,d)=>{const L=++x.current;h(N),d!=null&&d.silent||P(!0),c({type:"list_files",path:N===""?void 0:N})||x.current===L&&P(!1)},[c]);i.useEffect(()=>{s&&s.path===g&&P(!1)},[s,g]),i.useEffect(()=>{if(o!==S.current){S.current=o,C("",{silent:!0});return}const N=setInterval(()=>{document.visibilityState!=="hidden"&&C(g,{silent:!0})},M);return()=>clearInterval(N)},[o,g,C]),i.useEffect(()=>{n&&n.path===g&&C(g,{silent:!0})},[n,g,C]);const D=N=>C(N),_=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&C(s.parent)},v=g.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 ${g===""?"active":""}`,onClick:()=>C(""),children:u("rootDir")}),v.map((N,d)=>{const L=v.slice(0,d+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(it,{}),e.jsx("button",{type:"button",className:`crumb ${L===g?"active":""}`,onClick:()=>C(L),children:N})]},L)})]}),e.jsxs("div",{className:"panel-body",children:[T&&e.jsx("div",{className:"panel-empty",children:u("loading")}),!T&&s&&s.path===g&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:_,children:[e.jsx(De,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(N=>N.type==="dir"?e.jsxs("div",{className:"file-item dir",children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>D(N.path),children:[e.jsx(De,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:N.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":u("linkFolderTip"),onClick:()=>a(N.path,N.name,"reference",!0),children:e.jsx(gt,{})})]},N.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${N.path} — ${u("previewFile")}`,onClick:()=>l(N.path,N.name),children:[e.jsx(ds,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:N.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":u("downloadFile"),onClick:()=>{zn(N.path,N.name).then(d=>{d.ok||d.cancelled||p("error",u("downloadFailed",{error:d.error}))})},children:e.jsx(bt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":u("attachInlineTip"),onClick:()=>a(N.path,N.name,"inline"),children:e.jsx(Be,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":u("referenceTip"),onClick:()=>a(N.path,N.name,"reference"),children:e.jsx(gt,{})})]},N.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:u("filesTruncated")})]}),!T&&!s&&e.jsx("div",{className:"panel-empty",children:u("noFiles")})]}),r.filter(N=>N.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:r.filter(N=>N.lines.length>0).map(N=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:u("widgetExpand"),onClick:()=>w(N.key),children:[e.jsx("span",{children:N.key}),e.jsx(cn,{})]}),e.jsx("pre",{className:"widget-lines",children:N.lines.join(`
4
+ `)})]},N.key))}),k&&(()=>{const N=r.find(d=>d.key===k);return N?e.jsx("div",{className:"modal-backdrop",onClick:()=>w(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:N.key}),e.jsx("button",{type:"button",className:"btn",title:u("close"),onClick:()=>w(null),children:e.jsx(Se,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:N.lines.join(`
5
+ `)})]})}):null})()]})});var qt=rs();const Gn=i.memo(function({text:s}){const n=oe(),[r,o]=i.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:n("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{o(!0),setTimeout(()=>o(!1),1200)})},children:r?e.jsx(kt,{}):e.jsx(ms,{})}):null}),ys=[As],js=[[_s,{detect:!0,ignoreMissing:!0}]];function bs({text:t}){return e.jsx(is,{remarkPlugins:ys,rehypePlugins:js,components:{pre:Jn},children:t})}const ot=i.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(bs,{text:s})})});function Jn({children:t,...s}){return e.jsxs("div",{className:"codeblock",children:[e.jsx(Gn,{text:vt(t)}),e.jsx("pre",{...s,children:t})]})}function vt(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(vt).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return vt(s==null?void 0:s.children)}return""}const Qn=/^\s{0,3}(`{3,}|~{3,})/,Yn=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function ut(t){return t.trim()===""}function zt(t){const s=Qn.exec(t);return s?s[1]:null}function Xn(t){const s=t.split(`
6
+ `),n=[];let r=[],o=null;for(let c=0;c<s.length;c++){const a=s[c];if(o!==null){const p=zt(a);p&&p[0]===o[0]&&p.length>=o.length&&(o=null),r.push(a);continue}const l=zt(a);if(l&&!ut(a)){o=l,r.push(a);continue}if(ut(a)){let p=c;for(;p<s.length&&ut(s[p]);)p++;if(!(p<s.length&&Yn.test(s[p]))&&r.length>0){n.push(r.join(`
7
+ `)),r=[];continue}r.push(a);continue}r.push(a)}return{frozen:n,active:r.join(`
8
+ `),inFence:o!==null}}const Zn=i.memo(function({text:s}){return e.jsx(is,{remarkPlugins:ys,rehypePlugins:js,children:s})}),Kt=200;function ea({text:t,inFence:s}){const[n,r]=i.useState(t),o=i.useRef(0),c=i.useRef(null);return i.useEffect(()=>{if(s)return;const a=Date.now()-o.current,l=()=>{o.current=Date.now(),r(t)};if(a>=Kt){l();return}return c.current=setTimeout(l,Kt-a),()=>{c.current&&clearTimeout(c.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx(bs,{text:n})}const ta=i.memo(function({text:s}){const{frozen:n,active:r,inFence:o}=i.useMemo(()=>Xn(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((c,a)=>e.jsx(Zn,{text:c},a)),r.length>0&&e.jsx(ea,{text:r,inFence:o},n.length)]})});function sa({thinking:t,streaming:s}){const n=oe(),[r,o]=i.useState(s),c=t.split(`
9
+ `)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${r?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>o(a=>!a),children:[r?e.jsx(Ie,{}):e.jsx(it,{}),e.jsx(nt,{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"})]}):r?n("thinking"):n("thinkingPreview",{preview:c})})]}),r&&e.jsx("div",{className:"thinking-body",children:t})]})}const na={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function aa(t){return na[t]??"🛠"}const ia=i.memo(function({block:s,view:n,onKillBash:r}){var D,_,v,N;const o=oe(),[c,a]=i.useState(!0),[l,p]=i.useState(!1),u=!n.result&&n.streaming&&!n.status,g=s.name==="bash"&&u,h=n.result!==void 0,k=!n.result&&!!n.status,w=((D=n.result)==null?void 0:D.isError)??((_=n.status)==null?void 0:_.isError)??!1,T=n.result?n.result.content.map(d=>d.type==="text"?d.text:"").join(""):n.liveOutput??"",P=w?"err":h?"ok":u||k?"run":"idle";let M=o(w?"error":h?"done":u?"running":k?"toolDoneWaitingModel":"toolQueued");const x=k&&((v=n.status)==null?void 0:v.durationMs)!==void 0?oa(n.status.durationMs):"";k&&x&&(M=`${M} · ${x}`);const S=k&&((N=n.status)==null?void 0:N.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",C=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),p(!0),setTimeout(()=>p(!1),1200))};return e.jsxs("div",{className:`toolcall ${P}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:aa(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[M,S&&e.jsx("em",{className:"toolcall-exit",children:S})]}),e.jsx("span",{className:"toolcall-spacer"}),g&&r&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:o("stopBashTip"),onClick:r,children:[e.jsx(Qe,{}),e.jsx("span",{children:o("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:o("copyArgs"),onClick:C,children:l?e.jsx(xn,{}):e.jsx(ms,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>a(d=>!d),children:c?e.jsx(Ie,{}):e.jsx(it,{})})]}),c&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(ra,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),T.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[o(w?"errorOutput":"output"),(u||k)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:T})]}),u&&T.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",o("waitingOutput")]}),k&&T.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",o("waitingModel")]})]})]})});function ra({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(st,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function oa(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),r=Math.round(s%60);return`${n}m ${String(r).padStart(2,"0")}s`}const la=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function Ct(t){var n;const s=t.match(la);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}function We(t){return t.type==="text"&&typeof t.text=="string"?t:null}function ks(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function Ns(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function ws(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function Cs(t){return t.type==="bash"&&typeof t.command=="string"?t:null}const Vt=i.memo(function({message:s,toolResults:n,liveOutputs:r,toolStatuses:o,streaming:c,isLast:a,onEdit:l,onKillBash:p,onCollapse:u,qnIndex:g,qnActive:h,onJump:k}){const w=oe(),[T,P]=i.useState(!1),[M,x]=i.useState("");if(s.role==="toolResult")return null;const S=s.role==="custom"&&s.customType==="file",C=s.content.map(F=>{var K;return((K=We(F))==null?void 0:K.text)??""}).filter(Boolean).join(`
10
+ `),D=s.role==="user"?Ct(C):null,_=D?D.userMessage??`skill:${D.name}`:C.split(`
11
+ `).join(" ").trim(),v=c&&a&&s.content.length===0,N=s.role==="user"&&!c&&!v&&!!l,d=()=>{x(D?`/skill:${D.name}${D.userMessage?` ${D.userMessage}`:""}`:s.content.map(F=>{var K;return((K=We(F))==null?void 0:K.text)??""}).filter(Boolean).join(`
12
+ `)),P(!0)},L=()=>{const F=M.trim();F&&(l==null||l(s.id,F),P(!1))},$=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),j=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${$?" 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"?j?w("goalWizardCard"):$?w("goalBarTitle"):s.customType==="file"?w("attachment"):`${w("plugin")} · ${s.customType??w("unknown")}`:Ss(s.role,w)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:ma(s.timestamp)}),u&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:w("collapseMsg"),onClick:()=>u(s.id),children:[e.jsx(at,{})," ",w("collapseMsg")]}),g!==void 0&&k&&e.jsxs("button",{type:"button",className:`qn-tag ${h?"active":""}`,title:`${g+1}. ${_}`,"aria-label":`${g+1}. ${_}`,onClick:()=>k(s.id),children:[e.jsx("span",{className:"qn-tag-bar"}),e.jsx("span",{className:"qn-tag-idx",children:g+1})]})]}),e.jsx("div",{className:"msg-body",children:T?e.jsxs("div",{className:"msg-editor",children:[e.jsx("textarea",{className:"msg-editor-input",value:M,autoFocus:!0,placeholder:w("editPlaceholder"),rows:Math.max(2,Math.min(10,M.split(`
13
+ `).length+1)),onChange:F=>x(F.target.value),onKeyDown:F=>{F.key==="Enter"&&(F.metaKey||F.ctrlKey)?(F.preventDefault(),L()):F.key==="Escape"&&P(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsx("span",{className:"msg-editor-hint",children:w("editHint")}),e.jsx("button",{type:"button",className:"chip",onClick:()=>P(!1),children:w("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!M.trim(),title:w("reaskFromHere"),onClick:L,children:[e.jsx(ft,{})," ",w("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),S?e.jsx(ca,{message:s}):D?e.jsxs(e.Fragment,{children:[e.jsx(ua,{block:D}),D.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(ot,{text:D.userMessage})}),s.content.map((F,K)=>F.type==="text"?null:e.jsx(Jt,{block:F,toolResults:n,liveOutputs:r,toolStatuses:o,streaming:c,isLast:a,onKillBash:p},`${s.id}-${K}`))]}):s.content.map((F,K)=>e.jsx(Jt,{block:F,toolResults:n,liveOutputs:r,toolStatuses:o,streaming:c,isLast:a,onKillBash:p},`${s.id}-${K}`)),v&&e.jsxs("div",{className:"thinking-wait",children:[w("thinkingWait"),e.jsx("span",{className:"dot"})]}),c&&a&&!v&&e.jsx("span",{className:"stream-cursor"})]})}),N&&!T&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:w("editReaskTip"),onClick:d,children:[e.jsx(ft,{})," ",w("editReask")]})})]})});function ca({message:t}){const s=oe(),[n,r]=i.useState(!1),o=t.details??{},c=o.name??o.path??s("attachment"),a=o.type==="folder",l=o.mode==="reference",p=o.mode==="bridged",u=t.content.filter(w=>w.type==="text").map(w=>w.text).join(`
14
+ `),g=da(u),h=t.content.find(w=>w.type==="image"),k=g.split(`
15
+ `).length;return e.jsxs("div",{className:`attachcard ${l?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>r(w=>!w),children:[e.jsx("span",{className:"attachcard-icon",children:a?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:c}),o.path&&e.jsx("span",{className:"attachcard-path",children:o.path}),e.jsx("span",{className:`attachcard-mode ${o.mode==="lines"?"lines":l?"ref":p?"bridged":"inline"}`,children:l?a?s("folderRefShort"):`${s("refOnlyShort")} · ${Gt(o.size)}`:p?s("bridgedVision"):h?s("image"):o.mode==="lines"?s("inlineLinesRange",{start:o.startLine??1,end:o.endLine??o.lines??1}):s("inlineLines",{n:o.lines??k})}),!l&&(n?e.jsx(Ie,{}):e.jsx(it,{}))]}),!l&&n&&(p?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:c})}),g&&e.jsx("pre",{className:"attachcard-content",children:g})]}):h!=null&&h.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:h.dataUrl,alt:c})}):e.jsx("pre",{className:"attachcard-content",children:g})),l&&e.jsx("div",{className:"attachcard-refnote",children:a?s("folderNotExpanded"):s("fileNotExpanded",{size:Gt(o.size)})})]})}function Gt(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function da(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 ua({block:t}){const s=oe(),[n,r]=i.useState(!1);return e.jsxs("div",{className:`skillcard${n?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>r(o=>!o),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(vn,{})}),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(at,{}):e.jsx(Ie,{}),s(n?"collapseMsg":"expandMsg")]})]}),n&&e.jsx("div",{className:"skillcard-body",children:e.jsx(ot,{text:t.content})})]})}function Jt({block:t,toolResults:s,liveOutputs:n,toolStatuses:r,streaming:o,isLast:c,onKillBash:a}){const l=oe(),p=We(t);if(p){const w=o&&c;return e.jsxs("div",{className:"msg-text",children:[w?e.jsx(ta,{text:p.text}):e.jsx(ot,{text:p.text}),p.truncated&&e.jsx("div",{className:"trunc-note",children:l("truncated")})]})}const u=ks(t);if(u)return e.jsx(sa,{thinking:u.thinking,streaming:o&&c});const g=Ns(t);if(g){const w=s.get(g.id),T=n.get(g.id),P={result:w,liveOutput:T==null?void 0:T.text,streaming:o,status:r.get(g.id)};return e.jsx(ia,{block:g,view:P,onKillBash:a})}const h=ws(t);if(h&&h.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:h.dataUrl,alt:"attachment"})});const k=Cs(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 Ss(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 ma(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}const pa=i.memo(function({message:s,onExpand:n}){const r=oe();let o="";for(const h of s.content){const k=We(h);if(k&&k.text.trim()){const w=Ct(k.text);w?o=`skill:${w.name}`+(w.userMessage?` · ${w.userMessage.replace(/\s+/g," ").trim()}`:""):o=k.text.replace(/\s+/g," ").trim();break}}if(!o&&s.role==="custom"&&s.customType==="file"){const h=s.details??{};o=h.name??h.path??""}o.length>90&&(o=`${o.slice(0,90)}…`);let a=0,l=0,p=0,u=0;for(const h of s.content)ks(h)?a++:Ns(h)?l++:Cs(h)?p++:ws(h)&&u++;const g=[];return a&&g.push(`${r("thinking")} ${a}`),l&&g.push(`${r("toolCalls")} ${l}`),p&&g.push(`${r("bashRuns")} ${p}`),u&&g.push(`${r("images")} ${u}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${r("expandMsg")} · ${o||g.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"?r("attachment"):Ss(s.role,r)}),e.jsxs("span",{className:"msg-collapsed-body",children:[o&&e.jsx("span",{className:"msg-collapsed-preview",children:o}),g.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:g.map((h,k)=>e.jsx("span",{className:"msg-collapsed-chip",children:h},k))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:ha(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(Ie,{})," ",r("expandMsg")]})]})});function ha(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}const ga=i.memo(function({id:s,show:n,height:r,containerRef:o,onMeasured:c,lazyRef:a,children:l}){const p=i.useRef(null),u=i.useRef(null);return i.useLayoutEffect(()=>{const g=u.current;if(u.current=n,!n||g!==!1)return;const h=p.current,k=o.current;if(!h||!k)return;const w=h.offsetHeight;c==null||c(s,w);const T=w-r;if(T!==0){const P=h.parentElement;P&&P.getBoundingClientRect().bottom<=k.getBoundingClientRect().top&&(k.scrollTop+=T)}},[n]),n?e.jsx("div",{ref:a,"data-lazy-id":s,children:e.jsx("div",{ref:p,children:l})}):e.jsx("div",{ref:a,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:r},"aria-hidden":"true"})});function fa(t,s,n,r){const o=[],c=[];let a=0;for(const l of t){if(n.has(l.id))continue;l.top<s.bottom&&l.bottom>s.top?r.has(l.id)&&o.push(l.id):r.has(l.id)||(c.push(l.id),l.bottom<=s.top&&(a+=l.bottom-l.top))}return{show:o,hide:c,shrinkAbove:a}}function xa(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const r of s.show)n.delete(r);for(const r of s.hide)n.add(r);return n}function va(t,s,n){const r=new Set;let o=0;for(let c=t.length-1;c>=0&&!(c<t.length-1&&o>=n);c--){const a=t[c];r.add(a.id),o+=s.get(a.id)??Ts(a.role,a.customType)}return r}function Ts(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 ya(t){if(t.role==="toolResult")return"";const s=[];for(const n of t.content)ja(n,s);return t.errorMessage&&s.push(t.errorMessage),s.join(`
16
+ `)}function ja(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 ba(t,s){const n=s.trim().toLowerCase();if(!n)return 0;const r=t.toLowerCase();let o=0,c=r.indexOf(n);for(;c!==-1;)o++,c=r.indexOf(n,c+n.length);return o}function ka(t,s){const n=s.trim().toLowerCase();if(!n)return[];const r=[];for(const o of t){const c=ya(o);if(!c)continue;const a=ba(c,n);for(let l=0;l<a;l++)r.push({messageId:o.id,occurrence:l})}return r}function Na(t,s){var a;const n=new Map,r=[],o=s.toLowerCase();if(!o)return{byMsg:n,all:r};const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(l){const p=l.parentElement;return!p||p.closest(".search-bar")?NodeFilter.FILTER_REJECT:(l.textContent??"").toLowerCase().includes(o)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let l=c.nextNode();l;l=c.nextNode()){const p=(l.textContent??"").toLowerCase(),u=(a=l.parentElement)==null?void 0:a.closest("[data-msg-id]");if(!u)continue;const g=u.getAttribute("data-msg-id")??"";let h=p.indexOf(o);for(;h!==-1;){const k=document.createRange();k.setStart(l,h),k.setEnd(l,h+o.length),r.push(k);const w=n.get(g);w?w.push(k):n.set(g,[k]),h=p.indexOf(o,h+o.length)}}return{byMsg:n,all:r}}function Pe(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const r=window.Highlight;r&&n.highlights.set(t,new r(...s))}function wa({containerRef:t,messages:s,open:n,onClose:r,onEnsureExpanded:o}){const c=oe(),a=i.useRef(null),[l,p]=i.useState(""),[u,g]=i.useState(0),h=i.useDeferredValue(l),k=n?h.trim():"",w=i.useMemo(()=>n?ka(s,k):[],[s,k,n]),T=i.useRef(w);T.current=w;const P=i.useRef(u);P.current=u,i.useEffect(()=>{n&&(g(0),requestAnimationFrame(()=>{var C;return(C=a.current)==null?void 0:C.select()}))},[n]),i.useEffect(()=>{if(!n)return;const C=D=>{D.key==="Escape"&&(D.preventDefault(),D.stopPropagation(),r())};return window.addEventListener("keydown",C,!0),()=>window.removeEventListener("keydown",C,!0)},[n,r]),i.useEffect(()=>(n||(Pe("msg-search",[]),Pe("msg-search-active",[])),()=>{Pe("msg-search",[]),Pe("msg-search-active",[])}),[n]);const M=i.useCallback(C=>{const D=t.current;if(!D)return;const _=D.querySelector(`[data-msg-id="${C}"]`);_&&(_.classList.remove("msg-flash"),_.offsetWidth,_.classList.add("msg-flash"))},[t]);i.useLayoutEffect(()=>{if(!n||!k)return;const C=t.current;if(!C)return;let D=!1,_=0;return _=requestAnimationFrame(()=>{var j;if(D)return;const{byMsg:v,all:N}=Na(C,k);Pe("msg-search",N);const d=T.current,L=d[Math.min(P.current,d.length-1)];if(!L)return;const $=(j=v.get(L.messageId))==null?void 0:j[L.occurrence];if($){Pe("msg-search-active",[$]);const F=$.startContainer.parentElement??C.querySelector(`[data-msg-id="${L.messageId}"]`);F==null||F.scrollIntoView({block:"center"})}else M(L.messageId)}),()=>{D=!0,cancelAnimationFrame(_)}},[n,k,w,t,M]);const x=i.useCallback(C=>{const D=T.current;if(D.length===0)return;const _=(P.current+C+D.length)%D.length;g(_),o(D[_].messageId)},[o]);if(!n)return null;const S=w.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:a,className:"search-input",type:"text",value:l,placeholder:c("searchPlaceholder"),onChange:C=>{p(C.target.value),g(0)},onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),x(C.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${S===0?"empty":""}`,children:S===0?c("searchNoResults"):`${Math.min(u+1,S)}/${S}`}),e.jsx("button",{type:"button",className:"search-btn",title:c("searchPrev"),disabled:S===0,onClick:()=>x(-1),children:e.jsx(at,{})}),e.jsx("button",{type:"button",className:"search-btn",title:c("searchNext"),disabled:S===0,onClick:()=>x(1),children:e.jsx(Ie,{})}),e.jsx("button",{type:"button",className:"search-btn",title:c("searchClose"),onClick:r,children:e.jsx(Se,{})})]})}const Qt=new Map,Ca=15,Yt=30,Xt=1200,Sa=1600;function Zt(t){return t.content.some(s=>s.type==="toolCall")}const Ta=[{key:"ex.understand",icon:"🔍"},{key:"ex.debug",icon:"🐛"},{key:"ex.test",icon:"🧪"},{key:"ex.review",icon:"🧹"}];function Ma(t){return Ta.map(({key:s,icon:n})=>({icon:n,text:t(s),prompt:t(`${s}.prompt`)}))}function Ea({state:t,liveOutputs:s,toolStatuses:n,onEdit:r,onKillBash:o}){const c=oe(),a=i.useRef(null),[l,p]=i.useState(!0),u=i.useRef(!0),g=i.useRef(0),h=i.useRef(!1),[k,w]=i.useState(()=>new Set),[T,P]=i.useState(!1),M=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,x=i.useMemo(()=>{const y=new Map;for(const B of t.messages)B.role==="toolResult"&&B.toolCallId&&y.set(B.toolCallId,B);return y},[t.messages]),S=M.length>0?M[M.length-1].id:null,C=t.messages.length>Yt?Math.max(0,t.messages.length-Ca):0,[D,_]=i.useState(()=>new Set),[v,N]=i.useState(()=>new Set),d=i.useRef(new Map),L=i.useRef(new Map),$=i.useRef(0),j=i.useRef(D);j.current=D;const F=t.messages.length>Yt&&!T,K=i.useRef(F);K.current=F;const Y=va(t.messages,d.current,Sa),m=i.useRef(Y);m.current=Y;const R=i.useCallback(()=>{const y=a.current;if(!y)return;if(!K.current){_(ie=>ie.size?new Set:ie);return}const B=y.getBoundingClientRect(),J={top:B.top-Xt,bottom:B.bottom+Xt},G=[];for(const[ie,he]of L.current){const we=he.getBoundingClientRect();G.push({id:ie,top:we.top,bottom:we.bottom}),j.current.has(ie)||d.current.set(ie,we.bottom-we.top)}const Z=fa(G,J,m.current,j.current);for(const ie of Z.hide){const he=L.current.get(ie);he&&d.current.set(ie,he.offsetHeight)}_(ie=>xa(ie,Z))},[]),E=i.useCallback(()=>{$.current||($.current=requestAnimationFrame(()=>{$.current=0,R()}))},[R]);i.useLayoutEffect(()=>{R()},[R]);const H=i.useRef(T);i.useLayoutEffect(()=>{H.current&&!T&&R(),H.current=T},[T,R]);const U=i.useCallback((y,B)=>{d.current.set(y,B)},[]),te=i.useCallback(y=>{y&&L.current.set(y.dataset.lazyId??"",y)},[]);i.useEffect(()=>{const y=new Set(t.messages.map(B=>B.id));for(const[B,J]of L.current)y.has(B)||(L.current.delete(B),d.current.delete(B));_(B=>{let J=!1;const G=new Set;for(const Z of B)y.has(Z)?G.add(Z):J=!0;return J?G:B})},[t.messages,k]),i.useEffect(()=>()=>cancelAnimationFrame($.current),[]);const le=i.useMemo(()=>{const y=[];for(const B of t.messages){if(B.role!=="user")continue;const J=B.content.map(ie=>{var he;return((he=We(ie))==null?void 0:he.text)??""}).filter(Boolean).join(" "),G=Ct(J),Z=G?G.userMessage??`skill:${G.name}`:J.trim();Z&&y.push({id:B.id,text:Z})}return y},[t.messages]),Q=i.useMemo(()=>{const y=new Map;return le.forEach((B,J)=>y.set(B.id,J)),y},[le]),[se,ce]=i.useState(-1),pe=i.useRef(-1),xe=i.useRef(le);i.useEffect(()=>{xe.current=le},[le]);const me=i.useCallback(()=>{const y=a.current,B=xe.current;if(!y||B.length===0)return;const J=y.getBoundingClientRect().top,G=140;let Z=-1;for(let ie=0;ie<B.length;ie++){const he=y.querySelector(`[data-msg-id="${B[ie].id}"]`);if(he)if(he.getBoundingClientRect().top<=J+G)Z=ie;else break}Z!==pe.current&&(pe.current=Z,ce(Z))},[]);i.useEffect(()=>{me()},[le,me]);const ge=i.useCallback(y=>{w(B=>B.has(y)?B:new Set(B).add(y))},[]),be=i.useCallback(y=>{const B=t.messages.findIndex(J=>J.id===y);B>=0&&B<C&&!k.has(y)&&qt.flushSync(()=>ge(y))},[t.messages,C,k,ge]);i.useEffect(()=>{const y=B=>{if(!(B.ctrlKey||B.metaKey)||B.key.toLowerCase()!=="f")return;const J=B.target;J&&(J.tagName==="INPUT"||J.tagName==="TEXTAREA"||J.isContentEditable)||(B.preventDefault(),P(!0))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]);const ue=i.useCallback(y=>{w(B=>{if(!B.has(y))return B;const J=new Set(B);return J.delete(y),J})},[]),ve=i.useCallback(y=>{const B=t.messages.findIndex(G=>G.id===y);qt.flushSync(()=>{B>=0&&B<C&&!k.has(y)&&ge(y),N(G=>G.has(y)?G:new Set(G).add(y))});const J=xe.current.findIndex(G=>G.id===y);pe.current=J,ce(J),requestAnimationFrame(()=>{var Z,ie,he;const G=(Z=a.current)==null?void 0:Z.querySelector(`[data-msg-id="${y}"]`);G&&((ie=a.current)==null||ie.querySelectorAll(".msg-flash").forEach(we=>we.classList.remove("msg-flash")),G.scrollIntoView({block:"start"}),G.classList.remove("msg-flash"),G.offsetWidth,G.classList.add("msg-flash"),G!==((he=a.current)==null?void 0:he.lastElementChild)&&(h.current=!0))})},[t.messages,C,k,ge]),ne=i.useCallback(()=>{const y=a.current;if(!y)return;const B=y.scrollTop-g.current;g.current=y.scrollTop;const J=y.scrollHeight-y.scrollTop-y.clientHeight<80;B<-4&&B>-500?h.current=!0:J&&B>=0&&(h.current=!1),u.current=J&&!h.current,p(u.current),me(),E()},[me,E]),f=i.useRef(!1);i.useEffect(()=>{const y=f.current;if(f.current=!!t.isStreaming,y&&!t.isStreaming&&!h.current){const B=()=>{const G=a.current;G&&!h.current&&(G.scrollTop=G.scrollHeight,u.current=!0,p(!0))};requestAnimationFrame(()=>requestAnimationFrame(B));const J=setTimeout(B,180);return()=>clearTimeout(J)}},[t.isStreaming]),i.useEffect(()=>{const y=a.current;y&&u.current&&(y.scrollTop=y.scrollHeight)},[M,t.isStreaming,s]);const O=i.useCallback(()=>{const y=a.current;y&&(y.scrollTop=y.scrollHeight),u.current=!0,h.current=!1,p(!0)},[]),ae=i.useRef(null);i.useEffect(()=>{const y=ae.current,B=a.current;if(!y||!B)return;const J=G=>{G.preventDefault();const Z=y.querySelector(".qn-list");if(Z&&Z.contains(G.target)&&Z.scrollHeight>Z.clientHeight){Z.scrollTop+=G.deltaY;return}B.scrollTop+=G.deltaY};return y.addEventListener("wheel",J,{passive:!1}),()=>y.removeEventListener("wheel",J)},[]);const[A,z]=i.useState(0);i.useEffect(()=>{const y=()=>{var B;z(((B=a.current)==null?void 0:B.clientHeight)??0),E()};return y(),window.addEventListener("resize",y),()=>window.removeEventListener("resize",y)},[E]);const ee=le.length,je=i.useMemo(()=>ee===0?27:Math.max(4,Math.min(27,Math.floor(((A||600)-16)/ee)-3)),[ee,A]),Ne=je<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:"messages",ref:a,onScroll:ne,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:c("welcomeTitle")}),e.jsx("p",{className:"empty-sub",children:c("welcomeSub")}),e.jsxs("div",{className:"empty-cwd",children:[e.jsx("span",{className:"empty-cwd-label",children:c("directory")}),e.jsx("span",{className:"empty-cwd-path",children:t.cwd})]}),e.jsx("div",{className:"empty-examples",children:Ma(c).map(y=>e.jsxs("button",{type:"button",className:"empty-example",title:c("clickToFill"),onClick:()=>window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:y.prompt})),children:[e.jsx("span",{className:"empty-example-icon",children:y.icon}),e.jsx("span",{className:"empty-example-text",children:y.text})]},y.prompt))})]}),t.messages.map((y,B)=>{const J=B<C,G=J&&k.has(y.id);if(J&&!G)return y.role==="toolResult"?null:e.jsx(pa,{message:y,onExpand:ge},y.id);const Z=y.role==="user"?Q.get(y.id):void 0,ie=!F||Y.has(y.id)||v.has(y.id)||!D.has(y.id);return e.jsx(ga,{id:y.id,show:ie,height:d.current.get(y.id)??Ts(y.role,y.customType),containerRef:a,onMeasured:U,lazyRef:te,children:e.jsx(Vt,{message:y,qnIndex:Z,qnActive:Z!==void 0?Z===se:void 0,onJump:ve,toolResults:x,liveOutputs:Zt(y)?s:Qt,toolStatuses:n,streaming:t.isStreaming,onKillBash:o,isLast:y.id===S,onEdit:r,onCollapse:G?ue:void 0},y.id)},y.id)}),t.streamingMessage&&e.jsx(Vt,{message:t.streamingMessage,toolResults:x,liveOutputs:Zt(t.streamingMessage)?s:Qt,toolStatuses:n,streaming:!0,isLast:!0,onEdit:r,onKillBash:o},t.streamingMessage.id),t.isStreaming&&M.length===0&&e.jsx("div",{className:"streaming-wait",children:c("waitingResponse")})]}),!l&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:O,children:[e.jsx(hs,{})," ",c("backToBottom")]}),e.jsx(wa,{containerRef:a,messages:M,open:T,onClose:()=>P(!1),onEnsureExpanded:be}),le.length>0&&e.jsxs("div",{className:`qn-rail ${Ne?"many":""}`,ref:ae,"aria-label":c("questionNavTitle"),style:{"--rail-gap":`${je}px`},children:[le.map((y,B)=>e.jsx("button",{type:"button",className:`qn-bar ${B===se?"active":""}`,"aria-label":`${B+1}. ${y.text}`,onClick:()=>ve(y.id),children:e.jsxs("span",{className:"qn-bar-text",children:[B+1,". ",y.text]})},y.id)),Ne&&e.jsx("div",{className:"qn-list",children:le.map((y,B)=>e.jsxs("button",{type:"button",className:`qn-list-item ${B===se?"active":""}`,"aria-label":`${B+1}. ${y.text}`,onClick:()=>ve(y.id),children:[e.jsx("span",{className:"qn-list-idx",children:B+1}),e.jsx("span",{className:"qn-list-text",children:y.text})]},y.id))})]})]})}const Ra=1568,La=2*1024*1024;function Ve(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function Ia(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,Ra/Math.max(s.width,s.height)),r=Math.max(1,Math.round(s.width*n)),o=Math.max(1,Math.round(s.height*n)),c=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,p]of c){const u=document.createElement("canvas");u.width=r,u.height=o;const g=u.getContext("2d");if(!g)continue;l!=="image/png"&&(g.fillStyle="#ffffff",g.fillRect(0,0,r,o)),g.drawImage(s,0,0,r,o);const h=u.toDataURL(l,p),k=h.match(/^data:([^;]+);base64,/),w=k?k[1]:l,T=h.replace(/^data:[^;]*;base64,/,""),P=Math.floor(T.length*3/4);if(a={data:T,mimeType:w,name:t.name,size:P},P<=La)return a}return a}finally{s.close()}}const Pa=i.memo(function({ready:s,streaming:n,queueSteering:r,queueFollowUp:o,messages:c,slashCommands:a,modelState:l,models:p,modelsLoading:u,send:g,attachments:h,onRemoveAttachment:k,onAddImageFiles:w,onAddLocalFiles:T,onNotice:P,onSent:M,onManageModels:x}){const S=oe(),{locale:C}=Nt(),D=f=>C==="en"&&f.descriptionEn?f.descriptionEn:f.description??"",_=f=>C==="en"&&f.argumentHintEn?f.argumentHintEn:f.argumentHint??"",[v,N]=i.useState(""),[d,L]=i.useState(!1),[$,j]=i.useState(null),[F,K]=i.useState(0),[Y,m]=i.useState(!1),[R,E]=i.useState(void 0),H=i.useRef(null),U=i.useRef(null),te=i.useRef(null),le={builtin:S("slashBuiltin"),extension:S("slashExtension"),prompt:S("slashPrompt"),skill:S("slashSkill")},Q=f=>{const O=f.match(/^\/([^\s]*)$/);if(O&&s){const ae=O[1].toLowerCase(),A=a.filter(z=>z.name.toLowerCase().startsWith(ae));j(A.length>0?A:null),K(0)}else j(null)};i.useEffect(()=>{var O;const f=(O=te.current)==null?void 0:O.querySelector(".slash-item.active");f==null||f.scrollIntoView({block:"nearest"})},[F,$]);const se=f=>{var ee;const O=$??[],ae=f??O[F%Math.max(O.length,1)];if(!ae){j(null);return}const A=v.match(/^\/([^\s]*)([\s\S]*)$/),z=A?A[2]:"";N(`/${ae.name} ${z}`),j(null),(ee=H.current)==null||ee.focus()},ce=async()=>{const O=[...c].reverse().find(A=>A.role==="assistant"&&A.content.some(z=>z.type==="text"&&z.text)),ae=O==null?void 0:O.content.filter(A=>A.type==="text").map(A=>A.text).join(`
17
+ `);if(!ae){P("warning",S("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(ae),P("info",S("slashCopied"))}catch{P("error",S("slashCopyFailed"))}},pe=f=>{if(!f||f.length===0){P("warning",S("foldersNotSupported"));return}const O=Array.from(f).filter(A=>Ve(A.type)),ae=Array.from(f).filter(A=>!Ve(A.type));O.length>0&&w(O),ae.length>0&&T(ae)},xe=f=>{var A;const O=(A=f.clipboardData)==null?void 0:A.items;if(!O)return;const ae=[];for(const z of O)if(z.kind==="file"&&Ve(z.type)){const ee=z.getAsFile();ee&&ae.push(ee)}ae.length!==0&&(f.preventDefault(),w(ae))},me=s,ge=r+o,be=i.useRef(v);i.useEffect(()=>{be.current=v},[v]),i.useEffect(()=>{Q(be.current)},[a]),i.useEffect(()=>{const f=O=>{var A;const ae=O.detail;N(ae),(A=H.current)==null||A.focus()};return window.addEventListener("pi-web:fill",f),()=>window.removeEventListener("pi-web:fill",f)},[]),i.useEffect(()=>{if(!Y)return;const f=O=>{O.key==="Escape"&&m(!1)};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[Y]),i.useEffect(()=>{const f=H.current;if(!f)return;f.style.height="auto";const O=f.scrollHeight>220;f.style.height=`${Math.min(f.scrollHeight,220)}px`,f.style.overflowY=O?"auto":"hidden"},[v]);const ue=(f=!1)=>{var A,z,ee,je,Ne;const O=v.trim(),ae=h.some(y=>y.imageData||y.fileData);if(!(!me||!O&&!ae)){if(O==="/help"){const y=(z=(A=H.current)==null?void 0:A.closest(".inputbox"))==null?void 0:z.getBoundingClientRect();E(y==null?void 0:y.width),m(!0),N(""),(ee=H.current)==null||ee.focus();return}if(O==="/copy"){N(""),(je=H.current)==null||je.focus(),ce();return}g({type:"prompt",text:O,queue:f,attachments:h.map(y=>y.imageData?{path:"",imageData:y.imageData,mimeType:y.mimeType,name:y.name}:y.fileData?{path:"",fileData:y.fileData,mimeType:y.mimeType,name:y.name,size:y.size}:{path:y.path,mode:y.mode,...y.lines?{lines:y.lines}:{}})})&&(N(""),M(),(Ne=H.current)==null||Ne.focus())}},ve=f=>{if(!f.nativeEvent.isComposing){if($&&$.length>0)switch(f.key){case"ArrowDown":f.preventDefault(),K(O=>(O+1)%$.length);return;case"ArrowUp":f.preventDefault(),K(O=>(O-1+$.length)%$.length);return;case"Tab":case"Enter":f.preventDefault(),se();return;case"Escape":f.preventDefault(),j(null);return}f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),ue())}},ne=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[v.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:S("supplementTip"),onClick:()=>ue(!0),children:[e.jsx(tn,{})," ",S("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:S("stopAgent"),onClick:()=>g({type:"abort"}),children:e.jsx(Qe,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:S("sendTip"),disabled:!me||!v.trim()&&!h.some(f=>f.imageData||f.fileData),onClick:()=>ue(),children:e.jsx(ps,{})})});return e.jsxs("div",{className:`inputbar${d?" drop-active":""}`,onDragOver:f=>{f.preventDefault(),f.stopPropagation(),L(!0)},onDragLeave:f=>{f.currentTarget.contains(f.relatedTarget)||L(!1)},onDrop:f=>{var O;f.preventDefault(),f.stopPropagation(),L(!1),pe(((O=f.dataTransfer)==null?void 0:O.files)??null)},children:[d&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",S("dropHereToAttach")]})}),h.length>0&&e.jsxs("div",{className:"attach-row",children:[h.map(f=>e.jsxs("span",{className:`attach-chip ${f.imageData?"image":f.fileData?"file":f.mode}`,title:f.imageData?S("attachImage",{name:f.name}):f.fileData?S("attachFile",{name:f.name}):f.isDir?S("folderRef",{path:f.path}):f.mode==="reference"?S("refOnly",{path:f.path}):f.mode==="lines"&&f.lines?S("attachLines",{path:f.path,start:f.lines.start,end:f.lines.end}):S("attachContent",{path:f.path}),children:[f.imageData?"🖼":f.fileData?"📄":f.isDir?"📁":f.mode==="reference"?"🔗":"📎"," ",f.name,f.mode==="lines"&&f.lines&&e.jsxs("span",{className:"attach-range",children:["L",f.lines.start,"-",f.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:S("removeAttachment"),onClick:()=>k(f.key??f.path),children:"×"})]},f.key??`${f.path}|${f.mode}|${f.lines?`${f.lines.start}-${f.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:S("attachHint")})]}),n&&ge>0&&e.jsxs("div",{className:"queue-hint",children:[o>0&&e.jsx("span",{children:S("followUpQueued",{n:o})}),r>0&&e.jsx("span",{children:S("steeringQueued",{n:r})})]}),$&&$.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:te,"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:()=>j(null),children:"Esc"})]}),$.map((f,O)=>e.jsxs("button",{type:"button",className:`slash-item${O===F?" active":""}`,onMouseEnter:()=>K(O),onClick:()=>se(f),children:[e.jsxs("span",{className:"slash-name",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:le[f.source]}),e.jsxs("span",{className:"slash-desc",children:[D(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:_(f)})]})]},f.name))]}),Y&&e.jsx("div",{className:"modal-backdrop",onClick:()=>m(!1),children:e.jsxs("div",{className:"slash-help",style:R?{width:R}:void 0,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",S("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>m(!1),children:S("close")})]}),e.jsx("div",{className:"slash-help-body",children:a.length===0?e.jsx("div",{className:"slash-help-empty",children:S("slashLoading")}):a.map(f=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:le[f.source]}),e.jsxs("span",{className:"slash-help-desc",children:[D(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:_(f)})]})]},f.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,onChange:f=>{pe(f.target.files),f.target.value=""}}),e.jsxs("div",{className:"inputbox-row",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!me,onClick:()=>{var f;return(f=U.current)==null?void 0:f.click()},children:e.jsx(Dt,{})}),e.jsx("textarea",{ref:H,value:v,rows:1,placeholder:S(me?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!me,onChange:f=>{N(f.target.value),Q(f.target.value)},onKeyDown:ve,onPaste:xe}),ne()]}),e.jsxs("div",{className:"input-tools",children:[e.jsx("div",{className:"input-tools-left",children:e.jsx(xs,{state:l,models:p,modelsLoading:u,send:g,onManageModels:x,compact:!0})}),e.jsxs("div",{className:"input-tools-right",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!me,onClick:()=>{var f;return(f=U.current)==null?void 0:f.click()},children:e.jsx(Dt,{})}),ne()]})]})]})]})}),Ba=i.memo(function({goal:s,models:n,modelsLoading:r,activeConversationId:o,send:c}){var j,F,K,Y,m,R;const a=oe(),l=!s.conversationId||s.conversationId===o,p=s.goal!==null&&l,[u,g]=i.useState(""),[h,k]=i.useState(s.reviewModel??""),[w,T]=i.useState(s.maxRounds),[P,M]=i.useState(s.locked),[x,S]=i.useState(!1),[C,D]=i.useState(!1),[_,v]=i.useState(!0);i.useEffect(()=>{k(s.reviewModel??""),T(s.maxRounds||0),M(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),i.useEffect(()=>{x&&n.length===0&&!C&&!r&&(D(!0),c({type:"list_models"}))},[x,n.length,C,r,c]),i.useEffect(()=>{n.length>0&&D(!1)},[n.length]);const N=()=>{var E;return h?((E=n.find(H=>H.id===h))==null?void 0:E.name)??h:a("goalBarUseMainModel")},d=()=>{const E=u.trim();E&&(c({type:"set_goal",goal:E,...h?{reviewModel:h}:{},maxRounds:w,locked:P}),g(""),v(!1))},L=()=>{const E=u.trim();E&&(c({type:"start_goal_wizard",text:E,...h?{wizardModel:h}:{},maxRounds:w,locked:P}),g(""),v(!1))},$=(((j=s.wizard)==null?void 0:j.active)??!1)&&l;return $?e.jsx("div",{className:`goalbar goalbar-active ${$?"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:((F=s.wizard)==null?void 0:F.draft)??"",children:[a("goalWizardRunning"),": ",(K=s.wizard)==null?void 0:K.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[a("goalBarRound",{n:(((Y=s.wizard)==null?void 0:Y.step)??0)+1})," ","/ ",((m=s.wizard)==null?void 0:m.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((R=s.wizard)==null?void 0:R.status)||a("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),onClick:()=>{c({type:"clear_goal"}),v(!0)},children:e.jsx(Se,{})})]})}):p?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:()=>{c({type:"clear_goal"}),v(!0)},children:e.jsx(Se,{})})]})}):_?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(Bt,{})," ",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(Bt,{})}),e.jsx("input",{className:"goalbar-input",value:u,placeholder:a("goalBarPlaceholder"),onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&d()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!u.trim(),onClick:d,children:a("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!u.trim(),title:a("goalWizardTip"),onClick:L,children:["🔍 ",a("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a(P?"goalBarLocked":"goalBarUnlocked"),onClick:()=>M(E=>(c({type:"set_goal_prefs",locked:!E}),!E)),children:P?e.jsx(dn,{}):e.jsx(Zs,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a("goalBarClear"),onClick:()=>v(!0),children:e.jsx(at,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Re,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[a("goalBarReviewModel"),": ",e.jsx("b",{children:N()})]}),open:x,onOpenChange:S,direction:"up",children:[e.jsx("div",{className:"dd-header",children:a("goalBarReviewModel")}),(C||r)&&e.jsx("div",{className:"dd-loading",children:a("loading")}),n.length===0&&!C&&!r&&e.jsx("div",{className:"dd-loading",children:a("noModels")}),e.jsx(ke,{active:h==="",onClick:()=>{k(""),S(!1),c({type:"set_goal_prefs",reviewModel:""})},children:a("goalBarUseMainModel")}),n.map(E=>e.jsx(ke,{active:h===E.id,onClick:()=>{k(E.id),S(!1),c({type:"set_goal_prefs",reviewModel:E.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:E.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:E.provider})})]})},E.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({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:w,placeholder:a("goalBarUnlimitedShort"),onChange:E=>{const H=parseInt(E.target.value,10);if(Number.isNaN(H)||H<0){T(0);return}T(H)},onBlur:()=>c({type:"set_goal_prefs",maxRounds:w}),onKeyDown:E=>{E.key==="Enter"&&(c({type:"set_goal_prefs",maxRounds:w}),E.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:a(P?"goalBarLocked":"goalBarUnlocked")})]})]})});function Da({chat:t,send:s}){const n=oe(),r=t.state,[o,c]=i.useState(!1),[a,l]=i.useState(""),[p,u]=i.useState(0),g=i.useRef(null),h=t.pathCompletions;if(i.useEffect(()=>{if(!o)return;const d=setTimeout(()=>{s({type:"complete_path",path:a})},150);return()=>clearTimeout(d)},[a,o,s]),i.useEffect(()=>u(0),[h]),i.useEffect(()=>{const d=document.querySelector(`.status-completions .pc-item[data-idx="${p}"]`);d==null||d.scrollIntoView({block:"nearest"})},[p]),!r)return null;const k=r.stats,w=t.ready?"ok":"busy",T=t.ready?n("connected"):n("connecting"),P=k.contextUsage,M=P.tokens!==null&&P.percent!==null?`${es(P.tokens)} / ${es(P.contextWindow)}`:"—",x=P.percent??null,S=x===null?"":x>=80?"warn":x>=50?"mid":"ok",C=r.queue.steering+r.queue.followUp,D=()=>{l(r.cwd),c(!0)},_=(d,L)=>{var j;const $=d.includes("\\")?"\\":"/";l(L?`${d}${$}`:d),u(0),(j=g.current)==null||j.focus()},v=d=>{const L=d.trim();L&&L!==r.cwd&&s({type:"set_cwd",path:L}),c(!1)},N=d=>{if(d.key==="ArrowDown")d.preventDefault(),u(L=>Math.min(L+1,h.length-1));else if(d.key==="ArrowUp")d.preventDefault(),u(L=>Math.max(L-1,0));else if(d.key==="Tab"&&h.length>0){d.preventDefault();const L=h[Math.min(p,h.length-1)];_(L.path,L.type==="dir")}else if(d.key==="Enter"&&!d.nativeEvent.isComposing){const L=a.trim();if(L.endsWith("/")||L.endsWith("\\"))v(L);else if(h.some($=>$.path===L))v(L);else if(h.length>0&&h[p]){d.preventDefault();const $=h[p];_($.path,$.type==="dir")}else v(L)}else d.key==="Escape"&&(h.length>0?(d.stopPropagation(),s({type:"complete_path",path:""})):c(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${w}`,title:T}),e.jsx("span",{className:"status-item",children:T}),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 ${S}`,children:x!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(x,100)}%`}})}),M]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",Fa(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(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),n("working"),C>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",C," ",n("queued")]})]})]}),o?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:g,className:"status-cwd-input",value:a,autoFocus:!0,placeholder:n("enterPath"),onChange:d=>l(d.target.value),onKeyDown:N,onBlur:()=>c(!1)}),h.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:d=>d.preventDefault(),children:h.map((d,L)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":L,className:`pc-item ${L===p?"sel":""}`,onMouseEnter:()=>u(L),onClick:()=>_(d.path,d.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:d.type==="dir"?e.jsx(De,{}):e.jsx(ds,{})}),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:r.cwd}),onClick:D,children:["📁 ",r.cwd]})]})}function es(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function Fa(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function _a({dialog:t,send:s}){const n=oe(),[r,o]=i.useState(""),[c,a]=i.useState(0),l=g=>{s({type:"dialog_response",id:t.id,value:g})};i.useEffect(()=>{o(""),a(0);const g=h=>{h.key==="Escape"&&l(null)};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t.id]);const p=Array.isArray(t.args[0])?t.args[0]:[],u=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:[p.map((g,h)=>e.jsx("button",{type:"button",className:`dialog-option ${h===c?"sel":""}`,onMouseEnter:()=>a(h),onClick:()=>l(g),children:g},h)),p.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:u}),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:r,placeholder:u||n("inputPlaceholder"),autoFocus:!0,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&!g.nativeEvent.isComposing&&l(r)}}),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(r),children:n("ok")})]})]})]})}function Aa(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 $a({chat:t,send:s,terminal:n,active:r,onSwitchToTerminal:o}){var we,Fe;const c=oe(),[a,l]=i.useState(null),[p,u]=i.useState([]),[g,h]=i.useState(""),[k,w]=i.useState(new Map),[T,P]=i.useState("changes"),[M,x]=i.useState([]),[S,C]=i.useState(null),[D,_]=i.useState(""),[v,N]=i.useState(!1),[d,L]=i.useState(null),[$,j]=i.useState(null),[F,K]=i.useState(!1),[Y,m]=i.useState(!1),[R,E]=i.useState(!1),[H,U]=i.useState(null),[te,le]=i.useState(!1),[Q,se]=i.useState(""),ce=i.useRef(0),pe=i.useRef(-1),xe=i.useRef(-1),me=i.useRef(-1),ge=i.useRef(-1),be=i.useRef(void 0),ue=i.useRef(null),ve=i.useRef([]),ne=i.useCallback(b=>{if(b.reqId===pe.current){if(pe.current=-1,m(!1),U(null),!b.ok){U(b.error??"查询失败");return}if(b.notRepo){le(!0),l(null),u([]),w(new Map),x([]),C(null),_(""),j(null);return}le(!1);const X={branch:b.branch??"",detached:!!b.detached,upstream:b.upstream??null,ahead:b.ahead??0,behind:b.behind??0,upstreamGone:!!b.upstreamGone,files:(b.files??[]).map(re=>({...re}))},V=(b.branches??[]).map(re=>({...re})),fe=new Map;for(const[re,ye]of Object.entries(b.stats??{}))fe.set(re,{add:ye[0],del:ye[1]});l(X),u(V),w(fe),h(re=>{var ye;return X.detached?re||"":X.branch&&V.some(Te=>Te.name===X.branch)?X.branch:re&&V.some(Te=>Te.name===re)?re:((ye=V[0])==null?void 0:ye.name)??""}),j(re=>re&&!X.files.some(ye=>ye.path===re.file.path)?null:re)}else if(b.reqId===xe.current){if(xe.current=-1,K(!1),!b.ok){U(b.error??"查询失败");return}const X=ue.current;if(!X)return;j({file:X,staged:b.stagedText??"",worktree:b.worktreeText??"",untracked:!1})}else if(b.reqId===ge.current){if(ge.current=-1,E(!1),!b.ok){U(b.error??"查询失败");return}x((b.history??[]).map(X=>({...X})))}else if(b.reqId===me.current){if(me.current=-1,N(!1),!b.ok){U(b.error??"查询失败");return}_(b.text??"")}},[]);i.useEffect(()=>{const b=t.scmData;b&&b.type==="scm_data"&&ne(b)},[t.scmData,ne]);const f=i.useCallback((b,X)=>{if(!t.ready||t.status!=="open")return!1;const V=++ce.current;return s({...b,reqId:V})?(X.current=V,!0):(ce.current-=1,!1)},[t.ready,t.status,s]),O=i.useCallback((b=!1,X=!1)=>{var V;!t.ready||t.status!=="open"||(V=t.state)!=null&&V.cwd&&(be.current!==void 0&&be.current!==t.state.cwd&&(l(null),u([]),w(new Map),x([]),E(!1),ge.current=-1,C(null),_(""),j(null),L(null)),be.current=t.state.cwd,U(null),f({type:"scm_status"},pe)&&(X||m(!0)))},[t.ready,(we=t.state)==null?void 0:we.cwd,t.status,f]),ae=i.useCallback(b=>{if(L(b),C(null),ue.current=b,b.x==="?"&&b.y==="?"){j({file:b,staged:"",worktree:"",untracked:!0});return}K(!0),U(null),f({type:"scm_filediff",path:b.path},xe)||K(!1)},[f]),A=i.useCallback(b=>{C(b),L(null),j(null),_(""),N(!0),U(null),f({type:"scm_commit",hash:b.hash},me)||N(!1)},[f]),z=i.useCallback((b,X)=>{var re,ye;if(!t.ready)return;const V={name:b,command:X,cwd:"${pwd}"},fe=t.terminals.find(Te=>Te.title===b);if(fe)n.restart(fe.id),s({type:"run_command",terminalId:fe.id,conversationId:fe.conversationId,command:V,cols:80,rows:24});else{const Te=tt();n.create({id:Te,conversationId:t.activeConversationId||((re=t.state)==null?void 0:re.conversationId)||"",title:b,cwd:((ye=t.state)==null?void 0:ye.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:V})}o()},[t.ready,(Fe=t.state)==null?void 0:Fe.cwd,t.terminals,o,s,n]),ee=i.useCallback(()=>{const b=Q.trim();if(!b||te)return;const X=b.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");z("git commit",`git add -A && git commit -m "${X}"`),se("")},[Q,te,z]),je=b=>`'${b.replace(/'/g,"'\\''")}`,Ne=i.useCallback(b=>{te||z("git add",`git add -- ${je(b.path)}`)},[te,z]),y=i.useCallback(b=>{te||z("git reset",`git reset HEAD -- ${je(b.path)}`)},[te,z]),B=i.useCallback(()=>{if(!g||te)return;const b=p.find(X=>X.name===g);if(b!=null&&b.remote&&typeof b.remote=="string"){const X=g.slice(b.remote.length+1);z("git checkout",`git checkout -b ${X} ${g} || git checkout ${g}`)}else z("git checkout",`git checkout ${g}`)},[g,p,te,z]),J=i.useCallback(()=>z("git push","git push"),[z]),G=i.useCallback(()=>z("git pull","git pull"),[z]),Z=i.useCallback(()=>{f({type:"scm_history"},ge)||(ge.current=-1)},[f]);i.useEffect(()=>{r&&O()},[r,O]),i.useEffect(()=>{T==="history"&&a&&Z()},[T,a,Z]),i.useEffect(()=>{t.scmDirty>0&&r&&O(!1,!0)},[t.scmDirty]),i.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const b=setInterval(()=>{document.visibilityState!=="hidden"&&O(!1,!0)},3e4);return()=>clearInterval(b)},[r,t.ready,t.status,O]),i.useEffect(()=>{const b=ve.current;if(ve.current=t.terminals,!r)return;t.terminals.some(V=>{var re;return V.running!==!1?!1:((re=b.find(ye=>ye.id===V.id))==null?void 0:re.running)===!0&&/^git /.test(V.title)})&&t.ready&&t.status==="open"&&(O(!1,!0),T==="history"&&a&&Z())},[t.terminals,r,t.ready,t.status,O,T,a,Z]);const ie={staged:c("scmStaged"),unstaged:c("scmUnstaged"),untracked:c("scmUntracked"),both:c("scmStagedUnstaged")},he=b=>{const X=b.split(`
18
+ `);return e.jsx("pre",{className:"scm-diff-pre",children:X.map((V,fe)=>{let re="";return V.startsWith("diff --git")||V.startsWith("index ")||V.startsWith("new file")||V.startsWith("deleted file")||V.startsWith("old mode")||V.startsWith("new mode")||V.startsWith("similarity index")||V.startsWith("rename ")||V.startsWith("copy ")||V.startsWith("Binary files")||V.startsWith("---")||V.startsWith("+++")?re="hdr":V.startsWith("@@")?re="hunk":V.startsWith("+")?re="add":V.startsWith("-")&&(re="del"),e.jsx("div",{className:`scm-diff-line ${re}`,children:V||" "},fe)})})};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(Ke,{}),c("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":T==="changes",className:T==="changes"?"active":"",onClick:()=>{P("changes"),U(null)},children:c("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":T==="history",className:T==="history"?"active":"",onClick:()=>{P("history"),U(null)},children:c("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:c("scmRefreshTip"),disabled:Y,onClick:()=>O(!0),children:e.jsx(jt,{className:Y?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:c("scmCurrentBranch"),children:[e.jsx(Ke,{}),a?a.detached?c("scmDetached"):a.branch:"…",(a==null?void 0:a.upstream)&&e.jsx("span",{className:"scm-upstream",children:a.upstreamGone?c("scmUpstreamGone"):a.ahead>0||a.behind>0?c("scmAheadBehind",{ahead:a.ahead,behind:a.behind}):a.upstream})]}),e.jsxs("select",{className:"scm-select",value:g,disabled:te||p.length===0,title:c("scmSwitchBranch"),onChange:b=>h(b.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:c("scmSelectBranch")}),p.filter(b=>!b.remote).map(b=>e.jsx("option",{value:b.name,children:b.current?`* ${b.name}`:b.name},b.name)),p.some(b=>b.remote)&&e.jsx("optgroup",{label:c("scmRemoteBranches"),children:p.filter(b=>b.remote).map(b=>e.jsx("option",{value:b.name,children:b.name},b.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!g||g===(a==null?void 0:a.branch)||te,title:c("scmSwitchBranchTip",{branch:g}),onClick:B,children:[e.jsx(Ke,{}),c("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||te,title:c("scmPushTip"),onClick:J,children:[e.jsx(ps,{}),c("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||te,title:c("scmPullTip"),onClick:G,children:[e.jsx(hs,{}),c("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:Q,placeholder:c("scmCommitPlaceholder"),disabled:te,onChange:b=>se(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.nativeEvent.isComposing&&ee()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!Q.trim()||te,title:c("scmCommitTip"),onClick:ee,children:[e.jsx(kt,{}),c("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[T==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:c("scmHistory")}),M.length>0&&e.jsx("span",{className:"scm-files-count",children:M.length})]}),e.jsx("div",{className:"scm-history-list",children:te?e.jsx("div",{className:"scm-empty",children:c("scmNotGitRepo")}):!a||R?e.jsx("div",{className:"scm-empty",children:t.status==="open"?c("scmLoading"):c("scmConnecting")}):M.length===0?e.jsx("div",{className:"scm-empty",children:c("scmNoHistory")}):M.map(b=>e.jsxs("button",{type:"button",className:`scm-commit ${(S==null?void 0:S.hash)===b.hash?"active":""}`,onClick:()=>A(b),title:b.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:b.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:b.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[b.shortHash," · ",b.author," · ",b.date]}),b.decorations&&e.jsx("span",{className:"scm-commit-refs",children:b.decorations})]})]},b.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:c("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:te?e.jsx("div",{className:"scm-empty",children:c("scmNotGitRepo")}):a?a.files.length===0?e.jsx("div",{className:"scm-empty",children:c("scmNoChanges")}):a.files.map(b=>{const X=Aa(b),V=k.get(b.path);return e.jsxs("div",{className:`scm-file ${(d==null?void 0:d.path)===b.path?"active":""}`,title:ie[X],onClick:()=>ae(b),children:[e.jsx("span",{className:`scm-file-xy ${X==="untracked"?"q":"x"}`,children:b.x!==" "?b.x:" "}),e.jsx("span",{className:`scm-file-xy ${X==="untracked"?"q":"y"}`,children:b.y!==" "?b.y:" "}),e.jsx("span",{className:"scm-file-path",children:b.path}),V&&(V.add>0||V.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[V.add>0&&e.jsxs("span",{className:"add",children:["+",V.add]}),V.del>0&&e.jsxs("span",{className:"del",children:["-",V.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(b.y!==" "||X==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:c("scmStageTip",{path:b.path}),onClick:fe=>{fe.stopPropagation(),Ne(b)},children:"+"}),X==="staged"||X==="both"?e.jsx("button",{type:"button",className:"scm-act",title:c("scmUnstageTip",{path:b.path}),onClick:fe=>{fe.stopPropagation(),y(b)},children:"−"}):null]})]},b.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?c("scmLoading"):c("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:T==="history"?S?`${S.shortHash} ${S.subject}`:c("scmCommitDetail"):d?d.path:c("scmDiff")}),(T==="history"?v:F)&&e.jsx("span",{className:"scm-diff-loading",children:c("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:T==="history"?e.jsxs(e.Fragment,{children:[H&&e.jsx("div",{className:"scm-error",children:H}),!S&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmSelectCommitHint")}),S&&v&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmLoading")}),S&&!v&&!H&&D?he(D):null]}):e.jsxs(e.Fragment,{children:[H&&e.jsx("div",{className:"scm-error",children:H}),!d&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmSelectFileHint")}),d&&!$&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmLoading")}),d&&$&&$.untracked&&e.jsx("div",{className:"scm-empty",children:c("scmUntrackedNote")}),d&&$&&!$.untracked&&e.jsxs(e.Fragment,{children:[$.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:c("scmStaged")}),he($.staged)]}),$.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:c("scmUnstaged")}),he($.worktree)]}),!$.staged&&!$.worktree&&e.jsx("div",{className:"scm-empty",children:c("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(st,{}),e.jsx("span",{children:c("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:o,children:c("scmViewTerminal")})]})]})}function Oa({send:t,piConfigured:s,providers:n,installResult:r,onClose:o}){const c=oe(),[a,l]=i.useState(!1),[p,u]=i.useState(""),[g,h]=i.useState(""),[k,w]=i.useState(!1);i.useEffect(()=>{t({type:"list_providers"})},[t]),i.useEffect(()=>{s&&o()},[s,o]),i.useEffect(()=>{r&&l(!1)},[r]),i.useEffect(()=>{var C;!p&&n.length>0&&u(((C=n.find(D=>!D.configured))==null?void 0:C.id)??n[0].id)},[n,p]);const T=()=>{a||(l(!0),t({type:"install_pi_agent"}))},P=()=>{!g.trim()||k||(w(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:g.trim()}),setTimeout(()=>w(!1),3e3))},M=()=>{t({type:"get_state"}),t({type:"list_providers"})},x=n.find(C=>C.id===p),S=r!==null&&!r.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":c("close"),onClick:o,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(nt,{className:"modal-head-icon"}),e.jsx("h2",{children:c("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:c("setupDesc")}),S?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:c("installFailed")}),e.jsx("pre",{className:"setup-detail",children:r.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:T,children:c("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:o,children:c("skip")})]})]}):r!=null&&r.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c("installDone")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:c("provider")}),e.jsxs("select",{value:p,onChange:C=>u(C.target.value),children:[n.length===0&&e.jsx("option",{value:"",children:c("loading")}),n.map(C=>e.jsxs("option",{value:C.id,children:[C.name,"(",C.id,")",C.configured?` · ${c("configured")}`:""]},C.id))]}),(x==null?void 0:x.configured)&&e.jsx("div",{className:"field-hint",children:c("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:c("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:C=>h(C.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||k||!p,onClick:P,children:c(k?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:M,children:[e.jsx(jt,{})," ",c("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:T,children:c(a?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:o,children:c("skip")})]})]})})}const Wa=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],St=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Ha=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[St()]});function Ua(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:[St()]).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 qa({send:t,providers:s,providerStatus:n,fetchModelsResult:r,refreshProviderResult:o,onClose:c}){const a=oe(),[l,p]=i.useState(null),[u,g]=i.useState({}),[h,k]=i.useState(null),[w,T]=i.useState({}),[P,M]=i.useState(!1),[x,S]=i.useState(0),[C,D]=i.useState(null),_=i.useRef(0),[v,N]=i.useState({});i.useRef(0);const d=i.useRef(0);i.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const L=()=>{if(!l)return;const m=l.baseUrl.trim();if(!m){D({ok:!1,text:a("fetchModelsNeedBaseUrl")});return}if(P)return;M(!0),D(null);const R=x+1;S(R),t({type:"fetch_models",reqId:R,baseUrl:m,apiKey:l.apiKey.trim()||void 0,authHeader:l.authHeader,api:l.api})};i.useEffect(()=>{var m;if(!(!r||r.reqId===_.current))if(_.current=r.reqId,M(!1),r.ok&&((m=r.models)!=null&&m.length)){const R=r.models;p(E=>{if(!E)return E;const H=E.models.map(Q=>{var pe;if(!Q.id.trim())return Q;const se=R.find(xe=>xe.id===Q.id.trim());if(!se)return Q;const ce={...Q};return!ce.name&&se.name&&(ce.name=se.name),!ce.contextWindow&&se.contextWindow&&(ce.contextWindow=String(se.contextWindow)),!ce.maxTokens&&se.maxTokens&&(ce.maxTokens=String(se.maxTokens)),ce.input==="text"&&((pe=se.input)!=null&&pe.includes("image"))&&(ce.input="text-image"),!ce.reasoning&&se.reasoning&&(ce.reasoning=!0),ce}),U=new Set(H.map(Q=>Q.id.trim()).filter(Boolean)),te=R.filter(Q=>!U.has(Q.id)).map(Q=>{var se;return{id:Q.id,name:Q.name??"",reasoning:Q.reasoning??!1,input:(se=Q.input)!=null&&se.includes("image")?"text-image":"text",contextWindow:Q.contextWindow?String(Q.contextWindow):"",maxTokens:Q.maxTokens?String(Q.maxTokens):""}}),le=[...H,...te];return le.some(Q=>Q.id.trim())?{...E,models:le.filter(Q=>Q.id.trim())}:E}),D({ok:!0,text:a("fetchModelsOk",{n:R.length})})}else D({ok:!1,text:r.error||a("fetchModelsEmpty")})},[r]);const $=m=>{const R=(u[m.id]??"").trim();!R||h||(k(m.id),t({type:"set_provider_api_key",provider:m.id,apiKey:R}),setTimeout(()=>{k(null),g(E=>({...E,[m.id]:""})),T(E=>({...E,[m.id]:!1})),t({type:"list_providers"})},1500))},j=()=>{if(!l)return;const m=l.providerId.trim(),R=l.models.filter(H=>H.id.trim()).map(H=>({id:H.id.trim(),name:H.name.trim()||void 0,reasoning:H.reasoning||void 0,input:H.input==="text-image"?["text","image"]:void 0,contextWindow:H.contextWindow?Number(H.contextWindow):void 0,maxTokens:H.maxTokens?Number(H.maxTokens):void 0})),E={providerId:m,name:l.name.trim()||void 0,api:l.api.trim()||void 0,baseUrl:l.baseUrl.trim()||void 0,apiKey:l.apiKey.trim()||void 0,authHeader:l.authHeader||void 0,models:R};t({type:"save_model_config",providerId:m,config:E}),c()};i.useEffect(()=>{!o||o.reqId===d.current||(d.current=o.reqId,N({}))},[o]);const F=m=>{window.confirm(a("clearKeyConfirm",{id:m}))&&t({type:"clear_provider_api_key",provider:m})},K=m=>{window.confirm(a("deleteProviderConfirm",{id:m.providerId,n:m.models.length}))&&t({type:"delete_model_config",providerId:m.providerId})},Y=(m,R)=>{l&&p({...l,models:l.models.map((E,H)=>H===m?{...E,...R}:E)})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal model-modal",onClick:m=>m.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":a("close"),onClick:c,children:e.jsx(Se,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:a(l?"editProvider":"manageModelsTitle")})}),l?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:[a("providerId")," ",e.jsx("em",{children:a("providerIdHint")})]}),e.jsx("input",{type:"text",value:l.providerId,disabled:s.some(m=>m.providerId===l.providerId),onChange:m=>p({...l,providerId:m.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:a("displayName")}),e.jsx("input",{type:"text",value:l.name,onChange:m=>p({...l,name:m.target.value}),placeholder:a("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:a("apiType")}),e.jsx("select",{value:l.api,onChange:m=>p({...l,api:m.target.value}),children:Wa.map(m=>e.jsx("option",{value:m,children:m},m))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:a("baseUrlHint")})]}),e.jsx("input",{type:"text",value:l.baseUrl,onChange:m=>p({...l,baseUrl:m.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:a("apiKey")}),e.jsx("input",{type:"password",value:l.apiKey,onChange:m=>p({...l,apiKey:m.target.value}),placeholder:a("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:l.authHeader,onChange:m=>p({...l,authHeader:m.target.checked})}),e.jsx("span",{children:a("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:a("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:P||!l.baseUrl.trim(),title:a("fetchModelsHint"),onClick:L,children:[e.jsx(bt,{})," ",a(P?"fetchingModels":"fetchModels")]})]})]}),l.models.map((m,R)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:m.id,onChange:E=>Y(R,{id:E.target.value}),placeholder:a("modelIdReq")}),e.jsx("input",{type:"text",value:m.name,onChange:E=>Y(R,{name:E.target.value}),placeholder:a("displayName")}),e.jsxs("select",{value:m.input,onChange:E=>Y(R,{input:E.target.value}),children:[e.jsx("option",{value:"text",children:a("text")}),e.jsx("option",{value:"text-image",children:a("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:m.reasoning,onChange:E=>Y(R,{reasoning:E.target.checked})}),e.jsx("span",{children:a("reasoning")})]}),e.jsx("input",{type:"number",value:m.contextWindow,onChange:E=>Y(R,{contextWindow:E.target.value}),placeholder:a("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:m.maxTokens,onChange:E=>Y(R,{maxTokens:E.target.value}),placeholder:a("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:a("removeModel"),onClick:()=>p({...l,models:l.models.filter((E,H)=>H!==R)}),children:e.jsx(ze,{})})]},R)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...l,models:[...l.models,St()]}),children:[e.jsx(Be,{})," ",a("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:a("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!l.providerId.trim()||!l.models.some(m=>m.id.trim()),onClick:j,children:a("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[a("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:a("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:a("loading")}),n.map(m=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:m.name}),e.jsxs("span",{className:"provider-sub",children:[m.id,m.configured&&e.jsx("span",{className:"auth-badge",children:a("configuredBadge")}),m.source&&!m.configured&&e.jsx("span",{className:"auth-badge dim",children:m.source})]})]}),e.jsx("div",{className:"provider-actions",children:m.configured&&!w[m.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:a("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:a("replaceKeyTitle"),onClick:()=>T(R=>({...R,[m.id]:!0})),children:[e.jsx(_t,{})," ",a("replaceKey")]}),m.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:a("clearKeyTitle"),onClick:()=>F(m.id),children:[e.jsx(ze,{})," ",a("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:a("pasteKey"),value:u[m.id]??"",onChange:R=>g(E=>({...E,[m.id]:R.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(u[m.id]??"").trim()||h===m.id,onClick:()=>$(m),children:[e.jsx(un,{})," ",h===m.id?a("savingKey"):a("saveKey")]})]})})]},m.id))]}),e.jsx("div",{className:"form-section-title",children:a("customProviders")}),e.jsx("p",{className:"modal-desc",children:a("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:a("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(m=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:m.providerId}),e.jsxs("span",{className:"provider-sub",children:[m.api??"—",m.baseUrl?` · ${m.baseUrl}`:"",m.models.length>0&&` · ${a("modelsCount",{n:m.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:a("edit"),onClick:()=>p(Ua(m)),children:e.jsx(_t,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:a("delete"),onClick:()=>K(m),children:e.jsx(ze,{})})]})]},m.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(Ha()),children:[e.jsx(Be,{})," ",a("addProvider")]})})]})]})})}function Ue({title:t,subtitle:s,enabled:n,onToggle:r}){const o=oe();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:t}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),e.jsx("button",{type:"button",className:`set-switch ${n?"on":""}`,role:"switch","aria-checked":n,title:o(n?"settingsEnabled":"settingsDisabled"),onClick:r,children:e.jsx("span",{className:"set-switch-knob"})})]})}function za({chat:t,send:s,onClose:n}){const r=oe(),o=t.settings,[c,a]=i.useState(""),[l,p]=i.useState("append"),u=i.useRef(!1),[g,h]=i.useState(""),[k,w]=i.useState("append"),T=i.useRef(!1),[P,M]=i.useState(""),x=i.useRef(!1),[S,C]=i.useState("");if(i.useEffect(()=>{o&&(p(o.promptMode),!u.current&&(a(l==="append"||o.customSystemPrompt?o.customSystemPrompt:o.defaultSystemPrompt||""),w(o.visionBridgePromptMode),!T.current&&(h(k==="append"||o.visionBridgePrompt?o.visionBridgePrompt:o.visionBridgeDefaultPrompt||""),x.current||M(o.reviewPrompt))))},[o,l,k]),!o)return null;const D=new Set(o.disabledSkills),_=new Set(o.disabledExtensions),v=j=>s({type:"set_settings",...j}),N=j=>{const F=new Set(D);F.has(j.name)?F.delete(j.name):F.add(j.name),v({disabledSkills:[...F]})},d=j=>{const F=new Set(_);F.has(j.id)?F.delete(j.id):F.add(j.id),v({disabledExtensions:[...F]})},L=j=>{const F=new Set(o.reviewSkills.filter(K=>!K.enabled).map(K=>K.name));F.has(j.name)?F.delete(j.name):F.add(j.name),v({reviewDisabledSkills:[...F]})},$=()=>{const j=l==="replace"&&o.defaultSystemPrompt&&c===o.defaultSystemPrompt?"":c;v({promptMode:l,customSystemPrompt:j})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal settings-modal",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:n,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(Ye,{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(ht,{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:l,onChange:j=>{const F=j.target.value;p(F),v({promptMode:F})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:r("promptPlaceholder"),value:c,onFocus:()=>u.current=!0,onBlur:()=>{u.current=!1,$()},onChange:j=>a(j.target.value)}),e.jsx("p",{className:"set-hint",children:r(l==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{className:"set-section-icon"}),r("settingsSkills"),e.jsx("span",{className:"set-count",children:o.skills.length})]}),o.skills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:o.skills.map(j=>e.jsx(Ue,{title:j.name,subtitle:j.description,enabled:j.enabled,onToggle:()=>N(j)},j.name))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nn,{className:"set-section-icon"}),r("settingsExtensions"),e.jsx("span",{className:"set-count",children:o.extensions.length})]}),o.extensions.length===0?e.jsx("p",{className:"set-empty",children:r("noExtensions")}):e.jsx("div",{className:"set-list",children:o.extensions.map(j=>e.jsx(Ue,{title:j.name,subtitle:j.path,enabled:j.enabled,onToggle:()=>d(j)},j.id))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ht,{className:"set-section-icon"}),r("settingsReview"),e.jsx("span",{className:"set-count",children:o.reviewSkills.length})]}),e.jsx("p",{className:"set-hint",children:r("settingsReviewDesc")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:r("reviewPromptPlaceholder"),value:P,onFocus:()=>x.current=!0,onBlur:()=>{x.current=!1,v({reviewPrompt:P})},onChange:j=>M(j.target.value)}),e.jsx("p",{className:"set-hint",children:r("reviewPromptHint")}),e.jsx("div",{className:"set-field-label",children:r("settingsReviewSkills")}),o.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:o.reviewSkills.map(j=>e.jsx(Ue,{title:j.name,subtitle:j.description,enabled:j.enabled,onToggle:()=>L(j)},`review-${j.name}`))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(us,{className:"set-section-icon"}),r("settingsVisionBridge")]}),e.jsx(Ue,{title:r("visionBridgeEnabled"),subtitle:r("settingsVisionBridgeDesc"),enabled:o.visionBridgeEnabled,onToggle:()=>v({visionBridgeEnabled:!o.visionBridgeEnabled})}),!o.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r("visionBridgeOffHint")}),o.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:o.visionBridgeModel??"",onChange:j=>v({visionBridgeModel:j.target.value||null}),children:[e.jsx("option",{value:"",children:r("visionBridgeAuto")}),o.visionModels.map(j=>e.jsx("option",{value:`${j.provider}/${j.id}`,children:j.label},`${j.provider}/${j.id}`))]})]}),o.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:k,onChange:j=>{const F=j.target.value;w(F),v({visionBridgePromptMode:F})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),o.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:r("visionBridgePromptPlaceholder"),value:g,onFocus:()=>T.current=!0,onBlur:()=>{T.current=!1;const j=k==="replace"&&o.visionBridgeDefaultPrompt&&g===o.visionBridgeDefaultPrompt?"":g;v({visionBridgePromptMode:k,visionBridgePrompt:j})},onChange:j=>h(j.target.value)}),o.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r(k==="append"?"visionBridgePromptAppendHint":"visionBridgePromptReplaceHint")}),o.visionBridgeEnabled&&(o.visionModels.length===0?e.jsx("p",{className:"set-hint",children:r("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:r("visionBridgeCurrent",{model:o.visionBridgeModel??r("visionBridgeAuto")})}))]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ye,{className:"set-section-icon"}),r("settingsPresets"),e.jsx("span",{className:"set-count",children:o.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:r("presetNamePlaceholder"),value:S,onChange:j=>C(j.target.value),onKeyDown:j=>{j.key==="Enter"&&S.trim()&&(s({type:"save_preset",name:S.trim()}),C(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!S.trim(),onClick:()=>{s({type:"save_preset",name:S.trim()}),C("")},children:[e.jsx(Be,{})," ",r("saveAsPreset")]})]}),o.presets.length===0?e.jsx("p",{className:"set-empty",children:r("noPresets")}):e.jsx("div",{className:"set-list",children:o.presets.map(j=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:j.name}),e.jsxs("div",{className:"set-row-desc",children:[j.promptMode==="replace"?r("promptModeReplace"):r("promptModeAppend"),j.disabledSkills.length>0&&` · ${r("settingsSkills")} ${j.disabledSkills.length}`,j.disabledExtensions.length>0&&` · ${r("settingsExtensions")} ${j.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:j.name}),children:r("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:r("deletePreset"),onClick:()=>s({type:"delete_preset",name:j.name}),children:e.jsx(ze,{})})]})]},j.name))})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:n,children:r("close")})})]})})}function Ka(t,s){const n=Math.max(0,Date.now()-t),r=Math.floor(n/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const o=Math.floor(r/60);return o<24?s("bgTaskHours",{n:o}):s("bgTaskDays",{n:Math.floor(o/24)})}function Va({servers:t,send:s,onClose:n}){const r=oe(),[o,c]=i.useState(new Set),a=l=>c(p=>{const u=new Set(p);return u.has(l)?u.delete(l):u.add(l),u});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(et,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:n,children:e.jsx(Se,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(et,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("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:r("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:[r("bgTaskPid")," ",l.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",Ka(l.since,r)]})]}),l.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${o.has(l.port)?"open":""}`,title:`${r("bgTaskCommand")}: ${l.command}`,onClick:()=>a(l.port),children:[e.jsx(st,{}),e.jsx("code",{children:l.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s({type:"kill_background_server",port:l.port}),children:[e.jsx(Qe,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},l.port))}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(jt,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(Qe,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function qe(t,s){return t.toLowerCase().includes(s)}function Ga({send:t,sessions:s,projects:n,cwd:r,fileSearch:o,onClose:c,onSwitchSession:a,onSwitchProject:l,onPreviewFile:p}){const u=oe(),g=i.useRef(null),[h,k]=i.useState(""),w=i.useDeferredValue(h),[T,P]=i.useState(0),M=i.useRef(1),x=i.useRef(0),S=i.useRef(null);i.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var m;return(m=g.current)==null?void 0:m.focus()})},[]);const[C,D]=i.useState(!1);i.useEffect(()=>{S.current&&clearTimeout(S.current);const m=w.trim();if(m)return S.current=setTimeout(()=>{const R=++M.current;x.current=R,D(!0),t({type:"search_files",reqId:R,query:m})},300),()=>{S.current&&clearTimeout(S.current)}},[w]);const _=w.trim().toLowerCase(),v=i.useMemo(()=>_?s.filter(m=>qe(m.firstMessage??"",_)||qe(m.name??"",_)||qe(m.path.split(/[\\/]/).pop()??"",_)).slice(0,20):[],[s,_]),N=i.useMemo(()=>_?n.filter(m=>qe(m.path,_)).slice(0,10):[],[n,_]),d=i.useMemo(()=>!_||!o||o.reqId!==x.current||!o.ok?[]:o.results,[o,_]);i.useEffect(()=>{o&&o.reqId===x.current&&x.current!==0&&D(!1)},[o]);const L=!!o&&o.ok&&o.truncated,$=i.useMemo(()=>[...v.map(m=>({kind:"session",path:m.path})),...N.map(m=>({kind:"project",path:m.path})),...d.filter(m=>m.type==="file").map(m=>({kind:"file",path:m.path,name:m.name}))],[v,N,d]);i.useEffect(()=>{P(0)},[w]);const j=i.useCallback(m=>{m&&(m.kind==="session"?a(m.path):m.kind==="project"?l(m.path):p(m.path,m.name),c())},[a,l,p,c]);i.useEffect(()=>{const m=R=>{R.key==="Escape"?(R.preventDefault(),R.stopPropagation(),c()):R.key==="ArrowDown"?(R.preventDefault(),P(E=>Math.min(E+1,$.length-1))):R.key==="ArrowUp"?(R.preventDefault(),P(E=>Math.max(E-1,0))):R.key==="Enter"&&(R.preventDefault(),j($[T]))};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[$,T,j,c]);const F=v.length+N.length+d.length,K=(m,R,E)=>e.jsxs("div",{className:"gs-section-head",children:[E,e.jsx("span",{children:m}),e.jsx("em",{children:R})]});let Y=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:c,children:e.jsxs("div",{className:"gs-modal",onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(Xe,{}),e.jsx("input",{ref:g,type:"text",value:h,placeholder:u("gsPlaceholder"),onChange:m=>k(m.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:u("close"),onClick:c,children:e.jsx(Se,{})})]}),e.jsxs("div",{className:"gs-results",children:[!_&&e.jsx("div",{className:"gs-empty",children:u("gsHint")}),_&&F===0&&!L&&e.jsx("div",{className:"gs-empty",children:u(C?"gsSearching":"gsNoResults")}),v.length>0&&e.jsxs("div",{className:"gs-section",children:[K(u("gsSessions"),v.length,e.jsx(Ze,{})),v.map(m=>{Y++;const R=Y;return e.jsxs("button",{type:"button",className:R===T?"gs-item active":"gs-item",onMouseEnter:()=>P(R),onClick:()=>j({kind:"session",path:m.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[m.name||m.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:m.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:m.firstMessage})]},m.path)})]}),N.length>0&&e.jsxs("div",{className:"gs-section",children:[K(u("gsProjects"),N.length,e.jsx(De,{})),N.map(m=>{Y++;const R=Y,E=r&&m.path===r;return e.jsxs("button",{type:"button",className:R===T?"gs-item active":"gs-item",onMouseEnter:()=>P(R),onClick:()=>j({kind:"project",path:m.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[m.path.split(/[\\/]/).pop(),E&&e.jsx("em",{className:"gs-item-meta",children:u("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:m.path})]},m.path)})]}),(d.length>0||_&&L)&&e.jsxs("div",{className:"gs-section",children:[K(u("gsFiles"),d.length,e.jsx(hn,{})),d.map(m=>{Y++;const R=Y;return e.jsxs("button",{type:"button",className:R===T?"gs-item active":"gs-item",disabled:m.type==="dir",title:m.type==="dir"?void 0:u("gsOpenPreview"),onMouseEnter:()=>P(R),onClick:()=>{m.type==="file"&&j({kind:"file",path:m.path,name:m.name})},children:[e.jsx("span",{className:"gs-item-title",children:m.name}),e.jsx("span",{className:"gs-item-sub",children:m.path})]},`${m.type}:${m.path}`)}),L&&e.jsx("div",{className:"gs-truncated",children:u("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",u("gsNavigate")]}),e.jsxs("span",{children:["Enter ",u("gsOpen")]}),e.jsxs("span",{children:["Esc ",u("gsCloseHint")]})]})]})})}const mt=5e3;function Ja({file:t,content:s,send:n,onAddLines:r,onAttach:o,onClose:c}){const a=oe(),[l,p]=i.useState(null),[u,g]=i.useState(!1),[h,k]=i.useState(null),[w,T]=i.useState(!1),[P,M]=i.useState(!1),[x,S]=i.useState(!1),[C,D]=i.useState(""),[_,v]=i.useState(!0),N=i.useRef(!1),[d,L]=i.useState(!0),[$,j]=i.useState(!1),[F,K]=i.useState(100),Y=i.useRef(0),m=i.useRef(!1),R=i.useRef(null);i.useEffect(()=>{g(!0),p(null),k(null),S(!1),D(""),v(!0),N.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),i.useEffect(()=>{s&&s.path===t.path&&(p(s),x||D(s.text),g(!1))},[s,x,t.path]),i.useEffect(()=>{const A=z=>{if(z.key==="Escape"){me();return}if((z.ctrlKey||z.metaKey)&&z.key.toLowerCase()==="s"&&x){z.preventDefault(),xe();return}const ee=z.target,je=ee&&(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable);(z.ctrlKey||z.metaKey)&&z.key.toLowerCase()==="a"&&!je&&(z.preventDefault(),le())};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[c,l,x,C]),i.useEffect(()=>{const A=()=>{m.current=!1,T(!1)};return window.addEventListener("mouseup",A),()=>window.removeEventListener("mouseup",A)},[]);const E=i.useMemo(()=>{if(!l)return[];const A=l.text.split(`
19
+ `);return A.length>0&&A[A.length-1]===""&&A.pop(),A.slice(0,mt)},[l]),H=(l==null?void 0:l.lines)??0,U=H>mt,te=(A,z)=>{if(z){const ee=Y.current>0?Y.current:A;k({start:Math.min(ee,A),end:Math.max(ee,A)})}else Y.current=A,k({start:A,end:A})},le=()=>{E.length!==0&&(Y.current=1,k({start:1,end:E.length}))},Q=()=>{h&&(r(t.path,t.name,h.start,h.end),M(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>M(!1),1400))},se=l!==null&&l.kind==="text"&&!l.binary&&!l.truncated,ce=()=>{D((l==null?void 0:l.text)??""),S(!1),N.current&&v(!0)},pe=()=>{if(x){if(C!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges")))return;ce();return}!se||!l||(N.current=pt(t.name)&&_,pt(t.name)&&v(!1),k(null),D(l.text),S(!0))},xe=()=>{!x||!l||!se||n({type:"write_file",path:t.path,text:C})&&(S(!1),N.current&&v(!0),k(null))},me=()=>{x&&C!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges"))||c()},ge=A=>{K(Math.min(200,Math.max(50,A)))},be=h?h.end-h.start+1:0,ue=(l==null?void 0:l.binary)??!1,ve=(l==null?void 0:l.truncated)??!1,ne=(l==null?void 0:l.kind)??"text",f=pt(t.name),O=f&&_&&!x&&ne==="text"&&!ue,ae=A=>rt(`/api/file?clientId=${encodeURIComponent(wt())}&path=${encodeURIComponent(A)}`);return e.jsx("div",{className:`fp-overlay ${$?"fullscreen":""}`,onMouseDown:A=>{A.target===A.currentTarget&&me()},children:e.jsxs("div",{className:`fp ${$?"fullscreen":""}`,style:{"--fp-zoom":F/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&&ne==="text"&&!ue&&a("fileLines",{n:H}),l&&` · ${Qa(l.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[f&&ne==="text"&&!ue&&l&&e.jsx("button",{type:"button",className:`fp-attach markdown ${_?"on":""}`,"data-tip":a(_?"showMarkdownSource":"showMarkdownPreview"),disabled:x,onClick:()=>v(A=>!A),children:_?e.jsx(us,{}):e.jsx(fn,{})}),ne==="text"&&!ue&&l&&e.jsx("button",{type:"button",className:`fp-attach edit ${x?"on":""}`,"data-tip":a(ve?"fileEditTruncated":x?"exitEditFile":"editFile"),disabled:!se&&!x,onClick:pe,children:e.jsx(ft,{})}),ne==="text"&&!ue&&!O&&e.jsx("button",{type:"button",className:`fp-attach wrap ${d?"on":""}`,"data-tip":a(d?"disableWrap":"enableWrap"),onClick:()=>L(A=>!A),children:e.jsx(gn,{})}),ne==="text"&&l&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":a("zoomOut"),disabled:F<=50,onClick:()=>ge(F-10),children:e.jsx(Ys,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:a("resetZoom"),onClick:()=>K(100),children:[F,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":a("zoomIn"),disabled:F>=200,onClick:()=>ge(F+10),children:e.jsx(Xs,{})})]}),ne!=="video"&&ne!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":a("attachInlineTip"),onClick:()=>o(t.path,t.name,"inline"),children:e.jsx(Be,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":a("referenceTip"),onClick:()=>o(t.path,t.name,"reference"),children:e.jsx(gt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${$?"on":""}`,"data-tip":a($?"exitFullscreen":"fullscreen"),onClick:()=>j(A=>!A),children:$?e.jsx(rn,{}):e.jsx(ln,{})}),e.jsx("button",{type:"button",className:"fp-close",title:a("close"),onClick:me,children:e.jsx(Se,{})})]})]}),ve&&ne==="text"&&!ue&&e.jsx("div",{className:"fp-notice",children:a("previewTruncated")}),u&&!l&&e.jsx("div",{className:"fp-empty",children:a("loading")}),!u&&ne==="none"&&!ue&&e.jsx("div",{className:"fp-empty",children:a("previewNotSupported")}),!u&&ne==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:ae(t.path),alt:t.name})}),!u&&ne==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:ae(t.path),controls:!0,preload:"metadata"})}),!u&&O&&l&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(ot,{text:l.text})})}),!u&&ue&&ne!=="image"&&ne!=="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})]}),!u&&x&&ne==="text"&&!ue&&l&&e.jsx("textarea",{className:`fp-editor ${d?"":"no-wrap"}`,value:C,onChange:A=>D(A.target.value),wrap:d?"soft":"off",spellCheck:!1,autoFocus:!0}),!u&&!O&&!x&&ne==="text"&&!ue&&l&&E.length===0&&e.jsx("div",{className:"fp-empty",children:a("emptyFile")}),!u&&!O&&!x&&ne==="text"&&!ue&&E.length>0&&e.jsxs("div",{className:`fp-code ${w?"dragging":""} ${d?"":"no-wrap"}`,onMouseDown:A=>{A.button===0&&A.preventDefault()},children:[E.map((A,z)=>{const ee=z+1,je=h!==null&&ee>=h.start&&ee<=h.end;return e.jsxs("div",{className:`fp-line ${je?"sel":""}`,onMouseDown:Ne=>{Ne.button===0&&(te(ee,Ne.shiftKey),m.current=!0,T(!0))},onMouseEnter:()=>{m.current&&te(ee,!0)},children:[e.jsx("span",{className:"fp-num",children:ee}),e.jsx("span",{className:"fp-code-text",children:A})]},ee)}),U&&e.jsx("div",{className:"fp-lines-note",children:a("previewLinesTruncated",{n:mt})})]}),e.jsx("div",{className:"fp-foot",children:x?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:pe,children:a("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:C===((l==null?void 0:l.text)??""),onClick:xe,children:[e.jsx(sn,{})," ",a("saveFile")]})]})]}):!O&&ne==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:h?a("selectedRange",{n:be,start:h.start,end:h.end}):a("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:E.length===0,onClick:le,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||ue,onClick:Q,children:[P?e.jsx(kt,{}):null,a(P?"addedToChat":"addToChat")]})]})]})})]})})}function pt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Qa(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Ms="pi-web-sounds",Ae={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function Es(){try{const t=localStorage.getItem(Ms);if(!t)return{...Ae};const s=JSON.parse(t),n={...Ae,...s};for(const r of["enabled","question","done","start","error"])typeof n[r]!="boolean"&&(n[r]=Ae[r]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=Ae.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...Ae}}}function Ya(t){try{localStorage.setItem(Ms,JSON.stringify(t))}catch{}}let $e=null;function Xa(){try{if(!$e){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;$e=new t}return $e.state==="suspended"&&$e.resume(),$e}catch{return null}}const Za=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],ei=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],ti=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],si=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],ni={question:Za,done:ei,start:ti,error:si};function ai(t,s,n){const r=t.createOscillator(),o=t.createGain();r.type=s.type,r.frequency.value=s.freq;const c=t.currentTime+s.start,a=Math.max(1e-4,s.peak*n);o.gain.setValueAtTime(1e-4,c),o.gain.exponentialRampToValueAtTime(a,c+.012),o.gain.exponentialRampToValueAtTime(1e-4,c+s.dur),r.connect(o),o.connect(t.destination),r.start(c),r.stop(c+s.dur+.05)}function Oe(t,s=Es()){if(!s.enabled||!s[t])return;const n=Xa();if(!n)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const o of ni[t])ai(n,o,r)}const yt="pi-web-ui:theme",Rs="dark",ts="theme-stylesheet",ss="pi-web-ui:theme-change";function Ls(){try{const t=localStorage.getItem(yt);if(t&&t!==Rs)return t}catch{}return null}function ii(t){try{t?localStorage.setItem(yt,t):localStorage.removeItem(yt)}catch{}}function Is(t){let s=document.getElementById(ts);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(ss));return}s||(s=document.createElement("link"),s.id=ts,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(ss))}async function ri(){try{const t=await fetch(rt("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function oi(){const[t,s]=i.useState([]),[n,r]=i.useState(()=>Ls());return i.useEffect(()=>{let c=!1;return ri().then(a=>{c||s(a)}),()=>{c=!0}},[]),i.useEffect(()=>{Is(n),ii(n)},[n]),{themes:t,theme:n,switchTheme:c=>r(c===Rs?null:c)}}function gi(){const t=getComputedStyle(document.documentElement),s=(n,r)=>t.getPropertyValue(n).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const li=i.lazy(()=>Us(()=>import("./TerminalPanel-CMBWruhs.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function ci({notice:t,onDismiss:s}){const n=oe(),[r,o]=i.useState(!1);i.useEffect(()=>{if(r)return;const a=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(a)},[r,t.id,t.level,s]);const c=t.level==="error"?jn:t.level==="warning"?yn:mn;return e.jsxs("div",{className:`notice notice-${t.level}${r?" paused":""}`,role:"status",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[e.jsx(c,{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 di=[],Ps=180,Bs=520,Ds=240,Fs=t=>`pi-web-ui:${t}-panel-width`;function ns(t){const s=Number(localStorage.getItem(Fs(t)));return Number.isFinite(s)&&s>=Ps&&s<=Bs?s:Ds}function as({side:t,width:s,onResize:n}){const r=oe(),o=i.useCallback(c=>{c.preventDefault();const a=c.clientX,l=s;let p=l;const u=h=>{const k=t==="left"?h.clientX-a:a-h.clientX;p=Math.min(Bs,Math.max(Ps,Math.round(l+k))),n(p)},g=()=>{window.removeEventListener("pointermove",u),window.removeEventListener("pointerup",g),document.body.classList.remove("panel-resizing"),localStorage.setItem(Fs(t),String(p))};window.addEventListener("pointermove",u),window.addEventListener("pointerup",g),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:o,onDoubleClick:()=>n(Ds)})}function ui(){var he,we,Fe,b,X,V,fe,re,ye,Te,Tt,Mt,Et;const t=oe(),{chat:s,send:n,dismissNotice:r,pushNotice:o,terminal:c}=An(),[a,l]=i.useState([]),[p,u]=i.useState(null),[g,h]=i.useState("chat"),[k,w]=i.useState(()=>ns("left")),[T,P]=i.useState(()=>ns("right")),M=i.useCallback(I=>w(I),[]),x=i.useCallback(I=>P(I),[]),[S,C]=i.useState(null),[D,_]=i.useState(()=>window.matchMedia("(max-width: 768px)").matches);i.useEffect(()=>{const I=window.matchMedia("(max-width: 768px)"),q=de=>_(de.matches);return I.addEventListener("change",q),()=>I.removeEventListener("change",q)},[]);const[v,N]=i.useState(!1),[d,L]=i.useState(!1),[$,j]=i.useState(!1),[F,K]=i.useState(!1),[Y,m]=i.useState(!1);i.useEffect(()=>{const I=q=>{!(q.ctrlKey||q.metaKey)||q.key.toLowerCase()!=="k"||(q.preventDefault(),m(de=>!de))};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[]);const[R,E]=i.useState(Es),{themes:H,theme:U,switchTheme:te}=oi(),le=i.useRef(null),Q=i.useRef(null),se=i.useRef(0),ce=i.useRef(!1);i.useEffect(()=>{Ya(R)},[R]),i.useEffect(()=>{var de;const I=((de=s.state)==null?void 0:de.isStreaming)??!1,q=le.current;le.current=I,q!==null&&(!q&&I?Oe("start",R):q&&!I&&Oe("done",R))},[(he=s.state)==null?void 0:he.isStreaming,R]),i.useEffect(()=>{var q;const I=((q=s.dialog)==null?void 0:q.id)??null;I!==null&&I!==Q.current&&Oe("question",R),Q.current=I},[s.dialog,R]),i.useEffect(()=>{const I=[...s.notices].reverse().find(q=>q.level==="error");I&&I.id!==se.current&&(se.current=I.id,Oe("error",R))},[s.notices,R]);const pe=(I,q,de,Ce=!1,Me)=>{const lt=`${I}|${de}|${Me?`${Me.start}-${Me.end}`:""}`;l(Ee=>Ee.some(_e=>`${_e.path}|${_e.mode}|${_e.lines?`${_e.lines.start}-${_e.lines.end}`:""}`===lt)?Ee:[...Ee,{path:I,name:q,mode:de,isDir:Ce,...Me?{lines:Me}:{}}])},xe=I=>l(q=>q.filter(de=>de.key?de.key!==I:de.path!==I)),me=i.useCallback(I=>(!I.type.startsWith("list_")&&!I.type.startsWith("get_")&&C(null),n(I)),[n]),ge=i.useRef(0),be=i.useRef(0),ue=I=>{var Ce;const q=Date.now();(Ce=s.state)!=null&&Ce.model&&!s.state.model.vision&&q-be.current>1e4&&(be.current=q,o("warning",t("imageNotSupported")));const de=`paste-${++ge.current}`;l(Me=>[...Me,{path:"",key:de,name:I.name,mode:"inline",imageData:I.data,mimeType:I.mimeType}])},ve=async I=>{for(const q of I){const de=await Ia(q);if(!de){o("error",t("imageLoadFailed",{name:q.name}));continue}ue(de)}},ne=20*1024*1024,f=i.useRef(0),O=async I=>{if(I.size>ne){o("warning",t("fileTooLarge",{name:I.name,size:ne/1024/1024}));return}let q;try{q=(await new Promise((Me,lt)=>{const Ee=new FileReader;Ee.onload=()=>Me(Ee.result),Ee.onerror=()=>lt(Ee.error??new Error("read failed")),Ee.readAsDataURL(I)})).replace(/^data:[^;]*;base64,/,"")}catch{o("error",t("fileLoadFailed",{name:I.name}));return}const de=`upload-${++f.current}`;l(Ce=>[...Ce,{path:"",key:de,name:I.name,mode:"inline",fileData:q,size:I.size,mimeType:I.type||void 0}])},ae=async I=>{for(const q of I)Ve(q.type)?await ve([q]):await O(q)},A=i.useCallback((I,q)=>{n({type:"edit_message",messageId:I,text:q})},[n]),z=i.useCallback(()=>L(!0),[]),ee=i.useCallback(()=>l([]),[]),je=i.useCallback(xe,[]),Ne=i.useCallback(ve,[ve]),y=i.useCallback(ae,[ae]),B=(we=s.state)==null?void 0:we.model,J=(Fe=s.state)==null?void 0:Fe.thinkingLevel,G=(b=s.state)==null?void 0:b.availableThinkingLevels,Z=i.useMemo(()=>B?{model:B,thinkingLevel:J??"off",availableThinkingLevels:G??[]}:null,[B,J,G]),ie=i.useCallback(()=>{var I,q;return!s.ready||s.terminals.length!==0?!1:(c.create({id:tt(),conversationId:s.activeConversationId||((I=s.state)==null?void 0:I.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((q=s.state)==null?void 0:q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(X=s.state)==null?void 0:X.cwd,s.terminals.length,t,c]);return i.useEffect(()=>{if(ce.current){if(g!=="terminal"||s.terminals.length!==0){ce.current=!1;return}ie()&&(ce.current=!1)}},[s.terminals.length,ie,g]),e.jsxs("div",{className:"app",onDragOver:I=>I.preventDefault(),onDrop:I=>I.preventDefault(),children:[e.jsx(Tn,{chat:s,send:n,view:g,onViewChange:I=>{ce.current=I==="terminal"&&s.terminals.length===0,ce.current&&ie()&&(ce.current=!1),h(I),C(null)},onOpenPanel:C,onManageModels:()=>L(!0),onOpenSettings:()=>j(!0),onOpenBgTasks:()=>K(!0),onOpenGlobalSearch:()=>m(!0),sound:R,onSoundChange:E,onSoundPreview:I=>Oe(I,R),themes:H,theme:U,onThemeChange:te}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(I=>e.jsx(ci,{notice:I,onDismiss:r},I.id))}),e.jsxs("div",{className:"layout",style:{"--left-w":`${k}px`,"--right-w":`${T}px`},children:[S&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>C(null)}),e.jsxs("div",{className:`view-pane ${g==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${S==="left"?"open":""}`,children:e.jsx(Mn,{send:me,active:!D||S==="left",ready:s.ready,status:s.status,cwd:((V=s.state)==null?void 0:V.cwd)??"",sessionFile:((fe=s.state)==null?void 0:fe.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!D&&e.jsx(as,{side:"left",width:k,onResize:M}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ea,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:A,onKillBash:()=>n({type:"abort_bash"})},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(Ba,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(_a,{dialog:s.dialog,send:n}),e.jsx(Pa,{send:n,ready:s.ready,streaming:((re=s.state)==null?void 0:re.isStreaming)??!1,queueSteering:((ye=s.state)==null?void 0:ye.queue.steering)??0,queueFollowUp:((Te=s.state)==null?void 0:Te.queue.followUp)??0,messages:((Tt=s.state)==null?void 0:Tt.messages)??di,slashCommands:s.slashCommands,modelState:Z,models:s.models,modelsLoading:s.modelsLoading,attachments:a,onRemoveAttachment:je,onAddImageFiles:Ne,onAddLocalFiles:y,onNotice:o,onManageModels:z,onSent:ee})]}),!D&&e.jsx(as,{side:"right",width:T,onResize:x}),e.jsx("div",{className:`panel-drawer drawer-right ${S==="right"?"open":""}`,children:e.jsx(Vn,{send:me,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((Mt=s.state)==null?void 0:Mt.cwd)??"",onAttach:(I,q,de,Ce)=>{C(null),pe(I,q,de,Ce)},onPreview:(I,q)=>{C(null),u({path:I,name:q})},onNotice:(I,q)=>o(I,q)})})]}),e.jsx("div",{className:`view-pane ${g==="terminal"?"":"hidden"}`,children:e.jsx(i.Suspense,{fallback:null,children:e.jsx(li,{chat:s,send:n,terminal:c})})}),e.jsx("div",{className:`view-pane ${g==="git"?"":"hidden"}`,children:e.jsx($a,{chat:s,send:n,terminal:c,active:g==="git",onSwitchToTerminal:()=>h("terminal")})})]}),e.jsx(Da,{chat:s,send:n}),p&&e.jsx(Ja,{file:p,content:s.fileContent,send:n,onAddLines:(I,q,de,Ce)=>pe(I,q,"lines",!1,{start:de,end:Ce}),onAttach:(I,q,de)=>pe(I,q,de),onClose:()=>u(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!v&&!d&&e.jsx(Oa,{send:n,piConfigured:s.state.piConfigured,providers:s.providers,installResult:s.installResult,onClose:()=>N(!0)}),d&&e.jsx(qa,{send:n,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,onClose:()=>L(!1)}),$&&e.jsx(za,{chat:s,send:n,onClose:()=>j(!1)}),F&&e.jsx(Va,{servers:s.bgServers,send:n,onClose:()=>K(!1)}),Y&&e.jsx(Ga,{send:n,sessions:s.sessions,projects:s.projects,cwd:((Et=s.state)==null?void 0:Et.cwd)??"",fileSearch:s.fileSearch,onClose:()=>m(!1),onSwitchSession:I=>{n({type:"switch_session",path:I})},onSwitchProject:I=>{n({type:"set_cwd",path:I})},onPreviewFile:(I,q)=>{u({path:I,name:q})}})]})}En();Is(Ls());Os.createRoot(document.getElementById("root")).render(e.jsx(i.StrictMode,{children:e.jsx(wn,{children:e.jsx(ui,{})})}));export{jt as F,ss as T,Be as a,gi as b,hi as c,_t as d,ze as e,Se as f,on as g,st as h,tt as r,oe as u};