pi-web-ui 0.64.6 → 0.64.8

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.
Files changed (70) hide show
  1. package/dist/server/agent-service.js +69 -33
  2. package/dist/server/settings-service.js +1 -1
  3. package/dist/server/subagents.js +2 -2
  4. package/dist/server/webui-context.js +3 -3
  5. package/package.json +1 -1
  6. package/web/dist/assets/{TerminalPanel-CoPFNu1d.js → TerminalPanel-DL8sTcRC.js} +1 -1
  7. package/web/dist/assets/{abnfDiagram-VCTEODGH-Dltz1N0G.js → abnfDiagram-VCTEODGH-BF9usV5C.js} +1 -1
  8. package/web/dist/assets/{arc-QOm2xRll.js → arc-BHXahvV5.js} +1 -1
  9. package/web/dist/assets/{architectureDiagram-5GKGNRK7-L3XUBFbb.js → architectureDiagram-5GKGNRK7-V2QNH_BW.js} +1 -1
  10. package/web/dist/assets/{blockDiagram-I7D4REHJ-CJmza4yx.js → blockDiagram-I7D4REHJ-DNWe8D5y.js} +1 -1
  11. package/web/dist/assets/{c4Diagram-7LVT6UL2-CwgA5WEW.js → c4Diagram-7LVT6UL2-Cd7YCdDn.js} +1 -1
  12. package/web/dist/assets/channel-DDCgqHU5.js +1 -0
  13. package/web/dist/assets/{chunk-2Q5K7J3B-DoqSiCVF.js → chunk-2Q5K7J3B-Dn4M1g1T.js} +1 -1
  14. package/web/dist/assets/{chunk-5VM5RSS4-CO14GhQ1.js → chunk-5VM5RSS4-U5uyVkTI.js} +1 -1
  15. package/web/dist/assets/{chunk-F27PBJKO-kRFf9SDx.js → chunk-F27PBJKO-lMqDdknq.js} +1 -1
  16. package/web/dist/assets/{chunk-IMKFNOWR-Cm6JOqm0.js → chunk-IMKFNOWR-DlzpFcKz.js} +1 -1
  17. package/web/dist/assets/{chunk-JWPE2WC7-DTpnGTdB.js → chunk-JWPE2WC7-BdI7zobW.js} +1 -1
  18. package/web/dist/assets/{chunk-POPQ4Y6H-CdSt_7xq.js → chunk-POPQ4Y6H-Dk7oA6BE.js} +1 -1
  19. package/web/dist/assets/{chunk-SVP7TREG-IQRTD_4U.js → chunk-SVP7TREG-BhXOKkNm.js} +1 -1
  20. package/web/dist/assets/{chunk-TICWLB2K-Duj1rt_5.js → chunk-TICWLB2K-DFW_5Q5s.js} +1 -1
  21. package/web/dist/assets/{chunk-XXDRQBXY-BFf3gcbL.js → chunk-XXDRQBXY-d-B9YyVA.js} +1 -1
  22. package/web/dist/assets/classDiagram-ZZMXUADV-DnlRT21K.js +1 -0
  23. package/web/dist/assets/classDiagram-v2-VYDZK3BY-DnlRT21K.js +1 -0
  24. package/web/dist/assets/{cose-bilkent-JH36ORCC-D5k0Z1dx.js → cose-bilkent-JH36ORCC-W3IYYiNN.js} +1 -1
  25. package/web/dist/assets/{cynefin-OW5HDTMX-OsV-x0h-.js → cynefin-OW5HDTMX-DVcVxvWj.js} +1 -1
  26. package/web/dist/assets/{cynefinDiagram-5FMLGOSQ-DM7XHm4s.js → cynefinDiagram-5FMLGOSQ-DdUHHDle.js} +1 -1
  27. package/web/dist/assets/{dagre-GXQ25YYZ-B0bIbgMh.js → dagre-GXQ25YYZ-DMqzPbm8.js} +1 -1
  28. package/web/dist/assets/{diagram-S7CK7UJ4-lMVsMjfI.js → diagram-S7CK7UJ4-g-T7ZpRp.js} +1 -1
  29. package/web/dist/assets/{diagram-UQ7AKVKN-BJDbkaYf.js → diagram-UQ7AKVKN-Cj1HB5mV.js} +1 -1
  30. package/web/dist/assets/{diagram-VSXAHHWV-1zUfVr-L.js → diagram-VSXAHHWV-D4Xgm5yq.js} +1 -1
  31. package/web/dist/assets/{diagram-VX7I27RA-B-Qy3dth.js → diagram-VX7I27RA-CPaDZ0sg.js} +1 -1
  32. package/web/dist/assets/{diagram-Z3DM3KII-DbKcoZFP.js → diagram-Z3DM3KII-BwroUmR-.js} +1 -1
  33. package/web/dist/assets/{ebnfDiagram-PWID7BFC-CuMZBzDi.js → ebnfDiagram-PWID7BFC-CymjTfGP.js} +1 -1
  34. package/web/dist/assets/{erDiagram-RLTQ6QDP-Dkw_Uhg2.js → erDiagram-RLTQ6QDP-CkCv1f0Q.js} +1 -1
  35. package/web/dist/assets/{flowDiagram-HODETNUW-CwDYMy38.js → flowDiagram-HODETNUW-IrWWLHqn.js} +1 -1
  36. package/web/dist/assets/{ganttDiagram-EL5Y4UJY-B2s3myqg.js → ganttDiagram-EL5Y4UJY-DhHylBej.js} +1 -1
  37. package/web/dist/assets/{gitGraphDiagram-WWUBYQGX-CJ3rUTG5.js → gitGraphDiagram-WWUBYQGX-C1O_4b0m.js} +1 -1
  38. package/web/dist/assets/{index-30RM921r.js → index-B-D8dBbi.js} +24 -24
  39. package/web/dist/assets/index-DWUw-5kk.css +10 -0
  40. package/web/dist/assets/{infoDiagram-27XIBGKW-DuIoOHyL.js → infoDiagram-27XIBGKW-B3SzbIHm.js} +1 -1
  41. package/web/dist/assets/{ishikawaDiagram-5VMMS53U-Fm14e_CH.js → ishikawaDiagram-5VMMS53U-CM5U90LI.js} +1 -1
  42. package/web/dist/assets/{journeyDiagram-3NMN7TZE-BuokOq_3.js → journeyDiagram-3NMN7TZE-BIWbaonv.js} +1 -1
  43. package/web/dist/assets/{kanban-definition-UXKFOSKX-D2FQMRnh.js → kanban-definition-UXKFOSKX-Cg0FRvzj.js} +1 -1
  44. package/web/dist/assets/{layout-CZUvkkNF.js → layout-BMZQTQDF.js} +1 -1
  45. package/web/dist/assets/{linear-tIFeS1QT.js → linear--htAmwBy.js} +1 -1
  46. package/web/dist/assets/{mermaid.core-BI5_3AOv.js → mermaid.core-Bxpg8jiH.js} +5 -5
  47. package/web/dist/assets/{mindmap-definition-YA3MSWOX-D5RmpgpB.js → mindmap-definition-YA3MSWOX-CNp9C6Gy.js} +1 -1
  48. package/web/dist/assets/{pegDiagram-XKGWAZYB-DpZxaRI3.js → pegDiagram-XKGWAZYB-B4mLGlJp.js} +1 -1
  49. package/web/dist/assets/{pieDiagram-E7YTZNPT-Co7MADQz.js → pieDiagram-E7YTZNPT-hP4zuAzM.js} +1 -1
  50. package/web/dist/assets/{quadrantDiagram-AXDQQJYC-BsRraVQ-.js → quadrantDiagram-AXDQQJYC-DVN-GEzm.js} +1 -1
  51. package/web/dist/assets/{railroadDiagram-O6MQD6OU-DW2pw5p_.js → railroadDiagram-O6MQD6OU-BjBVdCWk.js} +1 -1
  52. package/web/dist/assets/{requirementDiagram-BXWQKSXE-DeaEY9Dk.js → requirementDiagram-BXWQKSXE-BOwNWcER.js} +1 -1
  53. package/web/dist/assets/{sankeyDiagram-P5KCCOFB-BlKg1xhH.js → sankeyDiagram-P5KCCOFB-CkK6Y6CK.js} +1 -1
  54. package/web/dist/assets/{sequenceDiagram-WJ2MYXX4-C0ffpRmx.js → sequenceDiagram-WJ2MYXX4-D49cIkIS.js} +1 -1
  55. package/web/dist/assets/{sizeCapture-INFHLROL-DHFDdkAo.js → sizeCapture-INFHLROL-D9R6YbVj.js} +1 -1
  56. package/web/dist/assets/{stateDiagram-D77RDMKH-CwKStGSS.js → stateDiagram-D77RDMKH-DvwH4KPJ.js} +1 -1
  57. package/web/dist/assets/stateDiagram-v2-MP3YSRHH-CHVwI1ZU.js +1 -0
  58. package/web/dist/assets/{swimlanes-42K2YHIH-MB6Uskqk.js → swimlanes-42K2YHIH-DgpCt172.js} +1 -1
  59. package/web/dist/assets/swimlanesDiagram-VR7AAH4N-L7ZmzB2n.js +8 -0
  60. package/web/dist/assets/{timeline-definition-24CTP7MA-CkcuHQ1A.js → timeline-definition-24CTP7MA-Cy-6c2rf.js} +1 -1
  61. package/web/dist/assets/{vennDiagram-4TSXK5OY-DRiGv5ga.js → vennDiagram-4TSXK5OY-D05mFAgh.js} +1 -1
  62. package/web/dist/assets/{wardleyDiagram-VM6X3IG4-Cwldlf89.js → wardleyDiagram-VM6X3IG4--c9A1xky.js} +1 -1
  63. package/web/dist/assets/{xychartDiagram-S5SC5T6Z-Biqu8RpV.js → xychartDiagram-S5SC5T6Z-F6B_ZHcI.js} +1 -1
  64. package/web/dist/index.html +2 -2
  65. package/web/dist/assets/channel-VncP7yyT.js +0 -1
  66. package/web/dist/assets/classDiagram-ZZMXUADV-BWCNDr-F.js +0 -1
  67. package/web/dist/assets/classDiagram-v2-VYDZK3BY-BWCNDr-F.js +0 -1
  68. package/web/dist/assets/index-B_lYcsGw.css +0 -10
  69. package/web/dist/assets/stateDiagram-v2-MP3YSRHH-B0qJoPpx.js +0 -1
  70. package/web/dist/assets/swimlanesDiagram-VR7AAH4N-IYPIFoU6.js +0 -8
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-BI5_3AOv.js","assets/markdown-BJJLXG-8.js","assets/TerminalPanel-CoPFNu1d.js","assets/xterm-D1D2FVe3.js","assets/react-ezqUM1Or.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
- import{R as Ye,a as l,j as e,M as gi,b as fi,c as xi}from"./markdown-BJJLXG-8.js";import{r as hn}from"./react-ezqUM1Or.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))r(c);new MutationObserver(c=>{for(const i of c)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(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 r(c){if(c.ep)return;c.ep=!0;const i=n(c);fetch(c.href,i)}})();var ht={},Ts;function yi(){if(Ts)return ht;Ts=1;var t=hn();return ht.createRoot=t.createRoot,ht.hydrateRoot=t.hydrateRoot,ht}var vi=yi();const bi="modulepreload",ki=function(t){return"/"+t},Es={},gn=function(s,n,r){let c=Promise.resolve();if(n&&n.length>0){let a=function(m){return Promise.all(m.map(y=>Promise.resolve(y).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=a(n.map(m=>{if(m=ki(m),m in Es)return;Es[m]=!0;const y=m.endsWith(".css"),g=y?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${g}`))return;const x=document.createElement("link");if(x.rel=y?"stylesheet":bi,y||(x.as="script"),x.crossOrigin="",x.href=m,u&&x.setAttribute("nonce",u),document.head.appendChild(x),y)return new Promise((b,E)=>{x.addEventListener("load",b),x.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${m}`)))})}))}function i(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return c.then(a=>{for(const o of a||[])o.status==="rejected"&&i(o.reason);return s().catch(i)})};var fn={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ps=Ye.createContext&&Ye.createContext(fn),ji=["attr","size","title"];function wi(t,s){if(t==null)return{};var n,r,c=Ni(t,s);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(c[n]=t[n])}return c}function Ni(t,s){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;n[r]=t[r]}return n}function bt(){return bt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},bt.apply(null,arguments)}function Ms(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),n.push.apply(n,r)}return n}function kt(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Ms(Object(n),!0).forEach(function(r){Ci(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ms(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Ci(t,s,n){return(s=Si(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Si(t){var s=Ti(t,"string");return typeof s=="symbol"?s:s+""}function Ti(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function xn(t){return t&&t.map((s,n)=>Ye.createElement(s.tag,kt({key:n},s.attr),xn(s.child)))}function se(t){return s=>Ye.createElement(Ei,bt({attr:kt({},t.attr)},s),xn(t.child))}function Ei(t){var s=n=>{var r=t.attr,c=t.size,i=t.title,a=wi(t,ji),o=c||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),Ye.createElement("svg",bt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,a,{className:u,style:kt(kt({color:t.color||n.color},n.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),i&&Ye.createElement("title",null,i),t.children)};return Ps!==void 0?Ye.createElement(Ps.Consumer,null,n=>s(n)):s(fn)}function Pi(t){return se({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 Mi(t){return se({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 xt(t){return se({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 Pe(t){return se({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 yn(t){return se({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 Rs(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"},child:[]},{tag:"circle",attr:{cx:"9",cy:"7",r:"4"},child:[]},{tag:"path",attr:{d:"M23 21v-2a4 4 0 0 0-3-3.87"},child:[]},{tag:"path",attr:{d:"M16 3.13a4 4 0 0 1 0 7.75"},child:[]}]})(t)}function Ri(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"17 8 12 3 7 8"},child:[]},{tag:"line",attr:{x1:"12",y1:"3",x2:"12",y2:"15"},child:[]}]})(t)}function Ii(t){return se({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 Ae(t){return se({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 tt(t){return se({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 Is(t){return se({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 Ls(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"},child:[]},{tag:"line",attr:{x1:"7",y1:"7",x2:"7.01",y2:"7"},child:[]}]})(t)}function Li(t){return se({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 jt(t){return se({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 Di(t){return se({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 wt(t){return se({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 vn(t){return se({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 Nt(t){return se({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 Ai(t){return se({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 bn(t){return se({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 rt(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"23 4 23 10 17 10"},child:[]},{tag:"polyline",attr:{points:"1 20 1 14 7 14"},child:[]},{tag:"path",attr:{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"},child:[]}]})(t)}function He(t){return se({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 ao(t){return se({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 _i(t){return se({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 Ds(t){return se({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 Bi(t){return se({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 Fi(t){return se({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 st(t){return se({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 $i(t){return se({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 Hi(t){return se({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 Oi(t){return se({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 Ki(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},child:[]},{tag:"path",attr:{d:"M7 11V7a5 5 0 0 1 10 0v4"},child:[]}]})(t)}function Gt(t){return se({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 Ct(t){return se({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 Wi(t){return se({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 Ui(t){return se({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 qi(t){return se({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 zi(t){return se({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 As(t){return se({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 yt(t){return se({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 Je(t){return se({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 Vi(t){return se({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 kn(t){return se({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 Qt(t){return se({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 Yt(t){return se({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 St(t){return se({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 ls(t){return se({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 lt(t){return se({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 Gi(t){return se({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 jn(t){return se({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 Qi(t){return se({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 _s(t){return se({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:"polyline",attr:{points:"12 6 12 12 16 14"},child:[]}]})(t)}function wn(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"13 17 18 12 13 7"},child:[]},{tag:"polyline",attr:{points:"6 17 11 12 6 7"},child:[]}]})(t)}function Nn(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"11 17 6 12 11 7"},child:[]},{tag:"polyline",attr:{points:"18 17 13 12 18 7"},child:[]}]})(t)}function ut(t){return se({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 Pt(t){return se({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 Ge(t){return se({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 pt(t){return se({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 Yi(t){return se({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 Lt(t){return se({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 Ji(t){return se({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 Xi(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"},child:[]},{tag:"path",attr:{d:"M13.73 21a2 2 0 0 1-3.46 0"},child:[]}]})(t)}function Cn(t){return se({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 Sn(t){return se({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 Zi(t){return se({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"21 8 21 21 3 21 3 8"},child:[]},{tag:"rect",attr:{x:"1",y:"3",width:"22",height:"5"},child:[]},{tag:"line",attr:{x1:"10",y1:"12",x2:"14",y2:"12"},child:[]}]})(t)}function ea(t){return se({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 ta(t){return se({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 sa(t){return t.map(s=>s.kind==="package"?`pi update npm:${s.name}`:`npm i -g ${s.name}@latest`).join("; ")}function Ue(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function ze({trigger:t,open:s,onOpenChange:n,children:r,align:c="right",fit:i=!1,direction:a="down",menuClassName:o,menuRef:u,menuStyle:m}){const y=l.useRef(null);return l.useEffect(()=>{if(!s)return;const g=b=>{y.current&&!y.current.contains(b.target)&&n(!1)},x=b=>{b.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",x)}},[s,n]),e.jsxs("div",{className:`dropdown ${c} ${i?"fit":""} ${a==="up"?"dd-up":""}`,ref:y,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(Ge,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:u,style:m,children:r})]})}function Ie({active:t,disabled:s=!1,title:n,onClick:r,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:r,children:c})}const Tn="pi-web-ui:lang",Bs={docTitle:"pi-web-ui — pi 编码智能体",cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",collapsePanel:"收起面板",expandPanel:"展开面板",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",engineBadge:"引擎",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",cwdGoUp:"上级目录",cwdPickCurrent:"选择当前目录",cwdChoose:"选择",cwdEnter:"进入",cwdEmpty:"(空目录)",cwdNewFolder:"新建文件夹",cwdNewName:"文件夹名称",cwdCreate:"创建",cwdCancel:"取消",cacheHit:"缓存命中",cacheHitTip:"缓存读取 {read} · 缓存写入 {write} · 未命中 {miss}(共 {input} 输入 token)",tps:"t/s",rateTip:"实时生成速率(估算)",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:"排队",queueRemoveTip:"移除此排队消息",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",mermaidRendering:"图表渲染中…",mermaidRenderFailed:"图表渲染失败,以下为原始代码:",mermaidRenderSetting:"渲染 Mermaid 图表",mermaidRenderSettingDesc:"开启后,消息中的 ```mermaid 代码块会渲染为图表;关闭则始终按普通代码块显示,跳过图表引擎的加载与渲染开销",recentProjects:"最近项目",runningConversations:"运行的对话",subagentBadge:"子代理",convErrorBadge:"子代理运行报错:{error}",subagentTitle:"子代理 · {title}",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",renameSession:"重命名该对话",renameSessionPlaceholder:"输入新名称…",renameSessionConfirm:"重命名",dismissConversation:"从运行列表移出(历史记录保留)",dismissConversationConfirm:"确认移出",collapseSection:"折叠",expandSection:"展开",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",updatesAllTitle:"全部组件更新",updatesAllBadge:"{n} 个更新",updatesAllUpToDate:"全部组件均为最新",kindWebUi:"Web 界面",kindPiCore:"核心",kindPackage:"组件",updatesAllRefresh:"重新检查全部",updateCheckFailed:"检查失败",updateBtn:"更新",updateAllBtn:"全部更新",updatePkgTabTitle:"更新 {name}",updateAllTabTitle:"更新全部组件",computer:"此电脑",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",fileNotFoundShort:"文件不存在",pluginMountFailed:"插件 {name} 挂载失败",liveOutputOmitted:`…[前 {n} 字符已省略]…
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-Bxpg8jiH.js","assets/markdown-BJJLXG-8.js","assets/TerminalPanel-DL8sTcRC.js","assets/xterm-D1D2FVe3.js","assets/react-ezqUM1Or.js","assets/TerminalPanel-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
+ import{R as Ye,a as l,j as e,M as gi,b as fi,c as xi}from"./markdown-BJJLXG-8.js";import{r as hn}from"./react-ezqUM1Or.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))r(c);new MutationObserver(c=>{for(const a of c)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(c){const a={};return c.integrity&&(a.integrity=c.integrity),c.referrerPolicy&&(a.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?a.credentials="include":c.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(c){if(c.ep)return;c.ep=!0;const a=n(c);fetch(c.href,a)}})();var ht={},Ts;function yi(){if(Ts)return ht;Ts=1;var t=hn();return ht.createRoot=t.createRoot,ht.hydrateRoot=t.hydrateRoot,ht}var vi=yi();const bi="modulepreload",ki=function(t){return"/"+t},Es={},gn=function(s,n,r){let c=Promise.resolve();if(n&&n.length>0){let i=function(m){return Promise.all(m.map(y=>Promise.resolve(y).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=i(n.map(m=>{if(m=ki(m),m in Es)return;Es[m]=!0;const y=m.endsWith(".css"),g=y?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${g}`))return;const x=document.createElement("link");if(x.rel=y?"stylesheet":bi,y||(x.as="script"),x.crossOrigin="",x.href=m,u&&x.setAttribute("nonce",u),document.head.appendChild(x),y)return new Promise((b,T)=>{x.addEventListener("load",b),x.addEventListener("error",()=>T(new Error(`Unable to preload CSS for ${m}`)))})}))}function a(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return c.then(i=>{for(const o of i||[])o.status==="rejected"&&a(o.reason);return s().catch(a)})};var fn={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ps=Ye.createContext&&Ye.createContext(fn),ji=["attr","size","title"];function wi(t,s){if(t==null)return{};var n,r,c=Ni(t,s);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r<a.length;r++)n=a[r],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(c[n]=t[n])}return c}function Ni(t,s){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(s.indexOf(r)!==-1)continue;n[r]=t[r]}return n}function bt(){return bt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},bt.apply(null,arguments)}function Ms(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(c){return Object.getOwnPropertyDescriptor(t,c).enumerable})),n.push.apply(n,r)}return n}function kt(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Ms(Object(n),!0).forEach(function(r){Ci(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ms(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Ci(t,s,n){return(s=Si(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Si(t){var s=Ti(t,"string");return typeof s=="symbol"?s:s+""}function Ti(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,s);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function xn(t){return t&&t.map((s,n)=>Ye.createElement(s.tag,kt({key:n},s.attr),xn(s.child)))}function ne(t){return s=>Ye.createElement(Ei,bt({attr:kt({},t.attr)},s),xn(t.child))}function Ei(t){var s=n=>{var r=t.attr,c=t.size,a=t.title,i=wi(t,ji),o=c||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),Ye.createElement("svg",bt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:u,style:kt(kt({color:t.color||n.color},n.style),t.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),a&&Ye.createElement("title",null,a),t.children)};return Ps!==void 0?Ye.createElement(Ps.Consumer,null,n=>s(n)):s(fn)}function Pi(t){return ne({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 Mi(t){return ne({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 xt(t){return ne({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 Pe(t){return ne({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 yn(t){return ne({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 Rs(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"},child:[]},{tag:"circle",attr:{cx:"9",cy:"7",r:"4"},child:[]},{tag:"path",attr:{d:"M23 21v-2a4 4 0 0 0-3-3.87"},child:[]},{tag:"path",attr:{d:"M16 3.13a4 4 0 0 1 0 7.75"},child:[]}]})(t)}function Ri(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},child:[]},{tag:"polyline",attr:{points:"17 8 12 3 7 8"},child:[]},{tag:"line",attr:{x1:"12",y1:"3",x2:"12",y2:"15"},child:[]}]})(t)}function Ii(t){return ne({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 Ae(t){return ne({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 tt(t){return ne({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 Is(t){return ne({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 Ls(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"},child:[]},{tag:"line",attr:{x1:"7",y1:"7",x2:"7.01",y2:"7"},child:[]}]})(t)}function Li(t){return ne({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 jt(t){return ne({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 Di(t){return ne({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 wt(t){return ne({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 vn(t){return ne({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 Nt(t){return ne({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 Ai(t){return ne({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 bn(t){return ne({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 rt(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"23 4 23 10 17 10"},child:[]},{tag:"polyline",attr:{points:"1 20 1 14 7 14"},child:[]},{tag:"path",attr:{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"},child:[]}]})(t)}function He(t){return ne({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 ao(t){return ne({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 _i(t){return ne({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 Ds(t){return ne({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 Bi(t){return ne({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 Fi(t){return ne({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 st(t){return ne({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 $i(t){return ne({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 Hi(t){return ne({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 Oi(t){return ne({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 Ki(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"rect",attr:{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},child:[]},{tag:"path",attr:{d:"M7 11V7a5 5 0 0 1 10 0v4"},child:[]}]})(t)}function Gt(t){return ne({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 Ct(t){return ne({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 Wi(t){return ne({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 Ui(t){return ne({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 qi(t){return ne({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 zi(t){return ne({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 As(t){return ne({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 yt(t){return ne({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 Je(t){return ne({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 Vi(t){return ne({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 kn(t){return ne({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 Qt(t){return ne({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 Yt(t){return ne({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 St(t){return ne({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 ls(t){return ne({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 lt(t){return ne({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 Gi(t){return ne({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 jn(t){return ne({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 Qi(t){return ne({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 _s(t){return ne({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:"polyline",attr:{points:"12 6 12 12 16 14"},child:[]}]})(t)}function wn(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"13 17 18 12 13 7"},child:[]},{tag:"polyline",attr:{points:"6 17 11 12 6 7"},child:[]}]})(t)}function Nn(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"11 17 6 12 11 7"},child:[]},{tag:"polyline",attr:{points:"18 17 13 12 18 7"},child:[]}]})(t)}function ut(t){return ne({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 Pt(t){return ne({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 Ge(t){return ne({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 pt(t){return ne({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 Yi(t){return ne({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 Lt(t){return ne({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 Ji(t){return ne({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 Xi(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"},child:[]},{tag:"path",attr:{d:"M13.73 21a2 2 0 0 1-3.46 0"},child:[]}]})(t)}function Cn(t){return ne({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 Sn(t){return ne({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 Zi(t){return ne({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"polyline",attr:{points:"21 8 21 21 3 21 3 8"},child:[]},{tag:"rect",attr:{x:"1",y:"3",width:"22",height:"5"},child:[]},{tag:"line",attr:{x1:"10",y1:"12",x2:"14",y2:"12"},child:[]}]})(t)}function ea(t){return ne({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 ta(t){return ne({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 sa(t){return t.map(s=>s.kind==="package"?`pi update npm:${s.name}`:`npm i -g ${s.name}@latest`).join("; ")}function Ue(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}function ze({trigger:t,open:s,onOpenChange:n,children:r,align:c="right",fit:a=!1,direction:i="down",menuClassName:o,menuRef:u,menuStyle:m}){const y=l.useRef(null);return l.useEffect(()=>{if(!s)return;const g=b=>{y.current&&!y.current.contains(b.target)&&n(!1)},x=b=>{b.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",g),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",x)}},[s,n]),e.jsxs("div",{className:`dropdown ${c} ${a?"fit":""} ${i==="up"?"dd-up":""}`,ref:y,children:[e.jsxs("button",{type:"button",className:"chip",onClick:()=>n(!s),"aria-expanded":s,children:[t,e.jsx(Ge,{className:`dd-caret ${s?"up":""}`})]}),s&&e.jsx("div",{className:`dd-menu ${o??""}`,ref:u,style:m,children:r})]})}function Ie({active:t,disabled:s=!1,title:n,onClick:r,children:c}){return e.jsx("button",{type:"button",className:`dd-item ${t?"active":""}`,disabled:s,title:n,onClick:r,children:c})}const Tn="pi-web-ui:lang",Bs={docTitle:"pi-web-ui — pi 编码智能体",cancel:"取消",ok:"确定",save:"保存",close:"关闭",widgetExpand:"点击放大查看完整输出",collapsePanel:"收起面板",expandPanel:"展开面板",dragToResize:"拖拽调整宽度 · 双击复位",loading:"加载中…",connected:"已连接",connecting:"连接中…",reconnecting:"重连中…",language:"语言",langZh:"中文",langEn:"English",githubRepo:"GitHub 仓库(xing-shuyin/pi-web-ui)",copy:"复制",viewSwitch:"视图切换",chat:"对话",terminal:"终端",selectModel:"选择模型",availableModels:"可用模型",allProviders:"全部",providers:"服务商",noModels:"暂无可用模型(请先配置 API 密钥)",reasoning:"推理",vision:"识图",refreshModels:"刷新模型列表(保留手填,合并新增)",manageModels:"⚙ 管理模型(新增 / 修改)",manageModelsTitle:"管理模型",thinkingLevel:"思考强度",thinking:"思考",thinkingChip:"思考:{level}",sound:"声音",theme:"主题",themeDefault:"深色(默认)",newChat:"新对话",more:"更多",newChatTip:"新建对话(每个浏览器独立保存会话)","thinking.off":"关闭","thinking.minimal":"极简","thinking.low":"低","thinking.medium":"中","thinking.high":"高","thinking.xhigh":"极高","thinking.max":"最大",thinkingUnsupported:"当前模型不支持该级别,已按模型能力就近生效",context:"上下文",contextUsage:"上下文用量",cumulativeCost:"累计成本",sessionMessages:"会话消息数",messages:"消息",pluginStatus:"插件状态",engineBadge:"引擎",working:"工作中",queued:"排队",enterPath:"输入路径,Enter 切换",cwdTip:"工作目录:{path}(点击切换)",cwdGoUp:"上级目录",cwdPickCurrent:"选择当前目录",cwdChoose:"选择",cwdEnter:"进入",cwdEmpty:"(空目录)",cwdNewFolder:"新建文件夹",cwdNewName:"文件夹名称",cwdCreate:"创建",cwdCancel:"取消",cacheHit:"缓存命中",cacheHitTip:"缓存读取 {read} · 缓存写入 {write} · 未命中 {miss}(共 {input} 输入 token)",tps:"t/s",rateTip:"实时生成速率(估算)",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:"排队",queueRemoveTip:"移除此排队消息",sendTip:"发送(Enter)",slashCommands:"命令",slashMenuHint:"↑↓ 选择 · Enter/Tab 补全",slashHelpTitle:"pi 命令",slashHelpHint:"输入 / 随时打开命令列表",slashLoading:"命令列表加载中…(连接服务器后可用)",slashBuiltin:"内置",slashExtension:"扩展",slashPrompt:"模板",slashSkill:"技能",slashPlugin:"插件",slashCopied:"已复制上一条助手回复",slashCopyFailed:"复制失败,请手动复制",slashCopyEmpty:"还没有可复制的助手回复",mermaidRendering:"图表渲染中…",mermaidRenderFailed:"图表渲染失败,以下为原始代码:",mermaidRenderSetting:"渲染 Mermaid 图表",mermaidRenderSettingDesc:"开启后,消息中的 ```mermaid 代码块会渲染为图表;关闭则始终按普通代码块显示,跳过图表引擎的加载与渲染开销",recentProjects:"最近项目",runningConversations:"运行的对话",subagentBadge:"子代理",convErrorBadge:"子代理运行报错:{error}",subagentTitle:"子代理 · {title}",historySessions:"历史对话",openHistory:"历史对话",openFiles:"文件列表",streaming:"进行中…",noHistory:"还没有历史对话",current:"当前",messageCount:"{n} 条消息",tuiTip:"pi 终端(TUI)中的对话",deleteProject:"从最近项目移出",deleteProjectConfirm:"确认移出",deleteSession:"删除该对话记录(不可恢复)",deleteSessionConfirm:"确认删除",renameSession:"重命名该对话",renameSessionPlaceholder:"输入新名称…",renameSessionConfirm:"重命名",dismissConversation:"从运行列表移出(历史记录保留)",dismissConversationConfirm:"确认移出",collapseSection:"折叠",expandSection:"展开",emptyChat:"空对话",editReask:"编辑重问",editReaskTip:"修改此问题,并从这里重新提问(会新建一个分支对话,原对话保留)",reaskFromHere:"从此处重新提问",editPlaceholder:"修改问题内容…",editHint:"⌘/Ctrl+Enter 提交 · Esc 取消",editAttachmentHint:"原附件已保留,可粘贴/拖入新图片或文件 · ⌘/Ctrl+Enter 提交 · Esc 取消",expandMsg:"展开",collapseMsg:"收起",toolCalls:"工具调用",bashRuns:"终端运行",images:"图片",update:"更新",updateTip:"检查并更新 pi-web-ui",currentVersion:"当前版本",latestVersion:"最新版本",checkingUpdate:"检查中…",checkUpdate:"检查更新",upToDate:"已是最新版本",updateAvailable:"发现新版本 v{version}",updateJustPublished:"v{version} 刚刚发布,npm 缓存可能尚未同步——若未检测到新版本,请稍后重新检查",updateNow:"在终端中更新",updateTabTitle:"更新 pi-web-ui",updateTerminalHint:"点击后会在可见终端中运行 npm i -g pi-web-ui@latest;完成后重启服务生效(pi-web-ui server restart)。",updatesAllTitle:"全部组件更新",updatesAllBadge:"{n} 个更新",updatesAllUpToDate:"全部组件均为最新",kindWebUi:"Web 界面",kindPiCore:"核心",kindPackage:"组件",updatesAllRefresh:"重新检查全部",updateCheckFailed:"检查失败",updateBtn:"更新",updateAllBtn:"全部更新",updatePkgTabTitle:"更新 {name}",updateAllTabTitle:"更新全部组件",computer:"此电脑",rootDir:"根目录",noFiles:"暂无文件",filesTruncated:"目录过大,列表已截断,仅显示前 2000 项",linkFolderTip:"链接文件夹路径到对话",attachInlineTip:"附加内容到对话",referenceTip:"仅引用路径(AI 按需读取)",previewFile:"预览",downloadFile:"下载文件",downloadFailed:"下载失败:{error}",fileNotFoundShort:"文件不存在",pluginMountFailed:"插件 {name} 挂载失败",liveOutputOmitted:`…[前 {n} 字符已省略]…
3
3
  `,uploadToFolder:"上传文件到此文件夹",uploadToCurrentDir:"上传文件到当前目录",protocolMismatch:"页面版本与服务器不一致(应用刚更新过),请刷新页面以恢复全部功能。",selectLinesHint:"点击选择行;拖拽或 Shift+点击选择范围",enableWrap:"开启自动换行",disableWrap:"关闭自动换行",selectedRange:"已选 {n} 行(第 {start}-{end} 行)",fileLines:"{n} 行",selectAll:"全选",clearSelection:"清除",addToChat:"添加到对话",addedToChat:"已添加",previewTruncated:"⚠ 文件过大,仅预览前 512KB",previewLinesTruncated:"… 文件行数过多,仅显示前 {n} 行",binaryFile:"🔣 二进制文件,已显示前 4KB 十六进制",binaryHexTruncated:"(文件更大,可下载完整文件)",previewNotSupported:"该类型文件不支持预览(仅图片 / 视频 / 文本)",emptyFile:"(空文件)",editFile:"编辑文件",exitEditFile:"退出编辑",saveFile:"保存文件",discardFileChanges:"放弃未保存的修改?",fileSaved:"已保存",fileEditTruncated:"文件过大,预览不完整,无法编辑",showMarkdownSource:"显示 Markdown 原文",showMarkdownPreview:"显示 Markdown 预览",fullscreen:"全屏",exitFullscreen:"退出全屏",zoomIn:"放大字号",zoomOut:"缩小字号",resetZoom:"重置缩放",pluginRequest:"插件请求",modelQuestion:"模型提问",modelQuestionCustom:"补充回答(可选)",modelQuestionSubmit:"提交回答",noOptions:"(无选项)",inputPlaceholder:"输入内容",questionTimeout:"⏳ 剩余 {s} 秒,超时将自动取消",questionTimeoutExpired:"提问已超时,正在恢复对话…",modelNoVision:"当前模型 {name} 不支持图片,请切换到 DeepSeek V4 Flash Vision (exp)",dshSkillsNote:"DSH 引擎使用运行时内置技能(dsh-skill),暂不支持在设置面板启停",dshExtensionsNote:"DSH 引擎无 pi 扩展体系,能力由运行时内置(MCP/subagent/goal/plan/skill 等)",dshReviewPromptNote:"DSH 无独立审查会话:此指令将随目标轮次附加到系统提示词,供模型在目标轮次中遵守",dshVisionHiddenNote:"DSH 引擎直接支持图片输入(仅 DeepSeek V4 Flash Vision (exp) 模型),无需视觉桥转写",dshNoReviewModel:"DSH 无独立审查模型:目标由模型自判定完成/受阻,轮次上限即自动迭代次数",soundHeader:"声音提示",enableSound:"启用声音",preview:"试听",volume:"音量",notifyHeader:"桌面通知",notifyEnable:"启用桌面通知(PWA)",notifyEnableDesc:"会话完成或需要你输入时,即使切到其他应用也会提醒(需授权,仅页面前台无焦点时触发)。",notifyDenied:"通知权限已被拒绝 —— 请在浏览器/系统设置里为本站点开启通知。",notifyUnsupported:"此浏览器不支持通知。",notifyDoneTitle:"任务完成",notifyDoneBody:"会话已完成,等待你的输入。",notifyQuestionTitle:"需要你回答",notifyQuestionBody:"pi 正在等你回答一个问题。",notifyErrorTitle:"出错了",notifyErrorBody:"一个会话报告了错误。","sound.question":"问卷弹出","sound.question.desc":"ask_user_question 出现时","sound.done":"回复结束","sound.done.desc":"智能体完成一轮回答时","sound.start":"回复开始","sound.start.desc":"智能体开始新一轮时","sound.error":"出错","sound.error.desc":"出现错误提示时",setupTitle:"未检测到 pi agent 配置",setupDesc:"pi-web-ui 需要 pi 的配置目录(~/.pi/agent)和至少一个 API 密钥才能运行智能体。pi 内置了 openai、anthropic、deepseek 等服务商——选一个填密钥即可,全程无需打开终端。",installFailed:"✖ pi agent 安装失败:",retryInstall:"重试安装",skip:"跳过",installDone:"✅ pi agent CLI 已安装。选择服务商并填入 API 密钥即可开始对话:",cliReadyHint:"✅ 本地已检测到 pi agent,选择服务商并填入 API 密钥即可开始对话:",provider:"服务商",configured:"已配置",providerKeyReady:"该服务商已配置密钥,可直接使用或更换新密钥。",apiKey:"API 密钥",saving:"保存中…",saveAndStart:"保存并开始使用",recheck:"重新检测",installing:"正在安装 pi agent CLI…",autoInstall:"自动安装 pi agent",attachment:"附件",plugin:"插件",unknown:"未知",thinkingWait:"正在思考",exitCode:"退出码 {code}",cancelled:"已取消",truncated:"… 内容过长,当前视图已截断",outputTruncated:"… 输出过长,当前视图已截断",refOnlyShort:"仅引用",folderRefShort:"文件夹 · 仅引用",inlineLines:"内联 · {n} 行",inlineLinesRange:"行 {start}-{end}",image:"🖼 图片",bridgedVision:"👁 已转写",bridgedVisionDetail:"图片已由视觉桥转写(当前模型不支持识图)",folderNotExpanded:"文件夹,未展开内容 —— 智能体会按需浏览目录",fileNotExpanded:"文件较大({size}),未展开内容 —— 智能体会按需读取","role.user":"你","role.assistant":"pi","role.tool":"工具","role.bash":"终端","role.branch":"分支摘要","role.compaction":"上下文已压缩",directory:"目录",waitingResponse:"正在等待模型响应…",backToBottom:"回到底部",questionNavTitle:"问题列表",searchPlaceholder:"在对话中搜索…",searchNoResults:"无结果",searchModels:"搜索模型…",noModelMatches:"无匹配模型",modelUsedCount:"已用 {n} 次",searchGlobal:"搜索",searchGlobalTip:"全局搜索:对话 / 项目 / 文件(Ctrl+K)",gsPlaceholder:"搜索项目、历史对话、工作区文件…",gsHint:"输入关键词:搜索历史对话全文(含 AI 回复)、最近项目与当前项目的文件名",gsSessions:"对话",gsProjects:"项目",gsFiles:"文件",gsNoResults:"无匹配结果",gsSearching:"正在搜索…",gsTruncated:"匹配过多,仅显示部分结果",gsCurrentProject:"当前",gsOpenPreview:"打开文件预览",gsNavigate:"选择",gsOpen:"打开",gsCloseHint:"关闭",bgTaskCommand:"命令行",searchPrev:"上一个(Shift+Enter)",searchNext:"下一个(Enter)",searchClose:"关闭(Esc)",questionNavTip:"本对话的全部问题,悬浮展开,点击跳转","tpl.title":"提示词模板","tpl.hint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.clickCard":"点击填入输入框","tpl.editTpl":"编辑 / 删除模板","tpl.openPicker":"提示词模板(常用提示词,随时取用)","tpl.pickerTitle":"提示词模板","tpl.pickerHint":"点击卡片直接填入输入框,✏️ 可编辑或删除 · 也能新增自己的模板","tpl.add":"新建模板","tpl.addDesc":"把常用工作流存成模板","tpl.reset":"恢复默认模板","tpl.resetConfirm":"确认恢复默认?","tpl.builtin":"内置","tpl.custom":"自定义","tpl.newTitle":"新建提示词模板","tpl.editTitle":"编辑提示词模板","tpl.fieldIcon":"图标","tpl.fieldTitle":"标题","tpl.fieldTitlePh":"卡片上显示的短标题","tpl.fieldDesc":"说明","tpl.fieldDescPh":"一句话说明,显示在卡片上","tpl.fieldPrompt":"提示词","tpl.fieldPromptPh":"完整提示词 —— 发送给智能体的内容","tpl.required":"标题和提示词不能为空","tpl.save":"保存修改","tpl.fill":"填入输入框","tpl.fillTip":"填入输入框,可再编辑后发送","tpl.sendNow":"直接发送","tpl.sendTip":"立即作为新对话发送","tpl.delete":"删除","tpl.deleteTip":"删除这个自定义模板","tpl.remove":"移出模板库","tpl.removeTip":"把内置模板移出模板库,可在底部「恢复默认模板」找回","tpl.restore":"恢复默认","tpl.restoreTip":"撤掉你的修改,恢复内置默认","tpl.sk.setup":"仓库初始化","tpl.sk.setup.desc":"让仓库了解它的构建与约定","tpl.sk.setup.prompt":`请先扫描这个仓库,建立「其他工作流都能用」的基础上下文,输出一份简明报告:
4
4
 
5
5
  1. 项目类型、技术栈与目录结构
@@ -301,26 +301,26 @@ Keep going until the plan holds up.`,"tpl.sk.tdd":"Test-driven","tpl.sk.tdd.desc
301
301
  2. Make them pass with the minimal implementation
302
302
  3. Refactor while keeping tests green
303
303
 
304
- 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})",exitBanner:"[Process exited with code {code}]",closeTerminal:"Close terminal",renameTerminal:"Rename terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",aiBashGroup:"Terminal-backed bash",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git commit -m "…" in the terminal (commits staged changes only)',scmCommitAll:"Commit All",scmCommitAllTip:'Runs git add -A && git commit -m "…" in the terminal (stages all changes incl. untracked and commits)',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 — stage it with + to include (or use Commit All)",scmQueryFailed:"Git query failed: {error}",scmQueryFailedShort:"Query failed",pluginCommandFallback:"Plugin command",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:"Add key",cloning:"Adding",cloneProviderTitle:"Add a second API key for this provider (baseUrl and model list are copied automatically)",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",addKey:"Add key",addKeyPlaceholder:"Paste the key value…",keyNamePh:"Name (optional, e.g. backup)",providerIdPlaceholder:"Provider ID",baseUrlExamplePh:"baseUrl, e.g. https://api.opencode.ai/zen/v1 or http://127.0.0.1:4096",saveAllBatch:"Save all ({n})",netDisconnected:"Network disconnected — reconnect and retry",advancedEdit:"Advanced edit",batchCreateProviders:"Batch-create providers ({n} APIs)",secondKeyTitle:"Add a second key for {api} · {baseUrl} · {n} models — just name the new provider and enter the key.",noBaseUrlShort:"(no baseUrl)",providerNameLabel:"Provider name",providerNameHint:"(new ID, e.g. opencode-2)",apiKeyLabel:"API key",secondKeyPlaceholder:"sk-… second key",batchDesc:"This provider has multiple APIs ({apis}); it was split into {n} custom providers. Save each so all models (e.g. muse-spark) work. Enter one shared second key to save all at once.",batchKeyLabel:"Shared API key (applies to all {n} providers)",modelsCountShort:"{n} models: ",noKeyYet:"No key yet — add one to use this provider",activateKey:"Set active",removeKey:"Remove",removeKeyConfirm:"Remove this key? It must be re-configured to be used again.",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",settingsPromptHistory:"Input history",settingsPromptHistoryDesc:"Cycle previous prompts with ↑/↓ in the input — global across conversations (localStorage)",promptHistoryMax:"Max entries",promptHistoryMaxHint:"Oldest entries are dropped when exceeded (1–500)",promptHistoryCharLimit:"Limit characters per entry",promptHistoryCharLimitHint:"When enabled, overlong prompts are truncated before saving",promptHistoryCharLimitPlaceholder:"Max chars (100–20000)",promptHistoryClear:"Clear history",promptHistoryClearConfirm:"Confirm clear?",promptHistoryCleared:"Input history cleared",promptHistoryCount:"{n} entries",promptHistoryEmpty:"No history yet — ↑/↓ has nothing to cycle",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",settingsMarkers:"Markers",settingsMarkersDesc:"Let the AI write [[todo:...]] / [[svc:...]] / [[notify:...]] / [[conv:rename:...]] inline markers in replies to update state without a tool round-trip. Global off disables all; per-marker toggles give fine control.",markersEnabled:"Markers enabled (global)",markersEnabledDesc:"Off = no marker guidance injected and no parsing; markers stay as plain text.",markersOffHint:"Globally off: all markers disabled — the AI won't write markers and no side effects fire.",markerGroupTodo:"todo — tasks",markerGroupSvc:"svc — background services",markerGroupNotify:"notify — non-blocking hints",markerGroupRename:"conv/rename — rename chat",markerRenameTip:"[[conv:rename:Title]] or [[rename:set:Title]] renames the current conversation (≤80 chars)",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"This switch decides whether bash is overridden to a terminal version: OFF = native SDK bash (process spawn, no terminal); ON = runs in a visible terminal, where the persist parameter decides (on top of the switch) one-shot (false — process exits when the command finishes, output retained) vs persistent (true — shell state retained across calls, silent commands move to the background and notify the AI)",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"In persistent-terminal mode, when a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",dshPatches:"DSH user patches",dshPatchesDesc:"Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.",dshPatchesRescan:"Rescan",dshPatchesRescanHint:"Re-scan the patch directory and restart the DSH runtime so new patches take effect",dshPatchesEmpty:"No patch files yet",dshPatchesPath:"Patch directory: ",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",settingsPresets:"Presets",settingsSubagentTemplates:"Subagent templates",settingsSubagentTemplatesDesc:"Presets for spawned subagents (role system prompt + skills/extensions whitelist + optional model). AI may pick a template (subagent_spawn template param) or spawn without one; disabled templates stay in the panel but are invisible to AI tools.",noSubagentTemplates:"No subagent templates yet. AI can pick a template when spawning a subagent (role prompt + skills/extensions whitelist + optional model), or spawn without a template param for default config.",subagentTemplateNew:"New template",subagentTemplateEdit:"Edit",subagentTemplateClosed:"Disabled",tplDefaultBadge:"Built-in",subagentDefaultModelLabel:"Default subagent model",subagentFollowMain:"Follow the main conversation's current model",subagentDefaultModelHint:"Fallback model for all subagents (a template's own model and the subagent_spawn model param take priority); does not change the main conversation's model.",subagentNoModels:"No usable models yet (configure a provider API key first) — subagents will follow the main conversation's model.",subagentTemplateOffHint:"Disabled templates stay in the panel and can be re-enabled, but AI tools can't see or pick them",subagentTemplateEnable:"Enable",subagentTemplateDisable:"Disable",tplNamePlaceholder:"Template name (referenced by AI via subagent_spawn's template param)…",tplDescriptionPlaceholder:"Description (AI uses it to judge when to pick this template)…",tplPromptModeLabel:"System prompt mode",tplModelLabel:"Model (empty = follow main conversation)",tplSystemPromptLabel:"System prompt",tplSystemPromptPlaceholder:"Template role system prompt… (may be empty in append mode)",tplWhitelistHint:"Whitelist: checked = the subagent only gets these; none checked = follow the main session settings",tplSkillsLabel:"Skills whitelist",tplExtensionsLabel:"Extensions whitelist",tplSave:"Save template",tplCancel:"Cancel edit",tplDelete:"Delete template",tplInherit:"Follow main session",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},En=l.createContext(null);function na(){try{const t=localStorage.getItem(Tn);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ia({children:t}){const[s,n]=l.useState(na),r=l.useCallback(a=>{n(a);try{localStorage.setItem(Tn,a)}catch{}},[]),c=l.useCallback((a,o)=>{let u=Fs[a];if(s==="zh"&&(u=Bs[a]),o)for(const[m,y]of Object.entries(o))u=u.replaceAll(`{${m}}`,String(y));return u},[s]);l.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en",document.title=s==="zh"?Bs.docTitle:Fs.docTitle},[s]);const i=l.useMemo(()=>({locale:s,setLocale:r,t:c}),[s,r,c]);return e.jsx(En.Provider,{value:i,children:t})}function mt(){const t=l.useContext(En);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function xe(){return mt().t}const aa=[{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 $s({settings:t,onChange:s,onPreview:n}){const r=xe(),c=i=>s({...t,...i});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:r("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(yn,{className:"sound-icon"}),e.jsx("span",{children:r("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:i=>c({enabled:i.target.checked})})]}),aa.map(({kind:i,labelKey:a,descKey:o})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:r(a)}),e.jsx("span",{className:"sound-desc",children:r(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:r("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),n(i)},children:r("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:r("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,"%"]})]})]})}let Dt=null;function ra(t){if(t===void 0){const n=globalThis.document;if(n&&typeof n.baseURI=="string"&&n.baseURI)try{t=new URL(n.baseURI).pathname}catch{}if(t===void 0)return"/"}if(!t||t==="/")return"/";let s=t.replace(/index\.html$/i,"");return s.endsWith("/")||(s+="/"),s}function Pn(){return Dt===null&&(Dt=ra()),Dt}function la(t,s){return s==="/"?t:s+t.replace(/^\/+/,"")}function Ve(t){return la(t,Pn())}const Mn="pi-web-notify",At={enabled:!1};function Rn(){try{const t=localStorage.getItem(Mn);if(!t)return{...At};const s=JSON.parse(t);return{enabled:typeof s.enabled=="boolean"?s.enabled:At.enabled}}catch{return{...At}}}function Hs(t){try{localStorage.setItem(Mn,JSON.stringify(t))}catch{}}function ot(){return typeof window<"u"&&"Notification"in window}function oa(){return ot()?Notification.permission:"denied"}async function ca(){if(!ot())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}}async function _t(t,s){var r;if(!ot()||document.hasFocus()||!Rn().enabled||Notification.permission!=="granted")return;const n={body:s,icon:Ve("/icons/icon-192.png"),badge:Ve("/icons/icon-192.png"),tag:"pi-web-ui"};try{const c=await((r=navigator.serviceWorker)==null?void 0:r.getRegistration());c&&typeof c.showNotification=="function"?c.showNotification(t,n):new Notification(t,n)}catch{}}function Os(){const t=xe(),[s,n]=l.useState(Rn),[r,c]=l.useState(()=>ot()?oa():"denied"),i=async a=>{const o={...s,enabled:a};if(n(o),Hs(o),a){const u=await ca();if(c(u),u!=="granted"){const m={...o,enabled:!1};n(m),Hs(m)}}};return e.jsxs("div",{className:"sound-menu",style:{borderTop:"1px solid var(--border-color, rgba(255,255,255,.08))",marginTop:6,paddingTop:6},children:[e.jsx("div",{className:"dd-header",children:t("notifyHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(Xi,{className:"sound-icon"}),e.jsx("span",{children:t("notifyEnable")})]}),e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:a=>i(a.target.checked)})]}),e.jsx("div",{className:"sound-desc",style:{padding:"2px 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyEnableDesc")}),!ot()&&e.jsx("div",{className:"sound-desc",style:{padding:"0 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyUnsupported")}),r==="denied"&&e.jsx("div",{className:"sound-desc",style:{padding:"0 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyDenied")})]})}function da({chat:t,send:s,terminal:n,view:r,plugins:c,onViewChange:i,onOpenPanel:a,onOpenSettings:o,onOpenBgTasks:u,onOpenGlobalSearch:m,sound:y,onSoundChange:g,onSoundPreview:x,themes:b,theme:E,onThemeChange:A}){var D;const{locale:H,setLocale:S,t:j}=mt(),[J,Q]=l.useState(!1),[X,U]=l.useState(!1),[K,q]=l.useState(!1),[Y,T]=l.useState(!1),[P,k]=l.useState(!1),B=[{value:"zh",label:j("langZh")},{value:"en",label:j("langEn")}],Z=t.ready?j("connected"):t.status==="closed"?j("reconnecting"):j("connecting"),G=t.ready?"ok":"busy",M=()=>{var L,ee;if(!t.ready)return;const d=j("updateTabTitle"),w={name:d,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},h=t.terminals.find(W=>W.title===d);h?(n.restart(h.id),s({type:"run_command",terminalId:h.id,conversationId:h.conversationId,command:w,cols:80,rows:24})):n.create({id:Ue(),conversationId:t.activeConversationId||((L=t.state)==null?void 0:L.conversationId)||"",title:d,cwd:((ee=t.state)==null?void 0:ee.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:w}),T(!1),k(!1),i("terminal")},I=(d,w)=>{var ee,W;if(!t.ready||d.length===0)return;const h={name:w,command:sa(d),cwd:"${pwd}"},L=t.terminals.find(ae=>ae.title===w);L?(n.restart(L.id),s({type:"run_command",terminalId:L.id,conversationId:L.conversationId,command:h,cols:80,rows:24})):n.create({id:Ue(),conversationId:t.activeConversationId||((ee=t.state)==null?void 0:ee.conversationId)||"",title:w,cwd:((W=t.state)==null?void 0:W.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:h}),T(!1),k(!1),i("terminal")},C=t.updatesAll??[],$=C.filter(d=>!d.upToDate&&!d.error).length,z=C.filter(d=>!d.upToDate&&!d.error&&d.kind!=="webui"),ne=()=>e.jsxs("div",{className:"dd-updates-all",children:[e.jsx("div",{className:"dd-header",children:j("updatesAllTitle")}),t.updatesAll===null?e.jsx("div",{className:"dd-note",children:j("checkingUpdate")}):C.length===0?e.jsx("div",{className:"dd-note",children:j("updatesAllUpToDate")}):e.jsx("ul",{className:"dd-all-list",children:C.map(d=>e.jsxs("li",{className:`dd-all-item${d.error?" err":d.upToDate?"":" warn"}`,children:[e.jsx("span",{className:"dd-all-name",title:d.name,children:d.name}),e.jsx("span",{className:"dd-all-kind",children:d.kind==="webui"?j("kindWebUi"):d.kind==="pi-core"?j("kindPiCore"):j("kindPackage")}),e.jsx("span",{className:"dd-all-vers",children:d.error?j("updateCheckFailed"):d.upToDate?`v${d.current}`:e.jsxs(e.Fragment,{children:["v",d.current," → v",d.latest]})}),d.kind!=="webui"&&!d.upToDate&&!d.error&&e.jsx("button",{type:"button",className:"dd-update-btn",onClick:()=>I([d],j("updatePkgTabTitle",{name:d.name})),children:j("updateBtn")})]},`${d.kind}:${d.name}`))}),e.jsxs("div",{className:"dd-actions",children:[z.length>0&&e.jsx("button",{type:"button",className:"dd-refresh accent",style:{flex:1},onClick:()=>I(z,j("updateAllTabTitle")),children:j("updateAllBtn")}),e.jsx("button",{type:"button",className:"dd-refresh",style:z.length>0?{flex:1}:void 0,onClick:()=>s({type:"check_updates_all",force:!0}),children:j("updatesAllRefresh")})]})]}),v=()=>{var d,w;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("currentVersion")}),e.jsxs("b",{children:["v",((d=t.update)==null?void 0:d.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("latestVersion")}),e.jsx("b",{children:t.update===null?j("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:j("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:j("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:j("updateAvailable",{version:t.update.latest})}),((w=t.update)==null?void 0:w.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:j("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:j("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?j("checkingUpdate"):j("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:M,children:j("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:j("openHistory"),onClick:()=>a("left"),children:e.jsx($i,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${G}`,title:Z}),e.jsx("span",{className:"conn-label",children:Z})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":j("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="chat",className:r==="chat"?"active":"",onClick:()=>i("chat"),children:[e.jsx(st,{}),e.jsx("span",{children:j("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="terminal",className:r==="terminal"?"active":"",onClick:()=>i("terminal"),children:[e.jsx(tt,{}),e.jsx("span",{children:j("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="git",className:r==="git"?"active":"",onClick:()=>i("git"),children:[e.jsx(yt,{}),e.jsx("span",{children:j("scmTab")})]}),c.map(d=>{const w=d.error?`${d.name}: ${d.error}`:d.description?`${d.name} — ${d.description}`:d.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":r===`plugin:${d.id}`,className:`plugin-tab${r===`plugin:${d.id}`?" active":""}${d.error?" broken":""}`,title:w,onClick:()=>i(`plugin:${d.id}`),children:[d.icon?e.jsx("span",{"aria-hidden":!0,children:d.icon}):null,e.jsx("span",{children:d.name})]},d.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:j("searchGlobalTip"),onClick:m,children:[e.jsx(Nt,{}),e.jsx("span",{className:"chip-sub",children:j("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":j("bgTasksTip"),onClick:u,children:[e.jsx(Ct,{}),e.jsx("span",{className:"chip-sub",children:j("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:j("settingsTitle"),onClick:o,children:[e.jsx(wt,{}),e.jsx("span",{className:"chip-sub",children:j("settings")})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(yn,{}),e.jsx("span",{className:"chip-sub",children:j("sound")})]}),open:J,onOpenChange:Q,children:[e.jsx($s,{settings:y,onChange:g,onPreview:x}),e.jsx(Os,{})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(zi,{}),e.jsx("span",{className:"chip-sub",children:H==="zh"?j("langZh"):"EN"})]}),open:X,onOpenChange:U,children:[e.jsx("div",{className:"dd-header",children:j("language")}),B.map(d=>e.jsx(Ie,{active:H===d.value,onClick:()=>{S(d.value),U(!1)},children:d.label},d.value))]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Li,{}),e.jsx("span",{className:"chip-sub",children:j("theme")})]}),open:K,onOpenChange:q,children:[e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ie,{active:E===null,onClick:()=>{A(null),q(!1)},children:j("themeDefault")}),b.map(d=>e.jsx(Ie,{active:E===d.id,onClick:()=>{A(d.id),q(!1)},children:H==="en"?d.nameEn??d.name:d.name},d.id))]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ls,{}),e.jsxs("span",{className:"chip-sub",children:["v",((D=t.update)==null?void 0:D.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:j("updateAvailable",{version:t.update.latest??""})}),$>0&&e.jsx("span",{className:"update-badge",children:j("updatesAllBadge",{n:$})})]}),open:Y,onOpenChange:d=>{T(d),d&&(s({type:"check_update"}),s({type:"check_updates_all"}))},fit:!0,children:[e.jsx("div",{className:"dd-header",children:j("update")}),v(),ne()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:j("githubRepo"),children:e.jsx(As,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":j("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(He,{}),e.jsx("span",{children:j("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Bi,{}),e.jsx("span",{className:"chip-sub",children:j("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:P,onOpenChange:d=>{k(d),d&&(s({type:"check_update"}),s({type:"check_updates_all"}))},children:[e.jsx("div",{className:"dd-header",children:j("sound")}),e.jsx("div",{className:"dd-header",children:j("settings")}),e.jsxs(Ie,{onClick:()=>{k(!1),o()},children:[e.jsx(wt,{})," ",j("settingsTitle")]}),e.jsxs(Ie,{onClick:()=>{k(!1),m()},children:[e.jsx(Nt,{})," ",j("searchGlobal")]}),e.jsxs(Ie,{onClick:()=>{k(!1),u()},children:[e.jsx(Ct,{})," ",j("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx($s,{settings:y,onChange:g,onPreview:x}),e.jsx(Os,{}),e.jsx("div",{className:"dd-header",children:j("language")}),B.map(d=>e.jsx(Ie,{active:H===d.value,onClick:()=>S(d.value),children:d.label},d.value)),e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ie,{active:E===null,onClick:()=>{A(null),k(!1)},children:j("themeDefault")}),b.map(d=>e.jsx(Ie,{active:E===d.id,onClick:()=>{A(d.id),k(!1)},children:H==="en"?d.nameEn??d.name:d.name},d.id)),e.jsx("div",{className:"dd-header",children:j("update")}),v(),ne(),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(As,{})," ",j("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:j("openFiles"),onClick:()=>a("right"),children:e.jsx(Je,{})})]})]})}function Ks(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}function ua(t,s){const n=new Map;for(const c of t){const i=n.get(c.cwd)??[];i.push(c),n.set(c.cwd,i)}const r=[...n.entries()].map(([c,i])=>({cwd:c,isCurrent:c===s,convs:i}));return r.sort((c,i)=>c.isCurrent?-1:i.isCurrent?1:c.cwd<i.cwd?-1:c.cwd>i.cwd?1:0),r}const pa="pi-web-ui:lp-collapse-projects",ma="pi-web-ui:lp-collapse-convs",ha="pi-web-ui:lp-collapse-sessions";function Bt(t,s=!1){const[n,r]=l.useState(()=>{try{const i=localStorage.getItem(t);if(i==="1")return!0;if(i==="0")return!1}catch{}return s}),c=l.useCallback(()=>{r(i=>{const a=!i;try{localStorage.setItem(t,a?"1":"0")}catch{}return a})},[t]);return[n,c]}const In="pi-web-ui:lp-sizes",Jt={projects:1,convs:1,sessions:1};function ga(){try{const t=localStorage.getItem(In);if(t){const s=JSON.parse(t);return{projects:typeof s.projects=="number"&&s.projects>0?s.projects:1,convs:typeof s.convs=="number"&&s.convs>0?s.convs:1,sessions:typeof s.sessions=="number"&&s.sessions>0?s.sessions:1}}}catch{}return{...Jt}}const fa=l.memo(function({ready:s,status:n,cwd:r,sessionFile:c,conversations:i,sessions:a,projects:o,activeConversationId:u,send:m,active:y,collapsible:g,onToggleCollapse:x}){const b=xe(),E=c,A=r,[H,S]=l.useState(null),[j,J]=l.useState(null),[Q,X]=l.useState(""),[U,K]=Bt(pa,!1),[q,Y]=Bt(ma,!1),[T,P]=Bt(ha,!1),k=l.useRef(null),[B,Z]=l.useState(()=>ga());l.useEffect(()=>{try{localStorage.setItem(In,JSON.stringify(B))}catch{}},[B]);const G=l.useCallback((d,w)=>h=>{h.preventDefault();const L=h.currentTarget,ee=h.clientY,W={...B},ae=k.current;if(!ae)return;const ye=32,be=72,ge=[{key:"projects",visible:o.length>0,collapsed:U},{key:"convs",visible:i.length>0,collapsed:q},{key:"sessions",visible:!0,collapsed:T}].filter(pe=>pe.visible),ke=ge.filter(pe=>pe.collapsed).length,re=ge.filter(pe=>!pe.collapsed).map(pe=>pe.key).reduce((pe,ve)=>pe+(W[ve]??1),0)||1,f=Math.max(120,ae.clientHeight-ke*ye),O=(W[d]??1)+(W[w]??1),de=be/f*re;L.classList.add("dragging"),document.body.classList.add("lp-resizing");const ue=pe=>{const Me=(pe.clientY-ee)/f*re;let he=(W[d]??1)+Me;const _e=O-de;he=Math.max(de,Math.min(_e,he));const Le=O-he;Z(Be=>({...Be,[d]:he,[w]:Le}))},me=()=>{window.removeEventListener("pointermove",ue),window.removeEventListener("pointerup",me),L.classList.remove("dragging"),document.body.classList.remove("lp-resizing")};window.addEventListener("pointermove",ue),window.addEventListener("pointerup",me)},[B,o.length,i.length,U,q,T]);l.useEffect(()=>{!y||!s||n!=="open"||r&&(m({type:"list_sessions"}),m({type:"list_projects"}))},[y,s,n,r,m]);const M=d=>{const w=d.name||d.firstMessage.trim();return w.length>0?w:b("emptyChat")},I=d=>d.split(/[\\/]/).pop()||d,C=(d,w,h,L,ee)=>{const W=H===d;return e.jsx("button",{type:"button",className:`lp-del ${W?"confirm":""}`,title:W?h:w,onClick:ae=>{ae.stopPropagation(),W?(S(null),L()):S(d)},children:W?e.jsx(pt,{}):ee??e.jsx(Ae,{})})},$=(d,w,h,L)=>e.jsxs("button",{type:"button",className:"lp-section-title panel-section-title",onClick:h,title:b(w?"expandSection":"collapseSection"),children:[e.jsxs("span",{className:"lp-section-title-text",children:[d,L!==void 0?` (${L})`:""]}),e.jsx("span",{className:"lp-section-chevron",children:w?e.jsx(Ge,{}):e.jsx(ut,{})})]}),ne=[{key:"projects",visible:o.length>0,collapsed:U},{key:"convs",visible:i.length>0,collapsed:q},{key:"sessions",visible:!0,collapsed:T}].filter(d=>d.visible).filter(d=>!d.collapsed),v=ne.reduce((d,w)=>d+(B[w.key]??1),0)||1,D=d=>ne.length<=1?1:(B[d]??1)/v*ne.length;return e.jsxs("aside",{ref:k,className:"panel panel-left lp-panel",children:[g&&x&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:b("collapsePanel"),onClick:x,children:e.jsx(Nn,{})}),o.length>0&&e.jsxs("div",{className:`lp-section panel-projects ${U?"collapsed":""}`,style:U?void 0:{flex:`${D("projects")} 1 0px`},children:[$(b("recentProjects"),U,K,o.length),!U&&e.jsx("div",{className:"lp-section-body projects-scroll",children:o.map(d=>{const w=A===d.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>S(h=>h===`proj:${d.path}`?null:h),children:[e.jsxs("button",{type:"button",className:`project-item ${w?"active":""}`,title:d.path,onClick:()=>{w||m({type:"set_cwd",path:d.path})},children:[e.jsx(Je,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:I(d.path)}),e.jsx("span",{className:"project-path",children:d.path})]}),e.jsx("span",{className:"project-time",children:Ks(d.lastUsed)})]}),C(`proj:${d.path}`,b("deleteProject"),b("deleteProjectConfirm"),()=>m({type:"remove_project",path:d.path}))]},d.path)})})]}),o.length>0&&!U&&(i.length>0?!q:!T)&&e.jsx("div",{className:"lp-sash",onPointerDown:G("projects",i.length>0?"convs":"sessions"),onDoubleClick:()=>Z({...Jt}),title:b("dragToResize")}),i.length>0&&e.jsxs("div",{className:`lp-section lp-section-convs panel-convs ${q?"collapsed":""}`,style:q?void 0:{flex:`${D("convs")} 1 0px`},children:[$(b("runningConversations"),q,Y,i.length),!q&&e.jsx("div",{className:"lp-section-body convs-scroll",children:ua(i,r).map(d=>e.jsxs("div",{className:"panel-conv-group",children:[!d.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:d.cwd,children:I(d.cwd)}),d.convs.map(w=>{const h=u===w.id;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>S(L=>L===`conv:${w.id}`?null:L),children:[e.jsxs("button",{type:"button",className:`session-item ${h?"active":""}`,title:`${w.title}${d.isCurrent?"":` — ${d.cwd}`}`,onClick:()=>{h||m({type:"switch_conversation",id:w.id})},children:[e.jsx(st,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[j===`conv:${w.id}`?e.jsx("input",{autoFocus:!0,className:"session-rename-input",value:Q,placeholder:b("renameSessionPlaceholder"),onClick:L=>L.stopPropagation(),onChange:L=>X(L.target.value),onKeyDown:L=>{if(L.stopPropagation(),L.key==="Enter"&&!L.nativeEvent.isComposing){const ee=Q.trim();ee&&m({type:"rename_conversation",id:w.id,name:ee}),J(null)}else L.key==="Escape"&&J(null)},onBlur:()=>J(null)}):e.jsxs("span",{className:"session-title",children:[w.isSubagent&&e.jsx("span",{className:"subagent-badge",children:b("subagentBadge")}),w.title,w.error&&e.jsx("span",{className:"conv-error-badge",title:b("convErrorBadge",{error:w.error})})]}),j===`conv:${w.id}`?null:e.jsx("span",{className:"session-sub",children:h?b("current"):b("messageCount",{n:w.messageCount})})]}),w.isStreaming&&e.jsx("span",{className:"conv-streaming",title:b("streaming")})]}),e.jsx("button",{type:"button",className:"lp-del lp-rename",title:b("renameSession"),onClick:L=>{L.stopPropagation(),S(null),X(w.title),J(`conv:${w.id}`)},children:e.jsx(St,{})}),!w.isStreaming&&!h&&C(`conv:${w.id}`,b("dismissConversation"),b("dismissConversationConfirm"),()=>m({type:"dismiss_conversation",id:w.id}),e.jsx(Pe,{})),w.isStreaming&&e.jsx("span",{className:"lp-row-stalled",title:b("streaming"),style:{position:"absolute",right:28,top:"50%",transform:"translateY(-50%)"}})]},w.id)})]},d.cwd))})]}),i.length>0&&!q&&!T&&e.jsx("div",{className:"lp-sash",onPointerDown:G("convs","sessions"),onDoubleClick:()=>Z({...Jt}),title:b("dragToResize")}),e.jsxs("div",{className:`lp-section lp-section-sessions panel-sessions ${T?"collapsed":""}`,style:T?void 0:{flex:`${D("sessions")} 1 0px`},children:[$(b("historySessions"),T,P,a.length),!T&&e.jsxs("div",{className:"lp-section-body sessions-scroll",children:[a.length===0&&e.jsx("div",{className:"panel-empty",children:b("noHistory")}),a.map(d=>{const w=E===d.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>S(h=>h===`sess:${d.path}`?null:h),children:[e.jsxs("button",{type:"button",className:`session-item ${w?"active":""}`,title:d.path,onClick:()=>{j||w||m({type:"switch_session",path:d.path})},children:[e.jsx(st,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[j===d.path?e.jsx("input",{autoFocus:!0,className:"session-rename-input",value:Q,placeholder:b("renameSessionPlaceholder"),onClick:h=>h.stopPropagation(),onChange:h=>X(h.target.value),onKeyDown:h=>{if(h.stopPropagation(),h.key==="Enter"&&!h.nativeEvent.isComposing){const L=Q.trim();L&&m({type:"rename_session",path:d.path,name:L}),J(null)}else h.key==="Escape"&&J(null)},onBlur:()=>J(null)}):e.jsx("span",{className:"session-title",children:M(d)}),j===d.path?null:e.jsxs("span",{className:"session-sub",children:[w?b("current"):b("messageCount",{n:d.messageCount}),d.source==="tui"&&e.jsx("span",{className:"session-src",title:b("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:Ks(d.modified)})]}),e.jsx("button",{type:"button",className:"lp-del lp-rename",title:b("renameSession"),onClick:h=>{h.stopPropagation(),S(null),X(d.name??""),J(d.path)},children:e.jsx(St,{})}),C(`sess:${d.path}`,b("deleteSession"),b("deleteSessionConfirm"),()=>m({type:"delete_session",path:d.path}))]},d.path)})]})]})]})}),Ln="pi-web-ui:token";function xa(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Ln,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function ya(){try{return localStorage.getItem(Ln)??""}catch{return""}}function Mt(t){const s=ya();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function va(t,s){const n=s.assistantMessageEvent,r=t.stats.tokens,c=s.usage!==null?{...r,...s.usage}:r,i=c===r?t.stats:{...t.stats,tokens:c};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return i===t.stats?t:{...t,stats:i};const a=n.delta??"";if(!a)return i===t.stats?t:{...t,stats:i};const o=t.streamingMessage??null,u=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},m=[...u.content],y=n.type==="thinking_delta"?"thinking":"text",g=n.contentIndex??m.length-1;return g>=0&&g<m.length&&m[g].type===y?m[g]=y==="thinking"?{type:"thinking",thinking:(m[g].thinking??"")+a}:{type:"text",text:(m[g].text??"")+a}:m.push(y==="thinking"?{type:"thinking",thinking:a}:{type:"text",text:a}),{...t,stats:i,streamingMessage:{...u,id:s.messageId,content:m}}}const Xt="pi-web-ui:plugin-data";function ba(t,s){window.dispatchEvent(new CustomEvent(Xt,{detail:{pluginId:t,payload:s}}))}function ka(t){const s=n=>{const r=n.detail;t(r.pluginId,r.payload)};return window.addEventListener(Xt,s),()=>window.removeEventListener(Xt,s)}const et=new Map,Zt=new Set,Xe=new Set;let Ws=-1;function Dn(){return[...et.values()]}function ja(){const t=Dn();for(const s of Zt)s(t)}function wa(t){return Zt.add(t),t(Dn()),()=>Zt.delete(t)}async function Na(t,s){s!==Ws&&(Ws=s,et.clear(),Xe.clear());const n=new Set(t.map(r=>r.id));for(const r of[...et.keys()])n.has(r)||et.delete(r);for(const r of[...Xe])n.has(r)||Xe.delete(r);await Promise.all(t.filter(r=>r.hasClient&&!r.error&&!et.has(r.id)&&!Xe.has(r.id)).map(async r=>{try{const i=(await import(Ve(`/plugins/${encodeURIComponent(r.id)}/client/entry.mjs?e=${s}`))).default;i&&typeof i.mount=="function"?et.set(r.id,{info:r,module:i}):(Xe.add(r.id),console.error(`[plugin:${r.id}] entry.mjs 缺少 default.mount`))}catch(c){Xe.add(r.id),console.error(`[plugin:${r.id}] 客户端加载失败:`,c)}})),ja()}function Ca(t,s){return{pluginId:t,send:n=>s({type:"plugin_message",pluginId:t,payload:n}),onData:n=>ka((r,c)=>{r===t&&n(c)})}}const Sa=12,Ft=2e5,Ta=2e5,Ea="LIVE_OMIT",Pa={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 Ma(){const t=new Map,s=new Map,n=(r,c)=>`${r}:${c}`;return{write(r,c,i){const a=n(r,c),o=t.get(a);if(o&&o.size>0){for(const y of o)try{y.write(i)}catch{}return}const u=s.get(a)??"",m=u.length+i.length>Ta?i:u+i;s.set(a,m)},register(r,c,i){const a=n(r,c);let o=t.get(a);o||(o=new Set,t.set(a,o)),o.add(i);const u=s.get(a);if(u){try{i.write(u)}catch{}s.delete(a)}return()=>{const m=t.get(a);m&&(m.delete(i),m.size===0&&t.delete(a)),s.delete(a)}},clear(){t.clear(),s.clear()}}}function Us(t,s){const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId),c.role==="bashExecution"&&n.add(`bash-${c.id}`);let r=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function qs(t,s){if(t.size===0)return t;const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId);let r=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function Ra(t,s){var n,r,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,engine:s.engine,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==Sa};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Us(t.liveOutputs,s.state),toolStatuses:qs(t.toolStatuses,s.state)};case"snapshot_delta":{const a=t.state,o=s.msg;if(!a||a.conversationId!==o.conversationId||a.rev!==o.baseRev)return t;const u={...a,...o.state,messages:o.appended.length>0?[...a.messages,...o.appended]:a.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:Us(t.liveOutputs,u),toolStatuses:qs(t.toolStatuses,u)}}case"tool_delta":{const a=t.liveOutputs.get(s.toolCallId),o=((a==null?void 0:a.text)??"")+s.delta,u=o.length>Ft?`…[${Ea}:${o.length-Ft}]…
305
- `+o.slice(o.length-Ft):o,m=new Map(t.liveOutputs);return m.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:m}}case"message_delta":{const a=t.state;return!a||a.conversationId!==s.msg.conversationId?t:{...t,state:va(a,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(a=>a.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"provider_keys":return{...t,providerKeys:s.keys};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"session_search_result":return{...t,sessionSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"update_status_all":return{...t,updatesAll:s.items};case"updates_check_started":return{...t,updatesAll:null};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"question":return{...t,question:s.question};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"dsh_patches":return{...t,dshPatches:{patchDir:s.patchDir,files:s.files}};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(a=>a.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(n=t.state)!=null&&n.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!1,exitCode:s.exitCode}:a)};case"terminal_restart":return{...t,terminals:t.terminals.map(a=>a.id===s.terminalId?{...a,running:!0,exitCode:null}:a)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((i=t.state)==null?void 0:i.conversationId))?t:{...t,terminals:s.terminals.map(a=>{var o;return{...a,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};case"terminal_active":return{...t,terminalActiveId:s.id};default:return t}}const zs="pi-web-client-id";let $t=null;function os(){if($t)return $t;let t=null;try{t=sessionStorage.getItem(zs),t||(t=Ue(),sessionStorage.setItem(zs,t))}catch{t=t??Ue()}return $t=t,t}const An="pi-web-last-cwd";function Ia(){try{return localStorage.getItem(An)}catch{return null}}function La(t){try{localStorage.setItem(An,t)}catch{}}function Da(){const t=location.protocol==="https:"?"wss:":"ws:";return Mt(`${t}//${location.host}${Ve("/ws")}`)}function Aa(){var Y;const[t,s]=l.useReducer(Ra,{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:[],providerKeys:{},installResult:null,pathCompletions:[],update:null,updatesAll:null,widgets:[],statuses:[],dialog:null,question:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],terminalActiveId:null,goal:Pa,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,dshPatches:null,protocolMismatch:!1}),n=l.useRef(null),r=l.useRef(Ma()),c=l.useRef(0),i=l.useRef(null),a=l.useRef(!0),o=l.useRef(0),u=l.useRef(0),m=l.useRef(new Map),y=l.useRef(null),g=l.useRef(!1),x=l.useRef(null),b=()=>{y.current||(y.current=setTimeout(()=>{y.current=null;const T=n.current;T&&T.readyState===WebSocket.OPEN&&T.send(JSON.stringify({type:"get_state"}))},300))},E=(T,P)=>{var Z;const k=m.current,B=k.get(T);if(B!==void 0&&P!==B+1){const G=q.current.chat,M=G.activeConversationId||((Z=G.state)==null?void 0:Z.conversationId);T===M&&b()}k.set(T,P)},A=l.useCallback((T,P)=>{const k=++u.current;s({type:"notice",notice:{id:k,level:T,text:P}})},[]),H=l.useCallback(T=>{const P=n.current;return P&&P.readyState===WebSocket.OPEN?(T.type==="check_updates_all"&&T.force===!0&&s({type:"updates_check_started"}),P.send(JSON.stringify(T)),!0):!1},[]),S=l.useCallback(()=>{if(!a.current)return;s({type:"status",status:"connecting"});const T=new WebSocket(Da());n.current=T,T.onopen=()=>{n.current===T&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),T.send(JSON.stringify({type:"hello",clientId:os()})))},T.onmessage=P=>{if(n.current!==T)return;o.current=Date.now();let k;try{k=JSON.parse(P.data)}catch{return}switch(k.type){case"ready":s({type:"ready",serverVersion:k.serverVersion,protocolVersion:k.protocolVersion,engine:k.engine}),T.send(JSON.stringify({type:"get_state"})),T.send(JSON.stringify({type:"list_files"})),T.send(JSON.stringify({type:"list_models"})),T.send(JSON.stringify({type:"list_commands"})),T.send(JSON.stringify({type:"get_commands"})),T.send(JSON.stringify({type:"check_update"})),T.send(JSON.stringify({type:"check_updates_all"}));break;case"snapshot":m.current=new Map,s({type:"snapshot",state:k.state});break;case"snapshot_delta":{const B=q.current.chat.state;(!B||B.conversationId!==k.conversationId||B.rev!==k.baseRev)&&b(),s({type:"snapshot_delta",msg:k});break}case"tool_delta":E(k.conversationId,k.seq),s({type:"tool_delta",toolCallId:k.toolCallId,toolName:k.toolName,delta:k.delta});break;case"tool_status":s({type:"tool_status",status:k});break;case"message_delta":{E(k.conversationId,k.seq),s({type:"message_delta",msg:k});break}case"notice":{const B=++u.current;s({type:"notice",notice:{id:B,level:k.level,text:k.text,textEn:k.textEn}});break}case"sessions":s({type:"sessions",sessions:k.sessions});break;case"conversations":s({type:"conversations",conversations:k.conversations,activeId:k.activeId});break;case"projects":s({type:"projects",projects:k.projects});break;case"files":s({type:"files",files:k});break;case"file_changed":s({type:"file_changed",path:k.path});break;case"file_content":s({type:"file_content",content:k});break;case"models":s({type:"models",models:k.models,loading:!1});break;case"models_config":s({type:"models_config",providers:k.providers});break;case"providers_status":s({type:"providers_status",providers:k.providers});break;case"provider_keys":s({type:"provider_keys",keys:k.keys});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:k.reqId,ok:k.ok,models:k.models,error:k.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:k.reqId,ok:k.ok,added:k.added,total:k.total,error:k.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:k.reqId,ok:k.ok,config:k.config,configs:k.configs,error:k.error}});break;case"scm_data":s({type:"scm_data",data:k});break;case"search_files_result":s({type:"file_search_result",result:{reqId:k.reqId,ok:k.ok,results:k.results,truncated:k.truncated}});break;case"session_search_results":s({type:"session_search_result",result:{reqId:k.reqId,ok:k.ok,results:k.results}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:k});break;case"path_completions":s({type:"path_completions",completions:k.completions});break;case"update_status":s({type:"update_status",status:k});break;case"update_status_all":s({type:"update_status_all",items:k.items});break;case"widgets":s({type:"widgets",widgets:k.widgets});break;case"statuses":s({type:"statuses",statuses:k.statuses});break;case"dialog":s({type:"dialog",dialog:{id:k.id,kind:k.kind,title:k.title,args:k.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"question_pending":s({type:"question",question:{id:k.id,questions:k.questions}});break;case"terminal_output":r.current.write(k.conversationId??q.current.chat.activeConversationId,k.terminalId,k.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:k.conversationId,terminalId:k.terminalId,exitCode:k.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:k.conversationId,terminals:k.terminals});break;case"commands":s({type:"commands",commands:k.commands,path:k.path});break;case"slash_commands":s({type:"slash_commands",commands:k.commands});break;case"goal_status":s({type:"goal_status",status:k.status});break;case"settings_state":s({type:"settings",settings:k.settings});break;case"bg_servers":s({type:"bg_servers",servers:k.servers});break;case"plugins":s({type:"plugins",plugins:k.plugins,epoch:k.epoch});break;case"dsh_patches":s({type:"dsh_patches",patchDir:k.patchDir,files:k.files});break;case"plugin_data":ba(k.pluginId,k.payload);break}},T.onclose=()=>{if(n.current===T&&(n.current=null),r.current.clear(),!a.current||n.current&&n.current!==T)return;s({type:"status",status:"closed"});const P=Math.min(1e3*2**c.current,1e4);c.current+=1,i.current=setTimeout(()=>{i.current=null,S()},P)},T.onerror=()=>{}},[]);l.useEffect(()=>{a.current=!0,S();const T=setInterval(()=>{if(!a.current)return;const P=n.current;P&&P.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&P.close()},5e3);return()=>{var P;a.current=!1,clearInterval(T),i.current&&(clearTimeout(i.current),i.current=null),(P=n.current)==null||P.close(),n.current=null}},[S]),l.useEffect(()=>{var P;const T=(P=t.state)==null?void 0:P.cwd;if(T){if(!g.current){g.current=!0;const k=Ia();if(k&&k!==T){H({type:"set_cwd",path:k});return}}x.current!==T&&(x.current=T,La(T))}},[(Y=t.state)==null?void 0:Y.cwd,H]);const j=l.useCallback(T=>s({type:"dismiss_notice",id:T}),[]),J=l.useCallback(T=>s({type:"terminal_add",meta:T}),[]),Q=l.useCallback(T=>s({type:"terminal_remove",id:T}),[]),X=l.useCallback(T=>s({type:"terminal_restart",terminalId:T}),[]),U=l.useCallback(T=>s({type:"terminal_active",id:T}),[]),K=l.useCallback((T,P,k)=>r.current.register(T,P,k),[]),q=l.useRef({chat:t,send:H,pushNotice:A,dismissNotice:j,terminal:{create:J,close:Q,register:K,restart:X,select:U}});return q.current={chat:t,send:H,pushNotice:A,dismissNotice:j,terminal:{create:J,close:Q,register:K,restart:X,select:U}},q.current}const _a=200*1024*1024,Ba=/windows/i.test(navigator.userAgent),Fa=/[<>:"/\\|?*\u0000-\u001f]/g,$a=/[. ]+$/,Ha=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Oa(t){const s=t.replace(Fa,"_").replace($a,"");return s?Ha.test(s)?`_${s}`:s:"_"}function Vs(t,s=!0){const n=new URLSearchParams({clientId:os(),path:t,...s?{download:"1"}:{}});return Mt(Ve(`/api/file?${n}`))}const _n="FILE_NOT_FOUND";async function Ka(t,s){const n=Ba?Oa(s):s;try{const r=await fetch(Vs(t));if(!r.ok)return{ok:!1,cancelled:!1,error:await r.text().catch(()=>"")||(r.status===404?_n:`HTTP ${r.status}`)};if(Number(r.headers.get("content-length")??"0")>_a)return window.location.assign(Vs(t)),{ok:!0};const i=await r.blob();return window.showSaveFilePicker&&window.isSecureContext?Wa(i,n):es(i,n)}catch(r){return{ok:!1,cancelled:!1,error:r instanceof Error?r.message:String(r)}}}async function Wa(t,s){let n;const r=window.showSaveFilePicker;if(!r)return es(t,s);try{n=await r({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:es(t,s)}try{const c=await n.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function es(t,s){const n=URL.createObjectURL(t),r=document.createElement("a");return r.href=n,r.download=s,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const gt="@root",Ua=l.memo(function({files:s,fileChanged:n,widgets:r,cwd:c,send:i,onAttach:a,onPreview:o,onNotice:u,collapsible:m,onToggleCollapse:y}){const g=xe(),[x,b]=l.useState(""),[E,A]=l.useState(null),[H,S]=l.useState(!1),[j,J]=l.useState(null),Q=l.useRef(""),X=l.useRef(null),U=l.useCallback((d,w)=>{d.preventDefault(),Q.current=w,J({x:Math.min(d.clientX,window.innerWidth-220),y:Math.min(d.clientY,window.innerHeight-90)})},[]),K=l.useCallback(()=>J(null),[]);l.useEffect(()=>{if(!j)return;const d=L=>{var ee;(ee=L.target)!=null&&ee.closest(".ctx-menu")||K()},w=L=>{L.key==="Escape"&&K()};window.addEventListener("mousedown",d,!0),window.addEventListener("keydown",w);const h=()=>K();return window.addEventListener("blur",h),()=>{window.removeEventListener("mousedown",d,!0),window.removeEventListener("keydown",w),window.removeEventListener("blur",h)}},[j,K]);const q=l.useCallback(()=>{var d;K(),X.current&&(X.current.value=""),(d=X.current)==null||d.click()},[K]),Y=l.useCallback((d,w)=>{for(const h of w){const L=new FileReader;L.onload=()=>{const ee=L.result,W=ee.slice(ee.indexOf(",")+1);W&&i({type:"upload_file",dirPath:d,name:h.name,data:W})},L.readAsDataURL(h)}},[i]),T=l.useCallback(d=>{Y(Q.current,Array.from(d.target.files??[]))},[Y]),P=l.useRef(null),k=d=>{var w;return Array.from(((w=d.dataTransfer)==null?void 0:w.types)??[]).includes("Files")},B=l.useCallback(()=>{var d,w;(d=P.current)==null||d.querySelectorAll(".file-item.drop-target").forEach(h=>h.classList.remove("drop-target")),(w=P.current)==null||w.classList.remove("drop-root")},[]),Z=l.useCallback(d=>{var h,L;if(B(),d==null)return;const w=(h=P.current)==null?void 0:h.querySelector(`.file-item[data-path="${CSS.escape(d)}"]`);w?w.classList.add("drop-target"):(L=P.current)==null||L.classList.add("drop-root")},[B]),G=d=>{const w=d instanceof Element?d.closest(".file-item"):null;return(w==null?void 0:w.dataset.type)==="dir"?w.dataset.path??x:x},M=l.useCallback(()=>{const d=document.querySelector(".app");d&&d.dispatchEvent(new DragEvent("dragleave",{bubbles:!0}))},[]),I=1e4,C=l.useRef(0),$=l.useRef(void 0),z=l.useCallback((d,w)=>{const h=++C.current;b(d),w!=null&&w.silent||S(!0),i({type:"list_files",path:d===""?void 0:d})||C.current===h&&S(!1)},[i]);l.useEffect(()=>{s&&s.path===x&&S(!1)},[s,x]),l.useEffect(()=>{if(c!==$.current){$.current=c,z("",{silent:!0});return}const d=setInterval(()=>{document.visibilityState!=="hidden"&&z(x,{silent:!0})},I);return()=>clearInterval(d)},[c,x,z]),l.useEffect(()=>{n&&n.path===x&&z(x,{silent:!0})},[n,x,z]);const ne=d=>z(d),v=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&z(s.parent)},D=(()=>{if(x===""||x===gt)return[];const d=x.split("/").filter(w=>!!w&&w!==gt);return x.startsWith("/")?d.map((w,h)=>({label:h===0?"/":d[h],path:"/"+d.slice(0,h+1).join("/")})):d.map((w,h)=>({label:d[h],path:d.slice(0,h+1).join("/")}))})();return e.jsxs("aside",{className:"panel panel-right",children:[m&&y&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:g("collapsePanel"),onClick:y,children:e.jsx(wn,{})}),e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${x===""?"active":""}`,onClick:()=>z(""),children:g("rootDir")}),e.jsx("button",{type:"button",className:`crumb ${x===gt?"active":""}`,title:g("computer"),onClick:()=>z(gt),children:"💻"}),D.map(d=>e.jsxs("span",{className:"crumb-seg",children:[e.jsx(Pt,{}),e.jsx("button",{type:"button",className:`crumb ${d.path===x?"active":""}`,onClick:()=>z(d.path),children:d.label})]},d.path))]}),e.jsxs("div",{ref:P,className:"panel-body",onContextMenu:d=>U(d,x),onDragOver:d=>{k(d)&&(d.preventDefault(),d.stopPropagation(),d.dataTransfer.dropEffect="copy",M(),Z(G(d.target)))},onDragLeave:d=>{d.relatedTarget&&d.currentTarget.contains(d.relatedTarget)||B()},onDrop:d=>{var h;if(B(),!k(d))return;d.preventDefault(),d.stopPropagation(),M();const w=Array.from(((h=d.dataTransfer)==null?void 0:h.files)??[]);if(w.length===0){u("warning",g("foldersNotSupported"));return}Y(G(d.target),w)},onDragEnd:B,children:[e.jsx("input",{ref:X,type:"file",multiple:!0,hidden:!0,onChange:T}),H&&e.jsx("div",{className:"panel-empty",children:g("loading")}),!H&&s&&s.path===x&&e.jsxs(e.Fragment,{children:[s.parent!=null&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:v,children:[e.jsx(Je,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(d=>d.type==="dir"?e.jsxs("div",{className:"file-item dir","data-type":"dir","data-path":d.path,onContextMenu:w=>{w.stopPropagation(),U(w,d.path)},children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>ne(d.path),children:[e.jsx(Je,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:d.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":g("linkFolderTip"),onClick:()=>a(d.path,d.name,"reference",!0),children:e.jsx(Gt,{})})]},d.path):e.jsxs("div",{className:"file-item file","data-type":"file","data-path":d.path,onContextMenu:w=>{w.stopPropagation(),U(w,x)},children:[e.jsxs("button",{type:"button",className:"file-name",title:`${d.path} — ${g("previewFile")}`,onClick:()=>o(d.path,d.name),children:[e.jsx(Vi,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:d.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":g("downloadFile"),onClick:()=>{Ka(d.path,d.name).then(w=>{w.ok||w.cancelled||u("error",g("downloadFailed",{error:w.error===_n?g("fileNotFoundShort"):w.error}))})},children:e.jsx(ls,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":g("attachInlineTip"),onClick:()=>a(d.path,d.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":g("referenceTip"),onClick:()=>a(d.path,d.name,"reference"),children:e.jsx(Gt,{})})]},d.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:g("filesTruncated")})]}),!H&&!s&&e.jsx("div",{className:"panel-empty",children:g("noFiles")})]}),r.filter(d=>d.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:r.filter(d=>d.lines.length>0).map(d=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:g("widgetExpand"),onClick:()=>A(d.key),children:[e.jsx("span",{children:d.key}),e.jsx(Oi,{})]}),e.jsx("pre",{className:"widget-lines",children:d.lines.join(`
306
- `)})]},d.key))}),E&&(()=>{const d=r.find(w=>w.key===E);return d?e.jsx("div",{className:"modal-backdrop",onClick:()=>A(null),children:e.jsxs("div",{className:"widget-expand",onClick:w=>w.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:d.key}),e.jsx("button",{type:"button",className:"btn",title:g("close"),onClick:()=>A(null),children:e.jsx(Pe,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:d.lines.join(`
307
- `)})]})}):null})(),j&&e.jsx("div",{className:"ctx-menu",style:{left:j.x,top:j.y},onContextMenu:d=>{d.preventDefault(),d.stopPropagation()},children:e.jsxs("button",{type:"button",className:"ctx-item",onClick:q,children:[e.jsx(Ri,{}),Q.current===x?g("uploadToCurrentDir"):g("uploadToFolder")]})})]})});var qa=hn();const Tt=l.memo(function({text:s}){const n=xe(),[r,c]=l.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:n("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{c(!0),setTimeout(()=>c(!1),1200)})},children:r?e.jsx(pt,{}):e.jsx(jn,{})}):null});function za(t){const s=r=>{var c;if(typeof r=="string"||typeof r=="number"){const i=String(r);return i===""?[[]]:i.split(`
308
- `).map(a=>a===""?[]:[a])}if(Array.isArray(r)){let i=[];for(const a of r){const o=s(a);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(r&&typeof r=="object"&&"props"in r){const i=r,a=(c=i.props)==null?void 0:c.children,o={...i.props,children:void 0},u=a==null?[]:s(a);return u.length===0?[[l.createElement(i.type,o)]]:u.map(m=>[l.createElement(i.type,o,...m)])}return[[r]]},n=s(t);return n.length>1&&n[n.length-1].length===0&&n.pop(),n}function Va(t){return typeof t=="string"&&/(^|\s)language-mermaid(\s|$)/.test(t)}function ts(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ts).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return ts(s==null?void 0:s.children)}return""}function Ga(t){const s=Array.isArray(t)?t[0]:t;return!s||typeof s!="object"||!("props"in s)?null:s}function Qa(t){var y,g;const s=t.match(/<svg\b([^>]*)>/i);if(!s)return t;const n=s[1],r=(y=n.match(/\bviewBox=(['"])([^'"]+)\1/i))==null?void 0:y[2];if(!r)return t;const c=r.trim().split(/[\s,]+/).map(Number),i=c.length===4?c[2]:Number.NaN;if(!Number.isFinite(i)||i<=0)return t;const o=(((g=n.match(/\sstyle=(['"])(.*?)\1/i))==null?void 0:g[2])??"").replace(/(?:^|;)\s*(?:max-)?width\s*:[^;]*/gi,"").replace(/^\s*;|;\s*$/g,""),u=n.replace(/\swidth=(['"])[^'"]*\1/i,"").replace(/\sstyle=(['"])(.*?)\1/i,""),m=o?`${o}; max-width:none`:"max-width:none";return t.replace(s[0],`<svg${u} width="${i}" style="${m}">`)}function Bn(t){var n;const s=Ga(t);return s!==null&&Va((n=s.props)==null?void 0:n.className)}let Ht=null;function Ya(){return Ht||(Ht=gn(()=>import("./mermaid.core-BI5_3AOv.js").then(t=>t.cb),__vite__mapDeps([0,1])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:{background:"#ffffff",primaryColor:"#f1edfe",primaryTextColor:"#1f2430",primaryBorderColor:"#8b5cf6",lineColor:"#6b7280",secondaryColor:"#eef2ff",tertiaryColor:"#f8fafc",textColor:"#1f2430",fontFamily:"var(--mono, monospace)"}}),s})),Ht}let Ja=0;function Xa({code:t}){const s=xe(),n=l.useId().replace(/[^a-zA-Z0-9]/g,""),[r,c]=l.useState(null),[i,a]=l.useState(null);return l.useEffect(()=>{let o=!1;c(null),a(null);const u=`mermaid-${n}-${++Ja}`,m=document.createElement("div");m.style.position="absolute",m.style.left="-99999px",m.style.width="1000px",m.dataset.mermaidRender=u,document.body.appendChild(m);const y=()=>{var g;return(g=document.querySelector(`[data-mermaid-render="${u}"]`))==null?void 0:g.remove()};return Ya().then(g=>g.render(u,t,m)).then(({svg:g})=>{y(),o||c(Qa(g))}).catch(g=>{y(),!o&&a(g instanceof Error?g.message:String(g))}),()=>{o=!0,y()}},[t,n]),i?e.jsxs("div",{className:"mermaid-block mermaid-block-error",children:[e.jsx("div",{className:"mermaid-note",children:s("mermaidRenderFailed")}),e.jsxs("div",{className:"codeblock",children:[e.jsx(Tt,{text:t}),e.jsx("pre",{children:e.jsx("code",{children:t})})]})]}):r?e.jsxs("div",{className:"mermaid-block",children:[e.jsx(Tt,{text:t}),e.jsx("div",{className:"mermaid-svg",dangerouslySetInnerHTML:{__html:r}})]}):e.jsx("div",{className:"mermaid-block mermaid-block-loading",children:e.jsx("div",{className:"mermaid-note",children:s("mermaidRendering")})})}function Za(t){return Bn(t)?ts(t):null}const Fn="pi-web-ui:mermaid-render",Et={enabled:!0};function $n(t){if(!t||typeof t!="object")return{...Et};const s=t;return{enabled:typeof s.enabled=="boolean"?s.enabled:Et.enabled}}function er(){try{const t=localStorage.getItem(Fn);return t?$n(JSON.parse(t)):{...Et}}catch{return{...Et}}}function tr(t){const s=$n(t);try{localStorage.setItem(Fn,JSON.stringify(s))}catch{}vt=s;for(const n of ss)n()}let vt=null;const ss=new Set;function sr(t){return ss.add(t),()=>{ss.delete(t)}}function nr(){return vt||(vt=er()),vt.enabled}function Hn(){return l.useSyncExternalStore(sr,nr)}const ir=[xi],ar=[[fi,{detect:!0,ignoreMissing:!0}]];function cs({text:t}){return e.jsx(gi,{remarkPlugins:ir,rehypePlugins:ar,components:{pre:rr},children:t})}const Rt=l.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(cs,{text:s})})});function rr({children:t,...s}){var o;if(Hn()&&Bn(t))return e.jsx(Xa,{code:Za(t)});const r=t&&typeof t=="object"&&"props"in t?(o=t.props)==null?void 0:o.children:t,c=za(r),i=c.length>1,a=i?`${String(c.length).length+1}ch`:void 0;return e.jsxs("div",{className:"codeblock",children:[e.jsx(Tt,{text:ns(t)}),e.jsx("pre",{...s,children:c.map((u,m)=>e.jsxs("div",{className:"code-line",children:[i&&e.jsx("span",{className:"code-num",style:a?{width:a}:void 0,children:m+1}),e.jsx("code",{className:"code-line-body hljs",children:u})]},m))})]})}function ns(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ns).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return ns(s==null?void 0:s.children)}return""}const lr=/^\s{0,3}(`{3,}|~{3,})/,or=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function Ot(t){return t.trim()===""}function Gs(t){const s=lr.exec(t);return s?s[1]:null}function cr(t){const s=t.split(`
309
- `),n=[];let r=[],c=null;for(let i=0;i<s.length;i++){const a=s[i];if(c!==null){const u=Gs(a);u&&u[0]===c[0]&&u.length>=c.length&&(c=null),r.push(a);continue}const o=Gs(a);if(o&&!Ot(a)){c=o,r.push(a);continue}if(Ot(a)){let u=i;for(;u<s.length&&Ot(s[u]);)u++;if(!(u<s.length&&or.test(s[u]))&&r.length>0){n.push(r.join(`
310
- `)),r=[];continue}r.push(a);continue}r.push(a)}return{frozen:n,active:r.join(`
311
- `),inFence:c!==null}}const dr=l.memo(function({text:s}){return e.jsx(cs,{text:s})}),Qs=200;function ur({text:t,inFence:s}){const[n,r]=l.useState(t),c=l.useRef(0),i=l.useRef(null);return l.useEffect(()=>{if(s)return;const a=Date.now()-c.current,o=()=>{c.current=Date.now(),r(t)};if(a>=Qs){o();return}return i.current=setTimeout(o,Qs-a),()=>{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(cs,{text:n})}const pr=l.memo(function({text:s}){const{frozen:n,active:r,inFence:c}=l.useMemo(()=>cr(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((i,a)=>e.jsx(dr,{text:i},a)),r.length>0&&e.jsx(ur,{text:r,inFence:c},n.length)]})});function mr({thinking:t,streaming:s,wrap:n=!0,forceOpen:r=!1}){const c=xe(),[i,a]=l.useState(null),o=i??n,u=o||r,m=s?t.trimEnd().slice(-80):t.split(`
312
- `)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${u?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>a(!o),children:[u?e.jsx(Ge,{}):e.jsx(Pt,{}),e.jsx(lt,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s&&u?e.jsxs("span",{className:"thinking-live-label",children:[c("thinkingNow"),e.jsx("span",{className:"dots"})]}):u?c("thinking"):c("thinkingPreview",{preview:m})})]}),u&&e.jsx("div",{className:"thinking-body",children:t})]})}const hr={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function gr(t){return hr[t]??"🛠"}const fr=l.memo(function({block:s,view:n,onKillBash:r,wrap:c=!0,forceOpen:i=!1}){var q,Y,T,P;const a=xe(),[o,u]=l.useState(c),m=o||i,[y,g]=l.useState(!1),x=!n.result&&n.streaming&&!n.status,b=s.name==="bash"&&x,E=n.result!==void 0,A=!n.result&&!!n.status,H=((q=n.result)==null?void 0:q.isError)??((Y=n.status)==null?void 0:Y.isError)??!1,j=(n.result?n.result.content.map(k=>k.type==="text"?k.text:"").join(""):n.liveOutput??"").replace(/…\[LIVE_OMIT:(\d+)\]…\n/,(k,B)=>a("liveOutputOmitted",{n:B})),J=H?"err":E?"ok":x||A?"run":"idle";let Q=a(H?"error":E?"done":x?"running":A?"toolDoneWaitingModel":"toolQueued");const X=A&&((T=n.status)==null?void 0:T.durationMs)!==void 0?yr(n.status.durationMs):"";A&&X&&(Q=`${Q} · ${X}`);const U=A&&((P=n.status)==null?void 0:P.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",K=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),g(!0),setTimeout(()=>g(!1),1200))};return e.jsxs("div",{className:`toolcall ${J}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:gr(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[Q,U&&e.jsx("em",{className:"toolcall-exit",children:U})]}),e.jsx("span",{className:"toolcall-spacer"}),b&&r&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:a("stopBashTip"),onClick:r,children:[e.jsx(jt,{}),e.jsx("span",{children:a("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:a("copyArgs"),onClick:K,children:y?e.jsx(Yi,{}):e.jsx(jn,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>u(k=>i?!0:!k),children:m?e.jsx(Ge,{}):e.jsx(Pt,{})})]}),m&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(xr,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),j.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[a(H?"errorOutput":"output"),(x||A)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:j})]}),x&&j.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",a("waitingOutput")]}),A&&j.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",a("waitingModel")]})]})]})});function xr({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(tt,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function yr(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),r=Math.round(s%60);return`${n}m ${String(r).padStart(2,"0")}s`}const vr=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function ds(t){var n;const s=t.match(vr);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}const br=1568,kr=2*1024*1024;function We(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function On(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const n=Math.min(1,br/Math.max(s.width,s.height)),r=Math.max(1,Math.round(s.width*n)),c=Math.max(1,Math.round(s.height*n)),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 a=null;for(const[o,u]of i){const m=document.createElement("canvas");m.width=r,m.height=c;const y=m.getContext("2d");if(!y)continue;o!=="image/png"&&(y.fillStyle="#ffffff",y.fillRect(0,0,r,c)),y.drawImage(s,0,0,r,c);const g=m.toDataURL(o,u),x=g.match(/^data:([^;]+);base64,/),b=x?x[1]:o,E=g.replace(/^data:[^;]*;base64,/,""),A=Math.floor(E.length*3/4);if(a={data:E,mimeType:b,name:t.name,size:A},A<=kr)return a}return a}finally{s.close()}}const jr=20*1024*1024;function ct(t){return t.type==="text"&&typeof t.text=="string"?t:null}function Kn(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function Wn(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function Un(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function qn(t){return t.type==="bash"&&typeof t.command=="string"?t:null}function wr(t){return t.imageData?"image":t.uploadPath?"upload":t.fileData?"file":"path"}function Nr(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 n=t.path.split("/").pop()??t.path;return t.mode==="lines"&&t.lines?s("attachLines",{path:n,start:t.lines.start,end:t.lines.end}):t.mode==="reference"?s("refOnly",{path:n}):s("attachContent",{path:n})}const Ys=l.memo(function({message:s,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:i,isLast:a,onEdit:o,onKillBash:u,onCollapse:m,questionAttachments:y,qnIndex:g,qnActive:x,onJump:b,thinkingWrap:E,toolsWrap:A,searchActive:H}){const S=xe(),[j,J]=l.useState(!1),[Q,X]=l.useState(""),[U,K]=l.useState([]),[q,Y]=l.useState(!1),[T,P]=l.useState(null),k=h=>{P(h),window.setTimeout(()=>P(L=>L===h?null:L),4e3)};if(s.role==="toolResult")return null;const B=s.role==="custom"&&s.customType==="file",Z=s.content.map(h=>{var L;return((L=ct(h))==null?void 0:L.text)??""}).filter(Boolean).join(`
304
+ 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})",exitBanner:"[Process exited with code {code}]",closeTerminal:"Close terminal",renameTerminal:"Rename terminal",rerun:"Reload .pi/commands.json",terminalTitle:"Terminal {n}",aiBashGroup:"Terminal-backed bash",exampleName:"e.g. start dev server",exampleCommand:"e.g. npm run dev",scmTab:"Git",scmTitle:"Source Control",scmRefreshTip:"Re-query git status & diff",scmCurrentBranch:"Current branch",scmUpstreamGone:"Upstream deleted",scmAheadBehind:"↑{ahead} ↓{behind}",scmDetached:"Detached HEAD",scmSelectBranch:"Select branch…",scmRemoteBranches:"Remote branches",scmStageTip:"Stage {path}",scmUnstageTip:"Unstage {path}",scmSwitch:"Switch",scmSwitchBranch:"Switch branch",scmSwitchBranchTip:"Runs git checkout {branch} in the terminal",scmPush:"Push",scmPushTip:"Runs git push in the terminal",scmPull:"Pull",scmPullTip:"Runs git pull in the terminal",scmCommit:"Commit",scmCommitTip:'Runs git commit -m "…" in the terminal (commits staged changes only)',scmCommitAll:"Commit All",scmCommitAllTip:'Runs git add -A && git commit -m "…" in the terminal (stages all changes incl. untracked and commits)',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 — stage it with + to include (or use Commit All)",scmQueryFailed:"Git query failed: {error}",scmQueryFailedShort:"Query failed",pluginCommandFallback:"Plugin command",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:"Add key",cloning:"Adding",cloneProviderTitle:"Add a second API key for this provider (baseUrl and model list are copied automatically)",pasteKey:"Paste API key…",savingKey:"Saving",saveKey:"Save key",addKey:"Add key",addKeyPlaceholder:"Paste the key value…",keyNamePh:"Name (optional, e.g. backup)",providerIdPlaceholder:"Provider ID",baseUrlExamplePh:"baseUrl, e.g. https://api.opencode.ai/zen/v1 or http://127.0.0.1:4096",saveAllBatch:"Save all ({n})",netDisconnected:"Network disconnected — reconnect and retry",advancedEdit:"Advanced edit",batchCreateProviders:"Batch-create providers ({n} APIs)",secondKeyTitle:"Add a second key for {api} · {baseUrl} · {n} models — just name the new provider and enter the key.",noBaseUrlShort:"(no baseUrl)",providerNameLabel:"Provider name",providerNameHint:"(new ID, e.g. opencode-2)",apiKeyLabel:"API key",secondKeyPlaceholder:"sk-… second key",batchDesc:"This provider has multiple APIs ({apis}); it was split into {n} custom providers. Save each so all models (e.g. muse-spark) work. Enter one shared second key to save all at once.",batchKeyLabel:"Shared API key (applies to all {n} providers)",modelsCountShort:"{n} models: ",noKeyYet:"No key yet — add one to use this provider",activateKey:"Set active",removeKey:"Remove",removeKeyConfirm:"Remove this key? It must be re-configured to be used again.",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",settingsPromptHistory:"Input history",settingsPromptHistoryDesc:"Cycle previous prompts with ↑/↓ in the input — global across conversations (localStorage)",promptHistoryMax:"Max entries",promptHistoryMaxHint:"Oldest entries are dropped when exceeded (1–500)",promptHistoryCharLimit:"Limit characters per entry",promptHistoryCharLimitHint:"When enabled, overlong prompts are truncated before saving",promptHistoryCharLimitPlaceholder:"Max chars (100–20000)",promptHistoryClear:"Clear history",promptHistoryClearConfirm:"Confirm clear?",promptHistoryCleared:"Input history cleared",promptHistoryCount:"{n} entries",promptHistoryEmpty:"No history yet — ↑/↓ has nothing to cycle",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",settingsMarkers:"Markers",settingsMarkersDesc:"Let the AI write [[todo:...]] / [[svc:...]] / [[notify:...]] / [[conv:rename:...]] inline markers in replies to update state without a tool round-trip. Global off disables all; per-marker toggles give fine control.",markersEnabled:"Markers enabled (global)",markersEnabledDesc:"Off = no marker guidance injected and no parsing; markers stay as plain text.",markersOffHint:"Globally off: all markers disabled — the AI won't write markers and no side effects fire.",markerGroupTodo:"todo — tasks",markerGroupSvc:"svc — background services",markerGroupNotify:"notify — non-blocking hints",markerGroupRename:"conv/rename — rename chat",markerRenameTip:"[[conv:rename:Title]] or [[rename:set:Title]] renames the current conversation (≤80 chars)",settingsTerminalTools:"Terminal tools",terminalToolsEnabled:"Enable persistent terminal tools",settingsTerminalToolsDesc:"Let the AI use the built-in terminal for interactive programs (REPLs/vim), long-running servers, continuous output watching, or when you ask it to work in the visible terminal; ordinary commands still go through the one-shot bash tool",terminalToolsOffHint:"Disabled: the AI has no terminal_* tools and receives no usage guidance",settingsMessageDisplay:"Message display",thinkingWrap:"Show full thinking",thinkingWrapDesc:"On: thinking always expands fully and wraps (live reasoning visible while streaming); Off: collapses to a one-line summary with the latest text shown live while streaming",toolsWrap:"Show full tools",toolsWrapDesc:"On: tool calls always expand fully showing arguments and output; Off: collapsed by default, click to expand",terminalBashTakeover:"Terminal-backed bash",terminalBashTakeoverDesc:"This switch decides whether bash is overridden to a terminal version: OFF = native SDK bash (process spawn, no terminal); ON = runs in a visible terminal, where the persist parameter decides (on top of the switch) one-shot (false — process exits when the command finishes, output retained) vs persistent (true — shell state retained across calls, silent commands move to the background and notify the AI)",terminalBashIdleMs:"Silence-to-background threshold (ms)",terminalBashIdleMsDesc:"In persistent-terminal mode, when a command produces no output for this long, stop blocking and let it keep running in the background; the AI is notified when it finishes. 0 = always wait until completion (default 15000)",visionBridgePromptPlaceholder:"Type a custom transcription prompt… (empty = built-in default, applied on blur)",visionBridgePromptAppendHint:"Append mode: custom text is appended after the built-in transcription prompt (recommended — keeps the verbatim-transcription contract).",visionBridgePromptReplaceHint:"Replace mode: custom text replaces the built-in transcription prompt entirely. After switching, the editor shows the built-in default prompt ready to edit; blurring without changes keeps the default.",uninstallExt:"Uninstall",uninstallConfirm:"Confirm?",uninstallConfirmHint:"Click again to confirm — runs pi remove in the terminal",uninstallHint:"Runs pi remove in a visible terminal, then refreshes the list automatically",uninstallTitle:"Uninstall",pluginUpdate:"Update",pluginUpdateHint:"Re-installs from the recorded source (--force, keeps config.json), then refreshes the plugin list automatically",pluginUninstallHint:"Runs pi-web-ui uninstall in a visible terminal (click again to confirm), then refreshes the list automatically",settingsExtensions:"Extensions",settingsUiPlugins:"UI plugins",noUiPlugins:"No UI plugins installed (<dataDir>/plugins/)",dshPatches:"DSH user patches",dshPatchesDesc:"Cordis patches loaded at runtime boot, in filename order (<dataDir>/dsh-patches/*.yml). New/edited files take effect after 'Rescan' restarts the runtime; broken files are skipped and logged to runtime stderr.",dshPatchesRescan:"Rescan",dshPatchesRescanHint:"Re-scan the patch directory and restart the DSH runtime so new patches take effect",dshPatchesEmpty:"No patch files yet",dshPatchesPath:"Patch directory: ",uiPluginNoSource:"Installed manually — no recorded source, online update unavailable",uiPluginPerms:"Permissions",pluginSettingsSave:"Save plugin settings",pluginSettingsSaving:"Saving…",pluginSettingsReset:"Reset defaults",settingsPresets:"Presets",settingsSubagentTemplates:"Subagent templates",settingsSubagentTemplatesDesc:"Presets for spawned subagents (role system prompt + skills/extensions whitelist + optional model). AI may pick a template (subagent_spawn template param) or spawn without one; disabled templates stay in the panel but are invisible to AI tools.",noSubagentTemplates:"No subagent templates yet. AI can pick a template when spawning a subagent (role prompt + skills/extensions whitelist + optional model), or spawn without a template param for default config.",subagentTemplateNew:"New template",subagentTemplateEdit:"Edit",subagentTemplateClosed:"Disabled",tplDefaultBadge:"Built-in",subagentDefaultModelLabel:"Default subagent model",subagentFollowMain:"Follow the main conversation's current model",subagentDefaultModelHint:"Fallback model for all subagents (a template's own model and the subagent_spawn model param take priority); does not change the main conversation's model.",subagentNoModels:"No usable models yet (configure a provider API key first) — subagents will follow the main conversation's model.",subagentTemplateOffHint:"Disabled templates stay in the panel and can be re-enabled, but AI tools can't see or pick them",subagentTemplateEnable:"Enable",subagentTemplateDisable:"Disable",tplNamePlaceholder:"Template name (referenced by AI via subagent_spawn's template param)…",tplDescriptionPlaceholder:"Description (AI uses it to judge when to pick this template)…",tplPromptModeLabel:"System prompt mode",tplModelLabel:"Model (empty = follow main conversation)",tplSystemPromptLabel:"System prompt",tplSystemPromptPlaceholder:"Template role system prompt… (may be empty in append mode)",tplWhitelistHint:"Whitelist: checked = the subagent only gets these; none checked = follow the main session settings",tplSkillsLabel:"Skills whitelist",tplExtensionsLabel:"Extensions whitelist",tplSave:"Save template",tplCancel:"Cancel edit",tplDelete:"Delete template",tplInherit:"Follow main session",settingsEnabled:"Enabled",settingsDisabled:"Disabled",presetNamePlaceholder:"Preset name…",saveAsPreset:"Save as preset",applyPreset:"Apply",deletePreset:"Delete preset",noSkills:"No skills",noExtensions:"No extensions",noPresets:"No presets yet (tune the settings above, then save them as a preset)",loadingSession:"Loading session…",connectingServer:"Connecting to pi-web-ui server…"},En=l.createContext(null);function na(){try{const t=localStorage.getItem(Tn);if(t==="zh"||t==="en")return t}catch{}return"zh"}function ia({children:t}){const[s,n]=l.useState(na),r=l.useCallback(i=>{n(i);try{localStorage.setItem(Tn,i)}catch{}},[]),c=l.useCallback((i,o)=>{let u=Fs[i];if(s==="zh"&&(u=Bs[i]),o)for(const[m,y]of Object.entries(o))u=u.replaceAll(`{${m}}`,String(y));return u},[s]);l.useEffect(()=>{document.documentElement.lang=s==="zh"?"zh-CN":"en",document.title=s==="zh"?Bs.docTitle:Fs.docTitle},[s]);const a=l.useMemo(()=>({locale:s,setLocale:r,t:c}),[s,r,c]);return e.jsx(En.Provider,{value:a,children:t})}function mt(){const t=l.useContext(En);if(!t)throw new Error("useI18n must be used within LanguageProvider");return t}function be(){return mt().t}const aa=[{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 $s({settings:t,onChange:s,onPreview:n}){const r=be(),c=a=>s({...t,...a});return e.jsxs("div",{className:"sound-menu",children:[e.jsx("div",{className:"dd-header",children:r("soundHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(yn,{className:"sound-icon"}),e.jsx("span",{children:r("enableSound")})]}),e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:a=>c({enabled:a.target.checked})})]}),aa.map(({kind:a,labelKey:i,descKey:o})=>e.jsxs("label",{className:`sound-row ${t.enabled?"":"disabled"}`,children:[e.jsxs("span",{className:"sound-label",children:[e.jsx("span",{className:"sound-name",children:r(i)}),e.jsx("span",{className:"sound-desc",children:r(o)})]}),e.jsxs("span",{className:"sound-right",children:[e.jsx("button",{type:"button",className:"sound-preview",title:r("preview"),disabled:!t.enabled,onClick:u=>{u.preventDefault(),n(a)},children:r("preview")}),e.jsx("input",{type:"checkbox",checked:t[a],disabled:!t.enabled,onChange:u=>c({[a]:u.target.checked})})]})]},a)),e.jsxs("div",{className:`sound-volume ${t.enabled?"":"disabled"}`,children:[e.jsx("span",{className:"sound-name",children:r("volume")}),e.jsx("input",{type:"range",min:0,max:100,step:5,value:t.volume,disabled:!t.enabled,onChange:a=>c({volume:Number(a.target.value)})}),e.jsxs("span",{className:"sound-vol-num",children:[t.volume,"%"]})]})]})}let Dt=null;function ra(t){if(t===void 0){const n=globalThis.document;if(n&&typeof n.baseURI=="string"&&n.baseURI)try{t=new URL(n.baseURI).pathname}catch{}if(t===void 0)return"/"}if(!t||t==="/")return"/";let s=t.replace(/index\.html$/i,"");return s.endsWith("/")||(s+="/"),s}function Pn(){return Dt===null&&(Dt=ra()),Dt}function la(t,s){return s==="/"?t:s+t.replace(/^\/+/,"")}function Ve(t){return la(t,Pn())}const Mn="pi-web-notify",At={enabled:!1};function Rn(){try{const t=localStorage.getItem(Mn);if(!t)return{...At};const s=JSON.parse(t);return{enabled:typeof s.enabled=="boolean"?s.enabled:At.enabled}}catch{return{...At}}}function Hs(t){try{localStorage.setItem(Mn,JSON.stringify(t))}catch{}}function ot(){return typeof window<"u"&&"Notification"in window}function oa(){return ot()?Notification.permission:"denied"}async function ca(){if(!ot())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}}async function _t(t,s){var r;if(!ot()||document.hasFocus()||!Rn().enabled||Notification.permission!=="granted")return;const n={body:s,icon:Ve("/icons/icon-192.png"),badge:Ve("/icons/icon-192.png"),tag:"pi-web-ui"};try{const c=await((r=navigator.serviceWorker)==null?void 0:r.getRegistration());c&&typeof c.showNotification=="function"?c.showNotification(t,n):new Notification(t,n)}catch{}}function Os(){const t=be(),[s,n]=l.useState(Rn),[r,c]=l.useState(()=>ot()?oa():"denied"),a=async i=>{const o={...s,enabled:i};if(n(o),Hs(o),i){const u=await ca();if(c(u),u!=="granted"){const m={...o,enabled:!1};n(m),Hs(m)}}};return e.jsxs("div",{className:"sound-menu",style:{borderTop:"1px solid var(--border-color, rgba(255,255,255,.08))",marginTop:6,paddingTop:6},children:[e.jsx("div",{className:"dd-header",children:t("notifyHeader")}),e.jsxs("label",{className:"sound-row sound-master",children:[e.jsxs("span",{className:"sound-label",children:[e.jsx(Xi,{className:"sound-icon"}),e.jsx("span",{children:t("notifyEnable")})]}),e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:i=>a(i.target.checked)})]}),e.jsx("div",{className:"sound-desc",style:{padding:"2px 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyEnableDesc")}),!ot()&&e.jsx("div",{className:"sound-desc",style:{padding:"0 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyUnsupported")}),r==="denied"&&e.jsx("div",{className:"sound-desc",style:{padding:"0 8px 4px",opacity:.7,fontSize:"0.82em"},children:t("notifyDenied")})]})}function da({chat:t,send:s,terminal:n,view:r,plugins:c,onViewChange:a,onOpenPanel:i,onOpenSettings:o,onOpenBgTasks:u,onOpenGlobalSearch:m,sound:y,onSoundChange:g,onSoundPreview:x,themes:b,theme:T,onThemeChange:D}){var L;const{locale:H,setLocale:C,t:j}=mt(),[J,Q]=l.useState(!1),[X,U]=l.useState(!1),[W,q]=l.useState(!1),[Y,S]=l.useState(!1),[P,k]=l.useState(!1),B=[{value:"zh",label:j("langZh")},{value:"en",label:j("langEn")}],Z=t.ready?j("connected"):t.status==="closed"?j("reconnecting"):j("connecting"),G=t.ready?"ok":"busy",M=()=>{var _,te;if(!t.ready)return;const d=j("updateTabTitle"),E={name:d,command:"npm i -g pi-web-ui@latest",cwd:"${pwd}"},h=t.terminals.find(O=>O.title===d);h?(n.restart(h.id),s({type:"run_command",terminalId:h.id,conversationId:h.conversationId,command:E,cols:80,rows:24})):n.create({id:Ue(),conversationId:t.activeConversationId||((_=t.state)==null?void 0:_.conversationId)||"",title:d,cwd:((te=t.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:E}),S(!1),k(!1),a("terminal")},I=(d,E)=>{var te,O;if(!t.ready||d.length===0)return;const h={name:E,command:sa(d),cwd:"${pwd}"},_=t.terminals.find(re=>re.title===E);_?(n.restart(_.id),s({type:"run_command",terminalId:_.id,conversationId:_.conversationId,command:h,cols:80,rows:24})):n.create({id:Ue(),conversationId:t.activeConversationId||((te=t.state)==null?void 0:te.conversationId)||"",title:E,cwd:((O=t.state)==null?void 0:O.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:h}),S(!1),k(!1),a("terminal")},N=t.updatesAll??[],$=N.filter(d=>!d.upToDate&&!d.error).length,z=N.filter(d=>!d.upToDate&&!d.error&&d.kind!=="webui"),ie=()=>e.jsxs("div",{className:"dd-updates-all",children:[e.jsx("div",{className:"dd-header",children:j("updatesAllTitle")}),t.updatesAll===null?e.jsx("div",{className:"dd-note",children:j("checkingUpdate")}):N.length===0?e.jsx("div",{className:"dd-note",children:j("updatesAllUpToDate")}):e.jsx("ul",{className:"dd-all-list",children:N.map(d=>e.jsxs("li",{className:`dd-all-item${d.error?" err":d.upToDate?"":" warn"}`,children:[e.jsx("span",{className:"dd-all-name",title:d.name,children:d.name}),e.jsx("span",{className:"dd-all-kind",children:d.kind==="webui"?j("kindWebUi"):d.kind==="pi-core"?j("kindPiCore"):j("kindPackage")}),e.jsx("span",{className:"dd-all-vers",children:d.error?j("updateCheckFailed"):d.upToDate?`v${d.current}`:e.jsxs(e.Fragment,{children:["v",d.current," → v",d.latest]})}),d.kind!=="webui"&&!d.upToDate&&!d.error&&e.jsx("button",{type:"button",className:"dd-update-btn",onClick:()=>I([d],j("updatePkgTabTitle",{name:d.name})),children:j("updateBtn")})]},`${d.kind}:${d.name}`))}),e.jsxs("div",{className:"dd-actions",children:[z.length>0&&e.jsx("button",{type:"button",className:"dd-refresh accent",style:{flex:1},onClick:()=>I(z,j("updateAllTabTitle")),children:j("updateAllBtn")}),e.jsx("button",{type:"button",className:"dd-refresh",style:z.length>0?{flex:1}:void 0,onClick:()=>s({type:"check_updates_all",force:!0}),children:j("updatesAllRefresh")})]})]}),v=()=>{var d,E;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dd-update",children:[e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("currentVersion")}),e.jsxs("b",{children:["v",((d=t.update)==null?void 0:d.current)??"…"]})]}),e.jsxs("div",{className:"dd-row",children:[e.jsx("span",{children:j("latestVersion")}),e.jsx("b",{children:t.update===null?j("checkingUpdate"):t.update.error?t.update.error:t.update.latest?`v${t.update.latest}`:j("checkingUpdate")})]}),t.update&&t.update.upToDate&&e.jsx("div",{className:"dd-note ok",children:j("upToDate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note warn",children:j("updateAvailable",{version:t.update.latest})}),((E=t.update)==null?void 0:E.latestPublishedAt)&&Date.now()-new Date(t.update.latestPublishedAt).getTime()<30*6e4&&e.jsx("div",{className:"dd-note warn",children:j("updateJustPublished",{version:t.update.latest??""})}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("div",{className:"dd-note",children:j("updateTerminalHint")})]}),e.jsxs("div",{className:"dd-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"check_update"}),children:t.update===null?j("checkingUpdate"):j("checkUpdate")}),t.update&&!t.update.upToDate&&t.update.latest&&e.jsx("button",{type:"button",className:"dd-refresh accent",onClick:M,children:j("updateNow")})]})]})};return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"brand",children:[e.jsx("button",{type:"button",className:"panel-toggle",title:j("openHistory"),onClick:()=>i("left"),children:e.jsx($i,{})}),e.jsx("span",{className:"brand-logo",children:"π"}),e.jsx("span",{className:"brand-name",children:"pi-web-ui"}),e.jsx("span",{className:`conn-dot ${G}`,title:Z}),e.jsx("span",{className:"conn-label",children:Z})]}),e.jsxs("div",{className:"topbar-actions",children:[e.jsxs("div",{className:"view-switch",role:"tablist","aria-label":j("viewSwitch"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="chat",className:r==="chat"?"active":"",onClick:()=>a("chat"),children:[e.jsx(st,{}),e.jsx("span",{children:j("chat")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="terminal",className:r==="terminal"?"active":"",onClick:()=>a("terminal"),children:[e.jsx(tt,{}),e.jsx("span",{children:j("terminal")})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":r==="git",className:r==="git"?"active":"",onClick:()=>a("git"),children:[e.jsx(yt,{}),e.jsx("span",{children:j("scmTab")})]}),c.map(d=>{const E=d.error?`${d.name}: ${d.error}`:d.description?`${d.name} — ${d.description}`:d.name;return e.jsxs("button",{type:"button",role:"tab","aria-selected":r===`plugin:${d.id}`,className:`plugin-tab${r===`plugin:${d.id}`?" active":""}${d.error?" broken":""}`,title:E,onClick:()=>a(`plugin:${d.id}`),children:[d.icon?e.jsx("span",{"aria-hidden":!0,children:d.icon}):null,e.jsx("span",{children:d.name})]},d.id)})]}),e.jsxs("div",{className:"topbar-desktop",children:[e.jsxs("button",{type:"button",className:"chip",title:j("searchGlobalTip"),onClick:m,children:[e.jsx(Nt,{}),e.jsx("span",{className:"chip-sub",children:j("searchGlobal")})]}),e.jsxs("button",{type:"button",className:"chip bg-task-chip","data-tip":j("bgTasksTip"),onClick:u,children:[e.jsx(Ct,{}),e.jsx("span",{className:"chip-sub",children:j("bgTasks")}),t.bgServers.length>0&&e.jsx("span",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsxs("button",{type:"button",className:"chip",title:j("settingsTitle"),onClick:o,children:[e.jsx(wt,{}),e.jsx("span",{className:"chip-sub",children:j("settings")})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(yn,{}),e.jsx("span",{className:"chip-sub",children:j("sound")})]}),open:J,onOpenChange:Q,children:[e.jsx($s,{settings:y,onChange:g,onPreview:x}),e.jsx(Os,{})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(zi,{}),e.jsx("span",{className:"chip-sub",children:H==="zh"?j("langZh"):"EN"})]}),open:X,onOpenChange:U,children:[e.jsx("div",{className:"dd-header",children:j("language")}),B.map(d=>e.jsx(Ie,{active:H===d.value,onClick:()=>{C(d.value),U(!1)},children:d.label},d.value))]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Li,{}),e.jsx("span",{className:"chip-sub",children:j("theme")})]}),open:W,onOpenChange:q,children:[e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ie,{active:T===null,onClick:()=>{D(null),q(!1)},children:j("themeDefault")}),b.map(d=>e.jsx(Ie,{active:T===d.id,onClick:()=>{D(d.id),q(!1)},children:H==="en"?d.nameEn??d.name:d.name},d.id))]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(ls,{}),e.jsxs("span",{className:"chip-sub",children:["v",((L=t.update)==null?void 0:L.current)??"…"]}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot",title:j("updateAvailable",{version:t.update.latest??""})}),$>0&&e.jsx("span",{className:"update-badge",children:j("updatesAllBadge",{n:$})})]}),open:Y,onOpenChange:d=>{S(d),d&&(s({type:"check_update"}),s({type:"check_updates_all"}))},fit:!0,children:[e.jsx("div",{className:"dd-header",children:j("update")}),v(),ie()]}),e.jsx("a",{className:"chip github",href:"https://github.com/xing-shuyin/pi-web-ui",target:"_blank",rel:"noreferrer noopener",title:j("githubRepo"),children:e.jsx(As,{})})]}),e.jsxs("button",{type:"button",className:"chip newchat","data-tip":j("newChatTip"),onClick:()=>s({type:"new_chat"}),children:[e.jsx(He,{}),e.jsx("span",{children:j("newChat")})]}),e.jsx("div",{className:"topbar-more",children:e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(Bi,{}),e.jsx("span",{className:"chip-sub",children:j("more")}),t.update&&!t.update.upToDate&&e.jsx("span",{className:"update-dot"})]}),open:P,onOpenChange:d=>{k(d),d&&(s({type:"check_update"}),s({type:"check_updates_all"}))},children:[e.jsx("div",{className:"dd-header",children:j("sound")}),e.jsx("div",{className:"dd-header",children:j("settings")}),e.jsxs(Ie,{onClick:()=>{k(!1),o()},children:[e.jsx(wt,{})," ",j("settingsTitle")]}),e.jsxs(Ie,{onClick:()=>{k(!1),m()},children:[e.jsx(Nt,{})," ",j("searchGlobal")]}),e.jsxs(Ie,{onClick:()=>{k(!1),u()},children:[e.jsx(Ct,{})," ",j("bgTasks"),t.bgServers.length>0&&e.jsx("em",{className:"bg-task-badge",children:t.bgServers.length})]}),e.jsx($s,{settings:y,onChange:g,onPreview:x}),e.jsx(Os,{}),e.jsx("div",{className:"dd-header",children:j("language")}),B.map(d=>e.jsx(Ie,{active:H===d.value,onClick:()=>C(d.value),children:d.label},d.value)),e.jsx("div",{className:"dd-header",children:j("theme")}),e.jsx(Ie,{active:T===null,onClick:()=>{D(null),k(!1)},children:j("themeDefault")}),b.map(d=>e.jsx(Ie,{active:T===d.id,onClick:()=>{D(d.id),k(!1)},children:H==="en"?d.nameEn??d.name:d.name},d.id)),e.jsx("div",{className:"dd-header",children:j("update")}),v(),ie(),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(As,{})," ",j("githubRepo")]})]})}),e.jsx("button",{type:"button",className:"panel-toggle",title:j("openFiles"),onClick:()=>i("right"),children:e.jsx(Je,{})})]})]})}function Ks(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:`${s.getMonth()+1}/${s.getDate()}`}function ua(t,s){var a;const n=new Map(t.map(i=>[i.id,i])),r=new Map;for(const i of t){const o=i.parentId?((a=n.get(i.parentId))==null?void 0:a.cwd)??i.cwd:i.cwd,u=r.get(o)??[];u.push(i),r.set(o,u)}const c=[...r.entries()].map(([i,o])=>({cwd:i,isCurrent:i===s,convs:o}));return c.sort((i,o)=>i.isCurrent?-1:o.isCurrent?1:i.cwd<o.cwd?-1:i.cwd>o.cwd?1:0),c}const pa="pi-web-ui:lp-collapse-projects",ma="pi-web-ui:lp-collapse-convs",ha="pi-web-ui:lp-collapse-sessions";function Bt(t,s=!1){const[n,r]=l.useState(()=>{try{const a=localStorage.getItem(t);if(a==="1")return!0;if(a==="0")return!1}catch{}return s}),c=l.useCallback(()=>{r(a=>{const i=!a;try{localStorage.setItem(t,i?"1":"0")}catch{}return i})},[t]);return[n,c]}const In="pi-web-ui:lp-sizes",Jt={projects:1,convs:1,sessions:1};function ga(){try{const t=localStorage.getItem(In);if(t){const s=JSON.parse(t);return{projects:typeof s.projects=="number"&&s.projects>0?s.projects:1,convs:typeof s.convs=="number"&&s.convs>0?s.convs:1,sessions:typeof s.sessions=="number"&&s.sessions>0?s.sessions:1}}}catch{}return{...Jt}}const fa=l.memo(function({ready:s,status:n,cwd:r,sessionFile:c,conversations:a,sessions:i,projects:o,activeConversationId:u,send:m,active:y,collapsible:g,onToggleCollapse:x}){const b=be(),T=c,D=r,[H,C]=l.useState(null),[j,J]=l.useState(null),[Q,X]=l.useState(""),[U,W]=Bt(pa,!1),[q,Y]=Bt(ma,!1),[S,P]=Bt(ha,!1),k=l.useRef(null),[B,Z]=l.useState(()=>ga());l.useEffect(()=>{try{localStorage.setItem(In,JSON.stringify(B))}catch{}},[B]);const G=l.useCallback((d,E)=>h=>{h.preventDefault();const _=h.currentTarget,te=h.clientY,O={...B},re=k.current;if(!re)return;const ee=32,ge=72,ue=[{key:"projects",visible:o.length>0,collapsed:U},{key:"convs",visible:a.length>0,collapsed:q},{key:"sessions",visible:!0,collapsed:S}].filter(fe=>fe.visible),de=ue.filter(fe=>fe.collapsed).length,le=ue.filter(fe=>!fe.collapsed).map(fe=>fe.key).reduce((fe,ke)=>fe+(O[ke]??1),0)||1,f=Math.max(120,re.clientHeight-de*ee),K=(O[d]??1)+(O[E]??1),me=ge/f*le;_.classList.add("dragging"),document.body.classList.add("lp-resizing");const he=fe=>{const Me=(fe.clientY-te)/f*le;let ye=(O[d]??1)+Me;const _e=K-me;ye=Math.max(me,Math.min(_e,ye));const Le=K-ye;Z(Be=>({...Be,[d]:ye,[E]:Le}))},xe=()=>{window.removeEventListener("pointermove",he),window.removeEventListener("pointerup",xe),_.classList.remove("dragging"),document.body.classList.remove("lp-resizing")};window.addEventListener("pointermove",he),window.addEventListener("pointerup",xe)},[B,o.length,a.length,U,q,S]);l.useEffect(()=>{!y||!s||n!=="open"||r&&(m({type:"list_sessions"}),m({type:"list_projects"}))},[y,s,n,r,m]);const M=d=>{const E=d.name||d.firstMessage.trim();return E.length>0?E:b("emptyChat")},I=d=>d.split(/[\\/]/).pop()||d,N=(d,E,h,_,te)=>{const O=H===d;return e.jsx("button",{type:"button",className:`lp-del ${O?"confirm":""}`,title:O?h:E,onClick:re=>{re.stopPropagation(),O?(C(null),_()):C(d)},children:O?e.jsx(pt,{}):te??e.jsx(Ae,{})})},$=(d,E,h,_)=>e.jsxs("button",{type:"button",className:"lp-section-title panel-section-title",onClick:h,title:b(E?"expandSection":"collapseSection"),children:[e.jsxs("span",{className:"lp-section-title-text",children:[d,_!==void 0?` (${_})`:""]}),e.jsx("span",{className:"lp-section-chevron",children:E?e.jsx(Ge,{}):e.jsx(ut,{})})]}),ie=[{key:"projects",visible:o.length>0,collapsed:U},{key:"convs",visible:a.length>0,collapsed:q},{key:"sessions",visible:!0,collapsed:S}].filter(d=>d.visible).filter(d=>!d.collapsed),v=ie.reduce((d,E)=>d+(B[E.key]??1),0)||1,L=d=>ie.length<=1?1:(B[d]??1)/v*ie.length;return e.jsxs("aside",{ref:k,className:"panel panel-left lp-panel",children:[g&&x&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:b("collapsePanel"),onClick:x,children:e.jsx(Nn,{})}),o.length>0&&e.jsxs("div",{className:`lp-section panel-projects ${U?"collapsed":""}`,style:U?void 0:{flex:`${L("projects")} 1 0px`},children:[$(b("recentProjects"),U,W,o.length),!U&&e.jsx("div",{className:"lp-section-body projects-scroll",children:o.map(d=>{const E=D===d.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>C(h=>h===`proj:${d.path}`?null:h),children:[e.jsxs("button",{type:"button",className:`project-item ${E?"active":""}`,title:d.path,onClick:()=>{E||m({type:"set_cwd",path:d.path})},children:[e.jsx(Je,{className:"project-icon"}),e.jsxs("span",{className:"project-info",children:[e.jsx("span",{className:"project-name",children:I(d.path)}),e.jsx("span",{className:"project-path",children:d.path})]}),e.jsx("span",{className:"project-time",children:Ks(d.lastUsed)})]}),N(`proj:${d.path}`,b("deleteProject"),b("deleteProjectConfirm"),()=>m({type:"remove_project",path:d.path}))]},d.path)})})]}),o.length>0&&!U&&(a.length>0?!q:!S)&&e.jsx("div",{className:"lp-sash",onPointerDown:G("projects",a.length>0?"convs":"sessions"),onDoubleClick:()=>Z({...Jt}),title:b("dragToResize")}),a.length>0&&e.jsxs("div",{className:`lp-section lp-section-convs panel-convs ${q?"collapsed":""}`,style:q?void 0:{flex:`${L("convs")} 1 0px`},children:[$(b("runningConversations"),q,Y,a.length),!q&&e.jsx("div",{className:"lp-section-body convs-scroll",children:ua(a,r).map(d=>e.jsxs("div",{className:"panel-conv-group",children:[!d.isCurrent&&e.jsx("div",{className:"panel-conv-group-title",title:d.cwd,children:I(d.cwd)}),(()=>{const E=new Map(d.convs.map(ee=>[ee.id,ee])),h=new Map,_=[];for(const ee of d.convs)if(ee.parentId&&E.has(ee.parentId)){const ge=h.get(ee.parentId)??[];ge.push(ee),h.set(ee.parentId,ge)}else _.push(ee);const te=[],O=new Set,re=(ee,ge)=>{if(!O.has(ee.id)){O.add(ee.id),te.push({c:ee,depth:ge});for(const ue of h.get(ee.id)??[])re(ue,ge+1)}};for(const ee of _)re(ee,0);for(const ee of d.convs)re(ee,0);return te.map(({c:ee,depth:ge})=>{const ue=u===ee.id;return e.jsxs("div",{className:`lp-row${ge>0?" lp-sub":""}`,style:ge>0?{marginLeft:ge*18}:void 0,onMouseLeave:()=>C(de=>de===`conv:${ee.id}`?null:de),children:[e.jsxs("button",{type:"button",className:`session-item ${ue?"active":""}`,title:`${ee.title}${d.isCurrent?"":` — ${d.cwd}`}`,onClick:()=>{ue||m({type:"switch_conversation",id:ee.id})},children:[e.jsx(st,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[j===`conv:${ee.id}`?e.jsx("input",{autoFocus:!0,className:"session-rename-input",value:Q,placeholder:b("renameSessionPlaceholder"),onClick:de=>de.stopPropagation(),onChange:de=>X(de.target.value),onKeyDown:de=>{if(de.stopPropagation(),de.key==="Enter"&&!de.nativeEvent.isComposing){const Se=Q.trim();Se&&m({type:"rename_conversation",id:ee.id,name:Se}),J(null)}else de.key==="Escape"&&J(null)},onBlur:()=>J(null)}):e.jsxs("span",{className:"session-title",children:[ee.isSubagent&&e.jsx("span",{className:"subagent-badge",children:b("subagentBadge")}),ee.title,ee.error&&e.jsx("span",{className:"conv-error-badge",title:b("convErrorBadge",{error:ee.error})})]}),j===`conv:${ee.id}`?null:e.jsx("span",{className:"session-sub",children:ue?b("current"):b("messageCount",{n:ee.messageCount})})]}),ee.isStreaming&&e.jsx("span",{className:"conv-streaming",title:b("streaming")})]}),e.jsx("button",{type:"button",className:"lp-del lp-rename",title:b("renameSession"),onClick:de=>{de.stopPropagation(),C(null),X(ee.title),J(`conv:${ee.id}`)},children:e.jsx(St,{})}),!ee.isStreaming&&!ue&&N(`conv:${ee.id}`,b("dismissConversation"),b("dismissConversationConfirm"),()=>m({type:"dismiss_conversation",id:ee.id}),e.jsx(Pe,{})),ee.isStreaming&&e.jsx("span",{className:"lp-row-stalled",title:b("streaming"),style:{position:"absolute",right:28,top:"50%",transform:"translateY(-50%)"}})]},ee.id)})})()]},d.cwd))})]}),a.length>0&&!q&&!S&&e.jsx("div",{className:"lp-sash",onPointerDown:G("convs","sessions"),onDoubleClick:()=>Z({...Jt}),title:b("dragToResize")}),e.jsxs("div",{className:`lp-section lp-section-sessions panel-sessions ${S?"collapsed":""}`,style:S?void 0:{flex:`${L("sessions")} 1 0px`},children:[$(b("historySessions"),S,P,i.length),!S&&e.jsxs("div",{className:"lp-section-body sessions-scroll",children:[i.length===0&&e.jsx("div",{className:"panel-empty",children:b("noHistory")}),i.map(d=>{const E=T===d.path;return e.jsxs("div",{className:"lp-row",onMouseLeave:()=>C(h=>h===`sess:${d.path}`?null:h),children:[e.jsxs("button",{type:"button",className:`session-item ${E?"active":""}`,title:d.path,onClick:()=>{j||E||m({type:"switch_session",path:d.path})},children:[e.jsx(st,{className:"session-icon"}),e.jsxs("span",{className:"session-info",children:[j===d.path?e.jsx("input",{autoFocus:!0,className:"session-rename-input",value:Q,placeholder:b("renameSessionPlaceholder"),onClick:h=>h.stopPropagation(),onChange:h=>X(h.target.value),onKeyDown:h=>{if(h.stopPropagation(),h.key==="Enter"&&!h.nativeEvent.isComposing){const _=Q.trim();_&&m({type:"rename_session",path:d.path,name:_}),J(null)}else h.key==="Escape"&&J(null)},onBlur:()=>J(null)}):e.jsx("span",{className:"session-title",children:M(d)}),j===d.path?null:e.jsxs("span",{className:"session-sub",children:[E?b("current"):b("messageCount",{n:d.messageCount}),d.source==="tui"&&e.jsx("span",{className:"session-src",title:b("tuiTip"),children:"TUI"})]})]}),e.jsx("span",{className:"session-time",children:Ks(d.modified)})]}),e.jsx("button",{type:"button",className:"lp-del lp-rename",title:b("renameSession"),onClick:h=>{h.stopPropagation(),C(null),X(d.name??""),J(d.path)},children:e.jsx(St,{})}),N(`sess:${d.path}`,b("deleteSession"),b("deleteSessionConfirm"),()=>m({type:"delete_session",path:d.path}))]},d.path)})]})]})]})}),Ln="pi-web-ui:token";function xa(){try{const t=new URL(window.location.href),s=t.searchParams.get("token");s&&(localStorage.setItem(Ln,s.trim()),t.searchParams.delete("token"),window.history.replaceState(null,"",t.toString()))}catch{}}function ya(){try{return localStorage.getItem(Ln)??""}catch{return""}}function Mt(t){const s=ya();return s?`${t}${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`:t}function va(t,s){const n=s.assistantMessageEvent,r=t.stats.tokens,c=s.usage!==null?{...r,...s.usage}:r,a=c===r?t.stats:{...t.stats,tokens:c};if(n.type!=="text_delta"&&n.type!=="thinking_delta")return a===t.stats?t:{...t,stats:a};const i=n.delta??"";if(!i)return a===t.stats?t:{...t,stats:a};const o=t.streamingMessage??null,u=o&&o.id===s.messageId?o:{id:s.messageId,content:[]},m=[...u.content],y=n.type==="thinking_delta"?"thinking":"text",g=n.contentIndex??m.length-1;return g>=0&&g<m.length&&m[g].type===y?m[g]=y==="thinking"?{type:"thinking",thinking:(m[g].thinking??"")+i}:{type:"text",text:(m[g].text??"")+i}:m.push(y==="thinking"?{type:"thinking",thinking:i}:{type:"text",text:i}),{...t,stats:a,streamingMessage:{...u,id:s.messageId,content:m}}}const Xt="pi-web-ui:plugin-data";function ba(t,s){window.dispatchEvent(new CustomEvent(Xt,{detail:{pluginId:t,payload:s}}))}function ka(t){const s=n=>{const r=n.detail;t(r.pluginId,r.payload)};return window.addEventListener(Xt,s),()=>window.removeEventListener(Xt,s)}const et=new Map,Zt=new Set,Xe=new Set;let Ws=-1;function Dn(){return[...et.values()]}function ja(){const t=Dn();for(const s of Zt)s(t)}function wa(t){return Zt.add(t),t(Dn()),()=>Zt.delete(t)}async function Na(t,s){s!==Ws&&(Ws=s,et.clear(),Xe.clear());const n=new Set(t.map(r=>r.id));for(const r of[...et.keys()])n.has(r)||et.delete(r);for(const r of[...Xe])n.has(r)||Xe.delete(r);await Promise.all(t.filter(r=>r.hasClient&&!r.error&&!et.has(r.id)&&!Xe.has(r.id)).map(async r=>{try{const a=(await import(Ve(`/plugins/${encodeURIComponent(r.id)}/client/entry.mjs?e=${s}`))).default;a&&typeof a.mount=="function"?et.set(r.id,{info:r,module:a}):(Xe.add(r.id),console.error(`[plugin:${r.id}] entry.mjs 缺少 default.mount`))}catch(c){Xe.add(r.id),console.error(`[plugin:${r.id}] 客户端加载失败:`,c)}})),ja()}function Ca(t,s){return{pluginId:t,send:n=>s({type:"plugin_message",pluginId:t,payload:n}),onData:n=>ka((r,c)=>{r===t&&n(c)})}}const Sa=12,Ft=2e5,Ta=2e5,Ea="LIVE_OMIT",Pa={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 Ma(){const t=new Map,s=new Map,n=(r,c)=>`${r}:${c}`;return{write(r,c,a){const i=n(r,c),o=t.get(i);if(o&&o.size>0){for(const y of o)try{y.write(a)}catch{}return}const u=s.get(i)??"",m=u.length+a.length>Ta?a:u+a;s.set(i,m)},register(r,c,a){const i=n(r,c);let o=t.get(i);o||(o=new Set,t.set(i,o)),o.add(a);const u=s.get(i);if(u){try{a.write(u)}catch{}s.delete(i)}return()=>{const m=t.get(i);m&&(m.delete(a),m.size===0&&t.delete(i)),s.delete(i)}},clear(){t.clear(),s.clear()}}}function Us(t,s){const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId),c.role==="bashExecution"&&n.add(`bash-${c.id}`);let r=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function qs(t,s){if(t.size===0)return t;const n=new Set;for(const c of s.messages)c.role==="toolResult"&&c.toolCallId&&n.add(c.toolCallId);let r=!1;for(const c of t.keys())n.has(c)&&(t.delete(c),r=!0);return r?new Map(t):t}function Ra(t,s){var n,r,c,a;switch(s.type){case"status":return{...t,status:s.status,ready:s.status==="open"?t.ready:!1,terminals:s.status==="closed"?[]:t.terminals};case"ready":return{...t,serverVersion:s.serverVersion,engine:s.engine,ready:!0,protocolMismatch:s.protocolVersion!==void 0&&s.protocolVersion!==Sa};case"snapshot":return{...t,ready:!0,state:s.state,activeConversationId:s.state.conversationId,liveOutputs:Us(t.liveOutputs,s.state),toolStatuses:qs(t.toolStatuses,s.state)};case"snapshot_delta":{const i=t.state,o=s.msg;if(!i||i.conversationId!==o.conversationId||i.rev!==o.baseRev)return t;const u={...i,...o.state,messages:o.appended.length>0?[...i.messages,...o.appended]:i.messages};return{...t,ready:!0,state:u,activeConversationId:u.conversationId,liveOutputs:Us(t.liveOutputs,u),toolStatuses:qs(t.toolStatuses,u)}}case"tool_delta":{const i=t.liveOutputs.get(s.toolCallId),o=((i==null?void 0:i.text)??"")+s.delta,u=o.length>Ft?`…[${Ea}:${o.length-Ft}]…
305
+ `+o.slice(o.length-Ft):o,m=new Map(t.liveOutputs);return m.set(s.toolCallId,{toolName:s.toolName,text:u}),{...t,liveOutputs:m}}case"message_delta":{const i=t.state;return!i||i.conversationId!==s.msg.conversationId?t:{...t,state:va(i,s.msg)}}case"tool_status":return{...t,toolStatuses:new Map(t.toolStatuses).set(s.status.toolCallId,s.status)};case"notice":return{...t,notices:[...t.notices,s.notice].slice(-6)};case"dismiss_notice":return{...t,notices:t.notices.filter(i=>i.id!==s.id)};case"sessions":return{...t,sessions:s.sessions};case"conversations":return{...t,conversations:s.conversations,activeConversationId:s.activeId};case"projects":return{...t,projects:s.projects};case"files":return{...t,files:s.files};case"file_changed":return{...t,fileChanged:{path:s.path}};case"file_content":return{...t,fileContent:s.content};case"models":return{...t,models:s.models,modelsLoading:s.loading};case"models_config":return{...t,modelsConfig:s.providers};case"providers_status":return{...t,providers:s.providers};case"provider_keys":return{...t,providerKeys:s.keys};case"fetch_models_result":return{...t,fetchModelsResult:s.result};case"refresh_provider_result":return{...t,refreshProviderResult:s.result};case"clone_provider_result":return{...t,cloneProviderResult:s.result};case"install_result":return{...t,installResult:s.result};case"scm_data":return{...t,scmData:s.data};case"file_search_result":return{...t,fileSearch:s.result};case"session_search_result":return{...t,sessionSearch:s.result};case"scm_changed":return{...t,scmDirty:t.scmDirty+1};case"path_completions":return{...t,pathCompletions:s.completions};case"update_status":return{...t,update:s.status};case"update_status_all":return{...t,updatesAll:s.items};case"updates_check_started":return{...t,updatesAll:null};case"widgets":return{...t,widgets:s.widgets};case"statuses":return{...t,statuses:s.statuses};case"dialog":return{...t,dialog:s.dialog};case"question":return{...t,question:s.question};case"commands":return{...t,commands:s.commands,commandsPath:s.path};case"slash_commands":return{...t,slashCommands:s.commands};case"goal_status":return{...t,goal:s.status};case"settings":return{...t,settings:s.settings};case"bg_servers":return{...t,bgServers:s.servers};case"plugins":return{...t,plugins:s.plugins,pluginsEpoch:s.epoch};case"dsh_patches":return{...t,dshPatches:{patchDir:s.patchDir,files:s.files}};case"terminal_add":return{...t,terminals:[...t.terminals,s.meta]};case"terminal_remove":return{...t,terminals:t.terminals.filter(i=>i.id!==s.id)};case"terminal_exit":return s.conversationId&&(t.activeConversationId||(n=t.state)!=null&&n.conversationId)&&s.conversationId!==(t.activeConversationId||((r=t.state)==null?void 0:r.conversationId))?t:{...t,terminals:t.terminals.map(i=>i.id===s.terminalId?{...i,running:!1,exitCode:s.exitCode}:i)};case"terminal_restart":return{...t,terminals:t.terminals.map(i=>i.id===s.terminalId?{...i,running:!0,exitCode:null}:i)};case"terminal_list":return s.conversationId&&(t.activeConversationId||(c=t.state)!=null&&c.conversationId)&&s.conversationId!==(t.activeConversationId||((a=t.state)==null?void 0:a.conversationId))?t:{...t,terminals:s.terminals.map(i=>{var o;return{...i,conversationId:s.conversationId??((o=t.state)==null?void 0:o.conversationId)??""}})};case"terminal_active":return{...t,terminalActiveId:s.id};default:return t}}const zs="pi-web-client-id";let $t=null;function os(){if($t)return $t;let t=null;try{t=sessionStorage.getItem(zs),t||(t=Ue(),sessionStorage.setItem(zs,t))}catch{t=t??Ue()}return $t=t,t}const An="pi-web-last-cwd";function Ia(){try{return localStorage.getItem(An)}catch{return null}}function La(t){try{localStorage.setItem(An,t)}catch{}}function Da(){const t=location.protocol==="https:"?"wss:":"ws:";return Mt(`${t}//${location.host}${Ve("/ws")}`)}function Aa(){var Y;const[t,s]=l.useReducer(Ra,{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:[],providerKeys:{},installResult:null,pathCompletions:[],update:null,updatesAll:null,widgets:[],statuses:[],dialog:null,question:null,commands:[],commandsPath:"",slashCommands:[],terminals:[],terminalActiveId:null,goal:Pa,bgServers:[],settings:null,fetchModelsResult:null,refreshProviderResult:null,cloneProviderResult:null,scmData:null,fileSearch:null,sessionSearch:null,scmDirty:0,plugins:[],pluginsEpoch:0,dshPatches:null,protocolMismatch:!1}),n=l.useRef(null),r=l.useRef(Ma()),c=l.useRef(0),a=l.useRef(null),i=l.useRef(!0),o=l.useRef(0),u=l.useRef(0),m=l.useRef(new Map),y=l.useRef(null),g=l.useRef(!1),x=l.useRef(null),b=()=>{y.current||(y.current=setTimeout(()=>{y.current=null;const S=n.current;S&&S.readyState===WebSocket.OPEN&&S.send(JSON.stringify({type:"get_state"}))},300))},T=(S,P)=>{var Z;const k=m.current,B=k.get(S);if(B!==void 0&&P!==B+1){const G=q.current.chat,M=G.activeConversationId||((Z=G.state)==null?void 0:Z.conversationId);S===M&&b()}k.set(S,P)},D=l.useCallback((S,P)=>{const k=++u.current;s({type:"notice",notice:{id:k,level:S,text:P}})},[]),H=l.useCallback(S=>{const P=n.current;return P&&P.readyState===WebSocket.OPEN?(S.type==="check_updates_all"&&S.force===!0&&s({type:"updates_check_started"}),P.send(JSON.stringify(S)),!0):!1},[]),C=l.useCallback(()=>{if(!i.current)return;s({type:"status",status:"connecting"});const S=new WebSocket(Da());n.current=S,S.onopen=()=>{n.current===S&&(s({type:"status",status:"open"}),c.current=0,o.current=Date.now(),S.send(JSON.stringify({type:"hello",clientId:os()})))},S.onmessage=P=>{if(n.current!==S)return;o.current=Date.now();let k;try{k=JSON.parse(P.data)}catch{return}switch(k.type){case"ready":s({type:"ready",serverVersion:k.serverVersion,protocolVersion:k.protocolVersion,engine:k.engine}),S.send(JSON.stringify({type:"get_state"})),S.send(JSON.stringify({type:"list_files"})),S.send(JSON.stringify({type:"list_models"})),S.send(JSON.stringify({type:"list_commands"})),S.send(JSON.stringify({type:"get_commands"})),S.send(JSON.stringify({type:"check_update"})),S.send(JSON.stringify({type:"check_updates_all"}));break;case"snapshot":m.current=new Map,s({type:"snapshot",state:k.state});break;case"snapshot_delta":{const B=q.current.chat.state;(!B||B.conversationId!==k.conversationId||B.rev!==k.baseRev)&&b(),s({type:"snapshot_delta",msg:k});break}case"tool_delta":T(k.conversationId,k.seq),s({type:"tool_delta",toolCallId:k.toolCallId,toolName:k.toolName,delta:k.delta});break;case"tool_status":s({type:"tool_status",status:k});break;case"message_delta":{T(k.conversationId,k.seq),s({type:"message_delta",msg:k});break}case"notice":{const B=++u.current;s({type:"notice",notice:{id:B,level:k.level,text:k.text,textEn:k.textEn}});break}case"sessions":s({type:"sessions",sessions:k.sessions});break;case"conversations":s({type:"conversations",conversations:k.conversations,activeId:k.activeId});break;case"projects":s({type:"projects",projects:k.projects});break;case"files":s({type:"files",files:k});break;case"file_changed":s({type:"file_changed",path:k.path});break;case"file_content":s({type:"file_content",content:k});break;case"models":s({type:"models",models:k.models,loading:!1});break;case"models_config":s({type:"models_config",providers:k.providers});break;case"providers_status":s({type:"providers_status",providers:k.providers});break;case"provider_keys":s({type:"provider_keys",keys:k.keys});break;case"fetch_models_result":s({type:"fetch_models_result",result:{reqId:k.reqId,ok:k.ok,models:k.models,error:k.error}});break;case"refresh_provider_result":s({type:"refresh_provider_result",result:{reqId:k.reqId,ok:k.ok,added:k.added,total:k.total,error:k.error}});break;case"clone_provider_result":s({type:"clone_provider_result",result:{reqId:k.reqId,ok:k.ok,config:k.config,configs:k.configs,error:k.error}});break;case"scm_data":s({type:"scm_data",data:k});break;case"search_files_result":s({type:"file_search_result",result:{reqId:k.reqId,ok:k.ok,results:k.results,truncated:k.truncated}});break;case"session_search_results":s({type:"session_search_result",result:{reqId:k.reqId,ok:k.ok,results:k.results}});break;case"scm_changed":s({type:"scm_changed"});break;case"install_result":s({type:"install_result",result:k});break;case"path_completions":s({type:"path_completions",completions:k.completions});break;case"update_status":s({type:"update_status",status:k});break;case"update_status_all":s({type:"update_status_all",items:k.items});break;case"widgets":s({type:"widgets",widgets:k.widgets});break;case"statuses":s({type:"statuses",statuses:k.statuses});break;case"dialog":s({type:"dialog",dialog:{id:k.id,kind:k.kind,title:k.title,args:k.args}});break;case"dialog_closed":s({type:"dialog",dialog:null});break;case"question_pending":s({type:"question",question:{id:k.id,questions:k.questions}});break;case"terminal_output":r.current.write(k.conversationId??q.current.chat.activeConversationId,k.terminalId,k.data);break;case"terminal_exit":s({type:"terminal_exit",conversationId:k.conversationId,terminalId:k.terminalId,exitCode:k.exitCode});break;case"terminal_list":s({type:"terminal_list",conversationId:k.conversationId,terminals:k.terminals});break;case"commands":s({type:"commands",commands:k.commands,path:k.path});break;case"slash_commands":s({type:"slash_commands",commands:k.commands});break;case"goal_status":s({type:"goal_status",status:k.status});break;case"settings_state":s({type:"settings",settings:k.settings});break;case"bg_servers":s({type:"bg_servers",servers:k.servers});break;case"plugins":s({type:"plugins",plugins:k.plugins,epoch:k.epoch});break;case"dsh_patches":s({type:"dsh_patches",patchDir:k.patchDir,files:k.files});break;case"plugin_data":ba(k.pluginId,k.payload);break}},S.onclose=()=>{if(n.current===S&&(n.current=null),r.current.clear(),!i.current||n.current&&n.current!==S)return;s({type:"status",status:"closed"});const P=Math.min(1e3*2**c.current,1e4);c.current+=1,a.current=setTimeout(()=>{a.current=null,C()},P)},S.onerror=()=>{}},[]);l.useEffect(()=>{i.current=!0,C();const S=setInterval(()=>{if(!i.current)return;const P=n.current;P&&P.readyState===WebSocket.OPEN&&Date.now()-o.current>3e4&&P.close()},5e3);return()=>{var P;i.current=!1,clearInterval(S),a.current&&(clearTimeout(a.current),a.current=null),(P=n.current)==null||P.close(),n.current=null}},[C]),l.useEffect(()=>{var P;const S=(P=t.state)==null?void 0:P.cwd;if(S){if(!g.current){g.current=!0;const k=Ia();if(k&&k!==S){H({type:"set_cwd",path:k});return}}x.current!==S&&(x.current=S,La(S))}},[(Y=t.state)==null?void 0:Y.cwd,H]);const j=l.useCallback(S=>s({type:"dismiss_notice",id:S}),[]),J=l.useCallback(S=>s({type:"terminal_add",meta:S}),[]),Q=l.useCallback(S=>s({type:"terminal_remove",id:S}),[]),X=l.useCallback(S=>s({type:"terminal_restart",terminalId:S}),[]),U=l.useCallback(S=>s({type:"terminal_active",id:S}),[]),W=l.useCallback((S,P,k)=>r.current.register(S,P,k),[]),q=l.useRef({chat:t,send:H,pushNotice:D,dismissNotice:j,terminal:{create:J,close:Q,register:W,restart:X,select:U}});return q.current={chat:t,send:H,pushNotice:D,dismissNotice:j,terminal:{create:J,close:Q,register:W,restart:X,select:U}},q.current}const _a=200*1024*1024,Ba=/windows/i.test(navigator.userAgent),Fa=/[<>:"/\\|?*\u0000-\u001f]/g,$a=/[. ]+$/,Ha=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;function Oa(t){const s=t.replace(Fa,"_").replace($a,"");return s?Ha.test(s)?`_${s}`:s:"_"}function Vs(t,s=!0){const n=new URLSearchParams({clientId:os(),path:t,...s?{download:"1"}:{}});return Mt(Ve(`/api/file?${n}`))}const _n="FILE_NOT_FOUND";async function Ka(t,s){const n=Ba?Oa(s):s;try{const r=await fetch(Vs(t));if(!r.ok)return{ok:!1,cancelled:!1,error:await r.text().catch(()=>"")||(r.status===404?_n:`HTTP ${r.status}`)};if(Number(r.headers.get("content-length")??"0")>_a)return window.location.assign(Vs(t)),{ok:!0};const a=await r.blob();return window.showSaveFilePicker&&window.isSecureContext?Wa(a,n):es(a,n)}catch(r){return{ok:!1,cancelled:!1,error:r instanceof Error?r.message:String(r)}}}async function Wa(t,s){let n;const r=window.showSaveFilePicker;if(!r)return es(t,s);try{n=await r({suggestedName:s})}catch(c){return c instanceof DOMException&&c.name==="AbortError"?{ok:!1,cancelled:!0}:es(t,s)}try{const c=await n.createWritable();return await c.write(t),await c.close(),{ok:!0}}catch(c){return{ok:!1,cancelled:!1,error:c instanceof Error?c.message:String(c)}}}function es(t,s){const n=URL.createObjectURL(t),r=document.createElement("a");return r.href=n,r.download=s,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4),{ok:!0}}const gt="@root",Ua=l.memo(function({files:s,fileChanged:n,widgets:r,cwd:c,send:a,onAttach:i,onPreview:o,onNotice:u,collapsible:m,onToggleCollapse:y}){const g=be(),[x,b]=l.useState(""),[T,D]=l.useState(null),[H,C]=l.useState(!1),[j,J]=l.useState(null),Q=l.useRef(""),X=l.useRef(null),U=l.useCallback((d,E)=>{d.preventDefault(),Q.current=E,J({x:Math.min(d.clientX,window.innerWidth-220),y:Math.min(d.clientY,window.innerHeight-90)})},[]),W=l.useCallback(()=>J(null),[]);l.useEffect(()=>{if(!j)return;const d=_=>{var te;(te=_.target)!=null&&te.closest(".ctx-menu")||W()},E=_=>{_.key==="Escape"&&W()};window.addEventListener("mousedown",d,!0),window.addEventListener("keydown",E);const h=()=>W();return window.addEventListener("blur",h),()=>{window.removeEventListener("mousedown",d,!0),window.removeEventListener("keydown",E),window.removeEventListener("blur",h)}},[j,W]);const q=l.useCallback(()=>{var d;W(),X.current&&(X.current.value=""),(d=X.current)==null||d.click()},[W]),Y=l.useCallback((d,E)=>{for(const h of E){const _=new FileReader;_.onload=()=>{const te=_.result,O=te.slice(te.indexOf(",")+1);O&&a({type:"upload_file",dirPath:d,name:h.name,data:O})},_.readAsDataURL(h)}},[a]),S=l.useCallback(d=>{Y(Q.current,Array.from(d.target.files??[]))},[Y]),P=l.useRef(null),k=d=>{var E;return Array.from(((E=d.dataTransfer)==null?void 0:E.types)??[]).includes("Files")},B=l.useCallback(()=>{var d,E;(d=P.current)==null||d.querySelectorAll(".file-item.drop-target").forEach(h=>h.classList.remove("drop-target")),(E=P.current)==null||E.classList.remove("drop-root")},[]),Z=l.useCallback(d=>{var h,_;if(B(),d==null)return;const E=(h=P.current)==null?void 0:h.querySelector(`.file-item[data-path="${CSS.escape(d)}"]`);E?E.classList.add("drop-target"):(_=P.current)==null||_.classList.add("drop-root")},[B]),G=d=>{const E=d instanceof Element?d.closest(".file-item"):null;return(E==null?void 0:E.dataset.type)==="dir"?E.dataset.path??x:x},M=l.useCallback(()=>{const d=document.querySelector(".app");d&&d.dispatchEvent(new DragEvent("dragleave",{bubbles:!0}))},[]),I=1e4,N=l.useRef(0),$=l.useRef(void 0),z=l.useCallback((d,E)=>{const h=++N.current;b(d),E!=null&&E.silent||C(!0),a({type:"list_files",path:d===""?void 0:d})||N.current===h&&C(!1)},[a]);l.useEffect(()=>{s&&s.path===x&&C(!1)},[s,x]),l.useEffect(()=>{if(c!==$.current){$.current=c,z("",{silent:!0});return}const d=setInterval(()=>{document.visibilityState!=="hidden"&&z(x,{silent:!0})},I);return()=>clearInterval(d)},[c,x,z]),l.useEffect(()=>{n&&n.path===x&&z(x,{silent:!0})},[n,x,z]);const ie=d=>z(d),v=()=>{(s==null?void 0:s.parent)!==null&&(s==null?void 0:s.parent)!==void 0&&z(s.parent)},L=(()=>{if(x===""||x===gt)return[];const d=x.split("/").filter(E=>!!E&&E!==gt);return x.startsWith("/")?d.map((E,h)=>({label:h===0?"/":d[h],path:"/"+d.slice(0,h+1).join("/")})):d.map((E,h)=>({label:d[h],path:d.slice(0,h+1).join("/")}))})();return e.jsxs("aside",{className:"panel panel-right",children:[m&&y&&e.jsx("button",{type:"button",className:"panel-collapse-btn",title:g("collapsePanel"),onClick:y,children:e.jsx(wn,{})}),e.jsxs("div",{className:"panel-crumbs",children:[e.jsx("button",{type:"button",className:`crumb ${x===""?"active":""}`,onClick:()=>z(""),children:g("rootDir")}),e.jsx("button",{type:"button",className:`crumb ${x===gt?"active":""}`,title:g("computer"),onClick:()=>z(gt),children:"💻"}),L.map(d=>e.jsxs("span",{className:"crumb-seg",children:[e.jsx(Pt,{}),e.jsx("button",{type:"button",className:`crumb ${d.path===x?"active":""}`,onClick:()=>z(d.path),children:d.label})]},d.path))]}),e.jsxs("div",{ref:P,className:"panel-body",onContextMenu:d=>U(d,x),onDragOver:d=>{k(d)&&(d.preventDefault(),d.stopPropagation(),d.dataTransfer.dropEffect="copy",M(),Z(G(d.target)))},onDragLeave:d=>{d.relatedTarget&&d.currentTarget.contains(d.relatedTarget)||B()},onDrop:d=>{var h;if(B(),!k(d))return;d.preventDefault(),d.stopPropagation(),M();const E=Array.from(((h=d.dataTransfer)==null?void 0:h.files)??[]);if(E.length===0){u("warning",g("foldersNotSupported"));return}Y(G(d.target),E)},onDragEnd:B,children:[e.jsx("input",{ref:X,type:"file",multiple:!0,hidden:!0,onChange:S}),H&&e.jsx("div",{className:"panel-empty",children:g("loading")}),!H&&s&&s.path===x&&e.jsxs(e.Fragment,{children:[s.parent!=null&&e.jsxs("button",{type:"button",className:"file-item dir",onClick:v,children:[e.jsx(Je,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:".."})]}),s.entries.map(d=>d.type==="dir"?e.jsxs("div",{className:"file-item dir","data-type":"dir","data-path":d.path,onContextMenu:E=>{E.stopPropagation(),U(E,d.path)},children:[e.jsxs("button",{type:"button",className:"file-dir-main",onClick:()=>ie(d.path),children:[e.jsx(Je,{className:"file-icon"}),e.jsx("span",{className:"file-name",children:d.name})]}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":g("linkFolderTip"),onClick:()=>i(d.path,d.name,"reference",!0),children:e.jsx(Gt,{})})]},d.path):e.jsxs("div",{className:"file-item file","data-type":"file","data-path":d.path,onContextMenu:E=>{E.stopPropagation(),U(E,x)},children:[e.jsxs("button",{type:"button",className:"file-name",title:`${d.path} — ${g("previewFile")}`,onClick:()=>o(d.path,d.name),children:[e.jsx(Vi,{className:"file-icon"}),e.jsx("span",{className:"file-name-text",children:d.name})]}),e.jsx("button",{type:"button",className:"file-attach download","data-tip":g("downloadFile"),onClick:()=>{Ka(d.path,d.name).then(E=>{E.ok||E.cancelled||u("error",g("downloadFailed",{error:E.error===_n?g("fileNotFoundShort"):E.error}))})},children:e.jsx(ls,{})}),e.jsx("button",{type:"button",className:"file-attach inline","data-tip":g("attachInlineTip"),onClick:()=>i(d.path,d.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"file-attach ref","data-tip":g("referenceTip"),onClick:()=>i(d.path,d.name,"reference"),children:e.jsx(Gt,{})})]},d.path)),s.truncated&&e.jsx("div",{className:"panel-empty files-truncated",children:g("filesTruncated")})]}),!H&&!s&&e.jsx("div",{className:"panel-empty",children:g("noFiles")})]}),r.filter(d=>d.lines.length>0).length>0&&e.jsx("div",{className:"panel-widgets",children:r.filter(d=>d.lines.length>0).map(d=>e.jsxs("div",{className:"widget",children:[e.jsxs("button",{type:"button",className:"widget-title widget-title-btn",title:g("widgetExpand"),onClick:()=>D(d.key),children:[e.jsx("span",{children:d.key}),e.jsx(Oi,{})]}),e.jsx("pre",{className:"widget-lines",children:d.lines.join(`
306
+ `)})]},d.key))}),T&&(()=>{const d=r.find(E=>E.key===T);return d?e.jsx("div",{className:"modal-backdrop",onClick:()=>D(null),children:e.jsxs("div",{className:"widget-expand",onClick:E=>E.stopPropagation(),children:[e.jsxs("div",{className:"widget-expand-head",children:[e.jsx("span",{className:"widget-expand-title",children:d.key}),e.jsx("button",{type:"button",className:"btn",title:g("close"),onClick:()=>D(null),children:e.jsx(Pe,{})})]}),e.jsx("pre",{className:"widget-expand-lines",children:d.lines.join(`
307
+ `)})]})}):null})(),j&&e.jsx("div",{className:"ctx-menu",style:{left:j.x,top:j.y},onContextMenu:d=>{d.preventDefault(),d.stopPropagation()},children:e.jsxs("button",{type:"button",className:"ctx-item",onClick:q,children:[e.jsx(Ri,{}),Q.current===x?g("uploadToCurrentDir"):g("uploadToFolder")]})})]})});var qa=hn();const Tt=l.memo(function({text:s}){const n=be(),[r,c]=l.useState(!1);return s?e.jsx("button",{type:"button",className:"copy-btn",title:n("copy"),onClick:()=>{navigator.clipboard.writeText(s).then(()=>{c(!0),setTimeout(()=>c(!1),1200)})},children:r?e.jsx(pt,{}):e.jsx(jn,{})}):null});function za(t){const s=r=>{var c;if(typeof r=="string"||typeof r=="number"){const a=String(r);return a===""?[[]]:a.split(`
308
+ `).map(i=>i===""?[]:[i])}if(Array.isArray(r)){let a=[];for(const i of r){const o=s(i);if(a.length===0)a=o;else{const u=o[0]??[];a[a.length-1].push(...u),a.push(...o.slice(1))}}return a}if(r&&typeof r=="object"&&"props"in r){const a=r,i=(c=a.props)==null?void 0:c.children,o={...a.props,children:void 0},u=i==null?[]:s(i);return u.length===0?[[l.createElement(a.type,o)]]:u.map(m=>[l.createElement(a.type,o,...m)])}return[[r]]},n=s(t);return n.length>1&&n[n.length-1].length===0&&n.pop(),n}function Va(t){return typeof t=="string"&&/(^|\s)language-mermaid(\s|$)/.test(t)}function ts(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ts).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return ts(s==null?void 0:s.children)}return""}function Ga(t){const s=Array.isArray(t)?t[0]:t;return!s||typeof s!="object"||!("props"in s)?null:s}function Qa(t){var y,g;const s=t.match(/<svg\b([^>]*)>/i);if(!s)return t;const n=s[1],r=(y=n.match(/\bviewBox=(['"])([^'"]+)\1/i))==null?void 0:y[2];if(!r)return t;const c=r.trim().split(/[\s,]+/).map(Number),a=c.length===4?c[2]:Number.NaN;if(!Number.isFinite(a)||a<=0)return t;const o=(((g=n.match(/\sstyle=(['"])(.*?)\1/i))==null?void 0:g[2])??"").replace(/(?:^|;)\s*(?:max-)?width\s*:[^;]*/gi,"").replace(/^\s*;|;\s*$/g,""),u=n.replace(/\swidth=(['"])[^'"]*\1/i,"").replace(/\sstyle=(['"])(.*?)\1/i,""),m=o?`${o}; max-width:none`:"max-width:none";return t.replace(s[0],`<svg${u} width="${a}" style="${m}">`)}function Bn(t){var n;const s=Ga(t);return s!==null&&Va((n=s.props)==null?void 0:n.className)}let Ht=null;function Ya(){return Ht||(Ht=gn(()=>import("./mermaid.core-Bxpg8jiH.js").then(t=>t.cb),__vite__mapDeps([0,1])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:{background:"#ffffff",primaryColor:"#f1edfe",primaryTextColor:"#1f2430",primaryBorderColor:"#8b5cf6",lineColor:"#6b7280",secondaryColor:"#eef2ff",tertiaryColor:"#f8fafc",textColor:"#1f2430",fontFamily:"var(--mono, monospace)"}}),s})),Ht}let Ja=0;function Xa({code:t}){const s=be(),n=l.useId().replace(/[^a-zA-Z0-9]/g,""),[r,c]=l.useState(null),[a,i]=l.useState(null);return l.useEffect(()=>{let o=!1;c(null),i(null);const u=`mermaid-${n}-${++Ja}`,m=document.createElement("div");m.style.position="absolute",m.style.left="-99999px",m.style.width="1000px",m.dataset.mermaidRender=u,document.body.appendChild(m);const y=()=>{var g;return(g=document.querySelector(`[data-mermaid-render="${u}"]`))==null?void 0:g.remove()};return Ya().then(g=>g.render(u,t,m)).then(({svg:g})=>{y(),o||c(Qa(g))}).catch(g=>{y(),!o&&i(g instanceof Error?g.message:String(g))}),()=>{o=!0,y()}},[t,n]),a?e.jsxs("div",{className:"mermaid-block mermaid-block-error",children:[e.jsx("div",{className:"mermaid-note",children:s("mermaidRenderFailed")}),e.jsxs("div",{className:"codeblock",children:[e.jsx(Tt,{text:t}),e.jsx("pre",{children:e.jsx("code",{children:t})})]})]}):r?e.jsxs("div",{className:"mermaid-block",children:[e.jsx(Tt,{text:t}),e.jsx("div",{className:"mermaid-svg",dangerouslySetInnerHTML:{__html:r}})]}):e.jsx("div",{className:"mermaid-block mermaid-block-loading",children:e.jsx("div",{className:"mermaid-note",children:s("mermaidRendering")})})}function Za(t){return Bn(t)?ts(t):null}const Fn="pi-web-ui:mermaid-render",Et={enabled:!0};function $n(t){if(!t||typeof t!="object")return{...Et};const s=t;return{enabled:typeof s.enabled=="boolean"?s.enabled:Et.enabled}}function er(){try{const t=localStorage.getItem(Fn);return t?$n(JSON.parse(t)):{...Et}}catch{return{...Et}}}function tr(t){const s=$n(t);try{localStorage.setItem(Fn,JSON.stringify(s))}catch{}vt=s;for(const n of ss)n()}let vt=null;const ss=new Set;function sr(t){return ss.add(t),()=>{ss.delete(t)}}function nr(){return vt||(vt=er()),vt.enabled}function Hn(){return l.useSyncExternalStore(sr,nr)}const ir=[xi],ar=[[fi,{detect:!0,ignoreMissing:!0}]];function cs({text:t}){return e.jsx(gi,{remarkPlugins:ir,rehypePlugins:ar,components:{pre:rr},children:t})}const Rt=l.memo(function({text:s}){return e.jsx("div",{className:"md",children:e.jsx(cs,{text:s})})});function rr({children:t,...s}){var o;if(Hn()&&Bn(t))return e.jsx(Xa,{code:Za(t)});const r=t&&typeof t=="object"&&"props"in t?(o=t.props)==null?void 0:o.children:t,c=za(r),a=c.length>1,i=a?`${String(c.length).length+1}ch`:void 0;return e.jsxs("div",{className:"codeblock",children:[e.jsx(Tt,{text:ns(t)}),e.jsx("pre",{...s,children:c.map((u,m)=>e.jsxs("div",{className:"code-line",children:[a&&e.jsx("span",{className:"code-num",style:i?{width:i}:void 0,children:m+1}),e.jsx("code",{className:"code-line-body hljs",children:u})]},m))})]})}function ns(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ns).join("");if(t&&typeof t=="object"&&"props"in t){const s=t.props;return ns(s==null?void 0:s.children)}return""}const lr=/^\s{0,3}(`{3,}|~{3,})/,or=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function Ot(t){return t.trim()===""}function Gs(t){const s=lr.exec(t);return s?s[1]:null}function cr(t){const s=t.split(`
309
+ `),n=[];let r=[],c=null;for(let a=0;a<s.length;a++){const i=s[a];if(c!==null){const u=Gs(i);u&&u[0]===c[0]&&u.length>=c.length&&(c=null),r.push(i);continue}const o=Gs(i);if(o&&!Ot(i)){c=o,r.push(i);continue}if(Ot(i)){let u=a;for(;u<s.length&&Ot(s[u]);)u++;if(!(u<s.length&&or.test(s[u]))&&r.length>0){n.push(r.join(`
310
+ `)),r=[];continue}r.push(i);continue}r.push(i)}return{frozen:n,active:r.join(`
311
+ `),inFence:c!==null}}const dr=l.memo(function({text:s}){return e.jsx(cs,{text:s})}),Qs=200;function ur({text:t,inFence:s}){const[n,r]=l.useState(t),c=l.useRef(0),a=l.useRef(null);return l.useEffect(()=>{if(s)return;const i=Date.now()-c.current,o=()=>{c.current=Date.now(),r(t)};if(i>=Qs){o();return}return a.current=setTimeout(o,Qs-i),()=>{a.current&&clearTimeout(a.current)}},[t,s]),s?e.jsx("div",{className:"codeblock",children:e.jsx("pre",{children:e.jsx("code",{children:t})})}):e.jsx(cs,{text:n})}const pr=l.memo(function({text:s}){const{frozen:n,active:r,inFence:c}=l.useMemo(()=>cr(s),[s]);return e.jsxs("div",{className:"md",children:[n.map((a,i)=>e.jsx(dr,{text:a},i)),r.length>0&&e.jsx(ur,{text:r,inFence:c},n.length)]})});function mr({thinking:t,streaming:s,wrap:n=!0,forceOpen:r=!1}){const c=be(),[a,i]=l.useState(null),o=a??n,u=o||r,m=s?t.trimEnd().slice(-80):t.split(`
312
+ `)[0].slice(0,80);return e.jsxs("div",{className:`thinking ${u?"open":""} ${s?"live":""}`,children:[e.jsxs("button",{type:"button",className:"thinking-toggle",onClick:()=>i(!o),children:[u?e.jsx(Ge,{}):e.jsx(Pt,{}),e.jsx(lt,{className:"thinking-icon"}),e.jsx("span",{className:"thinking-label",children:s&&u?e.jsxs("span",{className:"thinking-live-label",children:[c("thinkingNow"),e.jsx("span",{className:"dots"})]}):u?c("thinking"):c("thinkingPreview",{preview:m})})]}),u&&e.jsx("div",{className:"thinking-body",children:t})]})}const hr={bash:"$",read:"📄",write:"✍️",edit:"✏️",grep:"🔍",find:"🧭",ls:"📂"};function gr(t){return hr[t]??"🛠"}const fr=l.memo(function({block:s,view:n,onKillBash:r,wrap:c=!0,forceOpen:a=!1}){var q,Y,S,P;const i=be(),[o,u]=l.useState(c),m=o||a,[y,g]=l.useState(!1),x=!n.result&&n.streaming&&!n.status,b=s.name==="bash"&&x,T=n.result!==void 0,D=!n.result&&!!n.status,H=((q=n.result)==null?void 0:q.isError)??((Y=n.status)==null?void 0:Y.isError)??!1,j=(n.result?n.result.content.map(k=>k.type==="text"?k.text:"").join(""):n.liveOutput??"").replace(/…\[LIVE_OMIT:(\d+)\]…\n/,(k,B)=>i("liveOutputOmitted",{n:B})),J=H?"err":T?"ok":x||D?"run":"idle";let Q=i(H?"error":T?"done":x?"running":D?"toolDoneWaitingModel":"toolQueued");const X=D&&((S=n.status)==null?void 0:S.durationMs)!==void 0?yr(n.status.durationMs):"";D&&X&&(Q=`${Q} · ${X}`);const U=D&&((P=n.status)==null?void 0:P.exitCode)!==void 0?`exit ${n.status.exitCode}`:"",W=()=>{s.argumentsText&&(navigator.clipboard.writeText(s.argumentsText),g(!0),setTimeout(()=>g(!1),1200))};return e.jsxs("div",{className:`toolcall ${J}`,children:[e.jsxs("div",{className:"toolcall-head",children:[e.jsx("span",{className:"toolcall-icon",children:gr(s.name)}),e.jsx("span",{className:"toolcall-name",children:s.name}),e.jsxs("span",{className:"toolcall-status",children:[Q,U&&e.jsx("em",{className:"toolcall-exit",children:U})]}),e.jsx("span",{className:"toolcall-spacer"}),b&&r&&e.jsxs("button",{type:"button",className:"toolcall-kill",title:i("stopBashTip"),onClick:r,children:[e.jsx(jt,{}),e.jsx("span",{children:i("stopBash")})]}),e.jsx("button",{type:"button",className:"toolcall-copy",title:i("copyArgs"),onClick:W,children:y?e.jsx(Yi,{}):e.jsx(jn,{})}),e.jsx("button",{type:"button",className:"toolcall-toggle",onClick:()=>u(k=>a?!0:!k),children:m?e.jsx(Ge,{}):e.jsx(Pt,{})})]}),m&&e.jsxs("div",{className:"toolcall-body",children:[s.argumentsText&&e.jsx("div",{className:"toolcall-args",children:s.name==="bash"&&s.argumentsText.startsWith("{")?e.jsx(xr,{args:s.argumentsText}):e.jsx("pre",{children:s.argumentsText})}),j.length>0&&e.jsxs("div",{className:"toolcall-output",children:[e.jsxs("div",{className:"toolcall-output-label",children:[i(H?"errorOutput":"output"),(x||D)&&e.jsx("span",{className:"cursor"})]}),e.jsx("pre",{children:j})]}),x&&j.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",i("waitingOutput")]}),D&&j.length===0&&e.jsxs("div",{className:"toolcall-waiting",children:[e.jsx("span",{className:"cursor"})," ",i("waitingModel")]})]})]})});function xr({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(tt,{className:"termline-icon"}),e.jsx("code",{children:s.command}),typeof s.timeout=="number"&&e.jsxs("span",{className:"termline-timeout",children:["⏱ ",s.timeout,"s"]})]})}function yr(t){if(t===void 0)return"";const s=t/1e3;if(s<60)return`${s.toFixed(1)}s`;const n=Math.floor(s/60),r=Math.round(s%60);return`${n}m ${String(r).padStart(2,"0")}s`}const vr=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;function ds(t){var n;const s=t.match(vr);return s?{name:s[1],location:s[2],content:s[3],userMessage:((n=s[4])==null?void 0:n.trim())||void 0}:null}const br=1568,kr=2*1024*1024;function We(t){return t.startsWith("image/")&&t!=="image/svg+xml"&&t!=="image/svg"}async function On(t){if(!t.type.startsWith("image/"))return null;let s;try{s=await createImageBitmap(t,{imageOrientation:"from-image"})}catch{return null}try{const n=Math.min(1,br/Math.max(s.width,s.height)),r=Math.max(1,Math.round(s.width*n)),c=Math.max(1,Math.round(s.height*n)),a=t.type==="image/jpeg"||t.type==="image/jpg"?[["image/jpeg",.85],["image/jpeg",.6],["image/webp",.8]]:[["image/png",1],["image/jpeg",.85],["image/jpeg",.6]];let i=null;for(const[o,u]of a){const m=document.createElement("canvas");m.width=r,m.height=c;const y=m.getContext("2d");if(!y)continue;o!=="image/png"&&(y.fillStyle="#ffffff",y.fillRect(0,0,r,c)),y.drawImage(s,0,0,r,c);const g=m.toDataURL(o,u),x=g.match(/^data:([^;]+);base64,/),b=x?x[1]:o,T=g.replace(/^data:[^;]*;base64,/,""),D=Math.floor(T.length*3/4);if(i={data:T,mimeType:b,name:t.name,size:D},D<=kr)return i}return i}finally{s.close()}}const jr=20*1024*1024;function ct(t){return t.type==="text"&&typeof t.text=="string"?t:null}function Kn(t){return t.type==="thinking"&&typeof t.thinking=="string"?t:null}function Wn(t){return t.type==="toolCall"&&typeof t.id=="string"&&typeof t.name=="string"?t:null}function Un(t){return t.type==="image"&&typeof t.dataUrl=="string"?t:null}function qn(t){return t.type==="bash"&&typeof t.command=="string"?t:null}function wr(t){return t.imageData?"image":t.uploadPath?"upload":t.fileData?"file":"path"}function Nr(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 n=t.path.split("/").pop()??t.path;return t.mode==="lines"&&t.lines?s("attachLines",{path:n,start:t.lines.start,end:t.lines.end}):t.mode==="reference"?s("refOnly",{path:n}):s("attachContent",{path:n})}const Ys=l.memo(function({message:s,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:a,isLast:i,onEdit:o,onKillBash:u,onCollapse:m,questionAttachments:y,qnIndex:g,qnActive:x,onJump:b,thinkingWrap:T,toolsWrap:D,searchActive:H}){const C=be(),[j,J]=l.useState(!1),[Q,X]=l.useState(""),[U,W]=l.useState([]),[q,Y]=l.useState(!1),[S,P]=l.useState(null),k=h=>{P(h),window.setTimeout(()=>P(_=>_===h?null:_),4e3)};if(s.role==="toolResult")return null;const B=s.role==="custom"&&s.customType==="file",Z=s.content.map(h=>{var _;return((_=ct(h))==null?void 0:_.text)??""}).filter(Boolean).join(`
313
313
  `),G=s.role==="user"?ds(Z):null,M=G?G.userMessage??`skill:${G.name}`:Z.split(`
314
- `).join(" ").trim(),I=i&&a&&s.content.length===0,C=s.role==="user"&&!i&&!I&&!!o,$=async h=>{const L=[];for(const ee of h){if(!We(ee.type))continue;const W=await On(ee);W&&L.push({path:"",imageData:W.data,mimeType:W.mimeType,name:W.name})}L.length>0&&K(ee=>[...ee,...L])},z=async h=>{if(h.size>jr){k(S("fileTooLarge",{name:h.name,size:20}));return}let L;try{L=(await new Promise((W,ae)=>{const ye=new FileReader;ye.onload=()=>W(ye.result),ye.onerror=()=>ae(ye.error??new Error("read failed")),ye.readAsDataURL(h)})).replace(/^data:[^;]*;base64,/,"")}catch{k(S("fileLoadFailed",{name:h.name}));return}K(ee=>[...ee,{path:"",fileData:L,name:h.name,size:h.size,mimeType:h.type||void 0}])},ne=async h=>{const L=[];for(const ee of h)We(ee.type)?L.push(ee):z(ee);L.length>0&&await $(L)},v=()=>{X(G?`/skill:${G.name}${G.userMessage?` ${G.userMessage}`:""}`:s.content.map(h=>{var L;return((L=ct(h))==null?void 0:L.text)??""}).filter(Boolean).join(`
315
- `)),K(y??[]),J(!0)},D=()=>{const h=Q.trim();h&&(o==null||o(s.id,h,U.length>0?U:void 0),J(!1))},d=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),w=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${d?" msg-goal-review":""}`,"data-role":s.role,"data-msg-id":s.id,children:[e.jsxs("div",{className:"msg-meta",children:[e.jsx("span",{className:"msg-role",children:s.role==="custom"?w?S("goalWizardCard"):d?S("goalBarTitle"):s.customType==="file"?S("attachment"):`${S("plugin")} · ${s.customType??S("unknown")}`:zn(s.role,S)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:Er(s.timestamp)}),m&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:S("collapseMsg"),onClick:()=>m(s.id),children:[e.jsx(ut,{})," ",S("collapseMsg")]}),g!==void 0&&b&&e.jsxs("button",{type:"button",className:`qn-tag ${x?"active":""}`,title:`${g+1}. ${M}`,"aria-label":`${g+1}. ${M}`,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:j?e.jsxs("div",{className:`msg-editor${q?" drag-over":""}`,onDragOver:h=>{h.preventDefault(),h.stopPropagation(),Y(!0)},onDragLeave:h=>{h.currentTarget.contains(h.relatedTarget)||Y(!1)},onDrop:h=>{var L;h.preventDefault(),h.stopPropagation(),Y(!1),ne(Array.from(((L=h.dataTransfer)==null?void 0:L.files)??[]))},children:[U.length>0&&e.jsx("div",{className:"msg-editor-images",children:U.map((h,L)=>{var W;const ee=wr(h);return e.jsxs("span",{className:`msg-editor-img ${ee==="image"?"":"file-chip"}`,title:Nr(h,S),children:[ee==="image"?e.jsx("img",{src:`data:${h.mimeType??"image/png"};base64,${h.imageData}`,alt:h.name}):e.jsxs("span",{className:"msg-editor-file",children:[e.jsx("span",{className:"msg-editor-file-icon",children:ee==="path"?h.mode==="reference"?"🔗":"📎":"📄"}),e.jsx("span",{className:"msg-editor-file-name",children:h.name??((W=h.path)==null?void 0:W.split("/").pop())})]}),e.jsx("button",{type:"button",className:"msg-editor-img-remove",title:S("removeAttachment"),onClick:()=>K(ae=>ae.filter((ye,be)=>be!==L)),children:e.jsx(Pe,{})})]},`${h.name??h.path??"att"}-${L}`)})}),T&&e.jsx("div",{className:"msg-editor-notice",children:T}),e.jsx("textarea",{className:"msg-editor-input",value:Q,autoFocus:!0,placeholder:S("editPlaceholder"),rows:Math.max(2,Math.min(10,Q.split(`
316
- `).length+1)),onChange:h=>X(h.target.value),onPaste:h=>{var ee;const L=[];for(const W of((ee=h.clipboardData)==null?void 0:ee.items)??[])if(W.kind==="file"&&We(W.type)){const ae=W.getAsFile();ae&&L.push(ae)}L.length!==0&&(h.preventDefault(),$(L))},onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)?(h.preventDefault(),D()):h.key==="Escape"&&J(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsxs("span",{className:"msg-editor-hint",children:[e.jsx(Ui,{})," ",S("editAttachmentHint")]}),e.jsx("button",{type:"button",className:"chip",onClick:()=>J(!1),children:S("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!Q.trim(),title:S("reaskFromHere"),onClick:D,children:[e.jsx(Yt,{})," ",S("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),B?e.jsx(Cr,{message:s,forceOpen:H}):G?e.jsxs(e.Fragment,{children:[e.jsx(Tr,{block:G,forceOpen:H}),G.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(Rt,{text:G.userMessage})}),s.content.map((h,L)=>h.type==="text"?null:e.jsx(Xs,{block:h,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:i,isLast:a,onKillBash:u,toolsWrap:A,thinkingWrap:E,searchActive:H},`${s.id}-${L}`))]}):s.content.map((h,L)=>e.jsx(Xs,{block:h,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:i,isLast:a,onKillBash:u,toolsWrap:A,thinkingWrap:E,searchActive:H},`${s.id}-${L}`)),I&&e.jsxs("div",{className:"thinking-wait",children:[S("thinkingWait"),e.jsx("span",{className:"dot"})]}),i&&a&&!I&&e.jsx("span",{className:"stream-cursor"})]})}),C&&!j&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:S("editReaskTip"),onClick:v,children:[e.jsx(Yt,{})," ",S("editReask")]})})]})});function Cr({message:t,forceOpen:s=!1}){const n=xe(),[r,c]=l.useState(!1),i=r||s,a=t.details??{},o=a.name??a.path??n("attachment"),u=a.type==="folder",m=a.mode==="reference",y=a.mode==="bridged",g=t.content.filter(A=>A.type==="text").map(A=>A.text).join(`
317
- `),x=Sr(g),b=t.content.find(A=>A.type==="image"),E=x.split(`
318
- `).length;return e.jsxs("div",{className:`attachcard ${m?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>c(A=>s?!0:!A),children:[e.jsx("span",{className:"attachcard-icon",children:u?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:o}),a.path&&e.jsx("span",{className:"attachcard-path",children:a.path}),e.jsx("span",{className:`attachcard-mode ${a.mode==="lines"?"lines":m?"ref":y?"bridged":"inline"}`,children:m?u?n("folderRefShort"):`${n("refOnlyShort")} · ${Js(a.size)}`:y?n("bridgedVision"):b?n("image"):a.mode==="lines"?n("inlineLinesRange",{start:a.startLine??1,end:a.endLine??a.lines??1}):n("inlineLines",{n:a.lines??E})}),!m&&(i?e.jsx(Ge,{}):e.jsx(Pt,{}))]}),!m&&i&&(y?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"attachcard-bridgenote",children:n("bridgedVisionDetail")}),(b==null?void 0:b.dataUrl)&&e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:b.dataUrl,alt:o})}),x&&e.jsx("pre",{className:"attachcard-content",children:x})]}):b!=null&&b.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:b.dataUrl,alt:o})}):e.jsx("pre",{className:"attachcard-content",children:x})),m&&e.jsx("div",{className:"attachcard-refnote",children:u?n("folderNotExpanded"):n("fileNotExpanded",{size:Js(a.size)})})]})}function Js(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function Sr(t){const s=t.match(/^\s*<file path="[^"]*"(?:\s+lines="[^"]*")?>\s*```\s*\n?([\s\S]*?)\n?```\s*<\/file>\s*$/);if(s)return s[1].trim();const n=t.match(/^\s*<vision-bridge>\s*([\s\S]*?)\s*<\/vision-bridge>\s*$/);return n?n[1].trim():t.trim()}function Tr({block:t,forceOpen:s=!1}){const n=xe(),[r,c]=l.useState(!1),i=r||s;return e.jsxs("div",{className:`skillcard${r?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>c(a=>s?!0:!a),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(Ji,{})}),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:[i?e.jsx(ut,{}):e.jsx(Ge,{}),n(i?"collapseMsg":"expandMsg")]})]}),i&&e.jsx("div",{className:"skillcard-body",children:e.jsx(Rt,{text:t.content})})]})}function Xs({block:t,toolResults:s,liveOutputs:n,toolStatuses:r,streaming:c,isLast:i,onKillBash:a,thinkingWrap:o,toolsWrap:u,searchActive:m}){const y=xe(),g=ct(t);if(g){const H=c&&i;return e.jsxs("div",{className:"msg-text",children:[H?e.jsx(pr,{text:g.text}):e.jsx(Rt,{text:g.text}),g.truncated&&e.jsx("div",{className:"trunc-note",children:y("truncated")})]})}const x=Kn(t);if(x)return e.jsx(mr,{thinking:x.thinking,streaming:c&&i,wrap:o,forceOpen:m});const b=Wn(t);if(b){const H=s.get(b.id),S=n.get(b.id),j={result:H,liveOutput:S==null?void 0:S.text,streaming:c,status:r.get(b.id)};return e.jsx(fr,{block:b,view:j,onKillBash:a,wrap:u,forceOpen:m})}const E=Un(t);if(E&&E.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:E.dataUrl,alt:"attachment"})});const A=qn(t);return A?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:A.command}),A.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${A.exitCode===0?"ok":"err"}`,children:y("exitCode",{code:A.exitCode})}),A.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:y("cancelled")})]}),A.output&&e.jsx("pre",{className:"bashblock-output",children:A.output}),A.truncated&&e.jsx("div",{className:"trunc-note",children:y("outputTruncated")})]}):null}function zn(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 Er(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}function Zs(t,s,n){let r=!1;for(const c of s){const i=c;if(i.type!=="image"||typeof i.dataUrl!="string"||!i.dataUrl.startsWith("data:"))continue;const a=i.dataUrl.match(/^data:([^;]*);base64,(.+)$/);a&&(r=!0,t.push({path:"",imageData:a[2],mimeType:a[1]||"image/png",name:n??`image.${(a[1]||"image/png").split("/")[1]??"png"}`}))}return r}function Pr(t){const s=new Map;for(let n=0;n<t.length;n++){const r=t[n];if(r.role!=="user"||!r.id)continue;const c=[];Zs(c,r.content);for(let i=n+1;i<t.length&&t[i].role==="custom"&&t[i].customType==="file";i++){const a=t[i].details??{};if(!Zs(c,t[i].content,a.name)){if(a.upload&&a.path){c.push({path:"",uploadPath:a.path,name:a.name??a.path,size:a.size});continue}if(a.path&&a.mode){const o=a.mode==="inline"||a.mode==="lines"?a.mode:"reference",u={path:a.path,mode:o};a.mode==="lines"&&typeof a.startLine=="number"&&typeof a.endLine=="number"&&(u.lines={start:a.startLine,end:a.endLine}),c.push(u)}}}c.length>0&&s.set(r.id,c)}return s}const Mr=l.memo(function({message:s,onExpand:n}){const r=xe();let c="";for(const g of s.content){const x=ct(g);if(x&&x.text.trim()){const b=ds(x.text);b?c=`skill:${b.name}`+(b.userMessage?` · ${b.userMessage.replace(/\s+/g," ").trim()}`:""):c=x.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 a=0,o=0,u=0,m=0;for(const g of s.content)Kn(g)?a++:Wn(g)?o++:qn(g)?u++:Un(g)&&m++;const y=[];return a&&y.push(`${r("thinking")} ${a}`),o&&y.push(`${r("toolCalls")} ${o}`),u&&y.push(`${r("bashRuns")} ${u}`),m&&y.push(`${r("images")} ${m}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${r("expandMsg")} · ${c||y.join(" · ")||s.role}`,onClick:()=>n(s.id),children:[e.jsx("span",{className:`msg-collapsed-role role-${s.role}`,children:s.role==="custom"&&s.customType==="file"?r("attachment"):zn(s.role,r)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),y.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:y.map((g,x)=>e.jsx("span",{className:"msg-collapsed-chip",children:g},x))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:Rr(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(Ge,{})," ",r("expandMsg")]})]})});function Rr(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}const Ir=l.memo(function({id:s,show:n,height:r,containerRef:c,onMeasured:i,lazyRef:a,children:o}){const u=l.useRef(null),m=l.useRef(null);return l.useLayoutEffect(()=>{const y=m.current;if(m.current=n,!n||y!==!1)return;const g=u.current,x=c.current;if(!g||!x)return;const b=g.offsetHeight;i==null||i(s,b);const E=b-r;if(E!==0){const A=g.parentElement;A&&A.getBoundingClientRect().bottom<=x.getBoundingClientRect().top&&(x.scrollTop+=E)}},[n]),n?e.jsx("div",{ref:a,"data-lazy-id":s,children:e.jsx("div",{ref:u,children:o})}):e.jsx("div",{ref:a,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:r},"aria-hidden":"true"})});function Lr(t,s,n,r){const c=[],i=[];let a=0;for(const o of t){if(n.has(o.id))continue;o.top<s.bottom&&o.bottom>s.top?r.has(o.id)&&c.push(o.id):r.has(o.id)||(i.push(o.id),o.bottom<=s.top&&(a+=o.bottom-o.top))}return{show:c,hide:i,shrinkAbove:a}}function Dr(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const r of s.show)n.delete(r);for(const r of s.hide)n.add(r);return n}function Ar(t,s,n){const r=new Set;let c=0;for(let i=t.length-1;i>=0&&!(i<t.length-1&&c>=n);i--){const a=t[i];r.add(a.id),c+=s.get(a.id)??Vn(a.role,a.customType)}return r}function Vn(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 _r=["text","thinking","argumentsText","output","command"];function Br(t){let s=0;for(const n of t.content){n.type==="image"&&(s+=1);for(const r of _r){const c=n[r];typeof c=="string"&&(s+=c.length)}}return s}function Fr(t,s,n,r){const c=n.get(t);return c&&c.len===s?c.h:r}function $r(t){const s=[];for(const n of t.content)n.type==="text"&&typeof n.text=="string"&&s.push(n.text);return s.join(`
319
- `)}function Hr(t,s){const n=[];for(const r of t.content)if(r.type==="text"&&typeof r.text=="string")n.push(r.text);else if(r.type==="thinking"&&typeof r.thinking=="string")n.push(r.thinking);else if(r.type==="toolCall"){if(typeof r.name=="string"&&n.push(r.name),typeof r.argumentsText=="string"&&n.push(r.argumentsText),typeof r.id=="string"){const c=s.get(r.id);if(c){const i=$r(c);i&&n.push(i)}}}else r.type==="bash"&&(typeof r.command=="string"&&n.push(r.command),typeof r.output=="string"&&n.push(r.output));return n.join(`
320
- `)}function Or(t,s){let n=0,r=t.indexOf(s);for(;r!==-1;)n++,r=t.indexOf(s,r+s.length);return n}function Kr(t,s,n,r){const c=new Map,i=n.toLowerCase();if(!i)return c;for(const a of t){if(!s.has(a.id))continue;const o=Or(Hr(a,r).toLowerCase(),i);o>0&&c.set(a.id,o)}return c}function Wr(t,s){var i;const n=[],r=s.toLowerCase();if(!r)return n;const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(a){const o=a.parentElement;return!o||o.closest(".search-bar")||o.closest(".msg-collapsed")?NodeFilter.FILTER_REJECT:(a.textContent??"").toLowerCase().includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let a=c.nextNode();a;a=c.nextNode()){const o=(a.textContent??"").toLowerCase();if(!((i=a.parentElement)!=null&&i.closest("[data-msg-id]")))continue;let u=o.indexOf(r);for(;u!==-1;){const m=document.createRange();m.setStart(a,u),m.setEnd(a,u+r.length),n.push(m),u=o.indexOf(r,u+r.length)}}return n}function Ur(t,s,n,r,c){var u;const i=Kr(n,r,s,c),a=new Map;for(const m of Wr(t,s)){const y=(u=m.startContainer.parentElement)==null?void 0:u.closest("[data-msg-id]");if(!(y!=null&&y.dataset.msgId))continue;const g=a.get(y.dataset.msgId);g?g.push(m):a.set(y.dataset.msgId,[m])}const o=[];for(const m of n){const y=a.get(m.id);if(y)for(let x=0;x<y.length;x++)o.push({kind:"dom",range:y[x],msgId:m.id,k:x});const g=i.get(m.id);if(g)for(let x=0;x<g;x++)o.push({kind:"folded",msgId:m.id,k:x})}return o}function Kt(t,s){return t.findIndex(n=>n.msgId===s.msgId&&n.k===s.k)}function $e(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const r=window.Highlight;r&&n.highlights.set(t,new r(...s))}function qr(t,s){const n=[];let r=t;for(;r&&r!==s;){const c=getComputedStyle(r);/(auto|scroll|hidden)/.test(c.overflowY+c.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&n.push(r),r=r.parentElement}return n}function zr(t,s){const n=s.startContainer.parentElement;for(const o of qr(n,t)){const u=s.getBoundingClientRect(),m=o.getBoundingClientRect();if(u.height<=0||u.width<=0)return;u.top>=m.top+4&&u.bottom<=m.bottom-4||(o.scrollTop+=u.top-m.top-(o.clientHeight-u.height)/2),u.left>=m.left+4&&u.right<=m.right-4||(o.scrollLeft+=u.left-m.left-(o.clientWidth-u.width)/2)}const r=s.getBoundingClientRect(),c=t.getBoundingClientRect();if(r.height<=0||r.width<=0)return;const i=r.top>=c.top+6&&r.bottom<=c.bottom-6,a=r.left>=c.left+6&&r.right<=c.right-6;i&&a||(i||(t.scrollTop+=r.top-c.top-(c.height-r.height)/2),a||(t.scrollLeft+=r.left-c.left-(c.width-r.width)/2))}function Vr({containerRef:t,messages:s,collapsedIds:n,toolResults:r,onExpand:c,onProgrammaticScroll:i,open:a,onClose:o}){const u=xe(),m=l.useRef(null),[y,g]=l.useState(""),[x,b]=l.useState(null),[E,A]=l.useState(0),[,H]=l.useState(0),S=l.useDeferredValue(y),j=a?S.trim():"",J=l.useRef(null);J.current=x;const Q=l.useRef([]),X=l.useRef({key:null}),U=l.useRef("");l.useEffect(()=>{a&&(b(null),requestAnimationFrame(()=>{var Y;return(Y=m.current)==null?void 0:Y.select()}))},[a]),l.useEffect(()=>{if(!a)return;const Y=T=>{T.key==="Escape"&&(T.preventDefault(),T.stopPropagation(),o())};return window.addEventListener("keydown",Y,!0),()=>window.removeEventListener("keydown",Y,!0)},[a,o]),l.useEffect(()=>(a||($e("msg-search",[]),$e("msg-search-active",[])),()=>{$e("msg-search",[]),$e("msg-search-active",[])}),[a]),l.useLayoutEffect(()=>{const Y=()=>{A(0),b(null),H(0),Q.current=[],$e("msg-search",[]),$e("msg-search-active",[]),X.current={key:null},U.current=""};if(!a||!j){Y();return}const T=t.current;if(!T)return;let P=!1,k=0;return k=requestAnimationFrame(()=>{var ne,v;if(P)return;const B=Ur(T,j,s,n,r);Q.current=B;const Z=B.length;if(A(Z),Z===0){b(null),H(0),$e("msg-search",[]),$e("msg-search-active",[]),X.current={key:null},U.current=j;return}const G=J.current;let M;if(G){if(M=Kt(B,G),M===-1){const D=[];for(let d=0;d<B.length;d++)B[d].msgId===G.msgId&&D.push(d);if(D.length>0){const d=Math.min(G.k,D.length-1);M=D[d]}else M=0}}else M=0;M<0&&(M=0),M>=Z&&(M=Z-1),(!G||G.msgId!==B[M].msgId||G.k!==B[M].k)&&b({msgId:B[M].msgId,k:B[M].k}),H(M);const I=B[M],C=X.current,$=((ne=C.key)==null?void 0:ne.msgId)!==I.msgId||((v=C.key)==null?void 0:v.k)!==I.k||C.kind==="folded"&&I.kind==="dom"||j!==U.current;X.current={key:{msgId:I.msgId,k:I.k},kind:I.kind},U.current=j;const z=B.filter(D=>D.kind==="dom").map(D=>D.range);if($e("msg-search",z),I.kind==="folded"){$e("msg-search-active",[]),$&&c(I.msgId);return}$e("msg-search-active",[I.range]),$&&(i==null||i(),zr(T,I.range))}),()=>{P=!0,cancelAnimationFrame(k)}},[a,j,s,t,x,n,r,c,i]);const K=l.useCallback(Y=>{const T=Q.current,P=T.length;if(P===0)return;const k=J.current,B=k?Kt(T,k):0,Z=T[(B+Y+P)%P];b(Z.kind==="dom"||Z.kind==="folded"?{msgId:Z.msgId,k:Z.k}:null)},[]);if(!a)return null;const q=x?(()=>{const Y=Kt(Q.current,x);return Y===-1?0:Y})():0;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:m,className:"search-input",type:"text",value:y,placeholder:u("searchPlaceholder"),onChange:Y=>{g(Y.target.value)},onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),K(Y.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${E===0?"empty":""}`,children:E===0?u("searchNoResults"):`${Math.min(q+1,E)}/${E}`}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchPrev"),disabled:E===0,onClick:()=>K(-1),children:e.jsx(ut,{})}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchNext"),disabled:E===0,onClick:()=>K(1),children:e.jsx(Ge,{})}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchClose"),onClick:o,children:e.jsx(Pe,{})})]})}function Gr(t){const{dSt:s,dSh:n,escaped:r,graceActive:c,stuck:i}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:n<0?{flipEscape:!1,reassert:i&&!r}:{flipEscape:!0,reassert:!1}}const Gn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],Qn="pi-web-ui:prompt-templates";function Qr(){try{const t=localStorage.getItem(Qn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(n=>!!n&&typeof n=="object"&&typeof n.id=="string"):[]}catch{return[]}}function en(t){return Gn.some(s=>s.id===t)}function ft(t){return typeof t.title=="string"}const Yn=l.createContext(null);function Jn(){const t=l.useContext(Yn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function Yr({send:t,children:s}){const n=xe(),[r,c]=l.useState(Qr),[i,a]=l.useState(!1),[o,u]=l.useState(null),[m,y]=l.useState(!1),[g,x]=l.useState(!1),[b,E]=l.useState(!1);l.useEffect(()=>{try{localStorage.setItem(Qn,JSON.stringify(r))}catch{}},[r]);const A=l.useMemo(()=>{const B=new Map,Z=new Set;for(const I of r)I.hidden?Z.add(I.id):(ft(I)&&!en(I.id)||ft(I))&&B.set(I.id,I);const G=Gn.filter(I=>!Z.has(I.id)).map(I=>{const C=B.get(I.id);return{id:I.id,icon:(C==null?void 0:C.icon)??I.icon,title:(C==null?void 0:C.title)??n(I.titleKey),desc:(C==null?void 0:C.desc)??n(I.descKey),prompt:(C==null?void 0:C.prompt)??n(I.promptKey),builtin:!0}}),M=r.filter(I=>ft(I)&&!en(I.id)).map(I=>({id:I.id,icon:I.icon??"📌",title:I.title??"",desc:I.desc??"",prompt:I.prompt??""}));return[...G,...M]},[r,n]),H=l.useCallback(()=>a(!0),[]),S=l.useCallback(B=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:B}))},[]),j=l.useCallback((B,Z=!1)=>{E(Z),B?(y(!1),u({...B})):(y(!0),u({id:Ue(),icon:"📌",title:"",desc:"",prompt:""}))},[]),J=l.useCallback(()=>{a(!1),u(null),E(!1)},[]),Q=l.useCallback(()=>{g?(c([]),x(!1)):(x(!0),setTimeout(()=>x(!1),5e3))},[g]),X=l.useCallback(B=>{a(!1),S(B.prompt)},[S]),U=l.useCallback(B=>{a(!1),j(B,!0)},[j]),K=l.useCallback(()=>{a(!1),j(void 0,!0)},[j]),q=l.useCallback(B=>{c(Z=>{const G=Z.findIndex(M=>M.id===B.id);if(G>=0){const M=[...Z];return M[G]=B,M}return[...Z,B]}),u(null),b&&(a(!0),E(!1))},[b]),Y=l.useCallback(B=>{c(Z=>B.builtin?[...Z.filter(M=>M.id!==B.id),{id:B.id,hidden:!0}]:Z.filter(G=>G.id!==B.id)),u(null),b&&(a(!0),E(!1))},[b]),T=l.useCallback(B=>{c(Z=>Z.filter(G=>G.id!==B.id||G.hidden)),u(null),b&&(a(!0),E(!1))},[b]),P=l.useMemo(()=>({templates:A,fill:S,openPicker:H,openEdit:j,resetConfirm:g,toggleReset:Q}),[A,S,H,j,g,Q]),k=o?r.some(B=>B.id===o.id&&!B.hidden&&ft(B)):!1;return e.jsxs(Yn.Provider,{value:P,children:[s,i&&e.jsx(Xr,{templates:A,resetConfirm:g,onFill:X,onEditTpl:U,onNew:K,onResetToggle:Q,onClose:J}),o&&e.jsx(Zr,{editing:o,isNew:m,hasOverride:k,onDraft:u,onSave:q,onRestore:()=>T(o),onRemove:()=>Y(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),J()},onSend:()=>{const B=o.prompt.trim();B&&t({type:"prompt",text:B,queue:!1})&&J()},onClose:J})]})}function Jr(){const t=xe(),{templates:s,fill:n,openEdit:r,toggleReset:c,resetConfirm:i}=Jn();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(a=>e.jsx(Xn,{tpl:a,title:t("tpl.clickCard"),onFill:()=>n(a.prompt),onEdit:()=>r(a),editTitle:t("tpl.editTpl")},a.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>r(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(bn,{}),t(i?"tpl.resetConfirm":"tpl.reset")]})})]})}function Xn({tpl:t,title:s,onFill:n,onEdit:r,editTitle:c}){const i=xe();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:n,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:a=>{a.stopPropagation(),r()},children:e.jsx(St,{})})]})}function Xr({templates:t,resetConfirm:s,onFill:n,onEditTpl:r,onNew:c,onResetToggle:i,onClose:a}){const o=xe();return l.useEffect(()=>{const u=m=>{m.key==="Escape"&&a()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[a]),e.jsx("div",{className:"modal-backdrop",onClick:a,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:a,children:e.jsx(Pe,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(u=>e.jsx(Xn,{tpl:u,title:o("tpl.clickCard"),onFill:()=>n(u),onEdit:()=>r(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(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:i,children:[e.jsx(bn,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Zr({editing:t,isNew:s,hasOverride:n,onDraft:r,onSave:c,onRestore:i,onRemove:a,onFill:o,onSend:u,onClose:m}){const y=xe(),g=l.useRef(null);l.useEffect(()=>{const E=A=>{A.key==="Escape"&&m()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[m]),l.useEffect(()=>{const E=g.current;if(!E)return;E.style.height="auto";const A=E.scrollHeight>300;E.style.height=`${Math.min(E.scrollHeight,300)}px`,E.style.overflowY=A?"auto":"hidden"},[t.prompt]);const x=()=>{const E=t.title.trim(),A=t.prompt.trim();if(!E||!A){r({...t,error:y("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:E,desc:t.desc.trim(),prompt:A})},b=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:m,children:e.jsxs("div",{className:"modal template-modal",onClick:E=>E.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:y(b?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:y(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:y("close"),onClick:m,children:e.jsx(Pe,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:E=>r({...t,icon:E.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:y("tpl.fieldTitlePh"),onChange:E=>r({...t,title:E.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:y("tpl.fieldDescPh"),onChange:E=>r({...t,desc:E.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldPrompt")}),e.jsx("textarea",{ref:g,className:"template-field-prompt",value:t.prompt,placeholder:y("tpl.fieldPromptPh"),onChange:E=>r({...t,prompt:E.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&&n&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:y("tpl.restoreTip"),onClick:i,children:y("tpl.restore")}),!s&&b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:y("tpl.removeTip"),onClick:a,children:[e.jsx(Ae,{})," ",y("tpl.remove")]}),!s&&!b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:y("tpl.deleteTip"),onClick:a,children:[e.jsx(Ae,{})," ",y("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:x,children:y("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:y("tpl.fillTip"),children:y("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:u,title:y("tpl.sendTip"),children:[e.jsx(vn,{})," ",y("tpl.sendNow")]})]})]})]})})}const tn=new Map,el=15,sn=30,Wt=250,nn=1200,tl=1600;function an(t){return t.content.some(s=>s.type==="toolCall")}function sl({state:t,liveOutputs:s,toolStatuses:n,onEdit:r,onKillBash:c,onRemoveQueued:i,thinkingWrap:a,toolsWrap:o,jumpTarget:u,onJumpDone:m}){const y=xe(),g=l.useRef(null),[x,b]=l.useState(!0),E=l.useRef(!0),A=l.useRef(0),H=l.useRef(0),S=l.useRef(!1),j=l.useRef(0),[J,Q]=l.useState(()=>new Set),[X,U]=l.useState(!1),K=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,q=l.useMemo(()=>{const N=new Map;for(const _ of t.messages)_.role==="toolResult"&&_.toolCallId&&N.set(_.toolCallId,_);return N},[t.messages]),Y=l.useMemo(()=>Pr(t.messages),[t.messages]),T=K.length>0?K[K.length-1].id:null,P=t.messages.length>sn?Math.max(0,t.messages.length-el):0,k=l.useMemo(()=>{const N=new Set;for(let _=0;_<P;_++){const ie=t.messages[_];ie.role!=="toolResult"&&(J.has(ie.id)||N.add(ie.id))}return N},[t.messages,P,J]),[B,Z]=l.useState(()=>new Set),[G,M]=l.useState(()=>new Set),I=l.useRef(new Map),C=l.useRef(new Map),$=l.useRef(new Map),z=l.useRef(0),ne=l.useMemo(()=>{const N=new Map;for(const _ of t.messages)N.set(_.id,Br(_));return N},[t.messages]),v=l.useRef(ne);v.current=ne;const D=l.useRef(B);D.current=B;const d=t.messages.length>sn&&!X,w=l.useRef(d);w.current=d;const h=Ar(t.messages,I.current,tl),L=l.useRef(h);L.current=h;const ee=l.useCallback(()=>{const N=g.current;if(!N)return;if(!w.current){Z(we=>we.size?new Set:we);return}const _=N.getBoundingClientRect(),ie={top:_.top-nn,bottom:_.bottom+nn},le=[];for(const[we,Te]of $.current){const Oe=Te.getBoundingClientRect();le.push({id:we,top:Oe.top,bottom:Oe.bottom}),D.current.has(we)||ye(we,Oe.bottom-Oe.top,v.current.get(we))}const je=Lr(le,ie,L.current,D.current);for(const we of je.hide){const Te=$.current.get(we);Te&&ye(we,Te.offsetHeight,v.current.get(we))}Z(we=>Dr(we,je))},[]),W=l.useCallback(()=>{z.current||(z.current=requestAnimationFrame(()=>{z.current=0,ee()}))},[ee]);l.useLayoutEffect(()=>{ee()},[ee]);const ae=l.useRef(X);l.useLayoutEffect(()=>{ae.current&&!X&&ee(),ae.current=X},[X,ee]);const ye=l.useCallback((N,_,ie)=>{ie!==void 0&&(C.current.set(N,{h:_,len:ie}),I.current.set(N,_))},[]),be=l.useCallback((N,_)=>{ye(N,_,v.current.get(N))},[ye]),ge=l.useCallback(N=>{N&&$.current.set(N.dataset.lazyId??"",N)},[]);l.useEffect(()=>{const N=new Set(t.messages.map(_=>_.id));for(const _ of $.current.keys())N.has(_)||($.current.delete(_),I.current.delete(_),C.current.delete(_));Z(_=>{let ie=!1;const le=new Set;for(const je of _)N.has(je)?le.add(je):ie=!0;return ie?le:_})},[t.messages,J]),l.useEffect(()=>()=>cancelAnimationFrame(z.current),[]);const ke=l.useMemo(()=>{const N=[];for(const _ of t.messages){if(_.role!=="user")continue;const ie=_.content.map(we=>{var Te;return((Te=ct(we))==null?void 0:Te.text)??""}).filter(Boolean).join(" "),le=ds(ie),je=le?le.userMessage??`skill:${le.name}`:ie.trim();je&&N.push({id:_.id,text:je})}return N},[t.messages]),Ee=l.useMemo(()=>{const N=new Map;return ke.forEach((_,ie)=>N.set(_.id,ie)),N},[ke]),[re,f]=l.useState(-1),O=l.useRef(-1),de=l.useRef(ke);l.useEffect(()=>{de.current=ke},[ke]);const ue=l.useCallback(()=>{const N=g.current,_=de.current;if(!N||_.length===0)return;const ie=N.getBoundingClientRect().top,le=140;let je=-1;for(let we=0;we<_.length;we++){const Te=N.querySelector(`[data-msg-id="${_[we].id}"]`);if(Te)if(Te.getBoundingClientRect().top<=ie+le)je=we;else break}je!==O.current&&(O.current=je,f(je))},[]);l.useEffect(()=>{ue()},[ke,ue]);const me=l.useCallback(N=>{Q(_=>_.has(N)?_:new Set(_).add(N))},[]);l.useEffect(()=>{const N=_=>{if(!(_.ctrlKey||_.metaKey)||_.key.toLowerCase()!=="f")return;const ie=_.target;ie&&(ie.tagName==="INPUT"||ie.tagName==="TEXTAREA"||ie.isContentEditable)||(_.preventDefault(),U(!0))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[]);const pe=l.useCallback(N=>{Q(_=>{if(!_.has(N))return _;const ie=new Set(_);return ie.delete(N),ie})},[]),ve=l.useCallback(N=>{const _=t.messages.findIndex(le=>le.id===N);qa.flushSync(()=>{_>=0&&_<P&&!J.has(N)&&me(N),M(le=>le.has(N)?le:new Set(le).add(N))});const ie=de.current.findIndex(le=>le.id===N);O.current=ie,f(ie),requestAnimationFrame(()=>{var je,we,Te;const le=(je=g.current)==null?void 0:je.querySelector(`[data-msg-id="${N}"]`);le&&((we=g.current)==null||we.querySelectorAll(".msg-flash").forEach(Oe=>Oe.classList.remove("msg-flash")),le.scrollIntoView({block:"start"}),le.classList.remove("msg-flash"),le.offsetWidth,le.classList.add("msg-flash"),le!==((Te=g.current)==null?void 0:Te.lastElementChild)&&(S.current=!0))})},[t.messages,P,J,me]),Me=l.useMemo(()=>{var N;return u?((N=t.messages.find(_=>_.role===u.role&&_.timestamp===u.timestamp))==null?void 0:N.id)??null:null},[t.messages,u]);l.useEffect(()=>{if(u){if(Me){ve(Me),m==null||m();return}t.sessionFile===u.path&&t.messages.length>0&&(m==null||m())}},[Me,ve,m,u,t.sessionFile,t.messages.length]);const he=l.useCallback(()=>{const N=g.current;if(!N)return;const _=N.scrollTop-A.current,ie=N.scrollHeight-H.current;A.current=N.scrollTop,H.current=N.scrollHeight;const le=N.scrollHeight-N.scrollTop-N.clientHeight<80,je=Date.now()<j.current,we=Gr({dSt:_,dSh:ie,escaped:S.current,graceActive:je,stuck:E.current});we.reassert&&(j.current=Date.now()+Wt,N.scrollTop=N.scrollHeight),we.flipEscape&&(S.current=!0),le&&_>=0&&(S.current=!1),je||(_<0?E.current=le&&!S.current:le&&(E.current=!0)),b(E.current),ue(),W()},[ue,W]),_e=l.useRef(!1);l.useEffect(()=>{const N=_e.current;if(_e.current=!!t.isStreaming,N&&!t.isStreaming&&!S.current){const _=()=>{const le=g.current;le&&!S.current&&(le.scrollTop=le.scrollHeight,E.current=!0,b(!0))};requestAnimationFrame(()=>requestAnimationFrame(_));const ie=setTimeout(_,180);return()=>clearTimeout(ie)}},[t.isStreaming]),l.useEffect(()=>{const N=g.current;N&&E.current&&(N.scrollTop=N.scrollHeight)},[K,t.isStreaming,s]);const Le=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");l.useEffect(()=>{const N=g.current;N&&E.current&&(N.scrollTop=N.scrollHeight)},[Le]),l.useEffect(()=>{const N=g.current;if(!N||typeof ResizeObserver>"u")return;const _=new ResizeObserver(()=>{E.current&&!S.current&&(N.scrollTop=N.scrollHeight,b(!0))});return _.observe(N),()=>_.disconnect()},[]),l.useEffect(()=>{const N=g.current;if(!N||typeof MutationObserver>"u")return;let _=!1;const ie=new MutationObserver(()=>{_||(_=!0,requestAnimationFrame(()=>{_=!1;const le=g.current;le&&E.current&&!S.current&&(le.scrollTop=le.scrollHeight,b(!0))}))});return ie.observe(N,{childList:!0,subtree:!0,characterData:!0}),()=>ie.disconnect()},[]);const Be=l.useCallback(()=>{if(!g.current)return;E.current=!0,S.current=!1,b(!0),j.current=Date.now()+Wt;const _=()=>{const ie=g.current;!ie||!E.current||S.current||(j.current=Date.now()+Wt,ie.scrollTop=ie.scrollHeight)};_(),requestAnimationFrame(()=>requestAnimationFrame(_)),setTimeout(_,120),setTimeout(_,300),setTimeout(_,600)},[]),De=l.useRef(null);l.useEffect(()=>{const N=De.current,_=g.current;if(!N||!_)return;const ie=le=>{le.preventDefault();const je=N.querySelector(".qn-list");if(je&&je.contains(le.target)&&je.scrollHeight>je.clientHeight){je.scrollTop+=le.deltaY;return}_.scrollTop+=le.deltaY};return N.addEventListener("wheel",ie,{passive:!1}),()=>N.removeEventListener("wheel",ie)},[]);const[R,fe]=l.useState(0);l.useEffect(()=>{const N=()=>{var _;fe(((_=g.current)==null?void 0:_.clientHeight)??0),W()};return N(),window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)},[W]);const oe=ke.length,p=l.useMemo(()=>oe===0?27:Math.max(4,Math.min(27,Math.floor(((R||600)-16)/oe)-3)),[oe,R]),V=p<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${X||x?"":" anchor-live"}`,ref:g,onScroll:he,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(Jr,{})}),t.messages.map((N,_)=>{const ie=_<P,le=ie&&J.has(N.id);if(ie&&!le)return N.role==="toolResult"?null:e.jsx(Mr,{message:N,onExpand:me},N.id);const je=N.role==="user"?Ee.get(N.id):void 0,we=!d||h.has(N.id)||G.has(N.id)||!B.has(N.id);return e.jsx(Ir,{id:N.id,show:we,height:Fr(N.id,ne.get(N.id)??-1,C.current,Vn(N.role,N.customType)),containerRef:g,onMeasured:be,lazyRef:ge,children:e.jsx(Ys,{message:N,qnIndex:je,qnActive:je!==void 0?je===re:void 0,onJump:ve,toolResults:q,liveOutputs:an(N)?s:tn,toolStatuses:n,streaming:t.isStreaming,onKillBash:c,toolsWrap:o,thinkingWrap:a,isLast:N.id===T,onEdit:r,questionAttachments:Y.get(N.id),onCollapse:le?pe:void 0,searchActive:X},N.id)},N.id)}),t.streamingMessage&&e.jsx(Ys,{message:t.streamingMessage,toolResults:q,liveOutputs:an(t.streamingMessage)?s:tn,toolStatuses:n,streaming:!0,isLast:!0,onEdit:r,onKillBash:c,toolsWrap:o,thinkingWrap:a,searchActive:X},t.streamingMessage.id),t.isStreaming&&K.length===0&&e.jsx("div",{className:"streaming-wait",children:y("waitingResponse")}),t.queue.steering.map((N,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:y("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:N}),i&&e.jsx("button",{type:"button",className:"queued-remove",title:y("queueRemoveTip"),onClick:()=>i("steer",N),children:"✕"})]})},`q-steer-${_}`)),t.queue.followUp.map((N,_)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:y("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:N}),i&&e.jsx("button",{type:"button",className:"queued-remove",title:y("queueRemoveTip"),onClick:()=>i("followUp",N),children:"✕"})]})},`q-fu-${_}`))]}),!x&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Be,children:[e.jsx(Sn,{})," ",y("backToBottom")]}),e.jsx(Vr,{containerRef:g,messages:K,collapsedIds:k,toolResults:q,onExpand:me,onProgrammaticScroll:()=>{S.current=!0,E.current=!1,b(!1)},open:X,onClose:()=>U(!1)}),ke.length>0&&e.jsxs("div",{className:`qn-rail ${V?"many":""}`,ref:De,"aria-label":y("questionNavTitle"),style:{"--rail-gap":`${p}px`},children:[ke.map((N,_)=>e.jsx("button",{type:"button",className:`qn-bar ${_===re?"active":""}`,"aria-label":`${_+1}. ${N.text}`,onClick:()=>ve(N.id),children:e.jsxs("span",{className:"qn-bar-text",children:[_+1,". ",N.text]})},N.id)),V&&e.jsx("div",{className:"qn-list",children:ke.map((N,_)=>e.jsxs("button",{type:"button",className:`qn-list-item ${_===re?"active":""}`,"aria-label":`${_+1}. ${N.text}`,onClick:()=>ve(N.id),children:[e.jsx("span",{className:"qn-list-idx",children:_+1}),e.jsx("span",{className:"qn-list-text",children:N.text})]},N.id))})]})]})}const Zn="pi-web-model-usage";function nl(t){if(!t||typeof t!="object")return{};const s={};for(const[n,r]of Object.entries(t)){const c=typeof r=="number"?Math.floor(r):0;Number.isFinite(c)&&c>0&&(s[n]=c)}return s}function il(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function al(t,s){const n=s;return t.map((r,c)=>({m:r,i:c,count:n[r.id]??0})).sort((r,c)=>c.count-r.count||r.i-c.i).map(r=>r.m)}function ei(){try{const t=localStorage.getItem(Zn);return t?nl(JSON.parse(t)):{}}catch{return{}}}function rl(t){try{localStorage.setItem(Zn,JSON.stringify(t))}catch{}}function ll(t){const s=il(ei(),t);return rl(s),s}const us="pi-web-ui:prompt-history",ol=100,ti="pi-web-ui:prompt-history-settings",is={maxEntries:100,charLimitEnabled:!1,charLimit:2e3};function si(t){const s=is;if(!t||typeof t!="object")return{...s};const n=t;let r=typeof n.maxEntries=="number"?Math.floor(n.maxEntries):s.maxEntries;(!Number.isFinite(r)||r<1)&&(r=1),r>500&&(r=500);let c=typeof n.charLimit=="number"?Math.floor(n.charLimit):s.charLimit;(!Number.isFinite(c)||c<100)&&(c=100),c>2e4&&(c=2e4);const i=typeof n.charLimitEnabled=="boolean"?n.charLimitEnabled:s.charLimitEnabled;return{maxEntries:r,charLimitEnabled:i,charLimit:c}}function ni(){try{const t=localStorage.getItem(ti);return t?si(JSON.parse(t)):{...is}}catch{return{...is}}}function Ut(t){const s=si(t);try{localStorage.setItem(ti,JSON.stringify(s))}catch{}try{let n=dt();s.charLimitEnabled&&(n=n.map(r=>r.length>s.charLimit?r.slice(0,s.charLimit):r)),n.length>s.maxEntries&&(n=n.slice(n.length-s.maxEntries)),ii(n)}catch{}}function cl(t){if(!Array.isArray(t))return[];const s=[];for(const n of t){if(typeof n!="string")continue;const r=n.trim();r&&s.push(r)}return s}function dl(t,s,n=ol){const r=s.trim();if(!r||t.length>0&&t[t.length-1]===r)return t;const c=[...t,r];return c.length>n?c.slice(c.length-n):c}function dt(){try{const t=localStorage.getItem(us);return t?cl(JSON.parse(t)):[]}catch{return[]}}function ii(t){let s=t;for(;s;)try{localStorage.setItem(us,JSON.stringify(s));return}catch(n){if(!(n instanceof DOMException&&(n.name==="QuotaExceededError"||n.code===22))||s.length<=1)return;s=s.slice(Math.ceil(s.length/2))}}function ul(t){let s=t.trim();if(!s)return;const n=ni();n.charLimitEnabled&&s.length>n.charLimit&&(s=s.slice(0,n.charLimit));const r=dt(),c=dl(r,s,n.maxEntries);c!==r&&ii(c)}function pl(){try{localStorage.removeItem(us)}catch{}}const ml=["off","minimal","low","medium","high","xhigh","max"],hl=l.memo(function({state:s,models:n,modelsLoading:r,send:c,onManageModels:i,providerKeys:a,compact:o=!1}){const u=xe(),m=s==null?void 0:s.model,y=m?`${m.provider}/${m.id}`:null,[g,x]=l.useState(!1),[b,E]=l.useState(!1),[A,H]=l.useState(""),[S,j]=l.useState(null),[J,Q]=l.useState({}),X=l.useRef(null),U=l.useRef(null),[K,q]=l.useState(null);l.useEffect(()=>{if(!g){q(null);return}if(n.length===0)return;const C=requestAnimationFrame(()=>{const $=U.current;$&&q($.offsetWidth)});return()=>cancelAnimationFrame(C)},[g,n.length]),l.useEffect(()=>{g&&Q(ei())},[g]),l.useEffect(()=>{g||(H(""),j(null))},[g]);const Y=l.useMemo(()=>{const C=new Map;for(const z of n)C.set(z.provider,(C.get(z.provider)??0)+1);const $=[];for(const[z,ne]of[...C.entries()].sort((v,D)=>v[0].localeCompare(D[0]))){const v=a[z];if(v&&v.length>1)for(const D of v)$.push({provider:z,keyName:D.name,count:ne});else $.push({provider:z,keyName:null,count:ne})}return $},[n,a]),T=l.useMemo(()=>al(n,J),[n,J]),P=l.useMemo(()=>{let C=T;S&&(C=C.filter(z=>z.provider===S.provider));const $=A.trim().toLowerCase();return $?C.filter(z=>z.name.toLowerCase().includes($)||z.provider.toLowerCase().includes($)||z.id.toLowerCase().includes($)):C},[T,A,S]),k=l.useMemo(()=>{const C=[];for(const $ of P){const z=a[$.provider];if(!z||z.length<=1){C.push({model:$,key:null});continue}let ne=z.find(v=>v.active)??z[0];if((S==null?void 0:S.provider)===$.provider&&S.keyName){const v=z.find(D=>D.name===S.keyName);v&&(ne=v)}C.push({model:$,key:ne})}return C},[P,a,S]),[B,Z]=l.useState(!1),G=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,M=ml.map(C=>({value:C,label:u(`thinking.${C}`),supported:G?G.has(C):!0})),I=C=>{var $;return(($=M.find(z=>z.value===C))==null?void 0:$.label)??C};return l.useEffect(()=>{g&&n.length===0&&!B&&!r&&(Z(!0),c({type:"list_models"}))},[g,n.length,B,r,c]),l.useEffect(()=>{n.length>0&&Z(!1)},[n.length]),l.useEffect(()=>{var $;if(!g)return;const C=($=X.current)==null?void 0:$.querySelector(".dd-item.active");C==null||C.scrollIntoView({block:"nearest"})},[g,y,n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(lt,{}),e.jsx("span",{className:"chip-model",children:m?m.name:u("selectModel")}),!o&&(m==null?void 0:m.vision)&&e.jsx("span",{className:"chip-vision",title:u("vision"),children:"🖼"}),!o&&m&&e.jsx("span",{className:"chip-sub",children:m.provider})]}),open:g,onOpenChange:x,menuClassName:"dd-menu-model",menuRef:U,menuStyle:K!=null?{width:K}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:u("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(Nt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:u("searchModels"),value:A,onChange:C=>H(C.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[Y.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:u("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${S===null?"active":""}`,onClick:()=>j(null),children:e.jsx("span",{children:u("allProviders")})}),Y.map(C=>{const $=(S==null?void 0:S.provider)===C.provider&&(S==null?void 0:S.keyName)===C.keyName;return e.jsxs("button",{type:"button",className:`dd-provider-item ${$?"active":""}`,onClick:()=>j($?null:{provider:C.provider,keyName:C.keyName}),title:C.keyName?`${C.provider} · ${C.keyName}`:`${C.provider} · ${C.count}`,children:[e.jsxs("span",{className:"dd-provider-txt",children:[e.jsx("span",{className:"dd-provider-name",children:C.provider}),C.keyName&&e.jsx("span",{className:"dd-provider-key",children:C.keyName})]}),e.jsx("span",{className:"dd-provider-count",children:C.count})]},C.keyName?`${C.provider}::${C.keyName}`:C.provider)})]}),e.jsxs("div",{className:"dd-model-scroll",ref:X,children:[(B||r)&&e.jsx("div",{className:"dd-loading",children:u("loading")}),n.length===0&&!B&&!r&&e.jsx("div",{className:"dd-loading",children:u("noModels")}),P.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:u("noModelMatches")}),k.map(C=>{const $=C.model,z=y===$.id&&(!C.key||C.key.active);return e.jsx(Ie,{active:z,onClick:()=>{C.key&&!C.key.active&&c({type:"activate_provider_key",provider:$.provider,keyName:C.key.name}),y!==$.id&&c({type:"set_model",modelId:$.id}),x(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:$.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:$.provider}),C.key&&e.jsxs("span",{className:`dd-model-key ${C.key.active?"active":""}`,children:[C.key.active?"●":"○"," ",C.key.name]}),(J[$.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:u("modelUsedCount",{n:J[$.id]})}),($.reasoning||$.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[$.reasoning&&e.jsx("span",{className:"dd-model-badge",children:u("reasoning")}),$.vision&&e.jsx("span",{className:"dd-model-badge",children:u("vision")})]})]})]})},C.key?`${$.id}::${C.key.name}`:$.id)})]})]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:u("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{x(!1),i()},children:u("manageModels")})]})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(xt,{}),e.jsx("span",{className:"chip-sub",children:u("thinkingChip",{level:s?I(s.thinkingLevel):"—"})})]}),open:b,onOpenChange:E,direction:"up",children:[e.jsx("div",{className:"dd-header",children:u("thinkingLevel")}),M.map(C=>e.jsx(Ie,{active:(s==null?void 0:s.thinkingLevel)===C.value,disabled:!C.supported,title:C.supported?void 0:u("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==C.value&&c({type:"set_thinking",level:C.value}),E(!1)},children:C.label},C.value))]})]})}),gl=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,fl=l.memo(function({ready:s,streaming:n,messages:r,slashCommands:c,modelState:i,models:a,modelsLoading:o,send:u,attachments:m,onRemoveAttachment:y,onAddImageFiles:g,onAddLocalFiles:x,onNotice:b,onSent:E,onManageModels:A,providerKeys:H}){const S=xe(),{locale:j}=mt(),{openPicker:J}=Jn(),Q=f=>j==="en"&&f.descriptionEn?f.descriptionEn:f.description??"",X=f=>j==="en"&&f.argumentHintEn?f.argumentHintEn:f.argumentHint??"",[U,K]=l.useState(""),[q,Y]=l.useState(!1),[T,P]=l.useState(null),[k,B]=l.useState(0),[Z,G]=l.useState(!1),[M,I]=l.useState(void 0),C=l.useRef(null),$=l.useRef(null),z=l.useRef(null),ne=l.useRef(-1),v=l.useRef(""),D={builtin:S("slashBuiltin"),extension:S("slashExtension"),prompt:S("slashPrompt"),skill:S("slashSkill"),plugin:S("slashPlugin")},d=f=>{const O=f.match(/^\/([^\s]*)$/);if(O&&s){const de=O[1].toLowerCase(),ue=c.filter(me=>me.name.toLowerCase().startsWith(de));P(ue.length>0?ue:null),B(0)}else P(null)};l.useEffect(()=>{var O;const f=(O=z.current)==null?void 0:O.querySelector(".slash-item.active");f==null||f.scrollIntoView({block:"nearest"})},[k,T]);const w=f=>{var pe;const O=T??[],de=f??O[k%Math.max(O.length,1)];if(!de){P(null);return}const ue=U.match(/^\/([^\s]*)([\s\S]*)$/),me=ue?ue[2]:"";K(`/${de.name} ${me}`),P(null),(pe=C.current)==null||pe.focus()},h=async()=>{const O=[...r].reverse().find(ue=>ue.role==="assistant"&&ue.content.some(me=>me.type==="text"&&me.text)),de=O==null?void 0:O.content.filter(ue=>ue.type==="text").map(ue=>ue.text).join(`
321
- `);if(!de){b("warning",S("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(de),b("info",S("slashCopied"))}catch{b("error",S("slashCopyFailed"))}},L=f=>{if(!f||f.length===0){b("warning",S("foldersNotSupported"));return}const O=Array.from(f).filter(me=>We(me.type)),de=Array.from(f).filter(me=>!We(me.type)),ue=W();O.length>0&&ue?b("warning",ue):O.length>0&&g(O),de.length>0&&x(de)},ee=f=>{var me;const O=(me=f.clipboardData)==null?void 0:me.items;if(!O)return;const de=[];for(const pe of O)if(pe.kind==="file"&&We(pe.type)){const ve=pe.getAsFile();ve&&de.push(ve)}if(de.length===0)return;f.preventDefault();const ue=W();if(ue){b("warning",ue);return}g(de)},W=()=>{const f=i==null?void 0:i.model;if(!(f!=null&&f.id))return null;const O=a.find(de=>de.id===f.id);return O&&O.vision===!1?S("modelNoVision",{name:O.name}):null},ae=s,ye=l.useRef(U);l.useEffect(()=>{ye.current=U},[U]),l.useEffect(()=>{d(ye.current)},[c]),l.useEffect(()=>{const f=O=>{var ue;const de=O.detail;K(de),(ue=C.current)==null||ue.focus()};return window.addEventListener("pi-web:fill",f),()=>window.removeEventListener("pi-web:fill",f)},[]),l.useEffect(()=>{if(!Z)return;const f=O=>{O.key==="Escape"&&G(!1)};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[Z]),l.useEffect(()=>{const f=C.current;if(!f)return;f.style.height="auto";const O=f.scrollHeight>220;f.style.height=`${Math.min(f.scrollHeight,220)}px`,f.style.overflowY=O?"auto":"hidden"},[U]);const be=f=>f.selectionStart!==f.selectionEnd?!1:!f.value.slice(0,f.selectionStart).includes(`
322
- `),ge=f=>f.selectionStart!==f.selectionEnd?!1:!f.value.slice(f.selectionStart).includes(`
323
- `),ke=(f=!1)=>{var ue,me,pe,ve,Me;const O=U.trim(),de=m.some(he=>he.imageData||he.fileData);if(!(!ae||!O&&!de)){if(O==="/help"){const he=(me=(ue=C.current)==null?void 0:ue.closest(".inputbox"))==null?void 0:me.getBoundingClientRect();I(he==null?void 0:he.width),G(!0),K(""),(pe=C.current)==null||pe.focus();return}if(O==="/copy"){K(""),(ve=C.current)==null||ve.focus(),h();return}if(u({type:"prompt",text:O,queue:f,attachments:m.map(he=>he.imageData?{path:"",imageData:he.imageData,mimeType:he.mimeType,name:he.name}:he.fileData?{path:"",fileData:he.fileData,mimeType:he.mimeType,name:he.name,size:he.size}:{path:he.path,mode:he.mode,...he.lines?{lines:he.lines}:{}})})){O&&ul(O),ne.current=-1,v.current="",K(""),E();const he=i==null?void 0:i.model;he&&ll(`${he.provider}/${he.id}`),(Me=C.current)==null||Me.focus()}}},Ee=f=>{if(!f.nativeEvent.isComposing){if(T&&T.length>0)switch(f.key){case"ArrowDown":f.preventDefault(),B(O=>(O+1)%T.length);return;case"ArrowUp":f.preventDefault(),B(O=>(O-1+T.length)%T.length);return;case"Tab":case"Enter":f.preventDefault(),w();return;case"Escape":f.preventDefault(),P(null);return}if(f.key==="ArrowUp"||f.key==="ArrowDown"){if(f.ctrlKey||f.metaKey||f.altKey)return;const O=C.current;if(!O)return;const de=f.key==="ArrowUp";if(de&&!be(O)||!de&&!ge(O)||!de&&ne.current===-1)return;const ue=dt();if(ue.length===0)return;if(f.preventDefault(),de){if(ne.current===-1){v.current=U;const me=ue.length-1;ne.current=me;const pe=ue[me];K(pe),d(pe),requestAnimationFrame(()=>{const ve=C.current;ve&&(ve.selectionStart=ve.selectionEnd=pe.length)})}else if(ne.current>0){const me=ne.current-1;ne.current=me;const pe=ue[me];K(pe),d(pe),requestAnimationFrame(()=>{const ve=C.current;ve&&(ve.selectionStart=ve.selectionEnd=pe.length)})}}else{const me=ne.current+1;if(me<ue.length){ne.current=me;const pe=ue[me];K(pe),d(pe),requestAnimationFrame(()=>{const ve=C.current;ve&&(ve.selectionStart=ve.selectionEnd=pe.length)})}else{ne.current=-1;const pe=v.current;K(pe),d(pe),requestAnimationFrame(()=>{const ve=C.current;ve&&(ve.selectionStart=ve.selectionEnd=pe.length)})}}return}if(f.key==="Escape"&&ne.current!==-1){f.preventDefault();const O=v.current;ne.current=-1,K(O),d(O),requestAnimationFrame(()=>{const de=C.current;de&&(de.selectionStart=de.selectionEnd=O.length)});return}if(f.key==="Enter"){if(gl&&!f.shiftKey&&!(f.ctrlKey||f.metaKey))return;f.shiftKey||(f.preventDefault(),ke())}}},re=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[U.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:S("supplementTip"),onClick:()=>ke(!0),children:[e.jsx(vn,{})," ",S("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:S("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(jt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:S("sendTip"),disabled:!ae||!U.trim()&&!m.some(f=>f.imageData||f.fileData),onClick:()=>ke(),children:e.jsx(Cn,{})})});return e.jsxs("div",{className:`inputbar${q?" drop-active":""}`,onDragOver:f=>{f.preventDefault(),f.stopPropagation(),Y(!0)},onDragLeave:f=>{f.currentTarget.contains(f.relatedTarget)||Y(!1)},onDrop:f=>{var O;f.preventDefault(),f.stopPropagation(),Y(!1),L(((O=f.dataTransfer)==null?void 0:O.files)??null)},children:[q&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",S("dropHereToAttach")]})}),m.length>0&&e.jsxs("div",{className:"attach-row",children:[m.map(f=>e.jsxs("span",{className:`attach-chip ${f.imageData?"image":f.fileData?"file":f.mode}`,title:f.imageData?S("attachImage",{name:f.name}):f.fileData?S("attachFile",{name:f.name}):f.isDir?S("folderRef",{path:f.path}):f.mode==="reference"?S("refOnly",{path:f.path}):f.mode==="lines"&&f.lines?S("attachLines",{path:f.path,start:f.lines.start,end:f.lines.end}):S("attachContent",{path:f.path}),children:[f.imageData?"🖼":f.fileData?"📄":f.isDir?"📁":f.mode==="reference"?"🔗":"📎"," ",f.name,f.mode==="lines"&&f.lines&&e.jsxs("span",{className:"attach-range",children:["L",f.lines.start,"-",f.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:S("removeAttachment"),onClick:()=>y(f.key??f.path),children:"×"})]},f.key??`${f.path}|${f.mode}|${f.lines?`${f.lines.start}-${f.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:S("attachHint")})]}),T&&T.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:z,"aria-label":S("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:S("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>P(null),children:"Esc"})]}),T.map((f,O)=>e.jsxs("button",{type:"button",className:`slash-item${O===k?" active":""}`,onMouseEnter:()=>B(O),onClick:()=>w(f),children:[e.jsxs("span",{className:"slash-name",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:D[f.source]}),e.jsxs("span",{className:"slash-desc",children:[Q(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:X(f)})]})]},f.name))]}),Z&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:M?{width:M}:void 0,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",S("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:S("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:S("slashLoading")}):c.map(f=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:D[f.source]}),e.jsxs("span",{className:"slash-help-desc",children:[Q(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:X(f)})]})]},f.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:$,type:"file",multiple:!0,hidden:!0,onChange:f=>{L(f.target.files),f.target.value=""}}),e.jsx("textarea",{ref:C,value:U,rows:1,placeholder:S(ae?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!ae,onChange:f=>{ne.current=-1,K(f.target.value),d(f.target.value)},onKeyDown:Ee,onPaste:ee}),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:S("uploadFile"),disabled:!ae,onClick:()=>{var f;return(f=$.current)==null?void 0:f.click()},children:e.jsx(_i,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:S("tpl.openPicker"),onClick:J,children:e.jsx(qi,{})}),e.jsx(hl,{state:i,models:a,modelsLoading:o,send:u,onManageModels:A,providerKeys:H,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:re()})]})]})]})}),xl=l.memo(function({goal:s,models:n,modelsLoading:r,activeConversationId:c,engine:i,send:a}){var M,I,C,$,z,ne,v;const o=xe(),{locale:u}=mt(),m=u==="en"&&s.statusEn?s.statusEn:s.status||"",y=u==="en"&&((M=s.wizard)!=null&&M.statusEn)?s.wizard.statusEn:((I=s.wizard)==null?void 0:I.status)||"",g=i==="dsh",x=!s.conversationId||s.conversationId===c,b=s.goal!==null&&x,[E,A]=l.useState(""),[H,S]=l.useState(s.reviewModel??""),[j,J]=l.useState(s.maxRounds),[Q,X]=l.useState(s.locked),[U,K]=l.useState(!1),[q,Y]=l.useState(!1),[T,P]=l.useState(!0);l.useEffect(()=>{S(s.reviewModel??""),J(s.maxRounds||0),X(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),l.useEffect(()=>{U&&n.length===0&&!q&&!r&&(Y(!0),a({type:"list_models"}))},[U,n.length,q,r,a]),l.useEffect(()=>{n.length>0&&Y(!1)},[n.length]);const k=()=>{var D;return H?((D=n.find(d=>d.id===H))==null?void 0:D.name)??H:o("goalBarUseMainModel")},B=()=>{const D=E.trim();D&&(a({type:"set_goal",goal:D,...H?{reviewModel:H}:{},maxRounds:j,locked:Q}),A(""),P(!1))},Z=()=>{const D=E.trim();D&&(a({type:"start_goal_wizard",text:D,...H?{wizardModel:H}:{},maxRounds:j,locked:Q}),A(""),P(!1))},G=(((C=s.wizard)==null?void 0:C.active)??!1)&&x;return G?e.jsx("div",{className:`goalbar goalbar-active ${G?"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:(($=s.wizard)==null?void 0:$.draft)??"",children:[o("goalWizardRunning"),": ",(z=s.wizard)==null?void 0:z.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarRound",{n:(((ne=s.wizard)==null?void 0:ne.step)??0)+1})," / ",((v=s.wizard)==null?void 0:v.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:y||o("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),onClick:()=>{a({type:"clear_goal"}),P(!0)},children:e.jsx(Pe,{})})]})}):b?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarReviewing")," ",o("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?o("goalBarPassed"):s.verdict==="fail"?o("goalBarFailed"):`${o("goalBarRound",{n:s.round||1})} · ${s.locked?o("goalBarLocked"):o("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:m}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),disabled:s.reviewing,onClick:()=>{a({type:"clear_goal"}),P(!0)},children:e.jsx(Pe,{})})]})}):T?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:o("goalBarPlaceholder"),onClick:()=>P(!1),children:[e.jsx(Is,{})," ",e.jsx("span",{children:o("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(Is,{})}),e.jsx("input",{className:"goalbar-input",value:E,placeholder:o("goalBarPlaceholder"),onChange:D=>A(D.target.value),onKeyDown:D=>{D.key==="Enter"&&B()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!E.trim(),onClick:B,children:o("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!E.trim(),title:o("goalWizardTip"),onClick:Z,children:["🔍 ",o("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o(Q?"goalBarLocked":"goalBarUnlocked"),onClick:()=>X(D=>(a({type:"set_goal_prefs",locked:!D}),!D)),children:Q?e.jsx(Ki,{}):e.jsx(Ii,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o("goalBarClear"),onClick:()=>P(!0),children:e.jsx(ut,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[g?e.jsx("p",{className:"goalbar-dsh-note",children:o("dshNoReviewModel")}):e.jsxs(ze,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[o("goalBarReviewModel"),": ",e.jsx("b",{children:k()})]}),open:U,onOpenChange:K,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("goalBarReviewModel")}),(q||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.length===0&&!q&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),e.jsx(Ie,{active:H==="",onClick:()=>{S(""),K(!1),a({type:"set_goal_prefs",reviewModel:""})},children:o("goalBarUseMainModel")}),n.map(D=>e.jsx(Ie,{active:H===D.id,onClick:()=>{S(D.id),K(!1),a({type:"set_goal_prefs",reviewModel:D.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:D.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:D.provider})})]})},D.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>a({type:"list_models"}),children:o("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:o("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:o("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:j,placeholder:o("goalBarUnlimitedShort"),onChange:D=>{const d=parseInt(D.target.value,10);if(Number.isNaN(d)||d<0){J(0);return}J(d)},onBlur:()=>a({type:"set_goal_prefs",maxRounds:j}),onKeyDown:D=>{D.key==="Enter"&&(a({type:"set_goal_prefs",maxRounds:j}),D.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:o(Q?"goalBarLocked":"goalBarUnlocked")})]})]})});function yl(t){const s=Math.max(0,t.input??0),n=Math.max(0,t.cacheRead??0),r=Math.max(0,t.cacheWrite??0),c=s+n+r;return{totalInput:c,miss:s,read:n,write:r,hitRate:c>0?Math.min(n/c,1):0,writeRate:c>0?Math.min(r/c,1):0}}const ai=2e3;function vl(t,s,n=ai){return t.filter(r=>s-r.t<=n)}function bl(t,s=ai){if(t.length<2)return 0;const n=t[t.length-1],r=t.find(i=>i.t>=n.t-s)??t[0],c=(n.t-r.t)/1e3;return c<=0?0:Math.max(0,(n.out-r.out)/c)}function rn(t){if(!t)return 0;let s=0;for(let r=0;r<t.length;r++){const c=t.charCodeAt(r);(c>=12352&&c<=12543||c>=13312&&c<=19903||c>=19968&&c<=40959||c>=63744&&c<=64255||c>=65280&&c<=65519||c===12288)&&s++}const n=t.length-s;return Math.round(s+n/4)}function kl(t){let s=0;for(const n of t)n.type==="text"&&typeof n.text=="string"&&n.text?s+=rn(n.text):n.type==="thinking"&&typeof n.thinking=="string"&&n.thinking&&(s+=rn(n.thinking));return s}const Qe="@root";function jl({chat:t,send:s}){const n=xe(),r=t.state,[c,i]=l.useState(!1),[a,o]=l.useState(""),[u,m]=l.useState(""),[y,g]=l.useState(!1),[x,b]=l.useState(""),[E,A]=l.useState(-1),H=l.useRef(null),S=l.useRef(null),j=t.pathCompletions.filter(h=>h.type==="dir"),J=h=>h.endsWith("/")?h:h+"/",Q=h=>{let L=h.endsWith("/")&&h!=="/"?h.slice(0,-1):h;if(L===Qe||L==="/")return null;const ee=L.lastIndexOf("/");if(ee<0)return/^[A-Za-z]:$/.test(L)?Qe:null;if(ee===0)return"/";const W=L.slice(0,ee);return/^[A-Za-z]:$/.test(W)?W+"/":W};l.useEffect(()=>{if(!c)return;const h=setTimeout(()=>{s({type:"complete_path",path:J(a)})},60);return()=>clearTimeout(h)},[a,c,s]),l.useEffect(()=>{if(!c||u===a)return;const h=setTimeout(()=>{s({type:"complete_path",path:u})},150);return()=>clearTimeout(h)},[u,a,c,s]);const X=l.useRef([]),U=(r==null?void 0:r.isStreaming)??!1,K=r!=null&&r.streamingMessage?kl(r.streamingMessage.content):0;if(l.useEffect(()=>{if(!U){X.current=[];return}const h=Date.now(),L=X.current,ee=L[L.length-1];ee&&h-ee.t<250||(X.current=vl([...L,{t:h,out:K}],h))},[U,K]),!r)return null;const q=r.stats,Y=yl(q.tokens),T=Y.hitRate*100,P=Y.totalInput===0?"":Y.hitRate>=.7?"ok":Y.hitRate>=.4?"mid":"warn",k=Y.totalInput>0?`${T.toFixed(1)}%`:"—",B=U?bl(X.current):0,Z=t.ready?"ok":"busy",G=t.ready?n("connected"):n("connecting"),M=q.contextUsage,I=M.tokens!==null&&M.percent!==null?`${Ze(M.tokens)} / ${Ze(M.contextWindow)}`:"—",C=M.percent??null,$=C===null?"":C>=80?"warn":C>=50?"mid":"ok",z=r.queue.steering.length+r.queue.followUp.length,ne=()=>{m(r.cwd),o(r.cwd),g(!1),b(""),i(!0)},v=h=>{const L=h.trim();L!==Qe&&(L&&L!==r.cwd&&s({type:"set_cwd",path:L}),i(!1))},D=()=>{const h=x.trim();h&&(s({type:"make_dir",path:`${J(a)}${h}`}),setTimeout(()=>{s({type:"complete_path",path:J(a)})},80),b(""),g(!1))},d=h=>{if(h.key==="Escape")h.stopPropagation(),i(!1);else if(h.key==="Enter"&&!h.nativeEvent.isComposing)v(u);else if(h.key==="Tab"){if(j.length===0)return;h.preventDefault();const L=E>=0?(E+1)%j.length:0;A(L),m(j[L].path),o(j[L].path)}},w=Q(a);return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${Z}`,title:G}),e.jsx("span",{className:"status-item",children:G}),e.jsx("span",{className:"status-sep",children:"·"}),t.engine&&t.engine!=="pi"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`status-item engine-badge engine-${t.engine}`,title:`${n("engineBadge")}: ${t.engine}`,children:t.engine==="dsh"?"DSH":t.engine}),e.jsx("span",{className:"status-sep",children:"·"})]}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${$}`,children:C!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(C,100)}%`}})}),I]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",wl(q.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-cache",title:n("cacheHitTip",{read:Ze(Y.read),write:Ze(Y.write),miss:Ze(Y.miss),input:Ze(Y.totalInput)}),children:[n("cacheHit"),e.jsx("b",{className:`cache-pct ${P}`,children:k})]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("sessionMessages"),children:[n("messages")," ",q.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:n("pluginStatus"),children:t.statuses.map(h=>h.text).join(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),n("working"),z>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",z," ",n("queued")]})]}),e.jsx("span",{className:"status-item status-rate",title:n("rateTip"),children:B>0?`${Math.round(B)}${n("tps")}`:"…"})]}),c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"status-cwd-backdrop",onClick:()=>i(!1)}),e.jsxs("div",{className:"cwd-picker",children:[e.jsxs("div",{className:"cwd-picker-head",children:[e.jsxs("span",{className:"cwd-picker-title",title:a===Qe?n("computer"):a,children:[a===Qe?"💻":e.jsx(Je,{}),e.jsx("span",{children:a===Qe?n("computer"):a})]}),e.jsxs("button",{type:"button",className:"cwd-up",disabled:!w,title:n("cwdGoUp"),onClick:()=>{w&&(o(w),m(w),A(-1))},children:["↑ ",n("cwdGoUp")]})]}),e.jsxs("div",{className:"cwd-picker-row",children:[e.jsx("input",{ref:H,className:"status-cwd-input cwd-picker-input",value:u,placeholder:n("enterPath"),spellCheck:!1,onChange:h=>{m(h.target.value),A(-1)},onKeyDown:d}),e.jsx("button",{type:"button",className:"cwd-choose-btn primary",title:n("cwdPickCurrent"),disabled:a===Qe,onClick:()=>v(a),children:n("cwdPickCurrent")})]}),e.jsxs("div",{className:"cwd-list",children:[j.length===0&&e.jsx("div",{className:"cwd-empty",children:n("cwdEmpty")}),j.map(h=>e.jsxs("div",{className:"cwd-item",children:[e.jsxs("button",{type:"button",className:"cwd-enter",title:`${n("cwdEnter")} ${h.path}`,onClick:()=>{o(h.path),m(h.path),A(-1)},children:[e.jsx(Je,{}),e.jsx("span",{className:"cwd-name",children:h.name})]}),e.jsx("button",{type:"button",className:"cwd-choose-btn",title:n("cwdChoose"),onClick:()=>v(h.path),children:n("cwdChoose")})]},h.path))]}),e.jsx("div",{className:"cwd-picker-foot",children:y?e.jsxs("div",{className:"cwd-newrow",children:[e.jsx("input",{ref:S,value:x,autoFocus:!0,spellCheck:!1,placeholder:n("cwdNewName"),onChange:h=>b(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.nativeEvent.isComposing?(h.preventDefault(),D()):h.key==="Escape"&&(h.stopPropagation(),g(!1),b(""))}}),e.jsx("button",{type:"button",className:"cwd-choose-btn primary",onClick:D,children:n("cwdCreate")}),e.jsx("button",{type:"button",className:"cwd-choose-btn",onClick:()=>{g(!1),b("")},children:n("cwdCancel")})]}):e.jsxs("button",{type:"button",className:"cwd-newbtn",onClick:()=>g(!0),children:["+ ",n("cwdNewFolder")]})})]})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:n("cwdTip",{path:r.cwd}),onClick:ne,children:["📁 ",r.cwd]})]})}function Ze(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function wl(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function Nl({dialog:t,send:s}){const n=xe(),[r,c]=l.useState(""),[i,a]=l.useState(0),o=y=>{s({type:"dialog_response",id:t.id,value:y})};l.useEffect(()=>{c(""),a(0);const y=g=>{g.key==="Escape"&&o(null)};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],m=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:n("pluginRequest")}),t.title&&t.title!==n("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((y,g)=>e.jsx("button",{type:"button",className:`dialog-option ${g===i?"sel":""}`,onMouseEnter:()=>a(g),onClick:()=>o(y),children:y},g)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:n("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:m}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:n("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:r,placeholder:m||n("inputPlaceholder"),autoFocus:!0,onChange:y=>c(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&o(r)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(r),children:n("ok")})]})]})]})}function Cl({question:t,send:s}){const n=xe(),[r,c]=l.useState({}),[i,a]=l.useState({}),[o,u]=l.useState(()=>t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1);l.useEffect(()=>{c({}),a({}),u(t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1)},[t.id,t.deadline]),l.useEffect(()=>{if(!t.deadline)return;const x=setInterval(()=>{u(b=>{const E=Math.max(0,Math.ceil((t.deadline-Date.now())/1e3));return E<=0&&b>0&&s({type:"question_answer",id:t.id,answers:[],cancelled:!0}),E})},1e3);return()=>clearInterval(x)},[t.id,t.deadline]);const m=x=>{if(x){s({type:"question_answer",id:t.id,answers:[],cancelled:!0});return}const b=t.questions.map(E=>{const A=r[E.id]??[],H=(i[E.id]??"").trim();return{id:E.id,selected:A,...H?{custom:H}:{}}});s({type:"question_answer",id:t.id,answers:b})};l.useEffect(()=>{const x=b=>{b.key==="Escape"&&m(!0)};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[t.id]);const y=(x,b,E)=>{c(A=>{const H=A[x]??[];return E?{...A,[x]:H.includes(b)?H.filter(S=>S!==b):[...H,b]}:{...A,[x]:[b]}})},g=t.questions.every(x=>{var b;return(((b=r[x.id])==null?void 0:b.length)??0)>0||(i[x.id]??"").trim()!==""});return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":"select",children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:n("modelQuestion")}),o>=0&&e.jsx("span",{className:"question-timer",children:o>0?n("questionTimeout",{s:o}):n("questionTimeoutExpired")}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>m(!0),children:"✕"})]}),t.questions.map((x,b)=>{var E;return e.jsxs("div",{className:"set-section",children:[e.jsx("div",{className:"set-section-title",children:x.header??`${n("modelQuestion")} ${b+1}`}),e.jsx("p",{className:"set-row-desc",children:x.question}),x.detail&&e.jsx("p",{className:"set-hint",children:x.detail}),(((E=x.options)==null?void 0:E.length)??0)>0&&e.jsx("div",{className:"set-list",children:x.options.map(A=>{const H=(r[x.id]??[]).includes(A.label);return e.jsxs("button",{type:"button",className:`set-row question-option${H?" active":""}`,onClick:()=>y(x.id,A.label,!!x.multiSelect),children:[e.jsxs("span",{className:"set-row-name",children:[x.multiSelect?H?"☑ ":"☐ ":H?"● ":"○ ",A.label]}),A.description&&e.jsx("span",{className:"set-row-desc",children:A.description})]},A.label)})}),e.jsx("input",{className:"set-prompt-input question-custom",placeholder:n("modelQuestionCustom"),value:i[x.id]??"",onChange:A=>a(H=>({...H,[x.id]:A.target.value}))})]},x.id)}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"dialog-submit",disabled:!g,onClick:()=>m(!1),children:n("modelQuestionSubmit")}),e.jsx("button",{type:"button",className:"dialog-dismiss-inline",onClick:()=>m(!0),children:n("cancel")})]})]})}const ln=t=>`'${t.replace(/'/g,"'\\''")}'`;function Sl(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",n=t.y!==" "&&t.y!=="?";return s&&n?"both":s?"staged":"unstaged"}function Tl({chat:t,send:s,terminal:n,active:r,onSwitchToTerminal:c}){var Be,De;const i=xe(),[a,o]=l.useState(null),[u,m]=l.useState([]),[y,g]=l.useState(""),[x,b]=l.useState(new Map),[E,A]=l.useState("changes"),[H,S]=l.useState([]),[j,J]=l.useState(null),[Q,X]=l.useState(""),[U,K]=l.useState(!1),[q,Y]=l.useState(null),[T,P]=l.useState(null),[k,B]=l.useState(!1),[Z,G]=l.useState(!1),[M,I]=l.useState(!1),[C,$]=l.useState(null),[z,ne]=l.useState(!1),[v,D]=l.useState(""),d=l.useRef(0),w=l.useRef(-1),h=l.useRef(-1),L=l.useRef(-1),ee=l.useRef(-1),W=l.useRef(void 0),ae=l.useRef(null),ye=l.useRef([]),be=l.useCallback(R=>{if(R.reqId===w.current){if(w.current=-1,G(!1),$(null),!R.ok){$(R.error??i("scmQueryFailedShort"));return}if(R.notRepo){ne(!0),o(null),m([]),b(new Map),S([]),J(null),X(""),P(null);return}ne(!1);const fe={branch:R.branch??"",detached:!!R.detached,upstream:R.upstream??null,ahead:R.ahead??0,behind:R.behind??0,upstreamGone:!!R.upstreamGone,files:(R.files??[]).map(V=>({...V}))},oe=(R.branches??[]).map(V=>({...V})),p=new Map;for(const[V,N]of Object.entries(R.stats??{}))p.set(V,{add:N[0],del:N[1]});o(fe),m(oe),b(p),g(V=>{var N;return fe.detached?V||"":fe.branch&&oe.some(_=>_.name===fe.branch)?fe.branch:V&&oe.some(_=>_.name===V)?V:((N=oe[0])==null?void 0:N.name)??""}),P(V=>V&&!fe.files.some(N=>N.path===V.file.path)?null:V)}else if(R.reqId===h.current){if(h.current=-1,B(!1),!R.ok){$(R.error??i("scmQueryFailedShort"));return}const fe=ae.current;if(!fe)return;P({file:fe,staged:R.stagedText??"",worktree:R.worktreeText??"",untracked:!1})}else if(R.reqId===ee.current){if(ee.current=-1,I(!1),!R.ok){$(R.error??i("scmQueryFailedShort"));return}S((R.history??[]).map(fe=>({...fe})))}else if(R.reqId===L.current){if(L.current=-1,K(!1),!R.ok){$(R.error??i("scmQueryFailedShort"));return}X(R.text??"")}},[]);l.useEffect(()=>{const R=t.scmData;R&&R.type==="scm_data"&&be(R)},[t.scmData,be]);const ge=l.useCallback((R,fe)=>{if(!t.ready||t.status!=="open")return!1;const oe=++d.current;return s({...R,reqId:oe})?(fe.current=oe,!0):(d.current-=1,!1)},[t.ready,t.status,s]),ke=l.useCallback((R=!1,fe=!1)=>{var oe;!t.ready||t.status!=="open"||(oe=t.state)!=null&&oe.cwd&&(W.current!==void 0&&W.current!==t.state.cwd&&(o(null),m([]),b(new Map),S([]),I(!1),ee.current=-1,J(null),X(""),P(null),Y(null)),W.current=t.state.cwd,$(null),ge({type:"scm_status"},w)&&(fe||G(!0)))},[t.ready,(Be=t.state)==null?void 0:Be.cwd,t.status,ge]),Ee=l.useCallback(R=>{if(Y(R),J(null),ae.current=R,R.x==="?"&&R.y==="?"){P({file:R,staged:"",worktree:"",untracked:!0});return}B(!0),$(null),ge({type:"scm_filediff",path:R.path},h)||B(!1)},[ge]),re=l.useCallback(R=>{J(R),Y(null),P(null),X(""),K(!0),$(null),ge({type:"scm_commit",hash:R.hash},L)||K(!1)},[ge]),f=l.useCallback((R,fe)=>{var N,_;if(!t.ready)return;const oe={name:R,command:fe,cwd:"${pwd}"};let p;const V=t.terminals.find(ie=>ie.title===R);V?(n.restart(V.id),s({type:"run_command",terminalId:V.id,conversationId:V.conversationId,command:oe,cols:80,rows:24}),p=V.id):(p=Ue(),n.create({id:p,conversationId:t.activeConversationId||((N=t.state)==null?void 0:N.conversationId)||"",title:R,cwd:((_=t.state)==null?void 0:_.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:oe})),n.select(p),c()},[t.ready,(De=t.state)==null?void 0:De.cwd,t.terminals,c,s,n]),O=l.useCallback(()=>{const R=v.trim();if(!R||z)return;const fe=R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");f("git commit",`git commit -m "${fe}"`),D("")},[v,z,f]),de=l.useCallback(()=>{const R=v.trim();if(!R||z)return;const fe=R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");f("git commit",`git add -A && git commit -m "${fe}"`),D("")},[v,z,f]),ue=l.useCallback(R=>{z||f("git add",`git add -- ${ln(R.path)}`)},[z,f]),me=l.useCallback(R=>{z||f("git reset",`git reset HEAD -- ${ln(R.path)}`)},[z,f]),pe=l.useCallback(()=>{if(!y||z)return;const R=u.find(fe=>fe.name===y);if(R!=null&&R.remote&&typeof R.remote=="string"){const fe=y.slice(R.remote.length+1);f("git checkout",`git checkout -b ${fe} ${y} || git checkout ${y}`)}else f("git checkout",`git checkout ${y}`)},[y,u,z,f]),ve=l.useCallback(()=>f("git push","git push"),[f]),Me=l.useCallback(()=>f("git pull","git pull"),[f]),he=l.useCallback(()=>{ge({type:"scm_history"},ee)||(ee.current=-1)},[ge]);l.useEffect(()=>{r&&ke()},[r,ke]),l.useEffect(()=>{E==="history"&&a&&he()},[E,a,he]),l.useEffect(()=>{t.scmDirty>0&&r&&ke(!1,!0)},[t.scmDirty]),l.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const R=setInterval(()=>{document.visibilityState!=="hidden"&&ke(!1,!0)},3e4);return()=>clearInterval(R)},[r,t.ready,t.status,ke]),l.useEffect(()=>{const R=ye.current;if(ye.current=t.terminals,!r)return;t.terminals.some(oe=>{var V;return oe.running!==!1?!1:((V=R.find(N=>N.id===oe.id))==null?void 0:V.running)===!0&&oe.title.startsWith("git ")})&&t.ready&&t.status==="open"&&(ke(!1,!0),E==="history"&&a&&he())},[t.terminals,r,t.ready,t.status,ke,E,a,he]);const _e={staged:i("scmStaged"),unstaged:i("scmUnstaged"),untracked:i("scmUntracked"),both:i("scmStagedUnstaged")},Le=R=>{const fe=R.split(`
324
- `);return e.jsx("pre",{className:"scm-diff-pre",children:fe.map((oe,p)=>{let V="";return oe.startsWith("diff --git")||oe.startsWith("index ")||oe.startsWith("new file")||oe.startsWith("deleted file")||oe.startsWith("old mode")||oe.startsWith("new mode")||oe.startsWith("similarity index")||oe.startsWith("rename ")||oe.startsWith("copy ")||oe.startsWith("Binary files")||oe.startsWith("---")||oe.startsWith("+++")?V="hdr":oe.startsWith("@@")?V="hunk":oe.startsWith("+")?V="add":oe.startsWith("-")&&(V="del"),e.jsx("div",{className:`scm-diff-line ${V}`,children:oe||" "},p)})})};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(yt,{}),i("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":E==="changes",className:E==="changes"?"active":"",onClick:()=>{A("changes"),$(null)},children:i("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":E==="history",className:E==="history"?"active":"",onClick:()=>{A("history"),$(null)},children:i("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:i("scmRefreshTip"),disabled:Z,onClick:()=>ke(!0),children:e.jsx(rt,{className:Z?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:i("scmCurrentBranch"),children:[e.jsx(yt,{}),a?a.detached?i("scmDetached"):a.branch:"…",(a==null?void 0:a.upstream)&&e.jsx("span",{className:"scm-upstream",children:a.upstreamGone?i("scmUpstreamGone"):a.ahead>0||a.behind>0?i("scmAheadBehind",{ahead:a.ahead,behind:a.behind}):a.upstream})]}),e.jsxs("select",{className:"scm-select",value:y,disabled:z||u.length===0,title:i("scmSwitchBranch"),onChange:R=>g(R.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:i("scmSelectBranch")}),u.filter(R=>!R.remote).map(R=>e.jsx("option",{value:R.name,children:R.current?`* ${R.name}`:R.name},R.name)),u.some(R=>R.remote)&&e.jsx("optgroup",{label:i("scmRemoteBranches"),children:u.filter(R=>R.remote).map(R=>e.jsx("option",{value:R.name,children:R.name},R.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!y||y===(a==null?void 0:a.branch)||z,title:i("scmSwitchBranchTip",{branch:y}),onClick:pe,children:[e.jsx(yt,{}),i("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||z,title:i("scmPushTip"),onClick:ve,children:[e.jsx(Cn,{}),i("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!a||a.detached||z,title:i("scmPullTip"),onClick:Me,children:[e.jsx(Sn,{}),i("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:v,placeholder:i("scmCommitPlaceholder"),disabled:z,onChange:R=>D(R.target.value),onKeyDown:R=>{R.key==="Enter"&&!R.nativeEvent.isComposing&&O()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!v.trim()||z,title:i("scmCommitTip"),onClick:O,children:[e.jsx(pt,{}),i("scmCommit")]}),e.jsx("button",{type:"button",className:"btn",disabled:!v.trim()||z,title:i("scmCommitAllTip"),onClick:de,children:i("scmCommitAll")})]})]}),e.jsxs("div",{className:"scm-body",children:[E==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:i("scmHistory")}),H.length>0&&e.jsx("span",{className:"scm-files-count",children:H.length})]}),e.jsx("div",{className:"scm-history-list",children:z?e.jsx("div",{className:"scm-empty",children:i("scmNotGitRepo")}):!a||M?e.jsx("div",{className:"scm-empty",children:t.status==="open"?i("scmLoading"):i("scmConnecting")}):H.length===0?e.jsx("div",{className:"scm-empty",children:i("scmNoHistory")}):H.map(R=>e.jsxs("button",{type:"button",className:`scm-commit ${(j==null?void 0:j.hash)===R.hash?"active":""}`,onClick:()=>re(R),title:R.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:R.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:R.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[R.shortHash," · ",R.author," · ",R.date]}),R.decorations&&e.jsx("span",{className:"scm-commit-refs",children:R.decorations})]})]},R.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:i("scmChanges")}),a&&a.files.length>0&&e.jsx("span",{className:"scm-files-count",children:a.files.length})]}),e.jsx("div",{className:"scm-files-list",children:z?e.jsx("div",{className:"scm-empty",children:i("scmNotGitRepo")}):a?a.files.length===0?e.jsx("div",{className:"scm-empty",children:i("scmNoChanges")}):a.files.map(R=>{const fe=Sl(R),oe=x.get(R.path);return e.jsxs("div",{className:`scm-file ${(q==null?void 0:q.path)===R.path?"active":""}`,title:_e[fe],onClick:()=>Ee(R),children:[e.jsx("span",{className:`scm-file-xy ${fe==="untracked"?"q":"x"}`,children:R.x!==" "?R.x:" "}),e.jsx("span",{className:`scm-file-xy ${fe==="untracked"?"q":"y"}`,children:R.y!==" "?R.y:" "}),e.jsx("span",{className:"scm-file-path",children:R.path}),oe&&(oe.add>0||oe.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[oe.add>0&&e.jsxs("span",{className:"add",children:["+",oe.add]}),oe.del>0&&e.jsxs("span",{className:"del",children:["-",oe.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(R.y!==" "||fe==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:i("scmStageTip",{path:R.path}),onClick:p=>{p.stopPropagation(),ue(R)},children:"+"}),fe==="staged"||fe==="both"?e.jsx("button",{type:"button",className:"scm-act",title:i("scmUnstageTip",{path:R.path}),onClick:p=>{p.stopPropagation(),me(R)},children:"−"}):null]})]},R.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:E==="history"?j?`${j.shortHash} ${j.subject}`:i("scmCommitDetail"):q?q.path:i("scmDiff")}),(E==="history"?U:k)&&e.jsx("span",{className:"scm-diff-loading",children:i("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:E==="history"?e.jsxs(e.Fragment,{children:[C&&e.jsx("div",{className:"scm-error",children:C}),!j&&!C&&e.jsx("div",{className:"scm-empty",children:i("scmSelectCommitHint")}),j&&U&&!C&&e.jsx("div",{className:"scm-empty",children:i("scmLoading")}),j&&!U&&!C&&Q?Le(Q):null]}):e.jsxs(e.Fragment,{children:[C&&e.jsx("div",{className:"scm-error",children:C}),!q&&!C&&e.jsx("div",{className:"scm-empty",children:i("scmSelectFileHint")}),q&&!T&&!C&&e.jsx("div",{className:"scm-empty",children:i("scmLoading")}),q&&T&&T.untracked&&e.jsx("div",{className:"scm-empty",children:i("scmUntrackedNote")}),q&&T&&!T.untracked&&e.jsxs(e.Fragment,{children:[T.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:i("scmStaged")}),Le(T.staged)]}),T.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:i("scmUnstaged")}),Le(T.worktree)]}),!T.staged&&!T.worktree&&e.jsx("div",{className:"scm-empty",children:i("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(tt,{}),e.jsx("span",{children:i("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:i("scmViewTerminal")})]})]})}function El({entry:t,send:s}){const n=l.useRef(null),r=xe();return l.useEffect(()=>{const c=n.current;if(!c)return;let i;try{i=t.module.mount(c,Ca(t.info.id,a=>s(a)))}catch(a){console.error(`[plugin:${t.info.id}] mount failed:`,a),c.textContent=r("pluginMountFailed",{name:t.info.name})}return()=>{if(typeof i=="function")try{i()}catch(a){console.error(`[plugin:${t.info.id}] cleanup failed:`,a)}c.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:n})}function Pl({send:t,piConfigured:s,piAgentInstalled:n,providers:r,installResult:c,onClose:i}){const a=xe(),[o,u]=l.useState(!1),[m,y]=l.useState(""),[g,x]=l.useState(""),[b,E]=l.useState(!1);l.useEffect(()=>{t({type:"list_providers"})},[t]),l.useEffect(()=>{s&&i()},[s,i]),l.useEffect(()=>{c&&u(!1)},[c]),l.useEffect(()=>{var Q;!m&&r.length>0&&y(((Q=r.find(X=>!X.configured))==null?void 0:Q.id)??r[0].id)},[r,m]);const A=()=>{o||(u(!0),t({type:"install_pi_agent"}))},H=()=>{!g.trim()||b||(E(!0),t({type:"set_provider_api_key",provider:m.trim(),apiKey:g.trim()}),setTimeout(()=>E(!1),3e3))},S=()=>{t({type:"get_state"}),t({type:"list_providers"})},j=r.find(Q=>Q.id===m),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":a("close"),onClick:i,children:e.jsx(Pe,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(lt,{className:"modal-head-icon"}),e.jsx("h2",{children:a("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:a("setupDesc")}),J?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:a("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:A,children:a("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:i,children:a("skip")})]})]}):n||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?a("installDone"):a("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:a("provider")}),e.jsxs("select",{value:m,onChange:Q=>y(Q.target.value),children:[r.length===0&&e.jsx("option",{value:"",children:a("loading")}),r.map(Q=>e.jsxs("option",{value:Q.id,children:[Q.name,"(",Q.id,")",Q.configured?` · ${a("configured")}`:""]},Q.id))]}),(j==null?void 0:j.configured)&&e.jsx("div",{className:"field-hint",children:a("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:a("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:Q=>x(Q.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||b||!m,onClick:H,children:a(b?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:S,children:[e.jsx(rt,{})," ",a("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:A,children:a(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:i,children:a("skip")})]})]})})}const Ml=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],ps=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Rl=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[ps()]});function qt(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:[ps()]).map(s=>{var n;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(n=s.input)!=null&&n.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function Il({send:t,providers:s,providerStatus:n,providerKeys:r,fetchModelsResult:c,cloneProviderResult:i,onClose:a}){const o=xe(),[u,m]=l.useState(null),[y,g]=l.useState({}),[x,b]=l.useState({}),[E,A]=l.useState(null),[H,S]=l.useState(!1),[j,J]=l.useState(0),[Q,X]=l.useState(null),U=l.useRef(0),[K,q]=l.useState(null),[Y,T]=l.useState(""),[P,k]=l.useState(null);l.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"}),t({type:"list_provider_keys"})},[t]);const B=()=>{if(!u)return;const v=u.baseUrl.trim();if(!v){X({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(H)return;S(!0),X(null);const D=j+1;J(D),t({type:"fetch_models",reqId:D,baseUrl:v,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};l.useEffect(()=>{var v;if(!(!c||c.reqId===U.current))if(U.current=c.reqId,S(!1),c.ok&&((v=c.models)!=null&&v.length)){const D=c.models;m(d=>{if(!d)return d;const w=d.models.map(W=>{var be;if(!W.id.trim())return W;const ae=D.find(ge=>ge.id===W.id.trim());if(!ae)return W;const ye={...W};return!ye.name&&ae.name&&(ye.name=ae.name),!ye.contextWindow&&ae.contextWindow&&(ye.contextWindow=String(ae.contextWindow)),!ye.maxTokens&&ae.maxTokens&&(ye.maxTokens=String(ae.maxTokens)),ye.input==="text"&&((be=ae.input)!=null&&be.includes("image"))&&(ye.input="text-image"),!ye.reasoning&&ae.reasoning&&(ye.reasoning=!0),ye}),h=new Set(w.map(W=>W.id.trim()).filter(Boolean)),L=D.filter(W=>!h.has(W.id)).map(W=>{var ae;return{id:W.id,name:W.name??"",reasoning:W.reasoning??!1,input:(ae=W.input)!=null&&ae.includes("image")?"text-image":"text",contextWindow:W.contextWindow?String(W.contextWindow):"",maxTokens:W.maxTokens?String(W.maxTokens):""}}),ee=[...w,...L];return ee.some(W=>W.id.trim())?{...d,models:ee.filter(W=>W.id.trim())}:d}),X({ok:!0,text:o("fetchModelsOk",{n:D.length})})}else X({ok:!1,text:c.error||o("fetchModelsEmpty")})},[c]);const Z=v=>{const D=(y[v.id]??"").trim();!D||E||(A(v.id),t({type:"add_provider_key",provider:v.id,apiKey:D,name:(x[v.id]??"").trim()||void 0}),setTimeout(()=>{A(null),g(d=>({...d,[v.id]:""})),b(d=>({...d,[v.id]:""})),t({type:"list_providers"}),t({type:"list_provider_keys"})},1500))},G=(v,D)=>{t({type:"activate_provider_key",provider:v,keyName:D}),t({type:"list_provider_keys"})},M=(v,D)=>{window.confirm(o("removeKeyConfirm"))&&(t({type:"remove_provider_key",provider:v,keyName:D}),t({type:"list_provider_keys"}))},I=()=>{if(!P)return;const v=P.providerId.trim();if(!v||!P.apiKey.trim())return;const D=P.models.filter(w=>w.id.trim()).map(w=>({id:w.id.trim(),name:w.name.trim()||void 0,reasoning:w.reasoning||void 0,input:w.input==="text-image"?["text","image"]:void 0,contextWindow:w.contextWindow?Number(w.contextWindow):void 0,maxTokens:w.maxTokens?Number(w.maxTokens):void 0})),d={providerId:v,name:P.name.trim()||void 0,api:P.api.trim()||void 0,baseUrl:P.baseUrl.trim()||void 0,apiKey:P.apiKey.trim()||void 0,authHeader:P.authHeader||void 0,models:D};t({type:"save_model_config",providerId:v,config:d}),k(null),a()},C=()=>{if(!u)return;const v=u.providerId.trim(),D=u.models.filter(w=>w.id.trim()).map(w=>({id:w.id.trim(),name:w.name.trim()||void 0,reasoning:w.reasoning||void 0,input:w.input==="text-image"?["text","image"]:void 0,contextWindow:w.contextWindow?Number(w.contextWindow):void 0,maxTokens:w.maxTokens?Number(w.maxTokens):void 0})),d={providerId:v,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:D};t({type:"save_model_config",providerId:v,config:d}),a()};l.useEffect(()=>{if(i&&i.ok){const v=i.configs;if(v&&v.length>1){q(v.map(D=>qt({...D,apiKey:""}))),T("");return}if(i.config){k(qt({...i.config,apiKey:""}));return}}},[i]);const $=v=>{window.confirm(o("clearKeyConfirm",{id:v}))&&t({type:"clear_provider_api_key",provider:v})},z=v=>{window.confirm(o("deleteProviderConfirm",{id:v.providerId,n:v.models.length}))&&t({type:"delete_model_config",providerId:v.providerId})},ne=(v,D)=>{u&&m({...u,models:u.models.map((d,w)=>w===v?{...d,...D}:d)})};return e.jsx("div",{className:"modal-backdrop",onClick:a,children:e.jsxs("div",{className:"modal model-modal",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:a,children:e.jsx(Pe,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:P?o("addKey"):K?o("batchCreateProviders",{n:K.length}):o(u?"editProvider":"manageModelsTitle")})}),P?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("secondKeyTitle",{api:P.api,baseUrl:P.baseUrl||o("noBaseUrlShort"),n:P.models.length})}),e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerNameLabel")," ",e.jsx("em",{children:o("providerNameHint")})]}),e.jsx("input",{type:"text",value:P.providerId,onChange:v=>k({...P,providerId:v.target.value}),placeholder:"opencode-2"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKeyLabel")}),e.jsx("input",{type:"password",value:P.apiKey,onChange:v=>k({...P,apiKey:v.target.value}),placeholder:o("secondKeyPlaceholder")})]})]}),e.jsxs("div",{style:{fontSize:12,opacity:.6,marginTop:8},children:[P.models.slice(0,5).map(v=>v.id).join(", "),P.models.length>5?` … +${P.models.length-5}`:""]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>k(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn",onClick:()=>{const v=P;k(null),m(v)},children:o("advancedEdit")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!P.providerId.trim()||!P.apiKey.trim(),onClick:I,children:o("save")})]})]}):K?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("batchDesc",{apis:K.map(v=>v.api).join("、"),n:K.length})}),e.jsxs("label",{className:"field",style:{marginBottom:16},children:[e.jsx("span",{className:"field-label",children:o("batchKeyLabel",{n:K.length})}),e.jsx("input",{type:"password",value:Y,onChange:v=>T(v.target.value),placeholder:o("secondKeyPlaceholder")})]}),e.jsx("div",{className:"provider-list",style:{marginBottom:16},children:K.map((v,D)=>e.jsxs("div",{className:"provider-row",style:{flexDirection:"column",alignItems:"stretch",gap:6},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:13},children:[e.jsx("strong",{children:v.providerId}),e.jsx("span",{style:{opacity:.7},children:v.api})]}),e.jsxs("div",{className:"provider-sub",style:{fontSize:12,opacity:.7},children:[v.baseUrl||o("noBaseUrlShort")," · ",o("modelsCountShort",{n:v.models.length}),v.models.slice(0,3).map(d=>d.id).join(", "),v.models.length>3?` … +${v.models.length-3}`:""]}),e.jsx("input",{type:"text",value:v.providerId,onChange:d=>q(w=>w.map((h,L)=>L===D?{...h,providerId:d.target.value}:h)),placeholder:o("providerIdPlaceholder"),style:{fontSize:12}}),e.jsx("input",{type:"text",value:v.baseUrl,onChange:d=>q(w=>w.map((h,L)=>L===D?{...h,baseUrl:d.target.value}:h)),placeholder:o("baseUrlExamplePh"),style:{fontSize:12}})]},D))})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>q(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!Y.trim(),onClick:()=>{for(const v of K){const D=v.providerId.trim();if(!D)continue;const d=v.models.filter(h=>h.id.trim()).map(h=>({id:h.id.trim(),name:h.name.trim()||void 0,reasoning:h.reasoning||void 0,input:h.input==="text-image"?["text","image"]:void 0,contextWindow:h.contextWindow?Number(h.contextWindow):void 0,maxTokens:h.maxTokens?Number(h.maxTokens):void 0})),w={providerId:D,name:v.name.trim()||void 0,api:v.api.trim()||void 0,baseUrl:v.baseUrl.trim()||void 0,apiKey:Y.trim()||void 0,authHeader:v.authHeader||void 0,models:d};t({type:"save_model_config",providerId:D,config:w})}q(null),a()},children:o("saveAllBatch",{n:K.length})})]})]}):u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children: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(v=>v.providerId===u.providerId),onChange:v=>m({...u,providerId:v.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:v=>m({...u,name:v.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:v=>m({...u,api:v.target.value}),children:Ml.map(v=>e.jsx("option",{value:v,children:v},v))})]}),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:v=>m({...u,baseUrl:v.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:v=>m({...u,apiKey:v.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:v=>m({...u,authHeader:v.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:[Q&&e.jsx("span",{className:`fetch-msg ${Q.ok?"ok":"err"}`,title:Q.text,children:Q.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:H||!u.baseUrl.trim(),title:o("fetchModelsHint"),onClick:B,children:[e.jsx(ls,{})," ",o(H?"fetchingModels":"fetchModels")]})]})]}),u.models.map((v,D)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:v.id,onChange:d=>ne(D,{id:d.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:v.name,onChange:d=>ne(D,{name:d.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:v.input,onChange:d=>ne(D,{input:d.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:v.reasoning,onChange:d=>ne(D,{reasoning:d.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:v.contextWindow,onChange:d=>ne(D,{contextWindow:d.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:v.maxTokens,onChange:d=>ne(D,{maxTokens:d.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>m({...u,models:u.models.filter((d,w)=>w!==D)}),children:e.jsx(Ae,{})})]},D)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>m({...u,models:[...u.models,ps()]}),children:[e.jsx(He,{})," ",o("addModel")]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>m(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(v=>v.id.trim()),onClick:C,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-fixed-hint",children:e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]})}),e.jsxs("div",{className:"model-modal-body",children:[e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.map(v=>{const D=r[v.id]??[];return e.jsxs("div",{className:"provider-row provider-key-row",children:[e.jsxs("div",{className:"provider-key-head",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.name}),e.jsxs("span",{className:"provider-sub",children:[v.id,v.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),v.source&&!v.configured&&e.jsx("span",{className:"auth-badge dim",children:v.source})]})]}),v.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>$(v.id),children:[e.jsx(Ae,{})," ",o("clearKey")]})]}),e.jsxs("div",{className:"provider-keys",children:[D.length===0&&e.jsx("div",{className:"provider-key-empty",children:o("noKeyYet")}),D.map(d=>e.jsxs("div",{className:`provider-key-item ${d.active?"active":""}`,children:[e.jsx("span",{className:"provider-key-dot",children:d.active?"●":"○"}),e.jsx("span",{className:"provider-key-label",children:d.name}),!d.active&&e.jsx("button",{type:"button",className:"iconbtn",title:o("activateKey"),onClick:()=>G(v.id,d.name),children:e.jsx(pt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeKey"),onClick:()=>M(v.id,d.name),children:e.jsx(Ae,{})})]},d.name)),e.jsxs("div",{className:"provider-add-key",children:[e.jsx("input",{type:"text",className:"key-input key-input-name",placeholder:o("keyNamePh"),value:x[v.id]??"",onChange:d=>b(w=>({...w,[v.id]:d.target.value}))}),e.jsx("input",{type:"password",className:"key-input key-input-value",placeholder:o("addKeyPlaceholder"),value:y[v.id]??"",onChange:d=>g(w=>({...w,[v.id]:d.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(y[v.id]??"").trim()||E===v.id,onClick:()=>Z(v),children:[e.jsx(He,{})," ",E===v.id?o("savingKey"):o("addKey")]})]})]})]},v.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(v=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.providerId}),e.jsxs("span",{className:"provider-sub",children:[v.api??"—",v.baseUrl?` · ${v.baseUrl}`:"",v.models.length>0&&` · ${o("modelsCount",{n:v.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>m(qt(v)),children:e.jsx(St,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>z(v),children:e.jsx(Ae,{})})]})]},v.providerId))})]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>m(Rl()),children:[e.jsx(He,{})," ",o("addProvider")]})})]})]})})}function Ll({plugin:t,send:s}){const n=xe(),r=t.settingsSchema??[],[c,i]=l.useState(()=>({...t.settingsValues})),[a,o]=l.useState(!1);if(r.length===0)return null;const u=(x,b)=>i(E=>({...E,[x]:b})),m=r.some(x=>{var b;return c[x.key]!==((b=t.settingsValues)==null?void 0:b[x.key])}),y=()=>{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:r.map(x=>e.jsxs("label",{className:"plugin-settings-field",title:x.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:x.label}),x.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[x.key],onChange:b=>u(x.key,b.target.checked)}):x.type==="select"?e.jsx("select",{value:String(c[x.key]??""),onChange:b=>u(x.key,b.target.value),children:(x.options??[]).map(b=>e.jsx("option",{value:b,children:b},b))}):e.jsx("input",{type:x.type==="password"?"password":x.type==="number"?"number":"text",value:String(c[x.key]??""),min:x.min,max:x.max,onChange:b=>u(x.key,x.type==="number"?Number(b.target.value):b.target.value)})]},x.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!m||a,onClick:y,children:n(a?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:g,children:n("pluginSettingsReset")})]})]})}function Dl(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Ke({text:t}){const s=l.useRef(null),[n,r]=l.useState(!1),c=()=>{var a;const i=(a=s.current)==null?void 0:a.getBoundingClientRect();i&&r(window.innerWidth-i.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${n?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Re({title:t,subtitle:s,tip:n,enabled:r,onToggle:c,action:i}){const a=xe();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,n&&e.jsx(Ke,{text:n})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),i,e.jsx("button",{type:"button",className:`set-switch ${r?"on":""}`,role:"switch","aria-checked":r,title:a(r?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Al({chat:t,send:s,terminal:n,onSwitchToTerminal:r,onClose:c}){var Le,Be,De,R,fe,oe;const i=xe(),a=t.settings,o=t.engine==="dsh",[u,m]=l.useState("prompt"),y=l.useRef(null);l.useEffect(()=>{var p;(p=y.current)==null||p.scrollTo({top:0})},[u]),l.useEffect(()=>{u==="plugins"&&t.engine==="dsh"&&s({type:"dsh_patches_list"})},[u,t.engine,s]);const[g,x]=l.useState(""),[b,E]=l.useState("append"),A=l.useRef(!1),[H,S]=l.useState(""),[j,J]=l.useState("append"),Q=l.useRef(!1),[X,U]=l.useState(""),K=l.useRef(!1),[q,Y]=l.useState(""),[T,P]=l.useState(null),[k,B]=l.useState(null),[Z,G]=l.useState(!1),M=Hn(),[I,C]=l.useState(()=>ni()),[$,z]=l.useState(()=>{try{return dt().length}catch{return 0}}),[ne,v]=l.useState(!1),D=()=>{try{z(dt().length)}catch{z(0)}};l.useEffect(()=>{u==="prompt-history"&&D()},[u]),l.useEffect(()=>{if(!ne)return;const p=window.setTimeout(()=>v(!1),3e3);return()=>window.clearTimeout(p)},[ne]);const[d,w]=l.useState(null),[h,L]=l.useState(null);l.useEffect(()=>{a&&(E(a.promptMode),!A.current&&(x(b==="append"||a.customSystemPrompt?a.customSystemPrompt:a.defaultSystemPrompt||""),J(a.visionBridgePromptMode),!Q.current&&(S(j==="append"||a.visionBridgePrompt?a.visionBridgePrompt:a.visionBridgeDefaultPrompt||""),K.current||U(a.reviewPrompt))))},[a,b,j]);const[ee,W]=l.useState(String((a==null?void 0:a.terminalBashIdleMs)??15e3));if(l.useEffect(()=>{W(String((a==null?void 0:a.terminalBashIdleMs)??15e3))},[a==null?void 0:a.terminalBashIdleMs]),!a)return null;const ae=[{id:"prompt",icon:e.jsx(kn,{}),label:i("settingsSystemPrompt")},{id:"prompt-history",icon:e.jsx(_s,{}),label:i("settingsPromptHistory"),count:$},{id:"terminal",icon:e.jsx(tt,{}),label:i("settingsTerminalTools")},{id:"display",icon:e.jsx(st,{}),label:i("settingsMessageDisplay")},{id:"markers",icon:e.jsx(Ls,{}),label:i("settingsMarkers"),count:((Le=a.markers)==null?void 0:Le.length)??0},{id:"skills",icon:e.jsx(lt,{}),label:i("settingsSkills"),count:a.skills.length},{id:"extensions",icon:e.jsx(Ds,{}),label:i("settingsExtensions"),count:a.extensions.length},{id:"plugins",icon:e.jsx(Lt,{}),label:i("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(xt,{}),label:i("settingsReview"),count:a.reviewSkills.length},...o?[]:[{id:"vision",icon:e.jsx(Qt,{}),label:i("settingsVisionBridge")}],{id:"presets",icon:e.jsx(Di,{}),label:i("settingsPresets"),count:a.presets.length},...o?[]:[{id:"subagent-templates",icon:e.jsx(Rs,{}),label:i("settingsSubagentTemplates"),count:a.subagentTemplates.length}]],ye=new Set(a.disabledSkills),be=new Set(a.disabledExtensions),ge=p=>s({type:"set_settings",...p}),ke=p=>{const V=new Set(ye);V.has(p.name)?V.delete(p.name):V.add(p.name),ge({disabledSkills:[...V]})},Ee=new Set(a.disabledPlugins??[]),re=p=>{const V=new Set(Ee);V.has(p.id)?V.delete(p.id):V.add(p.id),ge({disabledPlugins:[...V]})},f=p=>{const V=new Set(be);V.has(p.id)?V.delete(p.id):V.add(p.id),ge({disabledExtensions:[...V]})},O=a.markersEnabled??!0,de=new Set(a.disabledMarkers??[]),ue=p=>{const V=new Set(de),N=p==="conv"||p==="rename"||p==="title"?["conv","rename","title"]:[p],_=!N.some(ie=>V.has(ie));for(const ie of N)_?V.add(ie):V.delete(ie);ge({disabledMarkers:[...V]})},me=(p,V)=>{var le,je;const N={name:p,command:V,cwd:"${pwd}"};let _;const ie=t.terminals.find(we=>we.title===p);ie?(n.restart(ie.id),s({type:"run_command",terminalId:ie.id,conversationId:ie.conversationId,command:N,cols:80,rows:24}),_=ie.id):(_=Ue(),n.create({id:_,conversationId:t.activeConversationId||((le=t.state)==null?void 0:le.conversationId)||"",title:p,cwd:((je=t.state)==null?void 0:je.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:N})),n.select(_),r(),c()},pe=p=>{w(null),me(`${i("uninstallTitle")} ${p}`,`pi remove npm:${p}`)},ve=p=>{L(null),me(`${i("uninstallTitle")} ${p}`,`pi-web-ui uninstall ${p}`)},Me=(p,V)=>{me(`${i("pluginUpdate")} ${p}`,`pi-web-ui install ${V} --name ${p} --force`)},he=p=>{const V=new Set(a.reviewSkills.filter(N=>!N.enabled).map(N=>N.name));V.has(p.name)?V.delete(p.name):V.add(p.name),ge({reviewDisabledSkills:[...V]})},_e=()=>{const p=b==="replace"&&a.defaultSystemPrompt&&g===a.defaultSystemPrompt?"":g;ge({promptMode:b,customSystemPrompt:p})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:p=>p.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":i("close"),onClick:c,children:e.jsx(Pe,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(wt,{className:"modal-head-icon"}),e.jsx("h2",{children:i("settingsTitle")}),e.jsx(Ke,{text:i("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":i("settingsTitle"),children:ae.map(p=>e.jsxs("button",{type:"button",className:`settings-tab${u===p.id?" active":""}`,"aria-current":u===p.id?"true":void 0,title:p.label,onClick:()=>m(p.id),children:[e.jsx("span",{className:"settings-tab-icon",children:p.icon}),e.jsx("span",{className:"settings-tab-label",children:p.label}),p.count!==void 0&&e.jsx("span",{className:"set-count",children:p.count})]},p.id))}),e.jsxs("div",{className:"modal-body",ref:y,children:[u==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{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:b,onChange:p=>{const V=p.target.value;E(V),ge({promptMode:V})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]}),e.jsx(Ke,{text:i(b==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:i("promptPlaceholder"),value:g,onFocus:()=>A.current=!0,onBlur:()=>{A.current=!1,_e()},onChange:p=>x(p.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":Z,onClick:()=>G(p=>!p),children:[i("settingsViewPrompt")," ",Z?"▴":"▾"]}),Z&&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(Tt,{text:a.effectiveSystemPrompt})]}),a.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:a.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:i("settingsViewPromptEmpty")})]})]}),u==="prompt-history"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(_s,{className:"set-section-icon"}),i("settingsPromptHistory"),e.jsx(Ke,{text:i("settingsPromptHistoryDesc")}),e.jsx("span",{className:"set-count",children:i("promptHistoryCount",{n:String($)})})]}),$===0?e.jsx("p",{className:"set-empty",children:i("promptHistoryEmpty")}):e.jsx("p",{className:"set-hint",children:i("promptHistoryCount",{n:String($)})}),e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"ph-max",children:i("promptHistoryMax")}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("input",{id:"ph-max",className:"set-input",type:"number",min:1,max:500,step:1,value:String(I.maxEntries),onChange:p=>{const V=Math.floor(Number(p.target.value)||0),N={...I,maxEntries:V};C(N)},onBlur:()=>{const p={...I};(!Number.isFinite(p.maxEntries)||p.maxEntries<1)&&(p.maxEntries=1),p.maxEntries>500&&(p.maxEntries=500),p.maxEntries=Math.floor(p.maxEntries),C(p),Ut(p),D()}}),e.jsx(Ke,{text:i("promptHistoryMaxHint")})]})]}),e.jsx(Re,{title:i("promptHistoryCharLimit"),tip:i("promptHistoryCharLimitHint"),enabled:I.charLimitEnabled,onToggle:()=>{const p={...I,charLimitEnabled:!I.charLimitEnabled};C(p),Ut(p),D()}}),I.charLimitEnabled&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"ph-char-limit",children:i("promptHistoryCharLimit")}),e.jsx("input",{id:"ph-char-limit",className:"set-input",type:"number",min:100,max:2e4,step:100,placeholder:i("promptHistoryCharLimitPlaceholder"),value:String(I.charLimit),onChange:p=>{const V=Math.floor(Number(p.target.value)||0);C({...I,charLimit:V})},onBlur:()=>{let p=Math.floor(Number(I.charLimit)||0);(!Number.isFinite(p)||p<100)&&(p=100),p>2e4&&(p=2e4);const V={...I,charLimit:p};C(V),Ut(V),D()}})]}),e.jsxs("div",{className:"set-field",style:{marginTop:12},children:[e.jsxs("button",{type:"button",className:`set-uninstall${ne?" confirm":""}`,disabled:$===0,title:i($===0?"promptHistoryEmpty":"promptHistoryClear"),onClick:()=>{if(!ne){v(!0);return}pl(),v(!1),D()},children:[e.jsx(Ae,{})," ",i(ne?"promptHistoryClearConfirm":"promptHistoryClear")]}),$>0&&e.jsx("span",{className:"set-hint",style:{marginLeft:8},children:i("promptHistoryCount",{n:String($)})})]}),e.jsxs("p",{className:"set-hint",children:[e.jsx(Zi,{style:{verticalAlign:"-2px",marginRight:4}}),i("settingsPromptHistoryDesc")]})]}),u==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(tt,{className:"set-section-icon"}),i("settingsTerminalTools")]}),e.jsx(Re,{title:i("terminalToolsEnabled"),tip:i("settingsTerminalToolsDesc"),enabled:a.terminalToolsEnabled,onToggle:()=>ge({terminalToolsEnabled:!a.terminalToolsEnabled})}),!a.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:i("terminalToolsOffHint")}),e.jsx(Re,{title:i("terminalBashTakeover"),tip:i("terminalBashTakeoverDesc"),enabled:a.terminalBash,onToggle:()=>ge({terminalBash:!a.terminalBash})}),a.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:ee,onChange:p=>W(p.target.value),onBlur:()=>{const p=Math.max(0,Math.floor(Number(ee)||0));W(String(p)),p!==a.terminalBashIdleMs&&ge({terminalBashIdleMs:p})}})]})]}),u==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(st,{className:"set-section-icon"}),i("settingsMessageDisplay")]}),e.jsx(Re,{title:i("thinkingWrap"),tip:i("thinkingWrapDesc"),enabled:a.thinkingWrap??!0,onToggle:()=>ge({thinkingWrap:!(a.thinkingWrap??!0)})}),e.jsx(Re,{title:i("toolsWrap"),tip:i("toolsWrapDesc"),enabled:a.toolsWrap??!0,onToggle:()=>ge({toolsWrap:!(a.toolsWrap??!0)})}),e.jsx("hr",{className:"set-sep"}),e.jsx(Re,{title:i("mermaidRenderSetting"),tip:i("mermaidRenderSettingDesc"),enabled:M,onToggle:()=>tr({enabled:!M})})]}),u==="markers"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ls,{className:"set-section-icon"}),i("settingsMarkers"),e.jsx(Ke,{text:i("settingsMarkersDesc")}),e.jsx("span",{className:"set-count",children:((Be=a.markers)==null?void 0:Be.length)??0})]}),e.jsx(Re,{title:i("markersEnabled"),tip:i("markersEnabledDesc"),enabled:O,onToggle:()=>ge({markersEnabled:!O})}),!O&&e.jsx("p",{className:"set-hint",children:i("markersOffHint")}),O&&(((De=a.markers)==null?void 0:De.length)??0)===0&&e.jsxs("p",{className:"set-empty",children:[i("loading"),"..."]}),O&&a.markers&&a.markers.length>0&&e.jsx("div",{className:"set-list",children:a.markers.map(p=>e.jsx(Re,{title:p.name==="todo"?i("markerGroupTodo"):p.name==="svc"?i("markerGroupSvc"):p.name==="notify"?i("markerGroupNotify"):p.name==="conv"||p.name==="rename"||p.name==="title"?i("markerGroupRename"):p.name,subtitle:(p.guidance[0]??"").slice(0,120),tip:p.guidance.join(`
325
- `),enabled:p.enabled,onToggle:()=>ue(p.name)},p.name))}),O&&e.jsx("p",{className:"set-hint",children:i("markerRenameTip")})]}),u==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(lt,{className:"set-section-icon"}),i("settingsSkills"),e.jsx("span",{className:"set-count",children:a.skills.length})]}),a.skills.length===0?e.jsx("p",{className:"set-empty",children:i(o?"dshSkillsNote":"noSkills")}):e.jsx("div",{className:"set-list",children:a.skills.map(p=>e.jsx(Re,{title:p.name,subtitle:p.description,enabled:p.enabled,onToggle:()=>ke(p)},p.name))})]}),u==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ds,{className:"set-section-icon"}),i("settingsExtensions"),e.jsx("span",{className:"set-count",children:a.extensions.length})]}),a.extensions.length===0?e.jsx("p",{className:"set-empty",children:i(o?"dshExtensionsNote":"noExtensions")}):e.jsx("div",{className:"set-list",children:a.extensions.map(p=>{const V=p.id.startsWith("npm:")?p.id.slice(4):null;return e.jsx(Re,{title:p.name,subtitle:p.path,enabled:p.enabled,onToggle:()=>f(p),action:V?d===p.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:i("uninstallConfirmHint"),onClick:()=>pe(V),children:i("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:i("uninstallHint"),onClick:()=>w(p.id),children:[e.jsx(Ae,{}),i("uninstallExt")]}):void 0},p.id)})})]}),u==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Lt,{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(p=>{var V;return e.jsxs(e.Fragment,{children:[e.jsx(Re,{title:`${p.icon?`${p.icon} `:""}${p.name}`,subtitle:(p.error?`${p.id} · ${p.error}`:p.source?`${p.id} · ${p.source}`:`${p.id} · ${i("uiPluginNoSource")}`)+((V=p.permissions)!=null&&V.length?` · ${i("uiPluginPerms")}: ${p.permissions.join(", ")}`:""),enabled:!Ee.has(p.id)&&!p.error,onToggle:()=>!p.error&&re(p),action:e.jsxs("div",{className:"set-row-actions",children:[p.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:i("pluginUpdateHint"),onClick:()=>Me(p.id,p.source),children:[e.jsx(rt,{}),i("pluginUpdate")]}),h===p.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:i("pluginUninstallHint"),onClick:()=>ve(p.id),children:i("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:i("pluginUninstallHint"),onClick:()=>L(p.id),children:[e.jsx(Ae,{}),i("uninstallExt")]})]})},p.id),p.settingsSchema&&p.settingsSchema.length>0&&e.jsx(Ll,{plugin:p,send:s})]})})})]}),u==="plugins"&&t.engine==="dsh"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Lt,{className:"set-section-icon"}),i("dshPatches"),e.jsx(Ke,{text:i("dshPatchesDesc")}),e.jsx("span",{className:"set-count",children:((R=t.dshPatches)==null?void 0:R.files.length)??0}),e.jsxs("button",{type:"button",className:"set-uninstall",title:i("dshPatchesRescanHint"),onClick:()=>s({type:"dsh_patches_rescan"}),children:[e.jsx(rt,{}),i("dshPatchesRescan")]})]}),(((fe=t.dshPatches)==null?void 0:fe.files.length)??0)===0?e.jsx("p",{className:"set-empty",children:i("dshPatchesEmpty")}):e.jsx("div",{className:"set-list",children:t.dshPatches.files.map(p=>e.jsx("div",{className:"set-row",children:e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:p.name}),e.jsxs("div",{className:"set-row-desc",children:[Dl(p.size)," · ",new Date(p.mtimeMs).toLocaleString()]})]})},p.name))}),e.jsxs("p",{className:"set-hint",children:[i("dshPatchesPath")," ",((oe=t.dshPatches)==null?void 0:oe.patchDir)??""]})]}),u==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{className:"set-section-icon"}),i("settingsReview"),e.jsx(Ke,{text:i("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:a.reviewSkills.length})]}),o&&e.jsx("p",{className:"set-hint",children:i("dshReviewPromptNote")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:i("reviewPromptPlaceholder"),value:X,onFocus:()=>K.current=!0,onBlur:()=>{K.current=!1,ge({reviewPrompt:X})},onChange:p=>U(p.target.value)}),e.jsx("div",{className:"set-field-label",children:i("settingsReviewSkills")}),a.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:i("noSkills")}):e.jsx("div",{className:"set-list",children:a.reviewSkills.map(p=>e.jsx(Re,{title:p.name,subtitle:p.description,enabled:p.enabled,onToggle:()=>he(p)},`review-${p.name}`))})]}),u==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Qt,{className:"set-section-icon"}),i("settingsVisionBridge")]}),e.jsx(Re,{title:i("visionBridgeEnabled"),tip:i("settingsVisionBridgeDesc"),enabled:a.visionBridgeEnabled,onToggle:()=>ge({visionBridgeEnabled:!a.visionBridgeEnabled})}),!a.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:i("visionBridgeOffHint")}),a.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:a.visionBridgeModel??"",onChange:p=>ge({visionBridgeModel:p.target.value||null}),children:[e.jsx("option",{value:"",children:i("visionBridgeAuto")}),a.visionModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),a.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:j,onChange:p=>{const V=p.target.value;J(V),ge({visionBridgePromptMode:V})},children:[e.jsx("option",{value:"append",children:i("promptModeAppend")}),e.jsx("option",{value:"replace",children:i("promptModeReplace")})]})]}),a.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:i("visionBridgePromptPlaceholder"),value:H,onFocus:()=>Q.current=!0,onBlur:()=>{Q.current=!1;const p=j==="replace"&&a.visionBridgeDefaultPrompt&&H===a.visionBridgeDefaultPrompt?"":H;ge({visionBridgePromptMode:j,visionBridgePrompt:p})},onChange:p=>S(p.target.value)}),a.visionBridgeEnabled&&(a.visionModels.length===0?e.jsx("p",{className:"set-hint",children:i("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:i("visionBridgeCurrent",{model:a.visionBridgeModel??i("visionBridgeAuto")})}))]}),u==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(wt,{className:"set-section-icon"}),i("settingsPresets"),e.jsx("span",{className:"set-count",children:a.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:i("presetNamePlaceholder"),value:q,onChange:p=>Y(p.target.value),onKeyDown:p=>{p.key==="Enter"&&q.trim()&&(s({type:"save_preset",name:q.trim()}),Y(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!q.trim(),onClick:()=>{s({type:"save_preset",name:q.trim()}),Y("")},children:[e.jsx(He,{})," ",i("saveAsPreset")]})]}),a.presets.length===0?e.jsx("p",{className:"set-empty",children:i("noPresets")}):e.jsx("div",{className:"set-list",children:a.presets.map(p=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:p.name}),e.jsxs("div",{className:"set-row-desc",children:[p.promptMode==="replace"?i("promptModeReplace"):i("promptModeAppend"),p.disabledSkills.length>0&&` · ${i("settingsSkills")} ${p.disabledSkills.length}`,p.disabledExtensions.length>0&&` · ${i("settingsExtensions")} ${p.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:p.name}),children:i("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:i("deletePreset"),onClick:()=>s({type:"delete_preset",name:p.name}),children:e.jsx(Ae,{})})]})]},p.name))})]}),u==="subagent-templates"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Rs,{className:"set-section-icon"}),i("settingsSubagentTemplates"),e.jsx(Ke,{text:i("settingsSubagentTemplatesDesc")}),e.jsx("span",{className:"set-count",children:a.subagentTemplates.length}),e.jsxs("button",{type:"button",className:"set-save-btn",title:i("subagentTemplateNew"),onClick:()=>P({name:"",description:"",promptMode:"replace",systemPrompt:"",enabledSkills:[],enabledExtensions:[],model:"",enabled:!0}),children:[e.jsx(He,{})," ",i("subagentTemplateNew")]})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("subagentDefaultModelLabel")}),e.jsxs("select",{className:"set-select",value:a.subagentDefaultModel??"",onChange:p=>ge({subagentDefaultModel:p.target.value||null}),children:[e.jsx("option",{value:"",children:i("subagentFollowMain")}),a.subagentModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),a.subagentModels.length===0?e.jsx("p",{className:"set-hint",children:i("subagentNoModels")}):e.jsx("p",{className:"set-hint",children:i("subagentDefaultModelHint")}),T&&e.jsxs("div",{className:"tpl-editor",children:[e.jsxs("div",{className:"tpl-fields",children:[e.jsx("input",{className:"set-input",placeholder:i("tplNamePlaceholder"),value:T.name,onChange:p=>P({...T,name:p.target.value})}),e.jsx("input",{className:"set-input",placeholder:i("tplDescriptionPlaceholder"),value:T.description,onChange:p=>P({...T,description:p.target.value})})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("tplPromptModeLabel")}),e.jsxs("select",{className:"set-select",value:T.promptMode,onChange:p=>P({...T,promptMode:p.target.value}),children:[e.jsx("option",{value:"replace",children:i("promptModeReplace")}),e.jsx("option",{value:"append",children:i("promptModeAppend")})]})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:i("tplModelLabel")}),e.jsxs("select",{className:"set-select",value:T.model??"",onChange:p=>P({...T,model:p.target.value}),children:[e.jsx("option",{value:"",children:i("subagentFollowMain")}),a.subagentModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:`${i("tplSystemPromptLabel")}:${i("tplSystemPromptPlaceholder")}`,value:T.systemPrompt,onChange:p=>P({...T,systemPrompt:p.target.value})}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[i("tplSkillsLabel")," · ",i("tplWhitelistHint")]})}),a.skills.length===0?e.jsx("p",{className:"set-hint",children:i("noSkills")}):e.jsx("div",{className:"tpl-pick",children:a.skills.map(p=>e.jsxs("label",{className:`tpl-chip${T.enabledSkills.includes(p.name)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:T.enabledSkills.includes(p.name),onChange:V=>{const N=V.target.checked;P({...T,enabledSkills:N?[...T.enabledSkills,p.name]:T.enabledSkills.filter(_=>_!==p.name)})}}),p.name]},p.name))})]}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[i("tplExtensionsLabel")," · ",i("tplWhitelistHint")]})}),a.extensions.length===0?e.jsx("p",{className:"set-hint",children:i("noExtensions")}):e.jsx("div",{className:"tpl-pick",children:a.extensions.map(p=>e.jsxs("label",{className:`tpl-chip${T.enabledExtensions.includes(p.id)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:T.enabledExtensions.includes(p.id),onChange:V=>{const N=V.target.checked;P({...T,enabledExtensions:N?[...T.enabledExtensions,p.id]:T.enabledExtensions.filter(_=>_!==p.id)})}}),p.name]},p.id))})]}),e.jsxs("div",{className:"tpl-actions",children:[e.jsx("button",{type:"button",className:"set-save-btn",disabled:!T.name.trim(),onClick:()=>{s({type:"save_subagent_template",template:{...T,name:T.name.trim()}}),P(null)},children:i("tplSave")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>P(null),children:i("tplCancel")})]})]}),a.subagentTemplates.length===0?e.jsx("p",{className:"set-empty",children:i("noSubagentTemplates")}):e.jsx("div",{className:"set-list",children:a.subagentTemplates.map(p=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[p.name,a.subagentDefaultTemplates.includes(p.name)&&e.jsx("span",{className:"tpl-badge default",children:i("tplDefaultBadge")}),!p.enabled&&e.jsx("span",{className:"tpl-badge",children:i("subagentTemplateClosed")})]}),e.jsxs("div",{className:"set-row-desc",children:[p.description||`${p.promptMode==="replace"?i("promptModeReplace"):i("promptModeAppend")}`,p.model?` · ${i("tplModelLabel")} ${p.model}`:` · ${i("subagentFollowMain")}`,p.enabledSkills.length>0&&` · ${i("tplSkillsLabel")} ${p.enabledSkills.length}`,p.enabledExtensions.length>0&&` · ${i("tplExtensionsLabel")} ${p.enabledExtensions.length}`,!p.description&&p.enabledSkills.length===0&&p.enabledExtensions.length===0&&` · ${i("tplInherit")}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:`set-switch${p.enabled?" on":""}`,role:"switch","aria-checked":p.enabled,title:`${p.enabled?i("subagentTemplateDisable"):i("subagentTemplateEnable")} · ${i("subagentTemplateOffHint")}`,onClick:()=>s({type:"save_subagent_template",template:{...p,enabled:!p.enabled}}),children:e.jsx("span",{className:"set-switch-knob"})}),e.jsx("button",{type:"button",className:"dd-refresh",title:i("subagentTemplateEdit"),onClick:()=>P({...p}),children:i("subagentTemplateEdit")}),k===p.name?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:i("uninstallConfirmHint"),onClick:()=>{s({type:"delete_subagent_template",name:p.name}),B(null)},children:i("uninstallConfirm")}):e.jsx("button",{type:"button",className:"set-icon-btn danger",title:i("tplDelete"),onClick:()=>B(p.name),children:e.jsx(Ae,{})})]})]},p.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:i("close")})})]})})}function _l(t,s){const n=Math.max(0,Date.now()-t),r=Math.floor(n/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const c=Math.floor(r/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function Bl({servers:t,send:s,onClose:n}){const r=xe(),[c,i]=l.useState(new Set),a=o=>i(u=>{const m=new Set(u);return m.has(o)?m.delete(o):m.add(o),m});return l.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(Ct,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:n,children:e.jsx(Pe,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(Ct,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const u=!!o.taskId,m=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:r("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:[r("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",_l(o.since,r)]}),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(m)?"open":""}`,title:`${r("bgTaskCommand")}: ${o.command}`,onClick:()=>a(m),children:[e.jsx(tt,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s(u?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(jt,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},m)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(rt,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(jt,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function Fl(t,s){return t.toLowerCase().includes(s)}function $l({open:t,send:s,projects:n,cwd:r,fileSearch:c,sessionSearch:i,onClose:a,onSwitchSession:o,onSwitchProject:u,onPreviewFile:m}){const y=xe(),g=l.useRef(null),[x,b]=l.useState(""),E=l.useDeferredValue(x),[A,H]=l.useState(0),S=l.useRef(1),j=l.useRef(0),J=l.useRef(null);l.useEffect(()=>{if(!t)return;s({type:"list_sessions"}),s({type:"list_projects"});const M=x.trim();if(M){const I=++S.current;j.current=I,X(!0),s({type:"search_files",reqId:I,query:M}),s({type:"search_sessions",reqId:I,query:M})}requestAnimationFrame(()=>{var I;return(I=g.current)==null?void 0:I.select()})},[t]);const[Q,X]=l.useState(!1);l.useEffect(()=>{J.current&&clearTimeout(J.current);const M=E.trim();if(!M){X(!1);return}return J.current=setTimeout(()=>{const I=++S.current;j.current=I,X(!0),s({type:"search_files",reqId:I,query:M}),s({type:"search_sessions",reqId:I,query:M})},300),()=>{J.current&&clearTimeout(J.current)}},[E]);const U=E.trim().toLowerCase(),K=l.useMemo(()=>!U||!i||i.reqId!==j.current||!i.ok?[]:i.results,[i,U]),q=l.useMemo(()=>U?n.filter(M=>Fl(M.path,U)).slice(0,10):[],[n,U]),Y=l.useMemo(()=>!U||!c||c.reqId!==j.current||!c.ok?[]:c.results,[c,U]);l.useEffect(()=>{c&&c.reqId===j.current&&i&&i.reqId===j.current&&j.current!==0&&X(!1)},[c,i]);const T=!!c&&c.ok&&c.truncated,P=l.useMemo(()=>[...K.map(M=>({kind:"session",path:M.path,anchors:M.anchors})),...q.map(M=>({kind:"project",path:M.path})),...Y.filter(M=>M.type==="file").map(M=>({kind:"file",path:M.path,name:M.name}))],[K,q,Y]);l.useEffect(()=>{H(0)},[E]);const k=l.useCallback(M=>{if(M)if(M.kind==="session")o(M.path,M.anchors),a();else if(M.kind==="project"){u(M.path),s({type:"list_sessions"}),s({type:"list_projects"});const I=E.trim();if(I){const C=++S.current;j.current=C,X(!0),s({type:"search_files",reqId:C,query:I}),s({type:"search_sessions",reqId:C,query:I})}}else m(M.path,M.name)},[o,u,m,s,E]);l.useEffect(()=>{if(!t)return;const M=I=>{I.key==="Escape"?(I.preventDefault(),I.stopPropagation(),a()):I.key==="ArrowDown"?(I.preventDefault(),H(C=>Math.min(C+1,P.length-1))):I.key==="ArrowUp"?(I.preventDefault(),H(C=>Math.max(C-1,0))):I.key==="Enter"&&(I.preventDefault(),k(P[A]))};return window.addEventListener("keydown",M,!0),()=>window.removeEventListener("keydown",M,!0)},[P,A,k,a,t]);const B=K.length+q.length+Y.length,Z=(M,I,C)=>e.jsxs("div",{className:"gs-section-head",children:[C,e.jsx("span",{children:M}),e.jsx("em",{children:I})]});let G=-1;return t?e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:a,children:e.jsxs("div",{className:"gs-modal",onClick:M=>M.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(Nt,{}),e.jsx("input",{ref:g,type:"text",value:x,placeholder:y("gsPlaceholder"),onChange:M=>b(M.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:y("close"),onClick:a,children:e.jsx(Pe,{})})]}),e.jsxs("div",{className:"gs-results",children:[!U&&e.jsx("div",{className:"gs-empty",children:y("gsHint")}),U&&B===0&&!T&&e.jsx("div",{className:"gs-empty",children:y(Q?"gsSearching":"gsNoResults")}),K.length>0&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsSessions"),K.length,e.jsx(st,{})),K.map(M=>{G++;const I=G;return e.jsxs("button",{type:"button",className:I===A?"gs-item active":"gs-item",onMouseEnter:()=>H(I),onClick:()=>k({kind:"session",path:M.path,anchors:M.anchors}),children:[e.jsxs("span",{className:"gs-item-title",children:[M.name||M.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:M.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:M.firstMessage})]},M.path)})]}),q.length>0&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsProjects"),q.length,e.jsx(Je,{})),q.map(M=>{G++;const I=G,C=r&&M.path===r;return e.jsxs("button",{type:"button",className:I===A?"gs-item active":"gs-item",onMouseEnter:()=>H(I),onClick:()=>k({kind:"project",path:M.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[M.path.split(/[\\/]/).pop(),C&&e.jsx("em",{className:"gs-item-meta",children:y("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:M.path})]},M.path)})]}),(Y.length>0||U&&T)&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsFiles"),Y.length,e.jsx(kn,{})),Y.map(M=>{G++;const I=G;return e.jsxs("button",{type:"button",className:I===A?"gs-item active":"gs-item",disabled:M.type==="dir",title:M.type==="dir"?void 0:y("gsOpenPreview"),onMouseEnter:()=>H(I),onClick:()=>{M.type==="file"&&k({kind:"file",path:M.path,name:M.name})},children:[e.jsx("span",{className:"gs-item-title",children:M.name}),e.jsx("span",{className:"gs-item-sub",children:M.path})]},`${M.type}:${M.path}`)}),T&&e.jsx("div",{className:"gs-truncated",children:y("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",y("gsNavigate")]}),e.jsxs("span",{children:["Enter ",y("gsOpen")]}),e.jsxs("span",{children:["Esc ",y("gsCloseHint")]})]})]})}):null}const zt=5e3;function Hl({file:t,content:s,send:n,onAddLines:r,onAttach:c,onClose:i}){const a=xe(),[o,u]=l.useState(null),[m,y]=l.useState(!1),[g,x]=l.useState(null),[b,E]=l.useState(!1),[A,H]=l.useState(!1),[S,j]=l.useState(!1),[J,Q]=l.useState(""),[X,U]=l.useState(!0),K=l.useRef(!1),[q,Y]=l.useState(!0),[T,P]=l.useState(!1),[k,B]=l.useState(100),Z=l.useRef(0),G=l.useRef(!1),M=l.useRef(null);l.useEffect(()=>{y(!0),u(null),x(null),j(!1),Q(""),U(!0),K.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),l.useEffect(()=>{s&&s.path===t.path&&(u(s),S||Q(s.text),y(!1))},[s,S,t.path]),l.useEffect(()=>{const re=f=>{if(f.key==="Escape"){L();return}if((f.ctrlKey||f.metaKey)&&f.key.toLowerCase()==="s"&&S){f.preventDefault(),h();return}const O=f.target,de=O&&(O.tagName==="INPUT"||O.tagName==="TEXTAREA"||O.isContentEditable);(f.ctrlKey||f.metaKey)&&f.key.toLowerCase()==="a"&&!de&&(f.preventDefault(),ne())};return document.addEventListener("keydown",re),()=>document.removeEventListener("keydown",re)},[i,o,S,J]),l.useEffect(()=>{const re=()=>{G.current=!1,E(!1)};return window.addEventListener("mouseup",re),()=>window.removeEventListener("mouseup",re)},[]);const I=l.useMemo(()=>{if(!o)return[];const re=o.text.split(`
326
- `);return re.length>0&&re[re.length-1]===""&&re.pop(),re.slice(0,zt)},[o]),C=(o==null?void 0:o.lines)??0,$=C>zt,z=(re,f)=>{if(f){const O=Z.current>0?Z.current:re;x({start:Math.min(O,re),end:Math.max(O,re)})}else Z.current=re,x({start:re,end:re})},ne=()=>{I.length!==0&&(Z.current=1,x({start:1,end:I.length}))},v=()=>{g&&(r(t.path,t.name,g.start,g.end),H(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>H(!1),1400))},D=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,d=()=>{Q((o==null?void 0:o.text)??""),j(!1),K.current&&U(!0)},w=()=>{if(S){if(J!==((o==null?void 0:o.text)??"")&&!window.confirm(a("discardFileChanges")))return;d();return}!D||!o||(K.current=Vt(t.name)&&X,Vt(t.name)&&U(!1),x(null),Q(o.text),j(!0))},h=()=>{!S||!o||!D||n({type:"write_file",path:t.path,text:J})&&(j(!1),K.current&&U(!0),x(null))},L=()=>{S&&J!==((o==null?void 0:o.text)??"")&&!window.confirm(a("discardFileChanges"))||i()},ee=re=>{B(Math.min(200,Math.max(50,re)))},W=g?g.end-g.start+1:0,ae=(o==null?void 0:o.binary)??!1,ye=(o==null?void 0:o.truncated)??!1,be=(o==null?void 0:o.kind)??"text",ge=Vt(t.name),ke=ge&&X&&!S&&be==="text"&&!ae,Ee=re=>Mt(Ve(`/api/file?clientId=${encodeURIComponent(os())}&path=${encodeURIComponent(re)}`));return e.jsx("div",{className:`fp-overlay ${T?"fullscreen":""}`,onMouseDown:re=>{re.target===re.currentTarget&&L()},children:e.jsxs("div",{className:`fp ${T?"fullscreen":""}`,style:{"--fp-zoom":k/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&&be==="text"&&!ae&&a("fileLines",{n:C}),o&&` · ${Ol(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[ge&&be==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${X?"on":""}`,"data-tip":a(X?"showMarkdownSource":"showMarkdownPreview"),disabled:S,onClick:()=>U(re=>!re),children:X?e.jsx(Qt,{}):e.jsx(Qi,{})}),be==="text"&&!ae&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${S?"on":""}`,"data-tip":a(ye?"fileEditTruncated":S?"exitEditFile":"editFile"),disabled:!D&&!S,onClick:w,children:e.jsx(Yt,{})}),be==="text"&&!ae&&!ke&&e.jsx("button",{type:"button",className:`fp-attach wrap ${q?"on":""}`,"data-tip":a(q?"disableWrap":"enableWrap"),onClick:()=>Y(re=>!re),children:e.jsx(Gi,{})}),be==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":a("zoomOut"),disabled:k<=50,onClick:()=>ee(k-10),children:e.jsx(Pi,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:a("resetZoom"),onClick:()=>B(100),children:[k,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":a("zoomIn"),disabled:k>=200,onClick:()=>ee(k+10),children:e.jsx(Mi,{})})]}),be!=="video"&&be!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":a("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":a("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Gt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${T?"on":""}`,"data-tip":a(T?"exitFullscreen":"fullscreen"),onClick:()=>P(re=>!re),children:T?e.jsx(Fi,{}):e.jsx(Hi,{})}),e.jsx("button",{type:"button",className:"fp-close",title:a("close"),onClick:L,children:e.jsx(Pe,{})})]})]}),ye&&be==="text"&&!ae&&e.jsx("div",{className:"fp-notice",children:a("previewTruncated")}),m&&!o&&e.jsx("div",{className:"fp-empty",children:a("loading")}),!m&&be==="none"&&!ae&&e.jsx("div",{className:"fp-empty",children:a("previewNotSupported")}),!m&&be==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:Ee(t.path),alt:t.name})}),!m&&be==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:Ee(t.path),controls:!0,preload:"metadata"})}),!m&&ke&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(Rt,{text:o.text})})}),!m&&ae&&be!=="image"&&be!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[a("binaryFile"),o.truncated&&a("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!m&&S&&be==="text"&&!ae&&o&&e.jsx("textarea",{className:`fp-editor ${q?"":"no-wrap"}`,value:J,onChange:re=>Q(re.target.value),wrap:q?"soft":"off",spellCheck:!1,autoFocus:!0}),!m&&!ke&&!S&&be==="text"&&!ae&&o&&I.length===0&&e.jsx("div",{className:"fp-empty",children:a("emptyFile")}),!m&&!ke&&!S&&be==="text"&&!ae&&I.length>0&&e.jsxs("div",{className:`fp-code ${b?"dragging":""} ${q?"":"no-wrap"}`,onMouseDown:re=>{re.button===0&&re.preventDefault()},children:[I.map((re,f)=>{const O=f+1,de=g!==null&&O>=g.start&&O<=g.end;return e.jsxs("div",{className:`fp-line ${de?"sel":""}`,onMouseDown:ue=>{ue.button===0&&(z(O,ue.shiftKey),G.current=!0,E(!0))},onMouseEnter:()=>{G.current&&z(O,!0)},children:[e.jsx("span",{className:"fp-num",children:O}),e.jsx("span",{className:"fp-code-text",children:re})]},O)}),$&&e.jsx("div",{className:"fp-lines-note",children:a("previewLinesTruncated",{n:zt})})]}),e.jsx("div",{className:"fp-foot",children:S?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:a("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:w,children:a("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:J===((o==null?void 0:o.text)??""),onClick:h,children:[e.jsx(Ai,{})," ",a("saveFile")]})]})]}):!ke&&be==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:g?a("selectedRange",{n:W,start:g.start,end:g.end}):a("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:I.length===0,onClick:ne,children:a("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!g,onClick:()=>x(null),children:a("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!g||ae,onClick:v,children:[A?e.jsx(pt,{}):null,a(A?"addedToChat":"addToChat")]})]})]})})]})})}function Vt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Ol(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const ri="pi-web-sounds",nt={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function li(){try{const t=localStorage.getItem(ri);if(!t)return{...nt};const s=JSON.parse(t),n={...nt,...s};for(const r of["enabled","question","done","start","error"])typeof n[r]!="boolean"&&(n[r]=nt[r]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=nt.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...nt}}}function Kl(t){try{localStorage.setItem(ri,JSON.stringify(t))}catch{}}let it=null;function Wl(){try{if(!it){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;it=new t}return it.state==="suspended"&&it.resume(),it}catch{return null}}const Ul=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],ql=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],zl=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],Vl=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Gl={question:Ul,done:ql,start:zl,error:Vl};function Ql(t,s,n){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const i=t.currentTime+s.start,a=Math.max(1e-4,s.peak*n);c.gain.setValueAtTime(1e-4,i),c.gain.exponentialRampToValueAtTime(a,i+.012),c.gain.exponentialRampToValueAtTime(1e-4,i+s.dur),r.connect(c),c.connect(t.destination),r.start(i),r.stop(i+s.dur+.05)}function at(t,s=li()){if(!s.enabled||!s[t])return;const n=Wl();if(!n)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Gl[t])Ql(n,c,r)}const as="pi-web-ui:theme",oi="dark",on="theme-stylesheet",cn="pi-web-ui:theme-change";function ci(){try{const t=localStorage.getItem(as);if(t&&t!==oi)return t}catch{}return null}function Yl(t){try{t?localStorage.setItem(as,t):localStorage.removeItem(as)}catch{}}function di(t){let s=document.getElementById(on);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(cn));return}s||(s=document.createElement("link"),s.id=on,s.rel="stylesheet",document.head.appendChild(s)),s.href=Ve(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(cn))}async function Jl(){try{const t=await fetch(Mt(Ve("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Xl(){const[t,s]=l.useState([]),[n,r]=l.useState(()=>ci());return l.useEffect(()=>{let i=!1;return Jl().then(a=>{i||s(a)}),()=>{i=!0}},[]),l.useEffect(()=>{di(n),Yl(n)},[n]),{themes:t,theme:n,switchTheme:i=>r(i===oi?null:i)}}function ro(){const t=getComputedStyle(document.documentElement),s=(n,r)=>t.getPropertyValue(n).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Zl=l.lazy(()=>gn(()=>import("./TerminalPanel-CoPFNu1d.js"),__vite__mapDeps([2,1,3,4,5])).then(t=>({default:t.TerminalPanel})));function eo({notice:t,onDismiss:s}){const n=xe(),{locale:r}=mt(),c=r==="en"&&t.textEn?t.textEn:t.text,[i,a]=l.useState(!1);l.useEffect(()=>{if(i)return;const u=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(u)},[i,t.id,t.level,s]);const o=t.level==="error"?ta:t.level==="warning"?ea:Wi;return e.jsxs("div",{className:`notice notice-${t.level}${i?" paused":""}`,role:"status",onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[e.jsx(o,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:c}),e.jsx("button",{type:"button",className:"notice-close",title:n("close"),onClick:()=>s(t.id),children:e.jsx(Pe,{})})]})}const to=[],ui=180,pi=520,mi=240,hi=t=>`pi-web-ui:${t}-panel-width`;function dn(t){const s=Number(localStorage.getItem(hi(t)));return Number.isFinite(s)&&s>=ui&&s<=pi?s:mi}const rs=t=>`pi-web-ui:${t}-panel-collapsed`;function un(t){return localStorage.getItem(rs(t))==="1"}function pn({side:t,width:s,onResize:n}){const r=xe(),c=l.useCallback(i=>{i.preventDefault();const a=i.clientX,o=s;let u=o;const m=g=>{const x=t==="left"?g.clientX-a:a-g.clientX;u=Math.min(pi,Math.max(ui,Math.round(o+x))),n(u)},y=()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",y),document.body.classList.remove("panel-resizing"),localStorage.setItem(hi(t),String(u))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",y),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>n(mi)})}function mn({side:t,onClick:s}){const n=xe();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:n("expandPanel"),onClick:s,children:t==="left"?e.jsx(wn,{}):e.jsx(Nn,{})})}function so(){var Oe,ms,hs,gs,fs,xs,ys,vs,bs,ks,js,ws,Ns,Cs;const t=xe(),{chat:s,send:n,dismissNotice:r,pushNotice:c,terminal:i}=Aa(),[a,o]=l.useState([]),[u,m]=l.useState(null),[y,g]=l.useState(!1),[x,b]=l.useState("chat"),E=l.useMemo(()=>s.plugins.filter(F=>{var te,ce;return!((ce=(te=s.settings)==null?void 0:te.disabledPlugins)!=null&&ce.includes(F.id))}),[s.plugins,(Oe=s.settings)==null?void 0:Oe.disabledPlugins]),[A,H]=l.useState([]);l.useEffect(()=>wa(H),[]),l.useEffect(()=>{Na(E,s.pluginsEpoch)},[E,s.pluginsEpoch]);const[S,j]=l.useState(()=>dn("left")),[J,Q]=l.useState(()=>dn("right")),X=l.useCallback(F=>j(F),[]),U=l.useCallback(F=>Q(F),[]),[K,q]=l.useState(()=>un("left")),[Y,T]=l.useState(()=>un("right")),P=l.useCallback(()=>{q(F=>(localStorage.setItem(rs("left"),F?"0":"1"),!F))},[]),k=l.useCallback(()=>{T(F=>(localStorage.setItem(rs("right"),F?"0":"1"),!F))},[]),[B,Z]=l.useState(null),[G,M]=l.useState(()=>window.matchMedia("(max-width: 768px)").matches);l.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),te=ce=>M(ce.matches);return F.addEventListener("change",te),()=>F.removeEventListener("change",te)},[]);const[I,C]=l.useState(!1),[$,z]=l.useState(!1),[ne,v]=l.useState(!1),[D,d]=l.useState(!1),[w,h]=l.useState(!1),[L,ee]=l.useState(null);l.useEffect(()=>{if(!L)return;const F=setTimeout(()=>ee(null),15e3);return()=>clearTimeout(F)},[L]),l.useEffect(()=>{const F=te=>{var qe,Ss;const ce=te.detail,Ne=(ce==null?void 0:ce.title)||t("pluginCommandFallback"),Ce=ce==null?void 0:ce.command;if(!Ce||!s.ready)return;const Fe={name:Ne,command:Ce,cwd:"${pwd}"},Se=s.terminals.find(It=>It.title===Ne);if(Se)i.restart(Se.id),n({type:"run_command",terminalId:Se.id,conversationId:Se.conversationId,command:Fe,cols:80,rows:24});else{const It=Ue();i.create({id:It,conversationId:s.activeConversationId||((qe=s.state)==null?void 0:qe.conversationId)||"",title:Ne,cwd:((Ss=s.state)==null?void 0:Ss.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Fe})}b("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,i,n]),l.useEffect(()=>{const F=te=>{!(te.ctrlKey||te.metaKey)||te.key.toLowerCase()!=="k"||(te.preventDefault(),h(ce=>!ce))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[W,ae]=l.useState(li),{themes:ye,theme:be,switchTheme:ge}=Xl(),ke=l.useRef(null),Ee=l.useRef(null),re=l.useRef(0),f=l.useRef(!1),O=l.useRef(s.terminals);l.useEffect(()=>{Kl(W)},[W]),l.useEffect(()=>{var te;const F=O.current;O.current=s.terminals;for(const ce of s.terminals){const Ne=((te=ce.command)==null?void 0:te.command)??"",Ce=F.find(Fe=>Fe.id===ce.id);!(Ce!=null&&Ce.running)||ce.running||(Ne.startsWith("pi remove ")?n({type:"extensions_reload"}):Ne.startsWith("pi-web-ui install ")||Ne.startsWith("pi-web-ui uninstall ")?n({type:"plugins_reload"}):Ne.startsWith("npm i -g ")&&(n({type:"extensions_reload"}),n({type:"plugins_reload"}),n({type:"check_updates_all",force:!0})))}},[s.terminals,n]),l.useEffect(()=>{var ce;const F=((ce=s.state)==null?void 0:ce.isStreaming)??!1,te=ke.current;ke.current=F,te!==null&&(!te&&F?at("start",W):te&&!F&&(at("done",W),_t(t("notifyDoneTitle"),t("notifyDoneBody"))))},[(ms=s.state)==null?void 0:ms.isStreaming,W]),l.useEffect(()=>{var te;const F=((te=s.dialog)==null?void 0:te.id)??null;F!==null&&F!==Ee.current&&(at("question",W),_t(t("notifyQuestionTitle"),t("notifyQuestionBody"))),Ee.current=F},[s.dialog,W]),l.useEffect(()=>{const F=[...s.notices].reverse().find(te=>te.level==="error");F&&F.id!==re.current&&(re.current=F.id,at("error",W),_t(t("notifyErrorTitle"),t("notifyErrorBody")))},[s.notices,W]);const de=(F,te,ce,Ne=!1,Ce)=>{const Fe=`${F}|${ce}|${Ce?`${Ce.start}-${Ce.end}`:""}`;o(Se=>Se.some(qe=>`${qe.path}|${qe.mode}|${qe.lines?`${qe.lines.start}-${qe.lines.end}`:""}`===Fe)?Se:[...Se,{path:F,name:te,mode:ce,isDir:Ne,...Ce?{lines:Ce}:{}}])},ue=F=>o(te=>te.filter(ce=>ce.key?ce.key!==F:ce.path!==F)),me=l.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&Z(null),n(F)),[n]),pe=l.useRef(0),ve=l.useRef(0),Me=F=>{var Ne;const te=Date.now();(Ne=s.state)!=null&&Ne.model&&!s.state.model.vision&&te-ve.current>1e4&&(ve.current=te,c("warning",t("imageNotSupported")));const ce=`paste-${++pe.current}`;o(Ce=>[...Ce,{path:"",key:ce,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},he=async F=>{for(const te of F){const ce=await On(te);if(!ce){c("error",t("imageLoadFailed",{name:te.name}));continue}Me(ce)}},_e=20*1024*1024,Le=l.useRef(0),Be=async F=>{if(F.size>_e){c("warning",t("fileTooLarge",{name:F.name,size:_e/1024/1024}));return}let te;try{te=(await new Promise((Ce,Fe)=>{const Se=new FileReader;Se.onload=()=>Ce(Se.result),Se.onerror=()=>Fe(Se.error??new Error("read failed")),Se.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const ce=`upload-${++Le.current}`;o(Ne=>[...Ne,{path:"",key:ce,name:F.name,mode:"inline",fileData:te,size:F.size,mimeType:F.type||void 0}])},De=async F=>{for(const te of F)We(te.type)?await he([te]):await Be(te)},R=l.useCallback((F,te,ce)=>{n({type:"edit_message",messageId:F,text:te,attachments:ce})},[n]),fe=l.useCallback((F,te)=>{n({type:"queue_remove",kind:F,text:te})},[n]),oe=l.useCallback(()=>z(!0),[]),p=l.useCallback(()=>o([]),[]),V=l.useCallback(ue,[]),N=l.useCallback(he,[he]),_=l.useCallback(De,[De]),ie=(hs=s.state)==null?void 0:hs.model,le=(gs=s.state)==null?void 0:gs.thinkingLevel,je=(fs=s.state)==null?void 0:fs.availableThinkingLevels,we=l.useMemo(()=>ie?{model:ie,thinkingLevel:le??"off",availableThinkingLevels:je??[]}:null,[ie,le,je]),Te=l.useCallback(()=>{var F,te;return!s.ready||s.terminals.length!==0?!1:(i.create({id:Ue(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((te=s.state)==null?void 0:te.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(xs=s.state)==null?void 0:xs.cwd,s.terminals.length,t,i]);return l.useEffect(()=>{if(f.current){if(x!=="terminal"||s.terminals.length!==0){f.current=!1;return}Te()&&(f.current=!1)}},[s.terminals.length,Te,x]),e.jsxs("div",{className:"app",onDragOver:F=>{var te;Array.from(((te=F.dataTransfer)==null?void 0:te.types)??[]).includes("Files")&&(F.preventDefault(),g(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||g(!1)},onDrop:F=>{var Ce,Fe;if(g(!1),!Array.from(((Ce=F.dataTransfer)==null?void 0:Ce.types)??[]).includes("Files"))return;F.preventDefault();const te=Array.from(((Fe=F.dataTransfer)==null?void 0:Fe.files)??[]);if(te.length===0){c("warning",t("foldersNotSupported"));return}const ce=te.filter(Se=>We(Se.type)),Ne=te.filter(Se=>!We(Se.type));ce.length>0&&he(ce),Ne.length>0&&De(Ne)},children:[y&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(da,{chat:s,send:n,terminal:i,view:x,plugins:E,onViewChange:F=>{f.current=F==="terminal"&&s.terminals.length===0,f.current&&Te()&&(f.current=!1),b(F),Z(null)},onOpenPanel:Z,onOpenSettings:()=>v(!0),onOpenBgTasks:()=>d(!0),onOpenGlobalSearch:()=>h(!0),sound:W,onSoundChange:ae,onSoundPreview:F=>at(F,W),themes:ye,theme:be,onThemeChange:ge}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(eo,{notice:F,onDismiss:r},F.id))}),e.jsx(Yr,{send:n,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${S}px`,"--right-w":`${J}px`},children:[B&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>Z(null)}),e.jsxs("div",{className:`view-pane ${x==="chat"?"":"hidden"}`,children:[!G&&K&&e.jsx(mn,{side:"left",onClick:P}),e.jsx("div",{className:`panel-drawer drawer-left ${B==="left"?"open":""}${G?"":K?" hidden":""}`,children:e.jsx(fa,{collapsible:!G,onToggleCollapse:P,send:me,active:!G||B==="left",ready:s.ready,status:s.status,cwd:((ys=s.state)==null?void 0:ys.cwd)??"",sessionFile:((vs=s.state)==null?void 0:vs.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!G&&e.jsx(pn,{side:"left",width:S,onResize:X}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(sl,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:R,onKillBash:()=>n({type:"abort_bash"}),onRemoveQueued:fe,thinkingWrap:((bs=s.settings)==null?void 0:bs.thinkingWrap)??!0,toolsWrap:((ks=s.settings)==null?void 0:ks.toolsWrap)??!0,jumpTarget:L,onJumpDone:()=>ee(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(xl,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(Nl,{dialog:s.dialog,send:n}),s.question&&e.jsx(Cl,{question:s.question,send:n}),e.jsx(fl,{send:n,ready:s.ready,streaming:((js=s.state)==null?void 0:js.isStreaming)??!1,messages:((ws=s.state)==null?void 0:ws.messages)??to,slashCommands:s.slashCommands,modelState:we,models:s.models,modelsLoading:s.modelsLoading,providerKeys:s.providerKeys,attachments:a,onRemoveAttachment:V,onAddImageFiles:N,onAddLocalFiles:_,onNotice:c,onManageModels:oe,onSent:p})]}),!G&&e.jsx(pn,{side:"right",width:J,onResize:U}),e.jsx("div",{className:`panel-drawer drawer-right ${B==="right"?"open":""}${G?"":Y?" hidden":""}`,children:e.jsx(Ua,{collapsible:!G,onToggleCollapse:k,send:me,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((Ns=s.state)==null?void 0:Ns.cwd)??"",onAttach:(F,te,ce,Ne)=>{Z(null),de(F,te,ce,Ne)},onPreview:(F,te)=>{Z(null),m({path:F,name:te})},onNotice:(F,te)=>c(F,te)})}),!G&&Y&&e.jsx(mn,{side:"right",onClick:k})]}),e.jsx("div",{className:`view-pane ${x==="terminal"?"":"hidden"}`,children:e.jsx(l.Suspense,{fallback:null,children:e.jsx(Zl,{chat:s,send:n,terminal:i})})}),e.jsx("div",{className:`view-pane ${x==="git"?"":"hidden"}`,children:e.jsx(Tl,{chat:s,send:n,terminal:i,active:x==="git",onSwitchToTerminal:()=>b("terminal")})}),A.map(F=>{const te=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${x===te?"":"hidden"}`,children:e.jsx(El,{entry:F,send:n})},F.info.id)})]})}),e.jsx(jl,{chat:s,send:n}),u&&e.jsx(Hl,{file:u,content:s.fileContent,send:n,onAddLines:(F,te,ce,Ne)=>de(F,te,"lines",!1,{start:ce,end:Ne}),onAttach:(F,te,ce)=>de(F,te,ce),onClose:()=>m(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!I&&!$&&e.jsx(Pl,{send:n,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>C(!0)}),$&&e.jsx(Il,{send:n,providers:s.modelsConfig,providerStatus:s.providers,providerKeys:s.providerKeys,fetchModelsResult:s.fetchModelsResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>z(!1)}),ne&&e.jsx(Al,{chat:s,send:n,terminal:i,onSwitchToTerminal:()=>b("terminal"),onClose:()=>v(!1)}),D&&e.jsx(Bl,{servers:s.bgServers,send:n,onClose:()=>d(!1)}),e.jsx($l,{open:w,send:n,projects:s.projects,cwd:((Cs=s.state)==null?void 0:Cs.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>h(!1),onSwitchSession:(F,te)=>{n({type:"switch_session",path:F});const ce=te&&te[0];ee(ce?{path:F,role:ce.role,timestamp:ce.timestamp}:null)},onSwitchProject:F=>{n({type:"set_cwd",path:F})},onPreviewFile:(F,te)=>{m({path:F,name:te})}})]})}xa();di(ci());vi.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(ia,{children:e.jsx(so,{})})}));"serviceWorker"in navigator&&window.addEventListener("load",()=>{const t=Pn();navigator.serviceWorker.register(`${t}sw.js`,{scope:t}).catch(s=>{console.warn("Service worker registration failed:",s)})});export{rt as F,cn as T,gn as _,xe as a,ro as b,He as c,ao as d,St as e,Ae as f,$i as g,tt as h,Pe as i,Ue as r,mt as u};
314
+ `).join(" ").trim(),I=a&&i&&s.content.length===0,N=s.role==="user"&&!a&&!I&&!!o,$=async h=>{const _=[];for(const te of h){if(!We(te.type))continue;const O=await On(te);O&&_.push({path:"",imageData:O.data,mimeType:O.mimeType,name:O.name})}_.length>0&&W(te=>[...te,..._])},z=async h=>{if(h.size>jr){k(C("fileTooLarge",{name:h.name,size:20}));return}let _;try{_=(await new Promise((O,re)=>{const ee=new FileReader;ee.onload=()=>O(ee.result),ee.onerror=()=>re(ee.error??new Error("read failed")),ee.readAsDataURL(h)})).replace(/^data:[^;]*;base64,/,"")}catch{k(C("fileLoadFailed",{name:h.name}));return}W(te=>[...te,{path:"",fileData:_,name:h.name,size:h.size,mimeType:h.type||void 0}])},ie=async h=>{const _=[];for(const te of h)We(te.type)?_.push(te):z(te);_.length>0&&await $(_)},v=()=>{X(G?`/skill:${G.name}${G.userMessage?` ${G.userMessage}`:""}`:s.content.map(h=>{var _;return((_=ct(h))==null?void 0:_.text)??""}).filter(Boolean).join(`
315
+ `)),W(y??[]),J(!0)},L=()=>{const h=Q.trim();h&&(o==null||o(s.id,h,U.length>0?U:void 0),J(!1))},d=s.role==="custom"&&(s.customType==="goal-review"||s.customType==="goal-wizard"),E=s.role==="custom"&&s.customType==="goal-wizard";return e.jsxs("div",{className:`msg msg-${s.role}${d?" msg-goal-review":""}`,"data-role":s.role,"data-msg-id":s.id,children:[e.jsxs("div",{className:"msg-meta",children:[e.jsx("span",{className:"msg-role",children:s.role==="custom"?E?C("goalWizardCard"):d?C("goalBarTitle"):s.customType==="file"?C("attachment"):`${C("plugin")} · ${s.customType??C("unknown")}`:zn(s.role,C)}),s.model&&e.jsx("span",{className:"msg-model",children:s.model}),s.timestamp&&e.jsx("span",{className:"msg-time",children:Er(s.timestamp)}),m&&e.jsxs("button",{type:"button",className:"msg-collapse-btn",title:C("collapseMsg"),onClick:()=>m(s.id),children:[e.jsx(ut,{})," ",C("collapseMsg")]}),g!==void 0&&b&&e.jsxs("button",{type:"button",className:`qn-tag ${x?"active":""}`,title:`${g+1}. ${M}`,"aria-label":`${g+1}. ${M}`,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:j?e.jsxs("div",{className:`msg-editor${q?" drag-over":""}`,onDragOver:h=>{h.preventDefault(),h.stopPropagation(),Y(!0)},onDragLeave:h=>{h.currentTarget.contains(h.relatedTarget)||Y(!1)},onDrop:h=>{var _;h.preventDefault(),h.stopPropagation(),Y(!1),ie(Array.from(((_=h.dataTransfer)==null?void 0:_.files)??[]))},children:[U.length>0&&e.jsx("div",{className:"msg-editor-images",children:U.map((h,_)=>{var O;const te=wr(h);return e.jsxs("span",{className:`msg-editor-img ${te==="image"?"":"file-chip"}`,title:Nr(h,C),children:[te==="image"?e.jsx("img",{src:`data:${h.mimeType??"image/png"};base64,${h.imageData}`,alt:h.name}):e.jsxs("span",{className:"msg-editor-file",children:[e.jsx("span",{className:"msg-editor-file-icon",children:te==="path"?h.mode==="reference"?"🔗":"📎":"📄"}),e.jsx("span",{className:"msg-editor-file-name",children:h.name??((O=h.path)==null?void 0:O.split("/").pop())})]}),e.jsx("button",{type:"button",className:"msg-editor-img-remove",title:C("removeAttachment"),onClick:()=>W(re=>re.filter((ee,ge)=>ge!==_)),children:e.jsx(Pe,{})})]},`${h.name??h.path??"att"}-${_}`)})}),S&&e.jsx("div",{className:"msg-editor-notice",children:S}),e.jsx("textarea",{className:"msg-editor-input",value:Q,autoFocus:!0,placeholder:C("editPlaceholder"),rows:Math.max(2,Math.min(10,Q.split(`
316
+ `).length+1)),onChange:h=>X(h.target.value),onPaste:h=>{var te;const _=[];for(const O of((te=h.clipboardData)==null?void 0:te.items)??[])if(O.kind==="file"&&We(O.type)){const re=O.getAsFile();re&&_.push(re)}_.length!==0&&(h.preventDefault(),$(_))},onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)?(h.preventDefault(),L()):h.key==="Escape"&&J(!1)}}),e.jsxs("div",{className:"msg-editor-actions",children:[e.jsxs("span",{className:"msg-editor-hint",children:[e.jsx(Ui,{})," ",C("editAttachmentHint")]}),e.jsx("button",{type:"button",className:"chip",onClick:()=>J(!1),children:C("cancel")}),e.jsxs("button",{type:"button",className:"chip primary",disabled:!Q.trim(),title:C("reaskFromHere"),onClick:L,children:[e.jsx(Yt,{})," ",C("reaskFromHere")]})]})]}):e.jsxs(e.Fragment,{children:[s.errorMessage&&e.jsx("div",{className:"msg-error",children:s.errorMessage}),B?e.jsx(Cr,{message:s,forceOpen:H}):G?e.jsxs(e.Fragment,{children:[e.jsx(Tr,{block:G,forceOpen:H}),G.userMessage&&e.jsx("div",{className:"msg-text",children:e.jsx(Rt,{text:G.userMessage})}),s.content.map((h,_)=>h.type==="text"?null:e.jsx(Xs,{block:h,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:a,isLast:i,onKillBash:u,toolsWrap:D,thinkingWrap:T,searchActive:H},`${s.id}-${_}`))]}):s.content.map((h,_)=>e.jsx(Xs,{block:h,toolResults:n,liveOutputs:r,toolStatuses:c,streaming:a,isLast:i,onKillBash:u,toolsWrap:D,thinkingWrap:T,searchActive:H},`${s.id}-${_}`)),I&&e.jsxs("div",{className:"thinking-wait",children:[C("thinkingWait"),e.jsx("span",{className:"dot"})]}),a&&i&&!I&&e.jsx("span",{className:"stream-cursor"})]})}),N&&!j&&e.jsx("div",{className:"msg-actions",children:e.jsxs("button",{type:"button",className:"msg-action",title:C("editReaskTip"),onClick:v,children:[e.jsx(Yt,{})," ",C("editReask")]})})]})});function Cr({message:t,forceOpen:s=!1}){const n=be(),[r,c]=l.useState(!1),a=r||s,i=t.details??{},o=i.name??i.path??n("attachment"),u=i.type==="folder",m=i.mode==="reference",y=i.mode==="bridged",g=t.content.filter(D=>D.type==="text").map(D=>D.text).join(`
317
+ `),x=Sr(g),b=t.content.find(D=>D.type==="image"),T=x.split(`
318
+ `).length;return e.jsxs("div",{className:`attachcard ${m?"reference":""}`,children:[e.jsxs("button",{type:"button",className:"attachcard-head",onClick:()=>c(D=>s?!0:!D),children:[e.jsx("span",{className:"attachcard-icon",children:u?"📁":"📎"}),e.jsx("span",{className:"attachcard-name",children:o}),i.path&&e.jsx("span",{className:"attachcard-path",children:i.path}),e.jsx("span",{className:`attachcard-mode ${i.mode==="lines"?"lines":m?"ref":y?"bridged":"inline"}`,children:m?u?n("folderRefShort"):`${n("refOnlyShort")} · ${Js(i.size)}`:y?n("bridgedVision"):b?n("image"):i.mode==="lines"?n("inlineLinesRange",{start:i.startLine??1,end:i.endLine??i.lines??1}):n("inlineLines",{n:i.lines??T})}),!m&&(a?e.jsx(Ge,{}):e.jsx(Pt,{}))]}),!m&&a&&(y?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"attachcard-bridgenote",children:n("bridgedVisionDetail")}),(b==null?void 0:b.dataUrl)&&e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:b.dataUrl,alt:o})}),x&&e.jsx("pre",{className:"attachcard-content",children:x})]}):b!=null&&b.dataUrl?e.jsx("div",{className:"attachcard-image",children:e.jsx("img",{src:b.dataUrl,alt:o})}):e.jsx("pre",{className:"attachcard-content",children:x})),m&&e.jsx("div",{className:"attachcard-refnote",children:u?n("folderNotExpanded"):n("fileNotExpanded",{size:Js(i.size)})})]})}function Js(t){return t===void 0?"":t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}function Sr(t){const s=t.match(/^\s*<file path="[^"]*"(?:\s+lines="[^"]*")?>\s*```\s*\n?([\s\S]*?)\n?```\s*<\/file>\s*$/);if(s)return s[1].trim();const n=t.match(/^\s*<vision-bridge>\s*([\s\S]*?)\s*<\/vision-bridge>\s*$/);return n?n[1].trim():t.trim()}function Tr({block:t,forceOpen:s=!1}){const n=be(),[r,c]=l.useState(!1),a=r||s;return e.jsxs("div",{className:`skillcard${r?" expanded":""}`,children:[e.jsxs("button",{type:"button",className:"skillcard-head",onClick:()=>c(i=>s?!0:!i),title:t.location,children:[e.jsx("span",{className:"skillcard-icon",children:e.jsx(Ji,{})}),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(ut,{}):e.jsx(Ge,{}),n(a?"collapseMsg":"expandMsg")]})]}),a&&e.jsx("div",{className:"skillcard-body",children:e.jsx(Rt,{text:t.content})})]})}function Xs({block:t,toolResults:s,liveOutputs:n,toolStatuses:r,streaming:c,isLast:a,onKillBash:i,thinkingWrap:o,toolsWrap:u,searchActive:m}){const y=be(),g=ct(t);if(g){const H=c&&a;return e.jsxs("div",{className:"msg-text",children:[H?e.jsx(pr,{text:g.text}):e.jsx(Rt,{text:g.text}),g.truncated&&e.jsx("div",{className:"trunc-note",children:y("truncated")})]})}const x=Kn(t);if(x)return e.jsx(mr,{thinking:x.thinking,streaming:c&&a,wrap:o,forceOpen:m});const b=Wn(t);if(b){const H=s.get(b.id),C=n.get(b.id),j={result:H,liveOutput:C==null?void 0:C.text,streaming:c,status:r.get(b.id)};return e.jsx(fr,{block:b,view:j,onKillBash:i,wrap:u,forceOpen:m})}const T=Un(t);if(T&&T.dataUrl)return e.jsx("div",{className:"msg-image",children:e.jsx("img",{src:T.dataUrl,alt:"attachment"})});const D=qn(t);return D?e.jsxs("div",{className:"bashblock",children:[e.jsxs("div",{className:"bashblock-command",children:[e.jsx("span",{className:"bashblock-prompt",children:"$"}),e.jsx("code",{children:D.command}),D.exitCode!==void 0&&e.jsx("span",{className:`bashblock-exit ${D.exitCode===0?"ok":"err"}`,children:y("exitCode",{code:D.exitCode})}),D.cancelled&&e.jsx("span",{className:"bashblock-exit err",children:y("cancelled")})]}),D.output&&e.jsx("pre",{className:"bashblock-output",children:D.output}),D.truncated&&e.jsx("div",{className:"trunc-note",children:y("outputTruncated")})]}):null}function zn(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 Er(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}function Zs(t,s,n){let r=!1;for(const c of s){const a=c;if(a.type!=="image"||typeof a.dataUrl!="string"||!a.dataUrl.startsWith("data:"))continue;const i=a.dataUrl.match(/^data:([^;]*);base64,(.+)$/);i&&(r=!0,t.push({path:"",imageData:i[2],mimeType:i[1]||"image/png",name:n??`image.${(i[1]||"image/png").split("/")[1]??"png"}`}))}return r}function Pr(t){const s=new Map;for(let n=0;n<t.length;n++){const r=t[n];if(r.role!=="user"||!r.id)continue;const c=[];Zs(c,r.content);for(let a=n+1;a<t.length&&t[a].role==="custom"&&t[a].customType==="file";a++){const i=t[a].details??{};if(!Zs(c,t[a].content,i.name)){if(i.upload&&i.path){c.push({path:"",uploadPath:i.path,name:i.name??i.path,size:i.size});continue}if(i.path&&i.mode){const o=i.mode==="inline"||i.mode==="lines"?i.mode:"reference",u={path:i.path,mode:o};i.mode==="lines"&&typeof i.startLine=="number"&&typeof i.endLine=="number"&&(u.lines={start:i.startLine,end:i.endLine}),c.push(u)}}}c.length>0&&s.set(r.id,c)}return s}const Mr=l.memo(function({message:s,onExpand:n}){const r=be();let c="";for(const g of s.content){const x=ct(g);if(x&&x.text.trim()){const b=ds(x.text);b?c=`skill:${b.name}`+(b.userMessage?` · ${b.userMessage.replace(/\s+/g," ").trim()}`:""):c=x.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 i=0,o=0,u=0,m=0;for(const g of s.content)Kn(g)?i++:Wn(g)?o++:qn(g)?u++:Un(g)&&m++;const y=[];return i&&y.push(`${r("thinking")} ${i}`),o&&y.push(`${r("toolCalls")} ${o}`),u&&y.push(`${r("bashRuns")} ${u}`),m&&y.push(`${r("images")} ${m}`),e.jsxs("button",{type:"button",className:"msg-collapsed","data-msg-id":s.id,title:`${r("expandMsg")} · ${c||y.join(" · ")||s.role}`,onClick:()=>n(s.id),children:[e.jsx("span",{className:`msg-collapsed-role role-${s.role}`,children:s.role==="custom"&&s.customType==="file"?r("attachment"):zn(s.role,r)}),e.jsxs("span",{className:"msg-collapsed-body",children:[c&&e.jsx("span",{className:"msg-collapsed-preview",children:c}),y.length>0&&e.jsx("span",{className:"msg-collapsed-chips",children:y.map((g,x)=>e.jsx("span",{className:"msg-collapsed-chip",children:g},x))})]}),s.timestamp?e.jsx("span",{className:"msg-collapsed-time",children:Rr(s.timestamp)}):null,e.jsxs("span",{className:"msg-collapsed-action",children:[e.jsx(Ge,{})," ",r("expandMsg")]})]})});function Rr(t){const s=new Date(t),n=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${n}:${r}`}const Ir=l.memo(function({id:s,show:n,height:r,containerRef:c,onMeasured:a,lazyRef:i,children:o}){const u=l.useRef(null),m=l.useRef(null);return l.useLayoutEffect(()=>{const y=m.current;if(m.current=n,!n||y!==!1)return;const g=u.current,x=c.current;if(!g||!x)return;const b=g.offsetHeight;a==null||a(s,b);const T=b-r;if(T!==0){const D=g.parentElement;D&&D.getBoundingClientRect().bottom<=x.getBoundingClientRect().top&&(x.scrollTop+=T)}},[n]),n?e.jsx("div",{ref:i,"data-lazy-id":s,children:e.jsx("div",{ref:u,children:o})}):e.jsx("div",{ref:i,className:"msg-lazy-ph","data-msg-id":s,"data-lazy-id":s,style:{height:r},"aria-hidden":"true"})});function Lr(t,s,n,r){const c=[],a=[];let i=0;for(const o of t){if(n.has(o.id))continue;o.top<s.bottom&&o.bottom>s.top?r.has(o.id)&&c.push(o.id):r.has(o.id)||(a.push(o.id),o.bottom<=s.top&&(i+=o.bottom-o.top))}return{show:c,hide:a,shrinkAbove:i}}function Dr(t,s){if(s.show.length===0&&s.hide.length===0)return t;const n=new Set(t);for(const r of s.show)n.delete(r);for(const r of s.hide)n.add(r);return n}function Ar(t,s,n){const r=new Set;let c=0;for(let a=t.length-1;a>=0&&!(a<t.length-1&&c>=n);a--){const i=t[a];r.add(i.id),c+=s.get(i.id)??Vn(i.role,i.customType)}return r}function Vn(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 _r=["text","thinking","argumentsText","output","command"];function Br(t){let s=0;for(const n of t.content){n.type==="image"&&(s+=1);for(const r of _r){const c=n[r];typeof c=="string"&&(s+=c.length)}}return s}function Fr(t,s,n,r){const c=n.get(t);return c&&c.len===s?c.h:r}function $r(t){const s=[];for(const n of t.content)n.type==="text"&&typeof n.text=="string"&&s.push(n.text);return s.join(`
319
+ `)}function Hr(t,s){const n=[];for(const r of t.content)if(r.type==="text"&&typeof r.text=="string")n.push(r.text);else if(r.type==="thinking"&&typeof r.thinking=="string")n.push(r.thinking);else if(r.type==="toolCall"){if(typeof r.name=="string"&&n.push(r.name),typeof r.argumentsText=="string"&&n.push(r.argumentsText),typeof r.id=="string"){const c=s.get(r.id);if(c){const a=$r(c);a&&n.push(a)}}}else r.type==="bash"&&(typeof r.command=="string"&&n.push(r.command),typeof r.output=="string"&&n.push(r.output));return n.join(`
320
+ `)}function Or(t,s){let n=0,r=t.indexOf(s);for(;r!==-1;)n++,r=t.indexOf(s,r+s.length);return n}function Kr(t,s,n,r){const c=new Map,a=n.toLowerCase();if(!a)return c;for(const i of t){if(!s.has(i.id))continue;const o=Or(Hr(i,r).toLowerCase(),a);o>0&&c.set(i.id,o)}return c}function Wr(t,s){var a;const n=[],r=s.toLowerCase();if(!r)return n;const c=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(i){const o=i.parentElement;return!o||o.closest(".search-bar")||o.closest(".msg-collapsed")?NodeFilter.FILTER_REJECT:(i.textContent??"").toLowerCase().includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let i=c.nextNode();i;i=c.nextNode()){const o=(i.textContent??"").toLowerCase();if(!((a=i.parentElement)!=null&&a.closest("[data-msg-id]")))continue;let u=o.indexOf(r);for(;u!==-1;){const m=document.createRange();m.setStart(i,u),m.setEnd(i,u+r.length),n.push(m),u=o.indexOf(r,u+r.length)}}return n}function Ur(t,s,n,r,c){var u;const a=Kr(n,r,s,c),i=new Map;for(const m of Wr(t,s)){const y=(u=m.startContainer.parentElement)==null?void 0:u.closest("[data-msg-id]");if(!(y!=null&&y.dataset.msgId))continue;const g=i.get(y.dataset.msgId);g?g.push(m):i.set(y.dataset.msgId,[m])}const o=[];for(const m of n){const y=i.get(m.id);if(y)for(let x=0;x<y.length;x++)o.push({kind:"dom",range:y[x],msgId:m.id,k:x});const g=a.get(m.id);if(g)for(let x=0;x<g;x++)o.push({kind:"folded",msgId:m.id,k:x})}return o}function Kt(t,s){return t.findIndex(n=>n.msgId===s.msgId&&n.k===s.k)}function $e(t,s){const n=CSS;if(!n.highlights)return;if(s.length===0){n.highlights.delete(t);return}const r=window.Highlight;r&&n.highlights.set(t,new r(...s))}function qr(t,s){const n=[];let r=t;for(;r&&r!==s;){const c=getComputedStyle(r);/(auto|scroll|hidden)/.test(c.overflowY+c.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&n.push(r),r=r.parentElement}return n}function zr(t,s){const n=s.startContainer.parentElement;for(const o of qr(n,t)){const u=s.getBoundingClientRect(),m=o.getBoundingClientRect();if(u.height<=0||u.width<=0)return;u.top>=m.top+4&&u.bottom<=m.bottom-4||(o.scrollTop+=u.top-m.top-(o.clientHeight-u.height)/2),u.left>=m.left+4&&u.right<=m.right-4||(o.scrollLeft+=u.left-m.left-(o.clientWidth-u.width)/2)}const r=s.getBoundingClientRect(),c=t.getBoundingClientRect();if(r.height<=0||r.width<=0)return;const a=r.top>=c.top+6&&r.bottom<=c.bottom-6,i=r.left>=c.left+6&&r.right<=c.right-6;a&&i||(a||(t.scrollTop+=r.top-c.top-(c.height-r.height)/2),i||(t.scrollLeft+=r.left-c.left-(c.width-r.width)/2))}function Vr({containerRef:t,messages:s,collapsedIds:n,toolResults:r,onExpand:c,onProgrammaticScroll:a,open:i,onClose:o}){const u=be(),m=l.useRef(null),[y,g]=l.useState(""),[x,b]=l.useState(null),[T,D]=l.useState(0),[,H]=l.useState(0),C=l.useDeferredValue(y),j=i?C.trim():"",J=l.useRef(null);J.current=x;const Q=l.useRef([]),X=l.useRef({key:null}),U=l.useRef("");l.useEffect(()=>{i&&(b(null),requestAnimationFrame(()=>{var Y;return(Y=m.current)==null?void 0:Y.select()}))},[i]),l.useEffect(()=>{if(!i)return;const Y=S=>{S.key==="Escape"&&(S.preventDefault(),S.stopPropagation(),o())};return window.addEventListener("keydown",Y,!0),()=>window.removeEventListener("keydown",Y,!0)},[i,o]),l.useEffect(()=>(i||($e("msg-search",[]),$e("msg-search-active",[])),()=>{$e("msg-search",[]),$e("msg-search-active",[])}),[i]),l.useLayoutEffect(()=>{const Y=()=>{D(0),b(null),H(0),Q.current=[],$e("msg-search",[]),$e("msg-search-active",[]),X.current={key:null},U.current=""};if(!i||!j){Y();return}const S=t.current;if(!S)return;let P=!1,k=0;return k=requestAnimationFrame(()=>{var ie,v;if(P)return;const B=Ur(S,j,s,n,r);Q.current=B;const Z=B.length;if(D(Z),Z===0){b(null),H(0),$e("msg-search",[]),$e("msg-search-active",[]),X.current={key:null},U.current=j;return}const G=J.current;let M;if(G){if(M=Kt(B,G),M===-1){const L=[];for(let d=0;d<B.length;d++)B[d].msgId===G.msgId&&L.push(d);if(L.length>0){const d=Math.min(G.k,L.length-1);M=L[d]}else M=0}}else M=0;M<0&&(M=0),M>=Z&&(M=Z-1),(!G||G.msgId!==B[M].msgId||G.k!==B[M].k)&&b({msgId:B[M].msgId,k:B[M].k}),H(M);const I=B[M],N=X.current,$=((ie=N.key)==null?void 0:ie.msgId)!==I.msgId||((v=N.key)==null?void 0:v.k)!==I.k||N.kind==="folded"&&I.kind==="dom"||j!==U.current;X.current={key:{msgId:I.msgId,k:I.k},kind:I.kind},U.current=j;const z=B.filter(L=>L.kind==="dom").map(L=>L.range);if($e("msg-search",z),I.kind==="folded"){$e("msg-search-active",[]),$&&c(I.msgId);return}$e("msg-search-active",[I.range]),$&&(a==null||a(),zr(S,I.range))}),()=>{P=!0,cancelAnimationFrame(k)}},[i,j,s,t,x,n,r,c,a]);const W=l.useCallback(Y=>{const S=Q.current,P=S.length;if(P===0)return;const k=J.current,B=k?Kt(S,k):0,Z=S[(B+Y+P)%P];b(Z.kind==="dom"||Z.kind==="folded"?{msgId:Z.msgId,k:Z.k}:null)},[]);if(!i)return null;const q=x?(()=>{const Y=Kt(Q.current,x);return Y===-1?0:Y})():0;return e.jsxs("div",{className:"search-bar",role:"search",children:[e.jsx("input",{ref:m,className:"search-input",type:"text",value:y,placeholder:u("searchPlaceholder"),onChange:Y=>{g(Y.target.value)},onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),W(Y.shiftKey?-1:1))}}),e.jsx("span",{className:`search-count ${T===0?"empty":""}`,children:T===0?u("searchNoResults"):`${Math.min(q+1,T)}/${T}`}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchPrev"),disabled:T===0,onClick:()=>W(-1),children:e.jsx(ut,{})}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchNext"),disabled:T===0,onClick:()=>W(1),children:e.jsx(Ge,{})}),e.jsx("button",{type:"button",className:"search-btn",title:u("searchClose"),onClick:o,children:e.jsx(Pe,{})})]})}function Gr(t){const{dSt:s,dSh:n,escaped:r,graceActive:c,stuck:a}=t;return c?{flipEscape:!1,reassert:!1}:s>=-4||s<=-500?{flipEscape:!1,reassert:!1}:n<0?{flipEscape:!1,reassert:a&&!r}:{flipEscape:!0,reassert:!1}}const Gn=[{id:"setup-matt-pocock-skills",icon:"🛠",titleKey:"tpl.sk.setup",descKey:"tpl.sk.setup.desc",promptKey:"tpl.sk.setup.prompt"},{id:"ask-matt",icon:"🧭",titleKey:"tpl.sk.ask",descKey:"tpl.sk.ask.desc",promptKey:"tpl.sk.ask.prompt"},{id:"grill-with-docs",icon:"🗣",titleKey:"tpl.sk.grilldocs",descKey:"tpl.sk.grilldocs.desc",promptKey:"tpl.sk.grilldocs.prompt"},{id:"to-spec",icon:"📝",titleKey:"tpl.sk.tospec",descKey:"tpl.sk.tospec.desc",promptKey:"tpl.sk.tospec.prompt"},{id:"to-tickets",icon:"🎫",titleKey:"tpl.sk.totickets",descKey:"tpl.sk.totickets.desc",promptKey:"tpl.sk.totickets.prompt"},{id:"implement",icon:"🏗",titleKey:"tpl.sk.implement",descKey:"tpl.sk.implement.desc",promptKey:"tpl.sk.implement.prompt"},{id:"code-review",icon:"🧹",titleKey:"tpl.sk.codeview",descKey:"tpl.sk.codeview.desc",promptKey:"tpl.sk.codeview.prompt"},{id:"wayfinder",icon:"🗺",titleKey:"tpl.sk.wayfinder",descKey:"tpl.sk.wayfinder.desc",promptKey:"tpl.sk.wayfinder.prompt"},{id:"prototype",icon:"🔬",titleKey:"tpl.sk.prototype",descKey:"tpl.sk.prototype.desc",promptKey:"tpl.sk.prototype.prompt"},{id:"research",icon:"📚",titleKey:"tpl.sk.research",descKey:"tpl.sk.research.desc",promptKey:"tpl.sk.research.prompt"},{id:"improve-codebase-architecture",icon:"🏛",titleKey:"tpl.sk.arch",descKey:"tpl.sk.arch.desc",promptKey:"tpl.sk.arch.prompt"},{id:"diagnosing-bugs",icon:"🐛",titleKey:"tpl.sk.debug",descKey:"tpl.sk.debug.desc",promptKey:"tpl.sk.debug.prompt"},{id:"resolving-merge-conflicts",icon:"🔀",titleKey:"tpl.sk.merge",descKey:"tpl.sk.merge.desc",promptKey:"tpl.sk.merge.prompt"},{id:"triage",icon:"🗂",titleKey:"tpl.sk.triage",descKey:"tpl.sk.triage.desc",promptKey:"tpl.sk.triage.prompt"},{id:"wizard",icon:"✨",titleKey:"tpl.sk.wizard",descKey:"tpl.sk.wizard.desc",promptKey:"tpl.sk.wizard.prompt"},{id:"grill-me",icon:"🔍",titleKey:"tpl.sk.grillme",descKey:"tpl.sk.grillme.desc",promptKey:"tpl.sk.grillme.prompt"},{id:"handoff",icon:"🤝",titleKey:"tpl.sk.handoff",descKey:"tpl.sk.handoff.desc",promptKey:"tpl.sk.handoff.prompt"},{id:"to-questionnaire",icon:"📋",titleKey:"tpl.sk.questionnaire",descKey:"tpl.sk.questionnaire.desc",promptKey:"tpl.sk.questionnaire.prompt"},{id:"teach",icon:"🎓",titleKey:"tpl.sk.teach",descKey:"tpl.sk.teach.desc",promptKey:"tpl.sk.teach.prompt"},{id:"wait-what",icon:"💬",titleKey:"tpl.sk.ww",descKey:"tpl.sk.ww.desc",promptKey:"tpl.sk.ww.prompt"},{id:"writing-for-agents",icon:"📄",titleKey:"tpl.sk.wfa",descKey:"tpl.sk.wfa.desc",promptKey:"tpl.sk.wfa.prompt"},{id:"codebase-design",icon:"🧱",titleKey:"tpl.sk.codesign",descKey:"tpl.sk.codesign.desc",promptKey:"tpl.sk.codesign.prompt"},{id:"domain-modeling",icon:"🏷",titleKey:"tpl.sk.domain",descKey:"tpl.sk.domain.desc",promptKey:"tpl.sk.domain.prompt"},{id:"grilling",icon:"🔥",titleKey:"tpl.sk.grilling",descKey:"tpl.sk.grilling.desc",promptKey:"tpl.sk.grilling.prompt"},{id:"tdd",icon:"🧪",titleKey:"tpl.sk.tdd",descKey:"tpl.sk.tdd.desc",promptKey:"tpl.sk.tdd.prompt"}],Qn="pi-web-ui:prompt-templates";function Qr(){try{const t=localStorage.getItem(Qn);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s.filter(n=>!!n&&typeof n=="object"&&typeof n.id=="string"):[]}catch{return[]}}function en(t){return Gn.some(s=>s.id===t)}function ft(t){return typeof t.title=="string"}const Yn=l.createContext(null);function Jn(){const t=l.useContext(Yn);if(!t)throw new Error("useTemplates must be used within TemplateProvider");return t}function Yr({send:t,children:s}){const n=be(),[r,c]=l.useState(Qr),[a,i]=l.useState(!1),[o,u]=l.useState(null),[m,y]=l.useState(!1),[g,x]=l.useState(!1),[b,T]=l.useState(!1);l.useEffect(()=>{try{localStorage.setItem(Qn,JSON.stringify(r))}catch{}},[r]);const D=l.useMemo(()=>{const B=new Map,Z=new Set;for(const I of r)I.hidden?Z.add(I.id):(ft(I)&&!en(I.id)||ft(I))&&B.set(I.id,I);const G=Gn.filter(I=>!Z.has(I.id)).map(I=>{const N=B.get(I.id);return{id:I.id,icon:(N==null?void 0:N.icon)??I.icon,title:(N==null?void 0:N.title)??n(I.titleKey),desc:(N==null?void 0:N.desc)??n(I.descKey),prompt:(N==null?void 0:N.prompt)??n(I.promptKey),builtin:!0}}),M=r.filter(I=>ft(I)&&!en(I.id)).map(I=>({id:I.id,icon:I.icon??"📌",title:I.title??"",desc:I.desc??"",prompt:I.prompt??""}));return[...G,...M]},[r,n]),H=l.useCallback(()=>i(!0),[]),C=l.useCallback(B=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:B}))},[]),j=l.useCallback((B,Z=!1)=>{T(Z),B?(y(!1),u({...B})):(y(!0),u({id:Ue(),icon:"📌",title:"",desc:"",prompt:""}))},[]),J=l.useCallback(()=>{i(!1),u(null),T(!1)},[]),Q=l.useCallback(()=>{g?(c([]),x(!1)):(x(!0),setTimeout(()=>x(!1),5e3))},[g]),X=l.useCallback(B=>{i(!1),C(B.prompt)},[C]),U=l.useCallback(B=>{i(!1),j(B,!0)},[j]),W=l.useCallback(()=>{i(!1),j(void 0,!0)},[j]),q=l.useCallback(B=>{c(Z=>{const G=Z.findIndex(M=>M.id===B.id);if(G>=0){const M=[...Z];return M[G]=B,M}return[...Z,B]}),u(null),b&&(i(!0),T(!1))},[b]),Y=l.useCallback(B=>{c(Z=>B.builtin?[...Z.filter(M=>M.id!==B.id),{id:B.id,hidden:!0}]:Z.filter(G=>G.id!==B.id)),u(null),b&&(i(!0),T(!1))},[b]),S=l.useCallback(B=>{c(Z=>Z.filter(G=>G.id!==B.id||G.hidden)),u(null),b&&(i(!0),T(!1))},[b]),P=l.useMemo(()=>({templates:D,fill:C,openPicker:H,openEdit:j,resetConfirm:g,toggleReset:Q}),[D,C,H,j,g,Q]),k=o?r.some(B=>B.id===o.id&&!B.hidden&&ft(B)):!1;return e.jsxs(Yn.Provider,{value:P,children:[s,a&&e.jsx(Xr,{templates:D,resetConfirm:g,onFill:X,onEditTpl:U,onNew:W,onResetToggle:Q,onClose:J}),o&&e.jsx(Zr,{editing:o,isNew:m,hasOverride:k,onDraft:u,onSave:q,onRestore:()=>S(o),onRemove:()=>Y(o),onFill:()=>{window.dispatchEvent(new CustomEvent("pi-web:fill",{detail:o.prompt})),J()},onSend:()=>{const B=o.prompt.trim();B&&t({type:"prompt",text:B,queue:!1})&&J()},onClose:J})]})}function Jr(){const t=be(),{templates:s,fill:n,openEdit:r,toggleReset:c,resetConfirm:a}=Jn();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(i=>e.jsx(Xn,{tpl:i,title:t("tpl.clickCard"),onFill:()=>n(i.prompt),onEdit:()=>r(i),editTitle:t("tpl.editTpl")},i.id)),e.jsxs("button",{type:"button",className:"empty-template add",onClick:()=>r(),title:t("tpl.add"),children:[e.jsx("span",{className:"empty-template-icon",children:e.jsx(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:t("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:t("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"empty-templates-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:c,children:[e.jsx(bn,{}),t(a?"tpl.resetConfirm":"tpl.reset")]})})]})}function Xn({tpl:t,title:s,onFill:n,onEdit:r,editTitle:c}){const a=be();return e.jsxs("button",{type:"button",className:"empty-template",title:s,onClick:n,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??a("tpl.editTpl"),onClick:i=>{i.stopPropagation(),r()},children:e.jsx(St,{})})]})}function Xr({templates:t,resetConfirm:s,onFill:n,onEditTpl:r,onNew:c,onResetToggle:a,onClose:i}){const o=be();return l.useEffect(()=>{const u=m=>{m.key==="Escape"&&i()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i]),e.jsx("div",{className:"modal-backdrop",onClick:i,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:i,children:e.jsx(Pe,{})})]}),e.jsx("div",{className:"template-picker-hint",children:o("tpl.pickerHint")}),e.jsxs("div",{className:"template-picker-grid",children:[t.map(u=>e.jsx(Xn,{tpl:u,title:o("tpl.clickCard"),onFill:()=>n(u),onEdit:()=>r(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(He,{})}),e.jsxs("span",{className:"empty-template-main",children:[e.jsx("span",{className:"empty-template-title",children:o("tpl.add")}),e.jsx("span",{className:"empty-template-desc",children:o("tpl.addDesc")})]})]})]}),e.jsx("div",{className:"template-picker-foot",children:e.jsxs("button",{type:"button",className:"empty-templates-reset",onClick:a,children:[e.jsx(bn,{}),o(s?"tpl.resetConfirm":"tpl.reset")]})})]})})}function Zr({editing:t,isNew:s,hasOverride:n,onDraft:r,onSave:c,onRestore:a,onRemove:i,onFill:o,onSend:u,onClose:m}){const y=be(),g=l.useRef(null);l.useEffect(()=>{const T=D=>{D.key==="Escape"&&m()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[m]),l.useEffect(()=>{const T=g.current;if(!T)return;T.style.height="auto";const D=T.scrollHeight>300;T.style.height=`${Math.min(T.scrollHeight,300)}px`,T.style.overflowY=D?"auto":"hidden"},[t.prompt]);const x=()=>{const T=t.title.trim(),D=t.prompt.trim();if(!T||!D){r({...t,error:y("tpl.required")});return}c({id:t.id,icon:t.icon.trim()||"📌",title:T,desc:t.desc.trim(),prompt:D})},b=!!t.builtin&&!s;return e.jsx("div",{className:"modal-backdrop",onClick:m,children:e.jsxs("div",{className:"modal template-modal",onClick:T=>T.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:y(b?"tpl.builtin":"tpl.custom")}),e.jsx("span",{className:"template-modal-title",children:y(s?"tpl.newTitle":"tpl.editTitle")}),e.jsx("button",{type:"button",className:"btn template-modal-close",title:y("close"),onClick:m,children:e.jsx(Pe,{})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldIcon")}),e.jsx("input",{className:"template-field-input icon",value:t.icon,maxLength:4,onChange:T=>r({...t,icon:T.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldTitle")}),e.jsx("input",{className:"template-field-input",value:t.title,placeholder:y("tpl.fieldTitlePh"),onChange:T=>r({...t,title:T.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldDesc")}),e.jsx("input",{className:"template-field-input",value:t.desc,placeholder:y("tpl.fieldDescPh"),onChange:T=>r({...t,desc:T.target.value})})]}),e.jsxs("label",{className:"template-field",children:[e.jsx("span",{className:"template-field-label",children:y("tpl.fieldPrompt")}),e.jsx("textarea",{ref:g,className:"template-field-prompt",value:t.prompt,placeholder:y("tpl.fieldPromptPh"),onChange:T=>r({...t,prompt:T.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&&n&&e.jsx("button",{type:"button",className:"btn template-btn ghost",title:y("tpl.restoreTip"),onClick:a,children:y("tpl.restore")}),!s&&b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:y("tpl.removeTip"),onClick:i,children:[e.jsx(Ae,{})," ",y("tpl.remove")]}),!s&&!b&&e.jsxs("button",{type:"button",className:"btn template-btn ghost danger",title:y("tpl.deleteTip"),onClick:i,children:[e.jsx(Ae,{})," ",y("tpl.delete")]})]}),e.jsxs("div",{className:"template-modal-actions-right",children:[e.jsx("button",{type:"button",className:"btn template-btn",onClick:x,children:y("tpl.save")}),e.jsx("button",{type:"button",className:"btn template-btn fill",onClick:o,title:y("tpl.fillTip"),children:y("tpl.fill")}),e.jsxs("button",{type:"button",className:"btn template-btn send",onClick:u,title:y("tpl.sendTip"),children:[e.jsx(vn,{})," ",y("tpl.sendNow")]})]})]})]})})}const tn=new Map,el=15,sn=30,Wt=250,nn=1200,tl=1600;function an(t){return t.content.some(s=>s.type==="toolCall")}function sl({state:t,liveOutputs:s,toolStatuses:n,onEdit:r,onKillBash:c,onRemoveQueued:a,thinkingWrap:i,toolsWrap:o,jumpTarget:u,onJumpDone:m}){const y=be(),g=l.useRef(null),[x,b]=l.useState(!0),T=l.useRef(!0),D=l.useRef(0),H=l.useRef(0),C=l.useRef(!1),j=l.useRef(0),[J,Q]=l.useState(()=>new Set),[X,U]=l.useState(!1),W=t.streamingMessage?[...t.messages,t.streamingMessage]:t.messages,q=l.useMemo(()=>{const w=new Map;for(const A of t.messages)A.role==="toolResult"&&A.toolCallId&&w.set(A.toolCallId,A);return w},[t.messages]),Y=l.useMemo(()=>Pr(t.messages),[t.messages]),S=W.length>0?W[W.length-1].id:null,P=t.messages.length>sn?Math.max(0,t.messages.length-el):0,k=l.useMemo(()=>{const w=new Set;for(let A=0;A<P;A++){const ae=t.messages[A];ae.role!=="toolResult"&&(J.has(ae.id)||w.add(ae.id))}return w},[t.messages,P,J]),[B,Z]=l.useState(()=>new Set),[G,M]=l.useState(()=>new Set),I=l.useRef(new Map),N=l.useRef(new Map),$=l.useRef(new Map),z=l.useRef(0),ie=l.useMemo(()=>{const w=new Map;for(const A of t.messages)w.set(A.id,Br(A));return w},[t.messages]),v=l.useRef(ie);v.current=ie;const L=l.useRef(B);L.current=B;const d=t.messages.length>sn&&!X,E=l.useRef(d);E.current=d;const h=Ar(t.messages,I.current,tl),_=l.useRef(h);_.current=h;const te=l.useCallback(()=>{const w=g.current;if(!w)return;if(!E.current){Z(we=>we.size?new Set:we);return}const A=w.getBoundingClientRect(),ae={top:A.top-nn,bottom:A.bottom+nn},oe=[];for(const[we,Ee]of $.current){const Oe=Ee.getBoundingClientRect();oe.push({id:we,top:Oe.top,bottom:Oe.bottom}),L.current.has(we)||ee(we,Oe.bottom-Oe.top,v.current.get(we))}const je=Lr(oe,ae,_.current,L.current);for(const we of je.hide){const Ee=$.current.get(we);Ee&&ee(we,Ee.offsetHeight,v.current.get(we))}Z(we=>Dr(we,je))},[]),O=l.useCallback(()=>{z.current||(z.current=requestAnimationFrame(()=>{z.current=0,te()}))},[te]);l.useLayoutEffect(()=>{te()},[te]);const re=l.useRef(X);l.useLayoutEffect(()=>{re.current&&!X&&te(),re.current=X},[X,te]);const ee=l.useCallback((w,A,ae)=>{ae!==void 0&&(N.current.set(w,{h:A,len:ae}),I.current.set(w,A))},[]),ge=l.useCallback((w,A)=>{ee(w,A,v.current.get(w))},[ee]),ue=l.useCallback(w=>{w&&$.current.set(w.dataset.lazyId??"",w)},[]);l.useEffect(()=>{const w=new Set(t.messages.map(A=>A.id));for(const A of $.current.keys())w.has(A)||($.current.delete(A),I.current.delete(A),N.current.delete(A));Z(A=>{let ae=!1;const oe=new Set;for(const je of A)w.has(je)?oe.add(je):ae=!0;return ae?oe:A})},[t.messages,J]),l.useEffect(()=>()=>cancelAnimationFrame(z.current),[]);const de=l.useMemo(()=>{const w=[];for(const A of t.messages){if(A.role!=="user")continue;const ae=A.content.map(we=>{var Ee;return((Ee=ct(we))==null?void 0:Ee.text)??""}).filter(Boolean).join(" "),oe=ds(ae),je=oe?oe.userMessage??`skill:${oe.name}`:ae.trim();je&&w.push({id:A.id,text:je})}return w},[t.messages]),Se=l.useMemo(()=>{const w=new Map;return de.forEach((A,ae)=>w.set(A.id,ae)),w},[de]),[le,f]=l.useState(-1),K=l.useRef(-1),me=l.useRef(de);l.useEffect(()=>{me.current=de},[de]);const he=l.useCallback(()=>{const w=g.current,A=me.current;if(!w||A.length===0)return;const ae=w.getBoundingClientRect().top,oe=140;let je=-1;for(let we=0;we<A.length;we++){const Ee=w.querySelector(`[data-msg-id="${A[we].id}"]`);if(Ee)if(Ee.getBoundingClientRect().top<=ae+oe)je=we;else break}je!==K.current&&(K.current=je,f(je))},[]);l.useEffect(()=>{he()},[de,he]);const xe=l.useCallback(w=>{Q(A=>A.has(w)?A:new Set(A).add(w))},[]);l.useEffect(()=>{const w=A=>{if(!(A.ctrlKey||A.metaKey)||A.key.toLowerCase()!=="f")return;const ae=A.target;ae&&(ae.tagName==="INPUT"||ae.tagName==="TEXTAREA"||ae.isContentEditable)||(A.preventDefault(),U(!0))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[]);const fe=l.useCallback(w=>{Q(A=>{if(!A.has(w))return A;const ae=new Set(A);return ae.delete(w),ae})},[]),ke=l.useCallback(w=>{const A=t.messages.findIndex(oe=>oe.id===w);qa.flushSync(()=>{A>=0&&A<P&&!J.has(w)&&xe(w),M(oe=>oe.has(w)?oe:new Set(oe).add(w))});const ae=me.current.findIndex(oe=>oe.id===w);K.current=ae,f(ae),requestAnimationFrame(()=>{var je,we,Ee;const oe=(je=g.current)==null?void 0:je.querySelector(`[data-msg-id="${w}"]`);oe&&((we=g.current)==null||we.querySelectorAll(".msg-flash").forEach(Oe=>Oe.classList.remove("msg-flash")),oe.scrollIntoView({block:"start"}),oe.classList.remove("msg-flash"),oe.offsetWidth,oe.classList.add("msg-flash"),oe!==((Ee=g.current)==null?void 0:Ee.lastElementChild)&&(C.current=!0))})},[t.messages,P,J,xe]),Me=l.useMemo(()=>{var w;return u?((w=t.messages.find(A=>A.role===u.role&&A.timestamp===u.timestamp))==null?void 0:w.id)??null:null},[t.messages,u]);l.useEffect(()=>{if(u){if(Me){ke(Me),m==null||m();return}t.sessionFile===u.path&&t.messages.length>0&&(m==null||m())}},[Me,ke,m,u,t.sessionFile,t.messages.length]);const ye=l.useCallback(()=>{const w=g.current;if(!w)return;const A=w.scrollTop-D.current,ae=w.scrollHeight-H.current;D.current=w.scrollTop,H.current=w.scrollHeight;const oe=w.scrollHeight-w.scrollTop-w.clientHeight<80,je=Date.now()<j.current,we=Gr({dSt:A,dSh:ae,escaped:C.current,graceActive:je,stuck:T.current});we.reassert&&(j.current=Date.now()+Wt,w.scrollTop=w.scrollHeight),we.flipEscape&&(C.current=!0),oe&&A>=0&&(C.current=!1),je||(A<0?T.current=oe&&!C.current:oe&&(T.current=!0)),b(T.current),he(),O()},[he,O]),_e=l.useRef(!1);l.useEffect(()=>{const w=_e.current;if(_e.current=!!t.isStreaming,w&&!t.isStreaming&&!C.current){const A=()=>{const oe=g.current;oe&&!C.current&&(oe.scrollTop=oe.scrollHeight,T.current=!0,b(!0))};requestAnimationFrame(()=>requestAnimationFrame(A));const ae=setTimeout(A,180);return()=>clearTimeout(ae)}},[t.isStreaming]),l.useEffect(()=>{const w=g.current;w&&T.current&&(w.scrollTop=w.scrollHeight)},[W,t.isStreaming,s]);const Le=t.queue.steering.join("\0")+""+t.queue.followUp.join("\0");l.useEffect(()=>{const w=g.current;w&&T.current&&(w.scrollTop=w.scrollHeight)},[Le]),l.useEffect(()=>{const w=g.current;if(!w||typeof ResizeObserver>"u")return;const A=new ResizeObserver(()=>{T.current&&!C.current&&(w.scrollTop=w.scrollHeight,b(!0))});return A.observe(w),()=>A.disconnect()},[]),l.useEffect(()=>{const w=g.current;if(!w||typeof MutationObserver>"u")return;let A=!1;const ae=new MutationObserver(()=>{A||(A=!0,requestAnimationFrame(()=>{A=!1;const oe=g.current;oe&&T.current&&!C.current&&(oe.scrollTop=oe.scrollHeight,b(!0))}))});return ae.observe(w,{childList:!0,subtree:!0,characterData:!0}),()=>ae.disconnect()},[]);const Be=l.useCallback(()=>{if(!g.current)return;T.current=!0,C.current=!1,b(!0),j.current=Date.now()+Wt;const A=()=>{const ae=g.current;!ae||!T.current||C.current||(j.current=Date.now()+Wt,ae.scrollTop=ae.scrollHeight)};A(),requestAnimationFrame(()=>requestAnimationFrame(A)),setTimeout(A,120),setTimeout(A,300),setTimeout(A,600)},[]),De=l.useRef(null);l.useEffect(()=>{const w=De.current,A=g.current;if(!w||!A)return;const ae=oe=>{oe.preventDefault();const je=w.querySelector(".qn-list");if(je&&je.contains(oe.target)&&je.scrollHeight>je.clientHeight){je.scrollTop+=oe.deltaY;return}A.scrollTop+=oe.deltaY};return w.addEventListener("wheel",ae,{passive:!1}),()=>w.removeEventListener("wheel",ae)},[]);const[R,ve]=l.useState(0);l.useEffect(()=>{const w=()=>{var A;ve(((A=g.current)==null?void 0:A.clientHeight)??0),O()};return w(),window.addEventListener("resize",w),()=>window.removeEventListener("resize",w)},[O]);const ce=de.length,p=l.useMemo(()=>ce===0?27:Math.max(4,Math.min(27,Math.floor(((R||600)-16)/ce)-3)),[ce,R]),V=p<20;return e.jsxs("div",{className:"messages-wrap",children:[e.jsxs("div",{className:`messages${X||x?"":" anchor-live"}`,ref:g,onScroll:ye,children:[t.messages.length===0&&!t.streamingMessage&&e.jsx("div",{className:"empty-state",children:e.jsx(Jr,{})}),t.messages.map((w,A)=>{const ae=A<P,oe=ae&&J.has(w.id);if(ae&&!oe)return w.role==="toolResult"?null:e.jsx(Mr,{message:w,onExpand:xe},w.id);const je=w.role==="user"?Se.get(w.id):void 0,we=!d||h.has(w.id)||G.has(w.id)||!B.has(w.id);return e.jsx(Ir,{id:w.id,show:we,height:Fr(w.id,ie.get(w.id)??-1,N.current,Vn(w.role,w.customType)),containerRef:g,onMeasured:ge,lazyRef:ue,children:e.jsx(Ys,{message:w,qnIndex:je,qnActive:je!==void 0?je===le:void 0,onJump:ke,toolResults:q,liveOutputs:an(w)?s:tn,toolStatuses:n,streaming:t.isStreaming,onKillBash:c,toolsWrap:o,thinkingWrap:i,isLast:w.id===S,onEdit:r,questionAttachments:Y.get(w.id),onCollapse:oe?fe:void 0,searchActive:X},w.id)},w.id)}),t.streamingMessage&&e.jsx(Ys,{message:t.streamingMessage,toolResults:q,liveOutputs:an(t.streamingMessage)?s:tn,toolStatuses:n,streaming:!0,isLast:!0,onEdit:r,onKillBash:c,toolsWrap:o,thinkingWrap:i,searchActive:X},t.streamingMessage.id),t.isStreaming&&W.length===0&&e.jsx("div",{className:"streaming-wait",children:y("waitingResponse")}),t.queue.steering.map((w,A)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag steer",children:y("queueSteerTag")}),e.jsx("div",{className:"queued-text",children:w}),a&&e.jsx("button",{type:"button",className:"queued-remove",title:y("queueRemoveTip"),onClick:()=>a("steer",w),children:"✕"})]})},`q-steer-${A}`)),t.queue.followUp.map((w,A)=>e.jsx("div",{className:"queued-msg",children:e.jsxs("div",{className:"queued-bubble",children:[e.jsx("span",{className:"queued-tag follow",children:y("queueFollowTag")}),e.jsx("div",{className:"queued-text",children:w}),a&&e.jsx("button",{type:"button",className:"queued-remove",title:y("queueRemoveTip"),onClick:()=>a("followUp",w),children:"✕"})]})},`q-fu-${A}`))]}),!x&&e.jsxs("button",{type:"button",className:"scroll-bottom",onClick:Be,children:[e.jsx(Sn,{})," ",y("backToBottom")]}),e.jsx(Vr,{containerRef:g,messages:W,collapsedIds:k,toolResults:q,onExpand:xe,onProgrammaticScroll:()=>{C.current=!0,T.current=!1,b(!1)},open:X,onClose:()=>U(!1)}),de.length>0&&e.jsxs("div",{className:`qn-rail ${V?"many":""}`,ref:De,"aria-label":y("questionNavTitle"),style:{"--rail-gap":`${p}px`},children:[de.map((w,A)=>e.jsx("button",{type:"button",className:`qn-bar ${A===le?"active":""}`,"aria-label":`${A+1}. ${w.text}`,onClick:()=>ke(w.id),children:e.jsxs("span",{className:"qn-bar-text",children:[A+1,". ",w.text]})},w.id)),V&&e.jsx("div",{className:"qn-list",children:de.map((w,A)=>e.jsxs("button",{type:"button",className:`qn-list-item ${A===le?"active":""}`,"aria-label":`${A+1}. ${w.text}`,onClick:()=>ke(w.id),children:[e.jsx("span",{className:"qn-list-idx",children:A+1}),e.jsx("span",{className:"qn-list-text",children:w.text})]},w.id))})]})]})}const Zn="pi-web-model-usage";function nl(t){if(!t||typeof t!="object")return{};const s={};for(const[n,r]of Object.entries(t)){const c=typeof r=="number"?Math.floor(r):0;Number.isFinite(c)&&c>0&&(s[n]=c)}return s}function il(t,s){return s?{...t,[s]:(t[s]??0)+1}:t}function al(t,s){const n=s;return t.map((r,c)=>({m:r,i:c,count:n[r.id]??0})).sort((r,c)=>c.count-r.count||r.i-c.i).map(r=>r.m)}function ei(){try{const t=localStorage.getItem(Zn);return t?nl(JSON.parse(t)):{}}catch{return{}}}function rl(t){try{localStorage.setItem(Zn,JSON.stringify(t))}catch{}}function ll(t){const s=il(ei(),t);return rl(s),s}const us="pi-web-ui:prompt-history",ol=100,ti="pi-web-ui:prompt-history-settings",is={maxEntries:100,charLimitEnabled:!1,charLimit:2e3};function si(t){const s=is;if(!t||typeof t!="object")return{...s};const n=t;let r=typeof n.maxEntries=="number"?Math.floor(n.maxEntries):s.maxEntries;(!Number.isFinite(r)||r<1)&&(r=1),r>500&&(r=500);let c=typeof n.charLimit=="number"?Math.floor(n.charLimit):s.charLimit;(!Number.isFinite(c)||c<100)&&(c=100),c>2e4&&(c=2e4);const a=typeof n.charLimitEnabled=="boolean"?n.charLimitEnabled:s.charLimitEnabled;return{maxEntries:r,charLimitEnabled:a,charLimit:c}}function ni(){try{const t=localStorage.getItem(ti);return t?si(JSON.parse(t)):{...is}}catch{return{...is}}}function Ut(t){const s=si(t);try{localStorage.setItem(ti,JSON.stringify(s))}catch{}try{let n=dt();s.charLimitEnabled&&(n=n.map(r=>r.length>s.charLimit?r.slice(0,s.charLimit):r)),n.length>s.maxEntries&&(n=n.slice(n.length-s.maxEntries)),ii(n)}catch{}}function cl(t){if(!Array.isArray(t))return[];const s=[];for(const n of t){if(typeof n!="string")continue;const r=n.trim();r&&s.push(r)}return s}function dl(t,s,n=ol){const r=s.trim();if(!r||t.length>0&&t[t.length-1]===r)return t;const c=[...t,r];return c.length>n?c.slice(c.length-n):c}function dt(){try{const t=localStorage.getItem(us);return t?cl(JSON.parse(t)):[]}catch{return[]}}function ii(t){let s=t;for(;s;)try{localStorage.setItem(us,JSON.stringify(s));return}catch(n){if(!(n instanceof DOMException&&(n.name==="QuotaExceededError"||n.code===22))||s.length<=1)return;s=s.slice(Math.ceil(s.length/2))}}function ul(t){let s=t.trim();if(!s)return;const n=ni();n.charLimitEnabled&&s.length>n.charLimit&&(s=s.slice(0,n.charLimit));const r=dt(),c=dl(r,s,n.maxEntries);c!==r&&ii(c)}function pl(){try{localStorage.removeItem(us)}catch{}}const ml=["off","minimal","low","medium","high","xhigh","max"],hl=l.memo(function({state:s,models:n,modelsLoading:r,send:c,onManageModels:a,providerKeys:i,compact:o=!1}){const u=be(),m=s==null?void 0:s.model,y=m?`${m.provider}/${m.id}`:null,[g,x]=l.useState(!1),[b,T]=l.useState(!1),[D,H]=l.useState(""),[C,j]=l.useState(null),[J,Q]=l.useState({}),X=l.useRef(null),U=l.useRef(null),[W,q]=l.useState(null);l.useEffect(()=>{if(!g){q(null);return}if(n.length===0)return;const N=requestAnimationFrame(()=>{const $=U.current;$&&q($.offsetWidth)});return()=>cancelAnimationFrame(N)},[g,n.length]),l.useEffect(()=>{g&&Q(ei())},[g]),l.useEffect(()=>{g||(H(""),j(null))},[g]);const Y=l.useMemo(()=>{const N=new Map;for(const z of n)N.set(z.provider,(N.get(z.provider)??0)+1);const $=[];for(const[z,ie]of[...N.entries()].sort((v,L)=>v[0].localeCompare(L[0]))){const v=i[z];if(v&&v.length>1)for(const L of v)$.push({provider:z,keyName:L.name,count:ie});else $.push({provider:z,keyName:null,count:ie})}return $},[n,i]),S=l.useMemo(()=>al(n,J),[n,J]),P=l.useMemo(()=>{let N=S;C&&(N=N.filter(z=>z.provider===C.provider));const $=D.trim().toLowerCase();return $?N.filter(z=>z.name.toLowerCase().includes($)||z.provider.toLowerCase().includes($)||z.id.toLowerCase().includes($)):N},[S,D,C]),k=l.useMemo(()=>{const N=[];for(const $ of P){const z=i[$.provider];if(!z||z.length<=1){N.push({model:$,key:null});continue}let ie=z.find(v=>v.active)??z[0];if((C==null?void 0:C.provider)===$.provider&&C.keyName){const v=z.find(L=>L.name===C.keyName);v&&(ie=v)}N.push({model:$,key:ie})}return N},[P,i,C]),[B,Z]=l.useState(!1),G=s!=null&&s.availableThinkingLevels&&s.availableThinkingLevels.length>0?new Set(s.availableThinkingLevels):null,M=ml.map(N=>({value:N,label:u(`thinking.${N}`),supported:G?G.has(N):!0})),I=N=>{var $;return(($=M.find(z=>z.value===N))==null?void 0:$.label)??N};return l.useEffect(()=>{g&&n.length===0&&!B&&!r&&(Z(!0),c({type:"list_models"}))},[g,n.length,B,r,c]),l.useEffect(()=>{n.length>0&&Z(!1)},[n.length]),l.useEffect(()=>{var $;if(!g)return;const N=($=X.current)==null?void 0:$.querySelector(".dd-item.active");N==null||N.scrollIntoView({block:"nearest"})},[g,y,n.length]),e.jsxs(e.Fragment,{children:[e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(lt,{}),e.jsx("span",{className:"chip-model",children:m?m.name:u("selectModel")}),!o&&(m==null?void 0:m.vision)&&e.jsx("span",{className:"chip-vision",title:u("vision"),children:"🖼"}),!o&&m&&e.jsx("span",{className:"chip-sub",children:m.provider})]}),open:g,onOpenChange:x,menuClassName:"dd-menu-model",menuRef:U,menuStyle:W!=null?{width:W}:void 0,direction:"up",children:[e.jsx("div",{className:"dd-header",children:u("availableModels")}),e.jsxs("div",{className:"dd-search-row",children:[e.jsx(Nt,{}),e.jsx("input",{className:"dd-search",type:"text",placeholder:u("searchModels"),value:D,onChange:N=>H(N.target.value)})]}),e.jsxs("div",{className:"dd-model-body",children:[Y.length>1&&e.jsxs("div",{className:"dd-provider-col",children:[e.jsx("div",{className:"dd-provider-head",children:u("providers")}),e.jsx("button",{type:"button",className:`dd-provider-item ${C===null?"active":""}`,onClick:()=>j(null),children:e.jsx("span",{children:u("allProviders")})}),Y.map(N=>{const $=(C==null?void 0:C.provider)===N.provider&&(C==null?void 0:C.keyName)===N.keyName;return e.jsxs("button",{type:"button",className:`dd-provider-item ${$?"active":""}`,onClick:()=>j($?null:{provider:N.provider,keyName:N.keyName}),title:N.keyName?`${N.provider} · ${N.keyName}`:`${N.provider} · ${N.count}`,children:[e.jsxs("span",{className:"dd-provider-txt",children:[e.jsx("span",{className:"dd-provider-name",children:N.provider}),N.keyName&&e.jsx("span",{className:"dd-provider-key",children:N.keyName})]}),e.jsx("span",{className:"dd-provider-count",children:N.count})]},N.keyName?`${N.provider}::${N.keyName}`:N.provider)})]}),e.jsxs("div",{className:"dd-model-scroll",ref:X,children:[(B||r)&&e.jsx("div",{className:"dd-loading",children:u("loading")}),n.length===0&&!B&&!r&&e.jsx("div",{className:"dd-loading",children:u("noModels")}),P.length===0&&n.length>0&&e.jsx("div",{className:"dd-loading",children:u("noModelMatches")}),k.map(N=>{const $=N.model,z=y===$.id&&(!N.key||N.key.active);return e.jsx(Ie,{active:z,onClick:()=>{N.key&&!N.key.active&&c({type:"activate_provider_key",provider:$.provider,keyName:N.key.name}),y!==$.id&&c({type:"set_model",modelId:$.id}),x(!1)},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:$.name}),e.jsxs("span",{className:"dd-model-meta",children:[e.jsx("span",{className:"dd-model-provider",children:$.provider}),N.key&&e.jsxs("span",{className:`dd-model-key ${N.key.active?"active":""}`,children:[N.key.active?"●":"○"," ",N.key.name]}),(J[$.id]??0)>0&&e.jsx("span",{className:"dd-model-usage",children:u("modelUsedCount",{n:J[$.id]})}),($.reasoning||$.vision)&&e.jsxs("span",{className:"dd-model-badges",children:[$.reasoning&&e.jsx("span",{className:"dd-model-badge",children:u("reasoning")}),$.vision&&e.jsx("span",{className:"dd-model-badge",children:u("vision")})]})]})]})},N.key?`${$.id}::${N.key.name}`:$.id)})]})]}),e.jsxs("div",{className:"dd-footer",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>c({type:"list_models"}),children:u("refreshModels")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>{x(!1),a()},children:u("manageModels")})]})]}),e.jsxs(ze,{trigger:e.jsxs(e.Fragment,{children:[e.jsx(xt,{}),e.jsx("span",{className:"chip-sub",children:u("thinkingChip",{level:s?I(s.thinkingLevel):"—"})})]}),open:b,onOpenChange:T,direction:"up",children:[e.jsx("div",{className:"dd-header",children:u("thinkingLevel")}),M.map(N=>e.jsx(Ie,{active:(s==null?void 0:s.thinkingLevel)===N.value,disabled:!N.supported,title:N.supported?void 0:u("thinkingUnsupported"),onClick:()=>{(s==null?void 0:s.thinkingLevel)!==N.value&&c({type:"set_thinking",level:N.value}),T(!1)},children:N.label},N.value))]})]})}),gl=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,fl=l.memo(function({ready:s,streaming:n,messages:r,slashCommands:c,modelState:a,models:i,modelsLoading:o,send:u,attachments:m,onRemoveAttachment:y,onAddImageFiles:g,onAddLocalFiles:x,onNotice:b,onSent:T,onManageModels:D,providerKeys:H}){const C=be(),{locale:j}=mt(),{openPicker:J}=Jn(),Q=f=>j==="en"&&f.descriptionEn?f.descriptionEn:f.description??"",X=f=>j==="en"&&f.argumentHintEn?f.argumentHintEn:f.argumentHint??"",[U,W]=l.useState(""),[q,Y]=l.useState(!1),[S,P]=l.useState(null),[k,B]=l.useState(0),[Z,G]=l.useState(!1),[M,I]=l.useState(void 0),N=l.useRef(null),$=l.useRef(null),z=l.useRef(null),ie=l.useRef(-1),v=l.useRef(""),L={builtin:C("slashBuiltin"),extension:C("slashExtension"),prompt:C("slashPrompt"),skill:C("slashSkill"),plugin:C("slashPlugin")},d=f=>{const K=f.match(/^\/([^\s]*)$/);if(K&&s){const me=K[1].toLowerCase(),he=c.filter(xe=>xe.name.toLowerCase().startsWith(me));P(he.length>0?he:null),B(0)}else P(null)};l.useEffect(()=>{var K;const f=(K=z.current)==null?void 0:K.querySelector(".slash-item.active");f==null||f.scrollIntoView({block:"nearest"})},[k,S]);const E=f=>{var fe;const K=S??[],me=f??K[k%Math.max(K.length,1)];if(!me){P(null);return}const he=U.match(/^\/([^\s]*)([\s\S]*)$/),xe=he?he[2]:"";W(`/${me.name} ${xe}`),P(null),(fe=N.current)==null||fe.focus()},h=async()=>{const K=[...r].reverse().find(he=>he.role==="assistant"&&he.content.some(xe=>xe.type==="text"&&xe.text)),me=K==null?void 0:K.content.filter(he=>he.type==="text").map(he=>he.text).join(`
321
+ `);if(!me){b("warning",C("slashCopyEmpty"));return}try{await navigator.clipboard.writeText(me),b("info",C("slashCopied"))}catch{b("error",C("slashCopyFailed"))}},_=f=>{if(!f||f.length===0){b("warning",C("foldersNotSupported"));return}const K=Array.from(f).filter(xe=>We(xe.type)),me=Array.from(f).filter(xe=>!We(xe.type)),he=O();K.length>0&&he?b("warning",he):K.length>0&&g(K),me.length>0&&x(me)},te=f=>{var xe;const K=(xe=f.clipboardData)==null?void 0:xe.items;if(!K)return;const me=[];for(const fe of K)if(fe.kind==="file"&&We(fe.type)){const ke=fe.getAsFile();ke&&me.push(ke)}if(me.length===0)return;f.preventDefault();const he=O();if(he){b("warning",he);return}g(me)},O=()=>{const f=a==null?void 0:a.model;if(!(f!=null&&f.id))return null;const K=i.find(me=>me.id===f.id);return K&&K.vision===!1?C("modelNoVision",{name:K.name}):null},re=s,ee=l.useRef(U);l.useEffect(()=>{ee.current=U},[U]),l.useEffect(()=>{d(ee.current)},[c]),l.useEffect(()=>{const f=K=>{var he;const me=K.detail;W(me),(he=N.current)==null||he.focus()};return window.addEventListener("pi-web:fill",f),()=>window.removeEventListener("pi-web:fill",f)},[]),l.useEffect(()=>{if(!Z)return;const f=K=>{K.key==="Escape"&&G(!1)};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[Z]),l.useEffect(()=>{const f=N.current;if(!f)return;f.style.height="auto";const K=f.scrollHeight>220;f.style.height=`${Math.min(f.scrollHeight,220)}px`,f.style.overflowY=K?"auto":"hidden"},[U]);const ge=f=>f.selectionStart!==f.selectionEnd?!1:!f.value.slice(0,f.selectionStart).includes(`
322
+ `),ue=f=>f.selectionStart!==f.selectionEnd?!1:!f.value.slice(f.selectionStart).includes(`
323
+ `),de=(f=!1)=>{var he,xe,fe,ke,Me;const K=U.trim(),me=m.some(ye=>ye.imageData||ye.fileData);if(!(!re||!K&&!me)){if(K==="/help"){const ye=(xe=(he=N.current)==null?void 0:he.closest(".inputbox"))==null?void 0:xe.getBoundingClientRect();I(ye==null?void 0:ye.width),G(!0),W(""),(fe=N.current)==null||fe.focus();return}if(K==="/copy"){W(""),(ke=N.current)==null||ke.focus(),h();return}if(u({type:"prompt",text:K,queue:f,attachments:m.map(ye=>ye.imageData?{path:"",imageData:ye.imageData,mimeType:ye.mimeType,name:ye.name}:ye.fileData?{path:"",fileData:ye.fileData,mimeType:ye.mimeType,name:ye.name,size:ye.size}:{path:ye.path,mode:ye.mode,...ye.lines?{lines:ye.lines}:{}})})){K&&ul(K),ie.current=-1,v.current="",W(""),T();const ye=a==null?void 0:a.model;ye&&ll(`${ye.provider}/${ye.id}`),(Me=N.current)==null||Me.focus()}}},Se=f=>{if(!f.nativeEvent.isComposing){if(S&&S.length>0)switch(f.key){case"ArrowDown":f.preventDefault(),B(K=>(K+1)%S.length);return;case"ArrowUp":f.preventDefault(),B(K=>(K-1+S.length)%S.length);return;case"Tab":case"Enter":f.preventDefault(),E();return;case"Escape":f.preventDefault(),P(null);return}if(f.key==="ArrowUp"||f.key==="ArrowDown"){if(f.ctrlKey||f.metaKey||f.altKey)return;const K=N.current;if(!K)return;const me=f.key==="ArrowUp";if(me&&!ge(K)||!me&&!ue(K)||!me&&ie.current===-1)return;const he=dt();if(he.length===0)return;if(f.preventDefault(),me){if(ie.current===-1){v.current=U;const xe=he.length-1;ie.current=xe;const fe=he[xe];W(fe),d(fe),requestAnimationFrame(()=>{const ke=N.current;ke&&(ke.selectionStart=ke.selectionEnd=fe.length)})}else if(ie.current>0){const xe=ie.current-1;ie.current=xe;const fe=he[xe];W(fe),d(fe),requestAnimationFrame(()=>{const ke=N.current;ke&&(ke.selectionStart=ke.selectionEnd=fe.length)})}}else{const xe=ie.current+1;if(xe<he.length){ie.current=xe;const fe=he[xe];W(fe),d(fe),requestAnimationFrame(()=>{const ke=N.current;ke&&(ke.selectionStart=ke.selectionEnd=fe.length)})}else{ie.current=-1;const fe=v.current;W(fe),d(fe),requestAnimationFrame(()=>{const ke=N.current;ke&&(ke.selectionStart=ke.selectionEnd=fe.length)})}}return}if(f.key==="Escape"&&ie.current!==-1){f.preventDefault();const K=v.current;ie.current=-1,W(K),d(K),requestAnimationFrame(()=>{const me=N.current;me&&(me.selectionStart=me.selectionEnd=K.length)});return}if(f.key==="Enter"){if(gl&&!f.shiftKey&&!(f.ctrlKey||f.metaKey))return;f.shiftKey||(f.preventDefault(),de())}}},le=()=>e.jsx("div",{className:"inputbox-actions",children:n?e.jsxs(e.Fragment,{children:[U.trim()!==""&&e.jsxs("button",{type:"button",className:"btn supplement",title:C("supplementTip"),onClick:()=>de(!0),children:[e.jsx(vn,{})," ",C("supplement")]}),e.jsx("button",{type:"button",className:"btn stop",title:C("stopAgent"),onClick:()=>u({type:"abort"}),children:e.jsx(jt,{})})]}):e.jsx("button",{type:"button",className:"btn send",title:C("sendTip"),disabled:!re||!U.trim()&&!m.some(f=>f.imageData||f.fileData),onClick:()=>de(),children:e.jsx(Cn,{})})});return e.jsxs("div",{className:`inputbar${q?" drop-active":""}`,onDragOver:f=>{f.preventDefault(),f.stopPropagation(),Y(!0)},onDragLeave:f=>{f.currentTarget.contains(f.relatedTarget)||Y(!1)},onDrop:f=>{var K;f.preventDefault(),f.stopPropagation(),Y(!1),_(((K=f.dataTransfer)==null?void 0:K.files)??null)},children:[q&&e.jsx("div",{className:"drop-overlay",children:e.jsxs("span",{children:["📎 ",C("dropHereToAttach")]})}),m.length>0&&e.jsxs("div",{className:"attach-row",children:[m.map(f=>e.jsxs("span",{className:`attach-chip ${f.imageData?"image":f.fileData?"file":f.mode}`,title:f.imageData?C("attachImage",{name:f.name}):f.fileData?C("attachFile",{name:f.name}):f.isDir?C("folderRef",{path:f.path}):f.mode==="reference"?C("refOnly",{path:f.path}):f.mode==="lines"&&f.lines?C("attachLines",{path:f.path,start:f.lines.start,end:f.lines.end}):C("attachContent",{path:f.path}),children:[f.imageData?"🖼":f.fileData?"📄":f.isDir?"📁":f.mode==="reference"?"🔗":"📎"," ",f.name,f.mode==="lines"&&f.lines&&e.jsxs("span",{className:"attach-range",children:["L",f.lines.start,"-",f.lines.end]}),e.jsx("button",{type:"button",className:"attach-remove",title:C("removeAttachment"),onClick:()=>y(f.key??f.path),children:"×"})]},f.key??`${f.path}|${f.mode}|${f.lines?`${f.lines.start}-${f.lines.end}`:""}`)),e.jsx("span",{className:"attach-hint",children:C("attachHint")})]}),S&&S.length>0&&e.jsxs("div",{className:"slash-menu",role:"listbox",ref:z,"aria-label":C("slashCommands"),children:[e.jsxs("div",{className:"slash-menu-hint",children:[e.jsx("span",{children:C("slashMenuHint")}),e.jsx("span",{className:"slash-menu-close",onClick:()=>P(null),children:"Esc"})]}),S.map((f,K)=>e.jsxs("button",{type:"button",className:`slash-item${K===k?" active":""}`,onMouseEnter:()=>B(K),onClick:()=>E(f),children:[e.jsxs("span",{className:"slash-name",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:L[f.source]}),e.jsxs("span",{className:"slash-desc",children:[Q(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:X(f)})]})]},f.name))]}),Z&&e.jsx("div",{className:"modal-backdrop",onClick:()=>G(!1),children:e.jsxs("div",{className:"slash-help",style:M?{width:M}:void 0,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"slash-help-head",children:[e.jsxs("span",{children:["⚡ ",C("slashHelpTitle")]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>G(!1),children:C("close")})]}),e.jsx("div",{className:"slash-help-body",children:c.length===0?e.jsx("div",{className:"slash-help-empty",children:C("slashLoading")}):c.map(f=>e.jsxs("div",{className:"slash-help-row",children:[e.jsxs("span",{className:"slash-help-cmd",children:["/",f.name]}),e.jsx("span",{className:`slash-source ${f.source}`,children:L[f.source]}),e.jsxs("span",{className:"slash-help-desc",children:[Q(f),f.argumentHint&&e.jsx("span",{className:"slash-hint",children:X(f)})]})]},f.name))})]})}),e.jsxs("div",{className:"inputbox",children:[e.jsx("input",{ref:$,type:"file",multiple:!0,hidden:!0,onChange:f=>{_(f.target.files),f.target.value=""}}),e.jsx("textarea",{ref:N,value:U,rows:1,placeholder:C(re?n?"placeholderStreaming":"placeholderIdle":"placeholderConnecting"),disabled:!re,onChange:f=>{ie.current=-1,W(f.target.value),d(f.target.value)},onKeyDown:Se,onPaste:te}),e.jsxs("div",{className:"composer-tools",children:[e.jsxs("div",{className:"composer-tools-left",children:[e.jsx("button",{type:"button",className:"btn attach-img",title:C("uploadFile"),disabled:!re,onClick:()=>{var f;return(f=$.current)==null?void 0:f.click()},children:e.jsx(_i,{})}),e.jsx("button",{type:"button",className:"btn tpl-open",title:C("tpl.openPicker"),onClick:J,children:e.jsx(qi,{})}),e.jsx(hl,{state:a,models:i,modelsLoading:o,send:u,onManageModels:D,providerKeys:H,compact:!0})]}),e.jsx("div",{className:"composer-tools-right",children:le()})]})]})]})}),xl=l.memo(function({goal:s,models:n,modelsLoading:r,activeConversationId:c,engine:a,send:i}){var M,I,N,$,z,ie,v;const o=be(),{locale:u}=mt(),m=u==="en"&&s.statusEn?s.statusEn:s.status||"",y=u==="en"&&((M=s.wizard)!=null&&M.statusEn)?s.wizard.statusEn:((I=s.wizard)==null?void 0:I.status)||"",g=a==="dsh",x=!s.conversationId||s.conversationId===c,b=s.goal!==null&&x,[T,D]=l.useState(""),[H,C]=l.useState(s.reviewModel??""),[j,J]=l.useState(s.maxRounds),[Q,X]=l.useState(s.locked),[U,W]=l.useState(!1),[q,Y]=l.useState(!1),[S,P]=l.useState(!0);l.useEffect(()=>{C(s.reviewModel??""),J(s.maxRounds||0),X(s.locked)},[s.goal,s.reviewModel,s.maxRounds,s.locked]),l.useEffect(()=>{U&&n.length===0&&!q&&!r&&(Y(!0),i({type:"list_models"}))},[U,n.length,q,r,i]),l.useEffect(()=>{n.length>0&&Y(!1)},[n.length]);const k=()=>{var L;return H?((L=n.find(d=>d.id===H))==null?void 0:L.name)??H:o("goalBarUseMainModel")},B=()=>{const L=T.trim();L&&(i({type:"set_goal",goal:L,...H?{reviewModel:H}:{},maxRounds:j,locked:Q}),D(""),P(!1))},Z=()=>{const L=T.trim();L&&(i({type:"start_goal_wizard",text:L,...H?{wizardModel:H}:{},maxRounds:j,locked:Q}),D(""),P(!1))},G=(((N=s.wizard)==null?void 0:N.active)??!1)&&x;return G?e.jsx("div",{className:`goalbar goalbar-active ${G?"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:(($=s.wizard)==null?void 0:$.draft)??"",children:[o("goalWizardRunning"),": ",(z=s.wizard)==null?void 0:z.draft]}),e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarRound",{n:(((ie=s.wizard)==null?void 0:ie.step)??0)+1})," / ",((v=s.wizard)==null?void 0:v.maxSteps)??6]}),e.jsx("span",{className:"goalbar-detail",children:y||o("goalBarReviewing")}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),onClick:()=>{i({type:"clear_goal"}),P(!0)},children:e.jsx(Pe,{})})]})}):b?e.jsx("div",{className:`goalbar goalbar-active ${s.reviewing?"reviewing":""}`,children:e.jsxs("div",{className:"goalbar-active-row",children:[e.jsx("span",{className:"goalbar-icon",children:s.reviewing?e.jsx("span",{className:"goalbar-spin",children:"◌"}):"🎯"}),e.jsx("span",{className:"goalbar-text",title:s.goal??"",children:s.goal}),s.reviewing?e.jsxs("span",{className:"goalbar-chip reviewing",children:[o("goalBarReviewing")," ",o("goalBarRound",{n:s.round})]}):e.jsx("span",{className:`goalbar-chip ${s.verdict==="pass"?"pass":s.verdict==="fail"?"fail":""}`,children:s.verdict==="pass"?o("goalBarPassed"):s.verdict==="fail"?o("goalBarFailed"):`${o("goalBarRound",{n:s.round||1})} · ${s.locked?o("goalBarLocked"):o("goalBarUnlocked")}`}),e.jsx("span",{className:"goalbar-detail",children:m}),e.jsx("button",{type:"button",className:"goalbar-x",title:o("goalBarClear"),disabled:s.reviewing,onClick:()=>{i({type:"clear_goal"}),P(!0)},children:e.jsx(Pe,{})})]})}):S?e.jsx("div",{className:"goalbar goalbar-collapsed",children:e.jsxs("button",{type:"button",className:"goalbar-hint",title:o("goalBarPlaceholder"),onClick:()=>P(!1),children:[e.jsx(Is,{})," ",e.jsx("span",{children:o("goalBarTitle")})]})}):e.jsxs("div",{className:"goalbar",children:[e.jsxs("div",{className:"goalbar-row",children:[e.jsx("span",{className:"goalbar-icon",children:e.jsx(Is,{})}),e.jsx("input",{className:"goalbar-input",value:T,placeholder:o("goalBarPlaceholder"),onChange:L=>D(L.target.value),onKeyDown:L=>{L.key==="Enter"&&B()}}),e.jsx("button",{type:"button",className:"goalbar-btn",disabled:!T.trim(),onClick:B,children:o("goalBarSet")}),e.jsxs("button",{type:"button",className:"goalbar-btn wizard",disabled:!T.trim(),title:o("goalWizardTip"),onClick:Z,children:["🔍 ",o("goalWizardBtn")]}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o(Q?"goalBarLocked":"goalBarUnlocked"),onClick:()=>X(L=>(i({type:"set_goal_prefs",locked:!L}),!L)),children:Q?e.jsx(Ki,{}):e.jsx(Ii,{})}),e.jsx("button",{type:"button",className:"goalbar-icon-btn",title:o("goalBarClear"),onClick:()=>P(!0),children:e.jsx(ut,{})})]}),e.jsxs("div",{className:"goalbar-opts",children:[g?e.jsx("p",{className:"goalbar-dsh-note",children:o("dshNoReviewModel")}):e.jsxs(ze,{trigger:e.jsxs("span",{className:"goalbar-opt",children:[o("goalBarReviewModel"),": ",e.jsx("b",{children:k()})]}),open:U,onOpenChange:W,direction:"up",children:[e.jsx("div",{className:"dd-header",children:o("goalBarReviewModel")}),(q||r)&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.length===0&&!q&&!r&&e.jsx("div",{className:"dd-loading",children:o("noModels")}),e.jsx(Ie,{active:H==="",onClick:()=>{C(""),W(!1),i({type:"set_goal_prefs",reviewModel:""})},children:o("goalBarUseMainModel")}),n.map(L=>e.jsx(Ie,{active:H===L.id,onClick:()=>{C(L.id),W(!1),i({type:"set_goal_prefs",reviewModel:L.id})},children:e.jsxs("span",{className:"dd-model-cell",children:[e.jsx("span",{className:"dd-model-name",children:L.name}),e.jsx("span",{className:"dd-model-meta",children:e.jsx("span",{className:"dd-model-provider",children:L.provider})})]})},L.id)),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>i({type:"list_models"}),children:o("refreshModels")})]}),e.jsxs("label",{className:"goalbar-round",title:o("goalBarMaxRoundsTip"),children:[e.jsx("span",{children:o("goalBarMaxRounds")}),e.jsx("input",{type:"number",min:0,step:1,value:j,placeholder:o("goalBarUnlimitedShort"),onChange:L=>{const d=parseInt(L.target.value,10);if(Number.isNaN(d)||d<0){J(0);return}J(d)},onBlur:()=>i({type:"set_goal_prefs",maxRounds:j}),onKeyDown:L=>{L.key==="Enter"&&(i({type:"set_goal_prefs",maxRounds:j}),L.target.blur())}})]}),e.jsx("span",{className:"goalbar-lock-hint",children:o(Q?"goalBarLocked":"goalBarUnlocked")})]})]})});function yl(t){const s=Math.max(0,t.input??0),n=Math.max(0,t.cacheRead??0),r=Math.max(0,t.cacheWrite??0),c=s+n+r;return{totalInput:c,miss:s,read:n,write:r,hitRate:c>0?Math.min(n/c,1):0,writeRate:c>0?Math.min(r/c,1):0}}const ai=2e3;function vl(t,s,n=ai){return t.filter(r=>s-r.t<=n)}function bl(t,s=ai){if(t.length<2)return 0;const n=t[t.length-1],r=t.find(a=>a.t>=n.t-s)??t[0],c=(n.t-r.t)/1e3;return c<=0?0:Math.max(0,(n.out-r.out)/c)}function rn(t){if(!t)return 0;let s=0;for(let r=0;r<t.length;r++){const c=t.charCodeAt(r);(c>=12352&&c<=12543||c>=13312&&c<=19903||c>=19968&&c<=40959||c>=63744&&c<=64255||c>=65280&&c<=65519||c===12288)&&s++}const n=t.length-s;return Math.round(s+n/4)}function kl(t){let s=0;for(const n of t)n.type==="text"&&typeof n.text=="string"&&n.text?s+=rn(n.text):n.type==="thinking"&&typeof n.thinking=="string"&&n.thinking&&(s+=rn(n.thinking));return s}const Qe="@root";function jl({chat:t,send:s}){const n=be(),r=t.state,[c,a]=l.useState(!1),[i,o]=l.useState(""),[u,m]=l.useState(""),[y,g]=l.useState(!1),[x,b]=l.useState(""),[T,D]=l.useState(-1),H=l.useRef(null),C=l.useRef(null),j=t.pathCompletions.filter(h=>h.type==="dir"),J=h=>h.endsWith("/")?h:h+"/",Q=h=>{let _=h.endsWith("/")&&h!=="/"?h.slice(0,-1):h;if(_===Qe||_==="/")return null;const te=_.lastIndexOf("/");if(te<0)return/^[A-Za-z]:$/.test(_)?Qe:null;if(te===0)return"/";const O=_.slice(0,te);return/^[A-Za-z]:$/.test(O)?O+"/":O};l.useEffect(()=>{if(!c)return;const h=setTimeout(()=>{s({type:"complete_path",path:J(i)})},60);return()=>clearTimeout(h)},[i,c,s]),l.useEffect(()=>{if(!c||u===i)return;const h=setTimeout(()=>{s({type:"complete_path",path:u})},150);return()=>clearTimeout(h)},[u,i,c,s]);const X=l.useRef([]),U=(r==null?void 0:r.isStreaming)??!1,W=r!=null&&r.streamingMessage?kl(r.streamingMessage.content):0;if(l.useEffect(()=>{if(!U){X.current=[];return}const h=Date.now(),_=X.current,te=_[_.length-1];te&&h-te.t<250||(X.current=vl([..._,{t:h,out:W}],h))},[U,W]),!r)return null;const q=r.stats,Y=yl(q.tokens),S=Y.hitRate*100,P=Y.totalInput===0?"":Y.hitRate>=.7?"ok":Y.hitRate>=.4?"mid":"warn",k=Y.totalInput>0?`${S.toFixed(1)}%`:"—",B=U?bl(X.current):0,Z=t.ready?"ok":"busy",G=t.ready?n("connected"):n("connecting"),M=q.contextUsage,I=M.tokens!==null&&M.percent!==null?`${Ze(M.tokens)} / ${Ze(M.contextWindow)}`:"—",N=M.percent??null,$=N===null?"":N>=80?"warn":N>=50?"mid":"ok",z=r.queue.steering.length+r.queue.followUp.length,ie=()=>{m(r.cwd),o(r.cwd),g(!1),b(""),a(!0)},v=h=>{const _=h.trim();_!==Qe&&(_&&_!==r.cwd&&s({type:"set_cwd",path:_}),a(!1))},L=()=>{const h=x.trim();h&&(s({type:"make_dir",path:`${J(i)}${h}`}),setTimeout(()=>{s({type:"complete_path",path:J(i)})},80),b(""),g(!1))},d=h=>{if(h.key==="Escape")h.stopPropagation(),a(!1);else if(h.key==="Enter"&&!h.nativeEvent.isComposing)v(u);else if(h.key==="Tab"){if(j.length===0)return;h.preventDefault();const _=T>=0?(T+1)%j.length:0;D(_),m(j[_].path),o(j[_].path)}},E=Q(i);return e.jsxs("footer",{className:"statusbar",children:[e.jsx("span",{className:`status-dot ${Z}`,title:G}),e.jsx("span",{className:"status-item",children:G}),e.jsx("span",{className:"status-sep",children:"·"}),t.engine&&t.engine!=="pi"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`status-item engine-badge engine-${t.engine}`,title:`${n("engineBadge")}: ${t.engine}`,children:t.engine==="dsh"?"DSH":t.engine}),e.jsx("span",{className:"status-sep",children:"·"})]}),e.jsxs("span",{className:"status-item status-ctx",title:n("contextUsage"),children:[n("context"),e.jsx("span",{className:`ctx-bar ${$}`,children:N!==null&&e.jsx("span",{className:"ctx-bar-fill",style:{width:`${Math.min(N,100)}%`}})}),I]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("cumulativeCost"),children:["$",wl(q.cost)]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item status-cache",title:n("cacheHitTip",{read:Ze(Y.read),write:Ze(Y.write),miss:Ze(Y.miss),input:Ze(Y.totalInput)}),children:[n("cacheHit"),e.jsx("b",{className:`cache-pct ${P}`,children:k})]}),e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item",title:n("sessionMessages"),children:[n("messages")," ",q.totalMessages]}),t.statuses.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsx("span",{className:"status-item ext-status",title:n("pluginStatus"),children:t.statuses.map(h=>h.text).join(" · ")})]}),r.isStreaming&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-sep",children:"·"}),e.jsxs("span",{className:"status-item working",children:[e.jsx("span",{className:"working-spin"}),n("working"),z>0&&e.jsxs("span",{className:"status-queue",children:["⏳ ",z," ",n("queued")]})]}),e.jsx("span",{className:"status-item status-rate",title:n("rateTip"),children:B>0?`${Math.round(B)}${n("tps")}`:"…"})]}),c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"status-cwd-backdrop",onClick:()=>a(!1)}),e.jsxs("div",{className:"cwd-picker",children:[e.jsxs("div",{className:"cwd-picker-head",children:[e.jsxs("span",{className:"cwd-picker-title",title:i===Qe?n("computer"):i,children:[i===Qe?"💻":e.jsx(Je,{}),e.jsx("span",{children:i===Qe?n("computer"):i})]}),e.jsxs("button",{type:"button",className:"cwd-up",disabled:!E,title:n("cwdGoUp"),onClick:()=>{E&&(o(E),m(E),D(-1))},children:["↑ ",n("cwdGoUp")]})]}),e.jsxs("div",{className:"cwd-picker-row",children:[e.jsx("input",{ref:H,className:"status-cwd-input cwd-picker-input",value:u,placeholder:n("enterPath"),spellCheck:!1,onChange:h=>{m(h.target.value),D(-1)},onKeyDown:d}),e.jsx("button",{type:"button",className:"cwd-choose-btn primary",title:n("cwdPickCurrent"),disabled:i===Qe,onClick:()=>v(i),children:n("cwdPickCurrent")})]}),e.jsxs("div",{className:"cwd-list",children:[j.length===0&&e.jsx("div",{className:"cwd-empty",children:n("cwdEmpty")}),j.map(h=>e.jsxs("div",{className:"cwd-item",children:[e.jsxs("button",{type:"button",className:"cwd-enter",title:`${n("cwdEnter")} ${h.path}`,onClick:()=>{o(h.path),m(h.path),D(-1)},children:[e.jsx(Je,{}),e.jsx("span",{className:"cwd-name",children:h.name})]}),e.jsx("button",{type:"button",className:"cwd-choose-btn",title:n("cwdChoose"),onClick:()=>v(h.path),children:n("cwdChoose")})]},h.path))]}),e.jsx("div",{className:"cwd-picker-foot",children:y?e.jsxs("div",{className:"cwd-newrow",children:[e.jsx("input",{ref:C,value:x,autoFocus:!0,spellCheck:!1,placeholder:n("cwdNewName"),onChange:h=>b(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.nativeEvent.isComposing?(h.preventDefault(),L()):h.key==="Escape"&&(h.stopPropagation(),g(!1),b(""))}}),e.jsx("button",{type:"button",className:"cwd-choose-btn primary",onClick:L,children:n("cwdCreate")}),e.jsx("button",{type:"button",className:"cwd-choose-btn",onClick:()=>{g(!1),b("")},children:n("cwdCancel")})]}):e.jsxs("button",{type:"button",className:"cwd-newbtn",onClick:()=>g(!0),children:["+ ",n("cwdNewFolder")]})})]})]}):e.jsxs("button",{type:"button",className:"status-item status-cwd",title:n("cwdTip",{path:r.cwd}),onClick:ie,children:["📁 ",r.cwd]})]})}function Ze(t){return t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:String(t)}function wl(t){return t<=0?"0":t<1e-4?"<0.0001":t.toFixed(4).replace(/\.?0+$/,"")}function Nl({dialog:t,send:s}){const n=be(),[r,c]=l.useState(""),[a,i]=l.useState(0),o=y=>{s({type:"dialog_response",id:t.id,value:y})};l.useEffect(()=>{c(""),i(0);const y=g=>{g.key==="Escape"&&o(null)};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[t.id]);const u=Array.isArray(t.args[0])?t.args[0]:[],m=typeof t.args[0]=="string"?t.args[0]:"";return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":t.kind,children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:n("pluginRequest")}),t.title&&t.title!==n("pluginRequest")&&e.jsx("span",{className:"dialog-title",children:t.title}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>o(null),children:"✕"})]}),t.kind==="select"&&e.jsxs("div",{className:"dialog-options",children:[u.map((y,g)=>e.jsx("button",{type:"button",className:`dialog-option ${g===a?"sel":""}`,onMouseEnter:()=>i(g),onClick:()=>o(y),children:y},g)),u.length===0&&e.jsx("div",{className:"dialog-hint",children:n("noOptions")})]}),t.kind==="confirm"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("p",{children:m}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(!1),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(!0),children:n("ok")})]})]}),t.kind==="input"&&e.jsxs("div",{className:"dialog-body",children:[e.jsx("input",{className:"dialog-input",value:r,placeholder:m||n("inputPlaceholder"),autoFocus:!0,onChange:y=>c(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&o(r)}}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>o(null),children:n("cancel")}),e.jsx("button",{type:"button",className:"btn primary",onClick:()=>o(r),children:n("ok")})]})]})]})}function Cl({question:t,send:s}){const n=be(),[r,c]=l.useState({}),[a,i]=l.useState({}),[o,u]=l.useState(()=>t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1);l.useEffect(()=>{c({}),i({}),u(t.deadline?Math.max(0,Math.ceil((t.deadline-Date.now())/1e3)):-1)},[t.id,t.deadline]),l.useEffect(()=>{if(!t.deadline)return;const x=setInterval(()=>{u(b=>{const T=Math.max(0,Math.ceil((t.deadline-Date.now())/1e3));return T<=0&&b>0&&s({type:"question_answer",id:t.id,answers:[],cancelled:!0}),T})},1e3);return()=>clearInterval(x)},[t.id,t.deadline]);const m=x=>{if(x){s({type:"question_answer",id:t.id,answers:[],cancelled:!0});return}const b=t.questions.map(T=>{const D=r[T.id]??[],H=(a[T.id]??"").trim();return{id:T.id,selected:D,...H?{custom:H}:{}}});s({type:"question_answer",id:t.id,answers:b})};l.useEffect(()=>{const x=b=>{b.key==="Escape"&&m(!0)};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[t.id]);const y=(x,b,T)=>{c(D=>{const H=D[x]??[];return T?{...D,[x]:H.includes(b)?H.filter(C=>C!==b):[...H,b]}:{...D,[x]:[b]}})},g=t.questions.every(x=>{var b;return(((b=r[x.id])==null?void 0:b.length)??0)>0||(a[x.id]??"").trim()!==""});return e.jsxs("div",{className:"dialog-inline","data-dialog-kind":"select",children:[e.jsxs("div",{className:"dialog-head",children:[e.jsx("span",{className:"dialog-badge",children:n("modelQuestion")}),o>=0&&e.jsx("span",{className:"question-timer",children:o>0?n("questionTimeout",{s:o}):n("questionTimeoutExpired")}),e.jsx("button",{type:"button",className:"dialog-dismiss",title:n("cancel"),onClick:()=>m(!0),children:"✕"})]}),t.questions.map((x,b)=>{var T;return e.jsxs("div",{className:"set-section",children:[e.jsx("div",{className:"set-section-title",children:x.header??`${n("modelQuestion")} ${b+1}`}),e.jsx("p",{className:"set-row-desc",children:x.question}),x.detail&&e.jsx("p",{className:"set-hint",children:x.detail}),(((T=x.options)==null?void 0:T.length)??0)>0&&e.jsx("div",{className:"set-list",children:x.options.map(D=>{const H=(r[x.id]??[]).includes(D.label);return e.jsxs("button",{type:"button",className:`set-row question-option${H?" active":""}`,onClick:()=>y(x.id,D.label,!!x.multiSelect),children:[e.jsxs("span",{className:"set-row-name",children:[x.multiSelect?H?"☑ ":"☐ ":H?"● ":"○ ",D.label]}),D.description&&e.jsx("span",{className:"set-row-desc",children:D.description})]},D.label)})}),e.jsx("input",{className:"set-prompt-input question-custom",placeholder:n("modelQuestionCustom"),value:a[x.id]??"",onChange:D=>i(H=>({...H,[x.id]:D.target.value}))})]},x.id)}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx("button",{type:"button",className:"dialog-submit",disabled:!g,onClick:()=>m(!1),children:n("modelQuestionSubmit")}),e.jsx("button",{type:"button",className:"dialog-dismiss-inline",onClick:()=>m(!0),children:n("cancel")})]})]})}const ln=t=>`'${t.replace(/'/g,"'\\''")}'`;function Sl(t){if(t.x==="?"&&t.y==="?")return"untracked";const s=t.x!==" "&&t.x!=="?",n=t.y!==" "&&t.y!=="?";return s&&n?"both":s?"staged":"unstaged"}function Tl({chat:t,send:s,terminal:n,active:r,onSwitchToTerminal:c}){var Be,De;const a=be(),[i,o]=l.useState(null),[u,m]=l.useState([]),[y,g]=l.useState(""),[x,b]=l.useState(new Map),[T,D]=l.useState("changes"),[H,C]=l.useState([]),[j,J]=l.useState(null),[Q,X]=l.useState(""),[U,W]=l.useState(!1),[q,Y]=l.useState(null),[S,P]=l.useState(null),[k,B]=l.useState(!1),[Z,G]=l.useState(!1),[M,I]=l.useState(!1),[N,$]=l.useState(null),[z,ie]=l.useState(!1),[v,L]=l.useState(""),d=l.useRef(0),E=l.useRef(-1),h=l.useRef(-1),_=l.useRef(-1),te=l.useRef(-1),O=l.useRef(void 0),re=l.useRef(null),ee=l.useRef([]),ge=l.useCallback(R=>{if(R.reqId===E.current){if(E.current=-1,G(!1),$(null),!R.ok){$(R.error??a("scmQueryFailedShort"));return}if(R.notRepo){ie(!0),o(null),m([]),b(new Map),C([]),J(null),X(""),P(null);return}ie(!1);const ve={branch:R.branch??"",detached:!!R.detached,upstream:R.upstream??null,ahead:R.ahead??0,behind:R.behind??0,upstreamGone:!!R.upstreamGone,files:(R.files??[]).map(V=>({...V}))},ce=(R.branches??[]).map(V=>({...V})),p=new Map;for(const[V,w]of Object.entries(R.stats??{}))p.set(V,{add:w[0],del:w[1]});o(ve),m(ce),b(p),g(V=>{var w;return ve.detached?V||"":ve.branch&&ce.some(A=>A.name===ve.branch)?ve.branch:V&&ce.some(A=>A.name===V)?V:((w=ce[0])==null?void 0:w.name)??""}),P(V=>V&&!ve.files.some(w=>w.path===V.file.path)?null:V)}else if(R.reqId===h.current){if(h.current=-1,B(!1),!R.ok){$(R.error??a("scmQueryFailedShort"));return}const ve=re.current;if(!ve)return;P({file:ve,staged:R.stagedText??"",worktree:R.worktreeText??"",untracked:!1})}else if(R.reqId===te.current){if(te.current=-1,I(!1),!R.ok){$(R.error??a("scmQueryFailedShort"));return}C((R.history??[]).map(ve=>({...ve})))}else if(R.reqId===_.current){if(_.current=-1,W(!1),!R.ok){$(R.error??a("scmQueryFailedShort"));return}X(R.text??"")}},[]);l.useEffect(()=>{const R=t.scmData;R&&R.type==="scm_data"&&ge(R)},[t.scmData,ge]);const ue=l.useCallback((R,ve)=>{if(!t.ready||t.status!=="open")return!1;const ce=++d.current;return s({...R,reqId:ce})?(ve.current=ce,!0):(d.current-=1,!1)},[t.ready,t.status,s]),de=l.useCallback((R=!1,ve=!1)=>{var ce;!t.ready||t.status!=="open"||(ce=t.state)!=null&&ce.cwd&&(O.current!==void 0&&O.current!==t.state.cwd&&(o(null),m([]),b(new Map),C([]),I(!1),te.current=-1,J(null),X(""),P(null),Y(null)),O.current=t.state.cwd,$(null),ue({type:"scm_status"},E)&&(ve||G(!0)))},[t.ready,(Be=t.state)==null?void 0:Be.cwd,t.status,ue]),Se=l.useCallback(R=>{if(Y(R),J(null),re.current=R,R.x==="?"&&R.y==="?"){P({file:R,staged:"",worktree:"",untracked:!0});return}B(!0),$(null),ue({type:"scm_filediff",path:R.path},h)||B(!1)},[ue]),le=l.useCallback(R=>{J(R),Y(null),P(null),X(""),W(!0),$(null),ue({type:"scm_commit",hash:R.hash},_)||W(!1)},[ue]),f=l.useCallback((R,ve)=>{var w,A;if(!t.ready)return;const ce={name:R,command:ve,cwd:"${pwd}"};let p;const V=t.terminals.find(ae=>ae.title===R);V?(n.restart(V.id),s({type:"run_command",terminalId:V.id,conversationId:V.conversationId,command:ce,cols:80,rows:24}),p=V.id):(p=Ue(),n.create({id:p,conversationId:t.activeConversationId||((w=t.state)==null?void 0:w.conversationId)||"",title:R,cwd:((A=t.state)==null?void 0:A.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:ce})),n.select(p),c()},[t.ready,(De=t.state)==null?void 0:De.cwd,t.terminals,c,s,n]),K=l.useCallback(()=>{const R=v.trim();if(!R||z)return;const ve=R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");f("git commit",`git commit -m "${ve}"`),L("")},[v,z,f]),me=l.useCallback(()=>{const R=v.trim();if(!R||z)return;const ve=R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/`/g,"\\`").replace(/\$/g,"\\$");f("git commit",`git add -A && git commit -m "${ve}"`),L("")},[v,z,f]),he=l.useCallback(R=>{z||f("git add",`git add -- ${ln(R.path)}`)},[z,f]),xe=l.useCallback(R=>{z||f("git reset",`git reset HEAD -- ${ln(R.path)}`)},[z,f]),fe=l.useCallback(()=>{if(!y||z)return;const R=u.find(ve=>ve.name===y);if(R!=null&&R.remote&&typeof R.remote=="string"){const ve=y.slice(R.remote.length+1);f("git checkout",`git checkout -b ${ve} ${y} || git checkout ${y}`)}else f("git checkout",`git checkout ${y}`)},[y,u,z,f]),ke=l.useCallback(()=>f("git push","git push"),[f]),Me=l.useCallback(()=>f("git pull","git pull"),[f]),ye=l.useCallback(()=>{ue({type:"scm_history"},te)||(te.current=-1)},[ue]);l.useEffect(()=>{r&&de()},[r,de]),l.useEffect(()=>{T==="history"&&i&&ye()},[T,i,ye]),l.useEffect(()=>{t.scmDirty>0&&r&&de(!1,!0)},[t.scmDirty]),l.useEffect(()=>{if(!r||!t.ready||t.status!=="open")return;const R=setInterval(()=>{document.visibilityState!=="hidden"&&de(!1,!0)},3e4);return()=>clearInterval(R)},[r,t.ready,t.status,de]),l.useEffect(()=>{const R=ee.current;if(ee.current=t.terminals,!r)return;t.terminals.some(ce=>{var V;return ce.running!==!1?!1:((V=R.find(w=>w.id===ce.id))==null?void 0:V.running)===!0&&ce.title.startsWith("git ")})&&t.ready&&t.status==="open"&&(de(!1,!0),T==="history"&&i&&ye())},[t.terminals,r,t.ready,t.status,de,T,i,ye]);const _e={staged:a("scmStaged"),unstaged:a("scmUnstaged"),untracked:a("scmUntracked"),both:a("scmStagedUnstaged")},Le=R=>{const ve=R.split(`
324
+ `);return e.jsx("pre",{className:"scm-diff-pre",children:ve.map((ce,p)=>{let V="";return ce.startsWith("diff --git")||ce.startsWith("index ")||ce.startsWith("new file")||ce.startsWith("deleted file")||ce.startsWith("old mode")||ce.startsWith("new mode")||ce.startsWith("similarity index")||ce.startsWith("rename ")||ce.startsWith("copy ")||ce.startsWith("Binary files")||ce.startsWith("---")||ce.startsWith("+++")?V="hdr":ce.startsWith("@@")?V="hunk":ce.startsWith("+")?V="add":ce.startsWith("-")&&(V="del"),e.jsx("div",{className:`scm-diff-line ${V}`,children:ce||" "},p)})})};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(yt,{}),a("scmTitle")]}),e.jsxs("div",{className:"scm-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":T==="changes",className:T==="changes"?"active":"",onClick:()=>{D("changes"),$(null)},children:a("scmChanges")}),e.jsx("button",{type:"button",role:"tab","aria-selected":T==="history",className:T==="history"?"active":"",onClick:()=>{D("history"),$(null)},children:a("scmHistory")})]}),e.jsx("button",{type:"button",className:"panel-refresh",title:a("scmRefreshTip"),disabled:Z,onClick:()=>de(!0),children:e.jsx(rt,{className:Z?"scm-spin":""})})]}),e.jsxs("div",{className:"scm-row",children:[e.jsxs("span",{className:"scm-branch-current",title:a("scmCurrentBranch"),children:[e.jsx(yt,{}),i?i.detached?a("scmDetached"):i.branch:"…",(i==null?void 0:i.upstream)&&e.jsx("span",{className:"scm-upstream",children:i.upstreamGone?a("scmUpstreamGone"):i.ahead>0||i.behind>0?a("scmAheadBehind",{ahead:i.ahead,behind:i.behind}):i.upstream})]}),e.jsxs("select",{className:"scm-select",value:y,disabled:z||u.length===0,title:a("scmSwitchBranch"),onChange:R=>g(R.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:a("scmSelectBranch")}),u.filter(R=>!R.remote).map(R=>e.jsx("option",{value:R.name,children:R.current?`* ${R.name}`:R.name},R.name)),u.some(R=>R.remote)&&e.jsx("optgroup",{label:a("scmRemoteBranches"),children:u.filter(R=>R.remote).map(R=>e.jsx("option",{value:R.name,children:R.name},R.name))})]}),e.jsxs("button",{type:"button",className:"btn",disabled:!y||y===(i==null?void 0:i.branch)||z,title:a("scmSwitchBranchTip",{branch:y}),onClick:fe,children:[e.jsx(yt,{}),a("scmSwitch")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!i||i.detached||z,title:a("scmPushTip"),onClick:ke,children:[e.jsx(Cn,{}),a("scmPush")]}),e.jsxs("button",{type:"button",className:"btn",disabled:!i||i.detached||z,title:a("scmPullTip"),onClick:Me,children:[e.jsx(Sn,{}),a("scmPull")]}),e.jsx("input",{className:"scm-commit-input",value:v,placeholder:a("scmCommitPlaceholder"),disabled:z,onChange:R=>L(R.target.value),onKeyDown:R=>{R.key==="Enter"&&!R.nativeEvent.isComposing&&K()}}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!v.trim()||z,title:a("scmCommitTip"),onClick:K,children:[e.jsx(pt,{}),a("scmCommit")]}),e.jsx("button",{type:"button",className:"btn",disabled:!v.trim()||z,title:a("scmCommitAllTip"),onClick:me,children:a("scmCommitAll")})]})]}),e.jsxs("div",{className:"scm-body",children:[T==="history"?e.jsxs("div",{className:"scm-history",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:a("scmHistory")}),H.length>0&&e.jsx("span",{className:"scm-files-count",children:H.length})]}),e.jsx("div",{className:"scm-history-list",children:z?e.jsx("div",{className:"scm-empty",children:a("scmNotGitRepo")}):!i||M?e.jsx("div",{className:"scm-empty",children:t.status==="open"?a("scmLoading"):a("scmConnecting")}):H.length===0?e.jsx("div",{className:"scm-empty",children:a("scmNoHistory")}):H.map(R=>e.jsxs("button",{type:"button",className:`scm-commit ${(j==null?void 0:j.hash)===R.hash?"active":""}`,onClick:()=>le(R),title:R.hash,children:[e.jsx("span",{className:"scm-commit-graph","aria-hidden":"true",children:R.graph||"* "}),e.jsxs("span",{className:"scm-commit-info",children:[e.jsx("span",{className:"scm-commit-subject",children:R.subject}),e.jsxs("span",{className:"scm-commit-meta",children:[R.shortHash," · ",R.author," · ",R.date]}),R.decorations&&e.jsx("span",{className:"scm-commit-refs",children:R.decorations})]})]},R.hash))})]}):e.jsxs("div",{className:"scm-files",children:[e.jsxs("div",{className:"scm-files-header",children:[e.jsx("span",{children:a("scmChanges")}),i&&i.files.length>0&&e.jsx("span",{className:"scm-files-count",children:i.files.length})]}),e.jsx("div",{className:"scm-files-list",children:z?e.jsx("div",{className:"scm-empty",children:a("scmNotGitRepo")}):i?i.files.length===0?e.jsx("div",{className:"scm-empty",children:a("scmNoChanges")}):i.files.map(R=>{const ve=Sl(R),ce=x.get(R.path);return e.jsxs("div",{className:`scm-file ${(q==null?void 0:q.path)===R.path?"active":""}`,title:_e[ve],onClick:()=>Se(R),children:[e.jsx("span",{className:`scm-file-xy ${ve==="untracked"?"q":"x"}`,children:R.x!==" "?R.x:" "}),e.jsx("span",{className:`scm-file-xy ${ve==="untracked"?"q":"y"}`,children:R.y!==" "?R.y:" "}),e.jsx("span",{className:"scm-file-path",children:R.path}),ce&&(ce.add>0||ce.del>0)&&e.jsxs("span",{className:"scm-file-stat",children:[ce.add>0&&e.jsxs("span",{className:"add",children:["+",ce.add]}),ce.del>0&&e.jsxs("span",{className:"del",children:["-",ce.del]})]}),e.jsxs("span",{className:"scm-file-actions",children:[(R.y!==" "||ve==="untracked")&&e.jsx("button",{type:"button",className:"scm-act",title:a("scmStageTip",{path:R.path}),onClick:p=>{p.stopPropagation(),he(R)},children:"+"}),ve==="staged"||ve==="both"?e.jsx("button",{type:"button",className:"scm-act",title:a("scmUnstageTip",{path:R.path}),onClick:p=>{p.stopPropagation(),xe(R)},children:"−"}):null]})]},R.path)}):e.jsx("div",{className:"scm-empty",children:t.status==="open"?a("scmLoading"):a("scmConnecting")})})]}),e.jsxs("div",{className:"scm-diff",children:[e.jsxs("div",{className:"scm-diff-header",children:[e.jsx("span",{children:T==="history"?j?`${j.shortHash} ${j.subject}`:a("scmCommitDetail"):q?q.path:a("scmDiff")}),(T==="history"?U:k)&&e.jsx("span",{className:"scm-diff-loading",children:a("scmLoading")})]}),e.jsx("div",{className:"scm-diff-body",children:T==="history"?e.jsxs(e.Fragment,{children:[N&&e.jsx("div",{className:"scm-error",children:N}),!j&&!N&&e.jsx("div",{className:"scm-empty",children:a("scmSelectCommitHint")}),j&&U&&!N&&e.jsx("div",{className:"scm-empty",children:a("scmLoading")}),j&&!U&&!N&&Q?Le(Q):null]}):e.jsxs(e.Fragment,{children:[N&&e.jsx("div",{className:"scm-error",children:N}),!q&&!N&&e.jsx("div",{className:"scm-empty",children:a("scmSelectFileHint")}),q&&!S&&!N&&e.jsx("div",{className:"scm-empty",children:a("scmLoading")}),q&&S&&S.untracked&&e.jsx("div",{className:"scm-empty",children:a("scmUntrackedNote")}),q&&S&&!S.untracked&&e.jsxs(e.Fragment,{children:[S.staged&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:a("scmStaged")}),Le(S.staged)]}),S.worktree&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"scm-diff-section",children:a("scmUnstaged")}),Le(S.worktree)]}),!S.staged&&!S.worktree&&e.jsx("div",{className:"scm-empty",children:a("scmNoDiff")})]})]})})]})]}),e.jsxs("div",{className:"scm-hint",children:[e.jsx(tt,{}),e.jsx("span",{children:a("scmRunsInTerminal")}),e.jsx("button",{type:"button",className:"scm-goto-term",onClick:c,children:a("scmViewTerminal")})]})]})}function El({entry:t,send:s}){const n=l.useRef(null),r=be();return l.useEffect(()=>{const c=n.current;if(!c)return;let a;try{a=t.module.mount(c,Ca(t.info.id,i=>s(i)))}catch(i){console.error(`[plugin:${t.info.id}] mount failed:`,i),c.textContent=r("pluginMountFailed",{name:t.info.name})}return()=>{if(typeof a=="function")try{a()}catch(i){console.error(`[plugin:${t.info.id}] cleanup failed:`,i)}c.textContent=""}},[t,s]),e.jsx("div",{className:"plugin-view",ref:n})}function Pl({send:t,piConfigured:s,piAgentInstalled:n,providers:r,installResult:c,onClose:a}){const i=be(),[o,u]=l.useState(!1),[m,y]=l.useState(""),[g,x]=l.useState(""),[b,T]=l.useState(!1);l.useEffect(()=>{t({type:"list_providers"})},[t]),l.useEffect(()=>{s&&a()},[s,a]),l.useEffect(()=>{c&&u(!1)},[c]),l.useEffect(()=>{var Q;!m&&r.length>0&&y(((Q=r.find(X=>!X.configured))==null?void 0:Q.id)??r[0].id)},[r,m]);const D=()=>{o||(u(!0),t({type:"install_pi_agent"}))},H=()=>{!g.trim()||b||(T(!0),t({type:"set_provider_api_key",provider:m.trim(),apiKey:g.trim()}),setTimeout(()=>T(!1),3e3))},C=()=>{t({type:"get_state"}),t({type:"list_providers"})},j=r.find(Q=>Q.id===m),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":i("close"),onClick:a,children:e.jsx(Pe,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(lt,{className:"modal-head-icon"}),e.jsx("h2",{children:i("setupTitle")})]}),e.jsx("p",{className:"modal-desc",children:i("setupDesc")}),J?e.jsxs("div",{className:"setup-failed",children:[e.jsx("div",{className:"setup-done",children:i("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:i("retryInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:a,children:i("skip")})]})]}):n||c!=null&&c.ok?e.jsxs("div",{className:"setup-key-form",children:[e.jsx("div",{className:"setup-done",children:c!=null&&c.ok?i("installDone"):i("cliReadyHint")}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:i("provider")}),e.jsxs("select",{value:m,onChange:Q=>y(Q.target.value),children:[r.length===0&&e.jsx("option",{value:"",children:i("loading")}),r.map(Q=>e.jsxs("option",{value:Q.id,children:[Q.name,"(",Q.id,")",Q.configured?` · ${i("configured")}`:""]},Q.id))]}),(j==null?void 0:j.configured)&&e.jsx("div",{className:"field-hint",children:i("providerKeyReady")})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:i("apiKey")}),e.jsx("input",{type:"password",value:g,onChange:Q=>x(Q.target.value),placeholder:"sk-…"})]}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:!g.trim()||b||!m,onClick:H,children:i(b?"saving":"saveAndStart")}),e.jsxs("button",{type:"button",className:"btn",onClick:C,children:[e.jsx(rt,{})," ",i("recheck")]})]})]}):e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{type:"button",className:"btn primary",disabled:o,onClick:D,children:i(o?"installing":"autoInstall")}),e.jsx("button",{type:"button",className:"btn",onClick:a,children:i("skip")})]})]})})}const Ml=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],ps=()=>({id:"",name:"",reasoning:!1,input:"text",contextWindow:"",maxTokens:""}),Rl=()=>({providerId:"",name:"",api:"openai-completions",baseUrl:"",apiKey:"",authHeader:!0,models:[ps()]});function qt(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:[ps()]).map(s=>{var n;return{id:s.id,name:s.name??"",reasoning:s.reasoning??!1,input:(n=s.input)!=null&&n.includes("image")?"text-image":"text",contextWindow:s.contextWindow?String(s.contextWindow):"",maxTokens:s.maxTokens?String(s.maxTokens):""}})}}function Il({send:t,providers:s,providerStatus:n,providerKeys:r,fetchModelsResult:c,cloneProviderResult:a,onClose:i}){const o=be(),[u,m]=l.useState(null),[y,g]=l.useState({}),[x,b]=l.useState({}),[T,D]=l.useState(null),[H,C]=l.useState(!1),[j,J]=l.useState(0),[Q,X]=l.useState(null),U=l.useRef(0),[W,q]=l.useState(null),[Y,S]=l.useState(""),[P,k]=l.useState(null);l.useEffect(()=>{t({type:"list_models_config"}),t({type:"list_providers"}),t({type:"list_provider_keys"})},[t]);const B=()=>{if(!u)return;const v=u.baseUrl.trim();if(!v){X({ok:!1,text:o("fetchModelsNeedBaseUrl")});return}if(H)return;C(!0),X(null);const L=j+1;J(L),t({type:"fetch_models",reqId:L,baseUrl:v,apiKey:u.apiKey.trim()||void 0,authHeader:u.authHeader,api:u.api})};l.useEffect(()=>{var v;if(!(!c||c.reqId===U.current))if(U.current=c.reqId,C(!1),c.ok&&((v=c.models)!=null&&v.length)){const L=c.models;m(d=>{if(!d)return d;const E=d.models.map(O=>{var ge;if(!O.id.trim())return O;const re=L.find(ue=>ue.id===O.id.trim());if(!re)return O;const ee={...O};return!ee.name&&re.name&&(ee.name=re.name),!ee.contextWindow&&re.contextWindow&&(ee.contextWindow=String(re.contextWindow)),!ee.maxTokens&&re.maxTokens&&(ee.maxTokens=String(re.maxTokens)),ee.input==="text"&&((ge=re.input)!=null&&ge.includes("image"))&&(ee.input="text-image"),!ee.reasoning&&re.reasoning&&(ee.reasoning=!0),ee}),h=new Set(E.map(O=>O.id.trim()).filter(Boolean)),_=L.filter(O=>!h.has(O.id)).map(O=>{var re;return{id:O.id,name:O.name??"",reasoning:O.reasoning??!1,input:(re=O.input)!=null&&re.includes("image")?"text-image":"text",contextWindow:O.contextWindow?String(O.contextWindow):"",maxTokens:O.maxTokens?String(O.maxTokens):""}}),te=[...E,..._];return te.some(O=>O.id.trim())?{...d,models:te.filter(O=>O.id.trim())}:d}),X({ok:!0,text:o("fetchModelsOk",{n:L.length})})}else X({ok:!1,text:c.error||o("fetchModelsEmpty")})},[c]);const Z=v=>{const L=(y[v.id]??"").trim();!L||T||(D(v.id),t({type:"add_provider_key",provider:v.id,apiKey:L,name:(x[v.id]??"").trim()||void 0}),setTimeout(()=>{D(null),g(d=>({...d,[v.id]:""})),b(d=>({...d,[v.id]:""})),t({type:"list_providers"}),t({type:"list_provider_keys"})},1500))},G=(v,L)=>{t({type:"activate_provider_key",provider:v,keyName:L}),t({type:"list_provider_keys"})},M=(v,L)=>{window.confirm(o("removeKeyConfirm"))&&(t({type:"remove_provider_key",provider:v,keyName:L}),t({type:"list_provider_keys"}))},I=()=>{if(!P)return;const v=P.providerId.trim();if(!v||!P.apiKey.trim())return;const L=P.models.filter(E=>E.id.trim()).map(E=>({id:E.id.trim(),name:E.name.trim()||void 0,reasoning:E.reasoning||void 0,input:E.input==="text-image"?["text","image"]:void 0,contextWindow:E.contextWindow?Number(E.contextWindow):void 0,maxTokens:E.maxTokens?Number(E.maxTokens):void 0})),d={providerId:v,name:P.name.trim()||void 0,api:P.api.trim()||void 0,baseUrl:P.baseUrl.trim()||void 0,apiKey:P.apiKey.trim()||void 0,authHeader:P.authHeader||void 0,models:L};t({type:"save_model_config",providerId:v,config:d}),k(null),i()},N=()=>{if(!u)return;const v=u.providerId.trim(),L=u.models.filter(E=>E.id.trim()).map(E=>({id:E.id.trim(),name:E.name.trim()||void 0,reasoning:E.reasoning||void 0,input:E.input==="text-image"?["text","image"]:void 0,contextWindow:E.contextWindow?Number(E.contextWindow):void 0,maxTokens:E.maxTokens?Number(E.maxTokens):void 0})),d={providerId:v,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:L};t({type:"save_model_config",providerId:v,config:d}),i()};l.useEffect(()=>{if(a&&a.ok){const v=a.configs;if(v&&v.length>1){q(v.map(L=>qt({...L,apiKey:""}))),S("");return}if(a.config){k(qt({...a.config,apiKey:""}));return}}},[a]);const $=v=>{window.confirm(o("clearKeyConfirm",{id:v}))&&t({type:"clear_provider_api_key",provider:v})},z=v=>{window.confirm(o("deleteProviderConfirm",{id:v.providerId,n:v.models.length}))&&t({type:"delete_model_config",providerId:v.providerId})},ie=(v,L)=>{u&&m({...u,models:u.models.map((d,E)=>E===v?{...d,...L}:d)})};return e.jsx("div",{className:"modal-backdrop",onClick:i,children:e.jsxs("div",{className:"modal model-modal",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":o("close"),onClick:i,children:e.jsx(Pe,{})}),e.jsx("div",{className:"modal-head",children:e.jsx("h2",{children:P?o("addKey"):W?o("batchCreateProviders",{n:W.length}):o(u?"editProvider":"manageModelsTitle")})}),P?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("secondKeyTitle",{api:P.api,baseUrl:P.baseUrl||o("noBaseUrlShort"),n:P.models.length})}),e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{className:"field",children:[e.jsxs("span",{className:"field-label",children:[o("providerNameLabel")," ",e.jsx("em",{children:o("providerNameHint")})]}),e.jsx("input",{type:"text",value:P.providerId,onChange:v=>k({...P,providerId:v.target.value}),placeholder:"opencode-2"})]}),e.jsxs("label",{className:"field",children:[e.jsx("span",{className:"field-label",children:o("apiKeyLabel")}),e.jsx("input",{type:"password",value:P.apiKey,onChange:v=>k({...P,apiKey:v.target.value}),placeholder:o("secondKeyPlaceholder")})]})]}),e.jsxs("div",{style:{fontSize:12,opacity:.6,marginTop:8},children:[P.models.slice(0,5).map(v=>v.id).join(", "),P.models.length>5?` … +${P.models.length-5}`:""]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>k(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn",onClick:()=>{const v=P;k(null),m(v)},children:o("advancedEdit")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!P.providerId.trim()||!P.apiKey.trim(),onClick:I,children:o("save")})]})]}):W?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children:e.jsxs("div",{className:"provider-form",children:[e.jsx("p",{className:"modal-desc",style:{marginBottom:12},children:o("batchDesc",{apis:W.map(v=>v.api).join("、"),n:W.length})}),e.jsxs("label",{className:"field",style:{marginBottom:16},children:[e.jsx("span",{className:"field-label",children:o("batchKeyLabel",{n:W.length})}),e.jsx("input",{type:"password",value:Y,onChange:v=>S(v.target.value),placeholder:o("secondKeyPlaceholder")})]}),e.jsx("div",{className:"provider-list",style:{marginBottom:16},children:W.map((v,L)=>e.jsxs("div",{className:"provider-row",style:{flexDirection:"column",alignItems:"stretch",gap:6},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:13},children:[e.jsx("strong",{children:v.providerId}),e.jsx("span",{style:{opacity:.7},children:v.api})]}),e.jsxs("div",{className:"provider-sub",style:{fontSize:12,opacity:.7},children:[v.baseUrl||o("noBaseUrlShort")," · ",o("modelsCountShort",{n:v.models.length}),v.models.slice(0,3).map(d=>d.id).join(", "),v.models.length>3?` … +${v.models.length-3}`:""]}),e.jsx("input",{type:"text",value:v.providerId,onChange:d=>q(E=>E.map((h,_)=>_===L?{...h,providerId:d.target.value}:h)),placeholder:o("providerIdPlaceholder"),style:{fontSize:12}}),e.jsx("input",{type:"text",value:v.baseUrl,onChange:d=>q(E=>E.map((h,_)=>_===L?{...h,baseUrl:d.target.value}:h)),placeholder:o("baseUrlExamplePh"),style:{fontSize:12}})]},L))})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>q(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!Y.trim(),onClick:()=>{for(const v of W){const L=v.providerId.trim();if(!L)continue;const d=v.models.filter(h=>h.id.trim()).map(h=>({id:h.id.trim(),name:h.name.trim()||void 0,reasoning:h.reasoning||void 0,input:h.input==="text-image"?["text","image"]:void 0,contextWindow:h.contextWindow?Number(h.contextWindow):void 0,maxTokens:h.maxTokens?Number(h.maxTokens):void 0})),E={providerId:L,name:v.name.trim()||void 0,api:v.api.trim()||void 0,baseUrl:v.baseUrl.trim()||void 0,apiKey:Y.trim()||void 0,authHeader:v.authHeader||void 0,models:d};t({type:"save_model_config",providerId:L,config:E})}q(null),i()},children:o("saveAllBatch",{n:W.length})})]})]}):u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-body",children: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(v=>v.providerId===u.providerId),onChange:v=>m({...u,providerId:v.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:v=>m({...u,name:v.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:v=>m({...u,api:v.target.value}),children:Ml.map(v=>e.jsx("option",{value:v,children:v},v))})]}),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:v=>m({...u,baseUrl:v.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:v=>m({...u,apiKey:v.target.value}),placeholder:o("apiKeyHint")})]}),e.jsxs("label",{className:"field check",children:[e.jsx("input",{type:"checkbox",checked:u.authHeader,onChange:v=>m({...u,authHeader:v.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:[Q&&e.jsx("span",{className:`fetch-msg ${Q.ok?"ok":"err"}`,title:Q.text,children:Q.text}),e.jsxs("button",{type:"button",className:"btn sm",disabled:H||!u.baseUrl.trim(),title:o("fetchModelsHint"),onClick:B,children:[e.jsx(ls,{})," ",o(H?"fetchingModels":"fetchModels")]})]})]}),u.models.map((v,L)=>e.jsxs("div",{className:"model-row",children:[e.jsx("input",{type:"text",value:v.id,onChange:d=>ie(L,{id:d.target.value}),placeholder:o("modelIdReq")}),e.jsx("input",{type:"text",value:v.name,onChange:d=>ie(L,{name:d.target.value}),placeholder:o("displayName")}),e.jsxs("select",{value:v.input,onChange:d=>ie(L,{input:d.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:v.reasoning,onChange:d=>ie(L,{reasoning:d.target.checked})}),e.jsx("span",{children:o("reasoning")})]}),e.jsx("input",{type:"number",value:v.contextWindow,onChange:d=>ie(L,{contextWindow:d.target.value}),placeholder:o("contextWindow"),title:"contextWindow"}),e.jsx("input",{type:"number",value:v.maxTokens,onChange:d=>ie(L,{maxTokens:d.target.value}),placeholder:o("maxOutput"),title:"maxTokens"}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeModel"),onClick:()=>m({...u,models:u.models.filter((d,E)=>E!==L)}),children:e.jsx(Ae,{})})]},L)),e.jsxs("button",{type:"button",className:"btn",onClick:()=>m({...u,models:[...u.models,ps()]}),children:[e.jsx(He,{})," ",o("addModel")]})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:()=>m(null),children:o("cancel")}),e.jsx("button",{type:"button",className:"btn primary",disabled:!u.providerId.trim()||!u.models.some(v=>v.id.trim()),onClick:N,children:o("save")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"model-modal-fixed-hint",children:e.jsxs("div",{className:"form-section-title",children:[o("builtinProviders")," ",e.jsx("em",{className:"section-hint",children:o("hintKeyOnly")})]})}),e.jsxs("div",{className:"model-modal-body",children:[e.jsxs("div",{className:"provider-list",children:[n.length===0&&e.jsx("div",{className:"dd-loading",children:o("loading")}),n.map(v=>{const L=r[v.id]??[];return e.jsxs("div",{className:"provider-row provider-key-row",children:[e.jsxs("div",{className:"provider-key-head",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.name}),e.jsxs("span",{className:"provider-sub",children:[v.id,v.configured&&e.jsx("span",{className:"auth-badge",children:o("configuredBadge")}),v.source&&!v.configured&&e.jsx("span",{className:"auth-badge dim",children:v.source})]})]}),v.source==="stored"&&e.jsxs("button",{type:"button",className:"btn sm danger",title:o("clearKeyTitle"),onClick:()=>$(v.id),children:[e.jsx(Ae,{})," ",o("clearKey")]})]}),e.jsxs("div",{className:"provider-keys",children:[L.length===0&&e.jsx("div",{className:"provider-key-empty",children:o("noKeyYet")}),L.map(d=>e.jsxs("div",{className:`provider-key-item ${d.active?"active":""}`,children:[e.jsx("span",{className:"provider-key-dot",children:d.active?"●":"○"}),e.jsx("span",{className:"provider-key-label",children:d.name}),!d.active&&e.jsx("button",{type:"button",className:"iconbtn",title:o("activateKey"),onClick:()=>G(v.id,d.name),children:e.jsx(pt,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("removeKey"),onClick:()=>M(v.id,d.name),children:e.jsx(Ae,{})})]},d.name)),e.jsxs("div",{className:"provider-add-key",children:[e.jsx("input",{type:"text",className:"key-input key-input-name",placeholder:o("keyNamePh"),value:x[v.id]??"",onChange:d=>b(E=>({...E,[v.id]:d.target.value}))}),e.jsx("input",{type:"password",className:"key-input key-input-value",placeholder:o("addKeyPlaceholder"),value:y[v.id]??"",onChange:d=>g(E=>({...E,[v.id]:d.target.value}))}),e.jsxs("button",{type:"button",className:"btn primary sm",disabled:!(y[v.id]??"").trim()||T===v.id,onClick:()=>Z(v),children:[e.jsx(He,{})," ",T===v.id?o("savingKey"):o("addKey")]})]})]})]},v.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(v=>e.jsxs("div",{className:"provider-row",children:[e.jsxs("div",{className:"provider-info",children:[e.jsx("span",{className:"provider-name",children:v.providerId}),e.jsxs("span",{className:"provider-sub",children:[v.api??"—",v.baseUrl?` · ${v.baseUrl}`:"",v.models.length>0&&` · ${o("modelsCount",{n:v.models.length})}`]})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsx("button",{type:"button",className:"iconbtn",title:o("edit"),onClick:()=>m(qt(v)),children:e.jsx(St,{})}),e.jsx("button",{type:"button",className:"iconbtn danger",title:o("delete"),onClick:()=>z(v),children:e.jsx(Ae,{})})]})]},v.providerId))})]}),e.jsx("div",{className:"modal-actions",children:e.jsxs("button",{type:"button",className:"btn primary",onClick:()=>m(Rl()),children:[e.jsx(He,{})," ",o("addProvider")]})})]})]})})}function Ll({plugin:t,send:s}){const n=be(),r=t.settingsSchema??[],[c,a]=l.useState(()=>({...t.settingsValues})),[i,o]=l.useState(!1);if(r.length===0)return null;const u=(x,b)=>a(T=>({...T,[x]:b})),m=r.some(x=>{var b;return c[x.key]!==((b=t.settingsValues)==null?void 0:b[x.key])}),y=()=>{o(!0),s({type:"plugin_settings",pluginId:t.id,values:c}),setTimeout(()=>o(!1),800)},g=()=>a({...t.settingsValues});return e.jsxs("div",{className:"plugin-settings-form",children:[e.jsx("div",{className:"plugin-settings-fields",children:r.map(x=>e.jsxs("label",{className:"plugin-settings-field",title:x.hint,children:[e.jsx("span",{className:"plugin-settings-label",children:x.label}),x.type==="boolean"?e.jsx("input",{type:"checkbox",checked:!!c[x.key],onChange:b=>u(x.key,b.target.checked)}):x.type==="select"?e.jsx("select",{value:String(c[x.key]??""),onChange:b=>u(x.key,b.target.value),children:(x.options??[]).map(b=>e.jsx("option",{value:b,children:b},b))}):e.jsx("input",{type:x.type==="password"?"password":x.type==="number"?"number":"text",value:String(c[x.key]??""),min:x.min,max:x.max,onChange:b=>u(x.key,x.type==="number"?Number(b.target.value):b.target.value)})]},x.key))}),e.jsxs("div",{className:"plugin-settings-actions",children:[e.jsx("button",{type:"button",className:"btn plugin-settings-save",disabled:!m||i,onClick:y,children:n(i?"pluginSettingsSaving":"pluginSettingsSave")}),e.jsx("button",{type:"button",className:"btn plugin-settings-reset",onClick:g,children:n("pluginSettingsReset")})]})]})}function Dl(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Ke({text:t}){const s=l.useRef(null),[n,r]=l.useState(!1),c=()=>{var i;const a=(i=s.current)==null?void 0:i.getBoundingClientRect();a&&r(window.innerWidth-a.right<340)};return e.jsxs("span",{ref:s,className:`set-tip${n?" flip":""}`,tabIndex:0,"aria-label":t,onMouseEnter:c,onFocus:c,children:["?",e.jsx("span",{className:"set-tip-bubble",role:"tooltip",children:t})]})}function Re({title:t,subtitle:s,tip:n,enabled:r,onToggle:c,action:a}){const i=be();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,n&&e.jsx(Ke,{text:n})]}),s&&e.jsx("div",{className:"set-row-desc",children:s})]}),a,e.jsx("button",{type:"button",className:`set-switch ${r?"on":""}`,role:"switch","aria-checked":r,title:i(r?"settingsEnabled":"settingsDisabled"),onClick:c,children:e.jsx("span",{className:"set-switch-knob"})})]})}function Al({chat:t,send:s,terminal:n,onSwitchToTerminal:r,onClose:c}){var Le,Be,De,R,ve,ce;const a=be(),i=t.settings,o=t.engine==="dsh",[u,m]=l.useState("prompt"),y=l.useRef(null);l.useEffect(()=>{var p;(p=y.current)==null||p.scrollTo({top:0})},[u]),l.useEffect(()=>{u==="plugins"&&t.engine==="dsh"&&s({type:"dsh_patches_list"})},[u,t.engine,s]);const[g,x]=l.useState(""),[b,T]=l.useState("append"),D=l.useRef(!1),[H,C]=l.useState(""),[j,J]=l.useState("append"),Q=l.useRef(!1),[X,U]=l.useState(""),W=l.useRef(!1),[q,Y]=l.useState(""),[S,P]=l.useState(null),[k,B]=l.useState(null),[Z,G]=l.useState(!1),M=Hn(),[I,N]=l.useState(()=>ni()),[$,z]=l.useState(()=>{try{return dt().length}catch{return 0}}),[ie,v]=l.useState(!1),L=()=>{try{z(dt().length)}catch{z(0)}};l.useEffect(()=>{u==="prompt-history"&&L()},[u]),l.useEffect(()=>{if(!ie)return;const p=window.setTimeout(()=>v(!1),3e3);return()=>window.clearTimeout(p)},[ie]);const[d,E]=l.useState(null),[h,_]=l.useState(null);l.useEffect(()=>{i&&(T(i.promptMode),!D.current&&(x(b==="append"||i.customSystemPrompt?i.customSystemPrompt:i.defaultSystemPrompt||""),J(i.visionBridgePromptMode),!Q.current&&(C(j==="append"||i.visionBridgePrompt?i.visionBridgePrompt:i.visionBridgeDefaultPrompt||""),W.current||U(i.reviewPrompt))))},[i,b,j]);const[te,O]=l.useState(String((i==null?void 0:i.terminalBashIdleMs)??15e3));if(l.useEffect(()=>{O(String((i==null?void 0:i.terminalBashIdleMs)??15e3))},[i==null?void 0:i.terminalBashIdleMs]),!i)return null;const re=[{id:"prompt",icon:e.jsx(kn,{}),label:a("settingsSystemPrompt")},{id:"prompt-history",icon:e.jsx(_s,{}),label:a("settingsPromptHistory"),count:$},{id:"terminal",icon:e.jsx(tt,{}),label:a("settingsTerminalTools")},{id:"display",icon:e.jsx(st,{}),label:a("settingsMessageDisplay")},{id:"markers",icon:e.jsx(Ls,{}),label:a("settingsMarkers"),count:((Le=i.markers)==null?void 0:Le.length)??0},{id:"skills",icon:e.jsx(lt,{}),label:a("settingsSkills"),count:i.skills.length},{id:"extensions",icon:e.jsx(Ds,{}),label:a("settingsExtensions"),count:i.extensions.length},{id:"plugins",icon:e.jsx(Lt,{}),label:a("settingsUiPlugins"),count:t.plugins.length},{id:"review",icon:e.jsx(xt,{}),label:a("settingsReview"),count:i.reviewSkills.length},...o?[]:[{id:"vision",icon:e.jsx(Qt,{}),label:a("settingsVisionBridge")}],{id:"presets",icon:e.jsx(Di,{}),label:a("settingsPresets"),count:i.presets.length},...o?[]:[{id:"subagent-templates",icon:e.jsx(Rs,{}),label:a("settingsSubagentTemplates"),count:i.subagentTemplates.length}]],ee=new Set(i.disabledSkills),ge=new Set(i.disabledExtensions),ue=p=>s({type:"set_settings",...p}),de=p=>{const V=new Set(ee);V.has(p.name)?V.delete(p.name):V.add(p.name),ue({disabledSkills:[...V]})},Se=new Set(i.disabledPlugins??[]),le=p=>{const V=new Set(Se);V.has(p.id)?V.delete(p.id):V.add(p.id),ue({disabledPlugins:[...V]})},f=p=>{const V=new Set(ge);V.has(p.id)?V.delete(p.id):V.add(p.id),ue({disabledExtensions:[...V]})},K=i.markersEnabled??!0,me=new Set(i.disabledMarkers??[]),he=p=>{const V=new Set(me),w=p==="conv"||p==="rename"||p==="title"?["conv","rename","title"]:[p],A=!w.some(ae=>V.has(ae));for(const ae of w)A?V.add(ae):V.delete(ae);ue({disabledMarkers:[...V]})},xe=(p,V)=>{var oe,je;const w={name:p,command:V,cwd:"${pwd}"};let A;const ae=t.terminals.find(we=>we.title===p);ae?(n.restart(ae.id),s({type:"run_command",terminalId:ae.id,conversationId:ae.conversationId,command:w,cols:80,rows:24}),A=ae.id):(A=Ue(),n.create({id:A,conversationId:t.activeConversationId||((oe=t.state)==null?void 0:oe.conversationId)||"",title:p,cwd:((je=t.state)==null?void 0:je.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:w})),n.select(A),r(),c()},fe=p=>{E(null),xe(`${a("uninstallTitle")} ${p}`,`pi remove npm:${p}`)},ke=p=>{_(null),xe(`${a("uninstallTitle")} ${p}`,`pi-web-ui uninstall ${p}`)},Me=(p,V)=>{xe(`${a("pluginUpdate")} ${p}`,`pi-web-ui install ${V} --name ${p} --force`)},ye=p=>{const V=new Set(i.reviewSkills.filter(w=>!w.enabled).map(w=>w.name));V.has(p.name)?V.delete(p.name):V.add(p.name),ue({reviewDisabledSkills:[...V]})},_e=()=>{const p=b==="replace"&&i.defaultSystemPrompt&&g===i.defaultSystemPrompt?"":g;ue({promptMode:b,customSystemPrompt:p})};return e.jsx("div",{className:"modal-backdrop",onClick:c,children:e.jsxs("div",{className:"modal settings-modal",onClick:p=>p.stopPropagation(),children:[e.jsx("button",{type:"button",className:"modal-close","aria-label":a("close"),onClick:c,children:e.jsx(Pe,{})}),e.jsxs("div",{className:"modal-head",children:[e.jsx(wt,{className:"modal-head-icon"}),e.jsx("h2",{children:a("settingsTitle")}),e.jsx(Ke,{text:a("settingsDesc")})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-rail","aria-label":a("settingsTitle"),children:re.map(p=>e.jsxs("button",{type:"button",className:`settings-tab${u===p.id?" active":""}`,"aria-current":u===p.id?"true":void 0,title:p.label,onClick:()=>m(p.id),children:[e.jsx("span",{className:"settings-tab-icon",children:p.icon}),e.jsx("span",{className:"settings-tab-label",children:p.label}),p.count!==void 0&&e.jsx("span",{className:"set-count",children:p.count})]},p.id))}),e.jsxs("div",{className:"modal-body",ref:y,children:[u==="prompt"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{className:"set-section-icon"}),a("settingsSystemPrompt")]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("settingsPromptMode")}),e.jsxs("select",{className:"set-select",value:b,onChange:p=>{const V=p.target.value;T(V),ue({promptMode:V})},children:[e.jsx("option",{value:"append",children:a("promptModeAppend")}),e.jsx("option",{value:"replace",children:a("promptModeReplace")})]}),e.jsx(Ke,{text:a(b==="append"?"promptAppendHint":"promptReplaceHint")})]}),e.jsx("textarea",{className:"set-prompt-input",rows:6,placeholder:a("promptPlaceholder"),value:g,onFocus:()=>D.current=!0,onBlur:()=>{D.current=!1,_e()},onChange:p=>x(p.target.value)}),e.jsxs("button",{type:"button",className:"set-view-prompt-btn","aria-expanded":Z,onClick:()=>G(p=>!p),children:[a("settingsViewPrompt")," ",Z?"▴":"▾"]}),Z&&e.jsxs("div",{className:"set-prompt-view",children:[e.jsxs("div",{className:"set-prompt-view-head",children:[e.jsx("span",{children:a("settingsViewPromptHint")}),e.jsx(Tt,{text:i.effectiveSystemPrompt})]}),i.effectiveSystemPrompt?e.jsx("pre",{className:"set-prompt-view-text",children:i.effectiveSystemPrompt}):e.jsx("p",{className:"set-empty",children:a("settingsViewPromptEmpty")})]})]}),u==="prompt-history"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(_s,{className:"set-section-icon"}),a("settingsPromptHistory"),e.jsx(Ke,{text:a("settingsPromptHistoryDesc")}),e.jsx("span",{className:"set-count",children:a("promptHistoryCount",{n:String($)})})]}),$===0?e.jsx("p",{className:"set-empty",children:a("promptHistoryEmpty")}):e.jsx("p",{className:"set-hint",children:a("promptHistoryCount",{n:String($)})}),e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"ph-max",children:a("promptHistoryMax")}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("input",{id:"ph-max",className:"set-input",type:"number",min:1,max:500,step:1,value:String(I.maxEntries),onChange:p=>{const V=Math.floor(Number(p.target.value)||0),w={...I,maxEntries:V};N(w)},onBlur:()=>{const p={...I};(!Number.isFinite(p.maxEntries)||p.maxEntries<1)&&(p.maxEntries=1),p.maxEntries>500&&(p.maxEntries=500),p.maxEntries=Math.floor(p.maxEntries),N(p),Ut(p),L()}}),e.jsx(Ke,{text:a("promptHistoryMaxHint")})]})]}),e.jsx(Re,{title:a("promptHistoryCharLimit"),tip:a("promptHistoryCharLimitHint"),enabled:I.charLimitEnabled,onToggle:()=>{const p={...I,charLimitEnabled:!I.charLimitEnabled};N(p),Ut(p),L()}}),I.charLimitEnabled&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"ph-char-limit",children:a("promptHistoryCharLimit")}),e.jsx("input",{id:"ph-char-limit",className:"set-input",type:"number",min:100,max:2e4,step:100,placeholder:a("promptHistoryCharLimitPlaceholder"),value:String(I.charLimit),onChange:p=>{const V=Math.floor(Number(p.target.value)||0);N({...I,charLimit:V})},onBlur:()=>{let p=Math.floor(Number(I.charLimit)||0);(!Number.isFinite(p)||p<100)&&(p=100),p>2e4&&(p=2e4);const V={...I,charLimit:p};N(V),Ut(V),L()}})]}),e.jsxs("div",{className:"set-field",style:{marginTop:12},children:[e.jsxs("button",{type:"button",className:`set-uninstall${ie?" confirm":""}`,disabled:$===0,title:a($===0?"promptHistoryEmpty":"promptHistoryClear"),onClick:()=>{if(!ie){v(!0);return}pl(),v(!1),L()},children:[e.jsx(Ae,{})," ",a(ie?"promptHistoryClearConfirm":"promptHistoryClear")]}),$>0&&e.jsx("span",{className:"set-hint",style:{marginLeft:8},children:a("promptHistoryCount",{n:String($)})})]}),e.jsxs("p",{className:"set-hint",children:[e.jsx(Zi,{style:{verticalAlign:"-2px",marginRight:4}}),a("settingsPromptHistoryDesc")]})]}),u==="terminal"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(tt,{className:"set-section-icon"}),a("settingsTerminalTools")]}),e.jsx(Re,{title:a("terminalToolsEnabled"),tip:a("settingsTerminalToolsDesc"),enabled:i.terminalToolsEnabled,onToggle:()=>ue({terminalToolsEnabled:!i.terminalToolsEnabled})}),!i.terminalToolsEnabled&&e.jsx("p",{className:"set-hint",children:a("terminalToolsOffHint")}),e.jsx(Re,{title:a("terminalBashTakeover"),tip:a("terminalBashTakeoverDesc"),enabled:i.terminalBash,onToggle:()=>ue({terminalBash:!i.terminalBash})}),i.terminalBash&&e.jsxs("div",{className:"set-field",children:[e.jsx("label",{className:"set-field-label",htmlFor:"tb-idle-ms",children:a("terminalBashIdleMs")}),e.jsx("input",{id:"tb-idle-ms",className:"set-input",type:"number",min:0,step:1e3,value:te,onChange:p=>O(p.target.value),onBlur:()=>{const p=Math.max(0,Math.floor(Number(te)||0));O(String(p)),p!==i.terminalBashIdleMs&&ue({terminalBashIdleMs:p})}})]})]}),u==="display"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(st,{className:"set-section-icon"}),a("settingsMessageDisplay")]}),e.jsx(Re,{title:a("thinkingWrap"),tip:a("thinkingWrapDesc"),enabled:i.thinkingWrap??!0,onToggle:()=>ue({thinkingWrap:!(i.thinkingWrap??!0)})}),e.jsx(Re,{title:a("toolsWrap"),tip:a("toolsWrapDesc"),enabled:i.toolsWrap??!0,onToggle:()=>ue({toolsWrap:!(i.toolsWrap??!0)})}),e.jsx("hr",{className:"set-sep"}),e.jsx(Re,{title:a("mermaidRenderSetting"),tip:a("mermaidRenderSettingDesc"),enabled:M,onToggle:()=>tr({enabled:!M})})]}),u==="markers"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ls,{className:"set-section-icon"}),a("settingsMarkers"),e.jsx(Ke,{text:a("settingsMarkersDesc")}),e.jsx("span",{className:"set-count",children:((Be=i.markers)==null?void 0:Be.length)??0})]}),e.jsx(Re,{title:a("markersEnabled"),tip:a("markersEnabledDesc"),enabled:K,onToggle:()=>ue({markersEnabled:!K})}),!K&&e.jsx("p",{className:"set-hint",children:a("markersOffHint")}),K&&(((De=i.markers)==null?void 0:De.length)??0)===0&&e.jsxs("p",{className:"set-empty",children:[a("loading"),"..."]}),K&&i.markers&&i.markers.length>0&&e.jsx("div",{className:"set-list",children:i.markers.map(p=>e.jsx(Re,{title:p.name==="todo"?a("markerGroupTodo"):p.name==="svc"?a("markerGroupSvc"):p.name==="notify"?a("markerGroupNotify"):p.name==="conv"||p.name==="rename"||p.name==="title"?a("markerGroupRename"):p.name,subtitle:(p.guidance[0]??"").slice(0,120),tip:p.guidance.join(`
325
+ `),enabled:p.enabled,onToggle:()=>he(p.name)},p.name))}),K&&e.jsx("p",{className:"set-hint",children:a("markerRenameTip")})]}),u==="skills"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(lt,{className:"set-section-icon"}),a("settingsSkills"),e.jsx("span",{className:"set-count",children:i.skills.length})]}),i.skills.length===0?e.jsx("p",{className:"set-empty",children:a(o?"dshSkillsNote":"noSkills")}):e.jsx("div",{className:"set-list",children:i.skills.map(p=>e.jsx(Re,{title:p.name,subtitle:p.description,enabled:p.enabled,onToggle:()=>de(p)},p.name))})]}),u==="extensions"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Ds,{className:"set-section-icon"}),a("settingsExtensions"),e.jsx("span",{className:"set-count",children:i.extensions.length})]}),i.extensions.length===0?e.jsx("p",{className:"set-empty",children:a(o?"dshExtensionsNote":"noExtensions")}):e.jsx("div",{className:"set-list",children:i.extensions.map(p=>{const V=p.id.startsWith("npm:")?p.id.slice(4):null;return e.jsx(Re,{title:p.name,subtitle:p.path,enabled:p.enabled,onToggle:()=>f(p),action:V?d===p.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("uninstallConfirmHint"),onClick:()=>fe(V),children:a("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:a("uninstallHint"),onClick:()=>E(p.id),children:[e.jsx(Ae,{}),a("uninstallExt")]}):void 0},p.id)})})]}),u==="plugins"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Lt,{className:"set-section-icon"}),a("settingsUiPlugins"),e.jsx("span",{className:"set-count",children:t.plugins.length})]}),t.plugins.length===0?e.jsx("p",{className:"set-empty",children:a("noUiPlugins")}):e.jsx("div",{className:"set-list",children:t.plugins.map(p=>{var V;return e.jsxs(e.Fragment,{children:[e.jsx(Re,{title:`${p.icon?`${p.icon} `:""}${p.name}`,subtitle:(p.error?`${p.id} · ${p.error}`:p.source?`${p.id} · ${p.source}`:`${p.id} · ${a("uiPluginNoSource")}`)+((V=p.permissions)!=null&&V.length?` · ${a("uiPluginPerms")}: ${p.permissions.join(", ")}`:""),enabled:!Se.has(p.id)&&!p.error,onToggle:()=>!p.error&&le(p),action:e.jsxs("div",{className:"set-row-actions",children:[p.source&&e.jsxs("button",{type:"button",className:"set-uninstall",title:a("pluginUpdateHint"),onClick:()=>Me(p.id,p.source),children:[e.jsx(rt,{}),a("pluginUpdate")]}),h===p.id?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("pluginUninstallHint"),onClick:()=>ke(p.id),children:a("uninstallConfirm")}):e.jsxs("button",{type:"button",className:"set-uninstall",title:a("pluginUninstallHint"),onClick:()=>_(p.id),children:[e.jsx(Ae,{}),a("uninstallExt")]})]})},p.id),p.settingsSchema&&p.settingsSchema.length>0&&e.jsx(Ll,{plugin:p,send:s})]})})})]}),u==="plugins"&&t.engine==="dsh"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Lt,{className:"set-section-icon"}),a("dshPatches"),e.jsx(Ke,{text:a("dshPatchesDesc")}),e.jsx("span",{className:"set-count",children:((R=t.dshPatches)==null?void 0:R.files.length)??0}),e.jsxs("button",{type:"button",className:"set-uninstall",title:a("dshPatchesRescanHint"),onClick:()=>s({type:"dsh_patches_rescan"}),children:[e.jsx(rt,{}),a("dshPatchesRescan")]})]}),(((ve=t.dshPatches)==null?void 0:ve.files.length)??0)===0?e.jsx("p",{className:"set-empty",children:a("dshPatchesEmpty")}):e.jsx("div",{className:"set-list",children:t.dshPatches.files.map(p=>e.jsx("div",{className:"set-row",children:e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:p.name}),e.jsxs("div",{className:"set-row-desc",children:[Dl(p.size)," · ",new Date(p.mtimeMs).toLocaleString()]})]})},p.name))}),e.jsxs("p",{className:"set-hint",children:[a("dshPatchesPath")," ",((ce=t.dshPatches)==null?void 0:ce.patchDir)??""]})]}),u==="review"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(xt,{className:"set-section-icon"}),a("settingsReview"),e.jsx(Ke,{text:a("settingsReviewDesc")}),e.jsx("span",{className:"set-count",children:i.reviewSkills.length})]}),o&&e.jsx("p",{className:"set-hint",children:a("dshReviewPromptNote")}),e.jsx("textarea",{className:"set-prompt-input",rows:5,placeholder:a("reviewPromptPlaceholder"),value:X,onFocus:()=>W.current=!0,onBlur:()=>{W.current=!1,ue({reviewPrompt:X})},onChange:p=>U(p.target.value)}),e.jsx("div",{className:"set-field-label",children:a("settingsReviewSkills")}),i.reviewSkills.length===0?e.jsx("p",{className:"set-empty",children:a("noSkills")}):e.jsx("div",{className:"set-list",children:i.reviewSkills.map(p=>e.jsx(Re,{title:p.name,subtitle:p.description,enabled:p.enabled,onToggle:()=>ye(p)},`review-${p.name}`))})]}),u==="vision"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Qt,{className:"set-section-icon"}),a("settingsVisionBridge")]}),e.jsx(Re,{title:a("visionBridgeEnabled"),tip:a("settingsVisionBridgeDesc"),enabled:i.visionBridgeEnabled,onToggle:()=>ue({visionBridgeEnabled:!i.visionBridgeEnabled})}),!i.visionBridgeEnabled&&e.jsx("p",{className:"set-hint",children:a("visionBridgeOffHint")}),i.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("visionBridgeModel")}),e.jsxs("select",{className:"set-select",value:i.visionBridgeModel??"",onChange:p=>ue({visionBridgeModel:p.target.value||null}),children:[e.jsx("option",{value:"",children:a("visionBridgeAuto")}),i.visionModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),i.visionBridgeEnabled&&e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("visionBridgePromptMode")}),e.jsxs("select",{className:"set-select",value:j,onChange:p=>{const V=p.target.value;J(V),ue({visionBridgePromptMode:V})},children:[e.jsx("option",{value:"append",children:a("promptModeAppend")}),e.jsx("option",{value:"replace",children:a("promptModeReplace")})]})]}),i.visionBridgeEnabled&&e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:a("visionBridgePromptPlaceholder"),value:H,onFocus:()=>Q.current=!0,onBlur:()=>{Q.current=!1;const p=j==="replace"&&i.visionBridgeDefaultPrompt&&H===i.visionBridgeDefaultPrompt?"":H;ue({visionBridgePromptMode:j,visionBridgePrompt:p})},onChange:p=>C(p.target.value)}),i.visionBridgeEnabled&&(i.visionModels.length===0?e.jsx("p",{className:"set-hint",children:a("visionBridgeNoModels")}):e.jsx("p",{className:"set-hint",children:a("visionBridgeCurrent",{model:i.visionBridgeModel??a("visionBridgeAuto")})}))]}),u==="presets"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(wt,{className:"set-section-icon"}),a("settingsPresets"),e.jsx("span",{className:"set-count",children:i.presets.length})]}),e.jsxs("div",{className:"set-preset-save",children:[e.jsx("input",{className:"set-input",placeholder:a("presetNamePlaceholder"),value:q,onChange:p=>Y(p.target.value),onKeyDown:p=>{p.key==="Enter"&&q.trim()&&(s({type:"save_preset",name:q.trim()}),Y(""))}}),e.jsxs("button",{type:"button",className:"set-save-btn",disabled:!q.trim(),onClick:()=>{s({type:"save_preset",name:q.trim()}),Y("")},children:[e.jsx(He,{})," ",a("saveAsPreset")]})]}),i.presets.length===0?e.jsx("p",{className:"set-empty",children:a("noPresets")}):e.jsx("div",{className:"set-list",children:i.presets.map(p=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsx("div",{className:"set-row-name",children:p.name}),e.jsxs("div",{className:"set-row-desc",children:[p.promptMode==="replace"?a("promptModeReplace"):a("promptModeAppend"),p.disabledSkills.length>0&&` · ${a("settingsSkills")} ${p.disabledSkills.length}`,p.disabledExtensions.length>0&&` · ${a("settingsExtensions")} ${p.disabledExtensions.length}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>s({type:"apply_preset",name:p.name}),children:a("applyPreset")}),e.jsx("button",{type:"button",className:"set-icon-btn danger",title:a("deletePreset"),onClick:()=>s({type:"delete_preset",name:p.name}),children:e.jsx(Ae,{})})]})]},p.name))})]}),u==="subagent-templates"&&e.jsxs("div",{className:"set-section",children:[e.jsxs("div",{className:"set-section-title",children:[e.jsx(Rs,{className:"set-section-icon"}),a("settingsSubagentTemplates"),e.jsx(Ke,{text:a("settingsSubagentTemplatesDesc")}),e.jsx("span",{className:"set-count",children:i.subagentTemplates.length}),e.jsxs("button",{type:"button",className:"set-save-btn",title:a("subagentTemplateNew"),onClick:()=>P({name:"",description:"",promptMode:"replace",systemPrompt:"",enabledSkills:[],enabledExtensions:[],model:"",enabled:!0}),children:[e.jsx(He,{})," ",a("subagentTemplateNew")]})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("subagentDefaultModelLabel")}),e.jsxs("select",{className:"set-select",value:i.subagentDefaultModel??"",onChange:p=>ue({subagentDefaultModel:p.target.value||null}),children:[e.jsx("option",{value:"",children:a("subagentFollowMain")}),i.subagentModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),i.subagentModels.length===0?e.jsx("p",{className:"set-hint",children:a("subagentNoModels")}):e.jsx("p",{className:"set-hint",children:a("subagentDefaultModelHint")}),S&&e.jsxs("div",{className:"tpl-editor",children:[e.jsxs("div",{className:"tpl-fields",children:[e.jsx("input",{className:"set-input",placeholder:a("tplNamePlaceholder"),value:S.name,onChange:p=>P({...S,name:p.target.value})}),e.jsx("input",{className:"set-input",placeholder:a("tplDescriptionPlaceholder"),value:S.description,onChange:p=>P({...S,description:p.target.value})})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("tplPromptModeLabel")}),e.jsxs("select",{className:"set-select",value:S.promptMode,onChange:p=>P({...S,promptMode:p.target.value}),children:[e.jsx("option",{value:"replace",children:a("promptModeReplace")}),e.jsx("option",{value:"append",children:a("promptModeAppend")})]})]}),e.jsxs("div",{className:"set-mode-row",children:[e.jsx("label",{className:"set-field-label",children:a("tplModelLabel")}),e.jsxs("select",{className:"set-select",value:S.model??"",onChange:p=>P({...S,model:p.target.value}),children:[e.jsx("option",{value:"",children:a("subagentFollowMain")}),i.subagentModels.map(p=>e.jsx("option",{value:`${p.provider}/${p.id}`,children:p.label},`${p.provider}/${p.id}`))]})]}),e.jsx("textarea",{className:"set-prompt-input",rows:4,placeholder:`${a("tplSystemPromptLabel")}:${a("tplSystemPromptPlaceholder")}`,value:S.systemPrompt,onChange:p=>P({...S,systemPrompt:p.target.value})}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[a("tplSkillsLabel")," · ",a("tplWhitelistHint")]})}),i.skills.length===0?e.jsx("p",{className:"set-hint",children:a("noSkills")}):e.jsx("div",{className:"tpl-pick",children:i.skills.map(p=>e.jsxs("label",{className:`tpl-chip${S.enabledSkills.includes(p.name)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:S.enabledSkills.includes(p.name),onChange:V=>{const w=V.target.checked;P({...S,enabledSkills:w?[...S.enabledSkills,p.name]:S.enabledSkills.filter(A=>A!==p.name)})}}),p.name]},p.name))})]}),e.jsxs("div",{className:"tpl-pick-block",children:[e.jsx("div",{className:"tpl-pick-head",children:e.jsxs("span",{children:[a("tplExtensionsLabel")," · ",a("tplWhitelistHint")]})}),i.extensions.length===0?e.jsx("p",{className:"set-hint",children:a("noExtensions")}):e.jsx("div",{className:"tpl-pick",children:i.extensions.map(p=>e.jsxs("label",{className:`tpl-chip${S.enabledExtensions.includes(p.id)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:S.enabledExtensions.includes(p.id),onChange:V=>{const w=V.target.checked;P({...S,enabledExtensions:w?[...S.enabledExtensions,p.id]:S.enabledExtensions.filter(A=>A!==p.id)})}}),p.name]},p.id))})]}),e.jsxs("div",{className:"tpl-actions",children:[e.jsx("button",{type:"button",className:"set-save-btn",disabled:!S.name.trim(),onClick:()=>{s({type:"save_subagent_template",template:{...S,name:S.name.trim()}}),P(null)},children:a("tplSave")}),e.jsx("button",{type:"button",className:"dd-refresh",onClick:()=>P(null),children:a("tplCancel")})]})]}),i.subagentTemplates.length===0?e.jsx("p",{className:"set-empty",children:a("noSubagentTemplates")}):e.jsx("div",{className:"set-list",children:i.subagentTemplates.map(p=>e.jsxs("div",{className:"set-row",children:[e.jsxs("div",{className:"set-row-info",children:[e.jsxs("div",{className:"set-row-name",children:[p.name,i.subagentDefaultTemplates.includes(p.name)&&e.jsx("span",{className:"tpl-badge default",children:a("tplDefaultBadge")}),!p.enabled&&e.jsx("span",{className:"tpl-badge",children:a("subagentTemplateClosed")})]}),e.jsxs("div",{className:"set-row-desc",children:[p.description||`${p.promptMode==="replace"?a("promptModeReplace"):a("promptModeAppend")}`,p.model?` · ${a("tplModelLabel")} ${p.model}`:` · ${a("subagentFollowMain")}`,p.enabledSkills.length>0&&` · ${a("tplSkillsLabel")} ${p.enabledSkills.length}`,p.enabledExtensions.length>0&&` · ${a("tplExtensionsLabel")} ${p.enabledExtensions.length}`,!p.description&&p.enabledSkills.length===0&&p.enabledExtensions.length===0&&` · ${a("tplInherit")}`]})]}),e.jsxs("div",{className:"set-row-actions",children:[e.jsx("button",{type:"button",className:`set-switch${p.enabled?" on":""}`,role:"switch","aria-checked":p.enabled,title:`${p.enabled?a("subagentTemplateDisable"):a("subagentTemplateEnable")} · ${a("subagentTemplateOffHint")}`,onClick:()=>s({type:"save_subagent_template",template:{...p,enabled:!p.enabled}}),children:e.jsx("span",{className:"set-switch-knob"})}),e.jsx("button",{type:"button",className:"dd-refresh",title:a("subagentTemplateEdit"),onClick:()=>P({...p}),children:a("subagentTemplateEdit")}),k===p.name?e.jsx("button",{type:"button",className:"set-uninstall confirm",title:a("uninstallConfirmHint"),onClick:()=>{s({type:"delete_subagent_template",name:p.name}),B(null)},children:a("uninstallConfirm")}):e.jsx("button",{type:"button",className:"set-icon-btn danger",title:a("tplDelete"),onClick:()=>B(p.name),children:e.jsx(Ae,{})})]})]},p.name))})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{type:"button",className:"dd-refresh",onClick:c,children:a("close")})})]})})}function _l(t,s){const n=Math.max(0,Date.now()-t),r=Math.floor(n/6e4);if(r<1)return s("bgTaskJustNow");if(r<60)return s("bgTaskMinutes",{n:r});const c=Math.floor(r/60);return c<24?s("bgTaskHours",{n:c}):s("bgTaskDays",{n:Math.floor(c/24)})}function Bl({servers:t,send:s,onClose:n}){const r=be(),[c,a]=l.useState(new Set),i=o=>a(u=>{const m=new Set(u);return m.has(o)?m.delete(o):m.add(o),m});return l.useEffect(()=>{s({type:"list_bg_servers"})},[]),e.jsx("div",{className:"modal-backdrop",onClick:n,children:e.jsxs("div",{className:"bg-task-modal",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"bg-task-head",children:[e.jsxs("span",{className:"bg-task-title",children:[e.jsx(Ct,{})," ",r("bgTasks"),t.length>0&&e.jsx("em",{className:"bg-task-count",children:t.length})]}),e.jsx("button",{type:"button",className:"btn",title:r("close"),onClick:n,children:e.jsx(Pe,{})})]}),t.length===0?e.jsxs("div",{className:"bg-task-empty",children:[e.jsx(Ct,{}),e.jsx("span",{children:r("bgTasksEmpty")}),e.jsx("small",{children:r("bgTasksDesc")})]}):e.jsx("ul",{className:"bg-task-list",children:t.map(o=>{const u=!!o.taskId,m=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:r("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:[r("bgTaskPid")," ",o.pid]}),e.jsxs("span",{children:[r("bgTaskSince")," ",_l(o.since,r)]}),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(m)?"open":""}`,title:`${r("bgTaskCommand")}: ${o.command}`,onClick:()=>i(m),children:[e.jsx(tt,{}),e.jsx("code",{children:o.command})]})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stop",title:r("bgTaskStop"),onClick:()=>s(u?{type:"kill_background_server",taskId:o.taskId}:{type:"kill_background_server",port:o.port}),children:[e.jsx(jt,{}),e.jsx("span",{children:r("bgTaskStop")})]})]},m)})}),e.jsxs("div",{className:"bg-task-foot",children:[e.jsxs("button",{type:"button",className:"btn",title:r("bgTaskRefresh"),onClick:()=>s({type:"list_bg_servers"}),children:[e.jsx(rt,{}),e.jsx("span",{children:r("bgTaskRefresh")})]}),e.jsxs("button",{type:"button",className:"btn bg-task-stopall",disabled:t.length===0,title:r("bgTaskStopAll"),onClick:()=>s({type:"kill_background_servers"}),children:[e.jsx(jt,{}),e.jsx("span",{children:r("bgTaskStopAll")})]})]})]})})}function Fl(t,s){return t.toLowerCase().includes(s)}function $l({open:t,send:s,projects:n,cwd:r,fileSearch:c,sessionSearch:a,onClose:i,onSwitchSession:o,onSwitchProject:u,onPreviewFile:m}){const y=be(),g=l.useRef(null),[x,b]=l.useState(""),T=l.useDeferredValue(x),[D,H]=l.useState(0),C=l.useRef(1),j=l.useRef(0),J=l.useRef(null);l.useEffect(()=>{if(!t)return;s({type:"list_sessions"}),s({type:"list_projects"});const M=x.trim();if(M){const I=++C.current;j.current=I,X(!0),s({type:"search_files",reqId:I,query:M}),s({type:"search_sessions",reqId:I,query:M})}requestAnimationFrame(()=>{var I;return(I=g.current)==null?void 0:I.select()})},[t]);const[Q,X]=l.useState(!1);l.useEffect(()=>{J.current&&clearTimeout(J.current);const M=T.trim();if(!M){X(!1);return}return J.current=setTimeout(()=>{const I=++C.current;j.current=I,X(!0),s({type:"search_files",reqId:I,query:M}),s({type:"search_sessions",reqId:I,query:M})},300),()=>{J.current&&clearTimeout(J.current)}},[T]);const U=T.trim().toLowerCase(),W=l.useMemo(()=>!U||!a||a.reqId!==j.current||!a.ok?[]:a.results,[a,U]),q=l.useMemo(()=>U?n.filter(M=>Fl(M.path,U)).slice(0,10):[],[n,U]),Y=l.useMemo(()=>!U||!c||c.reqId!==j.current||!c.ok?[]:c.results,[c,U]);l.useEffect(()=>{c&&c.reqId===j.current&&a&&a.reqId===j.current&&j.current!==0&&X(!1)},[c,a]);const S=!!c&&c.ok&&c.truncated,P=l.useMemo(()=>[...W.map(M=>({kind:"session",path:M.path,anchors:M.anchors})),...q.map(M=>({kind:"project",path:M.path})),...Y.filter(M=>M.type==="file").map(M=>({kind:"file",path:M.path,name:M.name}))],[W,q,Y]);l.useEffect(()=>{H(0)},[T]);const k=l.useCallback(M=>{if(M)if(M.kind==="session")o(M.path,M.anchors),i();else if(M.kind==="project"){u(M.path),s({type:"list_sessions"}),s({type:"list_projects"});const I=T.trim();if(I){const N=++C.current;j.current=N,X(!0),s({type:"search_files",reqId:N,query:I}),s({type:"search_sessions",reqId:N,query:I})}}else m(M.path,M.name)},[o,u,m,s,T]);l.useEffect(()=>{if(!t)return;const M=I=>{I.key==="Escape"?(I.preventDefault(),I.stopPropagation(),i()):I.key==="ArrowDown"?(I.preventDefault(),H(N=>Math.min(N+1,P.length-1))):I.key==="ArrowUp"?(I.preventDefault(),H(N=>Math.max(N-1,0))):I.key==="Enter"&&(I.preventDefault(),k(P[D]))};return window.addEventListener("keydown",M,!0),()=>window.removeEventListener("keydown",M,!0)},[P,D,k,i,t]);const B=W.length+q.length+Y.length,Z=(M,I,N)=>e.jsxs("div",{className:"gs-section-head",children:[N,e.jsx("span",{children:M}),e.jsx("em",{children:I})]});let G=-1;return t?e.jsx("div",{className:"modal-backdrop gs-backdrop",onClick:i,children:e.jsxs("div",{className:"gs-modal",onClick:M=>M.stopPropagation(),children:[e.jsxs("div",{className:"gs-input-row",children:[e.jsx(Nt,{}),e.jsx("input",{ref:g,type:"text",value:x,placeholder:y("gsPlaceholder"),onChange:M=>b(M.target.value)}),e.jsx("button",{type:"button",className:"gs-close",title:y("close"),onClick:i,children:e.jsx(Pe,{})})]}),e.jsxs("div",{className:"gs-results",children:[!U&&e.jsx("div",{className:"gs-empty",children:y("gsHint")}),U&&B===0&&!S&&e.jsx("div",{className:"gs-empty",children:y(Q?"gsSearching":"gsNoResults")}),W.length>0&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsSessions"),W.length,e.jsx(st,{})),W.map(M=>{G++;const I=G;return e.jsxs("button",{type:"button",className:I===D?"gs-item active":"gs-item",onMouseEnter:()=>H(I),onClick:()=>k({kind:"session",path:M.path,anchors:M.anchors}),children:[e.jsxs("span",{className:"gs-item-title",children:[M.name||M.path.split(/[\\/]/).pop(),e.jsx("em",{className:"gs-item-meta",children:M.messageCount})]}),e.jsx("span",{className:"gs-item-sub",children:M.firstMessage})]},M.path)})]}),q.length>0&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsProjects"),q.length,e.jsx(Je,{})),q.map(M=>{G++;const I=G,N=r&&M.path===r;return e.jsxs("button",{type:"button",className:I===D?"gs-item active":"gs-item",onMouseEnter:()=>H(I),onClick:()=>k({kind:"project",path:M.path}),children:[e.jsxs("span",{className:"gs-item-title",children:[M.path.split(/[\\/]/).pop(),N&&e.jsx("em",{className:"gs-item-meta",children:y("gsCurrentProject")})]}),e.jsx("span",{className:"gs-item-sub",children:M.path})]},M.path)})]}),(Y.length>0||U&&S)&&e.jsxs("div",{className:"gs-section",children:[Z(y("gsFiles"),Y.length,e.jsx(kn,{})),Y.map(M=>{G++;const I=G;return e.jsxs("button",{type:"button",className:I===D?"gs-item active":"gs-item",disabled:M.type==="dir",title:M.type==="dir"?void 0:y("gsOpenPreview"),onMouseEnter:()=>H(I),onClick:()=>{M.type==="file"&&k({kind:"file",path:M.path,name:M.name})},children:[e.jsx("span",{className:"gs-item-title",children:M.name}),e.jsx("span",{className:"gs-item-sub",children:M.path})]},`${M.type}:${M.path}`)}),S&&e.jsx("div",{className:"gs-truncated",children:y("gsTruncated")})]})]}),e.jsxs("div",{className:"gs-foot",children:[e.jsxs("span",{children:["↑↓ ",y("gsNavigate")]}),e.jsxs("span",{children:["Enter ",y("gsOpen")]}),e.jsxs("span",{children:["Esc ",y("gsCloseHint")]})]})]})}):null}const zt=5e3;function Hl({file:t,content:s,send:n,onAddLines:r,onAttach:c,onClose:a}){const i=be(),[o,u]=l.useState(null),[m,y]=l.useState(!1),[g,x]=l.useState(null),[b,T]=l.useState(!1),[D,H]=l.useState(!1),[C,j]=l.useState(!1),[J,Q]=l.useState(""),[X,U]=l.useState(!0),W=l.useRef(!1),[q,Y]=l.useState(!0),[S,P]=l.useState(!1),[k,B]=l.useState(100),Z=l.useRef(0),G=l.useRef(!1),M=l.useRef(null);l.useEffect(()=>{y(!0),u(null),x(null),j(!1),Q(""),U(!0),W.current=!1,n({type:"read_file",path:t.path})},[t.path,n]),l.useEffect(()=>{s&&s.path===t.path&&(u(s),C||Q(s.text),y(!1))},[s,C,t.path]),l.useEffect(()=>{const le=f=>{if(f.key==="Escape"){_();return}if((f.ctrlKey||f.metaKey)&&f.key.toLowerCase()==="s"&&C){f.preventDefault(),h();return}const K=f.target,me=K&&(K.tagName==="INPUT"||K.tagName==="TEXTAREA"||K.isContentEditable);(f.ctrlKey||f.metaKey)&&f.key.toLowerCase()==="a"&&!me&&(f.preventDefault(),ie())};return document.addEventListener("keydown",le),()=>document.removeEventListener("keydown",le)},[a,o,C,J]),l.useEffect(()=>{const le=()=>{G.current=!1,T(!1)};return window.addEventListener("mouseup",le),()=>window.removeEventListener("mouseup",le)},[]);const I=l.useMemo(()=>{if(!o)return[];const le=o.text.split(`
326
+ `);return le.length>0&&le[le.length-1]===""&&le.pop(),le.slice(0,zt)},[o]),N=(o==null?void 0:o.lines)??0,$=N>zt,z=(le,f)=>{if(f){const K=Z.current>0?Z.current:le;x({start:Math.min(K,le),end:Math.max(K,le)})}else Z.current=le,x({start:le,end:le})},ie=()=>{I.length!==0&&(Z.current=1,x({start:1,end:I.length}))},v=()=>{g&&(r(t.path,t.name,g.start,g.end),H(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>H(!1),1400))},L=o!==null&&o.kind==="text"&&!o.binary&&!o.truncated,d=()=>{Q((o==null?void 0:o.text)??""),j(!1),W.current&&U(!0)},E=()=>{if(C){if(J!==((o==null?void 0:o.text)??"")&&!window.confirm(i("discardFileChanges")))return;d();return}!L||!o||(W.current=Vt(t.name)&&X,Vt(t.name)&&U(!1),x(null),Q(o.text),j(!0))},h=()=>{!C||!o||!L||n({type:"write_file",path:t.path,text:J})&&(j(!1),W.current&&U(!0),x(null))},_=()=>{C&&J!==((o==null?void 0:o.text)??"")&&!window.confirm(i("discardFileChanges"))||a()},te=le=>{B(Math.min(200,Math.max(50,le)))},O=g?g.end-g.start+1:0,re=(o==null?void 0:o.binary)??!1,ee=(o==null?void 0:o.truncated)??!1,ge=(o==null?void 0:o.kind)??"text",ue=Vt(t.name),de=ue&&X&&!C&&ge==="text"&&!re,Se=le=>Mt(Ve(`/api/file?clientId=${encodeURIComponent(os())}&path=${encodeURIComponent(le)}`));return e.jsx("div",{className:`fp-overlay ${S?"fullscreen":""}`,onMouseDown:le=>{le.target===le.currentTarget&&_()},children:e.jsxs("div",{className:`fp ${S?"fullscreen":""}`,style:{"--fp-zoom":k/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&&ge==="text"&&!re&&i("fileLines",{n:N}),o&&` · ${Ol(o.size)}`]}),e.jsxs("span",{className:"fp-head-actions",children:[ue&&ge==="text"&&!re&&o&&e.jsx("button",{type:"button",className:`fp-attach markdown ${X?"on":""}`,"data-tip":i(X?"showMarkdownSource":"showMarkdownPreview"),disabled:C,onClick:()=>U(le=>!le),children:X?e.jsx(Qt,{}):e.jsx(Qi,{})}),ge==="text"&&!re&&o&&e.jsx("button",{type:"button",className:`fp-attach edit ${C?"on":""}`,"data-tip":i(ee?"fileEditTruncated":C?"exitEditFile":"editFile"),disabled:!L&&!C,onClick:E,children:e.jsx(Yt,{})}),ge==="text"&&!re&&!de&&e.jsx("button",{type:"button",className:`fp-attach wrap ${q?"on":""}`,"data-tip":i(q?"disableWrap":"enableWrap"),onClick:()=>Y(le=>!le),children:e.jsx(Gi,{})}),ge==="text"&&o&&e.jsxs("span",{className:"fp-zoom",children:[e.jsx("button",{type:"button",className:"fp-attach zoom-out","data-tip":i("zoomOut"),disabled:k<=50,onClick:()=>te(k-10),children:e.jsx(Pi,{})}),e.jsxs("button",{type:"button",className:"fp-zoom-val",title:i("resetZoom"),onClick:()=>B(100),children:[k,"%"]}),e.jsx("button",{type:"button",className:"fp-attach zoom-in","data-tip":i("zoomIn"),disabled:k>=200,onClick:()=>te(k+10),children:e.jsx(Mi,{})})]}),ge!=="video"&&ge!=="none"&&e.jsx("button",{type:"button",className:"fp-attach inline","data-tip":i("attachInlineTip"),onClick:()=>c(t.path,t.name,"inline"),children:e.jsx(He,{})}),e.jsx("button",{type:"button",className:"fp-attach ref","data-tip":i("referenceTip"),onClick:()=>c(t.path,t.name,"reference"),children:e.jsx(Gt,{})}),e.jsx("button",{type:"button",className:`fp-attach full ${S?"on":""}`,"data-tip":i(S?"exitFullscreen":"fullscreen"),onClick:()=>P(le=>!le),children:S?e.jsx(Fi,{}):e.jsx(Hi,{})}),e.jsx("button",{type:"button",className:"fp-close",title:i("close"),onClick:_,children:e.jsx(Pe,{})})]})]}),ee&&ge==="text"&&!re&&e.jsx("div",{className:"fp-notice",children:i("previewTruncated")}),m&&!o&&e.jsx("div",{className:"fp-empty",children:i("loading")}),!m&&ge==="none"&&!re&&e.jsx("div",{className:"fp-empty",children:i("previewNotSupported")}),!m&&ge==="image"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("img",{className:"fp-media",src:Se(t.path),alt:t.name})}),!m&&ge==="video"&&e.jsx("div",{className:"fp-media-wrap",children:e.jsx("video",{className:"fp-media",src:Se(t.path),controls:!0,preload:"metadata"})}),!m&&de&&o&&e.jsx("div",{className:"fp-markdown msg-text",children:e.jsx("div",{className:"fp-markdown-zoom",children:e.jsx(Rt,{text:o.text})})}),!m&&re&&ge!=="image"&&ge!=="video"&&o&&e.jsxs("div",{className:"fp-hex-wrap",children:[e.jsxs("div",{className:"fp-notice",children:[i("binaryFile"),o.truncated&&i("binaryHexTruncated")]}),e.jsx("pre",{className:"fp-hex",children:o.text})]}),!m&&C&&ge==="text"&&!re&&o&&e.jsx("textarea",{className:`fp-editor ${q?"":"no-wrap"}`,value:J,onChange:le=>Q(le.target.value),wrap:q?"soft":"off",spellCheck:!1,autoFocus:!0}),!m&&!de&&!C&&ge==="text"&&!re&&o&&I.length===0&&e.jsx("div",{className:"fp-empty",children:i("emptyFile")}),!m&&!de&&!C&&ge==="text"&&!re&&I.length>0&&e.jsxs("div",{className:`fp-code ${b?"dragging":""} ${q?"":"no-wrap"}`,onMouseDown:le=>{le.button===0&&le.preventDefault()},children:[I.map((le,f)=>{const K=f+1,me=g!==null&&K>=g.start&&K<=g.end;return e.jsxs("div",{className:`fp-line ${me?"sel":""}`,onMouseDown:he=>{he.button===0&&(z(K,he.shiftKey),G.current=!0,T(!0))},onMouseEnter:()=>{G.current&&z(K,!0)},children:[e.jsx("span",{className:"fp-num",children:K}),e.jsx("span",{className:"fp-code-text",children:le})]},K)}),$&&e.jsx("div",{className:"fp-lines-note",children:i("previewLinesTruncated",{n:zt})})]}),e.jsx("div",{className:"fp-foot",children:C?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:i("editFile")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:E,children:i("cancel")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:J===((o==null?void 0:o.text)??""),onClick:h,children:[e.jsx(Ai,{})," ",i("saveFile")]})]})]}):!de&&ge==="text"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fp-hint",children:g?i("selectedRange",{n:O,start:g.start,end:g.end}):i("selectLinesHint")}),e.jsxs("div",{className:"fp-actions",children:[e.jsx("button",{type:"button",className:"btn",disabled:I.length===0,onClick:ie,children:i("selectAll")}),e.jsx("button",{type:"button",className:"btn",disabled:!g,onClick:()=>x(null),children:i("clearSelection")}),e.jsxs("button",{type:"button",className:"btn primary",disabled:!g||re,onClick:v,children:[D?e.jsx(pt,{}):null,i(D?"addedToChat":"addToChat")]})]})]})})]})})}function Vt(t){const s=t.toLowerCase();return s.endsWith(".md")||s.endsWith(".markdown")}function Ol(t){return t>=1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`}const ri="pi-web-sounds",nt={enabled:!0,question:!0,done:!0,start:!1,error:!0,volume:100};function li(){try{const t=localStorage.getItem(ri);if(!t)return{...nt};const s=JSON.parse(t),n={...nt,...s};for(const r of["enabled","question","done","start","error"])typeof n[r]!="boolean"&&(n[r]=nt[r]);return typeof n.volume!="number"||!Number.isFinite(n.volume)?n.volume=nt.volume:n.volume=Math.round(Math.max(0,Math.min(100,n.volume))/5)*5,n}catch{return{...nt}}}function Kl(t){try{localStorage.setItem(ri,JSON.stringify(t))}catch{}}let it=null;function Wl(){try{if(!it){const t=window.AudioContext??window.webkitAudioContext;if(!t)return null;it=new t}return it.state==="suspended"&&it.resume(),it}catch{return null}}const Ul=[{type:"sine",freq:587.33,start:0,dur:.13,peak:.5},{type:"sine",freq:880,start:.11,dur:.24,peak:.5}],ql=[{type:"sine",freq:880,start:0,dur:.15,peak:.35},{type:"sine",freq:587.33,start:.15,dur:.32,peak:.35}],zl=[{type:"triangle",freq:660,start:0,dur:.08,peak:.22}],Vl=[{type:"square",freq:220,start:0,dur:.16,peak:.18},{type:"square",freq:174.61,start:.18,dur:.26,peak:.18}],Gl={question:Ul,done:ql,start:zl,error:Vl};function Ql(t,s,n){const r=t.createOscillator(),c=t.createGain();r.type=s.type,r.frequency.value=s.freq;const a=t.currentTime+s.start,i=Math.max(1e-4,s.peak*n);c.gain.setValueAtTime(1e-4,a),c.gain.exponentialRampToValueAtTime(i,a+.012),c.gain.exponentialRampToValueAtTime(1e-4,a+s.dur),r.connect(c),c.connect(t.destination),r.start(a),r.stop(a+s.dur+.05)}function at(t,s=li()){if(!s.enabled||!s[t])return;const n=Wl();if(!n)return;const r=Math.max(0,Math.min(1,s.volume/100));for(const c of Gl[t])Ql(n,c,r)}const as="pi-web-ui:theme",oi="dark",on="theme-stylesheet",cn="pi-web-ui:theme-change";function ci(){try{const t=localStorage.getItem(as);if(t&&t!==oi)return t}catch{}return null}function Yl(t){try{t?localStorage.setItem(as,t):localStorage.removeItem(as)}catch{}}function di(t){let s=document.getElementById(on);if(!t){s==null||s.remove(),window.dispatchEvent(new CustomEvent(cn));return}s||(s=document.createElement("link"),s.id=on,s.rel="stylesheet",document.head.appendChild(s)),s.href=Ve(`/themes/${encodeURIComponent(t)}.css`),s.onload=()=>window.dispatchEvent(new CustomEvent(cn))}async function Jl(){try{const t=await fetch(Mt(Ve("/api/themes")));if(!t.ok)return[];const s=await t.json();return Array.isArray(s.themes)?s.themes:[]}catch{return[]}}function Xl(){const[t,s]=l.useState([]),[n,r]=l.useState(()=>ci());return l.useEffect(()=>{let a=!1;return Jl().then(i=>{a||s(i)}),()=>{a=!0}},[]),l.useEffect(()=>{di(n),Yl(n)},[n]),{themes:t,theme:n,switchTheme:a=>r(a===oi?null:a)}}function ro(){const t=getComputedStyle(document.documentElement),s=(n,r)=>t.getPropertyValue(n).trim()||r;return{background:s("--term-bg","#0b0d12"),foreground:s("--term-fg","#e6e8ef"),cursor:s("--term-cursor","#8b5cf6"),cursorAccent:s("--term-cursor-accent","#0b0d12"),selectionBackground:s("--term-selection","rgba(139, 92, 246, 0.35)"),black:s("--term-black","#1a1d26"),red:s("--term-red","#f87171"),green:s("--term-green","#34d399"),yellow:s("--term-yellow","#fbbf24"),blue:s("--term-blue","#60a5fa"),magenta:s("--term-magenta","#c084fc"),cyan:s("--term-cyan","#22d3ee"),white:s("--term-white","#e6e8ef"),brightBlack:s("--term-bright-black","#6b7284"),brightRed:s("--term-bright-red","#f87171"),brightGreen:s("--term-bright-green","#34d399"),brightYellow:s("--term-bright-yellow","#fbbf24"),brightBlue:s("--term-bright-blue","#60a5fa"),brightMagenta:s("--term-bright-magenta","#c084fc"),brightCyan:s("--term-bright-cyan","#22d3ee"),brightWhite:s("--term-bright-white","#ffffff")}}const Zl=l.lazy(()=>gn(()=>import("./TerminalPanel-DL8sTcRC.js"),__vite__mapDeps([2,1,3,4,5])).then(t=>({default:t.TerminalPanel})));function eo({notice:t,onDismiss:s}){const n=be(),{locale:r}=mt(),c=r==="en"&&t.textEn?t.textEn:t.text,[a,i]=l.useState(!1);l.useEffect(()=>{if(a)return;const u=setTimeout(()=>s(t.id),t.level==="error"?12e3:7e3);return()=>clearTimeout(u)},[a,t.id,t.level,s]);const o=t.level==="error"?ta:t.level==="warning"?ea:Wi;return e.jsxs("div",{className:`notice notice-${t.level}${a?" paused":""}`,role:"status",onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[e.jsx(o,{className:"notice-icon"}),e.jsx("span",{className:"notice-text",children:c}),e.jsx("button",{type:"button",className:"notice-close",title:n("close"),onClick:()=>s(t.id),children:e.jsx(Pe,{})})]})}const to=[],ui=180,pi=520,mi=240,hi=t=>`pi-web-ui:${t}-panel-width`;function dn(t){const s=Number(localStorage.getItem(hi(t)));return Number.isFinite(s)&&s>=ui&&s<=pi?s:mi}const rs=t=>`pi-web-ui:${t}-panel-collapsed`;function un(t){return localStorage.getItem(rs(t))==="1"}function pn({side:t,width:s,onResize:n}){const r=be(),c=l.useCallback(a=>{a.preventDefault();const i=a.clientX,o=s;let u=o;const m=g=>{const x=t==="left"?g.clientX-i:i-g.clientX;u=Math.min(pi,Math.max(ui,Math.round(o+x))),n(u)},y=()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",y),document.body.classList.remove("panel-resizing"),localStorage.setItem(hi(t),String(u))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",y),document.body.classList.add("panel-resizing")},[t,s,n]);return e.jsx("div",{className:`resize-handle resize-${t}`,title:r("dragToResize"),onPointerDown:c,onDoubleClick:()=>n(mi)})}function mn({side:t,onClick:s}){const n=be();return e.jsx("button",{type:"button",className:`panel-rail panel-rail-${t}`,title:n("expandPanel"),onClick:s,children:t==="left"?e.jsx(wn,{}):e.jsx(Nn,{})})}function so(){var Oe,ms,hs,gs,fs,xs,ys,vs,bs,ks,js,ws,Ns,Cs;const t=be(),{chat:s,send:n,dismissNotice:r,pushNotice:c,terminal:a}=Aa(),[i,o]=l.useState([]),[u,m]=l.useState(null),[y,g]=l.useState(!1),[x,b]=l.useState("chat"),T=l.useMemo(()=>s.plugins.filter(F=>{var se,pe;return!((pe=(se=s.settings)==null?void 0:se.disabledPlugins)!=null&&pe.includes(F.id))}),[s.plugins,(Oe=s.settings)==null?void 0:Oe.disabledPlugins]),[D,H]=l.useState([]);l.useEffect(()=>wa(H),[]),l.useEffect(()=>{Na(T,s.pluginsEpoch)},[T,s.pluginsEpoch]);const[C,j]=l.useState(()=>dn("left")),[J,Q]=l.useState(()=>dn("right")),X=l.useCallback(F=>j(F),[]),U=l.useCallback(F=>Q(F),[]),[W,q]=l.useState(()=>un("left")),[Y,S]=l.useState(()=>un("right")),P=l.useCallback(()=>{q(F=>(localStorage.setItem(rs("left"),F?"0":"1"),!F))},[]),k=l.useCallback(()=>{S(F=>(localStorage.setItem(rs("right"),F?"0":"1"),!F))},[]),[B,Z]=l.useState(null),[G,M]=l.useState(()=>window.matchMedia("(max-width: 768px)").matches);l.useEffect(()=>{const F=window.matchMedia("(max-width: 768px)"),se=pe=>M(pe.matches);return F.addEventListener("change",se),()=>F.removeEventListener("change",se)},[]);const[I,N]=l.useState(!1),[$,z]=l.useState(!1),[ie,v]=l.useState(!1),[L,d]=l.useState(!1),[E,h]=l.useState(!1),[_,te]=l.useState(null);l.useEffect(()=>{if(!_)return;const F=setTimeout(()=>te(null),15e3);return()=>clearTimeout(F)},[_]),l.useEffect(()=>{const F=se=>{var qe,Ss;const pe=se.detail,Ne=(pe==null?void 0:pe.title)||t("pluginCommandFallback"),Ce=pe==null?void 0:pe.command;if(!Ce||!s.ready)return;const Fe={name:Ne,command:Ce,cwd:"${pwd}"},Te=s.terminals.find(It=>It.title===Ne);if(Te)a.restart(Te.id),n({type:"run_command",terminalId:Te.id,conversationId:Te.conversationId,command:Fe,cols:80,rows:24});else{const It=Ue();a.create({id:It,conversationId:s.activeConversationId||((qe=s.state)==null?void 0:qe.conversationId)||"",title:Ne,cwd:((Ss=s.state)==null?void 0:Ss.cwd)??"",cols:80,rows:24,running:!0,exitCode:null,command:Fe})}b("terminal")};return window.addEventListener("pi-web-ui:plugin-run-command",F),()=>window.removeEventListener("pi-web-ui:plugin-run-command",F)},[s,a,n]),l.useEffect(()=>{const F=se=>{!(se.ctrlKey||se.metaKey)||se.key.toLowerCase()!=="k"||(se.preventDefault(),h(pe=>!pe))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]);const[O,re]=l.useState(li),{themes:ee,theme:ge,switchTheme:ue}=Xl(),de=l.useRef(null),Se=l.useRef(null),le=l.useRef(0),f=l.useRef(!1),K=l.useRef(s.terminals);l.useEffect(()=>{Kl(O)},[O]),l.useEffect(()=>{var se;const F=K.current;K.current=s.terminals;for(const pe of s.terminals){const Ne=((se=pe.command)==null?void 0:se.command)??"",Ce=F.find(Fe=>Fe.id===pe.id);!(Ce!=null&&Ce.running)||pe.running||(Ne.startsWith("pi remove ")?n({type:"extensions_reload"}):Ne.startsWith("pi-web-ui install ")||Ne.startsWith("pi-web-ui uninstall ")?n({type:"plugins_reload"}):Ne.startsWith("npm i -g ")&&(n({type:"extensions_reload"}),n({type:"plugins_reload"}),n({type:"check_updates_all",force:!0})))}},[s.terminals,n]),l.useEffect(()=>{var pe;const F=((pe=s.state)==null?void 0:pe.isStreaming)??!1,se=de.current;de.current=F,se!==null&&(!se&&F?at("start",O):se&&!F&&(at("done",O),_t(t("notifyDoneTitle"),t("notifyDoneBody"))))},[(ms=s.state)==null?void 0:ms.isStreaming,O]),l.useEffect(()=>{var se;const F=((se=s.dialog)==null?void 0:se.id)??null;F!==null&&F!==Se.current&&(at("question",O),_t(t("notifyQuestionTitle"),t("notifyQuestionBody"))),Se.current=F},[s.dialog,O]),l.useEffect(()=>{const F=[...s.notices].reverse().find(se=>se.level==="error");F&&F.id!==le.current&&(le.current=F.id,at("error",O),_t(t("notifyErrorTitle"),t("notifyErrorBody")))},[s.notices,O]);const me=(F,se,pe,Ne=!1,Ce)=>{const Fe=`${F}|${pe}|${Ce?`${Ce.start}-${Ce.end}`:""}`;o(Te=>Te.some(qe=>`${qe.path}|${qe.mode}|${qe.lines?`${qe.lines.start}-${qe.lines.end}`:""}`===Fe)?Te:[...Te,{path:F,name:se,mode:pe,isDir:Ne,...Ce?{lines:Ce}:{}}])},he=F=>o(se=>se.filter(pe=>pe.key?pe.key!==F:pe.path!==F)),xe=l.useCallback(F=>(!F.type.startsWith("list_")&&!F.type.startsWith("get_")&&Z(null),n(F)),[n]),fe=l.useRef(0),ke=l.useRef(0),Me=F=>{var Ne;const se=Date.now();(Ne=s.state)!=null&&Ne.model&&!s.state.model.vision&&se-ke.current>1e4&&(ke.current=se,c("warning",t("imageNotSupported")));const pe=`paste-${++fe.current}`;o(Ce=>[...Ce,{path:"",key:pe,name:F.name,mode:"inline",imageData:F.data,mimeType:F.mimeType}])},ye=async F=>{for(const se of F){const pe=await On(se);if(!pe){c("error",t("imageLoadFailed",{name:se.name}));continue}Me(pe)}},_e=20*1024*1024,Le=l.useRef(0),Be=async F=>{if(F.size>_e){c("warning",t("fileTooLarge",{name:F.name,size:_e/1024/1024}));return}let se;try{se=(await new Promise((Ce,Fe)=>{const Te=new FileReader;Te.onload=()=>Ce(Te.result),Te.onerror=()=>Fe(Te.error??new Error("read failed")),Te.readAsDataURL(F)})).replace(/^data:[^;]*;base64,/,"")}catch{c("error",t("fileLoadFailed",{name:F.name}));return}const pe=`upload-${++Le.current}`;o(Ne=>[...Ne,{path:"",key:pe,name:F.name,mode:"inline",fileData:se,size:F.size,mimeType:F.type||void 0}])},De=async F=>{for(const se of F)We(se.type)?await ye([se]):await Be(se)},R=l.useCallback((F,se,pe)=>{n({type:"edit_message",messageId:F,text:se,attachments:pe})},[n]),ve=l.useCallback((F,se)=>{n({type:"queue_remove",kind:F,text:se})},[n]),ce=l.useCallback(()=>z(!0),[]),p=l.useCallback(()=>o([]),[]),V=l.useCallback(he,[]),w=l.useCallback(ye,[ye]),A=l.useCallback(De,[De]),ae=(hs=s.state)==null?void 0:hs.model,oe=(gs=s.state)==null?void 0:gs.thinkingLevel,je=(fs=s.state)==null?void 0:fs.availableThinkingLevels,we=l.useMemo(()=>ae?{model:ae,thinkingLevel:oe??"off",availableThinkingLevels:je??[]}:null,[ae,oe,je]),Ee=l.useCallback(()=>{var F,se;return!s.ready||s.terminals.length!==0?!1:(a.create({id:Ue(),conversationId:s.activeConversationId||((F=s.state)==null?void 0:F.conversationId)||"",title:t("terminalTitle",{n:1}),cwd:((se=s.state)==null?void 0:se.cwd)??"",cols:80,rows:24,running:!0,exitCode:null}),!0)},[s.ready,(xs=s.state)==null?void 0:xs.cwd,s.terminals.length,t,a]);return l.useEffect(()=>{if(f.current){if(x!=="terminal"||s.terminals.length!==0){f.current=!1;return}Ee()&&(f.current=!1)}},[s.terminals.length,Ee,x]),e.jsxs("div",{className:"app",onDragOver:F=>{var se;Array.from(((se=F.dataTransfer)==null?void 0:se.types)??[]).includes("Files")&&(F.preventDefault(),g(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||g(!1)},onDrop:F=>{var Ce,Fe;if(g(!1),!Array.from(((Ce=F.dataTransfer)==null?void 0:Ce.types)??[]).includes("Files"))return;F.preventDefault();const se=Array.from(((Fe=F.dataTransfer)==null?void 0:Fe.files)??[]);if(se.length===0){c("warning",t("foldersNotSupported"));return}const pe=se.filter(Te=>We(Te.type)),Ne=se.filter(Te=>!We(Te.type));pe.length>0&&ye(pe),Ne.length>0&&De(Ne)},children:[y&&e.jsx("div",{className:"app-drop-overlay","aria-hidden":!0,children:e.jsxs("span",{children:["📎 ",t("dropHereToAttach")]})}),e.jsx(da,{chat:s,send:n,terminal:a,view:x,plugins:T,onViewChange:F=>{f.current=F==="terminal"&&s.terminals.length===0,f.current&&Ee()&&(f.current=!1),b(F),Z(null)},onOpenPanel:Z,onOpenSettings:()=>v(!0),onOpenBgTasks:()=>d(!0),onOpenGlobalSearch:()=>h(!0),sound:O,onSoundChange:re,onSoundPreview:F=>at(F,O),themes:ee,theme:ge,onThemeChange:ue}),s.protocolMismatch&&e.jsxs("div",{className:"protocol-banner",children:["⚠ ",t("protocolMismatch")]}),e.jsx("div",{className:"notices",children:s.notices.map(F=>e.jsx(eo,{notice:F,onDismiss:r},F.id))}),e.jsx(Yr,{send:n,children:e.jsxs("div",{className:"layout",style:{"--left-w":`${C}px`,"--right-w":`${J}px`},children:[B&&e.jsx("div",{className:"drawer-backdrop",onClick:()=>Z(null)}),e.jsxs("div",{className:`view-pane ${x==="chat"?"":"hidden"}`,children:[!G&&W&&e.jsx(mn,{side:"left",onClick:P}),e.jsx("div",{className:`panel-drawer drawer-left ${B==="left"?"open":""}${G?"":W?" hidden":""}`,children:e.jsx(fa,{collapsible:!G,onToggleCollapse:P,send:xe,active:!G||B==="left",ready:s.ready,status:s.status,cwd:((ys=s.state)==null?void 0:ys.cwd)??"",sessionFile:((vs=s.state)==null?void 0:vs.sessionFile)??null,conversations:s.conversations,sessions:s.sessions,projects:s.projects,activeConversationId:s.activeConversationId})}),!G&&e.jsx(pn,{side:"left",width:C,onResize:X}),e.jsxs("main",{className:"main",children:[s.state?e.jsx(sl,{state:s.state,liveOutputs:s.liveOutputs,toolStatuses:s.toolStatuses,onEdit:R,onKillBash:()=>n({type:"abort_bash"}),onRemoveQueued:ve,thinkingWrap:((bs=s.settings)==null?void 0:bs.thinkingWrap)??!0,toolsWrap:((ks=s.settings)==null?void 0:ks.toolsWrap)??!0,jumpTarget:_,onJumpDone:()=>te(null)},s.state.conversationId??"boot"):e.jsx("div",{className:"boot-wait",children:s.ready?t("loadingSession"):t("connectingServer")}),e.jsx(xl,{send:n,goal:s.goal,models:s.models,modelsLoading:s.modelsLoading,activeConversationId:s.activeConversationId,engine:s.engine}),s.dialog&&e.jsx(Nl,{dialog:s.dialog,send:n}),s.question&&e.jsx(Cl,{question:s.question,send:n}),e.jsx(fl,{send:n,ready:s.ready,streaming:((js=s.state)==null?void 0:js.isStreaming)??!1,messages:((ws=s.state)==null?void 0:ws.messages)??to,slashCommands:s.slashCommands,modelState:we,models:s.models,modelsLoading:s.modelsLoading,providerKeys:s.providerKeys,attachments:i,onRemoveAttachment:V,onAddImageFiles:w,onAddLocalFiles:A,onNotice:c,onManageModels:ce,onSent:p})]}),!G&&e.jsx(pn,{side:"right",width:J,onResize:U}),e.jsx("div",{className:`panel-drawer drawer-right ${B==="right"?"open":""}${G?"":Y?" hidden":""}`,children:e.jsx(Ua,{collapsible:!G,onToggleCollapse:k,send:xe,files:s.files,fileChanged:s.fileChanged,widgets:s.widgets,cwd:((Ns=s.state)==null?void 0:Ns.cwd)??"",onAttach:(F,se,pe,Ne)=>{Z(null),me(F,se,pe,Ne)},onPreview:(F,se)=>{Z(null),m({path:F,name:se})},onNotice:(F,se)=>c(F,se)})}),!G&&Y&&e.jsx(mn,{side:"right",onClick:k})]}),e.jsx("div",{className:`view-pane ${x==="terminal"?"":"hidden"}`,children:e.jsx(l.Suspense,{fallback:null,children:e.jsx(Zl,{chat:s,send:n,terminal:a})})}),e.jsx("div",{className:`view-pane ${x==="git"?"":"hidden"}`,children:e.jsx(Tl,{chat:s,send:n,terminal:a,active:x==="git",onSwitchToTerminal:()=>b("terminal")})}),D.map(F=>{const se=`plugin:${F.info.id}`;return e.jsx("div",{className:`view-pane ${x===se?"":"hidden"}`,children:e.jsx(El,{entry:F,send:n})},F.info.id)})]})}),e.jsx(jl,{chat:s,send:n}),u&&e.jsx(Hl,{file:u,content:s.fileContent,send:n,onAddLines:(F,se,pe,Ne)=>me(F,se,"lines",!1,{start:pe,end:Ne}),onAttach:(F,se,pe)=>me(F,se,pe),onClose:()=>m(null)}),s.ready&&s.state&&s.state.piConfigured===!1&&!I&&!$&&e.jsx(Pl,{send:n,piConfigured:s.state.piConfigured,piAgentInstalled:s.state.piAgentInstalled,providers:s.providers,installResult:s.installResult,onClose:()=>N(!0)}),$&&e.jsx(Il,{send:n,providers:s.modelsConfig,providerStatus:s.providers,providerKeys:s.providerKeys,fetchModelsResult:s.fetchModelsResult,cloneProviderResult:s.cloneProviderResult,onClose:()=>z(!1)}),ie&&e.jsx(Al,{chat:s,send:n,terminal:a,onSwitchToTerminal:()=>b("terminal"),onClose:()=>v(!1)}),L&&e.jsx(Bl,{servers:s.bgServers,send:n,onClose:()=>d(!1)}),e.jsx($l,{open:E,send:n,projects:s.projects,cwd:((Cs=s.state)==null?void 0:Cs.cwd)??"",fileSearch:s.fileSearch,sessionSearch:s.sessionSearch,onClose:()=>h(!1),onSwitchSession:(F,se)=>{n({type:"switch_session",path:F});const pe=se&&se[0];te(pe?{path:F,role:pe.role,timestamp:pe.timestamp}:null)},onSwitchProject:F=>{n({type:"set_cwd",path:F})},onPreviewFile:(F,se)=>{m({path:F,name:se})}})]})}xa();di(ci());vi.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(ia,{children:e.jsx(so,{})})}));"serviceWorker"in navigator&&window.addEventListener("load",()=>{const t=Pn();navigator.serviceWorker.register(`${t}sw.js`,{scope:t}).catch(s=>{console.warn("Service worker registration failed:",s)})});export{rt as F,cn as T,gn as _,be as a,ro as b,He as c,ao as d,St as e,Ae as f,$i as g,tt as h,Pe as i,Ue as r,mt as u};