pi-web-ui 0.30.0 → 0.32.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/LICENSE +21 -21
- package/README.md +295 -295
- package/README.zh-CN.md +279 -279
- package/bin/pi-web-ui.mjs +0 -0
- package/deploy/com.xingshuyin.pi-web-ui.plist +48 -48
- package/deploy/nginx-subpath.conf +88 -88
- package/deploy/pi-web-ui-task.xml +71 -71
- package/deploy/pi-web-ui.service +31 -31
- package/dist/server/agent-service.js +67 -144
- package/dist/server/attachments.js +3 -3
- package/dist/server/client-state.js +2 -0
- package/dist/server/index.js +39 -48
- package/dist/server/model-admin.js +94 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/settings-service.js +9 -1
- package/dist/server/slash-commands.js +2 -0
- package/dist/server/terminals.js +19 -2
- package/dist/server/themes.js +20 -2
- package/extensions/webui.ts +192 -192
- package/package.json +1 -1
- package/themes/light.css +65 -0
- package/themes/md-preview.css +6911 -0
- package/themes/white.css +6972 -0
- package/web/dist/assets/{TerminalPanel-CMBWruhs.js → TerminalPanel-D9N7NOQl.js} +1 -1
- package/web/dist/assets/index-C9LigvHH.css +10 -0
- package/web/dist/assets/index-vcrKbPaa.js +19 -0
- package/web/dist/favicon.svg +8 -8
- package/web/dist/index.html +15 -15
- package/web/public/favicon.svg +8 -8
- package/web/dist/assets/index-C8YkKrP3.css +0 -10
- package/web/dist/assets/index-DpzPCOcG.js +0 -19
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-D9N7NOQl.js","assets/markdown-DRBrS2Nf.js","assets/xterm-D1D2FVe3.js","assets/react-C9ovnpIm.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as Le,a,j as e,M as rs,b as Fs,c as As}from"./markdown-DRBrS2Nf.js";import{r as os}from"./react-C9ovnpIm.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))l(c);new MutationObserver(c=>{for(const r of c)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&l(i)}).observe(document,{childList:!0,subtree:!0});function n(c){const r={};return c.integrity&&(r.integrity=c.integrity),c.referrerPolicy&&(r.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?r.credentials="include":c.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function l(c){if(c.ep)return;c.ep=!0;const r=n(c);fetch(c.href,r)}})();var Ke={},Rt;function $s(){if(Rt)return Ke;Rt=1;var t=os();return Ke.createRoot=t.createRoot,Ke.hydrateRoot=t.hydrateRoot,Ke}var Os=$s();const Hs="modulepreload",Ws=function(t){return"/"+t},Lt={},qs=function(s,n,l){let c=Promise.resolve();if(n&&n.length>0){let i=function(m){return Promise.all(m.map(g=>Promise.resolve(g).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),u=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=i(n.map(m=>{if(m=Ws(m),m in Lt)return;Lt[m]=!0;const g=m.endsWith(".css"),p=g?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${p}`))return;const k=document.createElement("link");if(k.rel=g?"stylesheet":Hs,g||(k.as="script"),k.crossOrigin="",k.href=m,u&&k.setAttribute("nonce",u),document.head.appendChild(k),g)return new Promise((C,T)=>{k.addEventListener("load",C),k.addEventListener("error",()=>T(new Error(`Unable to preload CSS for ${m}`)))})}))}function r(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return c.then(i=>{for(const o of i||[])o.status==="rejected"&&r(o.reason);return s().catch(r)})};var ls={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},It=Le.createContext&&Le.createContext(ls),Us=["attr","size","title"];function zs(t,s){if(t==null)return{};var n,l,c=Ks(t,s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(l=0;l<r.length;l++)n=r[l],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(c[n]=t[n])}return c}function Ks(t,s){if(t==null)return{};var n={};for(var l in t)if({}.hasOwnProperty.call(t,l)){if(s.indexOf(l)!==-1)continue;n[l]=t[l]}return n}function Qe(){return Qe=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var l in n)({}).hasOwnProperty.call(n,l)&&(t[l]=n[l])}return t},Qe.apply(null,arguments)}function Pt(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);s&&(l=l.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),n.push.apply(n,l)}return n}function Ye(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Pt(Object(n),!0).forEach(function(l){Vs(t,l,n[l])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Pt(Object(n)).forEach(function(l){Object.defineProperty(t,l,Object.getOwnPropertyDescriptor(n,l))})}return t}function Vs(t,s,n){return(s=Gs(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Gs(t){var s=Js(t,"string");return typeof s=="symbol"?s:s+""}function Js(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var l=n.call(t,s);if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function cs(t){return t&&t.map((s,n)=>Le.createElement(s.tag,Ye({key:n},s.attr),cs(s.child)))}function O(t){return s=>Le.createElement(Qs,Qe({attr:Ye({},t.attr)},s),cs(t.child))}function Qs(t){var s=n=>{var l=t.attr,c=t.size,r=t.title,i=zs(t,Us),o=c||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),Le.createElement("svg",Qe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,l,i,{className:u,style:Ye(Ye({color:t.color||n.color},n.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),r&&Le.createElement("title",null,r),t.children)};return It!==void 0?Le.createElement(It.Consumer,null,n=>s(n)):s(ls)}function Ys(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"11",cy:"11",r:"8"},child:[]},{tag:"line",attr:{x1:"21",y1:"21",x2:"16.65",y2:"16.65"},child:[]},{tag:"line",attr:{x1:"8",y1:"11",x2:"14",y2:"11"},child:[]}]})(t)}function Xs(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"11",cy:"11",r:"8"},child:[]},{tag:"line",attr:{x1:"21",y1:"21",x2:"16.65",y2:"16.65"},child:[]},{tag:"line",attr:{x1:"11",y1:"8",x2:"11",y2:"14"},child:[]},{tag:"line",attr:{x1:"8",y1:"11",x2:"14",y2:"11"},child:[]}]})(t)}function ht(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polygon",attr:{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"},child:[]}]})(t)}function Se(t){return O({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 ds(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polygon",attr:{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"},child:[]},{tag:"path",attr:{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"},child:[]}]})(t)}function Zs(t){return O({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 qe(t){return O({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 ze(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"4 17 10 11 4 5"},child:[]},{tag:"line",attr:{x1:"12",y1:"19",x2:"20",y2:"19"},child:[]}]})(t)}function Bt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"12",cy:"12",r:"10"},child:[]},{tag:"circle",attr:{cx:"12",cy:"12",r:"6"},child:[]},{tag:"circle",attr:{cx:"12",cy:"12",r:"2"},child:[]}]})(t)}function en(t){return O({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 Xe(t){return O({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 Ze(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"12",cy:"12",r:"3"},child:[]},{tag:"path",attr:{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"},child:[]}]})(t)}function tn(t){return O({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 et(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"11",cy:"11",r:"8"},child:[]},{tag:"line",attr:{x1:"21",y1:"21",x2:"16.65",y2:"16.65"},child:[]}]})(t)}function sn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"},child:[]},{tag:"polyline",attr:{points:"17 21 17 13 7 13 7 21"},child:[]},{tag:"polyline",attr:{points:"7 3 7 8 15 8"},child:[]}]})(t)}function jt(t){return O({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 De(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"12",y1:"5",x2:"12",y2:"19"},child:[]},{tag:"line",attr:{x1:"5",y1:"12",x2:"19",y2:"12"},child:[]}]})(t)}function pi(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polygon",attr:{points:"5 3 19 12 5 21 5 3"},child:[]}]})(t)}function Dt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"},child:[]}]})(t)}function nn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"16.5",y1:"9.4",x2:"7.5",y2:"4.21"},child:[]},{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function an(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"12",cy:"12",r:"1"},child:[]},{tag:"circle",attr:{cx:"19",cy:"12",r:"1"},child:[]},{tag:"circle",attr:{cx:"5",cy:"12",r:"1"},child:[]}]})(t)}function rn(t){return O({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 tt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},child:[]}]})(t)}function on(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"3",y1:"12",x2:"21",y2:"12"},child:[]},{tag:"line",attr:{x1:"3",y1:"6",x2:"21",y2:"6"},child:[]},{tag:"line",attr:{x1:"3",y1:"18",x2:"21",y2:"18"},child:[]}]})(t)}function ln(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"},child:[]}]})(t)}function cn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"15 3 21 3 21 9"},child:[]},{tag:"polyline",attr:{points:"9 21 3 21 3 15"},child:[]},{tag:"line",attr:{x1:"21",y1:"3",x2:"14",y2:"10"},child:[]},{tag:"line",attr:{x1:"3",y1:"21",x2:"10",y2:"14"},child:[]}]})(t)}function dn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},child:[]},{tag:"path",attr:{d:"M7 11V7a5 5 0 0 1 10 0v4"},child:[]}]})(t)}function gt(t){return O({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 st(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polygon",attr:{points:"12 2 2 7 12 12 22 7 12 2"},child:[]},{tag:"polyline",attr:{points:"2 17 12 22 22 17"},child:[]},{tag:"polyline",attr:{points:"2 12 12 17 22 12"},child:[]}]})(t)}function un(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"},child:[]}]})(t)}function mn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"12",cy:"12",r:"10"},child:[]},{tag:"line",attr:{x1:"12",y1:"16",x2:"12",y2:"12"},child:[]},{tag:"line",attr:{x1:"12",y1:"8",x2:"12.01",y2:"8"},child:[]}]})(t)}function pn(t){return O({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 _t(t){return O({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 Ge(t){return O({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 _e(t){return O({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 us(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"},child:[]},{tag:"polyline",attr:{points:"13 2 13 9 20 9"},child:[]}]})(t)}function hn(t){return O({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 ms(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"},child:[]},{tag:"circle",attr:{cx:"12",cy:"12",r:"3"},child:[]}]})(t)}function ft(t){return O({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 Ft(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"},child:[]}]})(t)}function bt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"7 10 12 15 17 10"},child:[]},{tag:"line",attr:{x1:"12",y1:"15",x2:"12",y2:"3"},child:[]}]})(t)}function nt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"4",y:"4",width:"16",height:"16",rx:"2",ry:"2"},child:[]},{tag:"rect",attr:{x:"9",y:"9",width:"6",height:"6"},child:[]},{tag:"line",attr:{x1:"9",y1:"1",x2:"9",y2:"4"},child:[]},{tag:"line",attr:{x1:"15",y1:"1",x2:"15",y2:"4"},child:[]},{tag:"line",attr:{x1:"9",y1:"20",x2:"9",y2:"23"},child:[]},{tag:"line",attr:{x1:"15",y1:"20",x2:"15",y2:"23"},child:[]},{tag:"line",attr:{x1:"20",y1:"9",x2:"23",y2:"9"},child:[]},{tag:"line",attr:{x1:"20",y1:"14",x2:"23",y2:"14"},child:[]},{tag:"line",attr:{x1:"1",y1:"9",x2:"4",y2:"9"},child:[]},{tag:"line",attr:{x1:"1",y1:"14",x2:"4",y2:"14"},child:[]}]})(t)}function gn(t){return O({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 kt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},child:[]},{tag:"path",attr:{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"},child:[]}]})(t)}function fn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"16 18 22 12 16 6"},child:[]},{tag:"polyline",attr:{points:"8 6 2 12 8 18"},child:[]}]})(t)}function at(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"18 15 12 9 6 15"},child:[]}]})(t)}function it(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"9 18 15 12 9 6"},child:[]}]})(t)}function Ie(t){return O({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 Nt(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"20 6 9 17 4 12"},child:[]}]})(t)}function xn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"},child:[]},{tag:"polyline",attr:{points:"22 4 12 14.01 9 11.01"},child:[]}]})(t)}function vn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"},child:[]},{tag:"path",attr:{d:"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"},child:[]}]})(t)}function ps(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"12",y1:"19",x2:"12",y2:"5"},child:[]},{tag:"polyline",attr:{points:"5 12 12 5 19 12"},child:[]}]})(t)}function hs(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"12",y1:"5",x2:"12",y2:"19"},child:[]},{tag:"polyline",attr:{points:"19 12 12 19 5 12"},child:[]}]})(t)}function yn(t){return O({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"},child:[]},{tag:"line",attr:{x1:"12",y1:"9",x2:"12",y2:"13"},child:[]},{tag:"line",attr:{x1:"12",y1:"17",x2:"12.01",y2:"17"},child:[]}]})(t)}function jn(t){return O({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 Fe(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function Re({trigger:t,open:s,onOpenChange:n,children:l,align:c="right",fit:r=!1,direction:i="down",menuClassName:o}){const u=a.useRef(null);return a.useEffect(()=>{if(!s)return;const m=p=>{u.current&&!u.current.contains(p.target)&&n(!1)},g=p=>{p.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",g)}},[s,n]),e.jsxs("div",{className:`dropdown ${c} ${r?"fit":""} ${i==="up"?"dd-up":""}`,ref:u,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(Ie,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,children:l})]})}function ke({active:t,disabled:s=!1,title:n,onClick:l,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:l,children:c})}const gs="pi-web-ui:lang",bn={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",folderRef:"文件夹引用:{path}",refOnly:"仅引用:{path}",attachContent:"附加内容:{path}",attachLines:"附加选中行:{path}(第 {start}-{end} 行)",attachImage:"图片:{name}",attachFile:"文件:{name}",removeAttachment:"移除附件",attachHint:"将随下一条消息发送",uploadFile:"添加文件(图片/文本/任意文件,也可直接拖入或粘贴截图)",dropHereToAttach:"松开以添加文件",imageNotSupported:"当前模型不支持识图:图片将交给视觉桥转写(若未配置视觉模型则可能被忽略)",imageLoadFailed:"图片读取失败:{name}",fileLoadFailed:"文件读取失败:{name}",fileTooLarge:"文件过大已跳过(>{size}MB):{name}",foldersNotSupported:"不支持直接拖入文件夹,请展开后选择文件",placeholderStreaming:"智能体正在工作中…回车插队发送,或点「排队」等回答结束后发送",placeholderIdle:"给 pi 发送消息 — Enter 发送,/ 查看命令",placeholderConnecting:"正在连接服务器…",stopAgent:"停止智能体",stop:"停止",bgTasks:"后台任务",bgTasksTip:"AI 在后台启动的服务(npm run dev & 等)——可逐个停止或全部关闭,对话结束后仍保留",bgTasksEmpty:"暂无后台任务",bgTasksDesc:"AI 运行中启动并仍在监听的进程(按监听端口检测)",bgTaskPort:"端口",bgTaskPid:"PID",bgTaskSince:"启动",bgTaskStop:"停止",bgTaskStopAll:"全部关闭",bgTaskRefresh:"刷新",bgTaskJustNow:"刚刚",bgTaskMinutes:"{n} 分钟前",bgTaskHours:"{n} 小时前",bgTaskDays:"{n} 天前",stopBash:"停止",stopBashTip:"停止正在运行的 bash 命令(对话继续)",supplement:"排队",supplementTip:"加入队列:AI 回答完全结束后才发送(不打断)",queueSteerTag:"插队",queueFollowTag:"排队",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",protocolMismatch:"页面版本与服务器不一致(应用刚更新过),请刷新页面以恢复全部功能。",selectLinesHint:"点击选择行;拖拽或 Shift+点击选择范围",enableWrap:"开启自动换行",disableWrap:"关闭自动换行",selectedRange:"已选 {n} 行(第 {start}-{end} 行)",fileLines:"{n} 行",selectAll:"全选",clearSelection:"清除",addToChat:"添加到对话",addedToChat:"已添加",previewTruncated:"⚠ 文件过大,仅预览前 512KB",previewLinesTruncated:"… 文件行数过多,仅显示前 {n} 行",binaryFile:"🔣 二进制文件,已显示前 4KB 十六进制",binaryHexTruncated:"(文件更大,可下载完整文件)",previewNotSupported:"该类型文件不支持预览(仅图片 / 视频 / 文本)",emptyFile:"(空文件)",editFile:"编辑文件",exitEditFile:"退出编辑",saveFile:"保存文件",discardFileChanges:"放弃未保存的修改?",fileSaved:"已保存",fileEditTruncated:"文件过大,预览不完整,无法编辑",showMarkdownSource:"显示 Markdown 原文",showMarkdownPreview:"显示 Markdown 预览",fullscreen:"全屏",exitFullscreen:"退出全屏",zoomIn:"放大字号",zoomOut:"缩小字号",resetZoom:"重置缩放",pluginRequest:"插件请求",noOptions:"(无选项)",inputPlaceholder:"输入内容",soundHeader:"声音提示",enableSound:"启用声音",preview:"试听",volume:"音量","sound.question":"问卷弹出","sound.question.desc":"ask_user_question 出现时","sound.done":"回复结束","sound.done.desc":"智能体完成一轮回答时","sound.start":"回复开始","sound.start.desc":"智能体开始新一轮时","sound.error":"出错","sound.error.desc":"出现错误提示时",setupTitle:"未检测到 pi agent 配置",setupDesc:"pi-web-ui 需要 pi 的配置目录(~/.pi/agent)和至少一个 API 密钥才能运行智能体。pi 内置了 openai、anthropic、deepseek 等服务商——选一个填密钥即可,全程无需打开终端。",installFailed:"✖ pi agent 安装失败:",retryInstall:"重试安装",skip:"跳过",installDone:"✅ pi agent CLI 已安装。选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",welcomeTitle:"pi 编码智能体",welcomeSub:"检查、编辑、运行 —— 随时待命",directory:"目录",clickToFill:"点击填入输入框",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:同时搜索历史对话、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索文件…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","ex.understand":"了解这个项目","ex.understand.prompt":"介绍一下这个项目:整体结构、主要模块和如何运行?","ex.debug":"排查一个问题","ex.debug.prompt":"帮我排查一个 bug,请先说明问题现象,我会补充细节。","ex.test":"编写测试","ex.test.prompt":"为项目的核心模块编写单元测试。","ex.review":"代码审查","ex.review.prompt":"审查最近改动的代码,指出潜在问题和改进建议。",error:"出错",done:"完成",running:"执行中…",toolQueued:"排队中",copyArgs:"复制参数",errorOutput:"错误输出",output:"输出",waitingOutput:"等待输出…",toolDoneWaitingModel:"已结束 · 等模型",waitingModel:"等待模型响应…",thinkingNow:"思考中",thinkingPreview:"思考:{preview}",commands:"命令",newCommand:"新建命令",newTerminal:"新建终端",name:"名称",command:"命令",cwdHint:"(${pwd} = 当前工作目录)",noCommands:"还没有命令,点 + 添加一个",clickToRun:"点击运行",edit:"编辑",delete:"删除",confirmQ:"确认?",builtinTerminal:"内置终端",termEmptySub:"点击左侧命令运行,或点右侧 + 新建终端",noTerminal:"暂无终端",exited:"(已退出{code})",closeTerminal:"关闭终端",rerun:"重新读取 .pi/commands.json",terminalTitle:"终端 {n}",exampleName:"例如:启动开发服务器",exampleCommand:"例如:npm run dev",scmTab:"Git",scmTitle:"源代码管理",scmRefreshTip:"重新查询 Git 状态与差异",scmCurrentBranch:"当前分支",scmUpstreamGone:"上游已删除",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"分离 HEAD",scmSelectBranch:"选择分支…",scmRemoteBranches:"远程分支",scmStageTip:"暂存 {path}",scmUnstageTip:"取消暂存 {path}",scmSwitch:"切换",scmSwitchBranch:"切换分支",scmSwitchBranchTip:"在终端中执行 git checkout {branch}",scmPush:"推送",scmPushTip:"在终端中执行 git push",scmPull:"拉取",scmPullTip:"在终端中执行 git pull",scmCommit:"提交",scmCommitTip:'在终端中执行 git add -A && git commit -m "…"(提交全部更改,含未跟踪)',scmCommitPlaceholder:"输入提交信息…",scmChanges:"更改",scmHistory:"提交树",scmCommitDetail:"提交详情",scmSelectCommitHint:"点击左侧提交查看详情",scmNoHistory:"暂无提交记录",scmNoChanges:"工作区干净,没有更改",scmNotGitRepo:"当前目录不是 Git 仓库",scmLoading:"查询中…",scmConnecting:"等待连接…",scmDiff:"差异",scmSelectFileHint:"点击左侧文件查看差异",scmNoDiff:"(无差异)",scmStaged:"已暂存",scmUnstaged:"未暂存",scmStagedUnstaged:"已暂存 + 未暂存",scmUntracked:"未跟踪",scmUntrackedNote:"未跟踪文件:差异不显示,提交时会一并包含",scmQueryFailed:"Git 查询失败:{error}",scmTooManyFailures:"Git 查询连续失败,请点击刷新重试",scmRunsInTerminal:"提交 / 切换分支 / 推送 / 拉取在终端中执行",scmViewTerminal:"去终端",editProvider:"编辑服务商",builtinProviders:"内置服务商",hintKeyOnly:"只需填入 API 密钥",configuredBadge:"✓ 已配置",keyReady:"密钥已就绪",replaceKey:"更换密钥",replaceKeyTitle:"替换已保存的密钥",clearKey:"清空",clearKeyTitle:"清除该服务商保存在 auth.json 的密钥,回到未配置状态(环境变量来源的无法在此清除)",clearKeyConfirm:"清空 {id} 已保存的密钥?其模型将从列表消失,直到重新配置。",cloneProvider:"复制为自定义",cloning:"复制中",cloneProviderTitle:"复制该内置供应商(baseUrl + 模型列表)为自定义供应商,填入另一个 API 密钥即可双 key 并存",pasteKey:"粘贴 API 密钥…",savingKey:"保存中",saveKey:"保存密钥",customProviders:"自定义服务商",customDesc:"用于 Ollama / vLLM / 兼容 OpenAI 的代理等,写入 pi 的 models.json,保存后热重载、立即生效。",noCustomProviders:"还没有自定义服务商",modelsCount:"{n} 个模型",addProvider:"新增服务商",providerId:"服务商 ID",providerIdHint:"(必填,如 ollama / my-proxy)",displayName:"显示名",displayNamePh:"我的代理",apiType:"API 类型",baseUrlHint:"(OpenAI 兼容端点)",apiKeyHint:"sk-…(可留空,用 auth.json 的密钥)",authHeader:"自动添加 Authorization 请求头",modelsTitle:"模型",modelIdReq:"模型 ID(必填)",text:"文本",textImage:"文本+图片",contextWindow:"上下文",maxOutput:"最大输出",removeModel:"移除模型",addModel:"添加模型",deleteProviderConfirm:"删除服务商 {id} 及其 {n} 个模型?",fetchModels:"自动获取模型列表",fetchModelsHint:"从 baseUrl 的 /models 接口自动拉取模型 ID(服务端请求,不受 CORS 限制)",fetchingModels:"获取中…",fetchModelsOk:"已获取 {n} 个模型",fetchModelsEmpty:"接口未返回任何模型",fetchModelsErr:"获取失败:{msg}",fetchModelsNeedBaseUrl:"请先填写 baseUrl 再获取",goalBarTitle:"目标",goalBarPlaceholder:"设定一个目标,agent 完成后自动审查…",goalBarSet:"开始",goalBarClear:"取消",goalBarLocked:"锁定:应用到后续所有回合",goalBarUnlocked:"仅本回合(改完自动清除)",goalBarReviewModel:"审查模型",goalBarUseMainModel:"使用主模型",goalBarMaxRounds:"最大轮数",goalBarMaxRoundsTip:"最大审查重改轮数;0 或不填 = 不限(持续改到通过)",goalBarUnlimitedShort:"不限",goalBarReviewing:"审查中…",goalBarRound:"第 {n} 轮",goalBarActive:"目标生效中",goalBarPassed:"已通过",goalBarFailed:"未通过",goalBarStatusPending:"等待生成…",goalWizardBtn:"AI 提炼",goalWizardTip:"让 AI 通过问卷调研细化需求,收敛为目标",goalWizardRunning:"目标调研中",goalWizardAnswer:"回答",goalWizardCard:"目标调研",settings:"设置",settingsTitle:"设置",settingsDesc:"修改立即生效:系统提示词、技能与插件开关会重建当前会话;审查提示词与审查技能只影响后续目标审查(回复进行中则主会话变更自动延迟)。",settingsSystemPrompt:"系统提示词",settingsPromptMode:"模式",promptModeAppend:"追加",promptModeReplace:"替换",promptAppendHint:"追加模式:自定义内容拼接到默认系统提示词末尾(推荐,保留默认行为约束)。",promptReplaceHint:"替换模式:完全用自定义内容替换系统提示词(项目上下文与技能段仍会自动附加)。切换后输入框会显示原本的默认提示词,可直接修改;不改动失焦则仍使用默认。",promptPlaceholder:"输入自定义系统提示词…(失焦后自动应用)",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",settingsTerminalTools:"终端工具",terminalToolsEnabled:"启用持久终端工具",settingsTerminalToolsDesc:"让 AI 在交互式程序(REPL/vim)、长驻服务、需要持续观察输出或你要求在可见终端操作时,使用内置终端;普通命令仍走一次性 bash 工具",terminalToolsOffHint:"已关闭:AI 无法使用 terminal_* 工具,也不会收到相关使用引导",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",uninstallExt:"卸载",uninstallConfirm:"确认卸载?",uninstallConfirmHint:"再次点击确认,将在终端执行 pi remove",uninstallHint:"通过可见终端执行 pi remove 卸载此包,完成后自动刷新列表",uninstallTitle:"卸载",settingsExtensions:"插件",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},kn={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",widgetExpand:"Click to view full output",dragToResize:"Drag to resize · double-click to reset",loading:"Loading…",connected:"Connected",connecting:"Connecting…",reconnecting:"Reconnecting…",language:"Language",langZh:"中文",langEn:"English",githubRepo:"GitHub repository (xing-shuyin/pi-web-ui)",copy:"Copy",viewSwitch:"Switch view",chat:"Chat",terminal:"Terminal",selectModel:"Select model",availableModels:"Available models",noModels:"No models available (configure an API key first)",reasoning:"reasoning",vision:"vision",refreshModels:"Refresh model list (keeps manual rows, merges new ones)",manageModels:"⚙ Manage models (add / edit)",manageModelsTitle:"Manage models",thinkingLevel:"Thinking level",thinking:"Thinking",thinkingChip:"Thinking: {level}",sound:"Sound",theme:"Theme",themeDefault:"Dark (default)",newChat:"New chat",more:"More",newChatTip:"New chat (sessions are saved per browser)","thinking.off":"Off","thinking.minimal":"Minimal","thinking.low":"Low","thinking.medium":"Medium","thinking.high":"High","thinking.xhigh":"Extra high","thinking.max":"Max",thinkingUnsupported:"Not supported by this model — snapped to the nearest supported level",context:"Context",contextUsage:"Context usage",cumulativeCost:"Cumulative cost",sessionMessages:"Session messages",messages:"messages",pluginStatus:"Plugin status",working:"Working",queued:"queued",enterPath:"Type a path, Enter to switch",cwdTip:"Working directory: {path} (click to switch)",folderRef:"Folder reference: {path}",refOnly:"Reference only: {path}",attachContent:"Attached content: {path}",attachLines:"Attached selected lines: {path} (lines {start}-{end})",attachImage:"Image: {name}",attachFile:"File: {name}",removeAttachment:"Remove attachment",attachHint:"Will be sent with the next message",uploadFile:"Add files (images / text / any file — or drag in / paste a screenshot)",dropHereToAttach:"Release to attach file",imageNotSupported:"The current model doesn't support vision — images will be transcribed by the vision bridge (may be ignored if no vision model is configured)",imageLoadFailed:"Couldn't read image: {name}",fileLoadFailed:"Couldn't read file: {name}",fileTooLarge:"File too large, skipped (> {size}MB): {name}",foldersNotSupported:"Folders can't be dropped directly — expand and pick files instead",placeholderStreaming:"The agent is working… press Enter to steer, or click Queue to send after the reply finishes",placeholderIdle:"Message pi — Enter to send, / for commands",placeholderConnecting:"Connecting to server…",stopAgent:"Stop agent",stop:"Stop",bgTasks:"Background tasks",bgTasksTip:"Servers the AI started in the background (npm run dev & etc.) — stop them individually or all at once; they survive the conversation",bgTasksEmpty:"No background tasks",bgTasksDesc:"Processes the AI started that are still listening (detected by port)",bgTaskPort:"Port",bgTaskPid:"PID",bgTaskSince:"Started",bgTaskStop:"Stop",bgTaskStopAll:"Stop all",bgTaskRefresh:"Refresh",bgTaskJustNow:"just now",bgTaskMinutes:"{n} min ago",bgTaskHours:"{n} hr ago",bgTaskDays:"{n} days ago",stopBash:"Stop",stopBashTip:"Stop the running bash command (conversation continues)",supplement:"Queue",supplementTip:"Add to queue: sent only after the whole run finishes (no interruption)",queueSteerTag:"Steer",queueFollowTag:"Queued",sendTip:"Send (Enter)",slashCommands:"Commands",slashMenuHint:"↑↓ select · Enter/Tab complete",slashHelpTitle:"pi commands",slashHelpHint:"Type / anytime to open the command list",slashLoading:"Loading commands… (available once connected)",slashBuiltin:"Builtin",slashExtension:"Extension",slashPrompt:"Template",slashSkill:"Skill",slashCopied:"Copied the last assistant reply",slashCopyFailed:"Copy failed — please copy manually",slashCopyEmpty:"No assistant reply to copy yet",recentProjects:"Recent projects",runningConversations:"Running chats",historySessions:"History",openHistory:"History",openFiles:"Files",streaming:"Streaming…",noHistory:"No previous chats",current:"Current",messageCount:"{n} messages",tuiTip:"Chat in the pi terminal (TUI)",emptyChat:"Empty chat",editReask:"Edit & re-ask",editReaskTip:"Edit this question and re-ask from here (forks a new conversation; the original is kept)",reaskFromHere:"Re-ask from here",editPlaceholder:"Edit the question…",editHint:"⌘/Ctrl+Enter to submit · Esc to cancel",expandMsg:"Expand",collapseMsg:"Collapse",toolCalls:"tool calls",bashRuns:"bash runs",images:"images",update:"Update",updateTip:"Check & update pi-web-ui",currentVersion:"Current version",latestVersion:"Latest version",checkingUpdate:"Checking…",checkUpdate:"Check for updates",upToDate:"You're up to date",updateAvailable:"New version v{version} available",updateJustPublished:"v{version} was just published — npm cache may lag; if the new version isn't detected yet, re-check in a moment",updateNow:"Update in terminal",updateTabTitle:"Update pi-web-ui",updateTerminalHint:"Clicking runs npm i -g pi-web-ui@latest in a visible terminal; restart the service afterwards to take effect (pi-web-ui server restart).",rootDir:"Root",noFiles:"No files",filesTruncated:"Directory too large — list truncated (first 2000 shown)",linkFolderTip:"Link folder path to chat",attachInlineTip:"Attach content to chat",referenceTip:"Reference path only (AI reads on demand)",previewFile:"Preview",downloadFile:"Download file",downloadFailed:"Download failed: {error}",protocolMismatch:"Page version differs from the server (the app was just updated). Refresh the page to restore full functionality.",selectLinesHint:"Click a line to select; drag or Shift+click for a range",enableWrap:"Enable line wrap",disableWrap:"Disable line wrap",selectedRange:"Selected {n} lines (lines {start}-{end})",fileLines:"{n} lines",selectAll:"Select all",clearSelection:"Clear",addToChat:"Add to chat",addedToChat:"Added",previewTruncated:"⚠ File too large — previewing the first 512KB",previewLinesTruncated:"… too many lines — showing the first {n}",binaryFile:"🔣 Binary file — first 4KB shown as hex",binaryHexTruncated:" (file larger — download for the full file)",previewNotSupported:"This file type can't be previewed (only images / videos / text)",emptyFile:"(empty file)",editFile:"Edit file",exitEditFile:"Exit editing",saveFile:"Save file",discardFileChanges:"Discard unsaved changes?",fileSaved:"Saved",fileEditTruncated:"The preview is incomplete, so this file can't be edited",showMarkdownSource:"Show Markdown source",showMarkdownPreview:"Show Markdown preview",fullscreen:"Fullscreen",exitFullscreen:"Exit fullscreen",zoomIn:"Increase font size",zoomOut:"Decrease font size",resetZoom:"Reset zoom",pluginRequest:"Plugin request",noOptions:"(no options)",inputPlaceholder:"Enter content",soundHeader:"Sound notifications",enableSound:"Enable sound",preview:"Preview",volume:"Volume","sound.question":"Question popup","sound.question.desc":"When ask_user_question appears","sound.done":"Reply finished","sound.done.desc":"When the agent finishes a turn","sound.start":"Reply started","sound.start.desc":"When the agent starts a new turn","sound.error":"Error","sound.error.desc":"When an error notice appears",setupTitle:"pi agent config not detected",setupDesc:"pi-web-ui needs pi's config directory (~/.pi/agent) and at least one API key to run the agent. pi has built-in providers such as openai, anthropic, and deepseek — just pick one and enter a key, no terminal needed.",installFailed:"✖ pi agent installation failed:",retryInstall:"Retry install",skip:"Skip",installDone:"✅ pi agent CLI installed. Pick a provider and enter an API key to start chatting:",provider:"Provider",configured:"configured",providerKeyReady:"This provider already has a key — use it or replace it.",apiKey:"API key",saving:"Saving…",saveAndStart:"Save and start using",recheck:"Recheck",installing:"Installing pi agent CLI…",autoInstall:"Auto-install pi agent",attachment:"Attachment",plugin:"plugin",unknown:"unknown",thinkingWait:"Thinking",exitCode:"Exit code {code}",cancelled:"Cancelled",truncated:"… content too long, truncated in this view",outputTruncated:"… output too long, truncated in this view",refOnlyShort:"Reference only",folderRefShort:"Folder · reference only",inlineLines:"Inline · {n} lines",inlineLinesRange:"Lines {start}-{end}",image:"🖼 Image",bridgedVision:"👁 Transcribed",bridgedVisionDetail:"Image transcribed by the vision bridge (current model can't see images)",folderNotExpanded:"Folder — content not expanded, the agent will browse it as needed",fileNotExpanded:"Large file ({size}) — content not expanded, the agent will read it as needed","role.user":"You","role.assistant":"pi","role.tool":"Tool","role.bash":"Terminal","role.branch":"Branch summary","role.compaction":"Context compacted",welcomeTitle:"pi coding agent",welcomeSub:"Inspect, edit, run — always ready",directory:"Directory",clickToFill:"Click to fill input",waitingResponse:"Waiting for model response…",backToBottom:"Back to bottom",questionNavTitle:"Questions",searchPlaceholder:"Search in conversation…",searchNoResults:"No results",searchModels:"Filter models…",noModelMatches:"No matching models",searchGlobal:"Search",searchGlobalTip:"Global search: sessions / projects / files (Ctrl+K)",gsPlaceholder:"Search projects, past conversations, workspace files…",gsHint:"Type to search session history, recent projects and file names in the current workspace at once",gsSessions:"Conversations",gsProjects:"Projects",gsFiles:"Files",gsNoResults:"No matches",gsSearching:"Searching files…",gsTruncated:"Too many matches — showing a subset",gsCurrentProject:"current",gsOpenPreview:"Open file preview",gsNavigate:"select",gsOpen:"open",gsCloseHint:"close",bgTaskCommand:"Command",searchPrev:"Previous (Shift+Enter)",searchNext:"Next (Enter)",searchClose:"Close (Esc)",questionNavTip:"All questions in this conversation — hover to expand, click to jump","ex.understand":"Understand this project","ex.understand.prompt":"Introduce this project: overall structure, main modules, and how to run it?","ex.debug":"Debug an issue","ex.debug.prompt":"Help me debug a bug — describe the symptom first, and I'll add details.","ex.test":"Write tests","ex.test.prompt":"Write unit tests for the core modules.","ex.review":"Code review","ex.review.prompt":"Review the recently changed code and point out potential issues and improvements.",error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",settingsExtensions:"Extensions",settingsPresets:"Presets",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},fs=a.createContext(null);function Nn(){try{const t=localStorage.getItem(gs);if(t==="zh"||t==="en")return t}catch{}return"zh"}function wn({children:t}){const[s,n]=a.useState(Nn),l=a.useCallback(i=>{n(i);try{localStorage.setItem(gs,i)}catch{}},[]),c=a.useCallback((i,o)=>{let u=kn[i];if(s==="zh"&&(u=bn[i]),o)for(const[m,g]of Object.entries(o))u=u.replaceAll(`{${m}}`,String(g));return u},[s]);a.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const r=a.useMemo(()=>({locale:s,setLocale:l,t:c}),[s,l,c]);return e.jsx(fs.Provider,{value:r,children:t})}function wt(){const t=a.useContext(fs);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function me(){return wt().t}const Cn=["off","minimal","low","medium","high","xhigh","max"],xs=a.memo(function({state:s,models:n,modelsLoading:l,send:c,onManageModels:r,compact:i=!1}){const o=me(),u=s==null?void 0:s.model,m=u?`${u.provider}/${u.id}`:null,[g,p]=a.useState(!1),[k,C]=a.useState(!1),[T,_]=a.useState("");a.useEffect(()=>{g||_("")},[g]);const y=a.useMemo(()=>{const x=T.trim().toLowerCase();return x?n.filter(w=>w.name.toLowerCase().includes(x)||w.provider.toLowerCase().includes(x)||w.id.toLowerCase().includes(x)):n},[n,T]),[M,N]=a.useState(!1),S=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,R=Cn.map(x=>({value:x,label:o(`thinking.${x}`),supported:S?S.has(x):!0})),B=x=>{var w;return((w=R.find(d=>d.value===x))==null?void 0:w.label)??x};return a.useEffect(()=>{g&&n.length===0&&!M&&!l&&(N(!0),c({type:"list_models"}))},[g,n.length,M,l,c]),a.useEffect(()=>{n.length>0&&N(!1)},[n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(nt,{}),e.jsx("span",{className:"chip-model",children:u?u.name:o("selectModel")}),!i&&(u==null?void 0:u.vision)&&e.jsx("span",{className:"chip-vision",title:o("vision"),children:"🖼"}),!i&&u&&e.jsx("span",{className:"chip-sub",children:u.provider})]}),open:g,onOpenChange:p,menuClassName:"dd-menu-model",children:[e.jsx("div",{className:"dd-header",children:o("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(et,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:o("searchModels"),value:T,onChange:x=>_(x.target.value)})]}),e.jsxs("div",{className:"dd-model-scroll",children:[(M||l)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.length===0&&!M&&!l&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),y.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:o("noModelMatches")}),y.map(x=>e.jsx(ke,{active:m===x.id,onClick:()=>{m!==x.id&&c({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:o("reasoning")}),x.vision&&e.jsx("span",{className:"dd-model-badge",children:o("vision")})]})]})]})},x.id))]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:o("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{p(!1),r()},children:o("manageModels")})]})]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ht,{}),e.jsx("span",{className:"chip-sub",children:o("thinkingChip",{level:s?B(s.thinkingLevel):"—"})})]}),open:k,onOpenChange:C,children:[e.jsx("div",{className:"dd-header",children:o("thinkingLevel")}),R.map(x=>e.jsx(ke,{active:(s==null?void 0:s.thinkingLevel)===x.value,disabled:!x.supported,title:x.supported?void 0:o("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==x.value&&c({type:"set_thinking",level:x.value}),C(!1)},children:x.label},x.value))]})]})}),Sn=[{kind:"question",labelKey:"sound.question",descKey:"sound.question.desc"},{kind:"done",labelKey:"sound.done",descKey:"sound.done.desc"},{kind:"start",labelKey:"sound.start",descKey:"sound.start.desc"},{kind:"error",labelKey:"sound.error",descKey:"sound.error.desc"}];function At({settings:t,onChange:s,onPreview:n}){const l=me(),c=r=>s({...t,...r});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:l("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(ds,{className:"sound-icon"}),e.jsx("span",{children:l("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:r=>c({enabled:r.target.checked})})]}),Sn.map(({kind:r,labelKey:i,descKey:o})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:l(i)}),e.jsx("span",{className:"sound-desc",children:l(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:l("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),n(r)},children:l("preview")}),e.jsx("input",{type:"checkbox",checked:t[r],disabled:!t.enabled,onChange:u=>c({[r]:u.target.checked})})]})]},r)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:l("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:r=>c({volume:Number(r.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function Tn({chat:t,send:s,terminal:n,view:l,onViewChange:c,onOpenPanel:r,onManageModels:i,onOpenSettings:o,onOpenBgTasks:u,onOpenGlobalSearch:m,sound:g,onSoundChange:p,onSoundPreview:k,themes:C,theme:T,onThemeChange:_}){var se;const{locale:y,setLocale:M,t:N}=wt(),[S,R]=a.useState(!1),[B,x]=a.useState(!1),[w,d]=a.useState(!1),[I,F]=a.useState(!1),[K,A]=a.useState(!1),Y=[{value:"zh",label:N("langZh")},{value:"en",label:N("langEn")}],re=t.ready?N("connected"):t.status==="closed"?N("reconnecting"):N("connecting"),L=t.ready?"ok":"busy",f=()=>{var V,q;if(!t.ready)return;const $=N("updateTabTitle"),X={name:$,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},b=t.terminals.find(ne=>ne.title===$);b?(n.restart(b.id),s({type:"run_command",terminalId:b.id,conversationId:b.conversationId,command:X,cols:80,rows:24})):n.create({id:Fe(),conversationId:t.activeConversationId||((V=t.state)==null?void 0:V.conversationId)||"",title:$,cwd:((q=t.state)==null?void 0:q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:X}),F(!1),A(!1),c("terminal")},E=()=>{var $,X;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:N("currentVersion")}),e.jsxs("b",{children:["v",(($=t.update)==null?void 0:$.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:N("latestVersion")}),e.jsx("b",{children:t.update===null?N("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:N("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:N("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:N("updateAvailable",{version:t.update.latest})}),((X=t.update)==null?void 0:X.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:N("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:N("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?N("checkingUpdate"):N("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:f,children:N("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:N("openHistory"),onClick:()=>r("left"),children:e.jsx(on,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${L}`,title:re}),e.jsx("span",{className:"conn-label",children:re})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":N("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="chat",className:l==="chat"?"active":"",onClick:()=>c("chat"),children:[e.jsx(tt,{}),e.jsx("span",{children:N("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="terminal",className:l==="terminal"?"active":"",onClick:()=>c("terminal"),children:[e.jsx(ze,{}),e.jsx("span",{children:N("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="git",className:l==="git"?"active":"",onClick:()=>c("git"),children:[e.jsx(Ge,{}),e.jsx("span",{children:N("scmTab")})]})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:N("searchGlobalTip"),onClick:m,children:[e.jsx(et,{}),e.jsx("span",{className:"chip-sub",children:N("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":N("bgTasksTip"),onClick:u,children:[e.jsx(st,{}),e.jsx("span",{className:"chip-sub",children:N("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(xs,{state:t.state?{model:t.state.model,thinkingLevel:t.state.thinkingLevel,availableThinkingLevels:t.state.availableThinkingLevels}:null,models:t.models,modelsLoading:t.modelsLoading,send:s,onManageModels:i}),e.jsxs("button",{type:"button",className:"chip",title:N("settingsTitle"),onClick:o,children:[e.jsx(Ze,{}),e.jsx("span",{className:"chip-sub",children:N("settings")})]}),e.jsx(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ds,{}),e.jsx("span",{className:"chip-sub",children:N("sound")})]}),open:S,onOpenChange:R,children:e.jsx(At,{settings:g,onChange:p,onPreview:k})}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(pn,{}),e.jsx("span",{className:"chip-sub",children:y==="zh"?N("langZh"):"EN"})]}),open:B,onOpenChange:x,children:[e.jsx("div",{className:"dd-header",children:N("language")}),Y.map($=>e.jsx(ke,{active:y===$.value,onClick:()=>{M($.value),x(!1)},children:$.label},$.value))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(en,{}),e.jsx("span",{className:"chip-sub",children:N("theme")})]}),open:w,onOpenChange:d,children:[e.jsx("div",{className:"dd-header",children:N("theme")}),e.jsx(ke,{active:T===null,onClick:()=>{_(null),d(!1)},children:N("themeDefault")}),C.map($=>e.jsx(ke,{active:T===$.id,onClick:()=>{_($.id),d(!1)},children:$.name},$.id))]}),e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(bt,{}),e.jsxs("span",{className:"chip-sub",children:["v",((se=t.update)==null?void 0:se.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:N("updateAvailable",{version:t.update.latest??""})})]}),open:I,onOpenChange:$=>{F($),$&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:N("update")}),E()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:N("githubRepo"),children:e.jsx(_t,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":N("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(De,{}),e.jsx("span",{children:N("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Re,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(an,{}),e.jsx("span",{className:"chip-sub",children:N("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:K,onOpenChange:$=>{A($),$&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:N("sound")}),e.jsx("div",{className:"dd-header",children:N("settings")}),e.jsxs(ke,{onClick:()=>{A(!1),o()},children:[e.jsx(Ze,{})," ",N("settingsTitle")]}),e.jsxs(ke,{onClick:()=>{A(!1),m()},children:[e.jsx(et,{})," ",N("searchGlobal")]}),e.jsxs(ke,{onClick:()=>{A(!1),u()},children:[e.jsx(st,{})," ",N("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(At,{settings:g,onChange:p,onPreview:k}),e.jsx("div",{className:"dd-header",children:N("language")}),Y.map($=>e.jsx(ke,{active:y===$.value,onClick:()=>M($.value),children:$.label},$.value)),e.jsx("div",{className:"dd-header",children:N("theme")}),e.jsx(ke,{active:T===null,onClick:()=>{_(null),A(!1)},children:N("themeDefault")}),C.map($=>e.jsx(ke,{active:T===$.id,onClick:()=>{_($.id),A(!1)},children:$.name},$.id)),e.jsx("div",{className:"dd-header",children:N("update")}),E(),e.jsxs("a",{className:"dd-refresh dd-more-link",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",children:[e.jsx(_t,{})," ",N("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:N("openFiles"),onClick:()=>r("right"),children:e.jsx(_e,{})})]})]})}function $t(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}const Mn=a.memo(function({ready:s,status:n,cwd:l,sessionFile:c,conversations:r,sessions:i,projects:o,activeConversationId:u,send:m,active:g}){const p=me(),k=c,C=l;a.useEffect(()=>{!g||!s||n!=="open"||l&&(m({type:"list_sessions"}),m({type:"list_projects"}))},[g,s,n,l,m]);const T=y=>{const M=y.name||y.firstMessage.trim();return M.length>0?M:p("emptyChat")},_=y=>y.split(/[\\/]/).pop()||y;return e.jsxs("aside",{className:"panel panel-left",children:[o.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:o.map(y=>{const M=C===y.path;return e.jsxs("button",{type:"button",className:`project-item ${M?"active":""}`,title:y.path,onClick:()=>{M||m({type:"set_cwd",path:y.path})},children:[e.jsx(_e,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:_(y.path)}),e.jsx("span",{className:"project-path",children:y.path})]}),e.jsx("span",{className:"project-time",children:$t(y.lastUsed)})]},y.path)})})]}),r.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:p("runningConversations")}),r.map(y=>{const M=u===y.id;return e.jsxs("button",{type:"button",className:`session-item ${M?"active":""}`,title:y.title,onClick:()=>{M||m({type:"switch_conversation",id:y.id})},children:[e.jsx(tt,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:y.title}),e.jsx("span",{className:"session-sub",children:M?p("current"):p("messageCount",{n:y.messageCount})})]}),y.isStreaming&&e.jsx("span",{className:"conv-streaming",title:p("streaming")})]},y.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:[i.length===0&&e.jsx("div",{className:"panel-empty",children:p("noHistory")}),i.map(y=>{const M=k===y.path;return e.jsxs("button",{type:"button",className:`session-item ${M?"active":""}`,title:y.path,onClick:()=>{M||m({type:"switch_session",path:y.path})},children:[e.jsx(tt,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:T(y)}),e.jsxs("span",{className:"session-sub",children:[M?p("current"):p("messageCount",{n:y.messageCount}),y.source==="tui"&&e.jsx("span",{className:"session-src",title:p("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:$t(y.modified)})]},y.path)})]})]})]})}),vs="pi-web-ui:token";function En(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(vs,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function Rn(){try{return localStorage.getItem(vs)??""}catch{return""}}function rt(t){const s=Rn();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function Ln(t,s){const n=s.assistantMessageEvent,l=t.stats.tokens,c=s.usage!==null?{...l,...s.usage}:l,r=c===l?t.stats:{...t.stats,tokens:c};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return r===t.stats?t:{...t,stats:r};const i=n.delta??"";if(!i)return r===t.stats?t:{...t,stats:r};const o=t.streamingMessage??null,u=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},m=[...u.content],g=n.type==="thinking_delta"?"thinking":"text",p=n.contentIndex??m.length-1;return p>=0&&p<m.length&&m[p].type===g?m[p]=g==="thinking"?{type:"thinking",thinking:(m[p].thinking??"")+i}:{type:"text",text:(m[p].text??"")+i}:m.push(g==="thinking"?{type:"thinking",thinking:i}:{type:"text",text:i}),{...t,stats:r,streamingMessage:{...u,id:s.messageId,content:m}}}const In=5,ct=2e5,Pn=2e5,Bn={conversationId:null,goal:null,reviewModel:null,maxRounds:3,locked:!0,reviewing:!1,round:0,status:"",verdict:"pending",wizard:{active:!1,draft:"",model:null,step:0,maxSteps:6,status:""}};function Dn(){const t=new Map,s=new Map,n=(l,c)=>`${l}:${c}`;return{write(l,c,r){const i=n(l,c),o=t.get(i);if(o&&o.size>0){for(const g of o)try{g.write(r)}catch{}return}const u=s.get(i)??"",m=u.length+r.length>Pn?r:u+r;s.set(i,m)},register(l,c,r){const i=n(l,c);let o=t.get(i);o||(o=new Set,t.set(i,o)),o.add(r);const u=s.get(i);if(u){try{r.write(u)}catch{}s.delete(i)}return()=>{const m=t.get(i);m&&(m.delete(r),m.size===0&&t.delete(i)),s.delete(i)}},clear(){t.clear(),s.clear()}}}function Ot(t,s){const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId),c.role==="bashExecution"&&n.add(`bash-${c.id}`);let l=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function Ht(t,s){if(t.size===0)return t;const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId);let l=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function _n(t,s){var n,l,c,r;switch(s.type){case"status":return{...t,status:s.status,ready:s.status==="open"?t.ready:!1,terminals:s.status==="closed"?[]:t.terminals};case"ready":return{...t,serverVersion:s.serverVersion,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==In};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Ot(t.liveOutputs,s.state),toolStatuses:Ht(t.toolStatuses,s.state)};case"snapshot_delta":{const i=t.state,o=s.msg;if(!i||i.conversationId!==o.conversationId||i.rev!==o.baseRev)return t;const u={...i,...o.state,messages:o.appended.length>0?[...i.messages,...o.appended]:i.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:Ot(t.liveOutputs,u),toolStatuses:Ht(t.toolStatuses,u)}}case"tool_delta":{const i=t.liveOutputs.get(s.toolCallId),o=((i==null?void 0:i.text)??"")+s.delta,u=o.length>ct?`…[前 ${o.length-ct} 字符已省略]…
|
|
3
|
+
`+o.slice(o.length-ct):o,m=new Map(t.liveOutputs);return m.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:m}}case"message_delta":{const i=t.state;return!i||i.conversationId!==s.msg.conversationId?t:{...t,state:Ln(i,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(i=>i.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(i=>i.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(n=t.state)!=null&&n.conversationId)&&s.conversationId!==(t.activeConversationId||((l=t.state)==null?void 0:l.conversationId))?t:{...t,terminals:t.terminals.map(i=>i.id===s.terminalId?{...i,running:!1,exitCode:s.exitCode}:i)};case"terminal_restart":return{...t,terminals:t.terminals.map(i=>i.id===s.terminalId?{...i,running:!0,exitCode:null}:i)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:s.terminals.map(i=>{var o;return{...i,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};default:return t}}const Wt="pi-web-client-id";let dt=null;function Ct(){if(dt)return dt;let t=null;try{t=sessionStorage.getItem(Wt),t||(t=Fe(),sessionStorage.setItem(Wt,t))}catch{t=t??Fe()}return dt=t,t}function Fn(){const t=location.protocol==="https:"?"wss:":"ws:";return rt(`${t}//${location.host}/ws`)}function An(){const[t,s]=a.useReducer(_n,{status:"connecting",ready:!1,state:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:[],conversations:[],activeConversationId:"",projects:[],files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],installResult:null,pathCompletions:[],update:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:Bn,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,protocolMismatch:!1}),n=a.useRef(null),l=a.useRef(Dn()),c=a.useRef(0),r=a.useRef(null),i=a.useRef(!0),o=a.useRef(0),u=a.useRef(0),m=a.useRef(new Map),g=a.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,w)=>{var F;const d=m.current,I=d.get(x);if(I!==void 0&&w!==I+1){const K=B.current.chat,A=K.activeConversationId||((F=K.state)==null?void 0:F.conversationId);x===A&&p()}d.set(x,w)},C=a.useCallback((x,w)=>{const d=++u.current;s({type:"notice",notice:{id:d,level:x,text:w}})},[]),T=a.useCallback(x=>{const w=n.current;return w&&w.readyState===WebSocket.OPEN?(w.send(JSON.stringify(x)),!0):!1},[]),_=a.useCallback(()=>{if(!i.current)return;s({type:"status",status:"connecting"});const x=new WebSocket(Fn());n.current=x,x.onopen=()=>{n.current===x&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),x.send(JSON.stringify({type:"hello",clientId:Ct()})))},x.onmessage=w=>{if(n.current!==x)return;o.current=Date.now();let d;try{d=JSON.parse(w.data)}catch{return}switch(d.type){case"ready":s({type:"ready",serverVersion:d.serverVersion,protocolVersion:d.protocolVersion}),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":m.current=new Map,s({type:"snapshot",state:d.state});break;case"snapshot_delta":{const I=B.current.chat.state;(!I||I.conversationId!==d.conversationId||I.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 I=++u.current;s({type:"notice",notice:{id:I,level:d.level,text:d.text}});break}case"sessions":s({type:"sessions",sessions:d.sessions});break;case"conversations":s({type:"conversations",conversations:d.conversations,activeId:d.activeId});break;case"projects":s({type:"projects",projects:d.projects});break;case"files":s({type:"files",files:d});break;case"file_changed":s({type:"file_changed",path:d.path});break;case"file_content":s({type:"file_content",content:d});break;case"models":s({type:"models",models:d.models,loading:!1});break;case"models_config":s({type:"models_config",providers:d.providers});break;case"providers_status":s({type:"providers_status",providers:d.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:d.reqId,ok:d.ok,models:d.models,error:d.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:d.reqId,ok:d.ok,added:d.added,total:d.total,error:d.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:d.reqId,ok:d.ok,config:d.config,error:d.error}});break;case"scm_data":s({type:"scm_data",data:d});break;case"search_files_result":s({type:"file_search_result",result:{reqId:d.reqId,ok:d.ok,results:d.results,truncated:d.truncated}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:d});break;case"path_completions":s({type:"path_completions",completions:d.completions});break;case"update_status":s({type:"update_status",status:d});break;case"widgets":s({type:"widgets",widgets:d.widgets});break;case"statuses":s({type:"statuses",statuses:d.statuses});break;case"dialog":s({type:"dialog",dialog:{id:d.id,kind:d.kind,title:d.title,args:d.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"terminal_output":l.current.write(d.conversationId??B.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),l.current.clear(),!i.current||n.current&&n.current!==x)return;s({type:"status",status:"closed"});const w=Math.min(1e3*2**c.current,1e4);c.current+=1,r.current=setTimeout(()=>{r.current=null,_()},w)},x.onerror=()=>{}},[]);a.useEffect(()=>{i.current=!0,_();const x=setInterval(()=>{if(!i.current)return;const w=n.current;w&&w.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&w.close()},5e3);return()=>{var w;i.current=!1,clearInterval(x),r.current&&(clearTimeout(r.current),r.current=null),(w=n.current)==null||w.close(),n.current=null}},[_]);const y=a.useCallback(x=>s({type:"dismiss_notice",id:x}),[]),M=a.useCallback(x=>s({type:"terminal_add",meta:x}),[]),N=a.useCallback(x=>s({type:"terminal_remove",id:x}),[]),S=a.useCallback(x=>s({type:"terminal_restart",terminalId:x}),[]),R=a.useCallback((x,w,d)=>l.current.register(x,w,d),[]),B=a.useRef({chat:t,send:T,pushNotice:C,dismissNotice:y,terminal:{create:M,close:N,register:R,restart:S}});return B.current={chat:t,send:T,pushNotice:C,dismissNotice:y,terminal:{create:M,close:N,register:R,restart:S}},B.current}const $n=200*1024*1024,On=/windows/i.test(navigator.userAgent),Hn=/[<>:"/\\|?*\u0000-\u001f]/g,Wn=/[. ]+$/,qn=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Un(t){const s=t.replace(Hn,"_").replace(Wn,"");return s?qn.test(s)?`_${s}`:s:"_"}function qt(t,s=!0){const n=new URLSearchParams({clientId:Ct(),path:t,...s?{download:"1"}:{}});return rt(`/api/file?${n}`)}async function zn(t,s){const n=On?Un(s):s;try{const l=await fetch(qt(t));if(!l.ok)return{ok:!1,cancelled:!1,error:await l.text().catch(()=>"")||(l.status===404?"文件不存在":`HTTP ${l.status}`)};if(Number(l.headers.get("content-length")??"0")>$n)return window.location.assign(qt(t)),{ok:!0};const r=await l.blob();return window.showSaveFilePicker&&window.isSecureContext?Kn(r,n):xt(r,n)}catch(l){return{ok:!1,cancelled:!1,error:l instanceof Error?l.message:String(l)}}}async function Kn(t,s){let n;const l=window.showSaveFilePicker;if(!l)return xt(t,s);try{n=await l({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:xt(t,s)}try{const c=await n.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function xt(t,s){const n=URL.createObjectURL(t),l=document.createElement("a");return l.href=n,l.download=s,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const Vn=a.memo(function({files:s,fileChanged:n,widgets:l,cwd:c,send:r,onAttach:i,onPreview:o,onNotice:u}){const m=me(),[g,p]=a.useState(""),[k,C]=a.useState(null),[T,_]=a.useState(!1),y=1e4,M=a.useRef(0),N=a.useRef(void 0),S=a.useCallback((w,d)=>{const I=++M.current;p(w),d!=null&&d.silent||_(!0),r({type:"list_files",path:w===""?void 0:w})||M.current===I&&_(!1)},[r]);a.useEffect(()=>{s&&s.path===g&&_(!1)},[s,g]),a.useEffect(()=>{if(c!==N.current){N.current=c,S("",{silent:!0});return}const w=setInterval(()=>{document.visibilityState!=="hidden"&&S(g,{silent:!0})},y);return()=>clearInterval(w)},[c,g,S]),a.useEffect(()=>{n&&n.path===g&&S(g,{silent:!0})},[n,g,S]);const R=w=>S(w),B=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&S(s.parent)},x=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:()=>S(""),children:m("rootDir")}),x.map((w,d)=>{const I=x.slice(0,d+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(it,{}),e.jsx("button",{type:"button",className:`crumb ${I===g?"active":""}`,onClick:()=>S(I),children:w})]},I)})]}),e.jsxs("div",{className:"panel-body",children:[T&&e.jsx("div",{className:"panel-empty",children:m("loading")}),!T&&s&&s.path===g&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:B,children:[e.jsx(_e,{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:()=>R(w.path),children:[e.jsx(_e,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("linkFolderTip"),onClick:()=>i(w.path,w.name,"reference",!0),children:e.jsx(gt,{})})]},w.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${w.path} — ${m("previewFile")}`,onClick:()=>o(w.path,w.name),children:[e.jsx(us,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:w.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":m("downloadFile"),onClick:()=>{zn(w.path,w.name).then(d=>{d.ok||d.cancelled||u("error",m("downloadFailed",{error:d.error}))})},children:e.jsx(bt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":m("attachInlineTip"),onClick:()=>i(w.path,w.name,"inline"),children:e.jsx(De,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":m("referenceTip"),onClick:()=>i(w.path,w.name,"reference"),children:e.jsx(gt,{})})]},w.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:m("filesTruncated")})]}),!T&&!s&&e.jsx("div",{className:"panel-empty",children:m("noFiles")})]}),l.filter(w=>w.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:l.filter(w=>w.lines.length>0).map(w=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:m("widgetExpand"),onClick:()=>C(w.key),children:[e.jsx("span",{children:w.key}),e.jsx(cn,{})]}),e.jsx("pre",{className:"widget-lines",children:w.lines.join(`
|
|
4
|
+
`)})]},w.key))}),k&&(()=>{const w=l.find(d=>d.key===k);return w?e.jsx("div",{className:"modal-backdrop",onClick:()=>C(null),children:e.jsxs("div",{className:"widget-expand",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:w.key}),e.jsx("button",{type:"button",className:"btn",title:m("close"),onClick:()=>C(null),children:e.jsx(Se,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:w.lines.join(`
|
|
5
|
+
`)})]})}):null})()]})});var Ut=os();const Gn=a.memo(function({text:s}){const n=me(),[l,c]=a.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:n("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{c(!0),setTimeout(()=>c(!1),1200)})},children:l?e.jsx(Nt,{}):e.jsx(kt,{})}):null}),ys=[As],js=[[Fs,{detect:!0,ignoreMissing:!0}]];function bs({text:t}){return e.jsx(rs,{remarkPlugins:ys,rehypePlugins:js,components:{pre:Jn},children:t})}const ot=a.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(bs,{text:s})})});function Jn({children:t,...s}){return e.jsxs("div",{className:"codeblock",children:[e.jsx(Gn,{text:vt(t)}),e.jsx("pre",{...s,children:t})]})}function vt(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(vt).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return vt(s==null?void 0:s.children)}return""}const Qn=/^\s{0,3}(`{3,}|~{3,})/,Yn=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function ut(t){return t.trim()===""}function zt(t){const s=Qn.exec(t);return s?s[1]:null}function Xn(t){const s=t.split(`
|
|
6
|
+
`),n=[];let l=[],c=null;for(let r=0;r<s.length;r++){const i=s[r];if(c!==null){const u=zt(i);u&&u[0]===c[0]&&u.length>=c.length&&(c=null),l.push(i);continue}const o=zt(i);if(o&&!ut(i)){c=o,l.push(i);continue}if(ut(i)){let u=r;for(;u<s.length&&ut(s[u]);)u++;if(!(u<s.length&&Yn.test(s[u]))&&l.length>0){n.push(l.join(`
|
|
7
|
+
`)),l=[];continue}l.push(i);continue}l.push(i)}return{frozen:n,active:l.join(`
|
|
8
|
+
`),inFence:c!==null}}const Zn=a.memo(function({text:s}){return e.jsx(rs,{remarkPlugins:ys,rehypePlugins:js,children:s})}),Kt=200;function ea({text:t,inFence:s}){const[n,l]=a.useState(t),c=a.useRef(0),r=a.useRef(null);return a.useEffect(()=>{if(s)return;const i=Date.now()-c.current,o=()=>{c.current=Date.now(),l(t)};if(i>=Kt){o();return}return r.current=setTimeout(o,Kt-i),()=>{r.current&&clearTimeout(r.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx(bs,{text:n})}const ta=a.memo(function({text:s}){const{frozen:n,active:l,inFence:c}=a.useMemo(()=>Xn(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((r,i)=>e.jsx(Zn,{text:r},i)),l.length>0&&e.jsx(ea,{text:l,inFence:c},n.length)]})});function sa({thinking:t,streaming:s}){const n=me(),[l,c]=a.useState(s),r=t.split(`
|
|
9
|
+
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${l?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>c(i=>!i),children:[l?e.jsx(Ie,{}):e.jsx(it,{}),e.jsx(nt,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s?e.jsxs("span",{className:"thinking-live-label",children:[n("thinkingNow"),e.jsx("span",{className:"dots"})]}):l?n("thinking"):n("thinkingPreview",{preview:r})})]}),l&&e.jsx("div",{className:"thinking-body",children:t})]})}const na={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function aa(t){return na[t]??"🛠"}const ia=a.memo(function({block:s,view:n,onKillBash:l}){var R,B,x,w;const c=me(),[r,i]=a.useState(!0),[o,u]=a.useState(!1),m=!n.result&&n.streaming&&!n.status,g=s.name==="bash"&&m,p=n.result!==void 0,k=!n.result&&!!n.status,C=((R=n.result)==null?void 0:R.isError)??((B=n.status)==null?void 0:B.isError)??!1,T=n.result?n.result.content.map(d=>d.type==="text"?d.text:"").join(""):n.liveOutput??"",_=C?"err":p?"ok":m||k?"run":"idle";let y=c(C?"error":p?"done":m?"running":k?"toolDoneWaitingModel":"toolQueued");const M=k&&((x=n.status)==null?void 0:x.durationMs)!==void 0?oa(n.status.durationMs):"";k&&M&&(y=`${y} · ${M}`);const N=k&&((w=n.status)==null?void 0:w.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",S=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),u(!0),setTimeout(()=>u(!1),1200))};return e.jsxs("div",{className:`toolcall ${_}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:aa(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[y,N&&e.jsx("em",{className:"toolcall-exit",children:N})]}),e.jsx("span",{className:"toolcall-spacer"}),g&&l&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:c("stopBashTip"),onClick:l,children:[e.jsx(Xe,{}),e.jsx("span",{children:c("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:c("copyArgs"),onClick:S,children:o?e.jsx(xn,{}):e.jsx(kt,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>i(d=>!d),children:r?e.jsx(Ie,{}):e.jsx(it,{})})]}),r&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(ra,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),T.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[c(C?"errorOutput":"output"),(m||k)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:T})]}),m&&T.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",c("waitingOutput")]}),k&&T.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",c("waitingModel")]})]})]})});function ra({args:t}){let s=null;try{s=JSON.parse(t)}catch{return e.jsx("pre",{children:t})}return typeof s.command!="string"?e.jsx("pre",{children:t}):e.jsxs("div",{className:"termline",children:[e.jsx(ze,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function oa(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),l=Math.round(s%60);return`${n}m ${String(l).padStart(2,"0")}s`}const la=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function St(t){var n;const s=t.match(la);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}function Ue(t){return t.type==="text"&&typeof t.text=="string"?t:null}function ks(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function Ns(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function ws(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function Cs(t){return t.type==="bash"&&typeof t.command=="string"?t:null}const Vt=a.memo(function({message:s,toolResults:n,liveOutputs:l,toolStatuses:c,streaming:r,isLast:i,onEdit:o,onKillBash:u,onCollapse:m,qnIndex:g,qnActive:p,onJump:k}){const C=me(),[T,_]=a.useState(!1),[y,M]=a.useState("");if(s.role==="toolResult")return null;const N=s.role==="custom"&&s.customType==="file",S=s.content.map(A=>{var Y;return((Y=Ue(A))==null?void 0:Y.text)??""}).filter(Boolean).join(`
|
|
10
|
+
`),R=s.role==="user"?St(S):null,B=R?R.userMessage??`skill:${R.name}`:S.split(`
|
|
11
|
+
`).join(" ").trim(),x=r&&i&&s.content.length===0,w=s.role==="user"&&!r&&!x&&!!o,d=()=>{M(R?`/skill:${R.name}${R.userMessage?` ${R.userMessage}`:""}`:s.content.map(A=>{var Y;return((Y=Ue(A))==null?void 0:Y.text)??""}).filter(Boolean).join(`
|
|
12
|
+
`)),_(!0)},I=()=>{const A=y.trim();A&&(o==null||o(s.id,A),_(!1))},F=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),K=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"?K?C("goalWizardCard"):F?C("goalBarTitle"):s.customType==="file"?C("attachment"):`${C("plugin")} · ${s.customType??C("unknown")}`:Ss(s.role,C)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:ma(s.timestamp)}),m&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:C("collapseMsg"),onClick:()=>m(s.id),children:[e.jsx(at,{})," ",C("collapseMsg")]}),g!==void 0&&k&&e.jsxs("button",{type:"button",className:`qn-tag ${p?"active":""}`,title:`${g+1}. ${B}`,"aria-label":`${g+1}. ${B}`,onClick:()=>k(s.id),children:[e.jsx("span",{className:"qn-tag-bar"}),e.jsx("span",{className:"qn-tag-idx",children:g+1})]})]}),e.jsx("div",{className:"msg-body",children:T?e.jsxs("div",{className:"msg-editor",children:[e.jsx("textarea",{className:"msg-editor-input",value:y,autoFocus:!0,placeholder:C("editPlaceholder"),rows:Math.max(2,Math.min(10,y.split(`
|
|
13
|
+
`).length+1)),onChange:A=>M(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.metaKey||A.ctrlKey)?(A.preventDefault(),I()):A.key==="Escape"&&_(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsx("span",{className:"msg-editor-hint",children:C("editHint")}),e.jsx("button",{type:"button",className:"chip",onClick:()=>_(!1),children:C("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!y.trim(),title:C("reaskFromHere"),onClick:I,children:[e.jsx(ft,{})," ",C("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),N?e.jsx(ca,{message:s}):R?e.jsxs(e.Fragment,{children:[e.jsx(ua,{block:R}),R.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(ot,{text:R.userMessage})}),s.content.map((A,Y)=>A.type==="text"?null:e.jsx(Jt,{block:A,toolResults:n,liveOutputs:l,toolStatuses:c,streaming:r,isLast:i,onKillBash:u},`${s.id}-${Y}`))]}):s.content.map((A,Y)=>e.jsx(Jt,{block:A,toolResults:n,liveOutputs:l,toolStatuses:c,streaming:r,isLast:i,onKillBash:u},`${s.id}-${Y}`)),x&&e.jsxs("div",{className:"thinking-wait",children:[C("thinkingWait"),e.jsx("span",{className:"dot"})]}),r&&i&&!x&&e.jsx("span",{className:"stream-cursor"})]})}),w&&!T&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:C("editReaskTip"),onClick:d,children:[e.jsx(ft,{})," ",C("editReask")]})})]})});function ca({message:t}){const s=me(),[n,l]=a.useState(!1),c=t.details??{},r=c.name??c.path??s("attachment"),i=c.type==="folder",o=c.mode==="reference",u=c.mode==="bridged",m=t.content.filter(C=>C.type==="text").map(C=>C.text).join(`
|
|
14
|
+
`),g=da(m),p=t.content.find(C=>C.type==="image"),k=g.split(`
|
|
15
|
+
`).length;return e.jsxs("div",{className:`attachcard ${o?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>l(C=>!C),children:[e.jsx("span",{className:"attachcard-icon",children:i?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:r}),c.path&&e.jsx("span",{className:"attachcard-path",children:c.path}),e.jsx("span",{className:`attachcard-mode ${c.mode==="lines"?"lines":o?"ref":u?"bridged":"inline"}`,children:o?i?s("folderRefShort"):`${s("refOnlyShort")} · ${Gt(c.size)}`:u?s("bridgedVision"):p?s("image"):c.mode==="lines"?s("inlineLinesRange",{start:c.startLine??1,end:c.endLine??c.lines??1}):s("inlineLines",{n:c.lines??k})}),!o&&(n?e.jsx(Ie,{}):e.jsx(it,{}))]}),!o&&n&&(u?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:r})}),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:r})}):e.jsx("pre",{className:"attachcard-content",children:g})),o&&e.jsx("div",{className:"attachcard-refnote",children:i?s("folderNotExpanded"):s("fileNotExpanded",{size:Gt(c.size)})})]})}function Gt(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function da(t){const s=t.match(/^\s*<file path="[^"]*"(?:\s+lines="[^"]*")?>\s*```\s*\n?([\s\S]*?)\n?```\s*<\/file>\s*$/);if(s)return s[1].trim();const n=t.match(/^\s*<vision-bridge>\s*([\s\S]*?)\s*<\/vision-bridge>\s*$/);return n?n[1].trim():t.trim()}function ua({block:t}){const s=me(),[n,l]=a.useState(!1);return e.jsxs("div",{className:`skillcard${n?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>l(c=>!c),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(vn,{})}),e.jsx("span",{className:"skillcard-name",children:t.name}),e.jsx("span",{className:"skillcard-path",children:t.location}),e.jsxs("span",{className:"skillcard-action",children:[n?e.jsx(at,{}):e.jsx(Ie,{}),s(n?"collapseMsg":"expandMsg")]})]}),n&&e.jsx("div",{className:"skillcard-body",children:e.jsx(ot,{text:t.content})})]})}function Jt({block:t,toolResults:s,liveOutputs:n,toolStatuses:l,streaming:c,isLast:r,onKillBash:i}){const o=me(),u=Ue(t);if(u){const C=c&&r;return e.jsxs("div",{className:"msg-text",children:[C?e.jsx(ta,{text:u.text}):e.jsx(ot,{text:u.text}),u.truncated&&e.jsx("div",{className:"trunc-note",children:o("truncated")})]})}const m=ks(t);if(m)return e.jsx(sa,{thinking:m.thinking,streaming:c&&r});const g=Ns(t);if(g){const C=s.get(g.id),T=n.get(g.id),_={result:C,liveOutput:T==null?void 0:T.text,streaming:c,status:l.get(g.id)};return e.jsx(ia,{block:g,view:_,onKillBash:i})}const p=ws(t);if(p&&p.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:p.dataUrl,alt:"attachment"})});const k=Cs(t);return k?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:k.command}),k.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${k.exitCode===0?"ok":"err"}`,children:o("exitCode",{code:k.exitCode})}),k.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:o("cancelled")})]}),k.output&&e.jsx("pre",{className:"bashblock-output",children:k.output}),k.truncated&&e.jsx("div",{className:"trunc-note",children:o("outputTruncated")})]}):null}function Ss(t,s){switch(t){case"user":return s("role.user");case"assistant":return s("role.assistant");case"toolResult":return s("role.tool");case"bashExecution":return s("role.bash");case"branchSummary":return s("role.branch");case"compactionSummary":return s("role.compaction");default:return t}}function ma(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),l=String(s.getMinutes()).padStart(2,"0");return`${n}:${l}`}const pa=a.memo(function({message:s,onExpand:n}){const l=me();let c="";for(const p of s.content){const k=Ue(p);if(k&&k.text.trim()){const C=St(k.text);C?c=`skill:${C.name}`+(C.userMessage?` · ${C.userMessage.replace(/\s+/g," ").trim()}`:""):c=k.text.replace(/\s+/g," ").trim();break}}if(!c&&s.role==="custom"&&s.customType==="file"){const p=s.details??{};c=p.name??p.path??""}c.length>90&&(c=`${c.slice(0,90)}…`);let i=0,o=0,u=0,m=0;for(const p of s.content)ks(p)?i++:Ns(p)?o++:Cs(p)?u++:ws(p)&&m++;const g=[];return i&&g.push(`${l("thinking")} ${i}`),o&&g.push(`${l("toolCalls")} ${o}`),u&&g.push(`${l("bashRuns")} ${u}`),m&&g.push(`${l("images")} ${m}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${l("expandMsg")} · ${c||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"?l("attachment"):Ss(s.role,l)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),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:ha(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(Ie,{})," ",l("expandMsg")]})]})});function ha(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),l=String(s.getMinutes()).padStart(2,"0");return`${n}:${l}`}const ga=a.memo(function({id:s,show:n,height:l,containerRef:c,onMeasured:r,lazyRef:i,children:o}){const u=a.useRef(null),m=a.useRef(null);return a.useLayoutEffect(()=>{const g=m.current;if(m.current=n,!n||g!==!1)return;const p=u.current,k=c.current;if(!p||!k)return;const C=p.offsetHeight;r==null||r(s,C);const T=C-l;if(T!==0){const _=p.parentElement;_&&_.getBoundingClientRect().bottom<=k.getBoundingClientRect().top&&(k.scrollTop+=T)}},[n]),n?e.jsx("div",{ref:i,"data-lazy-id":s,children:e.jsx("div",{ref:u,children:o})}):e.jsx("div",{ref:i,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:l},"aria-hidden":"true"})});function fa(t,s,n,l){const c=[],r=[];let i=0;for(const o of t){if(n.has(o.id))continue;o.top<s.bottom&&o.bottom>s.top?l.has(o.id)&&c.push(o.id):l.has(o.id)||(r.push(o.id),o.bottom<=s.top&&(i+=o.bottom-o.top))}return{show:c,hide:r,shrinkAbove:i}}function xa(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const l of s.show)n.delete(l);for(const l of s.hide)n.add(l);return n}function va(t,s,n){const l=new Set;let c=0;for(let r=t.length-1;r>=0&&!(r<t.length-1&&c>=n);r--){const i=t[r];l.add(i.id),c+=s.get(i.id)??Ts(i.role,i.customType)}return l}function Ts(t,s){switch(t){case"user":return 72;case"assistant":return 280;case"toolResult":return 8;case"custom":return s==="file"?96:72;default:return 60}}function ya(t){if(t.role==="toolResult")return"";const s=[];for(const n of t.content)ja(n,s);return t.errorMessage&&s.push(t.errorMessage),s.join(`
|
|
16
|
+
`)}function ja(t,s){if(typeof t.text=="string"){s.push(t.text);return}switch(t.type){case"thinking":typeof t.thinking=="string"&&s.push(t.thinking);break;case"toolCall":{typeof t.name=="string"&&s.push(t.name),typeof t.argumentsText=="string"&&s.push(t.argumentsText);break}case"bash":typeof t.command=="string"&&s.push(t.command),typeof t.output=="string"&&s.push(t.output);break}}function ba(t,s){const n=s.trim().toLowerCase();if(!n)return 0;const l=t.toLowerCase();let c=0,r=l.indexOf(n);for(;r!==-1;)c++,r=l.indexOf(n,r+n.length);return c}function ka(t,s){const n=s.trim().toLowerCase();if(!n)return[];const l=[];for(const c of t){const r=ya(c);if(!r)continue;const i=ba(r,n);for(let o=0;o<i;o++)l.push({messageId:c.id,occurrence:o})}return l}function Na(t,s){var i;const n=new Map,l=[],c=s.toLowerCase();if(!c)return{byMsg:n,all:l};const r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(o){const u=o.parentElement;return!u||u.closest(".search-bar")?NodeFilter.FILTER_REJECT:(o.textContent??"").toLowerCase().includes(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let o=r.nextNode();o;o=r.nextNode()){const u=(o.textContent??"").toLowerCase(),m=(i=o.parentElement)==null?void 0:i.closest("[data-msg-id]");if(!m)continue;const g=m.getAttribute("data-msg-id")??"";let p=u.indexOf(c);for(;p!==-1;){const k=document.createRange();k.setStart(o,p),k.setEnd(o,p+c.length),l.push(k);const C=n.get(g);C?C.push(k):n.set(g,[k]),p=u.indexOf(c,p+c.length)}}return{byMsg:n,all:l}}function Be(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const l=window.Highlight;l&&n.highlights.set(t,new l(...s))}function wa({containerRef:t,messages:s,open:n,onClose:l,onEnsureExpanded:c}){const r=me(),i=a.useRef(null),[o,u]=a.useState(""),[m,g]=a.useState(0),p=a.useDeferredValue(o),k=n?p.trim():"",C=a.useMemo(()=>n?ka(s,k):[],[s,k,n]),T=a.useRef(C);T.current=C;const _=a.useRef(m);_.current=m,a.useEffect(()=>{n&&(g(0),requestAnimationFrame(()=>{var S;return(S=i.current)==null?void 0:S.select()}))},[n]),a.useEffect(()=>{if(!n)return;const S=R=>{R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),l())};return window.addEventListener("keydown",S,!0),()=>window.removeEventListener("keydown",S,!0)},[n,l]),a.useEffect(()=>(n||(Be("msg-search",[]),Be("msg-search-active",[])),()=>{Be("msg-search",[]),Be("msg-search-active",[])}),[n]);const y=a.useCallback(S=>{const R=t.current;if(!R)return;const B=R.querySelector(`[data-msg-id="${S}"]`);B&&(B.classList.remove("msg-flash"),B.offsetWidth,B.classList.add("msg-flash"))},[t]);a.useLayoutEffect(()=>{if(!n||!k)return;const S=t.current;if(!S)return;let R=!1,B=0;return B=requestAnimationFrame(()=>{var K;if(R)return;const{byMsg:x,all:w}=Na(S,k);Be("msg-search",w);const d=T.current,I=d[Math.min(_.current,d.length-1)];if(!I)return;const F=(K=x.get(I.messageId))==null?void 0:K[I.occurrence];if(F){Be("msg-search-active",[F]);const A=F.startContainer.parentElement??S.querySelector(`[data-msg-id="${I.messageId}"]`);A==null||A.scrollIntoView({block:"center"})}else y(I.messageId)}),()=>{R=!0,cancelAnimationFrame(B)}},[n,k,C,t,y]);const M=a.useCallback(S=>{const R=T.current;if(R.length===0)return;const B=(_.current+S+R.length)%R.length;g(B),c(R[B].messageId)},[c]);if(!n)return null;const N=C.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:i,className:"search-input",type:"text",value:o,placeholder:r("searchPlaceholder"),onChange:S=>{u(S.target.value),g(0)},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),M(S.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${N===0?"empty":""}`,children:N===0?r("searchNoResults"):`${Math.min(m+1,N)}/${N}`}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchPrev"),disabled:N===0,onClick:()=>M(-1),children:e.jsx(at,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchNext"),disabled:N===0,onClick:()=>M(1),children:e.jsx(Ie,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchClose"),onClick:l,children:e.jsx(Se,{})})]})}const Qt=new Map,Ca=15,Yt=30,Xt=1200,Sa=1600;function Zt(t){return t.content.some(s=>s.type==="toolCall")}const Ta=[{key:"ex.understand",icon:"🔍"},{key:"ex.debug",icon:"🐛"},{key:"ex.test",icon:"🧪"},{key:"ex.review",icon:"🧹"}];function Ma(t){return Ta.map(({key:s,icon:n})=>({icon:n,text:t(s),prompt:t(`${s}.prompt`)}))}function Ea({state:t,liveOutputs:s,toolStatuses:n,onEdit:l,onKillBash:c}){const r=me(),i=a.useRef(null),[o,u]=a.useState(!0),m=a.useRef(!0),g=a.useRef(0),p=a.useRef(!1),[k,C]=a.useState(()=>new Set),[T,_]=a.useState(!1),y=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,M=a.useMemo(()=>{const j=new Map;for(const D of t.messages)D.role==="toolResult"&&D.toolCallId&&j.set(D.toolCallId,D);return j},[t.messages]),N=y.length>0?y[y.length-1].id:null,S=t.messages.length>Yt?Math.max(0,t.messages.length-Ca):0,[R,B]=a.useState(()=>new Set),[x,w]=a.useState(()=>new Set),d=a.useRef(new Map),I=a.useRef(new Map),F=a.useRef(0),K=a.useRef(R);K.current=R;const A=t.messages.length>Yt&&!T,Y=a.useRef(A);Y.current=A;const re=va(t.messages,d.current,Sa),L=a.useRef(re);L.current=re;const f=a.useCallback(()=>{const j=i.current;if(!j)return;if(!Y.current){B(le=>le.size?new Set:le);return}const D=j.getBoundingClientRect(),te={top:D.top-Xt,bottom:D.bottom+Xt},G=[];for(const[le,xe]of I.current){const we=xe.getBoundingClientRect();G.push({id:le,top:we.top,bottom:we.bottom}),K.current.has(le)||d.current.set(le,we.bottom-we.top)}const ce=fa(G,te,L.current,K.current);for(const le of ce.hide){const xe=I.current.get(le);xe&&d.current.set(le,xe.offsetHeight)}B(le=>xa(le,ce))},[]),E=a.useCallback(()=>{F.current||(F.current=requestAnimationFrame(()=>{F.current=0,f()}))},[f]);a.useLayoutEffect(()=>{f()},[f]);const se=a.useRef(T);a.useLayoutEffect(()=>{se.current&&!T&&f(),se.current=T},[T,f]);const $=a.useCallback((j,D)=>{d.current.set(j,D)},[]),X=a.useCallback(j=>{j&&I.current.set(j.dataset.lazyId??"",j)},[]);a.useEffect(()=>{const j=new Set(t.messages.map(D=>D.id));for(const[D,te]of I.current)j.has(D)||(I.current.delete(D),d.current.delete(D));B(D=>{let te=!1;const G=new Set;for(const ce of D)j.has(ce)?G.add(ce):te=!0;return te?G:D})},[t.messages,k]),a.useEffect(()=>()=>cancelAnimationFrame(F.current),[]);const b=a.useMemo(()=>{const j=[];for(const D of t.messages){if(D.role!=="user")continue;const te=D.content.map(le=>{var xe;return((xe=Ue(le))==null?void 0:xe.text)??""}).filter(Boolean).join(" "),G=St(te),ce=G?G.userMessage??`skill:${G.name}`:te.trim();ce&&j.push({id:D.id,text:ce})}return j},[t.messages]),V=a.useMemo(()=>{const j=new Map;return b.forEach((D,te)=>j.set(D.id,te)),j},[b]),[q,ne]=a.useState(-1),he=a.useRef(-1),fe=a.useRef(b);a.useEffect(()=>{fe.current=b},[b]);const ge=a.useCallback(()=>{const j=i.current,D=fe.current;if(!j||D.length===0)return;const te=j.getBoundingClientRect().top,G=140;let ce=-1;for(let le=0;le<D.length;le++){const xe=j.querySelector(`[data-msg-id="${D[le].id}"]`);if(xe)if(xe.getBoundingClientRect().top<=te+G)ce=le;else break}ce!==he.current&&(he.current=ce,ne(ce))},[]);a.useEffect(()=>{ge()},[b,ge]);const Z=a.useCallback(j=>{C(D=>D.has(j)?D:new Set(D).add(j))},[]),pe=a.useCallback(j=>{const D=t.messages.findIndex(te=>te.id===j);D>=0&&D<S&&!k.has(j)&&Ut.flushSync(()=>Z(j))},[t.messages,S,k,Z]);a.useEffect(()=>{const j=D=>{if(!(D.ctrlKey||D.metaKey)||D.key.toLowerCase()!=="f")return;const te=D.target;te&&(te.tagName==="INPUT"||te.tagName==="TEXTAREA"||te.isContentEditable)||(D.preventDefault(),_(!0))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[]);const h=a.useCallback(j=>{C(D=>{if(!D.has(j))return D;const te=new Set(D);return te.delete(j),te})},[]),H=a.useCallback(j=>{const D=t.messages.findIndex(G=>G.id===j);Ut.flushSync(()=>{D>=0&&D<S&&!k.has(j)&&Z(j),w(G=>G.has(j)?G:new Set(G).add(j))});const te=fe.current.findIndex(G=>G.id===j);he.current=te,ne(te),requestAnimationFrame(()=>{var ce,le,xe;const G=(ce=i.current)==null?void 0:ce.querySelector(`[data-msg-id="${j}"]`);G&&((le=i.current)==null||le.querySelectorAll(".msg-flash").forEach(we=>we.classList.remove("msg-flash")),G.scrollIntoView({block:"start"}),G.classList.remove("msg-flash"),G.offsetWidth,G.classList.add("msg-flash"),G!==((xe=i.current)==null?void 0:xe.lastElementChild)&&(p.current=!0))})},[t.messages,S,k,Z]),z=a.useCallback(()=>{const j=i.current;if(!j)return;const D=j.scrollTop-g.current;g.current=j.scrollTop;const te=j.scrollHeight-j.scrollTop-j.clientHeight<80;D<-4&&D>-500?p.current=!0:te&&D>=0&&(p.current=!1),m.current=te&&!p.current,u(m.current),ge(),E()},[ge,E]),Q=a.useRef(!1);a.useEffect(()=>{const j=Q.current;if(Q.current=!!t.isStreaming,j&&!t.isStreaming&&!p.current){const D=()=>{const G=i.current;G&&!p.current&&(G.scrollTop=G.scrollHeight,m.current=!0,u(!0))};requestAnimationFrame(()=>requestAnimationFrame(D));const te=setTimeout(D,180);return()=>clearTimeout(te)}},[t.isStreaming]),a.useEffect(()=>{const j=i.current;j&&m.current&&(j.scrollTop=j.scrollHeight)},[y,t.isStreaming,s]);const oe=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");a.useEffect(()=>{const j=i.current;j&&m.current&&(j.scrollTop=j.scrollHeight)},[oe]);const ve=a.useCallback(()=>{const j=i.current;j&&(j.scrollTop=j.scrollHeight),m.current=!0,p.current=!1,u(!0)},[]),U=a.useRef(null);a.useEffect(()=>{const j=U.current,D=i.current;if(!j||!D)return;const te=G=>{G.preventDefault();const ce=j.querySelector(".qn-list");if(ce&&ce.contains(G.target)&&ce.scrollHeight>ce.clientHeight){ce.scrollTop+=G.deltaY;return}D.scrollTop+=G.deltaY};return j.addEventListener("wheel",te,{passive:!1}),()=>j.removeEventListener("wheel",te)},[]);const[ae,ee]=a.useState(0);a.useEffect(()=>{const j=()=>{var D;ee(((D=i.current)==null?void 0:D.clientHeight)??0),E()};return j(),window.addEventListener("resize",j),()=>window.removeEventListener("resize",j)},[E]);const Ne=b.length,Me=a.useMemo(()=>Ne===0?27:Math.max(4,Math.min(27,Math.floor(((ae||600)-16)/Ne)-3)),[Ne,ae]),Pe=Me<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:"messages",ref:i,onScroll:z,children:[t.messages.length===0&&!t.streamingMessage&&e.jsxs("div",{className:"empty-state",children:[e.jsx("div",{className:"empty-logo-wrap",children:e.jsx("div",{className:"empty-logo",children:"π"})}),e.jsx("h2",{className:"empty-title",children:r("welcomeTitle")}),e.jsx("p",{className:"empty-sub",children:r("welcomeSub")}),e.jsxs("div",{className:"empty-cwd",children:[e.jsx("span",{className:"empty-cwd-label",children:r("directory")}),e.jsx("span",{className:"empty-cwd-path",children:t.cwd})]}),e.jsx("div",{className:"empty-examples",children:Ma(r).map(j=>e.jsxs("button",{type:"button",className:"empty-example",title:r("clickToFill"),onClick:()=>window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:j.prompt})),children:[e.jsx("span",{className:"empty-example-icon",children:j.icon}),e.jsx("span",{className:"empty-example-text",children:j.text})]},j.prompt))})]}),t.messages.map((j,D)=>{const te=D<S,G=te&&k.has(j.id);if(te&&!G)return j.role==="toolResult"?null:e.jsx(pa,{message:j,onExpand:Z},j.id);const ce=j.role==="user"?V.get(j.id):void 0,le=!A||re.has(j.id)||x.has(j.id)||!R.has(j.id);return e.jsx(ga,{id:j.id,show:le,height:d.current.get(j.id)??Ts(j.role,j.customType),containerRef:i,onMeasured:$,lazyRef:X,children:e.jsx(Vt,{message:j,qnIndex:ce,qnActive:ce!==void 0?ce===q:void 0,onJump:H,toolResults:M,liveOutputs:Zt(j)?s:Qt,toolStatuses:n,streaming:t.isStreaming,onKillBash:c,isLast:j.id===N,onEdit:l,onCollapse:G?h:void 0},j.id)},j.id)}),t.streamingMessage&&e.jsx(Vt,{message:t.streamingMessage,toolResults:M,liveOutputs:Zt(t.streamingMessage)?s:Qt,toolStatuses:n,streaming:!0,isLast:!0,onEdit:l,onKillBash:c},t.streamingMessage.id),t.isStreaming&&y.length===0&&e.jsx("div",{className:"streaming-wait",children:r("waitingResponse")}),t.queue.steering.map((j,D)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:r("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:j})]})},`q-steer-${D}`)),t.queue.followUp.map((j,D)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:r("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:j})]})},`q-fu-${D}`))]}),!o&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:ve,children:[e.jsx(hs,{})," ",r("backToBottom")]}),e.jsx(wa,{containerRef:i,messages:y,open:T,onClose:()=>_(!1),onEnsureExpanded:pe}),b.length>0&&e.jsxs("div",{className:`qn-rail ${Pe?"many":""}`,ref:U,"aria-label":r("questionNavTitle"),style:{"--rail-gap":`${Me}px`},children:[b.map((j,D)=>e.jsx("button",{type:"button",className:`qn-bar ${D===q?"active":""}`,"aria-label":`${D+1}. ${j.text}`,onClick:()=>H(j.id),children:e.jsxs("span",{className:"qn-bar-text",children:[D+1,". ",j.text]})},j.id)),Pe&&e.jsx("div",{className:"qn-list",children:b.map((j,D)=>e.jsxs("button",{type:"button",className:`qn-list-item ${D===q?"active":""}`,"aria-label":`${D+1}. ${j.text}`,onClick:()=>H(j.id),children:[e.jsx("span",{className:"qn-list-idx",children:D+1}),e.jsx("span",{className:"qn-list-text",children:j.text})]},j.id))})]})]})}const Ra=1568,La=2*1024*1024;function Je(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function Ia(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const n=Math.min(1,Ra/Math.max(s.width,s.height)),l=Math.max(1,Math.round(s.width*n)),c=Math.max(1,Math.round(s.height*n)),r=t.type==="image/jpeg"||t.type==="image/jpg"?[["image/jpeg",.85],["image/jpeg",.6],["image/webp",.8]]:[["image/png",1],["image/jpeg",.85],["image/jpeg",.6]];let i=null;for(const[o,u]of r){const m=document.createElement("canvas");m.width=l,m.height=c;const g=m.getContext("2d");if(!g)continue;o!=="image/png"&&(g.fillStyle="#ffffff",g.fillRect(0,0,l,c)),g.drawImage(s,0,0,l,c);const p=m.toDataURL(o,u),k=p.match(/^data:([^;]+);base64,/),C=k?k[1]:o,T=p.replace(/^data:[^;]*;base64,/,""),_=Math.floor(T.length*3/4);if(i={data:T,mimeType:C,name:t.name,size:_},_<=La)return i}return i}finally{s.close()}}const Pa=a.memo(function({ready:s,streaming:n,messages:l,slashCommands:c,modelState:r,models:i,modelsLoading:o,send:u,attachments:m,onRemoveAttachment:g,onAddImageFiles:p,onAddLocalFiles:k,onNotice:C,onSent:T,onManageModels:_}){const y=me(),{locale:M}=wt(),N=h=>M==="en"&&h.descriptionEn?h.descriptionEn:h.description??"",S=h=>M==="en"&&h.argumentHintEn?h.argumentHintEn:h.argumentHint??"",[R,B]=a.useState(""),[x,w]=a.useState(!1),[d,I]=a.useState(null),[F,K]=a.useState(0),[A,Y]=a.useState(!1),[re,L]=a.useState(void 0),f=a.useRef(null),E=a.useRef(null),se=a.useRef(null),$={builtin:y("slashBuiltin"),extension:y("slashExtension"),prompt:y("slashPrompt"),skill:y("slashSkill")},X=h=>{const H=h.match(/^\/([^\s]*)$/);if(H&&s){const z=H[1].toLowerCase(),Q=c.filter(oe=>oe.name.toLowerCase().startsWith(z));I(Q.length>0?Q:null),K(0)}else I(null)};a.useEffect(()=>{var H;const h=(H=se.current)==null?void 0:H.querySelector(".slash-item.active");h==null||h.scrollIntoView({block:"nearest"})},[F,d]);const b=h=>{var ve;const H=d??[],z=h??H[F%Math.max(H.length,1)];if(!z){I(null);return}const Q=R.match(/^\/([^\s]*)([\s\S]*)$/),oe=Q?Q[2]:"";B(`/${z.name} ${oe}`),I(null),(ve=f.current)==null||ve.focus()},V=async()=>{const H=[...l].reverse().find(Q=>Q.role==="assistant"&&Q.content.some(oe=>oe.type==="text"&&oe.text)),z=H==null?void 0:H.content.filter(Q=>Q.type==="text").map(Q=>Q.text).join(`
|
|
17
|
+
`);if(!z){C("warning",y("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(z),C("info",y("slashCopied"))}catch{C("error",y("slashCopyFailed"))}},q=h=>{if(!h||h.length===0){C("warning",y("foldersNotSupported"));return}const H=Array.from(h).filter(Q=>Je(Q.type)),z=Array.from(h).filter(Q=>!Je(Q.type));H.length>0&&p(H),z.length>0&&k(z)},ne=h=>{var Q;const H=(Q=h.clipboardData)==null?void 0:Q.items;if(!H)return;const z=[];for(const oe of H)if(oe.kind==="file"&&Je(oe.type)){const ve=oe.getAsFile();ve&&z.push(ve)}z.length!==0&&(h.preventDefault(),p(z))},he=s,fe=a.useRef(R);a.useEffect(()=>{fe.current=R},[R]),a.useEffect(()=>{X(fe.current)},[c]),a.useEffect(()=>{const h=H=>{var Q;const z=H.detail;B(z),(Q=f.current)==null||Q.focus()};return window.addEventListener("pi-web:fill",h),()=>window.removeEventListener("pi-web:fill",h)},[]),a.useEffect(()=>{if(!A)return;const h=H=>{H.key==="Escape"&&Y(!1)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[A]),a.useEffect(()=>{const h=f.current;if(!h)return;h.style.height="auto";const H=h.scrollHeight>220;h.style.height=`${Math.min(h.scrollHeight,220)}px`,h.style.overflowY=H?"auto":"hidden"},[R]);const ge=(h=!1)=>{var Q,oe,ve,U,ae;const H=R.trim(),z=m.some(ee=>ee.imageData||ee.fileData);if(!(!he||!H&&!z)){if(H==="/help"){const ee=(oe=(Q=f.current)==null?void 0:Q.closest(".inputbox"))==null?void 0:oe.getBoundingClientRect();L(ee==null?void 0:ee.width),Y(!0),B(""),(ve=f.current)==null||ve.focus();return}if(H==="/copy"){B(""),(U=f.current)==null||U.focus(),V();return}u({type:"prompt",text:H,queue:h,attachments:m.map(ee=>ee.imageData?{path:"",imageData:ee.imageData,mimeType:ee.mimeType,name:ee.name}:ee.fileData?{path:"",fileData:ee.fileData,mimeType:ee.mimeType,name:ee.name,size:ee.size}:{path:ee.path,mode:ee.mode,...ee.lines?{lines:ee.lines}:{}})})&&(B(""),T(),(ae=f.current)==null||ae.focus())}},Z=h=>{if(!h.nativeEvent.isComposing){if(d&&d.length>0)switch(h.key){case"ArrowDown":h.preventDefault(),K(H=>(H+1)%d.length);return;case"ArrowUp":h.preventDefault(),K(H=>(H-1+d.length)%d.length);return;case"Tab":case"Enter":h.preventDefault(),b();return;case"Escape":h.preventDefault(),I(null);return}h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),ge())}},pe=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[R.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:y("supplementTip"),onClick:()=>ge(!0),children:[e.jsx(tn,{})," ",y("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:y("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(Xe,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:y("sendTip"),disabled:!he||!R.trim()&&!m.some(h=>h.imageData||h.fileData),onClick:()=>ge(),children:e.jsx(ps,{})})});return e.jsxs("div",{className:`inputbar${x?" drop-active":""}`,onDragOver:h=>{h.preventDefault(),h.stopPropagation(),w(!0)},onDragLeave:h=>{h.currentTarget.contains(h.relatedTarget)||w(!1)},onDrop:h=>{var H;h.preventDefault(),h.stopPropagation(),w(!1),q(((H=h.dataTransfer)==null?void 0:H.files)??null)},children:[x&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",y("dropHereToAttach")]})}),m.length>0&&e.jsxs("div",{className:"attach-row",children:[m.map(h=>e.jsxs("span",{className:`attach-chip ${h.imageData?"image":h.fileData?"file":h.mode}`,title:h.imageData?y("attachImage",{name:h.name}):h.fileData?y("attachFile",{name:h.name}):h.isDir?y("folderRef",{path:h.path}):h.mode==="reference"?y("refOnly",{path:h.path}):h.mode==="lines"&&h.lines?y("attachLines",{path:h.path,start:h.lines.start,end:h.lines.end}):y("attachContent",{path:h.path}),children:[h.imageData?"🖼":h.fileData?"📄":h.isDir?"📁":h.mode==="reference"?"🔗":"📎"," ",h.name,h.mode==="lines"&&h.lines&&e.jsxs("span",{className:"attach-range",children:["L",h.lines.start,"-",h.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:y("removeAttachment"),onClick:()=>g(h.key??h.path),children:"×"})]},h.key??`${h.path}|${h.mode}|${h.lines?`${h.lines.start}-${h.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:y("attachHint")})]}),d&&d.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:se,"aria-label":y("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:y("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>I(null),children:"Esc"})]}),d.map((h,H)=>e.jsxs("button",{type:"button",className:`slash-item${H===F?" active":""}`,onMouseEnter:()=>K(H),onClick:()=>b(h),children:[e.jsxs("span",{className:"slash-name",children:["/",h.name]}),e.jsx("span",{className:`slash-source ${h.source}`,children:$[h.source]}),e.jsxs("span",{className:"slash-desc",children:[N(h),h.argumentHint&&e.jsx("span",{className:"slash-hint",children:S(h)})]})]},h.name))]}),A&&e.jsx("div",{className:"modal-backdrop",onClick:()=>Y(!1),children:e.jsxs("div",{className:"slash-help",style:re?{width:re}:void 0,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",y("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>Y(!1),children:y("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:y("slashLoading")}):c.map(h=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",h.name]}),e.jsx("span",{className:`slash-source ${h.source}`,children:$[h.source]}),e.jsxs("span",{className:"slash-help-desc",children:[N(h),h.argumentHint&&e.jsx("span",{className:"slash-hint",children:S(h)})]})]},h.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:E,type:"file",multiple:!0,hidden:!0,onChange:h=>{q(h.target.files),h.target.value=""}}),e.jsxs("div",{className:"inputbox-row",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:y("uploadFile"),disabled:!he,onClick:()=>{var h;return(h=E.current)==null?void 0:h.click()},children:e.jsx(Dt,{})}),e.jsx("textarea",{ref:f,value:R,rows:1,placeholder:y(he?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!he,onChange:h=>{B(h.target.value),X(h.target.value)},onKeyDown:Z,onPaste:ne}),pe()]}),e.jsxs("div",{className:"input-tools",children:[e.jsx("div",{className:"input-tools-left",children:e.jsx(xs,{state:r,models:i,modelsLoading:o,send:u,onManageModels:_,compact:!0})}),e.jsxs("div",{className:"input-tools-right",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:y("uploadFile"),disabled:!he,onClick:()=>{var h;return(h=E.current)==null?void 0:h.click()},children:e.jsx(Dt,{})}),pe()]})]})]})]})}),Ba=a.memo(function({goal:s,models:n,modelsLoading:l,activeConversationId:c,send:r}){var K,A,Y,re,L,f;const i=me(),o=!s.conversationId||s.conversationId===c,u=s.goal!==null&&o,[m,g]=a.useState(""),[p,k]=a.useState(s.reviewModel??""),[C,T]=a.useState(s.maxRounds),[_,y]=a.useState(s.locked),[M,N]=a.useState(!1),[S,R]=a.useState(!1),[B,x]=a.useState(!0);a.useEffect(()=>{k(s.reviewModel??""),T(s.maxRounds||0),y(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),a.useEffect(()=>{M&&n.length===0&&!S&&!l&&(R(!0),r({type:"list_models"}))},[M,n.length,S,l,r]),a.useEffect(()=>{n.length>0&&R(!1)},[n.length]);const w=()=>{var E;return p?((E=n.find(se=>se.id===p))==null?void 0:E.name)??p:i("goalBarUseMainModel")},d=()=>{const E=m.trim();E&&(r({type:"set_goal",goal:E,...p?{reviewModel:p}:{},maxRounds:C,locked:_}),g(""),x(!1))},I=()=>{const E=m.trim();E&&(r({type:"start_goal_wizard",text:E,...p?{wizardModel:p}:{},maxRounds:C,locked:_}),g(""),x(!1))},F=(((K=s.wizard)==null?void 0:K.active)??!1)&&o;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:((A=s.wizard)==null?void 0:A.draft)??"",children:[i("goalWizardRunning"),": ",(Y=s.wizard)==null?void 0:Y.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[i("goalBarRound",{n:(((re=s.wizard)==null?void 0:re.step)??0)+1})," ","/ ",((L=s.wizard)==null?void 0:L.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((f=s.wizard)==null?void 0:f.status)||i("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:i("goalBarClear"),onClick:()=>{r({type:"clear_goal"}),x(!0)},children:e.jsx(Se,{})})]})}):u?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[i("goalBarReviewing")," ",i("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?i("goalBarPassed"):s.verdict==="fail"?i("goalBarFailed"):`${i("goalBarRound",{n:s.round||1})} · ${s.locked?i("goalBarLocked"):i("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:s.status}),e.jsx("button",{type:"button",className:"goalbar-x",title:i("goalBarClear"),disabled:s.reviewing,onClick:()=>{r({type:"clear_goal"}),x(!0)},children:e.jsx(Se,{})})]})}):B?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:i("goalBarPlaceholder"),onClick:()=>x(!1),children:[e.jsx(Bt,{})," ",e.jsx("span",{children:i("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(Bt,{})}),e.jsx("input",{className:"goalbar-input",value:m,placeholder:i("goalBarPlaceholder"),onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&d()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!m.trim(),onClick:d,children:i("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!m.trim(),title:i("goalWizardTip"),onClick:I,children:["🔍 ",i("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:i(_?"goalBarLocked":"goalBarUnlocked"),onClick:()=>y(E=>(r({type:"set_goal_prefs",locked:!E}),!E)),children:_?e.jsx(dn,{}):e.jsx(Zs,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:i("goalBarClear"),onClick:()=>x(!0),children:e.jsx(at,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Re,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[i("goalBarReviewModel"),": ",e.jsx("b",{children:w()})]}),open:M,onOpenChange:N,direction:"up",children:[e.jsx("div",{className:"dd-header",children:i("goalBarReviewModel")}),(S||l)&&e.jsx("div",{className:"dd-loading",children:i("loading")}),n.length===0&&!S&&!l&&e.jsx("div",{className:"dd-loading",children:i("noModels")}),e.jsx(ke,{active:p==="",onClick:()=>{k(""),N(!1),r({type:"set_goal_prefs",reviewModel:""})},children:i("goalBarUseMainModel")}),n.map(E=>e.jsx(ke,{active:p===E.id,onClick:()=>{k(E.id),N(!1),r({type:"set_goal_prefs",reviewModel:E.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:E.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:E.provider})})]})},E.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>r({type:"list_models"}),children:i("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:i("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:i("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:C,placeholder:i("goalBarUnlimitedShort"),onChange:E=>{const se=parseInt(E.target.value,10);if(Number.isNaN(se)||se<0){T(0);return}T(se)},onBlur:()=>r({type:"set_goal_prefs",maxRounds:C}),onKeyDown:E=>{E.key==="Enter"&&(r({type:"set_goal_prefs",maxRounds:C}),E.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:i(_?"goalBarLocked":"goalBarUnlocked")})]})]})});function Da({chat:t,send:s}){const n=me(),l=t.state,[c,r]=a.useState(!1),[i,o]=a.useState(""),[u,m]=a.useState(0),g=a.useRef(null),p=t.pathCompletions;if(a.useEffect(()=>{if(!c)return;const d=setTimeout(()=>{s({type:"complete_path",path:i})},150);return()=>clearTimeout(d)},[i,c,s]),a.useEffect(()=>m(0),[p]),a.useEffect(()=>{const d=document.querySelector(`.status-completions .pc-item[data-idx="${u}"]`);d==null||d.scrollIntoView({block:"nearest"})},[u]),!l)return null;const k=l.stats,C=t.ready?"ok":"busy",T=t.ready?n("connected"):n("connecting"),_=k.contextUsage,y=_.tokens!==null&&_.percent!==null?`${es(_.tokens)} / ${es(_.contextWindow)}`:"—",M=_.percent??null,N=M===null?"":M>=80?"warn":M>=50?"mid":"ok",S=l.queue.steering.length+l.queue.followUp.length,R=()=>{o(l.cwd),r(!0)},B=(d,I)=>{var K;const F=d.includes("\\")?"\\":"/";o(I?`${d}${F}`:d),m(0),(K=g.current)==null||K.focus()},x=d=>{const I=d.trim();I&&I!==l.cwd&&s({type:"set_cwd",path:I}),r(!1)},w=d=>{if(d.key==="ArrowDown")d.preventDefault(),m(I=>Math.min(I+1,p.length-1));else if(d.key==="ArrowUp")d.preventDefault(),m(I=>Math.max(I-1,0));else if(d.key==="Tab"&&p.length>0){d.preventDefault();const I=p[Math.min(u,p.length-1)];B(I.path,I.type==="dir")}else if(d.key==="Enter"&&!d.nativeEvent.isComposing){const I=i.trim();if(I.endsWith("/")||I.endsWith("\\"))x(I);else if(p.some(F=>F.path===I))x(I);else if(p.length>0&&p[u]){d.preventDefault();const F=p[u];B(F.path,F.type==="dir")}else x(I)}else d.key==="Escape"&&(p.length>0?(d.stopPropagation(),s({type:"complete_path",path:""})):r(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${C}`,title:T}),e.jsx("span",{className:"status-item",children:T}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${N}`,children:M!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(M,100)}%`}})}),y]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",_a(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(" · ")})]}),l.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"),S>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",S," ",n("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:g,className:"status-cwd-input",value:i,autoFocus:!0,placeholder:n("enterPath"),onChange:d=>o(d.target.value),onKeyDown:w,onBlur:()=>r(!1)}),p.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:d=>d.preventDefault(),children:p.map((d,I)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":I,className:`pc-item ${I===u?"sel":""}`,onMouseEnter:()=>m(I),onClick:()=>B(d.path,d.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:d.type==="dir"?e.jsx(_e,{}):e.jsx(us,{})}),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:l.cwd}),onClick:R,children:["📁 ",l.cwd]})]})}function es(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function _a(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function Fa({dialog:t,send:s}){const n=me(),[l,c]=a.useState(""),[r,i]=a.useState(0),o=g=>{s({type:"dialog_response",id:t.id,value:g})};a.useEffect(()=>{c(""),i(0);const g=p=>{p.key==="Escape"&&o(null)};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],m=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:n("pluginRequest")}),t.title&&t.title!==n("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((g,p)=>e.jsx("button",{type:"button",className:`dialog-option ${p===r?"sel":""}`,onMouseEnter:()=>i(p),onClick:()=>o(g),children:g},p)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:n("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:m}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:n("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:l,placeholder:m||n("inputPlaceholder"),autoFocus:!0,onChange:g=>c(g.target.value),onKeyDown:g=>{g.key==="Enter"&&!g.nativeEvent.isComposing&&o(l)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(l),children:n("ok")})]})]})]})}function Aa(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",n=t.y!==" "&&t.y!=="?";return s&&n?"both":s?"staged":"unstaged"}function $a({chat:t,send:s,terminal:n,active:l,onSwitchToTerminal:c}){var xe,we;const r=me(),[i,o]=a.useState(null),[u,m]=a.useState([]),[g,p]=a.useState(""),[k,C]=a.useState(new Map),[T,_]=a.useState("changes"),[y,M]=a.useState([]),[N,S]=a.useState(null),[R,B]=a.useState(""),[x,w]=a.useState(!1),[d,I]=a.useState(null),[F,K]=a.useState(null),[A,Y]=a.useState(!1),[re,L]=a.useState(!1),[f,E]=a.useState(!1),[se,$]=a.useState(null),[X,b]=a.useState(!1),[V,q]=a.useState(""),ne=a.useRef(0),he=a.useRef(-1),fe=a.useRef(-1),ge=a.useRef(-1),Z=a.useRef(-1),pe=a.useRef(void 0),h=a.useRef(null),H=a.useRef([]),z=a.useCallback(v=>{if(v.reqId===he.current){if(he.current=-1,L(!1),$(null),!v.ok){$(v.error??"查询失败");return}if(v.notRepo){b(!0),o(null),m([]),C(new Map),M([]),S(null),B(""),K(null);return}b(!1);const ie={branch:v.branch??"",detached:!!v.detached,upstream:v.upstream??null,ahead:v.ahead??0,behind:v.behind??0,upstreamGone:!!v.upstreamGone,files:(v.files??[]).map(ue=>({...ue}))},J=(v.branches??[]).map(ue=>({...ue})),ye=new Map;for(const[ue,je]of Object.entries(v.stats??{}))ye.set(ue,{add:je[0],del:je[1]});o(ie),m(J),C(ye),p(ue=>{var je;return ie.detached?ue||"":ie.branch&&J.some(Te=>Te.name===ie.branch)?ie.branch:ue&&J.some(Te=>Te.name===ue)?ue:((je=J[0])==null?void 0:je.name)??""}),K(ue=>ue&&!ie.files.some(je=>je.path===ue.file.path)?null:ue)}else if(v.reqId===fe.current){if(fe.current=-1,Y(!1),!v.ok){$(v.error??"查询失败");return}const ie=h.current;if(!ie)return;K({file:ie,staged:v.stagedText??"",worktree:v.worktreeText??"",untracked:!1})}else if(v.reqId===Z.current){if(Z.current=-1,E(!1),!v.ok){$(v.error??"查询失败");return}M((v.history??[]).map(ie=>({...ie})))}else if(v.reqId===ge.current){if(ge.current=-1,w(!1),!v.ok){$(v.error??"查询失败");return}B(v.text??"")}},[]);a.useEffect(()=>{const v=t.scmData;v&&v.type==="scm_data"&&z(v)},[t.scmData,z]);const Q=a.useCallback((v,ie)=>{if(!t.ready||t.status!=="open")return!1;const J=++ne.current;return s({...v,reqId:J})?(ie.current=J,!0):(ne.current-=1,!1)},[t.ready,t.status,s]),oe=a.useCallback((v=!1,ie=!1)=>{var J;!t.ready||t.status!=="open"||(J=t.state)!=null&&J.cwd&&(pe.current!==void 0&&pe.current!==t.state.cwd&&(o(null),m([]),C(new Map),M([]),E(!1),Z.current=-1,S(null),B(""),K(null),I(null)),pe.current=t.state.cwd,$(null),Q({type:"scm_status"},he)&&(ie||L(!0)))},[t.ready,(xe=t.state)==null?void 0:xe.cwd,t.status,Q]),ve=a.useCallback(v=>{if(I(v),S(null),h.current=v,v.x==="?"&&v.y==="?"){K({file:v,staged:"",worktree:"",untracked:!0});return}Y(!0),$(null),Q({type:"scm_filediff",path:v.path},fe)||Y(!1)},[Q]),U=a.useCallback(v=>{S(v),I(null),K(null),B(""),w(!0),$(null),Q({type:"scm_commit",hash:v.hash},ge)||w(!1)},[Q]),ae=a.useCallback((v,ie)=>{var ue,je;if(!t.ready)return;const J={name:v,command:ie,cwd:"${pwd}"},ye=t.terminals.find(Te=>Te.title===v);if(ye)n.restart(ye.id),s({type:"run_command",terminalId:ye.id,conversationId:ye.conversationId,command:J,cols:80,rows:24});else{const Te=Fe();n.create({id:Te,conversationId:t.activeConversationId||((ue=t.state)==null?void 0:ue.conversationId)||"",title:v,cwd:((je=t.state)==null?void 0:je.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:J})}c()},[t.ready,(we=t.state)==null?void 0:we.cwd,t.terminals,c,s,n]),ee=a.useCallback(()=>{const v=V.trim();if(!v||X)return;const ie=v.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ae("git commit",`git add -A && git commit -m "${ie}"`),q("")},[V,X,ae]),Ne=v=>`'${v.replace(/'/g,"'\\''")}`,Me=a.useCallback(v=>{X||ae("git add",`git add -- ${Ne(v.path)}`)},[X,ae]),Pe=a.useCallback(v=>{X||ae("git reset",`git reset HEAD -- ${Ne(v.path)}`)},[X,ae]),j=a.useCallback(()=>{if(!g||X)return;const v=u.find(ie=>ie.name===g);if(v!=null&&v.remote&&typeof v.remote=="string"){const ie=g.slice(v.remote.length+1);ae("git checkout",`git checkout -b ${ie} ${g} || git checkout ${g}`)}else ae("git checkout",`git checkout ${g}`)},[g,u,X,ae]),D=a.useCallback(()=>ae("git push","git push"),[ae]),te=a.useCallback(()=>ae("git pull","git pull"),[ae]),G=a.useCallback(()=>{Q({type:"scm_history"},Z)||(Z.current=-1)},[Q]);a.useEffect(()=>{l&&oe()},[l,oe]),a.useEffect(()=>{T==="history"&&i&&G()},[T,i,G]),a.useEffect(()=>{t.scmDirty>0&&l&&oe(!1,!0)},[t.scmDirty]),a.useEffect(()=>{if(!l||!t.ready||t.status!=="open")return;const v=setInterval(()=>{document.visibilityState!=="hidden"&&oe(!1,!0)},3e4);return()=>clearInterval(v)},[l,t.ready,t.status,oe]),a.useEffect(()=>{const v=H.current;if(H.current=t.terminals,!l)return;t.terminals.some(J=>{var ue;return J.running!==!1?!1:((ue=v.find(je=>je.id===J.id))==null?void 0:ue.running)===!0&&/^git /.test(J.title)})&&t.ready&&t.status==="open"&&(oe(!1,!0),T==="history"&&i&&G())},[t.terminals,l,t.ready,t.status,oe,T,i,G]);const ce={staged:r("scmStaged"),unstaged:r("scmUnstaged"),untracked:r("scmUntracked"),both:r("scmStagedUnstaged")},le=v=>{const ie=v.split(`
|
|
18
|
+
`);return e.jsx("pre",{className:"scm-diff-pre",children:ie.map((J,ye)=>{let ue="";return J.startsWith("diff --git")||J.startsWith("index ")||J.startsWith("new file")||J.startsWith("deleted file")||J.startsWith("old mode")||J.startsWith("new mode")||J.startsWith("similarity index")||J.startsWith("rename ")||J.startsWith("copy ")||J.startsWith("Binary files")||J.startsWith("---")||J.startsWith("+++")?ue="hdr":J.startsWith("@@")?ue="hunk":J.startsWith("+")?ue="add":J.startsWith("-")&&(ue="del"),e.jsx("div",{className:`scm-diff-line ${ue}`,children:J||" "},ye)})})};return e.jsxs("div",{className:"scm-view",children:[e.jsxs("div",{className:"scm-header",children:[e.jsxs("div",{className:"scm-title-row",children:[e.jsxs("span",{className:"scm-title",children:[e.jsx(Ge,{}),r("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":T==="changes",className:T==="changes"?"active":"",onClick:()=>{_("changes"),$(null)},children:r("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":T==="history",className:T==="history"?"active":"",onClick:()=>{_("history"),$(null)},children:r("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:r("scmRefreshTip"),disabled:re,onClick:()=>oe(!0),children:e.jsx(jt,{className:re?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:r("scmCurrentBranch"),children:[e.jsx(Ge,{}),i?i.detached?r("scmDetached"):i.branch:"…",(i==null?void 0:i.upstream)&&e.jsx("span",{className:"scm-upstream",children:i.upstreamGone?r("scmUpstreamGone"):i.ahead>0||i.behind>0?r("scmAheadBehind",{ahead:i.ahead,behind:i.behind}):i.upstream})]}),e.jsxs("select",{className:"scm-select",value:g,disabled:X||u.length===0,title:r("scmSwitchBranch"),onChange:v=>p(v.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("scmSelectBranch")}),u.filter(v=>!v.remote).map(v=>e.jsx("option",{value:v.name,children:v.current?`* ${v.name}`:v.name},v.name)),u.some(v=>v.remote)&&e.jsx("optgroup",{label:r("scmRemoteBranches"),children:u.filter(v=>v.remote).map(v=>e.jsx("option",{value:v.name,children:v.name},v.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!g||g===(i==null?void 0:i.branch)||X,title:r("scmSwitchBranchTip",{branch:g}),onClick:j,children:[e.jsx(Ge,{}),r("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!i||i.detached||X,title:r("scmPushTip"),onClick:D,children:[e.jsx(ps,{}),r("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!i||i.detached||X,title:r("scmPullTip"),onClick:te,children:[e.jsx(hs,{}),r("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:V,placeholder:r("scmCommitPlaceholder"),disabled:X,onChange:v=>q(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.nativeEvent.isComposing&&ee()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!V.trim()||X,title:r("scmCommitTip"),onClick:ee,children:[e.jsx(Nt,{}),r("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[T==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmHistory")}),y.length>0&&e.jsx("span",{className:"scm-files-count",children:y.length})]}),e.jsx("div",{className:"scm-history-list",children:X?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):!i||f?e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")}):y.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoHistory")}):y.map(v=>e.jsxs("button",{type:"button",className:`scm-commit ${(N==null?void 0:N.hash)===v.hash?"active":""}`,onClick:()=>U(v),title:v.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:v.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:v.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[v.shortHash," · ",v.author," · ",v.date]}),v.decorations&&e.jsx("span",{className:"scm-commit-refs",children:v.decorations})]})]},v.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmChanges")}),i&&i.files.length>0&&e.jsx("span",{className:"scm-files-count",children:i.files.length})]}),e.jsx("div",{className:"scm-files-list",children:X?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):i?i.files.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoChanges")}):i.files.map(v=>{const ie=Aa(v),J=k.get(v.path);return e.jsxs("div",{className:`scm-file ${(d==null?void 0:d.path)===v.path?"active":""}`,title:ce[ie],onClick:()=>ve(v),children:[e.jsx("span",{className:`scm-file-xy ${ie==="untracked"?"q":"x"}`,children:v.x!==" "?v.x:" "}),e.jsx("span",{className:`scm-file-xy ${ie==="untracked"?"q":"y"}`,children:v.y!==" "?v.y:" "}),e.jsx("span",{className:"scm-file-path",children:v.path}),J&&(J.add>0||J.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[J.add>0&&e.jsxs("span",{className:"add",children:["+",J.add]}),J.del>0&&e.jsxs("span",{className:"del",children:["-",J.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(v.y!==" "||ie==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:r("scmStageTip",{path:v.path}),onClick:ye=>{ye.stopPropagation(),Me(v)},children:"+"}),ie==="staged"||ie==="both"?e.jsx("button",{type:"button",className:"scm-act",title:r("scmUnstageTip",{path:v.path}),onClick:ye=>{ye.stopPropagation(),Pe(v)},children:"−"}):null]})]},v.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:T==="history"?N?`${N.shortHash} ${N.subject}`:r("scmCommitDetail"):d?d.path:r("scmDiff")}),(T==="history"?x:A)&&e.jsx("span",{className:"scm-diff-loading",children:r("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:T==="history"?e.jsxs(e.Fragment,{children:[se&&e.jsx("div",{className:"scm-error",children:se}),!N&&!se&&e.jsx("div",{className:"scm-empty",children:r("scmSelectCommitHint")}),N&&x&&!se&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),N&&!x&&!se&&R?le(R):null]}):e.jsxs(e.Fragment,{children:[se&&e.jsx("div",{className:"scm-error",children:se}),!d&&!se&&e.jsx("div",{className:"scm-empty",children:r("scmSelectFileHint")}),d&&!F&&!se&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),d&&F&&F.untracked&&e.jsx("div",{className:"scm-empty",children:r("scmUntrackedNote")}),d&&F&&!F.untracked&&e.jsxs(e.Fragment,{children:[F.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmStaged")}),le(F.staged)]}),F.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmUnstaged")}),le(F.worktree)]}),!F.staged&&!F.worktree&&e.jsx("div",{className:"scm-empty",children:r("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(ze,{}),e.jsx("span",{children:r("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:r("scmViewTerminal")})]})]})}function Oa({send:t,piConfigured:s,providers:n,installResult:l,onClose:c}){const r=me(),[i,o]=a.useState(!1),[u,m]=a.useState(""),[g,p]=a.useState(""),[k,C]=a.useState(!1);a.useEffect(()=>{t({type:"list_providers"})},[t]),a.useEffect(()=>{s&&c()},[s,c]),a.useEffect(()=>{l&&o(!1)},[l]),a.useEffect(()=>{var S;!u&&n.length>0&&m(((S=n.find(R=>!R.configured))==null?void 0:S.id)??n[0].id)},[n,u]);const T=()=>{i||(o(!0),t({type:"install_pi_agent"}))},_=()=>{!g.trim()||k||(C(!0),t({type:"set_provider_api_key",provider:u.trim(),apiKey:g.trim()}),setTimeout(()=>C(!1),3e3))},y=()=>{t({type:"get_state"}),t({type:"list_providers"})},M=n.find(S=>S.id===u),N=l!==null&&!l.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:c,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(nt,{className:"modal-head-icon"}),e.jsx("h2",{children:r("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("setupDesc")}),N?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:r("installFailed")}),e.jsx("pre",{className:"setup-detail",children:l.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:i,onClick:T,children:r("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]}):l!=null&&l.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:r("installDone")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("provider")}),e.jsxs("select",{value:u,onChange:S=>m(S.target.value),children:[n.length===0&&e.jsx("option",{value:"",children:r("loading")}),n.map(S=>e.jsxs("option",{value:S.id,children:[S.name,"(",S.id,")",S.configured?` · ${r("configured")}`:""]},S.id))]}),(M==null?void 0:M.configured)&&e.jsx("div",{className:"field-hint",children:r("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:r("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:S=>p(S.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||k||!u,onClick:_,children:r(k?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:y,children:[e.jsx(jt,{})," ",r("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:i,onClick:T,children:r(i?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:c,children:r("skip")})]})]})})}const Ha=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],Tt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Wa=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[Tt()]});function ts(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:[Tt()]).map(s=>{var n;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(n=s.input)!=null&&n.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function qa({send:t,providers:s,providerStatus:n,fetchModelsResult:l,refreshProviderResult:c,cloneProviderResult:r,onClose:i}){const o=me(),[u,m]=a.useState(null),[g,p]=a.useState({}),[k,C]=a.useState(null),[T,_]=a.useState({}),[y,M]=a.useState(!1),[N,S]=a.useState(0),[R,B]=a.useState(null),x=a.useRef(0),[w,d]=a.useState({});a.useRef(0);const I=a.useRef(0),[F,K]=a.useState(null),A=a.useRef(0),Y=a.useRef(0);a.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const re=()=>{if(!u)return;const b=u.baseUrl.trim();if(!b){B({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(y)return;M(!0),B(null);const V=N+1;S(V),t({type:"fetch_models",reqId:V,baseUrl:b,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};a.useEffect(()=>{var b;if(!(!l||l.reqId===x.current))if(x.current=l.reqId,M(!1),l.ok&&((b=l.models)!=null&&b.length)){const V=l.models;m(q=>{if(!q)return q;const ne=q.models.map(Z=>{var H;if(!Z.id.trim())return Z;const pe=V.find(z=>z.id===Z.id.trim());if(!pe)return Z;const h={...Z};return!h.name&&pe.name&&(h.name=pe.name),!h.contextWindow&&pe.contextWindow&&(h.contextWindow=String(pe.contextWindow)),!h.maxTokens&&pe.maxTokens&&(h.maxTokens=String(pe.maxTokens)),h.input==="text"&&((H=pe.input)!=null&&H.includes("image"))&&(h.input="text-image"),!h.reasoning&&pe.reasoning&&(h.reasoning=!0),h}),he=new Set(ne.map(Z=>Z.id.trim()).filter(Boolean)),fe=V.filter(Z=>!he.has(Z.id)).map(Z=>{var pe;return{id:Z.id,name:Z.name??"",reasoning:Z.reasoning??!1,input:(pe=Z.input)!=null&&pe.includes("image")?"text-image":"text",contextWindow:Z.contextWindow?String(Z.contextWindow):"",maxTokens:Z.maxTokens?String(Z.maxTokens):""}}),ge=[...ne,...fe];return ge.some(Z=>Z.id.trim())?{...q,models:ge.filter(Z=>Z.id.trim())}:q}),B({ok:!0,text:o("fetchModelsOk",{n:V.length})})}else B({ok:!1,text:l.error||o("fetchModelsEmpty")})},[l]);const L=b=>{const V=(g[b.id]??"").trim();!V||k||(C(b.id),t({type:"set_provider_api_key",provider:b.id,apiKey:V}),setTimeout(()=>{C(null),p(q=>({...q,[b.id]:""})),_(q=>({...q,[b.id]:!1})),t({type:"list_providers"})},1500))},f=()=>{if(!u)return;const b=u.providerId.trim(),V=u.models.filter(ne=>ne.id.trim()).map(ne=>({id:ne.id.trim(),name:ne.name.trim()||void 0,reasoning:ne.reasoning||void 0,input:ne.input==="text-image"?["text","image"]:void 0,contextWindow:ne.contextWindow?Number(ne.contextWindow):void 0,maxTokens:ne.maxTokens?Number(ne.maxTokens):void 0})),q={providerId:b,name:u.name.trim()||void 0,api:u.api.trim()||void 0,baseUrl:u.baseUrl.trim()||void 0,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader||void 0,models:V};t({type:"save_model_config",providerId:b,config:q}),i()};a.useEffect(()=>{!c||c.reqId===I.current||(I.current=c.reqId,d({}))},[c]);const E=b=>{if(F)return;K(b.id);const V=++A.current+Date.now();t({type:"clone_provider",provider:b.id,reqId:V})};a.useEffect(()=>{!r||r.reqId===Y.current||(Y.current=r.reqId,K(null),r.ok&&r.config&&m(ts({...r.config,apiKey:""})))},[r]);const se=b=>{window.confirm(o("clearKeyConfirm",{id:b}))&&t({type:"clear_provider_api_key",provider:b})},$=b=>{window.confirm(o("deleteProviderConfirm",{id:b.providerId,n:b.models.length}))&&t({type:"delete_model_config",providerId:b.providerId})},X=(b,V)=>{u&&m({...u,models:u.models.map((q,ne)=>ne===b?{...q,...V}:q)})};return e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"modal model-modal",onClick:b=>b.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:i,children:e.jsx(Se,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:o(u?"editProvider":"manageModelsTitle")})}),u?e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:u.providerId,disabled:s.some(b=>b.providerId===u.providerId),onChange:b=>m({...u,providerId:b.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:u.name,onChange:b=>m({...u,name:b.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:u.api,onChange:b=>m({...u,api:b.target.value}),children:Ha.map(b=>e.jsx("option",{value:b,children:b},b))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:b=>m({...u,baseUrl:b.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:u.apiKey,onChange:b=>m({...u,apiKey:b.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:b=>m({...u,authHeader:b.target.checked})}),e.jsx("span",{children:o("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:o("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[R&&e.jsx("span",{className:`fetch-msg ${R.ok?"ok":"err"}`,title:R.text,children:R.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:y||!u.baseUrl.trim(),title:o("fetchModelsHint"),onClick:re,children:[e.jsx(bt,{})," ",o(y?"fetchingModels":"fetchModels")]})]})]}),u.models.map((b,V)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:b.id,onChange:q=>X(V,{id:q.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:b.name,onChange:q=>X(V,{name:q.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:b.input,onChange:q=>X(V,{input:q.target.value}),children:[e.jsx("option",{value:"text",children:o("text")}),e.jsx("option",{value:"text-image",children:o("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:b.reasoning,onChange:q=>X(V,{reasoning:q.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:b.contextWindow,onChange:q=>X(V,{contextWindow:q.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:b.maxTokens,onChange:q=>X(V,{maxTokens:q.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>m({...u,models:u.models.filter((q,ne)=>ne!==V)}),children:e.jsx(qe,{})})]},V)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>m({...u,models:[...u.models,Tt()]}),children:[e.jsx(De,{})," ",o("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>m(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(b=>b.id.trim()),onClick:f,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.map(b=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:b.name}),e.jsxs("span",{className:"provider-sub",children:[b.id,b.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),b.source&&!b.configured&&e.jsx("span",{className:"auth-badge dim",children:b.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[b.configured&&!T[b.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:o("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:o("replaceKeyTitle"),onClick:()=>_(V=>({...V,[b.id]:!0})),children:[e.jsx(Ft,{})," ",o("replaceKey")]}),b.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>se(b.id),children:[e.jsx(qe,{})," ",o("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:o("pasteKey"),value:g[b.id]??"",onChange:V=>p(q=>({...q,[b.id]:V.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(g[b.id]??"").trim()||k===b.id,onClick:()=>L(b),children:[e.jsx(un,{})," ",k===b.id?o("savingKey"):o("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:F!==null,title:o("cloneProviderTitle"),onClick:()=>E(b),children:[e.jsx(kt,{})," ",F===b.id?o("cloning"):o("cloneProvider")]})]})]},b.id))]}),e.jsx("div",{className:"form-section-title",children:o("customProviders")}),e.jsx("p",{className:"modal-desc",children:o("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:o("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(b=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:b.providerId}),e.jsxs("span",{className:"provider-sub",children:[b.api??"—",b.baseUrl?` · ${b.baseUrl}`:"",b.models.length>0&&` · ${o("modelsCount",{n:b.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>m(ts(b)),children:e.jsx(Ft,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>$(b),children:e.jsx(qe,{})})]})]},b.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>m(Wa()),children:[e.jsx(De,{})," ",o("addProvider")]})})]})]})})}function $e({title:t,subtitle:s,enabled:n,onToggle:l,action:c}){const r=me();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})]}),c,e.jsx("button",{type:"button",className:`set-switch ${n?"on":""}`,role:"switch","aria-checked":n,title:r(n?"settingsEnabled":"settingsDisabled"),onClick:l,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Ua({chat:t,send:s,terminal:n,onSwitchToTerminal:l,onClose:c}){const r=me(),i=t.settings,[o,u]=a.useState(""),[m,g]=a.useState("append"),p=a.useRef(!1),[k,C]=a.useState(""),[T,_]=a.useState("append"),y=a.useRef(!1),[M,N]=a.useState(""),S=a.useRef(!1),[R,B]=a.useState(""),[x,w]=a.useState(null);if(a.useEffect(()=>{i&&(g(i.promptMode),!p.current&&(u(m==="append"||i.customSystemPrompt?i.customSystemPrompt:i.defaultSystemPrompt||""),_(i.visionBridgePromptMode),!y.current&&(C(T==="append"||i.visionBridgePrompt?i.visionBridgePrompt:i.visionBridgeDefaultPrompt||""),S.current||N(i.reviewPrompt))))},[i,m,T]),!i)return null;const d=new Set(i.disabledSkills),I=new Set(i.disabledExtensions),F=f=>s({type:"set_settings",...f}),K=f=>{const E=new Set(d);E.has(f.name)?E.delete(f.name):E.add(f.name),F({disabledSkills:[...E]})},A=f=>{const E=new Set(I);E.has(f.id)?E.delete(f.id):E.add(f.id),F({disabledExtensions:[...E]})},Y=f=>{var X,b;w(null);const E=`${r("uninstallTitle")} ${f}`,se={name:E,command:`pi remove npm:${f}`,cwd:"${pwd}"},$=t.terminals.find(V=>V.title===E);$?(n.restart($.id),s({type:"run_command",terminalId:$.id,conversationId:$.conversationId,command:se,cols:80,rows:24})):n.create({id:Fe(),conversationId:t.activeConversationId||((X=t.state)==null?void 0:X.conversationId)||"",title:E,cwd:((b=t.state)==null?void 0:b.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:se}),l(),c()},re=f=>{const E=new Set(i.reviewSkills.filter(se=>!se.enabled).map(se=>se.name));E.has(f.name)?E.delete(f.name):E.add(f.name),F({reviewDisabledSkills:[...E]})},L=()=>{const f=m==="replace"&&i.defaultSystemPrompt&&o===i.defaultSystemPrompt?"":o;F({promptMode:m,customSystemPrompt:f})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:f=>f.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:c,children:e.jsx(Se,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(Ze,{className:"modal-head-icon"}),e.jsx("h2",{children:r("settingsTitle")})]}),e.jsx("p",{className:"modal-desc",children:r("settingsDesc")}),e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ht,{className:"set-section-icon"}),r("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:m,onChange:f=>{const E=f.target.value;g(E),F({promptMode:E})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:r("promptPlaceholder"),value:o,onFocus:()=>p.current=!0,onBlur:()=>{p.current=!1,L()},onChange:f=>u(f.target.value)}),e.jsx("p",{className:"set-hint",children:r(m==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ze,{className:"set-section-icon"}),r("settingsTerminalTools")]}),e.jsx($e,{title:r("terminalToolsEnabled"),subtitle:r("settingsTerminalToolsDesc"),enabled:i.terminalToolsEnabled,onToggle:()=>F({terminalToolsEnabled:!i.terminalToolsEnabled})}),!i.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:r("terminalToolsOffHint")})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{className:"set-section-icon"}),r("settingsSkills"),e.jsx("span",{className:"set-count",children:i.skills.length})]}),i.skills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:i.skills.map(f=>e.jsx($e,{title:f.name,subtitle:f.description,enabled:f.enabled,onToggle:()=>K(f)},f.name))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nn,{className:"set-section-icon"}),r("settingsExtensions"),e.jsx("span",{className:"set-count",children:i.extensions.length})]}),i.extensions.length===0?e.jsx("p",{className:"set-empty",children:r("noExtensions")}):e.jsx("div",{className:"set-list",children:i.extensions.map(f=>{const E=f.id.startsWith("npm:")?f.id.slice(4):null;return e.jsx($e,{title:f.name,subtitle:f.path,enabled:f.enabled,onToggle:()=>A(f),action:E?x===f.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:r("uninstallConfirmHint"),onClick:()=>Y(E),children:r("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:r("uninstallHint"),onClick:()=>w(f.id),children:[e.jsx(qe,{}),r("uninstallExt")]}):void 0},f.id)})})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ht,{className:"set-section-icon"}),r("settingsReview"),e.jsx("span",{className:"set-count",children:i.reviewSkills.length})]}),e.jsx("p",{className:"set-hint",children:r("settingsReviewDesc")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:r("reviewPromptPlaceholder"),value:M,onFocus:()=>S.current=!0,onBlur:()=>{S.current=!1,F({reviewPrompt:M})},onChange:f=>N(f.target.value)}),e.jsx("p",{className:"set-hint",children:r("reviewPromptHint")}),e.jsx("div",{className:"set-field-label",children:r("settingsReviewSkills")}),i.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:r("noSkills")}):e.jsx("div",{className:"set-list",children:i.reviewSkills.map(f=>e.jsx($e,{title:f.name,subtitle:f.description,enabled:f.enabled,onToggle:()=>re(f)},`review-${f.name}`))})]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ms,{className:"set-section-icon"}),r("settingsVisionBridge")]}),e.jsx($e,{title:r("visionBridgeEnabled"),subtitle:r("settingsVisionBridgeDesc"),enabled:i.visionBridgeEnabled,onToggle:()=>F({visionBridgeEnabled:!i.visionBridgeEnabled})}),!i.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r("visionBridgeOffHint")}),i.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:i.visionBridgeModel??"",onChange:f=>F({visionBridgeModel:f.target.value||null}),children:[e.jsx("option",{value:"",children:r("visionBridgeAuto")}),i.visionModels.map(f=>e.jsx("option",{value:`${f.provider}/${f.id}`,children:f.label},`${f.provider}/${f.id}`))]})]}),i.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:r("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:T,onChange:f=>{const E=f.target.value;_(E),F({visionBridgePromptMode:E})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]})]}),i.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:r("visionBridgePromptPlaceholder"),value:k,onFocus:()=>y.current=!0,onBlur:()=>{y.current=!1;const f=T==="replace"&&i.visionBridgeDefaultPrompt&&k===i.visionBridgeDefaultPrompt?"":k;F({visionBridgePromptMode:T,visionBridgePrompt:f})},onChange:f=>C(f.target.value)}),i.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:r(T==="append"?"visionBridgePromptAppendHint":"visionBridgePromptReplaceHint")}),i.visionBridgeEnabled&&(i.visionModels.length===0?e.jsx("p",{className:"set-hint",children:r("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:r("visionBridgeCurrent",{model:i.visionBridgeModel??r("visionBridgeAuto")})}))]}),e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ze,{className:"set-section-icon"}),r("settingsPresets"),e.jsx("span",{className:"set-count",children:i.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:r("presetNamePlaceholder"),value:R,onChange:f=>B(f.target.value),onKeyDown:f=>{f.key==="Enter"&&R.trim()&&(s({type:"save_preset",name:R.trim()}),B(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!R.trim(),onClick:()=>{s({type:"save_preset",name:R.trim()}),B("")},children:[e.jsx(De,{})," ",r("saveAsPreset")]})]}),i.presets.length===0?e.jsx("p",{className:"set-empty",children:r("noPresets")}):e.jsx("div",{className:"set-list",children:i.presets.map(f=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:f.name}),e.jsxs("div",{className:"set-row-desc",children:[f.promptMode==="replace"?r("promptModeReplace"):r("promptModeAppend"),f.disabledSkills.length>0&&` · ${r("settingsSkills")} ${f.disabledSkills.length}`,f.disabledExtensions.length>0&&` · ${r("settingsExtensions")} ${f.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:f.name}),children:r("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:r("deletePreset"),onClick:()=>s({type:"delete_preset",name:f.name}),children:e.jsx(qe,{})})]})]},f.name))})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:r("close")})})]})})}function za(t,s){const n=Math.max(0,Date.now()-t),l=Math.floor(n/6e4);if(l<1)return s("bgTaskJustNow");if(l<60)return s("bgTaskMinutes",{n:l});const c=Math.floor(l/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function Ka({servers:t,send:s,onClose:n}){const l=me(),[c,r]=a.useState(new Set),i=o=>r(u=>{const m=new Set(u);return m.has(o)?m.delete(o):m.add(o),m});return a.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(st,{})," ",l("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:l("close"),onClick:n,children:e.jsx(Se,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(st,{}),e.jsx("span",{children:l("bgTasksEmpty")}),e.jsx("small",{children:l("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:l("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:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[e.jsxs("span",{children:[l("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[l("bgTaskSince")," ",za(o.since,l)]})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(o.port)?"open":""}`,title:`${l("bgTaskCommand")}: ${o.command}`,onClick:()=>i(o.port),children:[e.jsx(ze,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:l("bgTaskStop"),onClick:()=>s({type:"kill_background_server",port:o.port}),children:[e.jsx(Xe,{}),e.jsx("span",{children:l("bgTaskStop")})]})]},o.port))}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:l("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(jt,{}),e.jsx("span",{children:l("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:l("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(Xe,{}),e.jsx("span",{children:l("bgTaskStopAll")})]})]})]})})}function Ve(t,s){return t.toLowerCase().includes(s)}function Va({send:t,sessions:s,projects:n,cwd:l,fileSearch:c,onClose:r,onSwitchSession:i,onSwitchProject:o,onPreviewFile:u}){const m=me(),g=a.useRef(null),[p,k]=a.useState(""),C=a.useDeferredValue(p),[T,_]=a.useState(0),y=a.useRef(1),M=a.useRef(0),N=a.useRef(null);a.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var L;return(L=g.current)==null?void 0:L.focus()})},[]);const[S,R]=a.useState(!1);a.useEffect(()=>{N.current&&clearTimeout(N.current);const L=C.trim();if(L)return N.current=setTimeout(()=>{const f=++y.current;M.current=f,R(!0),t({type:"search_files",reqId:f,query:L})},300),()=>{N.current&&clearTimeout(N.current)}},[C]);const B=C.trim().toLowerCase(),x=a.useMemo(()=>B?s.filter(L=>Ve(L.firstMessage??"",B)||Ve(L.name??"",B)||Ve(L.path.split(/[\\/]/).pop()??"",B)).slice(0,20):[],[s,B]),w=a.useMemo(()=>B?n.filter(L=>Ve(L.path,B)).slice(0,10):[],[n,B]),d=a.useMemo(()=>!B||!c||c.reqId!==M.current||!c.ok?[]:c.results,[c,B]);a.useEffect(()=>{c&&c.reqId===M.current&&M.current!==0&&R(!1)},[c]);const I=!!c&&c.ok&&c.truncated,F=a.useMemo(()=>[...x.map(L=>({kind:"session",path:L.path})),...w.map(L=>({kind:"project",path:L.path})),...d.filter(L=>L.type==="file").map(L=>({kind:"file",path:L.path,name:L.name}))],[x,w,d]);a.useEffect(()=>{_(0)},[C]);const K=a.useCallback(L=>{L&&(L.kind==="session"?i(L.path):L.kind==="project"?o(L.path):u(L.path,L.name),r())},[i,o,u,r]);a.useEffect(()=>{const L=f=>{f.key==="Escape"?(f.preventDefault(),f.stopPropagation(),r()):f.key==="ArrowDown"?(f.preventDefault(),_(E=>Math.min(E+1,F.length-1))):f.key==="ArrowUp"?(f.preventDefault(),_(E=>Math.max(E-1,0))):f.key==="Enter"&&(f.preventDefault(),K(F[T]))};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[F,T,K,r]);const A=x.length+w.length+d.length,Y=(L,f,E)=>e.jsxs("div",{className:"gs-section-head",children:[E,e.jsx("span",{children:L}),e.jsx("em",{children:f})]});let re=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:r,children:e.jsxs("div",{className:"gs-modal",onClick:L=>L.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(et,{}),e.jsx("input",{ref:g,type:"text",value:p,placeholder:m("gsPlaceholder"),onChange:L=>k(L.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:m("close"),onClick:r,children:e.jsx(Se,{})})]}),e.jsxs("div",{className:"gs-results",children:[!B&&e.jsx("div",{className:"gs-empty",children:m("gsHint")}),B&&A===0&&!I&&e.jsx("div",{className:"gs-empty",children:m(S?"gsSearching":"gsNoResults")}),x.length>0&&e.jsxs("div",{className:"gs-section",children:[Y(m("gsSessions"),x.length,e.jsx(tt,{})),x.map(L=>{re++;const f=re;return e.jsxs("button",{type:"button",className:f===T?"gs-item active":"gs-item",onMouseEnter:()=>_(f),onClick:()=>K({kind:"session",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.name||L.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:L.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:L.firstMessage})]},L.path)})]}),w.length>0&&e.jsxs("div",{className:"gs-section",children:[Y(m("gsProjects"),w.length,e.jsx(_e,{})),w.map(L=>{re++;const f=re,E=l&&L.path===l;return e.jsxs("button",{type:"button",className:f===T?"gs-item active":"gs-item",onMouseEnter:()=>_(f),onClick:()=>K({kind:"project",path:L.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[L.path.split(/[\\/]/).pop(),E&&e.jsx("em",{className:"gs-item-meta",children:m("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},L.path)})]}),(d.length>0||B&&I)&&e.jsxs("div",{className:"gs-section",children:[Y(m("gsFiles"),d.length,e.jsx(hn,{})),d.map(L=>{re++;const f=re;return e.jsxs("button",{type:"button",className:f===T?"gs-item active":"gs-item",disabled:L.type==="dir",title:L.type==="dir"?void 0:m("gsOpenPreview"),onMouseEnter:()=>_(f),onClick:()=>{L.type==="file"&&K({kind:"file",path:L.path,name:L.name})},children:[e.jsx("span",{className:"gs-item-title",children:L.name}),e.jsx("span",{className:"gs-item-sub",children:L.path})]},`${L.type}:${L.path}`)}),I&&e.jsx("div",{className:"gs-truncated",children:m("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",m("gsNavigate")]}),e.jsxs("span",{children:["Enter ",m("gsOpen")]}),e.jsxs("span",{children:["Esc ",m("gsCloseHint")]})]})]})})}const mt=5e3;function Ga({file:t,content:s,send:n,onAddLines:l,onAttach:c,onClose:r}){const i=me(),[o,u]=a.useState(null),[m,g]=a.useState(!1),[p,k]=a.useState(null),[C,T]=a.useState(!1),[_,y]=a.useState(!1),[M,N]=a.useState(!1),[S,R]=a.useState(""),[B,x]=a.useState(!0),w=a.useRef(!1),[d,I]=a.useState(!0),[F,K]=a.useState(!1),[A,Y]=a.useState(100),re=a.useRef(0),L=a.useRef(!1),f=a.useRef(null);a.useEffect(()=>{g(!0),u(null),k(null),N(!1),R(""),x(!0),w.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),a.useEffect(()=>{s&&s.path===t.path&&(u(s),M||R(s.text),g(!1))},[s,M,t.path]),a.useEffect(()=>{const U=ae=>{if(ae.key==="Escape"){ge();return}if((ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="s"&&M){ae.preventDefault(),fe();return}const ee=ae.target,Ne=ee&&(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable);(ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="a"&&!Ne&&(ae.preventDefault(),b())};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},[r,o,M,S]),a.useEffect(()=>{const U=()=>{L.current=!1,T(!1)};return window.addEventListener("mouseup",U),()=>window.removeEventListener("mouseup",U)},[]);const E=a.useMemo(()=>{if(!o)return[];const U=o.text.split(`
|
|
19
|
+
`);return U.length>0&&U[U.length-1]===""&&U.pop(),U.slice(0,mt)},[o]),se=(o==null?void 0:o.lines)??0,$=se>mt,X=(U,ae)=>{if(ae){const ee=re.current>0?re.current:U;k({start:Math.min(ee,U),end:Math.max(ee,U)})}else re.current=U,k({start:U,end:U})},b=()=>{E.length!==0&&(re.current=1,k({start:1,end:E.length}))},V=()=>{p&&(l(t.path,t.name,p.start,p.end),y(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>y(!1),1400))},q=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,ne=()=>{R((o==null?void 0:o.text)??""),N(!1),w.current&&x(!0)},he=()=>{if(M){if(S!==((o==null?void 0:o.text)??"")&&!window.confirm(i("discardFileChanges")))return;ne();return}!q||!o||(w.current=pt(t.name)&&B,pt(t.name)&&x(!1),k(null),R(o.text),N(!0))},fe=()=>{!M||!o||!q||n({type:"write_file",path:t.path,text:S})&&(N(!1),w.current&&x(!0),k(null))},ge=()=>{M&&S!==((o==null?void 0:o.text)??"")&&!window.confirm(i("discardFileChanges"))||r()},Z=U=>{Y(Math.min(200,Math.max(50,U)))},pe=p?p.end-p.start+1:0,h=(o==null?void 0:o.binary)??!1,H=(o==null?void 0:o.truncated)??!1,z=(o==null?void 0:o.kind)??"text",Q=pt(t.name),oe=Q&&B&&!M&&z==="text"&&!h,ve=U=>rt(`/api/file?clientId=${encodeURIComponent(Ct())}&path=${encodeURIComponent(U)}`);return e.jsx("div",{className:`fp-overlay ${F?"fullscreen":""}`,onMouseDown:U=>{U.target===U.currentTarget&&ge()},children:e.jsxs("div",{className:`fp ${F?"fullscreen":""}`,style:{"--fp-zoom":A/100},children:[e.jsxs("div",{className:"fp-head",children:[e.jsx("span",{className:"fp-name",title:t.path,children:t.name}),e.jsx("span",{className:"fp-path",children:t.path}),e.jsxs("span",{className:"fp-meta",children:[o&&z==="text"&&!h&&i("fileLines",{n:se}),o&&` · ${Ja(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[Q&&z==="text"&&!h&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${B?"on":""}`,"data-tip":i(B?"showMarkdownSource":"showMarkdownPreview"),disabled:M,onClick:()=>x(U=>!U),children:B?e.jsx(ms,{}):e.jsx(fn,{})}),z==="text"&&!h&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${M?"on":""}`,"data-tip":i(H?"fileEditTruncated":M?"exitEditFile":"editFile"),disabled:!q&&!M,onClick:he,children:e.jsx(ft,{})}),z==="text"&&!h&&!oe&&e.jsx("button",{type:"button",className:`fp-attach wrap ${d?"on":""}`,"data-tip":i(d?"disableWrap":"enableWrap"),onClick:()=>I(U=>!U),children:e.jsx(gn,{})}),z==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":i("zoomOut"),disabled:A<=50,onClick:()=>Z(A-10),children:e.jsx(Ys,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:i("resetZoom"),onClick:()=>Y(100),children:[A,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":i("zoomIn"),disabled:A>=200,onClick:()=>Z(A+10),children:e.jsx(Xs,{})})]}),z!=="video"&&z!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":i("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(De,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":i("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(gt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${F?"on":""}`,"data-tip":i(F?"exitFullscreen":"fullscreen"),onClick:()=>K(U=>!U),children:F?e.jsx(rn,{}):e.jsx(ln,{})}),e.jsx("button",{type:"button",className:"fp-close",title:i("close"),onClick:ge,children:e.jsx(Se,{})})]})]}),H&&z==="text"&&!h&&e.jsx("div",{className:"fp-notice",children:i("previewTruncated")}),m&&!o&&e.jsx("div",{className:"fp-empty",children:i("loading")}),!m&&z==="none"&&!h&&e.jsx("div",{className:"fp-empty",children:i("previewNotSupported")}),!m&&z==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:ve(t.path),alt:t.name})}),!m&&z==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:ve(t.path),controls:!0,preload:"metadata"})}),!m&&oe&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(ot,{text:o.text})})}),!m&&h&&z!=="image"&&z!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[i("binaryFile"),o.truncated&&i("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!m&&M&&z==="text"&&!h&&o&&e.jsx("textarea",{className:`fp-editor ${d?"":"no-wrap"}`,value:S,onChange:U=>R(U.target.value),wrap:d?"soft":"off",spellCheck:!1,autoFocus:!0}),!m&&!oe&&!M&&z==="text"&&!h&&o&&E.length===0&&e.jsx("div",{className:"fp-empty",children:i("emptyFile")}),!m&&!oe&&!M&&z==="text"&&!h&&E.length>0&&e.jsxs("div",{className:`fp-code ${C?"dragging":""} ${d?"":"no-wrap"}`,onMouseDown:U=>{U.button===0&&U.preventDefault()},children:[E.map((U,ae)=>{const ee=ae+1,Ne=p!==null&&ee>=p.start&&ee<=p.end;return e.jsxs("div",{className:`fp-line ${Ne?"sel":""}`,onMouseDown:Me=>{Me.button===0&&(X(ee,Me.shiftKey),L.current=!0,T(!0))},onMouseEnter:()=>{L.current&&X(ee,!0)},children:[e.jsx("span",{className:"fp-num",children:ee}),e.jsx("span",{className:"fp-code-text",children:U})]},ee)}),$&&e.jsx("div",{className:"fp-lines-note",children:i("previewLinesTruncated",{n:mt})})]}),e.jsx("div",{className:"fp-foot",children:M?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:i("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:he,children:i("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:S===((o==null?void 0:o.text)??""),onClick:fe,children:[e.jsx(sn,{})," ",i("saveFile")]})]})]}):!oe&&z==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:p?i("selectedRange",{n:pe,start:p.start,end:p.end}):i("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:E.length===0,onClick:b,children:i("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!p,onClick:()=>k(null),children:i("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!p||h,onClick:V,children:[_?e.jsx(Nt,{}):null,i(_?"addedToChat":"addToChat")]})]})]})})]})})}function pt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Ja(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const Ms="pi-web-sounds",Oe={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function Es(){try{const t=localStorage.getItem(Ms);if(!t)return{...Oe};const s=JSON.parse(t),n={...Oe,...s};for(const l of["enabled","question","done","start","error"])typeof n[l]!="boolean"&&(n[l]=Oe[l]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=Oe.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...Oe}}}function Qa(t){try{localStorage.setItem(Ms,JSON.stringify(t))}catch{}}let He=null;function Ya(){try{if(!He){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;He=new t}return He.state==="suspended"&&He.resume(),He}catch{return null}}const Xa=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Za=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],ei=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],ti=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],si={question:Xa,done:Za,start:ei,error:ti};function ni(t,s,n){const l=t.createOscillator(),c=t.createGain();l.type=s.type,l.frequency.value=s.freq;const r=t.currentTime+s.start,i=Math.max(1e-4,s.peak*n);c.gain.setValueAtTime(1e-4,r),c.gain.exponentialRampToValueAtTime(i,r+.012),c.gain.exponentialRampToValueAtTime(1e-4,r+s.dur),l.connect(c),c.connect(t.destination),l.start(r),l.stop(r+s.dur+.05)}function We(t,s=Es()){if(!s.enabled||!s[t])return;const n=Ya();if(!n)return;const l=Math.max(0,Math.min(1,s.volume/100));for(const c of si[t])ni(n,c,l)}const yt="pi-web-ui:theme",Rs="dark",ss="theme-stylesheet",ns="pi-web-ui:theme-change";function Ls(){try{const t=localStorage.getItem(yt);if(t&&t!==Rs)return t}catch{}return null}function ai(t){try{t?localStorage.setItem(yt,t):localStorage.removeItem(yt)}catch{}}function Is(t){let s=document.getElementById(ss);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(ns));return}s||(s=document.createElement("link"),s.id=ss,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(ns))}async function ii(){try{const t=await fetch(rt("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function ri(){const[t,s]=a.useState([]),[n,l]=a.useState(()=>Ls());return a.useEffect(()=>{let r=!1;return ii().then(i=>{r||s(i)}),()=>{r=!0}},[]),a.useEffect(()=>{Is(n),ai(n)},[n]),{themes:t,theme:n,switchTheme:r=>l(r===Rs?null:r)}}function hi(){const t=getComputedStyle(document.documentElement),s=(n,l)=>t.getPropertyValue(n).trim()||l;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 oi=a.lazy(()=>qs(()=>import("./TerminalPanel-D9N7NOQl.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function li({notice:t,onDismiss:s}){const n=me(),[l,c]=a.useState(!1);a.useEffect(()=>{if(l)return;const i=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(i)},[l,t.id,t.level,s]);const r=t.level==="error"?jn:t.level==="warning"?yn:mn;return e.jsxs("div",{className:`notice notice-${t.level}${l?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(r,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:n("close"),onClick:()=>s(t.id),children:e.jsx(Se,{})})]})}const ci=[],Ps=180,Bs=520,Ds=240,_s=t=>`pi-web-ui:${t}-panel-width`;function as(t){const s=Number(localStorage.getItem(_s(t)));return Number.isFinite(s)&&s>=Ps&&s<=Bs?s:Ds}function is({side:t,width:s,onResize:n}){const l=me(),c=a.useCallback(r=>{r.preventDefault();const i=r.clientX,o=s;let u=o;const m=p=>{const k=t==="left"?p.clientX-i:i-p.clientX;u=Math.min(Bs,Math.max(Ps,Math.round(o+k))),n(u)},g=()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",g),document.body.classList.remove("panel-resizing"),localStorage.setItem(_s(t),String(u))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",g),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:l("dragToResize"),onPointerDown:c,onDoubleClick:()=>n(Ds)})}function di(){var xe,we,v,ie,J,ye,ue,je,Te,Mt,Et;const t=me(),{chat:s,send:n,dismissNotice:l,pushNotice:c,terminal:r}=An(),[i,o]=a.useState([]),[u,m]=a.useState(null),[g,p]=a.useState("chat"),[k,C]=a.useState(()=>as("left")),[T,_]=a.useState(()=>as("right")),y=a.useCallback(P=>C(P),[]),M=a.useCallback(P=>_(P),[]),[N,S]=a.useState(null),[R,B]=a.useState(()=>window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{const P=window.matchMedia("(max-width: 768px)"),W=de=>B(de.matches);return P.addEventListener("change",W),()=>P.removeEventListener("change",W)},[]);const[x,w]=a.useState(!1),[d,I]=a.useState(!1),[F,K]=a.useState(!1),[A,Y]=a.useState(!1),[re,L]=a.useState(!1);a.useEffect(()=>{const P=W=>{!(W.ctrlKey||W.metaKey)||W.key.toLowerCase()!=="k"||(W.preventDefault(),L(de=>!de))};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[]);const[f,E]=a.useState(Es),{themes:se,theme:$,switchTheme:X}=ri(),b=a.useRef(null),V=a.useRef(null),q=a.useRef(0),ne=a.useRef(!1),he=a.useRef(s.terminals);a.useEffect(()=>{Qa(f)},[f]),a.useEffect(()=>{var W;const P=he.current;he.current=s.terminals;for(const de of s.terminals){if(!((W=de.command)!=null&&W.command.startsWith("pi remove ")))continue;const be=P.find(Ce=>Ce.id===de.id);be!=null&&be.running&&!de.running&&n({type:"extensions_reload"})}},[s.terminals,n]),a.useEffect(()=>{var de;const P=((de=s.state)==null?void 0:de.isStreaming)??!1,W=b.current;b.current=P,W!==null&&(!W&&P?We("start",f):W&&!P&&We("done",f))},[(xe=s.state)==null?void 0:xe.isStreaming,f]),a.useEffect(()=>{var W;const P=((W=s.dialog)==null?void 0:W.id)??null;P!==null&&P!==V.current&&We("question",f),V.current=P},[s.dialog,f]),a.useEffect(()=>{const P=[...s.notices].reverse().find(W=>W.level==="error");P&&P.id!==q.current&&(q.current=P.id,We("error",f))},[s.notices,f]);const fe=(P,W,de,be=!1,Ce)=>{const lt=`${P}|${de}|${Ce?`${Ce.start}-${Ce.end}`:""}`;o(Ee=>Ee.some(Ae=>`${Ae.path}|${Ae.mode}|${Ae.lines?`${Ae.lines.start}-${Ae.lines.end}`:""}`===lt)?Ee:[...Ee,{path:P,name:W,mode:de,isDir:be,...Ce?{lines:Ce}:{}}])},ge=P=>o(W=>W.filter(de=>de.key?de.key!==P:de.path!==P)),Z=a.useCallback(P=>(!P.type.startsWith("list_")&&!P.type.startsWith("get_")&&S(null),n(P)),[n]),pe=a.useRef(0),h=a.useRef(0),H=P=>{var be;const W=Date.now();(be=s.state)!=null&&be.model&&!s.state.model.vision&&W-h.current>1e4&&(h.current=W,c("warning",t("imageNotSupported")));const de=`paste-${++pe.current}`;o(Ce=>[...Ce,{path:"",key:de,name:P.name,mode:"inline",imageData:P.data,mimeType:P.mimeType}])},z=async P=>{for(const W of P){const de=await Ia(W);if(!de){c("error",t("imageLoadFailed",{name:W.name}));continue}H(de)}},Q=20*1024*1024,oe=a.useRef(0),ve=async P=>{if(P.size>Q){c("warning",t("fileTooLarge",{name:P.name,size:Q/1024/1024}));return}let W;try{W=(await new Promise((Ce,lt)=>{const Ee=new FileReader;Ee.onload=()=>Ce(Ee.result),Ee.onerror=()=>lt(Ee.error??new Error("read failed")),Ee.readAsDataURL(P)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:P.name}));return}const de=`upload-${++oe.current}`;o(be=>[...be,{path:"",key:de,name:P.name,mode:"inline",fileData:W,size:P.size,mimeType:P.type||void 0}])},U=async P=>{for(const W of P)Je(W.type)?await z([W]):await ve(W)},ae=a.useCallback((P,W)=>{n({type:"edit_message",messageId:P,text:W})},[n]),ee=a.useCallback(()=>I(!0),[]),Ne=a.useCallback(()=>o([]),[]),Me=a.useCallback(ge,[]),Pe=a.useCallback(z,[z]),j=a.useCallback(U,[U]),D=(we=s.state)==null?void 0:we.model,te=(v=s.state)==null?void 0:v.thinkingLevel,G=(ie=s.state)==null?void 0:ie.availableThinkingLevels,ce=a.useMemo(()=>D?{model:D,thinkingLevel:te??"off",availableThinkingLevels:G??[]}:null,[D,te,G]),le=a.useCallback(()=>{var P,W;return!s.ready||s.terminals.length!==0?!1:(r.create({id:Fe(),conversationId:s.activeConversationId||((P=s.state)==null?void 0:P.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((W=s.state)==null?void 0:W.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(J=s.state)==null?void 0:J.cwd,s.terminals.length,t,r]);return a.useEffect(()=>{if(ne.current){if(g!=="terminal"||s.terminals.length!==0){ne.current=!1;return}le()&&(ne.current=!1)}},[s.terminals.length,le,g]),e.jsxs("div",{className:"app",onDragOver:P=>P.preventDefault(),onDrop:P=>P.preventDefault(),children:[e.jsx(Tn,{chat:s,send:n,terminal:r,view:g,onViewChange:P=>{ne.current=P==="terminal"&&s.terminals.length===0,ne.current&&le()&&(ne.current=!1),p(P),S(null)},onOpenPanel:S,onManageModels:()=>I(!0),onOpenSettings:()=>K(!0),onOpenBgTasks:()=>Y(!0),onOpenGlobalSearch:()=>L(!0),sound:f,onSoundChange:E,onSoundPreview:P=>We(P,f),themes:se,theme:$,onThemeChange:X}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(P=>e.jsx(li,{notice:P,onDismiss:l},P.id))}),e.jsxs("div",{className:"layout",style:{"--left-w":`${k}px`,"--right-w":`${T}px`},children:[N&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>S(null)}),e.jsxs("div",{className:`view-pane ${g==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${N==="left"?"open":""}`,children:e.jsx(Mn,{send:Z,active:!R||N==="left",ready:s.ready,status:s.status,cwd:((ye=s.state)==null?void 0:ye.cwd)??"",sessionFile:((ue=s.state)==null?void 0:ue.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!R&&e.jsx(is,{side:"left",width:k,onResize:y}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ea,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:ae,onKillBash:()=>n({type:"abort_bash"})},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(Ba,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(Fa,{dialog:s.dialog,send:n}),e.jsx(Pa,{send:n,ready:s.ready,streaming:((je=s.state)==null?void 0:je.isStreaming)??!1,messages:((Te=s.state)==null?void 0:Te.messages)??ci,slashCommands:s.slashCommands,modelState:ce,models:s.models,modelsLoading:s.modelsLoading,attachments:i,onRemoveAttachment:Me,onAddImageFiles:Pe,onAddLocalFiles:j,onNotice:c,onManageModels:ee,onSent:Ne})]}),!R&&e.jsx(is,{side:"right",width:T,onResize:M}),e.jsx("div",{className:`panel-drawer drawer-right ${N==="right"?"open":""}`,children:e.jsx(Vn,{send:Z,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((Mt=s.state)==null?void 0:Mt.cwd)??"",onAttach:(P,W,de,be)=>{S(null),fe(P,W,de,be)},onPreview:(P,W)=>{S(null),m({path:P,name:W})},onNotice:(P,W)=>c(P,W)})})]}),e.jsx("div",{className:`view-pane ${g==="terminal"?"":"hidden"}`,children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(oi,{chat:s,send:n,terminal:r})})}),e.jsx("div",{className:`view-pane ${g==="git"?"":"hidden"}`,children:e.jsx($a,{chat:s,send:n,terminal:r,active:g==="git",onSwitchToTerminal:()=>p("terminal")})})]}),e.jsx(Da,{chat:s,send:n}),u&&e.jsx(Ga,{file:u,content:s.fileContent,send:n,onAddLines:(P,W,de,be)=>fe(P,W,"lines",!1,{start:de,end:be}),onAttach:(P,W,de)=>fe(P,W,de),onClose:()=>m(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!x&&!d&&e.jsx(Oa,{send:n,piConfigured:s.state.piConfigured,providers:s.providers,installResult:s.installResult,onClose:()=>w(!0)}),d&&e.jsx(qa,{send:n,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>I(!1)}),F&&e.jsx(Ua,{chat:s,send:n,terminal:r,onSwitchToTerminal:()=>p("terminal"),onClose:()=>K(!1)}),A&&e.jsx(Ka,{servers:s.bgServers,send:n,onClose:()=>Y(!1)}),re&&e.jsx(Va,{send:n,sessions:s.sessions,projects:s.projects,cwd:((Et=s.state)==null?void 0:Et.cwd)??"",fileSearch:s.fileSearch,onClose:()=>L(!1),onSwitchSession:P=>{n({type:"switch_session",path:P})},onSwitchProject:P=>{n({type:"set_cwd",path:P})},onPreviewFile:(P,W)=>{m({path:P,name:W})}})]})}En();Is(Ls());Os.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(wn,{children:e.jsx(di,{})})}));export{jt as F,ns as T,De as a,hi as b,pi as c,Ft as d,qe as e,Se as f,on as g,ze as h,Fe as r,me as u};
|