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