pi-web-ui 0.59.0 → 0.60.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 +497 -468
- package/README.zh-CN.md +422 -391
- package/bin/pi-web-ui.mjs +1881 -1848
- package/deploy/com.xingshuyin.pi-web-ui.plist +48 -48
- package/deploy/nginx-subpath.conf +88 -88
- package/deploy/pi-web-ui-task.xml +54 -54
- package/deploy/pi-web-ui.service +31 -31
- package/dist/server/agent-service.js +63 -33
- package/dist/server/attachments.js +3 -3
- package/dist/server/dsh/runtime/goal-rpc.mjs +662 -662
- package/dist/server/index.js +28 -11
- package/dist/server/terminals.js +135 -138
- package/extensions/webui.ts +192 -192
- package/package.json +1 -1
- package/web/dist/assets/TerminalPanel-CSzqnWV2.js +2 -0
- package/web/dist/assets/index-D9iD9G_p.css +10 -0
- package/web/dist/assets/{index-MeifpZzi.js → index-TZDcJFdi.js} +12 -12
- 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/TerminalPanel-_VfntAyG.js +0 -2
- package/web/dist/assets/index-DRsP4BO2.css +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-
|
|
2
|
-
import{R as Ue,a,j as e,M as Hs,b as Rn,c as In}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"]'))r(c);new MutationObserver(c=>{for(const l of c)if(l.type==="childList")for(const n of l.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&r(n)}).observe(document,{childList:!0,subtree:!0});function i(c){const l={};return c.integrity&&(l.integrity=c.integrity),c.referrerPolicy&&(l.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?l.credentials="include":c.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(c){if(c.ep)return;c.ep=!0;const l=i(c);fetch(c.href,l)}})();var rt={},ls;function Ln(){if(ls)return rt;ls=1;var t=Os();return rt.createRoot=t.createRoot,rt.hydrateRoot=t.hydrateRoot,rt}var Dn=Ln();const Bn="modulepreload",_n=function(t){return"/"+t},os={},An=function(s,i,r){let c=Promise.resolve();if(i&&i.length>0){let n=function(p){return Promise.all(p.map(m=>Promise.resolve(m).then(v=>({status:"fulfilled",value:v}),v=>({status:"rejected",reason:v}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),d=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=n(i.map(p=>{if(p=_n(p),p in os)return;os[p]=!0;const m=p.endsWith(".css"),v=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${v}`))return;const h=document.createElement("link");if(h.rel=m?"stylesheet":Bn,m||(h.as="script"),h.crossOrigin="",h.href=p,d&&h.setAttribute("nonce",d),document.head.appendChild(h),m)return new Promise((x,N)=>{h.addEventListener("load",x),h.addEventListener("error",()=>N(new Error(`Unable to preload CSS for ${p}`)))})}))}function l(n){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=n,window.dispatchEvent(o),!o.defaultPrevented)throw n}return c.then(n=>{for(const o of n||[])o.status==="rejected"&&l(o.reason);return s().catch(l)})};var Ws={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},cs=Ue.createContext&&Ue.createContext(Ws),Fn=["attr","size","title"];function $n(t,s){if(t==null)return{};var i,r,c=Hn(t,s);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(r=0;r<l.length;r++)i=l[r],s.indexOf(i)===-1&&{}.propertyIsEnumerable.call(t,i)&&(c[i]=t[i])}return c}function Hn(t,s){if(t==null)return{};var i={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;i[r]=t[r]}return i}function dt(){return dt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var i=arguments[s];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},dt.apply(null,arguments)}function ds(t,s){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),i.push.apply(i,r)}return i}function ut(t){for(var s=1;s<arguments.length;s++){var i=arguments[s]!=null?arguments[s]:{};s%2?ds(Object(i),!0).forEach(function(r){On(t,r,i[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ds(Object(i)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(i,r))})}return t}function On(t,s,i){return(s=Wn(s))in t?Object.defineProperty(t,s,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[s]=i,t}function Wn(t){var s=Un(t,"string");return typeof s=="symbol"?s:s+""}function Un(t,s){if(typeof t!="object"||!t)return t;var i=t[Symbol.toPrimitive];if(i!==void 0){var r=i.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function Us(t){return t&&t.map((s,i)=>Ue.createElement(s.tag,ut({key:i},s.attr),Us(s.child)))}function ee(t){return s=>Ue.createElement(qn,dt({attr:ut({},t.attr)},s),Us(t.child))}function qn(t){var s=i=>{var r=t.attr,c=t.size,l=t.title,n=$n(t,Fn),o=c||i.size||"1em",d;return i.className&&(d=i.className),t.className&&(d=(d?d+" ":"")+t.className),Ue.createElement("svg",dt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},i.attr,r,n,{className:d,style:ut(ut({color:t.color||i.color},i.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),l&&Ue.createElement("title",null,l),t.children)};return cs!==void 0?Ue.createElement(cs.Consumer,null,i=>s(i)):s(Ws)}function Kn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"11",cy:"11",r:"8"},child:[]},{tag:"line",attr:{x1:"21",y1:"21",x2:"16.65",y2:"16.65"},child:[]},{tag:"line",attr:{x1:"8",y1:"11",x2:"14",y2:"11"},child:[]}]})(t)}function zn(t){return ee({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 ot(t){return ee({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 Ne(t){return ee({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 qs(t){return ee({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 Vn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"17 8 12 3 7 8"},child:[]},{tag:"line",attr:{x1:"12",y1:"3",x2:"12",y2:"15"},child:[]}]})(t)}function Gn(t){return ee({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 De(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"3 6 5 6 21 6"},child:[]},{tag:"path",attr:{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},child:[]},{tag:"line",attr:{x1:"10",y1:"11",x2:"10",y2:"17"},child:[]},{tag:"line",attr:{x1:"14",y1:"11",x2:"14",y2:"17"},child:[]}]})(t)}function Ge(t){return ee({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 us(t){return ee({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 Qn(t){return ee({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 pt(t){return ee({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 Yn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"4",y1:"21",x2:"4",y2:"14"},child:[]},{tag:"line",attr:{x1:"4",y1:"10",x2:"4",y2:"3"},child:[]},{tag:"line",attr:{x1:"12",y1:"21",x2:"12",y2:"12"},child:[]},{tag:"line",attr:{x1:"12",y1:"8",x2:"12",y2:"3"},child:[]},{tag:"line",attr:{x1:"20",y1:"21",x2:"20",y2:"16"},child:[]},{tag:"line",attr:{x1:"20",y1:"12",x2:"20",y2:"3"},child:[]},{tag:"line",attr:{x1:"1",y1:"14",x2:"7",y2:"14"},child:[]},{tag:"line",attr:{x1:"9",y1:"8",x2:"15",y2:"8"},child:[]},{tag:"line",attr:{x1:"17",y1:"16",x2:"23",y2:"16"},child:[]}]})(t)}function mt(t){return ee({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 Ks(t){return ee({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 ht(t){return ee({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 Jn(t){return ee({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 zs(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"1 4 1 10 7 10"},child:[]},{tag:"path",attr:{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"},child:[]}]})(t)}function nt(t){return ee({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 He(t){return ee({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 qr(t){return ee({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 Xn(t){return ee({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 ps(t){return ee({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 Zn(t){return ee({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 ei(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"},child:[]}]})(t)}function Qe(t){return ee({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 ti(t){return ee({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 si(t){return ee({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 ni(t){return ee({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 ii(t){return ee({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 Rt(t){return ee({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 gt(t){return ee({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 ai(t){return ee({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 ri(t){return ee({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 li(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},child:[]},{tag:"circle",attr:{cx:"8.5",cy:"8.5",r:"1.5"},child:[]},{tag:"polyline",attr:{points:"21 15 16 10 5 21"},child:[]}]})(t)}function oi(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"14",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"3",y:"14",width:"7",height:"7"},child:[]}]})(t)}function ci(t){return ee({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 ms(t){return ee({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 ct(t){return ee({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 Ye(t){return ee({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 Vs(t){return ee({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 Gs(t){return ee({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 It(t){return ee({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 Lt(t){return ee({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 Dt(t){return ee({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 Ot(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"7 10 12 15 17 10"},child:[]},{tag:"line",attr:{x1:"12",y1:"15",x2:"12",y2:"3"},child:[]}]})(t)}function it(t){return ee({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 di(t){return ee({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 Wt(t){return ee({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 ui(t){return ee({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 Qs(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"13 17 18 12 13 7"},child:[]},{tag:"polyline",attr:{points:"6 17 11 12 6 7"},child:[]}]})(t)}function Ys(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"11 17 6 12 11 7"},child:[]},{tag:"polyline",attr:{points:"18 17 13 12 18 7"},child:[]}]})(t)}function ft(t){return ee({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 xt(t){return ee({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 qe(t){return ee({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 vt(t){return ee({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 pi(t){return ee({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 jt(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function mi(t){return ee({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 Js(t){return ee({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 Xs(t){return ee({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 hi(t){return ee({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 gi(t){return ee({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 fi(t){return t.map(s=>s.kind==="package"?`pi update npm:${s.name}`:`npm i -g ${s.name}@latest`).join("; ")}function _e(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let i=0;i<16;i++)t[i]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function $e({trigger:t,open:s,onOpenChange:i,children:r,align:c="right",fit:l=!1,direction:n="down",menuClassName:o,menuRef:d,menuStyle:p}){const m=a.useRef(null);return a.useEffect(()=>{if(!s)return;const v=x=>{m.current&&!m.current.contains(x.target)&&i(!1)},h=x=>{x.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",h)}},[s,i]),e.jsxs("div",{className:`dropdown ${c} ${l?"fit":""} ${n==="up"?"dd-up":""}`,ref:m,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>i(!s),"aria-expanded":s,children:[t,e.jsx(qe,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:d,style:p,children:r})]})}function Ce({active:t,disabled:s=!1,title:i,onClick:r,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:i,onClick:r,children:c})}const Zs="pi-web-ui:lang",xi={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",collapsePanel:"收起面板",expandPanel:"展开面板",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",engineBadge:"引擎",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",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:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",updatesAllTitle:"全部组件更新",updatesAllBadge:"{n} 个更新",updatesAllUpToDate:"全部组件均为最新",kindWebUi:"Web 界面",kindPiCore:"核心",kindPackage:"组件",updatesAllRefresh:"重新检查全部",updateCheckFailed:"检查失败",updateBtn:"更新",updateAllBtn:"全部更新",updatePkgTabTitle:"更新 {name}",updateAllTabTitle:"更新全部组件",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",uploadToFolder:"上传文件到此文件夹",uploadToCurrentDir:"上传文件到当前目录",protocolMismatch:"页面版本与服务器不一致(应用刚更新过),请刷新页面以恢复全部功能。",selectLinesHint:"点击选择行;拖拽或 Shift+点击选择范围",enableWrap:"开启自动换行",disableWrap:"关闭自动换行",selectedRange:"已选 {n} 行(第 {start}-{end} 行)",fileLines:"{n} 行",selectAll:"全选",clearSelection:"清除",addToChat:"添加到对话",addedToChat:"已添加",previewTruncated:"⚠ 文件过大,仅预览前 512KB",previewLinesTruncated:"… 文件行数过多,仅显示前 {n} 行",binaryFile:"🔣 二进制文件,已显示前 4KB 十六进制",binaryHexTruncated:"(文件更大,可下载完整文件)",previewNotSupported:"该类型文件不支持预览(仅图片 / 视频 / 文本)",emptyFile:"(空文件)",editFile:"编辑文件",exitEditFile:"退出编辑",saveFile:"保存文件",discardFileChanges:"放弃未保存的修改?",fileSaved:"已保存",fileEditTruncated:"文件过大,预览不完整,无法编辑",showMarkdownSource:"显示 Markdown 原文",showMarkdownPreview:"显示 Markdown 预览",fullscreen:"全屏",exitFullscreen:"退出全屏",zoomIn:"放大字号",zoomOut:"缩小字号",resetZoom:"重置缩放",pluginRequest:"插件请求",modelQuestion:"模型提问",modelQuestionCustom:"补充回答(可选)",modelQuestionSubmit:"提交回答",noOptions:"(无选项)",inputPlaceholder:"输入内容",questionTimeout:"⏳ 剩余 {s} 秒,超时将自动取消",questionTimeoutExpired:"提问已超时,正在恢复对话…",modelNoVision:"当前模型 {name} 不支持图片,请切换到 DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH 引擎使用运行时内置技能(dsh-skill),暂不支持在设置面板启停",dshExtensionsNote:"DSH 引擎无 pi 扩展体系,能力由运行时内置(MCP/subagent/goal/plan/skill 等)",dshReviewPromptNote:"DSH 无独立审查会话:此指令将随目标轮次附加到系统提示词,供模型在目标轮次中遵守",dshVisionHiddenNote:"DSH 引擎直接支持图片输入(仅 DeepSeek V4 Flash Vision (exp) 模型),无需视觉桥转写",dshNoReviewModel:"DSH 无独立审查模型:目标由模型自判定完成/受阻,轮次上限即自动迭代次数",soundHeader:"声音提示",enableSound:"启用声音",preview:"试听",volume:"音量","sound.question":"问卷弹出","sound.question.desc":"ask_user_question 出现时","sound.done":"回复结束","sound.done.desc":"智能体完成一轮回答时","sound.start":"回复开始","sound.start.desc":"智能体开始新一轮时","sound.error":"出错","sound.error.desc":"出现错误提示时",setupTitle:"未检测到 pi agent 配置",setupDesc:"pi-web-ui 需要 pi 的配置目录(~/.pi/agent)和至少一个 API 密钥才能运行智能体。pi 内置了 openai、anthropic、deepseek 等服务商——选一个填密钥即可,全程无需打开终端。",installFailed:"✖ pi agent 安装失败:",retryInstall:"重试安装",skip:"跳过",installDone:"✅ pi agent CLI 已安装。选择服务商并填入 API 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:搜索历史对话全文(含 AI 回复)、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-CSzqnWV2.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 Ue,a,j as e,M as Hs,b as Rn,c as In}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"]'))r(c);new MutationObserver(c=>{for(const l of c)if(l.type==="childList")for(const n of l.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&r(n)}).observe(document,{childList:!0,subtree:!0});function i(c){const l={};return c.integrity&&(l.integrity=c.integrity),c.referrerPolicy&&(l.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?l.credentials="include":c.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(c){if(c.ep)return;c.ep=!0;const l=i(c);fetch(c.href,l)}})();var rt={},ls;function Ln(){if(ls)return rt;ls=1;var t=Os();return rt.createRoot=t.createRoot,rt.hydrateRoot=t.hydrateRoot,rt}var Dn=Ln();const Bn="modulepreload",Fn=function(t){return"/"+t},os={},_n=function(s,i,r){let c=Promise.resolve();if(i&&i.length>0){let n=function(p){return Promise.all(p.map(m=>Promise.resolve(m).then(v=>({status:"fulfilled",value:v}),v=>({status:"rejected",reason:v}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),d=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=n(i.map(p=>{if(p=Fn(p),p in os)return;os[p]=!0;const m=p.endsWith(".css"),v=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${v}`))return;const h=document.createElement("link");if(h.rel=m?"stylesheet":Bn,m||(h.as="script"),h.crossOrigin="",h.href=p,d&&h.setAttribute("nonce",d),document.head.appendChild(h),m)return new Promise((x,N)=>{h.addEventListener("load",x),h.addEventListener("error",()=>N(new Error(`Unable to preload CSS for ${p}`)))})}))}function l(n){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=n,window.dispatchEvent(o),!o.defaultPrevented)throw n}return c.then(n=>{for(const o of n||[])o.status==="rejected"&&l(o.reason);return s().catch(l)})};var Ws={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},cs=Ue.createContext&&Ue.createContext(Ws),An=["attr","size","title"];function $n(t,s){if(t==null)return{};var i,r,c=Hn(t,s);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(r=0;r<l.length;r++)i=l[r],s.indexOf(i)===-1&&{}.propertyIsEnumerable.call(t,i)&&(c[i]=t[i])}return c}function Hn(t,s){if(t==null)return{};var i={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;i[r]=t[r]}return i}function dt(){return dt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var i=arguments[s];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},dt.apply(null,arguments)}function ds(t,s){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),i.push.apply(i,r)}return i}function ut(t){for(var s=1;s<arguments.length;s++){var i=arguments[s]!=null?arguments[s]:{};s%2?ds(Object(i),!0).forEach(function(r){On(t,r,i[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ds(Object(i)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(i,r))})}return t}function On(t,s,i){return(s=Wn(s))in t?Object.defineProperty(t,s,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[s]=i,t}function Wn(t){var s=Un(t,"string");return typeof s=="symbol"?s:s+""}function Un(t,s){if(typeof t!="object"||!t)return t;var i=t[Symbol.toPrimitive];if(i!==void 0){var r=i.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function Us(t){return t&&t.map((s,i)=>Ue.createElement(s.tag,ut({key:i},s.attr),Us(s.child)))}function ee(t){return s=>Ue.createElement(qn,dt({attr:ut({},t.attr)},s),Us(t.child))}function qn(t){var s=i=>{var r=t.attr,c=t.size,l=t.title,n=$n(t,An),o=c||i.size||"1em",d;return i.className&&(d=i.className),t.className&&(d=(d?d+" ":"")+t.className),Ue.createElement("svg",dt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},i.attr,r,n,{className:d,style:ut(ut({color:t.color||i.color},i.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),l&&Ue.createElement("title",null,l),t.children)};return cs!==void 0?Ue.createElement(cs.Consumer,null,i=>s(i)):s(Ws)}function Kn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"circle",attr:{cx:"11",cy:"11",r:"8"},child:[]},{tag:"line",attr:{x1:"21",y1:"21",x2:"16.65",y2:"16.65"},child:[]},{tag:"line",attr:{x1:"8",y1:"11",x2:"14",y2:"11"},child:[]}]})(t)}function zn(t){return ee({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 ot(t){return ee({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 Ne(t){return ee({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 qs(t){return ee({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 Vn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"17 8 12 3 7 8"},child:[]},{tag:"line",attr:{x1:"12",y1:"3",x2:"12",y2:"15"},child:[]}]})(t)}function Gn(t){return ee({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 De(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"3 6 5 6 21 6"},child:[]},{tag:"path",attr:{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},child:[]},{tag:"line",attr:{x1:"10",y1:"11",x2:"10",y2:"17"},child:[]},{tag:"line",attr:{x1:"14",y1:"11",x2:"14",y2:"17"},child:[]}]})(t)}function Ge(t){return ee({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 us(t){return ee({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 Qn(t){return ee({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 pt(t){return ee({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 Yn(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"4",y1:"21",x2:"4",y2:"14"},child:[]},{tag:"line",attr:{x1:"4",y1:"10",x2:"4",y2:"3"},child:[]},{tag:"line",attr:{x1:"12",y1:"21",x2:"12",y2:"12"},child:[]},{tag:"line",attr:{x1:"12",y1:"8",x2:"12",y2:"3"},child:[]},{tag:"line",attr:{x1:"20",y1:"21",x2:"20",y2:"16"},child:[]},{tag:"line",attr:{x1:"20",y1:"12",x2:"20",y2:"3"},child:[]},{tag:"line",attr:{x1:"1",y1:"14",x2:"7",y2:"14"},child:[]},{tag:"line",attr:{x1:"9",y1:"8",x2:"15",y2:"8"},child:[]},{tag:"line",attr:{x1:"17",y1:"16",x2:"23",y2:"16"},child:[]}]})(t)}function mt(t){return ee({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 Ks(t){return ee({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 ht(t){return ee({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 Jn(t){return ee({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 zs(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"1 4 1 10 7 10"},child:[]},{tag:"path",attr:{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"},child:[]}]})(t)}function nt(t){return ee({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 He(t){return ee({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 qr(t){return ee({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 Xn(t){return ee({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 ps(t){return ee({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 Zn(t){return ee({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 ei(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"},child:[]}]})(t)}function Qe(t){return ee({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 ti(t){return ee({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 si(t){return ee({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 ni(t){return ee({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 ii(t){return ee({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 Rt(t){return ee({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 gt(t){return ee({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 ai(t){return ee({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 ri(t){return ee({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 li(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},child:[]},{tag:"circle",attr:{cx:"8.5",cy:"8.5",r:"1.5"},child:[]},{tag:"polyline",attr:{points:"21 15 16 10 5 21"},child:[]}]})(t)}function oi(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"14",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"3",y:"14",width:"7",height:"7"},child:[]}]})(t)}function ci(t){return ee({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 ms(t){return ee({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 ct(t){return ee({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 Ye(t){return ee({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 Vs(t){return ee({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 Gs(t){return ee({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 It(t){return ee({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 Lt(t){return ee({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 Dt(t){return ee({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 Ot(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"7 10 12 15 17 10"},child:[]},{tag:"line",attr:{x1:"12",y1:"15",x2:"12",y2:"3"},child:[]}]})(t)}function it(t){return ee({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 di(t){return ee({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 Wt(t){return ee({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 ui(t){return ee({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 Qs(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"13 17 18 12 13 7"},child:[]},{tag:"polyline",attr:{points:"6 17 11 12 6 7"},child:[]}]})(t)}function Ys(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"11 17 6 12 11 7"},child:[]},{tag:"polyline",attr:{points:"18 17 13 12 18 7"},child:[]}]})(t)}function ft(t){return ee({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 xt(t){return ee({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 qe(t){return ee({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 vt(t){return ee({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 pi(t){return ee({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 jt(t){return ee({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function mi(t){return ee({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 Js(t){return ee({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 Xs(t){return ee({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 hi(t){return ee({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 gi(t){return ee({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 fi(t){return t.map(s=>s.kind==="package"?`pi update npm:${s.name}`:`npm i -g ${s.name}@latest`).join("; ")}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 i=0;i<16;i++)t[i]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function $e({trigger:t,open:s,onOpenChange:i,children:r,align:c="right",fit:l=!1,direction:n="down",menuClassName:o,menuRef:d,menuStyle:p}){const m=a.useRef(null);return a.useEffect(()=>{if(!s)return;const v=x=>{m.current&&!m.current.contains(x.target)&&i(!1)},h=x=>{x.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",h)}},[s,i]),e.jsxs("div",{className:`dropdown ${c} ${l?"fit":""} ${n==="up"?"dd-up":""}`,ref:m,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>i(!s),"aria-expanded":s,children:[t,e.jsx(qe,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:d,style:p,children:r})]})}function Ce({active:t,disabled:s=!1,title:i,onClick:r,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:i,onClick:r,children:c})}const Zs="pi-web-ui:lang",xi={cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",collapsePanel:"收起面板",expandPanel:"展开面板",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",engineBadge:"引擎",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",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:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",updatesAllTitle:"全部组件更新",updatesAllBadge:"{n} 个更新",updatesAllUpToDate:"全部组件均为最新",kindWebUi:"Web 界面",kindPiCore:"核心",kindPackage:"组件",updatesAllRefresh:"重新检查全部",updateCheckFailed:"检查失败",updateBtn:"更新",updateAllBtn:"全部更新",updatePkgTabTitle:"更新 {name}",updateAllTabTitle:"更新全部组件",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",uploadToFolder:"上传文件到此文件夹",uploadToCurrentDir:"上传文件到当前目录",protocolMismatch:"页面版本与服务器不一致(应用刚更新过),请刷新页面以恢复全部功能。",selectLinesHint:"点击选择行;拖拽或 Shift+点击选择范围",enableWrap:"开启自动换行",disableWrap:"关闭自动换行",selectedRange:"已选 {n} 行(第 {start}-{end} 行)",fileLines:"{n} 行",selectAll:"全选",clearSelection:"清除",addToChat:"添加到对话",addedToChat:"已添加",previewTruncated:"⚠ 文件过大,仅预览前 512KB",previewLinesTruncated:"… 文件行数过多,仅显示前 {n} 行",binaryFile:"🔣 二进制文件,已显示前 4KB 十六进制",binaryHexTruncated:"(文件更大,可下载完整文件)",previewNotSupported:"该类型文件不支持预览(仅图片 / 视频 / 文本)",emptyFile:"(空文件)",editFile:"编辑文件",exitEditFile:"退出编辑",saveFile:"保存文件",discardFileChanges:"放弃未保存的修改?",fileSaved:"已保存",fileEditTruncated:"文件过大,预览不完整,无法编辑",showMarkdownSource:"显示 Markdown 原文",showMarkdownPreview:"显示 Markdown 预览",fullscreen:"全屏",exitFullscreen:"退出全屏",zoomIn:"放大字号",zoomOut:"缩小字号",resetZoom:"重置缩放",pluginRequest:"插件请求",modelQuestion:"模型提问",modelQuestionCustom:"补充回答(可选)",modelQuestionSubmit:"提交回答",noOptions:"(无选项)",inputPlaceholder:"输入内容",questionTimeout:"⏳ 剩余 {s} 秒,超时将自动取消",questionTimeoutExpired:"提问已超时,正在恢复对话…",modelNoVision:"当前模型 {name} 不支持图片,请切换到 DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH 引擎使用运行时内置技能(dsh-skill),暂不支持在设置面板启停",dshExtensionsNote:"DSH 引擎无 pi 扩展体系,能力由运行时内置(MCP/subagent/goal/plan/skill 等)",dshReviewPromptNote:"DSH 无独立审查会话:此指令将随目标轮次附加到系统提示词,供模型在目标轮次中遵守",dshVisionHiddenNote:"DSH 引擎直接支持图片输入(仅 DeepSeek V4 Flash Vision (exp) 模型),无需视觉桥转写",dshNoReviewModel:"DSH 无独立审查模型:目标由模型自判定完成/受阻,轮次上限即自动迭代次数",soundHeader:"声音提示",enableSound:"启用声音",preview:"试听",volume:"音量","sound.question":"问卷弹出","sound.question.desc":"ask_user_question 出现时","sound.done":"回复结束","sound.done.desc":"智能体完成一轮回答时","sound.start":"回复开始","sound.start.desc":"智能体开始新一轮时","sound.error":"出错","sound.error.desc":"出现错误提示时",setupTitle:"未检测到 pi agent 配置",setupDesc:"pi-web-ui 需要 pi 的配置目录(~/.pi/agent)和至少一个 API 密钥才能运行智能体。pi 内置了 openai、anthropic、deepseek 等服务商——选一个填密钥即可,全程无需打开终端。",installFailed:"✖ pi agent 安装失败:",retryInstall:"重试安装",skip:"跳过",installDone:"✅ pi agent CLI 已安装。选择服务商并填入 API 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:搜索历史对话全文(含 AI 回复)、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
|
|
3
3
|
|
|
4
4
|
1. 项目类型、技术栈与目录结构
|
|
5
5
|
2. 构建 / 测试 / 运行 / 格式化的具体命令
|
|
@@ -149,7 +149,7 @@ import{R as Ue,a,j as e,M as Hs,b as Rn,c as In}from"./markdown-DRBrS2Nf.js";imp
|
|
|
149
149
|
2. 用最小实现让测试通过
|
|
150
150
|
3. 重构并保持测试通过
|
|
151
151
|
|
|
152
|
-
避免三种反模式:与实现耦合的测试、空洞断言(永远为真)、横向切片(只测表面)。每步汇报并运行测试。`,error:"出错",done:"完成",running:"执行中…",toolQueued:"排队中",copyArgs:"复制参数",errorOutput:"错误输出",output:"输出",waitingOutput:"等待输出…",toolDoneWaitingModel:"已结束 · 等模型",waitingModel:"等待模型响应…",thinkingNow:"思考中",thinkingPreview:"思考:{preview}",commands:"命令",newCommand:"新建命令",newTerminal:"新建终端",name:"名称",command:"命令",cwdHint:"(${pwd} = 当前工作目录)",noCommands:"还没有命令,点 + 添加一个",clickToRun:"点击运行",edit:"编辑",delete:"删除",confirmQ:"确认?",builtinTerminal:"内置终端",termEmptySub:"点击左侧命令运行,或点右侧 + 新建终端",noTerminal:"暂无终端",exited:"(已退出{code})",closeTerminal:"关闭终端",rerun:"重新读取 .pi/commands.json",terminalTitle:"终端 {n}",exampleName:"例如:启动开发服务器",exampleCommand:"例如:npm run dev",scmTab:"Git",scmTitle:"源代码管理",scmRefreshTip:"重新查询 Git 状态与差异",scmCurrentBranch:"当前分支",scmUpstreamGone:"上游已删除",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"分离 HEAD",scmSelectBranch:"选择分支…",scmRemoteBranches:"远程分支",scmStageTip:"暂存 {path}",scmUnstageTip:"取消暂存 {path}",scmSwitch:"切换",scmSwitchBranch:"切换分支",scmSwitchBranchTip:"在终端中执行 git checkout {branch}",scmPush:"推送",scmPushTip:"在终端中执行 git push",scmPull:"拉取",scmPullTip:"在终端中执行 git pull",scmCommit:"提交",scmCommitTip:'在终端中执行 git add -A && git commit -m "…"(提交全部更改,含未跟踪)',scmCommitPlaceholder:"输入提交信息…",scmChanges:"更改",scmHistory:"提交树",scmCommitDetail:"提交详情",scmSelectCommitHint:"点击左侧提交查看详情",scmNoHistory:"暂无提交记录",scmNoChanges:"工作区干净,没有更改",scmNotGitRepo:"当前目录不是 Git 仓库",scmLoading:"查询中…",scmConnecting:"等待连接…",scmDiff:"差异",scmSelectFileHint:"点击左侧文件查看差异",scmNoDiff:"(无差异)",scmStaged:"已暂存",scmUnstaged:"未暂存",scmStagedUnstaged:"已暂存 + 未暂存",scmUntracked:"未跟踪",scmUntrackedNote:"未跟踪文件:差异不显示,提交时会一并包含",scmQueryFailed:"Git 查询失败:{error}",scmTooManyFailures:"Git 查询连续失败,请点击刷新重试",scmRunsInTerminal:"提交 / 切换分支 / 推送 / 拉取在终端中执行",scmViewTerminal:"去终端",editProvider:"编辑服务商",builtinProviders:"内置服务商",hintKeyOnly:"只需填入 API 密钥",configuredBadge:"✓ 已配置",keyReady:"密钥已就绪",replaceKey:"更换密钥",replaceKeyTitle:"替换已保存的密钥",clearKey:"清空",clearKeyTitle:"清除该服务商保存在 auth.json 的密钥,回到未配置状态(环境变量来源的无法在此清除)",clearKeyConfirm:"清空 {id} 已保存的密钥?其模型将从列表消失,直到重新配置。",cloneProvider:"复制为自定义",cloning:"复制中",cloneProviderTitle:"复制该内置供应商(baseUrl + 模型列表)为自定义供应商,填入另一个 API 密钥即可双 key 并存",pasteKey:"粘贴 API 密钥…",savingKey:"保存中",saveKey:"保存密钥",customProviders:"自定义服务商",customDesc:"用于 Ollama / vLLM / 兼容 OpenAI 的代理等,写入 pi 的 models.json,保存后热重载、立即生效。",noCustomProviders:"还没有自定义服务商",modelsCount:"{n} 个模型",addProvider:"新增服务商",providerId:"服务商 ID",providerIdHint:"(必填,如 ollama / my-proxy)",displayName:"显示名",displayNamePh:"我的代理",apiType:"API 类型",baseUrlHint:"(OpenAI 兼容端点)",apiKeyHint:"sk-…(可留空,用 auth.json 的密钥)",authHeader:"自动添加 Authorization 请求头",modelsTitle:"模型",modelIdReq:"模型 ID(必填)",text:"文本",textImage:"文本+图片",contextWindow:"上下文",maxOutput:"最大输出",removeModel:"移除模型",addModel:"添加模型",deleteProviderConfirm:"删除服务商 {id} 及其 {n} 个模型?",fetchModels:"自动获取模型列表",fetchModelsHint:"从 baseUrl 的 /models 接口自动拉取模型 ID(服务端请求,不受 CORS 限制)",fetchingModels:"获取中…",fetchModelsOk:"已获取 {n} 个模型",fetchModelsEmpty:"接口未返回任何模型",fetchModelsErr:"获取失败:{msg}",fetchModelsNeedBaseUrl:"请先填写 baseUrl 再获取",goalBarTitle:"目标",goalBarPlaceholder:"设定一个目标,agent 完成后自动审查…",goalBarSet:"开始",goalBarClear:"取消",goalBarLocked:"锁定:应用到后续所有回合",goalBarUnlocked:"仅本回合(改完自动清除)",goalBarReviewModel:"审查模型",goalBarUseMainModel:"使用主模型",goalBarMaxRounds:"最大轮数",goalBarMaxRoundsTip:"最大审查重改轮数;0 或不填 = 不限(持续改到通过)",goalBarUnlimitedShort:"不限",goalBarReviewing:"审查中…",goalBarRound:"第 {n} 轮",goalBarActive:"目标生效中",goalBarPassed:"已通过",goalBarFailed:"未通过",goalBarStatusPending:"等待生成…",goalWizardBtn:"AI 提炼",goalWizardTip:"让 AI 通过问卷调研细化需求,收敛为目标",goalWizardRunning:"目标调研中",goalWizardAnswer:"回答",goalWizardCard:"目标调研",settings:"设置",settingsTitle:"设置",settingsDesc:"修改立即生效:系统提示词、技能与插件开关会重建当前会话;审查提示词与审查技能只影响后续目标审查(回复进行中则主会话变更自动延迟)。",settingsSystemPrompt:"系统提示词",settingsPromptMode:"模式",promptModeAppend:"追加",promptModeReplace:"替换",promptAppendHint:"追加模式:自定义内容拼接到默认系统提示词末尾(推荐,保留默认行为约束)。",promptReplaceHint:"替换模式:完全用自定义内容替换系统提示词(项目上下文与技能段仍会自动附加)。切换后输入框会显示原本的默认提示词,可直接修改;不改动失焦则仍使用默认。",promptPlaceholder:"输入自定义系统提示词…(失焦后自动应用)",settingsViewPrompt:"查看当前完整提示词",settingsViewPromptHint:"当前会话实际生效的完整系统提示词(含自定义追加/替换内容、项目上下文、技能说明与工具引导),只读。",settingsViewPromptEmpty:"会话尚未就绪,暂无系统提示词。",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",settingsTerminalTools:"终端工具",terminalToolsEnabled:"启用持久终端工具",settingsTerminalToolsDesc:"让 AI 在交互式程序(REPL/vim)、长驻服务、需要持续观察输出或你要求在可见终端操作时,使用内置终端;普通命令仍走一次性 bash 工具",terminalToolsOffHint:"已关闭:AI 无法使用 terminal_* 工具,也不会收到相关使用引导",settingsMessageDisplay:"消息显示",thinkingWrap:"完整显示思考",thinkingWrapDesc:"开启:思考内容始终完整展开并自动换行(流式推理过程也实时可见);关闭:折叠成一行摘要,流式中一行实时显示最新文本",toolsWrap:"完整显示工具",toolsWrapDesc:"开启:工具调用始终完整展开显示参数和输出;关闭:默认折叠,点击展开",terminalBashTakeover:"终端接管 bash",terminalBashTakeoverDesc:"bash 命令改在持久可见终端里执行:完整输出自动返回、shell 状态跨调用保留(cd/venv/ssh);命令静默超时自动转后台并在结束后主动通知 AI",terminalBashIdleMs:"静默转后台阈值(毫秒)",terminalBashIdleMsDesc:"命令连续无输出达到该时长即不再阻塞等待,转入后台继续运行并通知 AI;0 = 一直等到命令结束(默认 15000)",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",uninstallExt:"卸载",uninstallConfirm:"确认卸载?",uninstallConfirmHint:"再次点击确认,将在终端执行 pi remove",uninstallHint:"通过可见终端执行 pi remove 卸载此包,完成后自动刷新列表",uninstallTitle:"卸载",pluginUpdate:"更新",pluginUpdateHint:"从安装来源重新拉取并覆盖安装(保留 config.json 配置),完成后自动重载插件列表",pluginUninstallHint:"在可见终端执行 pi-web-ui uninstall 卸载此插件(再次点击确认),完成后自动刷新列表",settingsExtensions:"插件",settingsUiPlugins:"界面插件",noUiPlugins:"未安装界面组件(<dataDir>/plugins/)",dshPatches:"DSH 用户补丁",dshPatchesDesc:"启动时按文件名序加载的 Cordis patch(<dataDir>/dsh-patches/*.yml)。新增/修改后点「重扫」重启运行时生效;失败的文件会被跳过并打印到运行时 stderr。",dshPatchesRescan:"重扫",dshPatchesRescanHint:"重新扫描补丁目录并重启 DSH 运行时使新补丁生效",dshPatchesEmpty:"未放置补丁文件",dshPatchesPath:"补丁目录:",uiPluginNoSource:"手工安装,无来源信息,无法在线更新",uiPluginPerms:"能力声明",pluginSettingsSave:"保存插件设置",pluginSettingsSaving:"保存中…",pluginSettingsReset:"恢复默认",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},vi={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",widgetExpand:"Click to view full output",collapsePanel:"Collapse panel",expandPanel:"Expand panel",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",allProviders:"All",providers:"Providers",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",engineBadge:"Engine",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",slashPlugin:"Plugin",slashCopied:"Copied the last assistant reply",slashCopyFailed:"Copy failed — please copy manually",slashCopyEmpty:"No assistant reply to copy yet",recentProjects:"Recent projects",runningConversations:"Running chats",historySessions:"History",openHistory:"History",openFiles:"Files",streaming:"Streaming…",noHistory:"No previous chats",current:"Current",messageCount:"{n} messages",tuiTip:"Chat in the pi terminal (TUI)",deleteProject:"Remove from recent projects",deleteProjectConfirm:"Confirm remove",deleteSession:"Delete this chat transcript permanently",deleteSessionConfirm:"Confirm delete",emptyChat:"Empty chat",editReask:"Edit & re-ask",editReaskTip:"Edit this question and re-ask from here (forks a new conversation; the original is kept)",reaskFromHere:"Re-ask from here",editPlaceholder:"Edit the question…",editHint:"⌘/Ctrl+Enter to submit · Esc to cancel",editAttachmentHint:"Original attachments kept — paste/drop images or files · ⌘/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).",updatesAllTitle:"Component updates",updatesAllBadge:"{n} updates",updatesAllUpToDate:"All components up to date",kindWebUi:"Web UI",kindPiCore:"Core",kindPackage:"Package",updatesAllRefresh:"Re-check all",updateCheckFailed:"Check failed",updateBtn:"Update",updateAllBtn:"Update all",updatePkgTabTitle:"Update {name}",updateAllTabTitle:"Update all components",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}",uploadToFolder:"Upload files to this folder",uploadToCurrentDir:"Upload files to current directory",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",modelQuestion:"Model question",modelQuestionCustom:"Custom answer (optional)",modelQuestionSubmit:"Submit answer",questionTimeout:"⏳ {s}s left — auto-cancels on timeout",questionTimeoutExpired:"Question timed out, resuming conversation…",modelNoVision:"Current model {name} doesn't support images — switch to DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH uses runtime-built-in skills (dsh-skill); toggling is not supported in settings yet",dshExtensionsNote:"DSH has no pi extension system; capabilities are runtime-built-in (MCP/subagent/goal/plan/skill…)",dshReviewPromptNote:"DSH has no separate reviewer: this text is appended to the system prompt for goal rounds",dshVisionHiddenNote:"DSH supports real image input (DeepSeek V4 Flash Vision (exp) only) — no vision bridge needed",dshNoReviewModel:"DSH has no separate reviewer model — the model self-certifies goal completion; max rounds = auto-iteration count",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:",cliReadyHint:"✅ pi agent CLI already installed locally. 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",directory:"Directory",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",modelUsedCount:"used {n}×",searchGlobal:"Search",searchGlobalTip:"Global search: sessions / projects / files (Ctrl+K)",gsPlaceholder:"Search projects, past conversations, workspace files…",gsHint:"Type to search full conversation text (AI replies included), recent projects and file names in the current workspace at once",gsSessions:"Conversations",gsProjects:"Projects",gsFiles:"Files",gsNoResults:"No matches",gsSearching:"Searching…",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","tpl.title":"Prompt templates","tpl.hint":"Click a card to fill the input; ✏️ to edit or delete; add your own too","tpl.clickCard":"Click to fill the input","tpl.editTpl":"Edit / delete template","tpl.openPicker":"Prompt templates (reusable prompts, anytime)","tpl.pickerTitle":"Prompt templates","tpl.pickerHint":"Click a card to fill the input; ✏️ to edit or delete; add your own too","tpl.add":"New template","tpl.addDesc":"Save a workflow you use often","tpl.reset":"Restore defaults","tpl.resetConfirm":"Restore defaults?","tpl.builtin":"Built-in","tpl.custom":"Custom","tpl.newTitle":"New prompt template","tpl.editTitle":"Edit prompt template","tpl.fieldIcon":"Icon","tpl.fieldTitle":"Title","tpl.fieldTitlePh":"Short title shown on the card","tpl.fieldDesc":"Description","tpl.fieldDescPh":"One-liner shown on the card","tpl.fieldPrompt":"Prompt","tpl.fieldPromptPh":"The full prompt sent to the agent","tpl.required":"Title and prompt are required","tpl.save":"Save","tpl.fill":"Fill input","tpl.fillTip":"Fill the input so you can tweak it before sending","tpl.sendNow":"Send now","tpl.sendTip":"Send immediately as a new conversation","tpl.delete":"Delete","tpl.deleteTip":"Delete this custom template","tpl.remove":"Remove from library","tpl.removeTip":"Remove this built-in template; restore later via “Restore defaults”","tpl.restore":"Restore default","tpl.restoreTip":"Discard your edits and restore the built-in default","tpl.sk.setup":"Repo setup","tpl.sk.setup.desc":"Give the repo a baseline that other workflows can use","tpl.sk.setup.prompt":`Scan this repository and build the baseline context other workflows rely on, then report concisely:
|
|
152
|
+
避免三种反模式:与实现耦合的测试、空洞断言(永远为真)、横向切片(只测表面)。每步汇报并运行测试。`,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}",aiBashGroup:"终端接管 bash",exampleName:"例如:启动开发服务器",exampleCommand:"例如:npm run dev",scmTab:"Git",scmTitle:"源代码管理",scmRefreshTip:"重新查询 Git 状态与差异",scmCurrentBranch:"当前分支",scmUpstreamGone:"上游已删除",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"分离 HEAD",scmSelectBranch:"选择分支…",scmRemoteBranches:"远程分支",scmStageTip:"暂存 {path}",scmUnstageTip:"取消暂存 {path}",scmSwitch:"切换",scmSwitchBranch:"切换分支",scmSwitchBranchTip:"在终端中执行 git checkout {branch}",scmPush:"推送",scmPushTip:"在终端中执行 git push",scmPull:"拉取",scmPullTip:"在终端中执行 git pull",scmCommit:"提交",scmCommitTip:'在终端中执行 git add -A && git commit -m "…"(提交全部更改,含未跟踪)',scmCommitPlaceholder:"输入提交信息…",scmChanges:"更改",scmHistory:"提交树",scmCommitDetail:"提交详情",scmSelectCommitHint:"点击左侧提交查看详情",scmNoHistory:"暂无提交记录",scmNoChanges:"工作区干净,没有更改",scmNotGitRepo:"当前目录不是 Git 仓库",scmLoading:"查询中…",scmConnecting:"等待连接…",scmDiff:"差异",scmSelectFileHint:"点击左侧文件查看差异",scmNoDiff:"(无差异)",scmStaged:"已暂存",scmUnstaged:"未暂存",scmStagedUnstaged:"已暂存 + 未暂存",scmUntracked:"未跟踪",scmUntrackedNote:"未跟踪文件:差异不显示,提交时会一并包含",scmQueryFailed:"Git 查询失败:{error}",scmTooManyFailures:"Git 查询连续失败,请点击刷新重试",scmRunsInTerminal:"提交 / 切换分支 / 推送 / 拉取在终端中执行",scmViewTerminal:"去终端",editProvider:"编辑服务商",builtinProviders:"内置服务商",hintKeyOnly:"只需填入 API 密钥",configuredBadge:"✓ 已配置",keyReady:"密钥已就绪",replaceKey:"更换密钥",replaceKeyTitle:"替换已保存的密钥",clearKey:"清空",clearKeyTitle:"清除该服务商保存在 auth.json 的密钥,回到未配置状态(环境变量来源的无法在此清除)",clearKeyConfirm:"清空 {id} 已保存的密钥?其模型将从列表消失,直到重新配置。",cloneProvider:"复制为自定义",cloning:"复制中",cloneProviderTitle:"复制该内置供应商(baseUrl + 模型列表)为自定义供应商,填入另一个 API 密钥即可双 key 并存",pasteKey:"粘贴 API 密钥…",savingKey:"保存中",saveKey:"保存密钥",customProviders:"自定义服务商",customDesc:"用于 Ollama / vLLM / 兼容 OpenAI 的代理等,写入 pi 的 models.json,保存后热重载、立即生效。",noCustomProviders:"还没有自定义服务商",modelsCount:"{n} 个模型",addProvider:"新增服务商",providerId:"服务商 ID",providerIdHint:"(必填,如 ollama / my-proxy)",displayName:"显示名",displayNamePh:"我的代理",apiType:"API 类型",baseUrlHint:"(OpenAI 兼容端点)",apiKeyHint:"sk-…(可留空,用 auth.json 的密钥)",authHeader:"自动添加 Authorization 请求头",modelsTitle:"模型",modelIdReq:"模型 ID(必填)",text:"文本",textImage:"文本+图片",contextWindow:"上下文",maxOutput:"最大输出",removeModel:"移除模型",addModel:"添加模型",deleteProviderConfirm:"删除服务商 {id} 及其 {n} 个模型?",fetchModels:"自动获取模型列表",fetchModelsHint:"从 baseUrl 的 /models 接口自动拉取模型 ID(服务端请求,不受 CORS 限制)",fetchingModels:"获取中…",fetchModelsOk:"已获取 {n} 个模型",fetchModelsEmpty:"接口未返回任何模型",fetchModelsErr:"获取失败:{msg}",fetchModelsNeedBaseUrl:"请先填写 baseUrl 再获取",goalBarTitle:"目标",goalBarPlaceholder:"设定一个目标,agent 完成后自动审查…",goalBarSet:"开始",goalBarClear:"取消",goalBarLocked:"锁定:应用到后续所有回合",goalBarUnlocked:"仅本回合(改完自动清除)",goalBarReviewModel:"审查模型",goalBarUseMainModel:"使用主模型",goalBarMaxRounds:"最大轮数",goalBarMaxRoundsTip:"最大审查重改轮数;0 或不填 = 不限(持续改到通过)",goalBarUnlimitedShort:"不限",goalBarReviewing:"审查中…",goalBarRound:"第 {n} 轮",goalBarActive:"目标生效中",goalBarPassed:"已通过",goalBarFailed:"未通过",goalBarStatusPending:"等待生成…",goalWizardBtn:"AI 提炼",goalWizardTip:"让 AI 通过问卷调研细化需求,收敛为目标",goalWizardRunning:"目标调研中",goalWizardAnswer:"回答",goalWizardCard:"目标调研",settings:"设置",settingsTitle:"设置",settingsDesc:"修改立即生效:系统提示词、技能与插件开关会重建当前会话;审查提示词与审查技能只影响后续目标审查(回复进行中则主会话变更自动延迟)。",settingsSystemPrompt:"系统提示词",settingsPromptMode:"模式",promptModeAppend:"追加",promptModeReplace:"替换",promptAppendHint:"追加模式:自定义内容拼接到默认系统提示词末尾(推荐,保留默认行为约束)。",promptReplaceHint:"替换模式:完全用自定义内容替换系统提示词(项目上下文与技能段仍会自动附加)。切换后输入框会显示原本的默认提示词,可直接修改;不改动失焦则仍使用默认。",promptPlaceholder:"输入自定义系统提示词…(失焦后自动应用)",settingsViewPrompt:"查看当前完整提示词",settingsViewPromptHint:"当前会话实际生效的完整系统提示词(含自定义追加/替换内容、项目上下文、技能说明与工具引导),只读。",settingsViewPromptEmpty:"会话尚未就绪,暂无系统提示词。",settingsSkills:"技能",settingsReview:"目标审查",settingsReviewDesc:"为独立的目标审查会话配置额外提示词和技能;不会改变主会话设置。",settingsReviewSkills:"审查可用技能",reviewPromptPlaceholder:"输入审查自定义提示词…(失焦后自动应用)",reviewPromptHint:"这些内容会追加到审查任务中;审查仍会强制要求输出 pass/fail JSON。技能开关仅对审查生效。",settingsVisionBridge:"视觉桥",settingsVisionBridgeDesc:"当前模型不支持识图时,把图片交给已配置的视觉模型转写为文字证据,再让模型回答",visionBridgeEnabled:"启用视觉桥",visionBridgeModel:"转写模型",visionBridgeAuto:"自动选择(按顺序)",visionBridgeNoModels:"未找到已配置的视觉模型:在模型配置里添加任意支持图片的模型(如 qwen-vl、GLM-4V、Gemini)即可自动启用",visionBridgeOffHint:"已关闭:图片将原样发送,纯文本模型可能看不到图片内容",visionBridgeCurrent:"当前转写模型:{model}",visionBridgePromptMode:"转写提示词",settingsTerminalTools:"终端工具",terminalToolsEnabled:"启用持久终端工具",settingsTerminalToolsDesc:"让 AI 在交互式程序(REPL/vim)、长驻服务、需要持续观察输出或你要求在可见终端操作时,使用内置终端;普通命令仍走一次性 bash 工具",terminalToolsOffHint:"已关闭:AI 无法使用 terminal_* 工具,也不会收到相关使用引导",settingsMessageDisplay:"消息显示",thinkingWrap:"完整显示思考",thinkingWrapDesc:"开启:思考内容始终完整展开并自动换行(流式推理过程也实时可见);关闭:折叠成一行摘要,流式中一行实时显示最新文本",toolsWrap:"完整显示工具",toolsWrapDesc:"开启:工具调用始终完整展开显示参数和输出;关闭:默认折叠,点击展开",terminalBashTakeover:"终端接管 bash",terminalBashTakeoverDesc:"此开关决定 bash 是否覆盖为终端版:关 = 原生 SDK bash(纯进程、不开终端);开 = 跑进可见终端,且 persist 参数在本开关的基础上决定一次性(false,命令跑完进程退出、输出留档)还是持久(true,shell 状态跨调用保留、静默自动转后台并通知 AI)",terminalBashIdleMs:"静默转后台阈值(毫秒)",terminalBashIdleMsDesc:"持久终端模式下,命令连续无输出达到该时长即不再阻塞等待,转入后台继续运行并通知 AI;0 = 一直等到命令结束(默认 15000)",visionBridgePromptPlaceholder:"输入自定义转写提示词…(留空 = 使用内置默认提示词,失焦后自动应用)",visionBridgePromptAppendHint:"追加模式:自定义内容拼接到内置转写提示词末尾(推荐,保留默认的逐字转写约束)。",visionBridgePromptReplaceHint:"替换模式:完全用自定义内容替换内置转写提示词。切换后输入框会显示内置默认提示词,可直接修改;不改动失焦则仍使用默认。",uninstallExt:"卸载",uninstallConfirm:"确认卸载?",uninstallConfirmHint:"再次点击确认,将在终端执行 pi remove",uninstallHint:"通过可见终端执行 pi remove 卸载此包,完成后自动刷新列表",uninstallTitle:"卸载",pluginUpdate:"更新",pluginUpdateHint:"从安装来源重新拉取并覆盖安装(保留 config.json 配置),完成后自动重载插件列表",pluginUninstallHint:"在可见终端执行 pi-web-ui uninstall 卸载此插件(再次点击确认),完成后自动刷新列表",settingsExtensions:"插件",settingsUiPlugins:"界面插件",noUiPlugins:"未安装界面组件(<dataDir>/plugins/)",dshPatches:"DSH 用户补丁",dshPatchesDesc:"启动时按文件名序加载的 Cordis patch(<dataDir>/dsh-patches/*.yml)。新增/修改后点「重扫」重启运行时生效;失败的文件会被跳过并打印到运行时 stderr。",dshPatchesRescan:"重扫",dshPatchesRescanHint:"重新扫描补丁目录并重启 DSH 运行时使新补丁生效",dshPatchesEmpty:"未放置补丁文件",dshPatchesPath:"补丁目录:",uiPluginNoSource:"手工安装,无来源信息,无法在线更新",uiPluginPerms:"能力声明",pluginSettingsSave:"保存插件设置",pluginSettingsSaving:"保存中…",pluginSettingsReset:"恢复默认",settingsPresets:"预设",settingsEnabled:"已启用",settingsDisabled:"已禁用",presetNamePlaceholder:"预设名称…",saveAsPreset:"保存为预设",applyPreset:"应用",deletePreset:"删除预设",noSkills:"暂无技能",noExtensions:"暂无插件",noPresets:"暂无预设(先调整上面的设置,再保存为预设组合)",loadingSession:"正在加载会话…",connectingServer:"正在连接 pi-web-ui 服务器…"},vi={cancel:"Cancel",ok:"OK",save:"Save",close:"Close",widgetExpand:"Click to view full output",collapsePanel:"Collapse panel",expandPanel:"Expand panel",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",allProviders:"All",providers:"Providers",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",engineBadge:"Engine",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",slashPlugin:"Plugin",slashCopied:"Copied the last assistant reply",slashCopyFailed:"Copy failed — please copy manually",slashCopyEmpty:"No assistant reply to copy yet",recentProjects:"Recent projects",runningConversations:"Running chats",historySessions:"History",openHistory:"History",openFiles:"Files",streaming:"Streaming…",noHistory:"No previous chats",current:"Current",messageCount:"{n} messages",tuiTip:"Chat in the pi terminal (TUI)",deleteProject:"Remove from recent projects",deleteProjectConfirm:"Confirm remove",deleteSession:"Delete this chat transcript permanently",deleteSessionConfirm:"Confirm delete",emptyChat:"Empty chat",editReask:"Edit & re-ask",editReaskTip:"Edit this question and re-ask from here (forks a new conversation; the original is kept)",reaskFromHere:"Re-ask from here",editPlaceholder:"Edit the question…",editHint:"⌘/Ctrl+Enter to submit · Esc to cancel",editAttachmentHint:"Original attachments kept — paste/drop images or files · ⌘/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).",updatesAllTitle:"Component updates",updatesAllBadge:"{n} updates",updatesAllUpToDate:"All components up to date",kindWebUi:"Web UI",kindPiCore:"Core",kindPackage:"Package",updatesAllRefresh:"Re-check all",updateCheckFailed:"Check failed",updateBtn:"Update",updateAllBtn:"Update all",updatePkgTabTitle:"Update {name}",updateAllTabTitle:"Update all components",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}",uploadToFolder:"Upload files to this folder",uploadToCurrentDir:"Upload files to current directory",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",modelQuestion:"Model question",modelQuestionCustom:"Custom answer (optional)",modelQuestionSubmit:"Submit answer",questionTimeout:"⏳ {s}s left — auto-cancels on timeout",questionTimeoutExpired:"Question timed out, resuming conversation…",modelNoVision:"Current model {name} doesn't support images — switch to DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH uses runtime-built-in skills (dsh-skill); toggling is not supported in settings yet",dshExtensionsNote:"DSH has no pi extension system; capabilities are runtime-built-in (MCP/subagent/goal/plan/skill…)",dshReviewPromptNote:"DSH has no separate reviewer: this text is appended to the system prompt for goal rounds",dshVisionHiddenNote:"DSH supports real image input (DeepSeek V4 Flash Vision (exp) only) — no vision bridge needed",dshNoReviewModel:"DSH has no separate reviewer model — the model self-certifies goal completion; max rounds = auto-iteration count",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:",cliReadyHint:"✅ pi agent CLI already installed locally. 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",directory:"Directory",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",modelUsedCount:"used {n}×",searchGlobal:"Search",searchGlobalTip:"Global search: sessions / projects / files (Ctrl+K)",gsPlaceholder:"Search projects, past conversations, workspace files…",gsHint:"Type to search full conversation text (AI replies included), recent projects and file names in the current workspace at once",gsSessions:"Conversations",gsProjects:"Projects",gsFiles:"Files",gsNoResults:"No matches",gsSearching:"Searching…",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","tpl.title":"Prompt templates","tpl.hint":"Click a card to fill the input; ✏️ to edit or delete; add your own too","tpl.clickCard":"Click to fill the input","tpl.editTpl":"Edit / delete template","tpl.openPicker":"Prompt templates (reusable prompts, anytime)","tpl.pickerTitle":"Prompt templates","tpl.pickerHint":"Click a card to fill the input; ✏️ to edit or delete; add your own too","tpl.add":"New template","tpl.addDesc":"Save a workflow you use often","tpl.reset":"Restore defaults","tpl.resetConfirm":"Restore defaults?","tpl.builtin":"Built-in","tpl.custom":"Custom","tpl.newTitle":"New prompt template","tpl.editTitle":"Edit prompt template","tpl.fieldIcon":"Icon","tpl.fieldTitle":"Title","tpl.fieldTitlePh":"Short title shown on the card","tpl.fieldDesc":"Description","tpl.fieldDescPh":"One-liner shown on the card","tpl.fieldPrompt":"Prompt","tpl.fieldPromptPh":"The full prompt sent to the agent","tpl.required":"Title and prompt are required","tpl.save":"Save","tpl.fill":"Fill input","tpl.fillTip":"Fill the input so you can tweak it before sending","tpl.sendNow":"Send now","tpl.sendTip":"Send immediately as a new conversation","tpl.delete":"Delete","tpl.deleteTip":"Delete this custom template","tpl.remove":"Remove from library","tpl.removeTip":"Remove this built-in template; restore later via “Restore defaults”","tpl.restore":"Restore default","tpl.restoreTip":"Discard your edits and restore the built-in default","tpl.sk.setup":"Repo setup","tpl.sk.setup.desc":"Give the repo a baseline that other workflows can use","tpl.sk.setup.prompt":`Scan this repository and build the baseline context other workflows rely on, then report concisely:
|
|
153
153
|
|
|
154
154
|
1. Project type, tech stack and directory layout
|
|
155
155
|
2. Concrete commands for build / test / run / format
|
|
@@ -299,23 +299,23 @@ Keep going until the plan holds up.`,"tpl.sk.tdd":"Test-driven","tpl.sk.tdd.desc
|
|
|
299
299
|
2. Make them pass with the minimal implementation
|
|
300
300
|
3. Refactor while keeping tests green
|
|
301
301
|
|
|
302
|
-
Avoid three test anti-patterns: tests coupled to the implementation, tautological assertions (always true), and horizontal slicing (surface only). Report after each step and run the tests.`,error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"Run bash commands inside the persistent visible terminal: full output returned automatically, shell state retained across calls (cd/venv/ssh); silent commands move to the background and notify the AI when they finish",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"When a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",dshPatches:"DSH user patches",dshPatchesDesc:"Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.",dshPatchesRescan:"Rescan",dshPatchesRescanHint:"Re-scan the patch directory and restart the DSH runtime so new patches take effect",dshPatchesEmpty:"No patch files yet",dshPatchesPath:"Patch directory: ",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",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…"},en=a.createContext(null);function yi(){try{const t=localStorage.getItem(Zs);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ki({children:t}){const[s,i]=a.useState(yi),r=a.useCallback(n=>{i(n);try{localStorage.setItem(Zs,n)}catch{}},[]),c=a.useCallback((n,o)=>{let d=vi[n];if(s==="zh"&&(d=xi[n]),o)for(const[p,m]of Object.entries(o))d=d.replaceAll(`{${p}}`,String(m));return d},[s]);a.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const l=a.useMemo(()=>({locale:s,setLocale:r,t:c}),[s,r,c]);return e.jsx(en.Provider,{value:l,children:t})}function Ut(){const t=a.useContext(en);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function me(){return Ut().t}const bi=[{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 hs({settings:t,onChange:s,onPreview:i}){const r=me(),c=l=>s({...t,...l});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:r("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(qs,{className:"sound-icon"}),e.jsx("span",{children:r("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:l=>c({enabled:l.target.checked})})]}),bi.map(({kind:l,labelKey:n,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:r(n)}),e.jsx("span",{className:"sound-desc",children:r(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:r("preview"),disabled:!t.enabled,onClick:d=>{d.preventDefault(),i(l)},children:r("preview")}),e.jsx("input",{type:"checkbox",checked:t[l],disabled:!t.enabled,onChange:d=>c({[l]:d.target.checked})})]})]},l)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:r("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:l=>c({volume:Number(l.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function ji({chat:t,send:s,terminal:i,view:r,plugins:c,onViewChange:l,onOpenPanel:n,onOpenSettings:o,onOpenBgTasks:d,onOpenGlobalSearch:p,sound:m,onSoundChange:v,onSoundPreview:h,themes:x,theme:N,onThemeChange:M}){var se;const{locale:C,setLocale:I,t:j}=Ut(),[z,H]=a.useState(!1),[R,A]=a.useState(!1),[P,T]=a.useState(!1),[f,_]=a.useState(!1),[Y,X]=a.useState(!1),O=[{value:"zh",label:j("langZh")},{value:"en",label:j("langEn")}],G=t.ready?j("connected"):t.status==="closed"?j("reconnecting"):j("connecting"),q=t.ready?"ok":"busy",k=()=>{var U,K;if(!t.ready)return;const u=j("updateTabTitle"),W={name:u,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},D=t.terminals.find(te=>te.title===u);D?(i.restart(D.id),s({type:"run_command",terminalId:D.id,conversationId:D.conversationId,command:W,cols:80,rows:24})):i.create({id:_e(),conversationId:t.activeConversationId||((U=t.state)==null?void 0:U.conversationId)||"",title:u,cwd:((K=t.state)==null?void 0:K.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:W}),_(!1),X(!1),l("terminal")},w=(u,W)=>{var K,te;if(!t.ready||u.length===0)return;const D={name:W,command:fi(u),cwd:"${pwd}"},U=t.terminals.find(oe=>oe.title===W);U?(i.restart(U.id),s({type:"run_command",terminalId:U.id,conversationId:U.conversationId,command:D,cols:80,rows:24})):i.create({id:_e(),conversationId:t.activeConversationId||((K=t.state)==null?void 0:K.conversationId)||"",title:W,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:D}),_(!1),X(!1),l("terminal")},$=t.updatesAll??[],J=$.filter(u=>!u.upToDate&&!u.error).length,Z=$.filter(u=>!u.upToDate&&!u.error&&u.kind!=="webui"),S=()=>e.jsxs("div",{className:"dd-updates-all",children:[e.jsx("div",{className:"dd-header",children:j("updatesAllTitle")}),t.updatesAll===null?e.jsx("div",{className:"dd-note",children:j("checkingUpdate")}):$.length===0?e.jsx("div",{className:"dd-note",children:j("updatesAllUpToDate")}):e.jsx("ul",{className:"dd-all-list",children:$.map(u=>e.jsxs("li",{className:`dd-all-item${u.error?" err":u.upToDate?"":" warn"}`,children:[e.jsx("span",{className:"dd-all-name",title:u.name,children:u.name}),e.jsx("span",{className:"dd-all-kind",children:u.kind==="webui"?j("kindWebUi"):u.kind==="pi-core"?j("kindPiCore"):j("kindPackage")}),e.jsx("span",{className:"dd-all-vers",children:u.error?j("updateCheckFailed"):u.upToDate?`v${u.current}`:e.jsxs(e.Fragment,{children:["v",u.current," → v",u.latest]})}),u.kind!=="webui"&&!u.upToDate&&!u.error&&e.jsx("button",{type:"button",className:"dd-update-btn",onClick:()=>w([u],j("updatePkgTabTitle",{name:u.name})),children:j("updateBtn")})]},`${u.kind}:${u.name}`))}),e.jsxs("div",{className:"dd-actions",children:[Z.length>0&&e.jsx("button",{type:"button",className:"dd-refresh accent",style:{flex:1},onClick:()=>w(Z,j("updateAllTabTitle")),children:j("updateAllBtn")}),e.jsx("button",{type:"button",className:"dd-refresh",style:Z.length>0?{flex:1}:void 0,onClick:()=>s({type:"check_updates_all",force:!0}),children:j("updatesAllRefresh")})]})]}),ie=()=>{var u,W;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("currentVersion")}),e.jsxs("b",{children:["v",((u=t.update)==null?void 0:u.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("latestVersion")}),e.jsx("b",{children:t.update===null?j("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:j("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:j("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:j("updateAvailable",{version:t.update.latest})}),((W=t.update)==null?void 0:W.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:j("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:j("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?j("checkingUpdate"):j("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:k,children:j("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:j("openHistory"),onClick:()=>n("left"),children:e.jsx(ti,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${q}`,title:G}),e.jsx("span",{className:"conn-label",children:G})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":j("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="chat",className:r==="chat"?"active":"",onClick:()=>l("chat"),children:[e.jsx(Qe,{}),e.jsx("span",{children:j("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="terminal",className:r==="terminal"?"active":"",onClick:()=>l("terminal"),children:[e.jsx(Ge,{}),e.jsx("span",{children:j("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="git",className:r==="git"?"active":"",onClick:()=>l("git"),children:[e.jsx(ct,{}),e.jsx("span",{children:j("scmTab")})]}),c.map(u=>{const W=u.error?`${u.name}: ${u.error}`:u.description?`${u.name} — ${u.description}`:u.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":r===`plugin:${u.id}`,className:`plugin-tab${r===`plugin:${u.id}`?" active":""}${u.error?" broken":""}`,title:W,onClick:()=>l(`plugin:${u.id}`),children:[u.icon?e.jsx("span",{"aria-hidden":!0,children:u.icon}):null,e.jsx("span",{children:u.name})]},u.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:j("searchGlobalTip"),onClick:p,children:[e.jsx(ht,{}),e.jsx("span",{className:"chip-sub",children:j("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":j("bgTasksTip"),onClick:d,children:[e.jsx(gt,{}),e.jsx("span",{className:"chip-sub",children:j("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:j("settingsTitle"),onClick:o,children:[e.jsx(mt,{}),e.jsx("span",{className:"chip-sub",children:j("settings")})]}),e.jsx($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(qs,{}),e.jsx("span",{className:"chip-sub",children:j("sound")})]}),open:z,onOpenChange:H,children:e.jsx(hs,{settings:m,onChange:v,onPreview:h})}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ci,{}),e.jsx("span",{className:"chip-sub",children:C==="zh"?j("langZh"):"EN"})]}),open:R,onOpenChange:A,children:[e.jsx("div",{className:"dd-header",children:j("language")}),O.map(u=>e.jsx(Ce,{active:C===u.value,onClick:()=>{I(u.value),A(!1)},children:u.label},u.value))]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Qn,{}),e.jsx("span",{className:"chip-sub",children:j("theme")})]}),open:P,onOpenChange:T,children:[e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ce,{active:N===null,onClick:()=>{M(null),T(!1)},children:j("themeDefault")}),x.map(u=>e.jsx(Ce,{active:N===u.id,onClick:()=>{M(u.id),T(!1)},children:u.name},u.id))]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Ot,{}),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:j("updateAvailable",{version:t.update.latest??""})}),J>0&&e.jsx("span",{className:"update-badge",children:j("updatesAllBadge",{n:J})})]}),open:f,onOpenChange:u=>{_(u),u&&(s({type:"check_update"}),s({type:"check_updates_all"}))},fit:!0,children:[e.jsx("div",{className:"dd-header",children:j("update")}),ie(),S()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:j("githubRepo"),children:e.jsx(ms,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":j("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(He,{}),e.jsx("span",{children:j("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Zn,{}),e.jsx("span",{className:"chip-sub",children:j("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:Y,onOpenChange:u=>{X(u),u&&(s({type:"check_update"}),s({type:"check_updates_all"}))},children:[e.jsx("div",{className:"dd-header",children:j("sound")}),e.jsx("div",{className:"dd-header",children:j("settings")}),e.jsxs(Ce,{onClick:()=>{X(!1),o()},children:[e.jsx(mt,{})," ",j("settingsTitle")]}),e.jsxs(Ce,{onClick:()=>{X(!1),p()},children:[e.jsx(ht,{})," ",j("searchGlobal")]}),e.jsxs(Ce,{onClick:()=>{X(!1),d()},children:[e.jsx(gt,{})," ",j("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(hs,{settings:m,onChange:v,onPreview:h}),e.jsx("div",{className:"dd-header",children:j("language")}),O.map(u=>e.jsx(Ce,{active:C===u.value,onClick:()=>I(u.value),children:u.label},u.value)),e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ce,{active:N===null,onClick:()=>{M(null),X(!1)},children:j("themeDefault")}),x.map(u=>e.jsx(Ce,{active:N===u.id,onClick:()=>{M(u.id),X(!1)},children:u.name},u.id)),e.jsx("div",{className:"dd-header",children:j("update")}),ie(),S(),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(ms,{})," ",j("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:j("openFiles"),onClick:()=>n("right"),children:e.jsx(Ye,{})})]})]})}function gs(t){const s=new Date(t),i=new Date;return s.toDateString()===i.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}function wi(t,s){const i=new Map;for(const c of t){const l=i.get(c.cwd)??[];l.push(c),i.set(c.cwd,l)}const r=[...i.entries()].map(([c,l])=>({cwd:c,isCurrent:c===s,convs:l}));return r.sort((c,l)=>c.isCurrent?-1:l.isCurrent?1:c.cwd<l.cwd?-1:c.cwd>l.cwd?1:0),r}const Ni=a.memo(function({ready:s,status:i,cwd:r,sessionFile:c,conversations:l,sessions:n,projects:o,activeConversationId:d,send:p,active:m,collapsible:v,onToggleCollapse:h}){const x=me(),N=c,M=r,[C,I]=a.useState(null);a.useEffect(()=>{!m||!s||i!=="open"||r&&(p({type:"list_sessions"}),p({type:"list_projects"}))},[m,s,i,r,p]);const j=R=>{const A=R.name||R.firstMessage.trim();return A.length>0?A:x("emptyChat")},z=R=>R.split(/[\\/]/).pop()||R,H=(R,A,P,T)=>{const f=C===R;return e.jsx("button",{type:"button",className:`lp-del ${f?"confirm":""}`,title:f?P:A,onClick:_=>{_.stopPropagation(),f?(I(null),T()):I(R)},children:f?e.jsx(vt,{}):e.jsx(De,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[v&&h&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:x("collapsePanel"),onClick:h,children:e.jsx(Ys,{})}),o.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:x("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:o.map(R=>{const A=M===R.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>I(P=>P===`proj:${R.path}`?null:P),children:[e.jsxs("button",{type:"button",className:`project-item ${A?"active":""}`,title:R.path,onClick:()=>{A||p({type:"set_cwd",path:R.path})},children:[e.jsx(Ye,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:z(R.path)}),e.jsx("span",{className:"project-path",children:R.path})]}),e.jsx("span",{className:"project-time",children:gs(R.lastUsed)})]}),H(`proj:${R.path}`,x("deleteProject"),x("deleteProjectConfirm"),()=>p({type:"remove_project",path:R.path}))]},R.path)})})]}),l.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:x("runningConversations")}),wi(l,r).map(R=>e.jsxs("div",{className:"panel-conv-group",children:[!R.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:R.cwd,children:z(R.cwd)}),R.convs.map(A=>{const P=d===A.id;return e.jsxs("button",{type:"button",className:`session-item ${P?"active":""}`,title:`${A.title}${R.isCurrent?"":` — ${R.cwd}`}`,onClick:()=>{P||p({type:"switch_conversation",id:A.id})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:A.title}),e.jsx("span",{className:"session-sub",children:P?x("current"):x("messageCount",{n:A.messageCount})})]}),A.isStreaming&&e.jsx("span",{className:"conv-streaming",title:x("streaming")})]},A.id)})]},R.cwd)),e.jsx("div",{className:"panel-section-divider"})]}),e.jsxs("div",{className:"panel-sessions",children:[e.jsx("div",{className:"panel-section-title",children:x("historySessions")}),e.jsxs("div",{className:"sessions-scroll",children:[n.length===0&&e.jsx("div",{className:"panel-empty",children:x("noHistory")}),n.map(R=>{const A=N===R.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>I(P=>P===`sess:${R.path}`?null:P),children:[e.jsxs("button",{type:"button",className:`session-item ${A?"active":""}`,title:R.path,onClick:()=>{A||p({type:"switch_session",path:R.path})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:j(R)}),e.jsxs("span",{className:"session-sub",children:[A?x("current"):x("messageCount",{n:R.messageCount}),R.source==="tui"&&e.jsx("span",{className:"session-src",title:x("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:gs(R.modified)})]}),H(`sess:${R.path}`,x("deleteSession"),x("deleteSessionConfirm"),()=>p({type:"delete_session",path:R.path}))]},R.path)})]})]})]})}),tn="pi-web-ui:token";function Ci(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(tn,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function Si(){try{return localStorage.getItem(tn)??""}catch{return""}}function yt(t){const s=Si();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}let wt=null;function Ti(t){if(t===void 0){const i=globalThis.document;if(i&&typeof i.baseURI=="string"&&i.baseURI)try{t=new URL(i.baseURI).pathname}catch{}if(t===void 0)return"/"}if(!t||t==="/")return"/";let s=t.replace(/index\.html$/i,"");return s.endsWith("/")||(s+="/"),s}function Ei(){return wt===null&&(wt=Ti()),wt}function Mi(t,s){return s==="/"?t:s+t.replace(/^\/+/,"")}function Je(t){return Mi(t,Ei())}function Pi(t,s){const i=s.assistantMessageEvent,r=t.stats.tokens,c=s.usage!==null?{...r,...s.usage}:r,l=c===r?t.stats:{...t.stats,tokens:c};if(i.type!=="text_delta"&&i.type!=="thinking_delta")return l===t.stats?t:{...t,stats:l};const n=i.delta??"";if(!n)return l===t.stats?t:{...t,stats:l};const o=t.streamingMessage??null,d=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},p=[...d.content],m=i.type==="thinking_delta"?"thinking":"text",v=i.contentIndex??p.length-1;return v>=0&&v<p.length&&p[v].type===m?p[v]=m==="thinking"?{type:"thinking",thinking:(p[v].thinking??"")+n}:{type:"text",text:(p[v].text??"")+n}:p.push(m==="thinking"?{type:"thinking",thinking:n}:{type:"text",text:n}),{...t,stats:l,streamingMessage:{...d,id:s.messageId,content:p}}}const Bt="pi-web-ui:plugin-data";function Ri(t,s){window.dispatchEvent(new CustomEvent(Bt,{detail:{pluginId:t,payload:s}}))}function Ii(t){const s=i=>{const r=i.detail;t(r.pluginId,r.payload)};return window.addEventListener(Bt,s),()=>window.removeEventListener(Bt,s)}const Ve=new Map,_t=new Set,ze=new Set;let fs=-1;function sn(){return[...Ve.values()]}function Li(){const t=sn();for(const s of _t)s(t)}function Di(t){return _t.add(t),t(sn()),()=>_t.delete(t)}async function Bi(t,s){s!==fs&&(fs=s,Ve.clear(),ze.clear());const i=new Set(t.map(r=>r.id));for(const r of[...Ve.keys()])i.has(r)||Ve.delete(r);for(const r of[...ze])i.has(r)||ze.delete(r);await Promise.all(t.filter(r=>r.hasClient&&!r.error&&!Ve.has(r.id)&&!ze.has(r.id)).map(async r=>{try{const l=(await import(Je(`/plugins/${encodeURIComponent(r.id)}/client/entry.mjs?e=${s}`))).default;l&&typeof l.mount=="function"?Ve.set(r.id,{info:r,module:l}):(ze.add(r.id),console.error(`[plugin:${r.id}] entry.mjs 缺少 default.mount`))}catch(c){ze.add(r.id),console.error(`[plugin:${r.id}] 客户端加载失败:`,c)}})),Li()}function _i(t,s){return{pluginId:t,send:i=>s({type:"plugin_message",pluginId:t,payload:i}),onData:i=>Ii((r,c)=>{r===t&&i(c)})}}const Ai=10,Nt=2e5,Fi=2e5,$i={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 Hi(){const t=new Map,s=new Map,i=(r,c)=>`${r}:${c}`;return{write(r,c,l){const n=i(r,c),o=t.get(n);if(o&&o.size>0){for(const m of o)try{m.write(l)}catch{}return}const d=s.get(n)??"",p=d.length+l.length>Fi?l:d+l;s.set(n,p)},register(r,c,l){const n=i(r,c);let o=t.get(n);o||(o=new Set,t.set(n,o)),o.add(l);const d=s.get(n);if(d){try{l.write(d)}catch{}s.delete(n)}return()=>{const p=t.get(n);p&&(p.delete(l),p.size===0&&t.delete(n)),s.delete(n)}},clear(){t.clear(),s.clear()}}}function xs(t,s){const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId),c.role==="bashExecution"&&i.add(`bash-${c.id}`);let r=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function vs(t,s){if(t.size===0)return t;const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId);let r=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function Oi(t,s){var i,r,c,l;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,engine:s.engine,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==Ai};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:xs(t.liveOutputs,s.state),toolStatuses:vs(t.toolStatuses,s.state)};case"snapshot_delta":{const n=t.state,o=s.msg;if(!n||n.conversationId!==o.conversationId||n.rev!==o.baseRev)return t;const d={...n,...o.state,messages:o.appended.length>0?[...n.messages,...o.appended]:n.messages};return{...t,ready:!0,state:d,activeConversationId:d.conversationId,liveOutputs:xs(t.liveOutputs,d),toolStatuses:vs(t.toolStatuses,d)}}case"tool_delta":{const n=t.liveOutputs.get(s.toolCallId),o=((n==null?void 0:n.text)??"")+s.delta,d=o.length>Nt?`…[前 ${o.length-Nt} 字符已省略]…
|
|
303
|
-
`+o.slice(o.length-Nt):o,p=new Map(t.liveOutputs);return p.set(s.toolCallId,{toolName:s.toolName,text:d}),{...t,liveOutputs:p}}case"message_delta":{const n=t.state;return!n||n.conversationId!==s.msg.conversationId?t:{...t,state:Pi(n,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(n=>n.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"session_search_result":return{...t,sessionSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"update_status_all":return{...t,updatesAll:s.items};case"updates_check_started":return{...t,updatesAll:null};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"question":return{...t,question:s.question};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"dsh_patches":return{...t,dshPatches:{patchDir:s.patchDir,files:s.files}};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(n=>n.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(i=t.state)!=null&&i.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:t.terminals.map(n=>n.id===s.terminalId?{...n,running:!1,exitCode:s.exitCode}:n)};case"terminal_restart":return{...t,terminals:t.terminals.map(n=>n.id===s.terminalId?{...n,running:!0,exitCode:null}:n)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((l=t.state)==null?void 0:l.conversationId))?t:{...t,terminals:s.terminals.map(n=>{var o;return{...n,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};case"terminal_active":return{...t,terminalActiveId:s.id};default:return t}}const ys="pi-web-client-id";let Ct=null;function qt(){if(Ct)return Ct;let t=null;try{t=sessionStorage.getItem(ys),t||(t=_e(),sessionStorage.setItem(ys,t))}catch{t=t??_e()}return Ct=t,t}function Wi(){const t=location.protocol==="https:"?"wss:":"ws:";return yt(`${t}//${location.host}${Je("/ws")}`)}function Ui(){const[t,s]=a.useReducer(Oi,{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,updatesAll:null,widgets:[],statuses:[],dialog:null,question:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],terminalActiveId:null,goal:$i,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,dshPatches:null,protocolMismatch:!1}),i=a.useRef(null),r=a.useRef(Hi()),c=a.useRef(0),l=a.useRef(null),n=a.useRef(!0),o=a.useRef(0),d=a.useRef(0),p=a.useRef(new Map),m=a.useRef(null),v=()=>{m.current||(m.current=setTimeout(()=>{m.current=null;const P=i.current;P&&P.readyState===WebSocket.OPEN&&P.send(JSON.stringify({type:"get_state"}))},300))},h=(P,T)=>{var Y;const f=p.current,_=f.get(P);if(_!==void 0&&T!==_+1){const X=A.current.chat,O=X.activeConversationId||((Y=X.state)==null?void 0:Y.conversationId);P===O&&v()}f.set(P,T)},x=a.useCallback((P,T)=>{const f=++d.current;s({type:"notice",notice:{id:f,level:P,text:T}})},[]),N=a.useCallback(P=>{const T=i.current;return T&&T.readyState===WebSocket.OPEN?(P.type==="check_updates_all"&&P.force===!0&&s({type:"updates_check_started"}),T.send(JSON.stringify(P)),!0):!1},[]),M=a.useCallback(()=>{if(!n.current)return;s({type:"status",status:"connecting"});const P=new WebSocket(Wi());i.current=P,P.onopen=()=>{i.current===P&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),P.send(JSON.stringify({type:"hello",clientId:qt()})))},P.onmessage=T=>{if(i.current!==P)return;o.current=Date.now();let f;try{f=JSON.parse(T.data)}catch{return}switch(f.type){case"ready":s({type:"ready",serverVersion:f.serverVersion,protocolVersion:f.protocolVersion,engine:f.engine}),P.send(JSON.stringify({type:"get_state"})),P.send(JSON.stringify({type:"list_files"})),P.send(JSON.stringify({type:"list_models"})),P.send(JSON.stringify({type:"list_commands"})),P.send(JSON.stringify({type:"get_commands"})),P.send(JSON.stringify({type:"check_update"})),P.send(JSON.stringify({type:"check_updates_all"}));break;case"snapshot":p.current=new Map,s({type:"snapshot",state:f.state});break;case"snapshot_delta":{const _=A.current.chat.state;(!_||_.conversationId!==f.conversationId||_.rev!==f.baseRev)&&v(),s({type:"snapshot_delta",msg:f});break}case"tool_delta":h(f.conversationId,f.seq),s({type:"tool_delta",toolCallId:f.toolCallId,toolName:f.toolName,delta:f.delta});break;case"tool_status":s({type:"tool_status",status:f});break;case"message_delta":{h(f.conversationId,f.seq),s({type:"message_delta",msg:f});break}case"notice":{const _=++d.current;s({type:"notice",notice:{id:_,level:f.level,text:f.text}});break}case"sessions":s({type:"sessions",sessions:f.sessions});break;case"conversations":s({type:"conversations",conversations:f.conversations,activeId:f.activeId});break;case"projects":s({type:"projects",projects:f.projects});break;case"files":s({type:"files",files:f});break;case"file_changed":s({type:"file_changed",path:f.path});break;case"file_content":s({type:"file_content",content:f});break;case"models":s({type:"models",models:f.models,loading:!1});break;case"models_config":s({type:"models_config",providers:f.providers});break;case"providers_status":s({type:"providers_status",providers:f.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:f.reqId,ok:f.ok,models:f.models,error:f.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:f.reqId,ok:f.ok,added:f.added,total:f.total,error:f.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:f.reqId,ok:f.ok,config:f.config,error:f.error}});break;case"scm_data":s({type:"scm_data",data:f});break;case"search_files_result":s({type:"file_search_result",result:{reqId:f.reqId,ok:f.ok,results:f.results,truncated:f.truncated}});break;case"session_search_results":s({type:"session_search_result",result:{reqId:f.reqId,ok:f.ok,results:f.results}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:f});break;case"path_completions":s({type:"path_completions",completions:f.completions});break;case"update_status":s({type:"update_status",status:f});break;case"update_status_all":s({type:"update_status_all",items:f.items});break;case"widgets":s({type:"widgets",widgets:f.widgets});break;case"statuses":s({type:"statuses",statuses:f.statuses});break;case"dialog":s({type:"dialog",dialog:{id:f.id,kind:f.kind,title:f.title,args:f.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"question_pending":s({type:"question",question:{id:f.id,questions:f.questions}});break;case"terminal_output":r.current.write(f.conversationId??A.current.chat.activeConversationId,f.terminalId,f.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:f.conversationId,terminalId:f.terminalId,exitCode:f.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:f.conversationId,terminals:f.terminals});break;case"commands":s({type:"commands",commands:f.commands,path:f.path});break;case"slash_commands":s({type:"slash_commands",commands:f.commands});break;case"goal_status":s({type:"goal_status",status:f.status});break;case"settings_state":s({type:"settings",settings:f.settings});break;case"bg_servers":s({type:"bg_servers",servers:f.servers});break;case"plugins":s({type:"plugins",plugins:f.plugins,epoch:f.epoch});break;case"dsh_patches":s({type:"dsh_patches",patchDir:f.patchDir,files:f.files});break;case"plugin_data":Ri(f.pluginId,f.payload);break}},P.onclose=()=>{if(i.current===P&&(i.current=null),r.current.clear(),!n.current||i.current&&i.current!==P)return;s({type:"status",status:"closed"});const T=Math.min(1e3*2**c.current,1e4);c.current+=1,l.current=setTimeout(()=>{l.current=null,M()},T)},P.onerror=()=>{}},[]);a.useEffect(()=>{n.current=!0,M();const P=setInterval(()=>{if(!n.current)return;const T=i.current;T&&T.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&T.close()},5e3);return()=>{var T;n.current=!1,clearInterval(P),l.current&&(clearTimeout(l.current),l.current=null),(T=i.current)==null||T.close(),i.current=null}},[M]);const C=a.useCallback(P=>s({type:"dismiss_notice",id:P}),[]),I=a.useCallback(P=>s({type:"terminal_add",meta:P}),[]),j=a.useCallback(P=>s({type:"terminal_remove",id:P}),[]),z=a.useCallback(P=>s({type:"terminal_restart",terminalId:P}),[]),H=a.useCallback(P=>s({type:"terminal_active",id:P}),[]),R=a.useCallback((P,T,f)=>r.current.register(P,T,f),[]),A=a.useRef({chat:t,send:N,pushNotice:x,dismissNotice:C,terminal:{create:I,close:j,register:R,restart:z,select:H}});return A.current={chat:t,send:N,pushNotice:x,dismissNotice:C,terminal:{create:I,close:j,register:R,restart:z,select:H}},A.current}const qi=200*1024*1024,Ki=/windows/i.test(navigator.userAgent),zi=/[<>:"/\\|?*\u0000-\u001f]/g,Vi=/[. ]+$/,Gi=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Qi(t){const s=t.replace(zi,"_").replace(Vi,"");return s?Gi.test(s)?`_${s}`:s:"_"}function ks(t,s=!0){const i=new URLSearchParams({clientId:qt(),path:t,...s?{download:"1"}:{}});return yt(Je(`/api/file?${i}`))}async function Yi(t,s){const i=Ki?Qi(s):s;try{const r=await fetch(ks(t));if(!r.ok)return{ok:!1,cancelled:!1,error:await r.text().catch(()=>"")||(r.status===404?"文件不存在":`HTTP ${r.status}`)};if(Number(r.headers.get("content-length")??"0")>qi)return window.location.assign(ks(t)),{ok:!0};const l=await r.blob();return window.showSaveFilePicker&&window.isSecureContext?Ji(l,i):At(l,i)}catch(r){return{ok:!1,cancelled:!1,error:r instanceof Error?r.message:String(r)}}}async function Ji(t,s){let i;const r=window.showSaveFilePicker;if(!r)return At(t,s);try{i=await r({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:At(t,s)}try{const c=await i.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 At(t,s){const i=URL.createObjectURL(t),r=document.createElement("a");return r.href=i,r.download=s,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(i),1e4),{ok:!0}}const Xi=a.memo(function({files:s,fileChanged:i,widgets:r,cwd:c,send:l,onAttach:n,onPreview:o,onNotice:d,collapsible:p,onToggleCollapse:m}){const v=me(),[h,x]=a.useState(""),[N,M]=a.useState(null),[C,I]=a.useState(!1),[j,z]=a.useState(null),H=a.useRef(""),R=a.useRef(null),A=a.useCallback((u,W)=>{u.preventDefault(),H.current=W,z({x:Math.min(u.clientX,window.innerWidth-220),y:Math.min(u.clientY,window.innerHeight-90)})},[]),P=a.useCallback(()=>z(null),[]);a.useEffect(()=>{if(!j)return;const u=U=>{var K;(K=U.target)!=null&&K.closest(".ctx-menu")||P()},W=U=>{U.key==="Escape"&&P()};window.addEventListener("mousedown",u,!0),window.addEventListener("keydown",W);const D=()=>P();return window.addEventListener("blur",D),()=>{window.removeEventListener("mousedown",u,!0),window.removeEventListener("keydown",W),window.removeEventListener("blur",D)}},[j,P]);const T=a.useCallback(()=>{var u;P(),R.current&&(R.current.value=""),(u=R.current)==null||u.click()},[P]),f=a.useCallback((u,W)=>{for(const D of W){const U=new FileReader;U.onload=()=>{const K=U.result,te=K.slice(K.indexOf(",")+1);te&&l({type:"upload_file",dirPath:u,name:D.name,data:te})},U.readAsDataURL(D)}},[l]),_=a.useCallback(u=>{f(H.current,Array.from(u.target.files??[]))},[f]),Y=a.useRef(null),X=u=>{var W;return Array.from(((W=u.dataTransfer)==null?void 0:W.types)??[]).includes("Files")},O=a.useCallback(()=>{var u,W;(u=Y.current)==null||u.querySelectorAll(".file-item.drop-target").forEach(D=>D.classList.remove("drop-target")),(W=Y.current)==null||W.classList.remove("drop-root")},[]),G=a.useCallback(u=>{var D,U;if(O(),u==null)return;const W=(D=Y.current)==null?void 0:D.querySelector(`.file-item[data-path="${CSS.escape(u)}"]`);W?W.classList.add("drop-target"):(U=Y.current)==null||U.classList.add("drop-root")},[O]),q=u=>{const W=u instanceof Element?u.closest(".file-item"):null;return(W==null?void 0:W.dataset.type)==="dir"?W.dataset.path??h:h},k=a.useCallback(()=>{const u=document.querySelector(".app");u&&u.dispatchEvent(new DragEvent("dragleave",{bubbles:!0}))},[]),w=1e4,$=a.useRef(0),J=a.useRef(void 0),Z=a.useCallback((u,W)=>{const D=++$.current;x(u),W!=null&&W.silent||I(!0),l({type:"list_files",path:u===""?void 0:u})||$.current===D&&I(!1)},[l]);a.useEffect(()=>{s&&s.path===h&&I(!1)},[s,h]),a.useEffect(()=>{if(c!==J.current){J.current=c,Z("",{silent:!0});return}const u=setInterval(()=>{document.visibilityState!=="hidden"&&Z(h,{silent:!0})},w);return()=>clearInterval(u)},[c,h,Z]),a.useEffect(()=>{i&&i.path===h&&Z(h,{silent:!0})},[i,h,Z]);const S=u=>Z(u),ie=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&Z(s.parent)},se=h.split("/").filter(Boolean);return e.jsxs("aside",{className:"panel panel-right",children:[p&&m&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:v("collapsePanel"),onClick:m,children:e.jsx(Qs,{})}),e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${h===""?"active":""}`,onClick:()=>Z(""),children:v("rootDir")}),se.map((u,W)=>{const D=se.slice(0,W+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(xt,{}),e.jsx("button",{type:"button",className:`crumb ${D===h?"active":""}`,onClick:()=>Z(D),children:u})]},D)})]}),e.jsxs("div",{ref:Y,className:"panel-body",onContextMenu:u=>A(u,h),onDragOver:u=>{X(u)&&(u.preventDefault(),u.stopPropagation(),u.dataTransfer.dropEffect="copy",k(),G(q(u.target)))},onDragLeave:u=>{u.relatedTarget&&u.currentTarget.contains(u.relatedTarget)||O()},onDrop:u=>{var D;if(O(),!X(u))return;u.preventDefault(),u.stopPropagation(),k();const W=Array.from(((D=u.dataTransfer)==null?void 0:D.files)??[]);if(W.length===0){d("warning",v("foldersNotSupported"));return}f(q(u.target),W)},onDragEnd:O,children:[e.jsx("input",{ref:R,type:"file",multiple:!0,hidden:!0,onChange:_}),C&&e.jsx("div",{className:"panel-empty",children:v("loading")}),!C&&s&&s.path===h&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:ie,children:[e.jsx(Ye,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(u=>u.type==="dir"?e.jsxs("div",{className:"file-item dir","data-type":"dir","data-path":u.path,onContextMenu:W=>{W.stopPropagation(),A(W,u.path)},children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>S(u.path),children:[e.jsx(Ye,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:u.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":v("linkFolderTip"),onClick:()=>n(u.path,u.name,"reference",!0),children:e.jsx(Rt,{})})]},u.path):e.jsxs("div",{className:"file-item file","data-type":"file","data-path":u.path,onContextMenu:W=>{W.stopPropagation(),A(W,h)},children:[e.jsxs("button",{type:"button",className:"file-name",title:`${u.path} — ${v("previewFile")}`,onClick:()=>o(u.path,u.name),children:[e.jsx(Vs,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:u.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":v("downloadFile"),onClick:()=>{Yi(u.path,u.name).then(W=>{W.ok||W.cancelled||d("error",v("downloadFailed",{error:W.error}))})},children:e.jsx(Ot,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":v("attachInlineTip"),onClick:()=>n(u.path,u.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":v("referenceTip"),onClick:()=>n(u.path,u.name,"reference"),children:e.jsx(Rt,{})})]},u.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:v("filesTruncated")})]}),!C&&!s&&e.jsx("div",{className:"panel-empty",children:v("noFiles")})]}),r.filter(u=>u.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:r.filter(u=>u.lines.length>0).map(u=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:v("widgetExpand"),onClick:()=>M(u.key),children:[e.jsx("span",{children:u.key}),e.jsx(ni,{})]}),e.jsx("pre",{className:"widget-lines",children:u.lines.join(`
|
|
302
|
+
Avoid three test anti-patterns: tests coupled to the implementation, tautological assertions (always true), and horizontal slicing (surface only). Report after each step and run the tests.`,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}",aiBashGroup:"Terminal-backed bash",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"This switch decides whether bash is overridden to a terminal version: OFF = native SDK bash (process spawn, no terminal); ON = runs in a visible terminal, where the persist parameter decides (on top of the switch) one-shot (false — process exits when the command finishes, output retained) vs persistent (true — shell state retained across calls, silent commands move to the background and notify the AI)",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"In persistent-terminal mode, when a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",dshPatches:"DSH user patches",dshPatchesDesc:"Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.",dshPatchesRescan:"Rescan",dshPatchesRescanHint:"Re-scan the patch directory and restart the DSH runtime so new patches take effect",dshPatchesEmpty:"No patch files yet",dshPatchesPath:"Patch directory: ",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",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…"},en=a.createContext(null);function yi(){try{const t=localStorage.getItem(Zs);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ki({children:t}){const[s,i]=a.useState(yi),r=a.useCallback(n=>{i(n);try{localStorage.setItem(Zs,n)}catch{}},[]),c=a.useCallback((n,o)=>{let d=vi[n];if(s==="zh"&&(d=xi[n]),o)for(const[p,m]of Object.entries(o))d=d.replaceAll(`{${p}}`,String(m));return d},[s]);a.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const l=a.useMemo(()=>({locale:s,setLocale:r,t:c}),[s,r,c]);return e.jsx(en.Provider,{value:l,children:t})}function Ut(){const t=a.useContext(en);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function me(){return Ut().t}const bi=[{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 hs({settings:t,onChange:s,onPreview:i}){const r=me(),c=l=>s({...t,...l});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:r("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(qs,{className:"sound-icon"}),e.jsx("span",{children:r("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:l=>c({enabled:l.target.checked})})]}),bi.map(({kind:l,labelKey:n,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:r(n)}),e.jsx("span",{className:"sound-desc",children:r(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:r("preview"),disabled:!t.enabled,onClick:d=>{d.preventDefault(),i(l)},children:r("preview")}),e.jsx("input",{type:"checkbox",checked:t[l],disabled:!t.enabled,onChange:d=>c({[l]:d.target.checked})})]})]},l)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:r("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:l=>c({volume:Number(l.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function ji({chat:t,send:s,terminal:i,view:r,plugins:c,onViewChange:l,onOpenPanel:n,onOpenSettings:o,onOpenBgTasks:d,onOpenGlobalSearch:p,sound:m,onSoundChange:v,onSoundPreview:h,themes:x,theme:N,onThemeChange:M}){var se;const{locale:C,setLocale:I,t:j}=Ut(),[z,H]=a.useState(!1),[R,_]=a.useState(!1),[P,T]=a.useState(!1),[f,F]=a.useState(!1),[Y,X]=a.useState(!1),O=[{value:"zh",label:j("langZh")},{value:"en",label:j("langEn")}],G=t.ready?j("connected"):t.status==="closed"?j("reconnecting"):j("connecting"),q=t.ready?"ok":"busy",k=()=>{var U,K;if(!t.ready)return;const u=j("updateTabTitle"),W={name:u,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},D=t.terminals.find(te=>te.title===u);D?(i.restart(D.id),s({type:"run_command",terminalId:D.id,conversationId:D.conversationId,command:W,cols:80,rows:24})):i.create({id:Fe(),conversationId:t.activeConversationId||((U=t.state)==null?void 0:U.conversationId)||"",title:u,cwd:((K=t.state)==null?void 0:K.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:W}),F(!1),X(!1),l("terminal")},w=(u,W)=>{var K,te;if(!t.ready||u.length===0)return;const D={name:W,command:fi(u),cwd:"${pwd}"},U=t.terminals.find(oe=>oe.title===W);U?(i.restart(U.id),s({type:"run_command",terminalId:U.id,conversationId:U.conversationId,command:D,cols:80,rows:24})):i.create({id:Fe(),conversationId:t.activeConversationId||((K=t.state)==null?void 0:K.conversationId)||"",title:W,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:D}),F(!1),X(!1),l("terminal")},$=t.updatesAll??[],J=$.filter(u=>!u.upToDate&&!u.error).length,Z=$.filter(u=>!u.upToDate&&!u.error&&u.kind!=="webui"),S=()=>e.jsxs("div",{className:"dd-updates-all",children:[e.jsx("div",{className:"dd-header",children:j("updatesAllTitle")}),t.updatesAll===null?e.jsx("div",{className:"dd-note",children:j("checkingUpdate")}):$.length===0?e.jsx("div",{className:"dd-note",children:j("updatesAllUpToDate")}):e.jsx("ul",{className:"dd-all-list",children:$.map(u=>e.jsxs("li",{className:`dd-all-item${u.error?" err":u.upToDate?"":" warn"}`,children:[e.jsx("span",{className:"dd-all-name",title:u.name,children:u.name}),e.jsx("span",{className:"dd-all-kind",children:u.kind==="webui"?j("kindWebUi"):u.kind==="pi-core"?j("kindPiCore"):j("kindPackage")}),e.jsx("span",{className:"dd-all-vers",children:u.error?j("updateCheckFailed"):u.upToDate?`v${u.current}`:e.jsxs(e.Fragment,{children:["v",u.current," → v",u.latest]})}),u.kind!=="webui"&&!u.upToDate&&!u.error&&e.jsx("button",{type:"button",className:"dd-update-btn",onClick:()=>w([u],j("updatePkgTabTitle",{name:u.name})),children:j("updateBtn")})]},`${u.kind}:${u.name}`))}),e.jsxs("div",{className:"dd-actions",children:[Z.length>0&&e.jsx("button",{type:"button",className:"dd-refresh accent",style:{flex:1},onClick:()=>w(Z,j("updateAllTabTitle")),children:j("updateAllBtn")}),e.jsx("button",{type:"button",className:"dd-refresh",style:Z.length>0?{flex:1}:void 0,onClick:()=>s({type:"check_updates_all",force:!0}),children:j("updatesAllRefresh")})]})]}),ie=()=>{var u,W;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("currentVersion")}),e.jsxs("b",{children:["v",((u=t.update)==null?void 0:u.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("latestVersion")}),e.jsx("b",{children:t.update===null?j("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:j("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:j("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:j("updateAvailable",{version:t.update.latest})}),((W=t.update)==null?void 0:W.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:j("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:j("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?j("checkingUpdate"):j("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:k,children:j("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:j("openHistory"),onClick:()=>n("left"),children:e.jsx(ti,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${q}`,title:G}),e.jsx("span",{className:"conn-label",children:G})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":j("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="chat",className:r==="chat"?"active":"",onClick:()=>l("chat"),children:[e.jsx(Qe,{}),e.jsx("span",{children:j("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="terminal",className:r==="terminal"?"active":"",onClick:()=>l("terminal"),children:[e.jsx(Ge,{}),e.jsx("span",{children:j("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="git",className:r==="git"?"active":"",onClick:()=>l("git"),children:[e.jsx(ct,{}),e.jsx("span",{children:j("scmTab")})]}),c.map(u=>{const W=u.error?`${u.name}: ${u.error}`:u.description?`${u.name} — ${u.description}`:u.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":r===`plugin:${u.id}`,className:`plugin-tab${r===`plugin:${u.id}`?" active":""}${u.error?" broken":""}`,title:W,onClick:()=>l(`plugin:${u.id}`),children:[u.icon?e.jsx("span",{"aria-hidden":!0,children:u.icon}):null,e.jsx("span",{children:u.name})]},u.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:j("searchGlobalTip"),onClick:p,children:[e.jsx(ht,{}),e.jsx("span",{className:"chip-sub",children:j("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":j("bgTasksTip"),onClick:d,children:[e.jsx(gt,{}),e.jsx("span",{className:"chip-sub",children:j("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:j("settingsTitle"),onClick:o,children:[e.jsx(mt,{}),e.jsx("span",{className:"chip-sub",children:j("settings")})]}),e.jsx($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(qs,{}),e.jsx("span",{className:"chip-sub",children:j("sound")})]}),open:z,onOpenChange:H,children:e.jsx(hs,{settings:m,onChange:v,onPreview:h})}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ci,{}),e.jsx("span",{className:"chip-sub",children:C==="zh"?j("langZh"):"EN"})]}),open:R,onOpenChange:_,children:[e.jsx("div",{className:"dd-header",children:j("language")}),O.map(u=>e.jsx(Ce,{active:C===u.value,onClick:()=>{I(u.value),_(!1)},children:u.label},u.value))]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Qn,{}),e.jsx("span",{className:"chip-sub",children:j("theme")})]}),open:P,onOpenChange:T,children:[e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ce,{active:N===null,onClick:()=>{M(null),T(!1)},children:j("themeDefault")}),x.map(u=>e.jsx(Ce,{active:N===u.id,onClick:()=>{M(u.id),T(!1)},children:u.name},u.id))]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Ot,{}),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:j("updateAvailable",{version:t.update.latest??""})}),J>0&&e.jsx("span",{className:"update-badge",children:j("updatesAllBadge",{n:J})})]}),open:f,onOpenChange:u=>{F(u),u&&(s({type:"check_update"}),s({type:"check_updates_all"}))},fit:!0,children:[e.jsx("div",{className:"dd-header",children:j("update")}),ie(),S()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:j("githubRepo"),children:e.jsx(ms,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":j("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(He,{}),e.jsx("span",{children:j("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Zn,{}),e.jsx("span",{className:"chip-sub",children:j("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:Y,onOpenChange:u=>{X(u),u&&(s({type:"check_update"}),s({type:"check_updates_all"}))},children:[e.jsx("div",{className:"dd-header",children:j("sound")}),e.jsx("div",{className:"dd-header",children:j("settings")}),e.jsxs(Ce,{onClick:()=>{X(!1),o()},children:[e.jsx(mt,{})," ",j("settingsTitle")]}),e.jsxs(Ce,{onClick:()=>{X(!1),p()},children:[e.jsx(ht,{})," ",j("searchGlobal")]}),e.jsxs(Ce,{onClick:()=>{X(!1),d()},children:[e.jsx(gt,{})," ",j("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(hs,{settings:m,onChange:v,onPreview:h}),e.jsx("div",{className:"dd-header",children:j("language")}),O.map(u=>e.jsx(Ce,{active:C===u.value,onClick:()=>I(u.value),children:u.label},u.value)),e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ce,{active:N===null,onClick:()=>{M(null),X(!1)},children:j("themeDefault")}),x.map(u=>e.jsx(Ce,{active:N===u.id,onClick:()=>{M(u.id),X(!1)},children:u.name},u.id)),e.jsx("div",{className:"dd-header",children:j("update")}),ie(),S(),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(ms,{})," ",j("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:j("openFiles"),onClick:()=>n("right"),children:e.jsx(Ye,{})})]})]})}function gs(t){const s=new Date(t),i=new Date;return s.toDateString()===i.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}function wi(t,s){const i=new Map;for(const c of t){const l=i.get(c.cwd)??[];l.push(c),i.set(c.cwd,l)}const r=[...i.entries()].map(([c,l])=>({cwd:c,isCurrent:c===s,convs:l}));return r.sort((c,l)=>c.isCurrent?-1:l.isCurrent?1:c.cwd<l.cwd?-1:c.cwd>l.cwd?1:0),r}const Ni=a.memo(function({ready:s,status:i,cwd:r,sessionFile:c,conversations:l,sessions:n,projects:o,activeConversationId:d,send:p,active:m,collapsible:v,onToggleCollapse:h}){const x=me(),N=c,M=r,[C,I]=a.useState(null);a.useEffect(()=>{!m||!s||i!=="open"||r&&(p({type:"list_sessions"}),p({type:"list_projects"}))},[m,s,i,r,p]);const j=R=>{const _=R.name||R.firstMessage.trim();return _.length>0?_:x("emptyChat")},z=R=>R.split(/[\\/]/).pop()||R,H=(R,_,P,T)=>{const f=C===R;return e.jsx("button",{type:"button",className:`lp-del ${f?"confirm":""}`,title:f?P:_,onClick:F=>{F.stopPropagation(),f?(I(null),T()):I(R)},children:f?e.jsx(vt,{}):e.jsx(De,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[v&&h&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:x("collapsePanel"),onClick:h,children:e.jsx(Ys,{})}),o.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:x("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:o.map(R=>{const _=M===R.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>I(P=>P===`proj:${R.path}`?null:P),children:[e.jsxs("button",{type:"button",className:`project-item ${_?"active":""}`,title:R.path,onClick:()=>{_||p({type:"set_cwd",path:R.path})},children:[e.jsx(Ye,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:z(R.path)}),e.jsx("span",{className:"project-path",children:R.path})]}),e.jsx("span",{className:"project-time",children:gs(R.lastUsed)})]}),H(`proj:${R.path}`,x("deleteProject"),x("deleteProjectConfirm"),()=>p({type:"remove_project",path:R.path}))]},R.path)})})]}),l.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:x("runningConversations")}),wi(l,r).map(R=>e.jsxs("div",{className:"panel-conv-group",children:[!R.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:R.cwd,children:z(R.cwd)}),R.convs.map(_=>{const P=d===_.id;return e.jsxs("button",{type:"button",className:`session-item ${P?"active":""}`,title:`${_.title}${R.isCurrent?"":` — ${R.cwd}`}`,onClick:()=>{P||p({type:"switch_conversation",id:_.id})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:_.title}),e.jsx("span",{className:"session-sub",children:P?x("current"):x("messageCount",{n:_.messageCount})})]}),_.isStreaming&&e.jsx("span",{className:"conv-streaming",title:x("streaming")})]},_.id)})]},R.cwd)),e.jsx("div",{className:"panel-section-divider"})]}),e.jsxs("div",{className:"panel-sessions",children:[e.jsx("div",{className:"panel-section-title",children:x("historySessions")}),e.jsxs("div",{className:"sessions-scroll",children:[n.length===0&&e.jsx("div",{className:"panel-empty",children:x("noHistory")}),n.map(R=>{const _=N===R.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>I(P=>P===`sess:${R.path}`?null:P),children:[e.jsxs("button",{type:"button",className:`session-item ${_?"active":""}`,title:R.path,onClick:()=>{_||p({type:"switch_session",path:R.path})},children:[e.jsx(Qe,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:j(R)}),e.jsxs("span",{className:"session-sub",children:[_?x("current"):x("messageCount",{n:R.messageCount}),R.source==="tui"&&e.jsx("span",{className:"session-src",title:x("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:gs(R.modified)})]}),H(`sess:${R.path}`,x("deleteSession"),x("deleteSessionConfirm"),()=>p({type:"delete_session",path:R.path}))]},R.path)})]})]})]})}),tn="pi-web-ui:token";function Ci(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(tn,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function Si(){try{return localStorage.getItem(tn)??""}catch{return""}}function yt(t){const s=Si();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}let wt=null;function Ti(t){if(t===void 0){const i=globalThis.document;if(i&&typeof i.baseURI=="string"&&i.baseURI)try{t=new URL(i.baseURI).pathname}catch{}if(t===void 0)return"/"}if(!t||t==="/")return"/";let s=t.replace(/index\.html$/i,"");return s.endsWith("/")||(s+="/"),s}function Ei(){return wt===null&&(wt=Ti()),wt}function Mi(t,s){return s==="/"?t:s+t.replace(/^\/+/,"")}function Je(t){return Mi(t,Ei())}function Pi(t,s){const i=s.assistantMessageEvent,r=t.stats.tokens,c=s.usage!==null?{...r,...s.usage}:r,l=c===r?t.stats:{...t.stats,tokens:c};if(i.type!=="text_delta"&&i.type!=="thinking_delta")return l===t.stats?t:{...t,stats:l};const n=i.delta??"";if(!n)return l===t.stats?t:{...t,stats:l};const o=t.streamingMessage??null,d=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},p=[...d.content],m=i.type==="thinking_delta"?"thinking":"text",v=i.contentIndex??p.length-1;return v>=0&&v<p.length&&p[v].type===m?p[v]=m==="thinking"?{type:"thinking",thinking:(p[v].thinking??"")+n}:{type:"text",text:(p[v].text??"")+n}:p.push(m==="thinking"?{type:"thinking",thinking:n}:{type:"text",text:n}),{...t,stats:l,streamingMessage:{...d,id:s.messageId,content:p}}}const Bt="pi-web-ui:plugin-data";function Ri(t,s){window.dispatchEvent(new CustomEvent(Bt,{detail:{pluginId:t,payload:s}}))}function Ii(t){const s=i=>{const r=i.detail;t(r.pluginId,r.payload)};return window.addEventListener(Bt,s),()=>window.removeEventListener(Bt,s)}const Ve=new Map,Ft=new Set,ze=new Set;let fs=-1;function sn(){return[...Ve.values()]}function Li(){const t=sn();for(const s of Ft)s(t)}function Di(t){return Ft.add(t),t(sn()),()=>Ft.delete(t)}async function Bi(t,s){s!==fs&&(fs=s,Ve.clear(),ze.clear());const i=new Set(t.map(r=>r.id));for(const r of[...Ve.keys()])i.has(r)||Ve.delete(r);for(const r of[...ze])i.has(r)||ze.delete(r);await Promise.all(t.filter(r=>r.hasClient&&!r.error&&!Ve.has(r.id)&&!ze.has(r.id)).map(async r=>{try{const l=(await import(Je(`/plugins/${encodeURIComponent(r.id)}/client/entry.mjs?e=${s}`))).default;l&&typeof l.mount=="function"?Ve.set(r.id,{info:r,module:l}):(ze.add(r.id),console.error(`[plugin:${r.id}] entry.mjs 缺少 default.mount`))}catch(c){ze.add(r.id),console.error(`[plugin:${r.id}] 客户端加载失败:`,c)}})),Li()}function Fi(t,s){return{pluginId:t,send:i=>s({type:"plugin_message",pluginId:t,payload:i}),onData:i=>Ii((r,c)=>{r===t&&i(c)})}}const _i=10,Nt=2e5,Ai=2e5,$i={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 Hi(){const t=new Map,s=new Map,i=(r,c)=>`${r}:${c}`;return{write(r,c,l){const n=i(r,c),o=t.get(n);if(o&&o.size>0){for(const m of o)try{m.write(l)}catch{}return}const d=s.get(n)??"",p=d.length+l.length>Ai?l:d+l;s.set(n,p)},register(r,c,l){const n=i(r,c);let o=t.get(n);o||(o=new Set,t.set(n,o)),o.add(l);const d=s.get(n);if(d){try{l.write(d)}catch{}s.delete(n)}return()=>{const p=t.get(n);p&&(p.delete(l),p.size===0&&t.delete(n)),s.delete(n)}},clear(){t.clear(),s.clear()}}}function xs(t,s){const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId),c.role==="bashExecution"&&i.add(`bash-${c.id}`);let r=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function vs(t,s){if(t.size===0)return t;const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId);let r=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function Oi(t,s){var i,r,c,l;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,engine:s.engine,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==_i};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:xs(t.liveOutputs,s.state),toolStatuses:vs(t.toolStatuses,s.state)};case"snapshot_delta":{const n=t.state,o=s.msg;if(!n||n.conversationId!==o.conversationId||n.rev!==o.baseRev)return t;const d={...n,...o.state,messages:o.appended.length>0?[...n.messages,...o.appended]:n.messages};return{...t,ready:!0,state:d,activeConversationId:d.conversationId,liveOutputs:xs(t.liveOutputs,d),toolStatuses:vs(t.toolStatuses,d)}}case"tool_delta":{const n=t.liveOutputs.get(s.toolCallId),o=((n==null?void 0:n.text)??"")+s.delta,d=o.length>Nt?`…[前 ${o.length-Nt} 字符已省略]…
|
|
303
|
+
`+o.slice(o.length-Nt):o,p=new Map(t.liveOutputs);return p.set(s.toolCallId,{toolName:s.toolName,text:d}),{...t,liveOutputs:p}}case"message_delta":{const n=t.state;return!n||n.conversationId!==s.msg.conversationId?t:{...t,state:Pi(n,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(n=>n.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"session_search_result":return{...t,sessionSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"update_status_all":return{...t,updatesAll:s.items};case"updates_check_started":return{...t,updatesAll:null};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"question":return{...t,question:s.question};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"dsh_patches":return{...t,dshPatches:{patchDir:s.patchDir,files:s.files}};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(n=>n.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(i=t.state)!=null&&i.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:t.terminals.map(n=>n.id===s.terminalId?{...n,running:!1,exitCode:s.exitCode}:n)};case"terminal_restart":return{...t,terminals:t.terminals.map(n=>n.id===s.terminalId?{...n,running:!0,exitCode:null}:n)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((l=t.state)==null?void 0:l.conversationId))?t:{...t,terminals:s.terminals.map(n=>{var o;return{...n,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};case"terminal_active":return{...t,terminalActiveId:s.id};default:return t}}const ys="pi-web-client-id";let Ct=null;function qt(){if(Ct)return Ct;let t=null;try{t=sessionStorage.getItem(ys),t||(t=Fe(),sessionStorage.setItem(ys,t))}catch{t=t??Fe()}return Ct=t,t}function Wi(){const t=location.protocol==="https:"?"wss:":"ws:";return yt(`${t}//${location.host}${Je("/ws")}`)}function Ui(){const[t,s]=a.useReducer(Oi,{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,updatesAll:null,widgets:[],statuses:[],dialog:null,question:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],terminalActiveId:null,goal:$i,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,dshPatches:null,protocolMismatch:!1}),i=a.useRef(null),r=a.useRef(Hi()),c=a.useRef(0),l=a.useRef(null),n=a.useRef(!0),o=a.useRef(0),d=a.useRef(0),p=a.useRef(new Map),m=a.useRef(null),v=()=>{m.current||(m.current=setTimeout(()=>{m.current=null;const P=i.current;P&&P.readyState===WebSocket.OPEN&&P.send(JSON.stringify({type:"get_state"}))},300))},h=(P,T)=>{var Y;const f=p.current,F=f.get(P);if(F!==void 0&&T!==F+1){const X=_.current.chat,O=X.activeConversationId||((Y=X.state)==null?void 0:Y.conversationId);P===O&&v()}f.set(P,T)},x=a.useCallback((P,T)=>{const f=++d.current;s({type:"notice",notice:{id:f,level:P,text:T}})},[]),N=a.useCallback(P=>{const T=i.current;return T&&T.readyState===WebSocket.OPEN?(P.type==="check_updates_all"&&P.force===!0&&s({type:"updates_check_started"}),T.send(JSON.stringify(P)),!0):!1},[]),M=a.useCallback(()=>{if(!n.current)return;s({type:"status",status:"connecting"});const P=new WebSocket(Wi());i.current=P,P.onopen=()=>{i.current===P&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),P.send(JSON.stringify({type:"hello",clientId:qt()})))},P.onmessage=T=>{if(i.current!==P)return;o.current=Date.now();let f;try{f=JSON.parse(T.data)}catch{return}switch(f.type){case"ready":s({type:"ready",serverVersion:f.serverVersion,protocolVersion:f.protocolVersion,engine:f.engine}),P.send(JSON.stringify({type:"get_state"})),P.send(JSON.stringify({type:"list_files"})),P.send(JSON.stringify({type:"list_models"})),P.send(JSON.stringify({type:"list_commands"})),P.send(JSON.stringify({type:"get_commands"})),P.send(JSON.stringify({type:"check_update"})),P.send(JSON.stringify({type:"check_updates_all"}));break;case"snapshot":p.current=new Map,s({type:"snapshot",state:f.state});break;case"snapshot_delta":{const F=_.current.chat.state;(!F||F.conversationId!==f.conversationId||F.rev!==f.baseRev)&&v(),s({type:"snapshot_delta",msg:f});break}case"tool_delta":h(f.conversationId,f.seq),s({type:"tool_delta",toolCallId:f.toolCallId,toolName:f.toolName,delta:f.delta});break;case"tool_status":s({type:"tool_status",status:f});break;case"message_delta":{h(f.conversationId,f.seq),s({type:"message_delta",msg:f});break}case"notice":{const F=++d.current;s({type:"notice",notice:{id:F,level:f.level,text:f.text}});break}case"sessions":s({type:"sessions",sessions:f.sessions});break;case"conversations":s({type:"conversations",conversations:f.conversations,activeId:f.activeId});break;case"projects":s({type:"projects",projects:f.projects});break;case"files":s({type:"files",files:f});break;case"file_changed":s({type:"file_changed",path:f.path});break;case"file_content":s({type:"file_content",content:f});break;case"models":s({type:"models",models:f.models,loading:!1});break;case"models_config":s({type:"models_config",providers:f.providers});break;case"providers_status":s({type:"providers_status",providers:f.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:f.reqId,ok:f.ok,models:f.models,error:f.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:f.reqId,ok:f.ok,added:f.added,total:f.total,error:f.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:f.reqId,ok:f.ok,config:f.config,error:f.error}});break;case"scm_data":s({type:"scm_data",data:f});break;case"search_files_result":s({type:"file_search_result",result:{reqId:f.reqId,ok:f.ok,results:f.results,truncated:f.truncated}});break;case"session_search_results":s({type:"session_search_result",result:{reqId:f.reqId,ok:f.ok,results:f.results}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:f});break;case"path_completions":s({type:"path_completions",completions:f.completions});break;case"update_status":s({type:"update_status",status:f});break;case"update_status_all":s({type:"update_status_all",items:f.items});break;case"widgets":s({type:"widgets",widgets:f.widgets});break;case"statuses":s({type:"statuses",statuses:f.statuses});break;case"dialog":s({type:"dialog",dialog:{id:f.id,kind:f.kind,title:f.title,args:f.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"question_pending":s({type:"question",question:{id:f.id,questions:f.questions}});break;case"terminal_output":r.current.write(f.conversationId??_.current.chat.activeConversationId,f.terminalId,f.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:f.conversationId,terminalId:f.terminalId,exitCode:f.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:f.conversationId,terminals:f.terminals});break;case"commands":s({type:"commands",commands:f.commands,path:f.path});break;case"slash_commands":s({type:"slash_commands",commands:f.commands});break;case"goal_status":s({type:"goal_status",status:f.status});break;case"settings_state":s({type:"settings",settings:f.settings});break;case"bg_servers":s({type:"bg_servers",servers:f.servers});break;case"plugins":s({type:"plugins",plugins:f.plugins,epoch:f.epoch});break;case"dsh_patches":s({type:"dsh_patches",patchDir:f.patchDir,files:f.files});break;case"plugin_data":Ri(f.pluginId,f.payload);break}},P.onclose=()=>{if(i.current===P&&(i.current=null),r.current.clear(),!n.current||i.current&&i.current!==P)return;s({type:"status",status:"closed"});const T=Math.min(1e3*2**c.current,1e4);c.current+=1,l.current=setTimeout(()=>{l.current=null,M()},T)},P.onerror=()=>{}},[]);a.useEffect(()=>{n.current=!0,M();const P=setInterval(()=>{if(!n.current)return;const T=i.current;T&&T.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&T.close()},5e3);return()=>{var T;n.current=!1,clearInterval(P),l.current&&(clearTimeout(l.current),l.current=null),(T=i.current)==null||T.close(),i.current=null}},[M]);const C=a.useCallback(P=>s({type:"dismiss_notice",id:P}),[]),I=a.useCallback(P=>s({type:"terminal_add",meta:P}),[]),j=a.useCallback(P=>s({type:"terminal_remove",id:P}),[]),z=a.useCallback(P=>s({type:"terminal_restart",terminalId:P}),[]),H=a.useCallback(P=>s({type:"terminal_active",id:P}),[]),R=a.useCallback((P,T,f)=>r.current.register(P,T,f),[]),_=a.useRef({chat:t,send:N,pushNotice:x,dismissNotice:C,terminal:{create:I,close:j,register:R,restart:z,select:H}});return _.current={chat:t,send:N,pushNotice:x,dismissNotice:C,terminal:{create:I,close:j,register:R,restart:z,select:H}},_.current}const qi=200*1024*1024,Ki=/windows/i.test(navigator.userAgent),zi=/[<>:"/\\|?*\u0000-\u001f]/g,Vi=/[. ]+$/,Gi=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Qi(t){const s=t.replace(zi,"_").replace(Vi,"");return s?Gi.test(s)?`_${s}`:s:"_"}function ks(t,s=!0){const i=new URLSearchParams({clientId:qt(),path:t,...s?{download:"1"}:{}});return yt(Je(`/api/file?${i}`))}async function Yi(t,s){const i=Ki?Qi(s):s;try{const r=await fetch(ks(t));if(!r.ok)return{ok:!1,cancelled:!1,error:await r.text().catch(()=>"")||(r.status===404?"文件不存在":`HTTP ${r.status}`)};if(Number(r.headers.get("content-length")??"0")>qi)return window.location.assign(ks(t)),{ok:!0};const l=await r.blob();return window.showSaveFilePicker&&window.isSecureContext?Ji(l,i):_t(l,i)}catch(r){return{ok:!1,cancelled:!1,error:r instanceof Error?r.message:String(r)}}}async function Ji(t,s){let i;const r=window.showSaveFilePicker;if(!r)return _t(t,s);try{i=await r({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:_t(t,s)}try{const c=await i.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 _t(t,s){const i=URL.createObjectURL(t),r=document.createElement("a");return r.href=i,r.download=s,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(i),1e4),{ok:!0}}const Xi=a.memo(function({files:s,fileChanged:i,widgets:r,cwd:c,send:l,onAttach:n,onPreview:o,onNotice:d,collapsible:p,onToggleCollapse:m}){const v=me(),[h,x]=a.useState(""),[N,M]=a.useState(null),[C,I]=a.useState(!1),[j,z]=a.useState(null),H=a.useRef(""),R=a.useRef(null),_=a.useCallback((u,W)=>{u.preventDefault(),H.current=W,z({x:Math.min(u.clientX,window.innerWidth-220),y:Math.min(u.clientY,window.innerHeight-90)})},[]),P=a.useCallback(()=>z(null),[]);a.useEffect(()=>{if(!j)return;const u=U=>{var K;(K=U.target)!=null&&K.closest(".ctx-menu")||P()},W=U=>{U.key==="Escape"&&P()};window.addEventListener("mousedown",u,!0),window.addEventListener("keydown",W);const D=()=>P();return window.addEventListener("blur",D),()=>{window.removeEventListener("mousedown",u,!0),window.removeEventListener("keydown",W),window.removeEventListener("blur",D)}},[j,P]);const T=a.useCallback(()=>{var u;P(),R.current&&(R.current.value=""),(u=R.current)==null||u.click()},[P]),f=a.useCallback((u,W)=>{for(const D of W){const U=new FileReader;U.onload=()=>{const K=U.result,te=K.slice(K.indexOf(",")+1);te&&l({type:"upload_file",dirPath:u,name:D.name,data:te})},U.readAsDataURL(D)}},[l]),F=a.useCallback(u=>{f(H.current,Array.from(u.target.files??[]))},[f]),Y=a.useRef(null),X=u=>{var W;return Array.from(((W=u.dataTransfer)==null?void 0:W.types)??[]).includes("Files")},O=a.useCallback(()=>{var u,W;(u=Y.current)==null||u.querySelectorAll(".file-item.drop-target").forEach(D=>D.classList.remove("drop-target")),(W=Y.current)==null||W.classList.remove("drop-root")},[]),G=a.useCallback(u=>{var D,U;if(O(),u==null)return;const W=(D=Y.current)==null?void 0:D.querySelector(`.file-item[data-path="${CSS.escape(u)}"]`);W?W.classList.add("drop-target"):(U=Y.current)==null||U.classList.add("drop-root")},[O]),q=u=>{const W=u instanceof Element?u.closest(".file-item"):null;return(W==null?void 0:W.dataset.type)==="dir"?W.dataset.path??h:h},k=a.useCallback(()=>{const u=document.querySelector(".app");u&&u.dispatchEvent(new DragEvent("dragleave",{bubbles:!0}))},[]),w=1e4,$=a.useRef(0),J=a.useRef(void 0),Z=a.useCallback((u,W)=>{const D=++$.current;x(u),W!=null&&W.silent||I(!0),l({type:"list_files",path:u===""?void 0:u})||$.current===D&&I(!1)},[l]);a.useEffect(()=>{s&&s.path===h&&I(!1)},[s,h]),a.useEffect(()=>{if(c!==J.current){J.current=c,Z("",{silent:!0});return}const u=setInterval(()=>{document.visibilityState!=="hidden"&&Z(h,{silent:!0})},w);return()=>clearInterval(u)},[c,h,Z]),a.useEffect(()=>{i&&i.path===h&&Z(h,{silent:!0})},[i,h,Z]);const S=u=>Z(u),ie=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&Z(s.parent)},se=h.split("/").filter(Boolean);return e.jsxs("aside",{className:"panel panel-right",children:[p&&m&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:v("collapsePanel"),onClick:m,children:e.jsx(Qs,{})}),e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${h===""?"active":""}`,onClick:()=>Z(""),children:v("rootDir")}),se.map((u,W)=>{const D=se.slice(0,W+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(xt,{}),e.jsx("button",{type:"button",className:`crumb ${D===h?"active":""}`,onClick:()=>Z(D),children:u})]},D)})]}),e.jsxs("div",{ref:Y,className:"panel-body",onContextMenu:u=>_(u,h),onDragOver:u=>{X(u)&&(u.preventDefault(),u.stopPropagation(),u.dataTransfer.dropEffect="copy",k(),G(q(u.target)))},onDragLeave:u=>{u.relatedTarget&&u.currentTarget.contains(u.relatedTarget)||O()},onDrop:u=>{var D;if(O(),!X(u))return;u.preventDefault(),u.stopPropagation(),k();const W=Array.from(((D=u.dataTransfer)==null?void 0:D.files)??[]);if(W.length===0){d("warning",v("foldersNotSupported"));return}f(q(u.target),W)},onDragEnd:O,children:[e.jsx("input",{ref:R,type:"file",multiple:!0,hidden:!0,onChange:F}),C&&e.jsx("div",{className:"panel-empty",children:v("loading")}),!C&&s&&s.path===h&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:ie,children:[e.jsx(Ye,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(u=>u.type==="dir"?e.jsxs("div",{className:"file-item dir","data-type":"dir","data-path":u.path,onContextMenu:W=>{W.stopPropagation(),_(W,u.path)},children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>S(u.path),children:[e.jsx(Ye,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:u.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":v("linkFolderTip"),onClick:()=>n(u.path,u.name,"reference",!0),children:e.jsx(Rt,{})})]},u.path):e.jsxs("div",{className:"file-item file","data-type":"file","data-path":u.path,onContextMenu:W=>{W.stopPropagation(),_(W,h)},children:[e.jsxs("button",{type:"button",className:"file-name",title:`${u.path} — ${v("previewFile")}`,onClick:()=>o(u.path,u.name),children:[e.jsx(Vs,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:u.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":v("downloadFile"),onClick:()=>{Yi(u.path,u.name).then(W=>{W.ok||W.cancelled||d("error",v("downloadFailed",{error:W.error}))})},children:e.jsx(Ot,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":v("attachInlineTip"),onClick:()=>n(u.path,u.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":v("referenceTip"),onClick:()=>n(u.path,u.name,"reference"),children:e.jsx(Rt,{})})]},u.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:v("filesTruncated")})]}),!C&&!s&&e.jsx("div",{className:"panel-empty",children:v("noFiles")})]}),r.filter(u=>u.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:r.filter(u=>u.lines.length>0).map(u=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:v("widgetExpand"),onClick:()=>M(u.key),children:[e.jsx("span",{children:u.key}),e.jsx(ni,{})]}),e.jsx("pre",{className:"widget-lines",children:u.lines.join(`
|
|
304
304
|
`)})]},u.key))}),N&&(()=>{const u=r.find(W=>W.key===N);return u?e.jsx("div",{className:"modal-backdrop",onClick:()=>M(null),children:e.jsxs("div",{className:"widget-expand",onClick:W=>W.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:u.key}),e.jsx("button",{type:"button",className:"btn",title:v("close"),onClick:()=>M(null),children:e.jsx(Ne,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:u.lines.join(`
|
|
305
305
|
`)})]})}):null})(),j&&e.jsx("div",{className:"ctx-menu",style:{left:j.x,top:j.y},onContextMenu:u=>{u.preventDefault(),u.stopPropagation()},children:e.jsxs("button",{type:"button",className:"ctx-item",onClick:T,children:[e.jsx(Vn,{}),H.current===h?v("uploadToCurrentDir"):v("uploadToFolder")]})})]})});var Zi=Os();const nn=a.memo(function({text:s}){const i=me(),[r,c]=a.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:i("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{c(!0),setTimeout(()=>c(!1),1200)})},children:r?e.jsx(vt,{}):e.jsx(Wt,{})}):null});function ea(t){const s=r=>{var c;if(typeof r=="string"||typeof r=="number"){const l=String(r);return l===""?[[]]:l.split(`
|
|
306
|
-
`).map(n=>n===""?[]:[n])}if(Array.isArray(r)){let l=[];for(const n of r){const o=s(n);if(l.length===0)l=o;else{const d=o[0]??[];l[l.length-1].push(...d),l.push(...o.slice(1))}}return l}if(r&&typeof r=="object"&&"props"in r){const l=r,n=(c=l.props)==null?void 0:c.children,o={...l.props??{},children:void 0},d=n==null?[]:s(n);return d.length===0?[[a.createElement(l.type,o)]]:d.map(p=>[a.createElement(l.type,o,...p)])}return[[r]]},i=s(t);return i.length>1&&i[i.length-1].length===0&&i.pop(),i}const an=[In],rn=[[Rn,{detect:!0,ignoreMissing:!0}]];function ln({text:t}){return e.jsx(Hs,{remarkPlugins:an,rehypePlugins:rn,components:{pre:ta},children:t})}const kt=a.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(ln,{text:s})})});function ta({children:t,...s}){var n;const i=t&&typeof t=="object"&&"props"in t?(n=t.props)==null?void 0:n.children:t,r=ea(i),c=r.length>1,l=c?`${String(r.length).length+1}ch`:void 0;return e.jsxs("div",{className:"codeblock",children:[e.jsx(nn,{text:
|
|
306
|
+
`).map(n=>n===""?[]:[n])}if(Array.isArray(r)){let l=[];for(const n of r){const o=s(n);if(l.length===0)l=o;else{const d=o[0]??[];l[l.length-1].push(...d),l.push(...o.slice(1))}}return l}if(r&&typeof r=="object"&&"props"in r){const l=r,n=(c=l.props)==null?void 0:c.children,o={...l.props??{},children:void 0},d=n==null?[]:s(n);return d.length===0?[[a.createElement(l.type,o)]]:d.map(p=>[a.createElement(l.type,o,...p)])}return[[r]]},i=s(t);return i.length>1&&i[i.length-1].length===0&&i.pop(),i}const an=[In],rn=[[Rn,{detect:!0,ignoreMissing:!0}]];function ln({text:t}){return e.jsx(Hs,{remarkPlugins:an,rehypePlugins:rn,components:{pre:ta},children:t})}const kt=a.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(ln,{text:s})})});function ta({children:t,...s}){var n;const i=t&&typeof t=="object"&&"props"in t?(n=t.props)==null?void 0:n.children:t,r=ea(i),c=r.length>1,l=c?`${String(r.length).length+1}ch`:void 0;return e.jsxs("div",{className:"codeblock",children:[e.jsx(nn,{text:At(t)}),e.jsx("pre",{...s,children:r.map((o,d)=>e.jsxs("div",{className:"code-line",children:[c&&e.jsx("span",{className:"code-num",style:l?{width:l}:void 0,children:d+1}),e.jsx("code",{className:"code-line-body hljs",children:o})]},d))})]})}function At(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(At).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return At(s==null?void 0:s.children)}return""}const sa=/^\s{0,3}(`{3,}|~{3,})/,na=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function St(t){return t.trim()===""}function bs(t){const s=sa.exec(t);return s?s[1]:null}function ia(t){const s=t.split(`
|
|
307
307
|
`),i=[];let r=[],c=null;for(let l=0;l<s.length;l++){const n=s[l];if(c!==null){const d=bs(n);d&&d[0]===c[0]&&d.length>=c.length&&(c=null),r.push(n);continue}const o=bs(n);if(o&&!St(n)){c=o,r.push(n);continue}if(St(n)){let d=l;for(;d<s.length&&St(s[d]);)d++;if(!(d<s.length&&na.test(s[d]))&&r.length>0){i.push(r.join(`
|
|
308
308
|
`)),r=[];continue}r.push(n);continue}r.push(n)}return{frozen:i,active:r.join(`
|
|
309
309
|
`),inFence:c!==null}}const aa=a.memo(function({text:s}){return e.jsx(Hs,{remarkPlugins:an,rehypePlugins:rn,children:s})}),js=200;function ra({text:t,inFence:s}){const[i,r]=a.useState(t),c=a.useRef(0),l=a.useRef(null);return a.useEffect(()=>{if(s)return;const n=Date.now()-c.current,o=()=>{c.current=Date.now(),r(t)};if(n>=js){o();return}return l.current=setTimeout(o,js-n),()=>{l.current&&clearTimeout(l.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx(ln,{text:i})}const la=a.memo(function({text:s}){const{frozen:i,active:r,inFence:c}=a.useMemo(()=>ia(s),[s]);return e.jsxs("div",{className:"md",children:[i.map((l,n)=>e.jsx(aa,{text:l},n)),r.length>0&&e.jsx(ra,{text:r,inFence:c},i.length)]})});function oa({thinking:t,streaming:s,wrap:i=!0,forceOpen:r=!1}){const c=me(),[l,n]=a.useState(null),o=l??i,d=o||r,p=s?t.trimEnd().slice(-80):t.split(`
|
|
310
|
-
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${d?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>n(!o),children:[d?e.jsx(qe,{}):e.jsx(xt,{}),e.jsx(it,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s&&d?e.jsxs("span",{className:"thinking-live-label",children:[c("thinkingNow"),e.jsx("span",{className:"dots"})]}):d?c("thinking"):c("thinkingPreview",{preview:p})})]}),d&&e.jsx("div",{className:"thinking-body",children:t})]})}const ca={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function da(t){return ca[t]??"🛠"}const ua=a.memo(function({block:s,view:i,onKillBash:r,wrap:c=!0,forceOpen:l=!1}){var P,T,f,
|
|
310
|
+
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${d?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>n(!o),children:[d?e.jsx(qe,{}):e.jsx(xt,{}),e.jsx(it,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s&&d?e.jsxs("span",{className:"thinking-live-label",children:[c("thinkingNow"),e.jsx("span",{className:"dots"})]}):d?c("thinking"):c("thinkingPreview",{preview:p})})]}),d&&e.jsx("div",{className:"thinking-body",children:t})]})}const ca={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function da(t){return ca[t]??"🛠"}const ua=a.memo(function({block:s,view:i,onKillBash:r,wrap:c=!0,forceOpen:l=!1}){var P,T,f,F;const n=me(),[o,d]=a.useState(c),p=o||l,[m,v]=a.useState(!1),h=!i.result&&i.streaming&&!i.status,x=s.name==="bash"&&h,N=i.result!==void 0,M=!i.result&&!!i.status,C=((P=i.result)==null?void 0:P.isError)??((T=i.status)==null?void 0:T.isError)??!1,I=i.result?i.result.content.map(Y=>Y.type==="text"?Y.text:"").join(""):i.liveOutput??"",j=C?"err":N?"ok":h||M?"run":"idle";let z=n(C?"error":N?"done":h?"running":M?"toolDoneWaitingModel":"toolQueued");const H=M&&((f=i.status)==null?void 0:f.durationMs)!==void 0?ma(i.status.durationMs):"";M&&H&&(z=`${z} · ${H}`);const R=M&&((F=i.status)==null?void 0:F.exitCode)!==void 0?`exit ${i.status.exitCode}`:"",_=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),v(!0),setTimeout(()=>v(!1),1200))};return e.jsxs("div",{className:`toolcall ${j}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:da(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[z,R&&e.jsx("em",{className:"toolcall-exit",children:R})]}),e.jsx("span",{className:"toolcall-spacer"}),x&&r&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:n("stopBashTip"),onClick:r,children:[e.jsx(pt,{}),e.jsx("span",{children:n("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:n("copyArgs"),onClick:_,children:m?e.jsx(pi,{}):e.jsx(Wt,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>d(Y=>l?!0:!Y),children:p?e.jsx(qe,{}):e.jsx(xt,{})})]}),p&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(pa,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),I.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[n(C?"errorOutput":"output"),(h||M)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:I})]}),h&&I.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",n("waitingOutput")]}),M&&I.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",n("waitingModel")]})]})]})});function pa({args:t}){let s=null;try{s=JSON.parse(t)}catch{return e.jsx("pre",{children:t})}return typeof s.command!="string"?e.jsx("pre",{children:t}):e.jsxs("div",{className:"termline",children:[e.jsx(Ge,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function ma(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const i=Math.floor(s/60),r=Math.round(s%60);return`${i}m ${String(r).padStart(2,"0")}s`}const ha=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function Kt(t){var i;const s=t.match(ha);return s?{name:s[1],location:s[2],content:s[3],userMessage:((i=s[4])==null?void 0:i.trim())||void 0}:null}const ga=1568,fa=2*1024*1024;function Be(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function on(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const i=Math.min(1,ga/Math.max(s.width,s.height)),r=Math.max(1,Math.round(s.width*i)),c=Math.max(1,Math.round(s.height*i)),l=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 n=null;for(const[o,d]of l){const p=document.createElement("canvas");p.width=r,p.height=c;const m=p.getContext("2d");if(!m)continue;o!=="image/png"&&(m.fillStyle="#ffffff",m.fillRect(0,0,r,c)),m.drawImage(s,0,0,r,c);const v=p.toDataURL(o,d),h=v.match(/^data:([^;]+);base64,/),x=h?h[1]:o,N=v.replace(/^data:[^;]*;base64,/,""),M=Math.floor(N.length*3/4);if(n={data:N,mimeType:x,name:t.name,size:M},M<=fa)return n}return n}finally{s.close()}}const xa=20*1024*1024;function at(t){return t.type==="text"&&typeof t.text=="string"?t:null}function cn(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function dn(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function un(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function pn(t){return t.type==="bash"&&typeof t.command=="string"?t:null}function va(t){return t.imageData?"image":t.uploadPath?"upload":t.fileData?"file":"path"}function ya(t,s){if(t.imageData)return s("attachImage",{name:t.name??"image"});if(t.uploadPath)return s("attachFile",{name:t.name??t.uploadPath});if(t.fileData)return s("attachFile",{name:t.name??"file"});const i=t.path.split("/").pop()??t.path;return t.mode==="lines"&&t.lines?s("attachLines",{path:i,start:t.lines.start,end:t.lines.end}):t.mode==="reference"?s("refOnly",{path:i}):s("attachContent",{path:i})}const ws=a.memo(function({message:s,toolResults:i,liveOutputs:r,toolStatuses:c,streaming:l,isLast:n,onEdit:o,onKillBash:d,onCollapse:p,questionAttachments:m,qnIndex:v,qnActive:h,onJump:x,thinkingWrap:N,toolsWrap:M,searchActive:C}){const I=me(),[j,z]=a.useState(!1),[H,R]=a.useState(""),[_,P]=a.useState([]),[T,f]=a.useState(!1),[F,Y]=a.useState(null),X=D=>{Y(D),window.setTimeout(()=>Y(U=>U===D?null:U),4e3)};if(s.role==="toolResult")return null;const O=s.role==="custom"&&s.customType==="file",G=s.content.map(D=>{var U;return((U=at(D))==null?void 0:U.text)??""}).filter(Boolean).join(`
|
|
311
311
|
`),q=s.role==="user"?Kt(G):null,k=q?q.userMessage??`skill:${q.name}`:G.split(`
|
|
312
312
|
`).join(" ").trim(),w=l&&n&&s.content.length===0,$=s.role==="user"&&!l&&!w&&!!o,J=async D=>{const U=[];for(const K of D){if(!Be(K.type))continue;const te=await on(K);te&&U.push({path:"",imageData:te.data,mimeType:te.mimeType,name:te.name})}U.length>0&&P(K=>[...K,...U])},Z=async D=>{if(D.size>xa){X(I("fileTooLarge",{name:D.name,size:20}));return}let U;try{U=(await new Promise((te,oe)=>{const ve=new FileReader;ve.onload=()=>te(ve.result),ve.onerror=()=>oe(ve.error??new Error("read failed")),ve.readAsDataURL(D)})).replace(/^data:[^;]*;base64,/,"")}catch{X(I("fileLoadFailed",{name:D.name}));return}P(K=>[...K,{path:"",fileData:U,name:D.name,size:D.size,mimeType:D.type||void 0}])},S=async D=>{const U=[];for(const K of D)Be(K.type)?U.push(K):Z(K);U.length>0&&await J(U)},ie=()=>{R(q?`/skill:${q.name}${q.userMessage?` ${q.userMessage}`:""}`:s.content.map(D=>{var U;return((U=at(D))==null?void 0:U.text)??""}).filter(Boolean).join(`
|
|
313
|
-
`)),P(m??[]),z(!0)},se=()=>{const D=H.trim();D&&(o==null||o(s.id,D,
|
|
313
|
+
`)),P(m??[]),z(!0)},se=()=>{const D=H.trim();D&&(o==null||o(s.id,D,_.length>0?_:void 0),z(!1))},u=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),W=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${u?" 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"?W?I("goalWizardCard"):u?I("goalBarTitle"):s.customType==="file"?I("attachment"):`${I("plugin")} · ${s.customType??I("unknown")}`:mn(s.role,I)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:wa(s.timestamp)}),p&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:I("collapseMsg"),onClick:()=>p(s.id),children:[e.jsx(ft,{})," ",I("collapseMsg")]}),v!==void 0&&x&&e.jsxs("button",{type:"button",className:`qn-tag ${h?"active":""}`,title:`${v+1}. ${k}`,"aria-label":`${v+1}. ${k}`,onClick:()=>x(s.id),children:[e.jsx("span",{className:"qn-tag-bar"}),e.jsx("span",{className:"qn-tag-idx",children:v+1})]})]}),e.jsx("div",{className:"msg-body",children:j?e.jsxs("div",{className:`msg-editor${T?" drag-over":""}`,onDragOver:D=>{D.preventDefault(),D.stopPropagation(),f(!0)},onDragLeave:D=>{D.currentTarget.contains(D.relatedTarget)||f(!1)},onDrop:D=>{var U;D.preventDefault(),D.stopPropagation(),f(!1),S(Array.from(((U=D.dataTransfer)==null?void 0:U.files)??[]))},children:[_.length>0&&e.jsx("div",{className:"msg-editor-images",children:_.map((D,U)=>{var te;const K=va(D);return e.jsxs("span",{className:`msg-editor-img ${K==="image"?"":"file-chip"}`,title:ya(D,I),children:[K==="image"?e.jsx("img",{src:`data:${D.mimeType??"image/png"};base64,${D.imageData}`,alt:D.name}):e.jsxs("span",{className:"msg-editor-file",children:[e.jsx("span",{className:"msg-editor-file-icon",children:K==="path"?D.mode==="reference"?"🔗":"📎":"📄"}),e.jsx("span",{className:"msg-editor-file-name",children:D.name??((te=D.path)==null?void 0:te.split("/").pop())})]}),e.jsx("button",{type:"button",className:"msg-editor-img-remove",title:I("removeAttachment"),onClick:()=>P(oe=>oe.filter((ve,y)=>y!==U)),children:e.jsx(Ne,{})})]},`${D.name??D.path??"att"}-${U}`)})}),F&&e.jsx("div",{className:"msg-editor-notice",children:F}),e.jsx("textarea",{className:"msg-editor-input",value:H,autoFocus:!0,placeholder:I("editPlaceholder"),rows:Math.max(2,Math.min(10,H.split(`
|
|
314
314
|
`).length+1)),onChange:D=>R(D.target.value),onPaste:D=>{var K;const U=[];for(const te of((K=D.clipboardData)==null?void 0:K.items)??[])if(te.kind==="file"&&Be(te.type)){const oe=te.getAsFile();oe&&U.push(oe)}U.length!==0&&(D.preventDefault(),J(U))},onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)?(D.preventDefault(),se()):D.key==="Escape"&&z(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsxs("span",{className:"msg-editor-hint",children:[e.jsx(li,{})," ",I("editAttachmentHint")]}),e.jsx("button",{type:"button",className:"chip",onClick:()=>z(!1),children:I("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!H.trim(),title:I("reaskFromHere"),onClick:se,children:[e.jsx(Lt,{})," ",I("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),O?e.jsx(ka,{message:s,forceOpen:C}):q?e.jsxs(e.Fragment,{children:[e.jsx(ja,{block:q,forceOpen:C}),q.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(kt,{text:q.userMessage})}),s.content.map((D,U)=>D.type==="text"?null:e.jsx(Cs,{block:D,toolResults:i,liveOutputs:r,toolStatuses:c,streaming:l,isLast:n,onKillBash:d,toolsWrap:M,thinkingWrap:N,searchActive:C},`${s.id}-${U}`))]}):s.content.map((D,U)=>e.jsx(Cs,{block:D,toolResults:i,liveOutputs:r,toolStatuses:c,streaming:l,isLast:n,onKillBash:d,toolsWrap:M,thinkingWrap:N,searchActive:C},`${s.id}-${U}`)),w&&e.jsxs("div",{className:"thinking-wait",children:[I("thinkingWait"),e.jsx("span",{className:"dot"})]}),l&&n&&!w&&e.jsx("span",{className:"stream-cursor"})]})}),$&&!j&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:I("editReaskTip"),onClick:ie,children:[e.jsx(Lt,{})," ",I("editReask")]})})]})});function ka({message:t,forceOpen:s=!1}){const i=me(),[r,c]=a.useState(!1),l=r||s,n=t.details??{},o=n.name??n.path??i("attachment"),d=n.type==="folder",p=n.mode==="reference",m=n.mode==="bridged",v=t.content.filter(M=>M.type==="text").map(M=>M.text).join(`
|
|
315
315
|
`),h=ba(v),x=t.content.find(M=>M.type==="image"),N=h.split(`
|
|
316
316
|
`).length;return e.jsxs("div",{className:`attachcard ${p?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>c(M=>s?!0:!M),children:[e.jsx("span",{className:"attachcard-icon",children:d?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:o}),n.path&&e.jsx("span",{className:"attachcard-path",children:n.path}),e.jsx("span",{className:`attachcard-mode ${n.mode==="lines"?"lines":p?"ref":m?"bridged":"inline"}`,children:p?d?i("folderRefShort"):`${i("refOnlyShort")} · ${Ns(n.size)}`:m?i("bridgedVision"):x?i("image"):n.mode==="lines"?i("inlineLinesRange",{start:n.startLine??1,end:n.endLine??n.lines??1}):i("inlineLines",{n:n.lines??N})}),!p&&(l?e.jsx(qe,{}):e.jsx(xt,{}))]}),!p&&l&&(m?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"attachcard-bridgenote",children:i("bridgedVisionDetail")}),(x==null?void 0:x.dataUrl)&&e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:x.dataUrl,alt:o})}),h&&e.jsx("pre",{className:"attachcard-content",children:h})]}):x!=null&&x.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:x.dataUrl,alt:o})}):e.jsx("pre",{className:"attachcard-content",children:h})),p&&e.jsx("div",{className:"attachcard-refnote",children:d?i("folderNotExpanded"):i("fileNotExpanded",{size:Ns(n.size)})})]})}function Ns(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function ba(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 i=t.match(/^\s*<vision-bridge>\s*([\s\S]*?)\s*<\/vision-bridge>\s*$/);return i?i[1].trim():t.trim()}function ja({block:t,forceOpen:s=!1}){const i=me(),[r,c]=a.useState(!1),l=r||s;return e.jsxs("div",{className:`skillcard${r?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>c(n=>s?!0:!n),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(mi,{})}),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:[l?e.jsx(ft,{}):e.jsx(qe,{}),i(l?"collapseMsg":"expandMsg")]})]}),l&&e.jsx("div",{className:"skillcard-body",children:e.jsx(kt,{text:t.content})})]})}function Cs({block:t,toolResults:s,liveOutputs:i,toolStatuses:r,streaming:c,isLast:l,onKillBash:n,thinkingWrap:o,toolsWrap:d,searchActive:p}){const m=me(),v=at(t);if(v){const C=c&&l;return e.jsxs("div",{className:"msg-text",children:[C?e.jsx(la,{text:v.text}):e.jsx(kt,{text:v.text}),v.truncated&&e.jsx("div",{className:"trunc-note",children:m("truncated")})]})}const h=cn(t);if(h)return e.jsx(oa,{thinking:h.thinking,streaming:c&&l,wrap:o,forceOpen:p});const x=dn(t);if(x){const C=s.get(x.id),I=i.get(x.id),j={result:C,liveOutput:I==null?void 0:I.text,streaming:c,status:r.get(x.id)};return e.jsx(ua,{block:x,view:j,onKillBash:n,wrap:d,forceOpen:p})}const N=un(t);if(N&&N.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:N.dataUrl,alt:"attachment"})});const M=pn(t);return M?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:M.command}),M.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${M.exitCode===0?"ok":"err"}`,children:m("exitCode",{code:M.exitCode})}),M.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:m("cancelled")})]}),M.output&&e.jsx("pre",{className:"bashblock-output",children:M.output}),M.truncated&&e.jsx("div",{className:"trunc-note",children:m("outputTruncated")})]}):null}function mn(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 wa(t){const s=new Date(t),i=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${i}:${r}`}function Ss(t,s,i){let r=!1;for(const c of s){const l=c;if(l.type!=="image"||typeof l.dataUrl!="string"||!l.dataUrl.startsWith("data:"))continue;const n=l.dataUrl.match(/^data:([^;]*);base64,(.+)$/);n&&(r=!0,t.push({path:"",imageData:n[2],mimeType:n[1]||"image/png",name:i??`image.${(n[1]||"image/png").split("/")[1]??"png"}`}))}return r}function Na(t){const s=new Map;for(let i=0;i<t.length;i++){const r=t[i];if(r.role!=="user"||!r.id)continue;const c=[];Ss(c,r.content);for(let l=i+1;l<t.length&&t[l].role==="custom"&&t[l].customType==="file";l++){const n=t[l].details??{};if(!Ss(c,t[l].content,n.name)){if(n.upload&&n.path){c.push({path:"",uploadPath:n.path,name:n.name??n.path,size:n.size});continue}if(n.path&&n.mode){const o=n.mode==="inline"||n.mode==="lines"?n.mode:"reference",d={path:n.path,mode:o};n.mode==="lines"&&typeof n.startLine=="number"&&typeof n.endLine=="number"&&(d.lines={start:n.startLine,end:n.endLine}),c.push(d)}}}c.length>0&&s.set(r.id,c)}return s}const Ca=a.memo(function({message:s,onExpand:i}){const r=me();let c="";for(const v of s.content){const h=at(v);if(h&&h.text.trim()){const x=Kt(h.text);x?c=`skill:${x.name}`+(x.userMessage?` · ${x.userMessage.replace(/\s+/g," ").trim()}`:""):c=h.text.replace(/\s+/g," ").trim();break}}if(!c&&s.role==="custom"&&s.customType==="file"){const v=s.details??{};c=v.name??v.path??""}c.length>90&&(c=`${c.slice(0,90)}…`);let n=0,o=0,d=0,p=0;for(const v of s.content)cn(v)?n++:dn(v)?o++:pn(v)?d++:un(v)&&p++;const m=[];return n&&m.push(`${r("thinking")} ${n}`),o&&m.push(`${r("toolCalls")} ${o}`),d&&m.push(`${r("bashRuns")} ${d}`),p&&m.push(`${r("images")} ${p}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${r("expandMsg")} · ${c||m.join(" · ")||s.role}`,onClick:()=>i(s.id),children:[e.jsx("span",{className:`msg-collapsed-role role-${s.role}`,children:s.role==="custom"&&s.customType==="file"?r("attachment"):mn(s.role,r)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),m.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:m.map((v,h)=>e.jsx("span",{className:"msg-collapsed-chip",children:v},h))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:Sa(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(qe,{})," ",r("expandMsg")]})]})});function Sa(t){const s=new Date(t),i=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${i}:${r}`}const Ta=a.memo(function({id:s,show:i,height:r,containerRef:c,onMeasured:l,lazyRef:n,children:o}){const d=a.useRef(null),p=a.useRef(null);return a.useLayoutEffect(()=>{const m=p.current;if(p.current=i,!i||m!==!1)return;const v=d.current,h=c.current;if(!v||!h)return;const x=v.offsetHeight;l==null||l(s,x);const N=x-r;if(N!==0){const M=v.parentElement;M&&M.getBoundingClientRect().bottom<=h.getBoundingClientRect().top&&(h.scrollTop+=N)}},[i]),i?e.jsx("div",{ref:n,"data-lazy-id":s,children:e.jsx("div",{ref:d,children:o})}):e.jsx("div",{ref:n,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:r},"aria-hidden":"true"})});function Ea(t,s,i,r){const c=[],l=[];let n=0;for(const o of t){if(i.has(o.id))continue;o.top<s.bottom&&o.bottom>s.top?r.has(o.id)&&c.push(o.id):r.has(o.id)||(l.push(o.id),o.bottom<=s.top&&(n+=o.bottom-o.top))}return{show:c,hide:l,shrinkAbove:n}}function Ma(t,s){if(s.show.length===0&&s.hide.length===0)return t;const i=new Set(t);for(const r of s.show)i.delete(r);for(const r of s.hide)i.add(r);return i}function Pa(t,s,i){const r=new Set;let c=0;for(let l=t.length-1;l>=0&&!(l<t.length-1&&c>=i);l--){const n=t[l];r.add(n.id),c+=s.get(n.id)??hn(n.role,n.customType)}return r}function hn(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}}const Ra=["text","thinking","argumentsText","output","command"];function Ia(t){let s=0;for(const i of t.content){i.type==="image"&&(s+=1);for(const r of Ra){const c=i[r];typeof c=="string"&&(s+=c.length)}}return s}function La(t,s,i,r){const c=i.get(t);return c&&c.len===s?c.h:r}function Da(t){const s=[];for(const i of t.content)i.type==="text"&&typeof i.text=="string"&&s.push(i.text);return s.join(`
|
|
317
317
|
`)}function Ba(t,s){const i=[];for(const r of t.content)if(r.type==="text"&&typeof r.text=="string")i.push(r.text);else if(r.type==="thinking"&&typeof r.thinking=="string")i.push(r.thinking);else if(r.type==="toolCall"){if(typeof r.name=="string"&&i.push(r.name),typeof r.argumentsText=="string"&&i.push(r.argumentsText),typeof r.id=="string"){const c=s.get(r.id);if(c){const l=Da(c);l&&i.push(l)}}}else r.type==="bash"&&(typeof r.command=="string"&&i.push(r.command),typeof r.output=="string"&&i.push(r.output));return i.join(`
|
|
318
|
-
`)}function _a(t,s){let i=0,r=t.indexOf(s);for(;r!==-1;)i++,r=t.indexOf(s,r+s.length);return i}function Aa(t,s,i,r){const c=new Map,l=i.toLowerCase();if(!l)return c;for(const n of t){if(!s.has(n.id))continue;const o=_a(Ba(n,r).toLowerCase(),l);o>0&&c.set(n.id,o)}return c}function Fa(t,s){var l;const i=[],r=s.toLowerCase();if(!r)return i;const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(n){const o=n.parentElement;return!o||o.closest(".search-bar")||o.closest(".msg-collapsed")?NodeFilter.FILTER_REJECT:(n.textContent??"").toLowerCase().includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let n=c.nextNode();n;n=c.nextNode()){const o=(n.textContent??"").toLowerCase();if(!((l=n.parentElement)!=null&&l.closest("[data-msg-id]")))continue;let d=o.indexOf(r);for(;d!==-1;){const p=document.createRange();p.setStart(n,d),p.setEnd(n,d+r.length),i.push(p),d=o.indexOf(r,d+r.length)}}return i}function $a(t,s,i,r,c){var d;const l=Aa(i,r,s,c),n=new Map;for(const p of Fa(t,s)){const m=(d=p.startContainer.parentElement)==null?void 0:d.closest("[data-msg-id]");if(!(m!=null&&m.dataset.msgId))continue;const v=n.get(m.dataset.msgId);v?v.push(p):n.set(m.dataset.msgId,[p])}const o=[];for(const p of i){const m=n.get(p.id);if(m)for(let h=0;h<m.length;h++)o.push({kind:"dom",range:m[h],msgId:p.id,k:h});const v=l.get(p.id);if(v)for(let h=0;h<v;h++)o.push({kind:"folded",msgId:p.id,k:h})}return o}function Tt(t,s){return t.findIndex(i=>i.msgId===s.msgId&&i.k===s.k)}function Me(t,s){const i=CSS;if(!i.highlights)return;if(s.length===0){i.highlights.delete(t);return}const r=window.Highlight;r&&i.highlights.set(t,new r(...s))}function Ha(t,s){const i=[];let r=t;for(;r&&r!==s;){const c=getComputedStyle(r);/(auto|scroll|hidden)/.test(c.overflowY+c.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&i.push(r),r=r.parentElement}return i}function Oa(t,s){const i=s.startContainer.parentElement;for(const o of Ha(i,t)){const d=s.getBoundingClientRect(),p=o.getBoundingClientRect();if(d.height<=0||d.width<=0)return;d.top>=p.top+4&&d.bottom<=p.bottom-4||(o.scrollTop+=d.top-p.top-(o.clientHeight-d.height)/2),d.left>=p.left+4&&d.right<=p.right-4||(o.scrollLeft+=d.left-p.left-(o.clientWidth-d.width)/2)}const r=s.getBoundingClientRect(),c=t.getBoundingClientRect();if(r.height<=0||r.width<=0)return;const l=r.top>=c.top+6&&r.bottom<=c.bottom-6,n=r.left>=c.left+6&&r.right<=c.right-6;l&&n||(l||(t.scrollTop+=r.top-c.top-(c.height-r.height)/2),n||(t.scrollLeft+=r.left-c.left-(c.width-r.width)/2))}function Wa({containerRef:t,messages:s,collapsedIds:i,toolResults:r,onExpand:c,onProgrammaticScroll:l,open:n,onClose:o}){const d=me(),p=a.useRef(null),[m,v]=a.useState(""),[h,x]=a.useState(null),[N,M]=a.useState(0),[C,I]=a.useState(0),j=a.useDeferredValue(m),z=n?j.trim():"",H=a.useRef(null);H.current=h;const R=a.useRef([]),A=a.useRef({key:null}),P=a.useRef("");a.useEffect(()=>{n&&(x(null),requestAnimationFrame(()=>{var _;return(_=p.current)==null?void 0:_.select()}))},[n]),a.useEffect(()=>{if(!n)return;const _=Y=>{Y.key==="Escape"&&(Y.preventDefault(),Y.stopPropagation(),o())};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[n,o]),a.useEffect(()=>(n||(Me("msg-search",[]),Me("msg-search-active",[])),()=>{Me("msg-search",[]),Me("msg-search-active",[])}),[n]),a.useLayoutEffect(()=>{const _=()=>{M(0),x(null),I(0),R.current=[],Me("msg-search",[]),Me("msg-search-active",[]),A.current={key:null},P.current=""};if(!n||!z){_();return}const Y=t.current;if(!Y)return;let X=!1,O=0;return O=requestAnimationFrame(()=>{var ie,se;if(X)return;const G=$a(Y,z,s,i,r);R.current=G;const q=G.length;if(M(q),q===0){x(null),I(0),Me("msg-search",[]),Me("msg-search-active",[]),A.current={key:null},P.current=z;return}const k=H.current;let w;if(k){if(w=Tt(G,k),w===-1){const u=[];for(let W=0;W<G.length;W++)G[W].msgId===k.msgId&&u.push(W);if(u.length>0){const W=Math.min(k.k,u.length-1);w=u[W]}else w=0}}else w=0;w<0&&(w=0),w>=q&&(w=q-1),(!k||k.msgId!==G[w].msgId||k.k!==G[w].k)&&x({msgId:G[w].msgId,k:G[w].k}),I(w);const $=G[w],J=A.current,Z=((ie=J.key)==null?void 0:ie.msgId)!==$.msgId||((se=J.key)==null?void 0:se.k)!==$.k||J.kind==="folded"&&$.kind==="dom"||z!==P.current;A.current={key:{msgId:$.msgId,k:$.k},kind:$.kind},P.current=z;const S=G.filter(u=>u.kind==="dom").map(u=>u.range);if(Me("msg-search",S),$.kind==="folded"){Me("msg-search-active",[]),Z&&c($.msgId);return}Me("msg-search-active",[$.range]),Z&&(l==null||l(),Oa(Y,$.range))}),()=>{X=!0,cancelAnimationFrame(O)}},[n,z,s,t,h,i,r,c,l]);const T=a.useCallback(_=>{const Y=R.current,X=Y.length;if(X===0)return;const O=H.current,G=O?Tt(Y,O):0,q=Y[(G+_+X)%X];x(q.kind==="dom"||q.kind==="folded"?{msgId:q.msgId,k:q.k}:null)},[]);if(!n)return null;const f=h?(()=>{const _=Tt(R.current,h);return _===-1?0:_})():0;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:p,className:"search-input",type:"text",value:m,placeholder:d("searchPlaceholder"),onChange:_=>{v(_.target.value)},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),T(_.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${N===0?"empty":""}`,children:N===0?d("searchNoResults"):`${Math.min(f+1,N)}/${N}`}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchPrev"),disabled:N===0,onClick:()=>T(-1),children:e.jsx(ft,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchNext"),disabled:N===0,onClick:()=>T(1),children:e.jsx(qe,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchClose"),onClick:o,children:e.jsx(Ne,{})})]})}function Ua(t){const{dSt:s,dSh:i,escaped:r,graceActive:c,stuck:l}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:i<0?{flipEscape:!1,reassert:l&&!r}:{flipEscape:!0,reassert:!1}}const gn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],fn="pi-web-ui:prompt-templates";function qa(){try{const t=localStorage.getItem(fn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(i=>!!i&&typeof i=="object"&&typeof i.id=="string"):[]}catch{return[]}}function Ts(t){return gn.some(s=>s.id===t)}function lt(t){return typeof t.title=="string"}const xn=a.createContext(null);function vn(){const t=a.useContext(xn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function Ka({send:t,children:s}){const i=me(),[r,c]=a.useState(qa),[l,n]=a.useState(!1),[o,d]=a.useState(null),[p,m]=a.useState(!1),[v,h]=a.useState(!1),[x,N]=a.useState(!1);a.useEffect(()=>{try{localStorage.setItem(fn,JSON.stringify(r))}catch{}},[r]);const M=a.useMemo(()=>{const O=new Map,G=new Set;for(const w of r)w.hidden?G.add(w.id):(lt(w)&&!Ts(w.id)||lt(w))&&O.set(w.id,w);const q=gn.filter(w=>!G.has(w.id)).map(w=>{const $=O.get(w.id);return{id:w.id,icon:($==null?void 0:$.icon)??w.icon,title:($==null?void 0:$.title)??i(w.titleKey),desc:($==null?void 0:$.desc)??i(w.descKey),prompt:($==null?void 0:$.prompt)??i(w.promptKey),builtin:!0}}),k=r.filter(w=>lt(w)&&!Ts(w.id)).map(w=>({id:w.id,icon:w.icon??"📌",title:w.title??"",desc:w.desc??"",prompt:w.prompt??""}));return[...q,...k]},[r,i]),C=a.useCallback(()=>n(!0),[]),I=a.useCallback(O=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:O}))},[]),j=a.useCallback((O,G=!1)=>{N(G),O?(m(!1),d({...O})):(m(!0),d({id:_e(),icon:"📌",title:"",desc:"",prompt:""}))},[]),z=a.useCallback(()=>{n(!1),d(null),N(!1)},[]),H=a.useCallback(()=>{v?(c([]),h(!1)):(h(!0),setTimeout(()=>h(!1),5e3))},[v]),R=a.useCallback(O=>{n(!1),I(O.prompt)},[I]),A=a.useCallback(O=>{n(!1),j(O,!0)},[j]),P=a.useCallback(()=>{n(!1),j(void 0,!0)},[j]),T=a.useCallback(O=>{c(G=>{const q=G.findIndex(k=>k.id===O.id);if(q>=0){const k=[...G];return k[q]=O,k}return[...G,O]}),d(null),x&&(n(!0),N(!1))},[x]),f=a.useCallback(O=>{c(G=>O.builtin?[...G.filter(k=>k.id!==O.id),{id:O.id,hidden:!0}]:G.filter(q=>q.id!==O.id)),d(null),x&&(n(!0),N(!1))},[x]),_=a.useCallback(O=>{c(G=>G.filter(q=>q.id!==O.id||q.hidden)),d(null),x&&(n(!0),N(!1))},[x]),Y=a.useMemo(()=>({templates:M,fill:I,openPicker:C,openEdit:j,resetConfirm:v,toggleReset:H}),[M,I,C,j,v,H]),X=o?r.some(O=>O.id===o.id&&!O.hidden&<(O)):!1;return e.jsxs(xn.Provider,{value:Y,children:[s,l&&e.jsx(Va,{templates:M,resetConfirm:v,onFill:R,onEditTpl:A,onNew:P,onResetToggle:H,onClose:z}),o&&e.jsx(Ga,{editing:o,isNew:p,hasOverride:X,onDraft:d,onSave:T,onRestore:()=>_(o),onRemove:()=>f(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),z()},onSend:()=>{const O=o.prompt.trim();O&&t({type:"prompt",text:O,queue:!1})&&z()},onClose:z})]})}function za(){const t=me(),{templates:s,fill:i,openEdit:r,toggleReset:c,resetConfirm:l}=vn();return e.jsxs("div",{className:"empty-templates",children:[e.jsxs("div",{className:"empty-templates-head",children:[e.jsx("span",{className:"empty-templates-title",children:t("tpl.title")}),e.jsx("span",{className:"empty-templates-hint",children:t("tpl.hint")})]}),e.jsxs("div",{className:"empty-templates-grid",children:[s.map(n=>e.jsx(yn,{tpl:n,title:t("tpl.clickCard"),onFill:()=>i(n.prompt),onEdit:()=>r(n),editTitle:t("tpl.editTpl")},n.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>r(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(zs,{}),t(l?"tpl.resetConfirm":"tpl.reset")]})})]})}function yn({tpl:t,title:s,onFill:i,onEdit:r,editTitle:c}){const l=me();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:i,children:[e.jsx("span",{className:"empty-template-icon",children:t.icon}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t.title}),e.jsx("span",{className:"empty-template-desc",children:t.desc})]}),e.jsx("span",{className:"template-card-ops",role:"button",title:c??l("tpl.editTpl"),onClick:n=>{n.stopPropagation(),r()},children:e.jsx(Dt,{})})]})}function Va({templates:t,resetConfirm:s,onFill:i,onEditTpl:r,onNew:c,onResetToggle:l,onClose:n}){const o=me();return a.useEffect(()=>{const d=p=>{p.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal template-picker",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"template-picker-head",children:[e.jsx("span",{className:"template-picker-title",children:o("tpl.pickerTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:o("close"),onClick:n,children:e.jsx(Ne,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(d=>e.jsx(yn,{tpl:d,title:o("tpl.clickCard"),onFill:()=>i(d),onEdit:()=>r(d),editTitle:o("tpl.editTpl")},d.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:c,title:o("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:l,children:[e.jsx(zs,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Ga({editing:t,isNew:s,hasOverride:i,onDraft:r,onSave:c,onRestore:l,onRemove:n,onFill:o,onSend:d,onClose:p}){const m=me(),v=a.useRef(null);a.useEffect(()=>{const N=M=>{M.key==="Escape"&&p()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[p]),a.useEffect(()=>{const N=v.current;if(!N)return;N.style.height="auto";const M=N.scrollHeight>300;N.style.height=`${Math.min(N.scrollHeight,300)}px`,N.style.overflowY=M?"auto":"hidden"},[t.prompt]);const h=()=>{const N=t.title.trim(),M=t.prompt.trim();if(!N||!M){r({...t,error:m("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:N,desc:t.desc.trim(),prompt:M})},x=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:p,children:e.jsxs("div",{className:"modal template-modal",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"template-modal-head",children:[e.jsx("span",{className:"template-modal-icon",children:t.icon}),e.jsx("span",{className:"template-modal-badge",children:m(x?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:m(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:m("close"),onClick:p,children:e.jsx(Ne,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:N=>r({...t,icon:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:m("tpl.fieldTitlePh"),onChange:N=>r({...t,title:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:m("tpl.fieldDescPh"),onChange:N=>r({...t,desc:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldPrompt")}),e.jsx("textarea",{ref:v,className:"template-field-prompt",value:t.prompt,placeholder:m("tpl.fieldPromptPh"),onChange:N=>r({...t,prompt:N.target.value})})]}),t.error&&e.jsx("div",{className:"template-error",children:t.error}),e.jsxs("div",{className:"template-modal-actions",children:[e.jsxs("div",{className:"template-modal-actions-left",children:[!s&&x&&i&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:m("tpl.restoreTip"),onClick:l,children:m("tpl.restore")}),!s&&x&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:m("tpl.removeTip"),onClick:n,children:[e.jsx(De,{})," ",m("tpl.remove")]}),!s&&!x&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:m("tpl.deleteTip"),onClick:n,children:[e.jsx(De,{})," ",m("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:h,children:m("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:m("tpl.fillTip"),children:m("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:d,title:m("tpl.sendTip"),children:[e.jsx(Ks,{})," ",m("tpl.sendNow")]})]})]})]})})}const Es=new Map,Qa=15,Ms=30,Et=250,Ps=1200,Ya=1600;function Rs(t){return t.content.some(s=>s.type==="toolCall")}function Ja({state:t,liveOutputs:s,toolStatuses:i,onEdit:r,onKillBash:c,thinkingWrap:l,toolsWrap:n,jumpTarget:o,onJumpDone:d}){const p=me(),m=a.useRef(null),[v,h]=a.useState(!0),x=a.useRef(!0),N=a.useRef(0),M=a.useRef(0),C=a.useRef(!1),I=a.useRef(0),[j,z]=a.useState(()=>new Set),[H,R]=a.useState(!1),A=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,P=a.useMemo(()=>{const b=new Map;for(const L of t.messages)L.role==="toolResult"&&L.toolCallId&&b.set(L.toolCallId,L);return b},[t.messages]),T=a.useMemo(()=>Na(t.messages),[t.messages]),f=A.length>0?A[A.length-1].id:null,_=t.messages.length>Ms?Math.max(0,t.messages.length-Qa):0,Y=a.useMemo(()=>{const b=new Set;for(let L=0;L<_;L++){const ne=t.messages[L];ne.role!=="toolResult"&&(j.has(ne.id)||b.add(ne.id))}return b},[t.messages,_,j]),[X,O]=a.useState(()=>new Set),[G,q]=a.useState(()=>new Set),k=a.useRef(new Map),w=a.useRef(new Map),$=a.useRef(new Map),J=a.useRef(0),Z=a.useMemo(()=>{const b=new Map;for(const L of t.messages)b.set(L.id,Ia(L));return b},[t.messages]),S=a.useRef(Z);S.current=Z;const ie=a.useRef(X);ie.current=X;const se=t.messages.length>Ms&&!H,u=a.useRef(se);u.current=se;const W=Pa(t.messages,k.current,Ya),D=a.useRef(W);D.current=W;const U=a.useCallback(()=>{const b=m.current;if(!b)return;if(!u.current){O(fe=>fe.size?new Set:fe);return}const L=b.getBoundingClientRect(),ne={top:L.top-Ps,bottom:L.bottom+Ps},re=[];for(const[fe,we]of $.current){const Ie=we.getBoundingClientRect();re.push({id:fe,top:Ie.top,bottom:Ie.bottom}),ie.current.has(fe)||oe(fe,Ie.bottom-Ie.top,S.current.get(fe))}const ge=Ea(re,ne,D.current,ie.current);for(const fe of ge.hide){const we=$.current.get(fe);we&&oe(fe,we.offsetHeight,S.current.get(fe))}O(fe=>Ma(fe,ge))},[]),K=a.useCallback(()=>{J.current||(J.current=requestAnimationFrame(()=>{J.current=0,U()}))},[U]);a.useLayoutEffect(()=>{U()},[U]);const te=a.useRef(H);a.useLayoutEffect(()=>{te.current&&!H&&U(),te.current=H},[H,U]);const oe=a.useCallback((b,L,ne)=>{ne!==void 0&&(w.current.set(b,{h:L,len:ne}),k.current.set(b,L))},[]),ve=a.useCallback((b,L)=>{oe(b,L,S.current.get(b))},[oe]),y=a.useCallback(b=>{b&&$.current.set(b.dataset.lazyId??"",b)},[]);a.useEffect(()=>{const b=new Set(t.messages.map(L=>L.id));for(const[L,ne]of $.current)b.has(L)||($.current.delete(L),k.current.delete(L),w.current.delete(L));O(L=>{let ne=!1;const re=new Set;for(const ge of L)b.has(ge)?re.add(ge):ne=!0;return ne?re:L})},[t.messages,j]),a.useEffect(()=>()=>cancelAnimationFrame(J.current),[]);const V=a.useMemo(()=>{const b=[];for(const L of t.messages){if(L.role!=="user")continue;const ne=L.content.map(fe=>{var we;return((we=at(fe))==null?void 0:we.text)??""}).filter(Boolean).join(" "),re=Kt(ne),ge=re?re.userMessage??`skill:${re.name}`:ne.trim();ge&&b.push({id:L.id,text:ge})}return b},[t.messages]),de=a.useMemo(()=>{const b=new Map;return V.forEach((L,ne)=>b.set(L.id,ne)),b},[V]),[g,F]=a.useState(-1),ae=a.useRef(-1),he=a.useRef(V);a.useEffect(()=>{he.current=V},[V]);const xe=a.useCallback(()=>{const b=m.current,L=he.current;if(!b||L.length===0)return;const ne=b.getBoundingClientRect().top,re=140;let ge=-1;for(let fe=0;fe<L.length;fe++){const we=b.querySelector(`[data-msg-id="${L[fe].id}"]`);if(we)if(we.getBoundingClientRect().top<=ne+re)ge=fe;else break}ge!==ae.current&&(ae.current=ge,F(ge))},[]);a.useEffect(()=>{xe()},[V,xe]);const ue=a.useCallback(b=>{z(L=>L.has(b)?L:new Set(L).add(b))},[]);a.useEffect(()=>{const b=L=>{if(!(L.ctrlKey||L.metaKey)||L.key.toLowerCase()!=="f")return;const ne=L.target;ne&&(ne.tagName==="INPUT"||ne.tagName==="TEXTAREA"||ne.isContentEditable)||(L.preventDefault(),R(!0))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]);const Pe=a.useCallback(b=>{z(L=>{if(!L.has(b))return L;const ne=new Set(L);return ne.delete(b),ne})},[]),Te=a.useCallback(b=>{const L=t.messages.findIndex(re=>re.id===b);Zi.flushSync(()=>{L>=0&&L<_&&!j.has(b)&&ue(b),q(re=>re.has(b)?re:new Set(re).add(b))});const ne=he.current.findIndex(re=>re.id===b);ae.current=ne,F(ne),requestAnimationFrame(()=>{var ge,fe,we;const re=(ge=m.current)==null?void 0:ge.querySelector(`[data-msg-id="${b}"]`);re&&((fe=m.current)==null||fe.querySelectorAll(".msg-flash").forEach(Ie=>Ie.classList.remove("msg-flash")),re.scrollIntoView({block:"start"}),re.classList.remove("msg-flash"),re.offsetWidth,re.classList.add("msg-flash"),re!==((we=m.current)==null?void 0:we.lastElementChild)&&(C.current=!0))})},[t.messages,_,j,ue]),Ae=a.useMemo(()=>{var b;return o?((b=t.messages.find(L=>L.role===o.role&&L.timestamp===o.timestamp))==null?void 0:b.id)??null:null},[t.messages,o]);a.useEffect(()=>{if(o){if(Ae){Te(Ae),d==null||d();return}t.sessionFile===o.path&&t.messages.length>0&&(d==null||d())}},[Ae,Te,d,o,t.sessionFile,t.messages.length]);const Xe=a.useCallback(()=>{const b=m.current;if(!b)return;const L=b.scrollTop-N.current,ne=b.scrollHeight-M.current;N.current=b.scrollTop,M.current=b.scrollHeight;const re=b.scrollHeight-b.scrollTop-b.clientHeight<80,ge=Date.now()<I.current,fe=Ua({dSt:L,dSh:ne,escaped:C.current,graceActive:ge,stuck:x.current});fe.reassert&&(I.current=Date.now()+Et,b.scrollTop=b.scrollHeight),fe.flipEscape&&(C.current=!0),re&&L>=0&&(C.current=!1),ge||(L<0?x.current=re&&!C.current:re&&(x.current=!0)),h(x.current),xe(),K()},[xe,K]),Se=a.useRef(!1);a.useEffect(()=>{const b=Se.current;if(Se.current=!!t.isStreaming,b&&!t.isStreaming&&!C.current){const L=()=>{const re=m.current;re&&!C.current&&(re.scrollTop=re.scrollHeight,x.current=!0,h(!0))};requestAnimationFrame(()=>requestAnimationFrame(L));const ne=setTimeout(L,180);return()=>clearTimeout(ne)}},[t.isStreaming]),a.useEffect(()=>{const b=m.current;b&&x.current&&(b.scrollTop=b.scrollHeight)},[A,t.isStreaming,s]);const Ke=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");a.useEffect(()=>{const b=m.current;b&&x.current&&(b.scrollTop=b.scrollHeight)},[Ke]),a.useEffect(()=>{const b=m.current;if(!b||typeof ResizeObserver>"u")return;const L=new ResizeObserver(()=>{x.current&&!C.current&&(b.scrollTop=b.scrollHeight,h(!0))});return L.observe(b),()=>L.disconnect()},[]),a.useEffect(()=>{const b=m.current;if(!b||typeof MutationObserver>"u")return;let L=!1;const ne=new MutationObserver(()=>{L||(L=!0,requestAnimationFrame(()=>{L=!1;const re=m.current;re&&x.current&&!C.current&&(re.scrollTop=re.scrollHeight,h(!0))}))});return ne.observe(b,{childList:!0,subtree:!0,characterData:!0}),()=>ne.disconnect()},[]);const Oe=a.useCallback(()=>{if(!m.current)return;x.current=!0,C.current=!1,h(!0),I.current=Date.now()+Et;const L=()=>{const ne=m.current;!ne||!x.current||C.current||(I.current=Date.now()+Et,ne.scrollTop=ne.scrollHeight)};L(),requestAnimationFrame(()=>requestAnimationFrame(L)),setTimeout(L,120),setTimeout(L,300),setTimeout(L,600)},[]),We=a.useRef(null);a.useEffect(()=>{const b=We.current,L=m.current;if(!b||!L)return;const ne=re=>{re.preventDefault();const ge=b.querySelector(".qn-list");if(ge&&ge.contains(re.target)&&ge.scrollHeight>ge.clientHeight){ge.scrollTop+=re.deltaY;return}L.scrollTop+=re.deltaY};return b.addEventListener("wheel",ne,{passive:!1}),()=>b.removeEventListener("wheel",ne)},[]);const[Re,E]=a.useState(0);a.useEffect(()=>{const b=()=>{var L;E(((L=m.current)==null?void 0:L.clientHeight)??0),K()};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[K]);const pe=V.length,ce=a.useMemo(()=>pe===0?27:Math.max(4,Math.min(27,Math.floor(((Re||600)-16)/pe)-3)),[pe,Re]),ke=ce<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${H||v?"":" anchor-live"}`,ref:m,onScroll:Xe,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(za,{})}),t.messages.map((b,L)=>{const ne=L<_,re=ne&&j.has(b.id);if(ne&&!re)return b.role==="toolResult"?null:e.jsx(Ca,{message:b,onExpand:ue},b.id);const ge=b.role==="user"?de.get(b.id):void 0,fe=!se||W.has(b.id)||G.has(b.id)||!X.has(b.id);return e.jsx(Ta,{id:b.id,show:fe,height:La(b.id,Z.get(b.id)??-1,w.current,hn(b.role,b.customType)),containerRef:m,onMeasured:ve,lazyRef:y,children:e.jsx(ws,{message:b,qnIndex:ge,qnActive:ge!==void 0?ge===g:void 0,onJump:Te,toolResults:P,liveOutputs:Rs(b)?s:Es,toolStatuses:i,streaming:t.isStreaming,onKillBash:c,toolsWrap:n,thinkingWrap:l,isLast:b.id===f,onEdit:r,questionAttachments:T.get(b.id),onCollapse:re?Pe:void 0,searchActive:H},b.id)},b.id)}),t.streamingMessage&&e.jsx(ws,{message:t.streamingMessage,toolResults:P,liveOutputs:Rs(t.streamingMessage)?s:Es,toolStatuses:i,streaming:!0,isLast:!0,onEdit:r,onKillBash:c,toolsWrap:n,thinkingWrap:l,searchActive:H},t.streamingMessage.id),t.isStreaming&&A.length===0&&e.jsx("div",{className:"streaming-wait",children:p("waitingResponse")}),t.queue.steering.map((b,L)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:p("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-steer-${L}`)),t.queue.followUp.map((b,L)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:p("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-fu-${L}`))]}),!v&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Oe,children:[e.jsx(Xs,{})," ",p("backToBottom")]}),e.jsx(Wa,{containerRef:m,messages:A,collapsedIds:Y,toolResults:P,onExpand:ue,onProgrammaticScroll:()=>{C.current=!0,x.current=!1,h(!1)},open:H,onClose:()=>R(!1)}),V.length>0&&e.jsxs("div",{className:`qn-rail ${ke?"many":""}`,ref:We,"aria-label":p("questionNavTitle"),style:{"--rail-gap":`${ce}px`},children:[V.map((b,L)=>e.jsx("button",{type:"button",className:`qn-bar ${L===g?"active":""}`,"aria-label":`${L+1}. ${b.text}`,onClick:()=>Te(b.id),children:e.jsxs("span",{className:"qn-bar-text",children:[L+1,". ",b.text]})},b.id)),ke&&e.jsx("div",{className:"qn-list",children:V.map((b,L)=>e.jsxs("button",{type:"button",className:`qn-list-item ${L===g?"active":""}`,"aria-label":`${L+1}. ${b.text}`,onClick:()=>Te(b.id),children:[e.jsx("span",{className:"qn-list-idx",children:L+1}),e.jsx("span",{className:"qn-list-text",children:b.text})]},b.id))})]})]})}const kn="pi-web-model-usage";function Xa(t){if(!t||typeof t!="object")return{};const s={};for(const[i,r]of Object.entries(t)){const c=typeof r=="number"?Math.floor(r):0;Number.isFinite(c)&&c>0&&(s[i]=c)}return s}function Za(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function er(t,s){const i=s;return t.map((r,c)=>({m:r,i:c,count:i[r.id]??0})).sort((r,c)=>c.count-r.count||r.i-c.i).map(r=>r.m)}function bn(){try{const t=localStorage.getItem(kn);return t?Xa(JSON.parse(t)):{}}catch{return{}}}function tr(t){try{localStorage.setItem(kn,JSON.stringify(t))}catch{}}function sr(t){const s=Za(bn(),t);return tr(s),s}const nr=["off","minimal","low","medium","high","xhigh","max"],ir=a.memo(function({state:s,models:i,modelsLoading:r,send:c,onManageModels:l,compact:n=!1}){const o=me(),d=s==null?void 0:s.model,p=d?`${d.provider}/${d.id}`:null,[m,v]=a.useState(!1),[h,x]=a.useState(!1),[N,M]=a.useState(""),[C,I]=a.useState(null),[j,z]=a.useState({}),H=a.useRef(null),R=a.useRef(null),[A,P]=a.useState(null);a.useEffect(()=>{if(!m){P(null);return}if(i.length===0)return;const k=requestAnimationFrame(()=>{const w=R.current;w&&P(w.offsetWidth)});return()=>cancelAnimationFrame(k)},[m,i.length]),a.useEffect(()=>{m&&z(bn())},[m]),a.useEffect(()=>{m||(M(""),I(null))},[m]);const T=a.useMemo(()=>{const k=new Map;for(const w of i)k.set(w.provider,(k.get(w.provider)??0)+1);return[...k.entries()].sort((w,$)=>w[0].localeCompare($[0])).map(([w,$])=>({name:w,count:$}))},[i]),f=a.useMemo(()=>er(i,j),[i,j]),_=a.useMemo(()=>{let k=f;C&&(k=k.filter($=>$.provider===C));const w=N.trim().toLowerCase();return w?k.filter($=>$.name.toLowerCase().includes(w)||$.provider.toLowerCase().includes(w)||$.id.toLowerCase().includes(w)):k},[f,N,C]),[Y,X]=a.useState(!1),O=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,G=nr.map(k=>({value:k,label:o(`thinking.${k}`),supported:O?O.has(k):!0})),q=k=>{var w;return((w=G.find($=>$.value===k))==null?void 0:w.label)??k};return a.useEffect(()=>{m&&i.length===0&&!Y&&!r&&(X(!0),c({type:"list_models"}))},[m,i.length,Y,r,c]),a.useEffect(()=>{i.length>0&&X(!1)},[i.length]),a.useEffect(()=>{var w;if(!m)return;const k=(w=H.current)==null?void 0:w.querySelector(".dd-item.active");k==null||k.scrollIntoView({block:"nearest"})},[m,p,i.length]),e.jsxs(e.Fragment,{children:[e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(it,{}),e.jsx("span",{className:"chip-model",children:d?d.name:o("selectModel")}),!n&&(d==null?void 0:d.vision)&&e.jsx("span",{className:"chip-vision",title:o("vision"),children:"🖼"}),!n&&d&&e.jsx("span",{className:"chip-sub",children:d.provider})]}),open:m,onOpenChange:v,menuClassName:"dd-menu-model",menuRef:R,menuStyle:A!=null?{width:A}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(ht,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:o("searchModels"),value:N,onChange:k=>M(k.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[T.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:o("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${C===null?"active":""}`,onClick:()=>I(null),children:e.jsx("span",{children:o("allProviders")})}),T.map(k=>e.jsxs("button",{type:"button",className:`dd-provider-item ${C===k.name?"active":""}`,onClick:()=>I(C===k.name?null:k.name),title:`${k.name} · ${k.count}`,children:[e.jsx("span",{className:"dd-provider-name",children:k.name}),e.jsx("span",{className:"dd-provider-count",children:k.count})]},k.name))]}),e.jsxs("div",{className:"dd-model-scroll",ref:H,children:[(Y||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!Y&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),_.length===0&&i.length>0&&e.jsx("div",{className:"dd-loading",children:o("noModelMatches")}),_.map(k=>e.jsx(Ce,{active:p===k.id,onClick:()=>{p!==k.id&&c({type:"set_model",modelId:k.id}),v(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:k.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:k.provider}),(j[k.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:o("modelUsedCount",{n:j[k.id]})}),(k.reasoning||k.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[k.reasoning&&e.jsx("span",{className:"dd-model-badge",children:o("reasoning")}),k.vision&&e.jsx("span",{className:"dd-model-badge",children:o("vision")})]})]})]})},k.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:()=>{v(!1),l()},children:o("manageModels")})]})]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ot,{}),e.jsx("span",{className:"chip-sub",children:o("thinkingChip",{level:s?q(s.thinkingLevel):"—"})})]}),open:h,onOpenChange:x,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("thinkingLevel")}),G.map(k=>e.jsx(Ce,{active:(s==null?void 0:s.thinkingLevel)===k.value,disabled:!k.supported,title:k.supported?void 0:o("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==k.value&&c({type:"set_thinking",level:k.value}),x(!1)},children:k.label},k.value))]})]})}),ar=a.memo(function({ready:s,streaming:i,messages:r,slashCommands:c,modelState:l,models:n,modelsLoading:o,send:d,attachments:p,onRemoveAttachment:m,onAddImageFiles:v,onAddLocalFiles:h,onNotice:x,onSent:N,onManageModels:M}){const C=me(),{locale:I}=Ut(),{openPicker:j}=vn(),z=y=>I==="en"&&y.descriptionEn?y.descriptionEn:y.description??"",H=y=>I==="en"&&y.argumentHintEn?y.argumentHintEn:y.argumentHint??"",[R,A]=a.useState(""),[P,T]=a.useState(!1),[f,_]=a.useState(null),[Y,X]=a.useState(0),[O,G]=a.useState(!1),[q,k]=a.useState(void 0),w=a.useRef(null),$=a.useRef(null),J=a.useRef(null),Z={builtin:C("slashBuiltin"),extension:C("slashExtension"),prompt:C("slashPrompt"),skill:C("slashSkill"),plugin:C("slashPlugin")},S=y=>{const V=y.match(/^\/([^\s]*)$/);if(V&&s){const de=V[1].toLowerCase(),g=c.filter(F=>F.name.toLowerCase().startsWith(de));_(g.length>0?g:null),X(0)}else _(null)};a.useEffect(()=>{var V;const y=(V=J.current)==null?void 0:V.querySelector(".slash-item.active");y==null||y.scrollIntoView({block:"nearest"})},[Y,f]);const ie=y=>{var ae;const V=f??[],de=y??V[Y%Math.max(V.length,1)];if(!de){_(null);return}const g=R.match(/^\/([^\s]*)([\s\S]*)$/),F=g?g[2]:"";A(`/${de.name} ${F}`),_(null),(ae=w.current)==null||ae.focus()},se=async()=>{const V=[...r].reverse().find(g=>g.role==="assistant"&&g.content.some(F=>F.type==="text"&&F.text)),de=V==null?void 0:V.content.filter(g=>g.type==="text").map(g=>g.text).join(`
|
|
319
|
-
`);if(!de){x("warning",C("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(de),x("info",C("slashCopied"))}catch{x("error",C("slashCopyFailed"))}},u=y=>{if(!y||y.length===0){x("warning",C("foldersNotSupported"));return}const V=Array.from(y).filter(F=>Be(F.type)),de=Array.from(y).filter(F=>!Be(F.type)),g=D();V.length>0&&g?x("warning",g):V.length>0&&v(V),de.length>0&&h(de)},W=y=>{var F;const V=(F=y.clipboardData)==null?void 0:F.items;if(!V)return;const de=[];for(const ae of V)if(ae.kind==="file"&&Be(ae.type)){const he=ae.getAsFile();he&&de.push(he)}if(de.length===0)return;y.preventDefault();const g=D();if(g){x("warning",g);return}v(de)},D=()=>{const y=l==null?void 0:l.model;if(!(y!=null&&y.id))return null;const V=n.find(de=>de.id===y.id);return V&&V.vision===!1?C("modelNoVision",{name:V.name}):null},U=s,K=a.useRef(R);a.useEffect(()=>{K.current=R},[R]),a.useEffect(()=>{S(K.current)},[c]),a.useEffect(()=>{const y=V=>{var g;const de=V.detail;A(de),(g=w.current)==null||g.focus()};return window.addEventListener("pi-web:fill",y),()=>window.removeEventListener("pi-web:fill",y)},[]),a.useEffect(()=>{if(!O)return;const y=V=>{V.key==="Escape"&&G(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[O]),a.useEffect(()=>{const y=w.current;if(!y)return;y.style.height="auto";const V=y.scrollHeight>220;y.style.height=`${Math.min(y.scrollHeight,220)}px`,y.style.overflowY=V?"auto":"hidden"},[R]);const te=(y=!1)=>{var g,F,ae,he,xe;const V=R.trim(),de=p.some(ue=>ue.imageData||ue.fileData);if(!(!U||!V&&!de)){if(V==="/help"){const ue=(F=(g=w.current)==null?void 0:g.closest(".inputbox"))==null?void 0:F.getBoundingClientRect();k(ue==null?void 0:ue.width),G(!0),A(""),(ae=w.current)==null||ae.focus();return}if(V==="/copy"){A(""),(he=w.current)==null||he.focus(),se();return}if(d({type:"prompt",text:V,queue:y,attachments:p.map(ue=>ue.imageData?{path:"",imageData:ue.imageData,mimeType:ue.mimeType,name:ue.name}:ue.fileData?{path:"",fileData:ue.fileData,mimeType:ue.mimeType,name:ue.name,size:ue.size}:{path:ue.path,mode:ue.mode,...ue.lines?{lines:ue.lines}:{}})})){A(""),N();const ue=l==null?void 0:l.model;ue&&sr(`${ue.provider}/${ue.id}`),(xe=w.current)==null||xe.focus()}}},oe=y=>{if(!y.nativeEvent.isComposing){if(f&&f.length>0)switch(y.key){case"ArrowDown":y.preventDefault(),X(V=>(V+1)%f.length);return;case"ArrowUp":y.preventDefault(),X(V=>(V-1+f.length)%f.length);return;case"Tab":case"Enter":y.preventDefault(),ie();return;case"Escape":y.preventDefault(),_(null);return}y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),te())}},ve=()=>e.jsx("div",{className:"inputbox-actions",children:i?e.jsxs(e.Fragment,{children:[R.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:C("supplementTip"),onClick:()=>te(!0),children:[e.jsx(Ks,{})," ",C("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:C("stopAgent"),onClick:()=>d({type:"abort"}),children:e.jsx(pt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:C("sendTip"),disabled:!U||!R.trim()&&!p.some(y=>y.imageData||y.fileData),onClick:()=>te(),children:e.jsx(Js,{})})});return e.jsxs("div",{className:`inputbar${P?" drop-active":""}`,onDragOver:y=>{y.preventDefault(),y.stopPropagation(),T(!0)},onDragLeave:y=>{y.currentTarget.contains(y.relatedTarget)||T(!1)},onDrop:y=>{var V;y.preventDefault(),y.stopPropagation(),T(!1),u(((V=y.dataTransfer)==null?void 0:V.files)??null)},children:[P&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",C("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(y=>e.jsxs("span",{className:`attach-chip ${y.imageData?"image":y.fileData?"file":y.mode}`,title:y.imageData?C("attachImage",{name:y.name}):y.fileData?C("attachFile",{name:y.name}):y.isDir?C("folderRef",{path:y.path}):y.mode==="reference"?C("refOnly",{path:y.path}):y.mode==="lines"&&y.lines?C("attachLines",{path:y.path,start:y.lines.start,end:y.lines.end}):C("attachContent",{path:y.path}),children:[y.imageData?"🖼":y.fileData?"📄":y.isDir?"📁":y.mode==="reference"?"🔗":"📎"," ",y.name,y.mode==="lines"&&y.lines&&e.jsxs("span",{className:"attach-range",children:["L",y.lines.start,"-",y.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:C("removeAttachment"),onClick:()=>m(y.key??y.path),children:"×"})]},y.key??`${y.path}|${y.mode}|${y.lines?`${y.lines.start}-${y.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:C("attachHint")})]}),f&&f.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:J,"aria-label":C("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:C("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>_(null),children:"Esc"})]}),f.map((y,V)=>e.jsxs("button",{type:"button",className:`slash-item${V===Y?" active":""}`,onMouseEnter:()=>X(V),onClick:()=>ie(y),children:[e.jsxs("span",{className:"slash-name",children:["/",y.name]}),e.jsx("span",{className:`slash-source ${y.source}`,children:Z[y.source]}),e.jsxs("span",{className:"slash-desc",children:[z(y),y.argumentHint&&e.jsx("span",{className:"slash-hint",children:H(y)})]})]},y.name))]}),O&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:q?{width:q}:void 0,onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",C("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:C("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:C("slashLoading")}):c.map(y=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",y.name]}),e.jsx("span",{className:`slash-source ${y.source}`,children:Z[y.source]}),e.jsxs("span",{className:"slash-help-desc",children:[z(y),y.argumentHint&&e.jsx("span",{className:"slash-hint",children:H(y)})]})]},y.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:$,type:"file",multiple:!0,hidden:!0,onChange:y=>{u(y.target.files),y.target.value=""}}),e.jsx("textarea",{ref:w,value:R,rows:1,placeholder:C(U?i?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!U,onChange:y=>{A(y.target.value),S(y.target.value)},onKeyDown:oe,onPaste:W}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:C("uploadFile"),disabled:!U,onClick:()=>{var y;return(y=$.current)==null?void 0:y.click()},children:e.jsx(Xn,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:C("tpl.openPicker"),onClick:j,children:e.jsx(oi,{})}),e.jsx(ir,{state:l,models:n,modelsLoading:o,send:d,onManageModels:M,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:ve()})]})]})]})}),rr=a.memo(function({goal:s,models:i,modelsLoading:r,activeConversationId:c,engine:l,send:n}){var O,G,q,k,w,$;const o=me(),d=l==="dsh",p=!s.conversationId||s.conversationId===c,m=s.goal!==null&&p,[v,h]=a.useState(""),[x,N]=a.useState(s.reviewModel??""),[M,C]=a.useState(s.maxRounds),[I,j]=a.useState(s.locked),[z,H]=a.useState(!1),[R,A]=a.useState(!1),[P,T]=a.useState(!0);a.useEffect(()=>{N(s.reviewModel??""),C(s.maxRounds||0),j(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),a.useEffect(()=>{z&&i.length===0&&!R&&!r&&(A(!0),n({type:"list_models"}))},[z,i.length,R,r,n]),a.useEffect(()=>{i.length>0&&A(!1)},[i.length]);const f=()=>{var J;return x?((J=i.find(Z=>Z.id===x))==null?void 0:J.name)??x:o("goalBarUseMainModel")},_=()=>{const J=v.trim();J&&(n({type:"set_goal",goal:J,...x?{reviewModel:x}:{},maxRounds:M,locked:I}),h(""),T(!1))},Y=()=>{const J=v.trim();J&&(n({type:"start_goal_wizard",text:J,...x?{wizardModel:x}:{},maxRounds:M,locked:I}),h(""),T(!1))},X=(((O=s.wizard)==null?void 0:O.active)??!1)&&p;return X?e.jsx("div",{className:`goalbar goalbar-active ${X?"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:((G=s.wizard)==null?void 0:G.draft)??"",children:[o("goalWizardRunning"),": ",(q=s.wizard)==null?void 0:q.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarRound",{n:(((k=s.wizard)==null?void 0:k.step)??0)+1})," ","/ ",((w=s.wizard)==null?void 0:w.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:(($=s.wizard)==null?void 0:$.status)||o("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),onClick:()=>{n({type:"clear_goal"}),T(!0)},children:e.jsx(Ne,{})})]})}):m?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarReviewing")," ",o("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?o("goalBarPassed"):s.verdict==="fail"?o("goalBarFailed"):`${o("goalBarRound",{n:s.round||1})} · ${s.locked?o("goalBarLocked"):o("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:s.status}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),disabled:s.reviewing,onClick:()=>{n({type:"clear_goal"}),T(!0)},children:e.jsx(Ne,{})})]})}):P?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:o("goalBarPlaceholder"),onClick:()=>T(!1),children:[e.jsx(us,{})," ",e.jsx("span",{children:o("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(us,{})}),e.jsx("input",{className:"goalbar-input",value:v,placeholder:o("goalBarPlaceholder"),onChange:J=>h(J.target.value),onKeyDown:J=>{J.key==="Enter"&&_()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!v.trim(),onClick:_,children:o("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!v.trim(),title:o("goalWizardTip"),onClick:Y,children:["🔍 ",o("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o(I?"goalBarLocked":"goalBarUnlocked"),onClick:()=>j(J=>(n({type:"set_goal_prefs",locked:!J}),!J)),children:I?e.jsx(ii,{}):e.jsx(Gn,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o("goalBarClear"),onClick:()=>T(!0),children:e.jsx(ft,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[d?e.jsx("p",{className:"goalbar-dsh-note",children:o("dshNoReviewModel")}):e.jsxs($e,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[o("goalBarReviewModel"),": ",e.jsx("b",{children:f()})]}),open:z,onOpenChange:H,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("goalBarReviewModel")}),(R||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!R&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),e.jsx(Ce,{active:x==="",onClick:()=>{N(""),H(!1),n({type:"set_goal_prefs",reviewModel:""})},children:o("goalBarUseMainModel")}),i.map(J=>e.jsx(Ce,{active:x===J.id,onClick:()=>{N(J.id),H(!1),n({type:"set_goal_prefs",reviewModel:J.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:J.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:J.provider})})]})},J.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>n({type:"list_models"}),children:o("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:o("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:o("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:M,placeholder:o("goalBarUnlimitedShort"),onChange:J=>{const Z=parseInt(J.target.value,10);if(Number.isNaN(Z)||Z<0){C(0);return}C(Z)},onBlur:()=>n({type:"set_goal_prefs",maxRounds:M}),onKeyDown:J=>{J.key==="Enter"&&(n({type:"set_goal_prefs",maxRounds:M}),J.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:o(I?"goalBarLocked":"goalBarUnlocked")})]})]})});function lr({chat:t,send:s}){const i=me(),r=t.state,[c,l]=a.useState(!1),[n,o]=a.useState(""),[d,p]=a.useState(0),m=a.useRef(null),v=t.pathCompletions;if(a.useEffect(()=>{if(!c)return;const T=setTimeout(()=>{s({type:"complete_path",path:n})},150);return()=>clearTimeout(T)},[n,c,s]),a.useEffect(()=>p(0),[v]),a.useEffect(()=>{const T=document.querySelector(`.status-completions .pc-item[data-idx="${d}"]`);T==null||T.scrollIntoView({block:"nearest"})},[d]),!r)return null;const h=r.stats,x=t.ready?"ok":"busy",N=t.ready?i("connected"):i("connecting"),M=h.contextUsage,C=M.tokens!==null&&M.percent!==null?`${Is(M.tokens)} / ${Is(M.contextWindow)}`:"—",I=M.percent??null,j=I===null?"":I>=80?"warn":I>=50?"mid":"ok",z=r.queue.steering.length+r.queue.followUp.length,H=()=>{o(r.cwd),l(!0)},R=(T,f)=>{var Y;const _=T.includes("\\")?"\\":"/";o(f?`${T}${_}`:T),p(0),(Y=m.current)==null||Y.focus()},A=T=>{const f=T.trim();f&&f!==r.cwd&&s({type:"set_cwd",path:f}),l(!1)},P=T=>{if(T.key==="ArrowDown")T.preventDefault(),p(f=>Math.min(f+1,v.length-1));else if(T.key==="ArrowUp")T.preventDefault(),p(f=>Math.max(f-1,0));else if(T.key==="Tab"&&v.length>0){T.preventDefault();const f=v[Math.min(d,v.length-1)];R(f.path,f.type==="dir")}else if(T.key==="Enter"&&!T.nativeEvent.isComposing){const f=n.trim();if(f.endsWith("/")||f.endsWith("\\"))A(f);else if(v.some(_=>_.path===f))A(f);else if(v.length>0&&v[d]){T.preventDefault();const _=v[d];R(_.path,_.type==="dir")}else A(f)}else T.key==="Escape"&&(v.length>0?(T.stopPropagation(),s({type:"complete_path",path:""})):l(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${x}`,title:N}),e.jsx("span",{className:"status-item",children:N}),e.jsx("span",{className:"status-sep",children:"·"}),t.engine&&t.engine!=="pi"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`status-item engine-badge engine-${t.engine}`,title:`${i("engineBadge")}: ${t.engine}`,children:t.engine==="dsh"?"DSH":t.engine}),e.jsx("span",{className:"status-sep",children:"·"})]}),e.jsxs("span",{className:"status-item status-ctx",title:i("contextUsage"),children:[i("context"),e.jsx("span",{className:`ctx-bar ${j}`,children:I!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(I,100)}%`}})}),C]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("cumulativeCost"),children:["$",or(h.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("sessionMessages"),children:[i("messages")," ",h.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:i("pluginStatus"),children:t.statuses.map(T=>T.text).join(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),i("working"),z>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",z," ",i("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:m,className:"status-cwd-input",value:n,autoFocus:!0,placeholder:i("enterPath"),onChange:T=>o(T.target.value),onKeyDown:P,onBlur:()=>l(!1)}),v.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:T=>T.preventDefault(),children:v.map((T,f)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":f,className:`pc-item ${f===d?"sel":""}`,onMouseEnter:()=>p(f),onClick:()=>R(T.path,T.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:T.type==="dir"?e.jsx(Ye,{}):e.jsx(Vs,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:T.name}),e.jsx("span",{className:"pc-path",children:T.path})]})]})},T.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:i("cwdTip",{path:r.cwd}),onClick:H,children:["📁 ",r.cwd]})]})}function Is(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function or(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function cr({dialog:t,send:s}){const i=me(),[r,c]=a.useState(""),[l,n]=a.useState(0),o=m=>{s({type:"dialog_response",id:t.id,value:m})};a.useEffect(()=>{c(""),n(0);const m=v=>{v.key==="Escape"&&o(null)};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t.id]);const d=Array.isArray(t.args[0])?t.args[0]:[],p=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("pluginRequest")}),t.title&&t.title!==i("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[d.map((m,v)=>e.jsx("button",{type:"button",className:`dialog-option ${v===l?"sel":""}`,onMouseEnter:()=>n(v),onClick:()=>o(m),children:m},v)),d.length===0&&e.jsx("div",{className:"dialog-hint",children:i("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:p}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:i("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:r,placeholder:p||i("inputPlaceholder"),autoFocus:!0,onChange:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.nativeEvent.isComposing&&o(r)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(r),children:i("ok")})]})]})]})}function dr({question:t,send:s}){const i=me(),[r,c]=a.useState({}),[l,n]=a.useState({}),[o,d]=a.useState(()=>t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1);a.useEffect(()=>{c({}),n({}),d(t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1)},[t.id,t.deadline]),a.useEffect(()=>{if(!t.deadline)return;const h=setInterval(()=>{d(x=>{const N=Math.max(0,Math.ceil((t.deadline-Date.now())/1e3));return N<=0&&x>0&&s({type:"question_answer",id:t.id,answers:[],cancelled:!0}),N})},1e3);return()=>clearInterval(h)},[t.id,t.deadline]);const p=h=>{if(h){s({type:"question_answer",id:t.id,answers:[],cancelled:!0});return}const x=t.questions.map(N=>{const M=r[N.id]??[],C=(l[N.id]??"").trim();return{id:N.id,selected:M,...C?{custom:C}:{}}});s({type:"question_answer",id:t.id,answers:x})};a.useEffect(()=>{const h=x=>{x.key==="Escape"&&p(!0)};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t.id]);const m=(h,x,N)=>{c(M=>{const C=M[h]??[];return N?{...M,[h]:C.includes(x)?C.filter(I=>I!==x):[...C,x]}:{...M,[h]:[x]}})},v=t.questions.every(h=>{var x;return(((x=r[h.id])==null?void 0:x.length)??0)>0||(l[h.id]??"").trim()!==""});return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":"select",children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("modelQuestion")}),o>=0&&e.jsx("span",{className:"question-timer",children:o>0?i("questionTimeout",{s:o}):i("questionTimeoutExpired")}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>p(!0),children:"✕"})]}),t.questions.map((h,x)=>{var N;return e.jsxs("div",{className:"set-section",children:[e.jsx("div",{className:"set-section-title",children:h.header??`${i("modelQuestion")} ${x+1}`}),e.jsx("p",{className:"set-row-desc",children:h.question}),h.detail&&e.jsx("p",{className:"set-hint",children:h.detail}),(((N=h.options)==null?void 0:N.length)??0)>0&&e.jsx("div",{className:"set-list",children:h.options.map(M=>{const C=(r[h.id]??[]).includes(M.label);return e.jsxs("button",{type:"button",className:`set-row question-option${C?" active":""}`,onClick:()=>m(h.id,M.label,!!h.multiSelect),children:[e.jsxs("span",{className:"set-row-name",children:[h.multiSelect?C?"☑ ":"☐ ":C?"● ":"○ ",M.label]}),M.description&&e.jsx("span",{className:"set-row-desc",children:M.description})]},M.label)})}),e.jsx("input",{className:"set-prompt-input question-custom",placeholder:i("modelQuestionCustom"),value:l[h.id]??"",onChange:M=>n(C=>({...C,[h.id]:M.target.value}))})]},h.id)}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"dialog-submit",disabled:!v,onClick:()=>p(!1),children:i("modelQuestionSubmit")}),e.jsx("button",{type:"button",className:"dialog-dismiss-inline",onClick:()=>p(!0),children:i("cancel")})]})]})}function ur(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",i=t.y!==" "&&t.y!=="?";return s&&i?"both":s?"staged":"unstaged"}function pr({chat:t,send:s,terminal:i,active:r,onSwitchToTerminal:c}){var We,Re;const l=me(),[n,o]=a.useState(null),[d,p]=a.useState([]),[m,v]=a.useState(""),[h,x]=a.useState(new Map),[N,M]=a.useState("changes"),[C,I]=a.useState([]),[j,z]=a.useState(null),[H,R]=a.useState(""),[A,P]=a.useState(!1),[T,f]=a.useState(null),[_,Y]=a.useState(null),[X,O]=a.useState(!1),[G,q]=a.useState(!1),[k,w]=a.useState(!1),[$,J]=a.useState(null),[Z,S]=a.useState(!1),[ie,se]=a.useState(""),u=a.useRef(0),W=a.useRef(-1),D=a.useRef(-1),U=a.useRef(-1),K=a.useRef(-1),te=a.useRef(void 0),oe=a.useRef(null),ve=a.useRef([]),y=a.useCallback(E=>{if(E.reqId===W.current){if(W.current=-1,q(!1),J(null),!E.ok){J(E.error??"查询失败");return}if(E.notRepo){S(!0),o(null),p([]),x(new Map),I([]),z(null),R(""),Y(null);return}S(!1);const pe={branch:E.branch??"",detached:!!E.detached,upstream:E.upstream??null,ahead:E.ahead??0,behind:E.behind??0,upstreamGone:!!E.upstreamGone,files:(E.files??[]).map(b=>({...b}))},ce=(E.branches??[]).map(b=>({...b})),ke=new Map;for(const[b,L]of Object.entries(E.stats??{}))ke.set(b,{add:L[0],del:L[1]});o(pe),p(ce),x(ke),v(b=>{var L;return pe.detached?b||"":pe.branch&&ce.some(ne=>ne.name===pe.branch)?pe.branch:b&&ce.some(ne=>ne.name===b)?b:((L=ce[0])==null?void 0:L.name)??""}),Y(b=>b&&!pe.files.some(L=>L.path===b.file.path)?null:b)}else if(E.reqId===D.current){if(D.current=-1,O(!1),!E.ok){J(E.error??"查询失败");return}const pe=oe.current;if(!pe)return;Y({file:pe,staged:E.stagedText??"",worktree:E.worktreeText??"",untracked:!1})}else if(E.reqId===K.current){if(K.current=-1,w(!1),!E.ok){J(E.error??"查询失败");return}I((E.history??[]).map(pe=>({...pe})))}else if(E.reqId===U.current){if(U.current=-1,P(!1),!E.ok){J(E.error??"查询失败");return}R(E.text??"")}},[]);a.useEffect(()=>{const E=t.scmData;E&&E.type==="scm_data"&&y(E)},[t.scmData,y]);const V=a.useCallback((E,pe)=>{if(!t.ready||t.status!=="open")return!1;const ce=++u.current;return s({...E,reqId:ce})?(pe.current=ce,!0):(u.current-=1,!1)},[t.ready,t.status,s]),de=a.useCallback((E=!1,pe=!1)=>{var ce;!t.ready||t.status!=="open"||(ce=t.state)!=null&&ce.cwd&&(te.current!==void 0&&te.current!==t.state.cwd&&(o(null),p([]),x(new Map),I([]),w(!1),K.current=-1,z(null),R(""),Y(null),f(null)),te.current=t.state.cwd,J(null),V({type:"scm_status"},W)&&(pe||q(!0)))},[t.ready,(We=t.state)==null?void 0:We.cwd,t.status,V]),g=a.useCallback(E=>{if(f(E),z(null),oe.current=E,E.x==="?"&&E.y==="?"){Y({file:E,staged:"",worktree:"",untracked:!0});return}O(!0),J(null),V({type:"scm_filediff",path:E.path},D)||O(!1)},[V]),F=a.useCallback(E=>{z(E),f(null),Y(null),R(""),P(!0),J(null),V({type:"scm_commit",hash:E.hash},U)||P(!1)},[V]),ae=a.useCallback((E,pe)=>{var L,ne;if(!t.ready)return;const ce={name:E,command:pe,cwd:"${pwd}"};let ke;const b=t.terminals.find(re=>re.title===E);b?(i.restart(b.id),s({type:"run_command",terminalId:b.id,conversationId:b.conversationId,command:ce,cols:80,rows:24}),ke=b.id):(ke=_e(),i.create({id:ke,conversationId:t.activeConversationId||((L=t.state)==null?void 0:L.conversationId)||"",title:E,cwd:((ne=t.state)==null?void 0:ne.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ce})),i.select(ke),c()},[t.ready,(Re=t.state)==null?void 0:Re.cwd,t.terminals,c,s,i]),he=a.useCallback(()=>{const E=ie.trim();if(!E||Z)return;const pe=E.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ae("git commit",`git add -A && git commit -m "${pe}"`),se("")},[ie,Z,ae]),xe=E=>`'${E.replace(/'/g,"'\\''")}`,ue=a.useCallback(E=>{Z||ae("git add",`git add -- ${xe(E.path)}`)},[Z,ae]),Pe=a.useCallback(E=>{Z||ae("git reset",`git reset HEAD -- ${xe(E.path)}`)},[Z,ae]),Te=a.useCallback(()=>{if(!m||Z)return;const E=d.find(pe=>pe.name===m);if(E!=null&&E.remote&&typeof E.remote=="string"){const pe=m.slice(E.remote.length+1);ae("git checkout",`git checkout -b ${pe} ${m} || git checkout ${m}`)}else ae("git checkout",`git checkout ${m}`)},[m,d,Z,ae]),Ae=a.useCallback(()=>ae("git push","git push"),[ae]),Xe=a.useCallback(()=>ae("git pull","git pull"),[ae]),Se=a.useCallback(()=>{V({type:"scm_history"},K)||(K.current=-1)},[V]);a.useEffect(()=>{r&&de()},[r,de]),a.useEffect(()=>{N==="history"&&n&&Se()},[N,n,Se]),a.useEffect(()=>{t.scmDirty>0&&r&&de(!1,!0)},[t.scmDirty]),a.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const E=setInterval(()=>{document.visibilityState!=="hidden"&&de(!1,!0)},3e4);return()=>clearInterval(E)},[r,t.ready,t.status,de]),a.useEffect(()=>{const E=ve.current;if(ve.current=t.terminals,!r)return;t.terminals.some(ce=>{var b;return ce.running!==!1?!1:((b=E.find(L=>L.id===ce.id))==null?void 0:b.running)===!0&&/^git /.test(ce.title)})&&t.ready&&t.status==="open"&&(de(!1,!0),N==="history"&&n&&Se())},[t.terminals,r,t.ready,t.status,de,N,n,Se]);const Ke={staged:l("scmStaged"),unstaged:l("scmUnstaged"),untracked:l("scmUntracked"),both:l("scmStagedUnstaged")},Oe=E=>{const pe=E.split(`
|
|
320
|
-
`);return e.jsx("pre",{className:"scm-diff-pre",children:pe.map((ce,ke)=>{let b="";return ce.startsWith("diff --git")||ce.startsWith("index ")||ce.startsWith("new file")||ce.startsWith("deleted file")||ce.startsWith("old mode")||ce.startsWith("new mode")||ce.startsWith("similarity index")||ce.startsWith("rename ")||ce.startsWith("copy ")||ce.startsWith("Binary files")||ce.startsWith("---")||ce.startsWith("+++")?b="hdr":ce.startsWith("@@")?b="hunk":ce.startsWith("+")?b="add":ce.startsWith("-")&&(b="del"),e.jsx("div",{className:`scm-diff-line ${b}`,children:ce||" "},ke)})})};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(ct,{}),l("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":N==="changes",className:N==="changes"?"active":"",onClick:()=>{M("changes"),J(null)},children:l("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":N==="history",className:N==="history"?"active":"",onClick:()=>{M("history"),J(null)},children:l("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:l("scmRefreshTip"),disabled:G,onClick:()=>de(!0),children:e.jsx(nt,{className:G?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:l("scmCurrentBranch"),children:[e.jsx(ct,{}),n?n.detached?l("scmDetached"):n.branch:"…",(n==null?void 0:n.upstream)&&e.jsx("span",{className:"scm-upstream",children:n.upstreamGone?l("scmUpstreamGone"):n.ahead>0||n.behind>0?l("scmAheadBehind",{ahead:n.ahead,behind:n.behind}):n.upstream})]}),e.jsxs("select",{className:"scm-select",value:m,disabled:Z||d.length===0,title:l("scmSwitchBranch"),onChange:E=>v(E.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:l("scmSelectBranch")}),d.filter(E=>!E.remote).map(E=>e.jsx("option",{value:E.name,children:E.current?`* ${E.name}`:E.name},E.name)),d.some(E=>E.remote)&&e.jsx("optgroup",{label:l("scmRemoteBranches"),children:d.filter(E=>E.remote).map(E=>e.jsx("option",{value:E.name,children:E.name},E.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!m||m===(n==null?void 0:n.branch)||Z,title:l("scmSwitchBranchTip",{branch:m}),onClick:Te,children:[e.jsx(ct,{}),l("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||Z,title:l("scmPushTip"),onClick:Ae,children:[e.jsx(Js,{}),l("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||Z,title:l("scmPullTip"),onClick:Xe,children:[e.jsx(Xs,{}),l("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:ie,placeholder:l("scmCommitPlaceholder"),disabled:Z,onChange:E=>se(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.nativeEvent.isComposing&&he()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!ie.trim()||Z,title:l("scmCommitTip"),onClick:he,children:[e.jsx(vt,{}),l("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[N==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:l("scmHistory")}),C.length>0&&e.jsx("span",{className:"scm-files-count",children:C.length})]}),e.jsx("div",{className:"scm-history-list",children:Z?e.jsx("div",{className:"scm-empty",children:l("scmNotGitRepo")}):!n||k?e.jsx("div",{className:"scm-empty",children:t.status==="open"?l("scmLoading"):l("scmConnecting")}):C.length===0?e.jsx("div",{className:"scm-empty",children:l("scmNoHistory")}):C.map(E=>e.jsxs("button",{type:"button",className:`scm-commit ${(j==null?void 0:j.hash)===E.hash?"active":""}`,onClick:()=>F(E),title:E.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:E.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:E.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[E.shortHash," · ",E.author," · ",E.date]}),E.decorations&&e.jsx("span",{className:"scm-commit-refs",children:E.decorations})]})]},E.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:l("scmChanges")}),n&&n.files.length>0&&e.jsx("span",{className:"scm-files-count",children:n.files.length})]}),e.jsx("div",{className:"scm-files-list",children:Z?e.jsx("div",{className:"scm-empty",children:l("scmNotGitRepo")}):n?n.files.length===0?e.jsx("div",{className:"scm-empty",children:l("scmNoChanges")}):n.files.map(E=>{const pe=ur(E),ce=h.get(E.path);return e.jsxs("div",{className:`scm-file ${(T==null?void 0:T.path)===E.path?"active":""}`,title:Ke[pe],onClick:()=>g(E),children:[e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"x"}`,children:E.x!==" "?E.x:" "}),e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"y"}`,children:E.y!==" "?E.y:" "}),e.jsx("span",{className:"scm-file-path",children:E.path}),ce&&(ce.add>0||ce.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[ce.add>0&&e.jsxs("span",{className:"add",children:["+",ce.add]}),ce.del>0&&e.jsxs("span",{className:"del",children:["-",ce.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(E.y!==" "||pe==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:l("scmStageTip",{path:E.path}),onClick:ke=>{ke.stopPropagation(),ue(E)},children:"+"}),pe==="staged"||pe==="both"?e.jsx("button",{type:"button",className:"scm-act",title:l("scmUnstageTip",{path:E.path}),onClick:ke=>{ke.stopPropagation(),Pe(E)},children:"−"}):null]})]},E.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?l("scmLoading"):l("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:N==="history"?j?`${j.shortHash} ${j.subject}`:l("scmCommitDetail"):T?T.path:l("scmDiff")}),(N==="history"?A:X)&&e.jsx("span",{className:"scm-diff-loading",children:l("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:N==="history"?e.jsxs(e.Fragment,{children:[$&&e.jsx("div",{className:"scm-error",children:$}),!j&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmSelectCommitHint")}),j&&A&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmLoading")}),j&&!A&&!$&&H?Oe(H):null]}):e.jsxs(e.Fragment,{children:[$&&e.jsx("div",{className:"scm-error",children:$}),!T&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmSelectFileHint")}),T&&!_&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmLoading")}),T&&_&&_.untracked&&e.jsx("div",{className:"scm-empty",children:l("scmUntrackedNote")}),T&&_&&!_.untracked&&e.jsxs(e.Fragment,{children:[_.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:l("scmStaged")}),Oe(_.staged)]}),_.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:l("scmUnstaged")}),Oe(_.worktree)]}),!_.staged&&!_.worktree&&e.jsx("div",{className:"scm-empty",children:l("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ge,{}),e.jsx("span",{children:l("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:l("scmViewTerminal")})]})]})}function mr({entry:t,send:s}){const i=a.useRef(null);return a.useEffect(()=>{const r=i.current;if(!r)return;let c;try{c=t.module.mount(r,_i(t.info.id,l=>s(l)))}catch(l){console.error(`[plugin:${t.info.id}] mount failed:`,l),r.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(l){console.error(`[plugin:${t.info.id}] cleanup failed:`,l)}r.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:i})}function hr({send:t,piConfigured:s,piAgentInstalled:i,providers:r,installResult:c,onClose:l}){const n=me(),[o,d]=a.useState(!1),[p,m]=a.useState(""),[v,h]=a.useState(""),[x,N]=a.useState(!1);a.useEffect(()=>{t({type:"list_providers"})},[t]),a.useEffect(()=>{s&&l()},[s,l]),a.useEffect(()=>{c&&d(!1)},[c]),a.useEffect(()=>{var H;!p&&r.length>0&&m(((H=r.find(R=>!R.configured))==null?void 0:H.id)??r[0].id)},[r,p]);const M=()=>{o||(d(!0),t({type:"install_pi_agent"}))},C=()=>{!v.trim()||x||(N(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:v.trim()}),setTimeout(()=>N(!1),3e3))},I=()=>{t({type:"get_state"}),t({type:"list_providers"})},j=r.find(H=>H.id===p),z=c!==null&&!c.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":n("close"),onClick:l,children:e.jsx(Ne,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(it,{className:"modal-head-icon"}),e.jsx("h2",{children:n("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:n("setupDesc")}),z?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:n("installFailed")}),e.jsx("pre",{className:"setup-detail",children:c.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:M,children:n("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:l,children:n("skip")})]})]}):i||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?n("installDone"):n("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("provider")}),e.jsxs("select",{value:p,onChange:H=>m(H.target.value),children:[r.length===0&&e.jsx("option",{value:"",children:n("loading")}),r.map(H=>e.jsxs("option",{value:H.id,children:[H.name,"(",H.id,")",H.configured?` · ${n("configured")}`:""]},H.id))]}),(j==null?void 0:j.configured)&&e.jsx("div",{className:"field-hint",children:n("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("apiKey")}),e.jsx("input",{type:"password",value:v,onChange:H=>h(H.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!v.trim()||x||!p,onClick:C,children:n(x?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:I,children:[e.jsx(nt,{})," ",n("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:M,children:n(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:l,children:n("skip")})]})]})})}const gr=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],zt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),fr=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[zt()]});function Ls(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:[zt()]).map(s=>{var i;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(i=s.input)!=null&&i.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function xr({send:t,providers:s,providerStatus:i,fetchModelsResult:r,refreshProviderResult:c,cloneProviderResult:l,onClose:n}){const o=me(),[d,p]=a.useState(null),[m,v]=a.useState({}),[h,x]=a.useState(null),[N,M]=a.useState({}),[C,I]=a.useState(!1),[j,z]=a.useState(0),[H,R]=a.useState(null),A=a.useRef(0),[P,T]=a.useState({});a.useRef(0);const f=a.useRef(0),[_,Y]=a.useState(null),X=a.useRef(0),O=a.useRef(0);a.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const G=()=>{if(!d)return;const S=d.baseUrl.trim();if(!S){R({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(C)return;I(!0),R(null);const ie=j+1;z(ie),t({type:"fetch_models",reqId:ie,baseUrl:S,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader,api:d.api})};a.useEffect(()=>{var S;if(!(!r||r.reqId===A.current))if(A.current=r.reqId,I(!1),r.ok&&((S=r.models)!=null&&S.length)){const ie=r.models;p(se=>{if(!se)return se;const u=se.models.map(K=>{var ve;if(!K.id.trim())return K;const te=ie.find(y=>y.id===K.id.trim());if(!te)return K;const oe={...K};return!oe.name&&te.name&&(oe.name=te.name),!oe.contextWindow&&te.contextWindow&&(oe.contextWindow=String(te.contextWindow)),!oe.maxTokens&&te.maxTokens&&(oe.maxTokens=String(te.maxTokens)),oe.input==="text"&&((ve=te.input)!=null&&ve.includes("image"))&&(oe.input="text-image"),!oe.reasoning&&te.reasoning&&(oe.reasoning=!0),oe}),W=new Set(u.map(K=>K.id.trim()).filter(Boolean)),D=ie.filter(K=>!W.has(K.id)).map(K=>{var te;return{id:K.id,name:K.name??"",reasoning:K.reasoning??!1,input:(te=K.input)!=null&&te.includes("image")?"text-image":"text",contextWindow:K.contextWindow?String(K.contextWindow):"",maxTokens:K.maxTokens?String(K.maxTokens):""}}),U=[...u,...D];return U.some(K=>K.id.trim())?{...se,models:U.filter(K=>K.id.trim())}:se}),R({ok:!0,text:o("fetchModelsOk",{n:ie.length})})}else R({ok:!1,text:r.error||o("fetchModelsEmpty")})},[r]);const q=S=>{const ie=(m[S.id]??"").trim();!ie||h||(x(S.id),t({type:"set_provider_api_key",provider:S.id,apiKey:ie}),setTimeout(()=>{x(null),v(se=>({...se,[S.id]:""})),M(se=>({...se,[S.id]:!1})),t({type:"list_providers"})},1500))},k=()=>{if(!d)return;const S=d.providerId.trim(),ie=d.models.filter(u=>u.id.trim()).map(u=>({id:u.id.trim(),name:u.name.trim()||void 0,reasoning:u.reasoning||void 0,input:u.input==="text-image"?["text","image"]:void 0,contextWindow:u.contextWindow?Number(u.contextWindow):void 0,maxTokens:u.maxTokens?Number(u.maxTokens):void 0})),se={providerId:S,name:d.name.trim()||void 0,api:d.api.trim()||void 0,baseUrl:d.baseUrl.trim()||void 0,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader||void 0,models:ie};t({type:"save_model_config",providerId:S,config:se}),n()};a.useEffect(()=>{!c||c.reqId===f.current||(f.current=c.reqId,T({}))},[c]);const w=S=>{if(_)return;Y(S.id);const ie=++X.current+Date.now();t({type:"clone_provider",provider:S.id,reqId:ie})};a.useEffect(()=>{!l||l.reqId===O.current||(O.current=l.reqId,Y(null),l.ok&&l.config&&p(Ls({...l.config,apiKey:""})))},[l]);const $=S=>{window.confirm(o("clearKeyConfirm",{id:S}))&&t({type:"clear_provider_api_key",provider:S})},J=S=>{window.confirm(o("deleteProviderConfirm",{id:S.providerId,n:S.models.length}))&&t({type:"delete_model_config",providerId:S.providerId})},Z=(S,ie)=>{d&&p({...d,models:d.models.map((se,u)=>u===S?{...se,...ie}:se)})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal model-modal",onClick:S=>S.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:n,children:e.jsx(Ne,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:o(d?"editProvider":"manageModelsTitle")})}),d?e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:d.providerId,disabled:s.some(S=>S.providerId===d.providerId),onChange:S=>p({...d,providerId:S.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:d.name,onChange:S=>p({...d,name:S.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:d.api,onChange:S=>p({...d,api:S.target.value}),children:gr.map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:d.baseUrl,onChange:S=>p({...d,baseUrl:S.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:d.apiKey,onChange:S=>p({...d,apiKey:S.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:d.authHeader,onChange:S=>p({...d,authHeader:S.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:[H&&e.jsx("span",{className:`fetch-msg ${H.ok?"ok":"err"}`,title:H.text,children:H.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:C||!d.baseUrl.trim(),title:o("fetchModelsHint"),onClick:G,children:[e.jsx(Ot,{})," ",o(C?"fetchingModels":"fetchModels")]})]})]}),d.models.map((S,ie)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:S.id,onChange:se=>Z(ie,{id:se.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:S.name,onChange:se=>Z(ie,{name:se.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:S.input,onChange:se=>Z(ie,{input:se.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:S.reasoning,onChange:se=>Z(ie,{reasoning:se.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:S.contextWindow,onChange:se=>Z(ie,{contextWindow:se.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:S.maxTokens,onChange:se=>Z(ie,{maxTokens:se.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>p({...d,models:d.models.filter((se,u)=>u!==ie)}),children:e.jsx(De,{})})]},ie)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...d,models:[...d.models,zt()]}),children:[e.jsx(He,{})," ",o("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!d.providerId.trim()||!d.models.some(S=>S.id.trim()),onClick:k,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:[i.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.map(S=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:S.name}),e.jsxs("span",{className:"provider-sub",children:[S.id,S.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),S.source&&!S.configured&&e.jsx("span",{className:"auth-badge dim",children:S.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[S.configured&&!N[S.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:()=>M(ie=>({...ie,[S.id]:!0})),children:[e.jsx(Dt,{})," ",o("replaceKey")]}),S.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>$(S.id),children:[e.jsx(De,{})," ",o("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:o("pasteKey"),value:m[S.id]??"",onChange:ie=>v(se=>({...se,[S.id]:ie.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(m[S.id]??"").trim()||h===S.id,onClick:()=>q(S),children:[e.jsx(ai,{})," ",h===S.id?o("savingKey"):o("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:_!==null,title:o("cloneProviderTitle"),onClick:()=>w(S),children:[e.jsx(Wt,{})," ",_===S.id?o("cloning"):o("cloneProvider")]})]})]},S.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(S=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:S.providerId}),e.jsxs("span",{className:"provider-sub",children:[S.api??"—",S.baseUrl?` · ${S.baseUrl}`:"",S.models.length>0&&` · ${o("modelsCount",{n:S.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>p(Ls(S)),children:e.jsx(Dt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>J(S),children:e.jsx(De,{})})]})]},S.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(fr()),children:[e.jsx(He,{})," ",o("addProvider")]})})]})]})})}function vr({plugin:t,send:s}){const i=me(),r=t.settingsSchema??[],[c,l]=a.useState(()=>({...t.settingsValues??{}})),[n,o]=a.useState(!1);if(r.length===0)return null;const d=(h,x)=>l(N=>({...N,[h]:x})),p=r.some(h=>{var x;return c[h.key]!==((x=t.settingsValues)==null?void 0:x[h.key])}),m=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},v=()=>l({...t.settingsValues??{}});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:r.map(h=>e.jsxs("label",{className:"plugin-settings-field",title:h.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:h.label}),h.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[h.key],onChange:x=>d(h.key,x.target.checked)}):h.type==="select"?e.jsx("select",{value:String(c[h.key]??""),onChange:x=>d(h.key,x.target.value),children:(h.options??[]).map(x=>e.jsx("option",{value:x,children:x},x))}):e.jsx("input",{type:h.type==="password"?"password":h.type==="number"?"number":"text",value:String(c[h.key]??""),min:h.min,max:h.max,onChange:x=>d(h.key,h.type==="number"?Number(x.target.value):x.target.value)})]},h.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!p||n,onClick:m,children:i(n?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:v,children:i("pluginSettingsReset")})]})]})}function yr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function st({text:t}){const s=a.useRef(null),[i,r]=a.useState(!1),c=()=>{var n;const l=(n=s.current)==null?void 0:n.getBoundingClientRect();l&&r(window.innerWidth-l.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${i?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Le({title:t,subtitle:s,tip:i,enabled:r,onToggle:c,action:l}){const n=me();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[t,i&&e.jsx(st,{text:i})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),l,e.jsx("button",{type:"button",className:`set-switch ${r?"on":""}`,role:"switch","aria-checked":r,title:n(r?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function kr({chat:t,send:s,terminal:i,onSwitchToTerminal:r,onClose:c}){var y,V,de;const l=me(),n=t.settings,o=t.engine==="dsh",[d,p]=a.useState("prompt"),m=a.useRef(null);a.useEffect(()=>{var g;(g=m.current)==null||g.scrollTo({top:0})},[d]),a.useEffect(()=>{d==="plugins"&&t.engine==="dsh"&&s({type:"dsh_patches_list"})},[d,t.engine,s]);const[v,h]=a.useState(""),[x,N]=a.useState("append"),M=a.useRef(!1),[C,I]=a.useState(""),[j,z]=a.useState("append"),H=a.useRef(!1),[R,A]=a.useState(""),P=a.useRef(!1),[T,f]=a.useState(""),[_,Y]=a.useState(!1),[X,O]=a.useState(null),[G,q]=a.useState(null);a.useEffect(()=>{n&&(N(n.promptMode),!M.current&&(h(x==="append"||n.customSystemPrompt?n.customSystemPrompt:n.defaultSystemPrompt||""),z(n.visionBridgePromptMode),!H.current&&(I(j==="append"||n.visionBridgePrompt?n.visionBridgePrompt:n.visionBridgeDefaultPrompt||""),P.current||A(n.reviewPrompt))))},[n,x,j]);const[k,w]=a.useState(String((n==null?void 0:n.terminalBashIdleMs)??15e3));if(a.useEffect(()=>{w(String((n==null?void 0:n.terminalBashIdleMs)??15e3))},[n==null?void 0:n.terminalBashIdleMs]),!n)return null;const $=[{id:"prompt",icon:e.jsx(Gs,{}),label:l("settingsSystemPrompt")},{id:"terminal",icon:e.jsx(Ge,{}),label:l("settingsTerminalTools")},{id:"display",icon:e.jsx(Qe,{}),label:l("settingsMessageDisplay")},{id:"skills",icon:e.jsx(it,{}),label:l("settingsSkills"),count:n.skills.length},{id:"extensions",icon:e.jsx(ps,{}),label:l("settingsExtensions"),count:n.extensions.length},{id:"plugins",icon:e.jsx(jt,{}),label:l("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(ot,{}),label:l("settingsReview"),count:n.reviewSkills.length},...o?[]:[{id:"vision",icon:e.jsx(It,{}),label:l("settingsVisionBridge")}],{id:"presets",icon:e.jsx(Yn,{}),label:l("settingsPresets"),count:n.presets.length}],J=new Set(n.disabledSkills),Z=new Set(n.disabledExtensions),S=g=>s({type:"set_settings",...g}),ie=g=>{const F=new Set(J);F.has(g.name)?F.delete(g.name):F.add(g.name),S({disabledSkills:[...F]})},se=new Set(n.disabledPlugins??[]),u=g=>{const F=new Set(se);F.has(g.id)?F.delete(g.id):F.add(g.id),S({disabledPlugins:[...F]})},W=g=>{const F=new Set(Z);F.has(g.id)?F.delete(g.id):F.add(g.id),S({disabledExtensions:[...F]})},D=(g,F)=>{var ue,Pe;const ae={name:g,command:F,cwd:"${pwd}"};let he;const xe=t.terminals.find(Te=>Te.title===g);xe?(i.restart(xe.id),s({type:"run_command",terminalId:xe.id,conversationId:xe.conversationId,command:ae,cols:80,rows:24}),he=xe.id):(he=_e(),i.create({id:he,conversationId:t.activeConversationId||((ue=t.state)==null?void 0:ue.conversationId)||"",title:g,cwd:((Pe=t.state)==null?void 0:Pe.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ae})),i.select(he),r(),c()},U=g=>{O(null),D(`${l("uninstallTitle")} ${g}`,`pi remove npm:${g}`)},K=g=>{q(null),D(`${l("uninstallTitle")} ${g}`,`pi-web-ui uninstall ${g}`)},te=(g,F)=>{D(`${l("pluginUpdate")} ${g}`,`pi-web-ui install ${F} --name ${g} --force`)},oe=g=>{const F=new Set(n.reviewSkills.filter(ae=>!ae.enabled).map(ae=>ae.name));F.has(g.name)?F.delete(g.name):F.add(g.name),S({reviewDisabledSkills:[...F]})},ve=()=>{const g=x==="replace"&&n.defaultSystemPrompt&&v===n.defaultSystemPrompt?"":v;S({promptMode:x,customSystemPrompt:g})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:g=>g.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":l("close"),onClick:c,children:e.jsx(Ne,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(mt,{className:"modal-head-icon"}),e.jsx("h2",{children:l("settingsTitle")}),e.jsx(st,{text:l("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":l("settingsTitle"),children:$.map(g=>e.jsxs("button",{type:"button",className:`settings-tab${d===g.id?" active":""}`,"aria-current":d===g.id?"true":void 0,title:g.label,onClick:()=>p(g.id),children:[e.jsx("span",{className:"settings-tab-icon",children:g.icon}),e.jsx("span",{className:"settings-tab-label",children:g.label}),g.count!==void 0&&e.jsx("span",{className:"set-count",children:g.count})]},g.id))}),e.jsxs("div",{className:"modal-body",ref:m,children:[d==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ot,{className:"set-section-icon"}),l("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:x,onChange:g=>{const F=g.target.value;N(F),S({promptMode:F})},children:[e.jsx("option",{value:"append",children:l("promptModeAppend")}),e.jsx("option",{value:"replace",children:l("promptModeReplace")})]}),e.jsx(st,{text:l(x==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:l("promptPlaceholder"),value:v,onFocus:()=>M.current=!0,onBlur:()=>{M.current=!1,ve()},onChange:g=>h(g.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":_,onClick:()=>Y(g=>!g),children:[l("settingsViewPrompt")," ",_?"▴":"▾"]}),_&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:l("settingsViewPromptHint")}),e.jsx(nn,{text:n.effectiveSystemPrompt})]}),n.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:n.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:l("settingsViewPromptEmpty")})]})]}),d==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ge,{className:"set-section-icon"}),l("settingsTerminalTools")]}),e.jsx(Le,{title:l("terminalToolsEnabled"),tip:l("settingsTerminalToolsDesc"),enabled:n.terminalToolsEnabled,onToggle:()=>S({terminalToolsEnabled:!n.terminalToolsEnabled})}),!n.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:l("terminalToolsOffHint")}),e.jsx(Le,{title:l("terminalBashTakeover"),tip:l("terminalBashTakeoverDesc"),enabled:n.terminalBash,onToggle:()=>S({terminalBash:!n.terminalBash})}),n.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:l("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:k,onChange:g=>w(g.target.value),onBlur:()=>{const g=Math.max(0,Math.floor(Number(k)||0));w(String(g)),g!==n.terminalBashIdleMs&&S({terminalBashIdleMs:g})}})]})]}),d==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Qe,{className:"set-section-icon"}),l("settingsMessageDisplay")]}),e.jsx(Le,{title:l("thinkingWrap"),tip:l("thinkingWrapDesc"),enabled:n.thinkingWrap??!0,onToggle:()=>S({thinkingWrap:!(n.thinkingWrap??!0)})}),e.jsx(Le,{title:l("toolsWrap"),tip:l("toolsWrapDesc"),enabled:n.toolsWrap??!0,onToggle:()=>S({toolsWrap:!(n.toolsWrap??!0)})})]}),d==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(it,{className:"set-section-icon"}),l("settingsSkills"),e.jsx("span",{className:"set-count",children:n.skills.length})]}),n.skills.length===0?e.jsx("p",{className:"set-empty",children:l(o?"dshSkillsNote":"noSkills")}):e.jsx("div",{className:"set-list",children:n.skills.map(g=>e.jsx(Le,{title:g.name,subtitle:g.description,enabled:g.enabled,onToggle:()=>ie(g)},g.name))})]}),d==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ps,{className:"set-section-icon"}),l("settingsExtensions"),e.jsx("span",{className:"set-count",children:n.extensions.length})]}),n.extensions.length===0?e.jsx("p",{className:"set-empty",children:l(o?"dshExtensionsNote":"noExtensions")}):e.jsx("div",{className:"set-list",children:n.extensions.map(g=>{const F=g.id.startsWith("npm:")?g.id.slice(4):null;return e.jsx(Le,{title:g.name,subtitle:g.path,enabled:g.enabled,onToggle:()=>W(g),action:F?X===g.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:l("uninstallConfirmHint"),onClick:()=>U(F),children:l("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:l("uninstallHint"),onClick:()=>O(g.id),children:[e.jsx(De,{}),l("uninstallExt")]}):void 0},g.id)})})]}),d==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(jt,{className:"set-section-icon"}),l("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:l("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(g=>{var F;return e.jsxs(e.Fragment,{children:[e.jsx(Le,{title:`${g.icon?`${g.icon} `:""}${g.name}`,subtitle:(g.error?`${g.id} · ${g.error}`:g.source?`${g.id} · ${g.source}`:`${g.id} · ${l("uiPluginNoSource")}`)+((F=g.permissions)!=null&&F.length?` · ${l("uiPluginPerms")}: ${g.permissions.join(", ")}`:""),enabled:!se.has(g.id)&&!g.error,onToggle:()=>!g.error&&u(g),action:e.jsxs("div",{className:"set-row-actions",children:[g.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:l("pluginUpdateHint"),onClick:()=>te(g.id,g.source),children:[e.jsx(nt,{}),l("pluginUpdate")]}),G===g.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:l("pluginUninstallHint"),onClick:()=>K(g.id),children:l("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:l("pluginUninstallHint"),onClick:()=>q(g.id),children:[e.jsx(De,{}),l("uninstallExt")]})]})},g.id),g.settingsSchema&&g.settingsSchema.length>0&&e.jsx(vr,{plugin:g,send:s})]})})})]}),d==="plugins"&&t.engine==="dsh"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(jt,{className:"set-section-icon"}),l("dshPatches"),e.jsx(st,{text:l("dshPatchesDesc")}),e.jsx("span",{className:"set-count",children:((y=t.dshPatches)==null?void 0:y.files.length)??0}),e.jsxs("button",{type:"button",className:"set-uninstall",title:l("dshPatchesRescanHint"),onClick:()=>s({type:"dsh_patches_rescan"}),children:[e.jsx(nt,{}),l("dshPatchesRescan")]})]}),(((V=t.dshPatches)==null?void 0:V.files.length)??0)===0?e.jsx("p",{className:"set-empty",children:l("dshPatchesEmpty")}):e.jsx("div",{className:"set-list",children:t.dshPatches.files.map(g=>e.jsx("div",{className:"set-row",children:e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:g.name}),e.jsxs("div",{className:"set-row-desc",children:[yr(g.size)," · ",new Date(g.mtimeMs).toLocaleString()]})]})},g.name))}),e.jsxs("p",{className:"set-hint",children:[l("dshPatchesPath")," ",((de=t.dshPatches)==null?void 0:de.patchDir)??""]})]}),d==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ot,{className:"set-section-icon"}),l("settingsReview"),e.jsx(st,{text:l("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:n.reviewSkills.length})]}),o&&e.jsx("p",{className:"set-hint",children:l("dshReviewPromptNote")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:l("reviewPromptPlaceholder"),value:R,onFocus:()=>P.current=!0,onBlur:()=>{P.current=!1,S({reviewPrompt:R})},onChange:g=>A(g.target.value)}),e.jsx("div",{className:"set-field-label",children:l("settingsReviewSkills")}),n.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:l("noSkills")}):e.jsx("div",{className:"set-list",children:n.reviewSkills.map(g=>e.jsx(Le,{title:g.name,subtitle:g.description,enabled:g.enabled,onToggle:()=>oe(g)},`review-${g.name}`))})]}),d==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(It,{className:"set-section-icon"}),l("settingsVisionBridge")]}),e.jsx(Le,{title:l("visionBridgeEnabled"),tip:l("settingsVisionBridgeDesc"),enabled:n.visionBridgeEnabled,onToggle:()=>S({visionBridgeEnabled:!n.visionBridgeEnabled})}),!n.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:l("visionBridgeOffHint")}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:n.visionBridgeModel??"",onChange:g=>S({visionBridgeModel:g.target.value||null}),children:[e.jsx("option",{value:"",children:l("visionBridgeAuto")}),n.visionModels.map(g=>e.jsx("option",{value:`${g.provider}/${g.id}`,children:g.label},`${g.provider}/${g.id}`))]})]}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:j,onChange:g=>{const F=g.target.value;z(F),S({visionBridgePromptMode:F})},children:[e.jsx("option",{value:"append",children:l("promptModeAppend")}),e.jsx("option",{value:"replace",children:l("promptModeReplace")})]})]}),n.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:l("visionBridgePromptPlaceholder"),value:C,onFocus:()=>H.current=!0,onBlur:()=>{H.current=!1;const g=j==="replace"&&n.visionBridgeDefaultPrompt&&C===n.visionBridgeDefaultPrompt?"":C;S({visionBridgePromptMode:j,visionBridgePrompt:g})},onChange:g=>I(g.target.value)}),n.visionBridgeEnabled&&(n.visionModels.length===0?e.jsx("p",{className:"set-hint",children:l("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:l("visionBridgeCurrent",{model:n.visionBridgeModel??l("visionBridgeAuto")})}))]}),d==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(mt,{className:"set-section-icon"}),l("settingsPresets"),e.jsx("span",{className:"set-count",children:n.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:l("presetNamePlaceholder"),value:T,onChange:g=>f(g.target.value),onKeyDown:g=>{g.key==="Enter"&&T.trim()&&(s({type:"save_preset",name:T.trim()}),f(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!T.trim(),onClick:()=>{s({type:"save_preset",name:T.trim()}),f("")},children:[e.jsx(He,{})," ",l("saveAsPreset")]})]}),n.presets.length===0?e.jsx("p",{className:"set-empty",children:l("noPresets")}):e.jsx("div",{className:"set-list",children:n.presets.map(g=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:g.name}),e.jsxs("div",{className:"set-row-desc",children:[g.promptMode==="replace"?l("promptModeReplace"):l("promptModeAppend"),g.disabledSkills.length>0&&` · ${l("settingsSkills")} ${g.disabledSkills.length}`,g.disabledExtensions.length>0&&` · ${l("settingsExtensions")} ${g.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:g.name}),children:l("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:l("deletePreset"),onClick:()=>s({type:"delete_preset",name:g.name}),children:e.jsx(De,{})})]})]},g.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:l("close")})})]})})}function br(t,s){const i=Math.max(0,Date.now()-t),r=Math.floor(i/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const c=Math.floor(r/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function jr({servers:t,send:s,onClose:i}){const r=me(),[c,l]=a.useState(new Set),n=o=>l(d=>{const p=new Set(d);return p.has(o)?p.delete(o):p.add(o),p});return a.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(gt,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:i,children:e.jsx(Ne,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(gt,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const d=!!o.taskId,p=o.taskId??String(o.port);return e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:d?o.plugin:r("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[d?e.jsxs("span",{className:"bg-task-port",title:o.taskId,children:["🧩 ",o.plugin]}):e.jsxs("span",{className:"bg-task-port",children:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[!d&&e.jsxs("span",{children:[r("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",br(o.since,r)]}),d&&o.status&&e.jsx("span",{className:"bg-task-status",children:o.status})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(p)?"open":""}`,title:`${r("bgTaskCommand")}: ${o.command}`,onClick:()=>n(p),children:[e.jsx(Ge,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s(d?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(pt,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},p)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(nt,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(pt,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function wr(t,s){return t.toLowerCase().includes(s)}function Nr({open:t,send:s,projects:i,cwd:r,fileSearch:c,sessionSearch:l,onClose:n,onSwitchSession:o,onSwitchProject:d,onPreviewFile:p}){const m=me(),v=a.useRef(null),[h,x]=a.useState(""),N=a.useDeferredValue(h),[M,C]=a.useState(0),I=a.useRef(1),j=a.useRef(0),z=a.useRef(null);a.useEffect(()=>{if(!t)return;s({type:"list_sessions"}),s({type:"list_projects"});const k=h.trim();if(k){const w=++I.current;j.current=w,R(!0),s({type:"search_files",reqId:w,query:k}),s({type:"search_sessions",reqId:w,query:k})}requestAnimationFrame(()=>{var w;return(w=v.current)==null?void 0:w.select()})},[t]);const[H,R]=a.useState(!1);a.useEffect(()=>{z.current&&clearTimeout(z.current);const k=N.trim();if(!k){R(!1);return}return z.current=setTimeout(()=>{const w=++I.current;j.current=w,R(!0),s({type:"search_files",reqId:w,query:k}),s({type:"search_sessions",reqId:w,query:k})},300),()=>{z.current&&clearTimeout(z.current)}},[N]);const A=N.trim().toLowerCase(),P=a.useMemo(()=>!A||!l||l.reqId!==j.current||!l.ok?[]:l.results,[l,A]),T=a.useMemo(()=>A?i.filter(k=>wr(k.path,A)).slice(0,10):[],[i,A]),f=a.useMemo(()=>!A||!c||c.reqId!==j.current||!c.ok?[]:c.results,[c,A]);a.useEffect(()=>{c&&c.reqId===j.current&&l&&l.reqId===j.current&&j.current!==0&&R(!1)},[c,l]);const _=!!c&&c.ok&&c.truncated,Y=a.useMemo(()=>[...P.map(k=>({kind:"session",path:k.path,anchors:k.anchors})),...T.map(k=>({kind:"project",path:k.path})),...f.filter(k=>k.type==="file").map(k=>({kind:"file",path:k.path,name:k.name}))],[P,T,f]);a.useEffect(()=>{C(0)},[N]);const X=a.useCallback(k=>{if(k)if(k.kind==="session")o(k.path,k.anchors),n();else if(k.kind==="project"){d(k.path),s({type:"list_sessions"}),s({type:"list_projects"});const w=N.trim();if(w){const $=++I.current;j.current=$,R(!0),s({type:"search_files",reqId:$,query:w}),s({type:"search_sessions",reqId:$,query:w})}}else p(k.path,k.name)},[o,d,p,s,N]);a.useEffect(()=>{if(!t)return;const k=w=>{w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),n()):w.key==="ArrowDown"?(w.preventDefault(),C($=>Math.min($+1,Y.length-1))):w.key==="ArrowUp"?(w.preventDefault(),C($=>Math.max($-1,0))):w.key==="Enter"&&(w.preventDefault(),X(Y[M]))};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[Y,M,X,n,t]);const O=P.length+T.length+f.length,G=(k,w,$)=>e.jsxs("div",{className:"gs-section-head",children:[$,e.jsx("span",{children:k}),e.jsx("em",{children:w})]});let q=-1;return t?e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:n,children:e.jsxs("div",{className:"gs-modal",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(ht,{}),e.jsx("input",{ref:v,type:"text",value:h,placeholder:m("gsPlaceholder"),onChange:k=>x(k.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:m("close"),onClick:n,children:e.jsx(Ne,{})})]}),e.jsxs("div",{className:"gs-results",children:[!A&&e.jsx("div",{className:"gs-empty",children:m("gsHint")}),A&&O===0&&!_&&e.jsx("div",{className:"gs-empty",children:m(H?"gsSearching":"gsNoResults")}),P.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsSessions"),P.length,e.jsx(Qe,{})),P.map(k=>{q++;const w=q;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",onMouseEnter:()=>C(w),onClick:()=>X({kind:"session",path:k.path,anchors:k.anchors}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.name||k.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:k.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:k.firstMessage})]},k.path)})]}),T.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsProjects"),T.length,e.jsx(Ye,{})),T.map(k=>{q++;const w=q,$=r&&k.path===r;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",onMouseEnter:()=>C(w),onClick:()=>X({kind:"project",path:k.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.path.split(/[\\/]/).pop(),$&&e.jsx("em",{className:"gs-item-meta",children:m("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},k.path)})]}),(f.length>0||A&&_)&&e.jsxs("div",{className:"gs-section",children:[G(m("gsFiles"),f.length,e.jsx(Gs,{})),f.map(k=>{q++;const w=q;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",disabled:k.type==="dir",title:k.type==="dir"?void 0:m("gsOpenPreview"),onMouseEnter:()=>C(w),onClick:()=>{k.type==="file"&&X({kind:"file",path:k.path,name:k.name})},children:[e.jsx("span",{className:"gs-item-title",children:k.name}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},`${k.type}:${k.path}`)}),_&&e.jsx("div",{className:"gs-truncated",children: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")]})]})]})}):null}const Mt=5e3;function Cr({file:t,content:s,send:i,onAddLines:r,onAttach:c,onClose:l}){const n=me(),[o,d]=a.useState(null),[p,m]=a.useState(!1),[v,h]=a.useState(null),[x,N]=a.useState(!1),[M,C]=a.useState(!1),[I,j]=a.useState(!1),[z,H]=a.useState(""),[R,A]=a.useState(!0),P=a.useRef(!1),[T,f]=a.useState(!0),[_,Y]=a.useState(!1),[X,O]=a.useState(100),G=a.useRef(0),q=a.useRef(!1),k=a.useRef(null);a.useEffect(()=>{m(!0),d(null),h(null),j(!1),H(""),A(!0),P.current=!1,i({type:"read_file",path:t.path})},[t.path,i]),a.useEffect(()=>{s&&s.path===t.path&&(d(s),I||H(s.text),m(!1))},[s,I,t.path]),a.useEffect(()=>{const F=ae=>{if(ae.key==="Escape"){U();return}if((ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="s"&&I){ae.preventDefault(),D();return}const he=ae.target,xe=he&&(he.tagName==="INPUT"||he.tagName==="TEXTAREA"||he.isContentEditable);(ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="a"&&!xe&&(ae.preventDefault(),S())};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[l,o,I,z]),a.useEffect(()=>{const F=()=>{q.current=!1,N(!1)};return window.addEventListener("mouseup",F),()=>window.removeEventListener("mouseup",F)},[]);const w=a.useMemo(()=>{if(!o)return[];const F=o.text.split(`
|
|
321
|
-
`);return F.length>0&&F[F.length-1]===""&&F.pop(),F.slice(0,Mt)},[o]),$=(o==null?void 0:o.lines)??0,J=$>Mt,Z=(F,ae)=>{if(ae){const he=G.current>0?G.current:F;h({start:Math.min(he,F),end:Math.max(he,F)})}else G.current=F,h({start:F,end:F})},S=()=>{w.length!==0&&(G.current=1,h({start:1,end:w.length}))},ie=()=>{v&&(r(t.path,t.name,v.start,v.end),C(!0),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>C(!1),1400))},se=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,u=()=>{H((o==null?void 0:o.text)??""),j(!1),P.current&&A(!0)},W=()=>{if(I){if(z!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;u();return}!se||!o||(P.current=Pt(t.name)&&R,Pt(t.name)&&A(!1),h(null),H(o.text),j(!0))},D=()=>{!I||!o||!se||i({type:"write_file",path:t.path,text:z})&&(j(!1),P.current&&A(!0),h(null))},U=()=>{I&&z!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||l()},K=F=>{O(Math.min(200,Math.max(50,F)))},te=v?v.end-v.start+1:0,oe=(o==null?void 0:o.binary)??!1,ve=(o==null?void 0:o.truncated)??!1,y=(o==null?void 0:o.kind)??"text",V=Pt(t.name),de=V&&R&&!I&&y==="text"&&!oe,g=F=>yt(Je(`/api/file?clientId=${encodeURIComponent(qt())}&path=${encodeURIComponent(F)}`));return e.jsx("div",{className:`fp-overlay ${_?"fullscreen":""}`,onMouseDown:F=>{F.target===F.currentTarget&&U()},children:e.jsxs("div",{className:`fp ${_?"fullscreen":""}`,style:{"--fp-zoom":X/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&&y==="text"&&!oe&&n("fileLines",{n:$}),o&&` · ${Sr(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[V&&y==="text"&&!oe&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${R?"on":""}`,"data-tip":n(R?"showMarkdownSource":"showMarkdownPreview"),disabled:I,onClick:()=>A(F=>!F),children:R?e.jsx(It,{}):e.jsx(ui,{})}),y==="text"&&!oe&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${I?"on":""}`,"data-tip":n(ve?"fileEditTruncated":I?"exitEditFile":"editFile"),disabled:!se&&!I,onClick:W,children:e.jsx(Lt,{})}),y==="text"&&!oe&&!de&&e.jsx("button",{type:"button",className:`fp-attach wrap ${T?"on":""}`,"data-tip":n(T?"disableWrap":"enableWrap"),onClick:()=>f(F=>!F),children:e.jsx(di,{})}),y==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:X<=50,onClick:()=>K(X-10),children:e.jsx(Kn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>O(100),children:[X,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:X>=200,onClick:()=>K(X+10),children:e.jsx(zn,{})})]}),y!=="video"&&y!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Rt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${_?"on":""}`,"data-tip":n(_?"exitFullscreen":"fullscreen"),onClick:()=>Y(F=>!F),children:_?e.jsx(ei,{}):e.jsx(si,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:U,children:e.jsx(Ne,{})})]})]}),ve&&y==="text"&&!oe&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&y==="none"&&!oe&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&y==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:g(t.path),alt:t.name})}),!p&&y==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:g(t.path),controls:!0,preload:"metadata"})}),!p&&de&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(kt,{text:o.text})})}),!p&&oe&&y!=="image"&&y!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&I&&y==="text"&&!oe&&o&&e.jsx("textarea",{className:`fp-editor ${T?"":"no-wrap"}`,value:z,onChange:F=>H(F.target.value),wrap:T?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!de&&!I&&y==="text"&&!oe&&o&&w.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!de&&!I&&y==="text"&&!oe&&w.length>0&&e.jsxs("div",{className:`fp-code ${x?"dragging":""} ${T?"":"no-wrap"}`,onMouseDown:F=>{F.button===0&&F.preventDefault()},children:[w.map((F,ae)=>{const he=ae+1,xe=v!==null&&he>=v.start&&he<=v.end;return e.jsxs("div",{className:`fp-line ${xe?"sel":""}`,onMouseDown:ue=>{ue.button===0&&(Z(he,ue.shiftKey),q.current=!0,N(!0))},onMouseEnter:()=>{q.current&&Z(he,!0)},children:[e.jsx("span",{className:"fp-num",children:he}),e.jsx("span",{className:"fp-code-text",children:F})]},he)}),J&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:Mt})})]}),e.jsx("div",{className:"fp-foot",children:I?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:n("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:W,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:z===((o==null?void 0:o.text)??""),onClick:D,children:[e.jsx(Jn,{})," ",n("saveFile")]})]})]}):!de&&y==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:v?n("selectedRange",{n:te,start:v.start,end:v.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:w.length===0,onClick:S,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!v,onClick:()=>h(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!v||oe,onClick:ie,children:[M?e.jsx(vt,{}):null,n(M?"addedToChat":"addToChat")]})]})]})})]})})}function Pt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Sr(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const jn="pi-web-sounds",Ze={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function wn(){try{const t=localStorage.getItem(jn);if(!t)return{...Ze};const s=JSON.parse(t),i={...Ze,...s};for(const r of["enabled","question","done","start","error"])typeof i[r]!="boolean"&&(i[r]=Ze[r]);return typeof i.volume!="number"||!Number.isFinite(i.volume)?i.volume=Ze.volume:i.volume=Math.round(Math.max(0,Math.min(100,i.volume))/5)*5,i}catch{return{...Ze}}}function Tr(t){try{localStorage.setItem(jn,JSON.stringify(t))}catch{}}let et=null;function Er(){try{if(!et){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;et=new t}return et.state==="suspended"&&et.resume(),et}catch{return null}}const Mr=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Pr=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],Rr=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],Ir=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Lr={question:Mr,done:Pr,start:Rr,error:Ir};function Dr(t,s,i){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const l=t.currentTime+s.start,n=Math.max(1e-4,s.peak*i);c.gain.setValueAtTime(1e-4,l),c.gain.exponentialRampToValueAtTime(n,l+.012),c.gain.exponentialRampToValueAtTime(1e-4,l+s.dur),r.connect(c),c.connect(t.destination),r.start(l),r.stop(l+s.dur+.05)}function tt(t,s=wn()){if(!s.enabled||!s[t])return;const i=Er();if(!i)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Lr[t])Dr(i,c,r)}const $t="pi-web-ui:theme",Nn="dark",Ds="theme-stylesheet",Bs="pi-web-ui:theme-change";function Cn(){try{const t=localStorage.getItem($t);if(t&&t!==Nn)return t}catch{}return null}function Br(t){try{t?localStorage.setItem($t,t):localStorage.removeItem($t)}catch{}}function Sn(t){let s=document.getElementById(Ds);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Bs));return}s||(s=document.createElement("link"),s.id=Ds,s.rel="stylesheet",document.head.appendChild(s)),s.href=Je(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(Bs))}async function _r(){try{const t=await fetch(yt(Je("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Ar(){const[t,s]=a.useState([]),[i,r]=a.useState(()=>Cn());return a.useEffect(()=>{let l=!1;return _r().then(n=>{l||s(n)}),()=>{l=!0}},[]),a.useEffect(()=>{Sn(i),Br(i)},[i]),{themes:t,theme:i,switchTheme:l=>r(l===Nn?null:l)}}function Kr(){const t=getComputedStyle(document.documentElement),s=(i,r)=>t.getPropertyValue(i).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Fr=a.lazy(()=>An(()=>import("./TerminalPanel-_VfntAyG.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function $r({notice:t,onDismiss:s}){const i=me(),[r,c]=a.useState(!1);a.useEffect(()=>{if(r)return;const n=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(n)},[r,t.id,t.level,s]);const l=t.level==="error"?gi:t.level==="warning"?hi:ri;return e.jsxs("div",{className:`notice notice-${t.level}${r?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(l,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:i("close"),onClick:()=>s(t.id),children:e.jsx(Ne,{})})]})}const Hr=[],Tn=180,En=520,Mn=240,Pn=t=>`pi-web-ui:${t}-panel-width`;function _s(t){const s=Number(localStorage.getItem(Pn(t)));return Number.isFinite(s)&&s>=Tn&&s<=En?s:Mn}const Ht=t=>`pi-web-ui:${t}-panel-collapsed`;function As(t){return localStorage.getItem(Ht(t))==="1"}function Fs({side:t,width:s,onResize:i}){const r=me(),c=a.useCallback(l=>{l.preventDefault();const n=l.clientX,o=s;let d=o;const p=v=>{const h=t==="left"?v.clientX-n:n-v.clientX;d=Math.min(En,Math.max(Tn,Math.round(o+h))),i(d)},m=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",m),document.body.classList.remove("panel-resizing"),localStorage.setItem(Pn(t),String(d))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",m),document.body.classList.add("panel-resizing")},[t,s,i]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>i(Mn)})}function $s({side:t,onClick:s}){const i=me();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:i("expandPanel"),onClick:s,children:t==="left"?e.jsx(Qs,{}):e.jsx(Ys,{})})}function Or(){var Ie,Vt,Gt,Qt,Yt,Jt,Xt,Zt,es,ts,ss,ns,is,as;const t=me(),{chat:s,send:i,dismissNotice:r,pushNotice:c,terminal:l}=Ui(),[n,o]=a.useState([]),[d,p]=a.useState(null),[m,v]=a.useState(!1),[h,x]=a.useState("chat"),N=a.useMemo(()=>s.plugins.filter(B=>{var Q,le;return!((le=(Q=s.settings)==null?void 0:Q.disabledPlugins)!=null&&le.includes(B.id))}),[s.plugins,(Ie=s.settings)==null?void 0:Ie.disabledPlugins]),[M,C]=a.useState([]);a.useEffect(()=>Di(C),[]),a.useEffect(()=>{Bi(N,s.pluginsEpoch)},[N,s.pluginsEpoch]);const[I,j]=a.useState(()=>_s("left")),[z,H]=a.useState(()=>_s("right")),R=a.useCallback(B=>j(B),[]),A=a.useCallback(B=>H(B),[]),[P,T]=a.useState(()=>As("left")),[f,_]=a.useState(()=>As("right")),Y=a.useCallback(()=>{T(B=>(localStorage.setItem(Ht("left"),B?"0":"1"),!B))},[]),X=a.useCallback(()=>{_(B=>(localStorage.setItem(Ht("right"),B?"0":"1"),!B))},[]),[O,G]=a.useState(null),[q,k]=a.useState(()=>window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{const B=window.matchMedia("(max-width: 768px)"),Q=le=>k(le.matches);return B.addEventListener("change",Q),()=>B.removeEventListener("change",Q)},[]);const[w,$]=a.useState(!1),[J,Z]=a.useState(!1),[S,ie]=a.useState(!1),[se,u]=a.useState(!1),[W,D]=a.useState(!1),[U,K]=a.useState(null);a.useEffect(()=>{if(!U)return;const B=setTimeout(()=>K(null),15e3);return()=>clearTimeout(B)},[U]),a.useEffect(()=>{const B=Q=>{var Fe,rs;const le=Q.detail,ye=(le==null?void 0:le.title)||"插件命令",be=le==null?void 0:le.command;if(!be||!s.ready)return;const Ee={name:ye,command:be,cwd:"${pwd}"},je=s.terminals.find(bt=>bt.title===ye);if(je)l.restart(je.id),i({type:"run_command",terminalId:je.id,conversationId:je.conversationId,command:Ee,cols:80,rows:24});else{const bt=_e();l.create({id:bt,conversationId:s.activeConversationId||((Fe=s.state)==null?void 0:Fe.conversationId)||"",title:ye,cwd:((rs=s.state)==null?void 0:rs.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Ee})}x("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",B),()=>window.removeEventListener("pi-web-ui:plugin-run-command",B)},[s,l,i]),a.useEffect(()=>{const B=Q=>{!(Q.ctrlKey||Q.metaKey)||Q.key.toLowerCase()!=="k"||(Q.preventDefault(),D(le=>!le))};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[]);const[te,oe]=a.useState(wn),{themes:ve,theme:y,switchTheme:V}=Ar(),de=a.useRef(null),g=a.useRef(null),F=a.useRef(0),ae=a.useRef(!1),he=a.useRef(s.terminals);a.useEffect(()=>{Tr(te)},[te]),a.useEffect(()=>{var Q;const B=he.current;he.current=s.terminals;for(const le of s.terminals){const ye=((Q=le.command)==null?void 0:Q.command)??"",be=B.find(Ee=>Ee.id===le.id);!(be!=null&&be.running)||le.running||(ye.startsWith("pi remove ")?i({type:"extensions_reload"}):ye.startsWith("pi-web-ui install ")||ye.startsWith("pi-web-ui uninstall ")?i({type:"plugins_reload"}):ye.startsWith("npm i -g ")&&(i({type:"extensions_reload"}),i({type:"plugins_reload"}),i({type:"check_updates_all",force:!0})))}},[s.terminals,i]),a.useEffect(()=>{var le;const B=((le=s.state)==null?void 0:le.isStreaming)??!1,Q=de.current;de.current=B,Q!==null&&(!Q&&B?tt("start",te):Q&&!B&&tt("done",te))},[(Vt=s.state)==null?void 0:Vt.isStreaming,te]),a.useEffect(()=>{var Q;const B=((Q=s.dialog)==null?void 0:Q.id)??null;B!==null&&B!==g.current&&tt("question",te),g.current=B},[s.dialog,te]),a.useEffect(()=>{const B=[...s.notices].reverse().find(Q=>Q.level==="error");B&&B.id!==F.current&&(F.current=B.id,tt("error",te))},[s.notices,te]);const xe=(B,Q,le,ye=!1,be)=>{const Ee=`${B}|${le}|${be?`${be.start}-${be.end}`:""}`;o(je=>je.some(Fe=>`${Fe.path}|${Fe.mode}|${Fe.lines?`${Fe.lines.start}-${Fe.lines.end}`:""}`===Ee)?je:[...je,{path:B,name:Q,mode:le,isDir:ye,...be?{lines:be}:{}}])},ue=B=>o(Q=>Q.filter(le=>le.key?le.key!==B:le.path!==B)),Pe=a.useCallback(B=>(!B.type.startsWith("list_")&&!B.type.startsWith("get_")&&G(null),i(B)),[i]),Te=a.useRef(0),Ae=a.useRef(0),Xe=B=>{var ye;const Q=Date.now();(ye=s.state)!=null&&ye.model&&!s.state.model.vision&&Q-Ae.current>1e4&&(Ae.current=Q,c("warning",t("imageNotSupported")));const le=`paste-${++Te.current}`;o(be=>[...be,{path:"",key:le,name:B.name,mode:"inline",imageData:B.data,mimeType:B.mimeType}])},Se=async B=>{for(const Q of B){const le=await on(Q);if(!le){c("error",t("imageLoadFailed",{name:Q.name}));continue}Xe(le)}},Ke=20*1024*1024,Oe=a.useRef(0),We=async B=>{if(B.size>Ke){c("warning",t("fileTooLarge",{name:B.name,size:Ke/1024/1024}));return}let Q;try{Q=(await new Promise((be,Ee)=>{const je=new FileReader;je.onload=()=>be(je.result),je.onerror=()=>Ee(je.error??new Error("read failed")),je.readAsDataURL(B)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:B.name}));return}const le=`upload-${++Oe.current}`;o(ye=>[...ye,{path:"",key:le,name:B.name,mode:"inline",fileData:Q,size:B.size,mimeType:B.type||void 0}])},Re=async B=>{for(const Q of B)Be(Q.type)?await Se([Q]):await We(Q)},E=a.useCallback((B,Q,le)=>{i({type:"edit_message",messageId:B,text:Q,attachments:le})},[i]),pe=a.useCallback(()=>Z(!0),[]),ce=a.useCallback(()=>o([]),[]),ke=a.useCallback(ue,[]),b=a.useCallback(Se,[Se]),L=a.useCallback(Re,[Re]),ne=(Gt=s.state)==null?void 0:Gt.model,re=(Qt=s.state)==null?void 0:Qt.thinkingLevel,ge=(Yt=s.state)==null?void 0:Yt.availableThinkingLevels,fe=a.useMemo(()=>ne?{model:ne,thinkingLevel:re??"off",availableThinkingLevels:ge??[]}:null,[ne,re,ge]),we=a.useCallback(()=>{var B,Q;return!s.ready||s.terminals.length!==0?!1:(l.create({id:_e(),conversationId:s.activeConversationId||((B=s.state)==null?void 0:B.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((Q=s.state)==null?void 0:Q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Jt=s.state)==null?void 0:Jt.cwd,s.terminals.length,t,l]);return a.useEffect(()=>{if(ae.current){if(h!=="terminal"||s.terminals.length!==0){ae.current=!1;return}we()&&(ae.current=!1)}},[s.terminals.length,we,h]),e.jsxs("div",{className:"app",onDragOver:B=>{var Q;Array.from(((Q=B.dataTransfer)==null?void 0:Q.types)??[]).includes("Files")&&(B.preventDefault(),v(!0))},onDragLeave:B=>{B.currentTarget.contains(B.relatedTarget)||v(!1)},onDrop:B=>{var be,Ee;if(v(!1),!Array.from(((be=B.dataTransfer)==null?void 0:be.types)??[]).includes("Files"))return;B.preventDefault();const Q=Array.from(((Ee=B.dataTransfer)==null?void 0:Ee.files)??[]);if(Q.length===0){c("warning",t("foldersNotSupported"));return}const le=Q.filter(je=>Be(je.type)),ye=Q.filter(je=>!Be(je.type));le.length>0&&Se(le),ye.length>0&&Re(ye)},children:[m&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(ji,{chat:s,send:i,terminal:l,view:h,plugins:N,onViewChange:B=>{ae.current=B==="terminal"&&s.terminals.length===0,ae.current&&we()&&(ae.current=!1),x(B),G(null)},onOpenPanel:G,onOpenSettings:()=>ie(!0),onOpenBgTasks:()=>u(!0),onOpenGlobalSearch:()=>D(!0),sound:te,onSoundChange:oe,onSoundPreview:B=>tt(B,te),themes:ve,theme:y,onThemeChange:V}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(B=>e.jsx($r,{notice:B,onDismiss:r},B.id))}),e.jsx(Ka,{send:i,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${I}px`,"--right-w":`${z}px`},children:[O&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>G(null)}),e.jsxs("div",{className:`view-pane ${h==="chat"?"":"hidden"}`,children:[!q&&P&&e.jsx($s,{side:"left",onClick:Y}),e.jsx("div",{className:`panel-drawer drawer-left ${O==="left"?"open":""}${q?"":P?" hidden":""}`,children:e.jsx(Ni,{collapsible:!q,onToggleCollapse:Y,send:Pe,active:!q||O==="left",ready:s.ready,status:s.status,cwd:((Xt=s.state)==null?void 0:Xt.cwd)??"",sessionFile:((Zt=s.state)==null?void 0:Zt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!q&&e.jsx(Fs,{side:"left",width:I,onResize:R}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ja,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:E,onKillBash:()=>i({type:"abort_bash"}),thinkingWrap:((es=s.settings)==null?void 0:es.thinkingWrap)??!0,toolsWrap:((ts=s.settings)==null?void 0:ts.toolsWrap)??!0,jumpTarget:U,onJumpDone:()=>K(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(rr,{send:i,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(cr,{dialog:s.dialog,send:i}),s.question&&e.jsx(dr,{question:s.question,send:i}),e.jsx(ar,{send:i,ready:s.ready,streaming:((ss=s.state)==null?void 0:ss.isStreaming)??!1,messages:((ns=s.state)==null?void 0:ns.messages)??Hr,slashCommands:s.slashCommands,modelState:fe,models:s.models,modelsLoading:s.modelsLoading,attachments:n,onRemoveAttachment:ke,onAddImageFiles:b,onAddLocalFiles:L,onNotice:c,onManageModels:pe,onSent:ce})]}),!q&&e.jsx(Fs,{side:"right",width:z,onResize:A}),e.jsx("div",{className:`panel-drawer drawer-right ${O==="right"?"open":""}${q?"":f?" hidden":""}`,children:e.jsx(Xi,{collapsible:!q,onToggleCollapse:X,send:Pe,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((is=s.state)==null?void 0:is.cwd)??"",onAttach:(B,Q,le,ye)=>{G(null),xe(B,Q,le,ye)},onPreview:(B,Q)=>{G(null),p({path:B,name:Q})},onNotice:(B,Q)=>c(B,Q)})}),!q&&f&&e.jsx($s,{side:"right",onClick:X})]}),e.jsx("div",{className:`view-pane ${h==="terminal"?"":"hidden"}`,children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(Fr,{chat:s,send:i,terminal:l})})}),e.jsx("div",{className:`view-pane ${h==="git"?"":"hidden"}`,children:e.jsx(pr,{chat:s,send:i,terminal:l,active:h==="git",onSwitchToTerminal:()=>x("terminal")})}),M.map(B=>{const Q=`plugin:${B.info.id}`;return e.jsx("div",{className:`view-pane ${h===Q?"":"hidden"}`,children:e.jsx(mr,{entry:B,send:i})},B.info.id)})]})}),e.jsx(lr,{chat:s,send:i}),d&&e.jsx(Cr,{file:d,content:s.fileContent,send:i,onAddLines:(B,Q,le,ye)=>xe(B,Q,"lines",!1,{start:le,end:ye}),onAttach:(B,Q,le)=>xe(B,Q,le),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!w&&!J&&e.jsx(hr,{send:i,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>$(!0)}),J&&e.jsx(xr,{send:i,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>Z(!1)}),S&&e.jsx(kr,{chat:s,send:i,terminal:l,onSwitchToTerminal:()=>x("terminal"),onClose:()=>ie(!1)}),se&&e.jsx(jr,{servers:s.bgServers,send:i,onClose:()=>u(!1)}),e.jsx(Nr,{open:W,send:i,projects:s.projects,cwd:((as=s.state)==null?void 0:as.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>D(!1),onSwitchSession:(B,Q)=>{i({type:"switch_session",path:B});const le=Q&&Q[0];K(le?{path:B,role:le.role,timestamp:le.timestamp}:null)},onSwitchProject:B=>{i({type:"set_cwd",path:B})},onPreviewFile:(B,Q)=>{p({path:B,name:Q})}})]})}Ci();Sn(Cn());Dn.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(ki,{children:e.jsx(Or,{})})}));export{nt as F,Bs as T,He as a,Kr as b,qr as c,Dt as d,De as e,Ne as f,ti as g,Ge as h,_e as r,me as u};
|
|
318
|
+
`)}function Fa(t,s){let i=0,r=t.indexOf(s);for(;r!==-1;)i++,r=t.indexOf(s,r+s.length);return i}function _a(t,s,i,r){const c=new Map,l=i.toLowerCase();if(!l)return c;for(const n of t){if(!s.has(n.id))continue;const o=Fa(Ba(n,r).toLowerCase(),l);o>0&&c.set(n.id,o)}return c}function Aa(t,s){var l;const i=[],r=s.toLowerCase();if(!r)return i;const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(n){const o=n.parentElement;return!o||o.closest(".search-bar")||o.closest(".msg-collapsed")?NodeFilter.FILTER_REJECT:(n.textContent??"").toLowerCase().includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let n=c.nextNode();n;n=c.nextNode()){const o=(n.textContent??"").toLowerCase();if(!((l=n.parentElement)!=null&&l.closest("[data-msg-id]")))continue;let d=o.indexOf(r);for(;d!==-1;){const p=document.createRange();p.setStart(n,d),p.setEnd(n,d+r.length),i.push(p),d=o.indexOf(r,d+r.length)}}return i}function $a(t,s,i,r,c){var d;const l=_a(i,r,s,c),n=new Map;for(const p of Aa(t,s)){const m=(d=p.startContainer.parentElement)==null?void 0:d.closest("[data-msg-id]");if(!(m!=null&&m.dataset.msgId))continue;const v=n.get(m.dataset.msgId);v?v.push(p):n.set(m.dataset.msgId,[p])}const o=[];for(const p of i){const m=n.get(p.id);if(m)for(let h=0;h<m.length;h++)o.push({kind:"dom",range:m[h],msgId:p.id,k:h});const v=l.get(p.id);if(v)for(let h=0;h<v;h++)o.push({kind:"folded",msgId:p.id,k:h})}return o}function Tt(t,s){return t.findIndex(i=>i.msgId===s.msgId&&i.k===s.k)}function Me(t,s){const i=CSS;if(!i.highlights)return;if(s.length===0){i.highlights.delete(t);return}const r=window.Highlight;r&&i.highlights.set(t,new r(...s))}function Ha(t,s){const i=[];let r=t;for(;r&&r!==s;){const c=getComputedStyle(r);/(auto|scroll|hidden)/.test(c.overflowY+c.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&i.push(r),r=r.parentElement}return i}function Oa(t,s){const i=s.startContainer.parentElement;for(const o of Ha(i,t)){const d=s.getBoundingClientRect(),p=o.getBoundingClientRect();if(d.height<=0||d.width<=0)return;d.top>=p.top+4&&d.bottom<=p.bottom-4||(o.scrollTop+=d.top-p.top-(o.clientHeight-d.height)/2),d.left>=p.left+4&&d.right<=p.right-4||(o.scrollLeft+=d.left-p.left-(o.clientWidth-d.width)/2)}const r=s.getBoundingClientRect(),c=t.getBoundingClientRect();if(r.height<=0||r.width<=0)return;const l=r.top>=c.top+6&&r.bottom<=c.bottom-6,n=r.left>=c.left+6&&r.right<=c.right-6;l&&n||(l||(t.scrollTop+=r.top-c.top-(c.height-r.height)/2),n||(t.scrollLeft+=r.left-c.left-(c.width-r.width)/2))}function Wa({containerRef:t,messages:s,collapsedIds:i,toolResults:r,onExpand:c,onProgrammaticScroll:l,open:n,onClose:o}){const d=me(),p=a.useRef(null),[m,v]=a.useState(""),[h,x]=a.useState(null),[N,M]=a.useState(0),[C,I]=a.useState(0),j=a.useDeferredValue(m),z=n?j.trim():"",H=a.useRef(null);H.current=h;const R=a.useRef([]),_=a.useRef({key:null}),P=a.useRef("");a.useEffect(()=>{n&&(x(null),requestAnimationFrame(()=>{var F;return(F=p.current)==null?void 0:F.select()}))},[n]),a.useEffect(()=>{if(!n)return;const F=Y=>{Y.key==="Escape"&&(Y.preventDefault(),Y.stopPropagation(),o())};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[n,o]),a.useEffect(()=>(n||(Me("msg-search",[]),Me("msg-search-active",[])),()=>{Me("msg-search",[]),Me("msg-search-active",[])}),[n]),a.useLayoutEffect(()=>{const F=()=>{M(0),x(null),I(0),R.current=[],Me("msg-search",[]),Me("msg-search-active",[]),_.current={key:null},P.current=""};if(!n||!z){F();return}const Y=t.current;if(!Y)return;let X=!1,O=0;return O=requestAnimationFrame(()=>{var ie,se;if(X)return;const G=$a(Y,z,s,i,r);R.current=G;const q=G.length;if(M(q),q===0){x(null),I(0),Me("msg-search",[]),Me("msg-search-active",[]),_.current={key:null},P.current=z;return}const k=H.current;let w;if(k){if(w=Tt(G,k),w===-1){const u=[];for(let W=0;W<G.length;W++)G[W].msgId===k.msgId&&u.push(W);if(u.length>0){const W=Math.min(k.k,u.length-1);w=u[W]}else w=0}}else w=0;w<0&&(w=0),w>=q&&(w=q-1),(!k||k.msgId!==G[w].msgId||k.k!==G[w].k)&&x({msgId:G[w].msgId,k:G[w].k}),I(w);const $=G[w],J=_.current,Z=((ie=J.key)==null?void 0:ie.msgId)!==$.msgId||((se=J.key)==null?void 0:se.k)!==$.k||J.kind==="folded"&&$.kind==="dom"||z!==P.current;_.current={key:{msgId:$.msgId,k:$.k},kind:$.kind},P.current=z;const S=G.filter(u=>u.kind==="dom").map(u=>u.range);if(Me("msg-search",S),$.kind==="folded"){Me("msg-search-active",[]),Z&&c($.msgId);return}Me("msg-search-active",[$.range]),Z&&(l==null||l(),Oa(Y,$.range))}),()=>{X=!0,cancelAnimationFrame(O)}},[n,z,s,t,h,i,r,c,l]);const T=a.useCallback(F=>{const Y=R.current,X=Y.length;if(X===0)return;const O=H.current,G=O?Tt(Y,O):0,q=Y[(G+F+X)%X];x(q.kind==="dom"||q.kind==="folded"?{msgId:q.msgId,k:q.k}:null)},[]);if(!n)return null;const f=h?(()=>{const F=Tt(R.current,h);return F===-1?0:F})():0;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:p,className:"search-input",type:"text",value:m,placeholder:d("searchPlaceholder"),onChange:F=>{v(F.target.value)},onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),T(F.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${N===0?"empty":""}`,children:N===0?d("searchNoResults"):`${Math.min(f+1,N)}/${N}`}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchPrev"),disabled:N===0,onClick:()=>T(-1),children:e.jsx(ft,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchNext"),disabled:N===0,onClick:()=>T(1),children:e.jsx(qe,{})}),e.jsx("button",{type:"button",className:"search-btn",title:d("searchClose"),onClick:o,children:e.jsx(Ne,{})})]})}function Ua(t){const{dSt:s,dSh:i,escaped:r,graceActive:c,stuck:l}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:i<0?{flipEscape:!1,reassert:l&&!r}:{flipEscape:!0,reassert:!1}}const gn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],fn="pi-web-ui:prompt-templates";function qa(){try{const t=localStorage.getItem(fn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(i=>!!i&&typeof i=="object"&&typeof i.id=="string"):[]}catch{return[]}}function Ts(t){return gn.some(s=>s.id===t)}function lt(t){return typeof t.title=="string"}const xn=a.createContext(null);function vn(){const t=a.useContext(xn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function Ka({send:t,children:s}){const i=me(),[r,c]=a.useState(qa),[l,n]=a.useState(!1),[o,d]=a.useState(null),[p,m]=a.useState(!1),[v,h]=a.useState(!1),[x,N]=a.useState(!1);a.useEffect(()=>{try{localStorage.setItem(fn,JSON.stringify(r))}catch{}},[r]);const M=a.useMemo(()=>{const O=new Map,G=new Set;for(const w of r)w.hidden?G.add(w.id):(lt(w)&&!Ts(w.id)||lt(w))&&O.set(w.id,w);const q=gn.filter(w=>!G.has(w.id)).map(w=>{const $=O.get(w.id);return{id:w.id,icon:($==null?void 0:$.icon)??w.icon,title:($==null?void 0:$.title)??i(w.titleKey),desc:($==null?void 0:$.desc)??i(w.descKey),prompt:($==null?void 0:$.prompt)??i(w.promptKey),builtin:!0}}),k=r.filter(w=>lt(w)&&!Ts(w.id)).map(w=>({id:w.id,icon:w.icon??"📌",title:w.title??"",desc:w.desc??"",prompt:w.prompt??""}));return[...q,...k]},[r,i]),C=a.useCallback(()=>n(!0),[]),I=a.useCallback(O=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:O}))},[]),j=a.useCallback((O,G=!1)=>{N(G),O?(m(!1),d({...O})):(m(!0),d({id:Fe(),icon:"📌",title:"",desc:"",prompt:""}))},[]),z=a.useCallback(()=>{n(!1),d(null),N(!1)},[]),H=a.useCallback(()=>{v?(c([]),h(!1)):(h(!0),setTimeout(()=>h(!1),5e3))},[v]),R=a.useCallback(O=>{n(!1),I(O.prompt)},[I]),_=a.useCallback(O=>{n(!1),j(O,!0)},[j]),P=a.useCallback(()=>{n(!1),j(void 0,!0)},[j]),T=a.useCallback(O=>{c(G=>{const q=G.findIndex(k=>k.id===O.id);if(q>=0){const k=[...G];return k[q]=O,k}return[...G,O]}),d(null),x&&(n(!0),N(!1))},[x]),f=a.useCallback(O=>{c(G=>O.builtin?[...G.filter(k=>k.id!==O.id),{id:O.id,hidden:!0}]:G.filter(q=>q.id!==O.id)),d(null),x&&(n(!0),N(!1))},[x]),F=a.useCallback(O=>{c(G=>G.filter(q=>q.id!==O.id||q.hidden)),d(null),x&&(n(!0),N(!1))},[x]),Y=a.useMemo(()=>({templates:M,fill:I,openPicker:C,openEdit:j,resetConfirm:v,toggleReset:H}),[M,I,C,j,v,H]),X=o?r.some(O=>O.id===o.id&&!O.hidden&<(O)):!1;return e.jsxs(xn.Provider,{value:Y,children:[s,l&&e.jsx(Va,{templates:M,resetConfirm:v,onFill:R,onEditTpl:_,onNew:P,onResetToggle:H,onClose:z}),o&&e.jsx(Ga,{editing:o,isNew:p,hasOverride:X,onDraft:d,onSave:T,onRestore:()=>F(o),onRemove:()=>f(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),z()},onSend:()=>{const O=o.prompt.trim();O&&t({type:"prompt",text:O,queue:!1})&&z()},onClose:z})]})}function za(){const t=me(),{templates:s,fill:i,openEdit:r,toggleReset:c,resetConfirm:l}=vn();return e.jsxs("div",{className:"empty-templates",children:[e.jsxs("div",{className:"empty-templates-head",children:[e.jsx("span",{className:"empty-templates-title",children:t("tpl.title")}),e.jsx("span",{className:"empty-templates-hint",children:t("tpl.hint")})]}),e.jsxs("div",{className:"empty-templates-grid",children:[s.map(n=>e.jsx(yn,{tpl:n,title:t("tpl.clickCard"),onFill:()=>i(n.prompt),onEdit:()=>r(n),editTitle:t("tpl.editTpl")},n.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>r(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(zs,{}),t(l?"tpl.resetConfirm":"tpl.reset")]})})]})}function yn({tpl:t,title:s,onFill:i,onEdit:r,editTitle:c}){const l=me();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:i,children:[e.jsx("span",{className:"empty-template-icon",children:t.icon}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t.title}),e.jsx("span",{className:"empty-template-desc",children:t.desc})]}),e.jsx("span",{className:"template-card-ops",role:"button",title:c??l("tpl.editTpl"),onClick:n=>{n.stopPropagation(),r()},children:e.jsx(Dt,{})})]})}function Va({templates:t,resetConfirm:s,onFill:i,onEditTpl:r,onNew:c,onResetToggle:l,onClose:n}){const o=me();return a.useEffect(()=>{const d=p=>{p.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal template-picker",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"template-picker-head",children:[e.jsx("span",{className:"template-picker-title",children:o("tpl.pickerTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:o("close"),onClick:n,children:e.jsx(Ne,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(d=>e.jsx(yn,{tpl:d,title:o("tpl.clickCard"),onFill:()=>i(d),onEdit:()=>r(d),editTitle:o("tpl.editTpl")},d.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:c,title:o("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:l,children:[e.jsx(zs,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Ga({editing:t,isNew:s,hasOverride:i,onDraft:r,onSave:c,onRestore:l,onRemove:n,onFill:o,onSend:d,onClose:p}){const m=me(),v=a.useRef(null);a.useEffect(()=>{const N=M=>{M.key==="Escape"&&p()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[p]),a.useEffect(()=>{const N=v.current;if(!N)return;N.style.height="auto";const M=N.scrollHeight>300;N.style.height=`${Math.min(N.scrollHeight,300)}px`,N.style.overflowY=M?"auto":"hidden"},[t.prompt]);const h=()=>{const N=t.title.trim(),M=t.prompt.trim();if(!N||!M){r({...t,error:m("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:N,desc:t.desc.trim(),prompt:M})},x=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:p,children:e.jsxs("div",{className:"modal template-modal",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"template-modal-head",children:[e.jsx("span",{className:"template-modal-icon",children:t.icon}),e.jsx("span",{className:"template-modal-badge",children:m(x?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:m(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:m("close"),onClick:p,children:e.jsx(Ne,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:N=>r({...t,icon:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:m("tpl.fieldTitlePh"),onChange:N=>r({...t,title:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:m("tpl.fieldDescPh"),onChange:N=>r({...t,desc:N.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:m("tpl.fieldPrompt")}),e.jsx("textarea",{ref:v,className:"template-field-prompt",value:t.prompt,placeholder:m("tpl.fieldPromptPh"),onChange:N=>r({...t,prompt:N.target.value})})]}),t.error&&e.jsx("div",{className:"template-error",children:t.error}),e.jsxs("div",{className:"template-modal-actions",children:[e.jsxs("div",{className:"template-modal-actions-left",children:[!s&&x&&i&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:m("tpl.restoreTip"),onClick:l,children:m("tpl.restore")}),!s&&x&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:m("tpl.removeTip"),onClick:n,children:[e.jsx(De,{})," ",m("tpl.remove")]}),!s&&!x&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:m("tpl.deleteTip"),onClick:n,children:[e.jsx(De,{})," ",m("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:h,children:m("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:m("tpl.fillTip"),children:m("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:d,title:m("tpl.sendTip"),children:[e.jsx(Ks,{})," ",m("tpl.sendNow")]})]})]})]})})}const Es=new Map,Qa=15,Ms=30,Et=250,Ps=1200,Ya=1600;function Rs(t){return t.content.some(s=>s.type==="toolCall")}function Ja({state:t,liveOutputs:s,toolStatuses:i,onEdit:r,onKillBash:c,thinkingWrap:l,toolsWrap:n,jumpTarget:o,onJumpDone:d}){const p=me(),m=a.useRef(null),[v,h]=a.useState(!0),x=a.useRef(!0),N=a.useRef(0),M=a.useRef(0),C=a.useRef(!1),I=a.useRef(0),[j,z]=a.useState(()=>new Set),[H,R]=a.useState(!1),_=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,P=a.useMemo(()=>{const b=new Map;for(const L of t.messages)L.role==="toolResult"&&L.toolCallId&&b.set(L.toolCallId,L);return b},[t.messages]),T=a.useMemo(()=>Na(t.messages),[t.messages]),f=_.length>0?_[_.length-1].id:null,F=t.messages.length>Ms?Math.max(0,t.messages.length-Qa):0,Y=a.useMemo(()=>{const b=new Set;for(let L=0;L<F;L++){const ne=t.messages[L];ne.role!=="toolResult"&&(j.has(ne.id)||b.add(ne.id))}return b},[t.messages,F,j]),[X,O]=a.useState(()=>new Set),[G,q]=a.useState(()=>new Set),k=a.useRef(new Map),w=a.useRef(new Map),$=a.useRef(new Map),J=a.useRef(0),Z=a.useMemo(()=>{const b=new Map;for(const L of t.messages)b.set(L.id,Ia(L));return b},[t.messages]),S=a.useRef(Z);S.current=Z;const ie=a.useRef(X);ie.current=X;const se=t.messages.length>Ms&&!H,u=a.useRef(se);u.current=se;const W=Pa(t.messages,k.current,Ya),D=a.useRef(W);D.current=W;const U=a.useCallback(()=>{const b=m.current;if(!b)return;if(!u.current){O(fe=>fe.size?new Set:fe);return}const L=b.getBoundingClientRect(),ne={top:L.top-Ps,bottom:L.bottom+Ps},re=[];for(const[fe,we]of $.current){const Ie=we.getBoundingClientRect();re.push({id:fe,top:Ie.top,bottom:Ie.bottom}),ie.current.has(fe)||oe(fe,Ie.bottom-Ie.top,S.current.get(fe))}const ge=Ea(re,ne,D.current,ie.current);for(const fe of ge.hide){const we=$.current.get(fe);we&&oe(fe,we.offsetHeight,S.current.get(fe))}O(fe=>Ma(fe,ge))},[]),K=a.useCallback(()=>{J.current||(J.current=requestAnimationFrame(()=>{J.current=0,U()}))},[U]);a.useLayoutEffect(()=>{U()},[U]);const te=a.useRef(H);a.useLayoutEffect(()=>{te.current&&!H&&U(),te.current=H},[H,U]);const oe=a.useCallback((b,L,ne)=>{ne!==void 0&&(w.current.set(b,{h:L,len:ne}),k.current.set(b,L))},[]),ve=a.useCallback((b,L)=>{oe(b,L,S.current.get(b))},[oe]),y=a.useCallback(b=>{b&&$.current.set(b.dataset.lazyId??"",b)},[]);a.useEffect(()=>{const b=new Set(t.messages.map(L=>L.id));for(const[L,ne]of $.current)b.has(L)||($.current.delete(L),k.current.delete(L),w.current.delete(L));O(L=>{let ne=!1;const re=new Set;for(const ge of L)b.has(ge)?re.add(ge):ne=!0;return ne?re:L})},[t.messages,j]),a.useEffect(()=>()=>cancelAnimationFrame(J.current),[]);const V=a.useMemo(()=>{const b=[];for(const L of t.messages){if(L.role!=="user")continue;const ne=L.content.map(fe=>{var we;return((we=at(fe))==null?void 0:we.text)??""}).filter(Boolean).join(" "),re=Kt(ne),ge=re?re.userMessage??`skill:${re.name}`:ne.trim();ge&&b.push({id:L.id,text:ge})}return b},[t.messages]),de=a.useMemo(()=>{const b=new Map;return V.forEach((L,ne)=>b.set(L.id,ne)),b},[V]),[g,A]=a.useState(-1),ae=a.useRef(-1),he=a.useRef(V);a.useEffect(()=>{he.current=V},[V]);const xe=a.useCallback(()=>{const b=m.current,L=he.current;if(!b||L.length===0)return;const ne=b.getBoundingClientRect().top,re=140;let ge=-1;for(let fe=0;fe<L.length;fe++){const we=b.querySelector(`[data-msg-id="${L[fe].id}"]`);if(we)if(we.getBoundingClientRect().top<=ne+re)ge=fe;else break}ge!==ae.current&&(ae.current=ge,A(ge))},[]);a.useEffect(()=>{xe()},[V,xe]);const ue=a.useCallback(b=>{z(L=>L.has(b)?L:new Set(L).add(b))},[]);a.useEffect(()=>{const b=L=>{if(!(L.ctrlKey||L.metaKey)||L.key.toLowerCase()!=="f")return;const ne=L.target;ne&&(ne.tagName==="INPUT"||ne.tagName==="TEXTAREA"||ne.isContentEditable)||(L.preventDefault(),R(!0))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]);const Pe=a.useCallback(b=>{z(L=>{if(!L.has(b))return L;const ne=new Set(L);return ne.delete(b),ne})},[]),Te=a.useCallback(b=>{const L=t.messages.findIndex(re=>re.id===b);Zi.flushSync(()=>{L>=0&&L<F&&!j.has(b)&&ue(b),q(re=>re.has(b)?re:new Set(re).add(b))});const ne=he.current.findIndex(re=>re.id===b);ae.current=ne,A(ne),requestAnimationFrame(()=>{var ge,fe,we;const re=(ge=m.current)==null?void 0:ge.querySelector(`[data-msg-id="${b}"]`);re&&((fe=m.current)==null||fe.querySelectorAll(".msg-flash").forEach(Ie=>Ie.classList.remove("msg-flash")),re.scrollIntoView({block:"start"}),re.classList.remove("msg-flash"),re.offsetWidth,re.classList.add("msg-flash"),re!==((we=m.current)==null?void 0:we.lastElementChild)&&(C.current=!0))})},[t.messages,F,j,ue]),_e=a.useMemo(()=>{var b;return o?((b=t.messages.find(L=>L.role===o.role&&L.timestamp===o.timestamp))==null?void 0:b.id)??null:null},[t.messages,o]);a.useEffect(()=>{if(o){if(_e){Te(_e),d==null||d();return}t.sessionFile===o.path&&t.messages.length>0&&(d==null||d())}},[_e,Te,d,o,t.sessionFile,t.messages.length]);const Xe=a.useCallback(()=>{const b=m.current;if(!b)return;const L=b.scrollTop-N.current,ne=b.scrollHeight-M.current;N.current=b.scrollTop,M.current=b.scrollHeight;const re=b.scrollHeight-b.scrollTop-b.clientHeight<80,ge=Date.now()<I.current,fe=Ua({dSt:L,dSh:ne,escaped:C.current,graceActive:ge,stuck:x.current});fe.reassert&&(I.current=Date.now()+Et,b.scrollTop=b.scrollHeight),fe.flipEscape&&(C.current=!0),re&&L>=0&&(C.current=!1),ge||(L<0?x.current=re&&!C.current:re&&(x.current=!0)),h(x.current),xe(),K()},[xe,K]),Se=a.useRef(!1);a.useEffect(()=>{const b=Se.current;if(Se.current=!!t.isStreaming,b&&!t.isStreaming&&!C.current){const L=()=>{const re=m.current;re&&!C.current&&(re.scrollTop=re.scrollHeight,x.current=!0,h(!0))};requestAnimationFrame(()=>requestAnimationFrame(L));const ne=setTimeout(L,180);return()=>clearTimeout(ne)}},[t.isStreaming]),a.useEffect(()=>{const b=m.current;b&&x.current&&(b.scrollTop=b.scrollHeight)},[_,t.isStreaming,s]);const Ke=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");a.useEffect(()=>{const b=m.current;b&&x.current&&(b.scrollTop=b.scrollHeight)},[Ke]),a.useEffect(()=>{const b=m.current;if(!b||typeof ResizeObserver>"u")return;const L=new ResizeObserver(()=>{x.current&&!C.current&&(b.scrollTop=b.scrollHeight,h(!0))});return L.observe(b),()=>L.disconnect()},[]),a.useEffect(()=>{const b=m.current;if(!b||typeof MutationObserver>"u")return;let L=!1;const ne=new MutationObserver(()=>{L||(L=!0,requestAnimationFrame(()=>{L=!1;const re=m.current;re&&x.current&&!C.current&&(re.scrollTop=re.scrollHeight,h(!0))}))});return ne.observe(b,{childList:!0,subtree:!0,characterData:!0}),()=>ne.disconnect()},[]);const Oe=a.useCallback(()=>{if(!m.current)return;x.current=!0,C.current=!1,h(!0),I.current=Date.now()+Et;const L=()=>{const ne=m.current;!ne||!x.current||C.current||(I.current=Date.now()+Et,ne.scrollTop=ne.scrollHeight)};L(),requestAnimationFrame(()=>requestAnimationFrame(L)),setTimeout(L,120),setTimeout(L,300),setTimeout(L,600)},[]),We=a.useRef(null);a.useEffect(()=>{const b=We.current,L=m.current;if(!b||!L)return;const ne=re=>{re.preventDefault();const ge=b.querySelector(".qn-list");if(ge&&ge.contains(re.target)&&ge.scrollHeight>ge.clientHeight){ge.scrollTop+=re.deltaY;return}L.scrollTop+=re.deltaY};return b.addEventListener("wheel",ne,{passive:!1}),()=>b.removeEventListener("wheel",ne)},[]);const[Re,E]=a.useState(0);a.useEffect(()=>{const b=()=>{var L;E(((L=m.current)==null?void 0:L.clientHeight)??0),K()};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[K]);const pe=V.length,ce=a.useMemo(()=>pe===0?27:Math.max(4,Math.min(27,Math.floor(((Re||600)-16)/pe)-3)),[pe,Re]),ke=ce<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${H||v?"":" anchor-live"}`,ref:m,onScroll:Xe,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(za,{})}),t.messages.map((b,L)=>{const ne=L<F,re=ne&&j.has(b.id);if(ne&&!re)return b.role==="toolResult"?null:e.jsx(Ca,{message:b,onExpand:ue},b.id);const ge=b.role==="user"?de.get(b.id):void 0,fe=!se||W.has(b.id)||G.has(b.id)||!X.has(b.id);return e.jsx(Ta,{id:b.id,show:fe,height:La(b.id,Z.get(b.id)??-1,w.current,hn(b.role,b.customType)),containerRef:m,onMeasured:ve,lazyRef:y,children:e.jsx(ws,{message:b,qnIndex:ge,qnActive:ge!==void 0?ge===g:void 0,onJump:Te,toolResults:P,liveOutputs:Rs(b)?s:Es,toolStatuses:i,streaming:t.isStreaming,onKillBash:c,toolsWrap:n,thinkingWrap:l,isLast:b.id===f,onEdit:r,questionAttachments:T.get(b.id),onCollapse:re?Pe:void 0,searchActive:H},b.id)},b.id)}),t.streamingMessage&&e.jsx(ws,{message:t.streamingMessage,toolResults:P,liveOutputs:Rs(t.streamingMessage)?s:Es,toolStatuses:i,streaming:!0,isLast:!0,onEdit:r,onKillBash:c,toolsWrap:n,thinkingWrap:l,searchActive:H},t.streamingMessage.id),t.isStreaming&&_.length===0&&e.jsx("div",{className:"streaming-wait",children:p("waitingResponse")}),t.queue.steering.map((b,L)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:p("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-steer-${L}`)),t.queue.followUp.map((b,L)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:p("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:b})]})},`q-fu-${L}`))]}),!v&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Oe,children:[e.jsx(Xs,{})," ",p("backToBottom")]}),e.jsx(Wa,{containerRef:m,messages:_,collapsedIds:Y,toolResults:P,onExpand:ue,onProgrammaticScroll:()=>{C.current=!0,x.current=!1,h(!1)},open:H,onClose:()=>R(!1)}),V.length>0&&e.jsxs("div",{className:`qn-rail ${ke?"many":""}`,ref:We,"aria-label":p("questionNavTitle"),style:{"--rail-gap":`${ce}px`},children:[V.map((b,L)=>e.jsx("button",{type:"button",className:`qn-bar ${L===g?"active":""}`,"aria-label":`${L+1}. ${b.text}`,onClick:()=>Te(b.id),children:e.jsxs("span",{className:"qn-bar-text",children:[L+1,". ",b.text]})},b.id)),ke&&e.jsx("div",{className:"qn-list",children:V.map((b,L)=>e.jsxs("button",{type:"button",className:`qn-list-item ${L===g?"active":""}`,"aria-label":`${L+1}. ${b.text}`,onClick:()=>Te(b.id),children:[e.jsx("span",{className:"qn-list-idx",children:L+1}),e.jsx("span",{className:"qn-list-text",children:b.text})]},b.id))})]})]})}const kn="pi-web-model-usage";function Xa(t){if(!t||typeof t!="object")return{};const s={};for(const[i,r]of Object.entries(t)){const c=typeof r=="number"?Math.floor(r):0;Number.isFinite(c)&&c>0&&(s[i]=c)}return s}function Za(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function er(t,s){const i=s;return t.map((r,c)=>({m:r,i:c,count:i[r.id]??0})).sort((r,c)=>c.count-r.count||r.i-c.i).map(r=>r.m)}function bn(){try{const t=localStorage.getItem(kn);return t?Xa(JSON.parse(t)):{}}catch{return{}}}function tr(t){try{localStorage.setItem(kn,JSON.stringify(t))}catch{}}function sr(t){const s=Za(bn(),t);return tr(s),s}const nr=["off","minimal","low","medium","high","xhigh","max"],ir=a.memo(function({state:s,models:i,modelsLoading:r,send:c,onManageModels:l,compact:n=!1}){const o=me(),d=s==null?void 0:s.model,p=d?`${d.provider}/${d.id}`:null,[m,v]=a.useState(!1),[h,x]=a.useState(!1),[N,M]=a.useState(""),[C,I]=a.useState(null),[j,z]=a.useState({}),H=a.useRef(null),R=a.useRef(null),[_,P]=a.useState(null);a.useEffect(()=>{if(!m){P(null);return}if(i.length===0)return;const k=requestAnimationFrame(()=>{const w=R.current;w&&P(w.offsetWidth)});return()=>cancelAnimationFrame(k)},[m,i.length]),a.useEffect(()=>{m&&z(bn())},[m]),a.useEffect(()=>{m||(M(""),I(null))},[m]);const T=a.useMemo(()=>{const k=new Map;for(const w of i)k.set(w.provider,(k.get(w.provider)??0)+1);return[...k.entries()].sort((w,$)=>w[0].localeCompare($[0])).map(([w,$])=>({name:w,count:$}))},[i]),f=a.useMemo(()=>er(i,j),[i,j]),F=a.useMemo(()=>{let k=f;C&&(k=k.filter($=>$.provider===C));const w=N.trim().toLowerCase();return w?k.filter($=>$.name.toLowerCase().includes(w)||$.provider.toLowerCase().includes(w)||$.id.toLowerCase().includes(w)):k},[f,N,C]),[Y,X]=a.useState(!1),O=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,G=nr.map(k=>({value:k,label:o(`thinking.${k}`),supported:O?O.has(k):!0})),q=k=>{var w;return((w=G.find($=>$.value===k))==null?void 0:w.label)??k};return a.useEffect(()=>{m&&i.length===0&&!Y&&!r&&(X(!0),c({type:"list_models"}))},[m,i.length,Y,r,c]),a.useEffect(()=>{i.length>0&&X(!1)},[i.length]),a.useEffect(()=>{var w;if(!m)return;const k=(w=H.current)==null?void 0:w.querySelector(".dd-item.active");k==null||k.scrollIntoView({block:"nearest"})},[m,p,i.length]),e.jsxs(e.Fragment,{children:[e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(it,{}),e.jsx("span",{className:"chip-model",children:d?d.name:o("selectModel")}),!n&&(d==null?void 0:d.vision)&&e.jsx("span",{className:"chip-vision",title:o("vision"),children:"🖼"}),!n&&d&&e.jsx("span",{className:"chip-sub",children:d.provider})]}),open:m,onOpenChange:v,menuClassName:"dd-menu-model",menuRef:R,menuStyle:_!=null?{width:_}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(ht,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:o("searchModels"),value:N,onChange:k=>M(k.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[T.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:o("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${C===null?"active":""}`,onClick:()=>I(null),children:e.jsx("span",{children:o("allProviders")})}),T.map(k=>e.jsxs("button",{type:"button",className:`dd-provider-item ${C===k.name?"active":""}`,onClick:()=>I(C===k.name?null:k.name),title:`${k.name} · ${k.count}`,children:[e.jsx("span",{className:"dd-provider-name",children:k.name}),e.jsx("span",{className:"dd-provider-count",children:k.count})]},k.name))]}),e.jsxs("div",{className:"dd-model-scroll",ref:H,children:[(Y||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!Y&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),F.length===0&&i.length>0&&e.jsx("div",{className:"dd-loading",children:o("noModelMatches")}),F.map(k=>e.jsx(Ce,{active:p===k.id,onClick:()=>{p!==k.id&&c({type:"set_model",modelId:k.id}),v(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:k.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:k.provider}),(j[k.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:o("modelUsedCount",{n:j[k.id]})}),(k.reasoning||k.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[k.reasoning&&e.jsx("span",{className:"dd-model-badge",children:o("reasoning")}),k.vision&&e.jsx("span",{className:"dd-model-badge",children:o("vision")})]})]})]})},k.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:()=>{v(!1),l()},children:o("manageModels")})]})]}),e.jsxs($e,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ot,{}),e.jsx("span",{className:"chip-sub",children:o("thinkingChip",{level:s?q(s.thinkingLevel):"—"})})]}),open:h,onOpenChange:x,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("thinkingLevel")}),G.map(k=>e.jsx(Ce,{active:(s==null?void 0:s.thinkingLevel)===k.value,disabled:!k.supported,title:k.supported?void 0:o("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==k.value&&c({type:"set_thinking",level:k.value}),x(!1)},children:k.label},k.value))]})]})}),ar=a.memo(function({ready:s,streaming:i,messages:r,slashCommands:c,modelState:l,models:n,modelsLoading:o,send:d,attachments:p,onRemoveAttachment:m,onAddImageFiles:v,onAddLocalFiles:h,onNotice:x,onSent:N,onManageModels:M}){const C=me(),{locale:I}=Ut(),{openPicker:j}=vn(),z=y=>I==="en"&&y.descriptionEn?y.descriptionEn:y.description??"",H=y=>I==="en"&&y.argumentHintEn?y.argumentHintEn:y.argumentHint??"",[R,_]=a.useState(""),[P,T]=a.useState(!1),[f,F]=a.useState(null),[Y,X]=a.useState(0),[O,G]=a.useState(!1),[q,k]=a.useState(void 0),w=a.useRef(null),$=a.useRef(null),J=a.useRef(null),Z={builtin:C("slashBuiltin"),extension:C("slashExtension"),prompt:C("slashPrompt"),skill:C("slashSkill"),plugin:C("slashPlugin")},S=y=>{const V=y.match(/^\/([^\s]*)$/);if(V&&s){const de=V[1].toLowerCase(),g=c.filter(A=>A.name.toLowerCase().startsWith(de));F(g.length>0?g:null),X(0)}else F(null)};a.useEffect(()=>{var V;const y=(V=J.current)==null?void 0:V.querySelector(".slash-item.active");y==null||y.scrollIntoView({block:"nearest"})},[Y,f]);const ie=y=>{var ae;const V=f??[],de=y??V[Y%Math.max(V.length,1)];if(!de){F(null);return}const g=R.match(/^\/([^\s]*)([\s\S]*)$/),A=g?g[2]:"";_(`/${de.name} ${A}`),F(null),(ae=w.current)==null||ae.focus()},se=async()=>{const V=[...r].reverse().find(g=>g.role==="assistant"&&g.content.some(A=>A.type==="text"&&A.text)),de=V==null?void 0:V.content.filter(g=>g.type==="text").map(g=>g.text).join(`
|
|
319
|
+
`);if(!de){x("warning",C("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(de),x("info",C("slashCopied"))}catch{x("error",C("slashCopyFailed"))}},u=y=>{if(!y||y.length===0){x("warning",C("foldersNotSupported"));return}const V=Array.from(y).filter(A=>Be(A.type)),de=Array.from(y).filter(A=>!Be(A.type)),g=D();V.length>0&&g?x("warning",g):V.length>0&&v(V),de.length>0&&h(de)},W=y=>{var A;const V=(A=y.clipboardData)==null?void 0:A.items;if(!V)return;const de=[];for(const ae of V)if(ae.kind==="file"&&Be(ae.type)){const he=ae.getAsFile();he&&de.push(he)}if(de.length===0)return;y.preventDefault();const g=D();if(g){x("warning",g);return}v(de)},D=()=>{const y=l==null?void 0:l.model;if(!(y!=null&&y.id))return null;const V=n.find(de=>de.id===y.id);return V&&V.vision===!1?C("modelNoVision",{name:V.name}):null},U=s,K=a.useRef(R);a.useEffect(()=>{K.current=R},[R]),a.useEffect(()=>{S(K.current)},[c]),a.useEffect(()=>{const y=V=>{var g;const de=V.detail;_(de),(g=w.current)==null||g.focus()};return window.addEventListener("pi-web:fill",y),()=>window.removeEventListener("pi-web:fill",y)},[]),a.useEffect(()=>{if(!O)return;const y=V=>{V.key==="Escape"&&G(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[O]),a.useEffect(()=>{const y=w.current;if(!y)return;y.style.height="auto";const V=y.scrollHeight>220;y.style.height=`${Math.min(y.scrollHeight,220)}px`,y.style.overflowY=V?"auto":"hidden"},[R]);const te=(y=!1)=>{var g,A,ae,he,xe;const V=R.trim(),de=p.some(ue=>ue.imageData||ue.fileData);if(!(!U||!V&&!de)){if(V==="/help"){const ue=(A=(g=w.current)==null?void 0:g.closest(".inputbox"))==null?void 0:A.getBoundingClientRect();k(ue==null?void 0:ue.width),G(!0),_(""),(ae=w.current)==null||ae.focus();return}if(V==="/copy"){_(""),(he=w.current)==null||he.focus(),se();return}if(d({type:"prompt",text:V,queue:y,attachments:p.map(ue=>ue.imageData?{path:"",imageData:ue.imageData,mimeType:ue.mimeType,name:ue.name}:ue.fileData?{path:"",fileData:ue.fileData,mimeType:ue.mimeType,name:ue.name,size:ue.size}:{path:ue.path,mode:ue.mode,...ue.lines?{lines:ue.lines}:{}})})){_(""),N();const ue=l==null?void 0:l.model;ue&&sr(`${ue.provider}/${ue.id}`),(xe=w.current)==null||xe.focus()}}},oe=y=>{if(!y.nativeEvent.isComposing){if(f&&f.length>0)switch(y.key){case"ArrowDown":y.preventDefault(),X(V=>(V+1)%f.length);return;case"ArrowUp":y.preventDefault(),X(V=>(V-1+f.length)%f.length);return;case"Tab":case"Enter":y.preventDefault(),ie();return;case"Escape":y.preventDefault(),F(null);return}y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),te())}},ve=()=>e.jsx("div",{className:"inputbox-actions",children:i?e.jsxs(e.Fragment,{children:[R.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:C("supplementTip"),onClick:()=>te(!0),children:[e.jsx(Ks,{})," ",C("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:C("stopAgent"),onClick:()=>d({type:"abort"}),children:e.jsx(pt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:C("sendTip"),disabled:!U||!R.trim()&&!p.some(y=>y.imageData||y.fileData),onClick:()=>te(),children:e.jsx(Js,{})})});return e.jsxs("div",{className:`inputbar${P?" drop-active":""}`,onDragOver:y=>{y.preventDefault(),y.stopPropagation(),T(!0)},onDragLeave:y=>{y.currentTarget.contains(y.relatedTarget)||T(!1)},onDrop:y=>{var V;y.preventDefault(),y.stopPropagation(),T(!1),u(((V=y.dataTransfer)==null?void 0:V.files)??null)},children:[P&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",C("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(y=>e.jsxs("span",{className:`attach-chip ${y.imageData?"image":y.fileData?"file":y.mode}`,title:y.imageData?C("attachImage",{name:y.name}):y.fileData?C("attachFile",{name:y.name}):y.isDir?C("folderRef",{path:y.path}):y.mode==="reference"?C("refOnly",{path:y.path}):y.mode==="lines"&&y.lines?C("attachLines",{path:y.path,start:y.lines.start,end:y.lines.end}):C("attachContent",{path:y.path}),children:[y.imageData?"🖼":y.fileData?"📄":y.isDir?"📁":y.mode==="reference"?"🔗":"📎"," ",y.name,y.mode==="lines"&&y.lines&&e.jsxs("span",{className:"attach-range",children:["L",y.lines.start,"-",y.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:C("removeAttachment"),onClick:()=>m(y.key??y.path),children:"×"})]},y.key??`${y.path}|${y.mode}|${y.lines?`${y.lines.start}-${y.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:C("attachHint")})]}),f&&f.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:J,"aria-label":C("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:C("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>F(null),children:"Esc"})]}),f.map((y,V)=>e.jsxs("button",{type:"button",className:`slash-item${V===Y?" active":""}`,onMouseEnter:()=>X(V),onClick:()=>ie(y),children:[e.jsxs("span",{className:"slash-name",children:["/",y.name]}),e.jsx("span",{className:`slash-source ${y.source}`,children:Z[y.source]}),e.jsxs("span",{className:"slash-desc",children:[z(y),y.argumentHint&&e.jsx("span",{className:"slash-hint",children:H(y)})]})]},y.name))]}),O&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:q?{width:q}:void 0,onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",C("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:C("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:C("slashLoading")}):c.map(y=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",y.name]}),e.jsx("span",{className:`slash-source ${y.source}`,children:Z[y.source]}),e.jsxs("span",{className:"slash-help-desc",children:[z(y),y.argumentHint&&e.jsx("span",{className:"slash-hint",children:H(y)})]})]},y.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:$,type:"file",multiple:!0,hidden:!0,onChange:y=>{u(y.target.files),y.target.value=""}}),e.jsx("textarea",{ref:w,value:R,rows:1,placeholder:C(U?i?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!U,onChange:y=>{_(y.target.value),S(y.target.value)},onKeyDown:oe,onPaste:W}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:C("uploadFile"),disabled:!U,onClick:()=>{var y;return(y=$.current)==null?void 0:y.click()},children:e.jsx(Xn,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:C("tpl.openPicker"),onClick:j,children:e.jsx(oi,{})}),e.jsx(ir,{state:l,models:n,modelsLoading:o,send:d,onManageModels:M,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:ve()})]})]})]})}),rr=a.memo(function({goal:s,models:i,modelsLoading:r,activeConversationId:c,engine:l,send:n}){var O,G,q,k,w,$;const o=me(),d=l==="dsh",p=!s.conversationId||s.conversationId===c,m=s.goal!==null&&p,[v,h]=a.useState(""),[x,N]=a.useState(s.reviewModel??""),[M,C]=a.useState(s.maxRounds),[I,j]=a.useState(s.locked),[z,H]=a.useState(!1),[R,_]=a.useState(!1),[P,T]=a.useState(!0);a.useEffect(()=>{N(s.reviewModel??""),C(s.maxRounds||0),j(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),a.useEffect(()=>{z&&i.length===0&&!R&&!r&&(_(!0),n({type:"list_models"}))},[z,i.length,R,r,n]),a.useEffect(()=>{i.length>0&&_(!1)},[i.length]);const f=()=>{var J;return x?((J=i.find(Z=>Z.id===x))==null?void 0:J.name)??x:o("goalBarUseMainModel")},F=()=>{const J=v.trim();J&&(n({type:"set_goal",goal:J,...x?{reviewModel:x}:{},maxRounds:M,locked:I}),h(""),T(!1))},Y=()=>{const J=v.trim();J&&(n({type:"start_goal_wizard",text:J,...x?{wizardModel:x}:{},maxRounds:M,locked:I}),h(""),T(!1))},X=(((O=s.wizard)==null?void 0:O.active)??!1)&&p;return X?e.jsx("div",{className:`goalbar goalbar-active ${X?"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:((G=s.wizard)==null?void 0:G.draft)??"",children:[o("goalWizardRunning"),": ",(q=s.wizard)==null?void 0:q.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarRound",{n:(((k=s.wizard)==null?void 0:k.step)??0)+1})," ","/ ",((w=s.wizard)==null?void 0:w.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:(($=s.wizard)==null?void 0:$.status)||o("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),onClick:()=>{n({type:"clear_goal"}),T(!0)},children:e.jsx(Ne,{})})]})}):m?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarReviewing")," ",o("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?o("goalBarPassed"):s.verdict==="fail"?o("goalBarFailed"):`${o("goalBarRound",{n:s.round||1})} · ${s.locked?o("goalBarLocked"):o("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:s.status}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),disabled:s.reviewing,onClick:()=>{n({type:"clear_goal"}),T(!0)},children:e.jsx(Ne,{})})]})}):P?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:o("goalBarPlaceholder"),onClick:()=>T(!1),children:[e.jsx(us,{})," ",e.jsx("span",{children:o("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(us,{})}),e.jsx("input",{className:"goalbar-input",value:v,placeholder:o("goalBarPlaceholder"),onChange:J=>h(J.target.value),onKeyDown:J=>{J.key==="Enter"&&F()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!v.trim(),onClick:F,children:o("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!v.trim(),title:o("goalWizardTip"),onClick:Y,children:["🔍 ",o("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o(I?"goalBarLocked":"goalBarUnlocked"),onClick:()=>j(J=>(n({type:"set_goal_prefs",locked:!J}),!J)),children:I?e.jsx(ii,{}):e.jsx(Gn,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o("goalBarClear"),onClick:()=>T(!0),children:e.jsx(ft,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[d?e.jsx("p",{className:"goalbar-dsh-note",children:o("dshNoReviewModel")}):e.jsxs($e,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[o("goalBarReviewModel"),": ",e.jsx("b",{children:f()})]}),open:z,onOpenChange:H,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("goalBarReviewModel")}),(R||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!R&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),e.jsx(Ce,{active:x==="",onClick:()=>{N(""),H(!1),n({type:"set_goal_prefs",reviewModel:""})},children:o("goalBarUseMainModel")}),i.map(J=>e.jsx(Ce,{active:x===J.id,onClick:()=>{N(J.id),H(!1),n({type:"set_goal_prefs",reviewModel:J.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:J.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:J.provider})})]})},J.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>n({type:"list_models"}),children:o("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:o("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:o("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:M,placeholder:o("goalBarUnlimitedShort"),onChange:J=>{const Z=parseInt(J.target.value,10);if(Number.isNaN(Z)||Z<0){C(0);return}C(Z)},onBlur:()=>n({type:"set_goal_prefs",maxRounds:M}),onKeyDown:J=>{J.key==="Enter"&&(n({type:"set_goal_prefs",maxRounds:M}),J.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:o(I?"goalBarLocked":"goalBarUnlocked")})]})]})});function lr({chat:t,send:s}){const i=me(),r=t.state,[c,l]=a.useState(!1),[n,o]=a.useState(""),[d,p]=a.useState(0),m=a.useRef(null),v=t.pathCompletions;if(a.useEffect(()=>{if(!c)return;const T=setTimeout(()=>{s({type:"complete_path",path:n})},150);return()=>clearTimeout(T)},[n,c,s]),a.useEffect(()=>p(0),[v]),a.useEffect(()=>{const T=document.querySelector(`.status-completions .pc-item[data-idx="${d}"]`);T==null||T.scrollIntoView({block:"nearest"})},[d]),!r)return null;const h=r.stats,x=t.ready?"ok":"busy",N=t.ready?i("connected"):i("connecting"),M=h.contextUsage,C=M.tokens!==null&&M.percent!==null?`${Is(M.tokens)} / ${Is(M.contextWindow)}`:"—",I=M.percent??null,j=I===null?"":I>=80?"warn":I>=50?"mid":"ok",z=r.queue.steering.length+r.queue.followUp.length,H=()=>{o(r.cwd),l(!0)},R=(T,f)=>{var Y;const F=T.includes("\\")?"\\":"/";o(f?`${T}${F}`:T),p(0),(Y=m.current)==null||Y.focus()},_=T=>{const f=T.trim();f&&f!==r.cwd&&s({type:"set_cwd",path:f}),l(!1)},P=T=>{if(T.key==="ArrowDown")T.preventDefault(),p(f=>Math.min(f+1,v.length-1));else if(T.key==="ArrowUp")T.preventDefault(),p(f=>Math.max(f-1,0));else if(T.key==="Tab"&&v.length>0){T.preventDefault();const f=v[Math.min(d,v.length-1)];R(f.path,f.type==="dir")}else if(T.key==="Enter"&&!T.nativeEvent.isComposing){const f=n.trim();if(f.endsWith("/")||f.endsWith("\\"))_(f);else if(v.some(F=>F.path===f))_(f);else if(v.length>0&&v[d]){T.preventDefault();const F=v[d];R(F.path,F.type==="dir")}else _(f)}else T.key==="Escape"&&(v.length>0?(T.stopPropagation(),s({type:"complete_path",path:""})):l(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${x}`,title:N}),e.jsx("span",{className:"status-item",children:N}),e.jsx("span",{className:"status-sep",children:"·"}),t.engine&&t.engine!=="pi"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`status-item engine-badge engine-${t.engine}`,title:`${i("engineBadge")}: ${t.engine}`,children:t.engine==="dsh"?"DSH":t.engine}),e.jsx("span",{className:"status-sep",children:"·"})]}),e.jsxs("span",{className:"status-item status-ctx",title:i("contextUsage"),children:[i("context"),e.jsx("span",{className:`ctx-bar ${j}`,children:I!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(I,100)}%`}})}),C]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("cumulativeCost"),children:["$",or(h.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("sessionMessages"),children:[i("messages")," ",h.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:i("pluginStatus"),children:t.statuses.map(T=>T.text).join(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),i("working"),z>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",z," ",i("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:m,className:"status-cwd-input",value:n,autoFocus:!0,placeholder:i("enterPath"),onChange:T=>o(T.target.value),onKeyDown:P,onBlur:()=>l(!1)}),v.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:T=>T.preventDefault(),children:v.map((T,f)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":f,className:`pc-item ${f===d?"sel":""}`,onMouseEnter:()=>p(f),onClick:()=>R(T.path,T.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:T.type==="dir"?e.jsx(Ye,{}):e.jsx(Vs,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:T.name}),e.jsx("span",{className:"pc-path",children:T.path})]})]})},T.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:i("cwdTip",{path:r.cwd}),onClick:H,children:["📁 ",r.cwd]})]})}function Is(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function or(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function cr({dialog:t,send:s}){const i=me(),[r,c]=a.useState(""),[l,n]=a.useState(0),o=m=>{s({type:"dialog_response",id:t.id,value:m})};a.useEffect(()=>{c(""),n(0);const m=v=>{v.key==="Escape"&&o(null)};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t.id]);const d=Array.isArray(t.args[0])?t.args[0]:[],p=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("pluginRequest")}),t.title&&t.title!==i("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[d.map((m,v)=>e.jsx("button",{type:"button",className:`dialog-option ${v===l?"sel":""}`,onMouseEnter:()=>n(v),onClick:()=>o(m),children:m},v)),d.length===0&&e.jsx("div",{className:"dialog-hint",children:i("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:p}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:i("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:r,placeholder:p||i("inputPlaceholder"),autoFocus:!0,onChange:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.nativeEvent.isComposing&&o(r)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(r),children:i("ok")})]})]})]})}function dr({question:t,send:s}){const i=me(),[r,c]=a.useState({}),[l,n]=a.useState({}),[o,d]=a.useState(()=>t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1);a.useEffect(()=>{c({}),n({}),d(t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1)},[t.id,t.deadline]),a.useEffect(()=>{if(!t.deadline)return;const h=setInterval(()=>{d(x=>{const N=Math.max(0,Math.ceil((t.deadline-Date.now())/1e3));return N<=0&&x>0&&s({type:"question_answer",id:t.id,answers:[],cancelled:!0}),N})},1e3);return()=>clearInterval(h)},[t.id,t.deadline]);const p=h=>{if(h){s({type:"question_answer",id:t.id,answers:[],cancelled:!0});return}const x=t.questions.map(N=>{const M=r[N.id]??[],C=(l[N.id]??"").trim();return{id:N.id,selected:M,...C?{custom:C}:{}}});s({type:"question_answer",id:t.id,answers:x})};a.useEffect(()=>{const h=x=>{x.key==="Escape"&&p(!0)};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t.id]);const m=(h,x,N)=>{c(M=>{const C=M[h]??[];return N?{...M,[h]:C.includes(x)?C.filter(I=>I!==x):[...C,x]}:{...M,[h]:[x]}})},v=t.questions.every(h=>{var x;return(((x=r[h.id])==null?void 0:x.length)??0)>0||(l[h.id]??"").trim()!==""});return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":"select",children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("modelQuestion")}),o>=0&&e.jsx("span",{className:"question-timer",children:o>0?i("questionTimeout",{s:o}):i("questionTimeoutExpired")}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>p(!0),children:"✕"})]}),t.questions.map((h,x)=>{var N;return e.jsxs("div",{className:"set-section",children:[e.jsx("div",{className:"set-section-title",children:h.header??`${i("modelQuestion")} ${x+1}`}),e.jsx("p",{className:"set-row-desc",children:h.question}),h.detail&&e.jsx("p",{className:"set-hint",children:h.detail}),(((N=h.options)==null?void 0:N.length)??0)>0&&e.jsx("div",{className:"set-list",children:h.options.map(M=>{const C=(r[h.id]??[]).includes(M.label);return e.jsxs("button",{type:"button",className:`set-row question-option${C?" active":""}`,onClick:()=>m(h.id,M.label,!!h.multiSelect),children:[e.jsxs("span",{className:"set-row-name",children:[h.multiSelect?C?"☑ ":"☐ ":C?"● ":"○ ",M.label]}),M.description&&e.jsx("span",{className:"set-row-desc",children:M.description})]},M.label)})}),e.jsx("input",{className:"set-prompt-input question-custom",placeholder:i("modelQuestionCustom"),value:l[h.id]??"",onChange:M=>n(C=>({...C,[h.id]:M.target.value}))})]},h.id)}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"dialog-submit",disabled:!v,onClick:()=>p(!1),children:i("modelQuestionSubmit")}),e.jsx("button",{type:"button",className:"dialog-dismiss-inline",onClick:()=>p(!0),children:i("cancel")})]})]})}function ur(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",i=t.y!==" "&&t.y!=="?";return s&&i?"both":s?"staged":"unstaged"}function pr({chat:t,send:s,terminal:i,active:r,onSwitchToTerminal:c}){var We,Re;const l=me(),[n,o]=a.useState(null),[d,p]=a.useState([]),[m,v]=a.useState(""),[h,x]=a.useState(new Map),[N,M]=a.useState("changes"),[C,I]=a.useState([]),[j,z]=a.useState(null),[H,R]=a.useState(""),[_,P]=a.useState(!1),[T,f]=a.useState(null),[F,Y]=a.useState(null),[X,O]=a.useState(!1),[G,q]=a.useState(!1),[k,w]=a.useState(!1),[$,J]=a.useState(null),[Z,S]=a.useState(!1),[ie,se]=a.useState(""),u=a.useRef(0),W=a.useRef(-1),D=a.useRef(-1),U=a.useRef(-1),K=a.useRef(-1),te=a.useRef(void 0),oe=a.useRef(null),ve=a.useRef([]),y=a.useCallback(E=>{if(E.reqId===W.current){if(W.current=-1,q(!1),J(null),!E.ok){J(E.error??"查询失败");return}if(E.notRepo){S(!0),o(null),p([]),x(new Map),I([]),z(null),R(""),Y(null);return}S(!1);const pe={branch:E.branch??"",detached:!!E.detached,upstream:E.upstream??null,ahead:E.ahead??0,behind:E.behind??0,upstreamGone:!!E.upstreamGone,files:(E.files??[]).map(b=>({...b}))},ce=(E.branches??[]).map(b=>({...b})),ke=new Map;for(const[b,L]of Object.entries(E.stats??{}))ke.set(b,{add:L[0],del:L[1]});o(pe),p(ce),x(ke),v(b=>{var L;return pe.detached?b||"":pe.branch&&ce.some(ne=>ne.name===pe.branch)?pe.branch:b&&ce.some(ne=>ne.name===b)?b:((L=ce[0])==null?void 0:L.name)??""}),Y(b=>b&&!pe.files.some(L=>L.path===b.file.path)?null:b)}else if(E.reqId===D.current){if(D.current=-1,O(!1),!E.ok){J(E.error??"查询失败");return}const pe=oe.current;if(!pe)return;Y({file:pe,staged:E.stagedText??"",worktree:E.worktreeText??"",untracked:!1})}else if(E.reqId===K.current){if(K.current=-1,w(!1),!E.ok){J(E.error??"查询失败");return}I((E.history??[]).map(pe=>({...pe})))}else if(E.reqId===U.current){if(U.current=-1,P(!1),!E.ok){J(E.error??"查询失败");return}R(E.text??"")}},[]);a.useEffect(()=>{const E=t.scmData;E&&E.type==="scm_data"&&y(E)},[t.scmData,y]);const V=a.useCallback((E,pe)=>{if(!t.ready||t.status!=="open")return!1;const ce=++u.current;return s({...E,reqId:ce})?(pe.current=ce,!0):(u.current-=1,!1)},[t.ready,t.status,s]),de=a.useCallback((E=!1,pe=!1)=>{var ce;!t.ready||t.status!=="open"||(ce=t.state)!=null&&ce.cwd&&(te.current!==void 0&&te.current!==t.state.cwd&&(o(null),p([]),x(new Map),I([]),w(!1),K.current=-1,z(null),R(""),Y(null),f(null)),te.current=t.state.cwd,J(null),V({type:"scm_status"},W)&&(pe||q(!0)))},[t.ready,(We=t.state)==null?void 0:We.cwd,t.status,V]),g=a.useCallback(E=>{if(f(E),z(null),oe.current=E,E.x==="?"&&E.y==="?"){Y({file:E,staged:"",worktree:"",untracked:!0});return}O(!0),J(null),V({type:"scm_filediff",path:E.path},D)||O(!1)},[V]),A=a.useCallback(E=>{z(E),f(null),Y(null),R(""),P(!0),J(null),V({type:"scm_commit",hash:E.hash},U)||P(!1)},[V]),ae=a.useCallback((E,pe)=>{var L,ne;if(!t.ready)return;const ce={name:E,command:pe,cwd:"${pwd}"};let ke;const b=t.terminals.find(re=>re.title===E);b?(i.restart(b.id),s({type:"run_command",terminalId:b.id,conversationId:b.conversationId,command:ce,cols:80,rows:24}),ke=b.id):(ke=Fe(),i.create({id:ke,conversationId:t.activeConversationId||((L=t.state)==null?void 0:L.conversationId)||"",title:E,cwd:((ne=t.state)==null?void 0:ne.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ce})),i.select(ke),c()},[t.ready,(Re=t.state)==null?void 0:Re.cwd,t.terminals,c,s,i]),he=a.useCallback(()=>{const E=ie.trim();if(!E||Z)return;const pe=E.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");ae("git commit",`git add -A && git commit -m "${pe}"`),se("")},[ie,Z,ae]),xe=E=>`'${E.replace(/'/g,"'\\''")}`,ue=a.useCallback(E=>{Z||ae("git add",`git add -- ${xe(E.path)}`)},[Z,ae]),Pe=a.useCallback(E=>{Z||ae("git reset",`git reset HEAD -- ${xe(E.path)}`)},[Z,ae]),Te=a.useCallback(()=>{if(!m||Z)return;const E=d.find(pe=>pe.name===m);if(E!=null&&E.remote&&typeof E.remote=="string"){const pe=m.slice(E.remote.length+1);ae("git checkout",`git checkout -b ${pe} ${m} || git checkout ${m}`)}else ae("git checkout",`git checkout ${m}`)},[m,d,Z,ae]),_e=a.useCallback(()=>ae("git push","git push"),[ae]),Xe=a.useCallback(()=>ae("git pull","git pull"),[ae]),Se=a.useCallback(()=>{V({type:"scm_history"},K)||(K.current=-1)},[V]);a.useEffect(()=>{r&&de()},[r,de]),a.useEffect(()=>{N==="history"&&n&&Se()},[N,n,Se]),a.useEffect(()=>{t.scmDirty>0&&r&&de(!1,!0)},[t.scmDirty]),a.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const E=setInterval(()=>{document.visibilityState!=="hidden"&&de(!1,!0)},3e4);return()=>clearInterval(E)},[r,t.ready,t.status,de]),a.useEffect(()=>{const E=ve.current;if(ve.current=t.terminals,!r)return;t.terminals.some(ce=>{var b;return ce.running!==!1?!1:((b=E.find(L=>L.id===ce.id))==null?void 0:b.running)===!0&&/^git /.test(ce.title)})&&t.ready&&t.status==="open"&&(de(!1,!0),N==="history"&&n&&Se())},[t.terminals,r,t.ready,t.status,de,N,n,Se]);const Ke={staged:l("scmStaged"),unstaged:l("scmUnstaged"),untracked:l("scmUntracked"),both:l("scmStagedUnstaged")},Oe=E=>{const pe=E.split(`
|
|
320
|
+
`);return e.jsx("pre",{className:"scm-diff-pre",children:pe.map((ce,ke)=>{let b="";return ce.startsWith("diff --git")||ce.startsWith("index ")||ce.startsWith("new file")||ce.startsWith("deleted file")||ce.startsWith("old mode")||ce.startsWith("new mode")||ce.startsWith("similarity index")||ce.startsWith("rename ")||ce.startsWith("copy ")||ce.startsWith("Binary files")||ce.startsWith("---")||ce.startsWith("+++")?b="hdr":ce.startsWith("@@")?b="hunk":ce.startsWith("+")?b="add":ce.startsWith("-")&&(b="del"),e.jsx("div",{className:`scm-diff-line ${b}`,children:ce||" "},ke)})})};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(ct,{}),l("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":N==="changes",className:N==="changes"?"active":"",onClick:()=>{M("changes"),J(null)},children:l("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":N==="history",className:N==="history"?"active":"",onClick:()=>{M("history"),J(null)},children:l("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:l("scmRefreshTip"),disabled:G,onClick:()=>de(!0),children:e.jsx(nt,{className:G?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:l("scmCurrentBranch"),children:[e.jsx(ct,{}),n?n.detached?l("scmDetached"):n.branch:"…",(n==null?void 0:n.upstream)&&e.jsx("span",{className:"scm-upstream",children:n.upstreamGone?l("scmUpstreamGone"):n.ahead>0||n.behind>0?l("scmAheadBehind",{ahead:n.ahead,behind:n.behind}):n.upstream})]}),e.jsxs("select",{className:"scm-select",value:m,disabled:Z||d.length===0,title:l("scmSwitchBranch"),onChange:E=>v(E.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:l("scmSelectBranch")}),d.filter(E=>!E.remote).map(E=>e.jsx("option",{value:E.name,children:E.current?`* ${E.name}`:E.name},E.name)),d.some(E=>E.remote)&&e.jsx("optgroup",{label:l("scmRemoteBranches"),children:d.filter(E=>E.remote).map(E=>e.jsx("option",{value:E.name,children:E.name},E.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!m||m===(n==null?void 0:n.branch)||Z,title:l("scmSwitchBranchTip",{branch:m}),onClick:Te,children:[e.jsx(ct,{}),l("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||Z,title:l("scmPushTip"),onClick:_e,children:[e.jsx(Js,{}),l("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||Z,title:l("scmPullTip"),onClick:Xe,children:[e.jsx(Xs,{}),l("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:ie,placeholder:l("scmCommitPlaceholder"),disabled:Z,onChange:E=>se(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.nativeEvent.isComposing&&he()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!ie.trim()||Z,title:l("scmCommitTip"),onClick:he,children:[e.jsx(vt,{}),l("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[N==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:l("scmHistory")}),C.length>0&&e.jsx("span",{className:"scm-files-count",children:C.length})]}),e.jsx("div",{className:"scm-history-list",children:Z?e.jsx("div",{className:"scm-empty",children:l("scmNotGitRepo")}):!n||k?e.jsx("div",{className:"scm-empty",children:t.status==="open"?l("scmLoading"):l("scmConnecting")}):C.length===0?e.jsx("div",{className:"scm-empty",children:l("scmNoHistory")}):C.map(E=>e.jsxs("button",{type:"button",className:`scm-commit ${(j==null?void 0:j.hash)===E.hash?"active":""}`,onClick:()=>A(E),title:E.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:E.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:E.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[E.shortHash," · ",E.author," · ",E.date]}),E.decorations&&e.jsx("span",{className:"scm-commit-refs",children:E.decorations})]})]},E.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:l("scmChanges")}),n&&n.files.length>0&&e.jsx("span",{className:"scm-files-count",children:n.files.length})]}),e.jsx("div",{className:"scm-files-list",children:Z?e.jsx("div",{className:"scm-empty",children:l("scmNotGitRepo")}):n?n.files.length===0?e.jsx("div",{className:"scm-empty",children:l("scmNoChanges")}):n.files.map(E=>{const pe=ur(E),ce=h.get(E.path);return e.jsxs("div",{className:`scm-file ${(T==null?void 0:T.path)===E.path?"active":""}`,title:Ke[pe],onClick:()=>g(E),children:[e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"x"}`,children:E.x!==" "?E.x:" "}),e.jsx("span",{className:`scm-file-xy ${pe==="untracked"?"q":"y"}`,children:E.y!==" "?E.y:" "}),e.jsx("span",{className:"scm-file-path",children:E.path}),ce&&(ce.add>0||ce.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[ce.add>0&&e.jsxs("span",{className:"add",children:["+",ce.add]}),ce.del>0&&e.jsxs("span",{className:"del",children:["-",ce.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(E.y!==" "||pe==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:l("scmStageTip",{path:E.path}),onClick:ke=>{ke.stopPropagation(),ue(E)},children:"+"}),pe==="staged"||pe==="both"?e.jsx("button",{type:"button",className:"scm-act",title:l("scmUnstageTip",{path:E.path}),onClick:ke=>{ke.stopPropagation(),Pe(E)},children:"−"}):null]})]},E.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?l("scmLoading"):l("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:N==="history"?j?`${j.shortHash} ${j.subject}`:l("scmCommitDetail"):T?T.path:l("scmDiff")}),(N==="history"?_:X)&&e.jsx("span",{className:"scm-diff-loading",children:l("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:N==="history"?e.jsxs(e.Fragment,{children:[$&&e.jsx("div",{className:"scm-error",children:$}),!j&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmSelectCommitHint")}),j&&_&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmLoading")}),j&&!_&&!$&&H?Oe(H):null]}):e.jsxs(e.Fragment,{children:[$&&e.jsx("div",{className:"scm-error",children:$}),!T&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmSelectFileHint")}),T&&!F&&!$&&e.jsx("div",{className:"scm-empty",children:l("scmLoading")}),T&&F&&F.untracked&&e.jsx("div",{className:"scm-empty",children:l("scmUntrackedNote")}),T&&F&&!F.untracked&&e.jsxs(e.Fragment,{children:[F.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:l("scmStaged")}),Oe(F.staged)]}),F.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:l("scmUnstaged")}),Oe(F.worktree)]}),!F.staged&&!F.worktree&&e.jsx("div",{className:"scm-empty",children:l("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ge,{}),e.jsx("span",{children:l("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:l("scmViewTerminal")})]})]})}function mr({entry:t,send:s}){const i=a.useRef(null);return a.useEffect(()=>{const r=i.current;if(!r)return;let c;try{c=t.module.mount(r,Fi(t.info.id,l=>s(l)))}catch(l){console.error(`[plugin:${t.info.id}] mount failed:`,l),r.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(l){console.error(`[plugin:${t.info.id}] cleanup failed:`,l)}r.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:i})}function hr({send:t,piConfigured:s,piAgentInstalled:i,providers:r,installResult:c,onClose:l}){const n=me(),[o,d]=a.useState(!1),[p,m]=a.useState(""),[v,h]=a.useState(""),[x,N]=a.useState(!1);a.useEffect(()=>{t({type:"list_providers"})},[t]),a.useEffect(()=>{s&&l()},[s,l]),a.useEffect(()=>{c&&d(!1)},[c]),a.useEffect(()=>{var H;!p&&r.length>0&&m(((H=r.find(R=>!R.configured))==null?void 0:H.id)??r[0].id)},[r,p]);const M=()=>{o||(d(!0),t({type:"install_pi_agent"}))},C=()=>{!v.trim()||x||(N(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:v.trim()}),setTimeout(()=>N(!1),3e3))},I=()=>{t({type:"get_state"}),t({type:"list_providers"})},j=r.find(H=>H.id===p),z=c!==null&&!c.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":n("close"),onClick:l,children:e.jsx(Ne,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(it,{className:"modal-head-icon"}),e.jsx("h2",{children:n("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:n("setupDesc")}),z?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:n("installFailed")}),e.jsx("pre",{className:"setup-detail",children:c.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:M,children:n("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:l,children:n("skip")})]})]}):i||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?n("installDone"):n("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("provider")}),e.jsxs("select",{value:p,onChange:H=>m(H.target.value),children:[r.length===0&&e.jsx("option",{value:"",children:n("loading")}),r.map(H=>e.jsxs("option",{value:H.id,children:[H.name,"(",H.id,")",H.configured?` · ${n("configured")}`:""]},H.id))]}),(j==null?void 0:j.configured)&&e.jsx("div",{className:"field-hint",children:n("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("apiKey")}),e.jsx("input",{type:"password",value:v,onChange:H=>h(H.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!v.trim()||x||!p,onClick:C,children:n(x?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:I,children:[e.jsx(nt,{})," ",n("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:M,children:n(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:l,children:n("skip")})]})]})})}const gr=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],zt=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),fr=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[zt()]});function Ls(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:[zt()]).map(s=>{var i;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(i=s.input)!=null&&i.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function xr({send:t,providers:s,providerStatus:i,fetchModelsResult:r,refreshProviderResult:c,cloneProviderResult:l,onClose:n}){const o=me(),[d,p]=a.useState(null),[m,v]=a.useState({}),[h,x]=a.useState(null),[N,M]=a.useState({}),[C,I]=a.useState(!1),[j,z]=a.useState(0),[H,R]=a.useState(null),_=a.useRef(0),[P,T]=a.useState({});a.useRef(0);const f=a.useRef(0),[F,Y]=a.useState(null),X=a.useRef(0),O=a.useRef(0);a.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const G=()=>{if(!d)return;const S=d.baseUrl.trim();if(!S){R({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(C)return;I(!0),R(null);const ie=j+1;z(ie),t({type:"fetch_models",reqId:ie,baseUrl:S,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader,api:d.api})};a.useEffect(()=>{var S;if(!(!r||r.reqId===_.current))if(_.current=r.reqId,I(!1),r.ok&&((S=r.models)!=null&&S.length)){const ie=r.models;p(se=>{if(!se)return se;const u=se.models.map(K=>{var ve;if(!K.id.trim())return K;const te=ie.find(y=>y.id===K.id.trim());if(!te)return K;const oe={...K};return!oe.name&&te.name&&(oe.name=te.name),!oe.contextWindow&&te.contextWindow&&(oe.contextWindow=String(te.contextWindow)),!oe.maxTokens&&te.maxTokens&&(oe.maxTokens=String(te.maxTokens)),oe.input==="text"&&((ve=te.input)!=null&&ve.includes("image"))&&(oe.input="text-image"),!oe.reasoning&&te.reasoning&&(oe.reasoning=!0),oe}),W=new Set(u.map(K=>K.id.trim()).filter(Boolean)),D=ie.filter(K=>!W.has(K.id)).map(K=>{var te;return{id:K.id,name:K.name??"",reasoning:K.reasoning??!1,input:(te=K.input)!=null&&te.includes("image")?"text-image":"text",contextWindow:K.contextWindow?String(K.contextWindow):"",maxTokens:K.maxTokens?String(K.maxTokens):""}}),U=[...u,...D];return U.some(K=>K.id.trim())?{...se,models:U.filter(K=>K.id.trim())}:se}),R({ok:!0,text:o("fetchModelsOk",{n:ie.length})})}else R({ok:!1,text:r.error||o("fetchModelsEmpty")})},[r]);const q=S=>{const ie=(m[S.id]??"").trim();!ie||h||(x(S.id),t({type:"set_provider_api_key",provider:S.id,apiKey:ie}),setTimeout(()=>{x(null),v(se=>({...se,[S.id]:""})),M(se=>({...se,[S.id]:!1})),t({type:"list_providers"})},1500))},k=()=>{if(!d)return;const S=d.providerId.trim(),ie=d.models.filter(u=>u.id.trim()).map(u=>({id:u.id.trim(),name:u.name.trim()||void 0,reasoning:u.reasoning||void 0,input:u.input==="text-image"?["text","image"]:void 0,contextWindow:u.contextWindow?Number(u.contextWindow):void 0,maxTokens:u.maxTokens?Number(u.maxTokens):void 0})),se={providerId:S,name:d.name.trim()||void 0,api:d.api.trim()||void 0,baseUrl:d.baseUrl.trim()||void 0,apiKey:d.apiKey.trim()||void 0,authHeader:d.authHeader||void 0,models:ie};t({type:"save_model_config",providerId:S,config:se}),n()};a.useEffect(()=>{!c||c.reqId===f.current||(f.current=c.reqId,T({}))},[c]);const w=S=>{if(F)return;Y(S.id);const ie=++X.current+Date.now();t({type:"clone_provider",provider:S.id,reqId:ie})};a.useEffect(()=>{!l||l.reqId===O.current||(O.current=l.reqId,Y(null),l.ok&&l.config&&p(Ls({...l.config,apiKey:""})))},[l]);const $=S=>{window.confirm(o("clearKeyConfirm",{id:S}))&&t({type:"clear_provider_api_key",provider:S})},J=S=>{window.confirm(o("deleteProviderConfirm",{id:S.providerId,n:S.models.length}))&&t({type:"delete_model_config",providerId:S.providerId})},Z=(S,ie)=>{d&&p({...d,models:d.models.map((se,u)=>u===S?{...se,...ie}:se)})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal model-modal",onClick:S=>S.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:n,children:e.jsx(Ne,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:o(d?"editProvider":"manageModelsTitle")})}),d?e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:d.providerId,disabled:s.some(S=>S.providerId===d.providerId),onChange:S=>p({...d,providerId:S.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:d.name,onChange:S=>p({...d,name:S.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:d.api,onChange:S=>p({...d,api:S.target.value}),children:gr.map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:d.baseUrl,onChange:S=>p({...d,baseUrl:S.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:d.apiKey,onChange:S=>p({...d,apiKey:S.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:d.authHeader,onChange:S=>p({...d,authHeader:S.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:[H&&e.jsx("span",{className:`fetch-msg ${H.ok?"ok":"err"}`,title:H.text,children:H.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:C||!d.baseUrl.trim(),title:o("fetchModelsHint"),onClick:G,children:[e.jsx(Ot,{})," ",o(C?"fetchingModels":"fetchModels")]})]})]}),d.models.map((S,ie)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:S.id,onChange:se=>Z(ie,{id:se.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:S.name,onChange:se=>Z(ie,{name:se.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:S.input,onChange:se=>Z(ie,{input:se.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:S.reasoning,onChange:se=>Z(ie,{reasoning:se.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:S.contextWindow,onChange:se=>Z(ie,{contextWindow:se.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:S.maxTokens,onChange:se=>Z(ie,{maxTokens:se.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>p({...d,models:d.models.filter((se,u)=>u!==ie)}),children:e.jsx(De,{})})]},ie)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...d,models:[...d.models,zt()]}),children:[e.jsx(He,{})," ",o("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!d.providerId.trim()||!d.models.some(S=>S.id.trim()),onClick:k,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:[i.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.map(S=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:S.name}),e.jsxs("span",{className:"provider-sub",children:[S.id,S.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),S.source&&!S.configured&&e.jsx("span",{className:"auth-badge dim",children:S.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[S.configured&&!N[S.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:()=>M(ie=>({...ie,[S.id]:!0})),children:[e.jsx(Dt,{})," ",o("replaceKey")]}),S.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>$(S.id),children:[e.jsx(De,{})," ",o("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:o("pasteKey"),value:m[S.id]??"",onChange:ie=>v(se=>({...se,[S.id]:ie.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(m[S.id]??"").trim()||h===S.id,onClick:()=>q(S),children:[e.jsx(ai,{})," ",h===S.id?o("savingKey"):o("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:F!==null,title:o("cloneProviderTitle"),onClick:()=>w(S),children:[e.jsx(Wt,{})," ",F===S.id?o("cloning"):o("cloneProvider")]})]})]},S.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(S=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:S.providerId}),e.jsxs("span",{className:"provider-sub",children:[S.api??"—",S.baseUrl?` · ${S.baseUrl}`:"",S.models.length>0&&` · ${o("modelsCount",{n:S.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>p(Ls(S)),children:e.jsx(Dt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>J(S),children:e.jsx(De,{})})]})]},S.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(fr()),children:[e.jsx(He,{})," ",o("addProvider")]})})]})]})})}function vr({plugin:t,send:s}){const i=me(),r=t.settingsSchema??[],[c,l]=a.useState(()=>({...t.settingsValues??{}})),[n,o]=a.useState(!1);if(r.length===0)return null;const d=(h,x)=>l(N=>({...N,[h]:x})),p=r.some(h=>{var x;return c[h.key]!==((x=t.settingsValues)==null?void 0:x[h.key])}),m=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},v=()=>l({...t.settingsValues??{}});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:r.map(h=>e.jsxs("label",{className:"plugin-settings-field",title:h.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:h.label}),h.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[h.key],onChange:x=>d(h.key,x.target.checked)}):h.type==="select"?e.jsx("select",{value:String(c[h.key]??""),onChange:x=>d(h.key,x.target.value),children:(h.options??[]).map(x=>e.jsx("option",{value:x,children:x},x))}):e.jsx("input",{type:h.type==="password"?"password":h.type==="number"?"number":"text",value:String(c[h.key]??""),min:h.min,max:h.max,onChange:x=>d(h.key,h.type==="number"?Number(x.target.value):x.target.value)})]},h.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!p||n,onClick:m,children:i(n?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:v,children:i("pluginSettingsReset")})]})]})}function yr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function st({text:t}){const s=a.useRef(null),[i,r]=a.useState(!1),c=()=>{var n;const l=(n=s.current)==null?void 0:n.getBoundingClientRect();l&&r(window.innerWidth-l.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${i?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Le({title:t,subtitle:s,tip:i,enabled:r,onToggle:c,action:l}){const n=me();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[t,i&&e.jsx(st,{text:i})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),l,e.jsx("button",{type:"button",className:`set-switch ${r?"on":""}`,role:"switch","aria-checked":r,title:n(r?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function kr({chat:t,send:s,terminal:i,onSwitchToTerminal:r,onClose:c}){var y,V,de;const l=me(),n=t.settings,o=t.engine==="dsh",[d,p]=a.useState("prompt"),m=a.useRef(null);a.useEffect(()=>{var g;(g=m.current)==null||g.scrollTo({top:0})},[d]),a.useEffect(()=>{d==="plugins"&&t.engine==="dsh"&&s({type:"dsh_patches_list"})},[d,t.engine,s]);const[v,h]=a.useState(""),[x,N]=a.useState("append"),M=a.useRef(!1),[C,I]=a.useState(""),[j,z]=a.useState("append"),H=a.useRef(!1),[R,_]=a.useState(""),P=a.useRef(!1),[T,f]=a.useState(""),[F,Y]=a.useState(!1),[X,O]=a.useState(null),[G,q]=a.useState(null);a.useEffect(()=>{n&&(N(n.promptMode),!M.current&&(h(x==="append"||n.customSystemPrompt?n.customSystemPrompt:n.defaultSystemPrompt||""),z(n.visionBridgePromptMode),!H.current&&(I(j==="append"||n.visionBridgePrompt?n.visionBridgePrompt:n.visionBridgeDefaultPrompt||""),P.current||_(n.reviewPrompt))))},[n,x,j]);const[k,w]=a.useState(String((n==null?void 0:n.terminalBashIdleMs)??15e3));if(a.useEffect(()=>{w(String((n==null?void 0:n.terminalBashIdleMs)??15e3))},[n==null?void 0:n.terminalBashIdleMs]),!n)return null;const $=[{id:"prompt",icon:e.jsx(Gs,{}),label:l("settingsSystemPrompt")},{id:"terminal",icon:e.jsx(Ge,{}),label:l("settingsTerminalTools")},{id:"display",icon:e.jsx(Qe,{}),label:l("settingsMessageDisplay")},{id:"skills",icon:e.jsx(it,{}),label:l("settingsSkills"),count:n.skills.length},{id:"extensions",icon:e.jsx(ps,{}),label:l("settingsExtensions"),count:n.extensions.length},{id:"plugins",icon:e.jsx(jt,{}),label:l("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(ot,{}),label:l("settingsReview"),count:n.reviewSkills.length},...o?[]:[{id:"vision",icon:e.jsx(It,{}),label:l("settingsVisionBridge")}],{id:"presets",icon:e.jsx(Yn,{}),label:l("settingsPresets"),count:n.presets.length}],J=new Set(n.disabledSkills),Z=new Set(n.disabledExtensions),S=g=>s({type:"set_settings",...g}),ie=g=>{const A=new Set(J);A.has(g.name)?A.delete(g.name):A.add(g.name),S({disabledSkills:[...A]})},se=new Set(n.disabledPlugins??[]),u=g=>{const A=new Set(se);A.has(g.id)?A.delete(g.id):A.add(g.id),S({disabledPlugins:[...A]})},W=g=>{const A=new Set(Z);A.has(g.id)?A.delete(g.id):A.add(g.id),S({disabledExtensions:[...A]})},D=(g,A)=>{var ue,Pe;const ae={name:g,command:A,cwd:"${pwd}"};let he;const xe=t.terminals.find(Te=>Te.title===g);xe?(i.restart(xe.id),s({type:"run_command",terminalId:xe.id,conversationId:xe.conversationId,command:ae,cols:80,rows:24}),he=xe.id):(he=Fe(),i.create({id:he,conversationId:t.activeConversationId||((ue=t.state)==null?void 0:ue.conversationId)||"",title:g,cwd:((Pe=t.state)==null?void 0:Pe.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ae})),i.select(he),r(),c()},U=g=>{O(null),D(`${l("uninstallTitle")} ${g}`,`pi remove npm:${g}`)},K=g=>{q(null),D(`${l("uninstallTitle")} ${g}`,`pi-web-ui uninstall ${g}`)},te=(g,A)=>{D(`${l("pluginUpdate")} ${g}`,`pi-web-ui install ${A} --name ${g} --force`)},oe=g=>{const A=new Set(n.reviewSkills.filter(ae=>!ae.enabled).map(ae=>ae.name));A.has(g.name)?A.delete(g.name):A.add(g.name),S({reviewDisabledSkills:[...A]})},ve=()=>{const g=x==="replace"&&n.defaultSystemPrompt&&v===n.defaultSystemPrompt?"":v;S({promptMode:x,customSystemPrompt:g})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:g=>g.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":l("close"),onClick:c,children:e.jsx(Ne,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(mt,{className:"modal-head-icon"}),e.jsx("h2",{children:l("settingsTitle")}),e.jsx(st,{text:l("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":l("settingsTitle"),children:$.map(g=>e.jsxs("button",{type:"button",className:`settings-tab${d===g.id?" active":""}`,"aria-current":d===g.id?"true":void 0,title:g.label,onClick:()=>p(g.id),children:[e.jsx("span",{className:"settings-tab-icon",children:g.icon}),e.jsx("span",{className:"settings-tab-label",children:g.label}),g.count!==void 0&&e.jsx("span",{className:"set-count",children:g.count})]},g.id))}),e.jsxs("div",{className:"modal-body",ref:m,children:[d==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ot,{className:"set-section-icon"}),l("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:x,onChange:g=>{const A=g.target.value;N(A),S({promptMode:A})},children:[e.jsx("option",{value:"append",children:l("promptModeAppend")}),e.jsx("option",{value:"replace",children:l("promptModeReplace")})]}),e.jsx(st,{text:l(x==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:l("promptPlaceholder"),value:v,onFocus:()=>M.current=!0,onBlur:()=>{M.current=!1,ve()},onChange:g=>h(g.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":F,onClick:()=>Y(g=>!g),children:[l("settingsViewPrompt")," ",F?"▴":"▾"]}),F&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:l("settingsViewPromptHint")}),e.jsx(nn,{text:n.effectiveSystemPrompt})]}),n.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:n.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:l("settingsViewPromptEmpty")})]})]}),d==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ge,{className:"set-section-icon"}),l("settingsTerminalTools")]}),e.jsx(Le,{title:l("terminalToolsEnabled"),tip:l("settingsTerminalToolsDesc"),enabled:n.terminalToolsEnabled,onToggle:()=>S({terminalToolsEnabled:!n.terminalToolsEnabled})}),!n.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:l("terminalToolsOffHint")}),e.jsx(Le,{title:l("terminalBashTakeover"),tip:l("terminalBashTakeoverDesc"),enabled:n.terminalBash,onToggle:()=>S({terminalBash:!n.terminalBash})}),n.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:l("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:k,onChange:g=>w(g.target.value),onBlur:()=>{const g=Math.max(0,Math.floor(Number(k)||0));w(String(g)),g!==n.terminalBashIdleMs&&S({terminalBashIdleMs:g})}})]})]}),d==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Qe,{className:"set-section-icon"}),l("settingsMessageDisplay")]}),e.jsx(Le,{title:l("thinkingWrap"),tip:l("thinkingWrapDesc"),enabled:n.thinkingWrap??!0,onToggle:()=>S({thinkingWrap:!(n.thinkingWrap??!0)})}),e.jsx(Le,{title:l("toolsWrap"),tip:l("toolsWrapDesc"),enabled:n.toolsWrap??!0,onToggle:()=>S({toolsWrap:!(n.toolsWrap??!0)})})]}),d==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(it,{className:"set-section-icon"}),l("settingsSkills"),e.jsx("span",{className:"set-count",children:n.skills.length})]}),n.skills.length===0?e.jsx("p",{className:"set-empty",children:l(o?"dshSkillsNote":"noSkills")}):e.jsx("div",{className:"set-list",children:n.skills.map(g=>e.jsx(Le,{title:g.name,subtitle:g.description,enabled:g.enabled,onToggle:()=>ie(g)},g.name))})]}),d==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ps,{className:"set-section-icon"}),l("settingsExtensions"),e.jsx("span",{className:"set-count",children:n.extensions.length})]}),n.extensions.length===0?e.jsx("p",{className:"set-empty",children:l(o?"dshExtensionsNote":"noExtensions")}):e.jsx("div",{className:"set-list",children:n.extensions.map(g=>{const A=g.id.startsWith("npm:")?g.id.slice(4):null;return e.jsx(Le,{title:g.name,subtitle:g.path,enabled:g.enabled,onToggle:()=>W(g),action:A?X===g.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:l("uninstallConfirmHint"),onClick:()=>U(A),children:l("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:l("uninstallHint"),onClick:()=>O(g.id),children:[e.jsx(De,{}),l("uninstallExt")]}):void 0},g.id)})})]}),d==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(jt,{className:"set-section-icon"}),l("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:l("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(g=>{var A;return e.jsxs(e.Fragment,{children:[e.jsx(Le,{title:`${g.icon?`${g.icon} `:""}${g.name}`,subtitle:(g.error?`${g.id} · ${g.error}`:g.source?`${g.id} · ${g.source}`:`${g.id} · ${l("uiPluginNoSource")}`)+((A=g.permissions)!=null&&A.length?` · ${l("uiPluginPerms")}: ${g.permissions.join(", ")}`:""),enabled:!se.has(g.id)&&!g.error,onToggle:()=>!g.error&&u(g),action:e.jsxs("div",{className:"set-row-actions",children:[g.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:l("pluginUpdateHint"),onClick:()=>te(g.id,g.source),children:[e.jsx(nt,{}),l("pluginUpdate")]}),G===g.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:l("pluginUninstallHint"),onClick:()=>K(g.id),children:l("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:l("pluginUninstallHint"),onClick:()=>q(g.id),children:[e.jsx(De,{}),l("uninstallExt")]})]})},g.id),g.settingsSchema&&g.settingsSchema.length>0&&e.jsx(vr,{plugin:g,send:s})]})})})]}),d==="plugins"&&t.engine==="dsh"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(jt,{className:"set-section-icon"}),l("dshPatches"),e.jsx(st,{text:l("dshPatchesDesc")}),e.jsx("span",{className:"set-count",children:((y=t.dshPatches)==null?void 0:y.files.length)??0}),e.jsxs("button",{type:"button",className:"set-uninstall",title:l("dshPatchesRescanHint"),onClick:()=>s({type:"dsh_patches_rescan"}),children:[e.jsx(nt,{}),l("dshPatchesRescan")]})]}),(((V=t.dshPatches)==null?void 0:V.files.length)??0)===0?e.jsx("p",{className:"set-empty",children:l("dshPatchesEmpty")}):e.jsx("div",{className:"set-list",children:t.dshPatches.files.map(g=>e.jsx("div",{className:"set-row",children:e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:g.name}),e.jsxs("div",{className:"set-row-desc",children:[yr(g.size)," · ",new Date(g.mtimeMs).toLocaleString()]})]})},g.name))}),e.jsxs("p",{className:"set-hint",children:[l("dshPatchesPath")," ",((de=t.dshPatches)==null?void 0:de.patchDir)??""]})]}),d==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ot,{className:"set-section-icon"}),l("settingsReview"),e.jsx(st,{text:l("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:n.reviewSkills.length})]}),o&&e.jsx("p",{className:"set-hint",children:l("dshReviewPromptNote")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:l("reviewPromptPlaceholder"),value:R,onFocus:()=>P.current=!0,onBlur:()=>{P.current=!1,S({reviewPrompt:R})},onChange:g=>_(g.target.value)}),e.jsx("div",{className:"set-field-label",children:l("settingsReviewSkills")}),n.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:l("noSkills")}):e.jsx("div",{className:"set-list",children:n.reviewSkills.map(g=>e.jsx(Le,{title:g.name,subtitle:g.description,enabled:g.enabled,onToggle:()=>oe(g)},`review-${g.name}`))})]}),d==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(It,{className:"set-section-icon"}),l("settingsVisionBridge")]}),e.jsx(Le,{title:l("visionBridgeEnabled"),tip:l("settingsVisionBridgeDesc"),enabled:n.visionBridgeEnabled,onToggle:()=>S({visionBridgeEnabled:!n.visionBridgeEnabled})}),!n.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:l("visionBridgeOffHint")}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:n.visionBridgeModel??"",onChange:g=>S({visionBridgeModel:g.target.value||null}),children:[e.jsx("option",{value:"",children:l("visionBridgeAuto")}),n.visionModels.map(g=>e.jsx("option",{value:`${g.provider}/${g.id}`,children:g.label},`${g.provider}/${g.id}`))]})]}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:l("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:j,onChange:g=>{const A=g.target.value;z(A),S({visionBridgePromptMode:A})},children:[e.jsx("option",{value:"append",children:l("promptModeAppend")}),e.jsx("option",{value:"replace",children:l("promptModeReplace")})]})]}),n.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:l("visionBridgePromptPlaceholder"),value:C,onFocus:()=>H.current=!0,onBlur:()=>{H.current=!1;const g=j==="replace"&&n.visionBridgeDefaultPrompt&&C===n.visionBridgeDefaultPrompt?"":C;S({visionBridgePromptMode:j,visionBridgePrompt:g})},onChange:g=>I(g.target.value)}),n.visionBridgeEnabled&&(n.visionModels.length===0?e.jsx("p",{className:"set-hint",children:l("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:l("visionBridgeCurrent",{model:n.visionBridgeModel??l("visionBridgeAuto")})}))]}),d==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(mt,{className:"set-section-icon"}),l("settingsPresets"),e.jsx("span",{className:"set-count",children:n.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:l("presetNamePlaceholder"),value:T,onChange:g=>f(g.target.value),onKeyDown:g=>{g.key==="Enter"&&T.trim()&&(s({type:"save_preset",name:T.trim()}),f(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!T.trim(),onClick:()=>{s({type:"save_preset",name:T.trim()}),f("")},children:[e.jsx(He,{})," ",l("saveAsPreset")]})]}),n.presets.length===0?e.jsx("p",{className:"set-empty",children:l("noPresets")}):e.jsx("div",{className:"set-list",children:n.presets.map(g=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:g.name}),e.jsxs("div",{className:"set-row-desc",children:[g.promptMode==="replace"?l("promptModeReplace"):l("promptModeAppend"),g.disabledSkills.length>0&&` · ${l("settingsSkills")} ${g.disabledSkills.length}`,g.disabledExtensions.length>0&&` · ${l("settingsExtensions")} ${g.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:g.name}),children:l("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:l("deletePreset"),onClick:()=>s({type:"delete_preset",name:g.name}),children:e.jsx(De,{})})]})]},g.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:l("close")})})]})})}function br(t,s){const i=Math.max(0,Date.now()-t),r=Math.floor(i/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const c=Math.floor(r/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function jr({servers:t,send:s,onClose:i}){const r=me(),[c,l]=a.useState(new Set),n=o=>l(d=>{const p=new Set(d);return p.has(o)?p.delete(o):p.add(o),p});return a.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(gt,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:i,children:e.jsx(Ne,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(gt,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const d=!!o.taskId,p=o.taskId??String(o.port);return e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:d?o.plugin:r("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[d?e.jsxs("span",{className:"bg-task-port",title:o.taskId,children:["🧩 ",o.plugin]}):e.jsxs("span",{className:"bg-task-port",children:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[!d&&e.jsxs("span",{children:[r("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",br(o.since,r)]}),d&&o.status&&e.jsx("span",{className:"bg-task-status",children:o.status})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(p)?"open":""}`,title:`${r("bgTaskCommand")}: ${o.command}`,onClick:()=>n(p),children:[e.jsx(Ge,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s(d?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(pt,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},p)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(nt,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(pt,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function wr(t,s){return t.toLowerCase().includes(s)}function Nr({open:t,send:s,projects:i,cwd:r,fileSearch:c,sessionSearch:l,onClose:n,onSwitchSession:o,onSwitchProject:d,onPreviewFile:p}){const m=me(),v=a.useRef(null),[h,x]=a.useState(""),N=a.useDeferredValue(h),[M,C]=a.useState(0),I=a.useRef(1),j=a.useRef(0),z=a.useRef(null);a.useEffect(()=>{if(!t)return;s({type:"list_sessions"}),s({type:"list_projects"});const k=h.trim();if(k){const w=++I.current;j.current=w,R(!0),s({type:"search_files",reqId:w,query:k}),s({type:"search_sessions",reqId:w,query:k})}requestAnimationFrame(()=>{var w;return(w=v.current)==null?void 0:w.select()})},[t]);const[H,R]=a.useState(!1);a.useEffect(()=>{z.current&&clearTimeout(z.current);const k=N.trim();if(!k){R(!1);return}return z.current=setTimeout(()=>{const w=++I.current;j.current=w,R(!0),s({type:"search_files",reqId:w,query:k}),s({type:"search_sessions",reqId:w,query:k})},300),()=>{z.current&&clearTimeout(z.current)}},[N]);const _=N.trim().toLowerCase(),P=a.useMemo(()=>!_||!l||l.reqId!==j.current||!l.ok?[]:l.results,[l,_]),T=a.useMemo(()=>_?i.filter(k=>wr(k.path,_)).slice(0,10):[],[i,_]),f=a.useMemo(()=>!_||!c||c.reqId!==j.current||!c.ok?[]:c.results,[c,_]);a.useEffect(()=>{c&&c.reqId===j.current&&l&&l.reqId===j.current&&j.current!==0&&R(!1)},[c,l]);const F=!!c&&c.ok&&c.truncated,Y=a.useMemo(()=>[...P.map(k=>({kind:"session",path:k.path,anchors:k.anchors})),...T.map(k=>({kind:"project",path:k.path})),...f.filter(k=>k.type==="file").map(k=>({kind:"file",path:k.path,name:k.name}))],[P,T,f]);a.useEffect(()=>{C(0)},[N]);const X=a.useCallback(k=>{if(k)if(k.kind==="session")o(k.path,k.anchors),n();else if(k.kind==="project"){d(k.path),s({type:"list_sessions"}),s({type:"list_projects"});const w=N.trim();if(w){const $=++I.current;j.current=$,R(!0),s({type:"search_files",reqId:$,query:w}),s({type:"search_sessions",reqId:$,query:w})}}else p(k.path,k.name)},[o,d,p,s,N]);a.useEffect(()=>{if(!t)return;const k=w=>{w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),n()):w.key==="ArrowDown"?(w.preventDefault(),C($=>Math.min($+1,Y.length-1))):w.key==="ArrowUp"?(w.preventDefault(),C($=>Math.max($-1,0))):w.key==="Enter"&&(w.preventDefault(),X(Y[M]))};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[Y,M,X,n,t]);const O=P.length+T.length+f.length,G=(k,w,$)=>e.jsxs("div",{className:"gs-section-head",children:[$,e.jsx("span",{children:k}),e.jsx("em",{children:w})]});let q=-1;return t?e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:n,children:e.jsxs("div",{className:"gs-modal",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(ht,{}),e.jsx("input",{ref:v,type:"text",value:h,placeholder:m("gsPlaceholder"),onChange:k=>x(k.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:m("close"),onClick:n,children:e.jsx(Ne,{})})]}),e.jsxs("div",{className:"gs-results",children:[!_&&e.jsx("div",{className:"gs-empty",children:m("gsHint")}),_&&O===0&&!F&&e.jsx("div",{className:"gs-empty",children:m(H?"gsSearching":"gsNoResults")}),P.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsSessions"),P.length,e.jsx(Qe,{})),P.map(k=>{q++;const w=q;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",onMouseEnter:()=>C(w),onClick:()=>X({kind:"session",path:k.path,anchors:k.anchors}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.name||k.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:k.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:k.firstMessage})]},k.path)})]}),T.length>0&&e.jsxs("div",{className:"gs-section",children:[G(m("gsProjects"),T.length,e.jsx(Ye,{})),T.map(k=>{q++;const w=q,$=r&&k.path===r;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",onMouseEnter:()=>C(w),onClick:()=>X({kind:"project",path:k.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[k.path.split(/[\\/]/).pop(),$&&e.jsx("em",{className:"gs-item-meta",children:m("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},k.path)})]}),(f.length>0||_&&F)&&e.jsxs("div",{className:"gs-section",children:[G(m("gsFiles"),f.length,e.jsx(Gs,{})),f.map(k=>{q++;const w=q;return e.jsxs("button",{type:"button",className:w===M?"gs-item active":"gs-item",disabled:k.type==="dir",title:k.type==="dir"?void 0:m("gsOpenPreview"),onMouseEnter:()=>C(w),onClick:()=>{k.type==="file"&&X({kind:"file",path:k.path,name:k.name})},children:[e.jsx("span",{className:"gs-item-title",children:k.name}),e.jsx("span",{className:"gs-item-sub",children:k.path})]},`${k.type}:${k.path}`)}),F&&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")]})]})]})}):null}const Mt=5e3;function Cr({file:t,content:s,send:i,onAddLines:r,onAttach:c,onClose:l}){const n=me(),[o,d]=a.useState(null),[p,m]=a.useState(!1),[v,h]=a.useState(null),[x,N]=a.useState(!1),[M,C]=a.useState(!1),[I,j]=a.useState(!1),[z,H]=a.useState(""),[R,_]=a.useState(!0),P=a.useRef(!1),[T,f]=a.useState(!0),[F,Y]=a.useState(!1),[X,O]=a.useState(100),G=a.useRef(0),q=a.useRef(!1),k=a.useRef(null);a.useEffect(()=>{m(!0),d(null),h(null),j(!1),H(""),_(!0),P.current=!1,i({type:"read_file",path:t.path})},[t.path,i]),a.useEffect(()=>{s&&s.path===t.path&&(d(s),I||H(s.text),m(!1))},[s,I,t.path]),a.useEffect(()=>{const A=ae=>{if(ae.key==="Escape"){U();return}if((ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="s"&&I){ae.preventDefault(),D();return}const he=ae.target,xe=he&&(he.tagName==="INPUT"||he.tagName==="TEXTAREA"||he.isContentEditable);(ae.ctrlKey||ae.metaKey)&&ae.key.toLowerCase()==="a"&&!xe&&(ae.preventDefault(),S())};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[l,o,I,z]),a.useEffect(()=>{const A=()=>{q.current=!1,N(!1)};return window.addEventListener("mouseup",A),()=>window.removeEventListener("mouseup",A)},[]);const w=a.useMemo(()=>{if(!o)return[];const A=o.text.split(`
|
|
321
|
+
`);return A.length>0&&A[A.length-1]===""&&A.pop(),A.slice(0,Mt)},[o]),$=(o==null?void 0:o.lines)??0,J=$>Mt,Z=(A,ae)=>{if(ae){const he=G.current>0?G.current:A;h({start:Math.min(he,A),end:Math.max(he,A)})}else G.current=A,h({start:A,end:A})},S=()=>{w.length!==0&&(G.current=1,h({start:1,end:w.length}))},ie=()=>{v&&(r(t.path,t.name,v.start,v.end),C(!0),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>C(!1),1400))},se=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,u=()=>{H((o==null?void 0:o.text)??""),j(!1),P.current&&_(!0)},W=()=>{if(I){if(z!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;u();return}!se||!o||(P.current=Pt(t.name)&&R,Pt(t.name)&&_(!1),h(null),H(o.text),j(!0))},D=()=>{!I||!o||!se||i({type:"write_file",path:t.path,text:z})&&(j(!1),P.current&&_(!0),h(null))},U=()=>{I&&z!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||l()},K=A=>{O(Math.min(200,Math.max(50,A)))},te=v?v.end-v.start+1:0,oe=(o==null?void 0:o.binary)??!1,ve=(o==null?void 0:o.truncated)??!1,y=(o==null?void 0:o.kind)??"text",V=Pt(t.name),de=V&&R&&!I&&y==="text"&&!oe,g=A=>yt(Je(`/api/file?clientId=${encodeURIComponent(qt())}&path=${encodeURIComponent(A)}`));return e.jsx("div",{className:`fp-overlay ${F?"fullscreen":""}`,onMouseDown:A=>{A.target===A.currentTarget&&U()},children:e.jsxs("div",{className:`fp ${F?"fullscreen":""}`,style:{"--fp-zoom":X/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&&y==="text"&&!oe&&n("fileLines",{n:$}),o&&` · ${Sr(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[V&&y==="text"&&!oe&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${R?"on":""}`,"data-tip":n(R?"showMarkdownSource":"showMarkdownPreview"),disabled:I,onClick:()=>_(A=>!A),children:R?e.jsx(It,{}):e.jsx(ui,{})}),y==="text"&&!oe&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${I?"on":""}`,"data-tip":n(ve?"fileEditTruncated":I?"exitEditFile":"editFile"),disabled:!se&&!I,onClick:W,children:e.jsx(Lt,{})}),y==="text"&&!oe&&!de&&e.jsx("button",{type:"button",className:`fp-attach wrap ${T?"on":""}`,"data-tip":n(T?"disableWrap":"enableWrap"),onClick:()=>f(A=>!A),children:e.jsx(di,{})}),y==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:X<=50,onClick:()=>K(X-10),children:e.jsx(Kn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>O(100),children:[X,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:X>=200,onClick:()=>K(X+10),children:e.jsx(zn,{})})]}),y!=="video"&&y!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Rt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${F?"on":""}`,"data-tip":n(F?"exitFullscreen":"fullscreen"),onClick:()=>Y(A=>!A),children:F?e.jsx(ei,{}):e.jsx(si,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:U,children:e.jsx(Ne,{})})]})]}),ve&&y==="text"&&!oe&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&y==="none"&&!oe&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&y==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:g(t.path),alt:t.name})}),!p&&y==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:g(t.path),controls:!0,preload:"metadata"})}),!p&&de&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(kt,{text:o.text})})}),!p&&oe&&y!=="image"&&y!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&I&&y==="text"&&!oe&&o&&e.jsx("textarea",{className:`fp-editor ${T?"":"no-wrap"}`,value:z,onChange:A=>H(A.target.value),wrap:T?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!de&&!I&&y==="text"&&!oe&&o&&w.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!de&&!I&&y==="text"&&!oe&&w.length>0&&e.jsxs("div",{className:`fp-code ${x?"dragging":""} ${T?"":"no-wrap"}`,onMouseDown:A=>{A.button===0&&A.preventDefault()},children:[w.map((A,ae)=>{const he=ae+1,xe=v!==null&&he>=v.start&&he<=v.end;return e.jsxs("div",{className:`fp-line ${xe?"sel":""}`,onMouseDown:ue=>{ue.button===0&&(Z(he,ue.shiftKey),q.current=!0,N(!0))},onMouseEnter:()=>{q.current&&Z(he,!0)},children:[e.jsx("span",{className:"fp-num",children:he}),e.jsx("span",{className:"fp-code-text",children:A})]},he)}),J&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:Mt})})]}),e.jsx("div",{className:"fp-foot",children:I?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:n("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:W,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:z===((o==null?void 0:o.text)??""),onClick:D,children:[e.jsx(Jn,{})," ",n("saveFile")]})]})]}):!de&&y==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:v?n("selectedRange",{n:te,start:v.start,end:v.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:w.length===0,onClick:S,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!v,onClick:()=>h(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!v||oe,onClick:ie,children:[M?e.jsx(vt,{}):null,n(M?"addedToChat":"addToChat")]})]})]})})]})})}function Pt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Sr(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const jn="pi-web-sounds",Ze={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function wn(){try{const t=localStorage.getItem(jn);if(!t)return{...Ze};const s=JSON.parse(t),i={...Ze,...s};for(const r of["enabled","question","done","start","error"])typeof i[r]!="boolean"&&(i[r]=Ze[r]);return typeof i.volume!="number"||!Number.isFinite(i.volume)?i.volume=Ze.volume:i.volume=Math.round(Math.max(0,Math.min(100,i.volume))/5)*5,i}catch{return{...Ze}}}function Tr(t){try{localStorage.setItem(jn,JSON.stringify(t))}catch{}}let et=null;function Er(){try{if(!et){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;et=new t}return et.state==="suspended"&&et.resume(),et}catch{return null}}const Mr=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],Pr=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],Rr=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],Ir=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Lr={question:Mr,done:Pr,start:Rr,error:Ir};function Dr(t,s,i){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const l=t.currentTime+s.start,n=Math.max(1e-4,s.peak*i);c.gain.setValueAtTime(1e-4,l),c.gain.exponentialRampToValueAtTime(n,l+.012),c.gain.exponentialRampToValueAtTime(1e-4,l+s.dur),r.connect(c),c.connect(t.destination),r.start(l),r.stop(l+s.dur+.05)}function tt(t,s=wn()){if(!s.enabled||!s[t])return;const i=Er();if(!i)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Lr[t])Dr(i,c,r)}const $t="pi-web-ui:theme",Nn="dark",Ds="theme-stylesheet",Bs="pi-web-ui:theme-change";function Cn(){try{const t=localStorage.getItem($t);if(t&&t!==Nn)return t}catch{}return null}function Br(t){try{t?localStorage.setItem($t,t):localStorage.removeItem($t)}catch{}}function Sn(t){let s=document.getElementById(Ds);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Bs));return}s||(s=document.createElement("link"),s.id=Ds,s.rel="stylesheet",document.head.appendChild(s)),s.href=Je(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(Bs))}async function Fr(){try{const t=await fetch(yt(Je("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function _r(){const[t,s]=a.useState([]),[i,r]=a.useState(()=>Cn());return a.useEffect(()=>{let l=!1;return Fr().then(n=>{l||s(n)}),()=>{l=!0}},[]),a.useEffect(()=>{Sn(i),Br(i)},[i]),{themes:t,theme:i,switchTheme:l=>r(l===Nn?null:l)}}function Kr(){const t=getComputedStyle(document.documentElement),s=(i,r)=>t.getPropertyValue(i).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Ar=a.lazy(()=>_n(()=>import("./TerminalPanel-CSzqnWV2.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function $r({notice:t,onDismiss:s}){const i=me(),[r,c]=a.useState(!1);a.useEffect(()=>{if(r)return;const n=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(n)},[r,t.id,t.level,s]);const l=t.level==="error"?gi:t.level==="warning"?hi:ri;return e.jsxs("div",{className:`notice notice-${t.level}${r?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(l,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:i("close"),onClick:()=>s(t.id),children:e.jsx(Ne,{})})]})}const Hr=[],Tn=180,En=520,Mn=240,Pn=t=>`pi-web-ui:${t}-panel-width`;function Fs(t){const s=Number(localStorage.getItem(Pn(t)));return Number.isFinite(s)&&s>=Tn&&s<=En?s:Mn}const Ht=t=>`pi-web-ui:${t}-panel-collapsed`;function _s(t){return localStorage.getItem(Ht(t))==="1"}function As({side:t,width:s,onResize:i}){const r=me(),c=a.useCallback(l=>{l.preventDefault();const n=l.clientX,o=s;let d=o;const p=v=>{const h=t==="left"?v.clientX-n:n-v.clientX;d=Math.min(En,Math.max(Tn,Math.round(o+h))),i(d)},m=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",m),document.body.classList.remove("panel-resizing"),localStorage.setItem(Pn(t),String(d))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",m),document.body.classList.add("panel-resizing")},[t,s,i]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>i(Mn)})}function $s({side:t,onClick:s}){const i=me();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:i("expandPanel"),onClick:s,children:t==="left"?e.jsx(Qs,{}):e.jsx(Ys,{})})}function Or(){var Ie,Vt,Gt,Qt,Yt,Jt,Xt,Zt,es,ts,ss,ns,is,as;const t=me(),{chat:s,send:i,dismissNotice:r,pushNotice:c,terminal:l}=Ui(),[n,o]=a.useState([]),[d,p]=a.useState(null),[m,v]=a.useState(!1),[h,x]=a.useState("chat"),N=a.useMemo(()=>s.plugins.filter(B=>{var Q,le;return!((le=(Q=s.settings)==null?void 0:Q.disabledPlugins)!=null&&le.includes(B.id))}),[s.plugins,(Ie=s.settings)==null?void 0:Ie.disabledPlugins]),[M,C]=a.useState([]);a.useEffect(()=>Di(C),[]),a.useEffect(()=>{Bi(N,s.pluginsEpoch)},[N,s.pluginsEpoch]);const[I,j]=a.useState(()=>Fs("left")),[z,H]=a.useState(()=>Fs("right")),R=a.useCallback(B=>j(B),[]),_=a.useCallback(B=>H(B),[]),[P,T]=a.useState(()=>_s("left")),[f,F]=a.useState(()=>_s("right")),Y=a.useCallback(()=>{T(B=>(localStorage.setItem(Ht("left"),B?"0":"1"),!B))},[]),X=a.useCallback(()=>{F(B=>(localStorage.setItem(Ht("right"),B?"0":"1"),!B))},[]),[O,G]=a.useState(null),[q,k]=a.useState(()=>window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{const B=window.matchMedia("(max-width: 768px)"),Q=le=>k(le.matches);return B.addEventListener("change",Q),()=>B.removeEventListener("change",Q)},[]);const[w,$]=a.useState(!1),[J,Z]=a.useState(!1),[S,ie]=a.useState(!1),[se,u]=a.useState(!1),[W,D]=a.useState(!1),[U,K]=a.useState(null);a.useEffect(()=>{if(!U)return;const B=setTimeout(()=>K(null),15e3);return()=>clearTimeout(B)},[U]),a.useEffect(()=>{const B=Q=>{var Ae,rs;const le=Q.detail,ye=(le==null?void 0:le.title)||"插件命令",be=le==null?void 0:le.command;if(!be||!s.ready)return;const Ee={name:ye,command:be,cwd:"${pwd}"},je=s.terminals.find(bt=>bt.title===ye);if(je)l.restart(je.id),i({type:"run_command",terminalId:je.id,conversationId:je.conversationId,command:Ee,cols:80,rows:24});else{const bt=Fe();l.create({id:bt,conversationId:s.activeConversationId||((Ae=s.state)==null?void 0:Ae.conversationId)||"",title:ye,cwd:((rs=s.state)==null?void 0:rs.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Ee})}x("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",B),()=>window.removeEventListener("pi-web-ui:plugin-run-command",B)},[s,l,i]),a.useEffect(()=>{const B=Q=>{!(Q.ctrlKey||Q.metaKey)||Q.key.toLowerCase()!=="k"||(Q.preventDefault(),D(le=>!le))};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[]);const[te,oe]=a.useState(wn),{themes:ve,theme:y,switchTheme:V}=_r(),de=a.useRef(null),g=a.useRef(null),A=a.useRef(0),ae=a.useRef(!1),he=a.useRef(s.terminals);a.useEffect(()=>{Tr(te)},[te]),a.useEffect(()=>{var Q;const B=he.current;he.current=s.terminals;for(const le of s.terminals){const ye=((Q=le.command)==null?void 0:Q.command)??"",be=B.find(Ee=>Ee.id===le.id);!(be!=null&&be.running)||le.running||(ye.startsWith("pi remove ")?i({type:"extensions_reload"}):ye.startsWith("pi-web-ui install ")||ye.startsWith("pi-web-ui uninstall ")?i({type:"plugins_reload"}):ye.startsWith("npm i -g ")&&(i({type:"extensions_reload"}),i({type:"plugins_reload"}),i({type:"check_updates_all",force:!0})))}},[s.terminals,i]),a.useEffect(()=>{var le;const B=((le=s.state)==null?void 0:le.isStreaming)??!1,Q=de.current;de.current=B,Q!==null&&(!Q&&B?tt("start",te):Q&&!B&&tt("done",te))},[(Vt=s.state)==null?void 0:Vt.isStreaming,te]),a.useEffect(()=>{var Q;const B=((Q=s.dialog)==null?void 0:Q.id)??null;B!==null&&B!==g.current&&tt("question",te),g.current=B},[s.dialog,te]),a.useEffect(()=>{const B=[...s.notices].reverse().find(Q=>Q.level==="error");B&&B.id!==A.current&&(A.current=B.id,tt("error",te))},[s.notices,te]);const xe=(B,Q,le,ye=!1,be)=>{const Ee=`${B}|${le}|${be?`${be.start}-${be.end}`:""}`;o(je=>je.some(Ae=>`${Ae.path}|${Ae.mode}|${Ae.lines?`${Ae.lines.start}-${Ae.lines.end}`:""}`===Ee)?je:[...je,{path:B,name:Q,mode:le,isDir:ye,...be?{lines:be}:{}}])},ue=B=>o(Q=>Q.filter(le=>le.key?le.key!==B:le.path!==B)),Pe=a.useCallback(B=>(!B.type.startsWith("list_")&&!B.type.startsWith("get_")&&G(null),i(B)),[i]),Te=a.useRef(0),_e=a.useRef(0),Xe=B=>{var ye;const Q=Date.now();(ye=s.state)!=null&&ye.model&&!s.state.model.vision&&Q-_e.current>1e4&&(_e.current=Q,c("warning",t("imageNotSupported")));const le=`paste-${++Te.current}`;o(be=>[...be,{path:"",key:le,name:B.name,mode:"inline",imageData:B.data,mimeType:B.mimeType}])},Se=async B=>{for(const Q of B){const le=await on(Q);if(!le){c("error",t("imageLoadFailed",{name:Q.name}));continue}Xe(le)}},Ke=20*1024*1024,Oe=a.useRef(0),We=async B=>{if(B.size>Ke){c("warning",t("fileTooLarge",{name:B.name,size:Ke/1024/1024}));return}let Q;try{Q=(await new Promise((be,Ee)=>{const je=new FileReader;je.onload=()=>be(je.result),je.onerror=()=>Ee(je.error??new Error("read failed")),je.readAsDataURL(B)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:B.name}));return}const le=`upload-${++Oe.current}`;o(ye=>[...ye,{path:"",key:le,name:B.name,mode:"inline",fileData:Q,size:B.size,mimeType:B.type||void 0}])},Re=async B=>{for(const Q of B)Be(Q.type)?await Se([Q]):await We(Q)},E=a.useCallback((B,Q,le)=>{i({type:"edit_message",messageId:B,text:Q,attachments:le})},[i]),pe=a.useCallback(()=>Z(!0),[]),ce=a.useCallback(()=>o([]),[]),ke=a.useCallback(ue,[]),b=a.useCallback(Se,[Se]),L=a.useCallback(Re,[Re]),ne=(Gt=s.state)==null?void 0:Gt.model,re=(Qt=s.state)==null?void 0:Qt.thinkingLevel,ge=(Yt=s.state)==null?void 0:Yt.availableThinkingLevels,fe=a.useMemo(()=>ne?{model:ne,thinkingLevel:re??"off",availableThinkingLevels:ge??[]}:null,[ne,re,ge]),we=a.useCallback(()=>{var B,Q;return!s.ready||s.terminals.length!==0?!1:(l.create({id:Fe(),conversationId:s.activeConversationId||((B=s.state)==null?void 0:B.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((Q=s.state)==null?void 0:Q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Jt=s.state)==null?void 0:Jt.cwd,s.terminals.length,t,l]);return a.useEffect(()=>{if(ae.current){if(h!=="terminal"||s.terminals.length!==0){ae.current=!1;return}we()&&(ae.current=!1)}},[s.terminals.length,we,h]),e.jsxs("div",{className:"app",onDragOver:B=>{var Q;Array.from(((Q=B.dataTransfer)==null?void 0:Q.types)??[]).includes("Files")&&(B.preventDefault(),v(!0))},onDragLeave:B=>{B.currentTarget.contains(B.relatedTarget)||v(!1)},onDrop:B=>{var be,Ee;if(v(!1),!Array.from(((be=B.dataTransfer)==null?void 0:be.types)??[]).includes("Files"))return;B.preventDefault();const Q=Array.from(((Ee=B.dataTransfer)==null?void 0:Ee.files)??[]);if(Q.length===0){c("warning",t("foldersNotSupported"));return}const le=Q.filter(je=>Be(je.type)),ye=Q.filter(je=>!Be(je.type));le.length>0&&Se(le),ye.length>0&&Re(ye)},children:[m&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(ji,{chat:s,send:i,terminal:l,view:h,plugins:N,onViewChange:B=>{ae.current=B==="terminal"&&s.terminals.length===0,ae.current&&we()&&(ae.current=!1),x(B),G(null)},onOpenPanel:G,onOpenSettings:()=>ie(!0),onOpenBgTasks:()=>u(!0),onOpenGlobalSearch:()=>D(!0),sound:te,onSoundChange:oe,onSoundPreview:B=>tt(B,te),themes:ve,theme:y,onThemeChange:V}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(B=>e.jsx($r,{notice:B,onDismiss:r},B.id))}),e.jsx(Ka,{send:i,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${I}px`,"--right-w":`${z}px`},children:[O&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>G(null)}),e.jsxs("div",{className:`view-pane ${h==="chat"?"":"hidden"}`,children:[!q&&P&&e.jsx($s,{side:"left",onClick:Y}),e.jsx("div",{className:`panel-drawer drawer-left ${O==="left"?"open":""}${q?"":P?" hidden":""}`,children:e.jsx(Ni,{collapsible:!q,onToggleCollapse:Y,send:Pe,active:!q||O==="left",ready:s.ready,status:s.status,cwd:((Xt=s.state)==null?void 0:Xt.cwd)??"",sessionFile:((Zt=s.state)==null?void 0:Zt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!q&&e.jsx(As,{side:"left",width:I,onResize:R}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ja,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:E,onKillBash:()=>i({type:"abort_bash"}),thinkingWrap:((es=s.settings)==null?void 0:es.thinkingWrap)??!0,toolsWrap:((ts=s.settings)==null?void 0:ts.toolsWrap)??!0,jumpTarget:U,onJumpDone:()=>K(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(rr,{send:i,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(cr,{dialog:s.dialog,send:i}),s.question&&e.jsx(dr,{question:s.question,send:i}),e.jsx(ar,{send:i,ready:s.ready,streaming:((ss=s.state)==null?void 0:ss.isStreaming)??!1,messages:((ns=s.state)==null?void 0:ns.messages)??Hr,slashCommands:s.slashCommands,modelState:fe,models:s.models,modelsLoading:s.modelsLoading,attachments:n,onRemoveAttachment:ke,onAddImageFiles:b,onAddLocalFiles:L,onNotice:c,onManageModels:pe,onSent:ce})]}),!q&&e.jsx(As,{side:"right",width:z,onResize:_}),e.jsx("div",{className:`panel-drawer drawer-right ${O==="right"?"open":""}${q?"":f?" hidden":""}`,children:e.jsx(Xi,{collapsible:!q,onToggleCollapse:X,send:Pe,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((is=s.state)==null?void 0:is.cwd)??"",onAttach:(B,Q,le,ye)=>{G(null),xe(B,Q,le,ye)},onPreview:(B,Q)=>{G(null),p({path:B,name:Q})},onNotice:(B,Q)=>c(B,Q)})}),!q&&f&&e.jsx($s,{side:"right",onClick:X})]}),e.jsx("div",{className:`view-pane ${h==="terminal"?"":"hidden"}`,children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(Ar,{chat:s,send:i,terminal:l})})}),e.jsx("div",{className:`view-pane ${h==="git"?"":"hidden"}`,children:e.jsx(pr,{chat:s,send:i,terminal:l,active:h==="git",onSwitchToTerminal:()=>x("terminal")})}),M.map(B=>{const Q=`plugin:${B.info.id}`;return e.jsx("div",{className:`view-pane ${h===Q?"":"hidden"}`,children:e.jsx(mr,{entry:B,send:i})},B.info.id)})]})}),e.jsx(lr,{chat:s,send:i}),d&&e.jsx(Cr,{file:d,content:s.fileContent,send:i,onAddLines:(B,Q,le,ye)=>xe(B,Q,"lines",!1,{start:le,end:ye}),onAttach:(B,Q,le)=>xe(B,Q,le),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!w&&!J&&e.jsx(hr,{send:i,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>$(!0)}),J&&e.jsx(xr,{send:i,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>Z(!1)}),S&&e.jsx(kr,{chat:s,send:i,terminal:l,onSwitchToTerminal:()=>x("terminal"),onClose:()=>ie(!1)}),se&&e.jsx(jr,{servers:s.bgServers,send:i,onClose:()=>u(!1)}),e.jsx(Nr,{open:W,send:i,projects:s.projects,cwd:((as=s.state)==null?void 0:as.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>D(!1),onSwitchSession:(B,Q)=>{i({type:"switch_session",path:B});const le=Q&&Q[0];K(le?{path:B,role:le.role,timestamp:le.timestamp}:null)},onSwitchProject:B=>{i({type:"set_cwd",path:B})},onPreviewFile:(B,Q)=>{p({path:B,name:Q})}})]})}Ci();Sn(Cn());Dn.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(ki,{children:e.jsx(Or,{})})}));export{nt as F,Bs as T,He as a,Kr as b,qr as c,Dt as d,De as e,ti as f,Ge as g,Ne as h,Fe as r,me as u};
|