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.
- package/dist/server/agent-service.js +4 -2
- package/dist/server/client-state.js +29 -0
- package/dist/server/index.js +16 -6
- package/dist/server/webui-context.js +17 -3
- package/package.json +96 -96
- package/themes/light.css +6900 -6749
- package/web/dist/assets/{TerminalPanel-D7lQ3g5k.js → TerminalPanel-CMBWruhs.js} +1 -1
- package/web/dist/assets/index-C8YkKrP3.css +10 -0
- package/web/dist/assets/index-DpzPCOcG.js +19 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-BiJTtKxQ.js +0 -18
- package/web/dist/assets/index-DxO8_hl1.css +0 -10
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-D7lQ3g5k.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 Me,a as r,j as e,M as Yt,b as Cs,c as Ss}from"./markdown-DRBrS2Nf.js";import{r as Zt}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"]'))i(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"&&i(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 i(o){if(o.ep)return;o.ep=!0;const c=n(o);fetch(o.href,c)}})();var Ae={},wt;function Ts(){if(wt)return Ae;wt=1;var t=Zt();return Ae.createRoot=t.createRoot,Ae.hydrateRoot=t.hydrateRoot,Ae}var Ms=Ts();const Es="modulepreload",Rs=function(t){return"/"+t},Ct={},Ls=function(s,n,i){let o=Promise.resolve();if(n&&n.length>0){let a=function(u){return Promise.all(u.map(g=>Promise.resolve(g).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),h=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));o=a(n.map(u=>{if(u=Rs(u),u in Ct)return;Ct[u]=!0;const g=u.endsWith(".css"),p=g?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${p}`))return;const k=document.createElement("link");if(k.rel=g?"stylesheet":Es,g||(k.as="script"),k.crossOrigin="",k.href=u,h&&k.setAttribute("nonce",h),document.head.appendChild(k),g)return new Promise((N,M)=>{k.addEventListener("load",N),k.addEventListener("error",()=>M(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 Xt={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},St=Me.createContext&&Me.createContext(Xt),Is=["attr","size","title"];function Ps(t,s){if(t==null)return{};var n,i,o=Bs(t,s);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);for(i=0;i<c.length;i++)n=c[i],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function Bs(t,s){if(t==null)return{};var n={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(s.indexOf(i)!==-1)continue;n[i]=t[i]}return n}function Ke(){return Ke=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Ke.apply(null,arguments)}function Tt(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);s&&(i=i.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,i)}return n}function ze(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Tt(Object(n),!0).forEach(function(i){Ds(t,i,n[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tt(Object(n)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(n,i))})}return t}function Ds(t,s,n){return(s=Fs(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Fs(t){var s=_s(t,"string");return typeof s=="symbol"?s:s+""}function _s(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var i=n.call(t,s);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function es(t){return t&&t.map((s,n)=>Me.createElement(s.tag,ze({key:n},s.attr),es(s.child)))}function U(t){return s=>Me.createElement($s,Ke({attr:ze({},t.attr)},s),es(t.child))}function $s(t){var s=n=>{var i=t.attr,o=t.size,c=t.title,a=Ps(t,Is),l=o||n.size||"1em",h;return n.className&&(h=n.className),t.className&&(h=(h?h+" ":"")+t.className),Me.createElement("svg",Ke({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,i,a,{className:h,style:ze(ze({color:t.color||n.color},n.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),c&&Me.createElement("title",null,c),t.children)};return St!==void 0?Me.createElement(St.Consumer,null,n=>s(n)):s(Xt)}function As(t){return U({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 Os(t){return U({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 ut(t){return U({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 we(t){return U({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 ts(t){return U({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 Hs(t){return U({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 We(t){return U({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"3 6 5 6 21 6"},child:[]},{tag:"path",attr:{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},child:[]},{tag:"line",attr:{x1:"10",y1:"11",x2:"10",y2:"17"},child:[]},{tag:"line",attr:{x1:"14",y1:"11",x2:"14",y2:"17"},child:[]}]})(t)}function Xe(t){return U({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 Mt(t){return U({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 Ws(t){return U({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 Ve(t){return U({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 Ge(t){return U({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 Us(t){return U({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 Je(t){return U({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 qs(t){return U({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 xt(t){return U({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 Le(t){return U({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 ti(t){return U({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 Et(t){return U({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 Ks(t){return U({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 zs(t){return U({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 Vs(t){return U({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 Qe(t){return U({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 Gs(t){return U({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 Js(t){return U({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 Qs(t){return U({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 mt(t){return U({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 Ye(t){return U({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 Ys(t){return U({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 Zs(t){return U({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 Xs(t){return U({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 Rt(t){return U({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 Ue(t){return U({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 Ie(t){return U({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 ss(t){return U({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 en(t){return U({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 ns(t){return U({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 pt(t){return U({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 Lt(t){return U({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 vt(t){return U({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 et(t){return U({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 tn(t){return U({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 as(t){return U({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 sn(t){return U({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 tt(t){return U({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 st(t){return U({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 Ee(t){return U({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 yt(t){return U({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 nn(t){return U({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 an(t){return U({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 is(t){return U({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 rs(t){return U({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 rn(t){return U({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 on(t){return U({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 Te({trigger:t,open:s,onOpenChange:n,children:i,align:o="right",fit:c=!1,direction:a="down",menuClassName:l}){const h=r.useRef(null);return r.useEffect(()=>{if(!s)return;const u=p=>{h.current&&!h.current.contains(p.target)&&n(!1)},g=p=>{p.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:h,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(Ee,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${l??""}`,children:i})]})}function be({active:t,disabled:s=!1,title:n,onClick:i,children:o}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:i,children:o})}const os="pi-web-ui:lang",ln={cancel:"取消",ok:"确定",save:"保存",close:"关闭",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 服务器…"},cn={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",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…"},ls=r.createContext(null);function dn(){try{const t=localStorage.getItem(os);if(t==="zh"||t==="en")return t}catch{}return"zh"}function un({children:t}){const[s,n]=r.useState(dn),i=r.useCallback(a=>{n(a);try{localStorage.setItem(os,a)}catch{}},[]),o=r.useCallback((a,l)=>{let h=cn[a];if(s==="zh"&&(h=ln[a]),l)for(const[u,g]of Object.entries(l))h=h.replaceAll(`{${u}}`,String(g));return h},[s]);r.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const c=r.useMemo(()=>({locale:s,setLocale:i,t:o}),[s,i,o]);return e.jsx(ls.Provider,{value:c,children:t})}function jt(){const t=r.useContext(ls);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function le(){return jt().t}const mn=["off","minimal","low","medium","high","xhigh","max"],cs=r.memo(function({state:s,models:n,modelsLoading:i,send:o,onManageModels:c,compact:a=!1}){const l=le(),h=s==null?void 0:s.model,u=h?`${h.provider}/${h.id}`:null,[g,p]=r.useState(!1),[k,N]=r.useState(!1),[M,I]=r.useState("");r.useEffect(()=>{g||I("")},[g]);const E=r.useMemo(()=>{const x=M.trim().toLowerCase();return x?n.filter(L=>L.name.toLowerCase().includes(x)||L.provider.toLowerCase().includes(x)||L.id.toLowerCase().includes(x)):n},[n,M]),[f,S]=r.useState(!1),T=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,D=mn.map(x=>({value:x,label:l(`thinking.${x}`),supported:T?T.has(x):!0})),w=x=>{var L;return((L=D.find(d=>d.value===x))==null?void 0:L.label)??x};return r.useEffect(()=>{g&&n.length===0&&!f&&!i&&(S(!0),o({type:"list_models"}))},[g,n.length,f,i,o]),r.useEffect(()=>{n.length>0&&S(!1)},[n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(et,{}),e.jsx("span",{className:"chip-model",children:h?h.name:l("selectModel")}),!a&&(h==null?void 0:h.vision)&&e.jsx("span",{className:"chip-vision",title:l("vision"),children:"🖼"}),!a&&h&&e.jsx("span",{className:"chip-sub",children:h.provider})]}),open:g,onOpenChange:p,menuClassName:"dd-menu-model",children:[e.jsx("div",{className:"dd-header",children:l("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(Je,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:l("searchModels"),value:M,onChange:x=>I(x.target.value)})]}),e.jsxs("div",{className:"dd-model-scroll",children:[(f||i)&&e.jsx("div",{className:"dd-loading",children:l("loading")}),n.length===0&&!f&&!i&&e.jsx("div",{className:"dd-loading",children:l("noModels")}),E.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:l("noModelMatches")}),E.map(x=>e.jsx(be,{active:u===x.id,onClick:()=>{u!==x.id&&o({type:"set_model",modelId:x.id}),p(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:x.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:x.provider}),(x.reasoning||x.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[x.reasoning&&e.jsx("span",{className:"dd-model-badge",children:l("reasoning")}),x.vision&&e.jsx("span",{className:"dd-model-badge",children:l("vision")})]})]})]})},x.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:()=>{p(!1),c()},children:l("manageModels")})]})]}),e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ut,{}),e.jsx("span",{className:"chip-sub",children:l("thinkingChip",{level:s?w(s.thinkingLevel):"—"})})]}),open:k,onOpenChange:N,children:[e.jsx("div",{className:"dd-header",children:l("thinkingLevel")}),D.map(x=>e.jsx(be,{active:(s==null?void 0:s.thinkingLevel)===x.value,disabled:!x.supported,title:x.supported?void 0:l("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==x.value&&o({type:"set_thinking",level:x.value}),N(!1)},children:x.label},x.value))]})]})}),pn=[{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 It({settings:t,onChange:s,onPreview:n}){const i=le(),o=c=>s({...t,...c});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:i("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(ts,{className:"sound-icon"}),e.jsx("span",{children:i("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:c=>o({enabled:c.target.checked})})]}),pn.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:i(a)}),e.jsx("span",{className:"sound-desc",children:i(l)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:i("preview"),disabled:!t.enabled,onClick:h=>{h.preventDefault(),n(c)},children:i("preview")}),e.jsx("input",{type:"checkbox",checked:t[c],disabled:!t.enabled,onChange:h=>o({[c]:h.target.checked})})]})]},c)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:i("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 hn({chat:t,send:s,view:n,onViewChange:i,onOpenPanel:o,onManageModels:c,onOpenSettings:a,onOpenBgTasks:l,onOpenGlobalSearch:h,sound:u,onSoundChange:g,onSoundPreview:p,themes:k,theme:N,onThemeChange:M}){var H;const{locale:I,setLocale:E,t:f}=jt(),[S,T]=r.useState(!1),[D,w]=r.useState(!1),[x,L]=r.useState(!1),[d,_]=r.useState(!1),[F,b]=r.useState(!1),[P,V]=r.useState(!1),Y=[{value:"zh",label:f("langZh")},{value:"en",label:f("langEn")}],m=t.ready?f("connected"):t.status==="closed"?f("reconnecting"):f("connecting"),$=t.ready?"ok":"busy",R=()=>{var q,se,ae,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:f("currentVersion")}),e.jsxs("b",{children:["v",((q=t.update)==null?void 0:q.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:f("latestVersion")}),e.jsx("b",{children:t.update===null?f("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:f("checkingUpdate")})]}),((se=t.update)==null?void 0:se.pendingRestart)&&e.jsx("div",{className:"dd-note ok",children:f("updateSuccess")}),t.update&&!t.update.pendingRestart&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:f("upToDate")}),t.update&&!t.update.pendingRestart&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:f("updateAvailable",{version:t.update.latest})}),((ae=t.update)==null?void 0:ae.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:f("updateJustPublished",{version:t.update.latest??""})}),t.updateResult&&!t.updateResult.ok&&e.jsx("div",{className:"dd-note err",children:f("updateFailed",{detail:t.updateResult.detail})}),((Q=t.update)==null?void 0:Q.pendingRestart)&&e.jsx("div",{className:"dd-note",children:f("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?f("checkingUpdate"):f("checkUpdate")}),t.update&&!t.update.pendingRestart&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:`dd-refresh accent ${P?"armed":""}`,onClick:()=>{if(!P){V(!0);return}V(!1),_(!1),b(!1),s({type:"update_app"})},children:f(P?"confirmUpdate":"updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:f("openHistory"),onClick:()=>o("left"),children:e.jsx(Gs,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${$}`,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":f("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="chat",className:n==="chat"?"active":"",onClick:()=>i("chat"),children:[e.jsx(Qe,{}),e.jsx("span",{children:f("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="terminal",className:n==="terminal"?"active":"",onClick:()=>i("terminal"),children:[e.jsx(Xe,{}),e.jsx("span",{children:f("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":n==="git",className:n==="git"?"active":"",onClick:()=>i("git"),children:[e.jsx(Ue,{}),e.jsx("span",{children:f("scmTab")})]})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:f("searchGlobalTip"),onClick:h,children:[e.jsx(Je,{}),e.jsx("span",{className:"chip-sub",children:f("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":f("bgTasksTip"),onClick:l,children:[e.jsx(Ye,{}),e.jsx("span",{className:"chip-sub",children:f("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(cs,{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:f("settingsTitle"),onClick:a,children:[e.jsx(Ge,{}),e.jsx("span",{className:"chip-sub",children:f("settings")})]}),e.jsx(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ts,{}),e.jsx("span",{className:"chip-sub",children:f("sound")})]}),open:S,onOpenChange:T,children:e.jsx(It,{settings:u,onChange:g,onPreview:p})}),e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Xs,{}),e.jsx("span",{className:"chip-sub",children:I==="zh"?f("langZh"):"EN"})]}),open:D,onOpenChange:w,children:[e.jsx("div",{className:"dd-header",children:f("language")}),Y.map(q=>e.jsx(be,{active:I===q.value,onClick:()=>{E(q.value),w(!1)},children:q.label},q.value))]}),e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Ws,{}),e.jsx("span",{className:"chip-sub",children:f("theme")})]}),open:x,onOpenChange:L,children:[e.jsx("div",{className:"dd-header",children:f("theme")}),e.jsx(be,{active:N===null,onClick:()=>{M(null),L(!1)},children:f("themeDefault")}),k.map(q=>e.jsx(be,{active:N===q.id,onClick:()=>{M(q.id),L(!1)},children:q.name},q.id))]}),e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(vt,{}),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:f("updateAvailable",{version:t.update.latest??""})})]}),open:d,onOpenChange:q=>{_(q),V(!1),q&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:f("update")}),R()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:f("githubRepo"),children:e.jsx(Rt,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":f("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(Le,{}),e.jsx("span",{children:f("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Te,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(zs,{}),e.jsx("span",{className:"chip-sub",children:f("more")}),t.update&&!t.update.upToDate&&!t.update.pendingRestart&&e.jsx("span",{className:"update-dot"})]}),open:F,onOpenChange:q=>{b(q),V(!1),q&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:f("sound")}),e.jsx("div",{className:"dd-header",children:f("settings")}),e.jsxs(be,{onClick:()=>{b(!1),a()},children:[e.jsx(Ge,{})," ",f("settingsTitle")]}),e.jsxs(be,{onClick:()=>{b(!1),h()},children:[e.jsx(Je,{})," ",f("searchGlobal")]}),e.jsxs(be,{onClick:()=>{b(!1),l()},children:[e.jsx(Ye,{})," ",f("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(It,{settings:u,onChange:g,onPreview:p}),e.jsx("div",{className:"dd-header",children:f("language")}),Y.map(q=>e.jsx(be,{active:I===q.value,onClick:()=>E(q.value),children:q.label},q.value)),e.jsx("div",{className:"dd-header",children:f("theme")}),e.jsx(be,{active:N===null,onClick:()=>{M(null),b(!1)},children:f("themeDefault")}),k.map(q=>e.jsx(be,{active:N===q.id,onClick:()=>{M(q.id),b(!1)},children:q.name},q.id)),e.jsx("div",{className:"dd-header",children:f("update")}),R(),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(Rt,{})," ",f("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:f("openFiles"),onClick:()=>o("right"),children:e.jsx(Ie,{})})]})]})}function Pt(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 gn=r.memo(function({ready:s,status:n,cwd:i,sessionFile:o,conversations:c,sessions:a,projects:l,activeConversationId:h,send:u,active:g}){const p=le(),k=o,N=i;r.useEffect(()=>{!g||!s||n!=="open"||i&&(u({type:"list_sessions"}),u({type:"list_projects"}))},[g,s,n,i,u]);const M=E=>{const f=E.name||E.firstMessage.trim();return f.length>0?f:p("emptyChat")},I=E=>E.split(/[\\/]/).pop()||E;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:p("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:l.map(E=>{const f=N===E.path;return e.jsxs("button",{type:"button",className:`project-item ${f?"active":""}`,title:E.path,onClick:()=>{f||u({type:"set_cwd",path:E.path})},children:[e.jsx(Ie,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:I(E.path)}),e.jsx("span",{className:"project-path",children:E.path})]}),e.jsx("span",{className:"project-time",children:Pt(E.lastUsed)})]},E.path)})})]}),c.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:p("runningConversations")}),c.map(E=>{const f=h===E.id;return e.jsxs("button",{type:"button",className:`session-item ${f?"active":""}`,title:E.title,onClick:()=>{f||u({type:"switch_conversation",id:E.id})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:E.title}),e.jsx("span",{className:"session-sub",children:f?p("current"):p("messageCount",{n:E.messageCount})})]}),E.isStreaming&&e.jsx("span",{className:"conv-streaming",title:p("streaming")})]},E.id)}),e.jsx("div",{className:"panel-section-divider"})]}),e.jsxs("div",{className:"panel-sessions",children:[e.jsx("div",{className:"panel-section-title",children:p("historySessions")}),e.jsxs("div",{className:"sessions-scroll",children:[a.length===0&&e.jsx("div",{className:"panel-empty",children:p("noHistory")}),a.map(E=>{const f=k===E.path;return e.jsxs("button",{type:"button",className:`session-item ${f?"active":""}`,title:E.path,onClick:()=>{f||u({type:"switch_session",path:E.path})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:M(E)}),e.jsxs("span",{className:"session-sub",children:[f?p("current"):p("messageCount",{n:E.messageCount}),E.source==="tui"&&e.jsx("span",{className:"session-src",title:p("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:Pt(E.modified)})]},E.path)})]})]})]})});function Ze(){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 ds="pi-web-ui:token";function fn(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(ds,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function xn(){try{return localStorage.getItem(ds)??""}catch{return""}}function nt(t){const s=xn();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function vn(t,s){const n=s.assistantMessageEvent,i=t.stats.tokens,o=s.usage!==null?{...i,...s.usage}:i,c=o===i?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,h=l&&l.id===s.messageId?l:{id:s.messageId,content:[]},u=[...h.content],g=n.type==="thinking_delta"?"thinking":"text",p=n.contentIndex??u.length-1;return p>=0&&p<u.length&&u[p].type===g?u[p]=g==="thinking"?{type:"thinking",thinking:(u[p].thinking??"")+a}:{type:"text",text:(u[p].text??"")+a}:u.push(g==="thinking"?{type:"thinking",thinking:a}:{type:"text",text:a}),{...t,stats:c,streamingMessage:{...h,id:s.messageId,content:u}}}const yn=3,rt=2e5,jn=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 kn(){const t=new Map,s=new Map,n=(i,o)=>`${i}:${o}`;return{write(i,o,c){const a=n(i,o),l=t.get(a);if(l&&l.size>0){for(const g of l)try{g.write(c)}catch{}return}const h=s.get(a)??"",u=h.length+c.length>jn?c:h+c;s.set(a,u)},register(i,o,c){const a=n(i,o);let l=t.get(a);l||(l=new Set,t.set(a,l)),l.add(c);const h=s.get(a);if(h){try{c.write(h)}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 Bt(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 i=!1;for(const o of t.keys())n.has(o)&&(t.delete(o),i=!0);return i?new Map(t):t}function Dt(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 i=!1;for(const o of t.keys())n.has(o)&&(t.delete(o),i=!0);return i?new Map(t):t}function Nn(t,s){var n,i,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!==yn};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Bt(t.liveOutputs,s.state),toolStatuses:Dt(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 h={...a,...l.state,messages:l.appended.length>0?[...a.messages,...l.appended]:a.messages};return{...t,ready:!0,state:h,activeConversationId:h.conversationId,liveOutputs:Bt(t.liveOutputs,h),toolStatuses:Dt(t.toolStatuses,h)}}case"tool_delta":{const a=t.liveOutputs.get(s.toolCallId),l=((a==null?void 0:a.text)??"")+s.delta,h=l.length>rt?`…[前 ${l.length-rt} 字符已省略]…
|
|
3
|
-
`+l.slice(l.length-rt):l,u=new Map(t.liveOutputs);return u.set(s.toolCallId,{toolName:s.toolName,text:h}),{...t,liveOutputs:u}}case"message_delta":{const a=t.state;return!a||a.conversationId!==s.msg.conversationId?t:{...t,state:vn(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||((i=t.state)==null?void 0:i.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 Ft="pi-web-client-id";let ot=null;function bt(){if(ot)return ot;let t=null;try{t=sessionStorage.getItem(Ft),t||(t=Ze(),sessionStorage.setItem(Ft,t))}catch{t=t??Ze()}return ot=t,t}function wn(){const t=location.protocol==="https:"?"wss:":"ws:";return nt(`${t}//${location.host}/ws`)}function Cn(){const[t,s]=r.useReducer(Nn,{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=r.useRef(null),i=r.useRef(kn()),o=r.useRef(0),c=r.useRef(null),a=r.useRef(!0),l=r.useRef(0),h=r.useRef(0),u=r.useRef(new Map),g=r.useRef(null),p=()=>{g.current||(g.current=setTimeout(()=>{g.current=null;const x=n.current;x&&x.readyState===WebSocket.OPEN&&x.send(JSON.stringify({type:"get_state"}))},300))},k=(x,L)=>{var F;const d=u.current,_=d.get(x);if(_!==void 0&&L!==_+1){const b=w.current.chat,P=b.activeConversationId||((F=b.state)==null?void 0:F.conversationId);x===P&&p()}d.set(x,L)},N=r.useCallback((x,L)=>{const d=++h.current;s({type:"notice",notice:{id:d,level:x,text:L}})},[]),M=r.useCallback(x=>{const L=n.current;return L&&L.readyState===WebSocket.OPEN?(L.send(JSON.stringify(x)),!0):!1},[]),I=r.useCallback(()=>{if(!a.current)return;s({type:"status",status:"connecting"});const x=new WebSocket(wn());n.current=x,x.onopen=()=>{n.current===x&&(s({type:"status",status:"open"}),o.current=0,l.current=Date.now(),x.send(JSON.stringify({type:"hello",clientId:bt()})))},x.onmessage=L=>{if(n.current!==x)return;l.current=Date.now();let d;try{d=JSON.parse(L.data)}catch{return}switch(d.type){case"ready":s({type:"ready",serverVersion:d.serverVersion,protocolVersion:d.protocolVersion}),x.send(JSON.stringify({type:"get_state"})),x.send(JSON.stringify({type:"list_files"})),x.send(JSON.stringify({type:"list_models"})),x.send(JSON.stringify({type:"list_commands"})),x.send(JSON.stringify({type:"get_commands"})),x.send(JSON.stringify({type:"check_update"}));break;case"snapshot":u.current=new Map,s({type:"snapshot",state:d.state});break;case"snapshot_delta":{const _=w.current.chat.state;(!_||_.conversationId!==d.conversationId||_.rev!==d.baseRev)&&p(),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 _=++h.current;s({type:"notice",notice:{id:_,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":i.current.write(d.conversationId??w.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}},x.onclose=()=>{if(n.current===x&&(n.current=null),i.current.clear(),!a.current||n.current&&n.current!==x)return;s({type:"status",status:"closed"});const L=Math.min(1e3*2**o.current,1e4);o.current+=1,c.current=setTimeout(()=>{c.current=null,I()},L)},x.onerror=()=>{}},[]);r.useEffect(()=>{a.current=!0,I();const x=setInterval(()=>{if(!a.current)return;const L=n.current;L&&L.readyState===WebSocket.OPEN&&Date.now()-l.current>3e4&&L.close()},5e3);return()=>{var L;a.current=!1,clearInterval(x),c.current&&(clearTimeout(c.current),c.current=null),(L=n.current)==null||L.close(),n.current=null}},[I]);const E=r.useCallback(x=>s({type:"dismiss_notice",id:x}),[]),f=r.useCallback(x=>s({type:"terminal_add",meta:x}),[]),S=r.useCallback(x=>s({type:"terminal_remove",id:x}),[]),T=r.useCallback(x=>s({type:"terminal_restart",terminalId:x}),[]),D=r.useCallback((x,L,d)=>i.current.register(x,L,d),[]),w=r.useRef({chat:t,send:M,pushNotice:N,dismissNotice:E,terminal:{create:f,close:S,register:D,restart:T}});return w.current={chat:t,send:M,pushNotice:N,dismissNotice:E,terminal:{create:f,close:S,register:D,restart:T}},w.current}const Sn=200*1024*1024,Tn=/windows/i.test(navigator.userAgent),Mn=/[<>:"/\\|?*\u0000-\u001f]/g,En=/[. ]+$/,Rn=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Ln(t){const s=t.replace(Mn,"_").replace(En,"");return s?Rn.test(s)?`_${s}`:s:"_"}function _t(t,s=!0){const n=new URLSearchParams({clientId:bt(),path:t,...s?{download:"1"}:{}});return nt(`/api/file?${n}`)}async function In(t,s){const n=Tn?Ln(s):s;try{const i=await fetch(_t(t));if(!i.ok)return{ok:!1,cancelled:!1,error:await i.text().catch(()=>"")||(i.status===404?"文件不存在":`HTTP ${i.status}`)};if(Number(i.headers.get("content-length")??"0")>Sn)return window.location.assign(_t(t)),{ok:!0};const c=await i.blob();return window.showSaveFilePicker&&window.isSecureContext?Pn(c,n):ht(c,n)}catch(i){return{ok:!1,cancelled:!1,error:i instanceof Error?i.message:String(i)}}}async function Pn(t,s){let n;const i=window.showSaveFilePicker;if(!i)return ht(t,s);try{n=await i({suggestedName:s})}catch(o){return o instanceof DOMException&&o.name==="AbortError"?{ok:!1,cancelled:!0}:ht(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 ht(t,s){const n=URL.createObjectURL(t),i=document.createElement("a");return i.href=n,i.download=s,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const Bn=r.memo(function({files:s,fileChanged:n,widgets:i,cwd:o,send:c,onAttach:a,onPreview:l,onNotice:h}){const u=le(),[g,p]=r.useState(""),[k,N]=r.useState(!1),M=1e4,I=r.useRef(0),E=r.useRef(void 0),f=r.useCallback((w,x)=>{const L=++I.current;p(w),x!=null&&x.silent||N(!0),c({type:"list_files",path:w===""?void 0:w})||I.current===L&&N(!1)},[c]);r.useEffect(()=>{s&&s.path===g&&N(!1)},[s,g]),r.useEffect(()=>{if(o!==E.current){E.current=o,f("",{silent:!0});return}const w=setInterval(()=>{document.visibilityState!=="hidden"&&f(g,{silent:!0})},M);return()=>clearInterval(w)},[o,g,f]),r.useEffect(()=>{n&&n.path===g&&f(g,{silent:!0})},[n,g,f]);const S=w=>f(w),T=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&f(s.parent)},D=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:()=>f(""),children:u("rootDir")}),D.map((w,x)=>{const L=D.slice(0,x+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(st,{}),e.jsx("button",{type:"button",className:`crumb ${L===g?"active":""}`,onClick:()=>f(L),children:w})]},L)})]}),e.jsxs("div",{className:"panel-body",children:[k&&e.jsx("div",{className:"panel-empty",children:u("loading")}),!k&&s&&s.path===g&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:T,children:[e.jsx(Ie,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(w=>w.type==="dir"?e.jsxs("div",{className:"file-item dir",children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>S(w.path),children:[e.jsx(Ie,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":u("linkFolderTip"),onClick:()=>a(w.path,w.name,"reference",!0),children:e.jsx(mt,{})})]},w.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${w.path} — ${u("previewFile")}`,onClick:()=>l(w.path,w.name),children:[e.jsx(ss,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":u("downloadFile"),onClick:()=>{In(w.path,w.name).then(x=>{x.ok||x.cancelled||h("error",u("downloadFailed",{error:x.error}))})},children:e.jsx(vt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":u("attachInlineTip"),onClick:()=>a(w.path,w.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":u("referenceTip"),onClick:()=>a(w.path,w.name,"reference"),children:e.jsx(mt,{})})]},w.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:u("filesTruncated")})]}),!k&&!s&&e.jsx("div",{className:"panel-empty",children:u("noFiles")})]}),i.filter(w=>w.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:i.filter(w=>w.lines.length>0).map(w=>e.jsxs("div",{className:"widget",children:[e.jsx("div",{className:"widget-title",children:w.key}),e.jsx("pre",{className:"widget-lines",children:w.lines.join(`
|
|
4
|
-
`)})]},w.key))})]})});var $t=Zt();const Dn=r.memo(function({text:s}){const n=le(),[i,o]=r.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:i?e.jsx(yt,{}):e.jsx(as,{})}):null}),us=[Ss],ms=[[Cs,{detect:!0,ignoreMissing:!0}]];function ps({text:t}){return e.jsx(Yt,{remarkPlugins:us,rehypePlugins:ms,components:{pre:Fn},children:t})}const at=r.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(ps,{text:s})})});function Fn({children:t,...s}){return e.jsxs("div",{className:"codeblock",children:[e.jsx(Dn,{text:gt(t)}),e.jsx("pre",{...s,children:t})]})}function gt(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(gt).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return gt(s==null?void 0:s.children)}return""}const _n=/^\s{0,3}(`{3,}|~{3,})/,$n=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function lt(t){return t.trim()===""}function At(t){const s=_n.exec(t);return s?s[1]:null}function An(t){const s=t.split(`
|
|
5
|
-
`),n=[];let i=[],o=null;for(let c=0;c<s.length;c++){const a=s[c];if(o!==null){const h=At(a);h&&h[0]===o[0]&&h.length>=o.length&&(o=null),i.push(a);continue}const l=At(a);if(l&&!lt(a)){o=l,i.push(a);continue}if(lt(a)){let h=c;for(;h<s.length&<(s[h]);)h++;if(!(h<s.length&&$n.test(s[h]))&&i.length>0){n.push(i.join(`
|
|
6
|
-
`)),i=[];continue}i.push(a);continue}i.push(a)}return{frozen:n,active:i.join(`
|
|
7
|
-
`),inFence:o!==null}}const On=r.memo(function({text:s}){return e.jsx(Yt,{remarkPlugins:us,rehypePlugins:ms,children:s})}),Ot=200;function Hn({text:t,inFence:s}){const[n,i]=r.useState(t),o=r.useRef(0),c=r.useRef(null);return r.useEffect(()=>{if(s)return;const a=Date.now()-o.current,l=()=>{o.current=Date.now(),i(t)};if(a>=Ot){l();return}return c.current=setTimeout(l,Ot-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(ps,{text:n})}const Wn=r.memo(function({text:s}){const{frozen:n,active:i,inFence:o}=r.useMemo(()=>An(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((c,a)=>e.jsx(On,{text:c},a)),i.length>0&&e.jsx(Hn,{text:i,inFence:o},n.length)]})});function Un({thinking:t,streaming:s}){const n=le(),[i,o]=r.useState(s),c=t.split(`
|
|
8
|
-
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${i?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>o(a=>!a),children:[i?e.jsx(Ee,{}):e.jsx(st,{}),e.jsx(et,{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"})]}):i?n("thinking"):n("thinkingPreview",{preview:c})})]}),i&&e.jsx("div",{className:"thinking-body",children:t})]})}const qn={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function Kn(t){return qn[t]??"🛠"}const zn=r.memo(function({block:s,view:n,onKillBash:i}){var D,w,x,L;const o=le(),[c,a]=r.useState(!0),[l,h]=r.useState(!1),u=!n.result&&n.streaming&&!n.status,g=s.name==="bash"&&u,p=n.result!==void 0,k=!n.result&&!!n.status,N=((D=n.result)==null?void 0:D.isError)??((w=n.status)==null?void 0:w.isError)??!1,M=n.result?n.result.content.map(d=>d.type==="text"?d.text:"").join(""):n.liveOutput??"",I=N?"err":p?"ok":u||k?"run":"idle";let E=o(N?"error":p?"done":u?"running":k?"toolDoneWaitingModel":"toolQueued");const f=k&&((x=n.status)==null?void 0:x.durationMs)!==void 0?Gn(n.status.durationMs):"";k&&f&&(E=`${E} · ${f}`);const S=k&&((L=n.status)==null?void 0:L.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",T=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),h(!0),setTimeout(()=>h(!1),1200))};return e.jsxs("div",{className:`toolcall ${I}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:Kn(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[E,S&&e.jsx("em",{className:"toolcall-exit",children:S})]}),e.jsx("span",{className:"toolcall-spacer"}),g&&i&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:o("stopBashTip"),onClick:i,children:[e.jsx(Ve,{}),e.jsx("span",{children:o("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:o("copyArgs"),onClick:T,children:l?e.jsx(nn,{}):e.jsx(as,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>a(d=>!d),children:c?e.jsx(Ee,{}):e.jsx(st,{})})]}),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(Vn,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),M.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[o(N?"errorOutput":"output"),(u||k)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:M})]}),u&&M.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",o("waitingOutput")]}),k&&M.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",o("waitingModel")]})]})]})});function Vn({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(Xe,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function Gn(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),i=Math.round(s%60);return`${n}m ${String(i).padStart(2,"0")}s`}const Jn=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function kt(t){var n;const s=t.match(Jn);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}function $e(t){return t.type==="text"&&typeof t.text=="string"?t:null}function hs(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function gs(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function fs(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function xs(t){return t.type==="bash"&&typeof t.command=="string"?t:null}const Ht=r.memo(function({message:s,toolResults:n,liveOutputs:i,toolStatuses:o,streaming:c,isLast:a,onEdit:l,onKillBash:h,onCollapse:u,qnIndex:g,qnActive:p,onJump:k}){const N=le(),[M,I]=r.useState(!1),[E,f]=r.useState("");if(s.role==="toolResult")return null;const S=s.role==="custom"&&s.customType==="file",T=s.content.map(P=>{var V;return((V=$e(P))==null?void 0:V.text)??""}).filter(Boolean).join(`
|
|
9
|
-
`),D=s.role==="user"?kt(T):null,w=D?D.userMessage??`skill:${D.name}`:T.split(`
|
|
10
|
-
`).join(" ").trim(),x=c&&a&&s.content.length===0,L=s.role==="user"&&!c&&!x&&!!l,d=()=>{f(D?`/skill:${D.name}${D.userMessage?` ${D.userMessage}`:""}`:s.content.map(P=>{var V;return((V=$e(P))==null?void 0:V.text)??""}).filter(Boolean).join(`
|
|
11
|
-
`)),I(!0)},_=()=>{const P=E.trim();P&&(l==null||l(s.id,P),I(!1))},F=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),b=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${F?" msg-goal-review":""}`,"data-role":s.role,"data-msg-id":s.id,children:[e.jsxs("div",{className:"msg-meta",children:[e.jsx("span",{className:"msg-role",children:s.role==="custom"?b?N("goalWizardCard"):F?N("goalBarTitle"):s.customType==="file"?N("attachment"):`${N("plugin")} · ${s.customType??N("unknown")}`:vs(s.role,N)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:Xn(s.timestamp)}),u&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:N("collapseMsg"),onClick:()=>u(s.id),children:[e.jsx(tt,{})," ",N("collapseMsg")]}),g!==void 0&&k&&e.jsxs("button",{type:"button",className:`qn-tag ${p?"active":""}`,title:`${g+1}. ${w}`,"aria-label":`${g+1}. ${w}`,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:M?e.jsxs("div",{className:"msg-editor",children:[e.jsx("textarea",{className:"msg-editor-input",value:E,autoFocus:!0,placeholder:N("editPlaceholder"),rows:Math.max(2,Math.min(10,E.split(`
|
|
12
|
-
`).length+1)),onChange:P=>f(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.metaKey||P.ctrlKey)?(P.preventDefault(),_()):P.key==="Escape"&&I(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsx("span",{className:"msg-editor-hint",children:N("editHint")}),e.jsx("button",{type:"button",className:"chip",onClick:()=>I(!1),children:N("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!E.trim(),title:N("reaskFromHere"),onClick:_,children:[e.jsx(pt,{})," ",N("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),S?e.jsx(Qn,{message:s}):D?e.jsxs(e.Fragment,{children:[e.jsx(Zn,{block:D}),D.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(at,{text:D.userMessage})}),s.content.map((P,V)=>P.type==="text"?null:e.jsx(Ut,{block:P,toolResults:n,liveOutputs:i,toolStatuses:o,streaming:c,isLast:a,onKillBash:h},`${s.id}-${V}`))]}):s.content.map((P,V)=>e.jsx(Ut,{block:P,toolResults:n,liveOutputs:i,toolStatuses:o,streaming:c,isLast:a,onKillBash:h},`${s.id}-${V}`)),x&&e.jsxs("div",{className:"thinking-wait",children:[N("thinkingWait"),e.jsx("span",{className:"dot"})]}),c&&a&&!x&&e.jsx("span",{className:"stream-cursor"})]})}),L&&!M&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:N("editReaskTip"),onClick:d,children:[e.jsx(pt,{})," ",N("editReask")]})})]})});function Qn({message:t}){const s=le(),[n,i]=r.useState(!1),o=t.details??{},c=o.name??o.path??s("attachment"),a=o.type==="folder",l=o.mode==="reference",h=o.mode==="bridged",u=t.content.filter(N=>N.type==="text").map(N=>N.text).join(`
|
|
13
|
-
`),g=Yn(u),p=t.content.find(N=>N.type==="image"),k=g.split(`
|
|
14
|
-
`).length;return e.jsxs("div",{className:`attachcard ${l?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>i(N=>!N),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":h?"bridged":"inline"}`,children:l?a?s("folderRefShort"):`${s("refOnlyShort")} · ${Wt(o.size)}`:h?s("bridgedVision"):p?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(Ee,{}):e.jsx(st,{}))]}),!l&&n&&(h?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"attachcard-bridgenote",children:s("bridgedVisionDetail")}),(p==null?void 0:p.dataUrl)&&e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:p.dataUrl,alt:c})}),g&&e.jsx("pre",{className:"attachcard-content",children:g})]}):p!=null&&p.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:p.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:Wt(o.size)})})]})}function Wt(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function Yn(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 Zn({block:t}){const s=le(),[n,i]=r.useState(!1);return e.jsxs("div",{className:`skillcard${n?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>i(o=>!o),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(an,{})}),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(tt,{}):e.jsx(Ee,{}),s(n?"collapseMsg":"expandMsg")]})]}),n&&e.jsx("div",{className:"skillcard-body",children:e.jsx(at,{text:t.content})})]})}function Ut({block:t,toolResults:s,liveOutputs:n,toolStatuses:i,streaming:o,isLast:c,onKillBash:a}){const l=le(),h=$e(t);if(h){const N=o&&c;return e.jsxs("div",{className:"msg-text",children:[N?e.jsx(Wn,{text:h.text}):e.jsx(at,{text:h.text}),h.truncated&&e.jsx("div",{className:"trunc-note",children:l("truncated")})]})}const u=hs(t);if(u)return e.jsx(Un,{thinking:u.thinking,streaming:o&&c});const g=gs(t);if(g){const N=s.get(g.id),M=n.get(g.id),I={result:N,liveOutput:M==null?void 0:M.text,streaming:o,status:i.get(g.id)};return e.jsx(zn,{block:g,view:I,onKillBash:a})}const p=fs(t);if(p&&p.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:p.dataUrl,alt:"attachment"})});const k=xs(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 vs(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 Xn(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),i=String(s.getMinutes()).padStart(2,"0");return`${n}:${i}`}const ea=r.memo(function({message:s,onExpand:n}){const i=le();let o="";for(const p of s.content){const k=$e(p);if(k&&k.text.trim()){const N=kt(k.text);N?o=`skill:${N.name}`+(N.userMessage?` · ${N.userMessage.replace(/\s+/g," ").trim()}`:""):o=k.text.replace(/\s+/g," ").trim();break}}if(!o&&s.role==="custom"&&s.customType==="file"){const p=s.details??{};o=p.name??p.path??""}o.length>90&&(o=`${o.slice(0,90)}…`);let a=0,l=0,h=0,u=0;for(const p of s.content)hs(p)?a++:gs(p)?l++:xs(p)?h++:fs(p)&&u++;const g=[];return a&&g.push(`${i("thinking")} ${a}`),l&&g.push(`${i("toolCalls")} ${l}`),h&&g.push(`${i("bashRuns")} ${h}`),u&&g.push(`${i("images")} ${u}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${i("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"?i("attachment"):vs(s.role,i)}),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((p,k)=>e.jsx("span",{className:"msg-collapsed-chip",children:p},k))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:ta(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(Ee,{})," ",i("expandMsg")]})]})});function ta(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),i=String(s.getMinutes()).padStart(2,"0");return`${n}:${i}`}const sa=r.memo(function({id:s,show:n,height:i,containerRef:o,onMeasured:c,lazyRef:a,children:l}){const h=r.useRef(null),u=r.useRef(null);return r.useLayoutEffect(()=>{const g=u.current;if(u.current=n,!n||g!==!1)return;const p=h.current,k=o.current;if(!p||!k)return;const N=p.offsetHeight;c==null||c(s,N);const M=N-i;if(M!==0){const I=p.parentElement;I&&I.getBoundingClientRect().bottom<=k.getBoundingClientRect().top&&(k.scrollTop+=M)}},[n]),n?e.jsx("div",{ref:a,"data-lazy-id":s,children:e.jsx("div",{ref:h,children:l})}):e.jsx("div",{ref:a,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:i},"aria-hidden":"true"})});function na(t,s,n,i){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?i.has(l.id)&&o.push(l.id):i.has(l.id)||(c.push(l.id),l.bottom<=s.top&&(a+=l.bottom-l.top))}return{show:o,hide:c,shrinkAbove:a}}function aa(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const i of s.show)n.delete(i);for(const i of s.hide)n.add(i);return n}function ia(t,s,n){const i=new Set;let o=0;for(let c=t.length-1;c>=0&&!(c<t.length-1&&o>=n);c--){const a=t[c];i.add(a.id),o+=s.get(a.id)??ys(a.role,a.customType)}return i}function ys(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 ra(t){if(t.role==="toolResult")return"";const s=[];for(const n of t.content)oa(n,s);return t.errorMessage&&s.push(t.errorMessage),s.join(`
|
|
15
|
-
`)}function oa(t,s){if(typeof t.text=="string"){s.push(t.text);return}switch(t.type){case"thinking":typeof t.thinking=="string"&&s.push(t.thinking);break;case"toolCall":{typeof t.name=="string"&&s.push(t.name),typeof t.argumentsText=="string"&&s.push(t.argumentsText);break}case"bash":typeof t.command=="string"&&s.push(t.command),typeof t.output=="string"&&s.push(t.output);break}}function la(t,s){const n=s.trim().toLowerCase();if(!n)return 0;const i=t.toLowerCase();let o=0,c=i.indexOf(n);for(;c!==-1;)o++,c=i.indexOf(n,c+n.length);return o}function ca(t,s){const n=s.trim().toLowerCase();if(!n)return[];const i=[];for(const o of t){const c=ra(o);if(!c)continue;const a=la(c,n);for(let l=0;l<a;l++)i.push({messageId:o.id,occurrence:l})}return i}function da(t,s){var a;const n=new Map,i=[],o=s.toLowerCase();if(!o)return{byMsg:n,all:i};const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(l){const h=l.parentElement;return!h||h.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 h=(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 p=h.indexOf(o);for(;p!==-1;){const k=document.createRange();k.setStart(l,p),k.setEnd(l,p+o.length),i.push(k);const N=n.get(g);N?N.push(k):n.set(g,[k]),p=h.indexOf(o,p+o.length)}}return{byMsg:n,all:i}}function Re(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const i=window.Highlight;i&&n.highlights.set(t,new i(...s))}function ua({containerRef:t,messages:s,open:n,onClose:i,onEnsureExpanded:o}){const c=le(),a=r.useRef(null),[l,h]=r.useState(""),[u,g]=r.useState(0),p=r.useDeferredValue(l),k=n?p.trim():"",N=r.useMemo(()=>n?ca(s,k):[],[s,k,n]),M=r.useRef(N);M.current=N;const I=r.useRef(u);I.current=u,r.useEffect(()=>{n&&(g(0),requestAnimationFrame(()=>{var T;return(T=a.current)==null?void 0:T.select()}))},[n]),r.useEffect(()=>{if(!n)return;const T=D=>{D.key==="Escape"&&(D.preventDefault(),D.stopPropagation(),i())};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[n,i]),r.useEffect(()=>(n||(Re("msg-search",[]),Re("msg-search-active",[])),()=>{Re("msg-search",[]),Re("msg-search-active",[])}),[n]);const E=r.useCallback(T=>{const D=t.current;if(!D)return;const w=D.querySelector(`[data-msg-id="${T}"]`);w&&(w.classList.remove("msg-flash"),w.offsetWidth,w.classList.add("msg-flash"))},[t]);r.useLayoutEffect(()=>{if(!n||!k)return;const T=t.current;if(!T)return;let D=!1,w=0;return w=requestAnimationFrame(()=>{var b;if(D)return;const{byMsg:x,all:L}=da(T,k);Re("msg-search",L);const d=M.current,_=d[Math.min(I.current,d.length-1)];if(!_)return;const F=(b=x.get(_.messageId))==null?void 0:b[_.occurrence];if(F){Re("msg-search-active",[F]);const P=F.startContainer.parentElement??T.querySelector(`[data-msg-id="${_.messageId}"]`);P==null||P.scrollIntoView({block:"center"})}else E(_.messageId)}),()=>{D=!0,cancelAnimationFrame(w)}},[n,k,N,t,E]);const f=r.useCallback(T=>{const D=M.current;if(D.length===0)return;const w=(I.current+T+D.length)%D.length;g(w),o(D[w].messageId)},[o]);if(!n)return null;const S=N.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:a,className:"search-input",type:"text",value:l,placeholder:c("searchPlaceholder"),onChange:T=>{h(T.target.value),g(0)},onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),f(T.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:()=>f(-1),children:e.jsx(tt,{})}),e.jsx("button",{type:"button",className:"search-btn",title:c("searchNext"),disabled:S===0,onClick:()=>f(1),children:e.jsx(Ee,{})}),e.jsx("button",{type:"button",className:"search-btn",title:c("searchClose"),onClick:i,children:e.jsx(we,{})})]})}const qt=new Map,ma=15,Kt=30,zt=1200,pa=1600;function Vt(t){return t.content.some(s=>s.type==="toolCall")}const ha=[{key:"ex.understand",icon:"🔍"},{key:"ex.debug",icon:"🐛"},{key:"ex.test",icon:"🧪"},{key:"ex.review",icon:"🧹"}];function ga(t){return ha.map(({key:s,icon:n})=>({icon:n,text:t(s),prompt:t(`${s}.prompt`)}))}function fa({state:t,liveOutputs:s,toolStatuses:n,onEdit:i,onKillBash:o}){const c=le(),a=r.useRef(null),[l,h]=r.useState(!0),u=r.useRef(!0),g=r.useRef(0),p=r.useRef(!1),[k,N]=r.useState(()=>new Set),[M,I]=r.useState(!1),E=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,f=r.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=E.length>0?E[E.length-1].id:null,T=t.messages.length>Kt?Math.max(0,t.messages.length-ma):0,[D,w]=r.useState(()=>new Set),[x,L]=r.useState(()=>new Set),d=r.useRef(new Map),_=r.useRef(new Map),F=r.useRef(0),b=r.useRef(D);b.current=D;const P=t.messages.length>Kt&&!M,V=r.useRef(P);V.current=P;const Y=ia(t.messages,d.current,pa),m=r.useRef(Y);m.current=Y;const $=r.useCallback(()=>{const y=a.current;if(!y)return;if(!V.current){w(oe=>oe.size?new Set:oe);return}const B=y.getBoundingClientRect(),J={top:B.top-zt,bottom:B.bottom+zt},G=[];for(const[oe,pe]of _.current){const ke=pe.getBoundingClientRect();G.push({id:oe,top:ke.top,bottom:ke.bottom}),b.current.has(oe)||d.current.set(oe,ke.bottom-ke.top)}const X=na(G,J,m.current,b.current);for(const oe of X.hide){const pe=_.current.get(oe);pe&&d.current.set(oe,pe.offsetHeight)}w(oe=>aa(oe,X))},[]),R=r.useCallback(()=>{F.current||(F.current=requestAnimationFrame(()=>{F.current=0,$()}))},[$]);r.useLayoutEffect(()=>{$()},[$]);const H=r.useRef(M);r.useLayoutEffect(()=>{H.current&&!M&&$(),H.current=M},[M,$]);const q=r.useCallback((y,B)=>{d.current.set(y,B)},[]),se=r.useCallback(y=>{y&&_.current.set(y.dataset.lazyId??"",y)},[]);r.useEffect(()=>{const y=new Set(t.messages.map(B=>B.id));for(const[B,J]of _.current)y.has(B)||(_.current.delete(B),d.current.delete(B));w(B=>{let J=!1;const G=new Set;for(const X of B)y.has(X)?G.add(X):J=!0;return J?G:B})},[t.messages,k]),r.useEffect(()=>()=>cancelAnimationFrame(F.current),[]);const ae=r.useMemo(()=>{const y=[];for(const B of t.messages){if(B.role!=="user")continue;const J=B.content.map(oe=>{var pe;return((pe=$e(oe))==null?void 0:pe.text)??""}).filter(Boolean).join(" "),G=kt(J),X=G?G.userMessage??`skill:${G.name}`:J.trim();X&&y.push({id:B.id,text:X})}return y},[t.messages]),Q=r.useMemo(()=>{const y=new Map;return ae.forEach((B,J)=>y.set(B.id,J)),y},[ae]),[ne,ce]=r.useState(-1),me=r.useRef(-1),ge=r.useRef(ae);r.useEffect(()=>{ge.current=ae},[ae]);const ue=r.useCallback(()=>{const y=a.current,B=ge.current;if(!y||B.length===0)return;const J=y.getBoundingClientRect().top,G=140;let X=-1;for(let oe=0;oe<B.length;oe++){const pe=y.querySelector(`[data-msg-id="${B[oe].id}"]`);if(pe)if(pe.getBoundingClientRect().top<=J+G)X=oe;else break}X!==me.current&&(me.current=X,ce(X))},[]);r.useEffect(()=>{ue()},[ae,ue]);const he=r.useCallback(y=>{N(B=>B.has(y)?B:new Set(B).add(y))},[]),ye=r.useCallback(y=>{const B=t.messages.findIndex(J=>J.id===y);B>=0&&B<T&&!k.has(y)&&$t.flushSync(()=>he(y))},[t.messages,T,k,he]);r.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(),I(!0))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]);const de=r.useCallback(y=>{N(B=>{if(!B.has(y))return B;const J=new Set(B);return J.delete(y),J})},[]),je=r.useCallback(y=>{const B=t.messages.findIndex(G=>G.id===y);$t.flushSync(()=>{B>=0&&B<T&&!k.has(y)&&he(y),L(G=>G.has(y)?G:new Set(G).add(y))});const J=ge.current.findIndex(G=>G.id===y);me.current=J,ce(J),requestAnimationFrame(()=>{var X,oe,pe;const G=(X=a.current)==null?void 0:X.querySelector(`[data-msg-id="${y}"]`);G&&((oe=a.current)==null||oe.querySelectorAll(".msg-flash").forEach(ke=>ke.classList.remove("msg-flash")),G.scrollIntoView({block:"start"}),G.classList.remove("msg-flash"),G.offsetWidth,G.classList.add("msg-flash"),G!==((pe=a.current)==null?void 0:pe.lastElementChild)&&(p.current=!0))})},[t.messages,T,k,he]),ie=r.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?p.current=!0:J&&B>=0&&(p.current=!1),u.current=J&&!p.current,h(u.current),ue(),R()},[ue,R]),v=r.useRef(!1);r.useEffect(()=>{const y=v.current;if(v.current=!!t.isStreaming,y&&!t.isStreaming&&!p.current){const B=()=>{const G=a.current;G&&!p.current&&(G.scrollTop=G.scrollHeight,u.current=!0,h(!0))};requestAnimationFrame(()=>requestAnimationFrame(B));const J=setTimeout(B,180);return()=>clearTimeout(J)}},[t.isStreaming]),r.useEffect(()=>{const y=a.current;y&&u.current&&(y.scrollTop=y.scrollHeight)},[E,t.isStreaming,s]);const W=r.useCallback(()=>{const y=a.current;y&&(y.scrollTop=y.scrollHeight),u.current=!0,p.current=!1,h(!0)},[]),re=r.useRef(null);r.useEffect(()=>{const y=re.current,B=a.current;if(!y||!B)return;const J=G=>{G.preventDefault();const X=y.querySelector(".qn-list");if(X&&X.contains(G.target)&&X.scrollHeight>X.clientHeight){X.scrollTop+=G.deltaY;return}B.scrollTop+=G.deltaY};return y.addEventListener("wheel",J,{passive:!1}),()=>y.removeEventListener("wheel",J)},[]);const[A,K]=r.useState(0);r.useEffect(()=>{const y=()=>{var B;K(((B=a.current)==null?void 0:B.clientHeight)??0),R()};return y(),window.addEventListener("resize",y),()=>window.removeEventListener("resize",y)},[R]);const te=ae.length,xe=r.useMemo(()=>te===0?27:Math.max(4,Math.min(27,Math.floor(((A||600)-16)/te)-3)),[te,A]),ve=xe<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:"messages",ref:a,onScroll:ie,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:ga(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<T,G=J&&k.has(y.id);if(J&&!G)return y.role==="toolResult"?null:e.jsx(ea,{message:y,onExpand:he},y.id);const X=y.role==="user"?Q.get(y.id):void 0,oe=!P||Y.has(y.id)||x.has(y.id)||!D.has(y.id);return e.jsx(sa,{id:y.id,show:oe,height:d.current.get(y.id)??ys(y.role,y.customType),containerRef:a,onMeasured:q,lazyRef:se,children:e.jsx(Ht,{message:y,qnIndex:X,qnActive:X!==void 0?X===ne:void 0,onJump:je,toolResults:f,liveOutputs:Vt(y)?s:qt,toolStatuses:n,streaming:t.isStreaming,onKillBash:o,isLast:y.id===S,onEdit:i,onCollapse:G?de:void 0},y.id)},y.id)}),t.streamingMessage&&e.jsx(Ht,{message:t.streamingMessage,toolResults:f,liveOutputs:Vt(t.streamingMessage)?s:qt,toolStatuses:n,streaming:!0,isLast:!0,onEdit:i,onKillBash:o},t.streamingMessage.id),t.isStreaming&&E.length===0&&e.jsx("div",{className:"streaming-wait",children:c("waitingResponse")})]}),!l&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:W,children:[e.jsx(rs,{})," ",c("backToBottom")]}),e.jsx(ua,{containerRef:a,messages:E,open:M,onClose:()=>I(!1),onEnsureExpanded:ye}),ae.length>0&&e.jsxs("div",{className:`qn-rail ${ve?"many":""}`,ref:re,"aria-label":c("questionNavTitle"),style:{"--rail-gap":`${xe}px`},children:[ae.map((y,B)=>e.jsx("button",{type:"button",className:`qn-bar ${B===ne?"active":""}`,"aria-label":`${B+1}. ${y.text}`,onClick:()=>je(y.id),children:e.jsxs("span",{className:"qn-bar-text",children:[B+1,". ",y.text]})},y.id)),ve&&e.jsx("div",{className:"qn-list",children:ae.map((y,B)=>e.jsxs("button",{type:"button",className:`qn-list-item ${B===ne?"active":""}`,"aria-label":`${B+1}. ${y.text}`,onClick:()=>je(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 xa=1568,va=2*1024*1024;function qe(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function ya(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,xa/Math.max(s.width,s.height)),i=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,h]of c){const u=document.createElement("canvas");u.width=i,u.height=o;const g=u.getContext("2d");if(!g)continue;l!=="image/png"&&(g.fillStyle="#ffffff",g.fillRect(0,0,i,o)),g.drawImage(s,0,0,i,o);const p=u.toDataURL(l,h),k=p.match(/^data:([^;]+);base64,/),N=k?k[1]:l,M=p.replace(/^data:[^;]*;base64,/,""),I=Math.floor(M.length*3/4);if(a={data:M,mimeType:N,name:t.name,size:I},I<=va)return a}return a}finally{s.close()}}const ja=r.memo(function({ready:s,streaming:n,queueSteering:i,queueFollowUp:o,messages:c,slashCommands:a,modelState:l,models:h,modelsLoading:u,send:g,attachments:p,onRemoveAttachment:k,onAddImageFiles:N,onAddLocalFiles:M,onNotice:I,onSent:E,onManageModels:f}){const S=le(),{locale:T}=jt(),D=v=>T==="en"&&v.descriptionEn?v.descriptionEn:v.description??"",w=v=>T==="en"&&v.argumentHintEn?v.argumentHintEn:v.argumentHint??"",[x,L]=r.useState(""),[d,_]=r.useState(!1),[F,b]=r.useState(null),[P,V]=r.useState(0),[Y,m]=r.useState(!1),[$,R]=r.useState(void 0),H=r.useRef(null),q=r.useRef(null),se=r.useRef(null),ae={builtin:S("slashBuiltin"),extension:S("slashExtension"),prompt:S("slashPrompt"),skill:S("slashSkill")},Q=v=>{const W=v.match(/^\/([^\s]*)$/);if(W&&s){const re=W[1].toLowerCase(),A=a.filter(K=>K.name.toLowerCase().startsWith(re));b(A.length>0?A:null),V(0)}else b(null)};r.useEffect(()=>{var W;const v=(W=se.current)==null?void 0:W.querySelector(".slash-item.active");v==null||v.scrollIntoView({block:"nearest"})},[P,F]);const ne=v=>{var te;const W=F??[],re=v??W[P%Math.max(W.length,1)];if(!re){b(null);return}const A=x.match(/^\/([^\s]*)([\s\S]*)$/),K=A?A[2]:"";L(`/${re.name} ${K}`),b(null),(te=H.current)==null||te.focus()},ce=async()=>{const W=[...c].reverse().find(A=>A.role==="assistant"&&A.content.some(K=>K.type==="text"&&K.text)),re=W==null?void 0:W.content.filter(A=>A.type==="text").map(A=>A.text).join(`
|
|
16
|
-
`);if(!re){I("warning",S("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(re),I("info",S("slashCopied"))}catch{I("error",S("slashCopyFailed"))}},me=v=>{if(!v||v.length===0){I("warning",S("foldersNotSupported"));return}const W=Array.from(v).filter(A=>qe(A.type)),re=Array.from(v).filter(A=>!qe(A.type));W.length>0&&N(W),re.length>0&&M(re)},ge=v=>{var A;const W=(A=v.clipboardData)==null?void 0:A.items;if(!W)return;const re=[];for(const K of W)if(K.kind==="file"&&qe(K.type)){const te=K.getAsFile();te&&re.push(te)}re.length!==0&&(v.preventDefault(),N(re))},ue=s,he=i+o,ye=r.useRef(x);r.useEffect(()=>{ye.current=x},[x]),r.useEffect(()=>{Q(ye.current)},[a]),r.useEffect(()=>{const v=W=>{var A;const re=W.detail;L(re),(A=H.current)==null||A.focus()};return window.addEventListener("pi-web:fill",v),()=>window.removeEventListener("pi-web:fill",v)},[]),r.useEffect(()=>{if(!Y)return;const v=W=>{W.key==="Escape"&&m(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[Y]),r.useEffect(()=>{const v=H.current;if(!v)return;v.style.height="auto";const W=v.scrollHeight>220;v.style.height=`${Math.min(v.scrollHeight,220)}px`,v.style.overflowY=W?"auto":"hidden"},[x]);const de=(v=!1)=>{var A,K,te,xe,ve;const W=x.trim(),re=p.some(y=>y.imageData||y.fileData);if(!(!ue||!W&&!re)){if(W==="/help"){const y=(K=(A=H.current)==null?void 0:A.closest(".inputbox"))==null?void 0:K.getBoundingClientRect();R(y==null?void 0:y.width),m(!0),L(""),(te=H.current)==null||te.focus();return}if(W==="/copy"){L(""),(xe=H.current)==null||xe.focus(),ce();return}g({type:"prompt",text:W,queue:v,attachments:p.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}:{}})})&&(L(""),E(),(ve=H.current)==null||ve.focus())}},je=v=>{if(!v.nativeEvent.isComposing){if(F&&F.length>0)switch(v.key){case"ArrowDown":v.preventDefault(),V(W=>(W+1)%F.length);return;case"ArrowUp":v.preventDefault(),V(W=>(W-1+F.length)%F.length);return;case"Tab":case"Enter":v.preventDefault(),ne();return;case"Escape":v.preventDefault(),b(null);return}v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),de())}},ie=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[x.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:S("supplementTip"),onClick:()=>de(!0),children:[e.jsx(Us,{})," ",S("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:S("stopAgent"),onClick:()=>g({type:"abort"}),children:e.jsx(Ve,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:S("sendTip"),disabled:!ue||!x.trim()&&!p.some(v=>v.imageData||v.fileData),onClick:()=>de(),children:e.jsx(is,{})})});return e.jsxs("div",{className:`inputbar${d?" drop-active":""}`,onDragOver:v=>{v.preventDefault(),v.stopPropagation(),_(!0)},onDragLeave:v=>{v.currentTarget.contains(v.relatedTarget)||_(!1)},onDrop:v=>{var W;v.preventDefault(),v.stopPropagation(),_(!1),me(((W=v.dataTransfer)==null?void 0:W.files)??null)},children:[d&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",S("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(v=>e.jsxs("span",{className:`attach-chip ${v.imageData?"image":v.fileData?"file":v.mode}`,title:v.imageData?S("attachImage",{name:v.name}):v.fileData?S("attachFile",{name:v.name}):v.isDir?S("folderRef",{path:v.path}):v.mode==="reference"?S("refOnly",{path:v.path}):v.mode==="lines"&&v.lines?S("attachLines",{path:v.path,start:v.lines.start,end:v.lines.end}):S("attachContent",{path:v.path}),children:[v.imageData?"🖼":v.fileData?"📄":v.isDir?"📁":v.mode==="reference"?"🔗":"📎"," ",v.name,v.mode==="lines"&&v.lines&&e.jsxs("span",{className:"attach-range",children:["L",v.lines.start,"-",v.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:S("removeAttachment"),onClick:()=>k(v.key??v.path),children:"×"})]},v.key??`${v.path}|${v.mode}|${v.lines?`${v.lines.start}-${v.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:S("attachHint")})]}),n&&he>0&&e.jsxs("div",{className:"queue-hint",children:[o>0&&e.jsx("span",{children:S("followUpQueued",{n:o})}),i>0&&e.jsx("span",{children:S("steeringQueued",{n:i})})]}),F&&F.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:se,"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:()=>b(null),children:"Esc"})]}),F.map((v,W)=>e.jsxs("button",{type:"button",className:`slash-item${W===P?" active":""}`,onMouseEnter:()=>V(W),onClick:()=>ne(v),children:[e.jsxs("span",{className:"slash-name",children:["/",v.name]}),e.jsx("span",{className:`slash-source ${v.source}`,children:ae[v.source]}),e.jsxs("span",{className:"slash-desc",children:[D(v),v.argumentHint&&e.jsx("span",{className:"slash-hint",children:w(v)})]})]},v.name))]}),Y&&e.jsx("div",{className:"modal-backdrop",onClick:()=>m(!1),children:e.jsxs("div",{className:"slash-help",style:$?{width:$}:void 0,onClick:v=>v.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(v=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",v.name]}),e.jsx("span",{className:`slash-source ${v.source}`,children:ae[v.source]}),e.jsxs("span",{className:"slash-help-desc",children:[D(v),v.argumentHint&&e.jsx("span",{className:"slash-hint",children:w(v)})]})]},v.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:q,type:"file",multiple:!0,hidden:!0,onChange:v=>{me(v.target.files),v.target.value=""}}),e.jsxs("div",{className:"inputbox-row",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var v;return(v=q.current)==null?void 0:v.click()},children:e.jsx(Et,{})}),e.jsx("textarea",{ref:H,value:x,rows:1,placeholder:S(ue?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!ue,onChange:v=>{L(v.target.value),Q(v.target.value)},onKeyDown:je,onPaste:ge}),ie()]}),e.jsxs("div",{className:"input-tools",children:[e.jsx("div",{className:"input-tools-left",children:e.jsx(cs,{state:l,models:h,modelsLoading:u,send:g,onManageModels:f,compact:!0})}),e.jsxs("div",{className:"input-tools-right",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:S("uploadFile"),disabled:!ue,onClick:()=>{var v;return(v=q.current)==null?void 0:v.click()},children:e.jsx(Et,{})}),ie()]})]})]})]})}),ba=r.memo(function({goal:s,models:n,modelsLoading:i,activeConversationId:o,send:c}){var b,P,V,Y,m,$;const a=le(),l=!s.conversationId||s.conversationId===o,h=s.goal!==null&&l,[u,g]=r.useState(""),[p,k]=r.useState(s.reviewModel??""),[N,M]=r.useState(s.maxRounds),[I,E]=r.useState(s.locked),[f,S]=r.useState(!1),[T,D]=r.useState(!1),[w,x]=r.useState(!0);r.useEffect(()=>{k(s.reviewModel??""),M(s.maxRounds||0),E(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),r.useEffect(()=>{f&&n.length===0&&!T&&!i&&(D(!0),c({type:"list_models"}))},[f,n.length,T,i,c]),r.useEffect(()=>{n.length>0&&D(!1)},[n.length]);const L=()=>{var R;return p?((R=n.find(H=>H.id===p))==null?void 0:R.name)??p:a("goalBarUseMainModel")},d=()=>{const R=u.trim();R&&(c({type:"set_goal",goal:R,...p?{reviewModel:p}:{},maxRounds:N,locked:I}),g(""),x(!1))},_=()=>{const R=u.trim();R&&(c({type:"start_goal_wizard",text:R,...p?{wizardModel:p}:{},maxRounds:N,locked:I}),g(""),x(!1))},F=(((b=s.wizard)==null?void 0:b.active)??!1)&&l;return F?e.jsx("div",{className:`goalbar goalbar-active ${F?"wizard":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx("span",{className:"goalbar-spin",children:"🔍"})}),e.jsxs("span",{className:"goalbar-text",title:((P=s.wizard)==null?void 0:P.draft)??"",children:[a("goalWizardRunning"),": ",(V=s.wizard)==null?void 0:V.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:(($=s.wizard)==null?void 0:$.status)||a("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:a("goalBarClear"),onClick:()=>{c({type:"clear_goal"}),x(!0)},children:e.jsx(we,{})})]})}):h?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"}),x(!0)},children:e.jsx(we,{})})]})}):w?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:a("goalBarPlaceholder"),onClick:()=>x(!1),children:[e.jsx(Mt,{})," ",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(Mt,{})}),e.jsx("input",{className:"goalbar-input",value:u,placeholder:a("goalBarPlaceholder"),onChange:R=>g(R.target.value),onKeyDown:R=>{R.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:_,children:["🔍 ",a("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a(I?"goalBarLocked":"goalBarUnlocked"),onClick:()=>E(R=>(c({type:"set_goal_prefs",locked:!R}),!R)),children:I?e.jsx(Qs,{}):e.jsx(Hs,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:a("goalBarClear"),onClick:()=>x(!0),children:e.jsx(tt,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Te,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[a("goalBarReviewModel"),": ",e.jsx("b",{children:L()})]}),open:f,onOpenChange:S,direction:"up",children:[e.jsx("div",{className:"dd-header",children:a("goalBarReviewModel")}),(T||i)&&e.jsx("div",{className:"dd-loading",children:a("loading")}),n.length===0&&!T&&!i&&e.jsx("div",{className:"dd-loading",children:a("noModels")}),e.jsx(be,{active:p==="",onClick:()=>{k(""),S(!1),c({type:"set_goal_prefs",reviewModel:""})},children:a("goalBarUseMainModel")}),n.map(R=>e.jsx(be,{active:p===R.id,onClick:()=>{k(R.id),S(!1),c({type:"set_goal_prefs",reviewModel:R.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:R.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:R.provider})})]})},R.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:N,placeholder:a("goalBarUnlimitedShort"),onChange:R=>{const H=parseInt(R.target.value,10);if(Number.isNaN(H)||H<0){M(0);return}M(H)},onBlur:()=>c({type:"set_goal_prefs",maxRounds:N}),onKeyDown:R=>{R.key==="Enter"&&(c({type:"set_goal_prefs",maxRounds:N}),R.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:a(I?"goalBarLocked":"goalBarUnlocked")})]})]})});function ka({chat:t,send:s}){const n=le(),i=t.state,[o,c]=r.useState(!1),[a,l]=r.useState(""),[h,u]=r.useState(0),g=r.useRef(null),p=t.pathCompletions;if(r.useEffect(()=>{if(!o)return;const d=setTimeout(()=>{s({type:"complete_path",path:a})},150);return()=>clearTimeout(d)},[a,o,s]),r.useEffect(()=>u(0),[p]),r.useEffect(()=>{const d=document.querySelector(`.status-completions .pc-item[data-idx="${h}"]`);d==null||d.scrollIntoView({block:"nearest"})},[h]),!i)return null;const k=i.stats,N=t.ready?"ok":"busy",M=t.ready?n("connected"):n("connecting"),I=k.contextUsage,E=I.tokens!==null&&I.percent!==null?`${Gt(I.tokens)} / ${Gt(I.contextWindow)}`:"—",f=I.percent??null,S=f===null?"":f>=80?"warn":f>=50?"mid":"ok",T=i.queue.steering+i.queue.followUp,D=()=>{l(i.cwd),c(!0)},w=(d,_)=>{var b;const F=d.includes("\\")?"\\":"/";l(_?`${d}${F}`:d),u(0),(b=g.current)==null||b.focus()},x=d=>{const _=d.trim();_&&_!==i.cwd&&s({type:"set_cwd",path:_}),c(!1)},L=d=>{if(d.key==="ArrowDown")d.preventDefault(),u(_=>Math.min(_+1,p.length-1));else if(d.key==="ArrowUp")d.preventDefault(),u(_=>Math.max(_-1,0));else if(d.key==="Tab"&&p.length>0){d.preventDefault();const _=p[Math.min(h,p.length-1)];w(_.path,_.type==="dir")}else if(d.key==="Enter"&&!d.nativeEvent.isComposing){const _=a.trim();if(_.endsWith("/")||_.endsWith("\\"))x(_);else if(p.some(F=>F.path===_))x(_);else if(p.length>0&&p[h]){d.preventDefault();const F=p[h];w(F.path,F.type==="dir")}else x(_)}else d.key==="Escape"&&(p.length>0?(d.stopPropagation(),s({type:"complete_path",path:""})):c(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${N}`,title:M}),e.jsx("span",{className:"status-item",children:M}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${S}`,children:f!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(f,100)}%`}})}),E]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",Na(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(" · ")})]}),i.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"),T>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",T," ",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:L,onBlur:()=>c(!1)}),p.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:d=>d.preventDefault(),children:p.map((d,_)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":_,className:`pc-item ${_===h?"sel":""}`,onMouseEnter:()=>u(_),onClick:()=>w(d.path,d.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:d.type==="dir"?e.jsx(Ie,{}):e.jsx(ss,{})}),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:i.cwd}),onClick:D,children:["📁 ",i.cwd]})]})}function Gt(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function Na(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function wa({dialog:t,send:s}){const n=le(),[i,o]=r.useState(""),[c,a]=r.useState(0),l=g=>{s({type:"dialog_response",id:t.id,value:g})};r.useEffect(()=>{o(""),a(0);const g=p=>{p.key==="Escape"&&l(null)};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t.id]);const h=Array.isArray(t.args[0])?t.args[0]:[],u=typeof t.args[0]=="string"?t.args[0]:"";return e.jsx("div",{className:"dialog-overlay",onMouseDown:g=>{g.target===g.currentTarget&&l(null)},children:e.jsxs("div",{className:"dialog",children:[e.jsx("div",{className:"dialog-title",children:t.title||n("pluginRequest")}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[h.map((g,p)=>e.jsx("button",{type:"button",className:`dialog-option ${p===c?"sel":""}`,onMouseEnter:()=>a(p),onClick:()=>l(g),children:g},p)),h.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:i,placeholder:u||n("inputPlaceholder"),autoFocus:!0,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&!g.nativeEvent.isComposing&&l(i)}}),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(i),children:n("ok")})]})]})]})})}function Ca(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 Sa({chat:t,send:s,terminal:n,active:i,onSwitchToTerminal:o}){var ke,Pe;const c=le(),[a,l]=r.useState(null),[h,u]=r.useState([]),[g,p]=r.useState(""),[k,N]=r.useState(new Map),[M,I]=r.useState("changes"),[E,f]=r.useState([]),[S,T]=r.useState(null),[D,w]=r.useState(""),[x,L]=r.useState(!1),[d,_]=r.useState(null),[F,b]=r.useState(null),[P,V]=r.useState(!1),[Y,m]=r.useState(!1),[$,R]=r.useState(!1),[H,q]=r.useState(null),[se,ae]=r.useState(!1),[Q,ne]=r.useState(""),ce=r.useRef(0),me=r.useRef(-1),ge=r.useRef(-1),ue=r.useRef(-1),he=r.useRef(-1),ye=r.useRef(void 0),de=r.useRef(null),je=r.useRef([]),ie=r.useCallback(j=>{if(j.reqId===me.current){if(me.current=-1,m(!1),q(null),!j.ok){q(j.error??"查询失败");return}if(j.notRepo){ae(!0),l(null),u([]),N(new Map),f([]),T(null),w(""),b(null);return}ae(!1);const Z={branch:j.branch??"",detached:!!j.detached,upstream:j.upstream??null,ahead:j.ahead??0,behind:j.behind??0,upstreamGone:!!j.upstreamGone,files:(j.files??[]).map(C=>({...C}))},z=(j.branches??[]).map(C=>({...C})),fe=new Map;for(const[C,O]of Object.entries(j.stats??{}))fe.set(C,{add:O[0],del:O[1]});l(Z),u(z),N(fe),p(C=>{var O;return Z.detached?C||"":Z.branch&&z.some(ee=>ee.name===Z.branch)?Z.branch:C&&z.some(ee=>ee.name===C)?C:((O=z[0])==null?void 0:O.name)??""}),b(C=>C&&!Z.files.some(O=>O.path===C.file.path)?null:C)}else if(j.reqId===ge.current){if(ge.current=-1,V(!1),!j.ok){q(j.error??"查询失败");return}const Z=de.current;if(!Z)return;b({file:Z,staged:j.stagedText??"",worktree:j.worktreeText??"",untracked:!1})}else if(j.reqId===he.current){if(he.current=-1,R(!1),!j.ok){q(j.error??"查询失败");return}f((j.history??[]).map(Z=>({...Z})))}else if(j.reqId===ue.current){if(ue.current=-1,L(!1),!j.ok){q(j.error??"查询失败");return}w(j.text??"")}},[]);r.useEffect(()=>{const j=t.scmData;j&&j.type==="scm_data"&&ie(j)},[t.scmData,ie]);const v=r.useCallback((j,Z)=>{if(!t.ready||t.status!=="open")return!1;const z=++ce.current;return s({...j,reqId:z})?(Z.current=z,!0):(ce.current-=1,!1)},[t.ready,t.status,s]),W=r.useCallback((j=!1,Z=!1)=>{var z;!t.ready||t.status!=="open"||(z=t.state)!=null&&z.cwd&&(ye.current!==void 0&&ye.current!==t.state.cwd&&(l(null),u([]),N(new Map),f([]),R(!1),he.current=-1,T(null),w(""),b(null),_(null)),ye.current=t.state.cwd,q(null),v({type:"scm_status"},me)&&(Z||m(!0)))},[t.ready,(ke=t.state)==null?void 0:ke.cwd,t.status,v]),re=r.useCallback(j=>{if(_(j),T(null),de.current=j,j.x==="?"&&j.y==="?"){b({file:j,staged:"",worktree:"",untracked:!0});return}V(!0),q(null),v({type:"scm_filediff",path:j.path},ge)||V(!1)},[v]),A=r.useCallback(j=>{T(j),_(null),b(null),w(""),L(!0),q(null),v({type:"scm_commit",hash:j.hash},ue)||L(!1)},[v]),K=r.useCallback((j,Z)=>{var C,O;if(!t.ready)return;const z={name:j,command:Z,cwd:"${pwd}"},fe=t.terminals.find(ee=>ee.title===j);if(fe)n.restart(fe.id),s({type:"run_command",terminalId:fe.id,conversationId:fe.conversationId,command:z,cols:80,rows:24});else{const ee=Ze();n.create({id:ee,conversationId:t.activeConversationId||((C=t.state)==null?void 0:C.conversationId)||"",title:j,cwd:((O=t.state)==null?void 0:O.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:z})}o()},[t.ready,(Pe=t.state)==null?void 0:Pe.cwd,t.terminals,o,s,n]),te=r.useCallback(()=>{const j=Q.trim();if(!j||se)return;const Z=j.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");K("git commit",`git add -A && git commit -m "${Z}"`),ne("")},[Q,se,K]),xe=j=>`'${j.replace(/'/g,"'\\''")}`,ve=r.useCallback(j=>{se||K("git add",`git add -- ${xe(j.path)}`)},[se,K]),y=r.useCallback(j=>{se||K("git reset",`git reset HEAD -- ${xe(j.path)}`)},[se,K]),B=r.useCallback(()=>{if(!g||se)return;const j=h.find(Z=>Z.name===g);if(j!=null&&j.remote&&typeof j.remote=="string"){const Z=g.slice(j.remote.length+1);K("git checkout",`git checkout -b ${Z} ${g} || git checkout ${g}`)}else K("git checkout",`git checkout ${g}`)},[g,h,se,K]),J=r.useCallback(()=>K("git push","git push"),[K]),G=r.useCallback(()=>K("git pull","git pull"),[K]),X=r.useCallback(()=>{v({type:"scm_history"},he)||(he.current=-1)},[v]);r.useEffect(()=>{i&&W()},[i,W]),r.useEffect(()=>{M==="history"&&a&&X()},[M,a,X]),r.useEffect(()=>{t.scmDirty>0&&i&&W(!1,!0)},[t.scmDirty]),r.useEffect(()=>{if(!i||!t.ready||t.status!=="open")return;const j=setInterval(()=>{document.visibilityState!=="hidden"&&W(!1,!0)},3e4);return()=>clearInterval(j)},[i,t.ready,t.status,W]),r.useEffect(()=>{const j=je.current;if(je.current=t.terminals,!i)return;t.terminals.some(z=>{var C;return z.running!==!1?!1:((C=j.find(O=>O.id===z.id))==null?void 0:C.running)===!0&&/^git /.test(z.title)})&&t.ready&&t.status==="open"&&(W(!1,!0),M==="history"&&a&&X())},[t.terminals,i,t.ready,t.status,W,M,a,X]);const oe={staged:c("scmStaged"),unstaged:c("scmUnstaged"),untracked:c("scmUntracked"),both:c("scmStagedUnstaged")},pe=j=>{const Z=j.split(`
|
|
17
|
-
`);return e.jsx("pre",{className:"scm-diff-pre",children:Z.map((z,fe)=>{let C="";return z.startsWith("diff --git")||z.startsWith("index ")||z.startsWith("new file")||z.startsWith("deleted file")||z.startsWith("old mode")||z.startsWith("new mode")||z.startsWith("similarity index")||z.startsWith("rename ")||z.startsWith("copy ")||z.startsWith("Binary files")||z.startsWith("---")||z.startsWith("+++")?C="hdr":z.startsWith("@@")?C="hunk":z.startsWith("+")?C="add":z.startsWith("-")&&(C="del"),e.jsx("div",{className:`scm-diff-line ${C}`,children:z||" "},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(Ue,{}),c("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":M==="changes",className:M==="changes"?"active":"",onClick:()=>{I("changes"),q(null)},children:c("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":M==="history",className:M==="history"?"active":"",onClick:()=>{I("history"),q(null)},children:c("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:c("scmRefreshTip"),disabled:Y,onClick:()=>W(!0),children:e.jsx(xt,{className:Y?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:c("scmCurrentBranch"),children:[e.jsx(Ue,{}),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:se||h.length===0,title:c("scmSwitchBranch"),onChange:j=>p(j.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:c("scmSelectBranch")}),h.filter(j=>!j.remote).map(j=>e.jsx("option",{value:j.name,children:j.current?`* ${j.name}`:j.name},j.name)),h.some(j=>j.remote)&&e.jsx("optgroup",{label:c("scmRemoteBranches"),children:h.filter(j=>j.remote).map(j=>e.jsx("option",{value:j.name,children:j.name},j.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!g||g===(a==null?void 0:a.branch)||se,title:c("scmSwitchBranchTip",{branch:g}),onClick:B,children:[e.jsx(Ue,{}),c("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||se,title:c("scmPushTip"),onClick:J,children:[e.jsx(is,{}),c("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||se,title:c("scmPullTip"),onClick:G,children:[e.jsx(rs,{}),c("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:Q,placeholder:c("scmCommitPlaceholder"),disabled:se,onChange:j=>ne(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.nativeEvent.isComposing&&te()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!Q.trim()||se,title:c("scmCommitTip"),onClick:te,children:[e.jsx(yt,{}),c("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[M==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:c("scmHistory")}),E.length>0&&e.jsx("span",{className:"scm-files-count",children:E.length})]}),e.jsx("div",{className:"scm-history-list",children:se?e.jsx("div",{className:"scm-empty",children:c("scmNotGitRepo")}):!a||$?e.jsx("div",{className:"scm-empty",children:t.status==="open"?c("scmLoading"):c("scmConnecting")}):E.length===0?e.jsx("div",{className:"scm-empty",children:c("scmNoHistory")}):E.map(j=>e.jsxs("button",{type:"button",className:`scm-commit ${(S==null?void 0:S.hash)===j.hash?"active":""}`,onClick:()=>A(j),title:j.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:j.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:j.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[j.shortHash," · ",j.author," · ",j.date]}),j.decorations&&e.jsx("span",{className:"scm-commit-refs",children:j.decorations})]})]},j.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:se?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(j=>{const Z=Ca(j),z=k.get(j.path);return e.jsxs("div",{className:`scm-file ${(d==null?void 0:d.path)===j.path?"active":""}`,title:oe[Z],onClick:()=>re(j),children:[e.jsx("span",{className:`scm-file-xy ${Z==="untracked"?"q":"x"}`,children:j.x!==" "?j.x:" "}),e.jsx("span",{className:`scm-file-xy ${Z==="untracked"?"q":"y"}`,children:j.y!==" "?j.y:" "}),e.jsx("span",{className:"scm-file-path",children:j.path}),z&&(z.add>0||z.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[z.add>0&&e.jsxs("span",{className:"add",children:["+",z.add]}),z.del>0&&e.jsxs("span",{className:"del",children:["-",z.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(j.y!==" "||Z==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:c("scmStageTip",{path:j.path}),onClick:fe=>{fe.stopPropagation(),ve(j)},children:"+"}),Z==="staged"||Z==="both"?e.jsx("button",{type:"button",className:"scm-act",title:c("scmUnstageTip",{path:j.path}),onClick:fe=>{fe.stopPropagation(),y(j)},children:"−"}):null]})]},j.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:M==="history"?S?`${S.shortHash} ${S.subject}`:c("scmCommitDetail"):d?d.path:c("scmDiff")}),(M==="history"?x:P)&&e.jsx("span",{className:"scm-diff-loading",children:c("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:M==="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&&x&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmLoading")}),S&&!x&&!H&&D?pe(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&&!F&&!H&&e.jsx("div",{className:"scm-empty",children:c("scmLoading")}),d&&F&&F.untracked&&e.jsx("div",{className:"scm-empty",children:c("scmUntrackedNote")}),d&&F&&!F.untracked&&e.jsxs(e.Fragment,{children:[F.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:c("scmStaged")}),pe(F.staged)]}),F.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:c("scmUnstaged")}),pe(F.worktree)]}),!F.staged&&!F.worktree&&e.jsx("div",{className:"scm-empty",children:c("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Xe,{}),e.jsx("span",{children:c("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:o,children:c("scmViewTerminal")})]})]})}function Ta({send:t,piConfigured:s,providers:n,installResult:i,onClose:o}){const c=le(),[a,l]=r.useState(!1),[h,u]=r.useState(""),[g,p]=r.useState(""),[k,N]=r.useState(!1);r.useEffect(()=>{t({type:"list_providers"})},[t]),r.useEffect(()=>{s&&o()},[s,o]),r.useEffect(()=>{i&&l(!1)},[i]),r.useEffect(()=>{var T;!h&&n.length>0&&u(((T=n.find(D=>!D.configured))==null?void 0:T.id)??n[0].id)},[n,h]);const M=()=>{a||(l(!0),t({type:"install_pi_agent"}))},I=()=>{!g.trim()||k||(N(!0),t({type:"set_provider_api_key",provider:h.trim(),apiKey:g.trim()}),setTimeout(()=>N(!1),3e3))},E=()=>{t({type:"get_state"}),t({type:"list_providers"})},f=n.find(T=>T.id===h),S=i!==null&&!i.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(we,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(et,{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:i.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:c("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:o,children:c("skip")})]})]}):i!=null&&i.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:h,onChange:T=>u(T.target.value),children:[n.length===0&&e.jsx("option",{value:"",children:c("loading")}),n.map(T=>e.jsxs("option",{value:T.id,children:[T.name,"(",T.id,")",T.configured?` · ${c("configured")}`:""]},T.id))]}),(f==null?void 0:f.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:T=>p(T.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||k||!h,onClick:I,children:c(k?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:E,children:[e.jsx(xt,{})," ",c("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:a,onClick:M,children:c(a?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:o,children:c("skip")})]})]})})}const Ma=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],Nt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Ea=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[Nt()]});function Ra(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:[Nt()]).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 La({send:t,providers:s,providerStatus:n,fetchModelsResult:i,refreshProviderResult:o,onClose:c}){const a=le(),[l,h]=r.useState(null),[u,g]=r.useState({}),[p,k]=r.useState(null),[N,M]=r.useState({}),[I,E]=r.useState(!1),[f,S]=r.useState(0),[T,D]=r.useState(null),w=r.useRef(0),[x,L]=r.useState({});r.useRef(0);const d=r.useRef(0);r.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const _=()=>{if(!l)return;const m=l.baseUrl.trim();if(!m){D({ok:!1,text:a("fetchModelsNeedBaseUrl")});return}if(I)return;E(!0),D(null);const $=f+1;S($),t({type:"fetch_models",reqId:$,baseUrl:m,apiKey:l.apiKey.trim()||void 0,authHeader:l.authHeader,api:l.api})};r.useEffect(()=>{var m;if(!(!i||i.reqId===w.current))if(w.current=i.reqId,E(!1),i.ok&&((m=i.models)!=null&&m.length)){const $=i.models;h(R=>{if(!R)return R;const H=R.models.map(Q=>{var me;if(!Q.id.trim())return Q;const ne=$.find(ge=>ge.id===Q.id.trim());if(!ne)return Q;const ce={...Q};return!ce.name&&ne.name&&(ce.name=ne.name),!ce.contextWindow&&ne.contextWindow&&(ce.contextWindow=String(ne.contextWindow)),!ce.maxTokens&&ne.maxTokens&&(ce.maxTokens=String(ne.maxTokens)),ce.input==="text"&&((me=ne.input)!=null&&me.includes("image"))&&(ce.input="text-image"),!ce.reasoning&&ne.reasoning&&(ce.reasoning=!0),ce}),q=new Set(H.map(Q=>Q.id.trim()).filter(Boolean)),se=$.filter(Q=>!q.has(Q.id)).map(Q=>{var ne;return{id:Q.id,name:Q.name??"",reasoning:Q.reasoning??!1,input:(ne=Q.input)!=null&&ne.includes("image")?"text-image":"text",contextWindow:Q.contextWindow?String(Q.contextWindow):"",maxTokens:Q.maxTokens?String(Q.maxTokens):""}}),ae=[...H,...se];return ae.some(Q=>Q.id.trim())?{...R,models:ae.filter(Q=>Q.id.trim())}:R}),D({ok:!0,text:a("fetchModelsOk",{n:$.length})})}else D({ok:!1,text:i.error||a("fetchModelsEmpty")})},[i]);const F=m=>{const $=(u[m.id]??"").trim();!$||p||(k(m.id),t({type:"set_provider_api_key",provider:m.id,apiKey:$}),setTimeout(()=>{k(null),g(R=>({...R,[m.id]:""})),M(R=>({...R,[m.id]:!1})),t({type:"list_providers"})},1500))},b=()=>{if(!l)return;const m=l.providerId.trim(),$=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})),R={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:$};t({type:"save_model_config",providerId:m,config:R}),c()};r.useEffect(()=>{!o||o.reqId===d.current||(d.current=o.reqId,L({}))},[o]);const P=m=>{window.confirm(a("clearKeyConfirm",{id:m}))&&t({type:"clear_provider_api_key",provider:m})},V=m=>{window.confirm(a("deleteProviderConfirm",{id:m.providerId,n:m.models.length}))&&t({type:"delete_model_config",providerId:m.providerId})},Y=(m,$)=>{l&&h({...l,models:l.models.map((R,H)=>H===m?{...R,...$}:R)})};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(we,{})}),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=>h({...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=>h({...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=>h({...l,api:m.target.value}),children:Ma.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=>h({...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=>h({...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=>h({...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:[T&&e.jsx("span",{className:`fetch-msg ${T.ok?"ok":"err"}`,title:T.text,children:T.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:I||!l.baseUrl.trim(),title:a("fetchModelsHint"),onClick:_,children:[e.jsx(vt,{})," ",a(I?"fetchingModels":"fetchModels")]})]})]}),l.models.map((m,$)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:m.id,onChange:R=>Y($,{id:R.target.value}),placeholder:a("modelIdReq")}),e.jsx("input",{type:"text",value:m.name,onChange:R=>Y($,{name:R.target.value}),placeholder:a("displayName")}),e.jsxs("select",{value:m.input,onChange:R=>Y($,{input:R.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:R=>Y($,{reasoning:R.target.checked})}),e.jsx("span",{children:a("reasoning")})]}),e.jsx("input",{type:"number",value:m.contextWindow,onChange:R=>Y($,{contextWindow:R.target.value}),placeholder:a("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:m.maxTokens,onChange:R=>Y($,{maxTokens:R.target.value}),placeholder:a("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:a("removeModel"),onClick:()=>h({...l,models:l.models.filter((R,H)=>H!==$)}),children:e.jsx(We,{})})]},$)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>h({...l,models:[...l.models,Nt()]}),children:[e.jsx(Le,{})," ",a("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>h(null),children:a("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!l.providerId.trim()||!l.models.some(m=>m.id.trim()),onClick:b,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&&!N[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:()=>M($=>({...$,[m.id]:!0})),children:[e.jsx(Lt,{})," ",a("replaceKey")]}),m.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:a("clearKeyTitle"),onClick:()=>P(m.id),children:[e.jsx(We,{})," ",a("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:a("pasteKey"),value:u[m.id]??"",onChange:$=>g(R=>({...R,[m.id]:$.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(u[m.id]??"").trim()||p===m.id,onClick:()=>F(m),children:[e.jsx(Ys,{})," ",p===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:()=>h(Ra(m)),children:e.jsx(Lt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:a("delete"),onClick:()=>V(m),children:e.jsx(We,{})})]})]},m.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>h(Ea()),children:[e.jsx(Le,{})," ",a("addProvider")]})})]})]})})}function Oe({title:t,subtitle:s,enabled:n,onToggle:i}){const o=le();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:i,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Ia({chat:t,send:s,onClose:n}){const i=le(),o=t.settings,[c,a]=r.useState(""),[l,h]=r.useState("append"),u=r.useRef(!1),[g,p]=r.useState(""),[k,N]=r.useState("append"),M=r.useRef(!1),[I,E]=r.useState(""),f=r.useRef(!1),[S,T]=r.useState("");if(r.useEffect(()=>{o&&(h(o.promptMode),!u.current&&(a(l==="append"||o.customSystemPrompt?o.customSystemPrompt:o.defaultSystemPrompt||""),N(o.visionBridgePromptMode),!M.current&&(p(k==="append"||o.visionBridgePrompt?o.visionBridgePrompt:o.visionBridgeDefaultPrompt||""),f.current||E(o.reviewPrompt))))},[o,l,k]),!o)return null;const D=new Set(o.disabledSkills),w=new Set(o.disabledExtensions),x=b=>s({type:"set_settings",...b}),L=b=>{const P=new Set(D);P.has(b.name)?P.delete(b.name):P.add(b.name),x({disabledSkills:[...P]})},d=b=>{const P=new Set(w);P.has(b.id)?P.delete(b.id):P.add(b.id),x({disabledExtensions:[...P]})},_=b=>{const P=new Set(o.reviewSkills.filter(V=>!V.enabled).map(V=>V.name));P.has(b.name)?P.delete(b.name):P.add(b.name),x({reviewDisabledSkills:[...P]})},F=()=>{const b=l==="replace"&&o.defaultSystemPrompt&&c===o.defaultSystemPrompt?"":c;x({promptMode:l,customSystemPrompt:b})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal settings-modal",onClick:b=>b.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":i("close"),onClick:n,children:e.jsx(we,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(Ge,{className:"modal-head-icon"}),e.jsx("h2",{children:i("settingsTitle")})]}),e.jsx("p",{className:"modal-desc",children:i("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(ut,{className:"set-section-icon"}),i("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:l,onChange:b=>{const P=b.target.value;h(P),x({promptMode:P})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:i("promptPlaceholder"),value:c,onFocus:()=>u.current=!0,onBlur:()=>{u.current=!1,F()},onChange:b=>a(b.target.value)}),e.jsx("p",{className:"set-hint",children:i(l==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(et,{className:"set-section-icon"}),i("settingsSkills"),e.jsx("span",{className:"set-count",children:o.skills.length})]}),o.skills.length===0?e.jsx("p",{className:"set-empty",children:i("noSkills")}):e.jsx("div",{className:"set-list",children:o.skills.map(b=>e.jsx(Oe,{title:b.name,subtitle:b.description,enabled:b.enabled,onToggle:()=>L(b)},b.name))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ks,{className:"set-section-icon"}),i("settingsExtensions"),e.jsx("span",{className:"set-count",children:o.extensions.length})]}),o.extensions.length===0?e.jsx("p",{className:"set-empty",children:i("noExtensions")}):e.jsx("div",{className:"set-list",children:o.extensions.map(b=>e.jsx(Oe,{title:b.name,subtitle:b.path,enabled:b.enabled,onToggle:()=>d(b)},b.id))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ut,{className:"set-section-icon"}),i("settingsReview"),e.jsx("span",{className:"set-count",children:o.reviewSkills.length})]}),e.jsx("p",{className:"set-hint",children:i("settingsReviewDesc")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:i("reviewPromptPlaceholder"),value:I,onFocus:()=>f.current=!0,onBlur:()=>{f.current=!1,x({reviewPrompt:I})},onChange:b=>E(b.target.value)}),e.jsx("p",{className:"set-hint",children:i("reviewPromptHint")}),e.jsx("div",{className:"set-field-label",children:i("settingsReviewSkills")}),o.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:i("noSkills")}):e.jsx("div",{className:"set-list",children:o.reviewSkills.map(b=>e.jsx(Oe,{title:b.name,subtitle:b.description,enabled:b.enabled,onToggle:()=>_(b)},`review-${b.name}`))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ns,{className:"set-section-icon"}),i("settingsVisionBridge")]}),e.jsx(Oe,{title:i("visionBridgeEnabled"),subtitle:i("settingsVisionBridgeDesc"),enabled:o.visionBridgeEnabled,onToggle:()=>x({visionBridgeEnabled:!o.visionBridgeEnabled})}),!o.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:i("visionBridgeOffHint")}),o.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:o.visionBridgeModel??"",onChange:b=>x({visionBridgeModel:b.target.value||null}),children:[e.jsx("option",{value:"",children:i("visionBridgeAuto")}),o.visionModels.map(b=>e.jsx("option",{value:`${b.provider}/${b.id}`,children:b.label},`${b.provider}/${b.id}`))]})]}),o.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:k,onChange:b=>{const P=b.target.value;N(P),x({visionBridgePromptMode:P})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]})]}),o.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:i("visionBridgePromptPlaceholder"),value:g,onFocus:()=>M.current=!0,onBlur:()=>{M.current=!1;const b=k==="replace"&&o.visionBridgeDefaultPrompt&&g===o.visionBridgeDefaultPrompt?"":g;x({visionBridgePromptMode:k,visionBridgePrompt:b})},onChange:b=>p(b.target.value)}),o.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:i(k==="append"?"visionBridgePromptAppendHint":"visionBridgePromptReplaceHint")}),o.visionBridgeEnabled&&(o.visionModels.length===0?e.jsx("p",{className:"set-hint",children:i("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:i("visionBridgeCurrent",{model:o.visionBridgeModel??i("visionBridgeAuto")})}))]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ge,{className:"set-section-icon"}),i("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:i("presetNamePlaceholder"),value:S,onChange:b=>T(b.target.value),onKeyDown:b=>{b.key==="Enter"&&S.trim()&&(s({type:"save_preset",name:S.trim()}),T(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!S.trim(),onClick:()=>{s({type:"save_preset",name:S.trim()}),T("")},children:[e.jsx(Le,{})," ",i("saveAsPreset")]})]}),o.presets.length===0?e.jsx("p",{className:"set-empty",children:i("noPresets")}):e.jsx("div",{className:"set-list",children:o.presets.map(b=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:b.name}),e.jsxs("div",{className:"set-row-desc",children:[b.promptMode==="replace"?i("promptModeReplace"):i("promptModeAppend"),b.disabledSkills.length>0&&` · ${i("settingsSkills")} ${b.disabledSkills.length}`,b.disabledExtensions.length>0&&` · ${i("settingsExtensions")} ${b.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:b.name}),children:i("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:i("deletePreset"),onClick:()=>s({type:"delete_preset",name:b.name}),children:e.jsx(We,{})})]})]},b.name))})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:n,children:i("close")})})]})})}function Pa(t,s){const n=Math.max(0,Date.now()-t),i=Math.floor(n/6e4);if(i<1)return s("bgTaskJustNow");if(i<60)return s("bgTaskMinutes",{n:i});const o=Math.floor(i/60);return o<24?s("bgTaskHours",{n:o}):s("bgTaskDays",{n:Math.floor(o/24)})}function Ba({servers:t,send:s,onClose:n}){const i=le(),[o,c]=r.useState(new Set),a=l=>c(h=>{const u=new Set(h);return u.has(l)?u.delete(l):u.add(l),u});return r.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(Ye,{})," ",i("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:i("close"),onClick:n,children:e.jsx(we,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(Ye,{}),e.jsx("span",{children:i("bgTasksEmpty")}),e.jsx("small",{children:i("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:i("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:[i("bgTaskPid")," ",l.pid]}),e.jsxs("span",{children:[i("bgTaskSince")," ",Pa(l.since,i)]})]}),l.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${o.has(l.port)?"open":""}`,title:`${i("bgTaskCommand")}: ${l.command}`,onClick:()=>a(l.port),children:[e.jsx(Xe,{}),e.jsx("code",{children:l.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:i("bgTaskStop"),onClick:()=>s({type:"kill_background_server",port:l.port}),children:[e.jsx(Ve,{}),e.jsx("span",{children:i("bgTaskStop")})]})]},l.port))}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:i("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(xt,{}),e.jsx("span",{children:i("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:i("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(Ve,{}),e.jsx("span",{children:i("bgTaskStopAll")})]})]})]})})}function He(t,s){return t.toLowerCase().includes(s)}function Da({send:t,sessions:s,projects:n,cwd:i,fileSearch:o,onClose:c,onSwitchSession:a,onSwitchProject:l,onPreviewFile:h}){const u=le(),g=r.useRef(null),[p,k]=r.useState(""),N=r.useDeferredValue(p),[M,I]=r.useState(0),E=r.useRef(1),f=r.useRef(0),S=r.useRef(null);r.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var m;return(m=g.current)==null?void 0:m.focus()})},[]);const[T,D]=r.useState(!1);r.useEffect(()=>{S.current&&clearTimeout(S.current);const m=N.trim();if(m)return S.current=setTimeout(()=>{const $=++E.current;f.current=$,D(!0),t({type:"search_files",reqId:$,query:m})},300),()=>{S.current&&clearTimeout(S.current)}},[N]);const w=N.trim().toLowerCase(),x=r.useMemo(()=>w?s.filter(m=>He(m.firstMessage??"",w)||He(m.name??"",w)||He(m.path.split(/[\\/]/).pop()??"",w)).slice(0,20):[],[s,w]),L=r.useMemo(()=>w?n.filter(m=>He(m.path,w)).slice(0,10):[],[n,w]),d=r.useMemo(()=>!w||!o||o.reqId!==f.current||!o.ok?[]:o.results,[o,w]);r.useEffect(()=>{o&&o.reqId===f.current&&f.current!==0&&D(!1)},[o]);const _=!!o&&o.ok&&o.truncated,F=r.useMemo(()=>[...x.map(m=>({kind:"session",path:m.path})),...L.map(m=>({kind:"project",path:m.path})),...d.filter(m=>m.type==="file").map(m=>({kind:"file",path:m.path,name:m.name}))],[x,L,d]);r.useEffect(()=>{I(0)},[N]);const b=r.useCallback(m=>{m&&(m.kind==="session"?a(m.path):m.kind==="project"?l(m.path):h(m.path,m.name),c())},[a,l,h,c]);r.useEffect(()=>{const m=$=>{$.key==="Escape"?($.preventDefault(),$.stopPropagation(),c()):$.key==="ArrowDown"?($.preventDefault(),I(R=>Math.min(R+1,F.length-1))):$.key==="ArrowUp"?($.preventDefault(),I(R=>Math.max(R-1,0))):$.key==="Enter"&&($.preventDefault(),b(F[M]))};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[F,M,b,c]);const P=x.length+L.length+d.length,V=(m,$,R)=>e.jsxs("div",{className:"gs-section-head",children:[R,e.jsx("span",{children:m}),e.jsx("em",{children:$})]});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(Je,{}),e.jsx("input",{ref:g,type:"text",value:p,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(we,{})})]}),e.jsxs("div",{className:"gs-results",children:[!w&&e.jsx("div",{className:"gs-empty",children:u("gsHint")}),w&&P===0&&!_&&e.jsx("div",{className:"gs-empty",children:u(T?"gsSearching":"gsNoResults")}),x.length>0&&e.jsxs("div",{className:"gs-section",children:[V(u("gsSessions"),x.length,e.jsx(Qe,{})),x.map(m=>{Y++;const $=Y;return e.jsxs("button",{type:"button",className:$===M?"gs-item active":"gs-item",onMouseEnter:()=>I($),onClick:()=>b({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)})]}),L.length>0&&e.jsxs("div",{className:"gs-section",children:[V(u("gsProjects"),L.length,e.jsx(Ie,{})),L.map(m=>{Y++;const $=Y,R=i&&m.path===i;return e.jsxs("button",{type:"button",className:$===M?"gs-item active":"gs-item",onMouseEnter:()=>I($),onClick:()=>b({kind:"project",path:m.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[m.path.split(/[\\/]/).pop(),R&&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||w&&_)&&e.jsxs("div",{className:"gs-section",children:[V(u("gsFiles"),d.length,e.jsx(en,{})),d.map(m=>{Y++;const $=Y;return e.jsxs("button",{type:"button",className:$===M?"gs-item active":"gs-item",disabled:m.type==="dir",title:m.type==="dir"?void 0:u("gsOpenPreview"),onMouseEnter:()=>I($),onClick:()=>{m.type==="file"&&b({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}`)}),_&&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 ct=5e3;function Fa({file:t,content:s,send:n,onAddLines:i,onAttach:o,onClose:c}){const a=le(),[l,h]=r.useState(null),[u,g]=r.useState(!1),[p,k]=r.useState(null),[N,M]=r.useState(!1),[I,E]=r.useState(!1),[f,S]=r.useState(!1),[T,D]=r.useState(""),[w,x]=r.useState(!0),L=r.useRef(!1),[d,_]=r.useState(!0),[F,b]=r.useState(!1),[P,V]=r.useState(100),Y=r.useRef(0),m=r.useRef(!1),$=r.useRef(null);r.useEffect(()=>{g(!0),h(null),k(null),S(!1),D(""),x(!0),L.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),r.useEffect(()=>{s&&s.path===t.path&&(h(s),f||D(s.text),g(!1))},[s,f,t.path]),r.useEffect(()=>{const A=K=>{if(K.key==="Escape"){ue();return}if((K.ctrlKey||K.metaKey)&&K.key.toLowerCase()==="s"&&f){K.preventDefault(),ge();return}const te=K.target,xe=te&&(te.tagName==="INPUT"||te.tagName==="TEXTAREA"||te.isContentEditable);(K.ctrlKey||K.metaKey)&&K.key.toLowerCase()==="a"&&!xe&&(K.preventDefault(),ae())};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[c,l,f,T]),r.useEffect(()=>{const A=()=>{m.current=!1,M(!1)};return window.addEventListener("mouseup",A),()=>window.removeEventListener("mouseup",A)},[]);const R=r.useMemo(()=>{if(!l)return[];const A=l.text.split(`
|
|
18
|
-
`);return A.length>0&&A[A.length-1]===""&&A.pop(),A.slice(0,ct)},[l]),H=(l==null?void 0:l.lines)??0,q=H>ct,se=(A,K)=>{if(K){const te=Y.current>0?Y.current:A;k({start:Math.min(te,A),end:Math.max(te,A)})}else Y.current=A,k({start:A,end:A})},ae=()=>{R.length!==0&&(Y.current=1,k({start:1,end:R.length}))},Q=()=>{p&&(i(t.path,t.name,p.start,p.end),E(!0),$.current&&clearTimeout($.current),$.current=setTimeout(()=>E(!1),1400))},ne=l!==null&&l.kind==="text"&&!l.binary&&!l.truncated,ce=()=>{D((l==null?void 0:l.text)??""),S(!1),L.current&&x(!0)},me=()=>{if(f){if(T!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges")))return;ce();return}!ne||!l||(L.current=dt(t.name)&&w,dt(t.name)&&x(!1),k(null),D(l.text),S(!0))},ge=()=>{!f||!l||!ne||n({type:"write_file",path:t.path,text:T})&&(S(!1),L.current&&x(!0),k(null))},ue=()=>{f&&T!==((l==null?void 0:l.text)??"")&&!window.confirm(a("discardFileChanges"))||c()},he=A=>{V(Math.min(200,Math.max(50,A)))},ye=p?p.end-p.start+1:0,de=(l==null?void 0:l.binary)??!1,je=(l==null?void 0:l.truncated)??!1,ie=(l==null?void 0:l.kind)??"text",v=dt(t.name),W=v&&w&&!f&&ie==="text"&&!de,re=A=>nt(`/api/file?clientId=${encodeURIComponent(bt())}&path=${encodeURIComponent(A)}`);return e.jsx("div",{className:`fp-overlay ${F?"fullscreen":""}`,onMouseDown:A=>{A.target===A.currentTarget&&ue()},children:e.jsxs("div",{className:`fp ${F?"fullscreen":""}`,style:{"--fp-zoom":P/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&&ie==="text"&&!de&&a("fileLines",{n:H}),l&&` · ${_a(l.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[v&&ie==="text"&&!de&&l&&e.jsx("button",{type:"button",className:`fp-attach markdown ${w?"on":""}`,"data-tip":a(w?"showMarkdownSource":"showMarkdownPreview"),disabled:f,onClick:()=>x(A=>!A),children:w?e.jsx(ns,{}):e.jsx(sn,{})}),ie==="text"&&!de&&l&&e.jsx("button",{type:"button",className:`fp-attach edit ${f?"on":""}`,"data-tip":a(je?"fileEditTruncated":f?"exitEditFile":"editFile"),disabled:!ne&&!f,onClick:me,children:e.jsx(pt,{})}),ie==="text"&&!de&&!W&&e.jsx("button",{type:"button",className:`fp-attach wrap ${d?"on":""}`,"data-tip":a(d?"disableWrap":"enableWrap"),onClick:()=>_(A=>!A),children:e.jsx(tn,{})}),ie==="text"&&l&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":a("zoomOut"),disabled:P<=50,onClick:()=>he(P-10),children:e.jsx(As,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:a("resetZoom"),onClick:()=>V(100),children:[P,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":a("zoomIn"),disabled:P>=200,onClick:()=>he(P+10),children:e.jsx(Os,{})})]}),ie!=="video"&&ie!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":a("attachInlineTip"),onClick:()=>o(t.path,t.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":a("referenceTip"),onClick:()=>o(t.path,t.name,"reference"),children:e.jsx(mt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${F?"on":""}`,"data-tip":a(F?"exitFullscreen":"fullscreen"),onClick:()=>b(A=>!A),children:F?e.jsx(Vs,{}):e.jsx(Js,{})}),e.jsx("button",{type:"button",className:"fp-close",title:a("close"),onClick:ue,children:e.jsx(we,{})})]})]}),je&&ie==="text"&&!de&&e.jsx("div",{className:"fp-notice",children:a("previewTruncated")}),u&&!l&&e.jsx("div",{className:"fp-empty",children:a("loading")}),!u&&ie==="none"&&!de&&e.jsx("div",{className:"fp-empty",children:a("previewNotSupported")}),!u&&ie==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:re(t.path),alt:t.name})}),!u&&ie==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:re(t.path),controls:!0,preload:"metadata"})}),!u&&W&&l&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(at,{text:l.text})})}),!u&&de&&ie!=="image"&&ie!=="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&&f&&ie==="text"&&!de&&l&&e.jsx("textarea",{className:`fp-editor ${d?"":"no-wrap"}`,value:T,onChange:A=>D(A.target.value),wrap:d?"soft":"off",spellCheck:!1,autoFocus:!0}),!u&&!W&&!f&&ie==="text"&&!de&&l&&R.length===0&&e.jsx("div",{className:"fp-empty",children:a("emptyFile")}),!u&&!W&&!f&&ie==="text"&&!de&&R.length>0&&e.jsxs("div",{className:`fp-code ${N?"dragging":""} ${d?"":"no-wrap"}`,onMouseDown:A=>{A.button===0&&A.preventDefault()},children:[R.map((A,K)=>{const te=K+1,xe=p!==null&&te>=p.start&&te<=p.end;return e.jsxs("div",{className:`fp-line ${xe?"sel":""}`,onMouseDown:ve=>{ve.button===0&&(se(te,ve.shiftKey),m.current=!0,M(!0))},onMouseEnter:()=>{m.current&&se(te,!0)},children:[e.jsx("span",{className:"fp-num",children:te}),e.jsx("span",{className:"fp-code-text",children:A})]},te)}),q&&e.jsx("div",{className:"fp-lines-note",children:a("previewLinesTruncated",{n:ct})})]}),e.jsx("div",{className:"fp-foot",children:f?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:me,children:a("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:T===((l==null?void 0:l.text)??""),onClick:ge,children:[e.jsx(qs,{})," ",a("saveFile")]})]})]}):!W&&ie==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:p?a("selectedRange",{n:ye,start:p.start,end:p.end}):a("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:R.length===0,onClick:ae,children:a("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!p,onClick:()=>k(null),children:a("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!p||de,onClick:Q,children:[I?e.jsx(yt,{}):null,a(I?"addedToChat":"addToChat")]})]})]})})]})})}function dt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function _a(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const js="pi-web-sounds",De={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function bs(){try{const t=localStorage.getItem(js);if(!t)return{...De};const s=JSON.parse(t),n={...De,...s};for(const i of["enabled","question","done","start","error"])typeof n[i]!="boolean"&&(n[i]=De[i]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=De.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...De}}}function $a(t){try{localStorage.setItem(js,JSON.stringify(t))}catch{}}let Fe=null;function Aa(){try{if(!Fe){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;Fe=new t}return Fe.state==="suspended"&&Fe.resume(),Fe}catch{return null}}const Oa=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Ha=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],Wa=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],Ua=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],qa={question:Oa,done:Ha,start:Wa,error:Ua};function Ka(t,s,n){const i=t.createOscillator(),o=t.createGain();i.type=s.type,i.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),i.connect(o),o.connect(t.destination),i.start(c),i.stop(c+s.dur+.05)}function _e(t,s=bs()){if(!s.enabled||!s[t])return;const n=Aa();if(!n)return;const i=Math.max(0,Math.min(1,s.volume/100));for(const o of qa[t])Ka(n,o,i)}const ft="pi-web-ui:theme",ks="dark",Jt="theme-stylesheet",Qt="pi-web-ui:theme-change";function Ns(){try{const t=localStorage.getItem(ft);if(t&&t!==ks)return t}catch{}return null}function za(t){try{t?localStorage.setItem(ft,t):localStorage.removeItem(ft)}catch{}}function ws(t){let s=document.getElementById(Jt);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Qt));return}s||(s=document.createElement("link"),s.id=Jt,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(Qt))}async function Va(){try{const t=await fetch(nt("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Ga(){const[t,s]=r.useState([]),[n,i]=r.useState(()=>Ns());return r.useEffect(()=>{let c=!1;return Va().then(a=>{c||s(a)}),()=>{c=!0}},[]),r.useEffect(()=>{ws(n),za(n)},[n]),{themes:t,theme:n,switchTheme:c=>i(c===ks?null:c)}}function si(){const t=getComputedStyle(document.documentElement),s=(n,i)=>t.getPropertyValue(n).trim()||i;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 Ja=r.lazy(()=>Ls(()=>import("./TerminalPanel-D7lQ3g5k.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function Qa({notice:t,onDismiss:s}){const n=le(),[i,o]=r.useState(!1);r.useEffect(()=>{if(i)return;const a=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(a)},[i,t.id,t.level,s]);const c=t.level==="error"?on:t.level==="warning"?rn:Zs;return e.jsxs("div",{className:`notice notice-${t.level}${i?" 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(we,{})})]})}const Ya=[];function Za(){var y,B,J,G,X,oe,pe,ke,Pe,j,Z,z,fe;const t=le(),{chat:s,send:n,dismissNotice:i,pushNotice:o,terminal:c}=Cn(),[a,l]=r.useState([]),[h,u]=r.useState(null),[g,p]=r.useState("chat"),[k,N]=r.useState(null),[M,I]=r.useState(()=>window.matchMedia("(max-width: 768px)").matches);r.useEffect(()=>{const C=window.matchMedia("(max-width: 768px)"),O=ee=>I(ee.matches);return C.addEventListener("change",O),()=>C.removeEventListener("change",O)},[]);const[E,f]=r.useState(!1),[S,T]=r.useState(!1),[D,w]=r.useState(!1),[x,L]=r.useState(!1),[d,_]=r.useState(!1);r.useEffect(()=>{const C=O=>{!(O.ctrlKey||O.metaKey)||O.key.toLowerCase()!=="k"||(O.preventDefault(),_(ee=>!ee))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);const[F,b]=r.useState(bs),{themes:P,theme:V,switchTheme:Y}=Ga(),m=r.useRef(null),$=r.useRef(null),R=r.useRef(0),H=r.useRef(!1);r.useEffect(()=>{$a(F)},[F]),r.useEffect(()=>{var ee;const C=((ee=s.state)==null?void 0:ee.isStreaming)??!1,O=m.current;m.current=C,O!==null&&(!O&&C?_e("start",F):O&&!C&&_e("done",F))},[(y=s.state)==null?void 0:y.isStreaming,F]),r.useEffect(()=>{var O;const C=((O=s.dialog)==null?void 0:O.id)??null;C!==null&&C!==$.current&&_e("question",F),$.current=C},[s.dialog,F]),r.useEffect(()=>{const C=[...s.notices].reverse().find(O=>O.level==="error");C&&C.id!==R.current&&(R.current=C.id,_e("error",F))},[s.notices,F]);const q=(C,O,ee,Ne=!1,Ce)=>{const it=`${C}|${ee}|${Ce?`${Ce.start}-${Ce.end}`:""}`;l(Se=>Se.some(Be=>`${Be.path}|${Be.mode}|${Be.lines?`${Be.lines.start}-${Be.lines.end}`:""}`===it)?Se:[...Se,{path:C,name:O,mode:ee,isDir:Ne,...Ce?{lines:Ce}:{}}])},se=C=>l(O=>O.filter(ee=>ee.key?ee.key!==C:ee.path!==C)),ae=r.useCallback(C=>(!C.type.startsWith("list_")&&!C.type.startsWith("get_")&&N(null),n(C)),[n]),Q=r.useRef(0),ne=r.useRef(0),ce=C=>{var Ne;const O=Date.now();(Ne=s.state)!=null&&Ne.model&&!s.state.model.vision&&O-ne.current>1e4&&(ne.current=O,o("warning",t("imageNotSupported")));const ee=`paste-${++Q.current}`;l(Ce=>[...Ce,{path:"",key:ee,name:C.name,mode:"inline",imageData:C.data,mimeType:C.mimeType}])},me=async C=>{for(const O of C){const ee=await ya(O);if(!ee){o("error",t("imageLoadFailed",{name:O.name}));continue}ce(ee)}},ge=20*1024*1024,ue=r.useRef(0),he=async C=>{if(C.size>ge){o("warning",t("fileTooLarge",{name:C.name,size:ge/1024/1024}));return}let O;try{O=(await new Promise((Ce,it)=>{const Se=new FileReader;Se.onload=()=>Ce(Se.result),Se.onerror=()=>it(Se.error??new Error("read failed")),Se.readAsDataURL(C)})).replace(/^data:[^;]*;base64,/,"")}catch{o("error",t("fileLoadFailed",{name:C.name}));return}const ee=`upload-${++ue.current}`;l(Ne=>[...Ne,{path:"",key:ee,name:C.name,mode:"inline",fileData:O,size:C.size,mimeType:C.type||void 0}])},ye=async C=>{for(const O of C)qe(O.type)?await me([O]):await he(O)},de=r.useCallback((C,O)=>{n({type:"edit_message",messageId:C,text:O})},[n]),je=r.useCallback(()=>T(!0),[]),ie=r.useCallback(()=>l([]),[]),v=r.useCallback(se,[]),W=r.useCallback(me,[me]),re=r.useCallback(ye,[ye]),A=(B=s.state)==null?void 0:B.model,K=(J=s.state)==null?void 0:J.thinkingLevel,te=(G=s.state)==null?void 0:G.availableThinkingLevels,xe=r.useMemo(()=>A?{model:A,thinkingLevel:K??"off",availableThinkingLevels:te??[]}:null,[A,K,te]),ve=r.useCallback(()=>{var C,O;return!s.ready||s.terminals.length!==0?!1:(c.create({id:Ze(),conversationId:s.activeConversationId||((C=s.state)==null?void 0:C.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((O=s.state)==null?void 0:O.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(X=s.state)==null?void 0:X.cwd,s.terminals.length,t,c]);return r.useEffect(()=>{if(H.current){if(g!=="terminal"||s.terminals.length!==0){H.current=!1;return}ve()&&(H.current=!1)}},[s.terminals.length,ve,g]),e.jsxs("div",{className:"app",onDragOver:C=>C.preventDefault(),onDrop:C=>C.preventDefault(),children:[e.jsx(hn,{chat:s,send:n,view:g,onViewChange:C=>{H.current=C==="terminal"&&s.terminals.length===0,H.current&&ve()&&(H.current=!1),p(C),N(null)},onOpenPanel:N,onManageModels:()=>T(!0),onOpenSettings:()=>w(!0),onOpenBgTasks:()=>L(!0),onOpenGlobalSearch:()=>_(!0),sound:F,onSoundChange:b,onSoundPreview:C=>_e(C,F),themes:P,theme:V,onThemeChange:Y}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(C=>e.jsx(Qa,{notice:C,onDismiss:i},C.id))}),e.jsxs("div",{className:"layout",children:[k&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>N(null)}),e.jsxs("div",{className:`view-pane ${g==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${k==="left"?"open":""}`,children:e.jsx(gn,{send:ae,active:!M||k==="left",ready:s.ready,status:s.status,cwd:((oe=s.state)==null?void 0:oe.cwd)??"",sessionFile:((pe=s.state)==null?void 0:pe.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(fa,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:de,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}),e.jsx(ja,{send:n,ready:s.ready,streaming:((ke=s.state)==null?void 0:ke.isStreaming)??!1,queueSteering:((Pe=s.state)==null?void 0:Pe.queue.steering)??0,queueFollowUp:((j=s.state)==null?void 0:j.queue.followUp)??0,messages:((Z=s.state)==null?void 0:Z.messages)??Ya,slashCommands:s.slashCommands,modelState:xe,models:s.models,modelsLoading:s.modelsLoading,attachments:a,onRemoveAttachment:v,onAddImageFiles:W,onAddLocalFiles:re,onNotice:o,onManageModels:je,onSent:ie})]}),e.jsx("div",{className:`panel-drawer drawer-right ${k==="right"?"open":""}`,children:e.jsx(Bn,{send:ae,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((z=s.state)==null?void 0:z.cwd)??"",onAttach:(C,O,ee,Ne)=>{N(null),q(C,O,ee,Ne)},onPreview:(C,O)=>{N(null),u({path:C,name:O})},onNotice:(C,O)=>o(C,O)})})]}),e.jsx("div",{className:`view-pane ${g==="terminal"?"":"hidden"}`,children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(Ja,{chat:s,send:n,terminal:c})})}),e.jsx("div",{className:`view-pane ${g==="git"?"":"hidden"}`,children:e.jsx(Sa,{chat:s,send:n,terminal:c,active:g==="git",onSwitchToTerminal:()=>p("terminal")})})]}),e.jsx(ka,{chat:s,send:n}),s.dialog&&e.jsx(wa,{dialog:s.dialog,send:n}),h&&e.jsx(Fa,{file:h,content:s.fileContent,send:n,onAddLines:(C,O,ee,Ne)=>q(C,O,"lines",!1,{start:ee,end:Ne}),onAttach:(C,O,ee)=>q(C,O,ee),onClose:()=>u(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!E&&!S&&e.jsx(Ta,{send:n,piConfigured:s.state.piConfigured,providers:s.providers,installResult:s.installResult,onClose:()=>f(!0)}),S&&e.jsx(La,{send:n,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,onClose:()=>T(!1)}),D&&e.jsx(Ia,{chat:s,send:n,onClose:()=>w(!1)}),x&&e.jsx(Ba,{servers:s.bgServers,send:n,onClose:()=>L(!1)}),d&&e.jsx(Da,{send:n,sessions:s.sessions,projects:s.projects,cwd:((fe=s.state)==null?void 0:fe.cwd)??"",fileSearch:s.fileSearch,onClose:()=>_(!1),onSwitchSession:C=>{n({type:"switch_session",path:C})},onSwitchProject:C=>{n({type:"set_cwd",path:C})},onPreviewFile:(C,O)=>{u({path:C,name:O})}})]})}fn();ws(Ns());Ms.createRoot(document.getElementById("root")).render(e.jsx(r.StrictMode,{children:e.jsx(un,{children:e.jsx(Za,{})})}));export{xt as F,Qt as T,Le as a,si as b,ti as c,Lt as d,We as e,we as f,Gs as g,Xe as h,Ze as r,le as u};
|