pi-web-ui 0.48.3 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/agent-service.js +39 -1
- package/dist/server/index.js +1 -3
- package/dist/server/slash-commands.js +4 -6
- package/package.json +5 -15
- package/themes/cyberpunk.css +29 -5
- package/themes/dazzle.css +29 -5
- package/themes/light.css +30 -6
- package/themes/md-preview.css +7707 -7676
- package/themes/white.css +7768 -7737
- package/web/dist/assets/{TerminalPanel-CsLJErXe.js → TerminalPanel-CqkXPEV8.js} +1 -1
- package/web/dist/assets/{index-B4Bb2-Uw.css → index-OKDW_plu.css} +1 -1
- package/web/dist/assets/{index-verW8_Ym.js → index-gd3hCgKS.js} +20 -19
- package/web/dist/index.html +2 -2
- package/electron/main.mjs +0 -427
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-
|
|
2
|
-
import{R as $e,a,j as e,M as Es,b as vn,c as yn}from"./markdown-DRBrS2Nf.js";import{r as Ms}from"./react-C9ovnpIm.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))l(c);new MutationObserver(c=>{for(const r of c)if(r.type==="childList")for(const n of r.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&l(n)}).observe(document,{childList:!0,subtree:!0});function i(c){const r={};return c.integrity&&(r.integrity=c.integrity),c.referrerPolicy&&(r.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?r.credentials="include":c.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function l(c){if(c.ep)return;c.ep=!0;const r=i(c);fetch(c.href,r)}})();var et={},Jt;function kn(){if(Jt)return et;Jt=1;var t=Ms();return et.createRoot=t.createRoot,et.hydrateRoot=t.hydrateRoot,et}var bn=kn();const jn="modulepreload",wn=function(t){return"/"+t},Yt={},Rs=function(s,i,l){let c=Promise.resolve();if(i&&i.length>0){let n=function(p){return Promise.all(p.map(h=>Promise.resolve(h).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),u=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=n(i.map(p=>{if(p=wn(p),p in Yt)return;Yt[p]=!0;const h=p.endsWith(".css"),g=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${g}`))return;const v=document.createElement("link");if(v.rel=h?"stylesheet":jn,h||(v.as="script"),v.crossOrigin="",v.href=p,u&&v.setAttribute("nonce",u),document.head.appendChild(v),h)return new Promise((b,k)=>{v.addEventListener("load",b),v.addEventListener("error",()=>k(new Error(`Unable to preload CSS for ${p}`)))})}))}function r(n){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=n,window.dispatchEvent(o),!o.defaultPrevented)throw n}return c.then(n=>{for(const o of n||[])o.status==="rejected"&&r(o.reason);return s().catch(r)})};var Ps={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Qt=$e.createContext&&$e.createContext(Ps),Nn=["attr","size","title"];function Cn(t,s){if(t==null)return{};var i,l,c=Sn(t,s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(l=0;l<r.length;l++)i=r[l],s.indexOf(i)===-1&&{}.propertyIsEnumerable.call(t,i)&&(c[i]=t[i])}return c}function Sn(t,s){if(t==null)return{};var i={};for(var l in t)if({}.hasOwnProperty.call(t,l)){if(s.indexOf(l)!==-1)continue;i[l]=t[l]}return i}function rt(){return rt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var i=arguments[s];for(var l in i)({}).hasOwnProperty.call(i,l)&&(t[l]=i[l])}return t},rt.apply(null,arguments)}function Xt(t,s){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);s&&(l=l.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),i.push.apply(i,l)}return i}function lt(t){for(var s=1;s<arguments.length;s++){var i=arguments[s]!=null?arguments[s]:{};s%2?Xt(Object(i),!0).forEach(function(l){Tn(t,l,i[l])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):Xt(Object(i)).forEach(function(l){Object.defineProperty(t,l,Object.getOwnPropertyDescriptor(i,l))})}return t}function Tn(t,s,i){return(s=En(s))in t?Object.defineProperty(t,s,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[s]=i,t}function En(t){var s=Mn(t,"string");return typeof s=="symbol"?s:s+""}function Mn(t,s){if(typeof t!="object"||!t)return t;var i=t[Symbol.toPrimitive];if(i!==void 0){var l=i.call(t,s);if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function Is(t){return t&&t.map((s,i)=>$e.createElement(s.tag,lt({key:i},s.attr),Is(s.child)))}function G(t){return s=>$e.createElement(Rn,rt({attr:lt({},t.attr)},s),Is(t.child))}function Rn(t){var s=i=>{var l=t.attr,c=t.size,r=t.title,n=Cn(t,Nn),o=c||i.size||"1em",u;return i.className&&(u=i.className),t.className&&(u=(u?u+" ":"")+t.className),$e.createElement("svg",rt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},i.attr,l,n,{className:u,style:lt(lt({color:t.color||i.color},i.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),r&&$e.createElement("title",null,r),t.children)};return Qt!==void 0?$e.createElement(Qt.Consumer,null,i=>s(i)):s(Ps)}function Pn(t){return G({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 In(t){return G({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 nt(t){return G({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 ke(t){return G({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 G({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 Ln(t){return G({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 Ee(t){return G({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 Ke(t){return G({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 Zt(t){return G({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 Dn(t){return G({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 ot(t){return G({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 Bn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"4",y1:"21",x2:"4",y2:"14"},child:[]},{tag:"line",attr:{x1:"4",y1:"10",x2:"4",y2:"3"},child:[]},{tag:"line",attr:{x1:"12",y1:"21",x2:"12",y2:"12"},child:[]},{tag:"line",attr:{x1:"12",y1:"8",x2:"12",y2:"3"},child:[]},{tag:"line",attr:{x1:"20",y1:"21",x2:"20",y2:"16"},child:[]},{tag:"line",attr:{x1:"20",y1:"12",x2:"20",y2:"3"},child:[]},{tag:"line",attr:{x1:"1",y1:"14",x2:"7",y2:"14"},child:[]},{tag:"line",attr:{x1:"9",y1:"8",x2:"15",y2:"8"},child:[]},{tag:"line",attr:{x1:"17",y1:"16",x2:"23",y2:"16"},child:[]}]})(t)}function ct(t){return G({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 Ds(t){return G({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 dt(t){return G({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 Fn(t){return G({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 Bs(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"1 4 1 10 7 10"},child:[]},{tag:"path",attr:{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"},child:[]}]})(t)}function pt(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"23 4 23 10 17 10"},child:[]},{tag:"polyline",attr:{points:"1 20 1 14 7 14"},child:[]},{tag:"path",attr:{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"},child:[]}]})(t)}function Le(t){return G({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 xr(t){return G({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 $n(t){return G({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 es(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"16.5",y1:"9.4",x2:"7.5",y2:"4.21"},child:[]},{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function An(t){return G({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 _n(t){return G({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 Ue(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},child:[]}]})(t)}function On(t){return G({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 Wn(t){return G({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 Hn(t){return G({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 qn(t){return G({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 Ct(t){return G({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 ut(t){return G({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 Kn(t){return G({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 G({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 zn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},child:[]},{tag:"circle",attr:{cx:"8.5",cy:"8.5",r:"1.5"},child:[]},{tag:"polyline",attr:{points:"21 15 16 10 5 21"},child:[]}]})(t)}function Vn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"14",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"3",y:"14",width:"7",height:"7"},child:[]}]})(t)}function Gn(t){return G({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 ts(t){return G({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 it(t){return G({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 ze(t){return G({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 Fs(t){return G({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 $s(t){return G({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 St(t){return G({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 Tt(t){return G({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 Et(t){return G({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 Dt(t){return G({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 Xe(t){return G({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 Jn(t){return G({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 Bt(t){return G({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 Yn(t){return G({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 mt(t){return G({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 ht(t){return G({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 Ae(t){return G({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 gt(t){return G({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 Qn(t){return G({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 ss(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function Xn(t){return G({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 As(t){return G({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 _s(t){return G({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 Zn(t){return G({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 ei(t){return G({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 De(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let i=0;i<16;i++)t[i]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function Ie({trigger:t,open:s,onOpenChange:i,children:l,align:c="right",fit:r=!1,direction:n="down",menuClassName:o,menuRef:u,menuStyle:p}){const h=a.useRef(null);return a.useEffect(()=>{if(!s)return;const g=b=>{h.current&&!h.current.contains(b.target)&&i(!1)},v=b=>{b.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",v)}},[s,i]),e.jsxs("div",{className:`dropdown ${c} ${r?"fit":""} ${n==="up"?"dd-up":""}`,ref:h,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>i(!s),"aria-expanded":s,children:[t,e.jsx(Ae,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:u,style:p,children:l})]})}function be({active:t,disabled:s=!1,title:i,onClick:l,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:i,onClick:l,children:c})}const Os="pi-web-ui:lang",ti={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:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",folderRef:"文件夹引用:{path}",refOnly:"仅引用:{path}",attachContent:"附加内容:{path}",attachLines:"附加选中行:{path}(第 {start}-{end} 行)",attachImage:"图片:{name}",attachFile:"文件:{name}",removeAttachment:"移除附件",attachHint:"将随下一条消息发送",uploadFile:"添加文件(图片/文本/任意文件,也可直接拖入或粘贴截图)",dropHereToAttach:"松开以添加文件",imageNotSupported:"当前模型不支持识图:图片将交给视觉桥转写(若未配置视觉模型则可能被忽略)",imageLoadFailed:"图片读取失败:{name}",fileLoadFailed:"文件读取失败:{name}",fileTooLarge:"文件过大已跳过(>{size}MB):{name}",foldersNotSupported:"不支持直接拖入文件夹,请展开后选择文件",placeholderStreaming:"智能体正在工作中…回车插队发送,或点「排队」等回答结束后发送",placeholderIdle:"给 pi 发送消息 — Enter 发送,/ 查看命令",placeholderConnecting:"正在连接服务器…",stopAgent:"停止智能体",stop:"停止",bgTasks:"后台任务",bgTasksTip:"AI 在后台启动的服务(npm run dev & 等)——可逐个停止或全部关闭,对话结束后仍保留",bgTasksEmpty:"暂无后台任务",bgTasksDesc:"AI 运行中启动并仍在监听的进程(按监听端口检测)",bgTaskPort:"端口",bgTaskPid:"PID",bgTaskSince:"启动",bgTaskStop:"停止",bgTaskStopAll:"全部关闭",bgTaskRefresh:"刷新",bgTaskJustNow:"刚刚",bgTaskMinutes:"{n} 分钟前",bgTaskHours:"{n} 小时前",bgTaskDays:"{n} 天前",stopBash:"停止",stopBashTip:"停止正在运行的 bash 命令(对话继续)",supplement:"排队",supplementTip:"加入队列:AI 回答完全结束后才发送(不打断)",queueSteerTag:"插队",queueFollowTag:"排队",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",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 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:同时搜索历史对话、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索文件…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-CqkXPEV8.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 Ae,a as r,j as e,M as Es,b as vn,c as yn}from"./markdown-DRBrS2Nf.js";import{r as Ms}from"./react-C9ovnpIm.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))l(c);new MutationObserver(c=>{for(const i of c)if(i.type==="childList")for(const n of i.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&l(n)}).observe(document,{childList:!0,subtree:!0});function a(c){const i={};return c.integrity&&(i.integrity=c.integrity),c.referrerPolicy&&(i.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?i.credentials="include":c.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function l(c){if(c.ep)return;c.ep=!0;const i=a(c);fetch(c.href,i)}})();var et={},Jt;function kn(){if(Jt)return et;Jt=1;var t=Ms();return et.createRoot=t.createRoot,et.hydrateRoot=t.hydrateRoot,et}var bn=kn();const jn="modulepreload",wn=function(t){return"/"+t},Yt={},Rs=function(s,a,l){let c=Promise.resolve();if(a&&a.length>0){let n=function(p){return Promise.all(p.map(h=>Promise.resolve(h).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),u=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));c=n(a.map(p=>{if(p=wn(p),p in Yt)return;Yt[p]=!0;const h=p.endsWith(".css"),g=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${g}`))return;const v=document.createElement("link");if(v.rel=h?"stylesheet":jn,h||(v.as="script"),v.crossOrigin="",v.href=p,u&&v.setAttribute("nonce",u),document.head.appendChild(v),h)return new Promise((b,k)=>{v.addEventListener("load",b),v.addEventListener("error",()=>k(new Error(`Unable to preload CSS for ${p}`)))})}))}function i(n){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=n,window.dispatchEvent(o),!o.defaultPrevented)throw n}return c.then(n=>{for(const o of n||[])o.status==="rejected"&&i(o.reason);return s().catch(i)})};var Ps={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Qt=Ae.createContext&&Ae.createContext(Ps),Nn=["attr","size","title"];function Cn(t,s){if(t==null)return{};var a,l,c=Sn(t,s);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(l=0;l<i.length;l++)a=i[l],s.indexOf(a)===-1&&{}.propertyIsEnumerable.call(t,a)&&(c[a]=t[a])}return c}function Sn(t,s){if(t==null)return{};var a={};for(var l in t)if({}.hasOwnProperty.call(t,l)){if(s.indexOf(l)!==-1)continue;a[l]=t[l]}return a}function rt(){return rt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var l in a)({}).hasOwnProperty.call(a,l)&&(t[l]=a[l])}return t},rt.apply(null,arguments)}function Xt(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);s&&(l=l.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),a.push.apply(a,l)}return a}function lt(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Xt(Object(a),!0).forEach(function(l){Tn(t,l,a[l])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Xt(Object(a)).forEach(function(l){Object.defineProperty(t,l,Object.getOwnPropertyDescriptor(a,l))})}return t}function Tn(t,s,a){return(s=En(s))in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function En(t){var s=Mn(t,"string");return typeof s=="symbol"?s:s+""}function Mn(t,s){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var l=a.call(t,s);if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function Is(t){return t&&t.map((s,a)=>Ae.createElement(s.tag,lt({key:a},s.attr),Is(s.child)))}function G(t){return s=>Ae.createElement(Rn,rt({attr:lt({},t.attr)},s),Is(t.child))}function Rn(t){var s=a=>{var l=t.attr,c=t.size,i=t.title,n=Cn(t,Nn),o=c||a.size||"1em",u;return a.className&&(u=a.className),t.className&&(u=(u?u+" ":"")+t.className),Ae.createElement("svg",rt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,l,n,{className:u,style:lt(lt({color:t.color||a.color},a.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),i&&Ae.createElement("title",null,i),t.children)};return Qt!==void 0?Ae.createElement(Qt.Consumer,null,a=>s(a)):s(Ps)}function Pn(t){return G({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 In(t){return G({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 nt(t){return G({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 ke(t){return G({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 G({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 Ln(t){return G({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 Ee(t){return G({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 Ke(t){return G({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 Zt(t){return G({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 Dn(t){return G({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 ot(t){return G({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 Bn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"line",attr:{x1:"4",y1:"21",x2:"4",y2:"14"},child:[]},{tag:"line",attr:{x1:"4",y1:"10",x2:"4",y2:"3"},child:[]},{tag:"line",attr:{x1:"12",y1:"21",x2:"12",y2:"12"},child:[]},{tag:"line",attr:{x1:"12",y1:"8",x2:"12",y2:"3"},child:[]},{tag:"line",attr:{x1:"20",y1:"21",x2:"20",y2:"16"},child:[]},{tag:"line",attr:{x1:"20",y1:"12",x2:"20",y2:"3"},child:[]},{tag:"line",attr:{x1:"1",y1:"14",x2:"7",y2:"14"},child:[]},{tag:"line",attr:{x1:"9",y1:"8",x2:"15",y2:"8"},child:[]},{tag:"line",attr:{x1:"17",y1:"16",x2:"23",y2:"16"},child:[]}]})(t)}function ct(t){return G({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 Ds(t){return G({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 dt(t){return G({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 Fn(t){return G({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 Bs(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"1 4 1 10 7 10"},child:[]},{tag:"path",attr:{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"},child:[]}]})(t)}function pt(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"23 4 23 10 17 10"},child:[]},{tag:"polyline",attr:{points:"1 20 1 14 7 14"},child:[]},{tag:"path",attr:{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"},child:[]}]})(t)}function Le(t){return G({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 vr(t){return G({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 An(t){return G({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 es(t){return G({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 $n(t){return G({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 _n(t){return G({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 Ue(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},child:[]}]})(t)}function On(t){return G({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 Wn(t){return G({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 Hn(t){return G({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 qn(t){return G({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 Ct(t){return G({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 ut(t){return G({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 Kn(t){return G({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 G({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 zn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},child:[]},{tag:"circle",attr:{cx:"8.5",cy:"8.5",r:"1.5"},child:[]},{tag:"polyline",attr:{points:"21 15 16 10 5 21"},child:[]}]})(t)}function Vn(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"3",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"14",y:"14",width:"7",height:"7"},child:[]},{tag:"rect",attr:{x:"3",y:"14",width:"7",height:"7"},child:[]}]})(t)}function Gn(t){return G({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 ts(t){return G({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 it(t){return G({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 ze(t){return G({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 Fs(t){return G({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 As(t){return G({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 St(t){return G({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 Tt(t){return G({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 Et(t){return G({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 Dt(t){return G({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 Xe(t){return G({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 Jn(t){return G({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 Bt(t){return G({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 Yn(t){return G({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 mt(t){return G({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 ht(t){return G({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 $e(t){return G({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 gt(t){return G({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 Qn(t){return G({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 ss(t){return G({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"},child:[]},{tag:"polyline",attr:{points:"3.27 6.96 12 12.01 20.73 6.96"},child:[]},{tag:"line",attr:{x1:"12",y1:"22.08",x2:"12",y2:"12"},child:[]}]})(t)}function Xn(t){return G({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 $s(t){return G({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 _s(t){return G({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 Zn(t){return G({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 ei(t){return G({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 De(){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)}`}function Ie({trigger:t,open:s,onOpenChange:a,children:l,align:c="right",fit:i=!1,direction:n="down",menuClassName:o,menuRef:u,menuStyle:p}){const h=r.useRef(null);return r.useEffect(()=>{if(!s)return;const g=b=>{h.current&&!h.current.contains(b.target)&&a(!1)},v=b=>{b.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",v)}},[s,a]),e.jsxs("div",{className:`dropdown ${c} ${i?"fit":""} ${n==="up"?"dd-up":""}`,ref:h,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>a(!s),"aria-expanded":s,children:[t,e.jsx($e,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:u,style:p,children:l})]})}function be({active:t,disabled:s=!1,title:a,onClick:l,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:a,onClick:l,children:c})}const Os="pi-web-ui:lang",ti={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:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",folderRef:"文件夹引用:{path}",refOnly:"仅引用:{path}",attachContent:"附加内容:{path}",attachLines:"附加选中行:{path}(第 {start}-{end} 行)",attachImage:"图片:{name}",attachFile:"文件:{name}",removeAttachment:"移除附件",attachHint:"将随下一条消息发送",uploadFile:"添加文件(图片/文本/任意文件,也可直接拖入或粘贴截图)",dropHereToAttach:"松开以添加文件",imageNotSupported:"当前模型不支持识图:图片将交给视觉桥转写(若未配置视觉模型则可能被忽略)",imageLoadFailed:"图片读取失败:{name}",fileLoadFailed:"文件读取失败:{name}",fileTooLarge:"文件过大已跳过(>{size}MB):{name}",foldersNotSupported:"不支持直接拖入文件夹,请展开后选择文件",placeholderStreaming:"智能体正在工作中…回车插队发送,或点「排队」等回答结束后发送",placeholderIdle:"给 pi 发送消息 — Enter 发送,/ 查看命令",placeholderConnecting:"正在连接服务器…",stopAgent:"停止智能体",stop:"停止",bgTasks:"后台任务",bgTasksTip:"AI 在后台启动的服务(npm run dev & 等)——可逐个停止或全部关闭,对话结束后仍保留",bgTasksEmpty:"暂无后台任务",bgTasksDesc:"AI 运行中启动并仍在监听的进程(按监听端口检测)",bgTaskPort:"端口",bgTaskPid:"PID",bgTaskSince:"启动",bgTaskStop:"停止",bgTaskStopAll:"全部关闭",bgTaskRefresh:"刷新",bgTaskJustNow:"刚刚",bgTaskMinutes:"{n} 分钟前",bgTaskHours:"{n} 小时前",bgTaskDays:"{n} 天前",stopBash:"停止",stopBashTip:"停止正在运行的 bash 命令(对话继续)",supplement:"排队",supplementTip:"加入队列:AI 回答完全结束后才发送(不打断)",queueSteerTag:"插队",queueFollowTag:"排队",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",recentProjects:"最近项目",runningConversations:"运行的对话",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",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 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:同时搜索历史对话、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索文件…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
|
|
3
3
|
|
|
4
4
|
1. 项目类型、技术栈与目录结构
|
|
5
5
|
2. 构建 / 测试 / 运行 / 格式化的具体命令
|
|
@@ -299,21 +299,22 @@ Keep going until the plan holds up.`,"tpl.sk.tdd":"Test-driven","tpl.sk.tdd.desc
|
|
|
299
299
|
2. Make them pass with the minimal implementation
|
|
300
300
|
3. Refactor while keeping tests green
|
|
301
301
|
|
|
302
|
-
Avoid three test anti-patterns: tests coupled to the implementation, tautological assertions (always true), and horizontal slicing (surface only). Report after each step and run the tests.`,error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"Run bash commands inside the persistent visible terminal: full output returned automatically, shell state retained across calls (cd/venv/ssh); silent commands move to the background and notify the AI when they finish",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"When a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",settingsPresets:"Presets",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},Ws=a.createContext(null);function ni(){try{const t=localStorage.getItem(Os);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ii({children:t}){const[s,i]=a.useState(ni),l=a.useCallback(n=>{i(n);try{localStorage.setItem(Os,n)}catch{}},[]),c=a.useCallback((n,o)=>{let u=si[n];if(s==="zh"&&(u=ti[n]),o)for(const[p,h]of Object.entries(o))u=u.replaceAll(`{${p}}`,String(h));return u},[s]);a.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const r=a.useMemo(()=>({locale:s,setLocale:l,t:c}),[s,l,c]);return e.jsx(Ws.Provider,{value:r,children:t})}function Ft(){const t=a.useContext(Ws);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function me(){return Ft().t}const ai=[{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 ns({settings:t,onChange:s,onPreview:i}){const l=me(),c=r=>s({...t,...r});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:l("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(Ls,{className:"sound-icon"}),e.jsx("span",{children:l("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:r=>c({enabled:r.target.checked})})]}),ai.map(({kind:r,labelKey:n,descKey:o})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:l(n)}),e.jsx("span",{className:"sound-desc",children:l(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:l("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),i(r)},children:l("preview")}),e.jsx("input",{type:"checkbox",checked:t[r],disabled:!t.enabled,onChange:u=>c({[r]:u.target.checked})})]})]},r)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:l("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:r=>c({volume:Number(r.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function ri({chat:t,send:s,terminal:i,view:l,plugins:c,onViewChange:r,onOpenPanel:n,onOpenSettings:o,onOpenBgTasks:u,onOpenGlobalSearch:p,sound:h,onSoundChange:g,onSoundPreview:v,themes:b,theme:k,onThemeChange:D}){var U;const{locale:E,setLocale:$,t:y}=Ft(),[j,R]=a.useState(!1),[L,M]=a.useState(!1),[C,m]=a.useState(!1),[B,W]=a.useState(!1),[ee,ne]=a.useState(!1),H=[{value:"zh",label:y("langZh")},{value:"en",label:y("langEn")}],K=t.ready?y("connected"):t.status==="closed"?y("reconnecting"):y("connecting"),I=t.ready?"ok":"busy",T=()=>{var X,te;if(!t.ready)return;const _=y("updateTabTitle"),z={name:_,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},N=t.terminals.find(ce=>ce.title===_);N?(i.restart(N.id),s({type:"run_command",terminalId:N.id,conversationId:N.conversationId,command:z,cols:80,rows:24})):i.create({id:De(),conversationId:t.activeConversationId||((X=t.state)==null?void 0:X.conversationId)||"",title:_,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:z}),W(!1),ne(!1),r("terminal")},S=()=>{var _,z;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:y("currentVersion")}),e.jsxs("b",{children:["v",((_=t.update)==null?void 0:_.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:y("latestVersion")}),e.jsx("b",{children:t.update===null?y("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:y("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:y("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:y("updateAvailable",{version:t.update.latest})}),((z=t.update)==null?void 0:z.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:y("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:y("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?y("checkingUpdate"):y("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:T,children:y("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:y("openHistory"),onClick:()=>n("left"),children:e.jsx(On,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${I}`,title:K}),e.jsx("span",{className:"conn-label",children:K})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":y("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="chat",className:l==="chat"?"active":"",onClick:()=>r("chat"),children:[e.jsx(Ue,{}),e.jsx("span",{children:y("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="terminal",className:l==="terminal"?"active":"",onClick:()=>r("terminal"),children:[e.jsx(Ke,{}),e.jsx("span",{children:y("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="git",className:l==="git"?"active":"",onClick:()=>r("git"),children:[e.jsx(it,{}),e.jsx("span",{children:y("scmTab")})]}),c.map(_=>{const z=_.error?`${_.name}: ${_.error}`:_.description?`${_.name} — ${_.description}`:_.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":l===`plugin:${_.id}`,className:`plugin-tab${l===`plugin:${_.id}`?" active":""}${_.error?" broken":""}`,title:z,onClick:()=>r(`plugin:${_.id}`),children:[_.icon?e.jsx("span",{"aria-hidden":!0,children:_.icon}):null,e.jsx("span",{children:_.name})]},_.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:y("searchGlobalTip"),onClick:p,children:[e.jsx(dt,{}),e.jsx("span",{className:"chip-sub",children:y("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":y("bgTasksTip"),onClick:u,children:[e.jsx(ut,{}),e.jsx("span",{className:"chip-sub",children:y("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:y("settingsTitle"),onClick:o,children:[e.jsx(ct,{}),e.jsx("span",{className:"chip-sub",children:y("settings")})]}),e.jsx(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Ls,{}),e.jsx("span",{className:"chip-sub",children:y("sound")})]}),open:j,onOpenChange:R,children:e.jsx(ns,{settings:h,onChange:g,onPreview:v})}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Gn,{}),e.jsx("span",{className:"chip-sub",children:E==="zh"?y("langZh"):"EN"})]}),open:L,onOpenChange:M,children:[e.jsx("div",{className:"dd-header",children:y("language")}),H.map(_=>e.jsx(be,{active:E===_.value,onClick:()=>{$(_.value),M(!1)},children:_.label},_.value))]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Dn,{}),e.jsx("span",{className:"chip-sub",children:y("theme")})]}),open:C,onOpenChange:m,children:[e.jsx("div",{className:"dd-header",children:y("theme")}),e.jsx(be,{active:k===null,onClick:()=>{D(null),m(!1)},children:y("themeDefault")}),b.map(_=>e.jsx(be,{active:k===_.id,onClick:()=>{D(_.id),m(!1)},children:_.name},_.id))]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Dt,{}),e.jsxs("span",{className:"chip-sub",children:["v",((U=t.update)==null?void 0:U.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:y("updateAvailable",{version:t.update.latest??""})})]}),open:B,onOpenChange:_=>{W(_),_&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:y("update")}),S()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:y("githubRepo"),children:e.jsx(ts,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":y("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(Le,{}),e.jsx("span",{children:y("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(An,{}),e.jsx("span",{className:"chip-sub",children:y("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:ee,onOpenChange:_=>{ne(_),_&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:y("sound")}),e.jsx("div",{className:"dd-header",children:y("settings")}),e.jsxs(be,{onClick:()=>{ne(!1),o()},children:[e.jsx(ct,{})," ",y("settingsTitle")]}),e.jsxs(be,{onClick:()=>{ne(!1),p()},children:[e.jsx(dt,{})," ",y("searchGlobal")]}),e.jsxs(be,{onClick:()=>{ne(!1),u()},children:[e.jsx(ut,{})," ",y("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(ns,{settings:h,onChange:g,onPreview:v}),e.jsx("div",{className:"dd-header",children:y("language")}),H.map(_=>e.jsx(be,{active:E===_.value,onClick:()=>$(_.value),children:_.label},_.value)),e.jsx("div",{className:"dd-header",children:y("theme")}),e.jsx(be,{active:k===null,onClick:()=>{D(null),ne(!1)},children:y("themeDefault")}),b.map(_=>e.jsx(be,{active:k===_.id,onClick:()=>{D(_.id),ne(!1)},children:_.name},_.id)),e.jsx("div",{className:"dd-header",children:y("update")}),S(),e.jsxs("a",{className:"dd-refresh dd-more-link",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",children:[e.jsx(ts,{})," ",y("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:y("openFiles"),onClick:()=>n("right"),children:e.jsx(ze,{})})]})]})}function is(t){const s=new Date(t),i=new Date;return s.toDateString()===i.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}function li(t,s){const i=new Map;for(const c of t){const r=i.get(c.cwd)??[];r.push(c),i.set(c.cwd,r)}const l=[...i.entries()].map(([c,r])=>({cwd:c,isCurrent:c===s,convs:r}));return l.sort((c,r)=>c.isCurrent?-1:r.isCurrent?1:c.cwd<r.cwd?-1:c.cwd>r.cwd?1:0),l}const oi=a.memo(function({ready:s,status:i,cwd:l,sessionFile:c,conversations:r,sessions:n,projects:o,activeConversationId:u,send:p,active:h}){const g=me(),v=c,b=l,[k,D]=a.useState(null);a.useEffect(()=>{!h||!s||i!=="open"||l&&(p({type:"list_sessions"}),p({type:"list_projects"}))},[h,s,i,l,p]);const E=j=>{const R=j.name||j.firstMessage.trim();return R.length>0?R:g("emptyChat")},$=j=>j.split(/[\\/]/).pop()||j,y=(j,R,L,M)=>{const C=k===j;return e.jsx("button",{type:"button",className:`lp-del ${C?"confirm":""}`,title:C?L:R,onClick:m=>{m.stopPropagation(),C?(D(null),M()):D(j)},children:C?e.jsx(gt,{}):e.jsx(Ee,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[o.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:g("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:o.map(j=>{const R=b===j.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(L=>L===`proj:${j.path}`?null:L),children:[e.jsxs("button",{type:"button",className:`project-item ${R?"active":""}`,title:j.path,onClick:()=>{R||p({type:"set_cwd",path:j.path})},children:[e.jsx(ze,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:$(j.path)}),e.jsx("span",{className:"project-path",children:j.path})]}),e.jsx("span",{className:"project-time",children:is(j.lastUsed)})]}),y(`proj:${j.path}`,g("deleteProject"),g("deleteProjectConfirm"),()=>p({type:"remove_project",path:j.path}))]},j.path)})})]}),r.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:g("runningConversations")}),li(r,l).map(j=>e.jsxs("div",{className:"panel-conv-group",children:[!j.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:j.cwd,children:$(j.cwd)}),j.convs.map(R=>{const L=u===R.id;return e.jsxs("button",{type:"button",className:`session-item ${L?"active":""}`,title:`${R.title}${j.isCurrent?"":` — ${j.cwd}`}`,onClick:()=>{L||p({type:"switch_conversation",id:R.id})},children:[e.jsx(Ue,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:R.title}),e.jsx("span",{className:"session-sub",children:L?g("current"):g("messageCount",{n:R.messageCount})})]}),R.isStreaming&&e.jsx("span",{className:"conv-streaming",title:g("streaming")})]},R.id)})]},j.cwd)),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(j=>{const R=v===j.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(L=>L===`sess:${j.path}`?null:L),children:[e.jsxs("button",{type:"button",className:`session-item ${R?"active":""}`,title:j.path,onClick:()=>{R||p({type:"switch_session",path:j.path})},children:[e.jsx(Ue,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:E(j)}),e.jsxs("span",{className:"session-sub",children:[R?g("current"):g("messageCount",{n:j.messageCount}),j.source==="tui"&&e.jsx("span",{className:"session-src",title:g("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:is(j.modified)})]}),y(`sess:${j.path}`,g("deleteSession"),g("deleteSessionConfirm"),()=>p({type:"delete_session",path:j.path}))]},j.path)})]})]})]})}),Hs="pi-web-ui:token";function ci(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Hs,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function di(){try{return localStorage.getItem(Hs)??""}catch{return""}}function ft(t){const s=di();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function ui(t,s){const i=s.assistantMessageEvent,l=t.stats.tokens,c=s.usage!==null?{...l,...s.usage}:l,r=c===l?t.stats:{...t.stats,tokens:c};if(i.type!=="text_delta"&&i.type!=="thinking_delta")return r===t.stats?t:{...t,stats:r};const n=i.delta??"";if(!n)return r===t.stats?t:{...t,stats:r};const o=t.streamingMessage??null,u=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},p=[...u.content],h=i.type==="thinking_delta"?"thinking":"text",g=i.contentIndex??p.length-1;return g>=0&&g<p.length&&p[g].type===h?p[g]=h==="thinking"?{type:"thinking",thinking:(p[g].thinking??"")+n}:{type:"text",text:(p[g].text??"")+n}:p.push(h==="thinking"?{type:"thinking",thinking:n}:{type:"text",text:n}),{...t,stats:r,streamingMessage:{...u,id:s.messageId,content:p}}}const Mt="pi-web-ui:plugin-data";function pi(t,s){window.dispatchEvent(new CustomEvent(Mt,{detail:{pluginId:t,payload:s}}))}function mi(t){const s=i=>{const l=i.detail;t(l.pluginId,l.payload)};return window.addEventListener(Mt,s),()=>window.removeEventListener(Mt,s)}const qe=new Map,Rt=new Set,We=new Set;let as=-1;function qs(){return[...qe.values()]}function hi(){const t=qs();for(const s of Rt)s(t)}function gi(t){return Rt.add(t),t(qs()),()=>Rt.delete(t)}async function fi(t,s){s!==as&&(as=s,qe.clear(),We.clear());const i=new Set(t.map(l=>l.id));for(const l of[...qe.keys()])i.has(l)||qe.delete(l);for(const l of[...We])i.has(l)||We.delete(l);await Promise.all(t.filter(l=>l.hasClient&&!l.error&&!qe.has(l.id)&&!We.has(l.id)).map(async l=>{try{const r=(await Rs(()=>import(`/plugins/${encodeURIComponent(l.id)}/client/entry.mjs?e=${s}`),[])).default;r&&typeof r.mount=="function"?qe.set(l.id,{info:l,module:r}):(We.add(l.id),console.error(`[plugin:${l.id}] entry.mjs 缺少 default.mount`))}catch(c){We.add(l.id),console.error(`[plugin:${l.id}] 客户端加载失败:`,c)}})),hi()}function xi(t,s){return{pluginId:t,send:i=>s({type:"plugin_message",pluginId:t,payload:i}),onData:i=>mi((l,c)=>{l===t&&i(c)})}}const vi=10,yt=2e5,yi=2e5,ki={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 bi(){const t=new Map,s=new Map,i=(l,c)=>`${l}:${c}`;return{write(l,c,r){const n=i(l,c),o=t.get(n);if(o&&o.size>0){for(const h of o)try{h.write(r)}catch{}return}const u=s.get(n)??"",p=u.length+r.length>yi?r:u+r;s.set(n,p)},register(l,c,r){const n=i(l,c);let o=t.get(n);o||(o=new Set,t.set(n,o)),o.add(r);const u=s.get(n);if(u){try{r.write(u)}catch{}s.delete(n)}return()=>{const p=t.get(n);p&&(p.delete(r),p.size===0&&t.delete(n)),s.delete(n)}},clear(){t.clear(),s.clear()}}}function rs(t,s){const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId),c.role==="bashExecution"&&i.add(`bash-${c.id}`);let l=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function ls(t,s){if(t.size===0)return t;const i=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&i.add(c.toolCallId);let l=!1;for(const c of t.keys())i.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function ji(t,s){var i,l,c,r;switch(s.type){case"status":return{...t,status:s.status,ready:s.status==="open"?t.ready:!1,terminals:s.status==="closed"?[]:t.terminals};case"ready":return{...t,serverVersion:s.serverVersion,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==vi};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:rs(t.liveOutputs,s.state),toolStatuses:ls(t.toolStatuses,s.state)};case"snapshot_delta":{const n=t.state,o=s.msg;if(!n||n.conversationId!==o.conversationId||n.rev!==o.baseRev)return t;const u={...n,...o.state,messages:o.appended.length>0?[...n.messages,...o.appended]:n.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:rs(t.liveOutputs,u),toolStatuses:ls(t.toolStatuses,u)}}case"tool_delta":{const n=t.liveOutputs.get(s.toolCallId),o=((n==null?void 0:n.text)??"")+s.delta,u=o.length>yt?`…[前 ${o.length-yt} 字符已省略]…
|
|
303
|
-
`+o.slice(o.length-yt):o,p=new Map(t.liveOutputs);return p.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:p}}case"message_delta":{const n=t.state;return!n||n.conversationId!==s.msg.conversationId?t:{...t,state:ui(n,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(n=>n.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(n=>n.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(i=t.state)!=null&&i.conversationId)&&s.conversationId!==(t.activeConversationId||((l=t.state)==null?void 0:l.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 o;return{...n,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};default:return t}}const os="pi-web-client-id";let kt=null;function $t(){if(kt)return kt;let t=null;try{t=sessionStorage.getItem(os),t||(t=De(),sessionStorage.setItem(os,t))}catch{t=t??De()}return kt=t,t}function wi(){const t=location.protocol==="https:"?"wss:":"ws:";return ft(`${t}//${location.host}/ws`)}function Ni(){const[t,s]=a.useReducer(ji,{status:"connecting",ready:!1,state:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:[],conversations:[],activeConversationId:"",projects:[],files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],installResult:null,pathCompletions:[],update:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:ki,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,protocolMismatch:!1}),i=a.useRef(null),l=a.useRef(bi()),c=a.useRef(0),r=a.useRef(null),n=a.useRef(!0),o=a.useRef(0),u=a.useRef(0),p=a.useRef(new Map),h=a.useRef(null),g=()=>{h.current||(h.current=setTimeout(()=>{h.current=null;const M=i.current;M&&M.readyState===WebSocket.OPEN&&M.send(JSON.stringify({type:"get_state"}))},300))},v=(M,C)=>{var W;const m=p.current,B=m.get(M);if(B!==void 0&&C!==B+1){const ee=L.current.chat,ne=ee.activeConversationId||((W=ee.state)==null?void 0:W.conversationId);M===ne&&g()}m.set(M,C)},b=a.useCallback((M,C)=>{const m=++u.current;s({type:"notice",notice:{id:m,level:M,text:C}})},[]),k=a.useCallback(M=>{const C=i.current;return C&&C.readyState===WebSocket.OPEN?(C.send(JSON.stringify(M)),!0):!1},[]),D=a.useCallback(()=>{if(!n.current)return;s({type:"status",status:"connecting"});const M=new WebSocket(wi());i.current=M,M.onopen=()=>{i.current===M&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),M.send(JSON.stringify({type:"hello",clientId:$t()})))},M.onmessage=C=>{if(i.current!==M)return;o.current=Date.now();let m;try{m=JSON.parse(C.data)}catch{return}switch(m.type){case"ready":s({type:"ready",serverVersion:m.serverVersion,protocolVersion:m.protocolVersion}),M.send(JSON.stringify({type:"get_state"})),M.send(JSON.stringify({type:"list_files"})),M.send(JSON.stringify({type:"list_models"})),M.send(JSON.stringify({type:"list_commands"})),M.send(JSON.stringify({type:"get_commands"})),M.send(JSON.stringify({type:"check_update"}));break;case"snapshot":p.current=new Map,s({type:"snapshot",state:m.state});break;case"snapshot_delta":{const B=L.current.chat.state;(!B||B.conversationId!==m.conversationId||B.rev!==m.baseRev)&&g(),s({type:"snapshot_delta",msg:m});break}case"tool_delta":v(m.conversationId,m.seq),s({type:"tool_delta",toolCallId:m.toolCallId,toolName:m.toolName,delta:m.delta});break;case"tool_status":s({type:"tool_status",status:m});break;case"message_delta":{v(m.conversationId,m.seq),s({type:"message_delta",msg:m});break}case"notice":{const B=++u.current;s({type:"notice",notice:{id:B,level:m.level,text:m.text}});break}case"sessions":s({type:"sessions",sessions:m.sessions});break;case"conversations":s({type:"conversations",conversations:m.conversations,activeId:m.activeId});break;case"projects":s({type:"projects",projects:m.projects});break;case"files":s({type:"files",files:m});break;case"file_changed":s({type:"file_changed",path:m.path});break;case"file_content":s({type:"file_content",content:m});break;case"models":s({type:"models",models:m.models,loading:!1});break;case"models_config":s({type:"models_config",providers:m.providers});break;case"providers_status":s({type:"providers_status",providers:m.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:m.reqId,ok:m.ok,models:m.models,error:m.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:m.reqId,ok:m.ok,added:m.added,total:m.total,error:m.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:m.reqId,ok:m.ok,config:m.config,error:m.error}});break;case"scm_data":s({type:"scm_data",data:m});break;case"search_files_result":s({type:"file_search_result",result:{reqId:m.reqId,ok:m.ok,results:m.results,truncated:m.truncated}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:m});break;case"path_completions":s({type:"path_completions",completions:m.completions});break;case"update_status":s({type:"update_status",status:m});break;case"widgets":s({type:"widgets",widgets:m.widgets});break;case"statuses":s({type:"statuses",statuses:m.statuses});break;case"dialog":s({type:"dialog",dialog:{id:m.id,kind:m.kind,title:m.title,args:m.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"terminal_output":l.current.write(m.conversationId??L.current.chat.activeConversationId,m.terminalId,m.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:m.conversationId,terminalId:m.terminalId,exitCode:m.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:m.conversationId,terminals:m.terminals});break;case"commands":s({type:"commands",commands:m.commands,path:m.path});break;case"slash_commands":s({type:"slash_commands",commands:m.commands});break;case"goal_status":s({type:"goal_status",status:m.status});break;case"settings_state":s({type:"settings",settings:m.settings});break;case"bg_servers":s({type:"bg_servers",servers:m.servers});break;case"plugins":s({type:"plugins",plugins:m.plugins,epoch:m.epoch});break;case"plugin_data":pi(m.pluginId,m.payload);break}},M.onclose=()=>{if(i.current===M&&(i.current=null),l.current.clear(),!n.current||i.current&&i.current!==M)return;s({type:"status",status:"closed"});const C=Math.min(1e3*2**c.current,1e4);c.current+=1,r.current=setTimeout(()=>{r.current=null,D()},C)},M.onerror=()=>{}},[]);a.useEffect(()=>{n.current=!0,D();const M=setInterval(()=>{if(!n.current)return;const C=i.current;C&&C.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&C.close()},5e3);return()=>{var C;n.current=!1,clearInterval(M),r.current&&(clearTimeout(r.current),r.current=null),(C=i.current)==null||C.close(),i.current=null}},[D]);const E=a.useCallback(M=>s({type:"dismiss_notice",id:M}),[]),$=a.useCallback(M=>s({type:"terminal_add",meta:M}),[]),y=a.useCallback(M=>s({type:"terminal_remove",id:M}),[]),j=a.useCallback(M=>s({type:"terminal_restart",terminalId:M}),[]),R=a.useCallback((M,C,m)=>l.current.register(M,C,m),[]),L=a.useRef({chat:t,send:k,pushNotice:b,dismissNotice:E,terminal:{create:$,close:y,register:R,restart:j}});return L.current={chat:t,send:k,pushNotice:b,dismissNotice:E,terminal:{create:$,close:y,register:R,restart:j}},L.current}const Ci=200*1024*1024,Si=/windows/i.test(navigator.userAgent),Ti=/[<>:"/\\|?*\u0000-\u001f]/g,Ei=/[. ]+$/,Mi=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Ri(t){const s=t.replace(Ti,"_").replace(Ei,"");return s?Mi.test(s)?`_${s}`:s:"_"}function cs(t,s=!0){const i=new URLSearchParams({clientId:$t(),path:t,...s?{download:"1"}:{}});return ft(`/api/file?${i}`)}async function Pi(t,s){const i=Si?Ri(s):s;try{const l=await fetch(cs(t));if(!l.ok)return{ok:!1,cancelled:!1,error:await l.text().catch(()=>"")||(l.status===404?"文件不存在":`HTTP ${l.status}`)};if(Number(l.headers.get("content-length")??"0")>Ci)return window.location.assign(cs(t)),{ok:!0};const r=await l.blob();return window.showSaveFilePicker&&window.isSecureContext?Ii(r,i):Pt(r,i)}catch(l){return{ok:!1,cancelled:!1,error:l instanceof Error?l.message:String(l)}}}async function Ii(t,s){let i;const l=window.showSaveFilePicker;if(!l)return Pt(t,s);try{i=await l({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:Pt(t,s)}try{const c=await i.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function Pt(t,s){const i=URL.createObjectURL(t),l=document.createElement("a");return l.href=i,l.download=s,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(i),1e4),{ok:!0}}const Li=a.memo(function({files:s,fileChanged:i,widgets:l,cwd:c,send:r,onAttach:n,onPreview:o,onNotice:u}){const p=me(),[h,g]=a.useState(""),[v,b]=a.useState(null),[k,D]=a.useState(!1),E=1e4,$=a.useRef(0),y=a.useRef(void 0),j=a.useCallback((C,m)=>{const B=++$.current;g(C),m!=null&&m.silent||D(!0),r({type:"list_files",path:C===""?void 0:C})||$.current===B&&D(!1)},[r]);a.useEffect(()=>{s&&s.path===h&&D(!1)},[s,h]),a.useEffect(()=>{if(c!==y.current){y.current=c,j("",{silent:!0});return}const C=setInterval(()=>{document.visibilityState!=="hidden"&&j(h,{silent:!0})},E);return()=>clearInterval(C)},[c,h,j]),a.useEffect(()=>{i&&i.path===h&&j(h,{silent:!0})},[i,h,j]);const R=C=>j(C),L=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&j(s.parent)},M=h.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 ${h===""?"active":""}`,onClick:()=>j(""),children:p("rootDir")}),M.map((C,m)=>{const B=M.slice(0,m+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(ht,{}),e.jsx("button",{type:"button",className:`crumb ${B===h?"active":""}`,onClick:()=>j(B),children:C})]},B)})]}),e.jsxs("div",{className:"panel-body",children:[k&&e.jsx("div",{className:"panel-empty",children:p("loading")}),!k&&s&&s.path===h&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:L,children:[e.jsx(ze,{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:()=>R(C.path),children:[e.jsx(ze,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:C.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":p("linkFolderTip"),onClick:()=>n(C.path,C.name,"reference",!0),children:e.jsx(Ct,{})})]},C.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${C.path} — ${p("previewFile")}`,onClick:()=>o(C.path,C.name),children:[e.jsx(Fs,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:C.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":p("downloadFile"),onClick:()=>{Pi(C.path,C.name).then(m=>{m.ok||m.cancelled||u("error",p("downloadFailed",{error:m.error}))})},children:e.jsx(Dt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":p("attachInlineTip"),onClick:()=>n(C.path,C.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":p("referenceTip"),onClick:()=>n(C.path,C.name,"reference"),children:e.jsx(Ct,{})})]},C.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:p("filesTruncated")})]}),!k&&!s&&e.jsx("div",{className:"panel-empty",children:p("noFiles")})]}),l.filter(C=>C.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:l.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:p("widgetExpand"),onClick:()=>b(C.key),children:[e.jsx("span",{children:C.key}),e.jsx(Hn,{})]}),e.jsx("pre",{className:"widget-lines",children:C.lines.join(`
|
|
302
|
+
Avoid three test anti-patterns: tests coupled to the implementation, tautological assertions (always true), and horizontal slicing (surface only). Report after each step and run the tests.`,error:"Error",done:"Done",running:"Running…",toolQueued:"Queued",copyArgs:"Copy args",errorOutput:"Error output",output:"Output",waitingOutput:"Waiting for output…",toolDoneWaitingModel:"Done · waiting on model",waitingModel:"Waiting for model response…",thinkingNow:"Thinking",thinkingPreview:"Thinking: {preview}",commands:"Commands",newCommand:"New command",newTerminal:"New terminal",name:"Name",command:"Command",cwdHint:"(${pwd} = current working directory)",noCommands:"No commands yet — click + to add one",clickToRun:"Click to run",edit:"Edit",delete:"Delete",confirmQ:"Confirm?",builtinTerminal:"Built-in terminal",termEmptySub:"Click a command on the left to run it, or + on the right for a new terminal",noTerminal:"No terminals",exited:"(exited{code})",closeTerminal:"Close terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git add -A && git commit -m "…" in the terminal (commits all changes incl. untracked)',scmCommitPlaceholder:"Type a commit message…",scmChanges:"Changes",scmHistory:"Commit tree",scmCommitDetail:"Commit details",scmSelectCommitHint:"Click a commit on the left to view its details",scmNoHistory:"No commits yet",scmNoChanges:"Working tree clean — no changes",scmNotGitRepo:"Current directory is not a Git repository",scmLoading:"Querying…",scmConnecting:"Waiting for connection…",scmDiff:"Diff",scmSelectFileHint:"Click a file on the left to view its diff",scmNoDiff:"(no diff)",scmStaged:"Staged",scmUnstaged:"Unstaged",scmStagedUnstaged:"Staged + unstaged",scmUntracked:"Untracked",scmUntrackedNote:"Untracked file — not shown in diff, included on commit",scmQueryFailed:"Git query failed: {error}",scmTooManyFailures:"Git queries keep failing — click refresh to retry",scmRunsInTerminal:"Commit / branch switch / push / pull run in the terminal",scmViewTerminal:"Open terminal",editProvider:"Edit provider",builtinProviders:"Built-in providers",hintKeyOnly:"Just enter an API key",configuredBadge:"✓ Configured",keyReady:"Key ready",replaceKey:"Replace key",replaceKeyTitle:"Replace the saved key",clearKey:"Clear",clearKeyTitle:"Remove this provider's key stored in auth.json; it returns to unconfigured (env-var sourced keys can't be cleared here)",clearKeyConfirm:"Clear the stored key for {id}? Its models will leave the list until you configure it again.",cloneProvider:"Clone as custom",cloning:"Cloning",cloneProviderTitle:"Copy this built-in provider (baseUrl + model catalog) into a custom provider — paste another API key to run both keys side by side",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",customProviders:"Custom providers",customDesc:"For Ollama / vLLM / OpenAI-compatible proxies, etc. Written to pi's models.json — hot-reloaded immediately.",noCustomProviders:"No custom providers yet",modelsCount:"{n} models",addProvider:"Add provider",providerId:"Provider ID",providerIdHint:"(required, e.g. ollama / my-proxy)",displayName:"Display name",displayNamePh:"My proxy",apiType:"API type",baseUrlHint:"(OpenAI-compatible endpoint)",apiKeyHint:"sk-… (optional — uses the auth.json key)",authHeader:"Auto-add Authorization header",modelsTitle:"Models",modelIdReq:"Model ID (required)",text:"Text",textImage:"Text+image",contextWindow:"Context",maxOutput:"Max output",removeModel:"Remove model",addModel:"Add model",deleteProviderConfirm:"Delete provider {id} and its {n} models?",fetchModels:"Fetch model list",fetchModelsHint:"Pull model IDs from the baseUrl /models endpoint (server-side, no CORS)",fetchingModels:"Fetching…",fetchModelsOk:"Fetched {n} models",fetchModelsEmpty:"The endpoint returned no models",fetchModelsErr:"Fetch failed: {msg}",fetchModelsNeedBaseUrl:"Enter a baseUrl first",goalBarTitle:"Goal",goalBarPlaceholder:"Set a goal; the agent's output is auto-reviewed…",goalBarSet:"Start",goalBarClear:"Cancel",goalBarLocked:"Locked: applies to every later turn",goalBarUnlocked:"This turn only (cleared afterwards)",goalBarReviewModel:"Review model",goalBarUseMainModel:"Use the main model",goalBarMaxRounds:"Max rounds",goalBarMaxRoundsTip:"Max review-revision rounds; 0 or empty = unlimited (keep revising until it passes)",goalBarUnlimitedShort:"Unlimited",goalBarReviewing:"Reviewing…",goalBarRound:"Round {n}",goalBarActive:"Goal active",goalBarPassed:"Passed",goalBarFailed:"Failed",goalBarStatusPending:"Waiting to generate…",goalWizardBtn:"AI Scrape",goalWizardTip:"Let AI refine the requirement into a goal via a Q&A survey",goalWizardRunning:"Scoping the goal",goalWizardAnswer:"Answer",goalWizardCard:"Goal survey",settings:"Settings",settingsTitle:"Settings",settingsDesc:"Changes apply immediately: system prompt, skill and extension toggles rebuild the current session; review instructions and review skills affect later goal reviews (main-session changes are deferred while streaming).",settingsSystemPrompt:"System prompt",settingsPromptMode:"Mode",promptModeAppend:"Append",promptModeReplace:"Replace",promptAppendHint:"Append mode: your text is appended to the end of the default system prompt (recommended — keeps the default behavior constraints).",promptReplaceHint:"Replace mode: your text fully replaces the system prompt (project context and skills are still appended automatically). After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",promptPlaceholder:"Type a custom system prompt… (applied on blur)",settingsViewPrompt:"View the current full prompt",settingsViewPromptHint:"The full system prompt actually in effect for this conversation (custom append/replace text, project context, skills and tool guidance). Read-only.",settingsViewPromptEmpty:"Session not ready yet — no system prompt available.",settingsSkills:"Skills",settingsReview:"Goal review",settingsReviewDesc:"Configure extra instructions and skills for the isolated goal-review session; the main session is unaffected.",settingsReviewSkills:"Skills available to review",reviewPromptPlaceholder:"Type custom review instructions… (applied on blur)",reviewPromptHint:"These instructions are added to the review task; pass/fail JSON output is still enforced. Skill toggles apply only to review.",settingsVisionBridge:"Vision bridge",settingsVisionBridgeDesc:"When the current model can't see images, send them to a configured vision model and transcribe into text evidence first",visionBridgeEnabled:"Enable vision bridge",visionBridgeModel:"Transcription model",visionBridgeAuto:"Auto (in order)",visionBridgeNoModels:"No configured vision model found: add any image-capable model (e.g. qwen-vl, GLM-4V, Gemini) in Model config to enable automatically",visionBridgeOffHint:"Disabled: images are sent as-is, a text-only model may not see them",visionBridgeCurrent:"Current transcription model: {model}",visionBridgePromptMode:"Transcription prompt",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"Run bash commands inside the persistent visible terminal: full output returned automatically, shell state retained across calls (cd/venv/ssh); silent commands move to the background and notify the AI when they finish",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"When a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",settingsPresets:"Presets",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},Ws=r.createContext(null);function ni(){try{const t=localStorage.getItem(Os);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ii({children:t}){const[s,a]=r.useState(ni),l=r.useCallback(n=>{a(n);try{localStorage.setItem(Os,n)}catch{}},[]),c=r.useCallback((n,o)=>{let u=si[n];if(s==="zh"&&(u=ti[n]),o)for(const[p,h]of Object.entries(o))u=u.replaceAll(`{${p}}`,String(h));return u},[s]);r.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en"},[s]);const i=r.useMemo(()=>({locale:s,setLocale:l,t:c}),[s,l,c]);return e.jsx(Ws.Provider,{value:i,children:t})}function Ft(){const t=r.useContext(Ws);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function me(){return Ft().t}const ai=[{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 ns({settings:t,onChange:s,onPreview:a}){const l=me(),c=i=>s({...t,...i});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:l("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(Ls,{className:"sound-icon"}),e.jsx("span",{children:l("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:i=>c({enabled:i.target.checked})})]}),ai.map(({kind:i,labelKey:n,descKey:o})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:l(n)}),e.jsx("span",{className:"sound-desc",children:l(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:l("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),a(i)},children:l("preview")}),e.jsx("input",{type:"checkbox",checked:t[i],disabled:!t.enabled,onChange:u=>c({[i]:u.target.checked})})]})]},i)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:l("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:i=>c({volume:Number(i.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}function ri({chat:t,send:s,terminal:a,view:l,plugins:c,onViewChange:i,onOpenPanel:n,onOpenSettings:o,onOpenBgTasks:u,onOpenGlobalSearch:p,sound:h,onSoundChange:g,onSoundPreview:v,themes:b,theme:k,onThemeChange:D}){var U;const{locale:E,setLocale:A,t:y}=Ft(),[j,R]=r.useState(!1),[L,M]=r.useState(!1),[C,m]=r.useState(!1),[B,W]=r.useState(!1),[ee,ne]=r.useState(!1),H=[{value:"zh",label:y("langZh")},{value:"en",label:y("langEn")}],K=t.ready?y("connected"):t.status==="closed"?y("reconnecting"):y("connecting"),I=t.ready?"ok":"busy",T=()=>{var X,te;if(!t.ready)return;const _=y("updateTabTitle"),z={name:_,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},N=t.terminals.find(ce=>ce.title===_);N?(a.restart(N.id),s({type:"run_command",terminalId:N.id,conversationId:N.conversationId,command:z,cols:80,rows:24})):a.create({id:De(),conversationId:t.activeConversationId||((X=t.state)==null?void 0:X.conversationId)||"",title:_,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:z}),W(!1),ne(!1),i("terminal")},S=()=>{var _,z;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:y("currentVersion")}),e.jsxs("b",{children:["v",((_=t.update)==null?void 0:_.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:y("latestVersion")}),e.jsx("b",{children:t.update===null?y("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:y("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:y("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:y("updateAvailable",{version:t.update.latest})}),((z=t.update)==null?void 0:z.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:y("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:y("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?y("checkingUpdate"):y("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:T,children:y("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:y("openHistory"),onClick:()=>n("left"),children:e.jsx(On,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${I}`,title:K}),e.jsx("span",{className:"conn-label",children:K})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":y("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="chat",className:l==="chat"?"active":"",onClick:()=>i("chat"),children:[e.jsx(Ue,{}),e.jsx("span",{children:y("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="terminal",className:l==="terminal"?"active":"",onClick:()=>i("terminal"),children:[e.jsx(Ke,{}),e.jsx("span",{children:y("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":l==="git",className:l==="git"?"active":"",onClick:()=>i("git"),children:[e.jsx(it,{}),e.jsx("span",{children:y("scmTab")})]}),c.map(_=>{const z=_.error?`${_.name}: ${_.error}`:_.description?`${_.name} — ${_.description}`:_.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":l===`plugin:${_.id}`,className:`plugin-tab${l===`plugin:${_.id}`?" active":""}${_.error?" broken":""}`,title:z,onClick:()=>i(`plugin:${_.id}`),children:[_.icon?e.jsx("span",{"aria-hidden":!0,children:_.icon}):null,e.jsx("span",{children:_.name})]},_.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:y("searchGlobalTip"),onClick:p,children:[e.jsx(dt,{}),e.jsx("span",{className:"chip-sub",children:y("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":y("bgTasksTip"),onClick:u,children:[e.jsx(ut,{}),e.jsx("span",{className:"chip-sub",children:y("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:y("settingsTitle"),onClick:o,children:[e.jsx(ct,{}),e.jsx("span",{className:"chip-sub",children:y("settings")})]}),e.jsx(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Ls,{}),e.jsx("span",{className:"chip-sub",children:y("sound")})]}),open:j,onOpenChange:R,children:e.jsx(ns,{settings:h,onChange:g,onPreview:v})}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Gn,{}),e.jsx("span",{className:"chip-sub",children:E==="zh"?y("langZh"):"EN"})]}),open:L,onOpenChange:M,children:[e.jsx("div",{className:"dd-header",children:y("language")}),H.map(_=>e.jsx(be,{active:E===_.value,onClick:()=>{A(_.value),M(!1)},children:_.label},_.value))]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Dn,{}),e.jsx("span",{className:"chip-sub",children:y("theme")})]}),open:C,onOpenChange:m,children:[e.jsx("div",{className:"dd-header",children:y("theme")}),e.jsx(be,{active:k===null,onClick:()=>{D(null),m(!1)},children:y("themeDefault")}),b.map(_=>e.jsx(be,{active:k===_.id,onClick:()=>{D(_.id),m(!1)},children:_.name},_.id))]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Dt,{}),e.jsxs("span",{className:"chip-sub",children:["v",((U=t.update)==null?void 0:U.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:y("updateAvailable",{version:t.update.latest??""})})]}),open:B,onOpenChange:_=>{W(_),_&&s({type:"check_update"})},fit:!0,children:[e.jsx("div",{className:"dd-header",children:y("update")}),S()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:y("githubRepo"),children:e.jsx(ts,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":y("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(Le,{}),e.jsx("span",{children:y("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx($n,{}),e.jsx("span",{className:"chip-sub",children:y("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:ee,onOpenChange:_=>{ne(_),_&&s({type:"check_update"})},children:[e.jsx("div",{className:"dd-header",children:y("sound")}),e.jsx("div",{className:"dd-header",children:y("settings")}),e.jsxs(be,{onClick:()=>{ne(!1),o()},children:[e.jsx(ct,{})," ",y("settingsTitle")]}),e.jsxs(be,{onClick:()=>{ne(!1),p()},children:[e.jsx(dt,{})," ",y("searchGlobal")]}),e.jsxs(be,{onClick:()=>{ne(!1),u()},children:[e.jsx(ut,{})," ",y("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx(ns,{settings:h,onChange:g,onPreview:v}),e.jsx("div",{className:"dd-header",children:y("language")}),H.map(_=>e.jsx(be,{active:E===_.value,onClick:()=>A(_.value),children:_.label},_.value)),e.jsx("div",{className:"dd-header",children:y("theme")}),e.jsx(be,{active:k===null,onClick:()=>{D(null),ne(!1)},children:y("themeDefault")}),b.map(_=>e.jsx(be,{active:k===_.id,onClick:()=>{D(_.id),ne(!1)},children:_.name},_.id)),e.jsx("div",{className:"dd-header",children:y("update")}),S(),e.jsxs("a",{className:"dd-refresh dd-more-link",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",children:[e.jsx(ts,{})," ",y("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:y("openFiles"),onClick:()=>n("right"),children:e.jsx(ze,{})})]})]})}function is(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()}`}function li(t,s){const a=new Map;for(const c of t){const i=a.get(c.cwd)??[];i.push(c),a.set(c.cwd,i)}const l=[...a.entries()].map(([c,i])=>({cwd:c,isCurrent:c===s,convs:i}));return l.sort((c,i)=>c.isCurrent?-1:i.isCurrent?1:c.cwd<i.cwd?-1:c.cwd>i.cwd?1:0),l}const oi=r.memo(function({ready:s,status:a,cwd:l,sessionFile:c,conversations:i,sessions:n,projects:o,activeConversationId:u,send:p,active:h}){const g=me(),v=c,b=l,[k,D]=r.useState(null);r.useEffect(()=>{!h||!s||a!=="open"||l&&(p({type:"list_sessions"}),p({type:"list_projects"}))},[h,s,a,l,p]);const E=j=>{const R=j.name||j.firstMessage.trim();return R.length>0?R:g("emptyChat")},A=j=>j.split(/[\\/]/).pop()||j,y=(j,R,L,M)=>{const C=k===j;return e.jsx("button",{type:"button",className:`lp-del ${C?"confirm":""}`,title:C?L:R,onClick:m=>{m.stopPropagation(),C?(D(null),M()):D(j)},children:C?e.jsx(gt,{}):e.jsx(Ee,{})})};return e.jsxs("aside",{className:"panel panel-left",children:[o.length>0&&e.jsxs("div",{className:"panel-projects",children:[e.jsx("div",{className:"panel-section-title",children:g("recentProjects")}),e.jsx("div",{className:"projects-scroll",children:o.map(j=>{const R=b===j.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(L=>L===`proj:${j.path}`?null:L),children:[e.jsxs("button",{type:"button",className:`project-item ${R?"active":""}`,title:j.path,onClick:()=>{R||p({type:"set_cwd",path:j.path})},children:[e.jsx(ze,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:A(j.path)}),e.jsx("span",{className:"project-path",children:j.path})]}),e.jsx("span",{className:"project-time",children:is(j.lastUsed)})]}),y(`proj:${j.path}`,g("deleteProject"),g("deleteProjectConfirm"),()=>p({type:"remove_project",path:j.path}))]},j.path)})})]}),i.length>0&&e.jsxs("div",{className:"panel-convs",children:[e.jsx("div",{className:"panel-section-title",children:g("runningConversations")}),li(i,l).map(j=>e.jsxs("div",{className:"panel-conv-group",children:[!j.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:j.cwd,children:A(j.cwd)}),j.convs.map(R=>{const L=u===R.id;return e.jsxs("button",{type:"button",className:`session-item ${L?"active":""}`,title:`${R.title}${j.isCurrent?"":` — ${j.cwd}`}`,onClick:()=>{L||p({type:"switch_conversation",id:R.id})},children:[e.jsx(Ue,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:R.title}),e.jsx("span",{className:"session-sub",children:L?g("current"):g("messageCount",{n:R.messageCount})})]}),R.isStreaming&&e.jsx("span",{className:"conv-streaming",title:g("streaming")})]},R.id)})]},j.cwd)),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(j=>{const R=v===j.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>D(L=>L===`sess:${j.path}`?null:L),children:[e.jsxs("button",{type:"button",className:`session-item ${R?"active":""}`,title:j.path,onClick:()=>{R||p({type:"switch_session",path:j.path})},children:[e.jsx(Ue,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[e.jsx("span",{className:"session-title",children:E(j)}),e.jsxs("span",{className:"session-sub",children:[R?g("current"):g("messageCount",{n:j.messageCount}),j.source==="tui"&&e.jsx("span",{className:"session-src",title:g("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:is(j.modified)})]}),y(`sess:${j.path}`,g("deleteSession"),g("deleteSessionConfirm"),()=>p({type:"delete_session",path:j.path}))]},j.path)})]})]})]})}),Hs="pi-web-ui:token";function ci(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Hs,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function di(){try{return localStorage.getItem(Hs)??""}catch{return""}}function ft(t){const s=di();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function ui(t,s){const a=s.assistantMessageEvent,l=t.stats.tokens,c=s.usage!==null?{...l,...s.usage}:l,i=c===l?t.stats:{...t.stats,tokens:c};if(a.type!=="text_delta"&&a.type!=="thinking_delta")return i===t.stats?t:{...t,stats:i};const n=a.delta??"";if(!n)return i===t.stats?t:{...t,stats:i};const o=t.streamingMessage??null,u=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},p=[...u.content],h=a.type==="thinking_delta"?"thinking":"text",g=a.contentIndex??p.length-1;return g>=0&&g<p.length&&p[g].type===h?p[g]=h==="thinking"?{type:"thinking",thinking:(p[g].thinking??"")+n}:{type:"text",text:(p[g].text??"")+n}:p.push(h==="thinking"?{type:"thinking",thinking:n}:{type:"text",text:n}),{...t,stats:i,streamingMessage:{...u,id:s.messageId,content:p}}}const Mt="pi-web-ui:plugin-data";function pi(t,s){window.dispatchEvent(new CustomEvent(Mt,{detail:{pluginId:t,payload:s}}))}function mi(t){const s=a=>{const l=a.detail;t(l.pluginId,l.payload)};return window.addEventListener(Mt,s),()=>window.removeEventListener(Mt,s)}const qe=new Map,Rt=new Set,We=new Set;let as=-1;function qs(){return[...qe.values()]}function hi(){const t=qs();for(const s of Rt)s(t)}function gi(t){return Rt.add(t),t(qs()),()=>Rt.delete(t)}async function fi(t,s){s!==as&&(as=s,qe.clear(),We.clear());const a=new Set(t.map(l=>l.id));for(const l of[...qe.keys()])a.has(l)||qe.delete(l);for(const l of[...We])a.has(l)||We.delete(l);await Promise.all(t.filter(l=>l.hasClient&&!l.error&&!qe.has(l.id)&&!We.has(l.id)).map(async l=>{try{const i=(await Rs(()=>import(`/plugins/${encodeURIComponent(l.id)}/client/entry.mjs?e=${s}`),[])).default;i&&typeof i.mount=="function"?qe.set(l.id,{info:l,module:i}):(We.add(l.id),console.error(`[plugin:${l.id}] entry.mjs 缺少 default.mount`))}catch(c){We.add(l.id),console.error(`[plugin:${l.id}] 客户端加载失败:`,c)}})),hi()}function xi(t,s){return{pluginId:t,send:a=>s({type:"plugin_message",pluginId:t,payload:a}),onData:a=>mi((l,c)=>{l===t&&a(c)})}}const vi=10,yt=2e5,yi=2e5,ki={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 bi(){const t=new Map,s=new Map,a=(l,c)=>`${l}:${c}`;return{write(l,c,i){const n=a(l,c),o=t.get(n);if(o&&o.size>0){for(const h of o)try{h.write(i)}catch{}return}const u=s.get(n)??"",p=u.length+i.length>yi?i:u+i;s.set(n,p)},register(l,c,i){const n=a(l,c);let o=t.get(n);o||(o=new Set,t.set(n,o)),o.add(i);const u=s.get(n);if(u){try{i.write(u)}catch{}s.delete(n)}return()=>{const p=t.get(n);p&&(p.delete(i),p.size===0&&t.delete(n)),s.delete(n)}},clear(){t.clear(),s.clear()}}}function rs(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 l=!1;for(const c of t.keys())a.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function ls(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 l=!1;for(const c of t.keys())a.has(c)&&(t.delete(c),l=!0);return l?new Map(t):t}function ji(t,s){var a,l,c,i;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!==vi};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:rs(t.liveOutputs,s.state),toolStatuses:ls(t.toolStatuses,s.state)};case"snapshot_delta":{const n=t.state,o=s.msg;if(!n||n.conversationId!==o.conversationId||n.rev!==o.baseRev)return t;const u={...n,...o.state,messages:o.appended.length>0?[...n.messages,...o.appended]:n.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:rs(t.liveOutputs,u),toolStatuses:ls(t.toolStatuses,u)}}case"tool_delta":{const n=t.liveOutputs.get(s.toolCallId),o=((n==null?void 0:n.text)??"")+s.delta,u=o.length>yt?`…[前 ${o.length-yt} 字符已省略]…
|
|
303
|
+
`+o.slice(o.length-yt):o,p=new Map(t.liveOutputs);return p.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:p}}case"message_delta":{const n=t.state;return!n||n.conversationId!==s.msg.conversationId?t:{...t,state:ui(n,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(n=>n.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};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||((l=t.state)==null?void 0:l.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||((i=t.state)==null?void 0:i.conversationId))?t:{...t,terminals:s.terminals.map(n=>{var o;return{...n,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};default:return t}}const os="pi-web-client-id";let kt=null;function At(){if(kt)return kt;let t=null;try{t=sessionStorage.getItem(os),t||(t=De(),sessionStorage.setItem(os,t))}catch{t=t??De()}return kt=t,t}function wi(){const t=location.protocol==="https:"?"wss:":"ws:";return ft(`${t}//${location.host}/ws`)}function Ni(){const[t,s]=r.useReducer(ji,{status:"connecting",ready:!1,state:null,liveOutputs:new Map,toolStatuses:new Map,notices:[],sessions:[],conversations:[],activeConversationId:"",projects:[],files:null,fileChanged:null,fileContent:null,models:[],modelsLoading:!1,modelsConfig:[],providers:[],installResult:null,pathCompletions:[],update:null,widgets:[],statuses:[],dialog:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],goal:ki,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,protocolMismatch:!1}),a=r.useRef(null),l=r.useRef(bi()),c=r.useRef(0),i=r.useRef(null),n=r.useRef(!0),o=r.useRef(0),u=r.useRef(0),p=r.useRef(new Map),h=r.useRef(null),g=()=>{h.current||(h.current=setTimeout(()=>{h.current=null;const M=a.current;M&&M.readyState===WebSocket.OPEN&&M.send(JSON.stringify({type:"get_state"}))},300))},v=(M,C)=>{var W;const m=p.current,B=m.get(M);if(B!==void 0&&C!==B+1){const ee=L.current.chat,ne=ee.activeConversationId||((W=ee.state)==null?void 0:W.conversationId);M===ne&&g()}m.set(M,C)},b=r.useCallback((M,C)=>{const m=++u.current;s({type:"notice",notice:{id:m,level:M,text:C}})},[]),k=r.useCallback(M=>{const C=a.current;return C&&C.readyState===WebSocket.OPEN?(C.send(JSON.stringify(M)),!0):!1},[]),D=r.useCallback(()=>{if(!n.current)return;s({type:"status",status:"connecting"});const M=new WebSocket(wi());a.current=M,M.onopen=()=>{a.current===M&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),M.send(JSON.stringify({type:"hello",clientId:At()})))},M.onmessage=C=>{if(a.current!==M)return;o.current=Date.now();let m;try{m=JSON.parse(C.data)}catch{return}switch(m.type){case"ready":s({type:"ready",serverVersion:m.serverVersion,protocolVersion:m.protocolVersion}),M.send(JSON.stringify({type:"get_state"})),M.send(JSON.stringify({type:"list_files"})),M.send(JSON.stringify({type:"list_models"})),M.send(JSON.stringify({type:"list_commands"})),M.send(JSON.stringify({type:"get_commands"})),M.send(JSON.stringify({type:"check_update"}));break;case"snapshot":p.current=new Map,s({type:"snapshot",state:m.state});break;case"snapshot_delta":{const B=L.current.chat.state;(!B||B.conversationId!==m.conversationId||B.rev!==m.baseRev)&&g(),s({type:"snapshot_delta",msg:m});break}case"tool_delta":v(m.conversationId,m.seq),s({type:"tool_delta",toolCallId:m.toolCallId,toolName:m.toolName,delta:m.delta});break;case"tool_status":s({type:"tool_status",status:m});break;case"message_delta":{v(m.conversationId,m.seq),s({type:"message_delta",msg:m});break}case"notice":{const B=++u.current;s({type:"notice",notice:{id:B,level:m.level,text:m.text}});break}case"sessions":s({type:"sessions",sessions:m.sessions});break;case"conversations":s({type:"conversations",conversations:m.conversations,activeId:m.activeId});break;case"projects":s({type:"projects",projects:m.projects});break;case"files":s({type:"files",files:m});break;case"file_changed":s({type:"file_changed",path:m.path});break;case"file_content":s({type:"file_content",content:m});break;case"models":s({type:"models",models:m.models,loading:!1});break;case"models_config":s({type:"models_config",providers:m.providers});break;case"providers_status":s({type:"providers_status",providers:m.providers});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:m.reqId,ok:m.ok,models:m.models,error:m.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:m.reqId,ok:m.ok,added:m.added,total:m.total,error:m.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:m.reqId,ok:m.ok,config:m.config,error:m.error}});break;case"scm_data":s({type:"scm_data",data:m});break;case"search_files_result":s({type:"file_search_result",result:{reqId:m.reqId,ok:m.ok,results:m.results,truncated:m.truncated}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:m});break;case"path_completions":s({type:"path_completions",completions:m.completions});break;case"update_status":s({type:"update_status",status:m});break;case"widgets":s({type:"widgets",widgets:m.widgets});break;case"statuses":s({type:"statuses",statuses:m.statuses});break;case"dialog":s({type:"dialog",dialog:{id:m.id,kind:m.kind,title:m.title,args:m.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"terminal_output":l.current.write(m.conversationId??L.current.chat.activeConversationId,m.terminalId,m.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:m.conversationId,terminalId:m.terminalId,exitCode:m.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:m.conversationId,terminals:m.terminals});break;case"commands":s({type:"commands",commands:m.commands,path:m.path});break;case"slash_commands":s({type:"slash_commands",commands:m.commands});break;case"goal_status":s({type:"goal_status",status:m.status});break;case"settings_state":s({type:"settings",settings:m.settings});break;case"bg_servers":s({type:"bg_servers",servers:m.servers});break;case"plugins":s({type:"plugins",plugins:m.plugins,epoch:m.epoch});break;case"plugin_data":pi(m.pluginId,m.payload);break}},M.onclose=()=>{if(a.current===M&&(a.current=null),l.current.clear(),!n.current||a.current&&a.current!==M)return;s({type:"status",status:"closed"});const C=Math.min(1e3*2**c.current,1e4);c.current+=1,i.current=setTimeout(()=>{i.current=null,D()},C)},M.onerror=()=>{}},[]);r.useEffect(()=>{n.current=!0,D();const M=setInterval(()=>{if(!n.current)return;const C=a.current;C&&C.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&C.close()},5e3);return()=>{var C;n.current=!1,clearInterval(M),i.current&&(clearTimeout(i.current),i.current=null),(C=a.current)==null||C.close(),a.current=null}},[D]);const E=r.useCallback(M=>s({type:"dismiss_notice",id:M}),[]),A=r.useCallback(M=>s({type:"terminal_add",meta:M}),[]),y=r.useCallback(M=>s({type:"terminal_remove",id:M}),[]),j=r.useCallback(M=>s({type:"terminal_restart",terminalId:M}),[]),R=r.useCallback((M,C,m)=>l.current.register(M,C,m),[]),L=r.useRef({chat:t,send:k,pushNotice:b,dismissNotice:E,terminal:{create:A,close:y,register:R,restart:j}});return L.current={chat:t,send:k,pushNotice:b,dismissNotice:E,terminal:{create:A,close:y,register:R,restart:j}},L.current}const Ci=200*1024*1024,Si=/windows/i.test(navigator.userAgent),Ti=/[<>:"/\\|?*\u0000-\u001f]/g,Ei=/[. ]+$/,Mi=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Ri(t){const s=t.replace(Ti,"_").replace(Ei,"");return s?Mi.test(s)?`_${s}`:s:"_"}function cs(t,s=!0){const a=new URLSearchParams({clientId:At(),path:t,...s?{download:"1"}:{}});return ft(`/api/file?${a}`)}async function Pi(t,s){const a=Si?Ri(s):s;try{const l=await fetch(cs(t));if(!l.ok)return{ok:!1,cancelled:!1,error:await l.text().catch(()=>"")||(l.status===404?"文件不存在":`HTTP ${l.status}`)};if(Number(l.headers.get("content-length")??"0")>Ci)return window.location.assign(cs(t)),{ok:!0};const i=await l.blob();return window.showSaveFilePicker&&window.isSecureContext?Ii(i,a):Pt(i,a)}catch(l){return{ok:!1,cancelled:!1,error:l instanceof Error?l.message:String(l)}}}async function Ii(t,s){let a;const l=window.showSaveFilePicker;if(!l)return Pt(t,s);try{a=await l({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:Pt(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 Pt(t,s){const a=URL.createObjectURL(t),l=document.createElement("a");return l.href=a,l.download=s,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(a),1e4),{ok:!0}}const Li=r.memo(function({files:s,fileChanged:a,widgets:l,cwd:c,send:i,onAttach:n,onPreview:o,onNotice:u}){const p=me(),[h,g]=r.useState(""),[v,b]=r.useState(null),[k,D]=r.useState(!1),E=1e4,A=r.useRef(0),y=r.useRef(void 0),j=r.useCallback((C,m)=>{const B=++A.current;g(C),m!=null&&m.silent||D(!0),i({type:"list_files",path:C===""?void 0:C})||A.current===B&&D(!1)},[i]);r.useEffect(()=>{s&&s.path===h&&D(!1)},[s,h]),r.useEffect(()=>{if(c!==y.current){y.current=c,j("",{silent:!0});return}const C=setInterval(()=>{document.visibilityState!=="hidden"&&j(h,{silent:!0})},E);return()=>clearInterval(C)},[c,h,j]),r.useEffect(()=>{a&&a.path===h&&j(h,{silent:!0})},[a,h,j]);const R=C=>j(C),L=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&j(s.parent)},M=h.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 ${h===""?"active":""}`,onClick:()=>j(""),children:p("rootDir")}),M.map((C,m)=>{const B=M.slice(0,m+1).join("/");return e.jsxs("span",{className:"crumb-seg",children:[e.jsx(ht,{}),e.jsx("button",{type:"button",className:`crumb ${B===h?"active":""}`,onClick:()=>j(B),children:C})]},B)})]}),e.jsxs("div",{className:"panel-body",children:[k&&e.jsx("div",{className:"panel-empty",children:p("loading")}),!k&&s&&s.path===h&&e.jsxs(e.Fragment,{children:[s.path!==""&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:L,children:[e.jsx(ze,{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:()=>R(C.path),children:[e.jsx(ze,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:C.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":p("linkFolderTip"),onClick:()=>n(C.path,C.name,"reference",!0),children:e.jsx(Ct,{})})]},C.path):e.jsxs("div",{className:"file-item file",children:[e.jsxs("button",{type:"button",className:"file-name",title:`${C.path} — ${p("previewFile")}`,onClick:()=>o(C.path,C.name),children:[e.jsx(Fs,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:C.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":p("downloadFile"),onClick:()=>{Pi(C.path,C.name).then(m=>{m.ok||m.cancelled||u("error",p("downloadFailed",{error:m.error}))})},children:e.jsx(Dt,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":p("attachInlineTip"),onClick:()=>n(C.path,C.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":p("referenceTip"),onClick:()=>n(C.path,C.name,"reference"),children:e.jsx(Ct,{})})]},C.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:p("filesTruncated")})]}),!k&&!s&&e.jsx("div",{className:"panel-empty",children:p("noFiles")})]}),l.filter(C=>C.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:l.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:p("widgetExpand"),onClick:()=>b(C.key),children:[e.jsx("span",{children:C.key}),e.jsx(Hn,{})]}),e.jsx("pre",{className:"widget-lines",children:C.lines.join(`
|
|
304
304
|
`)})]},C.key))}),v&&(()=>{const C=l.find(m=>m.key===v);return C?e.jsx("div",{className:"modal-backdrop",onClick:()=>b(null),children:e.jsxs("div",{className:"widget-expand",onClick:m=>m.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:p("close"),onClick:()=>b(null),children:e.jsx(ke,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:C.lines.join(`
|
|
305
|
-
`)})]})}):null})()]})});var ds=Ms();const Ks=
|
|
306
|
-
`)
|
|
307
|
-
`)
|
|
308
|
-
`)
|
|
309
|
-
`)
|
|
310
|
-
`),
|
|
311
|
-
`)
|
|
312
|
-
`)
|
|
313
|
-
`)
|
|
314
|
-
`),
|
|
315
|
-
`)
|
|
316
|
-
`)}function ha(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 ga(t,s){const i=s.trim().toLowerCase();if(!i)return 0;const l=t.toLowerCase();let c=0,r=l.indexOf(i);for(;r!==-1;)c++,r=l.indexOf(i,r+i.length);return c}function fa(t,s){const i=s.trim().toLowerCase();if(!i)return[];const l=[];for(const c of t){const r=ma(c);if(!r)continue;const n=ga(r,i);for(let o=0;o<n;o++)l.push({messageId:c.id,occurrence:o})}return l}function xa(t,s){var n;const i=new Map,l=[],c=s.toLowerCase();if(!c)return{byMsg:i,all:l};const r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(o){const u=o.parentElement;return!u||u.closest(".search-bar")?NodeFilter.FILTER_REJECT:(o.textContent??"").toLowerCase().includes(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let o=r.nextNode();o;o=r.nextNode()){const u=(o.textContent??"").toLowerCase(),p=(n=o.parentElement)==null?void 0:n.closest("[data-msg-id]");if(!p)continue;const h=p.getAttribute("data-msg-id")??"";let g=u.indexOf(c);for(;g!==-1;){const v=document.createRange();v.setStart(o,g),v.setEnd(o,g+c.length),l.push(v);const b=i.get(h);b?b.push(v):i.set(h,[v]),g=u.indexOf(c,g+c.length)}}return{byMsg:i,all:l}}function He(t,s){const i=CSS;if(!i.highlights)return;if(s.length===0){i.highlights.delete(t);return}const l=window.Highlight;l&&i.highlights.set(t,new l(...s))}function va({containerRef:t,messages:s,open:i,onClose:l,onEnsureExpanded:c}){const r=me(),n=a.useRef(null),[o,u]=a.useState(""),[p,h]=a.useState(0),g=a.useDeferredValue(o),v=i?g.trim():"",b=a.useMemo(()=>i?fa(s,v):[],[s,v,i]),k=a.useRef(b);k.current=b;const D=a.useRef(p);D.current=p,a.useEffect(()=>{i&&(h(0),requestAnimationFrame(()=>{var j;return(j=n.current)==null?void 0:j.select()}))},[i]),a.useEffect(()=>{if(!i)return;const j=R=>{R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),l())};return window.addEventListener("keydown",j,!0),()=>window.removeEventListener("keydown",j,!0)},[i,l]),a.useEffect(()=>(i||(He("msg-search",[]),He("msg-search-active",[])),()=>{He("msg-search",[]),He("msg-search-active",[])}),[i]);const E=a.useCallback(j=>{const R=t.current;if(!R)return;const L=R.querySelector(`[data-msg-id="${j}"]`);L&&(L.classList.remove("msg-flash"),L.offsetWidth,L.classList.add("msg-flash"))},[t]);a.useLayoutEffect(()=>{if(!i||!v)return;const j=t.current;if(!j)return;let R=!1,L=0;return L=requestAnimationFrame(()=>{var ee;if(R)return;const{byMsg:M,all:C}=xa(j,v);He("msg-search",C);const m=k.current,B=m[Math.min(D.current,m.length-1)];if(!B)return;const W=(ee=M.get(B.messageId))==null?void 0:ee[B.occurrence];if(W){He("msg-search-active",[W]);const ne=W.startContainer.parentElement??j.querySelector(`[data-msg-id="${B.messageId}"]`);ne==null||ne.scrollIntoView({block:"center"})}else E(B.messageId)}),()=>{R=!0,cancelAnimationFrame(L)}},[i,v,b,t,E]);const $=a.useCallback(j=>{const R=k.current;if(R.length===0)return;const L=(D.current+j+R.length)%R.length;h(L),c(R[L].messageId)},[c]);if(!i)return null;const y=b.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:n,className:"search-input",type:"text",value:o,placeholder:r("searchPlaceholder"),onChange:j=>{u(j.target.value),h(0)},onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),$(j.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${y===0?"empty":""}`,children:y===0?r("searchNoResults"):`${Math.min(p+1,y)}/${y}`}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchPrev"),disabled:y===0,onClick:()=>$(-1),children:e.jsx(mt,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchNext"),disabled:y===0,onClick:()=>$(1),children:e.jsx(Ae,{})}),e.jsx("button",{type:"button",className:"search-btn",title:r("searchClose"),onClick:l,children:e.jsx(ke,{})})]})}function ya(t){const{dSt:s,dSh:i,escaped:l,graceActive:c,stuck:r}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:i<0?{flipEscape:!1,reassert:r&&!l}:{flipEscape:!0,reassert:!1}}const tn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],sn="pi-web-ui:prompt-templates";function ka(){try{const t=localStorage.getItem(sn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(i=>!!i&&typeof i=="object"&&typeof i.id=="string"):[]}catch{return[]}}function xs(t){return tn.some(s=>s.id===t)}function tt(t){return typeof t.title=="string"}const nn=a.createContext(null);function an(){const t=a.useContext(nn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function ba({send:t,children:s}){const i=me(),[l,c]=a.useState(ka),[r,n]=a.useState(!1),[o,u]=a.useState(null),[p,h]=a.useState(!1),[g,v]=a.useState(!1),[b,k]=a.useState(!1);a.useEffect(()=>{try{localStorage.setItem(sn,JSON.stringify(l))}catch{}},[l]);const D=a.useMemo(()=>{const H=new Map,K=new Set;for(const S of l)S.hidden?K.add(S.id):(tt(S)&&!xs(S.id)||tt(S))&&H.set(S.id,S);const I=tn.filter(S=>!K.has(S.id)).map(S=>{const U=H.get(S.id);return{id:S.id,icon:(U==null?void 0:U.icon)??S.icon,title:(U==null?void 0:U.title)??i(S.titleKey),desc:(U==null?void 0:U.desc)??i(S.descKey),prompt:(U==null?void 0:U.prompt)??i(S.promptKey),builtin:!0}}),T=l.filter(S=>tt(S)&&!xs(S.id)).map(S=>({id:S.id,icon:S.icon??"📌",title:S.title??"",desc:S.desc??"",prompt:S.prompt??""}));return[...I,...T]},[l,i]),E=a.useCallback(()=>n(!0),[]),$=a.useCallback(H=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:H}))},[]),y=a.useCallback((H,K=!1)=>{k(K),H?(h(!1),u({...H})):(h(!0),u({id:De(),icon:"📌",title:"",desc:"",prompt:""}))},[]),j=a.useCallback(()=>{n(!1),u(null),k(!1)},[]),R=a.useCallback(()=>{g?(c([]),v(!1)):(v(!0),setTimeout(()=>v(!1),5e3))},[g]),L=a.useCallback(H=>{n(!1),$(H.prompt)},[$]),M=a.useCallback(H=>{n(!1),y(H,!0)},[y]),C=a.useCallback(()=>{n(!1),y(void 0,!0)},[y]),m=a.useCallback(H=>{c(K=>{const I=K.findIndex(T=>T.id===H.id);if(I>=0){const T=[...K];return T[I]=H,T}return[...K,H]}),u(null),b&&(n(!0),k(!1))},[b]),B=a.useCallback(H=>{c(K=>H.builtin?[...K.filter(T=>T.id!==H.id),{id:H.id,hidden:!0}]:K.filter(I=>I.id!==H.id)),u(null),b&&(n(!0),k(!1))},[b]),W=a.useCallback(H=>{c(K=>K.filter(I=>I.id!==H.id||I.hidden)),u(null),b&&(n(!0),k(!1))},[b]),ee=a.useMemo(()=>({templates:D,fill:$,openPicker:E,openEdit:y,resetConfirm:g,toggleReset:R}),[D,$,E,y,g,R]),ne=o?l.some(H=>H.id===o.id&&!H.hidden&&tt(H)):!1;return e.jsxs(nn.Provider,{value:ee,children:[s,r&&e.jsx(wa,{templates:D,resetConfirm:g,onFill:L,onEditTpl:M,onNew:C,onResetToggle:R,onClose:j}),o&&e.jsx(Na,{editing:o,isNew:p,hasOverride:ne,onDraft:u,onSave:m,onRestore:()=>W(o),onRemove:()=>B(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),j()},onSend:()=>{const H=o.prompt.trim();H&&t({type:"prompt",text:H,queue:!1})&&j()},onClose:j})]})}function ja(){const t=me(),{templates:s,fill:i,openEdit:l,toggleReset:c,resetConfirm:r}=an();return e.jsxs("div",{className:"empty-templates",children:[e.jsxs("div",{className:"empty-templates-head",children:[e.jsx("span",{className:"empty-templates-title",children:t("tpl.title")}),e.jsx("span",{className:"empty-templates-hint",children:t("tpl.hint")})]}),e.jsxs("div",{className:"empty-templates-grid",children:[s.map(n=>e.jsx(rn,{tpl:n,title:t("tpl.clickCard"),onFill:()=>i(n.prompt),onEdit:()=>l(n),editTitle:t("tpl.editTpl")},n.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>l(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Le,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(Bs,{}),t(r?"tpl.resetConfirm":"tpl.reset")]})})]})}function rn({tpl:t,title:s,onFill:i,onEdit:l,editTitle:c}){const r=me();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:i,children:[e.jsx("span",{className:"empty-template-icon",children:t.icon}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t.title}),e.jsx("span",{className:"empty-template-desc",children:t.desc})]}),e.jsx("span",{className:"template-card-ops",role:"button",title:c??r("tpl.editTpl"),onClick:n=>{n.stopPropagation(),l()},children:e.jsx(Et,{})})]})}function wa({templates:t,resetConfirm:s,onFill:i,onEditTpl:l,onNew:c,onResetToggle:r,onClose:n}){const o=me();return a.useEffect(()=>{const u=p=>{p.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal template-picker",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"template-picker-head",children:[e.jsx("span",{className:"template-picker-title",children:o("tpl.pickerTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:o("close"),onClick:n,children:e.jsx(ke,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(u=>e.jsx(rn,{tpl:u,title:o("tpl.clickCard"),onFill:()=>i(u),onEdit:()=>l(u),editTitle:o("tpl.editTpl")},u.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:c,title:o("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Le,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:r,children:[e.jsx(Bs,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Na({editing:t,isNew:s,hasOverride:i,onDraft:l,onSave:c,onRestore:r,onRemove:n,onFill:o,onSend:u,onClose:p}){const h=me(),g=a.useRef(null);a.useEffect(()=>{const k=D=>{D.key==="Escape"&&p()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[p]),a.useEffect(()=>{const k=g.current;if(!k)return;k.style.height="auto";const D=k.scrollHeight>300;k.style.height=`${Math.min(k.scrollHeight,300)}px`,k.style.overflowY=D?"auto":"hidden"},[t.prompt]);const v=()=>{const k=t.title.trim(),D=t.prompt.trim();if(!k||!D){l({...t,error:h("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:k,desc:t.desc.trim(),prompt:D})},b=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:p,children:e.jsxs("div",{className:"modal template-modal",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"template-modal-head",children:[e.jsx("span",{className:"template-modal-icon",children:t.icon}),e.jsx("span",{className:"template-modal-badge",children:h(b?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:h(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:h("close"),onClick:p,children:e.jsx(ke,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:k=>l({...t,icon:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:h("tpl.fieldTitlePh"),onChange:k=>l({...t,title:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:h("tpl.fieldDescPh"),onChange:k=>l({...t,desc:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldPrompt")}),e.jsx("textarea",{ref:g,className:"template-field-prompt",value:t.prompt,placeholder:h("tpl.fieldPromptPh"),onChange:k=>l({...t,prompt:k.target.value})})]}),t.error&&e.jsx("div",{className:"template-error",children:t.error}),e.jsxs("div",{className:"template-modal-actions",children:[e.jsxs("div",{className:"template-modal-actions-left",children:[!s&&b&&i&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:h("tpl.restoreTip"),onClick:r,children:h("tpl.restore")}),!s&&b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:h("tpl.removeTip"),onClick:n,children:[e.jsx(Ee,{})," ",h("tpl.remove")]}),!s&&!b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:h("tpl.deleteTip"),onClick:n,children:[e.jsx(Ee,{})," ",h("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:v,children:h("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:h("tpl.fillTip"),children:h("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:u,title:h("tpl.sendTip"),children:[e.jsx(Ds,{})," ",h("tpl.sendNow")]})]})]})]})})}const vs=new Map,Ca=15,ys=30,jt=250,ks=1200,Sa=1600;function bs(t){return t.content.some(s=>s.type==="toolCall")}function Ta({state:t,liveOutputs:s,toolStatuses:i,onEdit:l,onKillBash:c,thinkingWrap:r,toolsWrap:n}){const o=me(),u=a.useRef(null),[p,h]=a.useState(!0),g=a.useRef(!0),v=a.useRef(0),b=a.useRef(0),k=a.useRef(!1),D=a.useRef(0),[E,$]=a.useState(()=>new Set),[y,j]=a.useState(!1),R=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,L=a.useMemo(()=>{const f=new Map;for(const x of t.messages)x.role==="toolResult"&&x.toolCallId&&f.set(x.toolCallId,x);return f},[t.messages]),M=a.useMemo(()=>na(t.messages),[t.messages]),C=R.length>0?R[R.length-1].id:null,m=t.messages.length>ys?Math.max(0,t.messages.length-Ca):0,[B,W]=a.useState(()=>new Set),[ee,ne]=a.useState(()=>new Set),H=a.useRef(new Map),K=a.useRef(new Map),I=a.useRef(new Map),T=a.useRef(0),S=a.useMemo(()=>{const f=new Map;for(const x of t.messages)f.set(x.id,ua(x));return f},[t.messages]),U=a.useRef(S);U.current=S;const _=a.useRef(B);_.current=B;const z=t.messages.length>ys&&!y,N=a.useRef(z);N.current=z;const X=ca(t.messages,H.current,Sa),te=a.useRef(X);te.current=X;const ce=a.useCallback(()=>{const f=u.current;if(!f)return;if(!N.current){W(de=>de.size?new Set:de);return}const x=f.getBoundingClientRect(),V={top:x.top-ks,bottom:x.bottom+ks},O=[];for(const[de,ye]of I.current){const Se=ye.getBoundingClientRect();O.push({id:de,top:Se.top,bottom:Se.bottom}),_.current.has(de)||oe(de,Se.bottom-Se.top,U.current.get(de))}const ie=la(O,V,te.current,_.current);for(const de of ie.hide){const ye=I.current.get(de);ye&&oe(de,ye.offsetHeight,U.current.get(de))}W(de=>oa(de,ie))},[]),A=a.useCallback(()=>{T.current||(T.current=requestAnimationFrame(()=>{T.current=0,ce()}))},[ce]);a.useLayoutEffect(()=>{ce()},[ce]);const Y=a.useRef(y);a.useLayoutEffect(()=>{Y.current&&!y&&ce(),Y.current=y},[y,ce]);const oe=a.useCallback((f,x,V)=>{V!==void 0&&(K.current.set(f,{h:x,len:V}),H.current.set(f,x))},[]),Q=a.useCallback((f,x)=>{oe(f,x,U.current.get(f))},[oe]),ue=a.useCallback(f=>{f&&I.current.set(f.dataset.lazyId??"",f)},[]);a.useEffect(()=>{const f=new Set(t.messages.map(x=>x.id));for(const[x,V]of I.current)f.has(x)||(I.current.delete(x),H.current.delete(x),K.current.delete(x));W(x=>{let V=!1;const O=new Set;for(const ie of x)f.has(ie)?O.add(ie):V=!0;return V?O:x})},[t.messages,E]),a.useEffect(()=>()=>cancelAnimationFrame(T.current),[]);const Z=a.useMemo(()=>{const f=[];for(const x of t.messages){if(x.role!=="user")continue;const V=x.content.map(de=>{var ye;return((ye=Ze(de))==null?void 0:ye.text)??""}).filter(Boolean).join(" "),O=At(V),ie=O?O.userMessage??`skill:${O.name}`:V.trim();ie&&f.push({id:x.id,text:ie})}return f},[t.messages]),d=a.useMemo(()=>{const f=new Map;return Z.forEach((x,V)=>f.set(x.id,V)),f},[Z]),[P,le]=a.useState(-1),se=a.useRef(-1),he=a.useRef(Z);a.useEffect(()=>{he.current=Z},[Z]);const J=a.useCallback(()=>{const f=u.current,x=he.current;if(!f||x.length===0)return;const V=f.getBoundingClientRect().top,O=140;let ie=-1;for(let de=0;de<x.length;de++){const ye=f.querySelector(`[data-msg-id="${x[de].id}"]`);if(ye)if(ye.getBoundingClientRect().top<=V+O)ie=de;else break}ie!==se.current&&(se.current=ie,le(ie))},[]);a.useEffect(()=>{J()},[Z,J]);const re=a.useCallback(f=>{$(x=>x.has(f)?x:new Set(x).add(f))},[]),ge=a.useCallback(f=>{const x=t.messages.findIndex(V=>V.id===f);x>=0&&x<m&&!E.has(f)&&ds.flushSync(()=>re(f))},[t.messages,m,E,re]);a.useEffect(()=>{const f=x=>{if(!(x.ctrlKey||x.metaKey)||x.key.toLowerCase()!=="f")return;const V=x.target;V&&(V.tagName==="INPUT"||V.tagName==="TEXTAREA"||V.isContentEditable)||(x.preventDefault(),j(!0))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]);const pe=a.useCallback(f=>{$(x=>{if(!x.has(f))return x;const V=new Set(x);return V.delete(f),V})},[]),we=a.useCallback(f=>{const x=t.messages.findIndex(O=>O.id===f);ds.flushSync(()=>{x>=0&&x<m&&!E.has(f)&&re(f),ne(O=>O.has(f)?O:new Set(O).add(f))});const V=he.current.findIndex(O=>O.id===f);se.current=V,le(V),requestAnimationFrame(()=>{var ie,de,ye;const O=(ie=u.current)==null?void 0:ie.querySelector(`[data-msg-id="${f}"]`);O&&((de=u.current)==null||de.querySelectorAll(".msg-flash").forEach(Se=>Se.classList.remove("msg-flash")),O.scrollIntoView({block:"start"}),O.classList.remove("msg-flash"),O.offsetWidth,O.classList.add("msg-flash"),O!==((ye=u.current)==null?void 0:ye.lastElementChild)&&(k.current=!0))})},[t.messages,m,E,re]),Be=a.useCallback(()=>{const f=u.current;if(!f)return;const x=f.scrollTop-v.current,V=f.scrollHeight-b.current;v.current=f.scrollTop,b.current=f.scrollHeight;const O=f.scrollHeight-f.scrollTop-f.clientHeight<80,ie=Date.now()<D.current,de=ya({dSt:x,dSh:V,escaped:k.current,graceActive:ie,stuck:g.current});de.reassert&&(D.current=Date.now()+jt,f.scrollTop=f.scrollHeight),de.flipEscape&&(k.current=!0),O&&x>=0&&(k.current=!1),ie||(x<0?g.current=O&&!k.current:O&&(g.current=!0)),h(g.current),J(),A()},[J,A]),_e=a.useRef(!1);a.useEffect(()=>{const f=_e.current;if(_e.current=!!t.isStreaming,f&&!t.isStreaming&&!k.current){const x=()=>{const O=u.current;O&&!k.current&&(O.scrollTop=O.scrollHeight,g.current=!0,h(!0))};requestAnimationFrame(()=>requestAnimationFrame(x));const V=setTimeout(x,180);return()=>clearTimeout(V)}},[t.isStreaming]),a.useEffect(()=>{const f=u.current;f&&g.current&&(f.scrollTop=f.scrollHeight)},[R,t.isStreaming,s]);const Ve=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");a.useEffect(()=>{const f=u.current;f&&g.current&&(f.scrollTop=f.scrollHeight)},[Ve]),a.useEffect(()=>{const f=u.current;if(!f||typeof ResizeObserver>"u")return;const x=new ResizeObserver(()=>{g.current&&!k.current&&(f.scrollTop=f.scrollHeight,h(!0))});return x.observe(f),()=>x.disconnect()},[]),a.useEffect(()=>{const f=u.current;if(!f||typeof MutationObserver>"u")return;let x=!1;const V=new MutationObserver(()=>{x||(x=!0,requestAnimationFrame(()=>{x=!1;const O=u.current;O&&g.current&&!k.current&&(O.scrollTop=O.scrollHeight,h(!0))}))});return V.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>V.disconnect()},[]);const Ge=a.useCallback(()=>{if(!u.current)return;g.current=!0,k.current=!1,h(!0),D.current=Date.now()+jt;const x=()=>{const V=u.current;!V||!g.current||k.current||(D.current=Date.now()+jt,V.scrollTop=V.scrollHeight)};x(),requestAnimationFrame(()=>requestAnimationFrame(x)),setTimeout(x,120),setTimeout(x,300),setTimeout(x,600)},[]),Ce=a.useRef(null);a.useEffect(()=>{const f=Ce.current,x=u.current;if(!f||!x)return;const V=O=>{O.preventDefault();const ie=f.querySelector(".qn-list");if(ie&&ie.contains(O.target)&&ie.scrollHeight>ie.clientHeight){ie.scrollTop+=O.deltaY;return}x.scrollTop+=O.deltaY};return f.addEventListener("wheel",V,{passive:!1}),()=>f.removeEventListener("wheel",V)},[]);const[Oe,Fe]=a.useState(0);a.useEffect(()=>{const f=()=>{var x;Fe(((x=u.current)==null?void 0:x.clientHeight)??0),A()};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[A]);const Ne=Z.length,Re=a.useMemo(()=>Ne===0?27:Math.max(4,Math.min(27,Math.floor(((Oe||600)-16)/Ne)-3)),[Ne,Oe]),w=Re<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${p?"":" anchor-live"}`,ref:u,onScroll:Be,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(ja,{})}),t.messages.map((f,x)=>{const V=x<m,O=V&&E.has(f.id);if(V&&!O)return f.role==="toolResult"?null:e.jsx(ia,{message:f,onExpand:re},f.id);const ie=f.role==="user"?d.get(f.id):void 0,de=!z||X.has(f.id)||ee.has(f.id)||!B.has(f.id);return e.jsx(ra,{id:f.id,show:de,height:pa(f.id,S.get(f.id)??-1,K.current,en(f.role,f.customType)),containerRef:u,onMeasured:Q,lazyRef:ue,children:e.jsx(ms,{message:f,qnIndex:ie,qnActive:ie!==void 0?ie===P:void 0,onJump:we,toolResults:L,liveOutputs:bs(f)?s:vs,toolStatuses:i,streaming:t.isStreaming,onKillBash:c,toolsWrap:n,thinkingWrap:r,isLast:f.id===C,onEdit:l,questionAttachments:M.get(f.id),onCollapse:O?pe:void 0},f.id)},f.id)}),t.streamingMessage&&e.jsx(ms,{message:t.streamingMessage,toolResults:L,liveOutputs:bs(t.streamingMessage)?s:vs,toolStatuses:i,streaming:!0,isLast:!0,onEdit:l,onKillBash:c,toolsWrap:n,thinkingWrap:r},t.streamingMessage.id),t.isStreaming&&R.length===0&&e.jsx("div",{className:"streaming-wait",children:o("waitingResponse")}),t.queue.steering.map((f,x)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:o("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:f})]})},`q-steer-${x}`)),t.queue.followUp.map((f,x)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:o("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:f})]})},`q-fu-${x}`))]}),!p&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Ge,children:[e.jsx(_s,{})," ",o("backToBottom")]}),e.jsx(va,{containerRef:u,messages:R,open:y,onClose:()=>j(!1),onEnsureExpanded:ge}),Z.length>0&&e.jsxs("div",{className:`qn-rail ${w?"many":""}`,ref:Ce,"aria-label":o("questionNavTitle"),style:{"--rail-gap":`${Re}px`},children:[Z.map((f,x)=>e.jsx("button",{type:"button",className:`qn-bar ${x===P?"active":""}`,"aria-label":`${x+1}. ${f.text}`,onClick:()=>we(f.id),children:e.jsxs("span",{className:"qn-bar-text",children:[x+1,". ",f.text]})},f.id)),w&&e.jsx("div",{className:"qn-list",children:Z.map((f,x)=>e.jsxs("button",{type:"button",className:`qn-list-item ${x===P?"active":""}`,"aria-label":`${x+1}. ${f.text}`,onClick:()=>we(f.id),children:[e.jsx("span",{className:"qn-list-idx",children:x+1}),e.jsx("span",{className:"qn-list-text",children:f.text})]},f.id))})]})]})}const ln="pi-web-model-usage";function Ea(t){if(!t||typeof t!="object")return{};const s={};for(const[i,l]of Object.entries(t)){const c=typeof l=="number"?Math.floor(l):0;Number.isFinite(c)&&c>0&&(s[i]=c)}return s}function Ma(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function Ra(t,s){const i=s;return t.map((l,c)=>({m:l,i:c,count:i[l.id]??0})).sort((l,c)=>c.count-l.count||l.i-c.i).map(l=>l.m)}function on(){try{const t=localStorage.getItem(ln);return t?Ea(JSON.parse(t)):{}}catch{return{}}}function Pa(t){try{localStorage.setItem(ln,JSON.stringify(t))}catch{}}function Ia(t){const s=Ma(on(),t);return Pa(s),s}const La=["off","minimal","low","medium","high","xhigh","max"],Da=a.memo(function({state:s,models:i,modelsLoading:l,send:c,onManageModels:r,compact:n=!1}){const o=me(),u=s==null?void 0:s.model,p=u?`${u.provider}/${u.id}`:null,[h,g]=a.useState(!1),[v,b]=a.useState(!1),[k,D]=a.useState(""),[E,$]=a.useState(null),[y,j]=a.useState({}),R=a.useRef(null),L=a.useRef(null),[M,C]=a.useState(null);a.useEffect(()=>{if(!h){C(null);return}if(i.length===0)return;const T=requestAnimationFrame(()=>{const S=L.current;S&&C(S.offsetWidth)});return()=>cancelAnimationFrame(T)},[h,i.length]),a.useEffect(()=>{h&&j(on())},[h]),a.useEffect(()=>{h||(D(""),$(null))},[h]);const m=a.useMemo(()=>{const T=new Map;for(const S of i)T.set(S.provider,(T.get(S.provider)??0)+1);return[...T.entries()].sort((S,U)=>S[0].localeCompare(U[0])).map(([S,U])=>({name:S,count:U}))},[i]),B=a.useMemo(()=>Ra(i,y),[i,y]),W=a.useMemo(()=>{let T=B;E&&(T=T.filter(U=>U.provider===E));const S=k.trim().toLowerCase();return S?T.filter(U=>U.name.toLowerCase().includes(S)||U.provider.toLowerCase().includes(S)||U.id.toLowerCase().includes(S)):T},[B,k,E]),[ee,ne]=a.useState(!1),H=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,K=La.map(T=>({value:T,label:o(`thinking.${T}`),supported:H?H.has(T):!0})),I=T=>{var S;return((S=K.find(U=>U.value===T))==null?void 0:S.label)??T};return a.useEffect(()=>{h&&i.length===0&&!ee&&!l&&(ne(!0),c({type:"list_models"}))},[h,i.length,ee,l,c]),a.useEffect(()=>{i.length>0&&ne(!1)},[i.length]),a.useEffect(()=>{var S;if(!h)return;const T=(S=R.current)==null?void 0:S.querySelector(".dd-item.active");T==null||T.scrollIntoView({block:"nearest"})},[h,p,i.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Xe,{}),e.jsx("span",{className:"chip-model",children:u?u.name:o("selectModel")}),!n&&(u==null?void 0:u.vision)&&e.jsx("span",{className:"chip-vision",title:o("vision"),children:"🖼"}),!n&&u&&e.jsx("span",{className:"chip-sub",children:u.provider})]}),open:h,onOpenChange:g,menuClassName:"dd-menu-model",menuRef:L,menuStyle:M!=null?{width:M}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(dt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:o("searchModels"),value:k,onChange:T=>D(T.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[m.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:o("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${E===null?"active":""}`,onClick:()=>$(null),children:e.jsx("span",{children:o("allProviders")})}),m.map(T=>e.jsxs("button",{type:"button",className:`dd-provider-item ${E===T.name?"active":""}`,onClick:()=>$(E===T.name?null:T.name),title:`${T.name} · ${T.count}`,children:[e.jsx("span",{className:"dd-provider-name",children:T.name}),e.jsx("span",{className:"dd-provider-count",children:T.count})]},T.name))]}),e.jsxs("div",{className:"dd-model-scroll",ref:R,children:[(ee||l)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.length===0&&!ee&&!l&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),W.length===0&&i.length>0&&e.jsx("div",{className:"dd-loading",children:o("noModelMatches")}),W.map(T=>e.jsx(be,{active:p===T.id,onClick:()=>{p!==T.id&&c({type:"set_model",modelId:T.id}),g(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:T.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:T.provider}),(y[T.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:o("modelUsedCount",{n:y[T.id]})}),(T.reasoning||T.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[T.reasoning&&e.jsx("span",{className:"dd-model-badge",children:o("reasoning")}),T.vision&&e.jsx("span",{className:"dd-model-badge",children:o("vision")})]})]})]})},T.id))]})]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:o("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{g(!1),r()},children:o("manageModels")})]})]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(nt,{}),e.jsx("span",{className:"chip-sub",children:o("thinkingChip",{level:s?I(s.thinkingLevel):"—"})})]}),open:v,onOpenChange:b,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("thinkingLevel")}),K.map(T=>e.jsx(be,{active:(s==null?void 0:s.thinkingLevel)===T.value,disabled:!T.supported,title:T.supported?void 0:o("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==T.value&&c({type:"set_thinking",level:T.value}),b(!1)},children:T.label},T.value))]})]})}),Ba=a.memo(function({ready:s,streaming:i,messages:l,slashCommands:c,modelState:r,models:n,modelsLoading:o,send:u,attachments:p,onRemoveAttachment:h,onAddImageFiles:g,onAddLocalFiles:v,onNotice:b,onSent:k,onManageModels:D}){const E=me(),{locale:$}=Ft(),{openPicker:y}=an(),j=d=>$==="en"&&d.descriptionEn?d.descriptionEn:d.description??"",R=d=>$==="en"&&d.argumentHintEn?d.argumentHintEn:d.argumentHint??"",[L,M]=a.useState(""),[C,m]=a.useState(!1),[B,W]=a.useState(null),[ee,ne]=a.useState(0),[H,K]=a.useState(!1),[I,T]=a.useState(void 0),S=a.useRef(null),U=a.useRef(null),_=a.useRef(null),z={builtin:E("slashBuiltin"),extension:E("slashExtension"),prompt:E("slashPrompt"),skill:E("slashSkill"),plugin:E("slashPlugin")},N=d=>{const P=d.match(/^\/([^\s]*)$/);if(P&&s){const le=P[1].toLowerCase(),se=c.filter(he=>he.name.toLowerCase().startsWith(le));W(se.length>0?se:null),ne(0)}else W(null)};a.useEffect(()=>{var P;const d=(P=_.current)==null?void 0:P.querySelector(".slash-item.active");d==null||d.scrollIntoView({block:"nearest"})},[ee,B]);const X=d=>{var J;const P=B??[],le=d??P[ee%Math.max(P.length,1)];if(!le){W(null);return}const se=L.match(/^\/([^\s]*)([\s\S]*)$/),he=se?se[2]:"";M(`/${le.name} ${he}`),W(null),(J=S.current)==null||J.focus()},te=async()=>{const P=[...l].reverse().find(se=>se.role==="assistant"&&se.content.some(he=>he.type==="text"&&he.text)),le=P==null?void 0:P.content.filter(se=>se.type==="text").map(se=>se.text).join(`
|
|
317
|
-
`);if(!le){b("warning",E("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(le),b("info",E("slashCopied"))}catch{b("error",E("slashCopyFailed"))}},ce=d=>{if(!d||d.length===0){b("warning",E("foldersNotSupported"));return}const P=Array.from(d).filter(se=>Me(se.type)),le=Array.from(d).filter(se=>!Me(se.type));P.length>0&&g(P),le.length>0&&v(le)},A=d=>{var se;const P=(se=d.clipboardData)==null?void 0:se.items;if(!P)return;const le=[];for(const he of P)if(he.kind==="file"&&Me(he.type)){const J=he.getAsFile();J&&le.push(J)}le.length!==0&&(d.preventDefault(),g(le))},Y=s,oe=a.useRef(L);a.useEffect(()=>{oe.current=L},[L]),a.useEffect(()=>{N(oe.current)},[c]),a.useEffect(()=>{const d=P=>{var se;const le=P.detail;M(le),(se=S.current)==null||se.focus()};return window.addEventListener("pi-web:fill",d),()=>window.removeEventListener("pi-web:fill",d)},[]),a.useEffect(()=>{if(!H)return;const d=P=>{P.key==="Escape"&&K(!1)};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[H]),a.useEffect(()=>{const d=S.current;if(!d)return;d.style.height="auto";const P=d.scrollHeight>220;d.style.height=`${Math.min(d.scrollHeight,220)}px`,d.style.overflowY=P?"auto":"hidden"},[L]);const Q=(d=!1)=>{var se,he,J,re,ge;const P=L.trim(),le=p.some(pe=>pe.imageData||pe.fileData);if(!(!Y||!P&&!le)){if(P==="/help"){const pe=(he=(se=S.current)==null?void 0:se.closest(".inputbox"))==null?void 0:he.getBoundingClientRect();T(pe==null?void 0:pe.width),K(!0),M(""),(J=S.current)==null||J.focus();return}if(P==="/copy"){M(""),(re=S.current)==null||re.focus(),te();return}if(u({type:"prompt",text:P,queue:d,attachments:p.map(pe=>pe.imageData?{path:"",imageData:pe.imageData,mimeType:pe.mimeType,name:pe.name}:pe.fileData?{path:"",fileData:pe.fileData,mimeType:pe.mimeType,name:pe.name,size:pe.size}:{path:pe.path,mode:pe.mode,...pe.lines?{lines:pe.lines}:{}})})){M(""),k();const pe=r==null?void 0:r.model;pe&&Ia(`${pe.provider}/${pe.id}`),(ge=S.current)==null||ge.focus()}}},ue=d=>{if(!d.nativeEvent.isComposing){if(B&&B.length>0)switch(d.key){case"ArrowDown":d.preventDefault(),ne(P=>(P+1)%B.length);return;case"ArrowUp":d.preventDefault(),ne(P=>(P-1+B.length)%B.length);return;case"Tab":case"Enter":d.preventDefault(),X();return;case"Escape":d.preventDefault(),W(null);return}d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),Q())}},Z=()=>e.jsx("div",{className:"inputbox-actions",children:i?e.jsxs(e.Fragment,{children:[L.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:E("supplementTip"),onClick:()=>Q(!0),children:[e.jsx(Ds,{})," ",E("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:E("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(ot,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:E("sendTip"),disabled:!Y||!L.trim()&&!p.some(d=>d.imageData||d.fileData),onClick:()=>Q(),children:e.jsx(As,{})})});return e.jsxs("div",{className:`inputbar${C?" drop-active":""}`,onDragOver:d=>{d.preventDefault(),d.stopPropagation(),m(!0)},onDragLeave:d=>{d.currentTarget.contains(d.relatedTarget)||m(!1)},onDrop:d=>{var P;d.preventDefault(),d.stopPropagation(),m(!1),ce(((P=d.dataTransfer)==null?void 0:P.files)??null)},children:[C&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",E("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(d=>e.jsxs("span",{className:`attach-chip ${d.imageData?"image":d.fileData?"file":d.mode}`,title:d.imageData?E("attachImage",{name:d.name}):d.fileData?E("attachFile",{name:d.name}):d.isDir?E("folderRef",{path:d.path}):d.mode==="reference"?E("refOnly",{path:d.path}):d.mode==="lines"&&d.lines?E("attachLines",{path:d.path,start:d.lines.start,end:d.lines.end}):E("attachContent",{path:d.path}),children:[d.imageData?"🖼":d.fileData?"📄":d.isDir?"📁":d.mode==="reference"?"🔗":"📎"," ",d.name,d.mode==="lines"&&d.lines&&e.jsxs("span",{className:"attach-range",children:["L",d.lines.start,"-",d.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:E("removeAttachment"),onClick:()=>h(d.key??d.path),children:"×"})]},d.key??`${d.path}|${d.mode}|${d.lines?`${d.lines.start}-${d.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:E("attachHint")})]}),B&&B.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:_,"aria-label":E("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:E("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>W(null),children:"Esc"})]}),B.map((d,P)=>e.jsxs("button",{type:"button",className:`slash-item${P===ee?" active":""}`,onMouseEnter:()=>ne(P),onClick:()=>X(d),children:[e.jsxs("span",{className:"slash-name",children:["/",d.name]}),e.jsx("span",{className:`slash-source ${d.source}`,children:z[d.source]}),e.jsxs("span",{className:"slash-desc",children:[j(d),d.argumentHint&&e.jsx("span",{className:"slash-hint",children:R(d)})]})]},d.name))]}),H&&e.jsx("div",{className:"modal-backdrop",onClick:()=>K(!1),children:e.jsxs("div",{className:"slash-help",style:I?{width:I}:void 0,onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",E("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>K(!1),children:E("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:E("slashLoading")}):c.map(d=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",d.name]}),e.jsx("span",{className:`slash-source ${d.source}`,children:z[d.source]}),e.jsxs("span",{className:"slash-help-desc",children:[j(d),d.argumentHint&&e.jsx("span",{className:"slash-hint",children:R(d)})]})]},d.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,onChange:d=>{ce(d.target.files),d.target.value=""}}),e.jsx("textarea",{ref:S,value:L,rows:1,placeholder:E(Y?i?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!Y,onChange:d=>{M(d.target.value),N(d.target.value)},onKeyDown:ue,onPaste:A}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:E("uploadFile"),disabled:!Y,onClick:()=>{var d;return(d=U.current)==null?void 0:d.click()},children:e.jsx($n,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:E("tpl.openPicker"),onClick:y,children:e.jsx(Vn,{})}),e.jsx(Da,{state:r,models:n,modelsLoading:o,send:u,onManageModels:D,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:Z()})]})]})]})}),Fa=a.memo(function({goal:s,models:i,modelsLoading:l,activeConversationId:c,send:r}){var ee,ne,H,K,I,T;const n=me(),o=!s.conversationId||s.conversationId===c,u=s.goal!==null&&o,[p,h]=a.useState(""),[g,v]=a.useState(s.reviewModel??""),[b,k]=a.useState(s.maxRounds),[D,E]=a.useState(s.locked),[$,y]=a.useState(!1),[j,R]=a.useState(!1),[L,M]=a.useState(!0);a.useEffect(()=>{v(s.reviewModel??""),k(s.maxRounds||0),E(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),a.useEffect(()=>{$&&i.length===0&&!j&&!l&&(R(!0),r({type:"list_models"}))},[$,i.length,j,l,r]),a.useEffect(()=>{i.length>0&&R(!1)},[i.length]);const C=()=>{var S;return g?((S=i.find(U=>U.id===g))==null?void 0:S.name)??g:n("goalBarUseMainModel")},m=()=>{const S=p.trim();S&&(r({type:"set_goal",goal:S,...g?{reviewModel:g}:{},maxRounds:b,locked:D}),h(""),M(!1))},B=()=>{const S=p.trim();S&&(r({type:"start_goal_wizard",text:S,...g?{wizardModel:g}:{},maxRounds:b,locked:D}),h(""),M(!1))},W=(((ee=s.wizard)==null?void 0:ee.active)??!1)&&o;return W?e.jsx("div",{className:`goalbar goalbar-active ${W?"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:((ne=s.wizard)==null?void 0:ne.draft)??"",children:[n("goalWizardRunning"),": ",(H=s.wizard)==null?void 0:H.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[n("goalBarRound",{n:(((K=s.wizard)==null?void 0:K.step)??0)+1})," ","/ ",((I=s.wizard)==null?void 0:I.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((T=s.wizard)==null?void 0:T.status)||n("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:n("goalBarClear"),onClick:()=>{r({type:"clear_goal"}),M(!0)},children:e.jsx(ke,{})})]})}):u?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[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"}),M(!0)},children:e.jsx(ke,{})})]})}):L?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:n("goalBarPlaceholder"),onClick:()=>M(!1),children:[e.jsx(Zt,{})," ",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(Zt,{})}),e.jsx("input",{className:"goalbar-input",value:p,placeholder:n("goalBarPlaceholder"),onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&m()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!p.trim(),onClick:m,children:n("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!p.trim(),title:n("goalWizardTip"),onClick:B,children:["🔍 ",n("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:n(D?"goalBarLocked":"goalBarUnlocked"),onClick:()=>E(S=>(r({type:"set_goal_prefs",locked:!S}),!S)),children:D?e.jsx(qn,{}):e.jsx(Ln,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:n("goalBarClear"),onClick:()=>M(!0),children:e.jsx(mt,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Ie,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[n("goalBarReviewModel"),": ",e.jsx("b",{children:C()})]}),open:$,onOpenChange:y,direction:"up",children:[e.jsx("div",{className:"dd-header",children:n("goalBarReviewModel")}),(j||l)&&e.jsx("div",{className:"dd-loading",children:n("loading")}),i.length===0&&!j&&!l&&e.jsx("div",{className:"dd-loading",children:n("noModels")}),e.jsx(be,{active:g==="",onClick:()=>{v(""),y(!1),r({type:"set_goal_prefs",reviewModel:""})},children:n("goalBarUseMainModel")}),i.map(S=>e.jsx(be,{active:g===S.id,onClick:()=>{v(S.id),y(!1),r({type:"set_goal_prefs",reviewModel:S.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:S.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:S.provider})})]})},S.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:b,placeholder:n("goalBarUnlimitedShort"),onChange:S=>{const U=parseInt(S.target.value,10);if(Number.isNaN(U)||U<0){k(0);return}k(U)},onBlur:()=>r({type:"set_goal_prefs",maxRounds:b}),onKeyDown:S=>{S.key==="Enter"&&(r({type:"set_goal_prefs",maxRounds:b}),S.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:n(D?"goalBarLocked":"goalBarUnlocked")})]})]})});function $a({chat:t,send:s}){const i=me(),l=t.state,[c,r]=a.useState(!1),[n,o]=a.useState(""),[u,p]=a.useState(0),h=a.useRef(null),g=t.pathCompletions;if(a.useEffect(()=>{if(!c)return;const m=setTimeout(()=>{s({type:"complete_path",path:n})},150);return()=>clearTimeout(m)},[n,c,s]),a.useEffect(()=>p(0),[g]),a.useEffect(()=>{const m=document.querySelector(`.status-completions .pc-item[data-idx="${u}"]`);m==null||m.scrollIntoView({block:"nearest"})},[u]),!l)return null;const v=l.stats,b=t.ready?"ok":"busy",k=t.ready?i("connected"):i("connecting"),D=v.contextUsage,E=D.tokens!==null&&D.percent!==null?`${js(D.tokens)} / ${js(D.contextWindow)}`:"—",$=D.percent??null,y=$===null?"":$>=80?"warn":$>=50?"mid":"ok",j=l.queue.steering.length+l.queue.followUp.length,R=()=>{o(l.cwd),r(!0)},L=(m,B)=>{var ee;const W=m.includes("\\")?"\\":"/";o(B?`${m}${W}`:m),p(0),(ee=h.current)==null||ee.focus()},M=m=>{const B=m.trim();B&&B!==l.cwd&&s({type:"set_cwd",path:B}),r(!1)},C=m=>{if(m.key==="ArrowDown")m.preventDefault(),p(B=>Math.min(B+1,g.length-1));else if(m.key==="ArrowUp")m.preventDefault(),p(B=>Math.max(B-1,0));else if(m.key==="Tab"&&g.length>0){m.preventDefault();const B=g[Math.min(u,g.length-1)];L(B.path,B.type==="dir")}else if(m.key==="Enter"&&!m.nativeEvent.isComposing){const B=n.trim();if(B.endsWith("/")||B.endsWith("\\"))M(B);else if(g.some(W=>W.path===B))M(B);else if(g.length>0&&g[u]){m.preventDefault();const W=g[u];L(W.path,W.type==="dir")}else M(B)}else m.key==="Escape"&&(g.length>0?(m.stopPropagation(),s({type:"complete_path",path:""})):r(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${b}`,title:k}),e.jsx("span",{className:"status-item",children:k}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-ctx",title:i("contextUsage"),children:[i("context"),e.jsx("span",{className:`ctx-bar ${y}`,children:$!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min($,100)}%`}})}),E]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("cumulativeCost"),children:["$",Aa(v.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:i("sessionMessages"),children:[i("messages")," ",v.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:i("pluginStatus"),children:t.statuses.map(m=>m.text).join(" · ")})]}),l.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),i("working"),j>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",j," ",i("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:h,className:"status-cwd-input",value:n,autoFocus:!0,placeholder:i("enterPath"),onChange:m=>o(m.target.value),onKeyDown:C,onBlur:()=>r(!1)}),g.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:m=>m.preventDefault(),children:g.map((m,B)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":B,className:`pc-item ${B===u?"sel":""}`,onMouseEnter:()=>p(B),onClick:()=>L(m.path,m.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:m.type==="dir"?e.jsx(ze,{}):e.jsx(Fs,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:m.name}),e.jsx("span",{className:"pc-path",children:m.path})]})]})},m.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:i("cwdTip",{path:l.cwd}),onClick:R,children:["📁 ",l.cwd]})]})}function js(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function Aa(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function _a({dialog:t,send:s}){const i=me(),[l,c]=a.useState(""),[r,n]=a.useState(0),o=h=>{s({type:"dialog_response",id:t.id,value:h})};a.useEffect(()=>{c(""),n(0);const h=g=>{g.key==="Escape"&&o(null)};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],p=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:i("pluginRequest")}),t.title&&t.title!==i("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:i("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((h,g)=>e.jsx("button",{type:"button",className:`dialog-option ${g===r?"sel":""}`,onMouseEnter:()=>n(g),onClick:()=>o(h),children:h},g)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:i("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:p}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:i("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:l,placeholder:p||i("inputPlaceholder"),autoFocus:!0,onChange:h=>c(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.nativeEvent.isComposing&&o(l)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:i("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(l),children:i("ok")})]})]})]})}function Oa(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",i=t.y!==" "&&t.y!=="?";return s&&i?"both":s?"staged":"unstaged"}function Wa({chat:t,send:s,terminal:i,active:l,onSwitchToTerminal:c}){var Ne,Re;const r=me(),[n,o]=a.useState(null),[u,p]=a.useState([]),[h,g]=a.useState(""),[v,b]=a.useState(new Map),[k,D]=a.useState("changes"),[E,$]=a.useState([]),[y,j]=a.useState(null),[R,L]=a.useState(""),[M,C]=a.useState(!1),[m,B]=a.useState(null),[W,ee]=a.useState(null),[ne,H]=a.useState(!1),[K,I]=a.useState(!1),[T,S]=a.useState(!1),[U,_]=a.useState(null),[z,N]=a.useState(!1),[X,te]=a.useState(""),ce=a.useRef(0),A=a.useRef(-1),Y=a.useRef(-1),oe=a.useRef(-1),Q=a.useRef(-1),ue=a.useRef(void 0),Z=a.useRef(null),d=a.useRef([]),P=a.useCallback(w=>{if(w.reqId===A.current){if(A.current=-1,I(!1),_(null),!w.ok){_(w.error??"查询失败");return}if(w.notRepo){N(!0),o(null),p([]),b(new Map),$([]),j(null),L(""),ee(null);return}N(!1);const f={branch:w.branch??"",detached:!!w.detached,upstream:w.upstream??null,ahead:w.ahead??0,behind:w.behind??0,upstreamGone:!!w.upstreamGone,files:(w.files??[]).map(O=>({...O}))},x=(w.branches??[]).map(O=>({...O})),V=new Map;for(const[O,ie]of Object.entries(w.stats??{}))V.set(O,{add:ie[0],del:ie[1]});o(f),p(x),b(V),g(O=>{var ie;return f.detached?O||"":f.branch&&x.some(de=>de.name===f.branch)?f.branch:O&&x.some(de=>de.name===O)?O:((ie=x[0])==null?void 0:ie.name)??""}),ee(O=>O&&!f.files.some(ie=>ie.path===O.file.path)?null:O)}else if(w.reqId===Y.current){if(Y.current=-1,H(!1),!w.ok){_(w.error??"查询失败");return}const f=Z.current;if(!f)return;ee({file:f,staged:w.stagedText??"",worktree:w.worktreeText??"",untracked:!1})}else if(w.reqId===Q.current){if(Q.current=-1,S(!1),!w.ok){_(w.error??"查询失败");return}$((w.history??[]).map(f=>({...f})))}else if(w.reqId===oe.current){if(oe.current=-1,C(!1),!w.ok){_(w.error??"查询失败");return}L(w.text??"")}},[]);a.useEffect(()=>{const w=t.scmData;w&&w.type==="scm_data"&&P(w)},[t.scmData,P]);const le=a.useCallback((w,f)=>{if(!t.ready||t.status!=="open")return!1;const x=++ce.current;return s({...w,reqId:x})?(f.current=x,!0):(ce.current-=1,!1)},[t.ready,t.status,s]),se=a.useCallback((w=!1,f=!1)=>{var x;!t.ready||t.status!=="open"||(x=t.state)!=null&&x.cwd&&(ue.current!==void 0&&ue.current!==t.state.cwd&&(o(null),p([]),b(new Map),$([]),S(!1),Q.current=-1,j(null),L(""),ee(null),B(null)),ue.current=t.state.cwd,_(null),le({type:"scm_status"},A)&&(f||I(!0)))},[t.ready,(Ne=t.state)==null?void 0:Ne.cwd,t.status,le]),he=a.useCallback(w=>{if(B(w),j(null),Z.current=w,w.x==="?"&&w.y==="?"){ee({file:w,staged:"",worktree:"",untracked:!0});return}H(!0),_(null),le({type:"scm_filediff",path:w.path},Y)||H(!1)},[le]),J=a.useCallback(w=>{j(w),B(null),ee(null),L(""),C(!0),_(null),le({type:"scm_commit",hash:w.hash},oe)||C(!1)},[le]),re=a.useCallback((w,f)=>{var O,ie;if(!t.ready)return;const x={name:w,command:f,cwd:"${pwd}"},V=t.terminals.find(de=>de.title===w);if(V)i.restart(V.id),s({type:"run_command",terminalId:V.id,conversationId:V.conversationId,command:x,cols:80,rows:24});else{const de=De();i.create({id:de,conversationId:t.activeConversationId||((O=t.state)==null?void 0:O.conversationId)||"",title:w,cwd:((ie=t.state)==null?void 0:ie.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:x})}c()},[t.ready,(Re=t.state)==null?void 0:Re.cwd,t.terminals,c,s,i]),ge=a.useCallback(()=>{const w=X.trim();if(!w||z)return;const f=w.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");re("git commit",`git add -A && git commit -m "${f}"`),te("")},[X,z,re]),pe=w=>`'${w.replace(/'/g,"'\\''")}`,we=a.useCallback(w=>{z||re("git add",`git add -- ${pe(w.path)}`)},[z,re]),Be=a.useCallback(w=>{z||re("git reset",`git reset HEAD -- ${pe(w.path)}`)},[z,re]),_e=a.useCallback(()=>{if(!h||z)return;const w=u.find(f=>f.name===h);if(w!=null&&w.remote&&typeof w.remote=="string"){const f=h.slice(w.remote.length+1);re("git checkout",`git checkout -b ${f} ${h} || git checkout ${h}`)}else re("git checkout",`git checkout ${h}`)},[h,u,z,re]),Ve=a.useCallback(()=>re("git push","git push"),[re]),Ge=a.useCallback(()=>re("git pull","git pull"),[re]),Ce=a.useCallback(()=>{le({type:"scm_history"},Q)||(Q.current=-1)},[le]);a.useEffect(()=>{l&&se()},[l,se]),a.useEffect(()=>{k==="history"&&n&&Ce()},[k,n,Ce]),a.useEffect(()=>{t.scmDirty>0&&l&&se(!1,!0)},[t.scmDirty]),a.useEffect(()=>{if(!l||!t.ready||t.status!=="open")return;const w=setInterval(()=>{document.visibilityState!=="hidden"&&se(!1,!0)},3e4);return()=>clearInterval(w)},[l,t.ready,t.status,se]),a.useEffect(()=>{const w=d.current;if(d.current=t.terminals,!l)return;t.terminals.some(x=>{var O;return x.running!==!1?!1:((O=w.find(ie=>ie.id===x.id))==null?void 0:O.running)===!0&&/^git /.test(x.title)})&&t.ready&&t.status==="open"&&(se(!1,!0),k==="history"&&n&&Ce())},[t.terminals,l,t.ready,t.status,se,k,n,Ce]);const Oe={staged:r("scmStaged"),unstaged:r("scmUnstaged"),untracked:r("scmUntracked"),both:r("scmStagedUnstaged")},Fe=w=>{const f=w.split(`
|
|
318
|
-
`);return e.jsx("pre",{className:"scm-diff-pre",children:f.map((x,V)=>{let O="";return x.startsWith("diff --git")||x.startsWith("index ")||x.startsWith("new file")||x.startsWith("deleted file")||x.startsWith("old mode")||x.startsWith("new mode")||x.startsWith("similarity index")||x.startsWith("rename ")||x.startsWith("copy ")||x.startsWith("Binary files")||x.startsWith("---")||x.startsWith("+++")?O="hdr":x.startsWith("@@")?O="hunk":x.startsWith("+")?O="add":x.startsWith("-")&&(O="del"),e.jsx("div",{className:`scm-diff-line ${O}`,children:x||" "},V)})})};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(it,{}),r("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":k==="changes",className:k==="changes"?"active":"",onClick:()=>{D("changes"),_(null)},children:r("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="history",className:k==="history"?"active":"",onClick:()=>{D("history"),_(null)},children:r("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:r("scmRefreshTip"),disabled:K,onClick:()=>se(!0),children:e.jsx(pt,{className:K?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:r("scmCurrentBranch"),children:[e.jsx(it,{}),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:h,disabled:z||u.length===0,title:r("scmSwitchBranch"),onChange:w=>g(w.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("scmSelectBranch")}),u.filter(w=>!w.remote).map(w=>e.jsx("option",{value:w.name,children:w.current?`* ${w.name}`:w.name},w.name)),u.some(w=>w.remote)&&e.jsx("optgroup",{label:r("scmRemoteBranches"),children:u.filter(w=>w.remote).map(w=>e.jsx("option",{value:w.name,children:w.name},w.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!h||h===(n==null?void 0:n.branch)||z,title:r("scmSwitchBranchTip",{branch:h}),onClick:_e,children:[e.jsx(it,{}),r("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||z,title:r("scmPushTip"),onClick:Ve,children:[e.jsx(As,{}),r("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||z,title:r("scmPullTip"),onClick:Ge,children:[e.jsx(_s,{}),r("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:X,placeholder:r("scmCommitPlaceholder"),disabled:z,onChange:w=>te(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.nativeEvent.isComposing&&ge()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!X.trim()||z,title:r("scmCommitTip"),onClick:ge,children:[e.jsx(gt,{}),r("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[k==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:r("scmHistory")}),E.length>0&&e.jsx("span",{className:"scm-files-count",children:E.length})]}),e.jsx("div",{className:"scm-history-list",children:z?e.jsx("div",{className:"scm-empty",children:r("scmNotGitRepo")}):!n||T?e.jsx("div",{className:"scm-empty",children:t.status==="open"?r("scmLoading"):r("scmConnecting")}):E.length===0?e.jsx("div",{className:"scm-empty",children:r("scmNoHistory")}):E.map(w=>e.jsxs("button",{type:"button",className:`scm-commit ${(y==null?void 0:y.hash)===w.hash?"active":""}`,onClick:()=>J(w),title:w.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:w.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:w.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[w.shortHash," · ",w.author," · ",w.date]}),w.decorations&&e.jsx("span",{className:"scm-commit-refs",children:w.decorations})]})]},w.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:z?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(w=>{const f=Oa(w),x=v.get(w.path);return e.jsxs("div",{className:`scm-file ${(m==null?void 0:m.path)===w.path?"active":""}`,title:Oe[f],onClick:()=>he(w),children:[e.jsx("span",{className:`scm-file-xy ${f==="untracked"?"q":"x"}`,children:w.x!==" "?w.x:" "}),e.jsx("span",{className:`scm-file-xy ${f==="untracked"?"q":"y"}`,children:w.y!==" "?w.y:" "}),e.jsx("span",{className:"scm-file-path",children:w.path}),x&&(x.add>0||x.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[x.add>0&&e.jsxs("span",{className:"add",children:["+",x.add]}),x.del>0&&e.jsxs("span",{className:"del",children:["-",x.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(w.y!==" "||f==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:r("scmStageTip",{path:w.path}),onClick:V=>{V.stopPropagation(),we(w)},children:"+"}),f==="staged"||f==="both"?e.jsx("button",{type:"button",className:"scm-act",title:r("scmUnstageTip",{path:w.path}),onClick:V=>{V.stopPropagation(),Be(w)},children:"−"}):null]})]},w.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:k==="history"?y?`${y.shortHash} ${y.subject}`:r("scmCommitDetail"):m?m.path:r("scmDiff")}),(k==="history"?M:ne)&&e.jsx("span",{className:"scm-diff-loading",children:r("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:k==="history"?e.jsxs(e.Fragment,{children:[U&&e.jsx("div",{className:"scm-error",children:U}),!y&&!U&&e.jsx("div",{className:"scm-empty",children:r("scmSelectCommitHint")}),y&&M&&!U&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),y&&!M&&!U&&R?Fe(R):null]}):e.jsxs(e.Fragment,{children:[U&&e.jsx("div",{className:"scm-error",children:U}),!m&&!U&&e.jsx("div",{className:"scm-empty",children:r("scmSelectFileHint")}),m&&!W&&!U&&e.jsx("div",{className:"scm-empty",children:r("scmLoading")}),m&&W&&W.untracked&&e.jsx("div",{className:"scm-empty",children:r("scmUntrackedNote")}),m&&W&&!W.untracked&&e.jsxs(e.Fragment,{children:[W.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmStaged")}),Fe(W.staged)]}),W.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:r("scmUnstaged")}),Fe(W.worktree)]}),!W.staged&&!W.worktree&&e.jsx("div",{className:"scm-empty",children:r("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ke,{}),e.jsx("span",{children:r("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:r("scmViewTerminal")})]})]})}function Ha({entry:t,send:s}){const i=a.useRef(null);return a.useEffect(()=>{const l=i.current;if(!l)return;let c;try{c=t.module.mount(l,xi(t.info.id,r=>s(r)))}catch(r){console.error(`[plugin:${t.info.id}] mount failed:`,r),l.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(r){console.error(`[plugin:${t.info.id}] cleanup failed:`,r)}l.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:i})}function qa({send:t,piConfigured:s,piAgentInstalled:i,providers:l,installResult:c,onClose:r}){const n=me(),[o,u]=a.useState(!1),[p,h]=a.useState(""),[g,v]=a.useState(""),[b,k]=a.useState(!1);a.useEffect(()=>{t({type:"list_providers"})},[t]),a.useEffect(()=>{s&&r()},[s,r]),a.useEffect(()=>{c&&u(!1)},[c]),a.useEffect(()=>{var R;!p&&l.length>0&&h(((R=l.find(L=>!L.configured))==null?void 0:R.id)??l[0].id)},[l,p]);const D=()=>{o||(u(!0),t({type:"install_pi_agent"}))},E=()=>{!g.trim()||b||(k(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:g.trim()}),setTimeout(()=>k(!1),3e3))},$=()=>{t({type:"get_state"}),t({type:"list_providers"})},y=l.find(R=>R.id===p),j=c!==null&&!c.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":n("close"),onClick:r,children:e.jsx(ke,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(Xe,{className:"modal-head-icon"}),e.jsx("h2",{children:n("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:n("setupDesc")}),j?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:n("installFailed")}),e.jsx("pre",{className:"setup-detail",children:c.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:D,children:n("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:r,children:n("skip")})]})]}):i||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?n("installDone"):n("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("provider")}),e.jsxs("select",{value:p,onChange:R=>h(R.target.value),children:[l.length===0&&e.jsx("option",{value:"",children:n("loading")}),l.map(R=>e.jsxs("option",{value:R.id,children:[R.name,"(",R.id,")",R.configured?` · ${n("configured")}`:""]},R.id))]}),(y==null?void 0:y.configured)&&e.jsx("div",{className:"field-hint",children:n("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:R=>v(R.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||b||!p,onClick:E,children:n(b?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:$,children:[e.jsx(pt,{})," ",n("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:D,children:n(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:r,children:n("skip")})]})]})})}const Ka=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],_t=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Ua=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[_t()]});function ws(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:[_t()]).map(s=>{var i;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(i=s.input)!=null&&i.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function za({send:t,providers:s,providerStatus:i,fetchModelsResult:l,refreshProviderResult:c,cloneProviderResult:r,onClose:n}){const o=me(),[u,p]=a.useState(null),[h,g]=a.useState({}),[v,b]=a.useState(null),[k,D]=a.useState({}),[E,$]=a.useState(!1),[y,j]=a.useState(0),[R,L]=a.useState(null),M=a.useRef(0),[C,m]=a.useState({});a.useRef(0);const B=a.useRef(0),[W,ee]=a.useState(null),ne=a.useRef(0),H=a.useRef(0);a.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const K=()=>{if(!u)return;const N=u.baseUrl.trim();if(!N){L({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(E)return;$(!0),L(null);const X=y+1;j(X),t({type:"fetch_models",reqId:X,baseUrl:N,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};a.useEffect(()=>{var N;if(!(!l||l.reqId===M.current))if(M.current=l.reqId,$(!1),l.ok&&((N=l.models)!=null&&N.length)){const X=l.models;p(te=>{if(!te)return te;const ce=te.models.map(Q=>{var d;if(!Q.id.trim())return Q;const ue=X.find(P=>P.id===Q.id.trim());if(!ue)return Q;const Z={...Q};return!Z.name&&ue.name&&(Z.name=ue.name),!Z.contextWindow&&ue.contextWindow&&(Z.contextWindow=String(ue.contextWindow)),!Z.maxTokens&&ue.maxTokens&&(Z.maxTokens=String(ue.maxTokens)),Z.input==="text"&&((d=ue.input)!=null&&d.includes("image"))&&(Z.input="text-image"),!Z.reasoning&&ue.reasoning&&(Z.reasoning=!0),Z}),A=new Set(ce.map(Q=>Q.id.trim()).filter(Boolean)),Y=X.filter(Q=>!A.has(Q.id)).map(Q=>{var ue;return{id:Q.id,name:Q.name??"",reasoning:Q.reasoning??!1,input:(ue=Q.input)!=null&&ue.includes("image")?"text-image":"text",contextWindow:Q.contextWindow?String(Q.contextWindow):"",maxTokens:Q.maxTokens?String(Q.maxTokens):""}}),oe=[...ce,...Y];return oe.some(Q=>Q.id.trim())?{...te,models:oe.filter(Q=>Q.id.trim())}:te}),L({ok:!0,text:o("fetchModelsOk",{n:X.length})})}else L({ok:!1,text:l.error||o("fetchModelsEmpty")})},[l]);const I=N=>{const X=(h[N.id]??"").trim();!X||v||(b(N.id),t({type:"set_provider_api_key",provider:N.id,apiKey:X}),setTimeout(()=>{b(null),g(te=>({...te,[N.id]:""})),D(te=>({...te,[N.id]:!1})),t({type:"list_providers"})},1500))},T=()=>{if(!u)return;const N=u.providerId.trim(),X=u.models.filter(ce=>ce.id.trim()).map(ce=>({id:ce.id.trim(),name:ce.name.trim()||void 0,reasoning:ce.reasoning||void 0,input:ce.input==="text-image"?["text","image"]:void 0,contextWindow:ce.contextWindow?Number(ce.contextWindow):void 0,maxTokens:ce.maxTokens?Number(ce.maxTokens):void 0})),te={providerId:N,name:u.name.trim()||void 0,api:u.api.trim()||void 0,baseUrl:u.baseUrl.trim()||void 0,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader||void 0,models:X};t({type:"save_model_config",providerId:N,config:te}),n()};a.useEffect(()=>{!c||c.reqId===B.current||(B.current=c.reqId,m({}))},[c]);const S=N=>{if(W)return;ee(N.id);const X=++ne.current+Date.now();t({type:"clone_provider",provider:N.id,reqId:X})};a.useEffect(()=>{!r||r.reqId===H.current||(H.current=r.reqId,ee(null),r.ok&&r.config&&p(ws({...r.config,apiKey:""})))},[r]);const U=N=>{window.confirm(o("clearKeyConfirm",{id:N}))&&t({type:"clear_provider_api_key",provider:N})},_=N=>{window.confirm(o("deleteProviderConfirm",{id:N.providerId,n:N.models.length}))&&t({type:"delete_model_config",providerId:N.providerId})},z=(N,X)=>{u&&p({...u,models:u.models.map((te,ce)=>ce===N?{...te,...X}:te)})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal model-modal",onClick:N=>N.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:n,children:e.jsx(ke,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:o(u?"editProvider":"manageModelsTitle")})}),u?e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:u.providerId,disabled:s.some(N=>N.providerId===u.providerId),onChange:N=>p({...u,providerId:N.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:u.name,onChange:N=>p({...u,name:N.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:u.api,onChange:N=>p({...u,api:N.target.value}),children:Ka.map(N=>e.jsx("option",{value:N,children:N},N))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:N=>p({...u,baseUrl:N.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:u.apiKey,onChange:N=>p({...u,apiKey:N.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:N=>p({...u,authHeader:N.target.checked})}),e.jsx("span",{children:o("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:o("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[R&&e.jsx("span",{className:`fetch-msg ${R.ok?"ok":"err"}`,title:R.text,children:R.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:E||!u.baseUrl.trim(),title:o("fetchModelsHint"),onClick:K,children:[e.jsx(Dt,{})," ",o(E?"fetchingModels":"fetchModels")]})]})]}),u.models.map((N,X)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:N.id,onChange:te=>z(X,{id:te.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:N.name,onChange:te=>z(X,{name:te.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:N.input,onChange:te=>z(X,{input:te.target.value}),children:[e.jsx("option",{value:"text",children:o("text")}),e.jsx("option",{value:"text-image",children:o("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:N.reasoning,onChange:te=>z(X,{reasoning:te.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:N.contextWindow,onChange:te=>z(X,{contextWindow:te.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:N.maxTokens,onChange:te=>z(X,{maxTokens:te.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>p({...u,models:u.models.filter((te,ce)=>ce!==X)}),children:e.jsx(Ee,{})})]},X)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...u,models:[...u.models,_t()]}),children:[e.jsx(Le,{})," ",o("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(N=>N.id.trim()),onClick:T,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[i.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),i.map(N=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:N.name}),e.jsxs("span",{className:"provider-sub",children:[N.id,N.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),N.source&&!N.configured&&e.jsx("span",{className:"auth-badge dim",children:N.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[N.configured&&!k[N.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:o("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:o("replaceKeyTitle"),onClick:()=>D(X=>({...X,[N.id]:!0})),children:[e.jsx(Et,{})," ",o("replaceKey")]}),N.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>U(N.id),children:[e.jsx(Ee,{})," ",o("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:o("pasteKey"),value:h[N.id]??"",onChange:X=>g(te=>({...te,[N.id]:X.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(h[N.id]??"").trim()||v===N.id,onClick:()=>I(N),children:[e.jsx(Kn,{})," ",v===N.id?o("savingKey"):o("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:W!==null,title:o("cloneProviderTitle"),onClick:()=>S(N),children:[e.jsx(Bt,{})," ",W===N.id?o("cloning"):o("cloneProvider")]})]})]},N.id))]}),e.jsx("div",{className:"form-section-title",children:o("customProviders")}),e.jsx("p",{className:"modal-desc",children:o("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:o("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(N=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:N.providerId}),e.jsxs("span",{className:"provider-sub",children:[N.api??"—",N.baseUrl?` · ${N.baseUrl}`:"",N.models.length>0&&` · ${o("modelsCount",{n:N.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>p(ws(N)),children:e.jsx(Et,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>_(N),children:e.jsx(Ee,{})})]})]},N.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(Ua()),children:[e.jsx(Le,{})," ",o("addProvider")]})})]})]})})}function Va({plugin:t,send:s}){const i=me(),l=t.settingsSchema??[],[c,r]=a.useState(()=>({...t.settingsValues??{}})),[n,o]=a.useState(!1);if(l.length===0)return null;const u=(v,b)=>r(k=>({...k,[v]:b})),p=l.some(v=>{var b;return c[v.key]!==((b=t.settingsValues)==null?void 0:b[v.key])}),h=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},g=()=>r({...t.settingsValues??{}});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:l.map(v=>e.jsxs("label",{className:"plugin-settings-field",title:v.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:v.label}),v.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[v.key],onChange:b=>u(v.key,b.target.checked)}):v.type==="select"?e.jsx("select",{value:String(c[v.key]??""),onChange:b=>u(v.key,b.target.value),children:(v.options??[]).map(b=>e.jsx("option",{value:b,children:b},b))}):e.jsx("input",{type:v.type==="password"?"password":v.type==="number"?"number":"text",value:String(c[v.key]??""),min:v.min,max:v.max,onChange:b=>u(v.key,v.type==="number"?Number(b.target.value):b.target.value)})]},v.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!p||n,onClick:h,children:i(n?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:g,children:i("pluginSettingsReset")})]})]})}function at({text:t}){const s=a.useRef(null),[i,l]=a.useState(!1),c=()=>{var n;const r=(n=s.current)==null?void 0:n.getBoundingClientRect();r&&l(window.innerWidth-r.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${i?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Te({title:t,subtitle:s,tip:i,enabled:l,onToggle:c,action:r}){const n=me();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[t,i&&e.jsx(at,{text:i})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),r,e.jsx("button",{type:"button",className:`set-switch ${l?"on":""}`,role:"switch","aria-checked":l,title:n(l?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Ga({chat:t,send:s,terminal:i,onSwitchToTerminal:l,onClose:c}){const r=me(),n=t.settings,[o,u]=a.useState("prompt"),p=a.useRef(null);a.useEffect(()=>{var d;(d=p.current)==null||d.scrollTo({top:0})},[o]);const[h,g]=a.useState(""),[v,b]=a.useState("append"),k=a.useRef(!1),[D,E]=a.useState(""),[$,y]=a.useState("append"),j=a.useRef(!1),[R,L]=a.useState(""),M=a.useRef(!1),[C,m]=a.useState(""),[B,W]=a.useState(!1),[ee,ne]=a.useState(null),[H,K]=a.useState(null);a.useEffect(()=>{n&&(b(n.promptMode),!k.current&&(g(v==="append"||n.customSystemPrompt?n.customSystemPrompt:n.defaultSystemPrompt||""),y(n.visionBridgePromptMode),!j.current&&(E($==="append"||n.visionBridgePrompt?n.visionBridgePrompt:n.visionBridgeDefaultPrompt||""),M.current||L(n.reviewPrompt))))},[n,v,$]);const[I,T]=a.useState(String((n==null?void 0:n.terminalBashIdleMs)??15e3));if(a.useEffect(()=>{T(String((n==null?void 0:n.terminalBashIdleMs)??15e3))},[n==null?void 0:n.terminalBashIdleMs]),!n)return null;const S=[{id:"prompt",icon:e.jsx($s,{}),label:r("settingsSystemPrompt")},{id:"terminal",icon:e.jsx(Ke,{}),label:r("settingsTerminalTools")},{id:"display",icon:e.jsx(Ue,{}),label:r("settingsMessageDisplay")},{id:"skills",icon:e.jsx(Xe,{}),label:r("settingsSkills"),count:n.skills.length},{id:"extensions",icon:e.jsx(es,{}),label:r("settingsExtensions"),count:n.extensions.length},{id:"plugins",icon:e.jsx(ss,{}),label:r("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(nt,{}),label:r("settingsReview"),count:n.reviewSkills.length},{id:"vision",icon:e.jsx(St,{}),label:r("settingsVisionBridge")},{id:"presets",icon:e.jsx(Bn,{}),label:r("settingsPresets"),count:n.presets.length}],U=new Set(n.disabledSkills),_=new Set(n.disabledExtensions),z=d=>s({type:"set_settings",...d}),N=d=>{const P=new Set(U);P.has(d.name)?P.delete(d.name):P.add(d.name),z({disabledSkills:[...P]})},X=new Set(n.disabledPlugins??[]),te=d=>{const P=new Set(X);P.has(d.id)?P.delete(d.id):P.add(d.id),z({disabledPlugins:[...P]})},ce=d=>{const P=new Set(_);P.has(d.id)?P.delete(d.id):P.add(d.id),z({disabledExtensions:[...P]})},A=(d,P)=>{var he,J;const le={name:d,command:P,cwd:"${pwd}"},se=t.terminals.find(re=>re.title===d);se?(i.restart(se.id),s({type:"run_command",terminalId:se.id,conversationId:se.conversationId,command:le,cols:80,rows:24})):i.create({id:De(),conversationId:t.activeConversationId||((he=t.state)==null?void 0:he.conversationId)||"",title:d,cwd:((J=t.state)==null?void 0:J.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:le}),l(),c()},Y=d=>{ne(null),A(`${r("uninstallTitle")} ${d}`,`pi remove npm:${d}`)},oe=d=>{K(null),A(`${r("uninstallTitle")} ${d}`,`pi-web-ui uninstall ${d}`)},Q=(d,P)=>{A(`${r("pluginUpdate")} ${d}`,`pi-web-ui install ${P} --name ${d} --force`)},ue=d=>{const P=new Set(n.reviewSkills.filter(le=>!le.enabled).map(le=>le.name));P.has(d.name)?P.delete(d.name):P.add(d.name),z({reviewDisabledSkills:[...P]})},Z=()=>{const d=v==="replace"&&n.defaultSystemPrompt&&h===n.defaultSystemPrompt?"":h;z({promptMode:v,customSystemPrompt:d})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:d=>d.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":r("close"),onClick:c,children:e.jsx(ke,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(ct,{className:"modal-head-icon"}),e.jsx("h2",{children:r("settingsTitle")}),e.jsx(at,{text:r("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":r("settingsTitle"),children:S.map(d=>e.jsxs("button",{type:"button",className:`settings-tab${o===d.id?" active":""}`,"aria-current":o===d.id?"true":void 0,title:d.label,onClick:()=>u(d.id),children:[e.jsx("span",{className:"settings-tab-icon",children:d.icon}),e.jsx("span",{className:"settings-tab-label",children:d.label}),d.count!==void 0&&e.jsx("span",{className:"set-count",children:d.count})]},d.id))}),e.jsxs("div",{className:"modal-body",ref:p,children:[o==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{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:v,onChange:d=>{const P=d.target.value;b(P),z({promptMode:P})},children:[e.jsx("option",{value:"append",children:r("promptModeAppend")}),e.jsx("option",{value:"replace",children:r("promptModeReplace")})]}),e.jsx(at,{text:r(v==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:r("promptPlaceholder"),value:h,onFocus:()=>k.current=!0,onBlur:()=>{k.current=!1,Z()},onChange:d=>g(d.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":B,onClick:()=>W(d=>!d),children:[r("settingsViewPrompt")," ",B?"▴":"▾"]}),B&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:r("settingsViewPromptHint")}),e.jsx(Ks,{text:n.effectiveSystemPrompt})]}),n.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:n.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:r("settingsViewPromptEmpty")})]})]}),o==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ke,{className:"set-section-icon"}),r("settingsTerminalTools")]}),e.jsx(Te,{title:r("terminalToolsEnabled"),tip:r("settingsTerminalToolsDesc"),enabled:n.terminalToolsEnabled,onToggle:()=>z({terminalToolsEnabled:!n.terminalToolsEnabled})}),!n.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:r("terminalToolsOffHint")}),e.jsx(Te,{title:r("terminalBashTakeover"),tip:r("terminalBashTakeoverDesc"),enabled:n.terminalBash,onToggle:()=>z({terminalBash:!n.terminalBash})}),n.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:r("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:I,onChange:d=>T(d.target.value),onBlur:()=>{const d=Math.max(0,Math.floor(Number(I)||0));T(String(d)),d!==n.terminalBashIdleMs&&z({terminalBashIdleMs:d})}})]})]}),o==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ue,{className:"set-section-icon"}),r("settingsMessageDisplay")]}),e.jsx(Te,{title:r("thinkingWrap"),tip:r("thinkingWrapDesc"),enabled:n.thinkingWrap??!0,onToggle:()=>z({thinkingWrap:!(n.thinkingWrap??!0)})}),e.jsx(Te,{title:r("toolsWrap"),tip:r("toolsWrapDesc"),enabled:n.toolsWrap??!0,onToggle:()=>z({toolsWrap:!(n.toolsWrap??!0)})})]}),o==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Xe,{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(d=>e.jsx(Te,{title:d.name,subtitle:d.description,enabled:d.enabled,onToggle:()=>N(d)},d.name))})]}),o==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(es,{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(d=>{const P=d.id.startsWith("npm:")?d.id.slice(4):null;return e.jsx(Te,{title:d.name,subtitle:d.path,enabled:d.enabled,onToggle:()=>ce(d),action:P?ee===d.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:r("uninstallConfirmHint"),onClick:()=>Y(P),children:r("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:r("uninstallHint"),onClick:()=>ne(d.id),children:[e.jsx(Ee,{}),r("uninstallExt")]}):void 0},d.id)})})]}),o==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ss,{className:"set-section-icon"}),r("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:r("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(d=>{var P;return e.jsxs(e.Fragment,{children:[e.jsx(Te,{title:`${d.icon?`${d.icon} `:""}${d.name}`,subtitle:(d.error?`${d.id} · ${d.error}`:d.source?`${d.id} · ${d.source}`:`${d.id} · ${r("uiPluginNoSource")}`)+((P=d.permissions)!=null&&P.length?` · ${r("uiPluginPerms")}: ${d.permissions.join(", ")}`:""),enabled:!X.has(d.id)&&!d.error,onToggle:()=>!d.error&&te(d),action:e.jsxs("div",{className:"set-row-actions",children:[d.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:r("pluginUpdateHint"),onClick:()=>Q(d.id,d.source),children:[e.jsx(pt,{}),r("pluginUpdate")]}),H===d.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:r("pluginUninstallHint"),onClick:()=>oe(d.id),children:r("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:r("pluginUninstallHint"),onClick:()=>K(d.id),children:[e.jsx(Ee,{}),r("uninstallExt")]})]})},d.id),d.settingsSchema&&d.settingsSchema.length>0&&e.jsx(Va,{plugin:d,send:s})]})})})]}),o==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{className:"set-section-icon"}),r("settingsReview"),e.jsx(at,{text:r("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:n.reviewSkills.length})]}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:r("reviewPromptPlaceholder"),value:R,onFocus:()=>M.current=!0,onBlur:()=>{M.current=!1,z({reviewPrompt:R})},onChange:d=>L(d.target.value)}),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(d=>e.jsx(Te,{title:d.name,subtitle:d.description,enabled:d.enabled,onToggle:()=>ue(d)},`review-${d.name}`))})]}),o==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(St,{className:"set-section-icon"}),r("settingsVisionBridge")]}),e.jsx(Te,{title:r("visionBridgeEnabled"),tip:r("settingsVisionBridgeDesc"),enabled:n.visionBridgeEnabled,onToggle:()=>z({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:d=>z({visionBridgeModel:d.target.value||null}),children:[e.jsx("option",{value:"",children:r("visionBridgeAuto")}),n.visionModels.map(d=>e.jsx("option",{value:`${d.provider}/${d.id}`,children:d.label},`${d.provider}/${d.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:$,onChange:d=>{const P=d.target.value;y(P),z({visionBridgePromptMode:P})},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:D,onFocus:()=>j.current=!0,onBlur:()=>{j.current=!1;const d=$==="replace"&&n.visionBridgeDefaultPrompt&&D===n.visionBridgeDefaultPrompt?"":D;z({visionBridgePromptMode:$,visionBridgePrompt:d})},onChange:d=>E(d.target.value)}),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")})}))]}),o==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ct,{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:C,onChange:d=>m(d.target.value),onKeyDown:d=>{d.key==="Enter"&&C.trim()&&(s({type:"save_preset",name:C.trim()}),m(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!C.trim(),onClick:()=>{s({type:"save_preset",name:C.trim()}),m("")},children:[e.jsx(Le,{})," ",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(d=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:d.name}),e.jsxs("div",{className:"set-row-desc",children:[d.promptMode==="replace"?r("promptModeReplace"):r("promptModeAppend"),d.disabledSkills.length>0&&` · ${r("settingsSkills")} ${d.disabledSkills.length}`,d.disabledExtensions.length>0&&` · ${r("settingsExtensions")} ${d.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:d.name}),children:r("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:r("deletePreset"),onClick:()=>s({type:"delete_preset",name:d.name}),children:e.jsx(Ee,{})})]})]},d.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:r("close")})})]})})}function Ja(t,s){const i=Math.max(0,Date.now()-t),l=Math.floor(i/6e4);if(l<1)return s("bgTaskJustNow");if(l<60)return s("bgTaskMinutes",{n:l});const c=Math.floor(l/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function Ya({servers:t,send:s,onClose:i}){const l=me(),[c,r]=a.useState(new Set),n=o=>r(u=>{const p=new Set(u);return p.has(o)?p.delete(o):p.add(o),p});return a.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(ut,{})," ",l("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:l("close"),onClick:i,children:e.jsx(ke,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(ut,{}),e.jsx("span",{children:l("bgTasksEmpty")}),e.jsx("small",{children:l("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const u=!!o.taskId,p=o.taskId??String(o.port);return e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:u?o.plugin:l("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[u?e.jsxs("span",{className:"bg-task-port",title:o.taskId,children:["🧩 ",o.plugin]}):e.jsxs("span",{className:"bg-task-port",children:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[!u&&e.jsxs("span",{children:[l("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[l("bgTaskSince")," ",Ja(o.since,l)]}),u&&o.status&&e.jsx("span",{className:"bg-task-status",children:o.status})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(p)?"open":""}`,title:`${l("bgTaskCommand")}: ${o.command}`,onClick:()=>n(p),children:[e.jsx(Ke,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:l("bgTaskStop"),onClick:()=>s(u?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(ot,{}),e.jsx("span",{children:l("bgTaskStop")})]})]},p)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:l("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(pt,{}),e.jsx("span",{children:l("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:l("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(ot,{}),e.jsx("span",{children:l("bgTaskStopAll")})]})]})]})})}function st(t,s){return t.toLowerCase().includes(s)}function Qa({send:t,sessions:s,projects:i,cwd:l,fileSearch:c,onClose:r,onSwitchSession:n,onSwitchProject:o,onPreviewFile:u}){const p=me(),h=a.useRef(null),[g,v]=a.useState(""),b=a.useDeferredValue(g),[k,D]=a.useState(0),E=a.useRef(1),$=a.useRef(0),y=a.useRef(null);a.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var I;return(I=h.current)==null?void 0:I.focus()})},[]);const[j,R]=a.useState(!1);a.useEffect(()=>{y.current&&clearTimeout(y.current);const I=b.trim();if(I)return y.current=setTimeout(()=>{const T=++E.current;$.current=T,R(!0),t({type:"search_files",reqId:T,query:I})},300),()=>{y.current&&clearTimeout(y.current)}},[b]);const L=b.trim().toLowerCase(),M=a.useMemo(()=>L?s.filter(I=>st(I.firstMessage??"",L)||st(I.name??"",L)||st(I.path.split(/[\\/]/).pop()??"",L)).slice(0,20):[],[s,L]),C=a.useMemo(()=>L?i.filter(I=>st(I.path,L)).slice(0,10):[],[i,L]),m=a.useMemo(()=>!L||!c||c.reqId!==$.current||!c.ok?[]:c.results,[c,L]);a.useEffect(()=>{c&&c.reqId===$.current&&$.current!==0&&R(!1)},[c]);const B=!!c&&c.ok&&c.truncated,W=a.useMemo(()=>[...M.map(I=>({kind:"session",path:I.path})),...C.map(I=>({kind:"project",path:I.path})),...m.filter(I=>I.type==="file").map(I=>({kind:"file",path:I.path,name:I.name}))],[M,C,m]);a.useEffect(()=>{D(0)},[b]);const ee=a.useCallback(I=>{I&&(I.kind==="session"?n(I.path):I.kind==="project"?o(I.path):u(I.path,I.name),r())},[n,o,u,r]);a.useEffect(()=>{const I=T=>{T.key==="Escape"?(T.preventDefault(),T.stopPropagation(),r()):T.key==="ArrowDown"?(T.preventDefault(),D(S=>Math.min(S+1,W.length-1))):T.key==="ArrowUp"?(T.preventDefault(),D(S=>Math.max(S-1,0))):T.key==="Enter"&&(T.preventDefault(),ee(W[k]))};return window.addEventListener("keydown",I,!0),()=>window.removeEventListener("keydown",I,!0)},[W,k,ee,r]);const ne=M.length+C.length+m.length,H=(I,T,S)=>e.jsxs("div",{className:"gs-section-head",children:[S,e.jsx("span",{children:I}),e.jsx("em",{children:T})]});let K=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:r,children:e.jsxs("div",{className:"gs-modal",onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(dt,{}),e.jsx("input",{ref:h,type:"text",value:g,placeholder:p("gsPlaceholder"),onChange:I=>v(I.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:p("close"),onClick:r,children:e.jsx(ke,{})})]}),e.jsxs("div",{className:"gs-results",children:[!L&&e.jsx("div",{className:"gs-empty",children:p("gsHint")}),L&&ne===0&&!B&&e.jsx("div",{className:"gs-empty",children:p(j?"gsSearching":"gsNoResults")}),M.length>0&&e.jsxs("div",{className:"gs-section",children:[H(p("gsSessions"),M.length,e.jsx(Ue,{})),M.map(I=>{K++;const T=K;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",onMouseEnter:()=>D(T),onClick:()=>ee({kind:"session",path:I.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[I.name||I.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:I.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:I.firstMessage})]},I.path)})]}),C.length>0&&e.jsxs("div",{className:"gs-section",children:[H(p("gsProjects"),C.length,e.jsx(ze,{})),C.map(I=>{K++;const T=K,S=l&&I.path===l;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",onMouseEnter:()=>D(T),onClick:()=>ee({kind:"project",path:I.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[I.path.split(/[\\/]/).pop(),S&&e.jsx("em",{className:"gs-item-meta",children:p("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:I.path})]},I.path)})]}),(m.length>0||L&&B)&&e.jsxs("div",{className:"gs-section",children:[H(p("gsFiles"),m.length,e.jsx($s,{})),m.map(I=>{K++;const T=K;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",disabled:I.type==="dir",title:I.type==="dir"?void 0:p("gsOpenPreview"),onMouseEnter:()=>D(T),onClick:()=>{I.type==="file"&&ee({kind:"file",path:I.path,name:I.name})},children:[e.jsx("span",{className:"gs-item-title",children:I.name}),e.jsx("span",{className:"gs-item-sub",children:I.path})]},`${I.type}:${I.path}`)}),B&&e.jsx("div",{className:"gs-truncated",children:p("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",p("gsNavigate")]}),e.jsxs("span",{children:["Enter ",p("gsOpen")]}),e.jsxs("span",{children:["Esc ",p("gsCloseHint")]})]})]})})}const wt=5e3;function Xa({file:t,content:s,send:i,onAddLines:l,onAttach:c,onClose:r}){const n=me(),[o,u]=a.useState(null),[p,h]=a.useState(!1),[g,v]=a.useState(null),[b,k]=a.useState(!1),[D,E]=a.useState(!1),[$,y]=a.useState(!1),[j,R]=a.useState(""),[L,M]=a.useState(!0),C=a.useRef(!1),[m,B]=a.useState(!0),[W,ee]=a.useState(!1),[ne,H]=a.useState(100),K=a.useRef(0),I=a.useRef(!1),T=a.useRef(null);a.useEffect(()=>{h(!0),u(null),v(null),y(!1),R(""),M(!0),C.current=!1,i({type:"read_file",path:t.path})},[t.path,i]),a.useEffect(()=>{s&&s.path===t.path&&(u(s),$||R(s.text),h(!1))},[s,$,t.path]),a.useEffect(()=>{const J=re=>{if(re.key==="Escape"){oe();return}if((re.ctrlKey||re.metaKey)&&re.key.toLowerCase()==="s"&&$){re.preventDefault(),Y();return}const ge=re.target,pe=ge&&(ge.tagName==="INPUT"||ge.tagName==="TEXTAREA"||ge.isContentEditable);(re.ctrlKey||re.metaKey)&&re.key.toLowerCase()==="a"&&!pe&&(re.preventDefault(),N())};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[r,o,$,j]),a.useEffect(()=>{const J=()=>{I.current=!1,k(!1)};return window.addEventListener("mouseup",J),()=>window.removeEventListener("mouseup",J)},[]);const S=a.useMemo(()=>{if(!o)return[];const J=o.text.split(`
|
|
319
|
-
`);return J.length>0&&J[J.length-1]===""&&J.pop(),J.slice(0,wt)},[o]),U=(o==null?void 0:o.lines)??0,_=U>wt,z=(J,re)=>{if(re){const ge=K.current>0?K.current:J;v({start:Math.min(ge,J),end:Math.max(ge,J)})}else K.current=J,v({start:J,end:J})},N=()=>{S.length!==0&&(K.current=1,v({start:1,end:S.length}))},X=()=>{g&&(l(t.path,t.name,g.start,g.end),E(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>E(!1),1400))},te=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,ce=()=>{R((o==null?void 0:o.text)??""),y(!1),C.current&&M(!0)},A=()=>{if($){if(j!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;ce();return}!te||!o||(C.current=Nt(t.name)&&L,Nt(t.name)&&M(!1),v(null),R(o.text),y(!0))},Y=()=>{!$||!o||!te||i({type:"write_file",path:t.path,text:j})&&(y(!1),C.current&&M(!0),v(null))},oe=()=>{$&&j!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||r()},Q=J=>{H(Math.min(200,Math.max(50,J)))},ue=g?g.end-g.start+1:0,Z=(o==null?void 0:o.binary)??!1,d=(o==null?void 0:o.truncated)??!1,P=(o==null?void 0:o.kind)??"text",le=Nt(t.name),se=le&&L&&!$&&P==="text"&&!Z,he=J=>ft(`/api/file?clientId=${encodeURIComponent($t())}&path=${encodeURIComponent(J)}`);return e.jsx("div",{className:`fp-overlay ${W?"fullscreen":""}`,onMouseDown:J=>{J.target===J.currentTarget&&oe()},children:e.jsxs("div",{className:`fp ${W?"fullscreen":""}`,style:{"--fp-zoom":ne/100},children:[e.jsxs("div",{className:"fp-head",children:[e.jsx("span",{className:"fp-name",title:t.path,children:t.name}),e.jsx("span",{className:"fp-path",children:t.path}),e.jsxs("span",{className:"fp-meta",children:[o&&P==="text"&&!Z&&n("fileLines",{n:U}),o&&` · ${Za(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[le&&P==="text"&&!Z&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${L?"on":""}`,"data-tip":n(L?"showMarkdownSource":"showMarkdownPreview"),disabled:$,onClick:()=>M(J=>!J),children:L?e.jsx(St,{}):e.jsx(Yn,{})}),P==="text"&&!Z&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${$?"on":""}`,"data-tip":n(d?"fileEditTruncated":$?"exitEditFile":"editFile"),disabled:!te&&!$,onClick:A,children:e.jsx(Tt,{})}),P==="text"&&!Z&&!se&&e.jsx("button",{type:"button",className:`fp-attach wrap ${m?"on":""}`,"data-tip":n(m?"disableWrap":"enableWrap"),onClick:()=>B(J=>!J),children:e.jsx(Jn,{})}),P==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:ne<=50,onClick:()=>Q(ne-10),children:e.jsx(Pn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>H(100),children:[ne,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:ne>=200,onClick:()=>Q(ne+10),children:e.jsx(In,{})})]}),P!=="video"&&P!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Ct,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${W?"on":""}`,"data-tip":n(W?"exitFullscreen":"fullscreen"),onClick:()=>ee(J=>!J),children:W?e.jsx(_n,{}):e.jsx(Wn,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:oe,children:e.jsx(ke,{})})]})]}),d&&P==="text"&&!Z&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&P==="none"&&!Z&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&P==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:he(t.path),alt:t.name})}),!p&&P==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:he(t.path),controls:!0,preload:"metadata"})}),!p&&se&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(xt,{text:o.text})})}),!p&&Z&&P!=="image"&&P!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&$&&P==="text"&&!Z&&o&&e.jsx("textarea",{className:`fp-editor ${m?"":"no-wrap"}`,value:j,onChange:J=>R(J.target.value),wrap:m?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!se&&!$&&P==="text"&&!Z&&o&&S.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!se&&!$&&P==="text"&&!Z&&S.length>0&&e.jsxs("div",{className:`fp-code ${b?"dragging":""} ${m?"":"no-wrap"}`,onMouseDown:J=>{J.button===0&&J.preventDefault()},children:[S.map((J,re)=>{const ge=re+1,pe=g!==null&&ge>=g.start&&ge<=g.end;return e.jsxs("div",{className:`fp-line ${pe?"sel":""}`,onMouseDown:we=>{we.button===0&&(z(ge,we.shiftKey),I.current=!0,k(!0))},onMouseEnter:()=>{I.current&&z(ge,!0)},children:[e.jsx("span",{className:"fp-num",children:ge}),e.jsx("span",{className:"fp-code-text",children:J})]},ge)}),_&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:wt})})]}),e.jsx("div",{className:"fp-foot",children:$?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:A,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:j===((o==null?void 0:o.text)??""),onClick:Y,children:[e.jsx(Fn,{})," ",n("saveFile")]})]})]}):!se&&P==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:g?n("selectedRange",{n:ue,start:g.start,end:g.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:S.length===0,onClick:N,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!g,onClick:()=>v(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!g||Z,onClick:X,children:[D?e.jsx(gt,{}):null,n(D?"addedToChat":"addToChat")]})]})]})})]})})}function Nt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Za(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const cn="pi-web-sounds",Je={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function dn(){try{const t=localStorage.getItem(cn);if(!t)return{...Je};const s=JSON.parse(t),i={...Je,...s};for(const l of["enabled","question","done","start","error"])typeof i[l]!="boolean"&&(i[l]=Je[l]);return typeof i.volume!="number"||!Number.isFinite(i.volume)?i.volume=Je.volume:i.volume=Math.round(Math.max(0,Math.min(100,i.volume))/5)*5,i}catch{return{...Je}}}function er(t){try{localStorage.setItem(cn,JSON.stringify(t))}catch{}}let Ye=null;function tr(){try{if(!Ye){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;Ye=new t}return Ye.state==="suspended"&&Ye.resume(),Ye}catch{return null}}const sr=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],nr=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],ir=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],ar=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],rr={question:sr,done:nr,start:ir,error:ar};function lr(t,s,i){const l=t.createOscillator(),c=t.createGain();l.type=s.type,l.frequency.value=s.freq;const r=t.currentTime+s.start,n=Math.max(1e-4,s.peak*i);c.gain.setValueAtTime(1e-4,r),c.gain.exponentialRampToValueAtTime(n,r+.012),c.gain.exponentialRampToValueAtTime(1e-4,r+s.dur),l.connect(c),c.connect(t.destination),l.start(r),l.stop(r+s.dur+.05)}function Qe(t,s=dn()){if(!s.enabled||!s[t])return;const i=tr();if(!i)return;const l=Math.max(0,Math.min(1,s.volume/100));for(const c of rr[t])lr(i,c,l)}const Lt="pi-web-ui:theme",un="dark",Ns="theme-stylesheet",Cs="pi-web-ui:theme-change";function pn(){try{const t=localStorage.getItem(Lt);if(t&&t!==un)return t}catch{}return null}function or(t){try{t?localStorage.setItem(Lt,t):localStorage.removeItem(Lt)}catch{}}function mn(t){let s=document.getElementById(Ns);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Cs));return}s||(s=document.createElement("link"),s.id=Ns,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(Cs))}async function cr(){try{const t=await fetch(ft("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function dr(){const[t,s]=a.useState([]),[i,l]=a.useState(()=>pn());return a.useEffect(()=>{let r=!1;return cr().then(n=>{r||s(n)}),()=>{r=!0}},[]),a.useEffect(()=>{mn(i),or(i)},[i]),{themes:t,theme:i,switchTheme:r=>l(r===un?null:r)}}function vr(){const t=getComputedStyle(document.documentElement),s=(i,l)=>t.getPropertyValue(i).trim()||l;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const ur=a.lazy(()=>Rs(()=>import("./TerminalPanel-CsLJErXe.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function pr({notice:t,onDismiss:s}){const i=me(),[l,c]=a.useState(!1);a.useEffect(()=>{if(l)return;const n=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(n)},[l,t.id,t.level,s]);const r=t.level==="error"?ei:t.level==="warning"?Zn:Un;return e.jsxs("div",{className:`notice notice-${t.level}${l?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(r,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:t.text}),e.jsx("button",{type:"button",className:"notice-close",title:i("close"),onClick:()=>s(t.id),children:e.jsx(ke,{})})]})}const mr=[],hn=180,gn=520,fn=240,xn=t=>`pi-web-ui:${t}-panel-width`;function Ss(t){const s=Number(localStorage.getItem(xn(t)));return Number.isFinite(s)&&s>=hn&&s<=gn?s:fn}function Ts({side:t,width:s,onResize:i}){const l=me(),c=a.useCallback(r=>{r.preventDefault();const n=r.clientX,o=s;let u=o;const p=g=>{const v=t==="left"?g.clientX-n:n-g.clientX;u=Math.min(gn,Math.max(hn,Math.round(o+v))),i(u)},h=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",h),document.body.classList.remove("panel-resizing"),localStorage.setItem(xn(t),String(u))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",h),document.body.classList.add("panel-resizing")},[t,s,i]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:l("dragToResize"),onPointerDown:c,onDoubleClick:()=>i(fn)})}function hr(){var V,O,ie,de,ye,Se,Ot,Wt,Ht,qt,Kt,Ut,zt,Vt;const t=me(),{chat:s,send:i,dismissNotice:l,pushNotice:c,terminal:r}=Ni(),[n,o]=a.useState([]),[u,p]=a.useState(null),[h,g]=a.useState(!1),[v,b]=a.useState("chat"),k=a.useMemo(()=>s.plugins.filter(F=>{var q,ae;return!((ae=(q=s.settings)==null?void 0:q.disabledPlugins)!=null&&ae.includes(F.id))}),[s.plugins,(V=s.settings)==null?void 0:V.disabledPlugins]),[D,E]=a.useState([]);a.useEffect(()=>gi(E),[]),a.useEffect(()=>{fi(k,s.pluginsEpoch)},[k,s.pluginsEpoch]);const[$,y]=a.useState(()=>Ss("left")),[j,R]=a.useState(()=>Ss("right")),L=a.useCallback(F=>y(F),[]),M=a.useCallback(F=>R(F),[]),[C,m]=a.useState(null),[B,W]=a.useState(()=>window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),q=ae=>W(ae.matches);return F.addEventListener("change",q),()=>F.removeEventListener("change",q)},[]);const[ee,ne]=a.useState(!1),[H,K]=a.useState(!1),[I,T]=a.useState(!1),[S,U]=a.useState(!1),[_,z]=a.useState(!1);a.useEffect(()=>{const F=q=>{var Pe,Gt;const ae=q.detail,fe=(ae==null?void 0:ae.title)||"插件命令",xe=ae==null?void 0:ae.command;if(!xe||!s.ready)return;const je={name:fe,command:xe,cwd:"${pwd}"},ve=s.terminals.find(vt=>vt.title===fe);if(ve)r.restart(ve.id),i({type:"run_command",terminalId:ve.id,conversationId:ve.conversationId,command:je,cols:80,rows:24});else{const vt=De();r.create({id:vt,conversationId:s.activeConversationId||((Pe=s.state)==null?void 0:Pe.conversationId)||"",title:fe,cwd:((Gt=s.state)==null?void 0:Gt.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:je})}b("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,r,i]),a.useEffect(()=>{const F=q=>{!(q.ctrlKey||q.metaKey)||q.key.toLowerCase()!=="k"||(q.preventDefault(),z(ae=>!ae))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[N,X]=a.useState(dn),{themes:te,theme:ce,switchTheme:A}=dr(),Y=a.useRef(null),oe=a.useRef(null),Q=a.useRef(0),ue=a.useRef(!1),Z=a.useRef(s.terminals);a.useEffect(()=>{er(N)},[N]),a.useEffect(()=>{var q;const F=Z.current;Z.current=s.terminals;for(const ae of s.terminals){const fe=((q=ae.command)==null?void 0:q.command)??"",xe=F.find(je=>je.id===ae.id);!(xe!=null&&xe.running)||ae.running||(fe.startsWith("pi remove ")?i({type:"extensions_reload"}):(fe.startsWith("pi-web-ui install ")||fe.startsWith("pi-web-ui uninstall "))&&i({type:"plugins_reload"}))}},[s.terminals,i]),a.useEffect(()=>{var ae;const F=((ae=s.state)==null?void 0:ae.isStreaming)??!1,q=Y.current;Y.current=F,q!==null&&(!q&&F?Qe("start",N):q&&!F&&Qe("done",N))},[(O=s.state)==null?void 0:O.isStreaming,N]),a.useEffect(()=>{var q;const F=((q=s.dialog)==null?void 0:q.id)??null;F!==null&&F!==oe.current&&Qe("question",N),oe.current=F},[s.dialog,N]),a.useEffect(()=>{const F=[...s.notices].reverse().find(q=>q.level==="error");F&&F.id!==Q.current&&(Q.current=F.id,Qe("error",N))},[s.notices,N]);const d=(F,q,ae,fe=!1,xe)=>{const je=`${F}|${ae}|${xe?`${xe.start}-${xe.end}`:""}`;o(ve=>ve.some(Pe=>`${Pe.path}|${Pe.mode}|${Pe.lines?`${Pe.lines.start}-${Pe.lines.end}`:""}`===je)?ve:[...ve,{path:F,name:q,mode:ae,isDir:fe,...xe?{lines:xe}:{}}])},P=F=>o(q=>q.filter(ae=>ae.key?ae.key!==F:ae.path!==F)),le=a.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&m(null),i(F)),[i]),se=a.useRef(0),he=a.useRef(0),J=F=>{var fe;const q=Date.now();(fe=s.state)!=null&&fe.model&&!s.state.model.vision&&q-he.current>1e4&&(he.current=q,c("warning",t("imageNotSupported")));const ae=`paste-${++se.current}`;o(xe=>[...xe,{path:"",key:ae,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},re=async F=>{for(const q of F){const ae=await Gs(q);if(!ae){c("error",t("imageLoadFailed",{name:q.name}));continue}J(ae)}},ge=20*1024*1024,pe=a.useRef(0),we=async F=>{if(F.size>ge){c("warning",t("fileTooLarge",{name:F.name,size:ge/1024/1024}));return}let q;try{q=(await new Promise((xe,je)=>{const ve=new FileReader;ve.onload=()=>xe(ve.result),ve.onerror=()=>je(ve.error??new Error("read failed")),ve.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const ae=`upload-${++pe.current}`;o(fe=>[...fe,{path:"",key:ae,name:F.name,mode:"inline",fileData:q,size:F.size,mimeType:F.type||void 0}])},Be=async F=>{for(const q of F)Me(q.type)?await re([q]):await we(q)},_e=a.useCallback((F,q,ae)=>{i({type:"edit_message",messageId:F,text:q,attachments:ae})},[i]),Ve=a.useCallback(()=>K(!0),[]),Ge=a.useCallback(()=>o([]),[]),Ce=a.useCallback(P,[]),Oe=a.useCallback(re,[re]),Fe=a.useCallback(Be,[Be]),Ne=(ie=s.state)==null?void 0:ie.model,Re=(de=s.state)==null?void 0:de.thinkingLevel,w=(ye=s.state)==null?void 0:ye.availableThinkingLevels,f=a.useMemo(()=>Ne?{model:Ne,thinkingLevel:Re??"off",availableThinkingLevels:w??[]}:null,[Ne,Re,w]),x=a.useCallback(()=>{var F,q;return!s.ready||s.terminals.length!==0?!1:(r.create({id:De(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((q=s.state)==null?void 0:q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Se=s.state)==null?void 0:Se.cwd,s.terminals.length,t,r]);return a.useEffect(()=>{if(ue.current){if(v!=="terminal"||s.terminals.length!==0){ue.current=!1;return}x()&&(ue.current=!1)}},[s.terminals.length,x,v]),e.jsxs("div",{className:"app",onDragOver:F=>{var q;Array.from(((q=F.dataTransfer)==null?void 0:q.types)??[]).includes("Files")&&(F.preventDefault(),g(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||g(!1)},onDrop:F=>{var xe,je;if(g(!1),!Array.from(((xe=F.dataTransfer)==null?void 0:xe.types)??[]).includes("Files"))return;F.preventDefault();const q=Array.from(((je=F.dataTransfer)==null?void 0:je.files)??[]);if(q.length===0){c("warning",t("foldersNotSupported"));return}const ae=q.filter(ve=>Me(ve.type)),fe=q.filter(ve=>!Me(ve.type));ae.length>0&&re(ae),fe.length>0&&Be(fe)},children:[h&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(ri,{chat:s,send:i,terminal:r,view:v,plugins:k,onViewChange:F=>{ue.current=F==="terminal"&&s.terminals.length===0,ue.current&&x()&&(ue.current=!1),b(F),m(null)},onOpenPanel:m,onOpenSettings:()=>T(!0),onOpenBgTasks:()=>U(!0),onOpenGlobalSearch:()=>z(!0),sound:N,onSoundChange:X,onSoundPreview:F=>Qe(F,N),themes:te,theme:ce,onThemeChange:A}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(pr,{notice:F,onDismiss:l},F.id))}),e.jsx(ba,{send:i,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${$}px`,"--right-w":`${j}px`},children:[C&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>m(null)}),e.jsxs("div",{className:`view-pane ${v==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${C==="left"?"open":""}`,children:e.jsx(oi,{send:le,active:!B||C==="left",ready:s.ready,status:s.status,cwd:((Ot=s.state)==null?void 0:Ot.cwd)??"",sessionFile:((Wt=s.state)==null?void 0:Wt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!B&&e.jsx(Ts,{side:"left",width:$,onResize:L}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ta,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:_e,onKillBash:()=>i({type:"abort_bash"}),thinkingWrap:((Ht=s.settings)==null?void 0:Ht.thinkingWrap)??!0,toolsWrap:((qt=s.settings)==null?void 0:qt.toolsWrap)??!0},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(Fa,{send:i,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(_a,{dialog:s.dialog,send:i}),e.jsx(Ba,{send:i,ready:s.ready,streaming:((Kt=s.state)==null?void 0:Kt.isStreaming)??!1,messages:((Ut=s.state)==null?void 0:Ut.messages)??mr,slashCommands:s.slashCommands,modelState:f,models:s.models,modelsLoading:s.modelsLoading,attachments:n,onRemoveAttachment:Ce,onAddImageFiles:Oe,onAddLocalFiles:Fe,onNotice:c,onManageModels:Ve,onSent:Ge})]}),!B&&e.jsx(Ts,{side:"right",width:j,onResize:M}),e.jsx("div",{className:`panel-drawer drawer-right ${C==="right"?"open":""}`,children:e.jsx(Li,{send:le,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((zt=s.state)==null?void 0:zt.cwd)??"",onAttach:(F,q,ae,fe)=>{m(null),d(F,q,ae,fe)},onPreview:(F,q)=>{m(null),p({path:F,name:q})},onNotice:(F,q)=>c(F,q)})})]}),e.jsx("div",{className:`view-pane ${v==="terminal"?"":"hidden"}`,children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(ur,{chat:s,send:i,terminal:r})})}),e.jsx("div",{className:`view-pane ${v==="git"?"":"hidden"}`,children:e.jsx(Wa,{chat:s,send:i,terminal:r,active:v==="git",onSwitchToTerminal:()=>b("terminal")})}),D.map(F=>{const q=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${v===q?"":"hidden"}`,children:e.jsx(Ha,{entry:F,send:i})},F.info.id)})]})}),e.jsx($a,{chat:s,send:i}),u&&e.jsx(Xa,{file:u,content:s.fileContent,send:i,onAddLines:(F,q,ae,fe)=>d(F,q,"lines",!1,{start:ae,end:fe}),onAttach:(F,q,ae)=>d(F,q,ae),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!ee&&!H&&e.jsx(qa,{send:i,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>ne(!0)}),H&&e.jsx(za,{send:i,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>K(!1)}),I&&e.jsx(Ga,{chat:s,send:i,terminal:r,onSwitchToTerminal:()=>b("terminal"),onClose:()=>T(!1)}),S&&e.jsx(Ya,{servers:s.bgServers,send:i,onClose:()=>U(!1)}),_&&e.jsx(Qa,{send:i,sessions:s.sessions,projects:s.projects,cwd:((Vt=s.state)==null?void 0:Vt.cwd)??"",fileSearch:s.fileSearch,onClose:()=>z(!1),onSwitchSession:F=>{i({type:"switch_session",path:F})},onSwitchProject:F=>{i({type:"set_cwd",path:F})},onPreviewFile:(F,q)=>{p({path:F,name:q})}})]})}ci();mn(pn());bn.createRoot(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(ii,{children:e.jsx(hr,{})})}));export{pt as F,Cs as T,Le as a,vr as b,xr as c,Et as d,Ee as e,ke as f,On as g,Ke as h,De as r,me as u};
|
|
305
|
+
`)})]})}):null})()]})});var ds=Ms();const Ks=r.memo(function({text:s}){const a=me(),[l,c]=r.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:l?e.jsx(gt,{}):e.jsx(Bt,{})}):null});function Di(t){const s=l=>{var c;if(typeof l=="string"||typeof l=="number"){const i=String(l);return i===""?[[]]:i.split(`
|
|
306
|
+
`).map(n=>n===""?[]:[n])}if(Array.isArray(l)){let i=[];for(const n of l){const o=s(n);if(i.length===0)i=o;else{const u=o[0]??[];i[i.length-1].push(...u),i.push(...o.slice(1))}}return i}if(l&&typeof l=="object"&&"props"in l){const i=l,n=(c=i.props)==null?void 0:c.children,o={...i.props??{},children:void 0},u=n==null?[]:s(n);return u.length===0?[[r.createElement(i.type,o)]]:u.map(p=>[r.createElement(i.type,o,...p)])}return[[l]]},a=s(t);return a.length>1&&a[a.length-1].length===0&&a.pop(),a}const Us=[yn],zs=[[vn,{detect:!0,ignoreMissing:!0}]];function Vs({text:t}){return e.jsx(Es,{remarkPlugins:Us,rehypePlugins:zs,components:{pre:Bi},children:t})}const xt=r.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(Vs,{text:s})})});function Bi({children:t,...s}){var n;const a=t&&typeof t=="object"&&"props"in t?(n=t.props)==null?void 0:n.children:t,l=Di(a),c=l.length>1,i=c?`${String(l.length).length+1}ch`:void 0;return e.jsxs("div",{className:"codeblock",children:[e.jsx(Ks,{text:It(t)}),e.jsx("pre",{...s,children:l.map((o,u)=>e.jsxs("div",{className:"code-line",children:[c&&e.jsx("span",{className:"code-num",style:i?{width:i}:void 0,children:u+1}),e.jsx("code",{className:"code-line-body hljs",children:o})]},u))})]})}function It(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(It).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return It(s==null?void 0:s.children)}return""}const Fi=/^\s{0,3}(`{3,}|~{3,})/,Ai=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function bt(t){return t.trim()===""}function us(t){const s=Fi.exec(t);return s?s[1]:null}function $i(t){const s=t.split(`
|
|
307
|
+
`),a=[];let l=[],c=null;for(let i=0;i<s.length;i++){const n=s[i];if(c!==null){const u=us(n);u&&u[0]===c[0]&&u.length>=c.length&&(c=null),l.push(n);continue}const o=us(n);if(o&&!bt(n)){c=o,l.push(n);continue}if(bt(n)){let u=i;for(;u<s.length&&bt(s[u]);)u++;if(!(u<s.length&&Ai.test(s[u]))&&l.length>0){a.push(l.join(`
|
|
308
|
+
`)),l=[];continue}l.push(n);continue}l.push(n)}return{frozen:a,active:l.join(`
|
|
309
|
+
`),inFence:c!==null}}const _i=r.memo(function({text:s}){return e.jsx(Es,{remarkPlugins:Us,rehypePlugins:zs,children:s})}),ps=200;function Oi({text:t,inFence:s}){const[a,l]=r.useState(t),c=r.useRef(0),i=r.useRef(null);return r.useEffect(()=>{if(s)return;const n=Date.now()-c.current,o=()=>{c.current=Date.now(),l(t)};if(n>=ps){o();return}return i.current=setTimeout(o,ps-n),()=>{i.current&&clearTimeout(i.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx(Vs,{text:a})}const Wi=r.memo(function({text:s}){const{frozen:a,active:l,inFence:c}=r.useMemo(()=>$i(s),[s]);return e.jsxs("div",{className:"md",children:[a.map((i,n)=>e.jsx(_i,{text:i},n)),l.length>0&&e.jsx(Oi,{text:l,inFence:c},a.length)]})});function Hi({thinking:t,streaming:s,wrap:a=!0}){const l=me(),[c,i]=r.useState(null),n=c??a,o=s?t.trimEnd().slice(-80):t.split(`
|
|
310
|
+
`)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${n?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>i(!n),children:[n?e.jsx($e,{}):e.jsx(ht,{}),e.jsx(Xe,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s&&n?e.jsxs("span",{className:"thinking-live-label",children:[l("thinkingNow"),e.jsx("span",{className:"dots"})]}):n?l("thinking"):l("thinkingPreview",{preview:o})})]}),n&&e.jsx("div",{className:"thinking-body",children:t})]})}const qi={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function Ki(t){return qi[t]??"🛠"}const Ui=r.memo(function({block:s,view:a,onKillBash:l,wrap:c=!0}){var L,M,C,m;const i=me(),[n,o]=r.useState(c),[u,p]=r.useState(!1),h=!a.result&&a.streaming&&!a.status,g=s.name==="bash"&&h,v=a.result!==void 0,b=!a.result&&!!a.status,k=((L=a.result)==null?void 0:L.isError)??((M=a.status)==null?void 0:M.isError)??!1,D=a.result?a.result.content.map(B=>B.type==="text"?B.text:"").join(""):a.liveOutput??"",E=k?"err":v?"ok":h||b?"run":"idle";let A=i(k?"error":v?"done":h?"running":b?"toolDoneWaitingModel":"toolQueued");const y=b&&((C=a.status)==null?void 0:C.durationMs)!==void 0?Vi(a.status.durationMs):"";b&&y&&(A=`${A} · ${y}`);const j=b&&((m=a.status)==null?void 0:m.exitCode)!==void 0?`exit ${a.status.exitCode}`:"",R=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),p(!0),setTimeout(()=>p(!1),1200))};return e.jsxs("div",{className:`toolcall ${E}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:Ki(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[A,j&&e.jsx("em",{className:"toolcall-exit",children:j})]}),e.jsx("span",{className:"toolcall-spacer"}),g&&l&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:i("stopBashTip"),onClick:l,children:[e.jsx(ot,{}),e.jsx("span",{children:i("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:i("copyArgs"),onClick:R,children:u?e.jsx(Qn,{}):e.jsx(Bt,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>o(B=>!B),children:n?e.jsx($e,{}):e.jsx(ht,{})})]}),n&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(zi,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),D.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[i(k?"errorOutput":"output"),(h||b)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:D})]}),h&&D.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",i("waitingOutput")]}),b&&D.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",i("waitingModel")]})]})]})});function zi({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(Ke,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function Vi(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const a=Math.floor(s/60),l=Math.round(s%60);return`${a}m ${String(l).padStart(2,"0")}s`}const Gi=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function $t(t){var a;const s=t.match(Gi);return s?{name:s[1],location:s[2],content:s[3],userMessage:((a=s[4])==null?void 0:a.trim())||void 0}:null}const Ji=1568,Yi=2*1024*1024;function Me(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function Gs(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,Ji/Math.max(s.width,s.height)),l=Math.max(1,Math.round(s.width*a)),c=Math.max(1,Math.round(s.height*a)),i=t.type==="image/jpeg"||t.type==="image/jpg"?[["image/jpeg",.85],["image/jpeg",.6],["image/webp",.8]]:[["image/png",1],["image/jpeg",.85],["image/jpeg",.6]];let n=null;for(const[o,u]of i){const p=document.createElement("canvas");p.width=l,p.height=c;const h=p.getContext("2d");if(!h)continue;o!=="image/png"&&(h.fillStyle="#ffffff",h.fillRect(0,0,l,c)),h.drawImage(s,0,0,l,c);const g=p.toDataURL(o,u),v=g.match(/^data:([^;]+);base64,/),b=v?v[1]:o,k=g.replace(/^data:[^;]*;base64,/,""),D=Math.floor(k.length*3/4);if(n={data:k,mimeType:b,name:t.name,size:D},D<=Yi)return n}return n}finally{s.close()}}const Qi=20*1024*1024;function Ze(t){return t.type==="text"&&typeof t.text=="string"?t:null}function Js(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function Ys(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function Qs(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function Xs(t){return t.type==="bash"&&typeof t.command=="string"?t:null}function Xi(t){return t.imageData?"image":t.uploadPath?"upload":t.fileData?"file":"path"}function Zi(t,s){if(t.imageData)return s("attachImage",{name:t.name??"image"});if(t.uploadPath)return s("attachFile",{name:t.name??t.uploadPath});if(t.fileData)return s("attachFile",{name:t.name??"file"});const a=t.path.split("/").pop()??t.path;return t.mode==="lines"&&t.lines?s("attachLines",{path:a,start:t.lines.start,end:t.lines.end}):t.mode==="reference"?s("refOnly",{path:a}):s("attachContent",{path:a})}const ms=r.memo(function({message:s,toolResults:a,liveOutputs:l,toolStatuses:c,streaming:i,isLast:n,onEdit:o,onKillBash:u,onCollapse:p,questionAttachments:h,qnIndex:g,qnActive:v,onJump:b,thinkingWrap:k,toolsWrap:D}){const E=me(),[A,y]=r.useState(!1),[j,R]=r.useState(""),[L,M]=r.useState([]),[C,m]=r.useState(!1),[B,W]=r.useState(null),ee=$=>{W($),window.setTimeout(()=>W(Y=>Y===$?null:Y),4e3)};if(s.role==="toolResult")return null;const ne=s.role==="custom"&&s.customType==="file",H=s.content.map($=>{var Y;return((Y=Ze($))==null?void 0:Y.text)??""}).filter(Boolean).join(`
|
|
311
|
+
`),K=s.role==="user"?$t(H):null,I=K?K.userMessage??`skill:${K.name}`:H.split(`
|
|
312
|
+
`).join(" ").trim(),T=i&&n&&s.content.length===0,S=s.role==="user"&&!i&&!T&&!!o,U=async $=>{const Y=[];for(const oe of $){if(!Me(oe.type))continue;const Q=await Gs(oe);Q&&Y.push({path:"",imageData:Q.data,mimeType:Q.mimeType,name:Q.name})}Y.length>0&&M(oe=>[...oe,...Y])},_=async $=>{if($.size>Qi){ee(E("fileTooLarge",{name:$.name,size:20}));return}let Y;try{Y=(await new Promise((Q,ue)=>{const Z=new FileReader;Z.onload=()=>Q(Z.result),Z.onerror=()=>ue(Z.error??new Error("read failed")),Z.readAsDataURL($)})).replace(/^data:[^;]*;base64,/,"")}catch{ee(E("fileLoadFailed",{name:$.name}));return}M(oe=>[...oe,{path:"",fileData:Y,name:$.name,size:$.size,mimeType:$.type||void 0}])},z=async $=>{const Y=[];for(const oe of $)Me(oe.type)?Y.push(oe):_(oe);Y.length>0&&await U(Y)},N=()=>{R(K?`/skill:${K.name}${K.userMessage?` ${K.userMessage}`:""}`:s.content.map($=>{var Y;return((Y=Ze($))==null?void 0:Y.text)??""}).filter(Boolean).join(`
|
|
313
|
+
`)),M(h??[]),y(!0)},X=()=>{const $=j.trim();$&&(o==null||o(s.id,$,L.length>0?L:void 0),y(!1))},te=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),ce=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${te?" 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"?ce?E("goalWizardCard"):te?E("goalBarTitle"):s.customType==="file"?E("attachment"):`${E("plugin")} · ${s.customType??E("unknown")}`:Zs(s.role,E)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:na(s.timestamp)}),p&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:E("collapseMsg"),onClick:()=>p(s.id),children:[e.jsx(mt,{})," ",E("collapseMsg")]}),g!==void 0&&b&&e.jsxs("button",{type:"button",className:`qn-tag ${v?"active":""}`,title:`${g+1}. ${I}`,"aria-label":`${g+1}. ${I}`,onClick:()=>b(s.id),children:[e.jsx("span",{className:"qn-tag-bar"}),e.jsx("span",{className:"qn-tag-idx",children:g+1})]})]}),e.jsx("div",{className:"msg-body",children:A?e.jsxs("div",{className:`msg-editor${C?" drag-over":""}`,onDragOver:$=>{$.preventDefault(),$.stopPropagation(),m(!0)},onDragLeave:$=>{$.currentTarget.contains($.relatedTarget)||m(!1)},onDrop:$=>{var Y;$.preventDefault(),$.stopPropagation(),m(!1),z(Array.from(((Y=$.dataTransfer)==null?void 0:Y.files)??[]))},children:[L.length>0&&e.jsx("div",{className:"msg-editor-images",children:L.map(($,Y)=>{var Q;const oe=Xi($);return e.jsxs("span",{className:`msg-editor-img ${oe==="image"?"":"file-chip"}`,title:Zi($,E),children:[oe==="image"?e.jsx("img",{src:`data:${$.mimeType??"image/png"};base64,${$.imageData}`,alt:$.name}):e.jsxs("span",{className:"msg-editor-file",children:[e.jsx("span",{className:"msg-editor-file-icon",children:oe==="path"?$.mode==="reference"?"🔗":"📎":"📄"}),e.jsx("span",{className:"msg-editor-file-name",children:$.name??((Q=$.path)==null?void 0:Q.split("/").pop())})]}),e.jsx("button",{type:"button",className:"msg-editor-img-remove",title:E("removeAttachment"),onClick:()=>M(ue=>ue.filter((Z,d)=>d!==Y)),children:e.jsx(ke,{})})]},`${$.name??$.path??"att"}-${Y}`)})}),B&&e.jsx("div",{className:"msg-editor-notice",children:B}),e.jsx("textarea",{className:"msg-editor-input",value:j,autoFocus:!0,placeholder:E("editPlaceholder"),rows:Math.max(2,Math.min(10,j.split(`
|
|
314
|
+
`).length+1)),onChange:$=>R($.target.value),onPaste:$=>{var oe;const Y=[];for(const Q of((oe=$.clipboardData)==null?void 0:oe.items)??[])if(Q.kind==="file"&&Me(Q.type)){const ue=Q.getAsFile();ue&&Y.push(ue)}Y.length!==0&&($.preventDefault(),U(Y))},onKeyDown:$=>{$.key==="Enter"&&($.metaKey||$.ctrlKey)?($.preventDefault(),X()):$.key==="Escape"&&y(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsxs("span",{className:"msg-editor-hint",children:[e.jsx(zn,{})," ",E("editAttachmentHint")]}),e.jsx("button",{type:"button",className:"chip",onClick:()=>y(!1),children:E("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!j.trim(),title:E("reaskFromHere"),onClick:X,children:[e.jsx(Tt,{})," ",E("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),ne?e.jsx(ea,{message:s}):K?e.jsxs(e.Fragment,{children:[e.jsx(sa,{block:K}),K.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(xt,{text:K.userMessage})}),s.content.map(($,Y)=>$.type==="text"?null:e.jsx(gs,{block:$,toolResults:a,liveOutputs:l,toolStatuses:c,streaming:i,isLast:n,onKillBash:u,toolsWrap:D,thinkingWrap:k},`${s.id}-${Y}`))]}):s.content.map(($,Y)=>e.jsx(gs,{block:$,toolResults:a,liveOutputs:l,toolStatuses:c,streaming:i,isLast:n,onKillBash:u,toolsWrap:D,thinkingWrap:k},`${s.id}-${Y}`)),T&&e.jsxs("div",{className:"thinking-wait",children:[E("thinkingWait"),e.jsx("span",{className:"dot"})]}),i&&n&&!T&&e.jsx("span",{className:"stream-cursor"})]})}),S&&!A&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:E("editReaskTip"),onClick:N,children:[e.jsx(Tt,{})," ",E("editReask")]})})]})});function ea({message:t}){const s=me(),[a,l]=r.useState(!1),c=t.details??{},i=c.name??c.path??s("attachment"),n=c.type==="folder",o=c.mode==="reference",u=c.mode==="bridged",p=t.content.filter(b=>b.type==="text").map(b=>b.text).join(`
|
|
315
|
+
`),h=ta(p),g=t.content.find(b=>b.type==="image"),v=h.split(`
|
|
316
|
+
`).length;return e.jsxs("div",{className:`attachcard ${o?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>l(b=>!b),children:[e.jsx("span",{className:"attachcard-icon",children:n?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:i}),c.path&&e.jsx("span",{className:"attachcard-path",children:c.path}),e.jsx("span",{className:`attachcard-mode ${c.mode==="lines"?"lines":o?"ref":u?"bridged":"inline"}`,children:o?n?s("folderRefShort"):`${s("refOnlyShort")} · ${hs(c.size)}`:u?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??v})}),!o&&(a?e.jsx($e,{}):e.jsx(ht,{}))]}),!o&&a&&(u?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:i})}),h&&e.jsx("pre",{className:"attachcard-content",children:h})]}):g!=null&&g.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:g.dataUrl,alt:i})}):e.jsx("pre",{className:"attachcard-content",children:h})),o&&e.jsx("div",{className:"attachcard-refnote",children:n?s("folderNotExpanded"):s("fileNotExpanded",{size:hs(c.size)})})]})}function hs(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function ta(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 sa({block:t}){const s=me(),[a,l]=r.useState(!1);return e.jsxs("div",{className:`skillcard${a?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>l(c=>!c),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(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(mt,{}):e.jsx($e,{}),s(a?"collapseMsg":"expandMsg")]})]}),a&&e.jsx("div",{className:"skillcard-body",children:e.jsx(xt,{text:t.content})})]})}function gs({block:t,toolResults:s,liveOutputs:a,toolStatuses:l,streaming:c,isLast:i,onKillBash:n,thinkingWrap:o,toolsWrap:u}){const p=me(),h=Ze(t);if(h){const D=c&&i;return e.jsxs("div",{className:"msg-text",children:[D?e.jsx(Wi,{text:h.text}):e.jsx(xt,{text:h.text}),h.truncated&&e.jsx("div",{className:"trunc-note",children:p("truncated")})]})}const g=Js(t);if(g)return e.jsx(Hi,{thinking:g.thinking,streaming:c&&i,wrap:o});const v=Ys(t);if(v){const D=s.get(v.id),E=a.get(v.id),A={result:D,liveOutput:E==null?void 0:E.text,streaming:c,status:l.get(v.id)};return e.jsx(Ui,{block:v,view:A,onKillBash:n,wrap:u})}const b=Qs(t);if(b&&b.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:b.dataUrl,alt:"attachment"})});const k=Xs(t);return k?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:k.command}),k.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${k.exitCode===0?"ok":"err"}`,children:p("exitCode",{code:k.exitCode})}),k.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:p("cancelled")})]}),k.output&&e.jsx("pre",{className:"bashblock-output",children:k.output}),k.truncated&&e.jsx("div",{className:"trunc-note",children:p("outputTruncated")})]}):null}function Zs(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 na(t){const s=new Date(t),a=String(s.getHours()).padStart(2,"0"),l=String(s.getMinutes()).padStart(2,"0");return`${a}:${l}`}function fs(t,s,a){let l=!1;for(const c of s){const i=c;if(i.type!=="image"||typeof i.dataUrl!="string"||!i.dataUrl.startsWith("data:"))continue;const n=i.dataUrl.match(/^data:([^;]*);base64,(.+)$/);n&&(l=!0,t.push({path:"",imageData:n[2],mimeType:n[1]||"image/png",name:a??`image.${(n[1]||"image/png").split("/")[1]??"png"}`}))}return l}function ia(t){const s=new Map;for(let a=0;a<t.length;a++){const l=t[a];if(l.role!=="user"||!l.id)continue;const c=[];fs(c,l.content);for(let i=a+1;i<t.length&&t[i].role==="custom"&&t[i].customType==="file";i++){const n=t[i].details??{};if(!fs(c,t[i].content,n.name)){if(n.upload&&n.path){c.push({path:"",uploadPath:n.path,name:n.name??n.path,size:n.size});continue}if(n.path&&n.mode){const o=n.mode==="inline"||n.mode==="lines"?n.mode:"reference",u={path:n.path,mode:o};n.mode==="lines"&&typeof n.startLine=="number"&&typeof n.endLine=="number"&&(u.lines={start:n.startLine,end:n.endLine}),c.push(u)}}}c.length>0&&s.set(l.id,c)}return s}const aa=r.memo(function({message:s,onExpand:a}){const l=me();let c="";for(const g of s.content){const v=Ze(g);if(v&&v.text.trim()){const b=$t(v.text);b?c=`skill:${b.name}`+(b.userMessage?` · ${b.userMessage.replace(/\s+/g," ").trim()}`:""):c=v.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,o=0,u=0,p=0;for(const g of s.content)Js(g)?n++:Ys(g)?o++:Xs(g)?u++:Qs(g)&&p++;const h=[];return n&&h.push(`${l("thinking")} ${n}`),o&&h.push(`${l("toolCalls")} ${o}`),u&&h.push(`${l("bashRuns")} ${u}`),p&&h.push(`${l("images")} ${p}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${l("expandMsg")} · ${c||h.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"?l("attachment"):Zs(s.role,l)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),h.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:h.map((g,v)=>e.jsx("span",{className:"msg-collapsed-chip",children:g},v))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:ra(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx($e,{})," ",l("expandMsg")]})]})});function ra(t){const s=new Date(t),a=String(s.getHours()).padStart(2,"0"),l=String(s.getMinutes()).padStart(2,"0");return`${a}:${l}`}const la=r.memo(function({id:s,show:a,height:l,containerRef:c,onMeasured:i,lazyRef:n,children:o}){const u=r.useRef(null),p=r.useRef(null);return r.useLayoutEffect(()=>{const h=p.current;if(p.current=a,!a||h!==!1)return;const g=u.current,v=c.current;if(!g||!v)return;const b=g.offsetHeight;i==null||i(s,b);const k=b-l;if(k!==0){const D=g.parentElement;D&&D.getBoundingClientRect().bottom<=v.getBoundingClientRect().top&&(v.scrollTop+=k)}},[a]),a?e.jsx("div",{ref:n,"data-lazy-id":s,children:e.jsx("div",{ref:u,children:o})}):e.jsx("div",{ref:n,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:l},"aria-hidden":"true"})});function oa(t,s,a,l){const c=[],i=[];let n=0;for(const o of t){if(a.has(o.id))continue;o.top<s.bottom&&o.bottom>s.top?l.has(o.id)&&c.push(o.id):l.has(o.id)||(i.push(o.id),o.bottom<=s.top&&(n+=o.bottom-o.top))}return{show:c,hide:i,shrinkAbove:n}}function ca(t,s){if(s.show.length===0&&s.hide.length===0)return t;const a=new Set(t);for(const l of s.show)a.delete(l);for(const l of s.hide)a.add(l);return a}function da(t,s,a){const l=new Set;let c=0;for(let i=t.length-1;i>=0&&!(i<t.length-1&&c>=a);i--){const n=t[i];l.add(n.id),c+=s.get(n.id)??en(n.role,n.customType)}return l}function en(t,s){switch(t){case"user":return 72;case"assistant":return 280;case"toolResult":return 8;case"custom":return s==="file"?96:72;default:return 60}}const ua=["text","thinking","argumentsText","output","command"];function pa(t){let s=0;for(const a of t.content){a.type==="image"&&(s+=1);for(const l of ua){const c=a[l];typeof c=="string"&&(s+=c.length)}}return s}function ma(t,s,a,l){const c=a.get(t);return c&&c.len===s?c.h:l}function ha(t){if(t.role==="toolResult")return"";const s=[];for(const a of t.content)ga(a,s);return t.errorMessage&&s.push(t.errorMessage),s.join(`
|
|
317
|
+
`)}function ga(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 fa(t,s){const a=s.trim().toLowerCase();if(!a)return 0;const l=t.toLowerCase();let c=0,i=l.indexOf(a);for(;i!==-1;)c++,i=l.indexOf(a,i+a.length);return c}function xa(t,s){const a=s.trim().toLowerCase();if(!a)return[];const l=[];for(const c of t){const i=ha(c);if(!i)continue;const n=fa(i,a);for(let o=0;o<n;o++)l.push({messageId:c.id,occurrence:o})}return l}function va(t,s){var n;const a=new Map,l=[],c=s.toLowerCase();if(!c)return{byMsg:a,all:l};const i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(o){const u=o.parentElement;return!u||u.closest(".search-bar")?NodeFilter.FILTER_REJECT:(o.textContent??"").toLowerCase().includes(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let o=i.nextNode();o;o=i.nextNode()){const u=(o.textContent??"").toLowerCase(),p=(n=o.parentElement)==null?void 0:n.closest("[data-msg-id]");if(!p)continue;const h=p.getAttribute("data-msg-id")??"";let g=u.indexOf(c);for(;g!==-1;){const v=document.createRange();v.setStart(o,g),v.setEnd(o,g+c.length),l.push(v);const b=a.get(h);b?b.push(v):a.set(h,[v]),g=u.indexOf(c,g+c.length)}}return{byMsg:a,all:l}}function He(t,s){const a=CSS;if(!a.highlights)return;if(s.length===0){a.highlights.delete(t);return}const l=window.Highlight;l&&a.highlights.set(t,new l(...s))}function ya({containerRef:t,messages:s,open:a,onClose:l,onEnsureExpanded:c}){const i=me(),n=r.useRef(null),[o,u]=r.useState(""),[p,h]=r.useState(0),g=r.useDeferredValue(o),v=a?g.trim():"",b=r.useMemo(()=>a?xa(s,v):[],[s,v,a]),k=r.useRef(b);k.current=b;const D=r.useRef(p);D.current=p,r.useEffect(()=>{a&&(h(0),requestAnimationFrame(()=>{var j;return(j=n.current)==null?void 0:j.select()}))},[a]),r.useEffect(()=>{if(!a)return;const j=R=>{R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),l())};return window.addEventListener("keydown",j,!0),()=>window.removeEventListener("keydown",j,!0)},[a,l]),r.useEffect(()=>(a||(He("msg-search",[]),He("msg-search-active",[])),()=>{He("msg-search",[]),He("msg-search-active",[])}),[a]);const E=r.useCallback(j=>{const R=t.current;if(!R)return;const L=R.querySelector(`[data-msg-id="${j}"]`);L&&(L.classList.remove("msg-flash"),L.offsetWidth,L.classList.add("msg-flash"))},[t]);r.useLayoutEffect(()=>{if(!a||!v)return;const j=t.current;if(!j)return;let R=!1,L=0;return L=requestAnimationFrame(()=>{var ee;if(R)return;const{byMsg:M,all:C}=va(j,v);He("msg-search",C);const m=k.current,B=m[Math.min(D.current,m.length-1)];if(!B)return;const W=(ee=M.get(B.messageId))==null?void 0:ee[B.occurrence];if(W){He("msg-search-active",[W]);const ne=W.startContainer.parentElement??j.querySelector(`[data-msg-id="${B.messageId}"]`);ne==null||ne.scrollIntoView({block:"center"})}else E(B.messageId)}),()=>{R=!0,cancelAnimationFrame(L)}},[a,v,b,t,E]);const A=r.useCallback(j=>{const R=k.current;if(R.length===0)return;const L=(D.current+j+R.length)%R.length;h(L),c(R[L].messageId)},[c]);if(!a)return null;const y=b.length;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:n,className:"search-input",type:"text",value:o,placeholder:i("searchPlaceholder"),onChange:j=>{u(j.target.value),h(0)},onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),A(j.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${y===0?"empty":""}`,children:y===0?i("searchNoResults"):`${Math.min(p+1,y)}/${y}`}),e.jsx("button",{type:"button",className:"search-btn",title:i("searchPrev"),disabled:y===0,onClick:()=>A(-1),children:e.jsx(mt,{})}),e.jsx("button",{type:"button",className:"search-btn",title:i("searchNext"),disabled:y===0,onClick:()=>A(1),children:e.jsx($e,{})}),e.jsx("button",{type:"button",className:"search-btn",title:i("searchClose"),onClick:l,children:e.jsx(ke,{})})]})}function ka(t){const{dSt:s,dSh:a,escaped:l,graceActive:c,stuck:i}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:a<0?{flipEscape:!1,reassert:i&&!l}:{flipEscape:!0,reassert:!1}}const tn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],sn="pi-web-ui:prompt-templates";function ba(){try{const t=localStorage.getItem(sn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(a=>!!a&&typeof a=="object"&&typeof a.id=="string"):[]}catch{return[]}}function xs(t){return tn.some(s=>s.id===t)}function tt(t){return typeof t.title=="string"}const nn=r.createContext(null);function an(){const t=r.useContext(nn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function ja({send:t,children:s}){const a=me(),[l,c]=r.useState(ba),[i,n]=r.useState(!1),[o,u]=r.useState(null),[p,h]=r.useState(!1),[g,v]=r.useState(!1),[b,k]=r.useState(!1);r.useEffect(()=>{try{localStorage.setItem(sn,JSON.stringify(l))}catch{}},[l]);const D=r.useMemo(()=>{const H=new Map,K=new Set;for(const S of l)S.hidden?K.add(S.id):(tt(S)&&!xs(S.id)||tt(S))&&H.set(S.id,S);const I=tn.filter(S=>!K.has(S.id)).map(S=>{const U=H.get(S.id);return{id:S.id,icon:(U==null?void 0:U.icon)??S.icon,title:(U==null?void 0:U.title)??a(S.titleKey),desc:(U==null?void 0:U.desc)??a(S.descKey),prompt:(U==null?void 0:U.prompt)??a(S.promptKey),builtin:!0}}),T=l.filter(S=>tt(S)&&!xs(S.id)).map(S=>({id:S.id,icon:S.icon??"📌",title:S.title??"",desc:S.desc??"",prompt:S.prompt??""}));return[...I,...T]},[l,a]),E=r.useCallback(()=>n(!0),[]),A=r.useCallback(H=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:H}))},[]),y=r.useCallback((H,K=!1)=>{k(K),H?(h(!1),u({...H})):(h(!0),u({id:De(),icon:"📌",title:"",desc:"",prompt:""}))},[]),j=r.useCallback(()=>{n(!1),u(null),k(!1)},[]),R=r.useCallback(()=>{g?(c([]),v(!1)):(v(!0),setTimeout(()=>v(!1),5e3))},[g]),L=r.useCallback(H=>{n(!1),A(H.prompt)},[A]),M=r.useCallback(H=>{n(!1),y(H,!0)},[y]),C=r.useCallback(()=>{n(!1),y(void 0,!0)},[y]),m=r.useCallback(H=>{c(K=>{const I=K.findIndex(T=>T.id===H.id);if(I>=0){const T=[...K];return T[I]=H,T}return[...K,H]}),u(null),b&&(n(!0),k(!1))},[b]),B=r.useCallback(H=>{c(K=>H.builtin?[...K.filter(T=>T.id!==H.id),{id:H.id,hidden:!0}]:K.filter(I=>I.id!==H.id)),u(null),b&&(n(!0),k(!1))},[b]),W=r.useCallback(H=>{c(K=>K.filter(I=>I.id!==H.id||I.hidden)),u(null),b&&(n(!0),k(!1))},[b]),ee=r.useMemo(()=>({templates:D,fill:A,openPicker:E,openEdit:y,resetConfirm:g,toggleReset:R}),[D,A,E,y,g,R]),ne=o?l.some(H=>H.id===o.id&&!H.hidden&&tt(H)):!1;return e.jsxs(nn.Provider,{value:ee,children:[s,i&&e.jsx(Na,{templates:D,resetConfirm:g,onFill:L,onEditTpl:M,onNew:C,onResetToggle:R,onClose:j}),o&&e.jsx(Ca,{editing:o,isNew:p,hasOverride:ne,onDraft:u,onSave:m,onRestore:()=>W(o),onRemove:()=>B(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),j()},onSend:()=>{const H=o.prompt.trim();H&&t({type:"prompt",text:H,queue:!1})&&j()},onClose:j})]})}function wa(){const t=me(),{templates:s,fill:a,openEdit:l,toggleReset:c,resetConfirm:i}=an();return e.jsxs("div",{className:"empty-templates",children:[e.jsxs("div",{className:"empty-templates-head",children:[e.jsx("span",{className:"empty-templates-title",children:t("tpl.title")}),e.jsx("span",{className:"empty-templates-hint",children:t("tpl.hint")})]}),e.jsxs("div",{className:"empty-templates-grid",children:[s.map(n=>e.jsx(rn,{tpl:n,title:t("tpl.clickCard"),onFill:()=>a(n.prompt),onEdit:()=>l(n),editTitle:t("tpl.editTpl")},n.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>l(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Le,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(Bs,{}),t(i?"tpl.resetConfirm":"tpl.reset")]})})]})}function rn({tpl:t,title:s,onFill:a,onEdit:l,editTitle:c}){const i=me();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:a,children:[e.jsx("span",{className:"empty-template-icon",children:t.icon}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t.title}),e.jsx("span",{className:"empty-template-desc",children:t.desc})]}),e.jsx("span",{className:"template-card-ops",role:"button",title:c??i("tpl.editTpl"),onClick:n=>{n.stopPropagation(),l()},children:e.jsx(Et,{})})]})}function Na({templates:t,resetConfirm:s,onFill:a,onEditTpl:l,onNew:c,onResetToggle:i,onClose:n}){const o=me();return r.useEffect(()=>{const u=p=>{p.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal template-picker",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"template-picker-head",children:[e.jsx("span",{className:"template-picker-title",children:o("tpl.pickerTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:o("close"),onClick:n,children:e.jsx(ke,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(u=>e.jsx(rn,{tpl:u,title:o("tpl.clickCard"),onFill:()=>a(u),onEdit:()=>l(u),editTitle:o("tpl.editTpl")},u.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:c,title:o("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(Le,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:i,children:[e.jsx(Bs,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Ca({editing:t,isNew:s,hasOverride:a,onDraft:l,onSave:c,onRestore:i,onRemove:n,onFill:o,onSend:u,onClose:p}){const h=me(),g=r.useRef(null);r.useEffect(()=>{const k=D=>{D.key==="Escape"&&p()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[p]),r.useEffect(()=>{const k=g.current;if(!k)return;k.style.height="auto";const D=k.scrollHeight>300;k.style.height=`${Math.min(k.scrollHeight,300)}px`,k.style.overflowY=D?"auto":"hidden"},[t.prompt]);const v=()=>{const k=t.title.trim(),D=t.prompt.trim();if(!k||!D){l({...t,error:h("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:k,desc:t.desc.trim(),prompt:D})},b=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:p,children:e.jsxs("div",{className:"modal template-modal",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"template-modal-head",children:[e.jsx("span",{className:"template-modal-icon",children:t.icon}),e.jsx("span",{className:"template-modal-badge",children:h(b?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:h(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:h("close"),onClick:p,children:e.jsx(ke,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:k=>l({...t,icon:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:h("tpl.fieldTitlePh"),onChange:k=>l({...t,title:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:h("tpl.fieldDescPh"),onChange:k=>l({...t,desc:k.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:h("tpl.fieldPrompt")}),e.jsx("textarea",{ref:g,className:"template-field-prompt",value:t.prompt,placeholder:h("tpl.fieldPromptPh"),onChange:k=>l({...t,prompt:k.target.value})})]}),t.error&&e.jsx("div",{className:"template-error",children:t.error}),e.jsxs("div",{className:"template-modal-actions",children:[e.jsxs("div",{className:"template-modal-actions-left",children:[!s&&b&&a&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:h("tpl.restoreTip"),onClick:i,children:h("tpl.restore")}),!s&&b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:h("tpl.removeTip"),onClick:n,children:[e.jsx(Ee,{})," ",h("tpl.remove")]}),!s&&!b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:h("tpl.deleteTip"),onClick:n,children:[e.jsx(Ee,{})," ",h("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:v,children:h("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:h("tpl.fillTip"),children:h("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:u,title:h("tpl.sendTip"),children:[e.jsx(Ds,{})," ",h("tpl.sendNow")]})]})]})]})})}const vs=new Map,Sa=15,ys=30,jt=250,ks=1200,Ta=1600;function bs(t){return t.content.some(s=>s.type==="toolCall")}function Ea({state:t,liveOutputs:s,toolStatuses:a,onEdit:l,onKillBash:c,thinkingWrap:i,toolsWrap:n}){const o=me(),u=r.useRef(null),[p,h]=r.useState(!0),g=r.useRef(!0),v=r.useRef(0),b=r.useRef(0),k=r.useRef(!1),D=r.useRef(0),[E,A]=r.useState(()=>new Set),[y,j]=r.useState(!1),R=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,L=r.useMemo(()=>{const f=new Map;for(const x of t.messages)x.role==="toolResult"&&x.toolCallId&&f.set(x.toolCallId,x);return f},[t.messages]),M=r.useMemo(()=>ia(t.messages),[t.messages]),C=R.length>0?R[R.length-1].id:null,m=t.messages.length>ys?Math.max(0,t.messages.length-Sa):0,[B,W]=r.useState(()=>new Set),[ee,ne]=r.useState(()=>new Set),H=r.useRef(new Map),K=r.useRef(new Map),I=r.useRef(new Map),T=r.useRef(0),S=r.useMemo(()=>{const f=new Map;for(const x of t.messages)f.set(x.id,pa(x));return f},[t.messages]),U=r.useRef(S);U.current=S;const _=r.useRef(B);_.current=B;const z=t.messages.length>ys&&!y,N=r.useRef(z);N.current=z;const X=da(t.messages,H.current,Ta),te=r.useRef(X);te.current=X;const ce=r.useCallback(()=>{const f=u.current;if(!f)return;if(!N.current){W(de=>de.size?new Set:de);return}const x=f.getBoundingClientRect(),V={top:x.top-ks,bottom:x.bottom+ks},O=[];for(const[de,ye]of I.current){const Se=ye.getBoundingClientRect();O.push({id:de,top:Se.top,bottom:Se.bottom}),_.current.has(de)||oe(de,Se.bottom-Se.top,U.current.get(de))}const ie=oa(O,V,te.current,_.current);for(const de of ie.hide){const ye=I.current.get(de);ye&&oe(de,ye.offsetHeight,U.current.get(de))}W(de=>ca(de,ie))},[]),$=r.useCallback(()=>{T.current||(T.current=requestAnimationFrame(()=>{T.current=0,ce()}))},[ce]);r.useLayoutEffect(()=>{ce()},[ce]);const Y=r.useRef(y);r.useLayoutEffect(()=>{Y.current&&!y&&ce(),Y.current=y},[y,ce]);const oe=r.useCallback((f,x,V)=>{V!==void 0&&(K.current.set(f,{h:x,len:V}),H.current.set(f,x))},[]),Q=r.useCallback((f,x)=>{oe(f,x,U.current.get(f))},[oe]),ue=r.useCallback(f=>{f&&I.current.set(f.dataset.lazyId??"",f)},[]);r.useEffect(()=>{const f=new Set(t.messages.map(x=>x.id));for(const[x,V]of I.current)f.has(x)||(I.current.delete(x),H.current.delete(x),K.current.delete(x));W(x=>{let V=!1;const O=new Set;for(const ie of x)f.has(ie)?O.add(ie):V=!0;return V?O:x})},[t.messages,E]),r.useEffect(()=>()=>cancelAnimationFrame(T.current),[]);const Z=r.useMemo(()=>{const f=[];for(const x of t.messages){if(x.role!=="user")continue;const V=x.content.map(de=>{var ye;return((ye=Ze(de))==null?void 0:ye.text)??""}).filter(Boolean).join(" "),O=$t(V),ie=O?O.userMessage??`skill:${O.name}`:V.trim();ie&&f.push({id:x.id,text:ie})}return f},[t.messages]),d=r.useMemo(()=>{const f=new Map;return Z.forEach((x,V)=>f.set(x.id,V)),f},[Z]),[P,le]=r.useState(-1),se=r.useRef(-1),he=r.useRef(Z);r.useEffect(()=>{he.current=Z},[Z]);const J=r.useCallback(()=>{const f=u.current,x=he.current;if(!f||x.length===0)return;const V=f.getBoundingClientRect().top,O=140;let ie=-1;for(let de=0;de<x.length;de++){const ye=f.querySelector(`[data-msg-id="${x[de].id}"]`);if(ye)if(ye.getBoundingClientRect().top<=V+O)ie=de;else break}ie!==se.current&&(se.current=ie,le(ie))},[]);r.useEffect(()=>{J()},[Z,J]);const re=r.useCallback(f=>{A(x=>x.has(f)?x:new Set(x).add(f))},[]),ge=r.useCallback(f=>{const x=t.messages.findIndex(V=>V.id===f);x>=0&&x<m&&!E.has(f)&&ds.flushSync(()=>re(f))},[t.messages,m,E,re]);r.useEffect(()=>{const f=x=>{if(!(x.ctrlKey||x.metaKey)||x.key.toLowerCase()!=="f")return;const V=x.target;V&&(V.tagName==="INPUT"||V.tagName==="TEXTAREA"||V.isContentEditable)||(x.preventDefault(),j(!0))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]);const pe=r.useCallback(f=>{A(x=>{if(!x.has(f))return x;const V=new Set(x);return V.delete(f),V})},[]),we=r.useCallback(f=>{const x=t.messages.findIndex(O=>O.id===f);ds.flushSync(()=>{x>=0&&x<m&&!E.has(f)&&re(f),ne(O=>O.has(f)?O:new Set(O).add(f))});const V=he.current.findIndex(O=>O.id===f);se.current=V,le(V),requestAnimationFrame(()=>{var ie,de,ye;const O=(ie=u.current)==null?void 0:ie.querySelector(`[data-msg-id="${f}"]`);O&&((de=u.current)==null||de.querySelectorAll(".msg-flash").forEach(Se=>Se.classList.remove("msg-flash")),O.scrollIntoView({block:"start"}),O.classList.remove("msg-flash"),O.offsetWidth,O.classList.add("msg-flash"),O!==((ye=u.current)==null?void 0:ye.lastElementChild)&&(k.current=!0))})},[t.messages,m,E,re]),Be=r.useCallback(()=>{const f=u.current;if(!f)return;const x=f.scrollTop-v.current,V=f.scrollHeight-b.current;v.current=f.scrollTop,b.current=f.scrollHeight;const O=f.scrollHeight-f.scrollTop-f.clientHeight<80,ie=Date.now()<D.current,de=ka({dSt:x,dSh:V,escaped:k.current,graceActive:ie,stuck:g.current});de.reassert&&(D.current=Date.now()+jt,f.scrollTop=f.scrollHeight),de.flipEscape&&(k.current=!0),O&&x>=0&&(k.current=!1),ie||(x<0?g.current=O&&!k.current:O&&(g.current=!0)),h(g.current),J(),$()},[J,$]),_e=r.useRef(!1);r.useEffect(()=>{const f=_e.current;if(_e.current=!!t.isStreaming,f&&!t.isStreaming&&!k.current){const x=()=>{const O=u.current;O&&!k.current&&(O.scrollTop=O.scrollHeight,g.current=!0,h(!0))};requestAnimationFrame(()=>requestAnimationFrame(x));const V=setTimeout(x,180);return()=>clearTimeout(V)}},[t.isStreaming]),r.useEffect(()=>{const f=u.current;f&&g.current&&(f.scrollTop=f.scrollHeight)},[R,t.isStreaming,s]);const Ve=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");r.useEffect(()=>{const f=u.current;f&&g.current&&(f.scrollTop=f.scrollHeight)},[Ve]),r.useEffect(()=>{const f=u.current;if(!f||typeof ResizeObserver>"u")return;const x=new ResizeObserver(()=>{g.current&&!k.current&&(f.scrollTop=f.scrollHeight,h(!0))});return x.observe(f),()=>x.disconnect()},[]),r.useEffect(()=>{const f=u.current;if(!f||typeof MutationObserver>"u")return;let x=!1;const V=new MutationObserver(()=>{x||(x=!0,requestAnimationFrame(()=>{x=!1;const O=u.current;O&&g.current&&!k.current&&(O.scrollTop=O.scrollHeight,h(!0))}))});return V.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>V.disconnect()},[]);const Ge=r.useCallback(()=>{if(!u.current)return;g.current=!0,k.current=!1,h(!0),D.current=Date.now()+jt;const x=()=>{const V=u.current;!V||!g.current||k.current||(D.current=Date.now()+jt,V.scrollTop=V.scrollHeight)};x(),requestAnimationFrame(()=>requestAnimationFrame(x)),setTimeout(x,120),setTimeout(x,300),setTimeout(x,600)},[]),Ce=r.useRef(null);r.useEffect(()=>{const f=Ce.current,x=u.current;if(!f||!x)return;const V=O=>{O.preventDefault();const ie=f.querySelector(".qn-list");if(ie&&ie.contains(O.target)&&ie.scrollHeight>ie.clientHeight){ie.scrollTop+=O.deltaY;return}x.scrollTop+=O.deltaY};return f.addEventListener("wheel",V,{passive:!1}),()=>f.removeEventListener("wheel",V)},[]);const[Oe,Fe]=r.useState(0);r.useEffect(()=>{const f=()=>{var x;Fe(((x=u.current)==null?void 0:x.clientHeight)??0),$()};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[$]);const Ne=Z.length,Re=r.useMemo(()=>Ne===0?27:Math.max(4,Math.min(27,Math.floor(((Oe||600)-16)/Ne)-3)),[Ne,Oe]),w=Re<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${p?"":" anchor-live"}`,ref:u,onScroll:Be,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(wa,{})}),t.messages.map((f,x)=>{const V=x<m,O=V&&E.has(f.id);if(V&&!O)return f.role==="toolResult"?null:e.jsx(aa,{message:f,onExpand:re},f.id);const ie=f.role==="user"?d.get(f.id):void 0,de=!z||X.has(f.id)||ee.has(f.id)||!B.has(f.id);return e.jsx(la,{id:f.id,show:de,height:ma(f.id,S.get(f.id)??-1,K.current,en(f.role,f.customType)),containerRef:u,onMeasured:Q,lazyRef:ue,children:e.jsx(ms,{message:f,qnIndex:ie,qnActive:ie!==void 0?ie===P:void 0,onJump:we,toolResults:L,liveOutputs:bs(f)?s:vs,toolStatuses:a,streaming:t.isStreaming,onKillBash:c,toolsWrap:n,thinkingWrap:i,isLast:f.id===C,onEdit:l,questionAttachments:M.get(f.id),onCollapse:O?pe:void 0},f.id)},f.id)}),t.streamingMessage&&e.jsx(ms,{message:t.streamingMessage,toolResults:L,liveOutputs:bs(t.streamingMessage)?s:vs,toolStatuses:a,streaming:!0,isLast:!0,onEdit:l,onKillBash:c,toolsWrap:n,thinkingWrap:i},t.streamingMessage.id),t.isStreaming&&R.length===0&&e.jsx("div",{className:"streaming-wait",children:o("waitingResponse")}),t.queue.steering.map((f,x)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:o("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:f})]})},`q-steer-${x}`)),t.queue.followUp.map((f,x)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:o("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:f})]})},`q-fu-${x}`))]}),!p&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Ge,children:[e.jsx(_s,{})," ",o("backToBottom")]}),e.jsx(ya,{containerRef:u,messages:R,open:y,onClose:()=>j(!1),onEnsureExpanded:ge}),Z.length>0&&e.jsxs("div",{className:`qn-rail ${w?"many":""}`,ref:Ce,"aria-label":o("questionNavTitle"),style:{"--rail-gap":`${Re}px`},children:[Z.map((f,x)=>e.jsx("button",{type:"button",className:`qn-bar ${x===P?"active":""}`,"aria-label":`${x+1}. ${f.text}`,onClick:()=>we(f.id),children:e.jsxs("span",{className:"qn-bar-text",children:[x+1,". ",f.text]})},f.id)),w&&e.jsx("div",{className:"qn-list",children:Z.map((f,x)=>e.jsxs("button",{type:"button",className:`qn-list-item ${x===P?"active":""}`,"aria-label":`${x+1}. ${f.text}`,onClick:()=>we(f.id),children:[e.jsx("span",{className:"qn-list-idx",children:x+1}),e.jsx("span",{className:"qn-list-text",children:f.text})]},f.id))})]})]})}const ln="pi-web-model-usage";function Ma(t){if(!t||typeof t!="object")return{};const s={};for(const[a,l]of Object.entries(t)){const c=typeof l=="number"?Math.floor(l):0;Number.isFinite(c)&&c>0&&(s[a]=c)}return s}function Ra(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function Pa(t,s){const a=s;return t.map((l,c)=>({m:l,i:c,count:a[l.id]??0})).sort((l,c)=>c.count-l.count||l.i-c.i).map(l=>l.m)}function on(){try{const t=localStorage.getItem(ln);return t?Ma(JSON.parse(t)):{}}catch{return{}}}function Ia(t){try{localStorage.setItem(ln,JSON.stringify(t))}catch{}}function La(t){const s=Ra(on(),t);return Ia(s),s}const Da=["off","minimal","low","medium","high","xhigh","max"],Ba=r.memo(function({state:s,models:a,modelsLoading:l,send:c,onManageModels:i,compact:n=!1}){const o=me(),u=s==null?void 0:s.model,p=u?`${u.provider}/${u.id}`:null,[h,g]=r.useState(!1),[v,b]=r.useState(!1),[k,D]=r.useState(""),[E,A]=r.useState(null),[y,j]=r.useState({}),R=r.useRef(null),L=r.useRef(null),[M,C]=r.useState(null);r.useEffect(()=>{if(!h){C(null);return}if(a.length===0)return;const T=requestAnimationFrame(()=>{const S=L.current;S&&C(S.offsetWidth)});return()=>cancelAnimationFrame(T)},[h,a.length]),r.useEffect(()=>{h&&j(on())},[h]),r.useEffect(()=>{h||(D(""),A(null))},[h]);const m=r.useMemo(()=>{const T=new Map;for(const S of a)T.set(S.provider,(T.get(S.provider)??0)+1);return[...T.entries()].sort((S,U)=>S[0].localeCompare(U[0])).map(([S,U])=>({name:S,count:U}))},[a]),B=r.useMemo(()=>Pa(a,y),[a,y]),W=r.useMemo(()=>{let T=B;E&&(T=T.filter(U=>U.provider===E));const S=k.trim().toLowerCase();return S?T.filter(U=>U.name.toLowerCase().includes(S)||U.provider.toLowerCase().includes(S)||U.id.toLowerCase().includes(S)):T},[B,k,E]),[ee,ne]=r.useState(!1),H=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,K=Da.map(T=>({value:T,label:o(`thinking.${T}`),supported:H?H.has(T):!0})),I=T=>{var S;return((S=K.find(U=>U.value===T))==null?void 0:S.label)??T};return r.useEffect(()=>{h&&a.length===0&&!ee&&!l&&(ne(!0),c({type:"list_models"}))},[h,a.length,ee,l,c]),r.useEffect(()=>{a.length>0&&ne(!1)},[a.length]),r.useEffect(()=>{var S;if(!h)return;const T=(S=R.current)==null?void 0:S.querySelector(".dd-item.active");T==null||T.scrollIntoView({block:"nearest"})},[h,p,a.length]),e.jsxs(e.Fragment,{children:[e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Xe,{}),e.jsx("span",{className:"chip-model",children:u?u.name:o("selectModel")}),!n&&(u==null?void 0:u.vision)&&e.jsx("span",{className:"chip-vision",title:o("vision"),children:"🖼"}),!n&&u&&e.jsx("span",{className:"chip-sub",children:u.provider})]}),open:h,onOpenChange:g,menuClassName:"dd-menu-model",menuRef:L,menuStyle:M!=null?{width:M}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(dt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:o("searchModels"),value:k,onChange:T=>D(T.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[m.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:o("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${E===null?"active":""}`,onClick:()=>A(null),children:e.jsx("span",{children:o("allProviders")})}),m.map(T=>e.jsxs("button",{type:"button",className:`dd-provider-item ${E===T.name?"active":""}`,onClick:()=>A(E===T.name?null:T.name),title:`${T.name} · ${T.count}`,children:[e.jsx("span",{className:"dd-provider-name",children:T.name}),e.jsx("span",{className:"dd-provider-count",children:T.count})]},T.name))]}),e.jsxs("div",{className:"dd-model-scroll",ref:R,children:[(ee||l)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),a.length===0&&!ee&&!l&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),W.length===0&&a.length>0&&e.jsx("div",{className:"dd-loading",children:o("noModelMatches")}),W.map(T=>e.jsx(be,{active:p===T.id,onClick:()=>{p!==T.id&&c({type:"set_model",modelId:T.id}),g(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:T.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:T.provider}),(y[T.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:o("modelUsedCount",{n:y[T.id]})}),(T.reasoning||T.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[T.reasoning&&e.jsx("span",{className:"dd-model-badge",children:o("reasoning")}),T.vision&&e.jsx("span",{className:"dd-model-badge",children:o("vision")})]})]})]})},T.id))]})]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:o("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{g(!1),i()},children:o("manageModels")})]})]}),e.jsxs(Ie,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(nt,{}),e.jsx("span",{className:"chip-sub",children:o("thinkingChip",{level:s?I(s.thinkingLevel):"—"})})]}),open:v,onOpenChange:b,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("thinkingLevel")}),K.map(T=>e.jsx(be,{active:(s==null?void 0:s.thinkingLevel)===T.value,disabled:!T.supported,title:T.supported?void 0:o("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==T.value&&c({type:"set_thinking",level:T.value}),b(!1)},children:T.label},T.value))]})]})}),Fa=r.memo(function({ready:s,streaming:a,messages:l,slashCommands:c,modelState:i,models:n,modelsLoading:o,send:u,attachments:p,onRemoveAttachment:h,onAddImageFiles:g,onAddLocalFiles:v,onNotice:b,onSent:k,onManageModels:D}){const E=me(),{locale:A}=Ft(),{openPicker:y}=an(),j=d=>A==="en"&&d.descriptionEn?d.descriptionEn:d.description??"",R=d=>A==="en"&&d.argumentHintEn?d.argumentHintEn:d.argumentHint??"",[L,M]=r.useState(""),[C,m]=r.useState(!1),[B,W]=r.useState(null),[ee,ne]=r.useState(0),[H,K]=r.useState(!1),[I,T]=r.useState(void 0),S=r.useRef(null),U=r.useRef(null),_=r.useRef(null),z={builtin:E("slashBuiltin"),extension:E("slashExtension"),prompt:E("slashPrompt"),skill:E("slashSkill"),plugin:E("slashPlugin")},N=d=>{const P=d.match(/^\/([^\s]*)$/);if(P&&s){const le=P[1].toLowerCase(),se=c.filter(he=>he.name.toLowerCase().startsWith(le));W(se.length>0?se:null),ne(0)}else W(null)};r.useEffect(()=>{var P;const d=(P=_.current)==null?void 0:P.querySelector(".slash-item.active");d==null||d.scrollIntoView({block:"nearest"})},[ee,B]);const X=d=>{var J;const P=B??[],le=d??P[ee%Math.max(P.length,1)];if(!le){W(null);return}const se=L.match(/^\/([^\s]*)([\s\S]*)$/),he=se?se[2]:"";M(`/${le.name} ${he}`),W(null),(J=S.current)==null||J.focus()},te=async()=>{const P=[...l].reverse().find(se=>se.role==="assistant"&&se.content.some(he=>he.type==="text"&&he.text)),le=P==null?void 0:P.content.filter(se=>se.type==="text").map(se=>se.text).join(`
|
|
318
|
+
`);if(!le){b("warning",E("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(le),b("info",E("slashCopied"))}catch{b("error",E("slashCopyFailed"))}},ce=d=>{if(!d||d.length===0){b("warning",E("foldersNotSupported"));return}const P=Array.from(d).filter(se=>Me(se.type)),le=Array.from(d).filter(se=>!Me(se.type));P.length>0&&g(P),le.length>0&&v(le)},$=d=>{var se;const P=(se=d.clipboardData)==null?void 0:se.items;if(!P)return;const le=[];for(const he of P)if(he.kind==="file"&&Me(he.type)){const J=he.getAsFile();J&&le.push(J)}le.length!==0&&(d.preventDefault(),g(le))},Y=s,oe=r.useRef(L);r.useEffect(()=>{oe.current=L},[L]),r.useEffect(()=>{N(oe.current)},[c]),r.useEffect(()=>{const d=P=>{var se;const le=P.detail;M(le),(se=S.current)==null||se.focus()};return window.addEventListener("pi-web:fill",d),()=>window.removeEventListener("pi-web:fill",d)},[]),r.useEffect(()=>{if(!H)return;const d=P=>{P.key==="Escape"&&K(!1)};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[H]),r.useEffect(()=>{const d=S.current;if(!d)return;d.style.height="auto";const P=d.scrollHeight>220;d.style.height=`${Math.min(d.scrollHeight,220)}px`,d.style.overflowY=P?"auto":"hidden"},[L]);const Q=(d=!1)=>{var se,he,J,re,ge;const P=L.trim(),le=p.some(pe=>pe.imageData||pe.fileData);if(!(!Y||!P&&!le)){if(P==="/help"){const pe=(he=(se=S.current)==null?void 0:se.closest(".inputbox"))==null?void 0:he.getBoundingClientRect();T(pe==null?void 0:pe.width),K(!0),M(""),(J=S.current)==null||J.focus();return}if(P==="/copy"){M(""),(re=S.current)==null||re.focus(),te();return}if(u({type:"prompt",text:P,queue:d,attachments:p.map(pe=>pe.imageData?{path:"",imageData:pe.imageData,mimeType:pe.mimeType,name:pe.name}:pe.fileData?{path:"",fileData:pe.fileData,mimeType:pe.mimeType,name:pe.name,size:pe.size}:{path:pe.path,mode:pe.mode,...pe.lines?{lines:pe.lines}:{}})})){M(""),k();const pe=i==null?void 0:i.model;pe&&La(`${pe.provider}/${pe.id}`),(ge=S.current)==null||ge.focus()}}},ue=d=>{if(!d.nativeEvent.isComposing){if(B&&B.length>0)switch(d.key){case"ArrowDown":d.preventDefault(),ne(P=>(P+1)%B.length);return;case"ArrowUp":d.preventDefault(),ne(P=>(P-1+B.length)%B.length);return;case"Tab":case"Enter":d.preventDefault(),X();return;case"Escape":d.preventDefault(),W(null);return}d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),Q())}},Z=()=>e.jsx("div",{className:"inputbox-actions",children:a?e.jsxs(e.Fragment,{children:[L.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:E("supplementTip"),onClick:()=>Q(!0),children:[e.jsx(Ds,{})," ",E("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:E("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(ot,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:E("sendTip"),disabled:!Y||!L.trim()&&!p.some(d=>d.imageData||d.fileData),onClick:()=>Q(),children:e.jsx($s,{})})});return e.jsxs("div",{className:`inputbar${C?" drop-active":""}`,onDragOver:d=>{d.preventDefault(),d.stopPropagation(),m(!0)},onDragLeave:d=>{d.currentTarget.contains(d.relatedTarget)||m(!1)},onDrop:d=>{var P;d.preventDefault(),d.stopPropagation(),m(!1),ce(((P=d.dataTransfer)==null?void 0:P.files)??null)},children:[C&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",E("dropHereToAttach")]})}),p.length>0&&e.jsxs("div",{className:"attach-row",children:[p.map(d=>e.jsxs("span",{className:`attach-chip ${d.imageData?"image":d.fileData?"file":d.mode}`,title:d.imageData?E("attachImage",{name:d.name}):d.fileData?E("attachFile",{name:d.name}):d.isDir?E("folderRef",{path:d.path}):d.mode==="reference"?E("refOnly",{path:d.path}):d.mode==="lines"&&d.lines?E("attachLines",{path:d.path,start:d.lines.start,end:d.lines.end}):E("attachContent",{path:d.path}),children:[d.imageData?"🖼":d.fileData?"📄":d.isDir?"📁":d.mode==="reference"?"🔗":"📎"," ",d.name,d.mode==="lines"&&d.lines&&e.jsxs("span",{className:"attach-range",children:["L",d.lines.start,"-",d.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:E("removeAttachment"),onClick:()=>h(d.key??d.path),children:"×"})]},d.key??`${d.path}|${d.mode}|${d.lines?`${d.lines.start}-${d.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:E("attachHint")})]}),B&&B.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:_,"aria-label":E("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:E("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>W(null),children:"Esc"})]}),B.map((d,P)=>e.jsxs("button",{type:"button",className:`slash-item${P===ee?" active":""}`,onMouseEnter:()=>ne(P),onClick:()=>X(d),children:[e.jsxs("span",{className:"slash-name",children:["/",d.name]}),e.jsx("span",{className:`slash-source ${d.source}`,children:z[d.source]}),e.jsxs("span",{className:"slash-desc",children:[j(d),d.argumentHint&&e.jsx("span",{className:"slash-hint",children:R(d)})]})]},d.name))]}),H&&e.jsx("div",{className:"modal-backdrop",onClick:()=>K(!1),children:e.jsxs("div",{className:"slash-help",style:I?{width:I}:void 0,onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",E("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>K(!1),children:E("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:E("slashLoading")}):c.map(d=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",d.name]}),e.jsx("span",{className:`slash-source ${d.source}`,children:z[d.source]}),e.jsxs("span",{className:"slash-help-desc",children:[j(d),d.argumentHint&&e.jsx("span",{className:"slash-hint",children:R(d)})]})]},d.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,onChange:d=>{ce(d.target.files),d.target.value=""}}),e.jsx("textarea",{ref:S,value:L,rows:1,placeholder:E(Y?a?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!Y,onChange:d=>{M(d.target.value),N(d.target.value)},onKeyDown:ue,onPaste:$}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:E("uploadFile"),disabled:!Y,onClick:()=>{var d;return(d=U.current)==null?void 0:d.click()},children:e.jsx(An,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:E("tpl.openPicker"),onClick:y,children:e.jsx(Vn,{})}),e.jsx(Ba,{state:i,models:n,modelsLoading:o,send:u,onManageModels:D,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:Z()})]})]})]})}),Aa=r.memo(function({goal:s,models:a,modelsLoading:l,activeConversationId:c,send:i}){var ee,ne,H,K,I,T;const n=me(),o=!s.conversationId||s.conversationId===c,u=s.goal!==null&&o,[p,h]=r.useState(""),[g,v]=r.useState(s.reviewModel??""),[b,k]=r.useState(s.maxRounds),[D,E]=r.useState(s.locked),[A,y]=r.useState(!1),[j,R]=r.useState(!1),[L,M]=r.useState(!0);r.useEffect(()=>{v(s.reviewModel??""),k(s.maxRounds||0),E(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),r.useEffect(()=>{A&&a.length===0&&!j&&!l&&(R(!0),i({type:"list_models"}))},[A,a.length,j,l,i]),r.useEffect(()=>{a.length>0&&R(!1)},[a.length]);const C=()=>{var S;return g?((S=a.find(U=>U.id===g))==null?void 0:S.name)??g:n("goalBarUseMainModel")},m=()=>{const S=p.trim();S&&(i({type:"set_goal",goal:S,...g?{reviewModel:g}:{},maxRounds:b,locked:D}),h(""),M(!1))},B=()=>{const S=p.trim();S&&(i({type:"start_goal_wizard",text:S,...g?{wizardModel:g}:{},maxRounds:b,locked:D}),h(""),M(!1))},W=(((ee=s.wizard)==null?void 0:ee.active)??!1)&&o;return W?e.jsx("div",{className:`goalbar goalbar-active ${W?"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:((ne=s.wizard)==null?void 0:ne.draft)??"",children:[n("goalWizardRunning"),": ",(H=s.wizard)==null?void 0:H.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[n("goalBarRound",{n:(((K=s.wizard)==null?void 0:K.step)??0)+1})," ","/ ",((I=s.wizard)==null?void 0:I.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:((T=s.wizard)==null?void 0:T.status)||n("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:n("goalBarClear"),onClick:()=>{i({type:"clear_goal"}),M(!0)},children:e.jsx(ke,{})})]})}):u?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[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:()=>{i({type:"clear_goal"}),M(!0)},children:e.jsx(ke,{})})]})}):L?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:n("goalBarPlaceholder"),onClick:()=>M(!1),children:[e.jsx(Zt,{})," ",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(Zt,{})}),e.jsx("input",{className:"goalbar-input",value:p,placeholder:n("goalBarPlaceholder"),onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&m()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!p.trim(),onClick:m,children:n("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!p.trim(),title:n("goalWizardTip"),onClick:B,children:["🔍 ",n("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:n(D?"goalBarLocked":"goalBarUnlocked"),onClick:()=>E(S=>(i({type:"set_goal_prefs",locked:!S}),!S)),children:D?e.jsx(qn,{}):e.jsx(Ln,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:n("goalBarClear"),onClick:()=>M(!0),children:e.jsx(mt,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[e.jsxs(Ie,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[n("goalBarReviewModel"),": ",e.jsx("b",{children:C()})]}),open:A,onOpenChange:y,direction:"up",children:[e.jsx("div",{className:"dd-header",children:n("goalBarReviewModel")}),(j||l)&&e.jsx("div",{className:"dd-loading",children:n("loading")}),a.length===0&&!j&&!l&&e.jsx("div",{className:"dd-loading",children:n("noModels")}),e.jsx(be,{active:g==="",onClick:()=>{v(""),y(!1),i({type:"set_goal_prefs",reviewModel:""})},children:n("goalBarUseMainModel")}),a.map(S=>e.jsx(be,{active:g===S.id,onClick:()=>{v(S.id),y(!1),i({type:"set_goal_prefs",reviewModel:S.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:S.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:S.provider})})]})},S.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>i({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:b,placeholder:n("goalBarUnlimitedShort"),onChange:S=>{const U=parseInt(S.target.value,10);if(Number.isNaN(U)||U<0){k(0);return}k(U)},onBlur:()=>i({type:"set_goal_prefs",maxRounds:b}),onKeyDown:S=>{S.key==="Enter"&&(i({type:"set_goal_prefs",maxRounds:b}),S.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:n(D?"goalBarLocked":"goalBarUnlocked")})]})]})});function $a({chat:t,send:s}){const a=me(),l=t.state,[c,i]=r.useState(!1),[n,o]=r.useState(""),[u,p]=r.useState(0),h=r.useRef(null),g=t.pathCompletions;if(r.useEffect(()=>{if(!c)return;const m=setTimeout(()=>{s({type:"complete_path",path:n})},150);return()=>clearTimeout(m)},[n,c,s]),r.useEffect(()=>p(0),[g]),r.useEffect(()=>{const m=document.querySelector(`.status-completions .pc-item[data-idx="${u}"]`);m==null||m.scrollIntoView({block:"nearest"})},[u]),!l)return null;const v=l.stats,b=t.ready?"ok":"busy",k=t.ready?a("connected"):a("connecting"),D=v.contextUsage,E=D.tokens!==null&&D.percent!==null?`${js(D.tokens)} / ${js(D.contextWindow)}`:"—",A=D.percent??null,y=A===null?"":A>=80?"warn":A>=50?"mid":"ok",j=l.queue.steering.length+l.queue.followUp.length,R=()=>{o(l.cwd),i(!0)},L=(m,B)=>{var ee;const W=m.includes("\\")?"\\":"/";o(B?`${m}${W}`:m),p(0),(ee=h.current)==null||ee.focus()},M=m=>{const B=m.trim();B&&B!==l.cwd&&s({type:"set_cwd",path:B}),i(!1)},C=m=>{if(m.key==="ArrowDown")m.preventDefault(),p(B=>Math.min(B+1,g.length-1));else if(m.key==="ArrowUp")m.preventDefault(),p(B=>Math.max(B-1,0));else if(m.key==="Tab"&&g.length>0){m.preventDefault();const B=g[Math.min(u,g.length-1)];L(B.path,B.type==="dir")}else if(m.key==="Enter"&&!m.nativeEvent.isComposing){const B=n.trim();if(B.endsWith("/")||B.endsWith("\\"))M(B);else if(g.some(W=>W.path===B))M(B);else if(g.length>0&&g[u]){m.preventDefault();const W=g[u];L(W.path,W.type==="dir")}else M(B)}else m.key==="Escape"&&(g.length>0?(m.stopPropagation(),s({type:"complete_path",path:""})):i(!1))};return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${b}`,title:k}),e.jsx("span",{className:"status-item",children:k}),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 ${y}`,children:A!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(A,100)}%`}})}),E]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:a("cumulativeCost"),children:["$",_a(v.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:a("sessionMessages"),children:[a("messages")," ",v.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(m=>m.text).join(" · ")})]}),l.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),a("working"),j>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",j," ",a("queued")]})]})]}),c?e.jsxs("div",{className:"status-cwd-wrap",children:[e.jsx("input",{ref:h,className:"status-cwd-input",value:n,autoFocus:!0,placeholder:a("enterPath"),onChange:m=>o(m.target.value),onKeyDown:C,onBlur:()=>i(!1)}),g.length>0&&e.jsx("ul",{className:"status-completions",onMouseDown:m=>m.preventDefault(),children:g.map((m,B)=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-idx":B,className:`pc-item ${B===u?"sel":""}`,onMouseEnter:()=>p(B),onClick:()=>L(m.path,m.type==="dir"),children:[e.jsx("span",{className:"pc-icon",children:m.type==="dir"?e.jsx(ze,{}):e.jsx(Fs,{})}),e.jsxs("span",{className:"pc-body",children:[e.jsx("span",{className:"pc-name",children:m.name}),e.jsx("span",{className:"pc-path",children:m.path})]})]})},m.path))})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:a("cwdTip",{path:l.cwd}),onClick:R,children:["📁 ",l.cwd]})]})}function js(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function _a(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function Oa({dialog:t,send:s}){const a=me(),[l,c]=r.useState(""),[i,n]=r.useState(0),o=h=>{s({type:"dialog_response",id:t.id,value:h})};r.useEffect(()=>{c(""),n(0);const h=g=>{g.key==="Escape"&&o(null)};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],p=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children: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:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((h,g)=>e.jsx("button",{type:"button",className:`dialog-option ${g===i?"sel":""}`,onMouseEnter:()=>n(g),onClick:()=>o(h),children:h},g)),u.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:p}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:a("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:a("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:l,placeholder:p||a("inputPlaceholder"),autoFocus:!0,onChange:h=>c(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.nativeEvent.isComposing&&o(l)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:a("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(l),children:a("ok")})]})]})]})}function Wa(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 Ha({chat:t,send:s,terminal:a,active:l,onSwitchToTerminal:c}){var Ne,Re;const i=me(),[n,o]=r.useState(null),[u,p]=r.useState([]),[h,g]=r.useState(""),[v,b]=r.useState(new Map),[k,D]=r.useState("changes"),[E,A]=r.useState([]),[y,j]=r.useState(null),[R,L]=r.useState(""),[M,C]=r.useState(!1),[m,B]=r.useState(null),[W,ee]=r.useState(null),[ne,H]=r.useState(!1),[K,I]=r.useState(!1),[T,S]=r.useState(!1),[U,_]=r.useState(null),[z,N]=r.useState(!1),[X,te]=r.useState(""),ce=r.useRef(0),$=r.useRef(-1),Y=r.useRef(-1),oe=r.useRef(-1),Q=r.useRef(-1),ue=r.useRef(void 0),Z=r.useRef(null),d=r.useRef([]),P=r.useCallback(w=>{if(w.reqId===$.current){if($.current=-1,I(!1),_(null),!w.ok){_(w.error??"查询失败");return}if(w.notRepo){N(!0),o(null),p([]),b(new Map),A([]),j(null),L(""),ee(null);return}N(!1);const f={branch:w.branch??"",detached:!!w.detached,upstream:w.upstream??null,ahead:w.ahead??0,behind:w.behind??0,upstreamGone:!!w.upstreamGone,files:(w.files??[]).map(O=>({...O}))},x=(w.branches??[]).map(O=>({...O})),V=new Map;for(const[O,ie]of Object.entries(w.stats??{}))V.set(O,{add:ie[0],del:ie[1]});o(f),p(x),b(V),g(O=>{var ie;return f.detached?O||"":f.branch&&x.some(de=>de.name===f.branch)?f.branch:O&&x.some(de=>de.name===O)?O:((ie=x[0])==null?void 0:ie.name)??""}),ee(O=>O&&!f.files.some(ie=>ie.path===O.file.path)?null:O)}else if(w.reqId===Y.current){if(Y.current=-1,H(!1),!w.ok){_(w.error??"查询失败");return}const f=Z.current;if(!f)return;ee({file:f,staged:w.stagedText??"",worktree:w.worktreeText??"",untracked:!1})}else if(w.reqId===Q.current){if(Q.current=-1,S(!1),!w.ok){_(w.error??"查询失败");return}A((w.history??[]).map(f=>({...f})))}else if(w.reqId===oe.current){if(oe.current=-1,C(!1),!w.ok){_(w.error??"查询失败");return}L(w.text??"")}},[]);r.useEffect(()=>{const w=t.scmData;w&&w.type==="scm_data"&&P(w)},[t.scmData,P]);const le=r.useCallback((w,f)=>{if(!t.ready||t.status!=="open")return!1;const x=++ce.current;return s({...w,reqId:x})?(f.current=x,!0):(ce.current-=1,!1)},[t.ready,t.status,s]),se=r.useCallback((w=!1,f=!1)=>{var x;!t.ready||t.status!=="open"||(x=t.state)!=null&&x.cwd&&(ue.current!==void 0&&ue.current!==t.state.cwd&&(o(null),p([]),b(new Map),A([]),S(!1),Q.current=-1,j(null),L(""),ee(null),B(null)),ue.current=t.state.cwd,_(null),le({type:"scm_status"},$)&&(f||I(!0)))},[t.ready,(Ne=t.state)==null?void 0:Ne.cwd,t.status,le]),he=r.useCallback(w=>{if(B(w),j(null),Z.current=w,w.x==="?"&&w.y==="?"){ee({file:w,staged:"",worktree:"",untracked:!0});return}H(!0),_(null),le({type:"scm_filediff",path:w.path},Y)||H(!1)},[le]),J=r.useCallback(w=>{j(w),B(null),ee(null),L(""),C(!0),_(null),le({type:"scm_commit",hash:w.hash},oe)||C(!1)},[le]),re=r.useCallback((w,f)=>{var O,ie;if(!t.ready)return;const x={name:w,command:f,cwd:"${pwd}"},V=t.terminals.find(de=>de.title===w);if(V)a.restart(V.id),s({type:"run_command",terminalId:V.id,conversationId:V.conversationId,command:x,cols:80,rows:24});else{const de=De();a.create({id:de,conversationId:t.activeConversationId||((O=t.state)==null?void 0:O.conversationId)||"",title:w,cwd:((ie=t.state)==null?void 0:ie.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:x})}c()},[t.ready,(Re=t.state)==null?void 0:Re.cwd,t.terminals,c,s,a]),ge=r.useCallback(()=>{const w=X.trim();if(!w||z)return;const f=w.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");re("git commit",`git add -A && git commit -m "${f}"`),te("")},[X,z,re]),pe=w=>`'${w.replace(/'/g,"'\\''")}`,we=r.useCallback(w=>{z||re("git add",`git add -- ${pe(w.path)}`)},[z,re]),Be=r.useCallback(w=>{z||re("git reset",`git reset HEAD -- ${pe(w.path)}`)},[z,re]),_e=r.useCallback(()=>{if(!h||z)return;const w=u.find(f=>f.name===h);if(w!=null&&w.remote&&typeof w.remote=="string"){const f=h.slice(w.remote.length+1);re("git checkout",`git checkout -b ${f} ${h} || git checkout ${h}`)}else re("git checkout",`git checkout ${h}`)},[h,u,z,re]),Ve=r.useCallback(()=>re("git push","git push"),[re]),Ge=r.useCallback(()=>re("git pull","git pull"),[re]),Ce=r.useCallback(()=>{le({type:"scm_history"},Q)||(Q.current=-1)},[le]);r.useEffect(()=>{l&&se()},[l,se]),r.useEffect(()=>{k==="history"&&n&&Ce()},[k,n,Ce]),r.useEffect(()=>{t.scmDirty>0&&l&&se(!1,!0)},[t.scmDirty]),r.useEffect(()=>{if(!l||!t.ready||t.status!=="open")return;const w=setInterval(()=>{document.visibilityState!=="hidden"&&se(!1,!0)},3e4);return()=>clearInterval(w)},[l,t.ready,t.status,se]),r.useEffect(()=>{const w=d.current;if(d.current=t.terminals,!l)return;t.terminals.some(x=>{var O;return x.running!==!1?!1:((O=w.find(ie=>ie.id===x.id))==null?void 0:O.running)===!0&&/^git /.test(x.title)})&&t.ready&&t.status==="open"&&(se(!1,!0),k==="history"&&n&&Ce())},[t.terminals,l,t.ready,t.status,se,k,n,Ce]);const Oe={staged:i("scmStaged"),unstaged:i("scmUnstaged"),untracked:i("scmUntracked"),both:i("scmStagedUnstaged")},Fe=w=>{const f=w.split(`
|
|
319
|
+
`);return e.jsx("pre",{className:"scm-diff-pre",children:f.map((x,V)=>{let O="";return x.startsWith("diff --git")||x.startsWith("index ")||x.startsWith("new file")||x.startsWith("deleted file")||x.startsWith("old mode")||x.startsWith("new mode")||x.startsWith("similarity index")||x.startsWith("rename ")||x.startsWith("copy ")||x.startsWith("Binary files")||x.startsWith("---")||x.startsWith("+++")?O="hdr":x.startsWith("@@")?O="hunk":x.startsWith("+")?O="add":x.startsWith("-")&&(O="del"),e.jsx("div",{className:`scm-diff-line ${O}`,children:x||" "},V)})})};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(it,{}),i("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":k==="changes",className:k==="changes"?"active":"",onClick:()=>{D("changes"),_(null)},children:i("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="history",className:k==="history"?"active":"",onClick:()=>{D("history"),_(null)},children:i("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:i("scmRefreshTip"),disabled:K,onClick:()=>se(!0),children:e.jsx(pt,{className:K?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:i("scmCurrentBranch"),children:[e.jsx(it,{}),n?n.detached?i("scmDetached"):n.branch:"…",(n==null?void 0:n.upstream)&&e.jsx("span",{className:"scm-upstream",children:n.upstreamGone?i("scmUpstreamGone"):n.ahead>0||n.behind>0?i("scmAheadBehind",{ahead:n.ahead,behind:n.behind}):n.upstream})]}),e.jsxs("select",{className:"scm-select",value:h,disabled:z||u.length===0,title:i("scmSwitchBranch"),onChange:w=>g(w.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:i("scmSelectBranch")}),u.filter(w=>!w.remote).map(w=>e.jsx("option",{value:w.name,children:w.current?`* ${w.name}`:w.name},w.name)),u.some(w=>w.remote)&&e.jsx("optgroup",{label:i("scmRemoteBranches"),children:u.filter(w=>w.remote).map(w=>e.jsx("option",{value:w.name,children:w.name},w.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!h||h===(n==null?void 0:n.branch)||z,title:i("scmSwitchBranchTip",{branch:h}),onClick:_e,children:[e.jsx(it,{}),i("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||z,title:i("scmPushTip"),onClick:Ve,children:[e.jsx($s,{}),i("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!n||n.detached||z,title:i("scmPullTip"),onClick:Ge,children:[e.jsx(_s,{}),i("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:X,placeholder:i("scmCommitPlaceholder"),disabled:z,onChange:w=>te(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.nativeEvent.isComposing&&ge()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!X.trim()||z,title:i("scmCommitTip"),onClick:ge,children:[e.jsx(gt,{}),i("scmCommit")]})]})]}),e.jsxs("div",{className:"scm-body",children:[k==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:i("scmHistory")}),E.length>0&&e.jsx("span",{className:"scm-files-count",children:E.length})]}),e.jsx("div",{className:"scm-history-list",children:z?e.jsx("div",{className:"scm-empty",children:i("scmNotGitRepo")}):!n||T?e.jsx("div",{className:"scm-empty",children:t.status==="open"?i("scmLoading"):i("scmConnecting")}):E.length===0?e.jsx("div",{className:"scm-empty",children:i("scmNoHistory")}):E.map(w=>e.jsxs("button",{type:"button",className:`scm-commit ${(y==null?void 0:y.hash)===w.hash?"active":""}`,onClick:()=>J(w),title:w.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:w.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:w.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[w.shortHash," · ",w.author," · ",w.date]}),w.decorations&&e.jsx("span",{className:"scm-commit-refs",children:w.decorations})]})]},w.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:i("scmChanges")}),n&&n.files.length>0&&e.jsx("span",{className:"scm-files-count",children:n.files.length})]}),e.jsx("div",{className:"scm-files-list",children:z?e.jsx("div",{className:"scm-empty",children:i("scmNotGitRepo")}):n?n.files.length===0?e.jsx("div",{className:"scm-empty",children:i("scmNoChanges")}):n.files.map(w=>{const f=Wa(w),x=v.get(w.path);return e.jsxs("div",{className:`scm-file ${(m==null?void 0:m.path)===w.path?"active":""}`,title:Oe[f],onClick:()=>he(w),children:[e.jsx("span",{className:`scm-file-xy ${f==="untracked"?"q":"x"}`,children:w.x!==" "?w.x:" "}),e.jsx("span",{className:`scm-file-xy ${f==="untracked"?"q":"y"}`,children:w.y!==" "?w.y:" "}),e.jsx("span",{className:"scm-file-path",children:w.path}),x&&(x.add>0||x.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[x.add>0&&e.jsxs("span",{className:"add",children:["+",x.add]}),x.del>0&&e.jsxs("span",{className:"del",children:["-",x.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(w.y!==" "||f==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:i("scmStageTip",{path:w.path}),onClick:V=>{V.stopPropagation(),we(w)},children:"+"}),f==="staged"||f==="both"?e.jsx("button",{type:"button",className:"scm-act",title:i("scmUnstageTip",{path:w.path}),onClick:V=>{V.stopPropagation(),Be(w)},children:"−"}):null]})]},w.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?i("scmLoading"):i("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:k==="history"?y?`${y.shortHash} ${y.subject}`:i("scmCommitDetail"):m?m.path:i("scmDiff")}),(k==="history"?M:ne)&&e.jsx("span",{className:"scm-diff-loading",children:i("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:k==="history"?e.jsxs(e.Fragment,{children:[U&&e.jsx("div",{className:"scm-error",children:U}),!y&&!U&&e.jsx("div",{className:"scm-empty",children:i("scmSelectCommitHint")}),y&&M&&!U&&e.jsx("div",{className:"scm-empty",children:i("scmLoading")}),y&&!M&&!U&&R?Fe(R):null]}):e.jsxs(e.Fragment,{children:[U&&e.jsx("div",{className:"scm-error",children:U}),!m&&!U&&e.jsx("div",{className:"scm-empty",children:i("scmSelectFileHint")}),m&&!W&&!U&&e.jsx("div",{className:"scm-empty",children:i("scmLoading")}),m&&W&&W.untracked&&e.jsx("div",{className:"scm-empty",children:i("scmUntrackedNote")}),m&&W&&!W.untracked&&e.jsxs(e.Fragment,{children:[W.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:i("scmStaged")}),Fe(W.staged)]}),W.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:i("scmUnstaged")}),Fe(W.worktree)]}),!W.staged&&!W.worktree&&e.jsx("div",{className:"scm-empty",children:i("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(Ke,{}),e.jsx("span",{children:i("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:i("scmViewTerminal")})]})]})}function qa({entry:t,send:s}){const a=r.useRef(null);return r.useEffect(()=>{const l=a.current;if(!l)return;let c;try{c=t.module.mount(l,xi(t.info.id,i=>s(i)))}catch(i){console.error(`[plugin:${t.info.id}] mount failed:`,i),l.textContent=`插件 ${t.info.name} 挂载失败`}return()=>{if(typeof c=="function")try{c()}catch(i){console.error(`[plugin:${t.info.id}] cleanup failed:`,i)}l.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:a})}function Ka({send:t,piConfigured:s,piAgentInstalled:a,providers:l,installResult:c,onClose:i}){const n=me(),[o,u]=r.useState(!1),[p,h]=r.useState(""),[g,v]=r.useState(""),[b,k]=r.useState(!1);r.useEffect(()=>{t({type:"list_providers"})},[t]),r.useEffect(()=>{s&&i()},[s,i]),r.useEffect(()=>{c&&u(!1)},[c]),r.useEffect(()=>{var R;!p&&l.length>0&&h(((R=l.find(L=>!L.configured))==null?void 0:R.id)??l[0].id)},[l,p]);const D=()=>{o||(u(!0),t({type:"install_pi_agent"}))},E=()=>{!g.trim()||b||(k(!0),t({type:"set_provider_api_key",provider:p.trim(),apiKey:g.trim()}),setTimeout(()=>k(!1),3e3))},A=()=>{t({type:"get_state"}),t({type:"list_providers"})},y=l.find(R=>R.id===p),j=c!==null&&!c.ok;return e.jsx("div",{className:"modal-backdrop",children:e.jsxs("div",{className:"modal setup-modal",children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":n("close"),onClick:i,children:e.jsx(ke,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(Xe,{className:"modal-head-icon"}),e.jsx("h2",{children:n("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:n("setupDesc")}),j?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:n("installFailed")}),e.jsx("pre",{className:"setup-detail",children:c.detail}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:D,children:n("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:i,children:n("skip")})]})]}):a||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?n("installDone"):n("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("provider")}),e.jsxs("select",{value:p,onChange:R=>h(R.target.value),children:[l.length===0&&e.jsx("option",{value:"",children:n("loading")}),l.map(R=>e.jsxs("option",{value:R.id,children:[R.name,"(",R.id,")",R.configured?` · ${n("configured")}`:""]},R.id))]}),(y==null?void 0:y.configured)&&e.jsx("div",{className:"field-hint",children:n("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:n("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:R=>v(R.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||b||!p,onClick:E,children:n(b?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:A,children:[e.jsx(pt,{})," ",n("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:D,children:n(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:i,children:n("skip")})]})]})})}const Ua=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],_t=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),za=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[_t()]});function ws(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:[_t()]).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 Va({send:t,providers:s,providerStatus:a,fetchModelsResult:l,refreshProviderResult:c,cloneProviderResult:i,onClose:n}){const o=me(),[u,p]=r.useState(null),[h,g]=r.useState({}),[v,b]=r.useState(null),[k,D]=r.useState({}),[E,A]=r.useState(!1),[y,j]=r.useState(0),[R,L]=r.useState(null),M=r.useRef(0),[C,m]=r.useState({});r.useRef(0);const B=r.useRef(0),[W,ee]=r.useState(null),ne=r.useRef(0),H=r.useRef(0);r.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"})},[t]);const K=()=>{if(!u)return;const N=u.baseUrl.trim();if(!N){L({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(E)return;A(!0),L(null);const X=y+1;j(X),t({type:"fetch_models",reqId:X,baseUrl:N,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};r.useEffect(()=>{var N;if(!(!l||l.reqId===M.current))if(M.current=l.reqId,A(!1),l.ok&&((N=l.models)!=null&&N.length)){const X=l.models;p(te=>{if(!te)return te;const ce=te.models.map(Q=>{var d;if(!Q.id.trim())return Q;const ue=X.find(P=>P.id===Q.id.trim());if(!ue)return Q;const Z={...Q};return!Z.name&&ue.name&&(Z.name=ue.name),!Z.contextWindow&&ue.contextWindow&&(Z.contextWindow=String(ue.contextWindow)),!Z.maxTokens&&ue.maxTokens&&(Z.maxTokens=String(ue.maxTokens)),Z.input==="text"&&((d=ue.input)!=null&&d.includes("image"))&&(Z.input="text-image"),!Z.reasoning&&ue.reasoning&&(Z.reasoning=!0),Z}),$=new Set(ce.map(Q=>Q.id.trim()).filter(Boolean)),Y=X.filter(Q=>!$.has(Q.id)).map(Q=>{var ue;return{id:Q.id,name:Q.name??"",reasoning:Q.reasoning??!1,input:(ue=Q.input)!=null&&ue.includes("image")?"text-image":"text",contextWindow:Q.contextWindow?String(Q.contextWindow):"",maxTokens:Q.maxTokens?String(Q.maxTokens):""}}),oe=[...ce,...Y];return oe.some(Q=>Q.id.trim())?{...te,models:oe.filter(Q=>Q.id.trim())}:te}),L({ok:!0,text:o("fetchModelsOk",{n:X.length})})}else L({ok:!1,text:l.error||o("fetchModelsEmpty")})},[l]);const I=N=>{const X=(h[N.id]??"").trim();!X||v||(b(N.id),t({type:"set_provider_api_key",provider:N.id,apiKey:X}),setTimeout(()=>{b(null),g(te=>({...te,[N.id]:""})),D(te=>({...te,[N.id]:!1})),t({type:"list_providers"})},1500))},T=()=>{if(!u)return;const N=u.providerId.trim(),X=u.models.filter(ce=>ce.id.trim()).map(ce=>({id:ce.id.trim(),name:ce.name.trim()||void 0,reasoning:ce.reasoning||void 0,input:ce.input==="text-image"?["text","image"]:void 0,contextWindow:ce.contextWindow?Number(ce.contextWindow):void 0,maxTokens:ce.maxTokens?Number(ce.maxTokens):void 0})),te={providerId:N,name:u.name.trim()||void 0,api:u.api.trim()||void 0,baseUrl:u.baseUrl.trim()||void 0,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader||void 0,models:X};t({type:"save_model_config",providerId:N,config:te}),n()};r.useEffect(()=>{!c||c.reqId===B.current||(B.current=c.reqId,m({}))},[c]);const S=N=>{if(W)return;ee(N.id);const X=++ne.current+Date.now();t({type:"clone_provider",provider:N.id,reqId:X})};r.useEffect(()=>{!i||i.reqId===H.current||(H.current=i.reqId,ee(null),i.ok&&i.config&&p(ws({...i.config,apiKey:""})))},[i]);const U=N=>{window.confirm(o("clearKeyConfirm",{id:N}))&&t({type:"clear_provider_api_key",provider:N})},_=N=>{window.confirm(o("deleteProviderConfirm",{id:N.providerId,n:N.models.length}))&&t({type:"delete_model_config",providerId:N.providerId})},z=(N,X)=>{u&&p({...u,models:u.models.map((te,ce)=>ce===N?{...te,...X}:te)})};return e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"modal model-modal",onClick:N=>N.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:n,children:e.jsx(ke,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:o(u?"editProvider":"manageModelsTitle")})}),u?e.jsxs("div",{className:"provider-form",children:[e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerId")," ",e.jsx("em",{children:o("providerIdHint")})]}),e.jsx("input",{type:"text",value:u.providerId,disabled:s.some(N=>N.providerId===u.providerId),onChange:N=>p({...u,providerId:N.target.value}),placeholder:"my-proxy"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("displayName")}),e.jsx("input",{type:"text",value:u.name,onChange:N=>p({...u,name:N.target.value}),placeholder:o("displayNamePh")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiType")}),e.jsx("select",{value:u.api,onChange:N=>p({...u,api:N.target.value}),children:Ua.map(N=>e.jsx("option",{value:N,children:N},N))})]}),e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:["baseUrl ",e.jsx("em",{children:o("baseUrlHint")})]}),e.jsx("input",{type:"text",value:u.baseUrl,onChange:N=>p({...u,baseUrl:N.target.value}),placeholder:"http://localhost:11434/v1"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKey")}),e.jsx("input",{type:"password",value:u.apiKey,onChange:N=>p({...u,apiKey:N.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:N=>p({...u,authHeader:N.target.checked})}),e.jsx("span",{children:o("authHeader")})]})]}),e.jsxs("div",{className:"model-section-head",children:[e.jsx("span",{className:"form-section-title",children:o("modelsTitle")}),e.jsxs("span",{className:"model-section-actions",children:[R&&e.jsx("span",{className:`fetch-msg ${R.ok?"ok":"err"}`,title:R.text,children:R.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:E||!u.baseUrl.trim(),title:o("fetchModelsHint"),onClick:K,children:[e.jsx(Dt,{})," ",o(E?"fetchingModels":"fetchModels")]})]})]}),u.models.map((N,X)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:N.id,onChange:te=>z(X,{id:te.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:N.name,onChange:te=>z(X,{name:te.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:N.input,onChange:te=>z(X,{input:te.target.value}),children:[e.jsx("option",{value:"text",children:o("text")}),e.jsx("option",{value:"text-image",children:o("textImage")})]}),e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:N.reasoning,onChange:te=>z(X,{reasoning:te.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:N.contextWindow,onChange:te=>z(X,{contextWindow:te.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:N.maxTokens,onChange:te=>z(X,{maxTokens:te.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>p({...u,models:u.models.filter((te,ce)=>ce!==X)}),children:e.jsx(Ee,{})})]},X)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>p({...u,models:[...u.models,_t()]}),children:[e.jsx(Le,{})," ",o("addModel")]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>p(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(N=>N.id.trim()),onClick:T,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]}),e.jsxs("div",{className:"provider-list",children:[a.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),a.map(N=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:N.name}),e.jsxs("span",{className:"provider-sub",children:[N.id,N.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),N.source&&!N.configured&&e.jsx("span",{className:"auth-badge dim",children:N.source})]})]}),e.jsxs("div",{className:"provider-actions",children:[N.configured&&!k[N.id]?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"auth-badge",children:o("keyReady")}),e.jsxs("button",{type:"button",className:"btn sm",title:o("replaceKeyTitle"),onClick:()=>D(X=>({...X,[N.id]:!0})),children:[e.jsx(Et,{})," ",o("replaceKey")]}),N.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>U(N.id),children:[e.jsx(Ee,{})," ",o("clearKey")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",className:"key-input",placeholder:o("pasteKey"),value:h[N.id]??"",onChange:X=>g(te=>({...te,[N.id]:X.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(h[N.id]??"").trim()||v===N.id,onClick:()=>I(N),children:[e.jsx(Kn,{})," ",v===N.id?o("savingKey"):o("saveKey")]})]}),e.jsxs("button",{type:"button",className:"btn sm",disabled:W!==null,title:o("cloneProviderTitle"),onClick:()=>S(N),children:[e.jsx(Bt,{})," ",W===N.id?o("cloning"):o("cloneProvider")]})]})]},N.id))]}),e.jsx("div",{className:"form-section-title",children:o("customProviders")}),e.jsx("p",{className:"modal-desc",children:o("customDesc")}),s.length===0&&e.jsx("div",{className:"dd-loading",children:o("noCustomProviders")}),e.jsx("div",{className:"provider-list",children:s.map(N=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:N.providerId}),e.jsxs("span",{className:"provider-sub",children:[N.api??"—",N.baseUrl?` · ${N.baseUrl}`:"",N.models.length>0&&` · ${o("modelsCount",{n:N.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>p(ws(N)),children:e.jsx(Et,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>_(N),children:e.jsx(Ee,{})})]})]},N.providerId))}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>p(za()),children:[e.jsx(Le,{})," ",o("addProvider")]})})]})]})})}function Ga({plugin:t,send:s}){const a=me(),l=t.settingsSchema??[],[c,i]=r.useState(()=>({...t.settingsValues??{}})),[n,o]=r.useState(!1);if(l.length===0)return null;const u=(v,b)=>i(k=>({...k,[v]:b})),p=l.some(v=>{var b;return c[v.key]!==((b=t.settingsValues)==null?void 0:b[v.key])}),h=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},g=()=>i({...t.settingsValues??{}});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:l.map(v=>e.jsxs("label",{className:"plugin-settings-field",title:v.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:v.label}),v.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[v.key],onChange:b=>u(v.key,b.target.checked)}):v.type==="select"?e.jsx("select",{value:String(c[v.key]??""),onChange:b=>u(v.key,b.target.value),children:(v.options??[]).map(b=>e.jsx("option",{value:b,children:b},b))}):e.jsx("input",{type:v.type==="password"?"password":v.type==="number"?"number":"text",value:String(c[v.key]??""),min:v.min,max:v.max,onChange:b=>u(v.key,v.type==="number"?Number(b.target.value):b.target.value)})]},v.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!p||n,onClick:h,children:a(n?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:g,children:a("pluginSettingsReset")})]})]})}function at({text:t}){const s=r.useRef(null),[a,l]=r.useState(!1),c=()=>{var n;const i=(n=s.current)==null?void 0:n.getBoundingClientRect();i&&l(window.innerWidth-i.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${a?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Te({title:t,subtitle:s,tip:a,enabled:l,onToggle:c,action:i}){const n=me();return e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[t,a&&e.jsx(at,{text:a})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),i,e.jsx("button",{type:"button",className:`set-switch ${l?"on":""}`,role:"switch","aria-checked":l,title:n(l?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Ja({chat:t,send:s,terminal:a,onSwitchToTerminal:l,onClose:c}){const i=me(),n=t.settings,[o,u]=r.useState("prompt"),p=r.useRef(null);r.useEffect(()=>{var d;(d=p.current)==null||d.scrollTo({top:0})},[o]);const[h,g]=r.useState(""),[v,b]=r.useState("append"),k=r.useRef(!1),[D,E]=r.useState(""),[A,y]=r.useState("append"),j=r.useRef(!1),[R,L]=r.useState(""),M=r.useRef(!1),[C,m]=r.useState(""),[B,W]=r.useState(!1),[ee,ne]=r.useState(null),[H,K]=r.useState(null);r.useEffect(()=>{n&&(b(n.promptMode),!k.current&&(g(v==="append"||n.customSystemPrompt?n.customSystemPrompt:n.defaultSystemPrompt||""),y(n.visionBridgePromptMode),!j.current&&(E(A==="append"||n.visionBridgePrompt?n.visionBridgePrompt:n.visionBridgeDefaultPrompt||""),M.current||L(n.reviewPrompt))))},[n,v,A]);const[I,T]=r.useState(String((n==null?void 0:n.terminalBashIdleMs)??15e3));if(r.useEffect(()=>{T(String((n==null?void 0:n.terminalBashIdleMs)??15e3))},[n==null?void 0:n.terminalBashIdleMs]),!n)return null;const S=[{id:"prompt",icon:e.jsx(As,{}),label:i("settingsSystemPrompt")},{id:"terminal",icon:e.jsx(Ke,{}),label:i("settingsTerminalTools")},{id:"display",icon:e.jsx(Ue,{}),label:i("settingsMessageDisplay")},{id:"skills",icon:e.jsx(Xe,{}),label:i("settingsSkills"),count:n.skills.length},{id:"extensions",icon:e.jsx(es,{}),label:i("settingsExtensions"),count:n.extensions.length},{id:"plugins",icon:e.jsx(ss,{}),label:i("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(nt,{}),label:i("settingsReview"),count:n.reviewSkills.length},{id:"vision",icon:e.jsx(St,{}),label:i("settingsVisionBridge")},{id:"presets",icon:e.jsx(Bn,{}),label:i("settingsPresets"),count:n.presets.length}],U=new Set(n.disabledSkills),_=new Set(n.disabledExtensions),z=d=>s({type:"set_settings",...d}),N=d=>{const P=new Set(U);P.has(d.name)?P.delete(d.name):P.add(d.name),z({disabledSkills:[...P]})},X=new Set(n.disabledPlugins??[]),te=d=>{const P=new Set(X);P.has(d.id)?P.delete(d.id):P.add(d.id),z({disabledPlugins:[...P]})},ce=d=>{const P=new Set(_);P.has(d.id)?P.delete(d.id):P.add(d.id),z({disabledExtensions:[...P]})},$=(d,P)=>{var he,J;const le={name:d,command:P,cwd:"${pwd}"},se=t.terminals.find(re=>re.title===d);se?(a.restart(se.id),s({type:"run_command",terminalId:se.id,conversationId:se.conversationId,command:le,cols:80,rows:24})):a.create({id:De(),conversationId:t.activeConversationId||((he=t.state)==null?void 0:he.conversationId)||"",title:d,cwd:((J=t.state)==null?void 0:J.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:le}),l(),c()},Y=d=>{ne(null),$(`${i("uninstallTitle")} ${d}`,`pi remove npm:${d}`)},oe=d=>{K(null),$(`${i("uninstallTitle")} ${d}`,`pi-web-ui uninstall ${d}`)},Q=(d,P)=>{$(`${i("pluginUpdate")} ${d}`,`pi-web-ui install ${P} --name ${d} --force`)},ue=d=>{const P=new Set(n.reviewSkills.filter(le=>!le.enabled).map(le=>le.name));P.has(d.name)?P.delete(d.name):P.add(d.name),z({reviewDisabledSkills:[...P]})},Z=()=>{const d=v==="replace"&&n.defaultSystemPrompt&&h===n.defaultSystemPrompt?"":h;z({promptMode:v,customSystemPrompt:d})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:d=>d.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":i("close"),onClick:c,children:e.jsx(ke,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(ct,{className:"modal-head-icon"}),e.jsx("h2",{children:i("settingsTitle")}),e.jsx(at,{text:i("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":i("settingsTitle"),children:S.map(d=>e.jsxs("button",{type:"button",className:`settings-tab${o===d.id?" active":""}`,"aria-current":o===d.id?"true":void 0,title:d.label,onClick:()=>u(d.id),children:[e.jsx("span",{className:"settings-tab-icon",children:d.icon}),e.jsx("span",{className:"settings-tab-label",children:d.label}),d.count!==void 0&&e.jsx("span",{className:"set-count",children:d.count})]},d.id))}),e.jsxs("div",{className:"modal-body",ref:p,children:[o==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{className:"set-section-icon"}),i("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:v,onChange:d=>{const P=d.target.value;b(P),z({promptMode:P})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]}),e.jsx(at,{text:i(v==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:i("promptPlaceholder"),value:h,onFocus:()=>k.current=!0,onBlur:()=>{k.current=!1,Z()},onChange:d=>g(d.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":B,onClick:()=>W(d=>!d),children:[i("settingsViewPrompt")," ",B?"▴":"▾"]}),B&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:i("settingsViewPromptHint")}),e.jsx(Ks,{text:n.effectiveSystemPrompt})]}),n.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:n.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:i("settingsViewPromptEmpty")})]})]}),o==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ke,{className:"set-section-icon"}),i("settingsTerminalTools")]}),e.jsx(Te,{title:i("terminalToolsEnabled"),tip:i("settingsTerminalToolsDesc"),enabled:n.terminalToolsEnabled,onToggle:()=>z({terminalToolsEnabled:!n.terminalToolsEnabled})}),!n.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:i("terminalToolsOffHint")}),e.jsx(Te,{title:i("terminalBashTakeover"),tip:i("terminalBashTakeoverDesc"),enabled:n.terminalBash,onToggle:()=>z({terminalBash:!n.terminalBash})}),n.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:i("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:I,onChange:d=>T(d.target.value),onBlur:()=>{const d=Math.max(0,Math.floor(Number(I)||0));T(String(d)),d!==n.terminalBashIdleMs&&z({terminalBashIdleMs:d})}})]})]}),o==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ue,{className:"set-section-icon"}),i("settingsMessageDisplay")]}),e.jsx(Te,{title:i("thinkingWrap"),tip:i("thinkingWrapDesc"),enabled:n.thinkingWrap??!0,onToggle:()=>z({thinkingWrap:!(n.thinkingWrap??!0)})}),e.jsx(Te,{title:i("toolsWrap"),tip:i("toolsWrapDesc"),enabled:n.toolsWrap??!0,onToggle:()=>z({toolsWrap:!(n.toolsWrap??!0)})})]}),o==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Xe,{className:"set-section-icon"}),i("settingsSkills"),e.jsx("span",{className:"set-count",children:n.skills.length})]}),n.skills.length===0?e.jsx("p",{className:"set-empty",children:i("noSkills")}):e.jsx("div",{className:"set-list",children:n.skills.map(d=>e.jsx(Te,{title:d.name,subtitle:d.description,enabled:d.enabled,onToggle:()=>N(d)},d.name))})]}),o==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(es,{className:"set-section-icon"}),i("settingsExtensions"),e.jsx("span",{className:"set-count",children:n.extensions.length})]}),n.extensions.length===0?e.jsx("p",{className:"set-empty",children:i("noExtensions")}):e.jsx("div",{className:"set-list",children:n.extensions.map(d=>{const P=d.id.startsWith("npm:")?d.id.slice(4):null;return e.jsx(Te,{title:d.name,subtitle:d.path,enabled:d.enabled,onToggle:()=>ce(d),action:P?ee===d.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:i("uninstallConfirmHint"),onClick:()=>Y(P),children:i("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:i("uninstallHint"),onClick:()=>ne(d.id),children:[e.jsx(Ee,{}),i("uninstallExt")]}):void 0},d.id)})})]}),o==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ss,{className:"set-section-icon"}),i("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:i("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(d=>{var P;return e.jsxs(e.Fragment,{children:[e.jsx(Te,{title:`${d.icon?`${d.icon} `:""}${d.name}`,subtitle:(d.error?`${d.id} · ${d.error}`:d.source?`${d.id} · ${d.source}`:`${d.id} · ${i("uiPluginNoSource")}`)+((P=d.permissions)!=null&&P.length?` · ${i("uiPluginPerms")}: ${d.permissions.join(", ")}`:""),enabled:!X.has(d.id)&&!d.error,onToggle:()=>!d.error&&te(d),action:e.jsxs("div",{className:"set-row-actions",children:[d.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:i("pluginUpdateHint"),onClick:()=>Q(d.id,d.source),children:[e.jsx(pt,{}),i("pluginUpdate")]}),H===d.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:i("pluginUninstallHint"),onClick:()=>oe(d.id),children:i("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:i("pluginUninstallHint"),onClick:()=>K(d.id),children:[e.jsx(Ee,{}),i("uninstallExt")]})]})},d.id),d.settingsSchema&&d.settingsSchema.length>0&&e.jsx(Ga,{plugin:d,send:s})]})})})]}),o==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(nt,{className:"set-section-icon"}),i("settingsReview"),e.jsx(at,{text:i("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:n.reviewSkills.length})]}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:i("reviewPromptPlaceholder"),value:R,onFocus:()=>M.current=!0,onBlur:()=>{M.current=!1,z({reviewPrompt:R})},onChange:d=>L(d.target.value)}),e.jsx("div",{className:"set-field-label",children:i("settingsReviewSkills")}),n.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:i("noSkills")}):e.jsx("div",{className:"set-list",children:n.reviewSkills.map(d=>e.jsx(Te,{title:d.name,subtitle:d.description,enabled:d.enabled,onToggle:()=>ue(d)},`review-${d.name}`))})]}),o==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(St,{className:"set-section-icon"}),i("settingsVisionBridge")]}),e.jsx(Te,{title:i("visionBridgeEnabled"),tip:i("settingsVisionBridgeDesc"),enabled:n.visionBridgeEnabled,onToggle:()=>z({visionBridgeEnabled:!n.visionBridgeEnabled})}),!n.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:i("visionBridgeOffHint")}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:n.visionBridgeModel??"",onChange:d=>z({visionBridgeModel:d.target.value||null}),children:[e.jsx("option",{value:"",children:i("visionBridgeAuto")}),n.visionModels.map(d=>e.jsx("option",{value:`${d.provider}/${d.id}`,children:d.label},`${d.provider}/${d.id}`))]})]}),n.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:A,onChange:d=>{const P=d.target.value;y(P),z({visionBridgePromptMode:P})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]})]}),n.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:i("visionBridgePromptPlaceholder"),value:D,onFocus:()=>j.current=!0,onBlur:()=>{j.current=!1;const d=A==="replace"&&n.visionBridgeDefaultPrompt&&D===n.visionBridgeDefaultPrompt?"":D;z({visionBridgePromptMode:A,visionBridgePrompt:d})},onChange:d=>E(d.target.value)}),n.visionBridgeEnabled&&(n.visionModels.length===0?e.jsx("p",{className:"set-hint",children:i("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:i("visionBridgeCurrent",{model:n.visionBridgeModel??i("visionBridgeAuto")})}))]}),o==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(ct,{className:"set-section-icon"}),i("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:i("presetNamePlaceholder"),value:C,onChange:d=>m(d.target.value),onKeyDown:d=>{d.key==="Enter"&&C.trim()&&(s({type:"save_preset",name:C.trim()}),m(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!C.trim(),onClick:()=>{s({type:"save_preset",name:C.trim()}),m("")},children:[e.jsx(Le,{})," ",i("saveAsPreset")]})]}),n.presets.length===0?e.jsx("p",{className:"set-empty",children:i("noPresets")}):e.jsx("div",{className:"set-list",children:n.presets.map(d=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:d.name}),e.jsxs("div",{className:"set-row-desc",children:[d.promptMode==="replace"?i("promptModeReplace"):i("promptModeAppend"),d.disabledSkills.length>0&&` · ${i("settingsSkills")} ${d.disabledSkills.length}`,d.disabledExtensions.length>0&&` · ${i("settingsExtensions")} ${d.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:d.name}),children:i("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:i("deletePreset"),onClick:()=>s({type:"delete_preset",name:d.name}),children:e.jsx(Ee,{})})]})]},d.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:i("close")})})]})})}function Ya(t,s){const a=Math.max(0,Date.now()-t),l=Math.floor(a/6e4);if(l<1)return s("bgTaskJustNow");if(l<60)return s("bgTaskMinutes",{n:l});const c=Math.floor(l/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function Qa({servers:t,send:s,onClose:a}){const l=me(),[c,i]=r.useState(new Set),n=o=>i(u=>{const p=new Set(u);return p.has(o)?p.delete(o):p.add(o),p});return r.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:a,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(ut,{})," ",l("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:l("close"),onClick:a,children:e.jsx(ke,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(ut,{}),e.jsx("span",{children:l("bgTasksEmpty")}),e.jsx("small",{children:l("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const u=!!o.taskId,p=o.taskId??String(o.port);return e.jsxs("li",{className:"bg-task-item",children:[e.jsx("span",{className:"bg-task-icon",title:u?o.plugin:l("bgTaskPort")}),e.jsxs("div",{className:"bg-task-info",children:[e.jsxs("div",{className:"bg-task-line1",children:[u?e.jsxs("span",{className:"bg-task-port",title:o.taskId,children:["🧩 ",o.plugin]}):e.jsxs("span",{className:"bg-task-port",children:[":",o.port]}),o.name&&e.jsx("span",{className:"bg-task-name",children:o.name})]}),e.jsxs("div",{className:"bg-task-line2",children:[!u&&e.jsxs("span",{children:[l("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[l("bgTaskSince")," ",Ya(o.since,l)]}),u&&o.status&&e.jsx("span",{className:"bg-task-status",children:o.status})]}),o.command&&e.jsxs("button",{type:"button",className:`bg-task-cmd ${c.has(p)?"open":""}`,title:`${l("bgTaskCommand")}: ${o.command}`,onClick:()=>n(p),children:[e.jsx(Ke,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:l("bgTaskStop"),onClick:()=>s(u?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(ot,{}),e.jsx("span",{children:l("bgTaskStop")})]})]},p)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:l("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(pt,{}),e.jsx("span",{children:l("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:l("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(ot,{}),e.jsx("span",{children:l("bgTaskStopAll")})]})]})]})})}function st(t,s){return t.toLowerCase().includes(s)}function Xa({send:t,sessions:s,projects:a,cwd:l,fileSearch:c,onClose:i,onSwitchSession:n,onSwitchProject:o,onPreviewFile:u}){const p=me(),h=r.useRef(null),[g,v]=r.useState(""),b=r.useDeferredValue(g),[k,D]=r.useState(0),E=r.useRef(1),A=r.useRef(0),y=r.useRef(null);r.useEffect(()=>{t({type:"list_sessions"}),t({type:"list_projects"}),requestAnimationFrame(()=>{var I;return(I=h.current)==null?void 0:I.focus()})},[]);const[j,R]=r.useState(!1);r.useEffect(()=>{y.current&&clearTimeout(y.current);const I=b.trim();if(I)return y.current=setTimeout(()=>{const T=++E.current;A.current=T,R(!0),t({type:"search_files",reqId:T,query:I})},300),()=>{y.current&&clearTimeout(y.current)}},[b]);const L=b.trim().toLowerCase(),M=r.useMemo(()=>L?s.filter(I=>st(I.firstMessage??"",L)||st(I.name??"",L)||st(I.path.split(/[\\/]/).pop()??"",L)).slice(0,20):[],[s,L]),C=r.useMemo(()=>L?a.filter(I=>st(I.path,L)).slice(0,10):[],[a,L]),m=r.useMemo(()=>!L||!c||c.reqId!==A.current||!c.ok?[]:c.results,[c,L]);r.useEffect(()=>{c&&c.reqId===A.current&&A.current!==0&&R(!1)},[c]);const B=!!c&&c.ok&&c.truncated,W=r.useMemo(()=>[...M.map(I=>({kind:"session",path:I.path})),...C.map(I=>({kind:"project",path:I.path})),...m.filter(I=>I.type==="file").map(I=>({kind:"file",path:I.path,name:I.name}))],[M,C,m]);r.useEffect(()=>{D(0)},[b]);const ee=r.useCallback(I=>{I&&(I.kind==="session"?n(I.path):I.kind==="project"?o(I.path):u(I.path,I.name),i())},[n,o,u,i]);r.useEffect(()=>{const I=T=>{T.key==="Escape"?(T.preventDefault(),T.stopPropagation(),i()):T.key==="ArrowDown"?(T.preventDefault(),D(S=>Math.min(S+1,W.length-1))):T.key==="ArrowUp"?(T.preventDefault(),D(S=>Math.max(S-1,0))):T.key==="Enter"&&(T.preventDefault(),ee(W[k]))};return window.addEventListener("keydown",I,!0),()=>window.removeEventListener("keydown",I,!0)},[W,k,ee,i]);const ne=M.length+C.length+m.length,H=(I,T,S)=>e.jsxs("div",{className:"gs-section-head",children:[S,e.jsx("span",{children:I}),e.jsx("em",{children:T})]});let K=-1;return e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:i,children:e.jsxs("div",{className:"gs-modal",onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(dt,{}),e.jsx("input",{ref:h,type:"text",value:g,placeholder:p("gsPlaceholder"),onChange:I=>v(I.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:p("close"),onClick:i,children:e.jsx(ke,{})})]}),e.jsxs("div",{className:"gs-results",children:[!L&&e.jsx("div",{className:"gs-empty",children:p("gsHint")}),L&&ne===0&&!B&&e.jsx("div",{className:"gs-empty",children:p(j?"gsSearching":"gsNoResults")}),M.length>0&&e.jsxs("div",{className:"gs-section",children:[H(p("gsSessions"),M.length,e.jsx(Ue,{})),M.map(I=>{K++;const T=K;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",onMouseEnter:()=>D(T),onClick:()=>ee({kind:"session",path:I.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[I.name||I.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:I.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:I.firstMessage})]},I.path)})]}),C.length>0&&e.jsxs("div",{className:"gs-section",children:[H(p("gsProjects"),C.length,e.jsx(ze,{})),C.map(I=>{K++;const T=K,S=l&&I.path===l;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",onMouseEnter:()=>D(T),onClick:()=>ee({kind:"project",path:I.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[I.path.split(/[\\/]/).pop(),S&&e.jsx("em",{className:"gs-item-meta",children:p("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:I.path})]},I.path)})]}),(m.length>0||L&&B)&&e.jsxs("div",{className:"gs-section",children:[H(p("gsFiles"),m.length,e.jsx(As,{})),m.map(I=>{K++;const T=K;return e.jsxs("button",{type:"button",className:T===k?"gs-item active":"gs-item",disabled:I.type==="dir",title:I.type==="dir"?void 0:p("gsOpenPreview"),onMouseEnter:()=>D(T),onClick:()=>{I.type==="file"&&ee({kind:"file",path:I.path,name:I.name})},children:[e.jsx("span",{className:"gs-item-title",children:I.name}),e.jsx("span",{className:"gs-item-sub",children:I.path})]},`${I.type}:${I.path}`)}),B&&e.jsx("div",{className:"gs-truncated",children:p("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",p("gsNavigate")]}),e.jsxs("span",{children:["Enter ",p("gsOpen")]}),e.jsxs("span",{children:["Esc ",p("gsCloseHint")]})]})]})})}const wt=5e3;function Za({file:t,content:s,send:a,onAddLines:l,onAttach:c,onClose:i}){const n=me(),[o,u]=r.useState(null),[p,h]=r.useState(!1),[g,v]=r.useState(null),[b,k]=r.useState(!1),[D,E]=r.useState(!1),[A,y]=r.useState(!1),[j,R]=r.useState(""),[L,M]=r.useState(!0),C=r.useRef(!1),[m,B]=r.useState(!0),[W,ee]=r.useState(!1),[ne,H]=r.useState(100),K=r.useRef(0),I=r.useRef(!1),T=r.useRef(null);r.useEffect(()=>{h(!0),u(null),v(null),y(!1),R(""),M(!0),C.current=!1,a({type:"read_file",path:t.path})},[t.path,a]),r.useEffect(()=>{s&&s.path===t.path&&(u(s),A||R(s.text),h(!1))},[s,A,t.path]),r.useEffect(()=>{const J=re=>{if(re.key==="Escape"){oe();return}if((re.ctrlKey||re.metaKey)&&re.key.toLowerCase()==="s"&&A){re.preventDefault(),Y();return}const ge=re.target,pe=ge&&(ge.tagName==="INPUT"||ge.tagName==="TEXTAREA"||ge.isContentEditable);(re.ctrlKey||re.metaKey)&&re.key.toLowerCase()==="a"&&!pe&&(re.preventDefault(),N())};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[i,o,A,j]),r.useEffect(()=>{const J=()=>{I.current=!1,k(!1)};return window.addEventListener("mouseup",J),()=>window.removeEventListener("mouseup",J)},[]);const S=r.useMemo(()=>{if(!o)return[];const J=o.text.split(`
|
|
320
|
+
`);return J.length>0&&J[J.length-1]===""&&J.pop(),J.slice(0,wt)},[o]),U=(o==null?void 0:o.lines)??0,_=U>wt,z=(J,re)=>{if(re){const ge=K.current>0?K.current:J;v({start:Math.min(ge,J),end:Math.max(ge,J)})}else K.current=J,v({start:J,end:J})},N=()=>{S.length!==0&&(K.current=1,v({start:1,end:S.length}))},X=()=>{g&&(l(t.path,t.name,g.start,g.end),E(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>E(!1),1400))},te=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,ce=()=>{R((o==null?void 0:o.text)??""),y(!1),C.current&&M(!0)},$=()=>{if(A){if(j!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges")))return;ce();return}!te||!o||(C.current=Nt(t.name)&&L,Nt(t.name)&&M(!1),v(null),R(o.text),y(!0))},Y=()=>{!A||!o||!te||a({type:"write_file",path:t.path,text:j})&&(y(!1),C.current&&M(!0),v(null))},oe=()=>{A&&j!==((o==null?void 0:o.text)??"")&&!window.confirm(n("discardFileChanges"))||i()},Q=J=>{H(Math.min(200,Math.max(50,J)))},ue=g?g.end-g.start+1:0,Z=(o==null?void 0:o.binary)??!1,d=(o==null?void 0:o.truncated)??!1,P=(o==null?void 0:o.kind)??"text",le=Nt(t.name),se=le&&L&&!A&&P==="text"&&!Z,he=J=>ft(`/api/file?clientId=${encodeURIComponent(At())}&path=${encodeURIComponent(J)}`);return e.jsx("div",{className:`fp-overlay ${W?"fullscreen":""}`,onMouseDown:J=>{J.target===J.currentTarget&&oe()},children:e.jsxs("div",{className:`fp ${W?"fullscreen":""}`,style:{"--fp-zoom":ne/100},children:[e.jsxs("div",{className:"fp-head",children:[e.jsx("span",{className:"fp-name",title:t.path,children:t.name}),e.jsx("span",{className:"fp-path",children:t.path}),e.jsxs("span",{className:"fp-meta",children:[o&&P==="text"&&!Z&&n("fileLines",{n:U}),o&&` · ${er(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[le&&P==="text"&&!Z&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${L?"on":""}`,"data-tip":n(L?"showMarkdownSource":"showMarkdownPreview"),disabled:A,onClick:()=>M(J=>!J),children:L?e.jsx(St,{}):e.jsx(Yn,{})}),P==="text"&&!Z&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${A?"on":""}`,"data-tip":n(d?"fileEditTruncated":A?"exitEditFile":"editFile"),disabled:!te&&!A,onClick:$,children:e.jsx(Tt,{})}),P==="text"&&!Z&&!se&&e.jsx("button",{type:"button",className:`fp-attach wrap ${m?"on":""}`,"data-tip":n(m?"disableWrap":"enableWrap"),onClick:()=>B(J=>!J),children:e.jsx(Jn,{})}),P==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":n("zoomOut"),disabled:ne<=50,onClick:()=>Q(ne-10),children:e.jsx(Pn,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:n("resetZoom"),onClick:()=>H(100),children:[ne,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":n("zoomIn"),disabled:ne>=200,onClick:()=>Q(ne+10),children:e.jsx(In,{})})]}),P!=="video"&&P!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":n("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(Le,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":n("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Ct,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${W?"on":""}`,"data-tip":n(W?"exitFullscreen":"fullscreen"),onClick:()=>ee(J=>!J),children:W?e.jsx(_n,{}):e.jsx(Wn,{})}),e.jsx("button",{type:"button",className:"fp-close",title:n("close"),onClick:oe,children:e.jsx(ke,{})})]})]}),d&&P==="text"&&!Z&&e.jsx("div",{className:"fp-notice",children:n("previewTruncated")}),p&&!o&&e.jsx("div",{className:"fp-empty",children:n("loading")}),!p&&P==="none"&&!Z&&e.jsx("div",{className:"fp-empty",children:n("previewNotSupported")}),!p&&P==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:he(t.path),alt:t.name})}),!p&&P==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:he(t.path),controls:!0,preload:"metadata"})}),!p&&se&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(xt,{text:o.text})})}),!p&&Z&&P!=="image"&&P!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[n("binaryFile"),o.truncated&&n("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!p&&A&&P==="text"&&!Z&&o&&e.jsx("textarea",{className:`fp-editor ${m?"":"no-wrap"}`,value:j,onChange:J=>R(J.target.value),wrap:m?"soft":"off",spellCheck:!1,autoFocus:!0}),!p&&!se&&!A&&P==="text"&&!Z&&o&&S.length===0&&e.jsx("div",{className:"fp-empty",children:n("emptyFile")}),!p&&!se&&!A&&P==="text"&&!Z&&S.length>0&&e.jsxs("div",{className:`fp-code ${b?"dragging":""} ${m?"":"no-wrap"}`,onMouseDown:J=>{J.button===0&&J.preventDefault()},children:[S.map((J,re)=>{const ge=re+1,pe=g!==null&&ge>=g.start&&ge<=g.end;return e.jsxs("div",{className:`fp-line ${pe?"sel":""}`,onMouseDown:we=>{we.button===0&&(z(ge,we.shiftKey),I.current=!0,k(!0))},onMouseEnter:()=>{I.current&&z(ge,!0)},children:[e.jsx("span",{className:"fp-num",children:ge}),e.jsx("span",{className:"fp-code-text",children:J})]},ge)}),_&&e.jsx("div",{className:"fp-lines-note",children:n("previewLinesTruncated",{n:wt})})]}),e.jsx("div",{className:"fp-foot",children:A?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:$,children:n("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:j===((o==null?void 0:o.text)??""),onClick:Y,children:[e.jsx(Fn,{})," ",n("saveFile")]})]})]}):!se&&P==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:g?n("selectedRange",{n:ue,start:g.start,end:g.end}):n("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:S.length===0,onClick:N,children:n("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!g,onClick:()=>v(null),children:n("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!g||Z,onClick:X,children:[D?e.jsx(gt,{}):null,n(D?"addedToChat":"addToChat")]})]})]})})]})})}function Nt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function er(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const cn="pi-web-sounds",Je={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function dn(){try{const t=localStorage.getItem(cn);if(!t)return{...Je};const s=JSON.parse(t),a={...Je,...s};for(const l of["enabled","question","done","start","error"])typeof a[l]!="boolean"&&(a[l]=Je[l]);return typeof a.volume!="number"||!Number.isFinite(a.volume)?a.volume=Je.volume:a.volume=Math.round(Math.max(0,Math.min(100,a.volume))/5)*5,a}catch{return{...Je}}}function tr(t){try{localStorage.setItem(cn,JSON.stringify(t))}catch{}}let Ye=null;function sr(){try{if(!Ye){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;Ye=new t}return Ye.state==="suspended"&&Ye.resume(),Ye}catch{return null}}const nr=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],ir=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],ar=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],rr=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],lr={question:nr,done:ir,start:ar,error:rr};function or(t,s,a){const l=t.createOscillator(),c=t.createGain();l.type=s.type,l.frequency.value=s.freq;const i=t.currentTime+s.start,n=Math.max(1e-4,s.peak*a);c.gain.setValueAtTime(1e-4,i),c.gain.exponentialRampToValueAtTime(n,i+.012),c.gain.exponentialRampToValueAtTime(1e-4,i+s.dur),l.connect(c),c.connect(t.destination),l.start(i),l.stop(i+s.dur+.05)}function Qe(t,s=dn()){if(!s.enabled||!s[t])return;const a=sr();if(!a)return;const l=Math.max(0,Math.min(1,s.volume/100));for(const c of lr[t])or(a,c,l)}const Lt="pi-web-ui:theme",un="dark",Ns="theme-stylesheet",Cs="pi-web-ui:theme-change";function pn(){try{const t=localStorage.getItem(Lt);if(t&&t!==un)return t}catch{}return null}function cr(t){try{t?localStorage.setItem(Lt,t):localStorage.removeItem(Lt)}catch{}}function mn(t){let s=document.getElementById(Ns);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(Cs));return}s||(s=document.createElement("link"),s.id=Ns,s.rel="stylesheet",document.head.appendChild(s)),s.href=`/themes/${encodeURIComponent(t)}.css`,s.onload=()=>window.dispatchEvent(new CustomEvent(Cs))}async function dr(){try{const t=await fetch(ft("/api/themes"));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function ur(){const[t,s]=r.useState([]),[a,l]=r.useState(()=>pn());return r.useEffect(()=>{let i=!1;return dr().then(n=>{i||s(n)}),()=>{i=!0}},[]),r.useEffect(()=>{mn(a),cr(a)},[a]),{themes:t,theme:a,switchTheme:i=>l(i===un?null:i)}}function yr(){const t=getComputedStyle(document.documentElement),s=(a,l)=>t.getPropertyValue(a).trim()||l;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const pr=r.lazy(()=>Rs(()=>import("./TerminalPanel-CqkXPEV8.js"),__vite__mapDeps([0,1,2,3,4])).then(t=>({default:t.TerminalPanel})));function mr({notice:t,onDismiss:s}){const a=me(),[l,c]=r.useState(!1);r.useEffect(()=>{if(l)return;const n=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(n)},[l,t.id,t.level,s]);const i=t.level==="error"?ei:t.level==="warning"?Zn:Un;return e.jsxs("div",{className:`notice notice-${t.level}${l?" paused":""}`,role:"status",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsx(i,{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(ke,{})})]})}const hr=[],hn=180,gn=520,fn=240,xn=t=>`pi-web-ui:${t}-panel-width`;function Ss(t){const s=Number(localStorage.getItem(xn(t)));return Number.isFinite(s)&&s>=hn&&s<=gn?s:fn}function Ts({side:t,width:s,onResize:a}){const l=me(),c=r.useCallback(i=>{i.preventDefault();const n=i.clientX,o=s;let u=o;const p=g=>{const v=t==="left"?g.clientX-n:n-g.clientX;u=Math.min(gn,Math.max(hn,Math.round(o+v))),a(u)},h=()=>{window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",h),document.body.classList.remove("panel-resizing"),localStorage.setItem(xn(t),String(u))};window.addEventListener("pointermove",p),window.addEventListener("pointerup",h),document.body.classList.add("panel-resizing")},[t,s,a]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:l("dragToResize"),onPointerDown:c,onDoubleClick:()=>a(fn)})}function gr(){var V,O,ie,de,ye,Se,Ot,Wt,Ht,qt,Kt,Ut,zt,Vt;const t=me(),{chat:s,send:a,dismissNotice:l,pushNotice:c,terminal:i}=Ni(),[n,o]=r.useState([]),[u,p]=r.useState(null),[h,g]=r.useState(!1),[v,b]=r.useState("chat"),k=r.useMemo(()=>s.plugins.filter(F=>{var q,ae;return!((ae=(q=s.settings)==null?void 0:q.disabledPlugins)!=null&&ae.includes(F.id))}),[s.plugins,(V=s.settings)==null?void 0:V.disabledPlugins]),[D,E]=r.useState([]);r.useEffect(()=>gi(E),[]),r.useEffect(()=>{fi(k,s.pluginsEpoch)},[k,s.pluginsEpoch]);const[A,y]=r.useState(()=>Ss("left")),[j,R]=r.useState(()=>Ss("right")),L=r.useCallback(F=>y(F),[]),M=r.useCallback(F=>R(F),[]),[C,m]=r.useState(null),[B,W]=r.useState(()=>window.matchMedia("(max-width: 768px)").matches);r.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),q=ae=>W(ae.matches);return F.addEventListener("change",q),()=>F.removeEventListener("change",q)},[]);const[ee,ne]=r.useState(!1),[H,K]=r.useState(!1),[I,T]=r.useState(!1),[S,U]=r.useState(!1),[_,z]=r.useState(!1);r.useEffect(()=>{const F=q=>{var Pe,Gt;const ae=q.detail,fe=(ae==null?void 0:ae.title)||"插件命令",xe=ae==null?void 0:ae.command;if(!xe||!s.ready)return;const je={name:fe,command:xe,cwd:"${pwd}"},ve=s.terminals.find(vt=>vt.title===fe);if(ve)i.restart(ve.id),a({type:"run_command",terminalId:ve.id,conversationId:ve.conversationId,command:je,cols:80,rows:24});else{const vt=De();i.create({id:vt,conversationId:s.activeConversationId||((Pe=s.state)==null?void 0:Pe.conversationId)||"",title:fe,cwd:((Gt=s.state)==null?void 0:Gt.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:je})}b("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,i,a]),r.useEffect(()=>{const F=q=>{!(q.ctrlKey||q.metaKey)||q.key.toLowerCase()!=="k"||(q.preventDefault(),z(ae=>!ae))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[N,X]=r.useState(dn),{themes:te,theme:ce,switchTheme:$}=ur(),Y=r.useRef(null),oe=r.useRef(null),Q=r.useRef(0),ue=r.useRef(!1),Z=r.useRef(s.terminals);r.useEffect(()=>{tr(N)},[N]),r.useEffect(()=>{var q;const F=Z.current;Z.current=s.terminals;for(const ae of s.terminals){const fe=((q=ae.command)==null?void 0:q.command)??"",xe=F.find(je=>je.id===ae.id);!(xe!=null&&xe.running)||ae.running||(fe.startsWith("pi remove ")?a({type:"extensions_reload"}):(fe.startsWith("pi-web-ui install ")||fe.startsWith("pi-web-ui uninstall "))&&a({type:"plugins_reload"}))}},[s.terminals,a]),r.useEffect(()=>{var ae;const F=((ae=s.state)==null?void 0:ae.isStreaming)??!1,q=Y.current;Y.current=F,q!==null&&(!q&&F?Qe("start",N):q&&!F&&Qe("done",N))},[(O=s.state)==null?void 0:O.isStreaming,N]),r.useEffect(()=>{var q;const F=((q=s.dialog)==null?void 0:q.id)??null;F!==null&&F!==oe.current&&Qe("question",N),oe.current=F},[s.dialog,N]),r.useEffect(()=>{const F=[...s.notices].reverse().find(q=>q.level==="error");F&&F.id!==Q.current&&(Q.current=F.id,Qe("error",N))},[s.notices,N]);const d=(F,q,ae,fe=!1,xe)=>{const je=`${F}|${ae}|${xe?`${xe.start}-${xe.end}`:""}`;o(ve=>ve.some(Pe=>`${Pe.path}|${Pe.mode}|${Pe.lines?`${Pe.lines.start}-${Pe.lines.end}`:""}`===je)?ve:[...ve,{path:F,name:q,mode:ae,isDir:fe,...xe?{lines:xe}:{}}])},P=F=>o(q=>q.filter(ae=>ae.key?ae.key!==F:ae.path!==F)),le=r.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&m(null),a(F)),[a]),se=r.useRef(0),he=r.useRef(0),J=F=>{var fe;const q=Date.now();(fe=s.state)!=null&&fe.model&&!s.state.model.vision&&q-he.current>1e4&&(he.current=q,c("warning",t("imageNotSupported")));const ae=`paste-${++se.current}`;o(xe=>[...xe,{path:"",key:ae,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},re=async F=>{for(const q of F){const ae=await Gs(q);if(!ae){c("error",t("imageLoadFailed",{name:q.name}));continue}J(ae)}},ge=20*1024*1024,pe=r.useRef(0),we=async F=>{if(F.size>ge){c("warning",t("fileTooLarge",{name:F.name,size:ge/1024/1024}));return}let q;try{q=(await new Promise((xe,je)=>{const ve=new FileReader;ve.onload=()=>xe(ve.result),ve.onerror=()=>je(ve.error??new Error("read failed")),ve.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const ae=`upload-${++pe.current}`;o(fe=>[...fe,{path:"",key:ae,name:F.name,mode:"inline",fileData:q,size:F.size,mimeType:F.type||void 0}])},Be=async F=>{for(const q of F)Me(q.type)?await re([q]):await we(q)},_e=r.useCallback((F,q,ae)=>{a({type:"edit_message",messageId:F,text:q,attachments:ae})},[a]),Ve=r.useCallback(()=>K(!0),[]),Ge=r.useCallback(()=>o([]),[]),Ce=r.useCallback(P,[]),Oe=r.useCallback(re,[re]),Fe=r.useCallback(Be,[Be]),Ne=(ie=s.state)==null?void 0:ie.model,Re=(de=s.state)==null?void 0:de.thinkingLevel,w=(ye=s.state)==null?void 0:ye.availableThinkingLevels,f=r.useMemo(()=>Ne?{model:Ne,thinkingLevel:Re??"off",availableThinkingLevels:w??[]}:null,[Ne,Re,w]),x=r.useCallback(()=>{var F,q;return!s.ready||s.terminals.length!==0?!1:(i.create({id:De(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((q=s.state)==null?void 0:q.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(Se=s.state)==null?void 0:Se.cwd,s.terminals.length,t,i]);return r.useEffect(()=>{if(ue.current){if(v!=="terminal"||s.terminals.length!==0){ue.current=!1;return}x()&&(ue.current=!1)}},[s.terminals.length,x,v]),e.jsxs("div",{className:"app",onDragOver:F=>{var q;Array.from(((q=F.dataTransfer)==null?void 0:q.types)??[]).includes("Files")&&(F.preventDefault(),g(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||g(!1)},onDrop:F=>{var xe,je;if(g(!1),!Array.from(((xe=F.dataTransfer)==null?void 0:xe.types)??[]).includes("Files"))return;F.preventDefault();const q=Array.from(((je=F.dataTransfer)==null?void 0:je.files)??[]);if(q.length===0){c("warning",t("foldersNotSupported"));return}const ae=q.filter(ve=>Me(ve.type)),fe=q.filter(ve=>!Me(ve.type));ae.length>0&&re(ae),fe.length>0&&Be(fe)},children:[h&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(ri,{chat:s,send:a,terminal:i,view:v,plugins:k,onViewChange:F=>{ue.current=F==="terminal"&&s.terminals.length===0,ue.current&&x()&&(ue.current=!1),b(F),m(null)},onOpenPanel:m,onOpenSettings:()=>T(!0),onOpenBgTasks:()=>U(!0),onOpenGlobalSearch:()=>z(!0),sound:N,onSoundChange:X,onSoundPreview:F=>Qe(F,N),themes:te,theme:ce,onThemeChange:$}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(mr,{notice:F,onDismiss:l},F.id))}),e.jsx(ja,{send:a,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${A}px`,"--right-w":`${j}px`},children:[C&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>m(null)}),e.jsxs("div",{className:`view-pane ${v==="chat"?"":"hidden"}`,children:[e.jsx("div",{className:`panel-drawer drawer-left ${C==="left"?"open":""}`,children:e.jsx(oi,{send:le,active:!B||C==="left",ready:s.ready,status:s.status,cwd:((Ot=s.state)==null?void 0:Ot.cwd)??"",sessionFile:((Wt=s.state)==null?void 0:Wt.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!B&&e.jsx(Ts,{side:"left",width:A,onResize:L}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(Ea,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:_e,onKillBash:()=>a({type:"abort_bash"}),thinkingWrap:((Ht=s.settings)==null?void 0:Ht.thinkingWrap)??!0,toolsWrap:((qt=s.settings)==null?void 0:qt.toolsWrap)??!0},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(Aa,{send:a,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId}),s.dialog&&e.jsx(Oa,{dialog:s.dialog,send:a}),e.jsx(Fa,{send:a,ready:s.ready,streaming:((Kt=s.state)==null?void 0:Kt.isStreaming)??!1,messages:((Ut=s.state)==null?void 0:Ut.messages)??hr,slashCommands:s.slashCommands,modelState:f,models:s.models,modelsLoading:s.modelsLoading,attachments:n,onRemoveAttachment:Ce,onAddImageFiles:Oe,onAddLocalFiles:Fe,onNotice:c,onManageModels:Ve,onSent:Ge})]}),!B&&e.jsx(Ts,{side:"right",width:j,onResize:M}),e.jsx("div",{className:`panel-drawer drawer-right ${C==="right"?"open":""}`,children:e.jsx(Li,{send:le,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((zt=s.state)==null?void 0:zt.cwd)??"",onAttach:(F,q,ae,fe)=>{m(null),d(F,q,ae,fe)},onPreview:(F,q)=>{m(null),p({path:F,name:q})},onNotice:(F,q)=>c(F,q)})})]}),e.jsx("div",{className:`view-pane ${v==="terminal"?"":"hidden"}`,children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(pr,{chat:s,send:a,terminal:i})})}),e.jsx("div",{className:`view-pane ${v==="git"?"":"hidden"}`,children:e.jsx(Ha,{chat:s,send:a,terminal:i,active:v==="git",onSwitchToTerminal:()=>b("terminal")})}),D.map(F=>{const q=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${v===q?"":"hidden"}`,children:e.jsx(qa,{entry:F,send:a})},F.info.id)})]})}),e.jsx($a,{chat:s,send:a}),u&&e.jsx(Za,{file:u,content:s.fileContent,send:a,onAddLines:(F,q,ae,fe)=>d(F,q,"lines",!1,{start:ae,end:fe}),onAttach:(F,q,ae)=>d(F,q,ae),onClose:()=>p(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!ee&&!H&&e.jsx(Ka,{send:a,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>ne(!0)}),H&&e.jsx(Va,{send:a,providers:s.modelsConfig,providerStatus:s.providers,fetchModelsResult:s.fetchModelsResult,refreshProviderResult:s.refreshProviderResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>K(!1)}),I&&e.jsx(Ja,{chat:s,send:a,terminal:i,onSwitchToTerminal:()=>b("terminal"),onClose:()=>T(!1)}),S&&e.jsx(Qa,{servers:s.bgServers,send:a,onClose:()=>U(!1)}),_&&e.jsx(Xa,{send:a,sessions:s.sessions,projects:s.projects,cwd:((Vt=s.state)==null?void 0:Vt.cwd)??"",fileSearch:s.fileSearch,onClose:()=>z(!1),onSwitchSession:F=>{a({type:"switch_session",path:F})},onSwitchProject:F=>{a({type:"set_cwd",path:F})},onPreviewFile:(F,q)=>{p({path:F,name:q})}})]})}ci();mn(pn());bn.createRoot(document.getElementById("root")).render(e.jsx(r.StrictMode,{children:e.jsx(ii,{children:e.jsx(gr,{})})}));export{pt as F,Cs as T,Le as a,yr as b,vr as c,Et as d,Ee as e,ke as f,On as g,Ke as h,De as r,me as u};
|