@rainmanhhh/pi-web 0.15.6 → 0.15.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.mjs +1 -1
- package/dist/static/assets/{CodeMirrorEditor-DuVYY3Kf.js → CodeMirrorEditor-BsodzoJM.js} +1 -1
- package/dist/static/assets/{abnfDiagram-VCTEODGH-QEvaadJP.js → abnfDiagram-VCTEODGH-Dr8_sp_I.js} +1 -1
- package/dist/static/assets/architecture-7GRP2DOG-CJuZDbHH.js +1 -0
- package/dist/static/assets/{architectureDiagram-5GKGNRK7-C2PDsdsq.js → architectureDiagram-5GKGNRK7-PrmURMnY.js} +1 -1
- package/dist/static/assets/{blockDiagram-I7D4REHJ-C5Yb1wRf.js → blockDiagram-I7D4REHJ-PBCnqhDB.js} +1 -1
- package/dist/static/assets/{c4Diagram-7LVT6UL2-DefE37pd.js → c4Diagram-7LVT6UL2-BChXC8TK.js} +1 -1
- package/dist/static/assets/channel-BKweKDiS.js +1 -0
- package/dist/static/assets/{chunk-4HAMMTFA-DqI-tkYb.js → chunk-4HAMMTFA-COC9meJx.js} +1 -1
- package/dist/static/assets/{chunk-75Z2AOVW-D209VZG7.js → chunk-75Z2AOVW-CORN0UqO.js} +1 -1
- package/dist/static/assets/{chunk-DU6HZSFF-DWCQL_Gz.js → chunk-DU6HZSFF-BwNAWU8T.js} +1 -1
- package/dist/static/assets/{chunk-F27PBJKO-C6OWYktx.js → chunk-F27PBJKO-pYLTgJTx.js} +1 -1
- package/dist/static/assets/{chunk-GMAD6QVW-2xX8HyYH.js → chunk-GMAD6QVW-Cqw9-89m.js} +1 -1
- package/dist/static/assets/{chunk-GVQU2GXP-ErYaMYVC.js → chunk-GVQU2GXP-DG5Q-_ME.js} +1 -1
- package/dist/static/assets/{chunk-IMKFNOWR-BS5O1cRy.js → chunk-IMKFNOWR-CmyNNtcd.js} +1 -1
- package/dist/static/assets/{chunk-L3NEJ4N5-BP3C5D9h.js → chunk-L3NEJ4N5-32coNd0b.js} +1 -1
- package/dist/static/assets/{chunk-OSK3NFVY-7UB4le0T.js → chunk-OSK3NFVY-C0yyTerx.js} +1 -1
- package/dist/static/assets/{chunk-P2QGCYS3-CUtfHbC7.js → chunk-P2QGCYS3-D2TnZGjh.js} +1 -1
- package/dist/static/assets/{chunk-POPQ4Y6H-BaDNCqgc.js → chunk-POPQ4Y6H-BHvArJPA.js} +1 -1
- package/dist/static/assets/{chunk-PWAF6VOD-WcTB_GKt.js → chunk-PWAF6VOD-BoiIT3Yi.js} +1 -1
- package/dist/static/assets/{chunk-SHT3W25Y-39r-apCT.js → chunk-SHT3W25Y-BuVhP2xo.js} +1 -1
- package/dist/static/assets/{chunk-SVP7TREG-0NAZXnJS.js → chunk-SVP7TREG-DKsGRdGN.js} +1 -1
- package/dist/static/assets/{chunk-TICWLB2K-DBCNi57Q.js → chunk-TICWLB2K-CP6ghlU8.js} +1 -1
- package/dist/static/assets/classDiagram-ZZMXUADV-C7gWdn5i.js +1 -0
- package/dist/static/assets/classDiagram-v2-VYDZK3BY-C7gWdn5i.js +1 -0
- package/dist/static/assets/{cynefin-OW5HDTMX-CsGjKVsX.js → cynefin-OW5HDTMX-CsMB1drO.js} +1 -1
- package/dist/static/assets/{cynefinDiagram-5FMLGOSQ-BLSoftSX.js → cynefinDiagram-5FMLGOSQ-ByhYbYYN.js} +1 -1
- package/dist/static/assets/{dagre-GXQ25YYZ-Bu8aONQz.js → dagre-GXQ25YYZ-CwnLbVWf.js} +1 -1
- package/dist/static/assets/{diagram-S7CK7UJ4-BH5IWRrR.js → diagram-S7CK7UJ4-Cj8b_clp.js} +1 -1
- package/dist/static/assets/{diagram-UQ7AKVKN-1KSBVAWy.js → diagram-UQ7AKVKN-DKPcr17v.js} +1 -1
- package/dist/static/assets/{diagram-VSXAHHWV-BwhAcHeO.js → diagram-VSXAHHWV-B-VXUjrH.js} +1 -1
- package/dist/static/assets/{diagram-VX7I27RA-DVUf9myr.js → diagram-VX7I27RA-BDVfPKqv.js} +1 -1
- package/dist/static/assets/{diagram-Z3DM3KII-DiPB2RGI.js → diagram-Z3DM3KII-YyugQwHQ.js} +1 -1
- package/dist/static/assets/{ebnfDiagram-PWID7BFC-BqjlHdWJ.js → ebnfDiagram-PWID7BFC-D633oQwi.js} +1 -1
- package/dist/static/assets/{erDiagram-RLTQ6QDP-BQjvotxd.js → erDiagram-RLTQ6QDP-BXLNCxJI.js} +1 -1
- package/dist/static/assets/eventmodeling-NTZA5JFV-kwlsA-Qn.js +1 -0
- package/dist/static/assets/flowDiagram-HODETNUW-CRAGJfeg.js +1 -0
- package/dist/static/assets/{ganttDiagram-EL5Y4UJY-BpnneQ0-.js → ganttDiagram-EL5Y4UJY-D3_AZ0YW.js} +1 -1
- package/dist/static/assets/{gitGraph-4MIJSDKK-C0TC7sHN.js → gitGraph-4MIJSDKK-De3-LT3R.js} +1 -1
- package/dist/static/assets/{gitGraphDiagram-WWUBYQGX-Dwj8vFxH.js → gitGraphDiagram-WWUBYQGX-DoxDhA_b.js} +1 -1
- package/dist/static/assets/{highlighted-body-KPVGNVTW-XY82aA4b.js → highlighted-body-KPVGNVTW-DdZUyfi_.js} +1 -1
- package/dist/static/assets/{index-CJKKj624.js → index-DDPR0x8b.js} +12 -12
- package/dist/static/assets/{info-A6RAGUB7-Da5IQbKT.js → info-A6RAGUB7-F656px0n.js} +1 -1
- package/dist/static/assets/{infoDiagram-27XIBGKW-yo3n2LW9.js → infoDiagram-27XIBGKW-CUfVAtwu.js} +1 -1
- package/dist/static/assets/{ishikawaDiagram-5VMMS53U-Dp6OdD25.js → ishikawaDiagram-5VMMS53U-CeEmZeNH.js} +1 -1
- package/dist/static/assets/{journeyDiagram-3NMN7TZE-DYjNsWw_.js → journeyDiagram-3NMN7TZE-BmBimMSP.js} +1 -1
- package/dist/static/assets/{kanban-definition-UXKFOSKX-CaWh5xbh.js → kanban-definition-UXKFOSKX-DeuR1HZC.js} +1 -1
- package/dist/static/assets/{line-DuN09USu.js → line-D7aArS-j.js} +1 -1
- package/dist/static/assets/mermaid-HWGCJPDP-BrB2pBlI.js +1 -0
- package/dist/static/assets/{mermaid-parser.core-xuNdw6Qq.js → mermaid-parser.core-CAc4Uy3T.js} +3 -3
- package/dist/static/assets/{mermaid.core-Cch8hsNv.js → mermaid.core-Ta81F5Ju.js} +4 -4
- package/dist/static/assets/{mindmap-definition-YA3MSWOX-DJh95WSV.js → mindmap-definition-YA3MSWOX-CJoFtMQy.js} +1 -1
- package/dist/static/assets/{packet-AYTQ26CC-CVwaLy2g.js → packet-AYTQ26CC-jXgJ_WXC.js} +1 -1
- package/dist/static/assets/{pegDiagram-XKGWAZYB-Cu1gzmuF.js → pegDiagram-XKGWAZYB-C5yux6xw.js} +1 -1
- package/dist/static/assets/{pie-WAS4IAKB--nEJjUUG.js → pie-WAS4IAKB-BCJq82h-.js} +1 -1
- package/dist/static/assets/{pieDiagram-E7YTZNPT-CAr7sy5B.js → pieDiagram-E7YTZNPT-BxZVUc-I.js} +1 -1
- package/dist/static/assets/{quadrantDiagram-AXDQQJYC-BO2Mo8YR.js → quadrantDiagram-AXDQQJYC-DErYBv-F.js} +1 -1
- package/dist/static/assets/{radar-RG4KPBEZ-DGwVBeC2.js → radar-RG4KPBEZ-BF5-8So9.js} +1 -1
- package/dist/static/assets/{railroad-74A4TZTK-C5Tk07hw.js → railroad-74A4TZTK-BDjogURW.js} +1 -1
- package/dist/static/assets/railroad-abnf-HS5TGJTU-DyB87-6L.js +1 -0
- package/dist/static/assets/railroad-ebnf-LZEXJU2U-CUrg2S9M.js +1 -0
- package/dist/static/assets/railroad-peg-WCYAUIDC-BYNTQnjo.js +1 -0
- package/dist/static/assets/{railroadDiagram-O6MQD6OU-DL8_slqW.js → railroadDiagram-O6MQD6OU-BgzauuHk.js} +1 -1
- package/dist/static/assets/{requirementDiagram-BXWQKSXE-BBzfqyGC.js → requirementDiagram-BXWQKSXE-E2ez9Njw.js} +1 -1
- package/dist/static/assets/{sankeyDiagram-P5KCCOFB-DQOCMDJf.js → sankeyDiagram-P5KCCOFB-DWIEoETG.js} +1 -1
- package/dist/static/assets/{sequenceDiagram-WJ2MYXX4-xCdL8iRR.js → sequenceDiagram-WJ2MYXX4-DrwtML7L.js} +1 -1
- package/dist/static/assets/{stateDiagram-D77RDMKH-CHqD-Nl-.js → stateDiagram-D77RDMKH-BlSBZvPQ.js} +1 -1
- package/dist/static/assets/stateDiagram-v2-MP3YSRHH-DeJ_f-yy.js +1 -0
- package/dist/static/assets/{swimlanes-42K2YHIH-C_eGewnw.js → swimlanes-42K2YHIH-BjYWL7FA.js} +1 -1
- package/dist/static/assets/swimlanesDiagram-VR7AAH4N-kcBdWrJY.js +8 -0
- package/dist/static/assets/{timeline-definition-24CTP7MA-DVZRfs_V.js → timeline-definition-24CTP7MA-36x5-q4s.js} +1 -1
- package/dist/static/assets/{treeView-Q6P3EWNA-CnK6dc-C.js → treeView-Q6P3EWNA-DA_S_dXb.js} +1 -1
- package/dist/static/assets/{treemap-WGGIJYW6-B2FLDMlk.js → treemap-WGGIJYW6-C0fGvYQn.js} +1 -1
- package/dist/static/assets/{vennDiagram-4TSXK5OY-BYYAwPfU.js → vennDiagram-4TSXK5OY-5qW7nCEM.js} +1 -1
- package/dist/static/assets/{wardley-WFR3VGLG-DFcs6dEA.js → wardley-WFR3VGLG-Xb0bOGpc.js} +1 -1
- package/dist/static/assets/{wardleyDiagram-VM6X3IG4-BbImL2w1.js → wardleyDiagram-VM6X3IG4-CTj9hbq8.js} +1 -1
- package/dist/static/assets/{xychartDiagram-S5SC5T6Z-DYSaDw_I.js → xychartDiagram-S5SC5T6Z-BAFQXJA0.js} +1 -1
- package/dist/static/index.html +1 -1
- package/package.json +1 -1
- package/dist/static/assets/architecture-7GRP2DOG-DOZm5N90.js +0 -1
- package/dist/static/assets/channel-BLN9kfIL.js +0 -1
- package/dist/static/assets/classDiagram-ZZMXUADV-kyt7GjQn.js +0 -1
- package/dist/static/assets/classDiagram-v2-VYDZK3BY-kyt7GjQn.js +0 -1
- package/dist/static/assets/eventmodeling-NTZA5JFV-rrugcW-V.js +0 -1
- package/dist/static/assets/flowDiagram-HODETNUW-C_-QEhd3.js +0 -1
- package/dist/static/assets/mermaid-HWGCJPDP-dkMjtjsB.js +0 -1
- package/dist/static/assets/railroad-abnf-HS5TGJTU-AEllPRN6.js +0 -1
- package/dist/static/assets/railroad-ebnf-LZEXJU2U-CQ01VYtX.js +0 -1
- package/dist/static/assets/railroad-peg-WCYAUIDC-UahViuE_.js +0 -1
- package/dist/static/assets/stateDiagram-v2-MP3YSRHH-B46jLy-y.js +0 -1
- package/dist/static/assets/swimlanesDiagram-VR7AAH4N-Dla2wAk-.js +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/highlighted-body-KPVGNVTW-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/highlighted-body-KPVGNVTW-DdZUyfi_.js","assets/rolldown-runtime-hePW80VL.js","assets/mermaid.core-Ta81F5Ju.js","assets/chunk-75Z2AOVW-CORN0UqO.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-B6xuSHsQ.js","assets/chunk-DU6HZSFF-BwNAWU8T.js","assets/dist-v5Q1xZ2K.js","assets/chunk-PWAF6VOD-BoiIT3Yi.js","assets/chunk-GMAD6QVW-Cqw9-89m.js","assets/chunk-P2QGCYS3-D2TnZGjh.js","assets/chunk-4HAMMTFA-COC9meJx.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-GVQU2GXP-DG5Q-_ME.js","assets/chunk-OSK3NFVY-C0yyTerx.js","assets/line-D7aArS-j.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/graphlib-DS17s2tU.js","assets/chunk-L3NEJ4N5-32coNd0b.js","assets/CodeMirrorEditor-BsodzoJM.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{n as e,r as t,t as n}from"./rolldown-runtime-hePW80VL.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var r=n((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ee(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var F=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},I={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=I,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:ee}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,F)}catch(e){F(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.8`})),i=n(((e,t)=>{t.exports=r()})),a=n((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),o=n(((e,t)=>{t.exports=a()})),s=n((e=>{var t=i();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var a={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return s(e,t,null,r)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)}},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.2.8`})),c=n(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=s()})),l=n((e=>{var t=o(),n=i(),r=c();function a(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function s(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function l(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function u(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function d(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function f(e){if(l(e)!==e)throw Error(a(188))}function p(e){var t=e.alternate;if(!t){if(t=l(e),t===null)throw Error(a(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var o=i.alternate;if(o===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===o.child){for(o=i.child;o;){if(o===n)return f(i),e;if(o===r)return f(i),t;o=o.sibling}throw Error(a(188))}if(n.return!==r.return)n=i,r=o;else{for(var s=!1,c=i.child;c;){if(c===n){s=!0,n=i,r=o;break}if(c===r){s=!0,r=i,n=o;break}c=c.sibling}if(!s){for(c=o.child;c;){if(c===n){s=!0,n=o,r=i;break}if(c===r){s=!0,r=o,n=i;break}c=c.sibling}if(!s)throw Error(a(189))}}if(n.alternate!==r)throw Error(a(190))}if(n.tag!==3)throw Error(a(188));return n.stateNode.current===n?e:t}function m(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=m(e),t!==null)return t;e=e.sibling}return null}var h=Object.assign,g=Symbol.for(`react.element`),_=Symbol.for(`react.transitional.element`),v=Symbol.for(`react.portal`),y=Symbol.for(`react.fragment`),b=Symbol.for(`react.strict_mode`),x=Symbol.for(`react.profiler`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),k=Symbol.for(`react.activity`),A=Symbol.for(`react.memo_cache_sentinel`),j=Symbol.iterator;function M(e){return typeof e!=`object`||!e?null:(e=j&&e[j]||e[`@@iterator`],typeof e==`function`?e:null)}var N=Symbol.for(`react.client.reference`);function P(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===N?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case y:return`Fragment`;case x:return`Profiler`;case b:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case k:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case v:return`Portal`;case C:return e.displayName||`Context`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?P(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return P(e(t))}catch{}}return null}var ee=Array.isArray,F=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te={pending:!1,data:null,method:null,action:null},ne=[],re=-1;function ie(e){return{current:e}}function ae(e){0>re||(e.current=ne[re],ne[re]=null,re--)}function L(e,t){re++,ne[re]=e.current,e.current=t}var R=ie(null),oe=ie(null),z=ie(null),se=ie(null);function ce(e,t){switch(L(z,t),L(oe,e),L(R,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?tf(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=tf(t),e=nf(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ae(R),L(R,e)}function le(){ae(R),ae(oe),ae(z)}function ue(e){e.memoizedState!==null&&L(se,e);var t=R.current,n=nf(t,e.type);t!==n&&(L(oe,e),L(R,n))}function de(e){oe.current===e&&(ae(R),ae(oe)),se.current===e&&(ae(se),fp._currentValue=te)}var fe,pe;function me(e){if(fe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);fe=t&&t[1]||``,pe=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+fe+e+pe}var he=!1;function ge(e,t){if(!e||he)return``;he=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
@@ -345,12 +345,12 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
345
345
|
`:`
|
|
346
346
|
`,n=e.split(/\r?\n/),r=[],i=null,a=0,o=null;for(let e=0;e<n.length;e++){let t=n[e];if(o){r.push(t),RegExp(`</${o}\\s*>`,`i`).test(t)&&(o=null);continue}let s=t.match(/^ {0,3}(`{3,}|~{3,})/);if(s){let e=s[1][0],n=s[1].length;i?e===i.marker&&n>=i.size&&(i=null):i={marker:e,size:n},a=0,r.push(t);continue}if(i){r.push(t);continue}let c=t.match(/<(code|pre|script|style)\b/i);if(c){let e=c[1].toLowerCase(),n=t.slice((c.index??0)+c[0].length);RegExp(`</${e}\\s*>`,`i`).test(n)||(o=e),a=0,r.push(t);continue}if(/^(?: {4}|\t)/.test(t)||t.trim()===``){a=0,r.push(t);continue}if(a||t.includes("`")){a=oG(t,a),r.push(t);continue}let l=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(l){let e=l[2].trim();if(e){r.push(`${l[1]}$$`,e,`${l[1]}$$`);continue}}let u=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(u){let t=aG(n,e+1);if(t!==-1){r.push(`${u[1]}$$`,...n.slice(e+1,t),`${u[1]}$$`),e=t;continue}}let d=t.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(d){let e=d[2].trim();if(e){r.push(`${d[1]}$$`,e,`${d[1]}$$`);continue}}r.push(sG(t))}return r.join(t)}function aG(e,t){for(let n=t;n<e.length;n++){let t=e[n];if(/^ {0,3}\\\][ \t]*$/.test(t))return n;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))return-1}return-1}function oG(e,t){let n=t;for(let t=0;t<e.length;){if(e[t]!=="`"){t++;continue}let r=t+1;for(;e[r]==="`";)r++;let i=r-t;n===0?n=i:i===n&&(n=0),t=r}return n}function sG(e){return/^\s{0,3}\[[^\]]+\]:/.test(e)||/]\s*\(/.test(e)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(e)||/\b(?:https?|file|mailto):/i.test(e)||/\b[A-Za-z]:\\/.test(e)?e:e.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)}var cG=[WW,nG],lG=[WW,nG],uG=[TV,[WV,rG],[BI,{throwOnError:!1,strict:!1}]],dG=[TV,[WV,rG],[BI,{throwOnError:!1,strict:!1}]];function fG(e){return/^[!+-].+/.test(e.trim())}function pG(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith(`\\\\`)?e.replace(/\\/g,`/`):e}function mG(e){return pG(e).split(`/`).filter(Boolean).map(encodeURIComponent).join(`/`)}function hG(e){let t=pG(e).replace(/\/+$/,``);return t.split(`/`).pop()??t}function gG(e){let t=pG(e).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n<0?``:n===0?`/`:n===2&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,n)}function _G(e,t){if(!t)return e;let n=pG(e),r=pG(t).replace(/\/$/,``);return n.startsWith(`${r}/`)?n.slice(r.length+1):e}function vG(e,t){return`${pG(e).replace(/\/$/,``)}/${t}`}function yG({className:e,type:t,...n}){return(0,E.jsx)(`input`,{type:t,"data-slot":`input`,className:sh(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...n})}async function bG(e){let t=e?`?path=${encodeURIComponent(e)}`:``,n=await fetch(`/api/cwd/browse${t}`),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return r}var xG={backgroundColor:`#ffffff`,color:`#0f1115`};function SG(){return(0,E.jsx)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M1.5 3h4l1.5 2h7.5v7.5h-13z`})})}function CG(){return(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.5`}),(0,E.jsx)(`path`,{d:`M2 9h12`}),(0,E.jsx)(`circle`,{cx:`11.5`,cy:`11`,r:`0.6`,fill:`currentColor`,stroke:`none`})]})}function wG(e){return/^[a-zA-Z]:[\\/]?$/.test(e)}function TG(){return(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M4 1.5h5l3 3v10h-8z`}),(0,E.jsx)(`path`,{d:`M9 1.5v3h3`})]})}function EG(e){return e.replace(/\\/g,`/`)}function DG({open:e,onCancel:t,onConfirm:n,title:r,confirmText:i,cancelText:a,noteLabel:o,notePlaceholder:s,busy:c=!1,error:l,showFiles:u=!0,showExtensionFilter:f=!1,extensionOptions:m=[],initialPath:h}){let{t:g}=N(),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(``),[C,w]=(0,d.useState)([]),[T,D]=(0,d.useState)([]),[O,k]=(0,d.useState)(null),[A,j]=(0,d.useState)(null),[M,P]=(0,d.useState)(``),[ee,F]=(0,d.useState)(``),[I,te]=(0,d.useState)(``),[ne,re]=(0,d.useState)(null),[ie,ae]=(0,d.useState)(!0),L=(0,d.useRef)(null),R=(0,d.useCallback)(async e=>{ae(!0),re(null);try{let t=await bG(e),n=EG(t.path??e??`/`);v(n),b(t.parentPath?EG(t.parentPath):null),S(n),w((t.directories??[]).map(e=>({...e,path:EG(e.path)}))),D((t.files??[]).map(e=>({...e,path:EG(e.path)}))),k(t.drives??null),j(null),F(``),te(``)}catch(e){re(e instanceof Error?e.message:String(e))}finally{ae(!1)}},[]);(0,d.useEffect)(()=>{e&&(P(``),R(h))},[e,R,h]);let oe=e=>{e.preventDefault();let t=EG(x.trim());t&&R(t)},z=!!y||wG(_),se=ee.trim().toLowerCase(),ce=e=>!se||e.toLowerCase().includes(se),le=O===null?[]:O.filter(e=>ce(e.name)||ce(e.path)),ue=C.filter(e=>ce(e.name)),de=u?T.filter(e=>ce(e.name)).filter(e=>!I||e.name.toLowerCase().endsWith(I.toLowerCase())):[],fe=!!A&&!c;return(0,E.jsx)(jS,{open:e,onOpenChange:e=>{!e&&!c&&t()},children:(0,E.jsxs)(FS,{className:`directory-picker-light flex w-[520px] max-w-[calc(100vw-16px)] flex-col gap-0 overflow-hidden p-0`,style:{height:`min(620px, calc(100dvh - 16px))`},showCloseButton:!1,onPointerDownOutside:e=>{c&&e.preventDefault()},onEscapeKeyDown:e=>{c&&e.preventDefault()},onOpenAutoFocus:e=>{e.preventDefault(),L.current?.focus()},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,flexShrink:0,padding:`12px 18px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(IS,{style:{fontWeight:700,fontSize:`var(--text-2xl)`,color:`var(--text)`},children:r}),(0,E.jsx)(NS,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,disabled:c,title:g(`i18n.close`),"aria-label":g(`i18n.close`),style:{padding:`2px 6px`,border:0,background:`none`,color:`var(--text-muted)`,fontSize:`var(--text-5xl)`,lineHeight:1,cursor:c?`default`:`pointer`,opacity:c?.5:1},children:`×`})})]}),o&&(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,flexShrink:0,padding:`10px 14px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`label`,{htmlFor:`file-picker-note`,style:{fontSize:`var(--text-sm)`,color:`var(--text-muted)`,whiteSpace:`nowrap`},children:o}),(0,E.jsx)(yG,{id:`file-picker-note`,className:`h-9 flex-1 bg-bg-panel`,type:`text`,value:M,placeholder:s,autoComplete:`off`,style:xG,onChange:e=>P(e.target.value)})]}),(0,E.jsxs)(`form`,{onSubmit:oe,style:{display:`flex`,alignItems:`center`,gap:8,flexShrink:0,padding:`10px 14px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>void R(y??void 0),disabled:ie||!z,title:g(`directoryPicker.goToParent`),"aria-label":g(`directoryPicker.goToParent`),style:{width:36,height:36,padding:0,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`1px solid var(--border)`,borderRadius:6,background:xG.backgroundColor,color:`var(--text-muted)`,cursor:z?`pointer`:`default`,opacity:z?1:.45},children:(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m18 15-6-6-6 6`})})}),(0,E.jsx)(`label`,{htmlFor:`file-picker-path`,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:g(`directoryPicker.directoryPath`)}),(0,E.jsx)(yG,{className:`h-9 flex-1 font-mono text-xs bg-bg-panel`,id:`file-picker-path`,type:`text`,ref:L,value:x,placeholder:`/path/to/folder or ~/folder`,autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>{S(EG(e.target.value)),re(null)}}),(0,E.jsx)(`button`,{type:`submit`,disabled:ie||!x.trim(),title:g(`directoryPicker.goToDirectory`),style:{minWidth:58,height:36,padding:`0 12px`,border:`1px solid var(--border)`,borderRadius:6,background:xG.backgroundColor,color:`var(--text-muted)`,cursor:ie||!x.trim()?`default`:`pointer`,opacity:ie||!x.trim()?.6:1},children:g(`directoryPicker.go`)})]}),(0,E.jsxs)(`div`,{className:`directory-picker-list`,style:{flex:1,minHeight:0,overflow:`auto`,padding:`8px 10px`},children:[ie?(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:g(`directoryPicker.loadingDirectories`)}):O===null?ue.length>0||de.length>0?(0,E.jsxs)(E.Fragment,{children:[ue.map(e=>(0,E.jsxs)(`button`,{type:`button`,onClick:()=>void R(e.path),title:e.path,style:{width:`100%`,minHeight:30,display:`flex`,alignItems:`center`,gap:7,padding:`5px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(SG,{}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)),de.map(e=>{let t=A===e.path;return(0,E.jsxs)(`button`,{type:`button`,onClick:()=>j(e.path),title:e.path,style:{width:`100%`,minHeight:30,display:`flex`,alignItems:`center`,gap:7,padding:`5px 8px`,border:0,borderRadius:5,background:t?`color-mix(in srgb, var(--accent) 14%, transparent)`:`none`,color:t?`var(--accent)`:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(TG,{}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)})]}):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:g(se?`directoryPicker.noMatches`:u?`i18n.noFiles`:`directoryPicker.noSubdirectories`)}):le.length>0?le.map(e=>(0,E.jsxs)(`button`,{type:`button`,onClick:()=>void R(e.path),title:e.path,style:{width:`100%`,minHeight:34,display:`flex`,alignItems:`center`,gap:7,padding:`6px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(CG,{}),(0,E.jsx)(`span`,{children:e.name})]},e.path)):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:g(se?`directoryPicker.noMatches`:`directoryPicker.noDrives`)}),(ne||l)&&(0,E.jsx)(`div`,{style:{padding:`8px`,color:`var(--status-error)`,fontSize:`var(--text-sm)`},children:ne??l})]}),(0,E.jsxs)(`div`,{className:`directory-picker-footer`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:10,flexShrink:0,padding:`10px 18px`,borderTop:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flex:1,minWidth:0},children:[f&&m.length>0&&(0,E.jsxs)(`select`,{value:I,onChange:e=>te(e.target.value),"aria-label":g(`i18n.filterByType`),style:{flexShrink:0,height:32,padding:`0 6px`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`,color:`var(--text)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(`option`,{value:``,children:g(`i18n.allFiles`)}),m.map(e=>(0,E.jsx)(`option`,{value:e,children:e},e))]}),(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`var(--text-dim)`,flexShrink:0},children:[(0,E.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,E.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),(0,E.jsx)(yG,{className:`directory-picker-search h-8 flex-1 bg-bg-panel`,type:`text`,value:ee,placeholder:g(`directoryPicker.search`),"aria-label":g(`directoryPicker.search`),autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>F(e.target.value)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexShrink:0},children:[(0,E.jsx)(`button`,{type:`button`,onClick:t,disabled:c,style:{padding:`6px 14px`,border:`1px solid var(--border)`,borderRadius:6,background:`none`,color:`var(--text-muted)`,cursor:c?`default`:`pointer`,fontSize:`var(--text-lg)`},children:a??g(`i18n.cancel`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>A&&n(A,M.trim()),disabled:!fe,title:A?void 0:g(`i18n.selectFile`),style:{padding:`6px 16px`,border:0,borderRadius:6,background:`var(--accent)`,color:`var(--on-accent)`,fontSize:`var(--text-lg)`,fontWeight:600,opacity:fe?1:.6,cursor:fe?`pointer`:`default`},children:c?g(`i18n.checking`):A?`${i}: ${hG(A)}`:i})]})]})]})})}var OG={display:`inline-flex`,alignItems:`center`,gap:4,maxWidth:220,padding:`4px 10px`,borderRadius:12,border:`1px solid var(--accent)`,background:`color-mix(in srgb, var(--accent) 12%, transparent)`,color:`var(--accent)`,fontSize:`var(--text-sm)`,overflow:`hidden`,whiteSpace:`nowrap`,textOverflow:`ellipsis`},kG={minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`};function AG({label:e,onClick:t,onRemove:n,title:r,removeLabel:i,testId:a}){return n?(0,E.jsxs)(`span`,{"data-testid":a,title:r,style:OG,children:[(0,E.jsx)(`button`,{type:`button`,title:r,onClick:t,style:{...kG,flex:1,background:`none`,border:`none`,color:`inherit`,font:`inherit`,padding:0,textAlign:`left`,cursor:t?`pointer`:`default`},children:e}),(0,E.jsx)(`button`,{type:`button`,"aria-label":i??r??`remove`,onClick:n,style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,marginLeft:`auto`,padding:2,borderRadius:4,color:`inherit`,background:`none`,border:`none`,cursor:`pointer`,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.sm})})]}):(0,E.jsx)(`button`,{type:`button`,"data-testid":a,title:r,onClick:t,style:{...OG,font:`inherit`,textAlign:`left`,cursor:t?`pointer`:`default`},children:(0,E.jsx)(`span`,{style:kG,children:e})})}function jG(e){try{return decodeURIComponent(e)}catch{return e}}function MG(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith(`\\\\`)?e.replace(/\\/g,`/`):e}function NG(e){return e.replace(/:\d+(?::\d+)?$/,``)}function PG(e){let t=MG(e),n=/^[a-zA-Z]:\//.test(t),r=t.startsWith(`//`),i=t.startsWith(`/`)&&!n&&!r,a=[];for(let e of t.split(`/`))if(!(!e||e===`.`)){if(e===`..`){a.length>0&&a[a.length-1]!==`..`?a.pop():!i&&!n&&!r&&a.push(e);continue}a.push(e)}let o=a.join(`/`);return n?o:r?`//${o}`:i?`/${o}`:o}function FG(e,t){let n=PG(e).replace(/\/+$/,``),r=PG(t).replace(/\/+$/,``),i=/^[a-zA-Z]:\//.test(n)||/^[a-zA-Z]:\//.test(r),a=i?n.toLowerCase():n,o=i?r.toLowerCase():r;return a===o||a.startsWith(`${o}/`)}function IG(e){return e.startsWith(`#`)||e.startsWith(`?`)?!1:e.startsWith(`./`)||e.startsWith(`../`)||e.includes(`/`)?!0:/(^|\/)\.?[^/]+\.[^/.]+$/.test(e)}function LG(e){try{let t=new URL(e);if(t.protocol!==`file:`)return null;let n=jG(t.pathname);return t.hostname?`//${t.hostname}${n.startsWith(`/`)?n:`/${n}`}`:/^\/[a-zA-Z]:\//.test(n)?n.slice(1):n}catch{return null}}function RG(e,t,n=t){if(!e)return null;let r=e.split(`#`,1)[0].split(`?`,1)[0].trim();if(!r)return null;let i=null,a=null,o=jG(r),s=o.startsWith(`\\\\`),c=MG(o),l=c.toLowerCase();if(l.startsWith(`/api/`)||l.startsWith(`/_next/`)||!s&&c.startsWith(`//`)||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(c)&&!l.startsWith(`file:`)&&!/^[a-zA-Z]:\//.test(c)||(l.startsWith(`file:`)?(i=LG(c),a=i?`absolute`:null):/^[a-zA-Z]:\//.test(c)||c.startsWith(`/`)?(i=c,a=`absolute`):t&&IG(c)&&(i=`${MG(t).replace(/\/+$/,``)}/${c}`,a=`relative`),!i))return null;let u=NG(PG(i));return a===`relative`&&n&&!FG(u,n)?null:u}function zG(e,t){if(!e)return{kind:`external`};let n=e.split(`#`,1)[0].split(`?`,1)[0].trim();if(!n||n.startsWith(`#`)||n.startsWith(`?`))return{kind:`external`};let r=jG(n);if(r.startsWith(`\\\\`))return{kind:`unsafe`};let i=MG(r);if(/^[a-zA-Z]:[\\/]/.test(i))return{kind:`unsafe`};if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(i)||i.startsWith(`//`))return{kind:`external`};if(i.startsWith(`/`))return{kind:`unsafe`};let a=PG(`${MG(t).replace(/\/+$/,``)}/${i}`);return FG(a,t)?{kind:`safe`,path:NG(a)}:{kind:`unsafe`}}function BG({href:e,markdownDir:t,onOpenFile:n,children:r,...i}){let{t:a}=N();if(!e||!n)return(0,E.jsx)(`a`,{href:e,...i,children:r});let o=zG(e,t),s=t=>{t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||(o.kind===`safe`?(t.preventDefault(),n(o.path)):o.kind===`unsafe`&&(t.preventDefault(),window.alert(a(`i18n.unsafeLinkBlocked`,{href:e}))))};return o.kind===`external`?(0,E.jsx)(`a`,{href:e,...i,target:`_blank`,rel:`noopener noreferrer`,children:r}):(0,E.jsx)(`a`,{href:e,...i,onClick:s,children:r})}var VG={install:12e4,update:12e4,remove:3e4,disable:15e3,enable:15e3,addExtensionFilter:15e3,removeExtensionFilter:15e3};function HG(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,`~`)}var UG=`package`,WG=null,GG=null;function KG(e){return e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/)?.[1]??e}function qG(e){return`${e.scope}\0${e.source}`}function JG(e){return`${e.scope}\0${e.pattern}`}function YG(e,t){if(e.disabled)return t(`i18n.disabled`);let n=e.version||e.configuredVersion;return[n?`${t(`i18n.versionShort`)}:${n}`:``,`${t(`i18n.extensionShort`)}:${e.counts.extensions}`,`${t(`i18n.skillShort`)}:${e.counts.skills}`].filter(Boolean).join(` `)}function XG(e,t){let n=[];return e.version&&n.push(t(`i18n.installedVersion`,{version:e.version})),e.configuredVersion&&n.push(t(`i18n.configuredVersion`,{version:e.configuredVersion})),n.length?n.join(` · `):t(`i18n.unknown`)}function ZG(e,t){return e===`project`?`${HG(t)}/.pi/agent/{npm,git}`:`~/.pi/agent/{npm,git}`}function QG(e,t,n){let r=t.trim(),i=r.startsWith(`npm:`)?r.slice(4):r;return e.find(e=>e.scope===n&&e.source===r)??e.find(e=>e.scope===n&&e.source===`npm:${i}`)??e.find(e=>e.scope===n&&e.source.endsWith(r))}function $G(e){let t=e[0];return t===`!`?`var(--status-error)`:t===`+`?`var(--status-success)`:`var(--text-dim)`}function eK(e,t){let n=e[0];return t(n===`!`?`plugins.filterPrefixExclude`:n===`+`?`plugins.filterPrefixForceInclude`:`plugins.filterPrefixForceExclude`)}function tK(e){return e===`loaded`?`var(--accent)`:e===`installed`?`var(--status-warning)`:e===`disabled`?`var(--text-dim)`:`var(--status-error)`}function nK(e,t){switch(e){case`loaded`:return t(`plugins.statusLoaded`);case`installed`:return t(`plugins.statusInstalled`);case`disabled`:return t(`plugins.statusDisabled`);default:return t(`plugins.statusMissing`)}}function rK({pkg:e}){let{t}=N(),n=[[`extension`,t(`i18n.extensions`)],[`skill`,t(`i18n.skills`)],[`prompt`,t(`i18n.prompts`)],[`theme`,t(`i18n.themes`)]].map(([t,n])=>({kind:t,label:n,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return n.length===0?(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-dim)`},children:e.disabled?t(`i18n.packageDisabled`):t(`i18n.noResolvedResources`)}):(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:n.map((e,t)=>(0,E.jsxs)(`div`,{style:{borderTop:t===0?`none`:`1px solid var(--border)`,paddingTop:t===0?0:12},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xs)`,fontWeight:700,color:`var(--text-dim)`,textTransform:`uppercase`,marginBottom:6},children:e.label}),(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:e.resources.map(e=>(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.path,children:e.name}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function iK({scope:e}){return(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 5px`,borderRadius:3,flexShrink:0,background:e===`project`?`color-mix(in srgb, var(--status-info) 12%, transparent)`:`color-mix(in srgb, var(--text-dim) 12%, transparent)`,color:e===`project`?`color-mix(in srgb, var(--status-info) 85%, transparent)`:`var(--text-dim)`},children:e})}function aK(e,t){return{padding:`6px 12px`,background:t?`color-mix(in srgb, var(--status-error) 8%, transparent)`:`none`,border:`1px solid var(--border)`,borderRadius:6,color:t?`var(--status-error)`:`var(--text-muted)`,cursor:e?`not-allowed`:`pointer`,fontSize:`var(--text-base)`,opacity:e?.5:1}}function oK({enabled:e,loading:t,onToggle:n,label:r,testId:i}){return(0,E.jsx)(`button`,{type:`button`,"data-testid":i,onClick:n,disabled:t,title:r,"aria-label":r,"aria-pressed":e,style:{flexShrink:0,width:40,height:22,borderRadius:11,border:`none`,padding:0,cursor:t?`wait`:`pointer`,background:e?`var(--accent)`:`var(--border)`,position:`relative`,transition:`background 0.18s`,outline:`none`,opacity:t?.65:1},children:(0,E.jsx)(`span`,{style:{position:`absolute`,top:3,left:e?21:3,width:16,height:16,borderRadius:`50%`,background:`var(--bg)`,boxShadow:`0 1px 4px var(--shadow-color)`,transition:`left 0.18s cubic-bezier(.4,0,.2,1)`}})})}function sK({value:e,projectResourcesLoaded:t,onChange:n}){let{t:r}=N();return(0,E.jsx)(XS,{value:e,onChange:n,options:[`global`,`project`].map(e=>({value:e,label:e,disabled:e===`project`&&!t,title:e===`project`&&!t?r(`trust.projectScopeUnavailable`):void 0}))})}function cK(e){return{width:`100%`,height:36,padding:`0 11px`,border:`1px solid ${e}`,borderRadius:6,background:`var(--bg-input)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,outline:`none`}}function lK({examples:e,onPick:t}){return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:7},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text-muted)`},children:`Examples`}),(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:e.map(e=>(0,E.jsx)(`button`,{type:`button`,onClick:()=>t(e),style:{width:`100%`,minHeight:30,textAlign:`left`,padding:`6px 9px`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`,color:`var(--text-dim)`,cursor:`pointer`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,"--hover-color":`var(--text-muted)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:e},e))})]})}function uK({scope:e,projectResourcesLoaded:t,onScopeChange:n,actionBusy:r,actionDisabled:i,actionLabel:a,onAction:o,actionTestId:s}){let{t:c}=N();return(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexWrap:`wrap`},children:[(0,E.jsx)(sK,{value:e,projectResourcesLoaded:t,onChange:n}),(0,E.jsx)(`button`,{type:`button`,"data-testid":s,onClick:o,disabled:i,style:{...aK(i),background:`var(--accent)`,color:`var(--on-accent)`,borderColor:`var(--accent)`},children:r?c(`i18n.installing`):a})]})}var dK=`/recommended-plugins.json`;function fK({packages:e,onPick:t}){let{t:n,locale:r}=N(),[i,a]=(0,d.useState)([]);if((0,d.useEffect)(()=>{fetch(dK).then(e=>e.json()).then(e=>{Array.isArray(e)&&a(e)}).catch(e=>console.error(`[pi-web] load recommended plugins:`,e))},[]),i.length===0)return null;let o=r===`zh-CN`?`zh`:`en`;return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:7},children:[(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text-muted)`,display:`flex`,alignItems:`center`,gap:6},children:[(0,E.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:`var(--accent)`},children:[(0,E.jsx)(`path`,{d:`M12 2L2 7l10 5 10-5-10-5z`}),(0,E.jsx)(`path`,{d:`M2 17l10 5 10-5`}),(0,E.jsx)(`path`,{d:`M2 12l10 5 10-5`})]}),n(`i18n.recommendedPlugins`)]}),(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:i.map(r=>{let i=e.some(e=>e.source===r.source||e.source===`npm:${r.source.replace(/^npm:/,``)}`||e.source.endsWith(r.source.replace(/^npm:/,``))),a=typeof r.name==`object`?r.name[o]??r.name.en:r.name,s=typeof r.description==`object`?r.description[o]??r.description.en:r.description;return(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`},children:[(0,E.jsxs)(`div`,{style:{minWidth:0,flex:1},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:a}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:s})]}),i?(0,E.jsx)(`span`,{style:{fontSize:`var(--text-sm)`,color:`var(--status-success)`,whiteSpace:`nowrap`,flexShrink:0,display:`inline-flex`,alignItems:`center`,gap:4},children:n(`i18n.installed`)}):(0,E.jsx)(`button`,{type:`button`,onClick:()=>t(r.source),className:`hover-shift`,style:{flexShrink:0,padding:`5px 12px`,border:`1px solid var(--accent)`,borderRadius:6,background:`transparent`,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:n(`i18n.install`)})]},r.source)})})]})}function pK({cwd:e,source:t,scope:n,projectResourcesLoaded:r,busy:i,actionError:a,packages:o,onSourceChange:s,onScopeChange:c,onInstall:l}){let{t:u}=N(),f=(0,d.useRef)(null);return(0,d.useEffect)(()=>{f.current?.focus()},[]),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:18,maxWidth:660,minHeight:`100%`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:5},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,fontWeight:700,color:`var(--text)`},children:u(`i18n.addPlugin`)}),(0,E.jsxs)(`a`,{href:`https://pi.dev/packages`,target:`_blank`,rel:`noopener noreferrer`,style:{display:`inline-flex`,alignItems:`center`,gap:5,color:`var(--accent)`,fontSize:`var(--text-base)`,textDecoration:`none`,whiteSpace:`nowrap`},children:[(0,E.jsxs)(`svg`,{width:`28`,height:`28`,viewBox:`0 0 800 800`,"aria-hidden":`true`,focusable:`false`,style:{flexShrink:0},children:[(0,E.jsx)(`path`,{fill:`#000`,fillRule:`evenodd`,d:`M165.29 165.29H517.36V400H400V517.36H282.65V634.72H165.29ZM282.65 282.65V400H400V282.65Z`}),(0,E.jsx)(`path`,{fill:`#000`,d:`M517.36 400H634.72V634.72H517.36Z`})]}),`pi.dev/packages`]})]}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-dim)`,fontFamily:`var(--font-mono)`},children:ZG(n,e)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:7},children:[(0,E.jsx)(`label`,{htmlFor:`plugin-source`,style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text-muted)`},children:`Source`}),(0,E.jsx)(qi,{label:(0,E.jsxs)(`span`,{style:{display:`flex`,flexDirection:`column`,gap:2,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,lineHeight:1.5},children:[(0,E.jsx)(`span`,{children:`npm:@scope/package`}),(0,E.jsx)(`span`,{children:`git:https://github.com/user/repo`}),(0,E.jsx)(`span`,{children:`/absolute/path/to/plugin`})]}),children:(0,E.jsx)(`input`,{id:`plugin-source`,ref:f,value:t,onChange:e=>s(e.target.value),onPaste:e=>{let t=e.clipboardData.getData(`text`),n=KG(t);n!==t&&(e.preventDefault(),s(n))},onBlur:e=>s(KG(e.currentTarget.value)),placeholder:u(`plugins.npmSourcePlaceholder`),style:cK(`var(--border)`),onKeyDown:e=>{e.key===`Enter`&&t.trim()&&!i&&l()}})})]}),(0,E.jsx)(uK,{scope:n,projectResourcesLoaded:r,onScopeChange:c,actionBusy:i,actionDisabled:i||!t.trim(),actionLabel:u(`i18n.install`),onAction:l}),(0,E.jsx)(fK,{packages:o,onPick:s}),a&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,whiteSpace:`pre-wrap`},children:a})]})}function mK({pattern:e,scope:t,projectResourcesLoaded:n,busy:r,actionError:i,onPatternChange:a,onScopeChange:o,onAdd:s}){let{t:c}=N(),l=(0,d.useRef)(null),u=e.trim(),f=u.length>0&&!fG(u);return(0,d.useEffect)(()=>{l.current?.focus()},[]),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:18,maxWidth:660,minHeight:`100%`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:5},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,fontWeight:700,color:`var(--text)`},children:c(`plugins.addFilter`)}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-dim)`,lineHeight:1.5},children:c(`plugins.extensionFiltersHint`)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:7},children:[(0,E.jsx)(`label`,{htmlFor:`extension-filter-pattern`,style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text-muted)`},children:c(`plugins.filterPatternLabel`)}),(0,E.jsx)(`input`,{id:`extension-filter-pattern`,"data-testid":`extension-filter-pattern`,ref:l,value:e,onChange:e=>a(e.target.value),placeholder:c(`plugins.filterPlaceholder`),style:cK(f?`var(--status-error)`:`var(--border)`),onKeyDown:e=>{e.key===`Enter`&&u&&!f&&!r&&s()}}),f&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--status-error)`},children:c(`plugins.filterInvalid`)})]}),(0,E.jsx)(uK,{scope:t,projectResourcesLoaded:n,onScopeChange:o,actionBusy:r,actionDisabled:r||!u||f,actionLabel:c(`plugins.addFilter`),onAction:s,actionTestId:`extension-filter-add`}),(0,E.jsx)(lK,{examples:[`!**/*.test.ts`,`+./my-ext.ts`,`-./legacy-ext.ts`],onPick:a}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:4},children:[(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,lineHeight:1.6},children:[(0,E.jsx)(`span`,{style:{color:`var(--status-error)`,fontWeight:700},children:`!`}),` `,c(`plugins.filterPrefixExclude`)]}),(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,lineHeight:1.6},children:[(0,E.jsx)(`span`,{style:{color:`var(--status-success)`,fontWeight:700},children:`+`}),` `,c(`plugins.filterPrefixForceInclude`)]}),(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,lineHeight:1.6},children:[(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`,fontWeight:700},children:`-`}),` `,c(`plugins.filterPrefixForceExclude`)]})]}),i&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,whiteSpace:`pre-wrap`},children:i})]})}function hK({filter:e,busyKey:t,actionError:n,actionMessage:r,onRemove:i}){let{t:a}=N(),o=JG(e),s=t?.endsWith(o)??!1;return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,gap:12,minWidth:0,flexWrap:`wrap`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,minWidth:180,flex:1},children:[(0,E.jsx)(iK,{scope:e.scope}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.pattern})]}),(0,E.jsx)(`button`,{"data-testid":`extension-filter-remove`,onClick:()=>i(e),disabled:s,style:aK(s,!0),children:a(s?`i18n.removing`:`plugins.removeFilter`)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:700,color:`var(--text)`},children:a(`plugins.filterEffect`)}),(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,lineHeight:1.55},children:[(0,E.jsx)(`span`,{style:{color:$G(e.pattern),fontWeight:700,fontFamily:`var(--font-mono)`},children:e.pattern[0]}),` `,eK(e.pattern,a)]}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,lineHeight:1.5},children:a(`plugins.extensionFiltersHint`)})]}),r&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-success)`},children:r}),n&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,whiteSpace:`pre-wrap`},children:n})]})}function gK({pkg:e,busyKey:t,actionError:n,actionMessage:r,sessionId:i,onAction:a,onReloadSession:o,onOpenFile:s}){let{t:c}=N(),{pluginConfigBindings:l,addPluginConfigBinding:u,removePluginConfigBinding:d}=ze(),f=qG(e),p=t?.endsWith(f)??!1,m=t===`reload`,h=!e.disabled;return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,justifyContent:`space-between`,gap:12,minWidth:0,flexWrap:`wrap`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,minWidth:180,flex:1},children:[(0,E.jsx)(oK,{enabled:h,loading:p||m,onToggle:()=>a(e.disabled?`enable`:`disable`,e),label:e.disabled?c(`i18n.enablePackage`):c(`i18n.disablePackage`),testId:`package-toggle`}),(0,E.jsx)(iK,{scope:e.scope}),e.disabled?(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 5px`,borderRadius:3,background:`color-mix(in srgb, var(--text-dim) 12%, transparent)`,color:`var(--text-dim)`},children:c(`i18n.disabled`)}):e.filtered&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 5px`,borderRadius:3,background:`color-mix(in srgb, var(--status-warning) 12%, transparent)`,color:`var(--status-warning)`},children:c(`i18n.filtered`)}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.source})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,E.jsxs)(`button`,{onClick:()=>a(`update`,e),disabled:p||m,style:aK(p||m),children:[t===`update:${f}`&&(0,E.jsx)(oi,{size:14,className:`animate-spin`,"aria-hidden":`true`}),t===`update:${f}`?c(`i18n.updating`):c(`i18n.update`)]}),(0,E.jsx)(`button`,{onClick:o,disabled:!i||m||p,style:aK(!i||m||p),title:c(i?`i18n.reloadSession`:`i18n.openSessionToReload`),children:c(m?`i18n.reloading`:`i18n.reloadSession`)}),(0,E.jsx)(`button`,{onClick:()=>a(`remove`,e),disabled:p||m,style:aK(p||m,!0),children:t===`remove:${f}`?c(`i18n.removing`):c(`i18n.remove`)})]})]}),(0,E.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`minmax(96px, 130px) minmax(0, 1fr)`,gap:`9px 14px`,fontSize:`var(--text-base)`,lineHeight:1.45},children:[(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`},children:c(`i18n.status`)}),(0,E.jsx)(`div`,{style:{color:tK(e.status),textTransform:`capitalize`},children:e.status}),(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`},children:c(`i18n.version`)}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,fontFamily:`var(--font-mono)`},children:XG(e,c)}),(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`},children:c(`i18n.package`)}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,fontFamily:`var(--font-mono)`,overflowWrap:`anywhere`},children:e.packageName??c(`i18n.unknown`)}),(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`},children:c(`i18n.resources`)}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`},children:YG(e,c)}),(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`},children:c(`i18n.installedPath`)}),(0,E.jsx)(`div`,{style:{color:e.installedPath?`var(--text-muted)`:`#ef4444`,fontFamily:`var(--font-mono)`,overflowWrap:`anywhere`},children:e.installedPath?HG(e.installedPath):c(`i18n.notFound`)})]}),e.readmePath&&e.readmeSummary&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`},children:c(`i18n.readme`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>s(e.readmePath,hG(e.readmePath)),style:{cursor:`pointer`,fontSize:`var(--text-sm)`,color:`var(--accent)`,background:`none`,border:`none`,padding:0},children:c(`i18n.readmeDetails`)})]}),(0,E.jsx)(`div`,{className:`markdown-body markdown-file-preview`,style:{fontSize:`var(--text-sm)`,lineHeight:1.5,overflowWrap:`anywhere`},children:(0,E.jsx)(Vk,{remarkPlugins:lG,rehypePlugins:dG,components:{a({href:t,children:n,...r}){return delete r.node,(0,E.jsx)(BG,{href:t,markdownDir:gG(e.readmePath),onOpenFile:e=>s(e,hG(e)),...r,children:n})}},children:e.readmeSummary})})]}),(0,E.jsx)(_K,{bindings:l[f]??[],onAdd:e=>u(f,e),onRemove:e=>d(f,e),onOpenFile:s}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:700,color:`var(--text)`},children:c(`i18n.resolvedResources`)}),(0,E.jsx)(rK,{pkg:e})]}),r&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-success)`},children:r}),n&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,whiteSpace:`pre-wrap`},children:n})]})}function _K({bindings:e,onAdd:t,onRemove:n,onOpenFile:r}){let{t:i}=N(),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`flex-start`,gap:8},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:700,color:`var(--text)`},children:i(`i18n.configBindings`)}),(0,E.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),style:{...aK(!1),display:`inline-flex`,alignItems:`center`,gap:4},children:[(0,E.jsx)(fi,{size:p.sm}),i(`i18n.addBinding`)]})]}),e.length===0?(0,E.jsx)(`p`,{style:{margin:0,fontSize:`var(--text-sm)`,color:`var(--text-muted)`},children:i(`i18n.noConfigBindings`)}):(0,E.jsxs)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6},children:[e.map(e=>{let t=e.note?`${hG(e.path)} · ${e.note}`:hG(e.path),n=e.note?`${e.path}\n${e.note}`:e.path;return(0,E.jsx)(qi,{label:n,wrapperStyle:{display:`inline-flex`,minWidth:0},children:(0,E.jsx)(AG,{label:t,title:n,onClick:()=>r(e.path,hG(e.path)),onRemove:()=>o(e.path)})},e.path)}),a!==null&&(0,E.jsx)(YS,{open:!0,title:i(`i18n.removeBinding`),description:(0,E.jsx)(`span`,{style:{display:`block`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,overflowWrap:`anywhere`},children:a}),confirmText:i(`i18n.confirm`),cancelText:i(`i18n.cancel`),destructive:!0,onConfirm:()=>{n(a),o(null)},onCancel:()=>o(null)})]}),(0,E.jsx)(DG,{open:s,title:i(`i18n.bindConfigFile`),confirmText:i(`i18n.confirm`),initialPath:`~/.pi`,noteLabel:i(`i18n.configFileNote`),showFiles:!0,showExtensionFilter:!0,extensionOptions:[`.json`,`.json5`,`.yaml`,`.yml`,`.toml`,`.ini`,`.conf`],onCancel:()=>c(!1),onConfirm:(e,n)=>{t({path:e,note:n||void 0}),c(!1)}})]})}function vK({cwd:e,sessionId:t,onClose:n,onOpenFile:r,onReloaded:i,pane:a,globalPackages:o=[],globalExtensionFilters:s=[]}){let c=ne(),{t:l}=N(),[u,f]=(0,d.useState)(null),[m,h]=(0,d.useState)(!0),[g,_]=(0,d.useState)(null),[v,y]=(0,d.useState)(WG),[b,x]=(0,d.useState)(GG),[S,C]=(0,d.useState)(UG),[w,T]=(0,d.useState)(`plugins`),[D,O]=(0,d.useState)(``),[k,A]=(0,d.useState)(``),[j,M]=(0,d.useState)(`global`),[P,ee]=(0,d.useState)(`global`),[F,I]=(0,d.useState)(280),[te,re]=(0,d.useState)(``),[ie,ae]=(0,d.useState)(null),[L,R]=(0,d.useState)(null),[oe,z]=(0,d.useState)(null),se=(0,d.useMemo)(()=>{let e=u?.packages??[];return!o||o.length===0?e:[...e,...o]},[u?.packages,o]),ce=se.find(e=>qG(e)===v)??null,le=(0,d.useMemo)(()=>{let e=[...u?.extensionFilters??[],...s??[]],t=new Set;return e.filter(e=>{let n=JG(e);return!t.has(n)&&(t.add(n),!0)})},[u?.extensionFilters,s]),ue=le.find(e=>JG(e)===b)??null,de=u?.projectResourcesLoaded??!0,fe=(0,d.useMemo)(()=>[`project`,`global`].map(e=>({scope:e,packages:se.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[se]),pe=te.trim().toLowerCase(),me=pe?fe.map(e=>({...e,packages:e.packages.filter(e=>e.source.toLowerCase().includes(pe))})).filter(e=>e.packages.length>0):fe,he=(0,d.useMemo)(()=>[`project`,`global`].map(e=>({scope:e,filters:le.filter(t=>t.scope===e)})).filter(e=>e.filters.length>0),[le]),ge=(0,d.useMemo)(()=>pe?he.map(e=>({...e,filters:e.filters.filter(e=>e.pattern.toLowerCase().includes(pe))})).filter(e=>e.filters.length>0):he,[he,pe]),_e=e=>{T(e),C(e===`plugins`?e=>e===`addFilter`||e===`filter`?ce?`package`:`addPlugin`:e:e=>e===`addPlugin`||e===`package`?ue?`filter`:`addFilter`:e)},ve=(0,d.useCallback)(async()=>{h(!0),_(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);f(n);let r=[...n.packages,...o??[]],i=[...n.extensionFilters,...s??[]];C(e=>r.length===0&&e!==`addFilter`?`addPlugin`:e),y(e=>e&&r.some(t=>qG(t)===e)?e:r[0]?qG(r[0]):null),x(e=>e&&i.some(t=>JG(t)===e)?e:null)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}},[e,o,s]);(0,d.useEffect)(()=>{ve()},[ve]),(0,d.useEffect)(()=>{UG=S,WG=v,GG=b});let ye=Li(),be=(0,d.useRef)(new Map),Se=(0,d.useCallback)(async(t,n)=>{let r=qG(n),i=`action:${t}:${r}`,a=(be.current.get(i)??0)+1;be.current.set(i,a),ae(`${t}:${r}`),R(null),z(null);try{let r=await ye.start(r=>fetch(`/api/plugins`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t,source:n.source,scope:n.scope,cwd:e}),signal:r}),VG[t],{joinKey:i}).promise;if(a!==be.current.get(i))return;let o=await r.json();if(!r.ok||o.error)throw Error(o.error??`HTTP ${r.status}`);let s={...o,packages:o.packages.filter(e=>e.scope===`project`),extensionFilters:o.extensionFilters.filter(e=>e.scope===`project`)};if(f(s),t===`remove`)y(s.packages[0]?qG(s.packages[0]):null),s.packages.length===0&&C(`addPlugin`),z(l(`plugins.packageRemoved`));else{let e={install:l(`plugins.packageInstalled`),update:l(`plugins.packageUpdated`),disable:l(`plugins.packageDisabled`),enable:l(`plugins.packageEnabled`),addExtensionFilter:l(`plugins.extensionFilterAdded`),removeExtensionFilter:l(`plugins.extensionFilterRemoved`)};z(e[t])}n.scope===`global`&&xe.refresh().catch(e=>console.error(`[pi-web] refresh home plugins:`,e))}catch(e){if(a!==be.current.get(i)||e instanceof Fi&&e.message===`cancelled`)return;R(e instanceof Error?e.message:String(e))}finally{a===be.current.get(i)&&ae(null)}},[e,l,ye]),Ce=(0,d.useCallback)(async(t,n)=>{let r=JG(n),i=`filter:${t}:${r}`,a=(be.current.get(i)??0)+1;be.current.set(i,a),ae(`${t}:${r}`),R(null),z(null);try{let o=await ye.start(r=>fetch(`/api/plugins`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t,source:n.pattern,scope:n.scope,cwd:e}),signal:r}),VG[t],{joinKey:i}).promise;if(a!==be.current.get(i))return;let s=await o.json();if(!o.ok||s.error)throw Error(s.error??`HTTP ${o.status}`);let c={...s,packages:s.packages.filter(e=>e.scope===`project`),extensionFilters:s.extensionFilters};f(c),t===`removeExtensionFilter`?(x(null),z(l(`plugins.extensionFilterRemoved`))):(x(r),z(l(`plugins.extensionFilterAdded`))),n.scope===`global`&&xe.refresh().catch(e=>console.error(`[pi-web] refresh home plugins:`,e))}catch(e){if(a!==be.current.get(i)||e instanceof Fi&&e.message===`cancelled`)return;R(e instanceof Error?e.message:String(e))}finally{a===be.current.get(i)&&ae(null)}},[e,l,ye]),we=(0,d.useCallback)(async()=>{let t=KG(D).trim();if(!t)return;O(t);let n=`${j}\0${t}`,r=`install:${n}`,i=(be.current.get(r)??0)+1;be.current.set(r,i),ae(`install:${n}`),R(null),z(null);try{let a=await ye.start(n=>fetch(`/api/plugins`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`install`,source:t,scope:j,cwd:e}),signal:n}),VG.install,{joinKey:r}).promise;if(i!==be.current.get(r))return;let o=await a.json();if(!a.ok||o.error)throw Error(o.error??`HTTP ${a.status}`);let s={...o,packages:o.packages.filter(e=>e.scope===`project`),extensionFilters:o.extensionFilters.filter(e=>e.scope===`project`)};f(s);let c=QG(s.packages,t,j);y(c?qG(c):n),C(`package`),O(``),z(l(`plugins.packageInstalled`)),j===`global`&&xe.refresh().catch(e=>console.error(`[pi-web] refresh home plugins:`,e))}catch(e){if(i!==be.current.get(r)||e instanceof Fi&&e.message===`cancelled`)return;R(e instanceof Error?e.message:String(e))}finally{i===be.current.get(r)&&ae(null)}},[e,j,D,l,ye]),Te=(0,d.useCallback)(async()=>{let e=k.trim();if(e){if(!fG(e)){R(l(`plugins.filterInvalid`));return}R(null),z(null),await Ce(`addExtensionFilter`,{pattern:e,scope:P}),C(`filter`),A(``)}},[k,P,Ce,l]),Ee=(0,d.useCallback)(async()=>{if(t){ae(`reload`),R(null),z(null);try{await lC(t,{type:`reload`}),i?.(),await ve(),z(l(`plugins.sessionReloaded`))}catch(e){R(e instanceof Error?e.message:String(e))}finally{ae(null)}}},[ve,i,t,l]),De=ie?.startsWith(`install:`)??!1,Oe=ie?.startsWith(`addExtensionFilter:`)??!1;return(0,E.jsx)(`div`,{style:a?{display:`contents`}:{position:`fixed`,inset:0,zIndex:1e3,background:`var(--overlay)`,display:`flex`,alignItems:`center`,justifyContent:`center`},onClick:e=>{e.target===e.currentTarget&&n()},children:(0,E.jsxs)(`div`,{style:a?{width:`100%`,height:`100%`,background:`var(--bg)`,display:`flex`,flexDirection:`column`,overflow:`hidden`}:{width:c?`calc(100vw - 16px)`:860,maxWidth:`calc(100vw - 16px)`,height:c?`calc(100dvh - 16px)`:`76vh`,maxHeight:`calc(100dvh - 16px)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,display:`flex`,flexDirection:`column`,boxShadow:`0 8px 32px var(--shadow-color)`,overflow:`hidden`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`12px 18px`,borderBottom:`1px solid var(--border)`,flexShrink:0},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,minWidth:0,flexWrap:`wrap`,rowGap:6},children:[(0,E.jsx)(`div`,{style:{display:`inline-flex`,border:`1px solid var(--border)`,borderRadius:7,overflow:`hidden`,flexShrink:0},children:[`plugins`,`filters`].map(e=>{let t=w===e;return(0,E.jsx)(`button`,{type:`button`,"data-testid":e===`plugins`?`plugins-tab-plugins`:`plugins-tab-filters`,onClick:()=>_e(e),style:{padding:`4px 12px`,border:`none`,borderRight:e===`plugins`?`1px solid var(--border)`:`none`,background:t?`var(--accent)`:`transparent`,color:t?`var(--on-accent)`:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,fontWeight:t?700:400},children:l(e===`plugins`?`plugins.managePlugins`:`plugins.filterRules`)},e)})}),(0,E.jsx)(`code`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-muted)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:HG(e)}),(0,E.jsx)(oC,{testId:`plugins-search`,query:te,onChange:re,t:l})]}),!a&&(0,E.jsx)(`button`,{onClick:n,style:{background:`none`,border:`none`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-5xl)`,lineHeight:1,padding:`2px 6px`},children:`×`})]}),!de&&(0,E.jsx)(`div`,{role:`status`,style:{padding:`8px 18px`,borderBottom:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:l(`trust.pluginsNotLoaded`)}),(0,E.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:c?`column`:`row`,overflow:`hidden`},children:[(0,E.jsxs)(`div`,{style:{width:c?`100%`:F,maxHeight:c?`40vh`:void 0,display:`flex`,flexDirection:`column`,flexShrink:0,background:`var(--bg)`},children:[(0,E.jsx)(`div`,{style:{flex:1,overflowY:`auto`,padding:`8px 6px`},children:m?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:l(`i18n.loading`)}):g?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--status-error)`},children:g}):w===`plugins`?se.length===0||pe&&me.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:l(pe?`i18n.noMatch`:`i18n.noPlugins`)}):(0,E.jsx)(E.Fragment,{children:me.map(e=>(0,E.jsxs)(`div`,{style:{marginBottom:6},children:[(0,E.jsx)(`div`,{style:{padding:`4px 8px 3px`,fontSize:`var(--text-xs)`,fontWeight:600,color:`var(--text-dim)`,textTransform:`uppercase`},children:e.scope}),e.packages.map(e=>{let t=qG(e),n=S===`package`&&v===t;return(0,E.jsxs)(`div`,{"data-testid":`package-item-${e.scope}-${e.source}`,onClick:()=>{y(t),C(`package`),R(null),z(null)},style:{display:`flex`,alignItems:`center`,gap:7,padding:`8px 8px`,borderRadius:5,cursor:`pointer`},className:n?`selectable-row row-selected-gradient`:`selectable-row`,children:[(0,E.jsx)(qi,{label:nK(e.status,l),children:(0,E.jsx)(`span`,{style:{flexShrink:0,width:7,height:7,borderRadius:`50%`,background:tK(e.status)}})}),(0,E.jsxs)(`div`,{style:{minWidth:0,flex:1},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:n?600:400,color:`var(--text)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:(0,E.jsx)(qi,{label:e.source,children:(0,E.jsx)(`span`,{children:e.source})})}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,marginTop:2},children:(0,E.jsx)(qi,{label:YG(e,l),children:(0,E.jsxs)(`span`,{style:{display:`inline-flex`,gap:8},children:[(e.version||e.configuredVersion)&&(0,E.jsxs)(`span`,{children:[(0,E.jsxs)(`span`,{children:[l(`i18n.versionShort`),`:`]}),(0,E.jsx)(`span`,{style:{color:`var(--text)`},children:e.version||e.configuredVersion})]}),(0,E.jsxs)(`span`,{children:[(0,E.jsxs)(`span`,{children:[l(`i18n.extensionShort`),`:`]}),(0,E.jsx)(`span`,{style:{color:`var(--text)`},children:e.counts.extensions})]}),(0,E.jsxs)(`span`,{children:[(0,E.jsxs)(`span`,{children:[l(`i18n.skillShort`),`:`]}),(0,E.jsx)(`span`,{style:{color:`var(--text)`},children:e.counts.skills})]})]})})})]})]},t)})]},e.scope))}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{style:{padding:`4px 8px 3px`,fontSize:`var(--text-xs)`,fontWeight:600,color:`var(--text-dim)`,textTransform:`uppercase`},children:l(`plugins.extensionFilters`)}),(0,E.jsx)(`div`,{style:{padding:`0 8px 4px`,fontSize:`var(--text-xs)`,color:`var(--text-dim)`,lineHeight:1.45},children:l(`plugins.extensionFiltersHint`)}),he.length===0||pe&&ge.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:l(pe?`i18n.noMatch`:`plugins.noExtensionFilters`)}):ge.map(e=>(0,E.jsxs)(`div`,{style:{marginBottom:6},children:[(0,E.jsx)(`div`,{style:{padding:`4px 8px 3px`,fontSize:`var(--text-xs)`,fontWeight:600,color:`var(--text-dim)`,textTransform:`uppercase`},children:e.scope}),e.filters.map(e=>{let t=JG(e),n=S===`filter`&&b===t;return(0,E.jsxs)(`div`,{"data-testid":`extension-filter-item-${e.scope}-${e.pattern}`,onClick:()=>{x(t),y(null),C(`filter`),R(null),z(null)},style:{display:`flex`,alignItems:`center`,gap:7,padding:`6px 8px`,borderRadius:5,cursor:`pointer`},className:n?`selectable-row row-selected-gradient`:`selectable-row`,children:[(0,E.jsx)(`span`,{style:{flexShrink:0,width:18,height:18,borderRadius:4,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`var(--text-sm)`,fontWeight:700,fontFamily:`var(--font-mono)`,color:$G(e.pattern),background:`color-mix(in srgb, var(--border) 55%, transparent)`},children:e.pattern[0]}),(0,E.jsx)(`span`,{style:{minWidth:0,flex:1,fontSize:`var(--text-sm)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:(0,E.jsx)(qi,{label:e.pattern,children:(0,E.jsx)(`span`,{children:e.pattern})})})]},t)})]},`filters-${e.scope}`))]})}),(0,E.jsx)(`div`,{style:{padding:`8px 6px`,borderTop:`1px solid var(--border)`,flexShrink:0},children:w===`plugins`?(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{C(`addPlugin`),R(null),z(null)},style:{display:`flex`,alignItems:`center`,gap:6,padding:`7px 8px`,borderRadius:5,border:`none`,width:`100%`,cursor:`pointer`,color:S===`addPlugin`?`var(--accent)`:`var(--text-dim)`,fontSize:`var(--text-base)`},className:S===`addPlugin`?`row-selected-gradient`:`hover-shift`,children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,E.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]}),l(`i18n.addPlugin`)]}):(0,E.jsxs)(`button`,{type:`button`,"data-testid":`add-extension-filter-btn`,onClick:()=>{C(`addFilter`),x(null),y(null),R(null),z(null)},style:{display:`flex`,alignItems:`center`,gap:6,padding:`7px 8px`,borderRadius:5,border:`none`,width:`100%`,cursor:`pointer`,color:S===`addFilter`?`var(--accent)`:`var(--text-dim)`,fontSize:`var(--text-base)`},className:S===`addFilter`?`row-selected-gradient`:`hover-shift`,children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M3 6h18`}),(0,E.jsx)(`path`,{d:`M7 12h10`}),(0,E.jsx)(`path`,{d:`M11 18h2`})]}),l(`plugins.addFilter`)]})})]}),!c&&(0,E.jsx)(aC,{width:F,onResize:I,ariaLabel:l(`i18n.resizeList`,{name:l(`i18n.plugins`)})}),(0,E.jsx)(`div`,{style:{flex:1,overflowY:`auto`,padding:20},children:S===`addFilter`?(0,E.jsx)(mK,{pattern:k,scope:P,projectResourcesLoaded:de,busy:Oe,actionError:L,onPatternChange:A,onScopeChange:ee,onAdd:Te}):m?null:S===`filter`&&ue?(0,E.jsx)(hK,{filter:ue,busyKey:ie,actionError:L,actionMessage:oe,onRemove:e=>void Ce(`removeExtensionFilter`,e)},JG(ue)):S===`addPlugin`?(0,E.jsx)(pK,{cwd:e,source:D,scope:j,projectResourcesLoaded:de,busy:De,actionError:L,packages:se,onSourceChange:O,onScopeChange:M,onInstall:we}):ce?(0,E.jsx)(gK,{pkg:ce,busyKey:ie,actionError:L,actionMessage:oe,sessionId:t,onAction:Se,onReloadSession:Ee,onOpenFile:r},qG(ce)):(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-dim)`,fontSize:`var(--text-lg)`},children:ue?null:l(`i18n.selectPackage`)})})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,padding:`10px 18px`,borderTop:`1px solid var(--border)`,flexShrink:0},children:[(0,E.jsx)(`div`,{style:{minWidth:0,flex:1,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,overflow:`hidden`},children:u?.diagnostics.length?(0,E.jsxs)(`span`,{title:u.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:``}${e.message}`).join(`
|
|
347
347
|
`),style:{color:u.diagnostics.some(e=>e.type===`error`)?`var(--status-error)`:`var(--status-warning)`},children:[u.diagnostics.length,` diagnostic`,u.diagnostics.length===1?``:`s`]}):(0,E.jsx)(`span`,{children:u?`${u.totals.extensions} ext · ${u.totals.skills} skills · ${u.totals.prompts} prompts · ${u.totals.themes} themes`:``})}),(0,E.jsx)(`button`,{onClick:()=>void ve(),disabled:m||ie!==null,style:aK(m||ie!==null),children:l(`i18n.refresh`)}),(0,E.jsx)(`button`,{onClick:n,style:aK(!1),children:l(`i18n.close`)})]})]})})}var yK=3e4,bK=12e4,xK=6e4,SK=12e4,CK=15e3;function wK(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,`~`)}function TK(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return n===`user`||t===`user`?`global`:n===`project`||t===`project`?`project`:`path`}function EK(e){let t=TK(e);return t===`path`?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function DK(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function OK(e){return e?e.slice(0,8):`unknown`}function kK({enabled:e,loading:t,onToggle:n,testId:r}){let{t:i}=N();return(0,E.jsx)(`button`,{"data-testid":r,onClick:n,disabled:t,title:i(e?`i18n.visibleInPrompt`:`i18n.hiddenFromPrompt`),style:{flexShrink:0,width:40,height:22,borderRadius:11,border:`none`,padding:0,cursor:t?`wait`:`pointer`,background:e?`var(--accent)`:`var(--border)`,position:`relative`,transition:`background 0.18s`,outline:`none`},children:(0,E.jsx)(`span`,{style:{position:`absolute`,top:3,left:e?21:3,width:16,height:16,borderRadius:`50%`,background:`var(--bg)`,boxShadow:`0 1px 4px var(--shadow-color)`,transition:`left 0.18s cubic-bezier(.4,0,.2,1)`}})})}function AK({skill:e,cwd:t,onToggle:n,toggling:r,saveError:i,updateStatus:a,checkingUpdate:o,updating:s,updateError:c,onCheckUpdate:l,onUpdate:u}){let{t:d}=N(),f=TK(e),p=!e.disableModelInvocation;function m(e){return f===`project`&&e.startsWith(t)?`./${e.slice(t.length).replace(/^[/\\]/,``)}`:wK(e)}return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:20},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:4},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:7},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 5px`,borderRadius:3,flexShrink:0,background:f===`project`?`color-mix(in srgb, var(--status-info) 12%, transparent)`:`color-mix(in srgb, var(--text-dim) 12%, transparent)`,color:f===`project`?`color-mix(in srgb, var(--status-info) 80%, transparent)`:`var(--text-dim)`},children:f}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,flex:1,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:m(e.filePath)}),(0,E.jsx)(kK,{enabled:p,loading:r,onToggle:()=>n(e),testId:`skill-toggle-${e.name}`})]}),(0,E.jsxs)(`div`,{style:{minHeight:16,display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:8,flexWrap:`wrap`,textAlign:`right`},children:[!p&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:d(`i18n.hiddenButInvocable`)}),i&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,overflowWrap:`anywhere`},children:i})]})]}),e.install?.skillsShUrl&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:5},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontWeight:500},children:`Source`}),(0,E.jsx)(`a`,{href:e.install.skillsShUrl,target:`_blank`,rel:`noreferrer`,title:e.install.skillsShUrl,style:{display:`flex`,alignItems:`center`,gap:8,width:`fit-content`,maxWidth:`100%`,color:`var(--accent)`,textDecoration:`none`},children:(0,E.jsxs)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[e.install.skillsShUrl.replace(/^https?:\/\//,``),` ↗`]})})]}),e.install&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:7},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontWeight:500},children:`Version`}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexWrap:`wrap`},children:[(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:OK(a?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,E.jsx)(`button`,{onClick:l,disabled:o||s,style:{padding:`4px 9px`,border:`1px solid var(--border)`,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:o||s?`not-allowed`:`pointer`,opacity:o||s?.5:1,fontSize:`var(--text-sm)`},children:d(`i18n.check`)}),a?.state===`update-available`&&(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,color:`var(--status-warning)`},children:OK(a.latestVersion)}),(o||a&&a.state!==`update-available`)&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:o?`var(--accent)`:a?.state===`up-to-date`?`var(--status-success)`:a?.state===`error`?`var(--status-error)`:`var(--text-dim)`},children:o?d(`i18n.checking`):a?.state===`up-to-date`?d(`i18n.upToDate`):a?.state===`unsupported`?d(`i18n.automaticChecksUnavailable`):a?.message||d(`i18n.checkFailed`)}),a?.state===`update-available`&&(0,E.jsx)(`button`,{onClick:u,disabled:s||o,style:{padding:`4px 10px`,border:`none`,borderRadius:5,background:`var(--accent)`,color:`var(--on-accent)`,cursor:s||o?`not-allowed`:`pointer`,opacity:s||o?.5:1,fontSize:`var(--text-sm)`,fontWeight:600},children:d(s?`i18n.updating`:`i18n.update`)})]}),c&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`},children:c})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:5},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontWeight:500},children:`Name`}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-xl)`,color:`var(--text)`},children:e.name})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:5},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontWeight:500},children:`Description`}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xl)`,color:`var(--text-muted)`,lineHeight:1.6},children:e.description})]})]})}function jK({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:r}){let{t:i}=N(),[a,o]=(0,d.useState)(``),[s,c]=(0,d.useState)([]),[l,u]=(0,d.useState)(!1),[f,p]=(0,d.useState)(null),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(null),[v,y]=(0,d.useState)(new Set),[b,x]=(0,d.useState)(`global`),S=(0,d.useRef)(null);(0,d.useEffect)(()=>{S.current?.focus()},[]);let C=Li(),w=(0,d.useRef)(0),T=(0,d.useCallback)(async e=>{if(!e.trim())return;let t=++w.current;u(!0),p(null),c([]);try{let n=await C.start(t=>fetch(`/api/skills/search`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({query:e.trim()}),signal:t}),yK,{joinKey:`search`}).promise;if(t!==w.current)return;let r=await n.json();if(r.error){p(r.error);return}c(r.results??[]),(r.results??[]).length===0&&p(i(`i18n.noSkills`))}catch(e){if(t!==w.current||e instanceof Fi&&e.message===`cancelled`)return;p(e instanceof Error?e.message:String(e))}finally{t===w.current&&u(!1)}},[i,C]),D=Li(),O=(0,d.useRef)(0),k=(0,d.useCallback)(async t=>{let n=++O.current;h(t),_(null);try{let i=await D.start(n=>fetch(`/api/skills/install`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({package:t,scope:b,cwd:e}),signal:n}),bK,{joinKey:`install:${b}:${t}`}).promise;if(n!==O.current)return;let a=await i.json();if(!i.ok||a.error){_(a.error??`HTTP ${i.status}`);return}y(e=>new Set(e).add(`${b}:${t}`)),r()}catch(e){if(n!==O.current||e instanceof Fi&&e.message===`cancelled`)return;_(e instanceof Error?e.message:String(e))}finally{n===O.current&&h(null)}},[r,b,e,D]),A=b===`global`?`~/.pi/agent/skills/`:`${wK(e)}/.pi/skills/`;return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12,marginBottom:20},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,fontWeight:600,color:`var(--text)`},children:i(`i18n.addSkill`)}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,E.jsx)(`input`,{ref:S,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(a)},placeholder:i(`i18n.skillSearchPlaceholder`),style:{flex:1,padding:`7px 10px`,fontSize:`var(--text-lg)`,background:`var(--bg-input)`,border:`1px solid var(--border)`,borderRadius:6,color:`var(--text)`,outline:`none`}}),(0,E.jsx)(`button`,{onClick:()=>T(a),disabled:l||!a.trim(),style:{padding:`7px 16px`,fontSize:`var(--text-lg)`,borderRadius:6,border:`none`,background:`var(--accent)`,color:`var(--on-accent)`,cursor:l||!a.trim()?`not-allowed`:`pointer`,opacity:l||!a.trim()?.5:1,flexShrink:0},children:i(l?`i18n.searching`:`i18n.search`)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,E.jsx)(`div`,{style:{display:`flex`,borderRadius:5,border:`1px solid var(--border)`,overflow:`hidden`,fontSize:`var(--text-base)`,flexShrink:0},children:[`global`,`project`].map(e=>(0,E.jsx)(`button`,{onClick:()=>{(e===`global`||n)&&x(e)},disabled:e===`project`&&!n,title:e===`project`&&!n?i(`trust.projectScopeUnavailable`):void 0,style:{padding:`3px 10px`,border:`none`,cursor:e===`project`&&!n?`not-allowed`:`pointer`,background:b===e?`var(--accent)`:`transparent`,color:b===e?`var(--on-accent)`:`var(--text-dim)`,fontWeight:b===e?600:400,opacity:e===`project`&&!n?.45:1,borderRight:e===`global`?`1px solid var(--border)`:`none`},children:e},e))}),(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-dim)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[`→ `,A]})]}),f&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`},children:f}),g&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--status-error)`,wordBreak:`break-word`},children:g})]}),s.length>0?(0,E.jsx)(`div`,{style:{flex:1,overflowY:`auto`},children:s.map(e=>{let n=t[b].has(e.package)||v.has(`${b}:${e.package}`),r=m===e.package,a=e.package.indexOf(`@`),o=a>-1?e.package.slice(0,a):e.package,s=a>-1?e.package.slice(a+1):null;return(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:14,padding:`12px 0`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-lg)`,fontWeight:600,color:`var(--text)`,marginBottom:3},children:s??o}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexWrap:`wrap`},children:[(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:o}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontWeight:500},children:e.installs}),e.url&&(0,E.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,style:{fontSize:`var(--text-base)`,color:`var(--accent)`,textDecoration:`none`},children:`skills.sh ↗`})]})]}),(0,E.jsx)(`button`,{onClick:()=>!n&&!r&&k(e.package),disabled:n||r||m!==null,style:{flexShrink:0,padding:`5px 14px`,fontSize:`var(--text-base)`,fontWeight:500,borderRadius:5,border:`1px solid var(--border)`,cursor:n||r||m!==null?`not-allowed`:`pointer`,background:n?`color-mix(in srgb, var(--status-success) 10%, transparent)`:`none`,color:n?`var(--status-success)`:r?`var(--accent)`:`var(--text-muted)`,transition:`color 0.12s`},children:n?`✓ ${i(`i18n.installed`)}`:i(r?`i18n.installing`:`i18n.install`)})]},e.package)})}):!f&&!l&&(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-lg)`,color:`var(--text-dim)`,lineHeight:1.8},children:[`Search`,` `,(0,E.jsx)(`a`,{href:`https://skills.sh`,target:`_blank`,rel:`noreferrer`,style:{color:`var(--accent)`,textDecoration:`none`},children:`skills.sh`}),` `,`to discover and install skills for your agent.`]})]})}var MK=null;function NK({cwd:e,onClose:t,pane:n,homeSkills:r=[]}){let i=ne(),{t:a}=N(),[o,s]=(0,d.useState)([]),c=(0,d.useMemo)(()=>r.length===0?o:[...o,...r],[o,r]),[l,u]=(0,d.useState)(!0),[f,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(MK),[_,v]=(0,d.useState)(new Set),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(!1),[C,w]=(0,d.useState)({}),[T,D]=(0,d.useState)(new Set),[O,k]=(0,d.useState)(!1),[A,j]=(0,d.useState)(null),[M,P]=(0,d.useState)(null),[ee,F]=(0,d.useState)(!0),[I,te]=(0,d.useState)({}),[re,ie]=(0,d.useState)(280),[ae,L]=(0,d.useState)(``),R=ae.trim().toLowerCase(),oe=(0,d.useCallback)(async()=>{u(!0),m(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);let r=n.skills??[];if(s(r),F(n.projectResourcesLoaded??!0),r.length>0&&!h){let e=r.find(e=>!e.disableModelInvocation)??r[0];g(e.filePath),e.disableModelInvocation&&te(t=>({...t,[EK(e)]:!0}))}return r}catch(e){return m(String(e)),[]}finally{u(!1)}},[e,h]);(0,d.useEffect)(()=>{w({}),P(null),oe()},[e]),(0,d.useEffect)(()=>{MK=h});let z=Li(),se=(0,d.useRef)(new Map),ce=(0,d.useCallback)(async t=>{let n=(t?[t]:o.filter(e=>!!e.install)).map(DK).filter(e=>!!e);if(n.length===0)return;let r=t?DK(t)??`check`:`check-all`,i=(se.current.get(r)??0)+1;se.current.set(r,i),P(null),D(e=>new Set([...e,...n])),t||k(!0);try{let n=await z.start(n=>fetch(`/api/skills/check`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,package:t?.install?.package,scope:t?.install?.scope}),signal:n}),xK,{joinKey:r}).promise;if(i!==se.current.get(r))return;let a=await n.json();if(!n.ok||a.error)throw Error(a.error??`HTTP ${n.status}`);w(e=>{let t={...e};for(let e of a.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){if(i!==se.current.get(r)||e instanceof Fi&&e.message===`cancelled`)return;P(e instanceof Error?e.message:String(e))}finally{i===se.current.get(r)&&(D(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||k(!1))}},[e,o,z]),le=Li(),ue=(0,d.useRef)(new Map),de=(0,d.useCallback)(async t=>{if(!t.install)return;let n=DK(t),r=(ue.current.get(n)??0)+1;ue.current.set(n,r),j(n),P(null);try{let i=await le.start(n=>fetch(`/api/skills/update`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,package:t.install.package,scope:t.install.scope}),signal:n}),SK,{joinKey:`update:${n}`}).promise;if(r!==ue.current.get(n))return;let a=await i.json();if(!i.ok||a.error||!a.success)throw Error(a.error??`HTTP ${i.status}`);await oe();let o=a.skill?.install?.versionHash;w(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:`up-to-date`,currentVersion:o,latestVersion:o}}))}catch(e){if(r!==ue.current.get(n)||e instanceof Fi&&e.message===`cancelled`)return;P(e instanceof Error?e.message:String(e))}finally{r===ue.current.get(n)&&j(null)}},[e,oe,le]),fe=Li(),pe=(0,d.useRef)(new Map),me=(0,d.useCallback)(async t=>{let n=!t.disableModelInvocation,i=(pe.current.get(t.filePath)??0)+1;pe.current.set(t.filePath,i),v(e=>new Set(e).add(t.filePath)),b(null);try{let a=await fe.start(r=>fetch(`/api/skills`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filePath:t.filePath,disableModelInvocation:n,cwd:e}),signal:r}),CK,{joinKey:`toggle:${t.filePath}`}).promise;if(i!==pe.current.get(t.filePath))return;let o=await a.json();if(!a.ok||o.error){b(o.error??`HTTP ${a.status}`);return}s(e=>e.map(e=>e.filePath===t.filePath?{...e,disableModelInvocation:n}:e)),r.some(e=>e.filePath===t.filePath)&&Te.refresh().catch(e=>console.error(`[pi-web] refresh home skills:`,e)),n&&te(e=>({...e,[EK(t)]:!0}))}catch(e){if(i!==pe.current.get(t.filePath)||e instanceof Fi&&e.message===`cancelled`)return;b(e instanceof Error?e.message:String(e))}finally{i===pe.current.get(t.filePath)&&v(e=>{let n=new Set(e);return n.delete(t.filePath),n})}},[r,e,fe]),he=o.find(e=>e.filePath===h)??null;return(0,E.jsx)(`div`,{style:n?{display:`contents`}:{position:`fixed`,inset:0,zIndex:1e3,background:`var(--overlay)`,display:`flex`,alignItems:`center`,justifyContent:`center`},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,E.jsxs)(`div`,{style:n?{width:`100%`,height:`100%`,background:`var(--bg)`,display:`flex`,flexDirection:`column`,overflow:`hidden`}:{width:i?`calc(100vw - 16px)`:860,maxWidth:`calc(100vw - 16px)`,height:i?`calc(100dvh - 16px)`:`78vh`,maxHeight:`calc(100dvh - 16px)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:10,display:`flex`,flexDirection:`column`,boxShadow:`0 8px 32px var(--shadow-color)`,overflow:`hidden`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`12px 18px`,borderBottom:`1px solid var(--border)`,flexShrink:0},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:10},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-2xl)`,fontWeight:700,color:`var(--text)`},children:a(`common.skills`)}),(0,E.jsx)(`code`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-muted)`,fontFamily:`var(--font-mono)`,maxWidth:320,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:wK(e)}),(0,E.jsx)(oC,{testId:`skills-search`,query:ae,onChange:L,t:a})]}),!n&&(0,E.jsx)(`button`,{onClick:t,style:{background:`none`,border:`none`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-5xl)`,lineHeight:1,padding:`2px 6px`},children:`×`})]}),!ee&&(0,E.jsx)(`div`,{role:`status`,style:{padding:`8px 18px`,borderBottom:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:a(`trust.skillsNotLoaded`)}),(0,E.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:i?`column`:`row`,overflow:`hidden`},children:[(0,E.jsxs)(`div`,{style:{width:i?`100%`:re,maxHeight:i?`40vh`:void 0,display:`flex`,flexDirection:`column`,flexShrink:0,background:`var(--bg)`},children:[(0,E.jsx)(`div`,{style:{flex:1,overflowY:`auto`,padding:`8px 6px`},children:l?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:a(`i18n.loading`)}):f?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--status-error)`},children:f}):c.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:a(`i18n.noSkills`)}):(()=>{let e=R?c.filter(e=>e.name.toLowerCase().includes(R)):c,t=[],n=[{label:`project / skills.sh`,matches:e=>TK(e)===`project`&&!!e.install?.skillsShUrl},{label:`project`,matches:e=>TK(e)===`project`&&!e.install?.skillsShUrl},{label:`global / skills.sh`,matches:e=>TK(e)===`global`&&!!e.install?.skillsShUrl},{label:`global`,matches:e=>TK(e)===`global`&&!e.install?.skillsShUrl},{label:`path`,matches:e=>TK(e)===`path`}];for(let{label:r,matches:i}of n){let n=e.filter(i);n.length>0&&t.push({label:r,skills:n})}if(t.length===0)return(0,E.jsx)(`div`,{style:{padding:`10px 8px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:a(`i18n.noMatch`)});let r=e=>{let t=!x&&h===e.filePath,n=e.disableModelInvocation;return(0,E.jsxs)(`div`,{onClick:()=>{g(e.filePath),S(!1)},style:{display:`flex`,alignItems:`center`,gap:7,padding:`8px 8px`,borderRadius:5,cursor:`pointer`},className:t?`selectable-row row-selected-gradient`:`selectable-row`,children:[(0,E.jsx)(`span`,{style:{flexShrink:0,width:7,height:7,borderRadius:`50%`,background:n?`var(--border)`:`var(--accent)`,boxShadow:n?`none`:`0 0 4px var(--accent)`,transition:`background 0.15s, box-shadow 0.15s`}}),(0,E.jsx)(qi,{label:e.name,children:(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,fontWeight:t?600:400,color:n?`var(--text-dim)`:`var(--text)`,fontFamily:`var(--font-mono)`,flex:1,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})}),(()=>{let t=DK(e);return(t?C[t]:void 0)?.state===`update-available`?(0,E.jsx)(`span`,{title:a(`i18n.updateAvailable`),style:{color:`var(--status-warning)`,fontSize:`var(--text-lg)`,lineHeight:1,flexShrink:0},children:`↑`}):null})()]},e.filePath)};return t.map(({label:e,skills:t})=>{let n=t.filter(e=>!e.disableModelInvocation),i=t.filter(e=>e.disableModelInvocation),o=I[e]??!1;return(0,E.jsxs)(`div`,{style:{marginBottom:6},children:[(0,E.jsx)(`div`,{style:{padding:`4px 8px 3px`,fontSize:`var(--text-xs)`,fontWeight:600,color:`var(--text-dim)`,textTransform:`uppercase`,letterSpacing:`0.06em`},children:e}),n.map(r),i.length>0&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{onClick:()=>te(t=>({...t,[e]:!o})),style:{display:`flex`,alignItems:`center`,gap:5,padding:`4px 8px 3px`,fontSize:`var(--text-xs)`,fontWeight:600,color:`var(--text-dim)`,textTransform:`uppercase`,letterSpacing:`0.06em`,cursor:`pointer`,userSelect:`none`},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-3xs)`},children:o?`▾`:`▸`}),a(`i18n.dormant`),` (`,i.length,`)`]}),o||R?i.map(r):null]})]},e)})})()}),(0,E.jsx)(`div`,{style:{padding:`8px 6px`,borderTop:`1px solid var(--border)`,flexShrink:0},children:!R&&(0,E.jsxs)(`div`,{onClick:()=>S(!0),style:{display:`flex`,alignItems:`center`,gap:6,padding:`7px 8px`,borderRadius:5,cursor:`pointer`,color:x?`var(--accent)`:`var(--text-dim)`,fontSize:`var(--text-base)`},className:x?`row-selected-gradient`:`hover-shift`,children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,E.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]}),a(`i18n.addSkill`)]})})]}),!i&&(0,E.jsx)(aC,{width:re,onResize:ie,ariaLabel:a(`i18n.resizeList`,{name:a(`i18n.skills`)})}),(0,E.jsx)(`div`,{style:{flex:1,overflowY:`auto`,padding:20},children:x?(0,E.jsx)(jK,{cwd:e,projectResourcesLoaded:ee,installedPackages:{global:new Set(o.filter(e=>e.install?.scope===`global`).map(e=>e.install.package)),project:new Set(o.filter(e=>e.install?.scope===`project`).map(e=>e.install.package))},onInstalled:()=>{oe()}}):l?null:he?(0,E.jsx)(AK,{skill:he,cwd:e,onToggle:me,toggling:_.has(he.filePath),saveError:y,updateStatus:DK(he)?C[DK(he)]:void 0,checkingUpdate:DK(he)?T.has(DK(he)):!1,updating:A===DK(he),updateError:M,onCheckUpdate:()=>void ce(he),onUpdate:()=>void de(he)},he.filePath):(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-dim)`,fontSize:`var(--text-lg)`},children:a(`i18n.selectSkill`)})})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`10px 18px`,borderTop:`1px solid var(--border)`,flexShrink:0},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[c.some(e=>!!e.install)&&(0,E.jsx)(`button`,{onClick:()=>void ce(),disabled:O||A!==null,style:{padding:`6px 12px`,background:`none`,border:`1px solid var(--border)`,borderRadius:6,color:`var(--text-muted)`,cursor:O||A!==null?`not-allowed`:`pointer`,opacity:O||A!==null?.5:1,fontSize:`var(--text-base)`},children:a(O?`i18n.checking`:`i18n.checkUpdates`)}),Object.values(C).filter(e=>e.state===`update-available`).length>0&&(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--status-warning)`},children:[Object.values(C).filter(e=>e.state===`update-available`).length,` `,Object.values(C).filter(e=>e.state===`update-available`).length===1?a(`i18n.update`):a(`i18n.updates`)]})]}),(0,E.jsx)(`button`,{onClick:t,style:{padding:`6px 14px`,background:`none`,border:`1px solid var(--border)`,borderRadius:6,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-lg)`},children:a(`i18n.close`)})]})]})})}var PK=[{name:`compact`,description:`chat.commandCompact`,source:`builtin`},{name:`reload`,description:`chat.commandReload`,source:`builtin`},{name:`name`,description:`chat.commandName`,source:`builtin`},{name:`session`,description:`chat.commandSession`,source:`builtin`},{name:`copy`,description:`chat.commandCopy`,source:`builtin`}],FK=[`builtin`,`extension`,`prompt`,`skill`],IK={builtin:`chat.builtIn`,extension:`chat.extensions`,prompt:`chat.prompts`,skill:`chat.skills`},LK={builtin:0,extension:1,prompt:2,skill:3},RK=new Intl.Collator(void 0,{numeric:!0,sensitivity:`base`});function zK(e,t,n){let r=e.name.toLowerCase(),i=BK(e,n).toLowerCase();return r===t?0:r.startsWith(t)?1:r.includes(t)?2:i.includes(t)?3:4}function BK(e,t){return e.source===`builtin`?t(e.description):e.description??``}function VK(e,t){return e.source!==`skill`||!e.name.startsWith(`skill:`)?!1:t[e.name.slice(6)]===!0}function HK(e,t){let n=0,r=FK.map(r=>{let i=e.filter(e=>e.source===r);return{source:r,items:(r===`skill`?[...i.filter(e=>!VK(e,t)),...i.filter(e=>VK(e,t))]:i).map(e=>({command:e,index:n++}))}}).filter(e=>e.items.length>0);return{commands:r.flatMap(e=>e.items.map(({command:e})=>e)),groups:r}}function UK(e){return e.startsWith(`/`)&&!/\s/.test(e.slice(1))?e.slice(1).toLowerCase():null}function WK(e){let{value:t,commands:n,skillDormancy:r={},builtinDisabled:i=!1,onLoadCommands:a,onApply:o}=e,{t:s}=N(),c=UK(t),[l,u]=(0,d.useState)(!1),[f,p]=(0,d.useState)(0),m=(0,d.useRef)([]),h=(0,d.useRef)(!1),g=(0,d.useRef)(a);(0,d.useEffect)(()=>{g.current=a});let _=(0,d.useMemo)(()=>c===null?[]:[...i?[]:PK,...n??[]].filter(e=>{let t=e.name.toLowerCase(),n=BK(e,s).toLowerCase();return t.includes(c)||n.includes(c)}).sort((e,t)=>{let n=zK(e,c,s)-zK(t,c,s);return n===0?LK[e.source]-LK[t.source]||RK.compare(e.name,t.name):n}),[c,i,n,s]),{commands:v,groups:y}=(0,d.useMemo)(()=>HK(_,r),[_,r]),b=(0,d.useMemo)(()=>_.length===1?s(c?`chat.match`:`chat.command`):s(c?`chat.matches`:`chat.commands`,{count:_.length}),[_.length,c,s]);(0,d.useEffect)(()=>{if(c===null){u(!1),p(0),h.current=!1;return}u(!0),p(0);let e=g.current;!h.current&&e&&(h.current=!0,Promise.resolve(e()).catch(()=>{h.current=!1}))},[c]),Wi(()=>{f>=v.length&&p(Math.max(0,v.length-1))},[v.length,f]),(0,d.useEffect)(()=>{m.current.length=v.length},[v.length]),(0,d.useEffect)(()=>{l&&m.current[f]?.scrollIntoView({block:`nearest`,behavior:`smooth`})},[f,l]);let x=(0,d.useCallback)(e=>{let t=v.length-1;if(t<0)return 0;if(e===`left`)return Math.max(0,f-1);if(e===`right`)return Math.min(t,f+1);let n=m.current[f];if(!n)return e===`down`?Math.min(t,f+1):Math.max(0,f-1);let r=n.getBoundingClientRect(),i=r.left+r.width/2,a=r.top+r.height/2,o=-1,s=1/0;for(let n=0;n<=t;n+=1){if(n===f)continue;let t=m.current[n];if(!t)continue;let r=t.getBoundingClientRect(),c=r.top+r.height/2-a;if(e===`down`?c<=4:c>=-4)continue;let l=r.left+r.width/2,u=Math.abs(c)*1e3+Math.abs(l-i);u<s&&(o=n,s=u)}return o>=0?o:e===`down`?Math.min(t,f+1):Math.max(0,f-1)},[v.length,f]),S=(0,d.useCallback)(e=>{o(e),u(!1),p(0)},[o]),C=(0,d.useCallback)(e=>!l||c===null?!1:e.key===`ArrowDown`?(e.preventDefault(),p(x(`down`)),!0):e.key===`ArrowUp`?(e.preventDefault(),p(x(`up`)),!0):e.key===`ArrowRight`?(e.preventDefault(),p(x(`right`)),!0):e.key===`ArrowLeft`?(e.preventDefault(),p(x(`left`)),!0):e.key===`Escape`?(e.preventDefault(),u(!1),!0):(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey)&&v[f]?(e.preventDefault(),S(v[f]),!0):!1,[l,c,x,v,f,S]);return{open:l,query:c,filteredCount:_.length,countLabel:b,displayed:v,groups:y,activeIndex:f,setActiveIndex:p,itemRefs:m,apply:S,handleKeyDown:C}}function GK({palette:e,loading:t,skillDormancy:n}){let{t:r}=N();return e.open&&e.query!==null?(0,E.jsxs)(`div`,{"data-testid":`slash-palette`,style:{position:`absolute`,left:0,right:0,bottom:`calc(100% + 8px)`,zIndex:120,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 -6px 20px var(--shadow-color)`,overflow:`hidden`,maxHeight:`min(56vh, 460px)`},children:[(0,E.jsxs)(`div`,{style:{padding:`8px 10px`,borderBottom:`1px solid var(--border)`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:[(0,E.jsx)(`span`,{children:t?r(`chat.loadingCommands`):r(`chat.slashCommands`,{label:e.countLabel})}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`},children:r(`chat.tabEnter`)})]}),(0,E.jsx)(`div`,{style:{maxHeight:`calc(min(56vh, 460px) - 34px)`,overflowY:`auto`,padding:10},children:!t&&e.filteredCount===0?(0,E.jsx)(`div`,{style:{padding:`2px 2px 4px`,fontSize:`var(--text-base)`,color:`var(--text-dim)`},children:r(`chat.noCommands`)}):e.groups.map(t=>(0,E.jsxs)(`section`,{style:{marginBottom:12},children:[(0,E.jsxs)(`div`,{style:{position:`sticky`,top:-10,zIndex:1,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8,padding:`4px 0 6px`,background:`var(--bg)`,color:`var(--text-dim)`,fontSize:`var(--text-xs)`,fontWeight:600,textTransform:`uppercase`},children:[(0,E.jsx)(`span`,{children:r(IK[t.source])}),(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,fontWeight:500},children:t.items.length})]}),(0,E.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(220px, 1fr))`,gap:8},children:t.items.map(({command:t,index:i})=>{let a=i===e.activeIndex,o=VK(t,n);return(0,E.jsxs)(`button`,{ref:t=>{e.itemRefs.current[i]=t},type:`button`,onMouseDown:n=>{n.preventDefault(),e.apply(t)},onMouseEnter:()=>e.setActiveIndex(i),style:{width:`100%`,minWidth:0,minHeight:58,display:`flex`,flexDirection:`column`,gap:4,justifyContent:`center`,padding:`9px 10px`,border:`1px solid ${a?`var(--accent)`:`var(--border)`}`,borderRadius:7,background:a?`var(--bg-selected)`:`var(--bg-panel)`,color:`var(--text)`,cursor:`pointer`,textAlign:`left`,boxShadow:a?`0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)`:`none`},children:[(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-lg)`,fontFamily:`var(--font-mono)`,overflowWrap:`anywhere`,wordBreak:`break-word`,color:o?`var(--text-dim)`:void 0},children:[`/`,t.name,o&&(0,E.jsx)(`span`,{style:{marginLeft:6,padding:`0 4px`,border:`1px solid var(--border)`,borderRadius:3,fontSize:`var(--text-2xs)`,color:`var(--text-dim)`,whiteSpace:`nowrap`},children:r(`chat.dormant`)})]}),t.description&&(0,E.jsx)(`span`,{style:{display:`-webkit-box`,WebkitBoxOrient:`vertical`,WebkitLineClamp:2,overflow:`hidden`,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--text-dim)`},children:BK(t,r)})]},`${t.source}:${t.name}`)})})]},t.source))})]}):null}function KK({open:e,onOpenChange:t,onConfirm:n,title:r,hint:i,labelPlaceholder:a,messagePlaceholder:o,initialValue:s,testIdPrefix:c=`bind`}){let{t:l,locale:u}=N(),[f,p]=(0,d.useState)(()=>s?wt(s.label,u):``),[m,h]=(0,d.useState)(()=>s?wt(s.message,u):``),[g,_]=(0,d.useState)(s?.allowAppend??!1),v=f.trim()!==``&&m.trim()!==``,y=(0,d.useCallback)(()=>({nextLabel:s?Et(s.label,f.trim(),u):Tt(f.trim()),nextMessage:s?Et(s.message,m.trim(),u):Tt(m.trim())}),[s,f,m,u]),b=P(Te).value,x=P(Ee).value,S=(0,d.useMemo)(()=>(b?.skills??[]).map(e=>({name:`skill:${e.name}`,description:e.description,source:`skill`})),[b]),C=(0,d.useMemo)(()=>{let e=[];for(let t of x?.commands??[])(t.source===`extension`||t.source===`prompt`)&&e.push({name:t.name,description:t.description??``,source:t.source});return e},[x]),w=(0,d.useMemo)(()=>[...S,...C],[S,C]),T=(0,d.useMemo)(()=>{let e={};for(let t of b?.skills??[])e[t.name]=t.disableModelInvocation;return e},[b]),D=WK({value:m,commands:w,skillDormancy:T,onLoadCommands:()=>{Te.load().catch(e=>console.error(`[pi-web] load home skills:`,e)),Ee.load().catch(e=>console.error(`[pi-web] load home commands:`,e))},onApply:(0,d.useCallback)(e=>{h(`/${e.name} `)},[])});return(0,E.jsx)(jS,{open:e,onOpenChange:t,children:(0,E.jsxs)(FS,{className:`sm:max-w-md`,showCloseButton:!0,onEscapeKeyDown:e=>{D.open&&D.query!==null&&e.preventDefault()},children:[(0,E.jsx)(IS,{style:{fontWeight:700,fontSize:`var(--text-2xl)`,color:`var(--text)`},children:r}),(0,E.jsx)(LS,{style:{fontSize:`var(--text-base)`,color:`var(--text-dim)`},children:i}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10,marginTop:4},children:[(0,E.jsxs)(`label`,{style:{display:`flex`,flexDirection:`column`,gap:4},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:l(`config.widgets.label`)}),(0,E.jsx)(yG,{"data-testid":`${c}-label`,value:f,onChange:e=>p(e.target.value),placeholder:a,autoFocus:!0})]}),(0,E.jsxs)(`label`,{style:{display:`flex`,flexDirection:`column`,gap:4},children:[(0,E.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:6,fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:[l(`config.widgets.message`),(0,E.jsx)(qi,{label:l(`config.widgets.messageTooltip`),children:(0,E.jsx)(`span`,{"aria-label":l(`config.widgets.messageTooltip`),style:{display:`inline-flex`,cursor:`help`,color:`var(--text-dim)`},children:(0,E.jsx)(ni,{size:14,strokeWidth:2})})})]}),(0,E.jsxs)(`div`,{style:{position:`relative`},children:[(0,E.jsx)(yG,{"data-testid":`${c}-message`,value:m,onChange:e=>h(e.target.value),placeholder:o,onKeyDown:e=>{if(!D.handleKeyDown(e)&&e.key===`Enter`&&v){let{nextLabel:e,nextMessage:t}=y();n(e,t,g),p(``),h(``),_(!1)}}}),(0,E.jsx)(GK,{palette:D,skillDormancy:T})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:l(`config.widgets.sendMode`)}),(0,E.jsx)(XS,{testId:`${c}-append`,value:g?`fill`:`send`,onChange:e=>_(e===`fill`),options:[{value:`send`,label:l(`config.widgets.sendImmediately`)},{value:`fill`,label:l(`config.widgets.fillToChatInput`)}]})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,marginTop:12},children:[(0,E.jsx)(AS,{type:`button`,variant:`outline`,className:`h-8 px-3 text-xs`,onClick:()=>t(!1),children:l(`i18n.cancel`)}),(0,E.jsx)(AS,{type:`button`,"data-testid":`${c}-confirm`,className:`h-8 px-3 text-xs`,disabled:!v,style:{cursor:v?`pointer`:`default`,opacity:v?1:.5},onClick:()=>{let{nextLabel:e,nextMessage:t}=y();n(e,t,g),p(``),h(``),_(!1)},children:l(`config.widgets.confirm`)})]})]})})}function qK({messages:e,onRemove:t,onEdit:n,chipTestIdPrefix:r}){let{locale:i}=N();return e.length===0?null:(0,E.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6,marginTop:8,paddingTop:8,borderTop:`1px solid var(--border)`},children:e.map((e,a)=>{let o=wt(e.label,i),s=wt(e.message,i);return(0,E.jsx)(qi,{label:s,wrapperStyle:{display:`inline-flex`,minWidth:0},children:(0,E.jsx)(AG,{testId:`${r}-${a}`,label:o,title:s,onRemove:t?()=>t(a):void 0,onClick:n?()=>n(a):void 0})},a)})})}function JK({messages:e,onAdd:t,onRemove:n,onUpdate:r,bindOpen:i,onBindOpenChange:a,ns:o,bindTestIdPrefix:s,editTestIdPrefix:c,chipTestIdPrefix:l,bindHintArgs:u,emptyLabel:f}){let{t:p,locale:m}=N(),[h,g]=(0,d.useState)(null),[_,v]=(0,d.useState)(null),y=h===null?null:e[h],b=_===null?null:e[_];return(0,E.jsxs)(E.Fragment,{children:[e.length===0?f?(0,E.jsx)(`div`,{style:{padding:`24px 16px`,textAlign:`center`,color:`var(--text-dim)`,fontSize:`var(--text-lg)`,lineHeight:1.6},children:f}):null:(0,E.jsx)(qK,{messages:e,onRemove:e=>g(e),onEdit:e=>v(e),chipTestIdPrefix:l}),i&&(0,E.jsx)(KK,{open:!0,onOpenChange:a,onConfirm:(e,n,r)=>{t({label:e,message:n,allowAppend:r}),a(!1)},testIdPrefix:s,title:p(`config.${o}.bindTitle`),hint:p(`config.${o}.bindHint`,u),labelPlaceholder:p(`config.widgets.labelPlaceholder`),messagePlaceholder:p(`config.widgets.messagePlaceholder`)}),h!==null&&y&&(0,E.jsx)(YS,{open:!0,title:p(`config.${o}.unbindTitle`),description:(0,E.jsxs)(`span`,{style:{display:`block`},children:[(0,E.jsx)(`span`,{style:{display:`block`},children:p(`config.${o}.unbindConfirm`,{label:wt(y.label,m)})}),(0,E.jsx)(`span`,{style:{display:`block`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,padding:`6px 8px`,borderRadius:5,background:`var(--bg)`,border:`1px solid var(--border)`,overflowWrap:`anywhere`,marginTop:6},children:wt(y.message,m)})]}),confirmText:p(`config.${o}.unbind`),cancelText:p(`i18n.cancel`),destructive:!0,onCancel:()=>g(null),onConfirm:()=>{n(h),g(null)}}),_!==null&&b&&(0,E.jsx)(KK,{open:!0,onOpenChange:e=>!e&&v(null),onConfirm:(e,t,n)=>{r(_,{label:e,message:t,allowAppend:n}),v(null)},initialValue:b,testIdPrefix:c,title:p(`config.${o}.editTitle`),hint:p(`config.${o}.editHint`),labelPlaceholder:p(`config.widgets.labelPlaceholder`),messagePlaceholder:p(`config.widgets.messagePlaceholder`)},c)]})}function YK(){let{t:e}=N(),{startScreenMessages:t,addStartScreenMessage:n,removeStartScreenMessage:r,updateStartScreenMessage:i,resetStartScreenMessages:a}=ze(),[o,s]=(0,d.useState)(!1);return(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`},children:(0,E.jsxs)(`div`,{style:{flex:1,minHeight:0,overflowY:`auto`,padding:10,display:`flex`,flexDirection:`column`,gap:8},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:e(`config.startScreen.hint`)}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,E.jsx)(qi,{label:e(`config.startScreen.resetHint`),children:(0,E.jsxs)(`button`,{type:`button`,"data-testid":`start-screen-reset`,onClick:a,style:{flexShrink:0,display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:[(0,E.jsx)(gi,{size:13,"aria-hidden":!0}),e(`config.startScreen.reset`)]})}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`start-screen-bind`,onClick:()=>s(!0),style:{flexShrink:0,display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:[(0,E.jsx)(ii,{size:13,"aria-hidden":!0}),e(`config.startScreen.bind`)]})]})]}),(0,E.jsx)(JK,{messages:t,onAdd:n,onRemove:r,onUpdate:i,bindOpen:o,onBindOpenChange:s,ns:`startScreen`,bindTestIdPrefix:`start-screen-bind`,editTestIdPrefix:`start-screen-edit`,chipTestIdPrefix:`start-screen-bound`,emptyLabel:e(`config.startScreen.empty`)})]})})}var XK=new Intl.Collator(void 0,{numeric:!0,sensitivity:`base`});function ZK(e,t){return XK.compare(`${e.provider}/${e.name||e.modelId}`,`${t.provider}/${t.name||t.modelId}`)}function QK(e,t){let n=t.trim().toLocaleLowerCase();return n?e.filter(e=>`${e.provider}/${e.name}`.toLocaleLowerCase().includes(n)):e}function $K({value:e,options:t,onChange:n,disabled:r,placeholder:i,variant:a=`form`,isAutoSelection:o}){let{t:s}=N(),[c,l]=(0,d.useState)(!1),[u,f]=(0,d.useState)(``),[m,h]=(0,d.useState)(0),[g,_]=(0,d.useState)(null),v=(0,d.useRef)(null),y=(0,d.useRef)(null),b=(0,d.useRef)(null),x=(0,d.useRef)(null),S=QK([...t].sort(ZK),u),C=e?t.find(t=>t.provider===e.provider&&t.modelId===e.modelId)?.name??e.modelId:null;(0,d.useEffect)(()=>{b.current?.scrollIntoView({block:`nearest`})},[m,u]),(0,d.useEffect)(()=>{if(!c)return;let e=e=>{v.current?.contains(e.target)||y.current?.contains(e.target)||(l(!1),f(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[c]);let w=t=>{l(!1),f(``),(e?.provider!==t.provider||e?.modelId!==t.modelId||o)&&n(t.provider,t.modelId)};return(0,E.jsxs)(`div`,{style:{position:`relative`,display:a===`chat`?`flex`:`block`,minWidth:0,flex:a===`chat`?1:void 0},children:[(0,E.jsxs)(`button`,{ref:v,type:`button`,disabled:r,onClick:e=>{if(r)return;if(c){l(!1),f(``);return}let t=e.currentTarget.getBoundingClientRect();_({top:t.top,left:t.left,width:t.width}),l(!0),h(0),requestAnimationFrame(()=>x.current?.focus())},style:a===`chat`?{display:`flex`,alignItems:`center`,gap:6,padding:`8px 12px`,height:32,minWidth:0,maxWidth:`100%`,overflow:`hidden`,background:`none`,border:`none`,borderRadius:9,color:`var(--text-muted)`,cursor:r?`not-allowed`:`pointer`,fontSize:`var(--text-base)`,opacity:r?.5:1}:{display:`flex`,alignItems:`center`,gap:6,padding:`6px 10px`,height:32,width:320,maxWidth:`100%`,background:`var(--bg-input)`,border:`1px solid var(--border)`,borderRadius:6,color:e?`var(--text)`:`var(--text-dim)`,cursor:r?`not-allowed`:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`},className:r?void 0:`hover-shift`,"aria-expanded":c,children:[a===`chat`&&(0,E.jsx)(Gr,{size:p[`2xl`],style:{color:`var(--status-info)`,flexShrink:0}}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,minWidth:0,flex:a===`form`?1:void 0},children:e&&C?a===`chat`?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`span`,{style:{color:`var(--text-dim)`},children:[e.provider,`/`]}),(0,E.jsx)(`span`,{style:{fontWeight:700,color:`var(--text)`},children:C})]}):`${e.provider}/${C}`:i??(t.length>0?s(`chat.filterModels`):s(`git.commitModel.noModels`))})]}),c&&g&&(0,E.jsxs)(`div`,{ref:y,"data-testid":`model-dropdown`,style:{position:`fixed`,zIndex:500,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 -4px 16px var(--shadow-color)`,overflow:`hidden`,display:`flex`,flexDirection:`column`,...a===`chat`?(()=>{let e=window.visualViewport?.height??window.innerHeight,t=e-g.top+6,n=Math.max(120,Math.min(g.top-8,e*.6));return{bottom:t,left:g.left,width:`max-content`,minWidth:g.width,maxHeight:n}})():{top:g.top+32+4,left:g.left,width:g.width,maxHeight:280}},children:[(0,E.jsx)(`div`,{style:{padding:6,borderBottom:`1px solid var(--border)`},children:(0,E.jsx)(`input`,{ref:x,value:u,onChange:e=>{f(e.target.value),h(0)},onKeyDown:e=>{if(e.key===`Escape`)f(``),l(!1);else if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),S.length===0)return;h(t=>e.key===`ArrowDown`?(t+1)%S.length:(t-1+S.length)%S.length)}else if(e.key===`Enter`){let e=S[m]??S[0];e&&w(e)}},placeholder:s(`chat.filterModels`),autoComplete:`off`,spellCheck:!1,style:{width:`100%`,padding:`6px 8px`,background:`var(--bg-hover)`,border:`none`,borderRadius:6,color:`var(--text)`,fontSize:`var(--text-base)`,outline:`none`}})}),(0,E.jsx)(`div`,{style:{minHeight:0,overflowY:`auto`},children:S.length===0?(0,E.jsx)(`div`,{style:{padding:`8px 12px`,color:`var(--text-dim)`,fontSize:`var(--text-base)`,whiteSpace:`nowrap`},children:u.trim()?s(`chat.noMatchingModels`):s(`git.commitModel.noModels`)}):S.map((t,n)=>{let r=e?.provider===t.provider&&e?.modelId===t.modelId,i=n===m;return(0,E.jsxs)(`button`,{ref:i?b:void 0,"data-highlighted":i?`true`:void 0,onClick:()=>w(t),onMouseEnter:()=>h(n),style:{display:`flex`,alignItems:`center`,gap:8,width:`100%`,padding:`7px 12px`,background:i?`var(--bg-hover)`:r?`var(--bg-selected)`:`none`,border:`none`,color:r?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`,fontWeight:r?600:400,whiteSpace:`nowrap`},children:[r?(0,E.jsx)(Rr,{size:p.xs,strokeWidth:4.8,style:{flexShrink:0}}):(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsxs)(`span`,{style:{display:`inline`},children:[(0,E.jsxs)(`span`,{style:{color:`var(--text-dim)`},children:[t.provider,`/`]}),(0,E.jsx)(`span`,{style:{fontWeight:700},children:t.name})]})]},`${t.provider}:${t.modelId}`)})})]})]})}function eq(e){fetch(`/api/preferences`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({preferences:e})}).catch(e=>Ke(e,`save git preferences`)).finally(()=>void ye.refresh().catch(e=>console.error(`[pi-web] refresh preferences:`,e)))}var tq={};function nq(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(ye.subscribe,()=>ye.get()?.preferences??tq,()=>tq),n=(0,d.useSyncExternalStore)(_e.subscribe,()=>_e.get()??null),r=t,i=r.commitMessageUseCurrentModel===!0,a=typeof r.commitMessageModel==`string`?r.commitMessageModel:``,o=typeof r.commitMessageMaxTokens==`number`&&Number.isFinite(r.commitMessageMaxTokens)?r.commitMessageMaxTokens:512,s=r.commitMessageAutoGenerateOnEmpty!==!1,c=r.commitStageAllConfirm!==!1,l=typeof r.gitAutoFetchIntervalSec==`number`&&Number.isFinite(r.gitAutoFetchIntervalSec)?r.gitAutoFetchIntervalSec:60,u=(n?.modelList??[]).map(e=>({provider:e.provider,modelId:e.id,name:e.name})),f=e=>{eq({commitMessageUseCurrentModel:e})},p=(e,t)=>{eq({commitMessageModel:`${e}/${t}`})},m=e=>{let t=Number(e);Number.isFinite(t)&&eq({commitMessageMaxTokens:Math.min(4096,Math.max(64,Math.round(t)))})},h=e=>{eq({commitMessageAutoGenerateOnEmpty:e})},g=e=>{eq({commitStageAllConfirm:e})},_=e=>{if(e.trim()===``)return;let t=Number(e);Number.isFinite(t)&&eq({gitAutoFetchIntervalSec:Math.min(3600,Math.max(0,Math.round(t)))})},v=(()=>{if(!a)return null;let e=a.indexOf(`/`);return e===-1?null:{provider:a.slice(0,e),modelId:a.slice(e+1)}})();return(0,E.jsxs)(`div`,{style:{height:`100%`,overflowY:`auto`,padding:`18px 20px 40px`,display:`flex`,flexDirection:`column`,gap:16,maxWidth:640},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12,padding:`14px 16px`,border:`1px solid var(--border)`,borderRadius:10,background:`var(--bg-panel)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`,lineHeight:1.4},children:e(`git.commitSectionTitle`)}),(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:(0,E.jsx)(ea,{label:e(`git.commitConfirmStageAll`),hint:e(`git.commitConfirmStageAllHint`),children:(0,E.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:8,cursor:`pointer`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`input`,{type:`checkbox`,"data-testid":`git-stage-all-confirm-toggle`,checked:c,onChange:e=>g(e.target.checked)}),(0,E.jsx)(`span`,{children:e(c?`git.commitConfirmStageAllOn`:`git.commitConfirmStageAllOff`)})]})})})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12,padding:`14px 16px`,border:`1px solid var(--border)`,borderRadius:10,background:`var(--bg-panel)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`,lineHeight:1.4},children:e(`git.groupTitle`)}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,E.jsx)(ea,{label:e(`git.commitModel.followCurrent`),hint:e(`git.commitModel.followCurrentHint`),children:(0,E.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:8,cursor:`pointer`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>f(e.target.checked)}),(0,E.jsx)(`span`,{children:e(i?`git.commitModel.followCurrentOn`:`git.commitModel.followCurrentOff`)})]})}),!i&&(0,E.jsx)(ea,{label:e(`git.commitModel.fixedModel`),hint:e(`git.commitModel.fixedModelHint`),children:(0,E.jsx)($K,{value:v,options:u,onChange:p,variant:`form`,placeholder:e(`git.commitModel.selectPlaceholder`)})}),!i&&!a&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--status-warning)`,padding:`0 2px`},children:e(`git.commitModel.notConfiguredHint`)}),(0,E.jsx)(ea,{label:e(`git.commitModel.autoGenerateOnEmpty`),hint:e(`git.commitModel.autoGenerateOnEmptyHint`),children:(0,E.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:8,cursor:`pointer`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>h(e.target.checked)}),(0,E.jsx)(`span`,{children:e(s?`git.ai.autoGenerateOn`:`git.ai.autoGenerateOff`)})]})}),(0,E.jsx)(ea,{label:e(`git.commitModel.maxTokens`),hint:e(`git.commitModel.maxTokensHint`),children:(0,E.jsx)(`input`,{type:`number`,min:64,max:4096,step:64,value:o,onChange:e=>m(e.target.value),onBlur:e=>{let t=Number(e.target.value);(!Number.isFinite(t)||t<64||t>4096)&&(e.target.value=String(o))},style:{width:120,height:28,padding:`0 8px`,fontSize:`var(--text-base)`,color:`var(--text)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,outline:`none`}})}),(0,E.jsx)(ea,{label:e(`git.autoFetchInterval`),hint:e(`git.autoFetchIntervalHint`),children:(0,E.jsx)(`input`,{type:`number`,"data-testid":`git-auto-fetch-interval`,min:0,max:3600,step:10,value:l,onChange:e=>_(e.target.value),onBlur:e=>{if(e.target.value.trim()===``){e.target.value=String(l);return}let t=Number(e.target.value);(!Number.isFinite(t)||t<0||t>3600)&&(e.target.value=String(l))},style:{width:120,height:28,padding:`0 8px`,fontSize:`var(--text-base)`,color:`var(--text)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,outline:`none`}})})]})]})]})}function rq(e){fetch(`/api/model-thinking`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}).catch(e=>Ke(e,`save model thinking preferences`)).finally(()=>void De.refresh().catch(e=>console.error(`[pi-web] refresh model thinking:`,e)))}function iq({value:e,providers:t,placeholder:n,onChange:r}){let{t:i}=N(),[a,o]=(0,d.useState)(!1),[s,c]=(0,d.useState)(``),l=(0,d.useRef)(null),u=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(!a)return;let e=e=>{l.current?.contains(e.target)||(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,d.useEffect)(()=>{a&&requestAnimationFrame(()=>u.current?.focus())},[a]);let f=s.trim().toLocaleLowerCase(),m=f?t.filter(e=>e.toLocaleLowerCase().includes(f)):t,h=e=>{let t=e.trim();t&&(r(t),o(!1),c(``))};return(0,E.jsxs)(`div`,{ref:l,style:{position:`relative`,minWidth:220},children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{if(a){o(!1),c(``);return}c(``),o(!0)},style:{display:`flex`,alignItems:`center`,gap:6,padding:`6px 10px`,height:32,width:220,maxWidth:`100%`,background:`var(--bg-input)`,border:`1px solid var(--border)`,borderRadius:6,color:e?`var(--text)`:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`},className:`hover-shift`,"aria-expanded":a,children:[(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:e||n}),(0,E.jsx)(zr,{size:p.sm,style:{color:`var(--text-dim)`,flexShrink:0}})]}),a&&(0,E.jsxs)(`div`,{style:{position:`absolute`,top:36,left:0,width:`max-content`,minWidth:`100%`,zIndex:500,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 -4px 16px var(--shadow-color)`,overflow:`hidden`,display:`flex`,flexDirection:`column`,maxHeight:280},children:[(0,E.jsx)(`div`,{style:{padding:6,borderBottom:`1px solid var(--border)`,position:`sticky`,top:0,background:`var(--bg)`,zIndex:1},children:(0,E.jsx)(`input`,{ref:u,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`?(o(!1),c(``)):e.key===`ArrowDown`||e.key===`ArrowUp`?e.preventDefault():e.key===`Enter`&&h(m[0]??s)},placeholder:i(`i18n.searchProviders`),autoComplete:`off`,spellCheck:!1,style:{width:`100%`,padding:`6px 8px`,background:`var(--bg-hover)`,border:`none`,borderRadius:6,color:`var(--text)`,fontSize:`var(--text-base)`,outline:`none`}})}),(0,E.jsxs)(`div`,{style:{overflowY:`auto`},children:[t.filter(e=>!f||e.toLocaleLowerCase().includes(f)).map(t=>{let n=t===e;return(0,E.jsxs)(`button`,{type:`button`,onClick:()=>h(t),style:{display:`flex`,alignItems:`center`,gap:8,width:`100%`,padding:`7px 12px`,background:n?`var(--bg-selected)`:`none`,border:`none`,color:n?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`,fontWeight:n?600:400,whiteSpace:`nowrap`},children:[n?(0,E.jsx)(Rr,{size:p.xs,strokeWidth:4.8,style:{flexShrink:0}}):(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(`span`,{children:t})]},t)}),f&&!t.some(e=>e.toLocaleLowerCase()===f)&&(0,E.jsxs)(`button`,{type:`button`,onClick:()=>h(s),style:{display:`flex`,alignItems:`center`,gap:8,width:`100%`,padding:`7px 12px`,background:`none`,border:`none`,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`,whiteSpace:`nowrap`},children:[(0,E.jsx)(fi,{size:p.xs,style:{flexShrink:0}}),(0,E.jsx)(`span`,{children:s.trim()})]}),!f&&t.length===0&&(0,E.jsx)(`div`,{style:{padding:`8px 12px`,color:`var(--text-dim)`,fontSize:`var(--text-base)`},children:i(`chat.noMatchingModels`)})]})]})]})}function aq({value:e,onChange:t,ariaLabel:n,width:r=225}){let{t:i}=N();return(0,E.jsxs)(ch,{value:e,onValueChange:e=>t(e),children:[(0,E.jsx)(uh,{size:`sm`,style:{width:r,background:`var(--bg-input)`,flexShrink:0},"aria-label":n,children:(0,E.jsx)(lh,{})}),(0,E.jsx)(dh,{children:sa.map(e=>(0,E.jsxs)(fh,{value:e,className:`text-xs`,children:[(0,E.jsx)(`span`,{className:`font-mono`,children:e}),(0,E.jsx)(`span`,{style:{color:`var(--text-muted)`},children:i(la[e])})]},e))})]})}var oq={};function sq(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(De.subscribe,()=>De.get()??oq,()=>oq),n=(0,d.useSyncExternalStore)(_e.subscribe,()=>_e.get()??null);(0,d.useEffect)(()=>{De.load().catch(e=>console.error(`[pi-web] load model thinking:`,e))},[]);let r=(0,d.useMemo)(()=>n?.modelList??[],[n]),i=(0,d.useMemo)(()=>r.map(e=>({provider:e.provider,modelId:e.id,name:e.name})),[r]),a=(0,d.useMemo)(()=>{let e=new Set;for(let t of r)e.add(t.provider);for(let n of Object.keys(t.providers??{}))e.add(n);return Array.from(e).sort((e,t)=>e.localeCompare(t))},[r,t.providers]),o=(0,d.useMemo)(()=>Object.entries(t.models??{}).sort(([e],[t])=>e.localeCompare(t)),[t.models]),s=(0,d.useMemo)(()=>Object.entries(t.providers??{}).sort(([e],[t])=>e.localeCompare(t)),[t.providers]),c=(e,n)=>{rq({...t,models:{...t.models??{},[e]:n}})},l=e=>{let n={...t.models??{}};delete n[e];let r={...t};Object.keys(n).length===0?delete r.models:r.models=n,rq(r)},u=(e,n)=>{rq({...t,providers:{...t.providers??{},[e]:n}})},f=e=>{let n={...t.providers??{}};delete n[e];let r={...t};Object.keys(n).length===0?delete r.providers:r.providers=n,rq(r)},[p,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(`medium`),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(`medium`);return(0,E.jsxs)(`div`,{style:{height:`100%`,overflowY:`auto`,padding:`18px 20px 40px`,display:`flex`,flexDirection:`column`,gap:16,maxWidth:720},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-muted)`,lineHeight:1.6},children:e(`modelThinking.desc`)}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12,padding:`14px 16px`,border:`1px solid var(--border)`,borderRadius:10,background:`var(--bg-panel)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`},children:e(`modelThinking.byModel`)}),o.length===0?(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,padding:`4px 0`},children:e(`modelThinking.emptyModel`)}):(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:o.map(([t,n])=>(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:8,background:`var(--bg)`},children:[(0,E.jsx)(`span`,{style:{flex:1,fontSize:`var(--text-sm)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:t}),(0,E.jsx)(aq,{value:n,onChange:e=>c(t,e),ariaLabel:`${t} ${e(`i18n.thinking`)}`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>l(t),title:e(`common.delete`),style:{width:28,height:28,display:`flex`,alignItems:`center`,justifyContent:`center`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`,color:`var(--text-muted)`,cursor:`pointer`},children:(0,E.jsx)(Ti,{size:14})})]},t))}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,flexWrap:`wrap`,marginTop:4},children:[(0,E.jsx)($K,{value:p?{provider:p.provider,modelId:p.modelId}:null,options:i,onChange:(e,t)=>{let n=i.find(n=>n.provider===e&&n.modelId===t);m(n??{provider:e,modelId:t,name:`${e}/${t}`})},variant:`form`,placeholder:e(`modelThinking.selectModelPlaceholder`)}),(0,E.jsx)(aq,{value:h,onChange:g,ariaLabel:e(`modelThinking.byModel`)}),(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{if(!p)return;let e=`${p.provider}/${p.modelId}`;rq({...t,models:{...t.models??{},[e]:h}}),m(null)},disabled:!p,style:{height:32,padding:`0 12px`,display:`flex`,alignItems:`center`,gap:6,border:`1px solid var(--accent)`,borderRadius:6,background:p?`var(--accent)`:`var(--bg)`,color:p?`white`:`var(--text-dim)`,cursor:p?`pointer`:`not-allowed`,fontSize:`var(--text-sm)`,fontWeight:600},children:[(0,E.jsx)(fi,{size:14}),` `,e(`common.add`)]})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12,padding:`14px 16px`,border:`1px solid var(--border)`,borderRadius:10,background:`var(--bg-panel)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`},children:e(`modelThinking.byProvider`)}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-muted)`,lineHeight:1.5},children:e(`modelThinking.byProviderHint`)}),s.length===0?(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,padding:`4px 0`},children:e(`modelThinking.emptyProvider`)}):(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:s.map(([t,n])=>(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:8,background:`var(--bg)`},children:[(0,E.jsx)(`span`,{style:{flex:1,fontSize:`var(--text-sm)`,color:`var(--text)`,fontFamily:`var(--font-mono)`},children:t}),(0,E.jsx)(aq,{value:n,onChange:e=>u(t,e),ariaLabel:`${t} ${e(`i18n.thinking`)}`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>f(t),title:e(`common.delete`),style:{width:28,height:28,display:`flex`,alignItems:`center`,justifyContent:`center`,border:`1px solid var(--border)`,borderRadius:6,background:`var(--bg-panel)`,color:`var(--text-muted)`,cursor:`pointer`},children:(0,E.jsx)(Ti,{size:14})})]},t))}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,flexWrap:`wrap`,marginTop:4},children:[(0,E.jsx)(iq,{value:_,providers:a,placeholder:e(`modelThinking.selectProviderPlaceholder`),onChange:v}),(0,E.jsx)(aq,{value:y,onChange:b,ariaLabel:e(`modelThinking.byProvider`)}),(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{let e=_.trim();e&&(rq({...t,providers:{...t.providers??{},[e]:y}}),v(``))},disabled:!_.trim(),style:{height:32,padding:`0 12px`,display:`flex`,alignItems:`center`,gap:6,border:`1px solid var(--accent)`,borderRadius:6,background:_.trim()?`var(--accent)`:`var(--bg)`,color:_.trim()?`white`:`var(--text-dim)`,cursor:_.trim()?`pointer`:`not-allowed`,fontSize:`var(--text-sm)`,fontWeight:600},children:[(0,E.jsx)(fi,{size:14}),` `,e(`common.add`)]})]})]}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,lineHeight:1.6,padding:`0 2px`},children:e(`modelThinking.footerHint`)})]})}var cq=[`models`,`plugins`,`skills`,`session`,`appearance`,`startScreen`,`git`,`updates`,`modelThinking`,`advanced`];function lq({section:e,onSectionChange:t,cwd:n,sessionId:r,onClose:i,onOpenFile:a,defaultThinkingLevel:o,onDefaultThinkingLevelChange:s,compaction:c,onCompactionChange:l,retry:u,onRetryChange:f,defaultProjectTrust:p,onDefaultProjectTrustChange:m,subagents:h,onSubagentsChange:g,sidebarWidth:_,onSidebarWidthChange:v,widgetPanelWidth:y,onWidgetPanelWidthChange:b,modelConfigFocus:x}){let{t:S}=N(),{value:C}=P(xe),{value:w}=P(Te),{value:T}=P(we);(0,d.useEffect)(()=>{xe.load().catch(e=>console.error(`[pi-web] load home plugins:`,e)),Te.load().catch(e=>console.error(`[pi-web] load home skills:`,e)),Ce(n),we.load().catch(e=>console.error(`[pi-web] load updates:`,e))},[n]);let D=e=>{switch(e){case`models`:return S(`common.models`);case`plugins`:return S(`common.plugins`);case`skills`:return S(`common.skills`);case`startScreen`:return S(`config.section.startScreen`);case`session`:return S(`config.section.session`);case`appearance`:return S(`config.section.appearance`);case`advanced`:return S(`config.section.advanced`);case`git`:return S(`config.section.git`);case`updates`:return S(`config.section.updates`);case`modelThinking`:return S(`config.section.modelThinking`)}},O=e=>{switch(e){case`models`:return(0,E.jsx)(Gr,{size:15});case`plugins`:return(0,E.jsx)(pi,{size:15});case`skills`:return(0,E.jsx)(ji,{size:15});case`startScreen`:return(0,E.jsx)(Ni,{size:15});case`session`:return(0,E.jsx)(xi,{size:15});case`appearance`:return(0,E.jsx)(ci,{size:15});case`advanced`:return(0,E.jsx)(yi,{size:15});case`git`:return(0,E.jsx)(Zr,{size:15});case`updates`:return(0,E.jsx)(Kr,{size:15});case`modelThinking`:return(0,E.jsx)(ri,{size:15})}},k=T===null?void 0:Fe(T),A=cq.map(e=>({id:e,label:D(e),icon:O(e),badge:e===`updates`&&k?k:void 0,closable:!1}));return(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,overflow:`hidden`,background:`var(--bg)`},children:(0,E.jsxs)(br,{tabs:A,activeTabId:e,onSelectTab:e=>t(e),onCloseTab:()=>{},children:[(0,E.jsx)(vr,{id:`models`,children:(0,E.jsx)(cC,{onClose:i,pane:!0,initialSelection:x?{provider:x.provider,modelId:x.modelId}:null})}),(0,E.jsx)(vr,{id:`plugins`,children:n?(0,E.jsx)(vK,{cwd:n,sessionId:r,onClose:i,onOpenFile:a,pane:!0,globalPackages:C?.packages??[],globalExtensionFilters:C?.extensionFilters??[]}):(0,E.jsx)(uq,{text:S(`config.section.requiresCwd`)})}),(0,E.jsx)(vr,{id:`skills`,children:n?(0,E.jsx)(NK,{cwd:n,onClose:i,pane:!0,homeSkills:w?.skills??[]}):(0,E.jsx)(uq,{text:S(`config.section.requiresCwd`)})}),(0,E.jsx)(vr,{id:`startScreen`,children:(0,E.jsx)(YK,{})}),(0,E.jsx)(vr,{id:`session`,children:(0,E.jsx)(vh,{defaultThinkingLevel:o,onDefaultThinkingLevelChange:s,compaction:c,onCompactionChange:l,retry:u,onRetryChange:f,defaultProjectTrust:p,onDefaultProjectTrustChange:m,subagents:h,onSubagentsChange:g})}),(0,E.jsx)(vr,{id:`appearance`,children:(0,E.jsx)(na,{sidebarWidth:_,onSidebarWidthChange:v,widgetPanelWidth:y,onWidgetPanelWidthChange:b})}),(0,E.jsx)(vr,{id:`advanced`,children:(0,E.jsx)(xh,{})}),(0,E.jsx)(vr,{id:`git`,children:(0,E.jsx)(nq,{})}),(0,E.jsx)(vr,{id:`updates`,children:(0,E.jsx)(Ui,{cwd:n})}),(0,E.jsx)(vr,{id:`modelThinking`,children:(0,E.jsx)(sq,{})})]})})}function uq({text:e}){return(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-muted)`,fontSize:`var(--text-lg)`,padding:24,textAlign:`center`},children:e})}var dq=`chat`,fq=`config`,pq=`widgets`,mq=e=>`file:${e}`;function hq(e){if(!e||typeof e!=`object`)return null;let t=e;return t.kind===`config`?typeof t.section==`string`&&cq.includes(t.section)?{kind:`config`,section:t.section}:null:t.kind===`file`&&typeof t.filePath==`string`&&t.filePath&&typeof t.label==`string`?{kind:`file`,filePath:t.filePath,label:t.label,sourceSessionId:typeof t.sourceSessionId==`string`?t.sourceSessionId:null,initialDisplayMode:t.initialDisplayMode===`source`||t.initialDisplayMode===`preview`||t.initialDisplayMode===`diff`?t.initialDisplayMode:void 0}:null}var gq=e=>Array.isArray(e)?e.map(hq).filter(e=>e!==null):[];function _q(e){return{id:mq(e.filePath),label:e.label,filePath:e.filePath,sourceSessionId:e.sourceSessionId,initialDisplayMode:e.initialDisplayMode}}function vq(){try{if(localStorage.getItem(`pi:openTabs`)!==null)return[];let e=[],t=JSON.parse(localStorage.getItem(`pi:fileTabs`)??`[]`);if(e.push(...gq(Array.isArray(t)?t.map(e=>({kind:`file`,...typeof e==`object`&&e?e:{}})):[])),localStorage.getItem(`pi:configTabOpen`)===`1`){let t=hq({kind:`config`,section:localStorage.getItem(`pi:configSection`)??`models`});t&&e.unshift(t)}for(let e of[`pi:fileTabs`,`pi:activeFileTab`,`pi:configTabOpen`,`pi:configTabActive`,`pi:configSection`])localStorage.removeItem(e);return e}catch{return[]}}function yq(){try{return localStorage.getItem(`pi:openTabsActive`)===null?localStorage.getItem(`pi:configTabActive`)===`1`?fq:localStorage.getItem(`pi:activeFileTab`):null}catch{return null}}function bq({onSessionSelected:e,onRefreshModels:t}){let[n,r]=Er(`pi:openTabs`,vq,gq),[i,a]=Er(`pi:openTabsActive`,yq),[o,s]=(0,d.useState)(null),c=n.find(e=>e.kind===`config`),l=c!==void 0,u=c?.kind===`config`?c.section:`models`,f=(0,d.useCallback)(e=>{r(t=>t.map(t=>t.kind===`config`?{kind:`config`,section:e}:t))},[r]),p=(0,d.useMemo)(()=>n.filter(e=>e.kind===`file`).map(_q),[n]),m=i===null?null:n.find(e=>e.kind===`file`&&mq(e.filePath)===i)??null,h=l&&i===`config`,g=(0,d.useCallback)((t,n,i)=>{let o=i?.sourceSessionId,s=i?.modeHint,c=mq(t);r(e=>{let r=e.find(e=>e.kind===`file`&&e.filePath===t);if(!r)return[...e,{kind:`file`,filePath:t,label:n,sourceSessionId:o,initialDisplayMode:s}];let i=!o||r.sourceSessionId===o,a=!s||r.initialDisplayMode===s;return i&&a?e:e.map(e=>e.kind!==`file`||e.filePath!==t?e:{...e,sourceSessionId:o??e.sourceSessionId,initialDisplayMode:s??e.initialDisplayMode})}),e?.(),a(c)},[e,r,a]),_=(0,d.useCallback)(e=>{r(t=>t.filter(t=>t.kind!==`file`||mq(t.filePath)!==e)),a(t=>{if(t!==e)return t;let r=n.filter(t=>t.kind===`file`&&mq(t.filePath)!==e);return r.length>0?mq(r[r.length-1].filePath):null})},[n,r,a]),v=(0,d.useCallback)(t=>{r(e=>{let n=e.findIndex(e=>e.kind===`config`),r=t??(n>=0&&e[n].kind===`config`?e[n].section:`models`);if(n>=0){let t=[...e];return t[n]={kind:`config`,section:r},t}return[...e,{kind:`config`,section:r}]}),e?.(),a(fq)},[e,r,a]),y=(0,d.useCallback)(e=>{s(e),v(`models`)},[v]),b=(0,d.useCallback)(()=>{r(e=>e.filter(e=>e.kind!==`config`)),a(e=>e===`config`?null:e),s(null),t?.()},[r,a,t]);return{savedTabs:n,setSavedTabs:r,activeSavedId:i,setActiveSavedId:a,configTabOpen:l,configSection:u,setConfigSection:f,configTabActive:h,activeFileTab:m,fileTabs:p,modelConfigFocus:o,handleOpenFile:g,handleCloseFileTab:_,openConfigTab:v,handleOpenModelConfig:y,closeConfigTab:b,handleCloseMainTab:(0,d.useCallback)(e=>{if(e===`config`){b();return}_(e)},[b,_])}}function xq({widgetGeometries:e,setWidgetGeometry:t}){let[n,r]=(0,d.useState)(!0),[i,a]=(0,d.useState)(!1),[o,s]=(0,d.useState)([]),[c,l]=(0,d.useState)(new Map),[u,f]=(0,d.useState)(!0);return{widgetPanelOpen:n,setWidgetPanelOpen:r,widgetsTabActive:i,setWidgetsTabActive:a,extensionWidgets:o,closedWidgets:c,handleCloseWidget:(0,d.useCallback)((n,r)=>{l(e=>new Map(e).set(n,r));let i=e[n];t(n,{x:i?.x??0,y:i?.y??0,width:i?.width??560,height:i?.height??Math.round(window.innerHeight*.6),collapsed:!0})},[e,t]),handleReopenWidget:(0,d.useCallback)(n=>{l(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t});let r=e[n];r&&t(n,{...r,collapsed:!1}),a(!1)},[e,t,a]),handleExtensionWidgetsChange:(0,d.useCallback)(n=>{s(n),l(r=>{let i=!1,a=new Map(r);for(let[o,s]of r){let r=n.find(e=>e.key===o);if(r&&r.lines.join(`
|
|
348
|
-
`)!==s){a.delete(o),i=!0;let n=e[o];n&&t(o,{...n,collapsed:!1})}}return i?a:r})},[e,t]),rightSidebarOpen:u,setRightSidebarOpen:f,closedWidgetCount:c.size}}function Sq({hasFocusedEditable:e,innerHeight:t,viewportHeight:n,viewportScale:r}){let i=Math.abs(r-1)<.01;return e&&i&&t-n>1}function Cq(){let e=document.activeElement;return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`SELECT`||e.tagName===`TEXTAREA`:!1}function wq(){(0,d.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,n=()=>{Sq({hasFocusedEditable:Cq(),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?(t.style.setProperty(`--app-viewport-height`,`${e.height}px`),(window.scrollX!==0||window.scrollY!==0)&&window.scrollTo(0,0)):t.style.removeProperty(`--app-viewport-height`)};return n(),e.addEventListener(`resize`,n),e.addEventListener(`scroll`,n),()=>{e.removeEventListener(`resize`,n),e.removeEventListener(`scroll`,n),t.style.removeProperty(`--app-viewport-height`)}},[])}function Tq(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let n=/(?:^|\s)@([^\s"]*)$/.exec(e);return n?{start:e.length-(n[1].length+1),query:n[1],quoted:!1}:null}function Eq(e){let t=0;for(let n=0;n<e.length;n++)e[n]===`/`&&t++;return t}function Dq(e){let t=new Set;for(let n of e){let e=n.indexOf(`/`);for(;e!==-1;)t.add(n.slice(0,e)),e=n.indexOf(`/`,e+1)}let n=[];for(let e of t)n.push({path:e,isDir:!0});for(let t of e)t&&n.push({path:t,isDir:!1});return n.sort((e,t)=>Eq(e.path)-Eq(t.path)||e.path.localeCompare(t.path)),n}function Oq(e,t){let n=e.path.toLowerCase(),r=0;if(t.includes(`/`))n===t?r=100:n.startsWith(t)?r=80:n.includes(t)&&(r=50);else{let e=n.lastIndexOf(`/`),i=e===-1?n:n.slice(e+1);i===t?r=100:i.startsWith(t)?r=80:i.includes(t)?r=50:n.includes(t)&&(r=30)}return e.isDir&&r>0&&(r+=10),r}function kq(e,t,n=20){let r=t.toLowerCase();if(!r)return e.slice(0,n);let i=[];for(let t of e){let e=Oq(t,r);e>0&&i.push({entry:t,score:e})}return i.sort((e,t)=>t.score-e.score||Eq(e.entry.path)-Eq(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),i.slice(0,n).map(e=>e.entry)}function Aq(e,t,n=!1){let r=t?`${e}/`:e,i=n||r.includes(` `);if(t){let e=i?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let a=i?`@"${r}" `:`@${r} `;return{text:a,cursorOffset:a.length}}function jq(e,t){let n=t?`${e}/`:e;return n.includes(` `)?`@"${n}" `:`@${n} `}function Mq(e,t,n){let r=Math.max(1,Math.min(t,n)),i=Math.max(1,Math.max(t,n));return`${e.includes(` `)?`@"${e}"`:`@${e}`}${r===i?`:${r}`:`:${r}-${i}`} `}function Nq(e){return e.map(e=>jq(e,!1)).join(``)}function Pq(e){let t=e.get(`cwd`)?.trim()||null;return{requestedCwd:t,sessionId:t?null:e.get(`session`)}}function Fq(){return(0,E.jsxs)(`div`,{role:`status`,"aria-label":`Loading`,"data-testid":`boot-splash`,style:{position:`fixed`,inset:0,zIndex:9999,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:18,background:`var(--bg)`,color:`var(--text-muted)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,color:`var(--accent)`,letterSpacing:`0.02em`},children:`pi`}),(0,E.jsx)(`div`,{style:{width:22,height:22,border:`2px solid var(--border)`,borderTopColor:`var(--accent)`,borderRadius:`50%`,animation:`boot-spin 0.8s linear infinite`}}),(0,E.jsx)(`style`,{children:`@keyframes boot-spin { to { transform: rotate(360deg); } }`})]})}var Iq=!1,Lq=performance.now();function Rq(e){Iq=e,Lq=performance.now(),Iq&&Bq(`boot`,`debug log enabled`)}function zq(e){return(t,n)=>Bq(e,t,n)}function Bq(e,t,n){if(!Iq)return;performance.now()-Lq;let r=new Date,i=(e,t=2)=>String(e).padStart(t,`0`);`${i(r.getHours())}${i(r.getMinutes())}${i(r.getSeconds())}${i(r.getMilliseconds(),3)}`}function Vq(){if(!Iq)return;let e=window.fetch;window.fetch=async(t,n)=>{let r=typeof t==`string`?t:t instanceof URL?t.href:t.url,i=n?.method??`GET`,a=performance.now();try{let o=await e(t,n);return Bq(`fetch`,`${i} ${r}`,`${o.status} ${Math.round(performance.now()-a)}ms`),o}catch(e){throw Bq(`fetch`,`${i} ${r}`,`failed ${Math.round(performance.now()-a)}ms`),e}}}var Hq=new Set([`select`,`confirm`,`input`,`editor`]),Uq=new Set,Wq=new Set;function Gq(){for(let e of Wq)e()}function Kq(e){if(Uq.has(e))return;let t=new Set(Uq);t.add(e),Uq=t,Gq()}function qq(e){if(!Uq.has(e))return;let t=new Set(Uq);t.delete(e),Uq=t,Gq()}function Jq(e){return Wq.add(e),()=>Wq.delete(e)}function Yq(){return Uq}function Xq(){return(0,d.useSyncExternalStore)(Jq,Yq,Yq)}function Zq(e,t,n){let r=`${t}/${n}`;if(e.models?.[r])return e.models[r];if(e.providers?.[t])return e.providers[t]}function Qq(e,t){return e.providers?.[t]}function $q(e,t,n,r){let i=`${t}/${n}`;if(r===`auto`){if(!e.models?.[i])return e;let t={...e.models};delete t[i];let n={...e};return Object.keys(t).length===0?delete n.models:n.models=t,n}let a=Qq(e,t);if(a!==void 0&&r===a){if(e.models?.[i]){let t={...e.models};delete t[i];let n={...e};return Object.keys(t).length===0?delete n.models:n.models=t,n}return e}return e.models?.[i]===r?e:{...e,models:{...e.models??{},[i]:r}}}function eJ(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tJ(e){return!eJ(e)||e.type!==`toolCall`?null:{type:`toolCall`,toolCallId:typeof e.toolCallId==`string`?e.toolCallId:typeof e.id==`string`?e.id:``,toolName:typeof e.toolName==`string`?e.toolName:typeof e.name==`string`?e.name:``,input:typeof e.input==`object`&&e.input!==null&&!Array.isArray(e.input)?e.input:typeof e.arguments==`object`&&e.arguments!==null&&!Array.isArray(e.arguments)?e.arguments:{}}}function nJ(e){if(e.role!==`assistant`)return e;let t=e.content;if(!Array.isArray(t))return e;let n=t.map(e=>tJ(e)??e);return{...e,content:n}}function rJ(e){if(e.role!==`assistant`)return e;let t=e.content;if(!Array.isArray(t))return e;for(let e=0;e<t.length;e++){let n=t[e],r=tJ(n);r!==null&&(t[e]=r)}return e}var iJ=e=>{let t=e;return t?typeof t.thinking==`string`?t.thinking.length:typeof t.text==`string`?t.text.length:typeof t.streamingOutput==`string`?t.streamingOutput.length:0:0};function aJ(){let e=new Map,t=new Map;return{snapshot(n){e.clear(),t.clear(),Array.isArray(n)&&n.forEach((n,r)=>{e.set(r,iJ(n)),t.set(r,0)})},take(n,r){let i=e.get(n)??0,a=t.get(n)??0;t.set(n,a+r.length);let o=Math.min(Math.max(i-a,0),r.length);return o>0?r.slice(o):r},reset(){e.clear(),t.clear()}}}var oJ=[],sJ=[`read`,`bash`,`edit`,`write`],cJ=[`bash`,`read`,`edit`,`write`,`grep`,`find`,`ls`],lJ=new Set(cJ);function uJ(e){let t=e.filter(e=>e.active);if(t.length===0)return`none`;let n=t.map(e=>e.name).filter(e=>lJ.has(e)).sort().join(`,`);return n===[...sJ].sort().join(`,`)?`default`:n===[...cJ].sort().join(`,`)?`full`:`default`}function dJ(e){return e===`none`?[...oJ]:e===`full`?[...cJ]:[...sJ]}function fJ(e,t){switch(t.type){case`start`:return{isStreaming:!0,streamingMessage:null};case`update`:return{isStreaming:!0,streamingMessage:t.message};case`end`:case`reset`:return{isStreaming:!1,streamingMessage:null};default:return e}}function pJ(e){if(!e||typeof e!=`object`)return;let t=e.content;if(!Array.isArray(t))return;let n=t.filter(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`).map(e=>e.text);return n.length>0?n.join(``):void 0}function mJ(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}var hJ=700,gJ=1200,_J=80,vJ=800,yJ=600,bJ=2e4,xJ=3e4,SJ=200,CJ=32,wJ=15e3,TJ=1e3,EJ=5e3,DJ=5,OJ=5e3,kJ=180,AJ=new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `,`Space`,`Spacebar`]),jJ=class extends Error{constructor(e){super(e===`timeout`?`Timed out connecting to the agent event stream. Please try again.`:`Failed to connect to the agent event stream. Please try again.`),this.status=e,this.name=`EventStreamConnectionError`}};function MJ(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`}function NJ(e){return new Promise(t=>setTimeout(t,e))}function PJ(e){let t=e.findIndex(e=>!e.exiting);return t===-1?e:e.map((e,n)=>n===t?{...e,exiting:!0}:e)}function FJ(e,t){let n=e,r=t;for(;r.length>0&&n.length<DJ;){let[e,...t]=r;n=[...n,e],r=t}return r.length>0&&!n.some(e=>e.exiting)&&(n=PJ(n)),{visible:n,pending:r}}function IJ(e,t){switch(t.type){case`add`:return e.visible.some(e=>e.exiting)||e.visible.length>=DJ?{visible:e.visible.some(e=>e.exiting)?e.visible:PJ(e.visible),pending:[...e.pending,t.notice],modals:e.modals}:{...e,visible:[...e.visible,t.notice]};case`mark_oldest_exiting`:return{...e,visible:PJ(e.visible)};case`add_modal`:return{...e,modals:[...e.modals,t.notice]};case`dismiss_modal`:return{...e,modals:e.modals.filter(e=>e.id!==t.id)};case`remove`:return{...FJ(e.visible.filter(e=>e.id!==t.id),e.pending),modals:e.modals};default:return e}}function LJ(){let[e,t]=(0,d.useReducer)(IJ,{visible:[],pending:[],modals:[]}),n=(0,d.useCallback)(e=>{let n=e.message.trim();if(!n)return;let r={id:e.id??MJ(),message:n,type:e.type??`info`};t(e.modal?{type:`add_modal`,notice:r}:{type:`add`,notice:r})},[]),r=(0,d.useCallback)(e=>{t({type:`dismiss_modal`,id:e})},[]);return(0,d.useEffect)(()=>{if(e.visible.length===0)return;let n=e.visible.find(e=>e.exiting);if(n){let e=setTimeout(()=>{t({type:`remove`,id:n.id})},kJ);return()=>clearTimeout(e)}if(!e.visible[0])return;let r=setTimeout(()=>{t({type:`mark_oldest_exiting`})},OJ);return()=>clearTimeout(r)},[e.visible]),{noticeState:e,addNotice:n,dismissModal:r}}function RJ({messages:e,contextUsage:t,data:n,session:r,sessionIdRef:i}){let[a,o]=(0,d.useState)(null);return{sessionStats:(0,d.useMemo)(()=>{if(a)return a;let o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},s=0,c=0,l=0,u=0,d=0;for(let t of e){if(t.role===`user`&&(c+=1),t.role===`toolResult`&&(u+=1),t.role!==`assistant`)continue;l+=1;let e=t.usage;d+=t.content.filter(e=>e.type===`toolCall`).length,e&&(o.input+=e.input??0,o.output+=e.output??0,o.cacheRead+=e.cacheRead??0,o.cacheWrite+=e.cacheWrite??0,s+=e.cost?.total??0)}return o.total=o.input+o.output+o.cacheRead+o.cacheWrite,o.total===0&&e.length===0?null:{sessionFile:n?.filePath||void 0,sessionId:i.current??r?.id??``,sessionName:r?.name,userMessages:c,assistantMessages:l,toolCalls:d,toolResults:u,totalMessages:e.length,tokens:o,cost:s,...t?{contextUsage:t}:{}}},[e,a,t,n?.filePath,r?.id,r?.name,i]),setSessionStatsOverride:o}}function zJ({isNew:e,sessionIdRef:t,ensuringNewSessionRef:n,setToolPresetOverride:r,addNotice:i,t:a}){let[o,s]=(0,d.useState)({}),[c,l]=(0,d.useState)([]),[u,f]=(0,d.useState)(null),[p,m]=(0,d.useState)([]),[h,g]=(0,d.useState)({}),[_,v]=(0,d.useState)({}),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)(`default`),[T,E]=(0,d.useState)(`auto`),[D,O]=(0,d.useState)(null),[k,A]=(0,d.useState)(null),j=(0,d.useRef)(null),M=(0,d.useRef)(null),N=(0,d.useRef)(null),P=r??w,ee=(0,d.useCallback)((t,n)=>{if(e){let e={provider:t,modelId:n};j.current=e,b(e),A(e);return}O({provider:t,modelId:n})},[e,b]);return{modelNames:o,modelList:c,modelError:u,modelScopeWarnings:p,modelThinkingLevels:h,modelThinkingLevelMaps:_,newSessionModel:y,newSessionDefaultModel:x,toolPreset:C,thinkingLevel:T,currentModelOverride:D,pendingModel:k,setThinkingLevel:E,setPendingModel:A,setNewSessionDefaultModel:S,setCurrentModelOverride:O,setModelError:f,setToolPresetState:P,newSessionModelOverrideRef:j,thinkingLevelOverrideRef:M,loadModels:(0,d.useCallback)(async t=>{let n=await _e.load(t);s(n.models),f(n.modelError??null),m(n.modelScopeWarnings??[]),g(n.thinkingLevels??{}),v(n.thinkingLevelMaps??{});let r=n.modelList??[];if(l(r),e){let e,o=!1,s=null;if(n.defaultModel)e=r.find(e=>e.id===n.defaultModel?.modelId&&e.provider===n.defaultModel?.provider),e||(o=!0,s=`${n.defaultModel.provider}/${n.defaultModel.modelId}`);else try{let e=(await be.load(t)).defaultModel;e&&(s=`${e.provider}/${e.modelId}`,o=!0)}catch{}if(o&&s){N.current!==s&&(N.current=s,i({type:`warning`,message:a(`models.defaultModelUnavailable`,{model:s})})),S(e=>e??null);return}let c=e??r[0]??null;c&&(N.current=null),S(e=>e??(c?{provider:c.provider,modelId:c.id}:null));let l=c&&n.thinkingLevelPins?.[`${c.provider}/${c.id}`];M.current===null&&E(e=>e===`auto`?l??`auto`:e)}},[e,i,a]),handleModelChange:ee,handleThinkingLevelChange:(0,d.useCallback)(async r=>{if(E(r),e&&!t.current&&(M.current=r===`auto`?null:r),r===`auto`)return;let i=t.current??await n.current;if(i)try{await lC(i,{type:`set_thinking_level`,level:r})}catch(e){console.error(`Failed to set thinking level:`,e)}},[e,t,n]),handleToolPresetChange:(0,d.useCallback)(async e=>{let r=dJ(e);P(e);let i=t.current??await n.current;if(i)try{await lC(i,{type:`set_tools`,toolNames:r})}catch(e){console.error(`Failed to set tools:`,e)}},[P,t,n])}}function BJ({addNotice:e,chatInputRef:t,sessionIdRef:n}){let[r,i]=(0,d.useState)(null),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)([]),[l,u]=(0,d.useState)([]);return(0,d.useEffect)(()=>{if(!r?.timeout)return;let e=r.id,t=setTimeout(()=>{Bq(`ui-chain`,`4c dialog auto-close by timeout`,`id=${e.slice(0,8)}`),i(t=>t?.id===e?null:t)},r.timeout);return()=>clearTimeout(t)},[r]),{extensionDialog:r,extensionCustomUi:a,extensionStatuses:s,extensionWidgets:l,setExtensionStatuses:c,setExtensionWidgets:u,respondToExtensionUi:(0,d.useCallback)(async(e,t)=>{let r=n.current;if(i(t=>t?.id===e.id?null:t),r)try{await lC(r,{type:`extension_ui_response`,id:e.id,...t})}catch(e){console.error(`Failed to send extension UI response:`,e)}},[n]),sendExtensionCustomInput:(0,d.useCallback)(async(e,t)=>{let r=n.current;if(r)try{await lC(r,{type:`extension_ui_input`,id:e.id,data:t})}catch(e){console.error(`Failed to send extension custom UI input:`,e)}},[n]),handleExtensionUiRequest:(0,d.useCallback)(n=>{switch(n.method){case`select`:case`confirm`:case`input`:case`editor`:i(n);break;case`notify`:{let t=n.notifyType??`info`,r=n.message;t===`warning`?console.warn(`[pi] notify (warning): ${r}`):t===`error`?console.error(`[pi] notify (error): ${r}`):console.info(`[pi] notify: ${r}`);let i=typeof r==`string`&&r.length>100;e({id:n.id,message:r,type:t,modal:t===`warning`||t===`error`||i});break}case`setStatus`:c(e=>{let t=e.filter(e=>e.key!==n.statusKey);return n.statusText===void 0?t:[...t,{key:n.statusKey,text:n.statusText}]});break;case`setWidget`:u(e=>{let t=e.filter(e=>e.key!==n.widgetKey);return n.widgetLines?[...t,{key:n.widgetKey,lines:n.widgetLines,placement:n.widgetPlacement??`aboveEditor`}]:t});break;case`setTitle`:n.title&&(document.title=n.title);break;case`set_editor_text`:t?.current?.insertText(n.text);break;case`custom`:o(e=>n.closed?e?.id===n.id?null:e:n)}},[e,t])}}function VJ(e){let t=e.content;return typeof t==`string`?t:Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
349
|
-
`):``}function
|
|
348
|
+
`)!==s){a.delete(o),i=!0;let n=e[o];n&&t(o,{...n,collapsed:!1})}}return i?a:r})},[e,t]),rightSidebarOpen:u,setRightSidebarOpen:f,closedWidgetCount:c.size}}function Sq({hasFocusedEditable:e,innerHeight:t,viewportHeight:n,viewportScale:r}){let i=Math.abs(r-1)<.01;return e&&i&&t-n>1}function Cq(){let e=document.activeElement;return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`SELECT`||e.tagName===`TEXTAREA`:!1}function wq(){(0,d.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,n=()=>{Sq({hasFocusedEditable:Cq(),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?(t.style.setProperty(`--app-viewport-height`,`${e.height}px`),(window.scrollX!==0||window.scrollY!==0)&&window.scrollTo(0,0)):t.style.removeProperty(`--app-viewport-height`)};return n(),e.addEventListener(`resize`,n),e.addEventListener(`scroll`,n),()=>{e.removeEventListener(`resize`,n),e.removeEventListener(`scroll`,n),t.style.removeProperty(`--app-viewport-height`)}},[])}function Tq(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let n=/(?:^|\s)@([^\s"]*)$/.exec(e);return n?{start:e.length-(n[1].length+1),query:n[1],quoted:!1}:null}function Eq(e){let t=0;for(let n=0;n<e.length;n++)e[n]===`/`&&t++;return t}function Dq(e){let t=new Set;for(let n of e){let e=n.indexOf(`/`);for(;e!==-1;)t.add(n.slice(0,e)),e=n.indexOf(`/`,e+1)}let n=[];for(let e of t)n.push({path:e,isDir:!0});for(let t of e)t&&n.push({path:t,isDir:!1});return n.sort((e,t)=>Eq(e.path)-Eq(t.path)||e.path.localeCompare(t.path)),n}function Oq(e,t){let n=e.path.toLowerCase(),r=0;if(t.includes(`/`))n===t?r=100:n.startsWith(t)?r=80:n.includes(t)&&(r=50);else{let e=n.lastIndexOf(`/`),i=e===-1?n:n.slice(e+1);i===t?r=100:i.startsWith(t)?r=80:i.includes(t)?r=50:n.includes(t)&&(r=30)}return e.isDir&&r>0&&(r+=10),r}function kq(e,t,n=20){let r=t.toLowerCase();if(!r)return e.slice(0,n);let i=[];for(let t of e){let e=Oq(t,r);e>0&&i.push({entry:t,score:e})}return i.sort((e,t)=>t.score-e.score||Eq(e.entry.path)-Eq(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),i.slice(0,n).map(e=>e.entry)}function Aq(e,t,n=!1){let r=t?`${e}/`:e,i=n||r.includes(` `);if(t){let e=i?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let a=i?`@"${r}" `:`@${r} `;return{text:a,cursorOffset:a.length}}function jq(e,t){let n=t?`${e}/`:e;return n.includes(` `)?`@"${n}" `:`@${n} `}function Mq(e,t,n){let r=Math.max(1,Math.min(t,n)),i=Math.max(1,Math.max(t,n));return`${e.includes(` `)?`@"${e}"`:`@${e}`}${r===i?`:${r}`:`:${r}-${i}`} `}function Nq(e){return e.map(e=>jq(e,!1)).join(``)}function Pq(e){let t=e.get(`cwd`)?.trim()||null;return{requestedCwd:t,sessionId:t?null:e.get(`session`)}}function Fq(){return(0,E.jsxs)(`div`,{role:`status`,"aria-label":`Loading`,"data-testid":`boot-splash`,style:{position:`fixed`,inset:0,zIndex:9999,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:18,background:`var(--bg)`,color:`var(--text-muted)`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,color:`var(--accent)`,letterSpacing:`0.02em`},children:`pi`}),(0,E.jsx)(`div`,{style:{width:22,height:22,border:`2px solid var(--border)`,borderTopColor:`var(--accent)`,borderRadius:`50%`,animation:`boot-spin 0.8s linear infinite`}}),(0,E.jsx)(`style`,{children:`@keyframes boot-spin { to { transform: rotate(360deg); } }`})]})}var Iq=!1,Lq=performance.now();function Rq(e){Iq=e,Lq=performance.now(),Iq&&Bq(`boot`,`debug log enabled`)}function zq(e){return(t,n)=>Bq(e,t,n)}function Bq(e,t,n){if(!Iq)return;performance.now()-Lq;let r=new Date,i=(e,t=2)=>String(e).padStart(t,`0`);`${i(r.getHours())}${i(r.getMinutes())}${i(r.getSeconds())}${i(r.getMilliseconds(),3)}`}function Vq(){if(!Iq)return;let e=window.fetch;window.fetch=async(t,n)=>{let r=typeof t==`string`?t:t instanceof URL?t.href:t.url,i=n?.method??`GET`,a=performance.now();try{let o=await e(t,n);return Bq(`fetch`,`${i} ${r}`,`${o.status} ${Math.round(performance.now()-a)}ms`),o}catch(e){throw Bq(`fetch`,`${i} ${r}`,`failed ${Math.round(performance.now()-a)}ms`),e}}}var Hq=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,Uq=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,Wq=/\x1B\[([0-9;]*)m/g,Gq=/\x1B_pi:c\x07/g,Kq=[`#1f2937`,`#dc2626`,`#16a34a`,`#d97706`,`#2563eb`,`#9333ea`,`#0891b2`,`#6b7280`],qq=[`#9ca3af`,`#ef4444`,`#22c55e`,`#f59e0b`,`#3b82f6`,`#a855f7`,`#06b6d4`,`#e5e7eb`];function Jq(e){return e.replace(Gq,``).replace(Hq,``)}function Yq(e){let t=[],n=0;for(;n<e.length;){if(e.charCodeAt(n)===27){let t=e.slice(n).match(Uq);if(t){n+=t[0].length;continue}}let r=e.codePointAt(n);if(r===void 0)break;let i=String.fromCodePoint(r);t.push({start:n,end:n+i.length,char:i}),n+=i.length}return t}function Xq(e,t){let n=Yq(e)[t];return n?e.slice(0,n.start)+e.slice(n.end):e}function Zq(e){return Yq(e)[0]?.char}function Qq(e){let t=Yq(e);for(let e=t.length-1;e>=0;e--)if(t[e].char.trim()!==``)return e;return-1}function $q(e){let t=e;for(;;){let e=Yq(t),n=e[e.length-1];if(n?.char.trim()!==``)return t;t=t.slice(0,n.start)+t.slice(n.end)}}function eJ(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,n=[];for(let r of e){let e=r.replace(Gq,``),i=Jq(e).trimEnd();if(t.test(i))continue;let a=e,o=Zq(a);(o===`│`||o===`┃`)&&(a=Xq(a,0),Zq(a)===` `&&(a=Xq(a,0)));let s=Qq(a),c=s>=0?Yq(a)[s]?.char:void 0;(c===`│`||c===`┃`)&&(a=Xq(a,s)),n.push($q(a))}for(;n.length>0&&Jq(n[0]).trim()===``;)n.shift();for(;n.length>0&&Jq(n[n.length-1]).trim()===``;)n.pop();return n.length?n:e}function tJ(e){if(e>=0&&e<8)return Kq[e];if(e>=8&&e<16)return qq[e-8];if(e>=16&&e<=231){let t=e-16,n=Math.floor(t/36),r=Math.floor(t%36/6),i=t%6,a=e=>e===0?0:55+e*40;return`rgb(${a(n)}, ${a(r)}, ${a(i)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}function nJ(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(r===0)for(let e of Object.keys(n))delete n[e];else if(r===1)n.fontWeight=700;else if(r===2)n.opacity=.65;else if(r===3)n.fontStyle=`italic`;else if(r===4)n.textDecoration=`underline`;else if(r===22)delete n.fontWeight,delete n.opacity;else if(r===23)delete n.fontStyle;else if(r===24)delete n.textDecoration;else if(r===39)delete n.color;else if(r===49)delete n.backgroundColor;else if(r>=30&&r<=37)n.color=Kq[r-30];else if(r>=90&&r<=97)n.color=qq[r-90];else if(r>=40&&r<=47)n.backgroundColor=Kq[r-40];else if(r>=100&&r<=107)n.backgroundColor=qq[r-100];else if((r===38||r===48)&&t[e+1]===2){let[i,a,o]=[t[e+2],t[e+3],t[e+4]];[i,a,o].every(e=>typeof e==`number`&&Number.isFinite(e))&&(r===38?n.color=`rgb(${i}, ${a}, ${o})`:n.backgroundColor=`rgb(${i}, ${a}, ${o})`),e+=4}else if((r===38||r===48)&&t[e+1]===5){let i=tJ(t[e+2]);i&&(r===38?n.color=i:n.backgroundColor=i),e+=2}}return n}function rJ(e){let t=[],n={},r=0,i;for(Wq.lastIndex=0;(i=Wq.exec(e))!==null;){i.index>r&&t.push({text:e.slice(r,i.index),style:n});let a=i[1]?i[1].split(`;`).map(e=>Number(e||`0`)):[0];n=nJ(n,a),r=i.index+i[0].length}return r<e.length&&t.push({text:e.slice(r),style:n}),t}var iJ=new Set([`select`,`confirm`,`input`,`editor`]),aJ=new Set,oJ=new Set;function sJ(){for(let e of oJ)e()}function cJ(e){if(aJ.has(e))return;let t=new Set(aJ);t.add(e),aJ=t,sJ()}function lJ(e){if(!aJ.has(e))return;let t=new Set(aJ);t.delete(e),aJ=t,sJ()}function uJ(e){return oJ.add(e),()=>oJ.delete(e)}function dJ(){return aJ}function fJ(){return(0,d.useSyncExternalStore)(uJ,dJ,dJ)}function pJ(e,t,n){let r=`${t}/${n}`;if(e.models?.[r])return e.models[r];if(e.providers?.[t])return e.providers[t]}function mJ(e,t){return e.providers?.[t]}function hJ(e,t,n,r){let i=`${t}/${n}`;if(r===`auto`){if(!e.models?.[i])return e;let t={...e.models};delete t[i];let n={...e};return Object.keys(t).length===0?delete n.models:n.models=t,n}let a=mJ(e,t);if(a!==void 0&&r===a){if(e.models?.[i]){let t={...e.models};delete t[i];let n={...e};return Object.keys(t).length===0?delete n.models:n.models=t,n}return e}return e.models?.[i]===r?e:{...e,models:{...e.models??{},[i]:r}}}function gJ(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _J(e){return!gJ(e)||e.type!==`toolCall`?null:{type:`toolCall`,toolCallId:typeof e.toolCallId==`string`?e.toolCallId:typeof e.id==`string`?e.id:``,toolName:typeof e.toolName==`string`?e.toolName:typeof e.name==`string`?e.name:``,input:typeof e.input==`object`&&e.input!==null&&!Array.isArray(e.input)?e.input:typeof e.arguments==`object`&&e.arguments!==null&&!Array.isArray(e.arguments)?e.arguments:{}}}function vJ(e){if(e.role!==`assistant`)return e;let t=e.content;if(!Array.isArray(t))return e;let n=t.map(e=>_J(e)??e);return{...e,content:n}}function yJ(e){if(e.role!==`assistant`)return e;let t=e.content;if(!Array.isArray(t))return e;for(let e=0;e<t.length;e++){let n=t[e],r=_J(n);r!==null&&(t[e]=r)}return e}var bJ=e=>{let t=e;return t?typeof t.thinking==`string`?t.thinking.length:typeof t.text==`string`?t.text.length:typeof t.streamingOutput==`string`?t.streamingOutput.length:0:0};function xJ(){let e=new Map,t=new Map;return{snapshot(n){e.clear(),t.clear(),Array.isArray(n)&&n.forEach((n,r)=>{e.set(r,bJ(n)),t.set(r,0)})},take(n,r){let i=e.get(n)??0,a=t.get(n)??0;t.set(n,a+r.length);let o=Math.min(Math.max(i-a,0),r.length);return o>0?r.slice(o):r},reset(){e.clear(),t.clear()}}}var SJ=[],CJ=[`read`,`bash`,`edit`,`write`],wJ=[`bash`,`read`,`edit`,`write`,`grep`,`find`,`ls`],TJ=new Set(wJ);function EJ(e){let t=e.filter(e=>e.active);if(t.length===0)return`none`;let n=t.map(e=>e.name).filter(e=>TJ.has(e)).sort().join(`,`);return n===[...CJ].sort().join(`,`)?`default`:n===[...wJ].sort().join(`,`)?`full`:`default`}function DJ(e){return e===`none`?[...SJ]:e===`full`?[...wJ]:[...CJ]}function OJ(e,t){switch(t.type){case`start`:return{isStreaming:!0,streamingMessage:null};case`update`:return{isStreaming:!0,streamingMessage:t.message};case`end`:case`reset`:return{isStreaming:!1,streamingMessage:null};default:return e}}function kJ(e){if(!e||typeof e!=`object`)return;let t=e.content;if(!Array.isArray(t))return;let n=t.filter(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`).map(e=>e.text);return n.length>0?n.join(``):void 0}function AJ(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}var jJ=700,MJ=1200,NJ=80,PJ=800,FJ=600,IJ=2e4,LJ=3e4,RJ=200,zJ=32,BJ=15e3,VJ=1e3,HJ=5e3,UJ=5,WJ=5e3,GJ=180,KJ=new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `,`Space`,`Spacebar`]),qJ=class extends Error{constructor(e){super(e===`timeout`?`Timed out connecting to the agent event stream. Please try again.`:`Failed to connect to the agent event stream. Please try again.`),this.status=e,this.name=`EventStreamConnectionError`}};function JJ(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`}function YJ(e){return new Promise(t=>setTimeout(t,e))}function XJ(e){let t=e.findIndex(e=>!e.exiting);return t===-1?e:e.map((e,n)=>n===t?{...e,exiting:!0}:e)}function ZJ(e,t){let n=e,r=t;for(;r.length>0&&n.length<UJ;){let[e,...t]=r;n=[...n,e],r=t}return r.length>0&&!n.some(e=>e.exiting)&&(n=XJ(n)),{visible:n,pending:r}}function QJ(e,t){switch(t.type){case`add`:return e.visible.some(e=>e.exiting)||e.visible.length>=UJ?{visible:e.visible.some(e=>e.exiting)?e.visible:XJ(e.visible),pending:[...e.pending,t.notice],modals:e.modals}:{...e,visible:[...e.visible,t.notice]};case`mark_oldest_exiting`:return{...e,visible:XJ(e.visible)};case`add_modal`:return{...e,modals:[...e.modals,t.notice]};case`dismiss_modal`:return{...e,modals:e.modals.filter(e=>e.id!==t.id)};case`remove`:return{...ZJ(e.visible.filter(e=>e.id!==t.id),e.pending),modals:e.modals};default:return e}}function $J(){let[e,t]=(0,d.useReducer)(QJ,{visible:[],pending:[],modals:[]}),n=(0,d.useCallback)(e=>{let n=e.message.trim();if(!n)return;let r={id:e.id??JJ(),message:n,type:e.type??`info`};t(e.modal?{type:`add_modal`,notice:r}:{type:`add`,notice:r})},[]),r=(0,d.useCallback)(e=>{t({type:`dismiss_modal`,id:e})},[]);return(0,d.useEffect)(()=>{if(e.visible.length===0)return;let n=e.visible.find(e=>e.exiting);if(n){let e=setTimeout(()=>{t({type:`remove`,id:n.id})},GJ);return()=>clearTimeout(e)}if(!e.visible[0])return;let r=setTimeout(()=>{t({type:`mark_oldest_exiting`})},WJ);return()=>clearTimeout(r)},[e.visible]),{noticeState:e,addNotice:n,dismissModal:r}}function eY({messages:e,contextUsage:t,data:n,session:r,sessionIdRef:i}){let[a,o]=(0,d.useState)(null);return{sessionStats:(0,d.useMemo)(()=>{if(a)return a;let o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},s=0,c=0,l=0,u=0,d=0;for(let t of e){if(t.role===`user`&&(c+=1),t.role===`toolResult`&&(u+=1),t.role!==`assistant`)continue;l+=1;let e=t.usage;d+=t.content.filter(e=>e.type===`toolCall`).length,e&&(o.input+=e.input??0,o.output+=e.output??0,o.cacheRead+=e.cacheRead??0,o.cacheWrite+=e.cacheWrite??0,s+=e.cost?.total??0)}return o.total=o.input+o.output+o.cacheRead+o.cacheWrite,o.total===0&&e.length===0?null:{sessionFile:n?.filePath||void 0,sessionId:i.current??r?.id??``,sessionName:r?.name,userMessages:c,assistantMessages:l,toolCalls:d,toolResults:u,totalMessages:e.length,tokens:o,cost:s,...t?{contextUsage:t}:{}}},[e,a,t,n?.filePath,r?.id,r?.name,i]),setSessionStatsOverride:o}}function tY({isNew:e,sessionIdRef:t,ensuringNewSessionRef:n,setToolPresetOverride:r,addNotice:i,t:a}){let[o,s]=(0,d.useState)({}),[c,l]=(0,d.useState)([]),[u,f]=(0,d.useState)(null),[p,m]=(0,d.useState)([]),[h,g]=(0,d.useState)({}),[_,v]=(0,d.useState)({}),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)(`default`),[T,E]=(0,d.useState)(`auto`),[D,O]=(0,d.useState)(null),[k,A]=(0,d.useState)(null),j=(0,d.useRef)(null),M=(0,d.useRef)(null),N=(0,d.useRef)(null),P=r??w,ee=(0,d.useCallback)((t,n)=>{if(e){let e={provider:t,modelId:n};j.current=e,b(e),A(e);return}O({provider:t,modelId:n})},[e,b]);return{modelNames:o,modelList:c,modelError:u,modelScopeWarnings:p,modelThinkingLevels:h,modelThinkingLevelMaps:_,newSessionModel:y,newSessionDefaultModel:x,toolPreset:C,thinkingLevel:T,currentModelOverride:D,pendingModel:k,setThinkingLevel:E,setPendingModel:A,setNewSessionDefaultModel:S,setCurrentModelOverride:O,setModelError:f,setToolPresetState:P,newSessionModelOverrideRef:j,thinkingLevelOverrideRef:M,loadModels:(0,d.useCallback)(async t=>{let n=await _e.load(t);s(n.models),f(n.modelError??null),m(n.modelScopeWarnings??[]),g(n.thinkingLevels??{}),v(n.thinkingLevelMaps??{});let r=n.modelList??[];if(l(r),e){let e,o=!1,s=null;if(n.defaultModel)e=r.find(e=>e.id===n.defaultModel?.modelId&&e.provider===n.defaultModel?.provider),e||(o=!0,s=`${n.defaultModel.provider}/${n.defaultModel.modelId}`);else try{let e=(await be.load(t)).defaultModel;e&&(s=`${e.provider}/${e.modelId}`,o=!0)}catch{}if(o&&s){N.current!==s&&(N.current=s,i({type:`warning`,message:a(`models.defaultModelUnavailable`,{model:s})})),S(e=>e??null);return}let c=e??r[0]??null;c&&(N.current=null),S(e=>e??(c?{provider:c.provider,modelId:c.id}:null));let l=c&&n.thinkingLevelPins?.[`${c.provider}/${c.id}`];M.current===null&&E(e=>e===`auto`?l??`auto`:e)}},[e,i,a]),handleModelChange:ee,handleThinkingLevelChange:(0,d.useCallback)(async r=>{if(E(r),e&&!t.current&&(M.current=r===`auto`?null:r),r===`auto`)return;let i=t.current??await n.current;if(i)try{await lC(i,{type:`set_thinking_level`,level:r})}catch(e){console.error(`Failed to set thinking level:`,e)}},[e,t,n]),handleToolPresetChange:(0,d.useCallback)(async e=>{let r=DJ(e);P(e);let i=t.current??await n.current;if(i)try{await lC(i,{type:`set_tools`,toolNames:r})}catch(e){console.error(`Failed to set tools:`,e)}},[P,t,n])}}function nY({addNotice:e,chatInputRef:t,sessionIdRef:n}){let[r,i]=(0,d.useState)(null),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)([]),[l,u]=(0,d.useState)([]);return(0,d.useEffect)(()=>{if(!r?.timeout)return;let e=r.id,t=setTimeout(()=>{Bq(`ui-chain`,`4c dialog auto-close by timeout`,`id=${e.slice(0,8)}`),i(t=>t?.id===e?null:t)},r.timeout);return()=>clearTimeout(t)},[r]),{extensionDialog:r,extensionCustomUi:a,extensionStatuses:s,extensionWidgets:l,setExtensionStatuses:c,setExtensionWidgets:u,respondToExtensionUi:(0,d.useCallback)(async(e,t)=>{let r=n.current;if(i(t=>t?.id===e.id?null:t),r)try{await lC(r,{type:`extension_ui_response`,id:e.id,...t})}catch(e){console.error(`Failed to send extension UI response:`,e)}},[n]),sendExtensionCustomInput:(0,d.useCallback)(async(e,t)=>{let r=n.current;if(r)try{await lC(r,{type:`extension_ui_input`,id:e.id,data:t})}catch(e){console.error(`Failed to send extension custom UI input:`,e)}},[n]),handleExtensionUiRequest:(0,d.useCallback)(n=>{switch(n.method){case`select`:case`confirm`:case`input`:case`editor`:i(n);break;case`notify`:{let t=n.notifyType??`info`,r=typeof n.message==`string`?Jq(n.message):n.message;t===`warning`?console.warn(`[pi] notify (warning): ${n.message}`):t===`error`?console.error(`[pi] notify (error): ${n.message}`):console.info(`[pi] notify: ${n.message}`);let i=typeof r==`string`&&r.length>100;e({id:n.id,message:r,type:t,modal:t===`warning`||t===`error`||i});break}case`setStatus`:c(e=>{let t=e.filter(e=>e.key!==n.statusKey);return n.statusText===void 0?t:[...t,{key:n.statusKey,text:n.statusText}]});break;case`setWidget`:u(e=>{let t=e.filter(e=>e.key!==n.widgetKey);return n.widgetLines?[...t,{key:n.widgetKey,lines:n.widgetLines,placement:n.widgetPlacement??`aboveEditor`}]:t});break;case`setTitle`:n.title&&(document.title=n.title);break;case`set_editor_text`:t?.current?.insertText(n.text);break;case`custom`:o(e=>n.closed?e?.id===n.id?null:e:n)}},[e,t])}}function rY(e){let t=e.content;return typeof t==`string`?t:Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
349
|
+
`):``}function iY(e){if(!e||typeof e!=`object`||e.type!==`image`)return``;let t=e.source;if(t&&typeof t==`object`){let e=t;return[e.type===`url`?`url`:`base64`,typeof e.media_type==`string`?e.media_type:``,typeof e.data==`string`?e.data:``,typeof e.url==`string`?e.url:``].join(`:`)}let n=e;return[`base64`,typeof n.mimeType==`string`?n.mimeType:``,typeof n.data==`string`?n.data:``,``].join(`:`)}function aY(e){function t(t,n){try{if(localStorage.getItem(`piWebDebug`)===`1`){let e=Error().stack;Bq(`messages`,t,e?.split(`
|
|
350
350
|
`).slice(1).join(`
|
|
351
|
-
`))}}catch{}e(n)}return{apply:(e,n)=>t(e,n),append:(e,n)=>t(`${e}:append`,e=>[...e,n]),replaceAll(e,n){t(`${e}:replaceAll`,n)},truncateFrom:(e,n)=>t(`${e}:truncateFrom`,e=>e.slice(0,Math.max(0,n))),dropLastIf:(e,n)=>t(`${e}:dropLastIf`,e=>n(e[e.length-1])?e.slice(0,-1):e)}}function WJ(e){let t=e.content;return JSON.stringify(typeof t==`string`?{text:t,images:[]}:Array.isArray(t)?{text:VJ(e),images:t.map(HJ).filter(Boolean)}:{text:``,images:[]})}function GJ(e,t){if(!e||typeof e!=`object`)return null;let n=e;return typeof n.tokensBefore!=`number`||typeof n.estimatedTokensAfter!=`number`?null:{reason:t,tokensBefore:n.tokensBefore,estimatedTokensAfter:n.estimatedTokensAfter}}function KJ(e,t,n,r){let i=new Set(t),a=new Set(e.filter(e=>e.role===`user`).map(WJ)),o=[...e];for(let e=0;e<n.length;e++){let t=r[e];if(t!==void 0)i.has(t)||o.push(n[e]);else{let t=n[e];(t.role!==`user`||!a.has(WJ(t)))&&o.push(t)}}return o}function qJ(e){let{session:t,newSessionCwd:n,onAgentEnd:r,onAgentSettled:i,onAgentError:a,onSessionCreated:o,onSessionForked:s,modelsRefreshKey:c}=e,l=t===null&&n!==null,[u,f]=(0,d.useState)(null),[p,m]=(0,d.useState)(!l),[h,g]=(0,d.useState)(null),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)([]),x=(0,d.useRef)(null);x.current||=UJ(b);let S=x.current,[C,w]=(0,d.useState)([]),[T,E]=(0,d.useReducer)(fJ,{isStreaming:!1,streamingMessage:null}),D=(0,d.useRef)(null),O=(0,d.useRef)(null),k=(0,d.useRef)(null),A=(0,d.useRef)(new Map),j=(0,d.useRef)(aJ()),M=(0,d.useRef)(!0),P=(0,d.useRef)([]),ee=(0,d.useRef)(new Map),F=(0,d.useRef)(null),I=(0,d.useRef)(null),te=(0,d.useCallback)(()=>{let e=A.current;if(e.size===0)return;let t=k.current;if(!t){e.clear();return}let n=t.content;if(!Array.isArray(n)){e.clear();return}for(let[t,r]of e){let e=r.join(``),i=n[t];if(!i)continue;let a=j.current.take(t,e);a&&(i.type===`thinking`?i.thinking=(i.thinking??``)+a:i.type===`text`?i.text=(i.text??``)+a:i.type===`toolCall`&&(i.streamingOutput=(i.streamingOutput??``)+a))}e.clear()},[]),ne=(0,d.useCallback)(()=>{O.current&&=(clearTimeout(O.current),null),te();let e=D.current;if(D.current=null,e&&Je.current){let t=e,n={...e,content:[...t.content??[]]};(0,d.startTransition)(()=>E({type:`update`,message:n}))}else if(k.current&&Je.current){let e=k.current,t={...e,content:[...e.content??[]]};(0,d.startTransition)(()=>E({type:`update`,message:t}))}},[te]);(0,d.useEffect)(()=>()=>{O.current&&=(clearTimeout(O.current),null),F.current&&=(clearTimeout(F.current),null),I.current&&=(clearTimeout(I.current),null)},[]);let[re,ie]=(0,d.useState)(!1),[ae,L]=(0,d.useState)(!1),R=(0,d.useCallback)(e=>{Je.current=e,ie(e)},[]),oe=(0,d.useCallback)(e=>{Qe.current=e,L(e)},[]),[z,se]=(0,d.useState)(``),[ce,le]=(0,d.useState)(null),[ue,de]=(0,d.useState)(null),[fe,pe]=(0,d.useState)(null),[me,he]=(0,d.useState)(null),[ge,ve]=(0,d.useState)(null),[ye,be]=(0,d.useState)(!1),[xe,Se]=(0,d.useState)(null),[Ce,we]=(0,d.useState)(null),[Te,Ee]=(0,d.useState)(null),[Oe,ke]=(0,d.useState)([]),[Ae,je]=(0,d.useState)(!1),{noticeState:Me,addNotice:Ne,dismissModal:Pe}=LJ(),{t:Fe}=N(),[Ie,Le]=(0,d.useState)({steering:[],followUp:[]}),[Re,ze]=(0,d.useState)(!1),Be=(0,d.useRef)(null),Ve=(0,d.useRef)(null),He=(0,d.useRef)(null),Ue=(0,d.useRef)(null),We=(0,d.useRef)(null),Ge=(0,d.useRef)(0),Ke=(0,d.useRef)(!1),qe=(0,d.useRef)(t?.id??null),Je=(0,d.useRef)(!1),Ye=(0,d.useRef)(!1),Xe=(0,d.useRef)(!1),Ze=(0,d.useRef)(-1),Qe=(0,d.useRef)(!1),$e=(0,d.useRef)(0),et=(0,d.useRef)(null),tt=(0,d.useRef)(!1),nt=(0,d.useRef)(null),rt=(0,d.useRef)(!1),it=(0,d.useRef)(!0),at=(0,d.useRef)(void 0),ot=(0,d.useRef)(0),st=(0,d.useRef)(0),ct=(0,d.useRef)(null),lt=(0,d.useRef)(null),ut=(0,d.useRef)(null),dt=(0,d.useRef)(!1),ft=(0,d.useRef)(0),pt=(0,d.useRef)(!1),{modelNames:mt,modelList:ht,modelError:gt,modelScopeWarnings:_t,modelThinkingLevels:vt,modelThinkingLevelMaps:yt,newSessionModel:bt,newSessionDefaultModel:xt,toolPreset:St,thinkingLevel:Ct,currentModelOverride:wt,pendingModel:Tt,setThinkingLevel:Et,setPendingModel:Dt,setNewSessionDefaultModel:Ot,setCurrentModelOverride:kt,setModelError:At,setToolPresetState:jt,newSessionModelOverrideRef:Mt,thinkingLevelOverrideRef:Nt,loadModels:Pt,handleModelChange:Ft,handleThinkingLevelChange:It,handleToolPresetChange:Lt}=zJ({isNew:l,sessionIdRef:qe,ensuringNewSessionRef:ut,setToolPresetOverride:e.setToolPreset,addNotice:Ne,t:Fe}),{extensionDialog:Rt,extensionCustomUi:zt,extensionStatuses:Bt,extensionWidgets:Vt,setExtensionStatuses:Ht,setExtensionWidgets:Ut,respondToExtensionUi:Wt,sendExtensionCustomInput:Gt,handleExtensionUiRequest:Kt}=BJ({addNotice:Ne,chatInputRef:e.chatInputRef,sessionIdRef:qe}),qt=(0,d.useCallback)(e=>{e?.contextUsage!==void 0&&pe(e.contextUsage??null),e?.systemPrompt!==void 0&&he(e.systemPrompt??null),e?.thinkingLevel!==void 0&&Et(e.thinkingLevel??`auto`),e?.extensionStatuses!==void 0&&Ht(e.extensionStatuses??[]),e?.extensionWidgets!==void 0&&Ut(e.extensionWidgets??[]),e?.queuedMessages!==void 0&&Le(mJ(e.queuedMessages))},[Et,Ht,Ut]),Jt=wt??u?.context.model??Tt??null,Yt=l?bt??xt:Jt,Xt=(0,d.useSyncExternalStore)(De.subscribe,()=>De.get()??null,()=>null);(0,d.useEffect)(()=>{De.load().catch(e=>console.error(`[pi-web] load model thinking:`,e))},[]);let Zt=(0,d.useRef)(null),Qt=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(!Yt||!Xt||Object.keys(vt).length===0)return;let e=Zq(Xt,Yt.provider,Yt.modelId),t=`${Yt.provider}/${Yt.modelId}`,n=Qt.current!==null&&Qt.current!==t;if(Qt.current=t,Zt.current&&Zt.current.key!==t&&(Zt.current=null),!e){n&&!Zt.current&&Ct!==`auto`&&(Et(`auto`),l&&!qe.current&&(Nt.current=null));return}if(Zt.current)return;let r=vt[t],i=!r||r.includes(e),a;if(i)a=e;else if(e===`auto`||!r||r.length===0)a=`auto`;else{a=ca(e,r);let t=De.get()??{},n=$q(t,Yt.provider,Yt.modelId,a);JSON.stringify(n)!==JSON.stringify(t)&&De.load().catch(e=>console.error(`[pi-web] load model thinking for writeback:`,e)).then(async()=>{try{await fetch(`/api/model-thinking`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),await De.refresh()}catch{}})}if(a!==Ct&&(Et(a),l&&!qe.current&&(Nt.current=a===`auto`?null:a),a!==`auto`&&qe.current)){let e=qe.current;lC(e,{type:`set_thinking_level`,level:a}).catch(e=>console.error(`[pi-web] set_thinking_level:`,e))}},[Yt?.provider,Yt?.modelId,Xt,vt,Ct,l]);let $t=(0,d.useCallback)(async e=>{if(Yt&&(Zt.current={key:`${Yt.provider}/${Yt.modelId}`,level:e}),await It(e),!Yt)return;try{await De.load()}catch{}let t=De.get()??{},n=$q(t,Yt.provider,Yt.modelId,e);if(JSON.stringify(n)!==JSON.stringify(t))try{await fetch(`/api/model-thinking`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),await De.refresh()}catch{}},[It,Yt]),{sessionStats:en,setSessionStatsOverride:tn}=RJ({messages:y,contextUsage:fe,data:u,session:t,sessionIdRef:qe}),nn=(0,d.useCallback)(async(e,t=!1,n=!1)=>{let r=!1;try{t&&m(!0);let i=new URLSearchParams({deferMedia:`1`}),a=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(a.status===404)return t&&(f(null),v(null),S.apply(`loadSession:notFound`,[]),g(null)),null;if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();if(qe.current!==e)return null;if(f(o),v(o.leafId),pt.current){let e=o.context.entryIds??[];S.apply(`loadSession:keepOptimistic`,t=>KJ(o.context.messages,e,t,C)),w(e)}else S.replaceAll(`loadSession`,o.context.messages),w(o.context.entryIds??[]);if(kt(null),g(null),o.context.thinkingLevel&&o.context.thinkingLevel!==`off`&&Et(o.context.thinkingLevel),r=!0,t&&m(!1),!n)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(qe.current!==e)return null;let r=n.state;return r?qt(r):n.running||Le({steering:[],followUp:[]}),n}catch(e){return console.error(`Failed to load agent state:`,e),null}}catch(e){return g(String(e)),null}finally{t&&!r&&m(!1)}},[qt,Et,kt,S,C]),rn=(0,d.useCallback)(async(e,t,n=!1)=>{try{let r=new URLSearchParams({deferMedia:`1`});t&&r.set(`leafId`,t);let i=`/api/sessions/${encodeURIComponent(e)}/context?${r}`,a=await fetch(i);if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json(),s=o.context.entryIds??[];S.apply(`loadContext merge=${n}`,e=>n?KJ(o.context.messages,s,e,C):o.context.messages),w(s)}catch(e){console.error(`Failed to load context:`,e)}},[C,S]),an=(0,d.useCallback)(async e=>{try{let t=await lC(e,{type:`get_tools`});t&&jt(uJ(t))}catch(e){console.error(`Failed to load tools:`,e)}},[jt]),on=(0,d.useCallback)((e=0,t=`(no messages)`)=>{let r=qe.current;!l||!n||!r||dt.current||(dt.current=!0,o?.({id:r,path:``,cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[l,n,o]),sn=(0,d.useCallback)(async()=>{if(qe.current||!l||!n)return qe.current;if(ut.current)return ut.current;let e=(async()=>{let e=Mt.current,t=Nt.current;e&&Dt(e);let r=dJ(St),i=await fetch(`/api/agent/new`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:n,type:`ensure_session`,toolNames:r,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json(),o=a.sessionId;return qe.current=o,a.model&&Mt.current===e&&(Dt(a.model),e||Ot(a.model)),a.thinkingLevel&&Nt.current===t&&Et(a.thinkingLevel),o})();ut.current=e;try{return await e}finally{ut.current=null}},[l,n,St,Nt,Mt,Dt,Et,Ot]),cn=(0,d.useCallback)(async()=>{let e=qe.current??await sn();if(!e)return ke([]),[];je(!0);try{let t=(await lC(e,{type:`get_commands`}))?.commands??[];return ke(t),t}catch(e){return console.error(`Failed to load slash commands:`,e),ke([]),[]}finally{je(!1)}},[sn]),ln=(0,d.useCallback)(()=>{Ge.current+=1,Ke.current=!1,We.current&&=(clearTimeout(We.current),null)},[]),un=(0,d.useCallback)(()=>{Be.current?.(),Be.current=null,He.current=null,Ue.current=null},[]),fn=(0,d.useCallback)(e=>{un();let t=`agent:${e}`,n=!1,r=null,i,a={key:t,promise:null,pending:!0},o=e=>{n||(n=!0,r&&clearTimeout(r),Ue.current===a&&(a.pending=!1),i({status:e}))};r=setTimeout(()=>o(`timeout`),EJ);let s=new Promise(e=>{i=e});return a.promise=s,Be.current=dn({ch:`agent`,sessionId:e},e=>{e.type===`connected`?o(`connected`):(e.type===`not_found`||e.type===`start_failed`)&&o(`closed`)}),He.current=e,Ue.current=a,s},[un]),pn=(0,d.useCallback)(async e=>{if(He.current===e&&Be.current){let e=Ue.current;if(e?.pending){let t=await e.promise;if(t.status===`connected`)return;throw un(),new jJ(t.status)}return}let t=await fn(e);if(t.status!==`connected`)throw un(),new jJ(t.status)},[un,fn]),mn=(0,d.useCallback)(()=>{let e=Je.current;return Je.current=!1,ie(!1),Ee(null),de(null),E({type:`end`}),e},[]),hn=(0,d.useCallback)(e=>Ze.current!==e&&(Ze.current=e,r?.(),!0),[r]),gn=(0,d.useCallback)(e=>{ln(),Ke.current=!0;let t=Ge.current,n=async()=>{if(!(t!==Ge.current||qe.current!==e||!Ke.current))try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(t!==Ge.current||qe.current!==e||!Ke.current)return;let a=i.state;if(i.running&&a&&(a.isStreaming||a.isPromptRunning)){Ke.current=!1,We.current=null,Ye.current=!!a?.isStreaming,Xe.current=!!a?.isPromptRunning,R(!0),Ee(a?.isStreaming?{kind:`waiting_model`}:{kind:`running_command`});return}if(i.running&&a?.isCompacting){be(!0),We.current=setTimeout(()=>void n(),yJ);return}Ke.current=!1,We.current=null,un()}catch{if(t!==Ge.current||qe.current!==e||!Ke.current)return;We.current=setTimeout(()=>void n(),yJ)}};We.current=setTimeout(()=>void n(),xJ)},[ln,un,R]),_n=(0,d.useCallback)(async(e=qe.current,t=ft.current)=>{if(ft.current===t)try{e&&await nn(e)}catch(e){if(ft.current!==t)return;throw e}finally{if(ft.current===t){let n=Xe.current,a=Ye.current;Xe.current=!1,Ye.current=!1,pt.current=!1;let o=mn();n?(hn(t),o&&i?.()):a&&o&&(r?.(),i?.()),e&&gn(e)}}},[nn,hn,r,i,gn,mn]),vn=(0,d.useCallback)(async(e,t)=>{await NJ(vJ);let n=Date.now();for(;Je.current&&Date.now()-n<bJ;){if(t!==void 0&&ft.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){let r=await n.json(),i=r.state;if(!r.running||!i||!i.isStreaming&&!i.isPromptRunning){await _n(e,t);return}}}catch{}await NJ(yJ)}},[_n]),yn=(0,d.useCallback)(async e=>{let t=$e.current+1;for($e.current=t;Qe.current&&$e.current===t&&qe.current===e;){await NJ(TJ);try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok||(await n.json()).state?.isBashRunning)continue;if(await nn(e),$e.current!==t||qe.current!==e)return;oe(!1),le(null);return}catch{}}},[nn,oe]),bn=(0,d.useCallback)(async e=>{if(!Je.current)return;let t=ft.current;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)return;let r=await n.json();if(ft.current!==t)return;let i=r.state;if(be(i?.isCompacting??!1),Le(mJ(i?.queuedMessages)),r.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)||!Je.current)return;i&&qt(i),await _n(e,t)}catch{}},[qt,_n]);(0,d.useEffect)(()=>{if(!re)return;let e=()=>{let e=qe.current;e&&bn(e)},t=()=>{document.visibilityState===`visible`&&e()},n=setInterval(e,wJ);return document.addEventListener(`visibilitychange`,t),window.addEventListener(`online`,e),()=>{clearInterval(n),document.removeEventListener(`visibilitychange`,t),window.removeEventListener(`online`,e)}},[re,bn]),(0,d.useEffect)(()=>{Je.current=re},[re]),et.current=(0,d.useCallback)(e=>{let t=e=>{let t=e.assistantMessageEvent;if(!t||typeof t.type!=`string`)return;let n=k.current;if(!n)return;let r=t.contentIndex;if(typeof r!=`number`)return;let i=n.content;if(Array.isArray(i))switch(t.type){case`thinking_start`:{if(i[r]?.type===`thinking`)break;let e={type:`thinking`,thinking:``};r>=i.length?i.push(e):i.splice(r,0,e),M.current=!0;break}case`thinking_delta`:if(i[r]?.type===`thinking`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`thinking_end`:{let e=A.current;if(e.has(r)){let t=e.get(r);e.delete(r);let n=t.join(``),a=j.current.take(r,n),o=i[r];o?.type===`thinking`&&a&&(o.thinking=(o.thinking??``)+a)}let n=i[r];if(n?.type===`thinking`&&typeof t.content==`string`&&(n.thinking=t.content),n?.type===`thinking`){let e=t.thinkingSignature??t.signature;typeof e==`string`&&e.length>0?n.thinkingSignature=e:e&&typeof e==`object`&&(n.thinkingSignature=JSON.stringify(e)),t.redacted===!0&&(n.redacted=!0);let i=t.partial?.content?.[r];i&&typeof i.thinkingSignature==`string`&&!n.thinkingSignature&&(n.thinkingSignature=i.thinkingSignature),i&&i.redacted===!0&&(n.redacted=!0)}break}case`text_start`:{if(i[r]?.type===`text`)break;let e={type:`text`,text:``};r>=i.length?i.push(e):i.splice(r,0,e),M.current=!0;break}case`text_delta`:if(i[r]?.type===`text`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`text_end`:{let e=A.current;if(e.has(r)){let t=e.get(r);e.delete(r);let n=t.join(``),a=j.current.take(r,n),o=i[r];o?.type===`text`&&a&&(o.text=(o.text??``)+a)}let n=i[r];n?.type===`text`&&typeof t.content==`string`&&(n.text=t.content);break}case`toolcall_start`:break;case`toolcall_delta`:if(i[r]?.type===`toolCall`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`toolcall_end`:{let e=A.current;e.has(r)&&e.delete(r),t.toolCall&&typeof t.toolCall==`object`&&(i[r]={type:`toolCall`,...t.toolCall});break}}},n=()=>{if(O.current)return;let e=M.current?CJ:SJ;O.current=setTimeout(()=>{O.current=null,te();let e=k.current??D.current;if(D.current=null,!e||!Je.current)return;let t=e.content;if(!(Array.isArray(t)&&t.some(e=>{let t=e.type;return t===`thinking`?!!((e.thinking?.trim()??``)!==``||typeof e.thinkingSignature==`string`&&e.thinkingSignature.length>0||e.redacted):t!==`text`||(e.text?.trim()??``)!==``})))return;M.current=!1;let n={...e,content:[...t??[]]};(0,d.startTransition)(()=>E({type:`update`,message:n}))},e)},o=()=>{if(!Je.current)return;let r=e.message;if(r&&r.role!==`user`){A.current.clear();let e=rJ(r);j.current.snapshot(e.content),k.current=e,D.current=e,M.current=!0,n()}else k.current&&(t(e),n())};switch(e.type){case`agent_start`:A.current.clear(),k.current=null,D.current=null,M.current=!0,j.current.reset(),ln(),Ye.current=!0,R(!0),Ee({kind:`waiting_model`}),de(null),E({type:`start`});break;case`agent_end`:if(!Je.current)break;if(Ee(null),de(null),E({type:`end`}),k.current=null,D.current=null,A.current.clear(),j.current.reset(),O.current&&=(clearTimeout(O.current),null),F.current&&=(clearTimeout(F.current),null),P.current.length){let e=P.current.join(``);P.current=[],e&&se(t=>t+e)}if(I.current&&=(clearTimeout(I.current),null),ee.current.size){let e=new Map(ee.current);ee.current.clear(),S.apply(`tool_execution_update:batched:drain`,t=>t.map(t=>{if(!(`content`in t)||!Array.isArray(t.content))return t;let n=!1,r=t.content.map(t=>{if(t.type===`toolCall`){let r=e.get(t.toolCallId??``);if(r!==void 0)return n=!0,{...t,streamingOutput:r}}return t});return n?{...t,content:r}:t}))}qe.current&&(nn(qe.current),fetch(`/api/agent/${encodeURIComponent(qe.current)}`).then(e=>e.json()).then(e=>{e.state&&qt(e.state),Le(mJ(e.state?.queuedMessages))}).catch(e=>console.error(`[pi-web] load agent state:`,e)));break;case`agent_settled`:{let e=Ye.current;if(Ye.current=!1,!e||Xe.current)break;let t=qe.current,n=mn();be(!1),t&&(nn(t),gn(t)),k.current=null,D.current=null,A.current.clear(),O.current&&=(clearTimeout(O.current),null),n&&(r?.(),i?.());break}case`prompt_done`:{let e=ft.current,t=Xe.current;Xe.current=!1,pt.current=!1;let n=hn(e);if(!t&&!n)break;let a=qe.current;if(a&&nn(a),!Ye.current){let e=mn();a&&gn(a),e&&(r?.(),i?.())}}break;case`prompt_error`:Ne({type:`error`,message:e.errorMessage??Fe(`i18n.commandFailed`)}),a?.(e.errorMessage??Fe(`i18n.commandFailed`));break;case`extension_error`:Ne({type:`error`,message:e.error??Fe(`i18n.extensionCommandFailed`)}),a?.(e.error??Fe(`i18n.extensionCommandFailed`));break;case`message_start`:o();break;case`message_update`:o(),e.assistantMessageEvent?.type?.startsWith(`thinking`)?Ee({kind:`thinking`}):Ee(null);break;case`message_end`:{if(!Je.current)break;ne();let t=e.message;if(t&&t.role===`user`){let e=nJ(t),n=WJ(e),r=pt.current;pt.current=!1,S.apply(`message_end:userEcho`,t=>{let i=t[t.length-1];return i?.role===`user`&&WJ(i)===n?t:r&&i?.role===`user`?[...t.slice(0,-1),e]:[...t,e]})}else t&&S.append(`message_end:assistant`,nJ(t));E({type:`reset`}),k.current=null,D.current=null,A.current.clear(),O.current&&=(clearTimeout(O.current),null),Ee({kind:`waiting_model`});break}case`tool_execution_start`:{let t=e.toolCallId,n=e.toolName;Ee(e=>{let r=e?.kind===`running_tools`?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n}),{kind:`running_tools`,tools:r}});break}case`tool_execution_update`:{let t=e.toolCallId,n=pJ(e.partialResult);if(n===void 0)break;ee.current.set(t,n),I.current||=setTimeout(()=>{I.current=null;let e=new Map(ee.current);ee.current.clear(),e.size!==0&&(0,d.startTransition)(()=>{S.apply(`tool_execution_update:batched`,t=>t.map(t=>{if(!(`content`in t)||!Array.isArray(t.content))return t;let n=!1,r=t.content.map(t=>{if(t.type===`toolCall`){let r=e.get(t.toolCallId??``);if(r!==void 0)return n=!0,{...t,streamingOutput:r}}return t});return n?{...t,content:r}:t}))})},SJ);break}case`tool_execution_end`:{let t=e.toolCallId;Ee(e=>{if(e?.kind!==`running_tools`)return e;let n=e.tools.filter(e=>e.id!==t);return n.length===0?{kind:`waiting_model`}:{kind:`running_tools`,tools:n}});break}case`bash_execution_update`:{let t=e.delta;if(!t)break;P.current.push(t),F.current||=setTimeout(()=>{F.current=null;let e=P.current;if(P.current=[],e.length===0)return;let t=e.join(``);t&&(0,d.startTransition)(()=>se(e=>e+t))},SJ);break}case`queue_update`:Le({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case`auto_retry_start`:de({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case`auto_retry_end`:de(null);break;case`auto_compaction_start`:case`compaction_start`:be(!0),Se(null),we(null);break;case`auto_compaction_end`:case`compaction_end`:be(!1),e.errorMessage?(Se(e.errorMessage),we(null)):e.aborted||(we(GJ(e.result,e.reason??`auto`)),qe.current&&nn(qe.current));break;case`extension_ui_request`:Kt(e)}},[Ne,ln,Kt,nn,hn,r,i,a,gn,mn,Fe,ne,qt,S,te,R]);let xn=(0,d.useRef)(Kt);xn.current=Kt,(0,d.useEffect)(()=>(Ve.current?.(),Ve.current=dn({ch:`global`},e=>{if(e.type===`extension_ui_request`&&(Bq(`ui-chain`,`4a ws recv ${e.method}`,`id=${String(e.id).slice(0,8)} evtSid=${String(e.sessionId).slice(0,8)} activeSid=${qe.current?.slice(0,8)??`null`}`),e.sessionId&&e.sessionId!==qe.current&&Hq.has(e.method??``)&&Kq(e.sessionId)),e.sessionId===qe.current){if(e.type===`extension_ui_request`){xn.current?.(e);return}et.current?.(e)}}),()=>{Ve.current?.(),Ve.current=null}),[]);let Sn=(0,d.useCallback)(async(r,i)=>{let a=r.trim();if(!a&&!i?.length||Je.current||Qe.current)return;let o=!i?.length&&a.startsWith(`/`);if(!i?.length&&a.startsWith(`!`)){let e=a.startsWith(`!!`),t=(e?a.slice(2):a.slice(1)).trim();if(!t)return;await at.current?.(t,e);return}Bq(`ui-chain`,`1 client send`,JSON.stringify(a.slice(0,80)));let s=ft.current+1;ln(),Xe.current=!0;let c=i?.map(e=>({type:`image`,source:{type:`base64`,media_type:e.mimeType,data:e.data}})),u={role:`user`,content:c?.length?[...r.trim()?[{type:`text`,text:r}]:[],...c]:r,timestamp:Date.now()};S.append(`handleSend:optimistic`,u),pt.current=!0,ft.current=s,R(!0),Ee(o?{kind:`running_command`}:{kind:`waiting_model`}),E({type:`start`}),rt.current=!0,it.current=!0;let d=i?.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType})),f=null,p=!1;try{if(l&&n){let e=bt,t=qe.current??await ut.current,n=t??await sn();n&&(f=n,e&&(Dt(e),t&&await lC(n,{type:`set_model`,provider:e.provider,modelId:e.modelId})),await pn(n),p=!0,on(1,r),await lC(n,{type:`prompt`,message:r,...d?.length?{images:d}:{}}))}else if(t){f=t.id,await pn(t.id),p=!0;let e=wt;await lC(t.id,{type:`prompt`,message:r,...d?.length?{images:d}:{},...e?{provider:e.provider,modelId:e.modelId}:{}})}o&&f&&vn(f,s)}catch(t){if(console.error(`Failed to send message:`,t),p&&f){t instanceof jJ||Ne({type:`error`,message:t instanceof Error?t.message:String(t)}),vn(f,s);return}Xe.current=!1,Je.current=!1,un(),t instanceof jJ&&(pt.current&&(pt.current=!1,S.dropLastIf(`sendError:rollbackOptimistic`,e=>e?.role===`user`)),Ne({type:`error`,message:t.message}),r&&e.chatInputRef?.current?.insertIfEmpty(r)),pt.current=!1,R(!1),Ee(null),E({type:`end`})}},[l,n,bt,t,sn,pn,on,wt,vn,Ne,ln,un,e.chatInputRef,Dt,S,R]);at.current=(0,d.useCallback)(async(n,r)=>{if(Je.current||Qe.current)return;let i=`${r?`!!`:`!`}${n}`;oe(!0),le({command:n,excludeFromContext:r}),se(``);try{let e=qe.current??t?.id??await sn();if(!e)throw Error(`Unable to create a session for the shell command`);await pn(e),on(1,i),await lC(e,{type:`bash`,command:n,excludeFromContext:r}),await nn(e)}catch(t){console.error(`Failed to execute shell command:`,t),Ne({type:`error`,message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(i)}finally{oe(!1),le(null)}},[Ne,pn,sn,nn,e.chatInputRef,on,t,oe]);let Cn=(0,d.useCallback)(async()=>{let e=qe.current;if(e){if(Qe.current){try{await lC(e,{type:`abort_bash`})}catch(e){console.error(`Failed to abort bash:`,e)}return}try{await lC(e,{type:`abort`})}catch(e){console.error(`Failed to abort:`,e)}}},[]),wn=(0,d.useCallback)(async e=>{if(Qe.current)return;let t=qe.current;if(t){ve(e);try{let{cancelled:n,newSessionId:r}=await lC(t,{type:`fork`,entryId:e})??{};!n&&r&&s?.(r)}catch(e){console.error(`Fork failed:`,e)}finally{ve(null)}}},[s]),Tn=(0,d.useCallback)(async e=>{if(Qe.current)return;let t=qe.current;t&&(lC(t,{type:`navigate_tree`,targetId:e}).catch(e=>console.error(`[pi-web] navigate_tree:`,e)),v(e),await rn(t,e))},[rn]),En=(0,d.useCallback)(async e=>{if(Qe.current)return;v(e);let t=qe.current;t&&(await rn(t,e),e&&lC(t,{type:`navigate_tree`,targetId:e}).catch(e=>console.error(`[pi-web] navigate_tree:`,e)))},[rn]),Dn=(0,d.useCallback)(async()=>{let e=qe.current;if(!(!e||ye)){be(!0),Se(null),we(null);try{let t=await lC(e,{type:`compact`});we(GJ(t,`manual`)),await nn(e,!0)}catch(e){Se(e instanceof Error?e.message:String(e)),we(null)}finally{be(!1)}}},[ye,nn]),On=(0,d.useCallback)(async e=>{if(!e.startsWith(`/`))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,n,r=``]=t,i=r.trim(),a=qe.current??await sn(),o=e=>(e.handled&&(e.error?Ne({type:`error`,message:e.error}):e.action!==`openSessionStats`&&Ne({type:`success`,message:e.message??Fe(`i18n.commandCompleted`)})),e);try{switch(ze(!0),n){case`compact`:{if(!a||ye)return o({handled:!0,error:Fe(`i18n.noActiveSessionToCompact`)});be(!0),Se(null),we(null);let e=await lC(a,{type:`compact`,...i?{customInstructions:i}:{}});return we(GJ(e,`manual`)),await nn(a,!0)&&on(),o({handled:!0,message:Fe(`i18n.compactedContext`)})}case`reload`:return a?(await lC(a,{type:`reload`}),await _e.refresh(),await Promise.all([nn(a,!1,!0),an(a),cn(),Pt()]),o({handled:!0,message:Fe(`i18n.reloadedSessionResources`)})):o({handled:!0,error:Fe(`i18n.noActiveSessionToReload`)});case`name`:return a?i?(await lC(a,{type:`set_session_name`,name:i}),await nn(a)&&on(),o({handled:!0,message:Fe(`i18n.sessionRenamedTo`,{name:i})})):o({handled:!0,error:Fe(`i18n.usageName`)}):o({handled:!0,error:Fe(`i18n.noActiveSessionToName`)});case`session`:{if(!a)return o({handled:!0,error:Fe(`i18n.noActiveSession`)});let e=await lC(a,{type:`get_session_stats`});return e&&tn(e),o({handled:!0,action:`openSessionStats`})}case`copy`:{if(!a)return o({handled:!0,error:Fe(`i18n.noActiveSession`)});let e=(await lC(a,{type:`get_last_assistant_text`}))?.text??``;return e?(await navigator.clipboard.writeText(e),o({handled:!0,message:Fe(`i18n.copiedLastAssistantMessage`)})):o({handled:!0,error:Fe(`i18n.noAssistantMessageToCopy`)})}default:return{handled:!1}}}catch(e){return o({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{ze(!1),n===`compact`&&be(!1)}},[Ne,sn,ye,Pt,nn,cn,an,on,tn,Fe]),kn=(0,d.useCallback)(async(e,t,n)=>{let r=qe.current;if(!r)return;let i=t?.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType}));try{await lC(r,{...e,...i?.length?{images:i}:{}})}catch(e){console.error(`Failed to ${n}:`,e),Ne({type:`error`,message:e instanceof Error?e.message:String(e)})}},[Ne]),An=(0,d.useCallback)((e,t)=>kn({type:`steer`,message:e},t,`steer`),[kn]),jn=(0,d.useCallback)((e,t,n)=>kn({type:`prompt`,message:e,streamingBehavior:t},n,`queue prompt`),[kn]),Mn=(0,d.useCallback)((e,t)=>kn({type:`follow_up`,message:e},t,`follow up`),[kn]),Nn=(0,d.useCallback)(async()=>{let e=qe.current;if(e)try{await lC(e,{type:`abort_compaction`})}catch(e){console.error(`Failed to abort compaction:`,e)}},[]),Pn=(0,d.useCallback)(async()=>{let t=qe.current;if(t)try{let n=await lC(t,{type:`clear_queue`});Le({steering:[],followUp:[]});let r=[...n?.steering??[],...n?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join(`
|
|
351
|
+
`))}}catch{}e(n)}return{apply:(e,n)=>t(e,n),append:(e,n)=>t(`${e}:append`,e=>[...e,n]),replaceAll(e,n){t(`${e}:replaceAll`,n)},truncateFrom:(e,n)=>t(`${e}:truncateFrom`,e=>e.slice(0,Math.max(0,n))),dropLastIf:(e,n)=>t(`${e}:dropLastIf`,e=>n(e[e.length-1])?e.slice(0,-1):e)}}function oY(e){let t=e.content;return JSON.stringify(typeof t==`string`?{text:t,images:[]}:Array.isArray(t)?{text:rY(e),images:t.map(iY).filter(Boolean)}:{text:``,images:[]})}function sY(e,t){if(!e||typeof e!=`object`)return null;let n=e;return typeof n.tokensBefore!=`number`||typeof n.estimatedTokensAfter!=`number`?null:{reason:t,tokensBefore:n.tokensBefore,estimatedTokensAfter:n.estimatedTokensAfter}}function cY(e,t,n,r){let i=new Set(t),a=new Set(e.filter(e=>e.role===`user`).map(oY)),o=[...e];for(let e=0;e<n.length;e++){let t=r[e];if(t!==void 0)i.has(t)||o.push(n[e]);else{let t=n[e];(t.role!==`user`||!a.has(oY(t)))&&o.push(t)}}return o}function lY(e){let{session:t,newSessionCwd:n,onAgentEnd:r,onAgentSettled:i,onAgentError:a,onSessionCreated:o,onSessionForked:s,modelsRefreshKey:c}=e,l=t===null&&n!==null,[u,f]=(0,d.useState)(null),[p,m]=(0,d.useState)(!l),[h,g]=(0,d.useState)(null),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)([]),x=(0,d.useRef)(null);x.current||=aY(b);let S=x.current,[C,w]=(0,d.useState)([]),[T,E]=(0,d.useReducer)(OJ,{isStreaming:!1,streamingMessage:null}),D=(0,d.useRef)(null),O=(0,d.useRef)(null),k=(0,d.useRef)(null),A=(0,d.useRef)(new Map),j=(0,d.useRef)(xJ()),M=(0,d.useRef)(!0),P=(0,d.useRef)([]),ee=(0,d.useRef)(new Map),F=(0,d.useRef)(null),I=(0,d.useRef)(null),te=(0,d.useCallback)(()=>{let e=A.current;if(e.size===0)return;let t=k.current;if(!t){e.clear();return}let n=t.content;if(!Array.isArray(n)){e.clear();return}for(let[t,r]of e){let e=r.join(``),i=n[t];if(!i)continue;let a=j.current.take(t,e);a&&(i.type===`thinking`?i.thinking=(i.thinking??``)+a:i.type===`text`?i.text=(i.text??``)+a:i.type===`toolCall`&&(i.streamingOutput=(i.streamingOutput??``)+a))}e.clear()},[]),ne=(0,d.useCallback)(()=>{O.current&&=(clearTimeout(O.current),null),te();let e=D.current;if(D.current=null,e&&Je.current){let t=e,n={...e,content:[...t.content??[]]};(0,d.startTransition)(()=>E({type:`update`,message:n}))}else if(k.current&&Je.current){let e=k.current,t={...e,content:[...e.content??[]]};(0,d.startTransition)(()=>E({type:`update`,message:t}))}},[te]);(0,d.useEffect)(()=>()=>{O.current&&=(clearTimeout(O.current),null),F.current&&=(clearTimeout(F.current),null),I.current&&=(clearTimeout(I.current),null)},[]);let[re,ie]=(0,d.useState)(!1),[ae,L]=(0,d.useState)(!1),R=(0,d.useCallback)(e=>{Je.current=e,ie(e)},[]),oe=(0,d.useCallback)(e=>{Qe.current=e,L(e)},[]),[z,se]=(0,d.useState)(``),[ce,le]=(0,d.useState)(null),[ue,de]=(0,d.useState)(null),[fe,pe]=(0,d.useState)(null),[me,he]=(0,d.useState)(null),[ge,ve]=(0,d.useState)(null),[ye,be]=(0,d.useState)(!1),[xe,Se]=(0,d.useState)(null),[Ce,we]=(0,d.useState)(null),[Te,Ee]=(0,d.useState)(null),[Oe,ke]=(0,d.useState)([]),[Ae,je]=(0,d.useState)(!1),{noticeState:Me,addNotice:Ne,dismissModal:Pe}=$J(),{t:Fe}=N(),[Ie,Le]=(0,d.useState)({steering:[],followUp:[]}),[Re,ze]=(0,d.useState)(!1),Be=(0,d.useRef)(null),Ve=(0,d.useRef)(null),He=(0,d.useRef)(null),Ue=(0,d.useRef)(null),We=(0,d.useRef)(null),Ge=(0,d.useRef)(0),Ke=(0,d.useRef)(!1),qe=(0,d.useRef)(t?.id??null),Je=(0,d.useRef)(!1),Ye=(0,d.useRef)(!1),Xe=(0,d.useRef)(!1),Ze=(0,d.useRef)(-1),Qe=(0,d.useRef)(!1),$e=(0,d.useRef)(0),et=(0,d.useRef)(null),tt=(0,d.useRef)(!1),nt=(0,d.useRef)(null),rt=(0,d.useRef)(!1),it=(0,d.useRef)(!0),at=(0,d.useRef)(void 0),ot=(0,d.useRef)(0),st=(0,d.useRef)(0),ct=(0,d.useRef)(null),lt=(0,d.useRef)(null),ut=(0,d.useRef)(null),dt=(0,d.useRef)(!1),ft=(0,d.useRef)(0),pt=(0,d.useRef)(!1),{modelNames:mt,modelList:ht,modelError:gt,modelScopeWarnings:_t,modelThinkingLevels:vt,modelThinkingLevelMaps:yt,newSessionModel:bt,newSessionDefaultModel:xt,toolPreset:St,thinkingLevel:Ct,currentModelOverride:wt,pendingModel:Tt,setThinkingLevel:Et,setPendingModel:Dt,setNewSessionDefaultModel:Ot,setCurrentModelOverride:kt,setModelError:At,setToolPresetState:jt,newSessionModelOverrideRef:Mt,thinkingLevelOverrideRef:Nt,loadModels:Pt,handleModelChange:Ft,handleThinkingLevelChange:It,handleToolPresetChange:Lt}=tY({isNew:l,sessionIdRef:qe,ensuringNewSessionRef:ut,setToolPresetOverride:e.setToolPreset,addNotice:Ne,t:Fe}),{extensionDialog:Rt,extensionCustomUi:zt,extensionStatuses:Bt,extensionWidgets:Vt,setExtensionStatuses:Ht,setExtensionWidgets:Ut,respondToExtensionUi:Wt,sendExtensionCustomInput:Gt,handleExtensionUiRequest:Kt}=nY({addNotice:Ne,chatInputRef:e.chatInputRef,sessionIdRef:qe}),qt=(0,d.useCallback)(e=>{e?.contextUsage!==void 0&&pe(e.contextUsage??null),e?.systemPrompt!==void 0&&he(e.systemPrompt??null),e?.thinkingLevel!==void 0&&Et(e.thinkingLevel??`auto`),e?.extensionStatuses!==void 0&&Ht(e.extensionStatuses??[]),e?.extensionWidgets!==void 0&&Ut(e.extensionWidgets??[]),e?.queuedMessages!==void 0&&Le(AJ(e.queuedMessages))},[Et,Ht,Ut]),Jt=wt??u?.context.model??Tt??null,Yt=l?bt??xt:Jt,Xt=(0,d.useSyncExternalStore)(De.subscribe,()=>De.get()??null,()=>null);(0,d.useEffect)(()=>{De.load().catch(e=>console.error(`[pi-web] load model thinking:`,e))},[]);let Zt=(0,d.useRef)(null),Qt=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(!Yt||!Xt||Object.keys(vt).length===0)return;let e=pJ(Xt,Yt.provider,Yt.modelId),t=`${Yt.provider}/${Yt.modelId}`,n=Qt.current!==null&&Qt.current!==t;if(Qt.current=t,Zt.current&&Zt.current.key!==t&&(Zt.current=null),!e){n&&!Zt.current&&Ct!==`auto`&&(Et(`auto`),l&&!qe.current&&(Nt.current=null));return}if(Zt.current)return;let r=vt[t],i=!r||r.includes(e),a;if(i)a=e;else if(e===`auto`||!r||r.length===0)a=`auto`;else{a=ca(e,r);let t=De.get()??{},n=hJ(t,Yt.provider,Yt.modelId,a);JSON.stringify(n)!==JSON.stringify(t)&&De.load().catch(e=>console.error(`[pi-web] load model thinking for writeback:`,e)).then(async()=>{try{await fetch(`/api/model-thinking`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),await De.refresh()}catch{}})}if(a!==Ct&&(Et(a),l&&!qe.current&&(Nt.current=a===`auto`?null:a),a!==`auto`&&qe.current)){let e=qe.current;lC(e,{type:`set_thinking_level`,level:a}).catch(e=>console.error(`[pi-web] set_thinking_level:`,e))}},[Yt?.provider,Yt?.modelId,Xt,vt,Ct,l]);let $t=(0,d.useCallback)(async e=>{if(Yt&&(Zt.current={key:`${Yt.provider}/${Yt.modelId}`,level:e}),await It(e),!Yt)return;try{await De.load()}catch{}let t=De.get()??{},n=hJ(t,Yt.provider,Yt.modelId,e);if(JSON.stringify(n)!==JSON.stringify(t))try{await fetch(`/api/model-thinking`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),await De.refresh()}catch{}},[It,Yt]),{sessionStats:en,setSessionStatsOverride:tn}=eY({messages:y,contextUsage:fe,data:u,session:t,sessionIdRef:qe}),nn=(0,d.useCallback)(async(e,t=!1,n=!1)=>{let r=!1;try{t&&m(!0);let i=new URLSearchParams({deferMedia:`1`}),a=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(a.status===404)return t&&(f(null),v(null),S.apply(`loadSession:notFound`,[]),g(null)),null;if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();if(qe.current!==e)return null;if(f(o),v(o.leafId),pt.current){let e=o.context.entryIds??[];S.apply(`loadSession:keepOptimistic`,t=>cY(o.context.messages,e,t,C)),w(e)}else S.replaceAll(`loadSession`,o.context.messages),w(o.context.entryIds??[]);if(kt(null),g(null),o.context.thinkingLevel&&o.context.thinkingLevel!==`off`&&Et(o.context.thinkingLevel),r=!0,t&&m(!1),!n)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(qe.current!==e)return null;let r=n.state;return r?qt(r):n.running||Le({steering:[],followUp:[]}),n}catch(e){return console.error(`Failed to load agent state:`,e),null}}catch(e){return g(String(e)),null}finally{t&&!r&&m(!1)}},[qt,Et,kt,S,C]),rn=(0,d.useCallback)(async(e,t,n=!1)=>{try{let r=new URLSearchParams({deferMedia:`1`});t&&r.set(`leafId`,t);let i=`/api/sessions/${encodeURIComponent(e)}/context?${r}`,a=await fetch(i);if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json(),s=o.context.entryIds??[];S.apply(`loadContext merge=${n}`,e=>n?cY(o.context.messages,s,e,C):o.context.messages),w(s)}catch(e){console.error(`Failed to load context:`,e)}},[C,S]),an=(0,d.useCallback)(async e=>{try{let t=await lC(e,{type:`get_tools`});t&&jt(EJ(t))}catch(e){console.error(`Failed to load tools:`,e)}},[jt]),on=(0,d.useCallback)((e=0,t=`(no messages)`)=>{let r=qe.current;!l||!n||!r||dt.current||(dt.current=!0,o?.({id:r,path:``,cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[l,n,o]),sn=(0,d.useCallback)(async()=>{if(qe.current||!l||!n)return qe.current;if(ut.current)return ut.current;let e=(async()=>{let e=Mt.current,t=Nt.current;e&&Dt(e);let r=DJ(St),i=await fetch(`/api/agent/new`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:n,type:`ensure_session`,toolNames:r,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json(),o=a.sessionId;return qe.current=o,a.model&&Mt.current===e&&(Dt(a.model),e||Ot(a.model)),a.thinkingLevel&&Nt.current===t&&Et(a.thinkingLevel),o})();ut.current=e;try{return await e}finally{ut.current=null}},[l,n,St,Nt,Mt,Dt,Et,Ot]),cn=(0,d.useCallback)(async()=>{let e=qe.current??await sn();if(!e)return ke([]),[];je(!0);try{let t=(await lC(e,{type:`get_commands`}))?.commands??[];return ke(t),t}catch(e){return console.error(`Failed to load slash commands:`,e),ke([]),[]}finally{je(!1)}},[sn]),ln=(0,d.useCallback)(()=>{Ge.current+=1,Ke.current=!1,We.current&&=(clearTimeout(We.current),null)},[]),un=(0,d.useCallback)(()=>{Be.current?.(),Be.current=null,He.current=null,Ue.current=null},[]),fn=(0,d.useCallback)(e=>{un();let t=`agent:${e}`,n=!1,r=null,i,a={key:t,promise:null,pending:!0},o=e=>{n||(n=!0,r&&clearTimeout(r),Ue.current===a&&(a.pending=!1),i({status:e}))};r=setTimeout(()=>o(`timeout`),HJ);let s=new Promise(e=>{i=e});return a.promise=s,Be.current=dn({ch:`agent`,sessionId:e},e=>{e.type===`connected`?o(`connected`):(e.type===`not_found`||e.type===`start_failed`)&&o(`closed`)}),He.current=e,Ue.current=a,s},[un]),pn=(0,d.useCallback)(async e=>{if(He.current===e&&Be.current){let e=Ue.current;if(e?.pending){let t=await e.promise;if(t.status===`connected`)return;throw un(),new qJ(t.status)}return}let t=await fn(e);if(t.status!==`connected`)throw un(),new qJ(t.status)},[un,fn]),mn=(0,d.useCallback)(()=>{let e=Je.current;return Je.current=!1,ie(!1),Ee(null),de(null),E({type:`end`}),e},[]),hn=(0,d.useCallback)(e=>Ze.current!==e&&(Ze.current=e,r?.(),!0),[r]),gn=(0,d.useCallback)(e=>{ln(),Ke.current=!0;let t=Ge.current,n=async()=>{if(!(t!==Ge.current||qe.current!==e||!Ke.current))try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(t!==Ge.current||qe.current!==e||!Ke.current)return;let a=i.state;if(i.running&&a&&(a.isStreaming||a.isPromptRunning)){Ke.current=!1,We.current=null,Ye.current=!!a?.isStreaming,Xe.current=!!a?.isPromptRunning,R(!0),Ee(a?.isStreaming?{kind:`waiting_model`}:{kind:`running_command`});return}if(i.running&&a?.isCompacting){be(!0),We.current=setTimeout(()=>void n(),FJ);return}Ke.current=!1,We.current=null,un()}catch{if(t!==Ge.current||qe.current!==e||!Ke.current)return;We.current=setTimeout(()=>void n(),FJ)}};We.current=setTimeout(()=>void n(),LJ)},[ln,un,R]),_n=(0,d.useCallback)(async(e=qe.current,t=ft.current)=>{if(ft.current===t)try{e&&await nn(e)}catch(e){if(ft.current!==t)return;throw e}finally{if(ft.current===t){let n=Xe.current,a=Ye.current;Xe.current=!1,Ye.current=!1,pt.current=!1;let o=mn();n?(hn(t),o&&i?.()):a&&o&&(r?.(),i?.()),e&&gn(e)}}},[nn,hn,r,i,gn,mn]),vn=(0,d.useCallback)(async(e,t)=>{await YJ(PJ);let n=Date.now();for(;Je.current&&Date.now()-n<IJ;){if(t!==void 0&&ft.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){let r=await n.json(),i=r.state;if(!r.running||!i||!i.isStreaming&&!i.isPromptRunning){await _n(e,t);return}}}catch{}await YJ(FJ)}},[_n]),yn=(0,d.useCallback)(async e=>{let t=$e.current+1;for($e.current=t;Qe.current&&$e.current===t&&qe.current===e;){await YJ(VJ);try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok||(await n.json()).state?.isBashRunning)continue;if(await nn(e),$e.current!==t||qe.current!==e)return;oe(!1),le(null);return}catch{}}},[nn,oe]),bn=(0,d.useCallback)(async e=>{if(!Je.current)return;let t=ft.current;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)return;let r=await n.json();if(ft.current!==t)return;let i=r.state;if(be(i?.isCompacting??!1),Le(AJ(i?.queuedMessages)),r.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)||!Je.current)return;i&&qt(i),await _n(e,t)}catch{}},[qt,_n]);(0,d.useEffect)(()=>{if(!re)return;let e=()=>{let e=qe.current;e&&bn(e)},t=()=>{document.visibilityState===`visible`&&e()},n=setInterval(e,BJ);return document.addEventListener(`visibilitychange`,t),window.addEventListener(`online`,e),()=>{clearInterval(n),document.removeEventListener(`visibilitychange`,t),window.removeEventListener(`online`,e)}},[re,bn]),(0,d.useEffect)(()=>{Je.current=re},[re]),et.current=(0,d.useCallback)(e=>{let t=e=>{let t=e.assistantMessageEvent;if(!t||typeof t.type!=`string`)return;let n=k.current;if(!n)return;let r=t.contentIndex;if(typeof r!=`number`)return;let i=n.content;if(Array.isArray(i))switch(t.type){case`thinking_start`:{if(i[r]?.type===`thinking`)break;let e={type:`thinking`,thinking:``};r>=i.length?i.push(e):i.splice(r,0,e),M.current=!0;break}case`thinking_delta`:if(i[r]?.type===`thinking`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`thinking_end`:{let e=A.current;if(e.has(r)){let t=e.get(r);e.delete(r);let n=t.join(``),a=j.current.take(r,n),o=i[r];o?.type===`thinking`&&a&&(o.thinking=(o.thinking??``)+a)}let n=i[r];if(n?.type===`thinking`&&typeof t.content==`string`&&(n.thinking=t.content),n?.type===`thinking`){let e=t.thinkingSignature??t.signature;typeof e==`string`&&e.length>0?n.thinkingSignature=e:e&&typeof e==`object`&&(n.thinkingSignature=JSON.stringify(e)),t.redacted===!0&&(n.redacted=!0);let i=t.partial?.content?.[r];i&&typeof i.thinkingSignature==`string`&&!n.thinkingSignature&&(n.thinkingSignature=i.thinkingSignature),i&&i.redacted===!0&&(n.redacted=!0)}break}case`text_start`:{if(i[r]?.type===`text`)break;let e={type:`text`,text:``};r>=i.length?i.push(e):i.splice(r,0,e),M.current=!0;break}case`text_delta`:if(i[r]?.type===`text`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`text_end`:{let e=A.current;if(e.has(r)){let t=e.get(r);e.delete(r);let n=t.join(``),a=j.current.take(r,n),o=i[r];o?.type===`text`&&a&&(o.text=(o.text??``)+a)}let n=i[r];n?.type===`text`&&typeof t.content==`string`&&(n.text=t.content);break}case`toolcall_start`:break;case`toolcall_delta`:if(i[r]?.type===`toolCall`&&typeof t.delta==`string`){let e=A.current,n=e.get(r)??[];n.push(t.delta),e.set(r,n)}break;case`toolcall_end`:{let e=A.current;e.has(r)&&e.delete(r),t.toolCall&&typeof t.toolCall==`object`&&(i[r]={type:`toolCall`,...t.toolCall});break}}},n=()=>{if(O.current)return;let e=M.current?zJ:RJ;O.current=setTimeout(()=>{O.current=null,te();let e=k.current??D.current;if(D.current=null,!e||!Je.current)return;let t=e.content;if(!(Array.isArray(t)&&t.some(e=>{let t=e.type;return t===`thinking`?!!((e.thinking?.trim()??``)!==``||typeof e.thinkingSignature==`string`&&e.thinkingSignature.length>0||e.redacted):t!==`text`||(e.text?.trim()??``)!==``})))return;M.current=!1;let n={...e,content:[...t??[]]};(0,d.startTransition)(()=>E({type:`update`,message:n}))},e)},o=()=>{if(!Je.current)return;let r=e.message;if(r&&r.role!==`user`){A.current.clear();let e=yJ(r);j.current.snapshot(e.content),k.current=e,D.current=e,M.current=!0,n()}else k.current&&(t(e),n())};switch(e.type){case`agent_start`:A.current.clear(),k.current=null,D.current=null,M.current=!0,j.current.reset(),ln(),Ye.current=!0,R(!0),Ee({kind:`waiting_model`}),de(null),E({type:`start`});break;case`agent_end`:if(!Je.current)break;if(Ee(null),de(null),E({type:`end`}),k.current=null,D.current=null,A.current.clear(),j.current.reset(),O.current&&=(clearTimeout(O.current),null),F.current&&=(clearTimeout(F.current),null),P.current.length){let e=P.current.join(``);P.current=[],e&&se(t=>t+e)}if(I.current&&=(clearTimeout(I.current),null),ee.current.size){let e=new Map(ee.current);ee.current.clear(),S.apply(`tool_execution_update:batched:drain`,t=>t.map(t=>{if(!(`content`in t)||!Array.isArray(t.content))return t;let n=!1,r=t.content.map(t=>{if(t.type===`toolCall`){let r=e.get(t.toolCallId??``);if(r!==void 0)return n=!0,{...t,streamingOutput:r}}return t});return n?{...t,content:r}:t}))}qe.current&&(nn(qe.current),fetch(`/api/agent/${encodeURIComponent(qe.current)}`).then(e=>e.json()).then(e=>{e.state&&qt(e.state),Le(AJ(e.state?.queuedMessages))}).catch(e=>console.error(`[pi-web] load agent state:`,e)));break;case`agent_settled`:{let e=Ye.current;if(Ye.current=!1,!e||Xe.current)break;let t=qe.current,n=mn();be(!1),t&&(nn(t),gn(t)),k.current=null,D.current=null,A.current.clear(),O.current&&=(clearTimeout(O.current),null),n&&(r?.(),i?.());break}case`prompt_done`:{let e=ft.current,t=Xe.current;Xe.current=!1,pt.current=!1;let n=hn(e);if(!t&&!n)break;let a=qe.current;if(a&&nn(a),!Ye.current){let e=mn();a&&gn(a),e&&(r?.(),i?.())}}break;case`prompt_error`:Ne({type:`error`,message:e.errorMessage??Fe(`i18n.commandFailed`)}),a?.(e.errorMessage??Fe(`i18n.commandFailed`));break;case`extension_error`:Ne({type:`error`,message:e.error??Fe(`i18n.extensionCommandFailed`)}),a?.(e.error??Fe(`i18n.extensionCommandFailed`));break;case`message_start`:o();break;case`message_update`:o(),e.assistantMessageEvent?.type?.startsWith(`thinking`)?Ee({kind:`thinking`}):Ee(null);break;case`message_end`:{if(!Je.current)break;ne();let t=e.message;if(t&&t.role===`user`){let e=vJ(t),n=oY(e),r=pt.current;pt.current=!1,S.apply(`message_end:userEcho`,t=>{let i=t[t.length-1];return i?.role===`user`&&oY(i)===n?t:r&&i?.role===`user`?[...t.slice(0,-1),e]:[...t,e]})}else t&&S.append(`message_end:assistant`,vJ(t));E({type:`reset`}),k.current=null,D.current=null,A.current.clear(),O.current&&=(clearTimeout(O.current),null),Ee({kind:`waiting_model`});break}case`tool_execution_start`:{let t=e.toolCallId,n=e.toolName;Ee(e=>{let r=e?.kind===`running_tools`?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n}),{kind:`running_tools`,tools:r}});break}case`tool_execution_update`:{let t=e.toolCallId,n=kJ(e.partialResult);if(n===void 0)break;ee.current.set(t,n),I.current||=setTimeout(()=>{I.current=null;let e=new Map(ee.current);ee.current.clear(),e.size!==0&&(0,d.startTransition)(()=>{S.apply(`tool_execution_update:batched`,t=>t.map(t=>{if(!(`content`in t)||!Array.isArray(t.content))return t;let n=!1,r=t.content.map(t=>{if(t.type===`toolCall`){let r=e.get(t.toolCallId??``);if(r!==void 0)return n=!0,{...t,streamingOutput:r}}return t});return n?{...t,content:r}:t}))})},RJ);break}case`tool_execution_end`:{let t=e.toolCallId;Ee(e=>{if(e?.kind!==`running_tools`)return e;let n=e.tools.filter(e=>e.id!==t);return n.length===0?{kind:`waiting_model`}:{kind:`running_tools`,tools:n}});break}case`bash_execution_update`:{let t=e.delta;if(!t)break;P.current.push(t),F.current||=setTimeout(()=>{F.current=null;let e=P.current;if(P.current=[],e.length===0)return;let t=e.join(``);t&&(0,d.startTransition)(()=>se(e=>e+t))},RJ);break}case`queue_update`:Le({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case`auto_retry_start`:de({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case`auto_retry_end`:de(null);break;case`auto_compaction_start`:case`compaction_start`:be(!0),Se(null),we(null);break;case`auto_compaction_end`:case`compaction_end`:be(!1),e.errorMessage?(Se(e.errorMessage),we(null)):e.aborted||(we(sY(e.result,e.reason??`auto`)),qe.current&&nn(qe.current));break;case`extension_ui_request`:Kt(e)}},[Ne,ln,Kt,nn,hn,r,i,a,gn,mn,Fe,ne,qt,S,te,R]);let xn=(0,d.useRef)(Kt);xn.current=Kt,(0,d.useEffect)(()=>(Ve.current?.(),Ve.current=dn({ch:`global`},e=>{if(e.type===`extension_ui_request`&&(Bq(`ui-chain`,`4a ws recv ${e.method}`,`id=${String(e.id).slice(0,8)} evtSid=${String(e.sessionId).slice(0,8)} activeSid=${qe.current?.slice(0,8)??`null`}`),e.sessionId&&e.sessionId!==qe.current&&iJ.has(e.method??``)&&cJ(e.sessionId)),e.sessionId===qe.current){if(e.type===`extension_ui_request`){xn.current?.(e);return}et.current?.(e)}}),()=>{Ve.current?.(),Ve.current=null}),[]);let Sn=(0,d.useCallback)(async(r,i)=>{let a=r.trim();if(!a&&!i?.length||Je.current||Qe.current)return;let o=!i?.length&&a.startsWith(`/`);if(!i?.length&&a.startsWith(`!`)){let e=a.startsWith(`!!`),t=(e?a.slice(2):a.slice(1)).trim();if(!t)return;await at.current?.(t,e);return}Bq(`ui-chain`,`1 client send`,JSON.stringify(a.slice(0,80)));let s=ft.current+1;ln(),Xe.current=!0;let c=i?.map(e=>({type:`image`,source:{type:`base64`,media_type:e.mimeType,data:e.data}})),u={role:`user`,content:c?.length?[...r.trim()?[{type:`text`,text:r}]:[],...c]:r,timestamp:Date.now()};S.append(`handleSend:optimistic`,u),pt.current=!0,ft.current=s,R(!0),Ee(o?{kind:`running_command`}:{kind:`waiting_model`}),E({type:`start`}),rt.current=!0,it.current=!0;let d=i?.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType})),f=null,p=!1;try{if(l&&n){let e=bt,t=qe.current??await ut.current,n=t??await sn();n&&(f=n,e&&(Dt(e),t&&await lC(n,{type:`set_model`,provider:e.provider,modelId:e.modelId})),await pn(n),p=!0,on(1,r),await lC(n,{type:`prompt`,message:r,...d?.length?{images:d}:{}}))}else if(t){f=t.id,await pn(t.id),p=!0;let e=wt;await lC(t.id,{type:`prompt`,message:r,...d?.length?{images:d}:{},...e?{provider:e.provider,modelId:e.modelId}:{}})}o&&f&&vn(f,s)}catch(t){if(console.error(`Failed to send message:`,t),p&&f){t instanceof qJ||Ne({type:`error`,message:t instanceof Error?t.message:String(t)}),vn(f,s);return}Xe.current=!1,Je.current=!1,un(),t instanceof qJ&&(pt.current&&(pt.current=!1,S.dropLastIf(`sendError:rollbackOptimistic`,e=>e?.role===`user`)),Ne({type:`error`,message:t.message}),r&&e.chatInputRef?.current?.insertIfEmpty(r)),pt.current=!1,R(!1),Ee(null),E({type:`end`})}},[l,n,bt,t,sn,pn,on,wt,vn,Ne,ln,un,e.chatInputRef,Dt,S,R]);at.current=(0,d.useCallback)(async(n,r)=>{if(Je.current||Qe.current)return;let i=`${r?`!!`:`!`}${n}`;oe(!0),le({command:n,excludeFromContext:r}),se(``);try{let e=qe.current??t?.id??await sn();if(!e)throw Error(`Unable to create a session for the shell command`);await pn(e),on(1,i),await lC(e,{type:`bash`,command:n,excludeFromContext:r}),await nn(e)}catch(t){console.error(`Failed to execute shell command:`,t),Ne({type:`error`,message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(i)}finally{oe(!1),le(null)}},[Ne,pn,sn,nn,e.chatInputRef,on,t,oe]);let Cn=(0,d.useCallback)(async()=>{let e=qe.current;if(e){if(Qe.current){try{await lC(e,{type:`abort_bash`})}catch(e){console.error(`Failed to abort bash:`,e)}return}try{await lC(e,{type:`abort`})}catch(e){console.error(`Failed to abort:`,e)}}},[]),wn=(0,d.useCallback)(async e=>{if(Qe.current)return;let t=qe.current;if(t){ve(e);try{let{cancelled:n,newSessionId:r}=await lC(t,{type:`fork`,entryId:e})??{};!n&&r&&s?.(r)}catch(e){console.error(`Fork failed:`,e)}finally{ve(null)}}},[s]),Tn=(0,d.useCallback)(async e=>{if(Qe.current)return;let t=qe.current;t&&(lC(t,{type:`navigate_tree`,targetId:e}).catch(e=>console.error(`[pi-web] navigate_tree:`,e)),v(e),await rn(t,e))},[rn]),En=(0,d.useCallback)(async e=>{if(Qe.current)return;v(e);let t=qe.current;t&&(await rn(t,e),e&&lC(t,{type:`navigate_tree`,targetId:e}).catch(e=>console.error(`[pi-web] navigate_tree:`,e)))},[rn]),Dn=(0,d.useCallback)(async()=>{let e=qe.current;if(!(!e||ye)){be(!0),Se(null),we(null);try{let t=await lC(e,{type:`compact`});we(sY(t,`manual`)),await nn(e,!0)}catch(e){Se(e instanceof Error?e.message:String(e)),we(null)}finally{be(!1)}}},[ye,nn]),On=(0,d.useCallback)(async e=>{if(!e.startsWith(`/`))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,n,r=``]=t,i=r.trim(),a=qe.current??await sn(),o=e=>(e.handled&&(e.error?Ne({type:`error`,message:e.error}):e.action!==`openSessionStats`&&Ne({type:`success`,message:e.message??Fe(`i18n.commandCompleted`)})),e);try{switch(ze(!0),n){case`compact`:{if(!a||ye)return o({handled:!0,error:Fe(`i18n.noActiveSessionToCompact`)});be(!0),Se(null),we(null);let e=await lC(a,{type:`compact`,...i?{customInstructions:i}:{}});return we(sY(e,`manual`)),await nn(a,!0)&&on(),o({handled:!0,message:Fe(`i18n.compactedContext`)})}case`reload`:return a?(await lC(a,{type:`reload`}),await _e.refresh(),await Promise.all([nn(a,!1,!0),an(a),cn(),Pt()]),o({handled:!0,message:Fe(`i18n.reloadedSessionResources`)})):o({handled:!0,error:Fe(`i18n.noActiveSessionToReload`)});case`name`:return a?i?(await lC(a,{type:`set_session_name`,name:i}),await nn(a)&&on(),o({handled:!0,message:Fe(`i18n.sessionRenamedTo`,{name:i})})):o({handled:!0,error:Fe(`i18n.usageName`)}):o({handled:!0,error:Fe(`i18n.noActiveSessionToName`)});case`session`:{if(!a)return o({handled:!0,error:Fe(`i18n.noActiveSession`)});let e=await lC(a,{type:`get_session_stats`});return e&&tn(e),o({handled:!0,action:`openSessionStats`})}case`copy`:{if(!a)return o({handled:!0,error:Fe(`i18n.noActiveSession`)});let e=(await lC(a,{type:`get_last_assistant_text`}))?.text??``;return e?(await navigator.clipboard.writeText(e),o({handled:!0,message:Fe(`i18n.copiedLastAssistantMessage`)})):o({handled:!0,error:Fe(`i18n.noAssistantMessageToCopy`)})}default:return{handled:!1}}}catch(e){return o({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{ze(!1),n===`compact`&&be(!1)}},[Ne,sn,ye,Pt,nn,cn,an,on,tn,Fe]),kn=(0,d.useCallback)(async(e,t,n)=>{let r=qe.current;if(!r)return;let i=t?.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType}));try{await lC(r,{...e,...i?.length?{images:i}:{}})}catch(e){console.error(`Failed to ${n}:`,e),Ne({type:`error`,message:e instanceof Error?e.message:String(e)})}},[Ne]),An=(0,d.useCallback)((e,t)=>kn({type:`steer`,message:e},t,`steer`),[kn]),jn=(0,d.useCallback)((e,t,n)=>kn({type:`prompt`,message:e,streamingBehavior:t},n,`queue prompt`),[kn]),Mn=(0,d.useCallback)((e,t)=>kn({type:`follow_up`,message:e},t,`follow up`),[kn]),Nn=(0,d.useCallback)(async()=>{let e=qe.current;if(e)try{await lC(e,{type:`abort_compaction`})}catch(e){console.error(`Failed to abort compaction:`,e)}},[]),Pn=(0,d.useCallback)(async()=>{let t=qe.current;if(t)try{let n=await lC(t,{type:`clear_queue`});Le({steering:[],followUp:[]});let r=[...n?.steering??[],...n?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join(`
|
|
352
352
|
|
|
353
|
-
`))}catch(e){console.error(`Failed to recall queued messages:`,e),Ne({type:`error`,message:Fe(`i18n.failedToRecallQueuedMessages`)})}},[e.chatInputRef,Ne,Fe]),Fn=(0,d.useCallback)((e=`smooth`)=>{st.current=Date.now()+hJ,ct.current?.scrollIntoView({behavior:e})},[]),In=(0,d.useCallback)(()=>{let e=lt.current,t=nt.current;if(!e||!t)return;let n=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;st.current=Date.now()+hJ,e.scrollTo({top:n-16,behavior:`smooth`})},[]),Ln=(0,d.useCallback)(e=>{e instanceof KeyboardEvent&&(!AJ.has(e.key)||e.target instanceof Element&&e.target.closest(`input, textarea, [contenteditable='true']`))||(ot.current=Date.now()+gJ)},[]),Rn=(0,d.useCallback)(()=>{if(Date.now()<st.current)return;let e=lt.current;if(e){if(e.scrollHeight-e.scrollTop-e.clientHeight<_J){it.current=!0;return}Je.current&&(Date.now()>ot.current||(it.current=!1))}},[]);return(0,d.useEffect)(()=>(t?(qe.current=t.id,nn(t.id,!0,!1).then(()=>fn(t.id)).then(()=>nn(t.id,!1,!0)).then(e=>{e?.running&&(an(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(Ye.current=!!e.state.isStreaming,Xe.current=!!e.state.isPromptRunning,R(!0),Ee(e.state.isStreaming?{kind:`waiting_model`}:{kind:`running_command`}),E({type:`start`}),!e.state.isStreaming&&e.state.isPromptRunning&&vn(t.id)),e.state?.isBashRunning&&(oe(!0),yn(t.id))),e?.state&&(e.state.isCompacting!==void 0&&be(e.state.isCompacting),qt(e.state))})):l&&n&&sn().then(async e=>{if(e){qe.current=e,await fn(e);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)return;let n=await t.json();qe.current===e&&qt(n.state)}catch{}}}),()=>{$e.current+=1,ln(),un()}),[]),(0,d.useEffect)(()=>(window.addEventListener(`keydown`,Ln),window.addEventListener(`pointerdown`,Ln,{passive:!0}),()=>{window.removeEventListener(`keydown`,Ln),window.removeEventListener(`pointerdown`,Ln)}),[Ln]),(0,d.useEffect)(()=>{let e=lt.current;if(e)return e.addEventListener(`wheel`,Ln,{passive:!0}),e.addEventListener(`touchstart`,Ln,{passive:!0}),e.addEventListener(`scroll`,Rn,{passive:!0}),()=>{e.removeEventListener(`wheel`,Ln),e.removeEventListener(`touchstart`,Ln),e.removeEventListener(`scroll`,Rn)}},[y.length,p,Rn,Ln]),(0,d.useEffect)(()=>{if(y.length>0){if(rt.current)rt.current=!1,tt.current=!0,In();else if(!tt.current)tt.current=!0,Fn(`instant`);else if(it.current){let e=lt.current;e&&(e.scrollTop=e.scrollHeight)}}},[y.length,re,Fn,In]),(0,d.useLayoutEffect)(()=>{if(!it.current||!T.isStreaming)return;let e=lt.current;e&&(e.scrollTop=e.scrollHeight)},[T.isStreaming,T.streamingMessage]),(0,d.useEffect)(()=>{let e=new AbortController,t=()=>Pt(e.signal).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||At(e instanceof Error?e.message:String(e))});return c===0?t():_e.refresh().catch(e=>console.error(`[pi-web] refresh model catalog:`,e)).then(t),()=>e.abort()},[Pt,c,At]),(0,d.useEffect)(()=>{if(!Ce)return;let e=setTimeout(()=>we(null),6e3);return()=>clearTimeout(e)},[Ce]),(0,d.useEffect)(()=>{tn(null)},[y.length,fe?.tokens,fe?.percent,fe?.contextWindow,tn]),{data:u,loading:p,error:h,activeLeafId:_,tree:u?.tree??[],messages:y,entryIds:C,streamState:T,agentRunning:re,modelNames:mt,modelList:ht,modelError:gt,modelScopeWarnings:_t,modelThinkingLevels:vt,modelThinkingLevelMaps:yt,newSessionModel:bt,toolPreset:St,thinkingLevel:Ct,retryInfo:ue,contextUsage:fe,systemPrompt:me,forkingEntryId:ge,isCompacting:ye,compactError:xe,compactResult:Ce,currentModel:Jt,displayModel:Yt,sessionStats:en,slashCommands:Oe,slashCommandsLoading:Ae,queuedMessages:Ie,notices:Me.visible,noticeModals:Me.modals,dismissNoticeModal:Pe,extensionDialog:Rt,extensionCustomUi:zt,extensionStatuses:Bt,extensionWidgets:Vt,respondToExtensionUi:Wt,sendExtensionCustomInput:Gt,isAutoModelSelection:l&&bt===null,agentPhase:Te,isNew:l,sessionIdRef:qe,loadContext:rn,messagesEndRef:ct,scrollContainerRef:lt,lastUserMsgRef:nt,pendingScrollToUserRef:rt,initialScrollDoneRef:tt,handleSend:Sn,handleAbort:Cn,handleFork:wn,handleNavigate:Tn,handleLeafChange:En,handleModelChange:Ft,handleCompact:Dn,handleSteer:An,handleFollowUp:Mn,handlePromptWithStreamingBehavior:jn,handleAbortCompaction:Nn,handleRecallQueue:Pn,handleBuiltinSlashCommand:On,handleToolPresetChange:Lt,handleThinkingLevelChange:$t,loadTools:an,loadSlashCommands:cn,setActiveLeafId:v,setData:f,setMessages:S,setSessionStatsOverride:tn,dispatch:E,setAgentRunning:ie,setForkingEntryId:ve,bashRunning:ae,bashOutput:z,pendingBash:ce,commandBusy:Re,handleAgentEventRef:et}}var JJ={background:`linear-gradient(90deg, var(--accent) 0%, var(--accent) 47%, var(--shine-highlight) 53%, var(--shine-highlight) 100%)`,backgroundSize:`200% 100%`,WebkitBackgroundClip:`text`,backgroundClip:`text`,color:`transparent`,animation:`pi-status-shine 1.5s linear infinite`},YJ={animation:`pi-status-icon-pulse 1.5s ease-in-out infinite`};function XJ(e,t){if(e?.kind===`running_tools`){let n=e.tools.map(e=>e.name);return n.length===0?t(`chat.runningTool`):n.length===1?t(`chat.runningNamedTool`,{name:n[0]}):n.length<=3?t(`chat.runningTools`,{names:n.join(`, `)}):t(`chat.runningToolsMore`,{names:n.slice(0,2).join(`, `),count:n.length-2})}return e?.kind===`thinking`?t(`chat.thinking`):e?.kind===`waiting_model`?t(`chat.waitingModel`):e?.kind===`running_command`?t(`chat.runningCommand`):e?.kind===`retrying`?t(`chat.retrying`,{attempt:e.attempt,max:e.maxAttempts}):null}function ZJ(e){return e?.kind===`running_tools`?(0,E.jsx)(ji,{size:p.lg}):e?.kind===`running_command`?(0,E.jsx)(wi,{size:p.lg}):e?.kind===`thinking`?(0,E.jsx)(ri,{size:p.lg,fill:`currentColor`,style:{color:`var(--bulb-warning)`}}):e?.kind===`retrying`?(0,E.jsx)(Di,{size:p.lg,style:{color:`var(--status-warning)`}}):(0,E.jsx)(ei,{size:p.lg})}function QJ({phase:e,elapsed:t,totalElapsed:n}){let{t:r}=N(),i=XJ(e,r)??r(`chat.runningCommand`);return(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,style:{...JJ,minWidth:0,maxWidth:`100%`},children:[(0,E.jsx)(`span`,{className:`inline-flex flex-shrink-0`,style:YJ,children:ZJ(e)}),(0,E.jsxs)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,minWidth:0},children:[i,t!=null&&(0,E.jsxs)(E.Fragment,{children:[` · `,t]}),n!=null&&(0,E.jsxs)(E.Fragment,{children:[` · `,r(`chat.totalElapsed`,{total:n})]})]})]})}function $J({msg:e,onSend:t,onFillInput:n,testId:r}){let{t:i,locale:a}=N(),o=wt(e.message,a),s=wt(e.label,a),c=()=>{if(e.allowAppend&&n){n(`${o} `);return}t(o)},l=`${e.allowAppend?i(`config.widgets.fillToChatInputTooltip`):i(`config.widgets.sendImmediatelyTooltip`)}${o}`;return(0,E.jsx)(qi,{label:l,children:(0,E.jsx)(AG,{label:s,title:l,onClick:c,testId:r})})}function eY({messages:e,onSend:t,onFillInput:n,testIdPrefix:r=`quick-msg`,wrapperTestId:i=`quick-message-buttons`,center:a=!1}){return e.length===0?null:(0,E.jsx)(`div`,{"data-testid":i,style:{display:`flex`,flexWrap:`wrap`,gap:6,justifyContent:a?`center`:`flex-start`,paddingTop:8,borderTop:a?`1px solid var(--border)`:void 0},children:e.map((e,i)=>(0,E.jsx)($J,{msg:e,onSend:t,onFillInput:n,testId:`${r}-${i}`},i))})}function tY(e){let t=e.currentTime;[523.25,659.25].forEach((n,r)=>{let i=e.createOscillator(),a=e.createGain();i.connect(a),a.connect(e.destination),i.type=`sine`,i.frequency.value=n;let o=t+r*.18;a.gain.setValueAtTime(0,o),a.gain.linearRampToValueAtTime(.18,o+.02),a.gain.exponentialRampToValueAtTime(.001,o+.45),i.start(o),i.stop(o+.45)})}function nY(){let[e,t]=(0,d.useState)(()=>{if(typeof window>`u`)return!0;let e=localStorage.getItem(`pi-sound-enabled`);return e===null||e===`true`}),n=(0,d.useRef)(e);(0,d.useEffect)(()=>{n.current=e},[e]);let r=(0,d.useRef)(null),i=(0,d.useCallback)(()=>{if(r.current&&r.current.state!==`closed`)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),a=(0,d.useCallback)((e=!1)=>{if(!e&&!n.current)return;let t=i();t?.state===`suspended`&&t.resume().catch(()=>{})},[i]);return{soundEnabled:e,onSoundToggle:(0,d.useCallback)(()=>{let e=!n.current;e&&a(!0),n.current=e,localStorage.setItem(`pi-sound-enabled`,String(e)),t(e)},[a]),playDoneSound:(0,d.useCallback)(()=>{if(!n.current)return;let e=i();if(!e)return;let t=()=>{try{tY(e)}catch{}};if(e.state===`suspended`){e.resume().then(t).catch(()=>{});return}t()},[i]),unlockAudio:a,soundEnabledRef:n}}function rY(e){let[t,n]=(0,d.useState)(!1),r=(0,d.useRef)(0);return{isDragOver:t,handleDragEnter:(0,d.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith(`image/`))&&(e.preventDefault(),r.current+=1,n(!0))},[]),handleDragOver:(0,d.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith(`image/`))&&e.preventDefault()},[]),handleDragLeave:(0,d.useCallback)(()=>{--r.current,r.current<=0&&(r.current=0,n(!1))},[]),handleDrop:(0,d.useCallback)(t=>{t.preventDefault(),r.current=0,n(!1),e(Array.from(t.dataTransfer.files))},[e])}}var iY=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,aY=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,oY=/\x1B\[([0-9;]*)m/g,sY=/\x1B_pi:c\x07/g,cY=[`#1f2937`,`#dc2626`,`#16a34a`,`#d97706`,`#2563eb`,`#9333ea`,`#0891b2`,`#6b7280`],lY=[`#9ca3af`,`#ef4444`,`#22c55e`,`#f59e0b`,`#3b82f6`,`#a855f7`,`#06b6d4`,`#e5e7eb`];function uY(e){return e.replace(sY,``).replace(iY,``)}function dY(e){let t=[],n=0;for(;n<e.length;){if(e.charCodeAt(n)===27){let t=e.slice(n).match(aY);if(t){n+=t[0].length;continue}}let r=e.codePointAt(n);if(r===void 0)break;let i=String.fromCodePoint(r);t.push({start:n,end:n+i.length,char:i}),n+=i.length}return t}function fY(e,t){let n=dY(e)[t];return n?e.slice(0,n.start)+e.slice(n.end):e}function pY(e){return dY(e)[0]?.char}function mY(e){let t=dY(e);for(let e=t.length-1;e>=0;e--)if(t[e].char.trim()!==``)return e;return-1}function hY(e){let t=e;for(;;){let e=dY(t),n=e[e.length-1];if(n?.char.trim()!==``)return t;t=t.slice(0,n.start)+t.slice(n.end)}}function gY(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,n=[];for(let r of e){let e=r.replace(sY,``),i=uY(e).trimEnd();if(t.test(i))continue;let a=e,o=pY(a);(o===`│`||o===`┃`)&&(a=fY(a,0),pY(a)===` `&&(a=fY(a,0)));let s=mY(a),c=s>=0?dY(a)[s]?.char:void 0;(c===`│`||c===`┃`)&&(a=fY(a,s)),n.push(hY(a))}for(;n.length>0&&uY(n[0]).trim()===``;)n.shift();for(;n.length>0&&uY(n[n.length-1]).trim()===``;)n.pop();return n.length?n:e}function _Y(e){if(e>=0&&e<8)return cY[e];if(e>=8&&e<16)return lY[e-8];if(e>=16&&e<=231){let t=e-16,n=Math.floor(t/36),r=Math.floor(t%36/6),i=t%6,a=e=>e===0?0:55+e*40;return`rgb(${a(n)}, ${a(r)}, ${a(i)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}function vY(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(r===0)for(let e of Object.keys(n))delete n[e];else if(r===1)n.fontWeight=700;else if(r===2)n.opacity=.65;else if(r===3)n.fontStyle=`italic`;else if(r===4)n.textDecoration=`underline`;else if(r===22)delete n.fontWeight,delete n.opacity;else if(r===23)delete n.fontStyle;else if(r===24)delete n.textDecoration;else if(r===39)delete n.color;else if(r===49)delete n.backgroundColor;else if(r>=30&&r<=37)n.color=cY[r-30];else if(r>=90&&r<=97)n.color=lY[r-90];else if(r>=40&&r<=47)n.backgroundColor=cY[r-40];else if(r>=100&&r<=107)n.backgroundColor=lY[r-100];else if((r===38||r===48)&&t[e+1]===2){let[i,a,o]=[t[e+2],t[e+3],t[e+4]];[i,a,o].every(e=>typeof e==`number`&&Number.isFinite(e))&&(r===38?n.color=`rgb(${i}, ${a}, ${o})`:n.backgroundColor=`rgb(${i}, ${a}, ${o})`),e+=4}else if((r===38||r===48)&&t[e+1]===5){let i=_Y(t[e+2]);i&&(r===38?n.color=i:n.backgroundColor=i),e+=2}}return n}function yY(e){let t=[],n={},r=0,i;for(oY.lastIndex=0;(i=oY.exec(e))!==null;){i.index>r&&t.push({text:e.slice(r,i.index),style:n});let a=i[1]?i[1].split(`;`).map(e=>Number(e||`0`)):[0];n=vY(n,a),r=i.index+i[0].length}return r<e.length&&t.push({text:e.slice(r),style:n}),t}var bY=`max(0px, (100% - 868px) / 2)`,xY=`max(0px, calc((100% - 884px) / 2))`,SY={ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`,Home:`\x1B[H`,End:`\x1B[F`,Insert:`\x1B[2~`,Delete:`\x1B[3~`,PageUp:`\x1B[5~`,PageDown:`\x1B[6~`,Escape:`\x1B`,Backspace:``},CY={ArrowLeft:`\x1Bb`,ArrowRight:`\x1Bf`,ArrowUp:`\x1Bp`,ArrowDown:`\x1Bn`};function wY(e){if(e.length!==1)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t&31):e===`?`?``:null}function TY(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&e.key.toLowerCase()===`v`)return null;if(e.ctrlKey&&!e.altKey){let t=wY(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if(e.key===`Backspace`)return`\x1B`;let t=CY[e.key];if(t)return t;if(e.key.length===1)return`\x1b${e.key}`}return e.key===`Enter`?e.shiftKey?`
|
|
353
|
+
`))}catch(e){console.error(`Failed to recall queued messages:`,e),Ne({type:`error`,message:Fe(`i18n.failedToRecallQueuedMessages`)})}},[e.chatInputRef,Ne,Fe]),Fn=(0,d.useCallback)((e=`smooth`)=>{st.current=Date.now()+jJ,ct.current?.scrollIntoView({behavior:e})},[]),In=(0,d.useCallback)(()=>{let e=lt.current,t=nt.current;if(!e||!t)return;let n=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;st.current=Date.now()+jJ,e.scrollTo({top:n-16,behavior:`smooth`})},[]),Ln=(0,d.useCallback)(e=>{e instanceof KeyboardEvent&&(!KJ.has(e.key)||e.target instanceof Element&&e.target.closest(`input, textarea, [contenteditable='true']`))||(ot.current=Date.now()+MJ)},[]),Rn=(0,d.useCallback)(()=>{if(Date.now()<st.current)return;let e=lt.current;if(e){if(e.scrollHeight-e.scrollTop-e.clientHeight<NJ){it.current=!0;return}Je.current&&(Date.now()>ot.current||(it.current=!1))}},[]);return(0,d.useEffect)(()=>(t?(qe.current=t.id,nn(t.id,!0,!1).then(()=>fn(t.id)).then(()=>nn(t.id,!1,!0)).then(e=>{e?.running&&(an(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(Ye.current=!!e.state.isStreaming,Xe.current=!!e.state.isPromptRunning,R(!0),Ee(e.state.isStreaming?{kind:`waiting_model`}:{kind:`running_command`}),E({type:`start`}),!e.state.isStreaming&&e.state.isPromptRunning&&vn(t.id)),e.state?.isBashRunning&&(oe(!0),yn(t.id))),e?.state&&(e.state.isCompacting!==void 0&&be(e.state.isCompacting),qt(e.state))})):l&&n&&sn().then(async e=>{if(e){qe.current=e,await fn(e);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)return;let n=await t.json();qe.current===e&&qt(n.state)}catch{}}}),()=>{$e.current+=1,ln(),un()}),[]),(0,d.useEffect)(()=>(window.addEventListener(`keydown`,Ln),window.addEventListener(`pointerdown`,Ln,{passive:!0}),()=>{window.removeEventListener(`keydown`,Ln),window.removeEventListener(`pointerdown`,Ln)}),[Ln]),(0,d.useEffect)(()=>{let e=lt.current;if(e)return e.addEventListener(`wheel`,Ln,{passive:!0}),e.addEventListener(`touchstart`,Ln,{passive:!0}),e.addEventListener(`scroll`,Rn,{passive:!0}),()=>{e.removeEventListener(`wheel`,Ln),e.removeEventListener(`touchstart`,Ln),e.removeEventListener(`scroll`,Rn)}},[y.length,p,Rn,Ln]),(0,d.useEffect)(()=>{if(y.length>0){if(rt.current)rt.current=!1,tt.current=!0,In();else if(!tt.current)tt.current=!0,Fn(`instant`);else if(it.current){let e=lt.current;e&&(e.scrollTop=e.scrollHeight)}}},[y.length,re,Fn,In]),(0,d.useLayoutEffect)(()=>{if(!it.current||!T.isStreaming)return;let e=lt.current;e&&(e.scrollTop=e.scrollHeight)},[T.isStreaming,T.streamingMessage]),(0,d.useEffect)(()=>{let e=new AbortController,t=()=>Pt(e.signal).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||At(e instanceof Error?e.message:String(e))});return c===0?t():_e.refresh().catch(e=>console.error(`[pi-web] refresh model catalog:`,e)).then(t),()=>e.abort()},[Pt,c,At]),(0,d.useEffect)(()=>{if(!Ce)return;let e=setTimeout(()=>we(null),6e3);return()=>clearTimeout(e)},[Ce]),(0,d.useEffect)(()=>{tn(null)},[y.length,fe?.tokens,fe?.percent,fe?.contextWindow,tn]),{data:u,loading:p,error:h,activeLeafId:_,tree:u?.tree??[],messages:y,entryIds:C,streamState:T,agentRunning:re,modelNames:mt,modelList:ht,modelError:gt,modelScopeWarnings:_t,modelThinkingLevels:vt,modelThinkingLevelMaps:yt,newSessionModel:bt,toolPreset:St,thinkingLevel:Ct,retryInfo:ue,contextUsage:fe,systemPrompt:me,forkingEntryId:ge,isCompacting:ye,compactError:xe,compactResult:Ce,currentModel:Jt,displayModel:Yt,sessionStats:en,slashCommands:Oe,slashCommandsLoading:Ae,queuedMessages:Ie,notices:Me.visible,noticeModals:Me.modals,dismissNoticeModal:Pe,extensionDialog:Rt,extensionCustomUi:zt,extensionStatuses:Bt,extensionWidgets:Vt,respondToExtensionUi:Wt,sendExtensionCustomInput:Gt,isAutoModelSelection:l&&bt===null,agentPhase:Te,isNew:l,sessionIdRef:qe,loadContext:rn,messagesEndRef:ct,scrollContainerRef:lt,lastUserMsgRef:nt,pendingScrollToUserRef:rt,initialScrollDoneRef:tt,handleSend:Sn,handleAbort:Cn,handleFork:wn,handleNavigate:Tn,handleLeafChange:En,handleModelChange:Ft,handleCompact:Dn,handleSteer:An,handleFollowUp:Mn,handlePromptWithStreamingBehavior:jn,handleAbortCompaction:Nn,handleRecallQueue:Pn,handleBuiltinSlashCommand:On,handleToolPresetChange:Lt,handleThinkingLevelChange:$t,loadTools:an,loadSlashCommands:cn,setActiveLeafId:v,setData:f,setMessages:S,setSessionStatsOverride:tn,dispatch:E,setAgentRunning:ie,setForkingEntryId:ve,bashRunning:ae,bashOutput:z,pendingBash:ce,commandBusy:Re,handleAgentEventRef:et}}var uY={background:`linear-gradient(90deg, var(--accent) 0%, var(--accent) 47%, var(--shine-highlight) 53%, var(--shine-highlight) 100%)`,backgroundSize:`200% 100%`,WebkitBackgroundClip:`text`,backgroundClip:`text`,color:`transparent`,animation:`pi-status-shine 1.5s linear infinite`},dY={animation:`pi-status-icon-pulse 1.5s ease-in-out infinite`};function fY(e,t){if(e?.kind===`running_tools`){let n=e.tools.map(e=>e.name);return n.length===0?t(`chat.runningTool`):n.length===1?t(`chat.runningNamedTool`,{name:n[0]}):n.length<=3?t(`chat.runningTools`,{names:n.join(`, `)}):t(`chat.runningToolsMore`,{names:n.slice(0,2).join(`, `),count:n.length-2})}return e?.kind===`thinking`?t(`chat.thinking`):e?.kind===`waiting_model`?t(`chat.waitingModel`):e?.kind===`running_command`?t(`chat.runningCommand`):e?.kind===`retrying`?t(`chat.retrying`,{attempt:e.attempt,max:e.maxAttempts}):null}function pY(e){return e?.kind===`running_tools`?(0,E.jsx)(ji,{size:p.lg}):e?.kind===`running_command`?(0,E.jsx)(wi,{size:p.lg}):e?.kind===`thinking`?(0,E.jsx)(ri,{size:p.lg,fill:`currentColor`,style:{color:`var(--bulb-warning)`}}):e?.kind===`retrying`?(0,E.jsx)(Di,{size:p.lg,style:{color:`var(--status-warning)`}}):(0,E.jsx)(ei,{size:p.lg})}function mY({phase:e,elapsed:t,totalElapsed:n}){let{t:r}=N(),i=fY(e,r)??r(`chat.runningCommand`);return(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,style:{...uY,minWidth:0,maxWidth:`100%`},children:[(0,E.jsx)(`span`,{className:`inline-flex flex-shrink-0`,style:dY,children:pY(e)}),(0,E.jsxs)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,minWidth:0},children:[i,t!=null&&(0,E.jsxs)(E.Fragment,{children:[` · `,t]}),n!=null&&(0,E.jsxs)(E.Fragment,{children:[` · `,r(`chat.totalElapsed`,{total:n})]})]})]})}function hY({msg:e,onSend:t,onFillInput:n,testId:r}){let{t:i,locale:a}=N(),o=wt(e.message,a),s=wt(e.label,a),c=()=>{if(e.allowAppend&&n){n(`${o} `);return}t(o)},l=`${e.allowAppend?i(`config.widgets.fillToChatInputTooltip`):i(`config.widgets.sendImmediatelyTooltip`)}${o}`;return(0,E.jsx)(qi,{label:l,children:(0,E.jsx)(AG,{label:s,title:l,onClick:c,testId:r})})}function gY({messages:e,onSend:t,onFillInput:n,testIdPrefix:r=`quick-msg`,wrapperTestId:i=`quick-message-buttons`,center:a=!1}){return e.length===0?null:(0,E.jsx)(`div`,{"data-testid":i,style:{display:`flex`,flexWrap:`wrap`,gap:6,justifyContent:a?`center`:`flex-start`,paddingTop:8,borderTop:a?`1px solid var(--border)`:void 0},children:e.map((e,i)=>(0,E.jsx)(hY,{msg:e,onSend:t,onFillInput:n,testId:`${r}-${i}`},i))})}function _Y(e){let t=e.currentTime;[523.25,659.25].forEach((n,r)=>{let i=e.createOscillator(),a=e.createGain();i.connect(a),a.connect(e.destination),i.type=`sine`,i.frequency.value=n;let o=t+r*.18;a.gain.setValueAtTime(0,o),a.gain.linearRampToValueAtTime(.18,o+.02),a.gain.exponentialRampToValueAtTime(.001,o+.45),i.start(o),i.stop(o+.45)})}function vY(){let[e,t]=(0,d.useState)(()=>{if(typeof window>`u`)return!0;let e=localStorage.getItem(`pi-sound-enabled`);return e===null||e===`true`}),n=(0,d.useRef)(e);(0,d.useEffect)(()=>{n.current=e},[e]);let r=(0,d.useRef)(null),i=(0,d.useCallback)(()=>{if(r.current&&r.current.state!==`closed`)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),a=(0,d.useCallback)((e=!1)=>{if(!e&&!n.current)return;let t=i();t?.state===`suspended`&&t.resume().catch(()=>{})},[i]);return{soundEnabled:e,onSoundToggle:(0,d.useCallback)(()=>{let e=!n.current;e&&a(!0),n.current=e,localStorage.setItem(`pi-sound-enabled`,String(e)),t(e)},[a]),playDoneSound:(0,d.useCallback)(()=>{if(!n.current)return;let e=i();if(!e)return;let t=()=>{try{_Y(e)}catch{}};if(e.state===`suspended`){e.resume().then(t).catch(()=>{});return}t()},[i]),unlockAudio:a,soundEnabledRef:n}}function yY(e){let[t,n]=(0,d.useState)(!1),r=(0,d.useRef)(0);return{isDragOver:t,handleDragEnter:(0,d.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith(`image/`))&&(e.preventDefault(),r.current+=1,n(!0))},[]),handleDragOver:(0,d.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith(`image/`))&&e.preventDefault()},[]),handleDragLeave:(0,d.useCallback)(()=>{--r.current,r.current<=0&&(r.current=0,n(!1))},[]),handleDrop:(0,d.useCallback)(t=>{t.preventDefault(),r.current=0,n(!1),e(Array.from(t.dataTransfer.files))},[e])}}var bY=`max(0px, (100% - 868px) / 2)`,xY=`max(0px, calc((100% - 884px) / 2))`,SY={ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`,Home:`\x1B[H`,End:`\x1B[F`,Insert:`\x1B[2~`,Delete:`\x1B[3~`,PageUp:`\x1B[5~`,PageDown:`\x1B[6~`,Escape:`\x1B`,Backspace:``},CY={ArrowLeft:`\x1Bb`,ArrowRight:`\x1Bf`,ArrowUp:`\x1Bp`,ArrowDown:`\x1Bn`};function wY(e){if(e.length!==1)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t&31):e===`?`?``:null}function TY(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&e.key.toLowerCase()===`v`)return null;if(e.ctrlKey&&!e.altKey){let t=wY(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if(e.key===`Backspace`)return`\x1B`;let t=CY[e.key];if(t)return t;if(e.key.length===1)return`\x1b${e.key}`}return e.key===`Enter`?e.shiftKey?`
|
|
354
354
|
`:`\r`:e.key===`Tab`?e.shiftKey?`\x1B[Z`:` `:SY[e.key]??null}function EY(e){return`\x1b[200~${e}\x1b[201~`}function DY(e){if(e.type!==`thinking`)return!1;let t=e;return t.thinking.trim()===``&&!!(t.redacted||typeof t.thinkingSignature==`string`&&t.thinkingSignature.trim().length>0)}function OY(e,t={}){return e.type===`thinking`&&!e.deferred&&!t.isStreaming&&e.thinking.trim()===``&&!DY(e)}function kY(e,t={}){return(e.content??[]).filter(e=>!OY(e,t))}function AY(e,t={}){return t.isStreaming||e.stopReason!==`error`?null:e.errorMessage?.trim()||`Unknown provider error`}function jY(e){return e.type===`text`||e.type===`image`}function MY(e,t={}){let n=kY(e,t),r=n.findLastIndex(e=>!jY(e));return r===-1?{answerBlocks:n,processBlocks:[]}:{answerBlocks:n.slice(r+1),processBlocks:n.slice(0,r+1)}}function NY(e){return e.filter(e=>e.type===`toolCall`).length}function PY(e){return e.role===`user`?96:e.role===`assistant`?260:120}function FY(e){return e.role===`assistant`&&MY(e).answerBlocks.some(e=>e.type===`image`||e.type===`text`&&e.text.trim().length>0)}function IY(e,t,n){for(let r=n-1;r>t;r--)if(FY(e[r]))return r;for(let r=n-1;r>t;r--)if(e[r]?.role===`assistant`)return r;return-1}function LY(e,t){let n=0;for(let r of t){let t=e[r];t?.role===`assistant`&&(n+=NY(kY(t)))}return n}function RY(e){return e.role===`assistant`?kY(e).length>0:e.role===`custom`}function zY(e){return e.role===`user`||e.role===`custom`&&e.customType===`compaction`}function BY(e,t,n={}){let r={...e,content:t};return n.omitUsage&&(r.usage=void 0),r}function VY(e,t){let{isLiveTail:n,lastAnchorIdx:r,visibleRefIndexByMessage:i}=t,a=[],o=(t,n={})=>{a.push({key:`message-${t}`,kind:`message`,msgIdx:t,estimate:PY(e[t]),...n})};for(let t=0;t<e.length;){let s=e[t];if(!zY(s)){o(t),t+=1;continue}let c=t,l=c+1;for(;l<e.length&&!zY(e[l]);)l+=1;let u=IY(e,c,l);if(u===-1||n&&l===e.length&&c===r){for(let e=c;e<l;e++)o(e);t=l;continue}o(c);let d=[];for(let e=c+1;e<u;e++)d.push(e);let f=d.filter(t=>RY(e[t])),p=e[u],m=MY(p),h=m.processBlocks.length>0?BY(p,m.processBlocks,{omitUsage:!0}):null,g=m.answerBlocks.length>0||AY(p)?BY(p,m.answerBlocks):null,_=f.length+ +!!h;if(_>0){let t=f.map(e=>i.get(e)).find(e=>typeof e==`number`)??(g?void 0:i.get(u));a.push({key:`group-header-${c}-${u}`,kind:`groupHeader`,groupUserIdx:c,finalAssistantIdx:u,messageCount:_,toolCallCount:LY(e,f)+NY(m.processBlocks),processRefIdx:t,estimate:40}),f.forEach((e,t)=>{o(e,{isProcess:!0,attachRef:!1,groupLast:!h&&t===f.length-1})}),h&&o(u,{isProcessFinal:!0,attachRef:!1,messageOverride:h,showTimestamp:!1,groupLast:!0})}g&&a.push({key:`message-${u}-answer`,kind:`message`,msgIdx:u,estimate:PY(e[u]),messageOverride:g,isAnswer:!0});for(let e=u+1;e<l;e++)o(e);t=l}return a}function HY(e){let t=new Map;return e.forEach((e,n)=>{e.kind===`message`&&t.set(e.msgIdx,n)}),t}var UY=new Map;function WY(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function GY(e){return!e.value&&e.images.length===0}function KY(e){let t=UY.get(e);return t?WY(t):null}function qY(e,t){if(GY(t)){UY.delete(e);return}UY.set(e,WY(t))}function JY(e){UY.delete(e)}var YY=`pi-web:pending-message:`;function XY(e,t){if(!t){QY(e);return}try{localStorage.setItem(YY+e,t)}catch{}}function ZY(e){try{return localStorage.getItem(YY+e)}catch{return null}}function QY(e){try{localStorage.removeItem(YY+e)}catch{}}function $Y(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===43||e===47}function eX(e){if(!e||e.length%4!=0)return null;let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`),n=e.length-t;for(let t=0;t<n;t+=1)if(!$Y(e.charCodeAt(t)))return null;for(let t=n;t<e.length;t+=1)if(e[t]!==`=`)return null;return e.length/4*3-t}function tX(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.data!=`string`||typeof t.mimeType!=`string`||!t.mimeType.startsWith(`image/`))return!1;let n=eX(t.data);return n!==null&&n<=10485760}function nX({active:e,label:t,desc:n,onSelect:r}){return(0,E.jsxs)(`button`,{type:`button`,onClick:r,style:{display:`flex`,alignItems:`center`,gap:8,width:`100%`,padding:`7px 12px`,background:e?`var(--bg-selected)`:`none`,border:`none`,color:e?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,textAlign:`left`,fontWeight:e?600:400,whiteSpace:`nowrap`},className:e?`selectable-row is-selected`:`selectable-row`,children:[e?(0,E.jsx)(Rr,{size:p.xs,strokeWidth:4.8,style:{flexShrink:0}}):(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(`span`,{style:{flex:1},children:t}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,marginLeft:8},children:n})]})}var rX=[`off`,`default`,`full`],iX={off:`none`,default:`default`,full:`full`},aX=100;function oX(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}function sX(e){return{data:e.data,mimeType:e.mimeType}}function cX(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function lX(e){return(e??[]).filter(tX).slice(0,10).map(cX)}function uX(e){e.previewUrl.startsWith(`blob:`)&&URL.revokeObjectURL(e.previewUrl)}function dX({kind:e,text:t}){return(0,E.jsx)(qi,{label:t,wrapperStyle:{display:`flex`,minWidth:0,flex:1},children:(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`3px 10px`,fontSize:`var(--text-base)`,color:`var(--text-muted)`,minWidth:0},children:[(0,E.jsx)(`span`,{style:{flexShrink:0,fontSize:`var(--text-xs)`,fontFamily:`var(--font-mono)`,padding:`1px 7px`,borderRadius:999,border:`1px solid ${e===`steer`?`color-mix(in srgb, var(--accent) 45%, transparent)`:`var(--border)`}`,color:e===`steer`?`var(--accent)`:`var(--text-dim)`},children:e}),(0,E.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:t})]})})}function fX({tone:e,title:t,body:n}){let r=e===`error`?`239,68,68`:`234,179,8`;return(0,E.jsxs)(`div`,{role:`alert`,style:{display:`flex`,alignItems:`flex-start`,gap:8,maxHeight:120,marginBottom:8,padding:`7px 10px`,overflowY:`auto`,border:`1px solid rgba(${r},0.3)`,borderRadius:6,background:`rgba(${r},0.07)`,color:`rgb(${r})`,fontSize:`var(--text-sm)`,lineHeight:1.45},children:[(0,E.jsx)(Di,{size:p.lg,style:{flexShrink:0,marginTop:1},"aria-hidden":`true`}),(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:{fontWeight:600},children:t}),(0,E.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:n})]})]})}function pX({error:e}){return e?(0,E.jsx)(fX,{tone:`error`,title:`Model error`,body:e}):null}function mX({warnings:e}){return!e||e.length===0?null:(0,E.jsx)(fX,{tone:`warning`,title:e.length>1?`Model scope warnings`:`Model scope warning`,body:e.join(`
|
|
355
355
|
`)})}var hX=(0,d.forwardRef)(function({onSend:e,onAbort:t,onSteer:n,onFollowUp:r,isStreaming:i,model:a,isAutoModelSelection:o,modelNames:s,modelList:c,modelError:l,modelScopeWarnings:u,onModelChange:f,onCompact:m,onReloadFromDisk:h,onAbortCompaction:g,isCompacting:_,compactError:v,compactResult:y,toolPreset:b,onToolPresetChange:x,thinkingLevel:S,onThinkingLevelChange:C,availableThinkingLevels:w,thinkingLevelMap:T,onOpenModelConfig:D,retryInfo:O,queuedMessages:k,inputHistory:A=[],onRecallQueue:j,slashCommands:M,slashCommandsLoading:P,onLoadSlashCommands:ee,onBuiltinCommand:F,commandBusy:I,soundEnabled:te,onSoundToggle:re,onAudioUnlock:ie,onPromptWithStreamingBehavior:ae,draftKey:L,cwd:R},oe){let{t:z}=N(),se=ne(),{isDark:ce}=Tr(),[le,ue]=(0,d.useState)(()=>L?KY(L)?.value??``:``),de=(k?.steering.length??0)+(k?.followUp.length??0),[fe,pe]=(0,d.useState)(!1),[me,he]=(0,d.useState)(``),[ge,_e]=(0,d.useState)(0),ve=(0,d.useRef)(null),[ye,be]=(0,d.useState)(!1),[xe,Se]=(0,d.useState)(!1),[Ce,we]=(0,d.useState)(!1),[Te,Ee]=(0,d.useState)(null),[De,Oe]=(0,d.useState)(()=>L?lX(KY(L)?.images):[]),ke=le.trimStart(),Ae=De.length===0&&ke.startsWith(`!`),je=Ae&&ke.startsWith(`!!`),[Me,Ne]=(0,d.useState)(null),[Pe,Fe]=(0,d.useState)(!1),[Ie,Le]=(0,d.useState)(0),[Re,ze]=(0,d.useState)(!1),[Be,Ve]=(0,d.useState)(0),[He,Ue]=(0,d.useState)(null),[We,Ge]=(0,d.useState)(!1),[Ke,qe]=(0,d.useState)(null),[Je,Ye]=(0,d.useState)(null),Xe=R&&Je?.cwd===R?Je.values:{},Ze=(0,d.useRef)(null),Qe=(0,d.useRef)(null),$e=(0,d.useRef)(null),et=(0,d.useRef)(null),tt=(0,d.useRef)(null),nt=(0,d.useRef)(null),rt=(0,d.useRef)(null),it=(0,d.useRef)(null),at=(0,d.useRef)(!1),ot=(0,d.useRef)(0),st=(0,d.useRef)([]),ct=(0,d.useRef)([]),lt=(0,d.useRef)(null),ut=(0,d.useRef)(null),dt=(0,d.useRef)(L),ft=(0,d.useRef)(le),pt=(0,d.useRef)(De),mt=(0,d.useRef)(0);(0,d.useEffect)(()=>{ft.current=le}),(0,d.useEffect)(()=>{pt.current=De});let ht=(0,d.useCallback)(async e=>{if(i)return;let t=Math.max(0,10-pt.current.length-mt.current),n=e.filter(e=>e.type.startsWith(`image/`)&&e.size<=10485760).slice(0,t);if(n.length){mt.current+=n.length;try{let e=await Promise.all(n.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=r.result.split(`,`)[1];t({data:n,mimeType:e.type,previewUrl:URL.createObjectURL(e)})},r.onerror=n,r.readAsDataURL(e)})));Oe(t=>{let n=e.slice(0,Math.max(0,10-t.length));return e.slice(n.length).forEach(uX),[...t,...n]})}finally{mt.current-=n.length}}},[i]),gt=(0,d.useCallback)(e=>{Oe(t=>{let n=[...t],[r]=n.splice(e,1);return r&&uX(r),n})},[]);(0,d.useImperativeHandle)(oe,()=>({insertIfEmpty(e){let t=Ze.current;(t?t.value:le).trim()||(ue(e),Ne(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=Ze.current,n=[e,t?t.value:le].filter(e=>e.trim()).join(`
|
|
356
356
|
|
|
@@ -437,7 +437,7 @@ ${e}</tr>
|
|
|
437
437
|
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${W1(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=G1(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+W1(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=G1(e);if(i===null)return W1(n);e=i;let a=`<img src="${e}" alt="${W1(n)}"`;return t&&(a+=` title="${W1(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:W1(e.text)}},t0=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},n0=class e{options;renderer;textRenderer;constructor(e){this.options=e||j$,this.options.renderer=this.options.renderer||new e0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new t0}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},r0=class{options;block;constructor(e){this.options=e||j$}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?$1.lex:$1.lexInline}provideParser(e=this.block){return e?n0.parse:n0.parseInline}},i0=new class{defaults=A$();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=n0;Renderer=e0;TextRenderer=t0;Lexer=$1;Tokenizer=Q1;Hooks=r0;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new e0(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Q1(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new r0;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=r0.passThroughHooks.has(n)?e=>{if(this.defaults.async&&r0.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return $1.lex(e,t??this.defaults)}parser(e,t){return n0.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?$1.lex:$1.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?n0.parse:n0.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?$1.lex:$1.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?n0.parse:n0.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
|
|
438
438
|
Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+W1(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function a0(e,t){return i0.parse(e,t)}a0.options=a0.setOptions=function(e){return i0.setOptions(e),a0.defaults=i0.defaults,M$(a0.defaults),a0},a0.getDefaults=A$,a0.defaults=j$,a0.use=function(...e){return i0.use(...e),a0.defaults=i0.defaults,M$(a0.defaults),a0},a0.walkTokens=function(e,t){return i0.walkTokens(e,t)},a0.parseInline=i0.parseInline,a0.Parser=n0,a0.parser=n0.parse,a0.Renderer=e0,a0.TextRenderer=t0,a0.Lexer=$1,a0.lexer=$1.lex,a0.Tokenizer=Q1,a0.Hooks=r0,a0.parse=a0,a0.options,a0.setOptions,a0.use,a0.walkTokens,a0.parseInline,n0.parse,$1.lex;var o0=`modulepreload`,s0=function(e){return`/`+e},c0={},l0=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=s0(t,n),t=s(t),t in c0)return;c0[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:o0,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},u0=300,d0=`300px`,f0=500;function p0(e={}){let{immediate:t=!1,debounceDelay:n=u0,rootMargin:r=d0,idleTimeout:i=f0}=e,[a,o]=(0,d.useState)(!1),s=(0,d.useRef)(null),c=(0,d.useRef)(null),l=(0,d.useRef)(null),u=(0,d.useMemo)(()=>e=>{let t=Date.now();return window.setTimeout(()=>{e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})},1)},[]),f=(0,d.useMemo)(()=>typeof window<`u`&&window.requestIdleCallback?(e,t)=>window.requestIdleCallback(e,t):u,[u]),p=(0,d.useMemo)(()=>typeof window<`u`&&window.cancelIdleCallback?e=>window.cancelIdleCallback(e):e=>{clearTimeout(e)},[]);return(0,d.useEffect)(()=>{if(t){o(!0);return}let e=s.current;if(!e)return;c.current&&=(clearTimeout(c.current),null),l.current&&=(p(l.current),null);let a=()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(p(l.current),null)},u=e=>{l.current=f(t=>{t.timeRemaining()>0||t.didTimeout?(o(!0),e.disconnect()):l.current=f(()=>{o(!0),e.disconnect()},{timeout:i/2})},{timeout:i})},d=e=>{a(),c.current=window.setTimeout(()=>{var t;let n=e.takeRecords();(n.length===0||(t=n.at(-1)?.isIntersecting)!=null&&t)&&u(e)},n)},m=(e,t)=>{e.isIntersecting?d(t):a()},h=new IntersectionObserver(e=>{for(let t of e)m(t,h)},{rootMargin:r,threshold:0});return h.observe(e),()=>{c.current&&clearTimeout(c.current),l.current&&p(l.current),h.disconnect()}},[t,n,r,i,p,f]),{shouldRender:a,containerRef:s}}var m0=320,h0=4,g0=()=>typeof performance>`u`?Date.now():performance.now();function _0(e){let t=e?.now??g0,n=e?.maxBacklogMs??m0,r=0,i=0;return{now:t,beginPass(e){i=Math.min(Math.max(r,e),e+n)},mark(){return i},rewind(e){i=e},take(e,t,r){if(e<=0)return{baseDelay:0,step:Math.max(0,t)};let a=Math.max(0,t),o=a===0?0:Math.min(a,h0),s=Math.max(i,r),c=r+n,l=s+Math.max(0,e-1)*a,u=a;if(l>c&&e>1){if(s<c){let t=c-s;u=Math.max(o,t/(e-1))}else u=o}let d=Math.max(0,Math.round(s-r));return i=s+e*u,{baseDelay:d,step:u}},commitPass(){r=i}}}var v0=/\s/,y0=/^\s+$/,b0=new Set([`pre`,`svg`,`math`,`annotation`]),x0=new Set([`img`,`hr`]),S0=e=>typeof e==`object`&&!!e&&`type`in e&&e.type===`element`,C0=e=>e.some(e=>S0(e)&&b0.has(e.tagName)),w0=e=>{for(let t=e.length-1;t>=0;t--){let n=e[t];if(S0(n)&&n.tagName===`li`)return n}},T0=(e,t,n,r)=>{e.properties??={},e.properties[`data-sd-animate-marker`]=!0;let i=typeof e.properties.style==`string`?`${e.properties.style};`:``;e.properties.style=`${i}--sd-marker-duration:${t}ms;--sd-marker-delay:${Math.round(n)}ms;--sd-marker-easing:${r}`},E0=new Set([`ul`,`ol`,`li`]),D0=e=>{for(let t of e.children)if(S0(t)){if(t.tagName===`input`)return t;if(E0.has(t.tagName))continue;let e=D0(t);if(e)return e}},O0=(e,t,n,r)=>{e.properties??={},e.properties[`data-sd-animate`]=!0;let i=typeof e.properties.style==`string`?`${e.properties.style};`:``;e.properties.style=`${i}--sd-animation:sd-${t.animation};--sd-duration:${n}ms;--sd-easing:${t.easing};--sd-delay:${Math.round(r)}ms`},k0=(e,t,n,r)=>{let i=D0(e);i&&O0(i,t,n,r)},A0=(e,t,n,r,i,a)=>{if(C0(t))return;let o=r.prevContentLength,s=i.count;i.count+=1;let c=o>0&&s<o,l=c?0:a.baseDelay+i.newIndex++*a.step;O0(e,n,c?0:n.duration,l)},j0=e=>{var t;for(let n=e.length-1;n>=0;--n){let r=e[n];if(S0(r)){if((t=r.properties)!=null&&t[`data-sd-animated`])break;r.properties={...r.properties,"data-sd-animated":!0}}}},M0=e=>{let t=[],n=``,r=!1;for(let i of e){let e=v0.test(i);if(e!==r&&n){if(e){n+=i,r=!0;continue}t.push(n),n=``}n+=i,r=e}return n&&t.push(n),t},N0=e=>{let t=[],n=``;for(let r of e)v0.test(r)?t.length>0&&!y0.test(t.at(-1))?t[t.length-1]+=r:n+=r:(n&&=(t.push(n),``),t.push(r));return n&&(t.length>0?t[t.length-1]+=n:t.push(n)),t},P0=(e,t,n,r,i,a)=>{let o=`--sd-animation:sd-${t};--sd-duration:${i?0:n}ms;--sd-easing:${r}`;return a&&(o+=`;--sd-delay:${Math.round(a)}ms`),{type:`element`,tagName:`span`,properties:{"data-sd-animate":!0,style:o},children:[{type:`text`,value:e}]}},F0=(e,t)=>!(e>0&&t<e),I0=e=>S0(e)&&x0.has(e.tagName),L0=(e,t,n)=>{let r=0,i=0;return GO(e,e=>e.type===`text`||I0(e),(e,a)=>{if(C0(a))return WO;if(I0(e)){F0(n,i)&&(r+=1),i+=1;return}let o=e.value;if(!o.trim()){i+=o.length;return}let s=t.sep===`char`?N0(o):M0(o);for(let e of s){let t=i;i+=e.length,!y0.test(e)&&F0(n,t)&&(r+=1)}}),r},R0=(e,t,n,r,i,a)=>{var o;let s=t.at(-1);if(!(s&&`children`in s))return;if(C0(t))return WO;let c=s,l=c.children.indexOf(e);if(l===-1)return;let u=e.value;if(!u.trim()){i.count+=u.length;return}let d=n.sep===`char`?N0(u):M0(u),f=r.prevContentLength,p=!1,m=w0(t),h=!!(m&&!((o=m.properties)!=null&&o[`data-sd-animate-marker`])),g=!1,_=d.map(e=>{let t=i.count;if(i.count+=e.length,y0.test(e))return{type:`text`,value:e};let r=f>0&&t<f,o=r?0:a.baseDelay+i.newIndex++*a.step;if(p=!0,m&&h&&!g){let e=r?0:n.duration;T0(m,e,o,n.easing),k0(m,n,e,o),g=!0}return P0(e,n.animation,n.duration,n.easing,r,o)});return p&&j0(t),c.children.splice(l,1,..._),l+_.length},z0=0;function B0(e){let t={animation:e?.animation??`fadeIn`,duration:e?.duration??150,easing:e?.easing??`ease`,sep:e?.sep??`word`,stagger:e?.stagger??40,timeline:e?.timeline},n={committedCharCount:0,prevContentLength:0,lastRenderCharCount:0,pendingMark:null},r=z0++,i=()=>e=>{let r={count:0,newIndex:0};n.prevContentLength=n.committedCharCount;let i=t.timeline,a=i?.now()??g0();i&&(n.pendingMark===null?n.pendingMark=i.mark():i.rewind(n.pendingMark));let o=i?i.take(L0(e,t,n.prevContentLength),t.stagger,a):{baseDelay:0,step:t.stagger};GO(e,e=>e.type===`text`||I0(e),(e,i)=>{if(e.type===`text`)return R0(e,i,t,n,r,o);A0(e,i,t,n,r,o)}),n.lastRenderCharCount=r.count,n.prevContentLength=0};return Object.defineProperty(i,"name",{value:`rehypeAnimate$${r}`}),{name:`animate`,type:`animate`,rehypePlugin:i,setPrevContentLength(e){n.committedCharCount=e,n.prevContentLength=e},getLastRenderCharCount(){return n.lastRenderCharCount},commit(){n.committedCharCount=n.lastRenderCharCount,n.pendingMark=null}}}B0();var V0=(0,d.createContext)(!1),H0=()=>(0,d.useContext)(V0),U0=(...e)=>oh(Np(e)),W0=(e,t)=>{if(!e||!t)return t;let n=`${e}:`;return t.split(/\s+/).filter(Boolean).map(t=>t.startsWith(n)?t:`${e}:${t}`).join(` `)},G0=e=>e?(...t)=>W0(e,oh(Np(t))):U0,K0=(e,t,n)=>{let r=typeof t==`string`&&n.startsWith(`text/csv`)?``:``,i=typeof t==`string`?new Blob([r+t],{type:n}):t,a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a)},q0=(0,d.createContext)(U0),J0=()=>(0,d.useContext)(q0),Y0=8,X0=e=>{if(e!==void 0&&e!==0&&e!==1/0){if(typeof e==`number`)return Number.isFinite(e)&&e>0?`${e}px`:void 0;if(e!==`0`&&e!==`none`&&e!==`Infinity`)return e}},Z0=(e,t,n)=>{let r=(0,d.useRef)(null),i=(0,d.useRef)(!0),a=(0,d.useRef)(!1);return(0,d.useEffect)(()=>{let e=r.current;if(!(e&&t))return;let n=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<Y0;i.current=t};return e.addEventListener(`scroll`,n,{passive:!0}),()=>e.removeEventListener(`scroll`,n)},[t]),(0,d.useEffect)(()=>{e&&!a.current&&(i.current=!0),e||(i.current=!0),a.current=e},[e]),(0,d.useEffect)(()=>{let n=r.current;n&&t&&e&&i.current&&n.scrollTo({top:n.scrollHeight,behavior:`instant`})},[e,t,n]),r},Q0=U0(`block`),$0=U0(`block`,`before:content-[counter(line)]`,`before:inline-block`,`before:[counter-increment:line]`,`before:w-6`,`before:mr-4`,`before:text-[13px]`,`before:text-right`,`before:text-muted-foreground/50`,`before:font-mono`,`before:select-none`),e2=e=>{let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e>0){let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}}return t},t2=(0,d.memo)(({children:e,result:t,language:n,className:r,maxHeight:i,startLine:a,lineNumbers:o=!0,...s})=>{let c=J0(),{isAnimating:l}=(0,d.useContext)(R3),u=X0(i),f=Z0(l,!!u,t),p=(0,d.useMemo)(()=>c($0),[c]),m=(0,d.useMemo)(()=>c(Q0),[c]),h=(0,d.useMemo)(()=>{let e={};return t.bg&&(e[`--sdm-bg`]=t.bg),t.fg&&(e[`--sdm-fg`]=t.fg),t.rootStyle&&Object.assign(e,e2(t.rootStyle)),e},[t.bg,t.fg,t.rootStyle]);return(0,E.jsx)(`div`,{className:c(r,u?`overflow-y-auto`:null,`overflow-x-auto rounded-md border border-border bg-background p-4 text-sm`),"data-language":n,"data-streamdown":`code-block-body`,ref:f,style:u?{maxHeight:u}:void 0,...s,children:(0,E.jsx)(`pre`,{className:c(r,`bg-[var(--sdm-bg,inherit)]`,`dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))]`),style:h,children:(0,E.jsx)(`code`,{className:o?c(`[counter-increment:line_0] [counter-reset:line]`):void 0,style:o&&a&&a>1?{counterReset:`line ${a-1}`}:void 0,children:t.tokens.map((e,t)=>(0,E.jsx)(`span`,{className:o?p:m,children:e.length===0||e.length===1&&e[0].content===``?`
|
|
439
439
|
`:e.map((e,t)=>{let n={},r=!!e.bgColor;if(e.color&&(n[`--sdm-c`]=e.color),e.bgColor&&(n[`--sdm-tbg`]=e.bgColor),e.htmlStyle)for(let[t,i]of Object.entries(e.htmlStyle))t===`color`?n[`--sdm-c`]=i:t===`background-color`?(n[`--sdm-tbg`]=i,r=!0):n[t]=i;return(0,E.jsx)(`span`,{className:c(`text-[var(--sdm-c,inherit)]`,`dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]`,r&&`bg-[var(--sdm-tbg)]`,r&&`dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]`),style:n,...e.htmlAttrs,children:e.content},t)})},t))})})})}),n2=({className:e,language:t,style:n,isIncomplete:r,...i})=>{let a=J0();return(0,E.jsx)(`div`,{className:a(`my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2`,e),"data-incomplete":r||void 0,"data-language":t,"data-streamdown":`code-block`,style:{contentVisibility:`auto`,containIntrinsicSize:`auto 200px`,...n},...i})},r2=(0,d.createContext)({code:``}),i2=()=>(0,d.useContext)(r2),a2=({language:e})=>{let t=J0();return(0,E.jsx)(`div`,{className:t(`flex h-8 items-center text-muted-foreground text-xs`),"data-language":e,"data-streamdown":`code-block-header`,children:(0,E.jsx)(`span`,{className:t(`ml-1 font-mono lowercase`),children:e})})},o2=e=>{let t=e.length;for(;t>0&&e[t-1]===`
|
|
440
|
-
`;)t--;return e.slice(0,t)},s2=(0,d.lazy)(()=>l0(()=>import(`./highlighted-body-KPVGNVTW-
|
|
440
|
+
`;)t--;return e.slice(0,t)},s2=(0,d.lazy)(()=>l0(()=>import(`./highlighted-body-KPVGNVTW-DdZUyfi_.js`).then(e=>({default:e.HighlightedCodeBlockBody})),__vite__mapDeps([0,1]))),c2=({code:e,language:t,className:n,children:r,isIncomplete:i=!1,startLine:a,lineNumbers:o,...s})=>{let c=J0(),{codeBlockMaxHeight:l}=(0,d.useContext)(R3),u=(0,d.useMemo)(()=>o2(e),[e]),f=(0,d.useMemo)(()=>({bg:`transparent`,fg:`inherit`,tokens:u.split(`
|
|
441
441
|
`).map(e=>[{content:e,color:`inherit`,bgColor:`transparent`,htmlStyle:{},offset:0}])}),[u]);return(0,E.jsx)(r2.Provider,{value:{code:e},children:(0,E.jsxs)(n2,{dir:`ltr`,isIncomplete:i,language:t,children:[(0,E.jsx)(a2,{language:t}),r?(0,E.jsx)(`div`,{className:c(`pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end`),children:(0,E.jsx)(`div`,{className:c(`pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur`),"data-streamdown":`code-block-actions`,children:r})}):null,(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(t2,{className:n,language:t,lineNumbers:o,maxHeight:l,result:f,startLine:a,...s}),children:(0,E.jsx)(s2,{className:n,code:u,language:t,lineNumbers:o,maxHeight:l,raw:f,startLine:a,...s})})]})})},l2={CheckIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z`,fill:`currentColor`,fillRule:`evenodd`})}),CopyIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z`,fill:`currentColor`,fillRule:`evenodd`})}),DownloadIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z`,fill:`currentColor`,fillRule:`evenodd`})}),ExternalLinkIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z`,fill:`currentColor`,fillRule:`evenodd`})}),Loader2Icon:e=>(0,E.jsxs)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:[(0,E.jsx)(`path`,{d:`M8 0V4`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M8 16V12`,opacity:`0.5`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M3.29773 1.52783L5.64887 4.7639`,opacity:`0.9`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M12.7023 1.52783L10.3511 4.7639`,opacity:`0.1`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M12.7023 14.472L10.3511 11.236`,opacity:`0.4`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M3.29773 14.472L5.64887 11.236`,opacity:`0.6`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M15.6085 5.52783L11.8043 6.7639`,opacity:`0.2`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M0.391602 10.472L4.19583 9.23598`,opacity:`0.7`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M15.6085 10.4722L11.8043 9.2361`,opacity:`0.3`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,E.jsx)(`path`,{d:`M0.391602 5.52783L4.19583 6.7639`,opacity:`0.8`,stroke:`currentColor`,strokeWidth:`1.5`})]}),Maximize2Icon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z`,fill:`currentColor`,fillRule:`evenodd`})}),RotateCcwIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z`,fill:`currentColor`,fillRule:`evenodd`})}),XIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z`,fill:`currentColor`,fillRule:`evenodd`})}),ZoomInIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z`,fill:`currentColor`,fillRule:`evenodd`})}),ZoomOutIcon:e=>(0,E.jsx)(`svg`,{"aria-hidden":`true`,color:`currentColor`,height:16,strokeLinejoin:`round`,viewBox:`0 0 16 16`,width:16,...e,children:(0,E.jsx)(`path`,{clipRule:`evenodd`,d:`M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z`,fill:`currentColor`,fillRule:`evenodd`})})},u2=(0,d.createContext)(l2),d2=(e,t)=>{if(e===t)return!0;if(!(e&&t))return e===t;let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>e[n]===t[n])},f2=({icons:e,children:t})=>{let n=(0,d.useRef)(e),r=(0,d.useRef)(e?{...l2,...e}:l2);d2(n.current,e)||(n.current=e,r.current=e?{...l2,...e}:l2);let i=r.current;return(0,E.jsx)(u2.Provider,{value:i,children:t})},p2=()=>(0,d.useContext)(u2),m2={copyCode:`Copy Code`,downloadFile:`Download file`,downloadDiagram:`Download diagram`,downloadDiagramAsSvg:`Download diagram as SVG`,downloadDiagramAsPng:`Download diagram as PNG`,downloadDiagramAsMmd:`Download diagram as MMD`,viewFullscreen:`View fullscreen`,exitFullscreen:`Exit fullscreen`,mermaidFormatSvg:`SVG`,mermaidFormatPng:`PNG`,mermaidFormatMmd:`MMD`,zoomIn:`Zoom in`,zoomOut:`Zoom out`,resetView:`Reset zoom and pan`,copyTable:`Copy table`,copyTableAsMarkdown:`Copy table as Markdown`,copyTableAsCsv:`Copy table as CSV`,copyTableAsTsv:`Copy table as TSV`,downloadTable:`Download table`,downloadTableAsCsv:`Download table as CSV`,downloadTableAsMarkdown:`Download table as Markdown`,tableFormatMarkdown:`Markdown`,tableFormatCsv:`CSV`,tableFormatTsv:`TSV`,imageNotAvailable:`Image not available`,downloadImage:`Download image`,openExternalLink:`Open external link?`,externalLinkWarning:`You're about to visit an external website.`,close:`Close`,copyLink:`Copy link`,copied:`Copied`,openLink:`Open link`},h2=(0,d.createContext)(m2),g2=()=>(0,d.useContext)(h2),_2=({onCopy:e,onError:t,timeout:n=2e3,children:r,className:i,code:a,...o})=>{let s=J0(),[c,l]=(0,d.useState)(!1),u=(0,d.useRef)(0),{code:f}=i2(),{isAnimating:p}=(0,d.useContext)(R3),m=g2(),h=a??f,g=async()=>{var r;if(typeof window>`u`||!((r=navigator==null?void 0:navigator.clipboard)!=null&&r.writeText)){t?.(Error(`Clipboard API not available`));return}try{c||(await navigator.clipboard.writeText(h),l(!0),e?.(),u.current=window.setTimeout(()=>l(!1),n))}catch(e){t?.(e)}};(0,d.useEffect)(()=>()=>{window.clearTimeout(u.current)},[]);let _=p2(),v=c?_.CheckIcon:_.CopyIcon;return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{"aria-label":m.copyCode,className:s(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,i),"data-streamdown":`code-block-copy-button`,disabled:p,onClick:g,title:m.copyCode,type:`button`,...o,children:r??(0,E.jsx)(v,{"aria-hidden":`true`,size:14})}),c&&(0,E.jsx)(`output`,{"aria-live":`polite`,className:`sr-only`,children:m.copied})]})},v2=(e,t,n)=>{if(typeof e==`boolean`)return n;let r=e[t];if(typeof r!=`object`)return n;let i=r.download;return typeof i==`object`&&i.filename||n},y2={"1c":`1c`,"1c-query":`1cq`,abap:`abap`,"actionscript-3":`as`,ada:`ada`,adoc:`adoc`,"angular-html":`html`,"angular-ts":`ts`,apache:`conf`,apex:`cls`,apl:`apl`,applescript:`applescript`,ara:`ara`,asciidoc:`adoc`,asm:`asm`,astro:`astro`,awk:`awk`,ballerina:`bal`,bash:`sh`,bat:`bat`,batch:`bat`,be:`be`,beancount:`beancount`,berry:`berry`,bibtex:`bib`,bicep:`bicep`,blade:`blade.php`,bsl:`bsl`,c:`c`,"c#":`cs`,"c++":`cpp`,cadence:`cdc`,cairo:`cairo`,cdc:`cdc`,clarity:`clar`,clj:`clj`,clojure:`clj`,"closure-templates":`soy`,cmake:`cmake`,cmd:`cmd`,cobol:`cob`,codeowners:`CODEOWNERS`,codeql:`ql`,coffee:`coffee`,coffeescript:`coffee`,"common-lisp":`lisp`,console:`sh`,coq:`v`,cpp:`cpp`,cql:`cql`,crystal:`cr`,cs:`cs`,csharp:`cs`,css:`css`,csv:`csv`,cue:`cue`,cypher:`cql`,d:`d`,dart:`dart`,dax:`dax`,desktop:`desktop`,diff:`diff`,docker:`dockerfile`,dockerfile:`dockerfile`,dotenv:`env`,"dream-maker":`dm`,edge:`edge`,elisp:`el`,elixir:`ex`,elm:`elm`,"emacs-lisp":`el`,erb:`erb`,erl:`erl`,erlang:`erl`,f:`f`,"f#":`fs`,f03:`f03`,f08:`f08`,f18:`f18`,f77:`f77`,f90:`f90`,f95:`f95`,fennel:`fnl`,fish:`fish`,fluent:`ftl`,for:`for`,"fortran-fixed-form":`f`,"fortran-free-form":`f90`,fs:`fs`,fsharp:`fs`,fsl:`fsl`,ftl:`ftl`,gdresource:`tres`,gdscript:`gd`,gdshader:`gdshader`,genie:`gs`,gherkin:`feature`,"git-commit":`gitcommit`,"git-rebase":`gitrebase`,gjs:`js`,gleam:`gleam`,"glimmer-js":`js`,"glimmer-ts":`ts`,glsl:`glsl`,gnuplot:`plt`,go:`go`,gql:`gql`,graphql:`graphql`,groovy:`groovy`,gts:`gts`,hack:`hack`,haml:`haml`,handlebars:`hbs`,haskell:`hs`,haxe:`hx`,hbs:`hbs`,hcl:`hcl`,hjson:`hjson`,hlsl:`hlsl`,hs:`hs`,html:`html`,"html-derivative":`html`,http:`http`,hxml:`hxml`,hy:`hy`,imba:`imba`,ini:`ini`,jade:`jade`,java:`java`,javascript:`js`,jinja:`jinja`,jison:`jison`,jl:`jl`,js:`js`,json:`json`,json5:`json5`,jsonc:`jsonc`,jsonl:`jsonl`,jsonnet:`jsonnet`,jssm:`jssm`,jsx:`jsx`,julia:`jl`,kotlin:`kt`,kql:`kql`,kt:`kt`,kts:`kts`,kusto:`kql`,latex:`tex`,lean:`lean`,lean4:`lean`,less:`less`,liquid:`liquid`,lisp:`lisp`,lit:`lit`,llvm:`ll`,log:`log`,logo:`logo`,lua:`lua`,luau:`luau`,make:`mak`,makefile:`mak`,markdown:`md`,marko:`marko`,matlab:`m`,md:`md`,mdc:`mdc`,mdx:`mdx`,mediawiki:`wiki`,mermaid:`mmd`,mips:`s`,mipsasm:`s`,mmd:`mmd`,mojo:`mojo`,move:`move`,nar:`nar`,narrat:`narrat`,nextflow:`nf`,nf:`nf`,nginx:`conf`,nim:`nim`,nix:`nix`,nu:`nu`,nushell:`nu`,objc:`m`,"objective-c":`m`,"objective-cpp":`mm`,ocaml:`ml`,pascal:`pas`,perl:`pl`,perl6:`p6`,php:`php`,plsql:`pls`,po:`po`,polar:`polar`,postcss:`pcss`,pot:`pot`,potx:`potx`,powerquery:`pq`,powershell:`ps1`,prisma:`prisma`,prolog:`pl`,properties:`properties`,proto:`proto`,protobuf:`proto`,ps:`ps`,ps1:`ps1`,pug:`pug`,puppet:`pp`,purescript:`purs`,py:`py`,python:`py`,ql:`ql`,qml:`qml`,qmldir:`qmldir`,qss:`qss`,r:`r`,racket:`rkt`,raku:`raku`,razor:`cshtml`,rb:`rb`,reg:`reg`,regex:`regex`,regexp:`regexp`,rel:`rel`,riscv:`s`,rs:`rs`,rst:`rst`,ruby:`rb`,rust:`rs`,sas:`sas`,sass:`sass`,scala:`scala`,scheme:`scm`,scss:`scss`,sdbl:`sdbl`,sh:`sh`,shader:`shader`,shaderlab:`shader`,shell:`sh`,shellscript:`sh`,shellsession:`sh`,smalltalk:`st`,solidity:`sol`,soy:`soy`,sparql:`rq`,spl:`spl`,splunk:`spl`,sql:`sql`,"ssh-config":`config`,stata:`do`,styl:`styl`,stylus:`styl`,svelte:`svelte`,swift:`swift`,"system-verilog":`sv`,systemd:`service`,talon:`talon`,talonscript:`talon`,tasl:`tasl`,tcl:`tcl`,templ:`templ`,terraform:`tf`,tex:`tex`,tf:`tf`,tfvars:`tfvars`,toml:`toml`,ts:`ts`,"ts-tags":`ts`,tsp:`tsp`,tsv:`tsv`,tsx:`tsx`,turtle:`ttl`,twig:`twig`,typ:`typ`,typescript:`ts`,typespec:`tsp`,typst:`typ`,v:`v`,vala:`vala`,vb:`vb`,verilog:`v`,vhdl:`vhdl`,vim:`vim`,viml:`vim`,vimscript:`vim`,vue:`vue`,"vue-html":`html`,"vue-vine":`vine`,vy:`vy`,vyper:`vy`,wasm:`wasm`,wenyan:`wy`,wgsl:`wgsl`,wiki:`wiki`,wikitext:`wiki`,wit:`wit`,wl:`wl`,wolfram:`wl`,xml:`xml`,xsl:`xsl`,yaml:`yaml`,yml:`yml`,zenscript:`zs`,zig:`zig`,zsh:`zsh`,文言:`wy`},b2=({onDownload:e,onError:t,language:n,children:r,className:i,code:a,...o})=>{let s=J0(),{code:c}=i2(),{isAnimating:l,controls:u}=(0,d.useContext)(R3),f=g2(),p=p2(),m=a??c,h=n&&n in y2?y2[n]:`txt`,g=`${v2(u,`code`,`file`)}.${h}`;return(0,E.jsx)(`button`,{"aria-label":f.downloadFile,className:s(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,i),"data-streamdown":`code-block-download-button`,disabled:l,onClick:()=>{try{K0(g,m,`text/plain`),e?.()}catch(e){t?.(e)}},title:f.downloadFile,type:`button`,...o,children:r??(0,E.jsx)(p.DownloadIcon,{size:14})})},x2=()=>{let{Loader2Icon:e}=p2(),t=J0();return(0,E.jsxs)(`div`,{className:t(`w-full divide-y divide-border overflow-hidden rounded-xl border border-border`),children:[(0,E.jsx)(`div`,{className:t(`h-[46px] w-full bg-muted/80`)}),(0,E.jsx)(`div`,{className:t(`flex w-full items-center justify-center p-4`),children:(0,E.jsx)(e,{className:t(`size-4 animate-spin`)})})]})},S2=/\.[^/.]+$/,C2=({node:e,className:t,src:n,alt:r,onLoad:i,onError:a,showControls:o=!0,showDownloadControl:s=!0,...c})=>{let{DownloadIcon:l}=p2(),u=J0(),f=(0,d.useRef)(null),[p,m]=(0,d.useState)(!1),[h,g]=(0,d.useState)(!1),_=g2(),v=c.width!=null||c.height!=null,y=(p||v)&&!h&&o&&s,b=h&&!v;(0,d.useEffect)(()=>{let e=f.current;if(e!=null&&e.complete){let t=e.naturalWidth>0;m(t),g(!t)}},[]);let x=(0,d.useCallback)(e=>{m(!0),g(!1),i?.(e)},[i]),S=(0,d.useCallback)(e=>{m(!1),g(!0),a?.(e)},[a]),C=async()=>{if(n)try{let e=await(await fetch(n)).blob(),t=new URL(n,window.location.origin).pathname.split(`/`).pop()||``,i=t.split(`.`).pop(),a=t.includes(`.`)&&i!==void 0&&i.length<=4,o=``;if(a)o=t;else{let n=e.type,i=`png`;n.includes(`jpeg`)||n.includes(`jpg`)?i=`jpg`:n.includes(`png`)?i=`png`:n.includes(`svg`)?i=`svg`:n.includes(`gif`)?i=`gif`:n.includes(`webp`)&&(i=`webp`),o=`${(r||t||`image`).replace(S2,``)}.${i}`}K0(o,e,e.type)}catch{window.open(n,`_blank`)}};return n?(0,E.jsxs)(`div`,{className:u(`group relative my-4 inline-block`),"data-streamdown":`image-wrapper`,children:[(0,E.jsx)(`img`,{alt:r,className:u(`max-w-full rounded-lg`,b&&`hidden`,t),"data-streamdown":`image`,onError:S,onLoad:x,ref:f,src:n,...c}),b&&(0,E.jsx)(`span`,{className:u(`text-muted-foreground text-xs italic`),"data-streamdown":`image-fallback`,children:_.imageNotAvailable}),o&&(0,E.jsx)(`div`,{className:u(`pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block`),"data-streamdown":`image-overlay`}),y&&(0,E.jsx)(`button`,{className:u(`absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background`,`opacity-0 group-hover:opacity-100`),onClick:C,title:_.downloadImage,type:`button`,children:(0,E.jsx)(l,{size:14})})]}):null},w2=0,T2=()=>{w2+=1,w2===1&&(document.body.style.overflow=`hidden`)},E2=()=>{w2=Math.max(0,w2-1),w2===0&&(document.body.style.overflow=``)},D2=({url:e,isOpen:t,onClose:n,onConfirm:r})=>{let{CheckIcon:i,CopyIcon:a,ExternalLinkIcon:o,XIcon:s}=p2(),c=J0(),[l,u]=(0,d.useState)(!1),f=g2(),p=(0,d.useCallback)(async()=>{try{await navigator.clipboard.writeText(e),u(!0),setTimeout(()=>u(!1),2e3)}catch{}},[e]),m=(0,d.useCallback)(()=>{r(),n()},[r,n]);if((0,d.useEffect)(()=>{if(t){T2();let e=e=>{e.key===`Escape`&&n()};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e),E2()}}},[t,n]),!t||typeof document>`u`)return null;let h=(0,E.jsx)(`div`,{className:c(`fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm`),"data-streamdown":`link-safety-modal`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&n()},role:`button`,tabIndex:0,children:(0,E.jsxs)(`div`,{className:c(`relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg`),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),role:`presentation`,children:[(0,E.jsx)(`button`,{className:c(`absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground`),onClick:n,title:f.close,type:`button`,children:(0,E.jsx)(s,{size:16})}),(0,E.jsxs)(`div`,{className:c(`flex flex-col gap-2`),children:[(0,E.jsxs)(`div`,{className:c(`flex items-center gap-2 font-semibold text-lg`),children:[(0,E.jsx)(o,{size:20}),(0,E.jsx)(`span`,{children:f.openExternalLink})]}),(0,E.jsx)(`p`,{className:c(`text-muted-foreground text-sm`),children:f.externalLinkWarning})]}),(0,E.jsx)(`div`,{className:c(`break-all rounded-md bg-muted p-3 font-mono text-sm`,e.length>100&&`max-h-32 overflow-y-auto`),children:e}),(0,E.jsxs)(`div`,{className:c(`flex gap-2`),children:[(0,E.jsx)(`button`,{className:c(`flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted`),onClick:p,type:`button`,children:l?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(i,{size:14}),(0,E.jsx)(`span`,{children:f.copied})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(a,{size:14}),(0,E.jsx)(`span`,{children:f.copyLink})]})}),(0,E.jsxs)(`button`,{className:c(`flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90`),onClick:m,type:`button`,children:[(0,E.jsx)(o,{size:14}),(0,E.jsx)(`span`,{children:f.openLink})]})]})]})});return(0,Gi.createPortal)(h,document.body)},O2=(0,d.createContext)(null),k2=()=>(0,d.useContext)(O2),A2=()=>k2()?.code??null,j2=()=>k2()?.mermaid??null,M2=e=>{var t;let n=k2();return n!=null&&n.renderers&&e&&(t=n.renderers.find(t=>Array.isArray(t.language)?t.language.includes(e):t.language===e))!=null?t:null},N2=e=>{if(typeof DOMParser>`u`||typeof XMLSerializer>`u`)return e;let t=new DOMParser().parseFromString(e,`text/html`).querySelector(`svg`);return t?new XMLSerializer().serializeToString(t):e},P2=(e,t)=>new Promise((t,n)=>{let r=`data:image/svg+xml;base64,`+btoa(unescape(encodeURIComponent(e))),i=new Image;i.crossOrigin=`anonymous`,i.onload=()=>{let e=document.createElement(`canvas`),r=i.width*5,a=i.height*5;e.width=r,e.height=a;let o=e.getContext(`2d`);if(!o){n(Error(`Failed to create 2D canvas context for PNG export`));return}o.drawImage(i,0,0,r,a),e.toBlob(e=>{if(!e){n(Error(`Failed to create PNG blob`));return}t(e)},`image/png`)},i.onerror=()=>n(Error(`Failed to load SVG image`)),i.src=r}),F2=({chart:e,children:t,className:n,onDownload:r,config:i,onError:a})=>{let o=J0(),[s,c]=(0,d.useState)(!1),l=(0,d.useRef)(null),{isAnimating:u,controls:f}=(0,d.useContext)(R3),p=p2(),m=j2(),h=g2(),g=v2(f,`mermaid`,`diagram`),_=async t=>{try{if(t===`mmd`){K0(`${g}.mmd`,e,`text/plain`),c(!1),r?.(t);return}if(!m){a?.(Error(`Mermaid plugin not available`));return}let n=m.getMermaid(i),o=e.split(``).reduce((e,t)=>(e<<5)-e+t.charCodeAt(0)|0,0),s=`mermaid-${Math.abs(o)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:l}=await n.render(s,e);if(!l){a?.(Error(`SVG not found. Please wait for the diagram to render.`));return}let u=N2(l);if(t===`svg`){K0(`${g}.svg`,u,`image/svg+xml`),c(!1),r?.(t);return}if(t===`png`){let e=await P2(u);K0(`${g}.png`,e,`image/png`),r?.(t),c(!1);return}}catch(e){a?.(e)}};return(0,d.useEffect)(()=>{let e=e=>{let t=e.composedPath();l.current&&!t.includes(l.current)&&c(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[]),(0,E.jsxs)(`div`,{className:o(`relative`),ref:l,children:[(0,E.jsx)(`button`,{"aria-label":h.downloadDiagram,className:o(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,n),disabled:u,onClick:()=>c(!s),title:h.downloadDiagram,type:`button`,children:t??(0,E.jsx)(p.DownloadIcon,{"aria-hidden":`true`,size:14})}),s?(0,E.jsxs)(`div`,{className:o(`absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg`),children:[(0,E.jsx)(`button`,{"aria-label":h.downloadDiagramAsSvg,className:o(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`svg`),title:h.downloadDiagramAsSvg,type:`button`,children:h.mermaidFormatSvg}),(0,E.jsx)(`button`,{"aria-label":h.downloadDiagramAsPng,className:o(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`png`),title:h.downloadDiagramAsPng,type:`button`,children:h.mermaidFormatPng}),(0,E.jsx)(`button`,{"aria-label":h.downloadDiagramAsMmd,className:o(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`mmd`),title:h.downloadDiagramAsMmd,type:`button`,children:h.mermaidFormatMmd})]}):null]})},I2=({chart:e,config:t,onFullscreen:n,onExit:r,className:i,...a})=>{let{Maximize2Icon:o,XIcon:s}=p2(),c=J0(),[l,u]=(0,d.useState)(!1),{isAnimating:f,controls:p}=(0,d.useContext)(R3),m=g2(),h=(()=>{if(typeof p==`boolean`)return p;let e=p.mermaid;return e===!1?!1:e===!0||e===void 0||e.panZoom!==!1})(),g=(()=>{if(typeof p==`boolean`)return p;let e=p.mermaid;return e===!1?!1:e===!0||e===void 0||e.download!==!1})(),_=(()=>{if(typeof p==`boolean`)return p;let e=p.mermaid;return e===!1?!1:e===!0||e===void 0||e.copy!==!1})(),v=()=>{u(!l)};return(0,d.useEffect)(()=>{if(l){T2();let e=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e),E2()}}},[l]),(0,d.useEffect)(()=>{l?n?.():r&&r()},[l,n,r]),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:c(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,i),disabled:f,onClick:v,title:m.viewFullscreen,type:`button`,...a,"aria-label":m.viewFullscreen,children:(0,E.jsx)(o,{"aria-hidden":`true`,size:14})}),l?(0,Gi.createPortal)((0,E.jsxs)(`div`,{"aria-label":m.viewFullscreen,"aria-modal":`true`,className:c(`fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm`),"data-streamdown":`mermaid-fullscreen`,onClick:v,onKeyDown:e=>{e.key===`Escape`&&v()},role:`dialog`,children:[(0,E.jsxs)(`div`,{className:c(`absolute top-4 right-4 z-10 flex items-center gap-1`),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),role:`presentation`,children:[g?(0,E.jsx)(F2,{chart:e,config:t}):null,_?(0,E.jsx)(_2,{code:e}):null,(0,E.jsx)(`button`,{"aria-label":m.exitFullscreen,className:c(`rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground`),onClick:v,title:m.exitFullscreen,type:`button`,children:(0,E.jsx)(s,{"aria-hidden":`true`,size:20})})]}),(0,E.jsx)(`div`,{className:c(`flex size-full items-center justify-center p-4`),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),role:`presentation`,children:(0,E.jsx)(H3,{chart:e,className:c(`size-full [&_svg]:h-auto [&_svg]:w-auto`),config:t,fullscreen:!0,showControls:h})})]}),document.body):null]})};function L2(e){if(e.nodeType===Node.TEXT_NODE)return e.textContent??``;if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e;return t.tagName===`BR`?`
|
|
442
442
|
`:Array.from(t.childNodes).map(L2).join(``)}var R2=e=>{let t=[],n=[],r=e.querySelectorAll(`thead th`);for(let e of r)t.push(L2(e).trim());let i=e.querySelectorAll(`tbody tr`);for(let e of i){let t=[],r=e.querySelectorAll(`td`);for(let e of r)t.push(L2(e).trim());n.push(t)}return{headers:t,rows:n}},z2=e=>{if(typeof e!=`object`)return`,`;let t=e.table;return typeof t==`object`?t.csvSeparator??`,`:`,`},B2=(e,t=`,`)=>{let n;n=t===`auto`?Intl.NumberFormat().format(1.1).includes(`,`)?`;`:`,`:t;let{headers:r,rows:i}=e,a=e=>{let t=!1;for(let r of e)if(r===n||r===`"`||r===`
|
|
443
443
|
`||r===`\r`){t=!0;break}return t?`"${e.replace(/"/g,`""`)}"`:e},o=r.length>0?i.length+1:i.length,s=Array(o),c=0;r.length>0&&(s[c]=r.map(a).join(n),c+=1);for(let e of i)s[c]=e.map(a).join(n),c+=1;return s.join(`
|
|
@@ -447,7 +447,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
|
|
|
447
447
|
`)},H2=e=>{let t=!1;for(let n of e)if(n===`\\`||n===`|`||n===`
|
|
448
448
|
`){t=!0;break}if(!t)return e;let n=[];for(let t of e)t===`\\`?n.push(`\\\\`):t===`|`?n.push(`\\|`):t===`
|
|
449
449
|
`?n.push(`<br>`):n.push(t);return n.join(``)},U2=e=>{let{headers:t,rows:n}=e;if(t.length===0)return``;let r=Array(n.length+2),i=0,a=t.map(e=>H2(e));r[i]=`| ${a.join(` | `)} |`,i+=1;let o=Array(t.length);for(let e=0;e<t.length;e+=1)o[e]=`---`;r[i]=`| ${o.join(` | `)} |`,i+=1;for(let e of n)if(e.length<t.length){let n=Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=r<e.length?H2(e[r]):``;r[i]=`| ${n.join(` | `)} |`,i+=1}else{let t=e.map(e=>H2(e));r[i]=`| ${t.join(` | `)} |`,i+=1}return r.join(`
|
|
450
|
-
`)},W2=({children:e,className:t,onCopy:n,onError:r,timeout:i=2e3})=>{let a=J0(),[o,s]=(0,d.useState)(!1),[c,l]=(0,d.useState)(!1),u=(0,d.useRef)(null),f=(0,d.useRef)(0),{isAnimating:p,controls:m}=(0,d.useContext)(R3),h=g2(),g=z2(m),_=async e=>{var t;if(typeof window>`u`||!((t=navigator==null?void 0:navigator.clipboard)!=null&&t.write)){r?.(Error(`Clipboard API not available`));return}try{let t=(u.current?.closest(`[data-streamdown="table-wrapper"]`))?.querySelector(`table`);if(!t){r?.(Error(`Table not found`));return}let a=R2(t),o=``;o=e===`csv`?B2(a,g):e===`tsv`?V2(a):U2(a);let c=new ClipboardItem({"text/plain":new Blob([o],{type:`text/plain`}),"text/html":new Blob([t.outerHTML],{type:`text/html`})});await navigator.clipboard.write([c]),l(!0),s(!1),n?.(e),f.current=window.setTimeout(()=>l(!1),i)}catch(e){r?.(e)}};(0,d.useEffect)(()=>{let e=e=>{let t=e.composedPath();u.current&&!t.includes(u.current)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e),window.clearTimeout(f.current)}},[]);let v=p2(),y=c?v.CheckIcon:v.CopyIcon;return(0,E.jsxs)(`div`,{className:a(`relative`),ref:u,children:[(0,E.jsx)(`button`,{className:a(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:p,onClick:()=>s(!o),title:h.copyTable,type:`button`,children:e??(0,E.jsx)(y,{height:14,width:14})}),o?(0,E.jsxs)(`div`,{className:a(`absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg`),children:[(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`md`),title:h.copyTableAsMarkdown,type:`button`,children:h.tableFormatMarkdown}),(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`csv`),title:h.copyTableAsCsv,type:`button`,children:h.tableFormatCsv}),(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`tsv`),title:h.copyTableAsTsv,type:`button`,children:h.tableFormatTsv})]}):null]})},G2=({children:e,className:t,onDownload:n,onError:r})=>{let i=J0(),[a,o]=(0,d.useState)(!1),s=(0,d.useRef)(null),{isAnimating:c,controls:l}=(0,d.useContext)(R3),u=g2(),f=p2(),p=z2(l),m=e=>{try{let t=(s.current?.closest(`[data-streamdown="table-wrapper"]`))?.querySelector(`table`);if(!t){r?.(Error(`Table not found`));return}let i=R2(t),a=e===`csv`?B2(i,p):U2(i),c=e===`csv`?`csv`:`md`;K0(`${v2(l,`table`,`table`)}.${c}`,a,e===`csv`?`text/csv`:`text/markdown`),o(!1),n?.(e)}catch(e){r?.(e)}};return(0,d.useEffect)(()=>{let e=e=>{let t=e.composedPath();s.current&&!t.includes(s.current)&&o(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[]),(0,E.jsxs)(`div`,{className:i(`relative`),ref:s,children:[(0,E.jsx)(`button`,{className:i(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:c,onClick:()=>o(!a),title:u.downloadTable,type:`button`,children:e??(0,E.jsx)(f.DownloadIcon,{size:14})}),a?(0,E.jsxs)(`div`,{className:i(`absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg`),children:[(0,E.jsx)(`button`,{className:i(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>m(`csv`),title:u.downloadTableAsCsv,type:`button`,children:u.tableFormatCsv}),(0,E.jsx)(`button`,{className:i(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>m(`markdown`),title:u.downloadTableAsMarkdown,type:`button`,children:u.tableFormatMarkdown})]}):null]})},K2=({children:e,className:t,showCopy:n=!0,showDownload:r=!0})=>{let{Maximize2Icon:i,XIcon:a}=p2(),o=J0(),[s,c]=(0,d.useState)(!1),{isAnimating:l}=(0,d.useContext)(R3),u=g2(),f=()=>{c(!0)},p=()=>{c(!1)};return(0,d.useEffect)(()=>{if(s){T2();let e=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e),E2()}}},[s]),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:o(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:l,onClick:f,title:u.viewFullscreen,type:`button`,children:(0,E.jsx)(i,{size:14})}),s?(0,Gi.createPortal)((0,E.jsx)(`div`,{"aria-label":u.viewFullscreen,"aria-modal":`true`,className:o(`fixed inset-0 z-50 flex flex-col bg-background`),"data-streamdown":`table-fullscreen`,onClick:p,onKeyDown:e=>{e.key===`Escape`&&p()},role:`dialog`,children:(0,E.jsxs)(`div`,{className:o(`flex h-full flex-col`),"data-streamdown":`table-wrapper`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),role:`presentation`,children:[(0,E.jsxs)(`div`,{className:o(`flex items-center justify-end gap-1 p-4`),children:[n?(0,E.jsx)(W2,{}):null,r?(0,E.jsx)(G2,{}):null,(0,E.jsx)(`button`,{className:o(`rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground`),onClick:p,title:u.exitFullscreen,type:`button`,children:(0,E.jsx)(a,{size:20})})]}),(0,E.jsx)(`div`,{className:o(`flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10`),children:(0,E.jsx)(`table`,{className:o(`w-full border-collapse border border-border`),"data-streamdown":`table`,children:e})})]})}),document.body):null]})},q2=({children:e,className:t,maxHeight:n,showControls:r,showCopy:i=!0,showDownload:a=!0,showFullscreen:o=!0,...s})=>{let c=J0(),{isAnimating:l}=(0,d.useContext)(R3),u=X0(n),f=Z0(l,!!u,e),p=r&&i,m=r&&a,h=r&&o,g=p||m||h;return(0,E.jsxs)(`div`,{className:c(`my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2`),"data-streamdown":`table-wrapper`,children:[g?(0,E.jsxs)(`div`,{className:c(`flex items-center justify-end gap-1`),children:[p?(0,E.jsx)(W2,{}):null,m?(0,E.jsx)(G2,{}):null,h?(0,E.jsx)(K2,{showCopy:p,showDownload:m,children:e}):null]}):null,(0,E.jsx)(`div`,{className:c(`border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background`),ref:f,style:u?{maxHeight:u}:void 0,children:(0,E.jsx)(`table`,{className:c(`w-full divide-y divide-border`,t),"data-streamdown":`table`,...s,children:e})})]})},J2=/startLine=(\d+)/,Y2=/\bnoLineNumbers\b/,X2=(0,d.lazy)(()=>l0(()=>import(`./mermaid-HWGCJPDP-dkMjtjsB.js`).then(e=>({default:e.Mermaid})),[])),Z2=/language-([^\s]+)/,Q2=`node`;function $2(e,t){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(e!==Q2&&!Object.is(r[e],i[e]))return!1;return!0}function e4(e,t){return e?.properties?.metastring===t?.properties?.metastring}var t4=(e,t)=>typeof e==`boolean`?e:e[t]!==!1,n4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.table;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},r4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.code;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},i4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.mermaid;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},a4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.image;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},o4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`ol`,{className:i(`list-inside list-decimal whitespace-normal [li_&]:pl-6`,t),"data-streamdown":`ordered-list`,...r,children:e})},(e,t)=>$2(e,t));o4.displayName=`MarkdownOl`;var s4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`li`,{className:i(`py-1 [&>p]:inline`,t),"data-streamdown":`list-item`,...r,children:e})},(e,t)=>$2(e,t));s4.displayName=`MarkdownLi`;var c4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`ul`,{className:i(`list-inside list-disc whitespace-normal [li_&]:pl-6`,t),"data-streamdown":`unordered-list`,...r,children:e})},(e,t)=>$2(e,t));c4.displayName=`MarkdownUl`;var l4=(0,d.memo)(({className:e,node:t,...n})=>{let r=J0();return(0,E.jsx)(`hr`,{className:r(`my-6 border-border`,e),"data-streamdown":`horizontal-rule`,...n})},(e,t)=>$2(e,t));l4.displayName=`MarkdownHr`;var u4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`span`,{className:i(`font-semibold`,t),"data-streamdown":`strong`,...r,children:e})},(e,t)=>$2(e,t));u4.displayName=`MarkdownStrong`;var d4=(0,d.memo)(({children:e,className:t,href:n,node:r,...i})=>{let a=J0(),{linkSafety:o}=(0,d.useContext)(R3),[s,c]=(0,d.useState)(!1),l=n===`streamdown:incomplete-link`,u=(0,d.useCallback)(async e=>{if(!(!(o!=null&&o.enabled&&n)||l)){if(e.preventDefault(),o.onLinkCheck&&await o.onLinkCheck(n)){window.open(n,`_blank`,`noreferrer`);return}c(!0)}},[o,n,l]),f=(0,d.useCallback)(()=>{n&&window.open(n,`_blank`,`noreferrer`)},[n]),p=(0,d.useCallback)(()=>{c(!1)},[]),m={url:n??``,isOpen:s,onClose:p,onConfirm:f};return o!=null&&o.enabled&&n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:a(`wrap-anywhere appearance-none text-left font-medium text-primary underline`,t),"data-incomplete":l,"data-streamdown":`link`,onClick:u,type:`button`,children:e}),o.renderModal?o.renderModal(m):(0,E.jsx)(D2,{...m})]}):(0,E.jsx)(`a`,{className:a(`wrap-anywhere font-medium text-primary underline`,t),"data-incomplete":l,"data-streamdown":`link`,href:n,rel:`noreferrer`,target:`_blank`,...i,children:e})},(e,t)=>$2(e,t));d4.displayName=`MarkdownA`;var f4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h1`,{className:i(`mt-6 mb-2 font-semibold text-3xl`,t),"data-streamdown":`heading-1`,...r,children:e})},(e,t)=>$2(e,t));f4.displayName=`MarkdownH1`;var p4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h2`,{className:i(`mt-6 mb-2 font-semibold text-2xl`,t),"data-streamdown":`heading-2`,...r,children:e})},(e,t)=>$2(e,t));p4.displayName=`MarkdownH2`;var m4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h3`,{className:i(`mt-6 mb-2 font-semibold text-xl`,t),"data-streamdown":`heading-3`,...r,children:e})},(e,t)=>$2(e,t));m4.displayName=`MarkdownH3`;var h4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h4`,{className:i(`mt-6 mb-2 font-semibold text-lg`,t),"data-streamdown":`heading-4`,...r,children:e})},(e,t)=>$2(e,t));h4.displayName=`MarkdownH4`;var g4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h5`,{className:i(`mt-6 mb-2 font-semibold text-base`,t),"data-streamdown":`heading-5`,...r,children:e})},(e,t)=>$2(e,t));g4.displayName=`MarkdownH5`;var _4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h6`,{className:i(`mt-6 mb-2 font-semibold text-sm`,t),"data-streamdown":`heading-6`,...r,children:e})},(e,t)=>$2(e,t));_4.displayName=`MarkdownH6`;var v4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let{controls:i,tableMaxHeight:a}=(0,d.useContext)(R3),o=t4(i,`table`),s=n4(i,`copy`),c=n4(i,`download`),l=n4(i,`fullscreen`);return(0,E.jsx)(q2,{className:t,maxHeight:a,showControls:o,showCopy:s,showDownload:c,showFullscreen:l,...r,children:e})},(e,t)=>$2(e,t));v4.displayName=`MarkdownTable`;var y4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`thead`,{className:i(`bg-muted/80`,t),"data-streamdown":`table-header`,...r,children:e})},(e,t)=>$2(e,t));y4.displayName=`MarkdownThead`;var b4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`tbody`,{className:i(`divide-y divide-border`,t),"data-streamdown":`table-body`,...r,children:e})},(e,t)=>$2(e,t));b4.displayName=`MarkdownTbody`;var x4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`tr`,{className:i(`border-border`,t),"data-streamdown":`table-row`,...r,children:e})},(e,t)=>$2(e,t));x4.displayName=`MarkdownTr`;var S4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`th`,{className:i(`whitespace-nowrap px-4 py-2 text-left font-semibold text-sm`,t),"data-streamdown":`table-header-cell`,...r,children:e})},(e,t)=>$2(e,t));S4.displayName=`MarkdownTh`;var C4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`td`,{className:i(`px-4 py-2 text-sm`,t),"data-streamdown":`table-cell`,...r,children:e})},(e,t)=>$2(e,t));C4.displayName=`MarkdownTd`;var w4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`blockquote`,{className:i(`my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic`,t),"data-streamdown":`blockquote`,...r,children:e})},(e,t)=>$2(e,t));w4.displayName=`MarkdownBlockquote`;var T4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`sup`,{className:i(`text-sm`,t),"data-streamdown":`superscript`,...r,children:e})},(e,t)=>$2(e,t));T4.displayName=`MarkdownSup`;var E4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`sub`,{className:i(`text-sm`,t),"data-streamdown":`subscript`,...r,children:e})},(e,t)=>$2(e,t));E4.displayName=`MarkdownSub`;var D4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{if(`data-footnotes`in r){let n=e=>{if(!(0,d.isValidElement)(e))return!1;let t=Array.isArray(e.props.children)?e.props.children:[e.props.children],n=!1,r=!1;for(let e of t)if(e){if(typeof e==`string`)e.trim()!==``&&(n=!0);else if((0,d.isValidElement)(e)){if(e.props?.[`data-footnote-backref`]!==void 0)r=!0;else{let t=Array.isArray(e.props.children)?e.props.children:[e.props.children];for(let e of t){if(typeof e==`string`&&e.trim()!==``){n=!0;break}if((0,d.isValidElement)(e)&&e.props?.[`data-footnote-backref`]===void 0){n=!0;break}}}}}return r&&!n},i=Array.isArray(e)?e.map(e=>{if(!(0,d.isValidElement)(e))return e;if(e.type===o4){let t=(Array.isArray(e.props.children)?e.props.children:[e.props.children]).filter(e=>!n(e));return t.length===0?null:{...e,props:{...e.props,children:t}}}return e}):e;return(Array.isArray(i)?i.some(e=>e!==null):i!==null)?(0,E.jsx)(`section`,{className:t,...r,children:i}):null}return(0,E.jsx)(`section`,{className:t,...r,children:e})},(e,t)=>$2(e,t));D4.displayName=`MarkdownSection`;var O4=(0,d.memo)(({node:e,className:t,children:n,...r})=>{let i=J0(),a=!(`data-block`in r),{mermaid:o,controls:s,lineNumbers:c}=(0,d.useContext)(R3),l=j2(),u=H0(),f=(t?.match(Z2))?.at(1)??``,p=M2(f);if(a)return(0,E.jsx)(`code`,{className:i(`rounded bg-muted px-1.5 py-0.5 font-mono text-sm`,t),"data-streamdown":`inline-code`,...r,children:n});let m=e?.properties?.metastring,h=m?.match(J2),g=h?Number.parseInt(h[1],10):void 0,_=g!==void 0&&g>=1?g:void 0,v=!(m&&Y2.test(m))&&c!==!1,y=``;if((0,d.isValidElement)(n)&&n.props&&typeof n.props==`object`&&`children`in n.props&&typeof n.props.children==`string`?y=n.props.children:typeof n==`string`&&(y=n),p){let e=p.component;return(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(x2,{}),children:(0,E.jsx)(e,{code:y,isIncomplete:u,language:f,meta:m})})}if(f===`mermaid`&&l){let e=t4(s,`mermaid`),n=i4(s,`download`),r=i4(s,`copy`),a=i4(s,`fullscreen`),c=i4(s,`panZoom`),l=e&&(n||r||a);return(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(x2,{}),children:(0,E.jsxs)(`div`,{className:i(`group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2`,t),"data-streamdown":`mermaid-block`,children:[(0,E.jsx)(`div`,{className:i(`flex h-8 items-center text-muted-foreground text-xs`),children:(0,E.jsx)(`span`,{className:i(`ml-1 font-mono lowercase`),children:`mermaid`})}),l?(0,E.jsx)(`div`,{className:i(`pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end`),children:(0,E.jsxs)(`div`,{className:i(`pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur`),"data-streamdown":`mermaid-block-actions`,children:[n?(0,E.jsx)(F2,{chart:y,config:o?.config}):null,r?(0,E.jsx)(_2,{code:y}):null,a?(0,E.jsx)(I2,{chart:y,config:o?.config}):null]})}):null,(0,E.jsx)(`div`,{className:i(`rounded-md border border-border bg-background`),children:(0,E.jsx)(X2,{chart:y,config:o?.config,showControls:c})})]})})}let b=t4(s,`code`),x=r4(s,`download`),S=r4(s,`copy`),{"data-block":C,...w}=r;return(0,E.jsx)(c2,{className:t,code:y,isIncomplete:u,language:f,lineNumbers:v,startLine:_,...w,children:b?(0,E.jsxs)(E.Fragment,{children:[x?(0,E.jsx)(b2,{code:y,language:f}):null,S?(0,E.jsx)(_2,{}):null]}):null})},(e,t)=>$2(e,t)&&e4(e.node,t.node));O4.displayName=`MarkdownCode`;var k4=(0,d.memo)(({node:e,className:t,...n})=>{let{controls:r}=(0,d.useContext)(R3),i=t4(r,`image`),a=i&&a4(r,`download`);return(0,E.jsx)(C2,{className:t,node:e,showControls:i,showDownloadControl:a,...n})},(e,t)=>$2(e,t));k4.displayName=`MarkdownImg`;var A4=(0,d.memo)(({children:e,node:t,...n})=>{let r=(Array.isArray(e)?e:[e]).filter(e=>e!=null&&e!==``);if(r.length===1&&(0,d.isValidElement)(r[0])){let t=r[0].props.node?.tagName;if(t===`img`||t===`code`&&`data-block`in r[0].props)return(0,E.jsx)(E.Fragment,{children:e})}return(0,E.jsx)(`p`,{...n,children:e})},(e,t)=>$2(e,t));A4.displayName=`MarkdownParagraph`;var j4={ol:o4,li:s4,ul:c4,hr:l4,strong:u4,a:d4,h1:f4,h2:p4,h3:m4,h4,h5:g4,h6:_4,table:v4,thead:y4,tbody:b4,tr:x4,th:S4,td:C4,blockquote:w4,code:O4,img:k4,pre:({children:e})=>(0,d.isValidElement)(e)?(0,d.cloneElement)(e,{"data-block":`true`}):e,sup:T4,sub:E4,p:A4,section:D4},M4=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,N4=/\p{L}/u;function P4(e){let t=e.replace(/(```|~~~)[\s\S]*?\1/g,``).replace(/^#{1,6}\s+/gm,``).replace(/(\*{1,3}|_{1,3})/g,``).replace(/`[^`]*`/g,``).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/^[\s>*\-+\d.]+/gm,``),n,r=0,i=0;for(let e of t){if(M4.test(e)){n??=`rtl`,i+=1;continue}N4.test(e)&&(n??=`ltr`,r+=1)}return i>r?`rtl`:r>i?`ltr`:n??`ltr`}var F4=/^[ \t]{0,3}(`{3,}|~{3,})/,I4=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,L4=e=>{let t=e.split(`
|
|
450
|
+
`)},W2=({children:e,className:t,onCopy:n,onError:r,timeout:i=2e3})=>{let a=J0(),[o,s]=(0,d.useState)(!1),[c,l]=(0,d.useState)(!1),u=(0,d.useRef)(null),f=(0,d.useRef)(0),{isAnimating:p,controls:m}=(0,d.useContext)(R3),h=g2(),g=z2(m),_=async e=>{var t;if(typeof window>`u`||!((t=navigator==null?void 0:navigator.clipboard)!=null&&t.write)){r?.(Error(`Clipboard API not available`));return}try{let t=(u.current?.closest(`[data-streamdown="table-wrapper"]`))?.querySelector(`table`);if(!t){r?.(Error(`Table not found`));return}let a=R2(t),o=``;o=e===`csv`?B2(a,g):e===`tsv`?V2(a):U2(a);let c=new ClipboardItem({"text/plain":new Blob([o],{type:`text/plain`}),"text/html":new Blob([t.outerHTML],{type:`text/html`})});await navigator.clipboard.write([c]),l(!0),s(!1),n?.(e),f.current=window.setTimeout(()=>l(!1),i)}catch(e){r?.(e)}};(0,d.useEffect)(()=>{let e=e=>{let t=e.composedPath();u.current&&!t.includes(u.current)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e),window.clearTimeout(f.current)}},[]);let v=p2(),y=c?v.CheckIcon:v.CopyIcon;return(0,E.jsxs)(`div`,{className:a(`relative`),ref:u,children:[(0,E.jsx)(`button`,{className:a(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:p,onClick:()=>s(!o),title:h.copyTable,type:`button`,children:e??(0,E.jsx)(y,{height:14,width:14})}),o?(0,E.jsxs)(`div`,{className:a(`absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg`),children:[(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`md`),title:h.copyTableAsMarkdown,type:`button`,children:h.tableFormatMarkdown}),(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`csv`),title:h.copyTableAsCsv,type:`button`,children:h.tableFormatCsv}),(0,E.jsx)(`button`,{className:a(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>_(`tsv`),title:h.copyTableAsTsv,type:`button`,children:h.tableFormatTsv})]}):null]})},G2=({children:e,className:t,onDownload:n,onError:r})=>{let i=J0(),[a,o]=(0,d.useState)(!1),s=(0,d.useRef)(null),{isAnimating:c,controls:l}=(0,d.useContext)(R3),u=g2(),f=p2(),p=z2(l),m=e=>{try{let t=(s.current?.closest(`[data-streamdown="table-wrapper"]`))?.querySelector(`table`);if(!t){r?.(Error(`Table not found`));return}let i=R2(t),a=e===`csv`?B2(i,p):U2(i),c=e===`csv`?`csv`:`md`;K0(`${v2(l,`table`,`table`)}.${c}`,a,e===`csv`?`text/csv`:`text/markdown`),o(!1),n?.(e)}catch(e){r?.(e)}};return(0,d.useEffect)(()=>{let e=e=>{let t=e.composedPath();s.current&&!t.includes(s.current)&&o(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[]),(0,E.jsxs)(`div`,{className:i(`relative`),ref:s,children:[(0,E.jsx)(`button`,{className:i(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:c,onClick:()=>o(!a),title:u.downloadTable,type:`button`,children:e??(0,E.jsx)(f.DownloadIcon,{size:14})}),a?(0,E.jsxs)(`div`,{className:i(`absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg`),children:[(0,E.jsx)(`button`,{className:i(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>m(`csv`),title:u.downloadTableAsCsv,type:`button`,children:u.tableFormatCsv}),(0,E.jsx)(`button`,{className:i(`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40`),onClick:()=>m(`markdown`),title:u.downloadTableAsMarkdown,type:`button`,children:u.tableFormatMarkdown})]}):null]})},K2=({children:e,className:t,showCopy:n=!0,showDownload:r=!0})=>{let{Maximize2Icon:i,XIcon:a}=p2(),o=J0(),[s,c]=(0,d.useState)(!1),{isAnimating:l}=(0,d.useContext)(R3),u=g2(),f=()=>{c(!0)},p=()=>{c(!1)};return(0,d.useEffect)(()=>{if(s){T2();let e=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e),E2()}}},[s]),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:o(`cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,t),disabled:l,onClick:f,title:u.viewFullscreen,type:`button`,children:(0,E.jsx)(i,{size:14})}),s?(0,Gi.createPortal)((0,E.jsx)(`div`,{"aria-label":u.viewFullscreen,"aria-modal":`true`,className:o(`fixed inset-0 z-50 flex flex-col bg-background`),"data-streamdown":`table-fullscreen`,onClick:p,onKeyDown:e=>{e.key===`Escape`&&p()},role:`dialog`,children:(0,E.jsxs)(`div`,{className:o(`flex h-full flex-col`),"data-streamdown":`table-wrapper`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),role:`presentation`,children:[(0,E.jsxs)(`div`,{className:o(`flex items-center justify-end gap-1 p-4`),children:[n?(0,E.jsx)(W2,{}):null,r?(0,E.jsx)(G2,{}):null,(0,E.jsx)(`button`,{className:o(`rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground`),onClick:p,title:u.exitFullscreen,type:`button`,children:(0,E.jsx)(a,{size:20})})]}),(0,E.jsx)(`div`,{className:o(`flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10`),children:(0,E.jsx)(`table`,{className:o(`w-full border-collapse border border-border`),"data-streamdown":`table`,children:e})})]})}),document.body):null]})},q2=({children:e,className:t,maxHeight:n,showControls:r,showCopy:i=!0,showDownload:a=!0,showFullscreen:o=!0,...s})=>{let c=J0(),{isAnimating:l}=(0,d.useContext)(R3),u=X0(n),f=Z0(l,!!u,e),p=r&&i,m=r&&a,h=r&&o,g=p||m||h;return(0,E.jsxs)(`div`,{className:c(`my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2`),"data-streamdown":`table-wrapper`,children:[g?(0,E.jsxs)(`div`,{className:c(`flex items-center justify-end gap-1`),children:[p?(0,E.jsx)(W2,{}):null,m?(0,E.jsx)(G2,{}):null,h?(0,E.jsx)(K2,{showCopy:p,showDownload:m,children:e}):null]}):null,(0,E.jsx)(`div`,{className:c(`border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background`),ref:f,style:u?{maxHeight:u}:void 0,children:(0,E.jsx)(`table`,{className:c(`w-full divide-y divide-border`,t),"data-streamdown":`table`,...s,children:e})})]})},J2=/startLine=(\d+)/,Y2=/\bnoLineNumbers\b/,X2=(0,d.lazy)(()=>l0(()=>import(`./mermaid-HWGCJPDP-BrB2pBlI.js`).then(e=>({default:e.Mermaid})),[])),Z2=/language-([^\s]+)/,Q2=`node`;function $2(e,t){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(e!==Q2&&!Object.is(r[e],i[e]))return!1;return!0}function e4(e,t){return e?.properties?.metastring===t?.properties?.metastring}var t4=(e,t)=>typeof e==`boolean`?e:e[t]!==!1,n4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.table;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},r4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.code;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},i4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.mermaid;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},a4=(e,t)=>{if(typeof e==`boolean`)return e;let n=e.image;return n===!1?!1:n===!0||n===void 0||n[t]!==!1},o4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`ol`,{className:i(`list-inside list-decimal whitespace-normal [li_&]:pl-6`,t),"data-streamdown":`ordered-list`,...r,children:e})},(e,t)=>$2(e,t));o4.displayName=`MarkdownOl`;var s4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`li`,{className:i(`py-1 [&>p]:inline`,t),"data-streamdown":`list-item`,...r,children:e})},(e,t)=>$2(e,t));s4.displayName=`MarkdownLi`;var c4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`ul`,{className:i(`list-inside list-disc whitespace-normal [li_&]:pl-6`,t),"data-streamdown":`unordered-list`,...r,children:e})},(e,t)=>$2(e,t));c4.displayName=`MarkdownUl`;var l4=(0,d.memo)(({className:e,node:t,...n})=>{let r=J0();return(0,E.jsx)(`hr`,{className:r(`my-6 border-border`,e),"data-streamdown":`horizontal-rule`,...n})},(e,t)=>$2(e,t));l4.displayName=`MarkdownHr`;var u4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`span`,{className:i(`font-semibold`,t),"data-streamdown":`strong`,...r,children:e})},(e,t)=>$2(e,t));u4.displayName=`MarkdownStrong`;var d4=(0,d.memo)(({children:e,className:t,href:n,node:r,...i})=>{let a=J0(),{linkSafety:o}=(0,d.useContext)(R3),[s,c]=(0,d.useState)(!1),l=n===`streamdown:incomplete-link`,u=(0,d.useCallback)(async e=>{if(!(!(o!=null&&o.enabled&&n)||l)){if(e.preventDefault(),o.onLinkCheck&&await o.onLinkCheck(n)){window.open(n,`_blank`,`noreferrer`);return}c(!0)}},[o,n,l]),f=(0,d.useCallback)(()=>{n&&window.open(n,`_blank`,`noreferrer`)},[n]),p=(0,d.useCallback)(()=>{c(!1)},[]),m={url:n??``,isOpen:s,onClose:p,onConfirm:f};return o!=null&&o.enabled&&n?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:a(`wrap-anywhere appearance-none text-left font-medium text-primary underline`,t),"data-incomplete":l,"data-streamdown":`link`,onClick:u,type:`button`,children:e}),o.renderModal?o.renderModal(m):(0,E.jsx)(D2,{...m})]}):(0,E.jsx)(`a`,{className:a(`wrap-anywhere font-medium text-primary underline`,t),"data-incomplete":l,"data-streamdown":`link`,href:n,rel:`noreferrer`,target:`_blank`,...i,children:e})},(e,t)=>$2(e,t));d4.displayName=`MarkdownA`;var f4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h1`,{className:i(`mt-6 mb-2 font-semibold text-3xl`,t),"data-streamdown":`heading-1`,...r,children:e})},(e,t)=>$2(e,t));f4.displayName=`MarkdownH1`;var p4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h2`,{className:i(`mt-6 mb-2 font-semibold text-2xl`,t),"data-streamdown":`heading-2`,...r,children:e})},(e,t)=>$2(e,t));p4.displayName=`MarkdownH2`;var m4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h3`,{className:i(`mt-6 mb-2 font-semibold text-xl`,t),"data-streamdown":`heading-3`,...r,children:e})},(e,t)=>$2(e,t));m4.displayName=`MarkdownH3`;var h4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h4`,{className:i(`mt-6 mb-2 font-semibold text-lg`,t),"data-streamdown":`heading-4`,...r,children:e})},(e,t)=>$2(e,t));h4.displayName=`MarkdownH4`;var g4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h5`,{className:i(`mt-6 mb-2 font-semibold text-base`,t),"data-streamdown":`heading-5`,...r,children:e})},(e,t)=>$2(e,t));g4.displayName=`MarkdownH5`;var _4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`h6`,{className:i(`mt-6 mb-2 font-semibold text-sm`,t),"data-streamdown":`heading-6`,...r,children:e})},(e,t)=>$2(e,t));_4.displayName=`MarkdownH6`;var v4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let{controls:i,tableMaxHeight:a}=(0,d.useContext)(R3),o=t4(i,`table`),s=n4(i,`copy`),c=n4(i,`download`),l=n4(i,`fullscreen`);return(0,E.jsx)(q2,{className:t,maxHeight:a,showControls:o,showCopy:s,showDownload:c,showFullscreen:l,...r,children:e})},(e,t)=>$2(e,t));v4.displayName=`MarkdownTable`;var y4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`thead`,{className:i(`bg-muted/80`,t),"data-streamdown":`table-header`,...r,children:e})},(e,t)=>$2(e,t));y4.displayName=`MarkdownThead`;var b4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`tbody`,{className:i(`divide-y divide-border`,t),"data-streamdown":`table-body`,...r,children:e})},(e,t)=>$2(e,t));b4.displayName=`MarkdownTbody`;var x4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`tr`,{className:i(`border-border`,t),"data-streamdown":`table-row`,...r,children:e})},(e,t)=>$2(e,t));x4.displayName=`MarkdownTr`;var S4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`th`,{className:i(`whitespace-nowrap px-4 py-2 text-left font-semibold text-sm`,t),"data-streamdown":`table-header-cell`,...r,children:e})},(e,t)=>$2(e,t));S4.displayName=`MarkdownTh`;var C4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`td`,{className:i(`px-4 py-2 text-sm`,t),"data-streamdown":`table-cell`,...r,children:e})},(e,t)=>$2(e,t));C4.displayName=`MarkdownTd`;var w4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`blockquote`,{className:i(`my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic`,t),"data-streamdown":`blockquote`,...r,children:e})},(e,t)=>$2(e,t));w4.displayName=`MarkdownBlockquote`;var T4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`sup`,{className:i(`text-sm`,t),"data-streamdown":`superscript`,...r,children:e})},(e,t)=>$2(e,t));T4.displayName=`MarkdownSup`;var E4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{let i=J0();return(0,E.jsx)(`sub`,{className:i(`text-sm`,t),"data-streamdown":`subscript`,...r,children:e})},(e,t)=>$2(e,t));E4.displayName=`MarkdownSub`;var D4=(0,d.memo)(({children:e,className:t,node:n,...r})=>{if(`data-footnotes`in r){let n=e=>{if(!(0,d.isValidElement)(e))return!1;let t=Array.isArray(e.props.children)?e.props.children:[e.props.children],n=!1,r=!1;for(let e of t)if(e){if(typeof e==`string`)e.trim()!==``&&(n=!0);else if((0,d.isValidElement)(e)){if(e.props?.[`data-footnote-backref`]!==void 0)r=!0;else{let t=Array.isArray(e.props.children)?e.props.children:[e.props.children];for(let e of t){if(typeof e==`string`&&e.trim()!==``){n=!0;break}if((0,d.isValidElement)(e)&&e.props?.[`data-footnote-backref`]===void 0){n=!0;break}}}}}return r&&!n},i=Array.isArray(e)?e.map(e=>{if(!(0,d.isValidElement)(e))return e;if(e.type===o4){let t=(Array.isArray(e.props.children)?e.props.children:[e.props.children]).filter(e=>!n(e));return t.length===0?null:{...e,props:{...e.props,children:t}}}return e}):e;return(Array.isArray(i)?i.some(e=>e!==null):i!==null)?(0,E.jsx)(`section`,{className:t,...r,children:i}):null}return(0,E.jsx)(`section`,{className:t,...r,children:e})},(e,t)=>$2(e,t));D4.displayName=`MarkdownSection`;var O4=(0,d.memo)(({node:e,className:t,children:n,...r})=>{let i=J0(),a=!(`data-block`in r),{mermaid:o,controls:s,lineNumbers:c}=(0,d.useContext)(R3),l=j2(),u=H0(),f=(t?.match(Z2))?.at(1)??``,p=M2(f);if(a)return(0,E.jsx)(`code`,{className:i(`rounded bg-muted px-1.5 py-0.5 font-mono text-sm`,t),"data-streamdown":`inline-code`,...r,children:n});let m=e?.properties?.metastring,h=m?.match(J2),g=h?Number.parseInt(h[1],10):void 0,_=g!==void 0&&g>=1?g:void 0,v=!(m&&Y2.test(m))&&c!==!1,y=``;if((0,d.isValidElement)(n)&&n.props&&typeof n.props==`object`&&`children`in n.props&&typeof n.props.children==`string`?y=n.props.children:typeof n==`string`&&(y=n),p){let e=p.component;return(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(x2,{}),children:(0,E.jsx)(e,{code:y,isIncomplete:u,language:f,meta:m})})}if(f===`mermaid`&&l){let e=t4(s,`mermaid`),n=i4(s,`download`),r=i4(s,`copy`),a=i4(s,`fullscreen`),c=i4(s,`panZoom`),l=e&&(n||r||a);return(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(x2,{}),children:(0,E.jsxs)(`div`,{className:i(`group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2`,t),"data-streamdown":`mermaid-block`,children:[(0,E.jsx)(`div`,{className:i(`flex h-8 items-center text-muted-foreground text-xs`),children:(0,E.jsx)(`span`,{className:i(`ml-1 font-mono lowercase`),children:`mermaid`})}),l?(0,E.jsx)(`div`,{className:i(`pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end`),children:(0,E.jsxs)(`div`,{className:i(`pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur`),"data-streamdown":`mermaid-block-actions`,children:[n?(0,E.jsx)(F2,{chart:y,config:o?.config}):null,r?(0,E.jsx)(_2,{code:y}):null,a?(0,E.jsx)(I2,{chart:y,config:o?.config}):null]})}):null,(0,E.jsx)(`div`,{className:i(`rounded-md border border-border bg-background`),children:(0,E.jsx)(X2,{chart:y,config:o?.config,showControls:c})})]})})}let b=t4(s,`code`),x=r4(s,`download`),S=r4(s,`copy`),{"data-block":C,...w}=r;return(0,E.jsx)(c2,{className:t,code:y,isIncomplete:u,language:f,lineNumbers:v,startLine:_,...w,children:b?(0,E.jsxs)(E.Fragment,{children:[x?(0,E.jsx)(b2,{code:y,language:f}):null,S?(0,E.jsx)(_2,{}):null]}):null})},(e,t)=>$2(e,t)&&e4(e.node,t.node));O4.displayName=`MarkdownCode`;var k4=(0,d.memo)(({node:e,className:t,...n})=>{let{controls:r}=(0,d.useContext)(R3),i=t4(r,`image`),a=i&&a4(r,`download`);return(0,E.jsx)(C2,{className:t,node:e,showControls:i,showDownloadControl:a,...n})},(e,t)=>$2(e,t));k4.displayName=`MarkdownImg`;var A4=(0,d.memo)(({children:e,node:t,...n})=>{let r=(Array.isArray(e)?e:[e]).filter(e=>e!=null&&e!==``);if(r.length===1&&(0,d.isValidElement)(r[0])){let t=r[0].props.node?.tagName;if(t===`img`||t===`code`&&`data-block`in r[0].props)return(0,E.jsx)(E.Fragment,{children:e})}return(0,E.jsx)(`p`,{...n,children:e})},(e,t)=>$2(e,t));A4.displayName=`MarkdownParagraph`;var j4={ol:o4,li:s4,ul:c4,hr:l4,strong:u4,a:d4,h1:f4,h2:p4,h3:m4,h4,h5:g4,h6:_4,table:v4,thead:y4,tbody:b4,tr:x4,th:S4,td:C4,blockquote:w4,code:O4,img:k4,pre:({children:e})=>(0,d.isValidElement)(e)?(0,d.cloneElement)(e,{"data-block":`true`}):e,sup:T4,sub:E4,p:A4,section:D4},M4=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,N4=/\p{L}/u;function P4(e){let t=e.replace(/(```|~~~)[\s\S]*?\1/g,``).replace(/^#{1,6}\s+/gm,``).replace(/(\*{1,3}|_{1,3})/g,``).replace(/`[^`]*`/g,``).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/^[\s>*\-+\d.]+/gm,``),n,r=0,i=0;for(let e of t){if(M4.test(e)){n??=`rtl`,i+=1;continue}N4.test(e)&&(n??=`ltr`,r+=1)}return i>r?`rtl`:r>i?`ltr`:n??`ltr`}var F4=/^[ \t]{0,3}(`{3,}|~{3,})/,I4=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,L4=e=>{let t=e.split(`
|
|
451
451
|
`),n=null,r=0;for(let e of t){let t=F4.exec(e);if(n===null){if(t){let e=t[1];n=e[0],r=e.length}}else if(t){let e=t[1],i=e[0],a=e.length;i===n&&a>=r&&(n=null,r=0)}}return n!==null},R4=e=>{let t=e.split(`
|
|
452
452
|
`);for(let e of t){let t=e.trim();if(t.length>0&&t.includes(`|`)&&I4.test(t))return!0}return!1},z4=()=>e=>{qO(e,`html`,(e,t,n)=>{!n||typeof t!=`number`||(n.children[t]={type:`text`,value:e.value})})},B4=[],V4={allowDangerousHtml:!0},H4=new WeakMap,U4=new class{constructor(){this.cache=new Map,this.keyCache=new WeakMap,this.maxSize=100}generateCacheKey(e){let t=this.keyCache.get(e);if(t)return t;let n=e.rehypePlugins,r=e.remarkPlugins,i=e.remarkRehypeOptions;if(!(n||r||i)){let t=`default`;return this.keyCache.set(e,t),t}let a=e=>{if(!e||e.length===0)return``;let t=``;for(let n=0;n<e.length;n+=1){let r=e[n];if(n>0&&(t+=`,`),Array.isArray(r)){let[e,n]=r;if(typeof e==`function`){let n=H4.get(e);n||(n=e.name,H4.set(e,n)),t+=n}else t+=String(e);t+=`:`,t+=JSON.stringify(n)}else if(typeof r==`function`){let e=H4.get(r);e||(e=r.name,H4.set(r,e)),t+=e}else t+=String(r)}return t},o=a(n),s=`${a(r)}::${o}::${i?JSON.stringify(i):``}`;return this.keyCache.set(e,s),s}get(e){let t=this.generateCacheKey(e),n=this.cache.get(t);return n&&(this.cache.delete(t),this.cache.set(t,n)),n}set(e,t){let n=this.generateCacheKey(e);if(this.cache.size>=this.maxSize){let e=this.cache.keys().next().value;e&&this.cache.delete(e)}this.cache.set(n,t)}clear(){this.cache.clear()}},W4=e=>{let t=G4(e),n=e.children||``;return Q4(t.runSync(t.parse(n),n),e)},G4=e=>{let t=U4.get(e);if(t)return t;let n=q4(e);return U4.set(e,n),n},K4=e=>e.some(e=>Array.isArray(e)?e[0]===TV:e===TV),q4=e=>{let t=e.rehypePlugins||B4,n=e.remarkPlugins||B4,r=K4(t)?n:[...n,z4],i=e.remarkRehypeOptions?{...V4,...e.remarkRehypeOptions}:V4;return Dk().use(zD).use(r).use(ek,i).use(t)},J4=e=>e,Y4=(e,t,n,r)=>{n?e.children.splice(t,1):e.children[t]={type:`text`,value:r}},X4=(e,t)=>{for(let n in Ww)if(Object.hasOwn(Ww,n)&&Object.hasOwn(e.properties,n)){let r=e.properties[n],i=Ww[n];(i===null||i.includes(e.tagName))&&(e.properties[n]=t(String(r||``),n,e)??void 0)}},Z4=(e,t,n,r,i,a)=>{let o=!1;return r?o=!r.includes(e.tagName):i&&(o=i.includes(e.tagName)),!o&&a&&typeof t==`number`&&(o=!a(e,t,n)),o},Q4=(e,t)=>{let{allowElement:n,allowedElements:r,disallowedElements:i,skipHtml:a,unwrapDisallowed:o,urlTransform:s}=t;if(n||r||i||a||s){let t=s||J4;qO(e,(e,s,c)=>{if(e.type===`raw`&&c&&typeof s==`number`)return Y4(c,s,a,e.value),s;if(e.type===`element`&&(X4(e,t),Z4(e,s,c,r,i,n)&&c&&typeof s==`number`))return o&&e.children?c.children.splice(s,1,...e.children):c.children.splice(s,1),s})}return Sw(e,{Fragment:E.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:E.jsx,jsxs:E.jsxs,passKeys:!0,passNode:!0})},$4=/\[\^[\w-]{1,200}\](?!:)/,e3=/\[\^[\w-]{1,200}\]:/,t3=/<([A-Za-z][\w:-]*)[\s>/]/,n3=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),r3=new Map,i3=new Map,a3=e=>{let t=e.toLowerCase(),n=r3.get(t);if(n)return n;let r=RegExp(`<${t}(?=[\\s>/])[^>]*>`,`gi`);return r3.set(t,r),r},o3=e=>{let t=e.toLowerCase(),n=i3.get(t);if(n)return n;let r=RegExp(`</${t}(?=[\\s>])[^>]*>`,`gi`);return i3.set(t,r),r},s3=(e,t)=>{if(n3.has(t.toLowerCase()))return 0;let n=e.match(a3(t));if(!n)return 0;let r=0;for(let e of n)e.trimEnd().endsWith(`/>`)||(r+=1);return r},c3=(e,t)=>{let n=e.match(o3(t));return n?n.length:0},l3=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]===`$`&&e[n+1]===`$`&&(t+=1,n+=1);return t},u3=e=>{let t=$4.test(e),n=e3.test(e);if(t||n)return[e];let r=$1.lex(e,{gfm:!0}),i=[],a=[],o=!1;for(let e of r){let t=e.raw,n=i.length;if(a.length>0){i[n-1]+=t;let e=a.at(-1),r=s3(t,e),o=c3(t,e);for(let t=0;t<r;t+=1)a.push(e);for(let t=0;t<o;t+=1)a.length>0&&a.at(-1)===e&&a.pop();continue}if(e.type===`html`&&e.block){let e=t.match(t3);if(e){let n=e[1];s3(t,n)>c3(t,n)&&a.push(n)}}if(n>0&&!o){let e=i[n-1];if(l3(e)%2==1){i[n-1]=e+t;continue}}i.push(t),e.type!==`space`&&(o=e.type===`code`)}return i},d3=/^\n*/,f3=/\n*$/,p3=/\n\n/g,m3=(e,t,n)=>t.includes(`
|
|
453
453
|
`)?`${e}${t.replace(p3,`
|
|
@@ -477,7 +477,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
477
477
|
`);n.forEach(function(t,i){var o=r&&d.length+a,s={type:`text`,value:`${t}
|
|
478
478
|
`};if(i===0){var c=g(u.slice(f+1,p).concat(T6({children:[s],className:e.properties.className})),o);d.push(c)}else if(i===n.length-1){var l=u[p+1]&&u[p+1].children&&u[p+1].children[0],m={type:`text`,value:`${t}`};if(l){var h=T6({children:[m],className:e.properties.className});u.splice(p+1,0,h)}else{var _=g([m],o,e.properties.className);d.push(_)}}else{var v=g([s],o,e.properties.className);d.push(v)}}),f=p}p++};p<u.length;)_();if(f!==u.length-1){var v=u.slice(f+1,u.length);if(v&&v.length){var y=g(v,r&&d.length+a);d.push(y)}}return t?d:(l=[]).concat.apply(l,d)}function O6(e){var t=e.rows,n=e.stylesheet,r=e.useInlineStyles;return t.map(function(e,t){return p6({node:e,stylesheet:n,useInlineStyles:r,key:`code-segment-${t}`})})}function k6(e){return e&&e.highlightAuto!==void 0}function A6(e){var t=e.astGenerator,n=e.language,r=e.code,i=e.defaultCodeValue;if(k6(t)){var a=m6(t,n);return n===`text`?{value:i,language:`text`}:a?t.highlight(n,r):t.highlightAuto(r)}try{return n&&n!==`text`?{value:t.highlight(r,n)}:{value:i}}catch{return{value:i}}}function j6(e,t){return function(n){var r=n.language,i=n.children,a=n.style,o=a===void 0?t:a,s=n.customStyle,c=s===void 0?{}:s,l=n.codeTagProps,u=l===void 0?{className:r?`language-${r}`:void 0,style:_6(_6({},o[`code[class*="language-"]`]),o[`code[class*="language-${r}"]`])}:l,f=n.useInlineStyles,p=f===void 0||f,m=n.showLineNumbers,h=m!==void 0&&m,g=n.showInlineLineNumbers,_=g===void 0||g,v=n.startingLineNumber,y=v===void 0?1:v,b=n.lineNumberContainerStyle,x=n.lineNumberStyle,S=x===void 0?{}:x,C=n.wrapLines,w=n.wrapLongLines,T=w!==void 0&&w,E=n.lineProps,D=E===void 0?{}:E,O=n.renderer,k=n.PreTag,A=k===void 0?`pre`:k,j=n.CodeTag,M=j===void 0?`code`:j,N=n.code,P=N===void 0?(Array.isArray(i)?i[0]:i)||``:N,ee=n.astGenerator,F=q3(n,h6);ee||=e;var I=h?d.createElement(x6,{containerStyle:b,codeStyle:u.style||{},numberStyle:S,startingLineNumber:y,codeString:P}):null,te=o.hljs||o[`pre[class*="language-"]`]||{backgroundColor:`#fff`},ne=k6(ee)?`hljs`:`prismjs`,re=p?Object.assign({},F,{style:Object.assign({},te,c)}):Object.assign({},F,{className:F.className?`${ne} ${F.className}`:ne,style:Object.assign({},c)});if(u.style=_6(T?{whiteSpace:`pre-wrap`}:{whiteSpace:`pre`},u.style),!ee)return d.createElement(A,re,I,d.createElement(M,u,P));(C===void 0&&O||T)&&(C=!0),O||=O6;var ie=[{type:`text`,value:P}],ae=A6({astGenerator:ee,language:r,code:P,defaultCodeValue:ie});ae.language===null&&(ae.value=ie);var L=y+(P.match(/\n/g)?.length??0),R=D6(ae,C,D,h,_,y,L,S,T);return d.createElement(A,re,d.createElement(M,u,!_&&I,O({rows:R,stylesheet:o,useInlineStyles:p})))}}var M6=`AElig.AMP.Aacute.Acirc.Agrave.Aring.Atilde.Auml.COPY.Ccedil.ETH.Eacute.Ecirc.Egrave.Euml.GT.Iacute.Icirc.Igrave.Iuml.LT.Ntilde.Oacute.Ocirc.Ograve.Oslash.Otilde.Ouml.QUOT.REG.THORN.Uacute.Ucirc.Ugrave.Uuml.Yacute.aacute.acirc.acute.aelig.agrave.amp.aring.atilde.auml.brvbar.ccedil.cedil.cent.copy.curren.deg.divide.eacute.ecirc.egrave.eth.euml.frac12.frac14.frac34.gt.iacute.icirc.iexcl.igrave.iquest.iuml.laquo.lt.macr.micro.middot.nbsp.not.ntilde.oacute.ocirc.ograve.ordf.ordm.oslash.otilde.ouml.para.plusmn.pound.quot.raquo.reg.sect.shy.sup1.sup2.sup3.szlig.thorn.times.uacute.ucirc.ugrave.uml.uuml.yacute.yen.yuml`.split(`.`),N6={0:`�`,128:`€`,130:`‚`,131:`ƒ`,132:`„`,133:`…`,134:`†`,135:`‡`,136:`ˆ`,137:`‰`,138:`Š`,139:`‹`,140:`Œ`,142:`Ž`,145:`‘`,146:`’`,147:`“`,148:`”`,149:`•`,150:`–`,151:`—`,152:`˜`,153:`™`,154:`š`,155:`›`,156:`œ`,158:`ž`,159:`Ÿ`};function P6(e){let t=typeof e==`string`?e.charCodeAt(0):e;return t>=48&&t<=57}function F6(e){let t=typeof e==`string`?e.charCodeAt(0):e;return t>=97&&t<=102||t>=65&&t<=70||t>=48&&t<=57}function I6(e){let t=typeof e==`string`?e.charCodeAt(0):e;return t>=97&&t<=122||t>=65&&t<=90}function L6(e){return I6(e)||P6(e)}var R6=[``,`Named character references must be terminated by a semicolon`,`Numeric character references must be terminated by a semicolon`,`Named character references cannot be empty`,`Numeric character references cannot be empty`,`Named character references must be known`,`Numeric character references cannot be disallowed`,`Numeric character references cannot be outside the permissible Unicode range`];function z6(e,t){let n=t||{},r=typeof n.additional==`string`?n.additional.charCodeAt(0):n.additional,i=[],a=0,o=-1,s=``,c,l;n.position&&(`start`in n.position||`indent`in n.position?(l=n.position.indent,c=n.position.start):c=n.position);let u=(c?c.line:0)||1,d=(c?c.column:0)||1,f=m(),p;for(a--;++a<=e.length;)if(p===10&&(d=(l?l[o]:0)||1),p=e.charCodeAt(a),p===38){let t=e.charCodeAt(a+1);if(t===9||t===10||t===12||t===32||t===38||t===60||Number.isNaN(t)||r&&t===r){s+=String.fromCharCode(p),d++;continue}let o=a+1,c=o,l=o,u;if(t===35){l=++c;let t=e.charCodeAt(l);t===88||t===120?(u=`hexadecimal`,l=++c):u=`decimal`}else u=`named`;let _=``,v=``,y=``,b=u===`named`?L6:u===`decimal`?P6:F6;for(l--;++l<=e.length;){let t=e.charCodeAt(l);if(!b(t))break;y+=String.fromCharCode(t),u===`named`&&M6.includes(y)&&(_=y,v=Zw(y))}let x=e.charCodeAt(l)===59;if(x){l++;let e=u===`named`&&Zw(y);e&&(_=y,v=e)}let S=1+l-o,C=``;if(!(!x&&n.nonTerminated===!1)){if(!y)u!==`named`&&h(4,S);else if(u===`named`){if(x&&!v)h(5,1);else if(_!==y&&(l=c+_.length,S=1+l-c,x=!1),!x){let t=_?1:3;if(n.attribute){let n=e.charCodeAt(l);n===61?(h(t,S),v=``):L6(n)?v=``:h(t,S)}else h(t,S)}C=v}else{x||h(2,S);let e=Number.parseInt(y,u===`hexadecimal`?16:10);if(B6(e))h(7,S),C=`�`;else if(e in N6)h(6,S),C=N6[e];else{let t=``;V6(e)&&h(6,S),e>65535&&(e-=65536,t+=String.fromCharCode(e>>>10|55296),e=56320|e&1023),C=t+String.fromCharCode(e)}}}if(C){g(),f=m(),a=l-1,d+=l-o+1,i.push(C);let t=m();t.offset++,n.reference&&n.reference.call(n.referenceContext||void 0,C,{start:f,end:t},e.slice(o-1,l)),f=t}else y=e.slice(o-1,l),s+=y,d+=y.length,a=l-1}else p===10&&(u++,o++,d=0),Number.isNaN(p)?g():(s+=String.fromCharCode(p),d++);return i.join(``);function m(){return{line:u,column:d,offset:a+((c?c.offset:0)||0)}}function h(e,t){let r;n.warning&&(r=m(),r.column+=t,r.offset+=t,n.warning.call(n.warningContext||void 0,R6[e],r,e))}function g(){s&&=(i.push(s),n.text&&n.text.call(n.textContext||void 0,s,{start:f,end:m()}),``)}}function B6(e){return e>=55296&&e<=57343||e>1114111}function V6(e){return e>=1&&e<=8||e===11||e>=13&&e<=31||e>=127&&e<=159||e>=64976&&e<=65007||(e&65535)==65535||(e&65535)==65534}var H6=0,U6={},W6={util:{type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++H6}),e.__id},clone:function e(t,n){n||={};var r,i;switch(W6.util.type(t)){case`Object`:if(i=W6.util.objId(t),n[i])return n[i];for(var a in r={},n[i]=r,t)t.hasOwnProperty(a)&&(r[a]=e(t[a],n));return r;case`Array`:return i=W6.util.objId(t),n[i]?n[i]:(r=[],n[i]=r,t.forEach(function(t,i){r[i]=e(t,n)}),r);default:return t}}},languages:{plain:U6,plaintext:U6,text:U6,txt:U6,extend:function(e,t){var n=W6.util.clone(W6.languages[e]);for(var r in t)n[r]=t[r];return n},insertBefore:function(e,t,n,r){r||=W6.languages;var i=r[e],a={};for(var o in i)if(i.hasOwnProperty(o)){if(o==t)for(var s in n)n.hasOwnProperty(s)&&(a[s]=n[s]);n.hasOwnProperty(o)||(a[o]=i[o])}var c=r[e];return r[e]=a,W6.languages.DFS(W6.languages,function(t,n){n===c&&t!=e&&(this[t]=a)}),a},DFS:function e(t,n,r,i){i||={};var a=W6.util.objId;for(var o in t)if(t.hasOwnProperty(o)){n.call(t,o,t[o],r||o);var s=t[o],c=W6.util.type(s);c===`Object`&&!i[a(s)]?(i[a(s)]=!0,e(s,n,null,i)):c===`Array`&&!i[a(s)]&&(i[a(s)]=!0,e(s,n,o,i))}}},plugins:{},highlight:function(e,t,n){var r={code:e,grammar:t,language:n};if(W6.hooks.run(`before-tokenize`,r),!r.grammar)throw Error(`The language "`+r.language+`" has no grammar.`);return r.tokens=W6.tokenize(r.code,r.grammar),W6.hooks.run(`after-tokenize`,r),G6.stringify(W6.util.encode(r.tokens),r.language)},tokenize:function(e,t){var n=t.rest;if(n){for(var r in n)t[r]=n[r];delete t.rest}var i=new J6;return Y6(i,i.head,e),q6(e,i,t,i.head,0),Z6(i)},hooks:{all:{},add:function(e,t){var n=W6.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=W6.hooks.all[e];if(!(!n||!n.length))for(var r=0,i;i=n[r++];)i(t)}},Token:G6};function G6(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=(r||``).length|0}function K6(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var a=i[1].length;i.index+=a,i[0]=i[0].slice(a)}return i}function q6(e,t,n,r,i,a){for(var o in n)if(!(!n.hasOwnProperty(o)||!n[o])){var s=n[o];s=Array.isArray(s)?s:[s];for(var c=0;c<s.length;++c){if(a&&a.cause==o+`,`+c)return;var l=s[c],u=l.inside,d=!!l.lookbehind,f=!!l.greedy,p=l.alias;if(f&&!l.pattern.global){var m=l.pattern.toString().match(/[imsuy]*$/)[0];l.pattern=RegExp(l.pattern.source,m+`g`)}for(var h=l.pattern||l,g=r.next,_=i;g!==t.tail&&!(a&&_>=a.reach);_+=g.value.length,g=g.next){var v=g.value;if(t.length>e.length)return;if(!(v instanceof G6)){var y=1,b;if(f){if(b=K6(h,_,e,d),!b||b.index>=e.length)break;var x=b.index,S=b.index+b[0].length,C=_;for(C+=g.value.length;x>=C;)g=g.next,C+=g.value.length;if(C-=g.value.length,_=C,g.value instanceof G6)continue;for(var w=g;w!==t.tail&&(C<S||typeof w.value==`string`);w=w.next)y++,C+=w.value.length;y--,v=e.slice(_,C),b.index-=_}else if(b=K6(h,0,v,d),!b)continue;var x=b.index,T=b[0],E=v.slice(0,x),D=v.slice(x+T.length),O=_+v.length;a&&O>a.reach&&(a.reach=O);var k=g.prev;E&&(k=Y6(t,k,E),_+=E.length),X6(t,k,y);var A=new G6(o,u?W6.tokenize(T,u):T,p,T);if(g=Y6(t,k,A),D&&Y6(t,g,D),y>1){var j={cause:o+`,`+c,reach:O};q6(e,t,n,g.prev,_,j),a&&j.reach>a.reach&&(a.reach=j.reach)}}}}}}function J6(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function Y6(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i}function X6(e,t,n){for(var r=t.next,i=0;i<n&&r!==e.tail;i++)r=r.next;t.next=r,r.prev=t,e.length-=i}function Z6(e){for(var t=[],n=e.head.next;n!==e.tail;)t.push(n.value),n=n.next;return t}var Q6=W6;function $6(){}$6.prototype=Q6;var e8=new $6;e8.highlight=t8,e8.register=n8,e8.alias=r8,e8.registered=i8,e8.listLanguages=a8,e8.util.encode=s8,e8.Token.stringify=o8;function t8(e,t){if(typeof e!=`string`)throw TypeError("Expected `string` for `value`, got `"+e+"`");let n,r;if(t&&typeof t==`object`)n=t;else{if(r=t,typeof r!=`string`)throw TypeError("Expected `string` for `name`, got `"+r+"`");if(Object.hasOwn(e8.languages,r))n=e8.languages[r];else throw Error("Unknown language: `"+r+"` is not registered")}return{type:`root`,children:Q6.highlight.call(e8,e,n,r)}}function n8(e){if(typeof e!=`function`||!e.displayName)throw Error("Expected `function` for `syntax`, got `"+e+"`");Object.hasOwn(e8.languages,e.displayName)||e(e8)}function r8(e,t){let n=e8.languages,r={};typeof e==`string`?t&&(r[e]=t):r=e;let i;for(i in r)if(Object.hasOwn(r,i)){let e=r[i],t=typeof e==`string`?[e]:e,a=-1;for(;++a<t.length;)n[t[a]]=n[i]}}function i8(e){if(typeof e!=`string`)throw TypeError("Expected `string` for `aliasOrLanguage`, got `"+e+"`");return Object.hasOwn(e8.languages,e)}function a8(){let e=e8.languages,t=[],n;for(n in e)Object.hasOwn(e,n)&&typeof e[n]==`object`&&t.push(n);return t}function o8(e,t){if(typeof e==`string`)return{type:`text`,value:e};if(Array.isArray(e)){let n=[],r=-1;for(;++r<e.length;)e[r]!==null&&e[r]!==void 0&&e[r]!==``&&n.push(o8(e[r],t));return n}let n={attributes:{},classes:[`token`,e.type],content:o8(e.content,t),language:t,tag:`span`,type:e.type};return e.alias&&n.classes.push(...typeof e.alias==`string`?[e.alias]:e.alias),e8.hooks.run(`wrap`,n),nA(n.tag+`.`+n.classes.join(`.`),c8(n.attributes),n.content)}function s8(e){return e}function c8(e){let t;for(t in e)Object.hasOwn(e,t)&&(e[t]=z6(e[t]));return e}var l8=j6(e8,{});l8.registerLanguage=function(e,t){return e8.register(t)},l8.alias=function(e,t){return e8.alias(e,t)},u8.displayName=`markup`,u8.aliases=[`atom`,`html`,`mathml`,`rss`,`ssml`,`svg`,`xml`];function u8(e){e.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:`attr-equals`},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:`named-entity`},/&#x?[\da-f]{1,8};/i]},e.languages.markup.tag.inside[`attr-value`].inside.entity=e.languages.markup.entity,e.languages.markup.doctype.inside[`internal-subset`].inside=e.languages.markup,e.hooks.add(`wrap`,function(e){e.type===`entity`&&(e.attributes.title=e.content.value.replace(/&/,`&`))}),Object.defineProperty(e.languages.markup.tag,"addInlined",{value:function(t,n){var r={};r[`language-`+n]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:e.languages[n]},r.cdata=/^<!\[CDATA\[|\]\]>$/i;var i={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:r}};i[`language-`+n]={pattern:/[\s\S]+/,inside:e.languages[n]};var a={};a[t]={pattern:RegExp(`(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[\\s\\S])*?(?=<\\/__>)`.replace(/__/g,function(){return t}),`i`),lookbehind:!0,greedy:!0,inside:i},e.languages.insertBefore(`markup`,`cdata`,a)}}),Object.defineProperty(e.languages.markup.tag,"addAttribute",{value:function(t,n){e.languages.markup.tag.inside[`special-attr`].push({pattern:RegExp(`(^|["'\\s])(?:`+t+`)\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s'">=]+(?=[\\s>]))`,`i`),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[n,`language-`+n],inside:e.languages[n]},punctuation:[{pattern:/^=/,alias:`attr-equals`},/"|'/]}}}})}}),e.languages.html=e.languages.markup,e.languages.mathml=e.languages.markup,e.languages.svg=e.languages.markup,e.languages.xml=e.languages.extend(`markup`,{}),e.languages.ssml=e.languages.xml,e.languages.atom=e.languages.xml,e.languages.rss=e.languages.xml}d8.displayName=`css`,d8.aliases=[];function d8(e){(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(e)}f8.displayName=`clike`,f8.aliases=[];function f8(e){e.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}}p8.displayName=`javascript`,p8.aliases=[`js`];function p8(e){e.register(f8),e.languages.javascript=e.languages.extend(`clike`,{"class-name":[e.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),e.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,e.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:e.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:e.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:e.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:e.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:e.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),e.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:e.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),e.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),e.languages.markup&&(e.languages.markup.tag.addInlined(`script`,`javascript`),e.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),e.languages.js=e.languages.javascript}m8.displayName=`sql`,m8.aliases=[];function m8(e){e.languages.sql={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,lookbehind:!0},variable:[{pattern:/@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,greedy:!0},/@[\w.$]+/],string:{pattern:/(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,greedy:!0,lookbehind:!0},identifier:{pattern:/(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,greedy:!0,lookbehind:!0,inside:{punctuation:/^`|`$/}},function:/\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,keyword:/\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,boolean:/\b(?:FALSE|NULL|TRUE)\b/i,number:/\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,operator:/[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,punctuation:/[;[\]()`,.]/}}h8.displayName=`c`,h8.aliases=[];function h8(e){e.register(f8),e.languages.c=e.languages.extend(`clike`,{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/}),e.languages.insertBefore(`c`,`string`,{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}}),e.languages.insertBefore(`c`,`string`,{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:`property`,inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},e.languages.c.string],char:e.languages.c.char,comment:e.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:`function`}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:`keyword`},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:e.languages.c}}}}),e.languages.insertBefore(`c`,`function`,{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/}),delete e.languages.c.boolean}g8.displayName=`cpp`,g8.aliases=[];function g8(e){e.register(h8),(function(e){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,n=`\\b(?!<keyword>)\\w+(?:\\s*\\.\\s*\\w+)*\\b`.replace(/<keyword>/g,function(){return t.source});e.languages.cpp=e.languages.extend(`c`,{"class-name":[{pattern:RegExp(`(\\b(?:class|concept|enum|struct|typename)\\s+)(?!<keyword>)\\w+`.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),e.languages.insertBefore(`cpp`,`string`,{module:{pattern:RegExp(`(\\b(?:import|module)\\s+)(?:"(?:\\\\(?:\\r\\n|[\\s\\S])|[^"\\\\\\r\\n])*"|<[^<>\\r\\n]*>|`+`<mod-name>(?:\\s*:\\s*<mod-name>)?|:\\s*<mod-name>`.replace(/<mod-name>/g,function(){return n})+`)`),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:`string`,greedy:!0}}),e.languages.insertBefore(`cpp`,`keyword`,{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:e.languages.cpp}}}}),e.languages.insertBefore(`cpp`,`operator`,{"double-colon":{pattern:/::/,alias:`punctuation`}}),e.languages.insertBefore(`cpp`,`class-name`,{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:e.languages.extend(`cpp`,{})}}),e.languages.insertBefore(`inside`,`double-colon`,{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},e.languages.cpp[`base-clause`])})(e)}_8.displayName=`bash`,_8.aliases=[`sh`,`shell`];function _8(e){(function(e){var t=`\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b`,n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:`punctuation`,inside:null},r={bash:n,environment:{pattern:RegExp(`\\$`+t),alias:`constant`},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp(`(\\{)`+t),lookbehind:!0,alias:`constant`}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:`important`},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:`function`},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:`function`}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:`variable`,lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,inside:{environment:{pattern:RegExp(`(^|[\\s;|&]|[<>]\\()`+t),lookbehind:!0,alias:`constant`}},alias:`variable`,lookbehind:!0},parameter:{pattern:/(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,alias:`variable`,lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp(`\\$?`+t),alias:`constant`},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:`class-name`},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:`important`},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:`important`}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var i=[`comment`,`function-name`,`for-or-select`,`assign-left`,`parameter`,`string`,`environment`,`function`,`keyword`,`builtin`,`boolean`,`file-descriptor`,`operator`,`punctuation`,`number`],a=r.variable[1].inside,o=0;o<i.length;o++)a[i[o]]=e.languages.bash[i[o]];e.languages.sh=e.languages.bash,e.languages.shell=e.languages.bash})(e)}v8.displayName=`yaml`,v8.aliases=[`yml`];function v8(e){(function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r=`(?:`+n.source+`(?:[ ]+`+t.source+`)?|`+t.source+`(?:[ ]+`+n.source+`)?)`,i=`(?:[^\\s\\x00-\\x08\\x0e-\\x1f!"#%&'*,\\-:>?@[\\]\`{|}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]|[?:-]<PLAIN>)(?:[ \\t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*`.replace(/<PLAIN>/g,function(){return`[^\\s\\x00-\\x08\\x0e-\\x1f,[\\]{}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]`}),a=`"(?:[^"\\\\\\r\\n]|\\\\.)*"|'(?:[^'\\\\\\r\\n]|\\\\.)*'`;function o(e,t){t=(t||``).replace(/m/g,``)+`m`;var n=`([:\\-,[{]\\s*(?:\\s<<prop>>[ \\t]+)?)(?:<<value>>)(?=[ \\t]*(?:$|,|\\]|\\}|(?:[\\r\\n]\\s*)?#))`.replace(/<<prop>>/g,function(){return r}).replace(/<<value>>/g,function(){return e});return RegExp(n,t)}e.languages.yaml={scalar:{pattern:RegExp(`([\\-:]\\s*(?:\\s<<prop>>[ \\t]+)?[|>])[ \\t]*(?:((?:\\r?\\n|\\r)[ \\t]+)\\S[^\\r\\n]*(?:\\2[^\\r\\n]+)*)`.replace(/<<prop>>/g,function(){return r})),lookbehind:!0,alias:`string`},comment:/#.*/,key:{pattern:RegExp(`((?:^|[:\\-,[{\\r\\n?])[ \\t]*(?:<<prop>>[ \\t]+)?)<<key>>(?=\\s*:\\s)`.replace(/<<prop>>/g,function(){return r}).replace(/<<key>>/g,function(){return`(?:`+i+`|`+a+`)`})),lookbehind:!0,greedy:!0,alias:`atrule`},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:`important`},datetime:{pattern:o(`\\d{4}-\\d\\d?-\\d\\d?(?:[tT]|[ \\t]+)\\d\\d?:\\d{2}:\\d{2}(?:\\.\\d*)?(?:[ \\t]*(?:Z|[-+]\\d\\d?(?::\\d{2})?))?|\\d{4}-\\d{2}-\\d{2}|\\d\\d?:\\d{2}(?::\\d{2}(?:\\.\\d*)?)?`),lookbehind:!0,alias:`number`},boolean:{pattern:o(`false|true`,`i`),lookbehind:!0,alias:`important`},null:{pattern:o(`null|~`,`i`),lookbehind:!0,alias:`important`},string:{pattern:o(a),lookbehind:!0,greedy:!0},number:{pattern:o(`[+-]?(?:0x[\\da-f]+|0o[0-7]+|(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?|\\.inf|\\.nan)`,`i`),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml})(e)}y8.displayName=`markdown`,y8.aliases=[`md`];function y8(e){e.register(u8),(function(e){function t(e){return e=e.replace(/<inner>/g,function(){return`(?:\\\\.|[^\\\\\\n\\r]|(?:\\n|\\r\\n?)(?![\\r\\n]))`}),RegExp(`((?:^|[^\\\\])(?:\\\\{2})*)(?:`+e+`)`)}var n="(?:\\\\.|``(?:[^`\\r\\n]|`(?!`))+``|`[^`\\r\\n]+`|[^\\\\|\\r\\n`])+",r=`\\|?__(?:\\|__)+\\|?(?:(?:\\n|\\r\\n?)|(?![\\s\\S]))`.replace(/__/g,function(){return n}),i=`\\|?[ \\t]*:?-{3,}:?[ \\t]*(?:\\|[ \\t]*:?-{3,}:?[ \\t]*)+\\|?(?:\\n|\\r\\n?)`;e.languages.markdown=e.languages.extend(`markup`,{}),e.languages.insertBefore(`markdown`,`prolog`,{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:[`yaml`,`language-yaml`],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:`punctuation`},table:{pattern:RegExp(`^`+r+i+`(?:`+r+`)*`,`m`),inside:{"table-data-rows":{pattern:RegExp(`^(`+r+i+`)(?:`+r+`)*$`),lookbehind:!0,inside:{"table-data":{pattern:RegExp(n),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp(`^(`+r+`)`+i+`$`),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp(`^`+r+`$`),inside:{"table-header":{pattern:RegExp(n),alias:`important`,inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:`keyword`},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:`important`,inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:`important`,inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:`punctuation`},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:`punctuation`},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:`url`},bold:{pattern:t(`\\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\\b|\\*\\*(?:(?!\\*)<inner>|\\*(?:(?!\\*)<inner>)+\\*)+\\*\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:t(`\\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\\b|\\*(?:(?!\\*)<inner>|\\*\\*(?:(?!\\*)<inner>)+\\*\\*)+\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:t(`(~~?)(?:(?!~)<inner>)+\\2`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:[`code`,`keyword`]},url:{pattern:t(`!?\\[(?:(?!\\])<inner>)+\\](?:\\([^\\s)]+(?:[\\t ]+"(?:\\\\.|[^"\\\\])*")?\\)|[ \\t]?\\[(?:(?!\\])<inner>)+\\])`),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),[`url`,`bold`,`italic`,`strike`].forEach(function(t){[`url`,`bold`,`italic`,`strike`,`code-snippet`].forEach(function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])})}),e.hooks.add(`after-tokenize`,function(e){if(e.language!==`markdown`&&e.language!==`md`)return;function t(e){if(!(!e||typeof e==`string`))for(var n=0,r=e.length;n<r;n++){var i=e[n];if(i.type!==`code`){t(i.content);continue}var a=i.content[1],o=i.content[3];if(a&&o&&a.type===`code-language`&&o.type===`code-block`&&typeof a.content==`string`){var s=a.content.replace(/\b#/g,`sharp`).replace(/\b\+\+/g,`pp`);s=(/[a-z][\w-]*/i.exec(s)||[``])[0].toLowerCase();var c=`language-`+s;o.alias?typeof o.alias==`string`?o.alias=[o.alias,c]:o.alias.push(c):o.alias=[c]}}}t(e.tokens)}),e.hooks.add(`wrap`,function(t){if(t.type===`code-block`){for(var n=``,r=0,i=t.classes.length;r<i;r++){var a=t.classes[r],o=/language-(.+)/.exec(a);if(o){n=o[1];break}}var s=e.languages[n];if(s)t.content=e.highlight(t.content.value,s,n);else if(n&&n!==`none`&&e.plugins.autoloader){var c=`md-`+new Date().valueOf()+`-`+Math.floor(Math.random()*0x2386f26fc10000);t.attributes.id=c,e.plugins.autoloader.loadLanguages(n,function(){var t=document.getElementById(c);t&&(t.innerHTML=e.highlight(t.textContent,e.languages[n],n))})}}}),RegExp(e.languages.markup.tag.pattern.source,`gi`),String.fromCodePoint||String.fromCharCode,e.languages.md=e.languages.markdown})(e)}b8.displayName=`csharp`,b8.aliases=[`cs`,`dotnet`];function b8(e){e.register(f8),(function(e){function t(e,t){return e.replace(/<<(\d+)>>/g,function(e,n){return`(?:`+t[+n]+`)`})}function n(e,n,r){return RegExp(t(e,n),r||``)}function r(e,t){for(var n=0;n<t;n++)e=e.replace(/<<self>>/g,function(){return`(?:`+e+`)`});return e.replace(/<<self>>/g,`[^\\s\\S]`)}var i={type:`bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void`,typeDeclaration:`class enum interface record struct`,contextual:`add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where with(?=\\s*{)`,other:`abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield`};function a(e){return`\\b(?:`+e.trim().replace(/ /g,`|`)+`)\\b`}var o=a(i.typeDeclaration),s=RegExp(a(i.type+` `+i.typeDeclaration+` `+i.contextual+` `+i.other)),c=a(i.typeDeclaration+` `+i.contextual+` `+i.other),l=a(i.type+` `+i.typeDeclaration+` `+i.other),u=r(`<(?:[^<>;=+\\-*/%&|^]|<<self>>)*>`,2),d=r(`\\((?:[^()]|<<self>>)*\\)`,2),f=`@?\\b[A-Za-z_]\\w*\\b`,p=t(`<<0>>(?:\\s*<<1>>)?`,[f,u]),m=t(`(?!<<0>>)<<1>>(?:\\s*\\.\\s*<<1>>)*`,[c,p]),h=`\\[\\s*(?:,\\s*)*\\]`,g=t(`<<0>>(?:\\s*(?:\\?\\s*)?<<1>>)*(?:\\s*\\?)?`,[m,h]),_=t(`(?:<<0>>|<<1>>)(?:\\s*(?:\\?\\s*)?<<2>>)*(?:\\s*\\?)?`,[t(`\\(<<0>>+(?:,<<0>>+)+\\)`,[t(`[^,()<>[\\];=+\\-*/%&|^]|<<0>>|<<1>>|<<2>>`,[u,d,h])]),m,h]),v={keyword:s,punctuation:/[<>()?,.:[\]]/},y=`'(?:[^\\r\\n'\\\\]|\\\\.|\\\\[Uux][\\da-fA-F]{1,8})'`,b=`"(?:\\\\.|[^\\\\"\\r\\n])*"`,x=`@"(?:""|\\\\[\\s\\S]|[^\\\\"])*"(?!")`;e.languages.csharp=e.languages.extend(`clike`,{string:[{pattern:n(`(^|[^$\\\\])<<0>>`,[x]),lookbehind:!0,greedy:!0},{pattern:n(`(^|[^@$\\\\])<<0>>`,[b]),lookbehind:!0,greedy:!0}],"class-name":[{pattern:n(`(\\busing\\s+static\\s+)<<0>>(?=\\s*;)`,[m]),lookbehind:!0,inside:v},{pattern:n(`(\\busing\\s+<<0>>\\s*=\\s*)<<1>>(?=\\s*;)`,[f,_]),lookbehind:!0,inside:v},{pattern:n(`(\\busing\\s+)<<0>>(?=\\s*=)`,[f]),lookbehind:!0},{pattern:n(`(\\b<<0>>\\s+)<<1>>`,[o,p]),lookbehind:!0,inside:v},{pattern:n(`(\\bcatch\\s*\\(\\s*)<<0>>`,[m]),lookbehind:!0,inside:v},{pattern:n(`(\\bwhere\\s+)<<0>>`,[f]),lookbehind:!0},{pattern:n(`(\\b(?:is(?:\\s+not)?|as)\\s+)<<0>>`,[g]),lookbehind:!0,inside:v},{pattern:n(`\\b<<0>>(?=\\s+(?!<<1>>|with\\s*\\{)<<2>>(?:\\s*[=,;:{)\\]]|\\s+(?:in|when)\\b))`,[_,l,f]),inside:v}],keyword:s,number:/(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:[dflmu]|lu|ul)?\b/i,operator:/>>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,punctuation:/\?\.?|::|[{}[\];(),.:]/}),e.languages.insertBefore(`csharp`,`number`,{range:{pattern:/\.\./,alias:`operator`}}),e.languages.insertBefore(`csharp`,`punctuation`,{"named-parameter":{pattern:n(`([(,]\\s*)<<0>>(?=\\s*:)`,[f]),lookbehind:!0,alias:`punctuation`}}),e.languages.insertBefore(`csharp`,`class-name`,{namespace:{pattern:n(`(\\b(?:namespace|using)\\s+)<<0>>(?:\\s*\\.\\s*<<0>>)*(?=\\s*[;{])`,[f]),lookbehind:!0,inside:{punctuation:/\./}},"type-expression":{pattern:n(`(\\b(?:default|sizeof|typeof)\\s*\\(\\s*(?!\\s))(?:[^()\\s]|\\s(?!\\s)|<<0>>)*(?=\\s*\\))`,[d]),lookbehind:!0,alias:`class-name`,inside:v},"return-type":{pattern:n(`<<0>>(?=\\s+(?:<<1>>\\s*(?:=>|[({]|\\.\\s*this\\s*\\[)|this\\s*\\[))`,[_,m]),inside:v,alias:`class-name`},"constructor-invocation":{pattern:n(`(\\bnew\\s+)<<0>>(?=\\s*[[({])`,[_]),lookbehind:!0,inside:v,alias:`class-name`},"generic-method":{pattern:n(`<<0>>\\s*<<1>>(?=\\s*\\()`,[f,u]),inside:{function:n(`^<<0>>`,[f]),generic:{pattern:RegExp(u),alias:`class-name`,inside:v}}},"type-list":{pattern:n(`\\b((?:<<0>>\\s+<<1>>|record\\s+<<1>>\\s*<<5>>|where\\s+<<2>>)\\s*:\\s*)(?:<<3>>|<<4>>|<<1>>\\s*<<5>>|<<6>>)(?:\\s*,\\s*(?:<<3>>|<<4>>|<<6>>))*(?=\\s*(?:where|[{;]|=>|$))`,[o,p,f,_,s.source,d,`\\bnew\\s*\\(\\s*\\)`]),lookbehind:!0,inside:{"record-arguments":{pattern:n(`(^(?!new\\s*\\()<<0>>\\s*)<<1>>`,[p,d]),lookbehind:!0,greedy:!0,inside:e.languages.csharp},keyword:s,"class-name":{pattern:RegExp(_),greedy:!0,inside:v},punctuation:/[,()]/}},preprocessor:{pattern:/(^[\t ]*)#.*/m,lookbehind:!0,alias:`property`,inside:{directive:{pattern:/(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,lookbehind:!0,alias:`keyword`}}}});var S=b+`|`+y,C=t(`\\/(?![*/])|\\/\\/[^\\r\\n]*[\\r\\n]|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/|<<0>>`,[S]),w=r(t(`[^"'/()]|<<0>>|\\(<<self>>*\\)`,[C]),2),T=`\\b(?:assembly|event|field|method|module|param|property|return|type)\\b`,E=t(`<<0>>(?:\\s*\\(<<1>>*\\))?`,[m,w]);e.languages.insertBefore(`csharp`,`class-name`,{attribute:{pattern:n(`((?:^|[^\\s\\w>)?])\\s*\\[\\s*)(?:<<0>>\\s*:\\s*)?<<1>>(?:\\s*,\\s*<<1>>)*(?=\\s*\\])`,[T,E]),lookbehind:!0,greedy:!0,inside:{target:{pattern:n(`^<<0>>(?=\\s*:)`,[T]),alias:`keyword`},"attribute-arguments":{pattern:n(`\\(<<0>>*\\)`,[w]),inside:e.languages.csharp},"class-name":{pattern:RegExp(m),inside:{punctuation:/\./}},punctuation:/[:,]/}}});var D=`:[^}\\r\\n]+`,O=r(t(`[^"'/()]|<<0>>|\\(<<self>>*\\)`,[C]),2),k=t(`\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}`,[O,D]),A=r(t(`[^"'/()]|\\/(?!\\*)|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/|<<0>>|\\(<<self>>*\\)`,[S]),2),j=t(`\\{(?!\\{)(?:(?![}:])<<0>>)*<<1>>?\\}`,[A,D]);function M(t,r){return{interpolation:{pattern:n(`((?:^|[^{])(?:\\{\\{)*)<<0>>`,[t]),lookbehind:!0,inside:{"format-string":{pattern:n(`(^\\{(?:(?![}:])<<0>>)*)<<1>>(?=\\}$)`,[r,D]),lookbehind:!0,inside:{punctuation:/^:/}},punctuation:/^\{|\}$/,expression:{pattern:/[\s\S]+/,alias:`language-csharp`,inside:e.languages.csharp}}},string:/[\s\S]+/}}e.languages.insertBefore(`csharp`,`string`,{"interpolation-string":[{pattern:n(`(^|[^\\\\])(?:\\$@|@\\$)"(?:""|\\\\[\\s\\S]|\\{\\{|<<0>>|[^\\\\{"])*"`,[k]),lookbehind:!0,greedy:!0,inside:M(k,O)},{pattern:n(`(^|[^@\\\\])\\$"(?:\\\\.|\\{\\{|<<0>>|[^\\\\"{])*"`,[j]),lookbehind:!0,greedy:!0,inside:M(j,A)}],char:{pattern:RegExp(y),greedy:!0}}),e.languages.dotnet=e.languages.cs=e.languages.csharp})(e)}x8.displayName=`diff`,x8.aliases=[];function x8(e){(function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":`-`,"deleted-arrow":`<`,"inserted-sign":`+`,"inserted-arrow":`>`,unchanged:` `,diff:`!`};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),n===`diff`&&i.push(`bold`),e.languages.diff[n]={pattern:RegExp(`^(?:[`+r+`].*(?:\r
|
|
479
479
|
?|
|
|
480
|
-
|(?![\\s\\S])))+`,`m`),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})})(e)}S8.displayName=`docker`,S8.aliases=[`dockerfile`];function S8(e){(function(e){var t=`(?:[ \\t]+(?![ \\t])(?:<SP_BS>)?|<SP_BS>)`.replace(/<SP_BS>/g,function(){return`\\\\[\\r\\n](?:\\s|\\\\[\\r\\n]|#.*(?!.))*(?![\\s#]|\\\\[\\r\\n])`}),n=`"(?:[^"\\\\\\r\\n]|\\\\(?:\\r\\n|[\\s\\S]))*"|'(?:[^'\\\\\\r\\n]|\\\\(?:\\r\\n|[\\s\\S]))*'`,r=`--[\\w-]+=(?:<STR>|(?!["'])(?:[^\\s\\\\]|\\\\.)+)`.replace(/<STR>/g,function(){return n}),i={pattern:RegExp(n),greedy:!0},a={pattern:/(^[ \t]*)#.*/m,lookbehind:!0,greedy:!0};function o(e,n){return e=e.replace(/<OPT>/g,function(){return r}).replace(/<SP>/g,function(){return t}),RegExp(e,n)}e.languages.docker={instruction:{pattern:/(^[ \t]*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)(?:\\.|[^\r\n\\])*(?:\\$(?:\s|#.*$)*(?![\s#])(?:\\.|[^\r\n\\])*)*/im,lookbehind:!0,greedy:!0,inside:{options:{pattern:o(`(^(?:ONBUILD<SP>)?\\w+<SP>)<OPT>(?:<SP><OPT>)*`,`i`),lookbehind:!0,greedy:!0,inside:{property:{pattern:/(^|\s)--[\w-]+/,lookbehind:!0},string:[i,{pattern:/(=)(?!["'])(?:[^\s\\]|\\.)+/,lookbehind:!0}],operator:/\\$/m,punctuation:/=/}},keyword:[{pattern:o(`(^(?:ONBUILD<SP>)?HEALTHCHECK<SP>(?:<OPT><SP>)*)(?:CMD|NONE)\\b`,`i`),lookbehind:!0,greedy:!0},{pattern:o(`(^(?:ONBUILD<SP>)?FROM<SP>(?:<OPT><SP>)*(?!--)[^ \\t\\\\]+<SP>)AS`,`i`),lookbehind:!0,greedy:!0},{pattern:o(`(^ONBUILD<SP>)\\w+`,`i`),lookbehind:!0,greedy:!0},{pattern:/^\w+/,greedy:!0}],comment:a,string:i,variable:/\$(?:\w+|\{[^{}"'\\]*\})/,operator:/\\$/m}},comment:a},e.languages.dockerfile=e.languages.docker})(e)}C8.displayName=`go`,C8.aliases=[];function C8(e){e.register(f8),e.languages.go=e.languages.extend(`clike`,{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),e.languages.insertBefore(`go`,`string`,{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete e.languages.go[`class-name`]}w8.displayName=`scss`,w8.aliases=[];function w8(e){e.register(d8),e.languages.scss=e.languages.extend(`css`,{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:`important`},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),e.languages.insertBefore(`scss`,`atrule`,{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),e.languages.insertBefore(`scss`,`important`,{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),e.languages.insertBefore(`scss`,`function`,{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:`keyword`},placeholder:{pattern:/%[-\w]+/,alias:`selector`},statement:{pattern:/\B!(?:default|optional)\b/i,alias:`keyword`},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:`keyword`},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),e.languages.scss.atrule.inside.rest=e.languages.scss}T8.displayName=`json`,T8.aliases=[`webmanifest`];function T8(e){e.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:`keyword`}},e.languages.webmanifest=e.languages.json}E8.displayName=`java`,E8.aliases=[];function E8(e){e.register(f8),(function(e){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,n=`(?:[a-z]\\w*\\s*\\.\\s*)*(?:[A-Z]\\w*\\s*\\.\\s*)*`,r={pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z](?:[\\d_A-Z]*[a-z]\\w*)?\\b`),lookbehind:!0,inside:{namespace:{pattern:/^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,inside:{punctuation:/\./}},punctuation:/\./}};e.languages.java=e.languages.extend(`clike`,{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,lookbehind:!0,greedy:!0},"class-name":[r,{pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z]\\w*(?=\\s+\\w+\\s*[;,=()]|\\s*(?:\\[[\\s,]*\\]\\s*)?::\\s*new\\b)`),lookbehind:!0,inside:r.inside},{pattern:RegExp(`(\\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\\s+)`+n+`[A-Z]\\w*\\b`),lookbehind:!0,inside:r.inside}],keyword:t,function:[e.languages.clike.function,{pattern:/(::\s*)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0},constant:/\b[A-Z][A-Z_\d]+\b/}),e.languages.insertBefore(`java`,`string`,{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:`string`},char:{pattern:/'(?:\\.|[^'\\\r\n]){1,6}'/,greedy:!0}}),e.languages.insertBefore(`java`,`class-name`,{annotation:{pattern:/(^|[^.])@\w+(?:\s*\.\s*\w+)*/,lookbehind:!0,alias:`punctuation`},generics:{pattern:/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,inside:{"class-name":r,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}},import:[{pattern:RegExp(`(\\bimport\\s+)`+n+`(?:[A-Z]\\w*|\\*)(?=\\s*;)`),lookbehind:!0,inside:{namespace:r.inside.namespace,punctuation:/\./,operator:/\*/,"class-name":/\w+/}},{pattern:RegExp(`(\\bimport\\s+static\\s+)`+n+`(?:\\w+|\\*)(?=\\s*;)`),lookbehind:!0,alias:`static`,inside:{namespace:r.inside.namespace,static:/\b\w+$/,punctuation:/\./,operator:/\*/,"class-name":/\w+/}}],namespace:{pattern:RegExp(`(\\b(?:exports|import(?:\\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\\s+)(?!<keyword>)[a-z]\\w*(?:\\.[a-z]\\w*)*\\.?`.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0,inside:{punctuation:/\./}}})})(e)}D8.displayName=`typescript`,D8.aliases=[`ts`];function D8(e){e.register(p8),(function(e){e.languages.typescript=e.languages.extend(`javascript`,{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript[`literal-property`];var t=e.languages.extend(`typescript`,{});delete t[`class-name`],e.languages.typescript[`class-name`].inside=t,e.languages.insertBefore(`typescript`,`function`,{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:`operator`},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:t}}}}),e.languages.ts=e.languages.typescript})(e)}O8.displayName=`python`,O8.aliases=[`py`];function O8(e){e.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern://,alias:`punctuation`},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:`string`},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:[`annotation`,`punctuation`],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},e.languages.python[`string-interpolation`].inside.interpolation.inside.rest=e.languages.python,e.languages.py=e.languages.python}k8.displayName=`jsx`,k8.aliases=[];function k8(e){e.register(p8),e.register(u8),(function(e){var t=e.util.clone(e.languages.javascript),n=`(?:\\s|\\/\\/.*(?!.)|\\/\\*(?:[^*]|\\*(?!\\/))\\*\\/)`,r=`(?:\\{(?:\\{(?:\\{[^{}]*\\}|[^{}])*\\}|[^{}])*\\})`,i=`(?:\\{<S>*\\.{3}(?:[^{}]|<BRACES>)*\\})`;function a(e,t){return e=e.replace(/<S>/g,function(){return n}).replace(/<BRACES>/g,function(){return r}).replace(/<SPREAD>/g,function(){return i}),RegExp(e,t)}i=a(i).source,e.languages.jsx=e.languages.extend(`markup`,t),e.languages.jsx.tag.pattern=a(`<\\/?(?:[\\w.:-]+(?:<S>+(?:[\\w.:$-]+(?:=(?:"(?:\\\\[\\s\\S]|[^\\\\"])*"|'(?:\\\\[\\s\\S]|[^\\\\'])*'|[^\\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\\/?)?>`),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside[`attr-value`].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside[`class-name`]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore(`inside`,`attr-name`,{spread:{pattern:a(`<SPREAD>`),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore(`inside`,`special-attr`,{script:{pattern:a(`=<BRACES>`),alias:`language-javascript`,inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:`punctuation`},rest:e.languages.jsx}}},e.languages.jsx.tag);var o=function(e){return e?typeof e==`string`?e:typeof e.content==`string`?e.content:e.content.map(o).join(``):``},s=function(t){for(var n=[],r=0;r<t.length;r++){var i=t[r],a=!1;if(typeof i!=`string`&&(i.type===`tag`&&i.content[0]&&i.content[0].type===`tag`?i.content[0].content[0].content===`</`?n.length>0&&n[n.length-1].tagName===o(i.content[0].content[1])&&n.pop():i.content[i.content.length-1].content===`/>`||n.push({tagName:o(i.content[0].content[1]),openedBraces:0}):n.length>0&&i.type===`punctuation`&&i.content===`{`?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&i.type===`punctuation`&&i.content===`}`?n[n.length-1].openedBraces--:a=!0),(a||typeof i==`string`)&&n.length>0&&n[n.length-1].openedBraces===0){var c=o(i);r<t.length-1&&(typeof t[r+1]==`string`||t[r+1].type===`plain-text`)&&(c+=o(t[r+1]),t.splice(r+1,1)),r>0&&(typeof t[r-1]==`string`||t[r-1].type===`plain-text`)&&(c=o(t[r-1])+c,t.splice(r-1,1),r--),t[r]=new e.Token(`plain-text`,c,null,c)}i.content&&typeof i.content!=`string`&&s(i.content)}};e.hooks.add(`after-tokenize`,function(e){(e.language===`jsx`||e.language===`tsx`)&&s(e.tokens)})})(e)}A8.displayName=`tsx`,A8.aliases=[];function A8(e){e.register(k8),e.register(D8),(function(e){var t=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend(`jsx`,t),delete e.languages.tsx.parameter,delete e.languages.tsx[`literal-property`];var n=e.languages.tsx.tag;n.pattern=RegExp(`(^|[^\\w$]|(?=<\\/))(?:`+n.pattern.source+`)`,n.pattern.flags),n.lookbehind=!0})(e)}j8.displayName=`rust`,j8.aliases=[];function j8(e){(function(e){for(var t=`\\/\\*(?:[^*/]|\\*(?!\\/)|\\/(?!\\*)|<self>)*\\*\\/`,n=0;n<2;n++)t=t.replace(/<self>/g,function(){return t});t=t.replace(/<self>/g,function(){return`[^\\s\\S]`}),e.languages.rust={comment:[{pattern:RegExp(`(^|[^\\\\])`+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,greedy:!0},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:`attr-name`,inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:`punctuation`},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:`symbol`},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:`punctuation`},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:`function`},"type-definition":{pattern:/(\b(?:enum|struct|trait|type|union)\s+)\w+/,lookbehind:!0,alias:`class-name`},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:`namespace`},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:`namespace`,inside:{punctuation:/::/}}],keyword:[/\b(?:Self|abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\b\w+!/,alias:`property`},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},e.languages.rust[`closure-params`].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string})(e)}var M8={'code[class*="language-"]':{color:`#393A34`,fontFamily:`"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,fontSize:`.9em`,lineHeight:`1.2em`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`},'pre[class*="language-"]':{color:`#393A34`,fontFamily:`"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,fontSize:`.9em`,lineHeight:`1.2em`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`,padding:`1em`,margin:`.5em 0`,overflow:`auto`,border:`1px solid #dddddd`,backgroundColor:`white`},'pre > code[class*="language-"]':{fontSize:`1em`},'pre[class*="language-"]::-moz-selection':{background:`#C1DEF1`},'pre[class*="language-"] ::-moz-selection':{background:`#C1DEF1`},'code[class*="language-"]::-moz-selection':{background:`#C1DEF1`},'code[class*="language-"] ::-moz-selection':{background:`#C1DEF1`},'pre[class*="language-"]::selection':{background:`#C1DEF1`},'pre[class*="language-"] ::selection':{background:`#C1DEF1`},'code[class*="language-"]::selection':{background:`#C1DEF1`},'code[class*="language-"] ::selection':{background:`#C1DEF1`},':not(pre) > code[class*="language-"]':{padding:`.2em`,paddingTop:`1px`,paddingBottom:`1px`,background:`#f8f8f8`,border:`1px solid #dddddd`},comment:{color:`#008000`,fontStyle:`italic`},prolog:{color:`#008000`,fontStyle:`italic`},doctype:{color:`#008000`,fontStyle:`italic`},cdata:{color:`#008000`,fontStyle:`italic`},namespace:{Opacity:`.7`},string:{color:`#A31515`},punctuation:{color:`#393A34`},operator:{color:`#393A34`},url:{color:`#36acaa`},symbol:{color:`#36acaa`},number:{color:`#36acaa`},boolean:{color:`#36acaa`},variable:{color:`#36acaa`},constant:{color:`#36acaa`},inserted:{color:`#36acaa`},atrule:{color:`#0000ff`},keyword:{color:`#0000ff`},"attr-value":{color:`#0000ff`},".language-autohotkey .token.selector":{color:`#0000ff`},".language-json .token.boolean":{color:`#0000ff`},".language-json .token.number":{color:`#0000ff`},'code[class*="language-css"]':{color:`#0000ff`},function:{color:`#393A34`},deleted:{color:`#9a050f`},".language-autohotkey .token.tag":{color:`#9a050f`},selector:{color:`#800000`},".language-autohotkey .token.keyword":{color:`#00009f`},important:{color:`#e90`,fontWeight:`bold`},bold:{fontWeight:`bold`},italic:{fontStyle:`italic`},"class-name":{color:`#2B91AF`},".language-json .token.property":{color:`#2B91AF`},tag:{color:`#800000`},"attr-name":{color:`#ff0000`},property:{color:`#ff0000`},regex:{color:`#ff0000`},entity:{color:`#ff0000`},"directive.tag.tag":{background:`#ffff00`,color:`#393A34`},".line-numbers.line-numbers .line-numbers-rows":{borderRightColor:`#a5a5a5`},".line-numbers .line-numbers-rows > span:before":{color:`#2B91AF`},".line-highlight.line-highlight":{background:`linear-gradient(to right, rgba(193, 222, 241, 0.2) 70%, rgba(221, 222, 241, 0))`}},N8={'pre[class*="language-"]':{color:`#d4d4d4`,fontSize:`13px`,textShadow:`none`,fontFamily:`Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,lineHeight:`1.5`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`,padding:`1em`,margin:`.5em 0`,overflow:`auto`,background:`#1e1e1e`},'code[class*="language-"]':{color:`#d4d4d4`,fontSize:`13px`,textShadow:`none`,fontFamily:`Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,lineHeight:`1.5`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`},'pre[class*="language-"]::selection':{textShadow:`none`,background:`#264F78`},'code[class*="language-"]::selection':{textShadow:`none`,background:`#264F78`},'pre[class*="language-"] *::selection':{textShadow:`none`,background:`#264F78`},'code[class*="language-"] *::selection':{textShadow:`none`,background:`#264F78`},':not(pre) > code[class*="language-"]':{padding:`.1em .3em`,borderRadius:`.3em`,color:`#db4c69`,background:`#1e1e1e`},".namespace":{Opacity:`.7`},"doctype.doctype-tag":{color:`#569CD6`},"doctype.name":{color:`#9cdcfe`},comment:{color:`#6a9955`},prolog:{color:`#6a9955`},punctuation:{color:`#d4d4d4`},".language-html .language-css .token.punctuation":{color:`#d4d4d4`},".language-html .language-javascript .token.punctuation":{color:`#d4d4d4`},property:{color:`#9cdcfe`},tag:{color:`#569cd6`},boolean:{color:`#569cd6`},number:{color:`#b5cea8`},constant:{color:`#9cdcfe`},symbol:{color:`#b5cea8`},inserted:{color:`#b5cea8`},unit:{color:`#b5cea8`},selector:{color:`#d7ba7d`},"attr-name":{color:`#9cdcfe`},string:{color:`#ce9178`},char:{color:`#ce9178`},builtin:{color:`#ce9178`},deleted:{color:`#ce9178`},".language-css .token.string.url":{textDecoration:`underline`},operator:{color:`#d4d4d4`},entity:{color:`#569cd6`},"operator.arrow":{color:`#569CD6`},atrule:{color:`#ce9178`},"atrule.rule":{color:`#c586c0`},"atrule.url":{color:`#9cdcfe`},"atrule.url.function":{color:`#dcdcaa`},"atrule.url.punctuation":{color:`#d4d4d4`},keyword:{color:`#569CD6`},"keyword.module":{color:`#c586c0`},"keyword.control-flow":{color:`#c586c0`},function:{color:`#dcdcaa`},"function.maybe-class-name":{color:`#dcdcaa`},regex:{color:`#d16969`},important:{color:`#569cd6`},italic:{fontStyle:`italic`},"class-name":{color:`#4ec9b0`},"maybe-class-name":{color:`#4ec9b0`},console:{color:`#9cdcfe`},parameter:{color:`#9cdcfe`},interpolation:{color:`#9cdcfe`},"punctuation.interpolation-punctuation":{color:`#569cd6`},variable:{color:`#9cdcfe`},"imports.maybe-class-name":{color:`#9cdcfe`},"exports.maybe-class-name":{color:`#9cdcfe`},escape:{color:`#d7ba7d`},"tag.punctuation":{color:`#808080`},cdata:{color:`#808080`},"attr-value":{color:`#ce9178`},"attr-value.punctuation":{color:`#ce9178`},"attr-value.punctuation.attr-equals":{color:`#d4d4d4`},namespace:{color:`#4ec9b0`},'pre[class*="language-javascript"]':{color:`#9cdcfe`},'code[class*="language-javascript"]':{color:`#9cdcfe`},'pre[class*="language-jsx"]':{color:`#9cdcfe`},'code[class*="language-jsx"]':{color:`#9cdcfe`},'pre[class*="language-typescript"]':{color:`#9cdcfe`},'code[class*="language-typescript"]':{color:`#9cdcfe`},'pre[class*="language-tsx"]':{color:`#9cdcfe`},'code[class*="language-tsx"]':{color:`#9cdcfe`},'pre[class*="language-css"]':{color:`#ce9178`},'code[class*="language-css"]':{color:`#ce9178`},'pre[class*="language-html"]':{color:`#d4d4d4`},'code[class*="language-html"]':{color:`#d4d4d4`},".language-regex .token.anchor":{color:`#dcdcaa`},".language-html .token.punctuation":{color:`#808080`},'pre[class*="language-"] > code[class*="language-"]':{position:`relative`,zIndex:`1`},".line-highlight.line-highlight":{background:`#f7ebc6`,boxShadow:`inset 5px 0 0 #f7d87c`,zIndex:`0`}},P8={bash:_8,c:h8,cpp:g8,csharp:b8,css:d8,diff:x8,docker:S8,go:C8,java:E8,javascript:p8,json:T8,jsx:k8,markdown:y8,markup:u8,python:O8,rust:j8,scss:w8,sql:m8,tsx:A8,typescript:D8,yaml:v8};for(let[e,t]of Object.entries(P8))l8.registerLanguage(e,t);var F8=.25,I8=.5,L8=3;function R8({code:e,isStreaming:t,defaultPreview:n=!1}){let{isDark:r}=Tr(),{t:i}=N(),[a,o]=(0,d.useState)(n),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(!1),f=`${r?`dark`:`light`}\n${e}`,p=a&&!t;(0,d.useEffect)(()=>{if(!p)return;let t=!1;return c({key:f,status:`loading`}),(async()=>{let{default:n}=await l0(async()=>{let{default:e}=await import(`./mermaid.core-Cch8hsNv.js`);return{default:e}},__vite__mapDeps([2,3,4,5,1,6,7,8,9,10,11,12,13,14,15,16,17,18,19]));if(n.initialize({startOnLoad:!1,securityLevel:`strict`,suppressErrorRendering:!0,theme:r?`dark`:`default`}),!await n.parse(e,{suppressErrors:!0}))throw Error(`Invalid Mermaid diagram`);let i=typeof crypto<`u`&&`randomUUID`in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,a=await n.render(i,e);t||c({key:f,status:`ready`,svg:a.svg})})().catch(()=>{t||c({key:f,status:`error`})}),()=>{t=!0}},[e,f,r,p]);let m=(0,E.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),disabled:t,title:i(t?`i18n.previewAfterStreaming`:p?`i18n.showMermaidSource`:`i18n.previewMermaid`),className:[`markdown-code-action`,p?`is-active`:``].filter(Boolean).join(` `),children:i(p?`i18n.source`:`i18n.preview`)});if(!p)return(0,E.jsx)(H8,{code:e,lang:`mermaid`,headerAction:m});let h=s?.key===f&&s.status===`error`?(0,E.jsx)(`div`,{className:`mermaid-block mermaid-block-error`,children:i(`i18n.invalidMermaid`)}):s?.key!==f||s.status!==`ready`?(0,E.jsx)(`div`,{className:`mermaid-block mermaid-block-loading`,"aria-label":i(`i18n.renderingMermaid`)}):(0,E.jsxs)(E.Fragment,{children:[!l&&(0,E.jsx)(`button`,{type:`button`,className:`mermaid-block mermaid-preview-button`,title:i(`i18n.openMermaidViewer`),"aria-label":i(`i18n.openMermaidViewer`),onClick:()=>u(!0),dangerouslySetInnerHTML:{__html:s.svg}}),l&&(0,E.jsx)(z8,{svg:s.svg,onClose:()=>u(!1)})]});return(0,E.jsxs)(`div`,{className:`markdown-code-block`,children:[(0,E.jsxs)(`div`,{className:`markdown-code-header`,children:[(0,E.jsx)(`span`,{className:`markdown-code-lang`,children:`mermaid`}),m]}),h]})}function z8({svg:e,onClose:t}){let{t:n}=N(),r=(0,d.useRef)(null),[i,a]=(0,d.useState)(1);return(0,d.useEffect)(()=>{let e=r.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,E.jsx)(`dialog`,{ref:r,className:`mermaid-zoom-dialog`,"aria-label":n(`i18n.mermaidViewer`),onCancel:e=>{e.preventDefault(),t()},onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),t())},children:(0,E.jsxs)(`div`,{className:`mermaid-zoom-layout`,children:[(0,E.jsxs)(`div`,{className:`mermaid-zoom-toolbar`,children:[(0,E.jsx)(`span`,{className:`mermaid-zoom-title`,children:n(`i18n.mermaidDiagram`)}),(0,E.jsxs)(`div`,{className:`mermaid-zoom-actions`,children:[(0,E.jsxs)(`div`,{className:`mermaid-zoom-stepper`,children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.max(I8,e-F8)),disabled:i<=I8,title:n(`i18n.zoomOut`),"aria-label":n(`i18n.zoomOut`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M5 12h14`})})}),(0,E.jsxs)(`span`,{className:`mermaid-zoom-value`,children:[Math.round(i*100),`%`]}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.min(L8,e+F8)),disabled:i>=L8,title:n(`i18n.zoomIn`),"aria-label":n(`i18n.zoomIn`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M12 5v14M5 12h14`})})})]}),(0,E.jsx)(`button`,{type:`button`,className:`mermaid-zoom-icon-button`,onClick:()=>a(1),title:n(`i18n.fitToWidth`),"aria-label":n(`i18n.fitToWidth`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5`})})}),(0,E.jsx)(`button`,{type:`button`,className:`mermaid-zoom-icon-button`,onClick:t,title:n(`i18n.close`),"aria-label":n(`i18n.close`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M6 6l12 12M18 6 6 18`})})})]})]}),(0,E.jsx)(`div`,{className:`mermaid-zoom-viewport`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,E.jsx)(`div`,{className:`mermaid-zoom-canvas`,style:{width:`${i*100}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}var B8=5e3,V8=800;function H8({code:e,lang:t,headerAction:n,isStreaming:r}){let{isDark:i}=Tr(),{t:a}=N(),[o,s]=(0,d.useState)(!1),c=()=>{Ri(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},l=e.length>B8||r===!0&&e.length>V8;return(0,E.jsxs)(`div`,{className:`markdown-code-block`,children:[(0,E.jsxs)(`div`,{className:`markdown-code-header`,children:[(0,E.jsx)(`span`,{className:`markdown-code-lang`,children:t||`text`}),(0,E.jsxs)(`div`,{className:`markdown-code-actions`,children:[n,(0,E.jsx)(`button`,{onClick:c,className:`markdown-code-action`,children:a(o?`i18n.copied`:`i18n.copy`)})]})]}),l?(0,E.jsx)(`pre`,{className:`markdown-code-plain`,style:{margin:0,padding:`11px 13px`,fontSize:`var(--text-md)`,lineHeight:1.62,borderRadius:0,background:`color-mix(in srgb, var(--bg) 92%, var(--bg-panel))`,overflow:`auto`},children:(0,E.jsx)(`code`,{style:{fontFamily:`var(--font-mono)`},children:e})}):(0,E.jsx)(l8,{language:t||`text`,style:i?N8:M8,showLineNumbers:!0,lineNumberStyle:{color:`var(--text-dim)`,fontStyle:`normal`},customStyle:{margin:0,padding:`11px 13px`,fontSize:`var(--text-md)`,lineHeight:1.62,borderRadius:0,background:`color-mix(in srgb, var(--bg) 92%, var(--bg-panel))`},codeTagProps:{style:{fontFamily:`var(--font-mono)`}},children:e})]})}function U8({children:e,className:t,isStreaming:n,cwd:r,onOpenFile:i}){let{t:a}=N(),[o,s]=(0,d.useState)(!1),c=!o&&e.length>1e5,l=(0,d.useMemo)(()=>c?G3(e):e,[c,e]),u=(0,d.useMemo)(()=>iG(l),[l]),f=(0,d.useMemo)(()=>({code({className:e,children:t,...r}){let i=e?.replace(`language-`,``).toLowerCase()??``,a=String(t);return e?.includes(`language-`)||a.includes(`
|
|
480
|
+
|(?![\\s\\S])))+`,`m`),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})})(e)}S8.displayName=`docker`,S8.aliases=[`dockerfile`];function S8(e){(function(e){var t=`(?:[ \\t]+(?![ \\t])(?:<SP_BS>)?|<SP_BS>)`.replace(/<SP_BS>/g,function(){return`\\\\[\\r\\n](?:\\s|\\\\[\\r\\n]|#.*(?!.))*(?![\\s#]|\\\\[\\r\\n])`}),n=`"(?:[^"\\\\\\r\\n]|\\\\(?:\\r\\n|[\\s\\S]))*"|'(?:[^'\\\\\\r\\n]|\\\\(?:\\r\\n|[\\s\\S]))*'`,r=`--[\\w-]+=(?:<STR>|(?!["'])(?:[^\\s\\\\]|\\\\.)+)`.replace(/<STR>/g,function(){return n}),i={pattern:RegExp(n),greedy:!0},a={pattern:/(^[ \t]*)#.*/m,lookbehind:!0,greedy:!0};function o(e,n){return e=e.replace(/<OPT>/g,function(){return r}).replace(/<SP>/g,function(){return t}),RegExp(e,n)}e.languages.docker={instruction:{pattern:/(^[ \t]*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)(?:\\.|[^\r\n\\])*(?:\\$(?:\s|#.*$)*(?![\s#])(?:\\.|[^\r\n\\])*)*/im,lookbehind:!0,greedy:!0,inside:{options:{pattern:o(`(^(?:ONBUILD<SP>)?\\w+<SP>)<OPT>(?:<SP><OPT>)*`,`i`),lookbehind:!0,greedy:!0,inside:{property:{pattern:/(^|\s)--[\w-]+/,lookbehind:!0},string:[i,{pattern:/(=)(?!["'])(?:[^\s\\]|\\.)+/,lookbehind:!0}],operator:/\\$/m,punctuation:/=/}},keyword:[{pattern:o(`(^(?:ONBUILD<SP>)?HEALTHCHECK<SP>(?:<OPT><SP>)*)(?:CMD|NONE)\\b`,`i`),lookbehind:!0,greedy:!0},{pattern:o(`(^(?:ONBUILD<SP>)?FROM<SP>(?:<OPT><SP>)*(?!--)[^ \\t\\\\]+<SP>)AS`,`i`),lookbehind:!0,greedy:!0},{pattern:o(`(^ONBUILD<SP>)\\w+`,`i`),lookbehind:!0,greedy:!0},{pattern:/^\w+/,greedy:!0}],comment:a,string:i,variable:/\$(?:\w+|\{[^{}"'\\]*\})/,operator:/\\$/m}},comment:a},e.languages.dockerfile=e.languages.docker})(e)}C8.displayName=`go`,C8.aliases=[];function C8(e){e.register(f8),e.languages.go=e.languages.extend(`clike`,{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),e.languages.insertBefore(`go`,`string`,{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete e.languages.go[`class-name`]}w8.displayName=`scss`,w8.aliases=[];function w8(e){e.register(d8),e.languages.scss=e.languages.extend(`css`,{comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},atrule:{pattern:/@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,inside:{rule:/@[\w-]+/}},url:/(?:[-a-z]+-)?url(?=\()/i,selector:{pattern:/(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,inside:{parent:{pattern:/&/,alias:`important`},placeholder:/%[-\w]+/,variable:/\$[-\w]+|#\{\$[-\w]+\}/}},property:{pattern:/(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,inside:{variable:/\$[-\w]+|#\{\$[-\w]+\}/}}}),e.languages.insertBefore(`scss`,`atrule`,{keyword:[/@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,{pattern:/( )(?:from|through)(?= )/,lookbehind:!0}]}),e.languages.insertBefore(`scss`,`important`,{variable:/\$[-\w]+|#\{\$[-\w]+\}/}),e.languages.insertBefore(`scss`,`function`,{"module-modifier":{pattern:/\b(?:as|hide|show|with)\b/i,alias:`keyword`},placeholder:{pattern:/%[-\w]+/,alias:`selector`},statement:{pattern:/\B!(?:default|optional)\b/i,alias:`keyword`},boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:`keyword`},operator:{pattern:/(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,lookbehind:!0}}),e.languages.scss.atrule.inside.rest=e.languages.scss}T8.displayName=`json`,T8.aliases=[`webmanifest`];function T8(e){e.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:`keyword`}},e.languages.webmanifest=e.languages.json}E8.displayName=`java`,E8.aliases=[];function E8(e){e.register(f8),(function(e){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,n=`(?:[a-z]\\w*\\s*\\.\\s*)*(?:[A-Z]\\w*\\s*\\.\\s*)*`,r={pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z](?:[\\d_A-Z]*[a-z]\\w*)?\\b`),lookbehind:!0,inside:{namespace:{pattern:/^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,inside:{punctuation:/\./}},punctuation:/\./}};e.languages.java=e.languages.extend(`clike`,{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,lookbehind:!0,greedy:!0},"class-name":[r,{pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z]\\w*(?=\\s+\\w+\\s*[;,=()]|\\s*(?:\\[[\\s,]*\\]\\s*)?::\\s*new\\b)`),lookbehind:!0,inside:r.inside},{pattern:RegExp(`(\\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\\s+)`+n+`[A-Z]\\w*\\b`),lookbehind:!0,inside:r.inside}],keyword:t,function:[e.languages.clike.function,{pattern:/(::\s*)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0},constant:/\b[A-Z][A-Z_\d]+\b/}),e.languages.insertBefore(`java`,`string`,{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:`string`},char:{pattern:/'(?:\\.|[^'\\\r\n]){1,6}'/,greedy:!0}}),e.languages.insertBefore(`java`,`class-name`,{annotation:{pattern:/(^|[^.])@\w+(?:\s*\.\s*\w+)*/,lookbehind:!0,alias:`punctuation`},generics:{pattern:/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,inside:{"class-name":r,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}},import:[{pattern:RegExp(`(\\bimport\\s+)`+n+`(?:[A-Z]\\w*|\\*)(?=\\s*;)`),lookbehind:!0,inside:{namespace:r.inside.namespace,punctuation:/\./,operator:/\*/,"class-name":/\w+/}},{pattern:RegExp(`(\\bimport\\s+static\\s+)`+n+`(?:\\w+|\\*)(?=\\s*;)`),lookbehind:!0,alias:`static`,inside:{namespace:r.inside.namespace,static:/\b\w+$/,punctuation:/\./,operator:/\*/,"class-name":/\w+/}}],namespace:{pattern:RegExp(`(\\b(?:exports|import(?:\\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\\s+)(?!<keyword>)[a-z]\\w*(?:\\.[a-z]\\w*)*\\.?`.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0,inside:{punctuation:/\./}}})})(e)}D8.displayName=`typescript`,D8.aliases=[`ts`];function D8(e){e.register(p8),(function(e){e.languages.typescript=e.languages.extend(`javascript`,{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript[`literal-property`];var t=e.languages.extend(`typescript`,{});delete t[`class-name`],e.languages.typescript[`class-name`].inside=t,e.languages.insertBefore(`typescript`,`function`,{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:`operator`},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:t}}}}),e.languages.ts=e.languages.typescript})(e)}O8.displayName=`python`,O8.aliases=[`py`];function O8(e){e.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern://,alias:`punctuation`},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:`string`},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:[`annotation`,`punctuation`],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},e.languages.python[`string-interpolation`].inside.interpolation.inside.rest=e.languages.python,e.languages.py=e.languages.python}k8.displayName=`jsx`,k8.aliases=[];function k8(e){e.register(p8),e.register(u8),(function(e){var t=e.util.clone(e.languages.javascript),n=`(?:\\s|\\/\\/.*(?!.)|\\/\\*(?:[^*]|\\*(?!\\/))\\*\\/)`,r=`(?:\\{(?:\\{(?:\\{[^{}]*\\}|[^{}])*\\}|[^{}])*\\})`,i=`(?:\\{<S>*\\.{3}(?:[^{}]|<BRACES>)*\\})`;function a(e,t){return e=e.replace(/<S>/g,function(){return n}).replace(/<BRACES>/g,function(){return r}).replace(/<SPREAD>/g,function(){return i}),RegExp(e,t)}i=a(i).source,e.languages.jsx=e.languages.extend(`markup`,t),e.languages.jsx.tag.pattern=a(`<\\/?(?:[\\w.:-]+(?:<S>+(?:[\\w.:$-]+(?:=(?:"(?:\\\\[\\s\\S]|[^\\\\"])*"|'(?:\\\\[\\s\\S]|[^\\\\'])*'|[^\\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\\/?)?>`),e.languages.jsx.tag.inside.tag.pattern=/^<\/?[^\s>\/]*/,e.languages.jsx.tag.inside[`attr-value`].pattern=/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/,e.languages.jsx.tag.inside.tag.inside[`class-name`]=/^[A-Z]\w*(?:\.[A-Z]\w*)*$/,e.languages.jsx.tag.inside.comment=t.comment,e.languages.insertBefore(`inside`,`attr-name`,{spread:{pattern:a(`<SPREAD>`),inside:e.languages.jsx}},e.languages.jsx.tag),e.languages.insertBefore(`inside`,`special-attr`,{script:{pattern:a(`=<BRACES>`),alias:`language-javascript`,inside:{"script-punctuation":{pattern:/^=(?=\{)/,alias:`punctuation`},rest:e.languages.jsx}}},e.languages.jsx.tag);var o=function(e){return e?typeof e==`string`?e:typeof e.content==`string`?e.content:e.content.map(o).join(``):``},s=function(t){for(var n=[],r=0;r<t.length;r++){var i=t[r],a=!1;if(typeof i!=`string`&&(i.type===`tag`&&i.content[0]&&i.content[0].type===`tag`?i.content[0].content[0].content===`</`?n.length>0&&n[n.length-1].tagName===o(i.content[0].content[1])&&n.pop():i.content[i.content.length-1].content===`/>`||n.push({tagName:o(i.content[0].content[1]),openedBraces:0}):n.length>0&&i.type===`punctuation`&&i.content===`{`?n[n.length-1].openedBraces++:n.length>0&&n[n.length-1].openedBraces>0&&i.type===`punctuation`&&i.content===`}`?n[n.length-1].openedBraces--:a=!0),(a||typeof i==`string`)&&n.length>0&&n[n.length-1].openedBraces===0){var c=o(i);r<t.length-1&&(typeof t[r+1]==`string`||t[r+1].type===`plain-text`)&&(c+=o(t[r+1]),t.splice(r+1,1)),r>0&&(typeof t[r-1]==`string`||t[r-1].type===`plain-text`)&&(c=o(t[r-1])+c,t.splice(r-1,1),r--),t[r]=new e.Token(`plain-text`,c,null,c)}i.content&&typeof i.content!=`string`&&s(i.content)}};e.hooks.add(`after-tokenize`,function(e){(e.language===`jsx`||e.language===`tsx`)&&s(e.tokens)})})(e)}A8.displayName=`tsx`,A8.aliases=[];function A8(e){e.register(k8),e.register(D8),(function(e){var t=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend(`jsx`,t),delete e.languages.tsx.parameter,delete e.languages.tsx[`literal-property`];var n=e.languages.tsx.tag;n.pattern=RegExp(`(^|[^\\w$]|(?=<\\/))(?:`+n.pattern.source+`)`,n.pattern.flags),n.lookbehind=!0})(e)}j8.displayName=`rust`,j8.aliases=[];function j8(e){(function(e){for(var t=`\\/\\*(?:[^*/]|\\*(?!\\/)|\\/(?!\\*)|<self>)*\\*\\/`,n=0;n<2;n++)t=t.replace(/<self>/g,function(){return t});t=t.replace(/<self>/g,function(){return`[^\\s\\S]`}),e.languages.rust={comment:[{pattern:RegExp(`(^|[^\\\\])`+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,greedy:!0},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:`attr-name`,inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:`punctuation`},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:`symbol`},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:`punctuation`},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:`function`},"type-definition":{pattern:/(\b(?:enum|struct|trait|type|union)\s+)\w+/,lookbehind:!0,alias:`class-name`},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:`namespace`},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:`namespace`,inside:{punctuation:/::/}}],keyword:[/\b(?:Self|abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\b\w+!/,alias:`property`},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},e.languages.rust[`closure-params`].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string})(e)}var M8={'code[class*="language-"]':{color:`#393A34`,fontFamily:`"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,fontSize:`.9em`,lineHeight:`1.2em`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`},'pre[class*="language-"]':{color:`#393A34`,fontFamily:`"Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,fontSize:`.9em`,lineHeight:`1.2em`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`,padding:`1em`,margin:`.5em 0`,overflow:`auto`,border:`1px solid #dddddd`,backgroundColor:`white`},'pre > code[class*="language-"]':{fontSize:`1em`},'pre[class*="language-"]::-moz-selection':{background:`#C1DEF1`},'pre[class*="language-"] ::-moz-selection':{background:`#C1DEF1`},'code[class*="language-"]::-moz-selection':{background:`#C1DEF1`},'code[class*="language-"] ::-moz-selection':{background:`#C1DEF1`},'pre[class*="language-"]::selection':{background:`#C1DEF1`},'pre[class*="language-"] ::selection':{background:`#C1DEF1`},'code[class*="language-"]::selection':{background:`#C1DEF1`},'code[class*="language-"] ::selection':{background:`#C1DEF1`},':not(pre) > code[class*="language-"]':{padding:`.2em`,paddingTop:`1px`,paddingBottom:`1px`,background:`#f8f8f8`,border:`1px solid #dddddd`},comment:{color:`#008000`,fontStyle:`italic`},prolog:{color:`#008000`,fontStyle:`italic`},doctype:{color:`#008000`,fontStyle:`italic`},cdata:{color:`#008000`,fontStyle:`italic`},namespace:{Opacity:`.7`},string:{color:`#A31515`},punctuation:{color:`#393A34`},operator:{color:`#393A34`},url:{color:`#36acaa`},symbol:{color:`#36acaa`},number:{color:`#36acaa`},boolean:{color:`#36acaa`},variable:{color:`#36acaa`},constant:{color:`#36acaa`},inserted:{color:`#36acaa`},atrule:{color:`#0000ff`},keyword:{color:`#0000ff`},"attr-value":{color:`#0000ff`},".language-autohotkey .token.selector":{color:`#0000ff`},".language-json .token.boolean":{color:`#0000ff`},".language-json .token.number":{color:`#0000ff`},'code[class*="language-css"]':{color:`#0000ff`},function:{color:`#393A34`},deleted:{color:`#9a050f`},".language-autohotkey .token.tag":{color:`#9a050f`},selector:{color:`#800000`},".language-autohotkey .token.keyword":{color:`#00009f`},important:{color:`#e90`,fontWeight:`bold`},bold:{fontWeight:`bold`},italic:{fontStyle:`italic`},"class-name":{color:`#2B91AF`},".language-json .token.property":{color:`#2B91AF`},tag:{color:`#800000`},"attr-name":{color:`#ff0000`},property:{color:`#ff0000`},regex:{color:`#ff0000`},entity:{color:`#ff0000`},"directive.tag.tag":{background:`#ffff00`,color:`#393A34`},".line-numbers.line-numbers .line-numbers-rows":{borderRightColor:`#a5a5a5`},".line-numbers .line-numbers-rows > span:before":{color:`#2B91AF`},".line-highlight.line-highlight":{background:`linear-gradient(to right, rgba(193, 222, 241, 0.2) 70%, rgba(221, 222, 241, 0))`}},N8={'pre[class*="language-"]':{color:`#d4d4d4`,fontSize:`13px`,textShadow:`none`,fontFamily:`Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,lineHeight:`1.5`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`,padding:`1em`,margin:`.5em 0`,overflow:`auto`,background:`#1e1e1e`},'code[class*="language-"]':{color:`#d4d4d4`,fontSize:`13px`,textShadow:`none`,fontFamily:`Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace`,direction:`ltr`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,lineHeight:`1.5`,MozTabSize:`4`,OTabSize:`4`,tabSize:`4`,WebkitHyphens:`none`,MozHyphens:`none`,msHyphens:`none`,hyphens:`none`},'pre[class*="language-"]::selection':{textShadow:`none`,background:`#264F78`},'code[class*="language-"]::selection':{textShadow:`none`,background:`#264F78`},'pre[class*="language-"] *::selection':{textShadow:`none`,background:`#264F78`},'code[class*="language-"] *::selection':{textShadow:`none`,background:`#264F78`},':not(pre) > code[class*="language-"]':{padding:`.1em .3em`,borderRadius:`.3em`,color:`#db4c69`,background:`#1e1e1e`},".namespace":{Opacity:`.7`},"doctype.doctype-tag":{color:`#569CD6`},"doctype.name":{color:`#9cdcfe`},comment:{color:`#6a9955`},prolog:{color:`#6a9955`},punctuation:{color:`#d4d4d4`},".language-html .language-css .token.punctuation":{color:`#d4d4d4`},".language-html .language-javascript .token.punctuation":{color:`#d4d4d4`},property:{color:`#9cdcfe`},tag:{color:`#569cd6`},boolean:{color:`#569cd6`},number:{color:`#b5cea8`},constant:{color:`#9cdcfe`},symbol:{color:`#b5cea8`},inserted:{color:`#b5cea8`},unit:{color:`#b5cea8`},selector:{color:`#d7ba7d`},"attr-name":{color:`#9cdcfe`},string:{color:`#ce9178`},char:{color:`#ce9178`},builtin:{color:`#ce9178`},deleted:{color:`#ce9178`},".language-css .token.string.url":{textDecoration:`underline`},operator:{color:`#d4d4d4`},entity:{color:`#569cd6`},"operator.arrow":{color:`#569CD6`},atrule:{color:`#ce9178`},"atrule.rule":{color:`#c586c0`},"atrule.url":{color:`#9cdcfe`},"atrule.url.function":{color:`#dcdcaa`},"atrule.url.punctuation":{color:`#d4d4d4`},keyword:{color:`#569CD6`},"keyword.module":{color:`#c586c0`},"keyword.control-flow":{color:`#c586c0`},function:{color:`#dcdcaa`},"function.maybe-class-name":{color:`#dcdcaa`},regex:{color:`#d16969`},important:{color:`#569cd6`},italic:{fontStyle:`italic`},"class-name":{color:`#4ec9b0`},"maybe-class-name":{color:`#4ec9b0`},console:{color:`#9cdcfe`},parameter:{color:`#9cdcfe`},interpolation:{color:`#9cdcfe`},"punctuation.interpolation-punctuation":{color:`#569cd6`},variable:{color:`#9cdcfe`},"imports.maybe-class-name":{color:`#9cdcfe`},"exports.maybe-class-name":{color:`#9cdcfe`},escape:{color:`#d7ba7d`},"tag.punctuation":{color:`#808080`},cdata:{color:`#808080`},"attr-value":{color:`#ce9178`},"attr-value.punctuation":{color:`#ce9178`},"attr-value.punctuation.attr-equals":{color:`#d4d4d4`},namespace:{color:`#4ec9b0`},'pre[class*="language-javascript"]':{color:`#9cdcfe`},'code[class*="language-javascript"]':{color:`#9cdcfe`},'pre[class*="language-jsx"]':{color:`#9cdcfe`},'code[class*="language-jsx"]':{color:`#9cdcfe`},'pre[class*="language-typescript"]':{color:`#9cdcfe`},'code[class*="language-typescript"]':{color:`#9cdcfe`},'pre[class*="language-tsx"]':{color:`#9cdcfe`},'code[class*="language-tsx"]':{color:`#9cdcfe`},'pre[class*="language-css"]':{color:`#ce9178`},'code[class*="language-css"]':{color:`#ce9178`},'pre[class*="language-html"]':{color:`#d4d4d4`},'code[class*="language-html"]':{color:`#d4d4d4`},".language-regex .token.anchor":{color:`#dcdcaa`},".language-html .token.punctuation":{color:`#808080`},'pre[class*="language-"] > code[class*="language-"]':{position:`relative`,zIndex:`1`},".line-highlight.line-highlight":{background:`#f7ebc6`,boxShadow:`inset 5px 0 0 #f7d87c`,zIndex:`0`}},P8={bash:_8,c:h8,cpp:g8,csharp:b8,css:d8,diff:x8,docker:S8,go:C8,java:E8,javascript:p8,json:T8,jsx:k8,markdown:y8,markup:u8,python:O8,rust:j8,scss:w8,sql:m8,tsx:A8,typescript:D8,yaml:v8};for(let[e,t]of Object.entries(P8))l8.registerLanguage(e,t);var F8=.25,I8=.5,L8=3;function R8({code:e,isStreaming:t,defaultPreview:n=!1}){let{isDark:r}=Tr(),{t:i}=N(),[a,o]=(0,d.useState)(n),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(!1),f=`${r?`dark`:`light`}\n${e}`,p=a&&!t;(0,d.useEffect)(()=>{if(!p)return;let t=!1;return c({key:f,status:`loading`}),(async()=>{let{default:n}=await l0(async()=>{let{default:e}=await import(`./mermaid.core-Ta81F5Ju.js`);return{default:e}},__vite__mapDeps([2,3,4,5,1,6,7,8,9,10,11,12,13,14,15,16,17,18,19]));if(n.initialize({startOnLoad:!1,securityLevel:`strict`,suppressErrorRendering:!0,theme:r?`dark`:`default`}),!await n.parse(e,{suppressErrors:!0}))throw Error(`Invalid Mermaid diagram`);let i=typeof crypto<`u`&&`randomUUID`in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,a=await n.render(i,e);t||c({key:f,status:`ready`,svg:a.svg})})().catch(()=>{t||c({key:f,status:`error`})}),()=>{t=!0}},[e,f,r,p]);let m=(0,E.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),disabled:t,title:i(t?`i18n.previewAfterStreaming`:p?`i18n.showMermaidSource`:`i18n.previewMermaid`),className:[`markdown-code-action`,p?`is-active`:``].filter(Boolean).join(` `),children:i(p?`i18n.source`:`i18n.preview`)});if(!p)return(0,E.jsx)(H8,{code:e,lang:`mermaid`,headerAction:m});let h=s?.key===f&&s.status===`error`?(0,E.jsx)(`div`,{className:`mermaid-block mermaid-block-error`,children:i(`i18n.invalidMermaid`)}):s?.key!==f||s.status!==`ready`?(0,E.jsx)(`div`,{className:`mermaid-block mermaid-block-loading`,"aria-label":i(`i18n.renderingMermaid`)}):(0,E.jsxs)(E.Fragment,{children:[!l&&(0,E.jsx)(`button`,{type:`button`,className:`mermaid-block mermaid-preview-button`,title:i(`i18n.openMermaidViewer`),"aria-label":i(`i18n.openMermaidViewer`),onClick:()=>u(!0),dangerouslySetInnerHTML:{__html:s.svg}}),l&&(0,E.jsx)(z8,{svg:s.svg,onClose:()=>u(!1)})]});return(0,E.jsxs)(`div`,{className:`markdown-code-block`,children:[(0,E.jsxs)(`div`,{className:`markdown-code-header`,children:[(0,E.jsx)(`span`,{className:`markdown-code-lang`,children:`mermaid`}),m]}),h]})}function z8({svg:e,onClose:t}){let{t:n}=N(),r=(0,d.useRef)(null),[i,a]=(0,d.useState)(1);return(0,d.useEffect)(()=>{let e=r.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,E.jsx)(`dialog`,{ref:r,className:`mermaid-zoom-dialog`,"aria-label":n(`i18n.mermaidViewer`),onCancel:e=>{e.preventDefault(),t()},onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),t())},children:(0,E.jsxs)(`div`,{className:`mermaid-zoom-layout`,children:[(0,E.jsxs)(`div`,{className:`mermaid-zoom-toolbar`,children:[(0,E.jsx)(`span`,{className:`mermaid-zoom-title`,children:n(`i18n.mermaidDiagram`)}),(0,E.jsxs)(`div`,{className:`mermaid-zoom-actions`,children:[(0,E.jsxs)(`div`,{className:`mermaid-zoom-stepper`,children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.max(I8,e-F8)),disabled:i<=I8,title:n(`i18n.zoomOut`),"aria-label":n(`i18n.zoomOut`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M5 12h14`})})}),(0,E.jsxs)(`span`,{className:`mermaid-zoom-value`,children:[Math.round(i*100),`%`]}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.min(L8,e+F8)),disabled:i>=L8,title:n(`i18n.zoomIn`),"aria-label":n(`i18n.zoomIn`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M12 5v14M5 12h14`})})})]}),(0,E.jsx)(`button`,{type:`button`,className:`mermaid-zoom-icon-button`,onClick:()=>a(1),title:n(`i18n.fitToWidth`),"aria-label":n(`i18n.fitToWidth`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5`})})}),(0,E.jsx)(`button`,{type:`button`,className:`mermaid-zoom-icon-button`,onClick:t,title:n(`i18n.close`),"aria-label":n(`i18n.close`),children:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M6 6l12 12M18 6 6 18`})})})]})]}),(0,E.jsx)(`div`,{className:`mermaid-zoom-viewport`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,E.jsx)(`div`,{className:`mermaid-zoom-canvas`,style:{width:`${i*100}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}var B8=5e3,V8=800;function H8({code:e,lang:t,headerAction:n,isStreaming:r}){let{isDark:i}=Tr(),{t:a}=N(),[o,s]=(0,d.useState)(!1),c=()=>{Ri(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},l=e.length>B8||r===!0&&e.length>V8;return(0,E.jsxs)(`div`,{className:`markdown-code-block`,children:[(0,E.jsxs)(`div`,{className:`markdown-code-header`,children:[(0,E.jsx)(`span`,{className:`markdown-code-lang`,children:t||`text`}),(0,E.jsxs)(`div`,{className:`markdown-code-actions`,children:[n,(0,E.jsx)(`button`,{onClick:c,className:`markdown-code-action`,children:a(o?`i18n.copied`:`i18n.copy`)})]})]}),l?(0,E.jsx)(`pre`,{className:`markdown-code-plain`,style:{margin:0,padding:`11px 13px`,fontSize:`var(--text-md)`,lineHeight:1.62,borderRadius:0,background:`color-mix(in srgb, var(--bg) 92%, var(--bg-panel))`,overflow:`auto`},children:(0,E.jsx)(`code`,{style:{fontFamily:`var(--font-mono)`},children:e})}):(0,E.jsx)(l8,{language:t||`text`,style:i?N8:M8,showLineNumbers:!0,lineNumberStyle:{color:`var(--text-dim)`,fontStyle:`normal`},customStyle:{margin:0,padding:`11px 13px`,fontSize:`var(--text-md)`,lineHeight:1.62,borderRadius:0,background:`color-mix(in srgb, var(--bg) 92%, var(--bg-panel))`},codeTagProps:{style:{fontFamily:`var(--font-mono)`}},children:e})]})}function U8({children:e,className:t,isStreaming:n,cwd:r,onOpenFile:i}){let{t:a}=N(),[o,s]=(0,d.useState)(!1),c=!o&&e.length>1e5,l=(0,d.useMemo)(()=>c?G3(e):e,[c,e]),u=(0,d.useMemo)(()=>iG(l),[l]),f=(0,d.useMemo)(()=>({code({className:e,children:t,...r}){let i=e?.replace(`language-`,``).toLowerCase()??``,a=String(t);return e?.includes(`language-`)||a.includes(`
|
|
481
481
|
`)?i===`mermaid`?(0,E.jsx)(R8,{code:a.replace(/\n$/,``),isStreaming:n}):(0,E.jsx)(H8,{code:a.replace(/\n$/,``),lang:i,isStreaming:n}):(0,E.jsx)(`code`,{className:`markdown-inline-code`,...r,children:t})},pre({children:e}){return(0,E.jsx)(E.Fragment,{children:e})},a({href:e,children:t,...n}){delete n.node;let a=i?RG(e,r):null,o=i;if(!a||!o)return(0,E.jsx)(`a`,{href:e,...n,target:`_blank`,rel:`noopener noreferrer`,children:t});let s=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute(`target`);t&&t!==`_self`||(e.preventDefault(),o(a))};return(0,E.jsx)(`a`,{href:e,...n,onClick:s,children:t})},img({src:e,alt:t,...n}){delete n.node;let i=typeof e==`string`?RG(e,r):null,a=i?`/api/files/${mG(i)}?type=read`:e;return(0,E.jsx)(`img`,{src:a,alt:t??``,loading:`lazy`,...n})},table({children:e}){return(0,E.jsx)(`div`,{className:`markdown-table-wrap`,children:(0,E.jsx)(`table`,{children:e})})},blockquote({children:e}){return(0,E.jsx)(`blockquote`,{children:e})}}),[r,n,i]);return(0,E.jsxs)(`div`,{className:[`markdown-body`,t].filter(Boolean).join(` `),style:{whiteSpace:`pre-wrap`},children:[(0,E.jsx)(B3,{remarkPlugins:cG??void 0,rehypePlugins:uG??void 0,components:f,children:u}),c&&(0,E.jsxs)(`button`,{type:`button`,"aria-label":a(`chat.expandMessage`),title:a(`chat.expandMessage`),onClick:()=>s(!0),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:6,width:`100%`,marginTop:6,padding:`5px 0`,border:`none`,borderTop:`1px solid var(--border)`,background:`var(--bg-subtle)`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,children:`…`}),(0,E.jsx)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]})]})}var{min:W8,max:G8,abs:K8,floor:q8}=Math,J8=(e,t,n)=>W8(n,G8(t,e)),Y8=e=>[...e].sort((e,t)=>e-t),X8=setTimeout,Z8=clearTimeout,Q8=typeof queueMicrotask==`function`?queueMicrotask:e=>{Promise.resolve().then(e)},$8=()=>{let e;return[new Promise(t=>{e=t}),e]},e5=e=>{let t;return()=>(e&&=(t=e(),void 0),t)},t5=typeof window<`u`,n5=e=>e.documentElement,r5=e=>e.ownerDocument,i5=e=>e.defaultView,a5=e5(()=>!!/iP(hone|od|ad)/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>0),o5=e5(()=>`scrollBehavior`in n5(document).style),s5=e=>G8(e.t(),e.o()),c5=({i:e,l:t,u:n,h:r,v:i,S:a,t:o,$:s,m:c,p:l},u=0)=>{let d=!!l,f=!!u,p=1,m=0,h=0,g=0,_=0,v=0,y=0,b=0,x=0,S=null,C=[0,f?G8(u-1,0):-1],w=0,T=!1,E=new Set,D=()=>g-h,O=()=>D()+v+_,k=(e,t)=>{let i=n(e)-v;return t?o()-i-r(e):i},A=e=>{e&&(a5()&&b!==0||S&&x===1?v+=e:_+=e)};return{_:()=>{E.clear()},I:()=>p,i:(t=200)=>{if(!T||f)return C;let n,r;if(y)[n,r]=C;else{let i=G8(0,O()),a=i+m;d||(t=G8(0,t),b!==1&&(i-=t),b!==2&&(a+=t)),[n,r]=C=e(G8(0,i),G8(0,a)),S&&(n=W8(n,S[0]),r=G8(r,S[1]))}return[G8(n,0),W8(r,s()-1)]},k:e=>t(e-h),R:a,u:k,h:r,C:s,T:()=>g,M:()=>b!==0,o:()=>m,O:()=>h,t:o,L:()=>(y=_,_=0,[y,x===2]),H:(e,t)=>{let n=[e,t];return E.add(n),()=>{E.delete(n)}},W:(n,s)=>{let u,C,j=0;switch(n){case 1:{if(s===g&&x===0)break;let e=y;y=0;let t=s-g,n=K8(t);e&&n<K8(e)+1||x!==0||(b=t<0?2:1),f&&=!1,g=s,j=4;let r=D();r>=-m&&r<=o()&&(j+=1,C=n>m);break}case 2:j=8,b!==0&&(u=!0,j+=1),b=0,x=0,S=null;break;case 3:{let e=s.filter(([e,t])=>!a(e,t));if(!e.length)break;A(e.reduce((e,[t,n])=>{let i;if(x===2)i=!0;else if(S&&x===1)i=t<S[0];else{let e=D(),n=k(t),a=r(t);i=b!==1&&x===0?n+a<=e:n<e&&n+a<e+m}return i&&(e+=n-r(t)),e},0));for(let[t,n]of e){let e=r(t),a=i(t,n);d&&(w+=a?n:n-e)}d&&m&&w>m&&(A(l(t(O()))),d=!1),j=3,C=!0;break}case 4:m!==s&&(m||(T=C=!0),m=s,j=3);break;case 5:s[1]?(A(c(s[0],!0)),x=2,j=1):(c(s[0]),j=1);break;case 6:h=s;break;case 7:x=1;break;case 8:S=e(s,s+m),j=1}j&&(p=1+(2147483647&p),u&&v&&(_+=v,v=0),E.forEach(([e,t])=>{j&e&&t(C)}))}}},l5=(e,t,n,r=0,i=t-1)=>{let a=r;for(;r<=i;){let t=q8((r+i)/2);e(t)<=n?(a=t,r=t+1):i=t-1}return J8(a,0,t-1)},u5=(e,t,n)=>{let r=n?`unshift`:`push`;for(let n=0;n<t;n++)e[r](-1);return e},d5=(e,t,n)=>{let r=n&&n[1]||t||40,i=-1,a=0,o=n&&n[0],s=o?u5(o.slice(0,W8(e,o.length)),G8(0,e-o.length)):u5([],e),c=u5([],e+1),l=e=>{let t=s[e];return t===-1?r:t},u=t=>{if(!e)return 0;if(i>=t)return c[t];i<0&&(c[0]=0,i=0);let n=i,r=c[n];for(;n<t;)r+=l(n),c[++n]=r;return i=t,r};return{i:(t,n)=>{let r,i;return a=W8(a,e-1),u(a)<=t?(i=l5(u,e,n,a),r=l5(u,e,t,a,i)):(r=l5(u,e,t,void 0,a),i=l5(u,e,n,r)),a=r,[r,i]},l:t=>l5(u,e,t),u,h:l,v:(e,t)=>{let n=s[e]===-1;return s[e]=t,i=W8(e,i),n},S:(e,t=-1)=>s[e]===t,t:()=>u(e),$:()=>e,m:(t,n)=>{let a=t-e;return i=n?-1:W8(t-1,i),e=t,a>0?(u5(c,a),u5(s,a,n),r*a):(c.splice(a),(n?s.splice(0,-a):s.splice(a)).reduce((e,t)=>e-(t===-1?r:t),0))},p:t?void 0:e=>{let t=0,n=[];s.forEach((r,i)=>{r!==-1&&(r&&n.push(r),i<e&&t++)}),i=-1;let a=Y8(n),o=a.length,c=o/2|0,l=o%2==0?(a[c-1]+a[c])/2:a[c],u=r;return((r=l)-u)*G8(e-t,0)},B:()=>[s.slice(),r]}},f5=e=>{let t;return{X(n){(t||=new(i5(r5(n))).ResizeObserver(e)).observe(n)},Y(e){t.unobserve(e)},q(){t&&t.disconnect()}}},p5=(e,t)=>t?-e:e,m5=(e,t,n,r,i,a)=>{let o,s=0,c=!1,l=!1,u=!1,d=!1,f=Date.now,p=()=>{if(c||l)return c=!1,void m();u=!1,e.W(2)},m=()=>{Z8(o),o=X8(p,150)},h=()=>{s=f(),u&&(d=!0),a&&e.W(6,a()),e.W(1,r()),m()},g=t=>{if(c||!e.M()||t.ctrlKey)return;let r=f()-s;150>r&&50<r&&(n?t.deltaX:t.deltaY)&&(c=!0)},_=()=>{l=!0,u=d=!1},v=()=>{l=!1,a5()&&(u=!0)};return t.addEventListener(`scroll`,h),t.addEventListener(`wheel`,g,{passive:!0}),t.addEventListener(`touchstart`,_,{passive:!0}),t.addEventListener(`touchend`,v,{passive:!0}),{q:()=>{t.removeEventListener(`scroll`,h),t.removeEventListener(`wheel`,g),t.removeEventListener(`touchstart`,_),t.removeEventListener(`touchend`,v),Z8(o)},A:()=>{let[t,n]=e.L();t&&(i(t,n,d),d=!1,n&&e.o()>e.t()&&e.W(1,r()))}}},h5=(e,t,n)=>{let r;return[async(i,a)=>{if(!await t())return;let o,s,c;r&&r();let l=a&&o5(),u=r=()=>{o=!0,Z8(s),c&&c()},d=()=>{if(!o){if(e.o()&&(Z8(s),s=X8(u,150)),l){for(let[t,n]=e.i(0);t<=n;t++)if(e.R(t))return;u()}e.W(7),n(i(),l)}},f=()=>{if(o)return;let t;c=e.H(2,()=>{t||(t=!0,Q8(()=>{t=!1,d()}))}),d()};l?(e.W(8,i()),Q8(f)):f()},()=>{r&&r()}]},g5=(e,t)=>{let n,r,i=$8(),a=!1,o=t?`scrollLeft`:`scrollTop`,s=t?`overflowX`:`overflowY`,[c,l]=h5(e,()=>i[0],(e,r)=>{e=p5(e,a),r?n.scrollTo({[t?`left`:`top`]:e,behavior:`smooth`}):n[o]=e}),u=t?`width`:`height`,d=new WeakMap,f=f5(t=>{let r=[];for(let{target:i,contentRect:a}of t)if(i.offsetParent){if(i===n)e.W(4,a[u]);else{let e=d.get(i);e!=null&&r.push([e,a[u]])}}r.length&&e.W(3,r)});return{D(c,u=c.parentElement){f.X(n=u),t&&(a=getComputedStyle(u).direction===`rtl`),r=m5(e,u,t,()=>p5(u[o],a),(t,n,r)=>{if(r){let e=u.style,t=e[s];e[s]=`hidden`,X8(()=>{e[s]=t})}u[o]=p5(e.T()+t,a),n&&l()}),i[1](!0)},_(){f.q(),r&&r.q(),i[1](!1),i=$8()},N:(e,t)=>(d.set(e,t),f.X(e),()=>{d.delete(e),f.Y(e)}),P:()=>a,V:c,J(){r&&r.A()},j:e.O,G:()=>0}},_5=(e,t)=>{e.V(()=>t)},v5=(e,t,n,{align:r,smooth:i,offset:a=0}={})=>{if(n=J8(n,0,t.C()-1),r===`nearest`){let e=t.u(n),i=t.T();if(e<i)r=`start`;else{if(!(e+t.h(n)>i+t.o()))return;r=`end`}}e.V(()=>a+e.j()+t.u(n)+(r===`end`?t.h(n)-(t.o()-e.G()):r===`center`?(t.h(n)-(t.o()-e.G()))/2:0),i)},y5=t5?d.useLayoutEffect:d.useEffect,b5=`current`,x5=(e,t)=>{if(Array.isArray(e))for(let n of e)x5(n,t);else e==null||typeof e==`boolean`||t.push(e)},S5=(e,t)=>e.key??`_`+t,C5=e=>{let t=(0,d.useRef)(null);return t.current||=e()},w5=e=>{let t=(0,d.useRef)(e);return y5(()=>{t[b5]=e},[e]),t},T5=(0,d.memo)(({ee:e,te:t,oe:n,ne:r,re:i,ie:a,se:o,le:s})=>{let c=(0,d.useRef)(null);y5(()=>t(c[b5],n),[n]);let l=(0,d.useMemo)(()=>{let e={contain:`layout style`,position:i&&s?void 0:`absolute`,[o?`height`:`width`]:`100%`,[o?`top`:`left`]:0,[o?`left`:`top`]:r,visibility:!i||s?void 0:`hidden`};return o&&(e.display=`inline-flex`),e},[r,i,s,o]);return(0,E.jsx)(a,typeof a==`string`?{ref:c,style:l,children:e}:{ref:c,style:l,index:n,children:e})}),E5=(e,t)=>(0,d.useMemo)(()=>{if(typeof e==`function`)return[n=>e(t[n],n),t.length];let n=(e=>{let t=[];return x5(e,t),t})(e);return[e=>n[e],n.length]},[e,t]),D5=(0,d.forwardRef)(({children:e,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,startMargin:c=0,ssrCount:l,as:u=`div`,item:f=`div`,scrollRef:p,onScroll:m,onScrollEnd:h},g)=>{let[_,v]=E5(e,t),y=(0,d.useRef)(null),b=(0,d.useRef)(!!l),x=w5(m),S=w5(h),[C,w,T,D]=C5(()=>{let e=!!a,t=d5(v,r,s),n=c5(t,l);return[n,t,g5(n,e),e]});v!==C.C()&&C.W(5,[v,i]),c!==C.O()&&C.W(6,c);let[O,k]=(0,d.useReducer)(C.I,void 0,C.I),A=C.M(),j=C.t(),M=T.P(),N=[],P=e=>{let t=_(e);return(0,E.jsx)(T5,{te:T.N,oe:e,ne:C.u(e,M),re:C.R(e),ie:f,ee:t,se:D,le:b[b5]},S5(t,e))};if(y5(()=>{b[b5]=!1,C.H(1,e=>{e?(0,Gi.flushSync)(k):k()}),C.H(4,()=>{x.current&&x.current(C.T())}),C.H(8,()=>{S.current&&S.current()});let e=y[b5];return p?Q8(()=>{p.current&&T.D(e,p[b5])}):T.D(e),()=>{C._(),T._()}},[]),y5(()=>{T.J()},[O]),(0,d.useImperativeHandle)(g,()=>({get cache(){return w.B()},get scrollOffset(){return C.T()},get scrollSize(){return s5(C)},get viewportSize(){return C.o()},findItemIndex:C.k,getItemOffset:C.u,getItemSize:C.h,scrollToIndex:(e,t)=>v5(T,C,e,t),scrollTo:e=>_5(T,e),scrollBy:e=>((e,t,n)=>{_5(e,n+t.T())})(T,C,e)}),[]),o){let e=new Set(o);for(let[t,r]=C.i(n);t<=r;t++)e.add(t);Y8([...e]).forEach(e=>{N.push(P(e))})}else for(let[e,t]=C.i(n);e<=t;e++)N.push(P(e));return(0,E.jsx)(u,{ref:y,style:{contain:`size style`,overflowAnchor:`none`,flex:`none`,position:`relative`,width:D?j:`100%`,height:D?`100%`:j,pointerEvents:A?`none`:void 0},children:N})}),O5=100,k5=new Map;function A5(e,t,n){let r=`${e}:${t}:${n}`,i=k5.get(r);if(i)return k5.delete(r),k5.set(r,i),i;let a=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${n}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if(typeof t.thinking!=`string`)throw Error(`Invalid thinking response`);return t.thinking}).catch(e=>{throw k5.delete(r),e});if(k5.set(r,a),k5.size>O5){let e=k5.keys().next().value;e&&k5.delete(e)}return a}function j5(e){if(!e)return null;let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),i=t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});return r?i:`${t.toLocaleDateString([],{month:`short`,day:`numeric`,year:t.getFullYear()===n.getFullYear()?void 0:`numeric`})} ${i}`}function M5(e,t,n){if(t===n||e.role!==`assistant`)return!0;for(let r of e.content??[])if(r.type===`toolCall`&&t?.get(r.toolCallId)!==n?.get(r.toolCallId))return!1;return!0}var N5=(0,d.memo)(function({message:e,isStreaming:t,toolResults:n,modelNames:r,cwd:i,onOpenFile:a,entryId:o,onFork:s,forking:c,onNavigate:l,prevAssistantEntryId:u,onEditContent:d,showTimestamp:f,turnStartTimestamp:p,sessionId:m,streamingBashOutput:h,longBlockCollapseChars:g,recentExpandedBlockKeys:_,modelLabelVisible:v,turnNumber:y}){return e.role===`user`?(0,E.jsx)(P5,{message:e,entryId:o,onFork:s,forking:c,onNavigate:l,prevAssistantEntryId:u,onEditContent:d,turnNumber:y}):e.role===`assistant`?(0,E.jsx)(F5,{message:e,isStreaming:t,toolResults:n,modelNames:r,cwd:i,onOpenFile:a,showTimestamp:f,turnStartTimestamp:p,sessionId:m,entryId:o,longBlockCollapseChars:g,recentExpandedBlockKeys:_,modelLabelVisible:v,turnNumber:y}):e.role===`toolResult`?null:e.role===`custom`?e.customType===`compaction`?(0,E.jsx)($5,{message:e}):(0,E.jsx)(n7,{message:e,cwd:i,onOpenFile:a}):e.role===`bashExecution`?(0,E.jsx)(d7,{message:e,sessionId:m,streamingOutput:h,longBlockCollapseChars:g}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&M5(e.message,e.toolResults,t.toolResults)&&e.modelNames===t.modelNames&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.entryId===t.entryId&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.showTimestamp===t.showTimestamp&&e.sessionId===t.sessionId&&e.streamingBashOutput===t.streamingBashOutput&&e.modelLabelVisible===t.modelLabelVisible&&e.longBlockCollapseChars===t.longBlockCollapseChars&&e.recentExpandedBlockKeys===t.recentExpandedBlockKeys);function P5({message:e,entryId:t,onFork:n,forking:r,onNavigate:i,prevAssistantEntryId:a,onEditContent:o,turnNumber:s}){let{t:c}=N(),[l,u]=(0,d.useState)(!1),[f,m]=(0,d.useState)(!1),h=typeof e.content==`string`?e.content:e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
482
482
|
`),g=typeof e.content==`string`?[]:e.content.filter(e=>e.type===`image`),_=j5(e.timestamp),v=!!t&&!!n,y=!!a&&!!i;return(0,E.jsxs)(`div`,{style:{marginBottom:16,display:`flex`,flexDirection:`column`,alignItems:`flex-end`},onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,maxWidth:`85%`},children:[s!==void 0&&(0,E.jsx)(iZ,{number:s}),(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0,position:`relative`,background:`var(--user-bg)`,border:`1px solid color-mix(in srgb, var(--accent) 20%, transparent)`,borderRadius:12,padding:`8px 12px`,fontSize:`var(--text-2xl)`,fontFamily:`var(--font-mono)`,lineHeight:1.6,color:`var(--text)`,wordBreak:`break-word`},children:[g.length>0&&(0,E.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`,marginBottom:h?8:0},children:g.map((e,t)=>{let n=a7(e);return(0,E.jsx)(`img`,{src:n,alt:``,style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:`contain`,display:`block`,border:`1px solid color-mix(in srgb, var(--accent) 15%, transparent)`}},t)})}),h&&(0,E.jsx)(`div`,{"data-testid":`user-message`,style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:h})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:6,marginTop:3},children:[(0,E.jsx)(`div`,{style:{display:`flex`,gap:3,opacity:+!!l,pointerEvents:l?`auto`:`none`,transition:`opacity 0.12s`},children:(0,E.jsxs)(`button`,{onClick:()=>{Ri(h).then(()=>{m(!0),setTimeout(()=>m(!1),1500)})},title:c(`i18n.copyMessage`),style:{display:`flex`,alignItems:`center`,gap:4,padding:`3px 8px`,height:22,background:`none`,border:`none`,borderRadius:5,color:f?`var(--accent)`:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:400,whiteSpace:`nowrap`,transition:`color 0.12s`,"--hover-color":`var(--accent)`},className:f?void 0:`hover-shift`,children:[f?(0,E.jsx)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`9`,y:`9`,width:p.lg,height:p.lg,rx:`2`,ry:`2`}),(0,E.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]}),c(f?`i18n.copied`:`i18n.copy`)]})}),(v||y)&&(0,E.jsxs)(`div`,{style:{display:`flex`,gap:3,opacity:l||r?1:0,pointerEvents:l||r?`auto`:`none`,transition:`opacity 0.12s`},children:[y&&(0,E.jsxs)(`button`,{onClick:()=>{i(a),o?.(h)},title:c(`i18n.editFromHereTitle`),style:{display:`flex`,alignItems:`center`,gap:4,padding:`3px 8px`,height:22,background:`none`,border:`none`,borderRadius:5,color:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:400,whiteSpace:`nowrap`,transition:`color 0.12s`,"--hover-color":`var(--accent)`},className:`hover-shift`,children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`polyline`,{points:`15 10 20 15 15 20`}),(0,E.jsx)(`path`,{d:`M4 4v7a4 4 0 0 0 4 4h12`})]}),c(`i18n.editFromHere`)]}),v&&(0,E.jsxs)(`button`,{onClick:()=>{n(t)},disabled:r,title:c(r?`i18n.creatingSession`:`i18n.newSessionTitle`),style:{display:`flex`,alignItems:`center`,gap:4,padding:`3px 8px`,height:22,background:`none`,border:`none`,borderRadius:5,color:r?`var(--accent)`:`var(--text-dim)`,cursor:r?`not-allowed`:`pointer`,fontSize:`var(--text-sm)`,fontWeight:400,whiteSpace:`nowrap`,transition:`color 0.12s`,"--hover-color":`var(--accent)`},className:r?void 0:`hover-shift`,children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),c(r?`i18n.creating`:`i18n.newSession`)]})]}),_&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`},children:_})]})]})}function F5({message:e,isStreaming:t,toolResults:n,modelNames:r,cwd:i,onOpenFile:a,showTimestamp:o,turnStartTimestamp:s,sessionId:c,entryId:l,longBlockCollapseChars:u,recentExpandedBlockKeys:f,modelLabelVisible:m=!0,turnNumber:h}){let{t:g}=N(),_=o?j5(e.timestamp):null,v=(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!OY(e,{isStreaming:t})),y=v.map(({block:e})=>e),b=AY(e,{isStreaming:t}),[x,S]=(0,d.useState)(!1),[C,w]=(0,d.useState)(!1),T=(0,d.useRef)(null),[D,O]=(0,d.useState)(null),k=(0,d.useRef)(v);(0,d.useEffect)(()=>{k.current=v});let A=(0,d.useRef)(new Map),[j,M]=(0,d.useState)(new Map),P=(0,d.useMemo)(()=>{if(!e.timestamp||!s)return;let t=Math.round((e.timestamp-s)/1e3);return t>0?t:void 0},[e.timestamp,s]),ee=(0,d.useMemo)(()=>{let t=new Map;if(!n||!e.timestamp)return t;for(let[r,i]of n)if(i.timestamp&&e.timestamp){let n=Math.round((i.timestamp-e.timestamp)/1e3);n>0&&t.set(r,n)}return t},[n,e.timestamp]),F=y.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
483
483
|
`);return(0,d.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{if(document.hidden)return;let e=k.current,t=e.map(({block:e})=>e),n=Date.now();e.forEach(({originalIndex:e})=>{A.current.has(e)||A.current.set(e,n)}),M(t=>{let r=!1,i=new Map(t);for(let t=0;t<e.length-1;t++){let a=e[t].originalIndex,o=e[t+1].originalIndex;if(!i.has(a)&&A.current.has(a)){let e=A.current.get(a),t=A.current.get(o)??n;i.set(a,Math.round((t-e)/1e3)),r=!0}}return r?i:t});let r=e[e.length-1];if(r&&r.block.type===`toolCall`){let e=A.current.get(r.originalIndex);e!==void 0&&M(t=>{let i=Math.round((n-e)/1e3);if(t.get(r.originalIndex)===i)return t;let a=new Map(t);return a.set(r.originalIndex,i),a})}let i=0;for(let e of t)e.type===`text`?i+=e.text?.length??0:e.type===`thinking`?i+=e.thinking?.length??0:e.type===`toolCall`&&(i+=JSON.stringify(e.input??{}).length);if(i===0)return;T.current===null&&(T.current=n);let a=(n-T.current)/1e3;a>.5&&O(i/4/a)},300);return()=>{clearInterval(e),T.current=null,O(null)}},[t,M,O,k,A,T]),y.length===0&&!t&&!b?null:(0,E.jsxs)(`div`,{style:{marginBottom:16},onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),children:[m&&(0,E.jsxs)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`,marginBottom:4,display:`flex`,alignItems:`center`,gap:6},children:[h!==void 0&&(0,E.jsx)(iZ,{number:h}),e.provider&&(0,E.jsx)(`span`,{children:r?.[`${e.provider}/${e.model}`]??r?.[e.model]??e.model}),t&&(()=>{let e=0;for(let t of y)t.type===`text`?e+=t.text?.length??0:t.type===`thinking`?e+=t.thinking?.length??0:t.type===`toolCall`&&(e+=JSON.stringify(t.input??{}).length);let t=Math.round(e/4);return(0,E.jsx)(E.Fragment,{children:t>0&&(0,E.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:4,color:`var(--text)`},title:g(`i18n.estimatedTokens`),children:[(0,E.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:2,fontSize:`var(--text-sm)`,fontWeight:400},children:[(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`line`,{x1:`5`,y1:`1.5`,x2:`5`,y2:`8.5`}),(0,E.jsx)(`polyline`,{points:`2 6 5 8.5 8 6`})]}),t]}),D!==null&&(0,E.jsxs)(`span`,{style:{marginLeft:6,padding:`1px 6px`,borderRadius:4,background:D>=50?`#53b3cb`:D>=30?`#9bc53d`:D>=15?`#f9c22e`:`#e01a4f`,color:`#fff`,fontSize:`var(--text-sm)`,fontWeight:400},children:[D.toFixed(1),` t/s`]})]})})})()]}),(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:v.map(({block:e,originalIndex:r})=>(0,E.jsx)(z5,{block:e,toolResults:n,isStreaming:t,streamingDuration:j.get(r),toolCallDurations:ee,cwd:i,onOpenFile:a,sessionId:c,entryId:l,blockIndex:r,longBlockCollapseChars:u,recentExpandedBlockKeys:f},`${l??`stream`}-${r}`))}),b&&(0,E.jsxs)(`div`,{role:`alert`,style:{marginTop:y.length>0?8:0,padding:`7px 10px`,border:`1px solid color-mix(in srgb, var(--status-error) 30%, transparent)`,borderRadius:6,background:`color-mix(in srgb, var(--status-error) 7%, transparent)`,color:`var(--status-error)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,lineHeight:1.5,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:[`Error: `,b]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:4},children:[e.usage&&!t&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:u7(e.usage)}),F&&!t&&(0,E.jsxs)(`button`,{onClick:()=>{Ri(F).then(()=>{w(!0),setTimeout(()=>w(!1),1500)})},title:g(`i18n.copyMessage`),style:{display:`flex`,alignItems:`center`,gap:4,padding:`3px 8px`,height:22,background:`none`,border:`none`,borderRadius:5,color:C?`var(--accent)`:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:400,whiteSpace:`nowrap`,opacity:+!!x,pointerEvents:x?`auto`:`none`,transition:`opacity 0.12s, color 0.12s`,"--hover-color":`var(--accent)`},className:C?void 0:`hover-shift`,children:[C?(0,E.jsx)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`9`,y:`9`,width:p.lg,height:p.lg,rx:`2`,ry:`2`}),(0,E.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]}),g(C?`i18n.copied`:`i18n.copy`)]}),_&&!t&&(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`,marginLeft:`auto`,fontVariantNumeric:`tabular-nums`},children:[_,P!==void 0&&(0,E.jsxs)(`span`,{children:[` `,`(`,g(`chat.turnDuration`,{duration:Wt(P)}),`)`]})]})]})]})}var I5=24;function L5({text:e}){let t=(0,d.useMemo)(()=>e.split(/\r?\n/),[e]);return typeof ResizeObserver>`u`||t.length<50&&e.length<5e3?(0,E.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`break-word`},children:e}):(0,E.jsx)(D5,{data:t,itemSize:I5,children:e=>(0,E.jsx)(`div`,{style:{minHeight:I5,lineHeight:`${I5}px`,whiteSpace:`pre-wrap`,overflowWrap:`break-word`},children:e})})}function R5({text:e,threshold:t,t:n,renderFull:r,isStreaming:i=!1,defaultExpanded:a=!1}){let[o,s]=(0,d.useState)(a),c=e.length;if(!(!i&&c>t))return r?(0,E.jsx)(E.Fragment,{children:r()}):i&&e.length>0?(0,E.jsx)(L5,{text:e}):(0,E.jsx)(E.Fragment,{children:e});let l=Math.max(1,Math.floor(t/2)),u=c-l*2,f=(0,E.jsx)(`button`,{type:`button`,"data-long-block-toggle":``,onClick:()=>s(e=>!e),"aria-expanded":o,style:{display:`block`,width:`100%`,margin:`6px 0`,padding:`3px 8px`,border:`1px dashed var(--border)`,borderRadius:6,background:`none`,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,cursor:`pointer`,textAlign:`center`},children:o?n(`longBlock.collapse`):n(`longBlock.expandHint`,{n:u})});return o?(0,E.jsxs)(E.Fragment,{children:[r?r():(0,E.jsx)(L5,{text:e}),f]}):(0,E.jsxs)(E.Fragment,{children:[e.slice(0,l),f,e.slice(c-l)]})}function z5({block:e,toolResults:t,isStreaming:n,streamingDuration:r,toolCallDurations:i,cwd:a,onOpenFile:o,sessionId:s,entryId:c,blockIndex:l,longBlockCollapseChars:u,recentExpandedBlockKeys:d}){let f=!n&&c!==void 0&&(e.type===`thinking`||e.type===`toolCall`)&&d?.has(_t(e.type,c,e.type===`toolCall`?e.toolCallId:void 0,e.type===`thinking`?l:void 0))===!0;if(e.type===`text`)return(0,E.jsx)(B5,{block:e,isStreaming:n,cwd:a,onOpenFile:o});if(e.type===`thinking`)return(0,E.jsx)(V5,{block:e,sessionId:s,entryId:c,blockIndex:l,isStreaming:n,keepExpanded:f,longBlockCollapseChars:u});if(e.type===`toolCall`){let a=e,o=t?.get(a.toolCallId),s=i?.get(a.toolCallId)??r;return(0,E.jsx)(U5,{block:a,result:o,duration:s,isStreaming:n,keepExpanded:f,longBlockCollapseChars:u})}return null}function B5({block:e,isStreaming:t,cwd:n,onOpenFile:r}){return(0,E.jsx)(U8,{isStreaming:t,cwd:n,onOpenFile:r,children:e.text})}function V5({block:e,sessionId:t,entryId:n,blockIndex:r,isStreaming:i=!1,keepExpanded:a=!1,longBlockCollapseChars:o=200}){let{t:s}=N(),[c,l]=(0,d.useState)(null),[u,f]=(0,d.useState)(!1),[m,h]=(0,d.useState)(null),g=(0,d.useRef)(!1),_=(0,d.useRef)(null);(0,d.useEffect)(()=>{e.deferred&&!g.current&&(g.current=!0,v())},[]);let v=async()=>{if(!(!e.deferred||c!==null)){if(!t||!n){h(s(`i18n.thinkingUnavailable`));return}f(!0),h(null);try{l(await A5(t,n,r))}catch(e){h(e instanceof Error?e.message:String(e))}finally{f(!1)}}},y=e.deferred?c:e.thinking,b=OZ(_,i,[y]);return(0,E.jsxs)(`div`,{style:{border:`1px solid var(--border)`,borderRadius:6,overflow:`hidden`,fontSize:`var(--text-base)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,padding:`6px 10px`,color:`var(--status-warning)`,fontSize:`var(--text-base)`,cursor:`default`},children:[(0,E.jsx)(ri,{size:p.base,fill:`currentColor`,style:{flexShrink:0,color:`var(--bulb-warning)`}}),(0,E.jsx)(`span`,{children:s(`i18n.thinking`)})]}),(0,E.jsx)(`div`,{ref:_,onScroll:b,style:{padding:`4px 10px 8px 28px`,borderTop:`1px solid var(--border)`,fontSize:`var(--text-lg)`,lineHeight:1.6,color:`var(--text-muted)`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`,fontFamily:`var(--font-mono)`,maxHeight:400,overflowY:`auto`,contentVisibility:`auto`,containIntrinsicBlockSize:400},children:u?(0,E.jsxs)(`span`,{style:{color:`var(--text-dim)`},children:[s(`i18n.loading`),`...`]}):m?(0,E.jsx)(`span`,{style:{color:`var(--status-error)`},children:m}):y?(0,E.jsx)(R5,{text:y,threshold:o,t:s,isStreaming:i,defaultExpanded:a}):DY(e)?(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`,fontStyle:`italic`},children:s(`i18n.thinkingEncrypted`)}):(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`},children:s(`i18n.noThinking`)})})]})}function H5({block:e,result:t,duration:n}){let{t:r}=N(),i=e.input??{},a=typeof i.question==`string`?i.question:null,o=Array.isArray(i.options)?i.options:[],s=t?t.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
@@ -488,13 +488,13 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
488
488
|
`)}if(e.role===`assistant`){let t=[];for(let n of e.content)n.type===`text`?t.push(n.text):n.type===`thinking`?t.push(n.thinking??``):n.type===`toolCall`&&t.push(`${n.toolName}(${JSON.stringify(n.input??{})})`);return t.join(`
|
|
489
489
|
`)}if(e.role===`toolResult`)return e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
490
490
|
`);if(e.role===`bashExecution`){let t=e;return`${t.command}\n${t.output??``}`}return``}var p7=100,m7=44;function h7({messages:e,t,onJump:n}){let[r,i]=(0,d.useState)(``),[a,o]=(0,d.useState)(0),s=(0,d.useRef)(null),c=(0,d.useRef)(null),l=(0,d.useMemo)(()=>e.map((e,t)=>({msgIdx:t,role:e.role,text:f7(e)})),[e]),u=(0,d.useMemo)(()=>{let e=r.trim().toLowerCase();if(!e)return[];let t=[];for(let{msgIdx:n,role:r,text:i}of l){let a=0,o=i.toLowerCase().indexOf(e,a);for(;o!==-1&&t.length<p7;)t.push({msgIdx:n,role:r,text:i,start:o}),a=o+1,o=i.toLowerCase().indexOf(e,a);if(t.length>=p7)break}return t},[l,r]);Wi(()=>o(e=>Math.min(e,Math.max(0,u.length-1))),[u.length]);let f=(0,d.useCallback)(e=>{let t=u[e];t&&(n(t.msgIdx),o(e))},[u,n]),m=(0,d.useCallback)(e=>{if(u.length!==0){if(e.key===`Enter`){e.preventDefault();let t=e.shiftKey?-1:1,n=(a+t+u.length)%u.length;f(n)}else e.key===`ArrowDown`?(e.preventDefault(),f(Math.min(a+1,u.length-1))):e.key===`ArrowUp`&&(e.preventDefault(),f(Math.max(a-1,0)))}},[a,f,u.length]);return(0,d.useEffect)(()=>{(c.current?.children[a])?.scrollIntoView({block:`nearest`})},[a]),(0,E.jsxs)(`div`,{style:{position:`relative`,flex:`1 1 0`,minWidth:0,maxWidth:2040},"data-testid":`search-box`,children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4,padding:`0 6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,height:30,boxSizing:`border-box`},children:[(0,E.jsx)(vi,{size:p.xl,color:`var(--text-muted)`,style:{flexShrink:0}}),(0,E.jsx)(`input`,{ref:s,value:r,onChange:e=>i(e.target.value),onKeyDown:m,placeholder:t(`chat.searchPlaceholder`),style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`var(--text)`,fontSize:`var(--text-sm)`}}),r&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{i(``),s.current?.focus()},"aria-label":t(`chat.clearSearch`),style:{border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0,padding:0},children:`✕`})]}),r.trim()&&(0,E.jsx)(`div`,{ref:c,style:{position:`absolute`,top:`calc(100% + 6px)`,left:0,right:0,maxHeight:`min(55vh, 480px)`,overflowY:`auto`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 8px 24px var(--shadow-color)`,zIndex:60},children:u.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 12px`,fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:t(`chat.searchNoResults`)}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{style:{padding:`6px 12px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,borderBottom:`1px solid var(--border)`},children:t(`chat.searchResults`,{count:u.length})}),u.map((e,t)=>{let n=r.trim(),i=Math.max(0,e.start-m7),o=Math.min(e.text.length,e.start+n.length+m7),s=i>0?`…`:``,c=o<e.text.length?`…`:``,l=`${s}${e.text.slice(i,o)}${c}`;return(0,E.jsxs)(`button`,{type:`button`,onClick:()=>f(t),"data-testid":`search-result`,style:{display:`block`,width:`100%`,textAlign:`left`,padding:`8px 12px`,border:`none`,borderBottom:`1px solid var(--border)`,background:t===a?`var(--bg-selected)`:`transparent`,color:`var(--text)`,cursor:`pointer`,fontSize:`var(--text-base)`,lineHeight:1.5},children:[(0,E.jsxs)(`span`,{style:{color:`var(--text-dim)`,marginRight:6,fontSize:`var(--text-sm)`},children:[`#`,e.msgIdx]}),(0,E.jsx)(`span`,{children:g7(l,n)})]},`${e.msgIdx}-${e.start}`)})]})})]})}function g7(e,t){let n=[],r=e,i=0;for(;r.length>0;){let e=r.toLowerCase().indexOf(t.toLowerCase());if(e===-1){n.push(r);break}e>0&&n.push(r.slice(0,e)),n.push((0,E.jsx)(`mark`,{children:r.slice(e,e+t.length)},i++)),r=r.slice(e+t.length)}return n}function _7({modelName:e,messageCount:t,toolCallCount:n,t:r}){let i=[`${t} ${r(t===1?`chat.message`:`chat.messages`)}`];return n>0&&i.push(`${n} ${r(n===1?`chat.toolCall`:`chat.toolCalls`)}`),(0,E.jsxs)(`div`,{"data-testid":`pd-group-header`,style:{display:`flex`,alignItems:`center`,gap:8,width:`auto`,minHeight:24,padding:`3px 10px`,border:`1px solid var(--border)`,borderRadius:8,background:`var(--bg-panel)`,color:`var(--text-muted)`,fontSize:`var(--text-base)`,lineHeight:1.6},children:[e&&(0,E.jsx)(`span`,{style:{fontWeight:700,color:`var(--text)`,whiteSpace:`nowrap`},children:e}),(0,E.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:i.join(` · `)})]})}function v7(e){let{rows:t,messages:n,entryIds:r,modelNames:i,messageCwd:a,onOpenFile:o,sessionBusy:s,isNew:c,handleFork:l,forkingEntryId:u,handleNavigate:f,handleEditContent:p,sessionId:m,longBlockCollapseChars:h,recentExpandedBlockKeys:g,isStreaming:_,flashKey:v,itemRef:y,t:b,messageRefs:x,lastUserMsgRef:S,visibleRefIndexByMessage:C,scrollContainerRef:w,virtualizerRef:T,initialCache:D}=e,O=(0,d.useRef)(!1);(0,d.useLayoutEffect)(()=>{if(O.current)return;O.current=!0;let e=w.current;e&&e.scrollHeight>e.clientHeight&&(e.scrollTop=e.scrollHeight)},[w]);let k=new Map;for(let e of n)e.role===`toolResult`&&k.set(e.toolCallId,e);let A=new Map;{let e=0;for(let t=0;t<n.length;t++)n[t].role===`user`?(e+=1,A.set(t,e)):n[t].role===`assistant`&&e>0&&A.set(t,e)}let j=-1;for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`){j=e;break}let M=(e,t)=>n=>{x.current[t]=n,e===j&&(S.current=n)},N=(e,t={})=>{let d=t.messageOverride??n[e],v=d.role===`user`&&e>0&&n[e-1].role===`assistant`?r[e-1]:void 0,y=d.role===`user`||d.role===`assistant`,b=C.get(e),x=!1;if(d.role===`assistant`){x=!0;for(let t=e+1;t<n.length;t++){let e=n[t].role;if(e===`user`)break;if(e===`assistant`){x=!1;break}}x&&_&&e===n.length-1&&(x=!1)}t.showTimestamp!==void 0&&(x=t.showTimestamp);let S;if(d.role===`assistant`){for(let t=e-1;t>=0;t--)if(n[t].role===`user`){S=n[t].timestamp;break}}let w=(0,E.jsx)(N5,{message:d,toolResults:k,modelNames:i,cwd:a,onOpenFile:o,entryId:r[e],onFork:s||c||e===0&&d.role===`user`?void 0:l,forking:u===r[e],onNavigate:s?void 0:f,prevAssistantEntryId:s?void 0:v,onEditContent:p,showTimestamp:x,turnStartTimestamp:S,sessionId:m,longBlockCollapseChars:h,recentExpandedBlockKeys:g,modelLabelVisible:t.modelLabelVisible,turnNumber:d.role===`user`||d.role===`assistant`&&t.isAnswer?A.get(e):void 0},`message-view-${e}`);return!y||t.attachRef===!1||b===void 0?w:(0,E.jsx)(`div`,{ref:M(e,b),children:w},`message-ref-${e}`)},P=e=>e.role!==`assistant`||!e.provider||!e.model?null:i?.[`${e.provider}/${e.model}`]??i?.[e.model]??e.model,ee=e=>{if(e.kind===`groupHeader`){let t=[];for(let r=e.groupUserIdx+1;r<=e.finalAssistantIdx;r++){let e=n[r];if(!e||e.role!==`assistant`)continue;let i=P(e);i&&!t.includes(i)&&t.push(i)}return(0,E.jsx)(_7,{modelName:t.join(` / `)||void 0,messageCount:e.messageCount,toolCallCount:e.toolCallCount,t:b})}return N(e.msgIdx,{attachRef:e.attachRef,messageOverride:e.messageOverride,showTimestamp:e.showTimestamp,modelLabelVisible:e.isProcess||e.isProcessFinal?!1:void 0,isAnswer:e.isAnswer})},F=e=>e.kind===`groupHeader`?8:e.isProcess||e.isProcessFinal?e.groupLast?14:8:0;return(0,E.jsx)(D5,{ref:T,data:t,cache:D,itemSize:200,bufferSize:400,scrollRef:w,children:e=>{let t=e.kind===`groupHeader`&&e.processRefIdx!==void 0?t=>{x.current[e.processRefIdx]=t}:void 0;return(0,E.jsx)(`div`,{className:v===e.key?`search-flash`:void 0,ref:y(e.key,t),style:{marginBottom:F(e)},children:ee(e)},e.key)}})}var y7={position:`relative`,display:`flex`,alignItems:`stretch`,flexShrink:0,width:`100%`,minWidth:0,height:36,gap:4,paddingLeft:4,paddingRight:4,borderBottom:`1px solid var(--border)`,background:`var(--bg)`},b7={display:`flex`,alignItems:`center`,justifyContent:`center`,alignSelf:`center`,width:32,height:32,padding:0,background:`transparent`,border:`1px solid var(--border)`,borderRadius:7,color:`var(--text-muted)`,flexShrink:0,cursor:`pointer`,transition:`color 0.12s, background 0.12s, border-color 0.12s`,"--hover-color":`var(--text)`,"--hover-bg":`var(--bg-selected)`,"--hover-border":`color-mix(in srgb, var(--accent) 35%, transparent)`},x7={display:`flex`,alignItems:`center`,gap:10,paddingLeft:12,paddingRight:12,height:`100%`,border:`none`,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,whiteSpace:`nowrap`,cursor:`pointer`,fontVariantNumeric:`tabular-nums`,transition:`color 0.1s, background 0.1s`,"--hover-color":`var(--text)`},S7={flexShrink:0};function C7(e){return e>=1e6?`${(e/1e6).toPrecision(3)}M`:e>=1e3?`${(e/1e3).toPrecision(3)}K`:String(e)}function w7({sessionStats:e,contextUsage:t,activeTopPanel:n,toggleTopPanel:r,isMobile:i,t:a,locale:o}){let s=e?.tokens,c=e?.cost??0,l=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),u=c>0?c>=.01?`$${c.toFixed(2)}`:`<$0.01`:null,d=`var(--text-muted)`,f=null;if(t?.contextWindow){let e=t.percent;e!==null&&e>90?d=`var(--status-error)`:e!==null&&e>70&&(d=`color-mix(in srgb, var(--status-warning) 95%, transparent)`),f=e===null?`? / ${l(t.contextWindow)}`:`${e.toFixed(0)}% / ${l(t.contextWindow)}`}let m=[];s&&(m.push(`in: ${s.input.toLocaleString(o)}`),m.push(`out: ${s.output.toLocaleString(o)}`),m.push(`cache read: ${s.cacheRead.toLocaleString(o)}`),m.push(`cache write: ${s.cacheWrite.toLocaleString(o)}`),c>0&&m.push(`cost: $${c.toFixed(4)}`));let h=s?s.input+s.cacheRead+s.cacheWrite:0,g=s&&h>0?s.cacheRead/h*100:null,_=(e,t)=>e===null?null:(0,E.jsx)(qi,{label:`${a(t)} · ${e.toFixed(1)}%`,children:(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`0 4px`,borderRadius:8,border:`1px solid color-mix(in srgb, var(--accent) 45%, transparent)`,background:`color-mix(in srgb, var(--accent) 10%, transparent)`,color:`var(--accent)`},children:[e.toFixed(1),`%`]})});if(t?.contextWindow){let e=t.percent;m.push(`context: ${e===null?`unknown`:`${e.toFixed(1)}%`} of ${t.contextWindow.toLocaleString()} tokens`)}let v=m.join(` | `);return(0,E.jsx)(qi,{label:v||a(`session.title`),wrapperStyle:{marginLeft:`auto`,flex:`0 0 auto`},children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>r(`session`),"aria-label":a(`session.title`),"aria-pressed":n===`session`,style:{...x7,background:n===`session`?`var(--bg-selected)`:`none`,borderTop:n===`session`?`2px solid var(--accent)`:`2px solid transparent`},className:`hover-shift`,children:[i&&(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12`,y2:`12`}),(0,E.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12.01`,y2:`8`})]}),!i&&s&&s.input>0&&(0,E.jsxs)(`span`,{style:T7,children:[(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:`var(--accent)`},children:[(0,E.jsx)(`line`,{x1:`5`,y1:`8.5`,x2:`5`,y2:`1.5`}),(0,E.jsx)(`polyline`,{points:`2 4 5 1.5 8 4`})]}),l(s.input)]}),!i&&s&&s.output>0&&(0,E.jsxs)(`span`,{style:T7,children:[(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:`var(--status-info)`},children:[(0,E.jsx)(`line`,{x1:`5`,y1:`1.5`,x2:`5`,y2:`8.5`}),(0,E.jsx)(`polyline`,{points:`2 6 5 8.5 8 6`})]}),l(s.output)]}),!i&&s&&s.cacheRead>0&&(0,E.jsxs)(`span`,{style:T7,children:[(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:`var(--status-success)`},children:[(0,E.jsx)(`path`,{d:`M8.5 5a3.5 3.5 0 1 1-1-2.45`}),(0,E.jsx)(`polyline`,{points:`6.5 1.5 8.5 2.5 7.5 4.5`})]}),l(s.cacheRead),_(g,`session.cacheReadRate`)]}),!i&&s&&s.cacheWrite>0&&(0,E.jsxs)(`span`,{style:T7,children:[(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:`var(--status-warning)`},children:[(0,E.jsx)(`path`,{d:`M8.5 5a3.5 3.5 0 1 0-1-2.45`}),(0,E.jsx)(`polyline`,{points:`2.5 1.5 4.5 2.5 3.5 4.5`})]}),l(s.cacheWrite)]}),!i&&u&&(0,E.jsx)(`span`,{style:E7,children:u}),f&&(0,E.jsxs)(`span`,{style:{...T7,color:d},children:[(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9`}),(0,E.jsx)(`line`,{x1:`1`,y1:`9`,x2:`9`,y2:`9`})]}),f]})]})})}var T7={display:`flex`,alignItems:`center`,gap:4},E7={display:`flex`,alignItems:`center`,color:`var(--text)`,fontWeight:500},D7={position:`absolute`,top:`100%`,left:0,right:0,zIndex:1500,background:`var(--bg)`,borderBottom:`1px solid var(--border)`,boxShadow:`0 10px 28px var(--shadow-color)`,maxHeight:`calc(100dvh - 80px)`,overflowY:`auto`},O7={padding:`10px 16px`,fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontStyle:`italic`},k7={fontSize:`var(--text-sm)`,fontWeight:700,color:`var(--text)`,marginBottom:6},A7={fontSize:`var(--text-xs)`,borderRadius:8,border:`1px solid color-mix(in srgb, var(--accent) 45%, transparent)`,background:`color-mix(in srgb, var(--accent) 10%, transparent)`,color:`var(--accent)`,whiteSpace:`nowrap`};function j7(e){let[t,n]=(0,d.useState)(null),r=(0,d.useRef)(null);return(0,d.useEffect)(()=>{if(!e){r.current=null,n(null);return}r.current===null&&(r.current=Date.now());let t=()=>{document.hidden||r.current!==null&&n(Wt((Date.now()-r.current)/1e3))};t();let i=setInterval(t,1e3),a=()=>{document.hidden||t()};return document.addEventListener(`visibilitychange`,a),()=>{clearInterval(i),document.removeEventListener(`visibilitychange`,a)}},[e]),t}function M7(e){if(e.role!==`user`)return null;if(typeof e.content==`string`){let t=e.content.trim();return t.length>0?t:null}let t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
491
|
-
`).trim();return t.length>0?t:null}function N7({session:e,newSessionCwd:t,onAgentEnd:n,onSessionCreated:r,onSessionForked:i,modelsRefreshKey:a,chatInputRef:o,onOpenModelConfig:s,onSessionRenamed:c,windowTitleBase:l,onOpenFile:u,toolbarExtra:f,closedWidgetKeys:m,onCloseWidget:h,onExtensionWidgetsChange:g,onExtensionDialogChange:_}){let{t:v,locale:y}=N(),{scrollStepPx:b,autoReloadSeconds:x,longBlockCollapseChars:S,recentBlocksExpanded:C,widgetGeometries:w,setWidgetGeometry:T,widgetMessages:D,startScreenMessages:O}=ze(),{soundEnabled:k,onSoundToggle:A,playDoneSound:j,unlockAudio:M}=nY(),P=ne(),ee=L(),F=(0,d.useRef)(j);(0,d.useEffect)(()=>{F.current=j});let I=(0,d.useRef)(k);(0,d.useEffect)(()=>{I.current=k});let te=(0,d.useRef)(null),re=(0,d.useCallback)(()=>{I.current&&F.current(),n?.()},[n]),ae=(0,d.useCallback)(e=>{o?.current?.insertIfEmpty(e)},[o]),R=(0,d.useCallback)(e=>{o?.current?.fillInput(e)},[o]),[oe,z]=(0,d.useState)({kind:`idle`}),se=pe(),ce=(0,d.useRef)(null),[le,ue]=(0,d.useState)(null),de=pe(),fe=(0,d.useRef)(null),me=(0,d.useRef)(null),{activeTopPanel:he,toggleTopPanel:ge,closeTopPanel:_e}=tt(),ve=pe(),ye=(0,d.useCallback)(()=>{ve.schedule(()=>{_e()},150)},[ve,_e]),be=ve.cancel;(0,d.useEffect)(()=>{se.cancel(),z({kind:`idle`}),ue(null),ce.current=e?.id??null},[e?.id,se]);let xe=(0,d.useCallback)(()=>{e&&window.open(`/api/sessions/${encodeURIComponent(e.id)}/export?inline=1`,`_blank`,`noopener,noreferrer`)},[e]),Se=(0,d.useCallback)((e,t)=>{Ri(t).then(()=>{de.cancel(),ue(e),de.schedule(()=>ue(null),1400)})},[de]),{loading:Ce,error:we,messages:Te,entryIds:Ee,streamState:De,agentRunning:Oe,bashRunning:ke,bashOutput:Ae,pendingBash:je,modelNames:Me,modelList:Ne,modelError:Pe,modelScopeWarnings:Fe,modelThinkingLevels:Ie,modelThinkingLevelMaps:Le,toolPreset:Re,thinkingLevel:Be,retryInfo:Ve,contextUsage:He,forkingEntryId:Ue,isCompacting:We,compactError:Ge,compactResult:Ke,displayModel:qe,sessionStats:Je,systemPrompt:Ye,slashCommands:Xe,slashCommandsLoading:Ze,queuedMessages:Qe,notices:$e,noticeModals:et,dismissNoticeModal:nt,extensionDialog:rt,extensionCustomUi:it,extensionStatuses:at,extensionWidgets:ot,respondToExtensionUi:st,sendExtensionCustomInput:ct,isAutoModelSelection:lt,agentPhase:ut,commandBusy:dt,isNew:ft,tree:pt,sessionIdRef:mt,activeLeafId:ht,loadContext:gt,messagesEndRef:vt,scrollContainerRef:yt,lastUserMsgRef:bt,handleSend:xt,handleAbort:St,handleFork:Ct,handleNavigate:wt,handleLeafChange:Tt,handleModelChange:Et,handleCompact:Dt,handleSteer:Ot,handleFollowUp:kt,handlePromptWithStreamingBehavior:At,handleAbortCompaction:jt,handleRecallQueue:Mt,handleBuiltinSlashCommand:Nt,handleToolPresetChange:Pt,handleThinkingLevelChange:Ft,loadSlashCommands:It,setSessionStatsOverride:Lt}=qJ({session:e,newSessionCwd:t,onAgentEnd:re,onSessionCreated:r,onSessionForked:i,modelsRefreshKey:a,chatInputRef:o});(0,d.useEffect)(()=>{g?.(ot)},[ot,g]);let Rt=Oe||ke,zt=(0,d.useCallback)(e=>{Rt?e.startsWith(`/`)?At(e,`steer`):Ot(e):xt(e)},[Rt,Ot,At,xt]),Bt=(0,d.useCallback)(async()=>{let t=e?.id;if(!(!t||oe.kind===`naming`)){se.cancel(),_e(),z({kind:`naming`});try{let e=await fetch(`/api/sessions/${encodeURIComponent(t)}/auto-name`,{method:`POST`}),n=await e.json().catch(()=>({}));if(!e.ok||!n.title)throw Error(n.error||`HTTP ${e.status}`);let r=n.title.trim();if(ce.current!==t)return;c?.(t,r),Lt(e=>e?.sessionId===t?{...e,sessionName:r}:e),z({kind:`success`}),se.schedule(()=>z({kind:`idle`}),1800)}catch(e){if(ce.current!==t)return;let n=e instanceof Error?e.message:String(e);z({kind:`error`,message:n}),se.schedule(()=>z({kind:`idle`}),5e3)}}},[oe.kind,se,e?.id,_e,c,Lt]),Vt=(0,d.useCallback)(async e=>{let t=await Nt(e);return t.handled&&t.action===`openSessionStats`&&ge(`session`),t},[Nt,ge]),Ht=(0,d.useMemo)(()=>{let e=De.streamingMessage;if(!e||e.role!==`assistant`)return;let t=0;for(let e of Te)e.role===`user`&&(t+=1);return t>0?t:void 0},[Te,De.streamingMessage]),Ut=(0,d.useMemo)(()=>{if(C==null)return;let e=[];Te.forEach((t,n)=>{t.role===`assistant`&&(t.content??[]).forEach((t,r)=>{t.type===`thinking`?e.push(_t(`thinking`,Ee[n]??``,void 0,r)):t.type===`toolCall`&&e.push(_t(`toolCall`,``,t.toolCallId))})});let t=e.slice(-((C??0)+1));return new Set(t)},[Te,Ee,C]),{runningSessionIds:Gt,runningPhaseSince:Kt,runningBusySince:qt}=Sn(),Jt=e?.id??mt.current??``,Yt=Gt.has(Jt)||Oe||dt||ke,Xt=j7(Yt),Zt=Cn(Yt,Kt[Jt]),Qt=Cn(Yt,qt[Jt]),$t=uY(SZ(at)),en=(0,d.useCallback)(()=>{let e=mt.current;e&>(e,ht,!0)},[ht,gt,mt]);(0,d.useEffect)(()=>{if(!x||x<=0)return;let e=setInterval(()=>{let e=mt.current;e&>(e,ht,!0)},x*1e3);return()=>clearInterval(e)},[x,ht,gt,mt]),(0,d.useEffect)(()=>{!rt||te.current===rt.id||(te.current=rt.id,Bq(`ui-chain`,`4b ExtensionDialog mounted, play sound`,`${rt.method} id=${rt.id.slice(0,8)} title=${JSON.stringify(rt.title)}`),F.current())},[rt]),(0,d.useEffect)(()=>{_?.(rt!==null)},[rt,_]),(0,d.useEffect)(()=>{On()},[]),(0,d.useEffect)(()=>{ie(Rt?St:null)},[Rt,St]);let tn=(0,d.useRef)(``);(0,d.useEffect)(()=>{let e=()=>{if(document.hasFocus())return;let e=De.isStreaming,t=l?` · ${l}`:``,n;if(rt)n=`❓`;else if(Rt){let t=Xt??``;if(ut?.kind===`running_tools`)n=`🔧 ${t}`.trimEnd();else if(ut?.kind===`running_command`)n=`💻 ${t}`.trimEnd();else if(ut?.kind===`thinking`)n=`💡 ${t}`.trimEnd();else if(ut?.kind===`waiting_model`&&e){let e=[...Te].reverse().find(e=>e.role===`assistant`),t=e&&e.role===`assistant`?e.usage:void 0;n=`⬇ ${C7(t?.input??0)}↑ ${C7(t?.output??0)}↓`}else n=`⏳ ${t}`.trimEnd()}else{let e;for(let t=Te.length-1;t>=0;t--){let n=Te[t];if(!(n.role!==`assistant`||!n.timestamp)){for(let r=t-1;r>=0;r--){let t=Te[r];if(t.role===`user`&&t.timestamp){let r=Math.round((n.timestamp-t.timestamp)/1e3);r>0&&(e=r);break}}break}}if(e===void 0)return;n=`✅ ${Wt(e)}`}let r=`${n}${t}`;r!==tn.current&&(tn.current=r,document.title=r)};e();let t=()=>{document.visibilityState===`hidden`&&e()};return document.addEventListener(`visibilitychange`,t),window.addEventListener(`blur`,e),()=>{document.removeEventListener(`visibilitychange`,t),window.removeEventListener(`blur`,e)}},[ut,De.isStreaming,Xt,Te,Rt,l,rt]);let nn=(0,d.useRef)(null);(0,d.useEffect)(()=>{Rt?nn.current===null&&(nn.current=Date.now()):nn.current=null},[Rt]),(0,d.useEffect)(()=>{if(!Rt&&!rt)return;let e=()=>{if(!document.hidden||document.hasFocus())return;let e=l?` · ${l}`:``,t;if(rt)t=`❓`;else if(Rt){let e=nn.current?Wt((Date.now()-nn.current)/1e3):Xt??``;if(ut?.kind===`running_tools`)t=`🔧 ${e}`.trimEnd();else if(ut?.kind===`running_command`)t=`💻 ${e}`.trimEnd();else if(ut?.kind===`thinking`)t=`💡 ${e}`.trimEnd();else if(ut?.kind===`waiting_model`&&De.isStreaming){let e=[...Te].reverse().find(e=>e.role===`assistant`),n=e&&e.role===`assistant`?e.usage:void 0;t=`⬇ ${C7(n?.input??0)}↑ ${C7(n?.output??0)}↓`}else t=`⏳ ${e}`.trimEnd()}else return;let n=`${t}${e}`;n!==tn.current&&(tn.current=n,document.title=n)},t=setInterval(e,1e3);return document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,e)}},[Rt,rt,ut,De.isStreaming,Te,l,Xt]);let[rn,an]=(0,d.useState)(null),[on,sn]=(0,d.useState)(!0),cn=(0,d.useRef)(new Map),ln=(0,d.useRef)(new Map),un=(0,d.useRef)(null),dn=(0,d.useRef)(!0),fn=(0,d.useRef)(0),pn=(0,d.useCallback)(e=>{let t=yt.current;t&&(t.scrollTop=e)},[yt]),mn=(0,d.useCallback)(()=>{let e=yt.current;e&&(e.scrollTop=e.scrollHeight),dn.current=!0,sn(!0)},[yt]),hn=(0,d.useCallback)(()=>{let e=yt.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;if(dn.current&&t>0&&e.scrollHeight!==fn.current){fn.current=e.scrollHeight,e.scrollTop=e.scrollHeight;return}t<16?(dn.current=!0,sn(!0)):t>64&&(dn.current=!1,sn(!1)),fn.current=e.scrollHeight},[yt]),gn=(0,d.useRef)(new Map),_n=(0,d.useCallback)((e,t)=>{gn.current.set(e,t);let n=ln.current.get(e);return n||(n=t=>{if(gn.current.get(e)?.(t),!t){cn.current.get(e)?.disconnect(),cn.current.delete(e),gn.current.delete(e);return}let n=cn.current.get(e);n?n.disconnect():(n=new ResizeObserver(()=>{document.hidden||dn.current&&requestAnimationFrame(()=>{if(document.hidden)return;let e=yt.current;e&&dn.current&&(e.scrollTop=e.scrollHeight)})}),cn.current.set(e,n)),n.observe(t)},ln.current.set(e,n)),n},[yt]);(0,d.useEffect)(()=>()=>{cn.current.forEach(e=>e.disconnect()),cn.current.clear(),ln.current.clear(),gn.current.clear()},[]);let vn=bZ(Te.filter(e=>e.role===`user`||e.role===`assistant`).length),[yn,bn]=(0,d.useState)(!1),xn=e?.id??t??``;(0,d.useEffect)(()=>{if(bn(!1),In.current=null,cn.current.forEach(e=>e.disconnect()),cn.current.clear(),ln.current.clear(),gn.current.clear(),vn.current=[],bt.current=null,yt.current){yt.current.scrollTop=0;let e=yt.current.firstElementChild;if(e&&e.children.length===1){let t=e.firstElementChild;t&&t.style.height&&(t.style.height=`0px`)}}},[xn]),(0,d.useEffect)(()=>{let e=yt.current;if(!e)return;let t=new ResizeObserver(()=>{document.hidden||dn.current&&requestAnimationFrame(()=>{if(document.hidden)return;let e=yt.current;e&&dn.current&&(e.scrollTop=e.scrollHeight)})});return t.observe(e),()=>t.disconnect()},[yt]),(0,d.useEffect)(()=>()=>{},[]);let{isDragOver:wn,handleDragEnter:Tn,handleDragOver:En,handleDragLeave:Dn,handleDrop:kn}=rY((0,d.useCallback)(e=>{Rt||o?.current?.addImages(e)},[Rt,o])),An=(0,d.useMemo)(()=>{let e=new Set,t=[];for(let n=Te.length-1;n>=0;--n){let r=M7(Te[n]);if(!(!r||e.has(r))&&(e.add(r),t.push(r),t.length>=50))break}return t.reverse()},[Te]),jn=(0,d.useMemo)(()=>{for(let e=Te.length-1;e>=0;e--)if(zY(Te[e]))return e;return-1},[Te]),Mn=(0,d.useMemo)(()=>{let e=new Map,t=0;return Te.forEach((n,r)=>{(n.role===`user`||n.role===`assistant`)&&e.set(r,t++)}),e},[Te]),Nn=(0,d.useMemo)(()=>VY(Te,{isLiveTail:(Rt||De.isStreaming)&&jn>=0,lastAnchorIdx:jn,visibleRefIndexByMessage:Mn}),[Te,Rt,De.isStreaming,jn,Mn]),Pn=(0,d.useMemo)(()=>HY(Nn),[Nn]),Fn=(0,d.useCallback)(e=>{let t=Pn.get(e);if(t===void 0)return null;let n=un.current;return n?n.getItemOffset(t):null},[Pn]),In=(0,d.useRef)(null),Ln=yn&&In.current?[In.current,200]:void 0;(0,d.useLayoutEffect)(()=>{yn||Nn.length!==0&&yt.current&&(In.current=Nn.map(e=>e.estimate),bn(!0))},[yn,Nn,yt]);let[Rn,zn]=(0,d.useState)(null),Bn=(0,d.useRef)(null),Vn=(0,d.useCallback)(e=>{let t=Pn.get(e);if(t===void 0)return;let n=un.current;if(!n)return;n.scrollToIndex(t,{align:`start`,offset:-24,smooth:!0});let r=Nn[t].key;zn(r),Bn.current&&clearTimeout(Bn.current),Bn.current=setTimeout(()=>{Bn.current=null,zn(e=>e===r?null:e)},1700)},[Nn,Pn]),Hn=ft&&Te.length===0&&!De.isStreaming&&!Rt,Un=!Oe&&!De.isStreaming&&!dt&&!ke;(0,d.useLayoutEffect)(()=>{if(!O.length||!Un||!dn.current)return;let e=yt.current;e&&(e.scrollTop=e.scrollHeight)},[O.length,Un,yt]);let Wn=e?.cwd??t??void 0,Gn=qe?Ie[`${qe.provider}/${qe.modelId}`]??null:null,Kn=qe?Le[`${qe.provider}/${qe.modelId}`]??null:null,qn=(0,E.jsx)(hX,{ref:o,onSend:xt,onAbort:St,onSteer:Oe?Ot:void 0,onFollowUp:Oe?kt:void 0,onPromptWithStreamingBehavior:Oe?At:void 0,isStreaming:Rt,commandBusy:dt,model:qe,isAutoModelSelection:lt,modelNames:Me,modelList:Ne,modelError:Pe,modelScopeWarnings:Fe,onModelChange:Et,onCompact:e||ft?Dt:void 0,onReloadFromDisk:en,onAbortCompaction:jt,isCompacting:We,compactError:Ge,compactResult:Ke,toolPreset:Re,onToolPresetChange:e||ft?Pt:void 0,thinkingLevel:Be,onThinkingLevelChange:e||ft?Ft:void 0,availableThinkingLevels:Gn,thinkingLevelMap:Kn,onOpenModelConfig:s,retryInfo:Ve,queuedMessages:Qe,inputHistory:An,onRecallQueue:Mt,slashCommands:Xe,slashCommandsLoading:Ze,onLoadSlashCommands:It,onBuiltinCommand:Vt,soundEnabled:k,onSoundToggle:A,onAudioUnlock:M,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t});return Ce?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-text-muted`,children:v(e?`chat.loadingSession`:`chat.noSessionSelected`)}):we?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-red-400`,children:we}):(0,E.jsxs)(`div`,{ref:an,className:`relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,style:{paddingBottom:`env(safe-area-inset-bottom)`},onDragEnter:Tn,onDragOver:En,onDragLeave:Dn,onDrop:kn,children:[wn&&!Rt&&(0,E.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[color-mix(in_srgb,var(--accent)_6%,transparent)] backdrop-blur-[1px]`,children:[(0,E.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center`,children:[0,.8,1.6].map(e=>(0,E.jsx)(`div`,{className:`absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[color-mix(in_srgb,var(--accent)_50%,transparent)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]`,style:{transformOrigin:`center`,animationDelay:`${e}s`}},e))}),(0,E.jsxs)(`svg`,{width:`280`,height:`280`,viewBox:`0 0 140 140`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`drop-shadow-[0_6px_18px_var(--accent-glow)]`,children:[(0,E.jsx)(`rect`,{x:`28`,y:`44`,width:`84`,height:`60`,rx:`8`,fill:`color-mix(in srgb, var(--accent) 8%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 50%, transparent)`,strokeWidth:`1.8`}),(0,E.jsx)(`path`,{d:`M36 100 L54 72 L68 88 L80 74 L104 100Z`,fill:`color-mix(in srgb, var(--accent) 16%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 40%, transparent)`,strokeWidth:`1.4`,strokeLinejoin:`round`}),(0,E.jsx)(`circle`,{cx:`96`,cy:`58`,r:`8`,fill:`color-mix(in srgb, var(--accent) 22%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 55%, transparent)`,strokeWidth:`1.6`}),(0,E.jsxs)(`g`,{stroke:`color-mix(in srgb, var(--accent) 45%, transparent)`,strokeWidth:`1.4`,strokeLinecap:`round`,children:[(0,E.jsx)(`line`,{x1:`96`,y1:`46`,x2:`96`,y2:`43`}),(0,E.jsx)(`line`,{x1:`96`,y1:`70`,x2:`96`,y2:`73`}),(0,E.jsx)(`line`,{x1:`84`,y1:`58`,x2:`81`,y2:`58`}),(0,E.jsx)(`line`,{x1:`108`,y1:`58`,x2:`111`,y2:`58`}),(0,E.jsx)(`line`,{x1:`87.5`,y1:`49.5`,x2:`85.4`,y2:`47.4`}),(0,E.jsx)(`line`,{x1:`104.5`,y1:`66.5`,x2:`106.6`,y2:`68.6`}),(0,E.jsx)(`line`,{x1:`104.5`,y1:`49.5`,x2:`106.6`,y2:`47.4`}),(0,E.jsx)(`line`,{x1:`87.5`,y1:`66.5`,x2:`85.4`,y2:`68.6`})]})]})]}),rt&&(0,E.jsx)(I7,{request:rt,onRespond:st}),et.length>0&&(0,E.jsx)(F7,{modals:et,onDismiss:nt}),it&&(0,E.jsx)(R7,{request:it,onInput:ct}),ot.filter(e=>!m.has(e.key)).map((e,t)=>(0,E.jsx)(z7,{widget:e,saved:w[e.key],messages:D[e.key]??[],defaultOffset:t%3==0?{dx:0,dy:0}:t%3==1?{dx:-80,dy:0}:{dx:80,dy:0},onCloseWidget:h,setWidgetGeometry:T,onSend:zt,fillChatInput:R,portalTarget:rn},e.key)),(0,E.jsxs)(`div`,{ref:fe,"data-testid":`chat-toolbar`,style:y7,children:[(0,E.jsx)(qi,{label:v(e?`history.full`:`history.unsaved`),children:(0,E.jsx)(`button`,{onClick:xe,disabled:!e,"aria-label":v(`history.full`),style:{...b7,color:e?`var(--text-muted)`:`var(--text-dim)`,cursor:e?`pointer`:`not-allowed`,opacity:e?1:.45},className:e?`hover-shift`:void 0,children:(0,E.jsx)(hi,{size:p.base,style:S7})})}),(()=>{let t=!!(e&&(Je?.userMessages??e.messageCount)>0),n=!e||!t||oe.kind===`naming`,r=oe.kind===`success`,i=oe.kind===`error`,a=oe.kind===`naming`?v(`title.generating`):v(r?`title.updated`:i?`title.failed`:`title.generate`),o=e?t?i?oe.message:v(`title.generateSession`):v(`title.noMessages`):v(`title.unsaved`);return(0,E.jsx)(qi,{label:o,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>void Bt(),disabled:n,"aria-label":a,style:{...b7,color:i?`var(--status-error)`:r?`var(--status-success)`:n?`var(--text-dim)`:`var(--text-muted)`,cursor:n?`not-allowed`:`pointer`,opacity:n&&oe.kind!==`naming`?.45:1,"--hover-color":i?`var(--status-error)`:`var(--text)`},className:n?void 0:`hover-shift`,children:oe.kind===`naming`?(0,E.jsx)(oi,{className:`animate-spin`,size:p.lg,"aria-hidden":`true`}):r?(0,E.jsx)(Rr,{size:p.lg,"aria-hidden":`true`}):(0,E.jsx)(li,{size:p.lg,"aria-hidden":`true`,style:S7})})})})(),(0,E.jsx)(qi,{label:v(`i18n.branches`),children:(0,E.jsx)(eZ,{tree:pt,activeLeafId:ht,onLeafChange:Tt,inline:!0,compact:!0,containerRef:fe,open:he===`branches`,onToggle:()=>ge(`branches`),hasSession:!0})}),(0,E.jsx)(qi,{label:v(`system.prompt`),children:(0,E.jsx)(`button`,{ref:me,onClick:()=>ge(`system`),"aria-label":v(`system.prompt`),"aria-pressed":he===`system`,style:{...b7,background:he===`system`?`var(--bg-selected)`:`transparent`,borderColor:he===`system`?`var(--accent)`:`var(--border)`,cursor:`pointer`,color:he===`system`?`var(--text)`:`var(--text-muted)`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsx)(Jr,{size:p.base,style:S7})})}),(0,E.jsx)(qi,{label:v(`session.reload`),children:(0,E.jsx)(`button`,{type:`button`,"data-testid":`chat-toolbar-reload`,onClick:()=>void Nt(`/reload`),"aria-label":v(`session.reload`),style:{...b7,background:`transparent`,borderColor:`var(--border)`,cursor:`pointer`,color:`var(--text-muted)`,"--hover-color":`var(--text)`},className:`hover-shift`,children:dt?(0,E.jsx)(oi,{className:`animate-spin`,size:p.base,style:S7}):(0,E.jsx)(mi,{size:p.base,style:S7})})}),(0,E.jsx)(`div`,{style:{marginLeft:8,display:`flex`,alignItems:`center`,flex:1,minWidth:0},children:(0,E.jsx)(h7,{messages:Te,t:v,onJump:Vn})}),Je||He?(0,E.jsx)(w7,{sessionStats:Je,contextUsage:He,activeTopPanel:he,toggleTopPanel:ge,isMobile:P,t:v,locale:y}):null,f,he===`system`&&(0,E.jsx)(`div`,{onMouseEnter:be,onMouseLeave:ye,style:D7,children:Ye?(0,E.jsx)(`div`,{style:{padding:`12px 16px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`,lineHeight:1.6,whiteSpace:`pre-wrap`,fontFamily:`var(--font-mono)`},children:Ye}):Ye===``?(0,E.jsx)(`div`,{style:O7,children:v(`system.empty`)}):(0,E.jsx)(`div`,{style:O7,children:v(`system.load`)})}),he===`session`&&(0,E.jsx)(`div`,{onMouseEnter:be,onMouseLeave:ye,style:{...D7,padding:`12px 16px`},children:Je?(()=>{let e=[...Je.sessionName?[{label:v(`session.name`),value:Je.sessionName,copyField:null}]:[],{label:v(`session.file`),value:Je.sessionFile??v(`session.inMemory`),copyField:`file`},{label:v(`session.id`),value:Je.sessionId,copyField:`id`}],t=[[v(`session.user`),Je.userMessages.toLocaleString(y)],[v(`session.assistant`),Je.assistantMessages.toLocaleString(y)],[v(`session.toolCalls`),Je.toolCalls.toLocaleString(y)],[v(`session.toolResults`),Je.toolResults.toLocaleString(y)],[v(`session.total`),Je.totalMessages.toLocaleString(y)]],n=Je.tokens.input+Je.tokens.cacheRead+Je.tokens.cacheWrite,r=[[v(`session.input`),Je.tokens.input.toLocaleString(y),{title:v(`session.inputHint`)}],[v(`session.output`),Je.tokens.output.toLocaleString(y),{title:v(`session.outputHint`)}],...Je.tokens.cacheRead>0?[[v(`session.cacheRead`),Je.tokens.cacheRead.toLocaleString(y),{title:v(`session.cacheReadHint`),badge:n>0?(e=>`${e.toFixed(1)}%`)(Je.tokens.cacheRead/n*100):void 0,badgeTitle:v(`session.cacheReadRate`)}]]:[],...Je.tokens.cacheWrite>0?[[v(`session.cacheWrite`),Je.tokens.cacheWrite.toLocaleString(y),{title:v(`session.cacheWriteHint`)}]]:[],[v(`session.total`),Je.tokens.total.toLocaleString(y),{title:v(`session.totalHint`)}]],i=He??Je.contextUsage,a=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=[...Je.cost>0?[[v(`session.cost`),`$${Je.cost.toFixed(4)}`]]:[],...i?.contextWindow?[[v(`session.context`),`${i.percent===null?`?`:`${i.percent.toFixed(1)}%`} / ${a(i.contextWindow)}`]]:[]],s=(e,t,n=`left`,r=!1)=>(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:k7,children:e}),(0,E.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:r?`max-content max-content max-content`:`auto minmax(0, 1fr) max-content`,columnGap:r?14:12,rowGap:4,justifyContent:r?`start`:void 0},children:t.map(([t,i,a])=>(0,E.jsxs)(`div`,{style:{display:`contents`},children:[(0,E.jsx)(qi,{label:a?.title,wrapperStyle:{display:`flex`,color:`var(--text-dim)`,whiteSpace:`nowrap`},children:(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`,whiteSpace:`nowrap`},children:t})}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,minWidth:0,overflowWrap:r?`normal`:`anywhere`,textAlign:n,whiteSpace:n===`right`?`nowrap`:`normal`},children:i}),(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`flex-end`,minWidth:0},children:a?.badge&&(0,E.jsx)(qi,{label:`${a.badgeTitle??``}${a.badgeTitle?` · `:``}${a.badge}`,children:(0,E.jsx)(`span`,{style:{padding:`0 5px`,...A7},children:a.badge})})})]},`${e}:${t}`))})]}),c=(e,t)=>{let n=le===e;return(0,E.jsx)(qi,{label:v(n?`session.copied`:e===`file`?`session.copyFile`:`session.copyId`),children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>Se(e,t),style:{alignSelf:`start`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:22,height:22,marginTop:-2,color:n?`var(--accent)`:`var(--text-dim)`,background:`transparent`,border:`1px solid var(--border)`,borderRadius:4,cursor:`pointer`,flex:`0 0 auto`,transition:`color 0.12s, border-color 0.12s, background 0.12s`,"--hover-color":`var(--accent)`,"--hover-border":`var(--accent)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:n?(0,E.jsx)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`rect`,{x:`9`,y:`9`,width:p.lg,height:p.lg,rx:`2`,ry:`2`}),(0,E.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})})})},l=(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:k7,children:v(`session.infoSection`)}),(0,E.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto minmax(0, 1fr) auto`,columnGap:12,rowGap:8,alignItems:`start`},children:e.map(e=>(0,E.jsxs)(`div`,{style:{display:`contents`},children:[(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`,whiteSpace:`nowrap`},children:e.label}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,minWidth:0,overflowWrap:`anywhere`,wordBreak:`break-word`,whiteSpace:`normal`},children:e.value}),(0,E.jsx)(`div`,{children:e.copyField?c(e.copyField,e.value):null})]},`session-info:${e.label}`))})]});return(0,E.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:P?`1fr`:`minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)`,gap:P?16:24,fontSize:`var(--text-base)`,lineHeight:1.5,fontFamily:`var(--font-mono)`},children:[l,s(v(`session.messages`),t),s(v(`session.tokens`),[...r,...o],`right`,!0)]})})():(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontStyle:`italic`},children:v(`session.load`)})})]}),Hn?(0,E.jsx)(`div`,{className:`relative flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8`,children:(0,E.jsxs)(`div`,{className:`w-full max-w-[820px]`,children:[(0,E.jsxs)(`div`,{className:`mb-3`,style:{textAlign:`center`,padding:`40px 0`},children:[ee==="default"?(0,E.jsxs)(`div`,{style:{marginBottom:20,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,lineHeight:1.6},children:[v(`notify.permission.bannerHintBefore`),` `,(0,E.jsxs)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--accent)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{display:`inline-block`,verticalAlign:-2},children:[(0,E.jsx)(`path`,{d:`M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`})]}),` `,v(`notify.permission.bannerHintAfter`)]}):null,(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,fontStyle:`italic`,color:`var(--accent)`},children:`Pi Web`}),t?(0,E.jsx)(`div`,{style:{marginTop:6,fontSize:`var(--text-3xl)`,color:`var(--text-muted)`,fontFamily:`var(--font-mono)`},children:t}):null]}),O.length>0&&(0,E.jsx)(`div`,{style:{marginBottom:28},children:(0,E.jsx)(eY,{messages:O,onSend:zt,onFillInput:R,testIdPrefix:`start-screen-msg`,wrapperTestId:`start-screen-messages`,center:!0})}),(0,E.jsx)(`div`,{style:{position:`absolute`,top:12,left:0,right:0,zIndex:40,padding:`0 16px`,pointerEvents:`none`},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`},children:(0,E.jsx)(P7,{notices:$e,floating:!0,align:`right`})})}),qn]})}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,E.jsx)(`div`,{style:{position:`absolute`,top:12,left:0,right:P?0:`calc(${bY} + 48px)`,zIndex:40,padding:`0 16px`,pointerEvents:`none`},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`},children:(0,E.jsx)(P7,{notices:$e,floating:!0,align:`right`})})}),(0,E.jsx)(`div`,{ref:yt,onScroll:hn,className:`min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [overflow-anchor:none]`,style:{paddingRight:48},"data-testid":`message-list`,children:(0,E.jsx)(`div`,{style:{minWidth:0,padding:`0 16px`},children:(0,E.jsxs)(`div`,{style:{width:`100%`,minWidth:0,maxWidth:820,margin:`0 auto`},children:[yn&&(0,E.jsx)(v7,{rows:Nn,messages:Te,entryIds:Ee,modelNames:Me,messageCwd:Wn,onOpenFile:u,sessionBusy:Rt,isNew:ft,handleFork:Ct,forkingEntryId:Ue,handleNavigate:wt,handleEditContent:ae,sessionId:e?.id??mt.current??void 0,longBlockCollapseChars:S,recentExpandedBlockKeys:Ut,isStreaming:De.isStreaming,flashKey:Rn,itemRef:_n,t:v,messageRefs:vn,lastUserMsgRef:bt,visibleRefIndexByMessage:Mn,scrollContainerRef:yt,virtualizerRef:un,initialCache:Ln},xn||`empty`),De.isStreaming&&De.streamingMessage&&(0,E.jsx)(`div`,{children:(0,E.jsx)(N5,{message:De.streamingMessage,isStreaming:!0,modelNames:Me,cwd:Wn,onOpenFile:u,longBlockCollapseChars:S,recentExpandedBlockKeys:Ut,turnNumber:Ht})}),(Oe||dt)&&(ut?.kind===`waiting_model`||ut?.kind===`thinking`||!De.streamingMessage)&&(ut||dt)&&(0,E.jsx)(`div`,{className:`py-2 text-[0.8125rem] text-text-muted`,children:(0,E.jsx)(QJ,{phase:ut??{kind:`running_command`},elapsed:Zt,totalElapsed:Qt})}),ke&&(0,E.jsx)(`div`,{className:`py-2 text-[0.8125rem] text-text-muted`,children:(0,E.jsx)(QJ,{phase:{kind:`running_command`},elapsed:Zt,totalElapsed:Qt})}),je&&(0,E.jsx)(N5,{message:{role:`bashExecution`,command:je.command,output:``,excludeFromContext:je.excludeFromContext},streamingBashOutput:Ae,sessionId:e?.id??mt.current??void 0,longBlockCollapseChars:S}),Oe&&(0,E.jsx)(`div`,{style:{height:48}}),(0,E.jsx)(`div`,{ref:vt})]})})}),!on&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{style:{position:`absolute`,left:0,right:0,bottom:0,height:30,background:`linear-gradient(to bottom, transparent, var(--bg))`,pointerEvents:`none`,zIndex:49}}),(0,E.jsx)(`button`,{type:`button`,onClick:mn,"aria-label":v(`chat.scrollToLatest`),"data-testid":`scroll-to-latest`,style:{position:`absolute`,bottom:0,left:`50%`,transform:`translateX(-50%)`,width:`min(100% / 3, 260px)`,zIndex:50,cursor:`pointer`,background:`transparent`,border:`none`,padding:0,height:30,display:`flex`,alignItems:`flex-end`,justifyContent:`center`},children:(0,E.jsx)(qi,{label:v(`chat.scrollToLatest`),children:(0,E.jsx)(`span`,{style:{position:`absolute`,bottom:4,left:`50%`,transform:`translateX(-50%)`,width:12,height:11,display:`flex`,alignItems:`flex-end`,justifyContent:`center`,cursor:`pointer`},children:(0,E.jsx)(`span`,{style:{position:`relative`,width:0,height:0,borderLeft:`6px solid transparent`,borderRight:`6px solid transparent`,borderTop:`7px solid var(--text-muted)`,pointerEvents:`none`}})})})})]}),P?null:(0,E.jsx)(yZ,{messages:Te,streamingMessage:De.streamingMessage,scrollContainer:yt,messageRefs:vn,resolveMessageOffset:Fn,scrollStepPx:b,onWindowJumpTo:pn})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`div`,{style:{padding:`0 16px`,paddingRight:P?16:64},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`}})}),O.length>0&&Un&&(0,E.jsx)(`div`,{style:{padding:`0 16px`,paddingRight:P?16:64},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`,paddingBottom:8},children:(0,E.jsx)(eY,{messages:O,onSend:zt,onFillInput:R,testIdPrefix:`start-screen-msg`,wrapperTestId:`start-screen-messages`})})}),qn]}),(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,flexShrink:0,minWidth:0,height:36,padding:`0 12px`,borderTop:`1px solid var(--border)`,gap:8},children:(0,E.jsx)(qi,{label:$t,wrapperStyle:{display:`flex`,flex:1,minWidth:0},children:(0,E.jsx)(`div`,{role:`status`,"aria-label":$t,style:{alignSelf:`stretch`,display:`flex`,alignItems:`center`,flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,color:`var(--text-dim)`},children:$t})})})]})]})}function P7({notices:e,floating:t=!1,align:n=`left`}){return e.length===0?null:(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:n===`right`?`flex-end`:`stretch`,marginBottom:t?0:10},children:e.map((n,r)=>{let i=n.type===`error`?`var(--status-error)`:n.type===`warning`?`var(--status-warning)`:n.type===`success`?`var(--status-success)`:`var(--accent)`;return(0,E.jsxs)(`div`,{className:`notice-shelf-item`,style:{display:`flex`,alignItems:`center`,gap:10,minHeight:60,marginBottom:r===e.length-1?0:6,borderRadius:14,border:`1px solid color-mix(in srgb, var(--border) 70%, transparent)`,background:`var(--bg)`,color:`var(--text-muted)`,width:`fit-content`,maxWidth:`min(100%, 620px)`,boxShadow:t?`0 1px 2px var(--shadow-color), 0 10px 28px -14px var(--shadow-color)`:`0 1px 2px var(--shadow-color), 0 8px 24px -12px var(--shadow-color)`,fontSize:`var(--text-4xl)`,lineHeight:1.45,transformOrigin:`top center`,animation:n.exiting?`notice-shelf-out 0.18s ease-in forwards`:`notice-shelf-in 0.18s ease-out both`,padding:`0 12px`},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:i,flexShrink:0}}),(0,E.jsx)(`span`,{style:{padding:`14px 0`,minWidth:0,maxWidth:`100%`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:n.message})]},n.id)})})}function F7({modals:e,onDismiss:t}){let{t:n}=N();return(0,E.jsx)(E.Fragment,{children:e.map((e,r)=>(0,E.jsx)(JX,{variant:e.type===`error`?`error`:`normal`,align:`center`,width:520,height:320,initialOffset:{dx:r%3*24,dy:r%3*24},title:e.type===`error`?n(`chat.notifyErrorTitle`):n(`chat.notifyWarningTitle`),footer:(0,E.jsx)(`button`,{onClick:()=>t(e.id),style:{padding:`6px 14px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,cursor:`pointer`},children:n(`chat.close`)}),children:(0,E.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`,fontSize:`var(--text-lg)`,lineHeight:1.6,color:`var(--text)`},children:e.message})},e.id))})}function I7({request:e,onRespond:t}){let{t:n}=N(),[r,i]=(0,d.useState)(e.method===`editor`?e.prefill??``:``),[a,o]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{i(e.method===`editor`?e.prefill??``:``),o(Date.now())},[e]),(0,d.useEffect)(()=>{if(!e.expiresAt)return;let t=setInterval(()=>{document.hidden||o(Date.now())},1e3),n=()=>{document.hidden||o(Date.now())};return document.addEventListener(`visibilitychange`,n),()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,n)}},[e.expiresAt]);let s=e.expiresAt?Math.max(0,Math.ceil((e.expiresAt-a)/1e3)):null;(0,d.useEffect)(()=>{s===0&&t(e,{cancelled:!0})},[s===0,e.id]);let c=()=>{e.method===`confirm`?t(e,{confirmed:!0}):t(e,{value:r})},l=e.method===`select`?n(`chat.extensionSelect`):e.method===`confirm`?n(`chat.extensionConfirm`):e.method===`editor`?n(`chat.extensionEditor`):n(`chat.extensionInput`);return(0,E.jsxs)(JX,{testId:`extension-dialog`,flashHeader:!0,title:(0,E.jsxs)(E.Fragment,{children:[l,s!==null&&(0,E.jsxs)(`span`,{style:{color:`var(--text-muted)`,marginLeft:6,fontVariantNumeric:`tabular-nums`},children:[`(`,s,`s)`]})]}),subtitle:n(`chat.extensionRequest`),maxWidth:Math.round(window.innerWidth*.6),footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{onClick:()=>t(e,{cancelled:!0}),style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,cursor:`pointer`},children:n(`chat.cancel`)}),e.method===`confirm`?(0,E.jsx)(`button`,{onClick:c,style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--accent)`,background:`var(--accent)`,color:`var(--on-accent)`,cursor:`pointer`},children:n(`chat.confirm`)}):e.method===`select`?null:(0,E.jsx)(`button`,{onClick:c,style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--accent)`,background:`var(--accent)`,color:`var(--on-accent)`,cursor:`pointer`},children:n(`chat.submit`)})]}),children:[(0,E.jsx)(`div`,{style:{marginBottom:12,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,fontSize:`var(--text-lg)`,lineHeight:1.6,whiteSpace:`pre-wrap`,maxHeight:360,overflowY:`auto`},children:e.title}),`Notification`in window&&Notification.permission===`denied`&&(0,E.jsx)(`div`,{style:{marginBottom:10,padding:`7px 10px`,borderRadius:7,border:`1px solid var(--border-warning, var(--border))`,background:`var(--bg-panel)`,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:n(`chat.questionNotificationDenied`)}),e.method===`confirm`&&(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,fontSize:`var(--text-lg)`,lineHeight:1.6,whiteSpace:`pre-wrap`},children:e.message}),e.method===`select`&&(0,E.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8},children:e.options.map(n=>(0,E.jsx)(`button`,{onClick:()=>t(e,{value:n}),style:{flex:`1 1 auto`,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-lg)`},children:n},n))}),e.method===`input`&&(0,E.jsx)(`input`,{autoFocus:!0,value:r,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&c(),n.key===`Escape`&&t(e,{cancelled:!0})},style:{width:`100%`,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text)`,outline:`none`,fontSize:`var(--text-2xl)`}}),e.method===`editor`&&(0,E.jsx)(`textarea`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Escape`&&t(e,{cancelled:!0}),(n.metaKey||n.ctrlKey)&&n.key===`Enter`&&c()},style:{width:`100%`,minHeight:220,padding:10,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,outline:`none`,resize:`vertical`,fontSize:`var(--text-2xl)`,lineHeight:1.55,fontFamily:`var(--font-mono)`}})]},e.id)}function L7(e,t){return yY(e).map((e,n)=>Object.keys(e.style).length>0?(0,E.jsx)(`span`,{style:e.style,children:e.text},`${t}-${n}`):e.text)}function R7({request:e,onInput:t}){let{t:n}=N(),r=(0,d.useRef)(null),i=(0,d.useRef)(!1),a=gY(e.lines);return(0,d.useEffect)(()=>{r.current?.focus()},[e.id]),(0,E.jsx)(`div`,{style:{position:`absolute`,inset:0,zIndex:95,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:20,background:`rgba(0,0,0,0.18)`},children:(0,E.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,onClick:e=>{e.target.closest(`button`)||r.current?.focus()},style:{position:`relative`,width:`min(920px, 100%)`,maxHeight:`min(760px, calc(100vh - 40px))`,border:`1px solid var(--border)`,borderRadius:8,background:`var(--bg)`,boxShadow:`0 20px 60px var(--shadow-strong)`,overflow:`hidden`,outline:`none`},children:[(0,E.jsx)(`textarea`,{ref:r,"aria-label":n(`chat.extensionInput`),autoCapitalize:`off`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,onKeyDown:n=>{if(i.current||n.nativeEvent.isComposing)return;let r=TY(n);r&&(n.preventDefault(),n.stopPropagation(),t(e,r))},onInput:n=>{if(i.current||n.nativeEvent.isComposing)return;let r=n.currentTarget.value;n.currentTarget.value=``,r&&t(e,r)},onCompositionStart:()=>{i.current=!0},onCompositionEnd:n=>{i.current=!1;let r=n.currentTarget;queueMicrotask(()=>{let n=r.value;r.value=``,n&&t(e,n)})},onPaste:n=>{n.preventDefault();let r=n.clipboardData.getData(`text`);r&&t(e,EY(r))},style:{position:`absolute`,width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:`none`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,padding:`10px 12px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`div`,{style:{color:`var(--text)`,fontSize:`var(--text-lg)`,fontWeight:650},children:n(`chat.extensionPanel`)}),(0,E.jsx)(`button`,{onClick:()=>t(e,``),style:{padding:`5px 9px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`},children:n(`chat.close`)})]}),(0,E.jsx)(`pre`,{style:{margin:0,padding:14,maxHeight:`calc(min(760px, 100vh - 40px) - 48px)`,overflow:`auto`,background:`var(--bg-panel)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,lineHeight:1.45,whiteSpace:`pre`},children:(a.length?a:[``]).map((e,t,n)=>(0,E.jsxs)(d.Fragment,{children:[L7(e,`line-${t}`),t<n.length-1?`
|
|
491
|
+
`).trim();return t.length>0?t:null}function N7({session:e,newSessionCwd:t,onAgentEnd:n,onSessionCreated:r,onSessionForked:i,modelsRefreshKey:a,chatInputRef:o,onOpenModelConfig:s,onSessionRenamed:c,windowTitleBase:l,onOpenFile:u,toolbarExtra:f,closedWidgetKeys:m,onCloseWidget:h,onExtensionWidgetsChange:g,onExtensionDialogChange:_}){let{t:v,locale:y}=N(),{scrollStepPx:b,autoReloadSeconds:x,longBlockCollapseChars:S,recentBlocksExpanded:C,widgetGeometries:w,setWidgetGeometry:T,widgetMessages:D,startScreenMessages:O}=ze(),{soundEnabled:k,onSoundToggle:A,playDoneSound:j,unlockAudio:M}=vY(),P=ne(),ee=L(),F=(0,d.useRef)(j);(0,d.useEffect)(()=>{F.current=j});let I=(0,d.useRef)(k);(0,d.useEffect)(()=>{I.current=k});let te=(0,d.useRef)(null),re=(0,d.useCallback)(()=>{I.current&&F.current(),n?.()},[n]),ae=(0,d.useCallback)(e=>{o?.current?.insertIfEmpty(e)},[o]),R=(0,d.useCallback)(e=>{o?.current?.fillInput(e)},[o]),[oe,z]=(0,d.useState)({kind:`idle`}),se=pe(),ce=(0,d.useRef)(null),[le,ue]=(0,d.useState)(null),de=pe(),fe=(0,d.useRef)(null),me=(0,d.useRef)(null),{activeTopPanel:he,toggleTopPanel:ge,closeTopPanel:_e}=tt(),ve=pe(),ye=(0,d.useCallback)(()=>{ve.schedule(()=>{_e()},150)},[ve,_e]),be=ve.cancel;(0,d.useEffect)(()=>{se.cancel(),z({kind:`idle`}),ue(null),ce.current=e?.id??null},[e?.id,se]);let xe=(0,d.useCallback)(()=>{e&&window.open(`/api/sessions/${encodeURIComponent(e.id)}/export?inline=1`,`_blank`,`noopener,noreferrer`)},[e]),Se=(0,d.useCallback)((e,t)=>{Ri(t).then(()=>{de.cancel(),ue(e),de.schedule(()=>ue(null),1400)})},[de]),{loading:Ce,error:we,messages:Te,entryIds:Ee,streamState:De,agentRunning:Oe,bashRunning:ke,bashOutput:Ae,pendingBash:je,modelNames:Me,modelList:Ne,modelError:Pe,modelScopeWarnings:Fe,modelThinkingLevels:Ie,modelThinkingLevelMaps:Le,toolPreset:Re,thinkingLevel:Be,retryInfo:Ve,contextUsage:He,forkingEntryId:Ue,isCompacting:We,compactError:Ge,compactResult:Ke,displayModel:qe,sessionStats:Je,systemPrompt:Ye,slashCommands:Xe,slashCommandsLoading:Ze,queuedMessages:Qe,notices:$e,noticeModals:et,dismissNoticeModal:nt,extensionDialog:rt,extensionCustomUi:it,extensionStatuses:at,extensionWidgets:ot,respondToExtensionUi:st,sendExtensionCustomInput:ct,isAutoModelSelection:lt,agentPhase:ut,commandBusy:dt,isNew:ft,tree:pt,sessionIdRef:mt,activeLeafId:ht,loadContext:gt,messagesEndRef:vt,scrollContainerRef:yt,lastUserMsgRef:bt,handleSend:xt,handleAbort:St,handleFork:Ct,handleNavigate:wt,handleLeafChange:Tt,handleModelChange:Et,handleCompact:Dt,handleSteer:Ot,handleFollowUp:kt,handlePromptWithStreamingBehavior:At,handleAbortCompaction:jt,handleRecallQueue:Mt,handleBuiltinSlashCommand:Nt,handleToolPresetChange:Pt,handleThinkingLevelChange:Ft,loadSlashCommands:It,setSessionStatsOverride:Lt}=lY({session:e,newSessionCwd:t,onAgentEnd:re,onSessionCreated:r,onSessionForked:i,modelsRefreshKey:a,chatInputRef:o});(0,d.useEffect)(()=>{g?.(ot)},[ot,g]);let Rt=Oe||ke,zt=(0,d.useCallback)(e=>{Rt?e.startsWith(`/`)?At(e,`steer`):Ot(e):xt(e)},[Rt,Ot,At,xt]),Bt=(0,d.useCallback)(async()=>{let t=e?.id;if(!(!t||oe.kind===`naming`)){se.cancel(),_e(),z({kind:`naming`});try{let e=await fetch(`/api/sessions/${encodeURIComponent(t)}/auto-name`,{method:`POST`}),n=await e.json().catch(()=>({}));if(!e.ok||!n.title)throw Error(n.error||`HTTP ${e.status}`);let r=n.title.trim();if(ce.current!==t)return;c?.(t,r),Lt(e=>e?.sessionId===t?{...e,sessionName:r}:e),z({kind:`success`}),se.schedule(()=>z({kind:`idle`}),1800)}catch(e){if(ce.current!==t)return;let n=e instanceof Error?e.message:String(e);z({kind:`error`,message:n}),se.schedule(()=>z({kind:`idle`}),5e3)}}},[oe.kind,se,e?.id,_e,c,Lt]),Vt=(0,d.useCallback)(async e=>{let t=await Nt(e);return t.handled&&t.action===`openSessionStats`&&ge(`session`),t},[Nt,ge]),Ht=(0,d.useMemo)(()=>{let e=De.streamingMessage;if(!e||e.role!==`assistant`)return;let t=0;for(let e of Te)e.role===`user`&&(t+=1);return t>0?t:void 0},[Te,De.streamingMessage]),Ut=(0,d.useMemo)(()=>{if(C==null)return;let e=[];Te.forEach((t,n)=>{t.role===`assistant`&&(t.content??[]).forEach((t,r)=>{t.type===`thinking`?e.push(_t(`thinking`,Ee[n]??``,void 0,r)):t.type===`toolCall`&&e.push(_t(`toolCall`,``,t.toolCallId))})});let t=e.slice(-((C??0)+1));return new Set(t)},[Te,Ee,C]),{runningSessionIds:Gt,runningPhaseSince:Kt,runningBusySince:qt}=Sn(),Jt=e?.id??mt.current??``,Yt=Gt.has(Jt)||Oe||dt||ke,Xt=j7(Yt),Zt=Cn(Yt,Kt[Jt]),Qt=Cn(Yt,qt[Jt]),$t=Jq(SZ(at)),en=(0,d.useCallback)(()=>{let e=mt.current;e&>(e,ht,!0)},[ht,gt,mt]);(0,d.useEffect)(()=>{if(!x||x<=0)return;let e=setInterval(()=>{let e=mt.current;e&>(e,ht,!0)},x*1e3);return()=>clearInterval(e)},[x,ht,gt,mt]),(0,d.useEffect)(()=>{!rt||te.current===rt.id||(te.current=rt.id,Bq(`ui-chain`,`4b ExtensionDialog mounted, play sound`,`${rt.method} id=${rt.id.slice(0,8)} title=${JSON.stringify(rt.title)}`),F.current())},[rt]),(0,d.useEffect)(()=>{_?.(rt!==null)},[rt,_]),(0,d.useEffect)(()=>{On()},[]),(0,d.useEffect)(()=>{ie(Rt?St:null)},[Rt,St]);let tn=(0,d.useRef)(``);(0,d.useEffect)(()=>{let e=()=>{if(document.hasFocus())return;let e=De.isStreaming,t=l?` · ${l}`:``,n;if(rt)n=`❓`;else if(Rt){let t=Xt??``;if(ut?.kind===`running_tools`)n=`🔧 ${t}`.trimEnd();else if(ut?.kind===`running_command`)n=`💻 ${t}`.trimEnd();else if(ut?.kind===`thinking`)n=`💡 ${t}`.trimEnd();else if(ut?.kind===`waiting_model`&&e){let e=[...Te].reverse().find(e=>e.role===`assistant`),t=e&&e.role===`assistant`?e.usage:void 0;n=`⬇ ${C7(t?.input??0)}↑ ${C7(t?.output??0)}↓`}else n=`⏳ ${t}`.trimEnd()}else{let e;for(let t=Te.length-1;t>=0;t--){let n=Te[t];if(!(n.role!==`assistant`||!n.timestamp)){for(let r=t-1;r>=0;r--){let t=Te[r];if(t.role===`user`&&t.timestamp){let r=Math.round((n.timestamp-t.timestamp)/1e3);r>0&&(e=r);break}}break}}if(e===void 0)return;n=`✅ ${Wt(e)}`}let r=`${n}${t}`;r!==tn.current&&(tn.current=r,document.title=r)};e();let t=()=>{document.visibilityState===`hidden`&&e()};return document.addEventListener(`visibilitychange`,t),window.addEventListener(`blur`,e),()=>{document.removeEventListener(`visibilitychange`,t),window.removeEventListener(`blur`,e)}},[ut,De.isStreaming,Xt,Te,Rt,l,rt]);let nn=(0,d.useRef)(null);(0,d.useEffect)(()=>{Rt?nn.current===null&&(nn.current=Date.now()):nn.current=null},[Rt]),(0,d.useEffect)(()=>{if(!Rt&&!rt)return;let e=()=>{if(!document.hidden||document.hasFocus())return;let e=l?` · ${l}`:``,t;if(rt)t=`❓`;else if(Rt){let e=nn.current?Wt((Date.now()-nn.current)/1e3):Xt??``;if(ut?.kind===`running_tools`)t=`🔧 ${e}`.trimEnd();else if(ut?.kind===`running_command`)t=`💻 ${e}`.trimEnd();else if(ut?.kind===`thinking`)t=`💡 ${e}`.trimEnd();else if(ut?.kind===`waiting_model`&&De.isStreaming){let e=[...Te].reverse().find(e=>e.role===`assistant`),n=e&&e.role===`assistant`?e.usage:void 0;t=`⬇ ${C7(n?.input??0)}↑ ${C7(n?.output??0)}↓`}else t=`⏳ ${e}`.trimEnd()}else return;let n=`${t}${e}`;n!==tn.current&&(tn.current=n,document.title=n)},t=setInterval(e,1e3);return document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,e)}},[Rt,rt,ut,De.isStreaming,Te,l,Xt]);let[rn,an]=(0,d.useState)(null),[on,sn]=(0,d.useState)(!0),cn=(0,d.useRef)(new Map),ln=(0,d.useRef)(new Map),un=(0,d.useRef)(null),dn=(0,d.useRef)(!0),fn=(0,d.useRef)(0),pn=(0,d.useCallback)(e=>{let t=yt.current;t&&(t.scrollTop=e)},[yt]),mn=(0,d.useCallback)(()=>{let e=yt.current;e&&(e.scrollTop=e.scrollHeight),dn.current=!0,sn(!0)},[yt]),hn=(0,d.useCallback)(()=>{let e=yt.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;if(dn.current&&t>0&&e.scrollHeight!==fn.current){fn.current=e.scrollHeight,e.scrollTop=e.scrollHeight;return}t<16?(dn.current=!0,sn(!0)):t>64&&(dn.current=!1,sn(!1)),fn.current=e.scrollHeight},[yt]),gn=(0,d.useRef)(new Map),_n=(0,d.useCallback)((e,t)=>{gn.current.set(e,t);let n=ln.current.get(e);return n||(n=t=>{if(gn.current.get(e)?.(t),!t){cn.current.get(e)?.disconnect(),cn.current.delete(e),gn.current.delete(e);return}let n=cn.current.get(e);n?n.disconnect():(n=new ResizeObserver(()=>{document.hidden||dn.current&&requestAnimationFrame(()=>{if(document.hidden)return;let e=yt.current;e&&dn.current&&(e.scrollTop=e.scrollHeight)})}),cn.current.set(e,n)),n.observe(t)},ln.current.set(e,n)),n},[yt]);(0,d.useEffect)(()=>()=>{cn.current.forEach(e=>e.disconnect()),cn.current.clear(),ln.current.clear(),gn.current.clear()},[]);let vn=bZ(Te.filter(e=>e.role===`user`||e.role===`assistant`).length),[yn,bn]=(0,d.useState)(!1),xn=e?.id??t??``;(0,d.useEffect)(()=>{if(bn(!1),In.current=null,cn.current.forEach(e=>e.disconnect()),cn.current.clear(),ln.current.clear(),gn.current.clear(),vn.current=[],bt.current=null,yt.current){yt.current.scrollTop=0;let e=yt.current.firstElementChild;if(e&&e.children.length===1){let t=e.firstElementChild;t&&t.style.height&&(t.style.height=`0px`)}}},[xn]),(0,d.useEffect)(()=>{let e=yt.current;if(!e)return;let t=new ResizeObserver(()=>{document.hidden||dn.current&&requestAnimationFrame(()=>{if(document.hidden)return;let e=yt.current;e&&dn.current&&(e.scrollTop=e.scrollHeight)})});return t.observe(e),()=>t.disconnect()},[yt]),(0,d.useEffect)(()=>()=>{},[]);let{isDragOver:wn,handleDragEnter:Tn,handleDragOver:En,handleDragLeave:Dn,handleDrop:kn}=yY((0,d.useCallback)(e=>{Rt||o?.current?.addImages(e)},[Rt,o])),An=(0,d.useMemo)(()=>{let e=new Set,t=[];for(let n=Te.length-1;n>=0;--n){let r=M7(Te[n]);if(!(!r||e.has(r))&&(e.add(r),t.push(r),t.length>=50))break}return t.reverse()},[Te]),jn=(0,d.useMemo)(()=>{for(let e=Te.length-1;e>=0;e--)if(zY(Te[e]))return e;return-1},[Te]),Mn=(0,d.useMemo)(()=>{let e=new Map,t=0;return Te.forEach((n,r)=>{(n.role===`user`||n.role===`assistant`)&&e.set(r,t++)}),e},[Te]),Nn=(0,d.useMemo)(()=>VY(Te,{isLiveTail:(Rt||De.isStreaming)&&jn>=0,lastAnchorIdx:jn,visibleRefIndexByMessage:Mn}),[Te,Rt,De.isStreaming,jn,Mn]),Pn=(0,d.useMemo)(()=>HY(Nn),[Nn]),Fn=(0,d.useCallback)(e=>{let t=Pn.get(e);if(t===void 0)return null;let n=un.current;return n?n.getItemOffset(t):null},[Pn]),In=(0,d.useRef)(null),Ln=yn&&In.current?[In.current,200]:void 0;(0,d.useLayoutEffect)(()=>{yn||Nn.length!==0&&yt.current&&(In.current=Nn.map(e=>e.estimate),bn(!0))},[yn,Nn,yt]);let[Rn,zn]=(0,d.useState)(null),Bn=(0,d.useRef)(null),Vn=(0,d.useCallback)(e=>{let t=Pn.get(e);if(t===void 0)return;let n=un.current;if(!n)return;n.scrollToIndex(t,{align:`start`,offset:-24,smooth:!0});let r=Nn[t].key;zn(r),Bn.current&&clearTimeout(Bn.current),Bn.current=setTimeout(()=>{Bn.current=null,zn(e=>e===r?null:e)},1700)},[Nn,Pn]),Hn=ft&&Te.length===0&&!De.isStreaming&&!Rt,Un=!Oe&&!De.isStreaming&&!dt&&!ke;(0,d.useLayoutEffect)(()=>{if(!O.length||!Un||!dn.current)return;let e=yt.current;e&&(e.scrollTop=e.scrollHeight)},[O.length,Un,yt]);let Wn=e?.cwd??t??void 0,Gn=qe?Ie[`${qe.provider}/${qe.modelId}`]??null:null,Kn=qe?Le[`${qe.provider}/${qe.modelId}`]??null:null,qn=(0,E.jsx)(hX,{ref:o,onSend:xt,onAbort:St,onSteer:Oe?Ot:void 0,onFollowUp:Oe?kt:void 0,onPromptWithStreamingBehavior:Oe?At:void 0,isStreaming:Rt,commandBusy:dt,model:qe,isAutoModelSelection:lt,modelNames:Me,modelList:Ne,modelError:Pe,modelScopeWarnings:Fe,onModelChange:Et,onCompact:e||ft?Dt:void 0,onReloadFromDisk:en,onAbortCompaction:jt,isCompacting:We,compactError:Ge,compactResult:Ke,toolPreset:Re,onToolPresetChange:e||ft?Pt:void 0,thinkingLevel:Be,onThinkingLevelChange:e||ft?Ft:void 0,availableThinkingLevels:Gn,thinkingLevelMap:Kn,onOpenModelConfig:s,retryInfo:Ve,queuedMessages:Qe,inputHistory:An,onRecallQueue:Mt,slashCommands:Xe,slashCommandsLoading:Ze,onLoadSlashCommands:It,onBuiltinCommand:Vt,soundEnabled:k,onSoundToggle:A,onAudioUnlock:M,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t});return Ce?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-text-muted`,children:v(e?`chat.loadingSession`:`chat.noSessionSelected`)}):we?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-red-400`,children:we}):(0,E.jsxs)(`div`,{ref:an,className:`relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,style:{paddingBottom:`env(safe-area-inset-bottom)`},onDragEnter:Tn,onDragOver:En,onDragLeave:Dn,onDrop:kn,children:[wn&&!Rt&&(0,E.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[color-mix(in_srgb,var(--accent)_6%,transparent)] backdrop-blur-[1px]`,children:[(0,E.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center`,children:[0,.8,1.6].map(e=>(0,E.jsx)(`div`,{className:`absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[color-mix(in_srgb,var(--accent)_50%,transparent)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]`,style:{transformOrigin:`center`,animationDelay:`${e}s`}},e))}),(0,E.jsxs)(`svg`,{width:`280`,height:`280`,viewBox:`0 0 140 140`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`drop-shadow-[0_6px_18px_var(--accent-glow)]`,children:[(0,E.jsx)(`rect`,{x:`28`,y:`44`,width:`84`,height:`60`,rx:`8`,fill:`color-mix(in srgb, var(--accent) 8%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 50%, transparent)`,strokeWidth:`1.8`}),(0,E.jsx)(`path`,{d:`M36 100 L54 72 L68 88 L80 74 L104 100Z`,fill:`color-mix(in srgb, var(--accent) 16%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 40%, transparent)`,strokeWidth:`1.4`,strokeLinejoin:`round`}),(0,E.jsx)(`circle`,{cx:`96`,cy:`58`,r:`8`,fill:`color-mix(in srgb, var(--accent) 22%, transparent)`,stroke:`color-mix(in srgb, var(--accent) 55%, transparent)`,strokeWidth:`1.6`}),(0,E.jsxs)(`g`,{stroke:`color-mix(in srgb, var(--accent) 45%, transparent)`,strokeWidth:`1.4`,strokeLinecap:`round`,children:[(0,E.jsx)(`line`,{x1:`96`,y1:`46`,x2:`96`,y2:`43`}),(0,E.jsx)(`line`,{x1:`96`,y1:`70`,x2:`96`,y2:`73`}),(0,E.jsx)(`line`,{x1:`84`,y1:`58`,x2:`81`,y2:`58`}),(0,E.jsx)(`line`,{x1:`108`,y1:`58`,x2:`111`,y2:`58`}),(0,E.jsx)(`line`,{x1:`87.5`,y1:`49.5`,x2:`85.4`,y2:`47.4`}),(0,E.jsx)(`line`,{x1:`104.5`,y1:`66.5`,x2:`106.6`,y2:`68.6`}),(0,E.jsx)(`line`,{x1:`104.5`,y1:`49.5`,x2:`106.6`,y2:`47.4`}),(0,E.jsx)(`line`,{x1:`87.5`,y1:`66.5`,x2:`85.4`,y2:`68.6`})]})]})]}),rt&&(0,E.jsx)(I7,{request:rt,onRespond:st}),et.length>0&&(0,E.jsx)(F7,{modals:et,onDismiss:nt}),it&&(0,E.jsx)(R7,{request:it,onInput:ct}),ot.filter(e=>!m.has(e.key)).map((e,t)=>(0,E.jsx)(z7,{widget:e,saved:w[e.key],messages:D[e.key]??[],defaultOffset:t%3==0?{dx:0,dy:0}:t%3==1?{dx:-80,dy:0}:{dx:80,dy:0},onCloseWidget:h,setWidgetGeometry:T,onSend:zt,fillChatInput:R,portalTarget:rn},e.key)),(0,E.jsxs)(`div`,{ref:fe,"data-testid":`chat-toolbar`,style:y7,children:[(0,E.jsx)(qi,{label:v(e?`history.full`:`history.unsaved`),children:(0,E.jsx)(`button`,{onClick:xe,disabled:!e,"aria-label":v(`history.full`),style:{...b7,color:e?`var(--text-muted)`:`var(--text-dim)`,cursor:e?`pointer`:`not-allowed`,opacity:e?1:.45},className:e?`hover-shift`:void 0,children:(0,E.jsx)(hi,{size:p.base,style:S7})})}),(()=>{let t=!!(e&&(Je?.userMessages??e.messageCount)>0),n=!e||!t||oe.kind===`naming`,r=oe.kind===`success`,i=oe.kind===`error`,a=oe.kind===`naming`?v(`title.generating`):v(r?`title.updated`:i?`title.failed`:`title.generate`),o=e?t?i?oe.message:v(`title.generateSession`):v(`title.noMessages`):v(`title.unsaved`);return(0,E.jsx)(qi,{label:o,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>void Bt(),disabled:n,"aria-label":a,style:{...b7,color:i?`var(--status-error)`:r?`var(--status-success)`:n?`var(--text-dim)`:`var(--text-muted)`,cursor:n?`not-allowed`:`pointer`,opacity:n&&oe.kind!==`naming`?.45:1,"--hover-color":i?`var(--status-error)`:`var(--text)`},className:n?void 0:`hover-shift`,children:oe.kind===`naming`?(0,E.jsx)(oi,{className:`animate-spin`,size:p.lg,"aria-hidden":`true`}):r?(0,E.jsx)(Rr,{size:p.lg,"aria-hidden":`true`}):(0,E.jsx)(li,{size:p.lg,"aria-hidden":`true`,style:S7})})})})(),(0,E.jsx)(qi,{label:v(`i18n.branches`),children:(0,E.jsx)(eZ,{tree:pt,activeLeafId:ht,onLeafChange:Tt,inline:!0,compact:!0,containerRef:fe,open:he===`branches`,onToggle:()=>ge(`branches`),hasSession:!0})}),(0,E.jsx)(qi,{label:v(`system.prompt`),children:(0,E.jsx)(`button`,{ref:me,onClick:()=>ge(`system`),"aria-label":v(`system.prompt`),"aria-pressed":he===`system`,style:{...b7,background:he===`system`?`var(--bg-selected)`:`transparent`,borderColor:he===`system`?`var(--accent)`:`var(--border)`,cursor:`pointer`,color:he===`system`?`var(--text)`:`var(--text-muted)`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsx)(Jr,{size:p.base,style:S7})})}),(0,E.jsx)(qi,{label:v(`session.reload`),children:(0,E.jsx)(`button`,{type:`button`,"data-testid":`chat-toolbar-reload`,onClick:()=>void Nt(`/reload`),"aria-label":v(`session.reload`),style:{...b7,background:`transparent`,borderColor:`var(--border)`,cursor:`pointer`,color:`var(--text-muted)`,"--hover-color":`var(--text)`},className:`hover-shift`,children:dt?(0,E.jsx)(oi,{className:`animate-spin`,size:p.base,style:S7}):(0,E.jsx)(mi,{size:p.base,style:S7})})}),(0,E.jsx)(`div`,{style:{marginLeft:8,display:`flex`,alignItems:`center`,flex:1,minWidth:0},children:(0,E.jsx)(h7,{messages:Te,t:v,onJump:Vn})}),Je||He?(0,E.jsx)(w7,{sessionStats:Je,contextUsage:He,activeTopPanel:he,toggleTopPanel:ge,isMobile:P,t:v,locale:y}):null,f,he===`system`&&(0,E.jsx)(`div`,{onMouseEnter:be,onMouseLeave:ye,style:D7,children:Ye?(0,E.jsx)(`div`,{style:{padding:`12px 16px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`,lineHeight:1.6,whiteSpace:`pre-wrap`,fontFamily:`var(--font-mono)`},children:Ye}):Ye===``?(0,E.jsx)(`div`,{style:O7,children:v(`system.empty`)}):(0,E.jsx)(`div`,{style:O7,children:v(`system.load`)})}),he===`session`&&(0,E.jsx)(`div`,{onMouseEnter:be,onMouseLeave:ye,style:{...D7,padding:`12px 16px`},children:Je?(()=>{let e=[...Je.sessionName?[{label:v(`session.name`),value:Je.sessionName,copyField:null}]:[],{label:v(`session.file`),value:Je.sessionFile??v(`session.inMemory`),copyField:`file`},{label:v(`session.id`),value:Je.sessionId,copyField:`id`}],t=[[v(`session.user`),Je.userMessages.toLocaleString(y)],[v(`session.assistant`),Je.assistantMessages.toLocaleString(y)],[v(`session.toolCalls`),Je.toolCalls.toLocaleString(y)],[v(`session.toolResults`),Je.toolResults.toLocaleString(y)],[v(`session.total`),Je.totalMessages.toLocaleString(y)]],n=Je.tokens.input+Je.tokens.cacheRead+Je.tokens.cacheWrite,r=[[v(`session.input`),Je.tokens.input.toLocaleString(y),{title:v(`session.inputHint`)}],[v(`session.output`),Je.tokens.output.toLocaleString(y),{title:v(`session.outputHint`)}],...Je.tokens.cacheRead>0?[[v(`session.cacheRead`),Je.tokens.cacheRead.toLocaleString(y),{title:v(`session.cacheReadHint`),badge:n>0?(e=>`${e.toFixed(1)}%`)(Je.tokens.cacheRead/n*100):void 0,badgeTitle:v(`session.cacheReadRate`)}]]:[],...Je.tokens.cacheWrite>0?[[v(`session.cacheWrite`),Je.tokens.cacheWrite.toLocaleString(y),{title:v(`session.cacheWriteHint`)}]]:[],[v(`session.total`),Je.tokens.total.toLocaleString(y),{title:v(`session.totalHint`)}]],i=He??Je.contextUsage,a=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=[...Je.cost>0?[[v(`session.cost`),`$${Je.cost.toFixed(4)}`]]:[],...i?.contextWindow?[[v(`session.context`),`${i.percent===null?`?`:`${i.percent.toFixed(1)}%`} / ${a(i.contextWindow)}`]]:[]],s=(e,t,n=`left`,r=!1)=>(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:k7,children:e}),(0,E.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:r?`max-content max-content max-content`:`auto minmax(0, 1fr) max-content`,columnGap:r?14:12,rowGap:4,justifyContent:r?`start`:void 0},children:t.map(([t,i,a])=>(0,E.jsxs)(`div`,{style:{display:`contents`},children:[(0,E.jsx)(qi,{label:a?.title,wrapperStyle:{display:`flex`,color:`var(--text-dim)`,whiteSpace:`nowrap`},children:(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`,whiteSpace:`nowrap`},children:t})}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,minWidth:0,overflowWrap:r?`normal`:`anywhere`,textAlign:n,whiteSpace:n===`right`?`nowrap`:`normal`},children:i}),(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`flex-end`,minWidth:0},children:a?.badge&&(0,E.jsx)(qi,{label:`${a.badgeTitle??``}${a.badgeTitle?` · `:``}${a.badge}`,children:(0,E.jsx)(`span`,{style:{padding:`0 5px`,...A7},children:a.badge})})})]},`${e}:${t}`))})]}),c=(e,t)=>{let n=le===e;return(0,E.jsx)(qi,{label:v(n?`session.copied`:e===`file`?`session.copyFile`:`session.copyId`),children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>Se(e,t),style:{alignSelf:`start`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:22,height:22,marginTop:-2,color:n?`var(--accent)`:`var(--text-dim)`,background:`transparent`,border:`1px solid var(--border)`,borderRadius:4,cursor:`pointer`,flex:`0 0 auto`,transition:`color 0.12s, border-color 0.12s, background 0.12s`,"--hover-color":`var(--accent)`,"--hover-border":`var(--accent)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:n?(0,E.jsx)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`rect`,{x:`9`,y:`9`,width:p.lg,height:p.lg,rx:`2`,ry:`2`}),(0,E.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})})})},l=(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(`div`,{style:k7,children:v(`session.infoSection`)}),(0,E.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto minmax(0, 1fr) auto`,columnGap:12,rowGap:8,alignItems:`start`},children:e.map(e=>(0,E.jsxs)(`div`,{style:{display:`contents`},children:[(0,E.jsx)(`div`,{style:{color:`var(--text-dim)`,whiteSpace:`nowrap`},children:e.label}),(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,minWidth:0,overflowWrap:`anywhere`,wordBreak:`break-word`,whiteSpace:`normal`},children:e.value}),(0,E.jsx)(`div`,{children:e.copyField?c(e.copyField,e.value):null})]},`session-info:${e.label}`))})]});return(0,E.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:P?`1fr`:`minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)`,gap:P?16:24,fontSize:`var(--text-base)`,lineHeight:1.5,fontFamily:`var(--font-mono)`},children:[l,s(v(`session.messages`),t),s(v(`session.tokens`),[...r,...o],`right`,!0)]})})():(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`,fontStyle:`italic`},children:v(`session.load`)})})]}),Hn?(0,E.jsx)(`div`,{className:`relative flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8`,children:(0,E.jsxs)(`div`,{className:`w-full max-w-[820px]`,children:[(0,E.jsxs)(`div`,{className:`mb-3`,style:{textAlign:`center`,padding:`40px 0`},children:[ee==="default"?(0,E.jsxs)(`div`,{style:{marginBottom:20,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,lineHeight:1.6},children:[v(`notify.permission.bannerHintBefore`),` `,(0,E.jsxs)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--accent)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{display:`inline-block`,verticalAlign:-2},children:[(0,E.jsx)(`path`,{d:`M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`})]}),` `,v(`notify.permission.bannerHintAfter`)]}):null,(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,fontStyle:`italic`,color:`var(--accent)`},children:`Pi Web`}),t?(0,E.jsx)(`div`,{style:{marginTop:6,fontSize:`var(--text-3xl)`,color:`var(--text-muted)`,fontFamily:`var(--font-mono)`},children:t}):null]}),O.length>0&&(0,E.jsx)(`div`,{style:{marginBottom:28},children:(0,E.jsx)(gY,{messages:O,onSend:zt,onFillInput:R,testIdPrefix:`start-screen-msg`,wrapperTestId:`start-screen-messages`,center:!0})}),(0,E.jsx)(`div`,{style:{position:`absolute`,top:12,left:0,right:0,zIndex:40,padding:`0 16px`,pointerEvents:`none`},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`},children:(0,E.jsx)(P7,{notices:$e,floating:!0,align:`right`})})}),qn]})}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,E.jsx)(`div`,{style:{position:`absolute`,top:12,left:0,right:P?0:`calc(${bY} + 48px)`,zIndex:40,padding:`0 16px`,pointerEvents:`none`},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`},children:(0,E.jsx)(P7,{notices:$e,floating:!0,align:`right`})})}),(0,E.jsx)(`div`,{ref:yt,onScroll:hn,className:`min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [overflow-anchor:none]`,style:{paddingRight:48},"data-testid":`message-list`,children:(0,E.jsx)(`div`,{style:{minWidth:0,padding:`0 16px`},children:(0,E.jsxs)(`div`,{style:{width:`100%`,minWidth:0,maxWidth:820,margin:`0 auto`},children:[yn&&(0,E.jsx)(v7,{rows:Nn,messages:Te,entryIds:Ee,modelNames:Me,messageCwd:Wn,onOpenFile:u,sessionBusy:Rt,isNew:ft,handleFork:Ct,forkingEntryId:Ue,handleNavigate:wt,handleEditContent:ae,sessionId:e?.id??mt.current??void 0,longBlockCollapseChars:S,recentExpandedBlockKeys:Ut,isStreaming:De.isStreaming,flashKey:Rn,itemRef:_n,t:v,messageRefs:vn,lastUserMsgRef:bt,visibleRefIndexByMessage:Mn,scrollContainerRef:yt,virtualizerRef:un,initialCache:Ln},xn||`empty`),De.isStreaming&&De.streamingMessage&&(0,E.jsx)(`div`,{children:(0,E.jsx)(N5,{message:De.streamingMessage,isStreaming:!0,modelNames:Me,cwd:Wn,onOpenFile:u,longBlockCollapseChars:S,recentExpandedBlockKeys:Ut,turnNumber:Ht})}),(Oe||dt)&&(ut?.kind===`waiting_model`||ut?.kind===`thinking`||!De.streamingMessage)&&(ut||dt)&&(0,E.jsx)(`div`,{className:`py-2 text-[0.8125rem] text-text-muted`,children:(0,E.jsx)(mY,{phase:ut??{kind:`running_command`},elapsed:Zt,totalElapsed:Qt})}),ke&&(0,E.jsx)(`div`,{className:`py-2 text-[0.8125rem] text-text-muted`,children:(0,E.jsx)(mY,{phase:{kind:`running_command`},elapsed:Zt,totalElapsed:Qt})}),je&&(0,E.jsx)(N5,{message:{role:`bashExecution`,command:je.command,output:``,excludeFromContext:je.excludeFromContext},streamingBashOutput:Ae,sessionId:e?.id??mt.current??void 0,longBlockCollapseChars:S}),Oe&&(0,E.jsx)(`div`,{style:{height:48}}),(0,E.jsx)(`div`,{ref:vt})]})})}),!on&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{style:{position:`absolute`,left:0,right:0,bottom:0,height:30,background:`linear-gradient(to bottom, transparent, var(--bg))`,pointerEvents:`none`,zIndex:49}}),(0,E.jsx)(`button`,{type:`button`,onClick:mn,"aria-label":v(`chat.scrollToLatest`),"data-testid":`scroll-to-latest`,style:{position:`absolute`,bottom:0,left:`50%`,transform:`translateX(-50%)`,width:`min(100% / 3, 260px)`,zIndex:50,cursor:`pointer`,background:`transparent`,border:`none`,padding:0,height:30,display:`flex`,alignItems:`flex-end`,justifyContent:`center`},children:(0,E.jsx)(qi,{label:v(`chat.scrollToLatest`),children:(0,E.jsx)(`span`,{style:{position:`absolute`,bottom:4,left:`50%`,transform:`translateX(-50%)`,width:12,height:11,display:`flex`,alignItems:`flex-end`,justifyContent:`center`,cursor:`pointer`},children:(0,E.jsx)(`span`,{style:{position:`relative`,width:0,height:0,borderLeft:`6px solid transparent`,borderRight:`6px solid transparent`,borderTop:`7px solid var(--text-muted)`,pointerEvents:`none`}})})})})]}),P?null:(0,E.jsx)(yZ,{messages:Te,streamingMessage:De.streamingMessage,scrollContainer:yt,messageRefs:vn,resolveMessageOffset:Fn,scrollStepPx:b,onWindowJumpTo:pn})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`div`,{style:{padding:`0 16px`,paddingRight:P?16:64},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`}})}),O.length>0&&Un&&(0,E.jsx)(`div`,{style:{padding:`0 16px`,paddingRight:P?16:64},children:(0,E.jsx)(`div`,{style:{maxWidth:820,margin:`0 auto`,paddingBottom:8},children:(0,E.jsx)(gY,{messages:O,onSend:zt,onFillInput:R,testIdPrefix:`start-screen-msg`,wrapperTestId:`start-screen-messages`})})}),qn]}),(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,flexShrink:0,minWidth:0,height:36,padding:`0 12px`,borderTop:`1px solid var(--border)`,gap:8},children:(0,E.jsx)(qi,{label:$t,wrapperStyle:{display:`flex`,flex:1,minWidth:0},children:(0,E.jsx)(`div`,{role:`status`,"aria-label":$t,style:{alignSelf:`stretch`,display:`flex`,alignItems:`center`,flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`,color:`var(--text-dim)`},children:$t})})})]})]})}function P7({notices:e,floating:t=!1,align:n=`left`}){return e.length===0?null:(0,E.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:n===`right`?`flex-end`:`stretch`,marginBottom:t?0:10},children:e.map((n,r)=>{let i=n.type===`error`?`var(--status-error)`:n.type===`warning`?`var(--status-warning)`:n.type===`success`?`var(--status-success)`:`var(--accent)`;return(0,E.jsxs)(`div`,{className:`notice-shelf-item`,style:{display:`flex`,alignItems:`center`,gap:10,minHeight:60,marginBottom:r===e.length-1?0:6,borderRadius:14,border:`1px solid color-mix(in srgb, var(--border) 70%, transparent)`,background:`var(--bg)`,color:`var(--text-muted)`,width:`fit-content`,maxWidth:`min(100%, 620px)`,boxShadow:t?`0 1px 2px var(--shadow-color), 0 10px 28px -14px var(--shadow-color)`:`0 1px 2px var(--shadow-color), 0 8px 24px -12px var(--shadow-color)`,fontSize:`var(--text-4xl)`,lineHeight:1.45,transformOrigin:`top center`,animation:n.exiting?`notice-shelf-out 0.18s ease-in forwards`:`notice-shelf-in 0.18s ease-out both`,padding:`0 12px`},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:i,flexShrink:0}}),(0,E.jsx)(`span`,{style:{padding:`14px 0`,minWidth:0,maxWidth:`100%`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:n.message})]},n.id)})})}function F7({modals:e,onDismiss:t}){let{t:n}=N();return(0,E.jsx)(E.Fragment,{children:e.map((e,r)=>(0,E.jsx)(JX,{variant:e.type===`error`?`error`:`normal`,align:`center`,width:520,height:320,initialOffset:{dx:r%3*24,dy:r%3*24},title:e.type===`error`?n(`chat.notifyErrorTitle`):n(`chat.notifyWarningTitle`),footer:(0,E.jsx)(`button`,{onClick:()=>t(e.id),style:{padding:`6px 14px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,cursor:`pointer`},children:n(`chat.close`)}),children:(0,E.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`,fontSize:`var(--text-lg)`,lineHeight:1.6,color:`var(--text)`},children:e.message})},e.id))})}function I7({request:e,onRespond:t}){let{t:n}=N(),[r,i]=(0,d.useState)(e.method===`editor`?e.prefill??``:``),[a,o]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{i(e.method===`editor`?e.prefill??``:``),o(Date.now())},[e]),(0,d.useEffect)(()=>{if(!e.expiresAt)return;let t=setInterval(()=>{document.hidden||o(Date.now())},1e3),n=()=>{document.hidden||o(Date.now())};return document.addEventListener(`visibilitychange`,n),()=>{clearInterval(t),document.removeEventListener(`visibilitychange`,n)}},[e.expiresAt]);let s=e.expiresAt?Math.max(0,Math.ceil((e.expiresAt-a)/1e3)):null;(0,d.useEffect)(()=>{s===0&&t(e,{cancelled:!0})},[s===0,e.id]);let c=()=>{e.method===`confirm`?t(e,{confirmed:!0}):t(e,{value:r})},l=e.method===`select`?n(`chat.extensionSelect`):e.method===`confirm`?n(`chat.extensionConfirm`):e.method===`editor`?n(`chat.extensionEditor`):n(`chat.extensionInput`);return(0,E.jsxs)(JX,{testId:`extension-dialog`,flashHeader:!0,title:(0,E.jsxs)(E.Fragment,{children:[l,s!==null&&(0,E.jsxs)(`span`,{style:{color:`var(--text-muted)`,marginLeft:6,fontVariantNumeric:`tabular-nums`},children:[`(`,s,`s)`]})]}),subtitle:n(`chat.extensionRequest`),maxWidth:Math.round(window.innerWidth*.6),footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{onClick:()=>t(e,{cancelled:!0}),style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,cursor:`pointer`},children:n(`chat.cancel`)}),e.method===`confirm`?(0,E.jsx)(`button`,{onClick:c,style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--accent)`,background:`var(--accent)`,color:`var(--on-accent)`,cursor:`pointer`},children:n(`chat.confirm`)}):e.method===`select`?null:(0,E.jsx)(`button`,{onClick:c,style:{padding:`6px 10px`,borderRadius:6,border:`1px solid var(--accent)`,background:`var(--accent)`,color:`var(--on-accent)`,cursor:`pointer`},children:n(`chat.submit`)})]}),children:[(0,E.jsx)(`div`,{style:{marginBottom:12,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,fontSize:`var(--text-lg)`,lineHeight:1.6,whiteSpace:`pre-wrap`,maxHeight:360,overflowY:`auto`},children:e.title}),`Notification`in window&&Notification.permission===`denied`&&(0,E.jsx)(`div`,{style:{marginBottom:10,padding:`7px 10px`,borderRadius:7,border:`1px solid var(--border-warning, var(--border))`,background:`var(--bg-panel)`,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:n(`chat.questionNotificationDenied`)}),e.method===`confirm`&&(0,E.jsx)(`div`,{style:{color:`var(--text-muted)`,fontSize:`var(--text-lg)`,lineHeight:1.6,whiteSpace:`pre-wrap`},children:e.message}),e.method===`select`&&(0,E.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8},children:e.options.map(n=>(0,E.jsx)(`button`,{onClick:()=>t(e,{value:n}),style:{flex:`1 1 auto`,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-lg)`},children:n},n))}),e.method===`input`&&(0,E.jsx)(`input`,{autoFocus:!0,value:r,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&c(),n.key===`Escape`&&t(e,{cancelled:!0})},style:{width:`100%`,padding:`9px 10px`,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text)`,outline:`none`,fontSize:`var(--text-2xl)`}}),e.method===`editor`&&(0,E.jsx)(`textarea`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Escape`&&t(e,{cancelled:!0}),(n.metaKey||n.ctrlKey)&&n.key===`Enter`&&c()},style:{width:`100%`,minHeight:220,padding:10,borderRadius:7,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text)`,outline:`none`,resize:`vertical`,fontSize:`var(--text-2xl)`,lineHeight:1.55,fontFamily:`var(--font-mono)`}})]},e.id)}function L7(e,t){return rJ(e).map((e,n)=>Object.keys(e.style).length>0?(0,E.jsx)(`span`,{style:e.style,children:e.text},`${t}-${n}`):e.text)}function R7({request:e,onInput:t}){let{t:n}=N(),r=(0,d.useRef)(null),i=(0,d.useRef)(!1),a=eJ(e.lines);return(0,d.useEffect)(()=>{r.current?.focus()},[e.id]),(0,E.jsx)(`div`,{style:{position:`absolute`,inset:0,zIndex:95,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:20,background:`rgba(0,0,0,0.18)`},children:(0,E.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,onClick:e=>{e.target.closest(`button`)||r.current?.focus()},style:{position:`relative`,width:`min(920px, 100%)`,maxHeight:`min(760px, calc(100vh - 40px))`,border:`1px solid var(--border)`,borderRadius:8,background:`var(--bg)`,boxShadow:`0 20px 60px var(--shadow-strong)`,overflow:`hidden`,outline:`none`},children:[(0,E.jsx)(`textarea`,{ref:r,"aria-label":n(`chat.extensionInput`),autoCapitalize:`off`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,onKeyDown:n=>{if(i.current||n.nativeEvent.isComposing)return;let r=TY(n);r&&(n.preventDefault(),n.stopPropagation(),t(e,r))},onInput:n=>{if(i.current||n.nativeEvent.isComposing)return;let r=n.currentTarget.value;n.currentTarget.value=``,r&&t(e,r)},onCompositionStart:()=>{i.current=!0},onCompositionEnd:n=>{i.current=!1;let r=n.currentTarget;queueMicrotask(()=>{let n=r.value;r.value=``,n&&t(e,n)})},onPaste:n=>{n.preventDefault();let r=n.clipboardData.getData(`text`);r&&t(e,EY(r))},style:{position:`absolute`,width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:`none`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,padding:`10px 12px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`div`,{style:{color:`var(--text)`,fontSize:`var(--text-lg)`,fontWeight:650},children:n(`chat.extensionPanel`)}),(0,E.jsx)(`button`,{onClick:()=>t(e,``),style:{padding:`5px 9px`,borderRadius:6,border:`1px solid var(--border)`,background:`var(--bg-panel)`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`},children:n(`chat.close`)})]}),(0,E.jsx)(`pre`,{style:{margin:0,padding:14,maxHeight:`calc(min(760px, 100vh - 40px) - 48px)`,overflow:`auto`,background:`var(--bg-panel)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,lineHeight:1.45,whiteSpace:`pre`},children:(a.length?a:[``]).map((e,t,n)=>(0,E.jsxs)(d.Fragment,{children:[L7(e,`line-${t}`),t<n.length-1?`
|
|
492
492
|
`:null]},t))})]})})}function z7({widget:e,saved:t,messages:n,defaultOffset:r,onCloseWidget:i,setWidgetGeometry:a,onSend:o,fillChatInput:s,portalTarget:c}){let{t:l}=N(),[u,f]=(0,d.useState)(!1),[m,h]=(0,d.useState)(null),g=(0,d.useRef)(null),_=(0,d.useCallback)(t=>{if(u)return;let n=()=>i(e.key,e.lines.join(`
|
|
493
493
|
`));if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches){n();return}let r=document.querySelector(`[data-tab-id="widgets"]`)??document.querySelector(`[data-testid="tab-bar"]`);if(!r){n();return}let a=t.currentTarget.getBoundingClientRect(),o=r.getBoundingClientRect(),s=`M ${a.left+a.width/2} ${a.top+a.height/2} L ${o.left+o.width/2} ${o.top+o.height/2}`;f(!0),h(s),window.setTimeout(n,280)},[u,i,e.key,e.lines]);return(0,d.useLayoutEffect)(()=>{if(!m||!g.current)return;let e=g.current;e.style.setProperty(`offset-path`,`path('${m}')`),e.style.setProperty(`offset-rotate`,`0deg`),e.animate([{offsetDistance:`0%`,r:28},{offsetDistance:`100%`,r:2}],{duration:240,easing:`cubic-bezier(0.22, 1, 0.36, 1)`,fill:`forwards`})},[m]),(0,d.useEffect)(()=>{t===void 0?a(e.key,{x:r.dx,y:r.dy,width:560,height:Math.round(window.innerHeight*.6)}):t.collapsed&&i(e.key,e.lines.join(`
|
|
494
494
|
`))},[e.key]),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(JX,{testId:`widget-dialog`,title:e.key,align:`center`,portalTarget:c,style:{opacity:+!u,transition:`opacity 200ms ease`},headerExtra:(0,E.jsx)(qi,{label:l(`widgets.collapse`),children:(0,E.jsx)(`button`,{type:`button`,"aria-label":l(`widgets.collapse`),onClick:_,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:26,height:26,borderRadius:6,border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`},className:`hover-shift`,children:(0,E.jsx)(si,{size:p.xl})})}),position:t?{x:t.x,y:t.y}:void 0,size:t?{width:t.width,height:t.height}:void 0,initialOffset:r,onDragStop:(n,r)=>a(e.key,{x:n,y:r,width:t?.width??560,height:t?.height??Math.round(window.innerHeight*.6)}),onResizeStop:(t,n,r,i)=>a(e.key,{x:r,y:i,width:t,height:n}),children:(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,E.jsx)(`pre`,{style:{margin:0,color:`var(--text-muted)`,fontSize:`var(--text-base)`,lineHeight:1.5,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontFamily:`var(--font-mono)`},children:e.lines.join(`
|
|
495
|
-
`)}),n.length>0&&(0,E.jsx)(`div`,{"data-testid":`widget-bound-messages`,style:{display:`flex`,flexWrap:`wrap`,gap:6,paddingTop:8,borderTop:`1px solid var(--border)`,flexShrink:0},children:n.map((t,n)=>(0,E.jsx)($J,{msg:t,onSend:o,onFillInput:s,testId:`widget-send-${e.key}-${n}`},n))})]})}),m&&(0,E.jsx)(`div`,{"data-testid":`widget-collapse-trail`,style:{position:`fixed`,inset:0,zIndex:70,pointerEvents:`none`},children:(0,E.jsx)(`svg`,{width:`100%`,height:`100%`,style:{position:`absolute`,inset:0},children:(0,E.jsx)(`circle`,{ref:g,r:28,fill:`var(--accent)`,fillOpacity:.7})})})]})}var B7=262144,V7=10485760,H7={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,bmp:`image/bmp`,ico:`image/x-icon`,avif:`image/avif`},U7={mp3:`audio/mpeg`,wav:`audio/wav`,ogg:`audio/ogg`,oga:`audio/ogg`,opus:`audio/ogg`,m4a:`audio/mp4`,aac:`audio/aac`,flac:`audio/flac`,weba:`audio/webm`,webm:`audio/webm`};function W7(e){return e.replace(/\\/g,`/`).split(`/`).pop()??``}function G7(e){return W7(e).toLowerCase().split(`.`).pop()??``}function K7(e){return H7[G7(e)]??null}function q7(e){return U7[G7(e)]??null}function J7(e){let t=G7(e);return t===`pdf`||t===`docx`?t:null}function Y7(e){return K7(e)!==null}function X7(e){return q7(e)!==null}function Z7(e){return J7(e)!==null}async function Q7(e,t){let n=e.split(/[\\/]/).filter(Boolean),r=n.pop();if(!r)throw Error(`Invalid file path`);let i=n.join(`/`)||`/`,a=new FormData;a.append(`files`,new File([t],r,{type:`text/plain`}));let o=await fetch(`/api/files/${mG(i)}?type=upload&conflict=overwrite`,{method:`POST`,body:a});if(!o.ok){let e=`Save failed (${o.status})`;try{let t=await o.json();t?.error&&(e=t.error)}catch{}throw Error(e)}}var $7=(0,d.lazy)(()=>l0(()=>import(`./CodeMirrorEditor-DuVYY3Kf.js`),__vite__mapDeps([20,1]))),e9={source:`Source`,preview:`Preview`,diff:`Diff`},t9={fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,lineHeight:1.6},n9={width:48,minWidth:48,padding:`0 10px`,textAlign:`right`,color:`var(--text-dim)`,background:`var(--bg-panel)`,borderRight:`1px solid var(--border)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,fontStyle:`normal`,fontVariantNumeric:`tabular-nums`,lineHeight:`20.8px`,userSelect:`none`,flexShrink:0,verticalAlign:`top`};function r9(){return(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,E.jsx)(`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`})]})}function i9(e){return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest(`.file-source-line[data-line-number]`)??null}function a9(e,t){if(!t||t.isCollapsed||t.rangeCount===0)return null;let n=t.getRangeAt(0);if(!e.contains(n.startContainer)||!e.contains(n.endContainer))return null;let r=i9(n.startContainer),i=i9(n.endContainer);if(!r||!i||!e.contains(r)||!e.contains(i))return null;let a=Number(r.dataset.lineNumber),o=Number(i.dataset.lineNumber);if(!Number.isInteger(a)||!Number.isInteger(o))return null;if(a<o){let e=r.querySelector(`.file-source-line-content`);if(e?.contains(n.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(n.startContainer,n.startOffset),t.toString().length===0){let e=r.nextElementSibling;e instanceof HTMLElement&&e.matches(`.file-source-line[data-line-number]`)&&(r=e,a=Number(r.dataset.lineNumber))}}let t=i.querySelector(`.file-source-line-content`);if(t?.contains(n.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(n.endContainer,n.endOffset),e.toString().length===0){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(`.file-source-line[data-line-number]`)&&(i=e,o=Number(i.dataset.lineNumber))}}}return a>o?null:{startLine:a,endLine:o}}function o9({rows:e,stylesheet:t,useInlineStyles:n,wrapLines:r}){return e.map((e,i)=>{let a=e.children??[],o=a[0]?.properties?.className,s=Array.isArray(o)&&o.includes(`react-syntax-highlighter-line-number`),c=s?a[0]:null,l=s?a.slice(1):a;return(0,E.jsxs)(`span`,{className:`file-source-line`,"data-line-number":i+1,style:{display:`flex`,minWidth:`100%`},children:[c&&p6({node:c,stylesheet:t,useInlineStyles:n,key:`source-line-number-${i}`}),(0,E.jsx)(`span`,{className:`file-source-line-content`,style:{flex:`1 1 auto`,minWidth:0,overflowWrap:r?`anywhere`:`normal`,whiteSpace:r?`pre-wrap`:`pre`},children:l.map((e,r)=>p6({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${i}-${r}`}))})]},`source-line-${i}`)})}function s9(e,t,n,r={}){let i=mG(e),a=new URLSearchParams({type:t});n&&a.set(`sessionId`,n);for(let[e,t]of Object.entries(r))t!==void 0&&a.set(e,String(t));return`/api/files/${i}?${a.toString()}`}function c9({filePath:e,sourceSessionId:t}){let{t:n}=N();return(0,E.jsx)(qi,{label:n(`i18n.downloadFile`),children:(0,E.jsx)(`a`,{href:s9(e,`download`,t),download:hG(e),"aria-label":n(`i18n.downloadFile`),className:`file-viewer-icon-button`,children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})})})}function l9(e,t,n){let[r,i]=(0,d.useState)(!1),a=(0,d.useRef)(n);(0,d.useEffect)(()=>{a.current=n});let o=(0,d.useRef)(null);return(0,d.useEffect)(()=>(i(!1),o.current?.(),o.current=dn({ch:`watch`,filePath:e},e=>{e.event===`connected`?i(!0):e.event===`error`?i(!1):a.current(e)}),()=>{o.current?.(),o.current=null}),[e]),{watching:r,closeWatch:(0,d.useCallback)(()=>{o.current?.(),o.current=null,i(!1)},[])}}function u9({filePath:e,cwd:t,extLabel:n,watching:r,sourceSessionId:i,ellipsis:a,children:o}){let{t:s}=N();return(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,padding:`4px 16px`,borderBottom:`1px solid var(--border)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,background:`var(--bg)`,flexShrink:0},children:[(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,...a?{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`}:{}},title:e,children:_G(e,t)}),(0,E.jsx)(`span`,{style:{marginLeft:`auto`},children:n}),o,(0,E.jsxs)(`span`,{title:s(r?`i18n.liveSync`:`i18n.notWatching`),style:{display:`flex`,alignItems:`center`,gap:4,color:r?`var(--status-success)`:`var(--text-dim)`},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:r?`var(--status-success)`:`var(--border)`,display:`inline-block`,boxShadow:r?`0 0 4px var(--status-success)`:`none`}}),r?`live`:`static`]}),(0,E.jsx)(c9,{filePath:e,sourceSessionId:i})]})}function d9(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function f9(e){let t=kZ(e);return t?t.flatMap(e=>e.rows.flatMap(e=>{if(e.type===`hunk`)return[];if(e.left.type===`context`&&e.right.type===`context`)return[{type:`unchanged`,text:e.right.text,oldLineNo:e.left.lineNo,newLineNo:e.right.lineNo}];let t=[];return e.left.type===`removed`&&t.push({type:`removed`,text:e.left.text,oldLineNo:e.left.lineNo,newLineNo:null}),e.right.type===`added`&&t.push({type:`added`,text:e.right.text,oldLineNo:null,newLineNo:e.right.lineNo}),t})):[]}function p9({patch:e}){let{t}=N(),n=f9(e);if(!n.some(e=>e.type!==`unchanged`))return(0,E.jsx)(`div`,{style:{padding:`12px 16px`,fontSize:`var(--text-base)`,color:`var(--text-dim)`,fontFamily:`var(--font-mono)`},children:t(`i18n.noChanges`)});let r=new Set(n.flatMap((e,t)=>e.type===`unchanged`?[]:[t])),i=new Set;for(let e of r)for(let t=Math.max(0,e-3);t<=Math.min(n.length-1,e+3);t++)i.add(t);let a=[],o=0;for(;o<n.length;)if(i.has(o)){let e=[];for(;o<n.length&&i.has(o);)e.push(n[o]),o++;a.push({hidden:!1,lines:e})}else{let e=0;for(;o<n.length&&!i.has(o);)e++,o++;a.push({hidden:!0,count:e})}return(0,E.jsx)(`div`,{className:`file-diff-view`,style:{width:`max-content`,minWidth:`100%`,...t9},children:a.map((e,t)=>{if(e.hidden)return(0,E.jsxs)(`div`,{style:{padding:`2px 16px`,color:`var(--text-dim)`,background:`var(--bg-panel)`,fontSize:`var(--text-sm)`,borderTop:`1px solid var(--border)`,borderBottom:`1px solid var(--border)`},children:[`... `,e.count,` unchanged lines ...`]},t);let n=e.lines.map((e,t)=>{let n=e.type===`added`?`color-mix(in srgb, var(--status-success) 12%, transparent)`:e.type===`removed`?`color-mix(in srgb, var(--status-error) 14%, transparent)`:`transparent`,r=e.type===`added`?`+`:e.type===`removed`?`-`:` `,i=e.type===`added`?`var(--status-success)`:e.type===`removed`?`var(--status-error)`:`var(--text-dim)`;return(0,E.jsxs)(`div`,{className:`file-diff-line`,style:{display:`flex`,minWidth:`100%`,background:n,borderLeft:e.type===`added`?`3px solid var(--status-success)`:e.type===`removed`?`3px solid var(--status-error)`:`3px solid transparent`},children:[(0,E.jsx)(`span`,{style:n9,children:e.type===`removed`?e.oldLineNo:e.newLineNo}),(0,E.jsx)(`span`,{style:{minWidth:16,padding:`0 6px`,color:i,userSelect:`none`,flexShrink:0,fontWeight:600},children:r}),(0,E.jsx)(`span`,{className:`file-diff-line-content`,style:{flexShrink:0,padding:`0 8px 0 0`,whiteSpace:`pre`,color:`var(--text)`},children:e.text||`\xA0`})]},t)});return(0,E.jsx)(`div`,{children:n},t)})})}function m9({filePath:e,cwd:t,sourceSessionId:n}){let[r,i]=(0,d.useState)(0),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(null),f=hG(e).toLowerCase().split(`.`).pop()??``;Wi(()=>{i(0),o(null),c(null),u(null)},[e,n]);let{watching:p}=l9(e,n,e=>{typeof e.size==`number`&&o(e.size),i(e=>e+1)}),m=s9(e,`read`,n,r?{v:r}:void 0),h=a==null?null:d9(a);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsxs)(u9,{filePath:e,cwd:t,extLabel:f||`image`,watching:p,sourceSessionId:n,children:[s&&(0,E.jsxs)(`span`,{children:[s.w,` × `,s.h]}),h&&(0,E.jsx)(`span`,{children:h})]}),(0,E.jsx)(`div`,{style:{flex:1,overflow:`auto`,backgroundColor:`var(--bg-panel)`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:16,backgroundImage:`linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)`,backgroundSize:`16px 16px`,backgroundPosition:`0 0, 0 8px, 8px -8px, -8px 0px`},children:l?(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:4},children:[(0,E.jsx)(`div`,{style:{color:`var(--status-error)`,fontSize:`var(--text-lg)`},children:l}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}):(0,E.jsx)(`img`,{src:m,alt:e,onLoad:e=>{let t=e.currentTarget;c({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>u(`Failed to load image`),style:{maxWidth:`100%`,maxHeight:`100%`,objectFit:`contain`,boxShadow:`0 2px 8px var(--shadow-color)`}})})]})}function h9({filePath:e,cwd:t,sourceSessionId:n}){let[r,i]=(0,d.useState)(0),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(null),f=hG(e).toLowerCase().split(`.`).pop()??``;Wi(()=>{i(0),o(null),c(null),u(null)},[e,n]);let{watching:p}=l9(e,n,e=>{typeof e.size==`number`&&o(e.size),c(null),u(null),i(e=>e+1)}),m=s9(e,`read`,n,r?{v:r}:void 0);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsxs)(u9,{filePath:e,cwd:t,extLabel:f||`audio`,watching:p,sourceSessionId:n,children:[s!=null&&(0,E.jsx)(`span`,{children:Wt(s)}),a!=null&&(0,E.jsx)(`span`,{children:d9(a)})]}),(0,E.jsx)(`div`,{style:{flex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:24,background:`var(--bg-panel)`},children:(0,E.jsxs)(`div`,{style:{width:`min(680px, 100%)`},children:[l&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{style:{color:`var(--status-error)`,fontSize:`var(--text-lg)`,marginBottom:12,textAlign:`center`},children:l}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}),(0,E.jsx)(`audio`,{controls:!0,preload:`metadata`,src:m,onLoadedMetadata:e=>c(e.currentTarget.duration),onError:()=>u(`Failed to load audio`),style:{width:`100%`}},m)]})})]})}function g9({filePath:e,cwd:t,sourceSessionId:n}){let{t:r}=N(),[i,a]=(0,d.useState)(0),[o,s]=(0,d.useState)(null),[c,l]=(0,d.useState)(null),u=G7(e),f=u===`pdf`,p=f?s9(e,`read`,n,i?{v:i}:void 0):s9(e,`preview`,n,i?{v:i}:void 0);(0,d.useEffect)(()=>{a(0),s(null),l(null),fetch(s9(e,`meta`,n)).then(e=>e.json()).then(e=>{e.error&&l(e.error),typeof e.size==`number`&&(s(e.size),!f&&e.size>10485760&&l(r(`files.docTooLargeForPreview`,{limit:d9(V7)})))}).catch(e=>l(String(e)))},[e,f,n,r]);let{watching:m}=l9(e,n,e=>{if(typeof e.size==`number`&&(s(e.size),!f&&e.size>10485760)){l(r(`files.docTooLargeForPreview`,{limit:d9(V7)}));return}l(null),a(e=>e+1)});return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsx)(u9,{filePath:e,cwd:t,extLabel:u===`docx`?`docx preview`:`pdf`,watching:m,sourceSessionId:n,ellipsis:!0,children:o!=null&&(0,E.jsx)(`span`,{children:d9(o)})}),(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,background:`var(--bg-panel)`},children:c?(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:24,color:`var(--status-error)`,fontSize:`var(--text-lg)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{children:c}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}):(0,E.jsx)(`iframe`,{src:p,sandbox:f?void 0:`allow-same-origin`,title:r(`i18n.previewFile`,{file:hG(e)}),style:{width:`100%`,height:`100%`,border:`none`,background:f?`var(--bg)`:`#eef1f5`}},p)})]})}function _9({filePath:e,sourceSessionId:t,cwd:n}){let{t:r}=N(),[i,a]=(0,d.useState)(!1),[o,s]=(0,d.useState)(null),c=typeof n==`string`&&/^[a-zA-Z]:[\\/]/.test(n)||typeof n==`string`&&n.startsWith(`\\\\`),l=(0,d.useCallback)(async n=>{a(!0),s(null);try{let i=await fetch(s9(e,`open`,t,n?{chooseApp:1}:void 0),{method:`POST`}),a=await i.json().catch(()=>null);i.ok?s({ok:!0,text:r(`files.openLaunched`)}):s({ok:!1,text:a?.error??`HTTP ${i.status}`})}catch(e){s({ok:!1,text:String(e)})}finally{a(!1)}},[e,t,r]);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:10,marginTop:16},children:[o&&(0,E.jsx)(`div`,{style:{color:o.ok?`var(--text-muted)`:`var(--status-error)`,fontSize:`var(--text-sm)`,maxWidth:460,textAlign:`center`,lineHeight:1.5},children:o.text}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,E.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>l(!1),className:`file-viewer-mode-button file-open-action-button`,children:r(`files.openInSystemApp`)}),c&&(0,E.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>l(!0),className:`file-viewer-mode-button file-open-action-button`,children:r(`files.chooseOtherApp`)})]})]})}function v9({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s}){return Y7(e)?(0,E.jsx)(m9,{filePath:e,cwd:t,sourceSessionId:n}):X7(e)?(0,E.jsx)(h9,{filePath:e,cwd:t,sourceSessionId:n}):Z7(e)?(0,E.jsx)(g9,{filePath:e,cwd:t,sourceSessionId:n}):(0,E.jsx)(Lee,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s})}function Iee({filePath:e,cwd:t,metadata:n,watching:r,isDeletedDiff:i,displayModes:a,effectiveDisplayMode:o,setDisplayMode:s,wrapLines:c,setWrapLines:l,editMode:u,dirty:d,handleSave:f,saveState:m,highlightReady:h,selectedLineRange:g,handleMentionSelectedLines:_,fileContent:v,sourceSessionId:y,t:b,saveError:x,enterEdit:S,cancelEdit:C}){return(0,E.jsxs)(`div`,{className:`file-viewer-toolbar`,style:{display:`flex`,alignItems:`center`,gap:8,padding:`5px 12px`,borderBottom:`1px solid var(--border)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,background:`var(--bg)`,flexShrink:0},children:[(0,E.jsx)(qi,{label:e,children:(0,E.jsx)(`span`,{className:`file-viewer-path`,style:{fontFamily:`var(--font-mono)`},children:_G(e,t)})}),(0,E.jsx)(qi,{label:n,children:(0,E.jsx)(`span`,{className:`file-viewer-meta`,children:n})}),!i&&(0,E.jsx)(qi,{label:b(r?`i18n.liveSync`:`i18n.notWatching`),children:(0,E.jsx)(`span`,{"aria-label":b(r?`i18n.liveSync`:`i18n.notWatching`),className:`file-viewer-live-indicator`,style:{background:r?`var(--status-success)`:`var(--border)`,boxShadow:r?`0 0 4px var(--status-success)`:`none`}})}),(0,E.jsxs)(`div`,{className:`file-viewer-controls`,children:[a.length>1&&(0,E.jsx)(`div`,{className:`file-viewer-mode-switch`,"aria-label":b(`i18n.fileViewMode`),children:a.map(e=>{let t=o===e;return(0,E.jsx)(qi,{label:e===`diff`?b(`i18n.compareHead`):void 0,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>s(e),"aria-pressed":t,className:`file-viewer-mode-button`,style:{background:t?`var(--bg-selected)`:`transparent`,color:t?`var(--text)`:`var(--text-muted)`},children:e9[e]})},e)})}),(0,E.jsxs)(`div`,{className:`file-viewer-actions`,children:[o===`source`&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(qi,{label:b(`i18n.mentionSelectedLines`),children:(0,E.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:_,"aria-label":b(`i18n.mentionSelectedLines`),disabled:!g,className:`file-viewer-icon-button`,children:(0,E.jsx)(r9,{})})}),(0,E.jsx)(qi,{label:b(c?`i18n.disableWrap`:`i18n.enableWrap`),children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-label":b(c?`i18n.disableWrap`:`i18n.enableWrap`),"aria-pressed":c,className:`file-viewer-icon-button`,style:{background:c?`var(--bg-selected)`:`transparent`,color:c?`var(--text)`:`var(--text-muted)`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M4 7V4h16v3`}),(0,E.jsx)(`path`,{d:`M9 20h6`}),(0,E.jsx)(`path`,{d:`M12 4v16`})]})})})]}),o===`source`&&h&&!u&&(0,E.jsx)(`a`,{href:s9(e,`download`,y),download:hG(e),"aria-label":b(`i18n.downloadFile`),className:`file-viewer-icon-button`,style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,textDecoration:`none`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})}),!i&&o===`source`&&(0,E.jsx)(`div`,{className:`file-viewer-edit-controls`,style:{display:`flex`,alignItems:`center`,gap:8,marginLeft:8},children:u?(0,E.jsxs)(E.Fragment,{children:[d&&(0,E.jsx)(qi,{label:b(`i18n.unsavedChanges`),children:(0,E.jsx)(`span`,{"aria-label":b(`i18n.unsavedChanges`),style:{color:`var(--status-warning)`,fontWeight:700},children:`●`})}),(0,E.jsx)(qi,{label:b(`i18n.saveFileShortcut`),children:(0,E.jsx)(`button`,{type:`button`,onClick:f,disabled:!d||m===`saving`,"aria-label":b(`i18n.saveFile`),className:`file-viewer-icon-button`,style:{background:d?`var(--accent)`:`transparent`,color:d?`var(--bg)`:`var(--text-muted)`},children:m===`saving`?(0,E.jsx)(oi,{size:p.lg,className:`animate-spin`}):(0,E.jsx)(_i,{size:p.lg})})}),(0,E.jsx)(qi,{label:b(`i18n.cancelEdit`),children:(0,E.jsx)(`button`,{type:`button`,onClick:C,"aria-label":b(`i18n.cancelEdit`),className:`file-viewer-icon-button`,children:(0,E.jsx)(Mi,{size:p.lg})})}),m===`error`&&x&&(0,E.jsx)(`span`,{style:{color:`var(--status-error)`,fontSize:`var(--text-sm)`},children:b(`i18n.saveFailed`,{error:x})}),m===`saved`&&!d&&(0,E.jsx)(`span`,{style:{color:`var(--status-success)`,fontSize:`var(--text-sm)`},children:b(`i18n.saved`)})]}):(0,E.jsx)(qi,{label:b(`i18n.editFile`),children:(0,E.jsx)(`button`,{type:`button`,onClick:S,"aria-label":b(`i18n.editFile`),className:`file-viewer-icon-button`,children:(0,E.jsx)(ui,{size:p.lg})})})}),!i&&(0,E.jsx)(c9,{filePath:e,sourceSessionId:y})]})]})]})}function Lee({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s}){let{isDark:c}=Tr(),{t:l}=N(),[u,f]=(0,d.useState)(null),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(!1),[v,y]=(0,d.useState)(!0),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(`source`),[D,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(!1),j=(0,d.useRef)(0),M=(0,d.useRef)(null),[P,ee]=(0,d.useState)(null),[F,I]=(0,d.useState)(!1),[te,ne]=(0,d.useState)(``),[re,ie]=(0,d.useState)(!1),[ae,L]=(0,d.useState)(`idle`),[R,oe]=(0,d.useState)(null),z=(0,d.useRef)(!1);z.current=F;let se=(0,d.useCallback)(e=>fetch(s9(e,`read`,n)).then(async e=>{let t=await e.json();return t.error?(x(t.error),C(e.status),null):(x(null),C(null),f(t),t)}).catch(e=>(x(String(e)),null)),[n]),ce=(0,d.useCallback)(async e=>{let n=++j.current;if(_(!0),!t){h(null),_(!1);return}try{let r=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${r.toString()}`),a=await i.json();if(n!==j.current)return;h(i.ok&&a.supported&&typeof a.patch==`string`?a:null)}catch{n===j.current&&h(null)}finally{n===j.current&&_(!1)}},[t]);(0,d.useEffect)(()=>{y(!0),x(null),C(null),f(null),h(null),T(s===`diff`?`diff`:`source`),A(!1),I(!1),ne(``),ie(!1),L(`idle`),oe(null),se(e).finally(()=>y(!1))},[e,se]);let{watching:le,closeWatch:ue}=l9(e,n,()=>{z.current||(se(e),ce(e))});(0,d.useEffect)(()=>{ce(e)},[ce,e,o]),(0,d.useEffect)(()=>{u?.language===`markdown`&&s!==`diff`&&T(`preview`)},[u?.language,s]);let de=m?.supported===!0&&typeof m.patch==`string`,fe=de&&m.status===`deleted`;(0,d.useEffect)(()=>{fe&&ue()},[fe,ue]);let pe=(0,d.useMemo)(()=>u?.language===`markdown`?iG(u.content):``,[u]);(0,d.useEffect)(()=>{let e=()=>{let e=M.current;ee(i&&w===`source`&&e?a9(e,window.getSelection()):null)};if(e(),!(!i||w!==`source`))return document.addEventListener(`selectionchange`,e),()=>document.removeEventListener(`selectionchange`,e)},[u?.content,w,i]);let me=(0,d.useCallback)(n=>{!i||!n||i(_G(e,t),n.startLine,n.endLine)},[t,e,i]),he=(0,d.useCallback)(()=>{me(P)},[me,P]);(0,d.useEffect)(()=>{if(!i||w!==`source`)return;let e=e=>{if(e.repeat||e.key.toLowerCase()!==`i`||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest(`input, textarea, [contenteditable='true']`))return;let n=M.current,r=n?a9(n,window.getSelection()):null;r&&(e.preventDefault(),me(r))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,me,i]);let ge=(0,d.useCallback)(()=>{ne(u?.content??``),ie(!1),L(`idle`),oe(null),I(!0)},[u?.content]),_e=(0,d.useCallback)(()=>{I(!1),ie(!1),L(`idle`),oe(null),se(e)},[e,se]),ve=(0,d.useCallback)(e=>{ne(e),ie(e!==(u?.content??``))},[u?.content]),ye=(0,d.useCallback)(async()=>{if(re){L(`saving`),oe(null);try{await Q7(e,te),f(e=>e&&{...e,content:te}),ie(!1),L(`saved`),a?.(e)}catch(e){L(`error`),oe(e instanceof Error?e.message:String(e))}}},[re,te,e,a]),be=u?.content??``;if((0,d.useEffect)(()=>{O(!1)},[be]),(0,d.useEffect)(()=>{if((fe?`diff`:w)!==`source`||D)return;let e=setTimeout(()=>O(!0),0);return()=>clearTimeout(e)},[fe,w,D]),v||w===`diff`&&g)return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,color:`var(--text-muted)`,fontSize:`var(--text-lg)`},children:[(0,E.jsx)(oi,{size:p.lg,className:`animate-spin`,"aria-hidden":`true`}),l(`i18n.loading`)]});if(b&&!fe)return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:24,color:`var(--status-error)`,fontSize:`var(--text-lg)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{children:S===413?l(`files.fileTooLargeForPreview`,{limit:d9(B7)}):b}),S===413&&(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]});if(!u&&!fe)return null;let xe=u?.language??`text`,Se=xe===`html`,Ce=xe===`markdown`,we=Se||Ce,Te=gG(e),Ee=be.split(`
|
|
495
|
+
`)}),n.length>0&&(0,E.jsx)(`div`,{"data-testid":`widget-bound-messages`,style:{display:`flex`,flexWrap:`wrap`,gap:6,paddingTop:8,borderTop:`1px solid var(--border)`,flexShrink:0},children:n.map((t,n)=>(0,E.jsx)(hY,{msg:t,onSend:o,onFillInput:s,testId:`widget-send-${e.key}-${n}`},n))})]})}),m&&(0,E.jsx)(`div`,{"data-testid":`widget-collapse-trail`,style:{position:`fixed`,inset:0,zIndex:70,pointerEvents:`none`},children:(0,E.jsx)(`svg`,{width:`100%`,height:`100%`,style:{position:`absolute`,inset:0},children:(0,E.jsx)(`circle`,{ref:g,r:28,fill:`var(--accent)`,fillOpacity:.7})})})]})}var B7=262144,V7=10485760,H7={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,bmp:`image/bmp`,ico:`image/x-icon`,avif:`image/avif`},U7={mp3:`audio/mpeg`,wav:`audio/wav`,ogg:`audio/ogg`,oga:`audio/ogg`,opus:`audio/ogg`,m4a:`audio/mp4`,aac:`audio/aac`,flac:`audio/flac`,weba:`audio/webm`,webm:`audio/webm`};function W7(e){return e.replace(/\\/g,`/`).split(`/`).pop()??``}function G7(e){return W7(e).toLowerCase().split(`.`).pop()??``}function K7(e){return H7[G7(e)]??null}function q7(e){return U7[G7(e)]??null}function J7(e){let t=G7(e);return t===`pdf`||t===`docx`?t:null}function Y7(e){return K7(e)!==null}function X7(e){return q7(e)!==null}function Z7(e){return J7(e)!==null}async function Q7(e,t){let n=e.split(/[\\/]/).filter(Boolean),r=n.pop();if(!r)throw Error(`Invalid file path`);let i=n.join(`/`)||`/`,a=new FormData;a.append(`files`,new File([t],r,{type:`text/plain`}));let o=await fetch(`/api/files/${mG(i)}?type=upload&conflict=overwrite`,{method:`POST`,body:a});if(!o.ok){let e=`Save failed (${o.status})`;try{let t=await o.json();t?.error&&(e=t.error)}catch{}throw Error(e)}}var $7=(0,d.lazy)(()=>l0(()=>import(`./CodeMirrorEditor-BsodzoJM.js`),__vite__mapDeps([20,1]))),e9={source:`Source`,preview:`Preview`,diff:`Diff`},t9={fontFamily:`var(--font-mono)`,fontSize:`var(--text-lg)`,lineHeight:1.6},n9={width:48,minWidth:48,padding:`0 10px`,textAlign:`right`,color:`var(--text-dim)`,background:`var(--bg-panel)`,borderRight:`1px solid var(--border)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,fontStyle:`normal`,fontVariantNumeric:`tabular-nums`,lineHeight:`20.8px`,userSelect:`none`,flexShrink:0,verticalAlign:`top`};function r9(){return(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,E.jsx)(`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`})]})}function i9(e){return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest(`.file-source-line[data-line-number]`)??null}function a9(e,t){if(!t||t.isCollapsed||t.rangeCount===0)return null;let n=t.getRangeAt(0);if(!e.contains(n.startContainer)||!e.contains(n.endContainer))return null;let r=i9(n.startContainer),i=i9(n.endContainer);if(!r||!i||!e.contains(r)||!e.contains(i))return null;let a=Number(r.dataset.lineNumber),o=Number(i.dataset.lineNumber);if(!Number.isInteger(a)||!Number.isInteger(o))return null;if(a<o){let e=r.querySelector(`.file-source-line-content`);if(e?.contains(n.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(n.startContainer,n.startOffset),t.toString().length===0){let e=r.nextElementSibling;e instanceof HTMLElement&&e.matches(`.file-source-line[data-line-number]`)&&(r=e,a=Number(r.dataset.lineNumber))}}let t=i.querySelector(`.file-source-line-content`);if(t?.contains(n.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(n.endContainer,n.endOffset),e.toString().length===0){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(`.file-source-line[data-line-number]`)&&(i=e,o=Number(i.dataset.lineNumber))}}}return a>o?null:{startLine:a,endLine:o}}function o9({rows:e,stylesheet:t,useInlineStyles:n,wrapLines:r}){return e.map((e,i)=>{let a=e.children??[],o=a[0]?.properties?.className,s=Array.isArray(o)&&o.includes(`react-syntax-highlighter-line-number`),c=s?a[0]:null,l=s?a.slice(1):a;return(0,E.jsxs)(`span`,{className:`file-source-line`,"data-line-number":i+1,style:{display:`flex`,minWidth:`100%`},children:[c&&p6({node:c,stylesheet:t,useInlineStyles:n,key:`source-line-number-${i}`}),(0,E.jsx)(`span`,{className:`file-source-line-content`,style:{flex:`1 1 auto`,minWidth:0,overflowWrap:r?`anywhere`:`normal`,whiteSpace:r?`pre-wrap`:`pre`},children:l.map((e,r)=>p6({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${i}-${r}`}))})]},`source-line-${i}`)})}function s9(e,t,n,r={}){let i=mG(e),a=new URLSearchParams({type:t});n&&a.set(`sessionId`,n);for(let[e,t]of Object.entries(r))t!==void 0&&a.set(e,String(t));return`/api/files/${i}?${a.toString()}`}function c9({filePath:e,sourceSessionId:t}){let{t:n}=N();return(0,E.jsx)(qi,{label:n(`i18n.downloadFile`),children:(0,E.jsx)(`a`,{href:s9(e,`download`,t),download:hG(e),"aria-label":n(`i18n.downloadFile`),className:`file-viewer-icon-button`,children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})})})}function l9(e,t,n){let[r,i]=(0,d.useState)(!1),a=(0,d.useRef)(n);(0,d.useEffect)(()=>{a.current=n});let o=(0,d.useRef)(null);return(0,d.useEffect)(()=>(i(!1),o.current?.(),o.current=dn({ch:`watch`,filePath:e},e=>{e.event===`connected`?i(!0):e.event===`error`?i(!1):a.current(e)}),()=>{o.current?.(),o.current=null}),[e]),{watching:r,closeWatch:(0,d.useCallback)(()=>{o.current?.(),o.current=null,i(!1)},[])}}function u9({filePath:e,cwd:t,extLabel:n,watching:r,sourceSessionId:i,ellipsis:a,children:o}){let{t:s}=N();return(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,padding:`4px 16px`,borderBottom:`1px solid var(--border)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,background:`var(--bg)`,flexShrink:0},children:[(0,E.jsx)(`span`,{style:{fontFamily:`var(--font-mono)`,...a?{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`}:{}},title:e,children:_G(e,t)}),(0,E.jsx)(`span`,{style:{marginLeft:`auto`},children:n}),o,(0,E.jsxs)(`span`,{title:s(r?`i18n.liveSync`:`i18n.notWatching`),style:{display:`flex`,alignItems:`center`,gap:4,color:r?`var(--status-success)`:`var(--text-dim)`},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:r?`var(--status-success)`:`var(--border)`,display:`inline-block`,boxShadow:r?`0 0 4px var(--status-success)`:`none`}}),r?`live`:`static`]}),(0,E.jsx)(c9,{filePath:e,sourceSessionId:i})]})}function d9(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function f9(e){let t=kZ(e);return t?t.flatMap(e=>e.rows.flatMap(e=>{if(e.type===`hunk`)return[];if(e.left.type===`context`&&e.right.type===`context`)return[{type:`unchanged`,text:e.right.text,oldLineNo:e.left.lineNo,newLineNo:e.right.lineNo}];let t=[];return e.left.type===`removed`&&t.push({type:`removed`,text:e.left.text,oldLineNo:e.left.lineNo,newLineNo:null}),e.right.type===`added`&&t.push({type:`added`,text:e.right.text,oldLineNo:null,newLineNo:e.right.lineNo}),t})):[]}function p9({patch:e}){let{t}=N(),n=f9(e);if(!n.some(e=>e.type!==`unchanged`))return(0,E.jsx)(`div`,{style:{padding:`12px 16px`,fontSize:`var(--text-base)`,color:`var(--text-dim)`,fontFamily:`var(--font-mono)`},children:t(`i18n.noChanges`)});let r=new Set(n.flatMap((e,t)=>e.type===`unchanged`?[]:[t])),i=new Set;for(let e of r)for(let t=Math.max(0,e-3);t<=Math.min(n.length-1,e+3);t++)i.add(t);let a=[],o=0;for(;o<n.length;)if(i.has(o)){let e=[];for(;o<n.length&&i.has(o);)e.push(n[o]),o++;a.push({hidden:!1,lines:e})}else{let e=0;for(;o<n.length&&!i.has(o);)e++,o++;a.push({hidden:!0,count:e})}return(0,E.jsx)(`div`,{className:`file-diff-view`,style:{width:`max-content`,minWidth:`100%`,...t9},children:a.map((e,t)=>{if(e.hidden)return(0,E.jsxs)(`div`,{style:{padding:`2px 16px`,color:`var(--text-dim)`,background:`var(--bg-panel)`,fontSize:`var(--text-sm)`,borderTop:`1px solid var(--border)`,borderBottom:`1px solid var(--border)`},children:[`... `,e.count,` unchanged lines ...`]},t);let n=e.lines.map((e,t)=>{let n=e.type===`added`?`color-mix(in srgb, var(--status-success) 12%, transparent)`:e.type===`removed`?`color-mix(in srgb, var(--status-error) 14%, transparent)`:`transparent`,r=e.type===`added`?`+`:e.type===`removed`?`-`:` `,i=e.type===`added`?`var(--status-success)`:e.type===`removed`?`var(--status-error)`:`var(--text-dim)`;return(0,E.jsxs)(`div`,{className:`file-diff-line`,style:{display:`flex`,minWidth:`100%`,background:n,borderLeft:e.type===`added`?`3px solid var(--status-success)`:e.type===`removed`?`3px solid var(--status-error)`:`3px solid transparent`},children:[(0,E.jsx)(`span`,{style:n9,children:e.type===`removed`?e.oldLineNo:e.newLineNo}),(0,E.jsx)(`span`,{style:{minWidth:16,padding:`0 6px`,color:i,userSelect:`none`,flexShrink:0,fontWeight:600},children:r}),(0,E.jsx)(`span`,{className:`file-diff-line-content`,style:{flexShrink:0,padding:`0 8px 0 0`,whiteSpace:`pre`,color:`var(--text)`},children:e.text||`\xA0`})]},t)});return(0,E.jsx)(`div`,{children:n},t)})})}function m9({filePath:e,cwd:t,sourceSessionId:n}){let[r,i]=(0,d.useState)(0),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(null),f=hG(e).toLowerCase().split(`.`).pop()??``;Wi(()=>{i(0),o(null),c(null),u(null)},[e,n]);let{watching:p}=l9(e,n,e=>{typeof e.size==`number`&&o(e.size),i(e=>e+1)}),m=s9(e,`read`,n,r?{v:r}:void 0),h=a==null?null:d9(a);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsxs)(u9,{filePath:e,cwd:t,extLabel:f||`image`,watching:p,sourceSessionId:n,children:[s&&(0,E.jsxs)(`span`,{children:[s.w,` × `,s.h]}),h&&(0,E.jsx)(`span`,{children:h})]}),(0,E.jsx)(`div`,{style:{flex:1,overflow:`auto`,backgroundColor:`var(--bg-panel)`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:16,backgroundImage:`linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)`,backgroundSize:`16px 16px`,backgroundPosition:`0 0, 0 8px, 8px -8px, -8px 0px`},children:l?(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:4},children:[(0,E.jsx)(`div`,{style:{color:`var(--status-error)`,fontSize:`var(--text-lg)`},children:l}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}):(0,E.jsx)(`img`,{src:m,alt:e,onLoad:e=>{let t=e.currentTarget;c({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>u(`Failed to load image`),style:{maxWidth:`100%`,maxHeight:`100%`,objectFit:`contain`,boxShadow:`0 2px 8px var(--shadow-color)`}})})]})}function h9({filePath:e,cwd:t,sourceSessionId:n}){let[r,i]=(0,d.useState)(0),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(null),f=hG(e).toLowerCase().split(`.`).pop()??``;Wi(()=>{i(0),o(null),c(null),u(null)},[e,n]);let{watching:p}=l9(e,n,e=>{typeof e.size==`number`&&o(e.size),c(null),u(null),i(e=>e+1)}),m=s9(e,`read`,n,r?{v:r}:void 0);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsxs)(u9,{filePath:e,cwd:t,extLabel:f||`audio`,watching:p,sourceSessionId:n,children:[s!=null&&(0,E.jsx)(`span`,{children:Wt(s)}),a!=null&&(0,E.jsx)(`span`,{children:d9(a)})]}),(0,E.jsx)(`div`,{style:{flex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:24,background:`var(--bg-panel)`},children:(0,E.jsxs)(`div`,{style:{width:`min(680px, 100%)`},children:[l&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{style:{color:`var(--status-error)`,fontSize:`var(--text-lg)`,marginBottom:12,textAlign:`center`},children:l}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}),(0,E.jsx)(`audio`,{controls:!0,preload:`metadata`,src:m,onLoadedMetadata:e=>c(e.currentTarget.duration),onError:()=>u(`Failed to load audio`),style:{width:`100%`}},m)]})})]})}function g9({filePath:e,cwd:t,sourceSessionId:n}){let{t:r}=N(),[i,a]=(0,d.useState)(0),[o,s]=(0,d.useState)(null),[c,l]=(0,d.useState)(null),u=G7(e),f=u===`pdf`,p=f?s9(e,`read`,n,i?{v:i}:void 0):s9(e,`preview`,n,i?{v:i}:void 0);(0,d.useEffect)(()=>{a(0),s(null),l(null),fetch(s9(e,`meta`,n)).then(e=>e.json()).then(e=>{e.error&&l(e.error),typeof e.size==`number`&&(s(e.size),!f&&e.size>10485760&&l(r(`files.docTooLargeForPreview`,{limit:d9(V7)})))}).catch(e=>l(String(e)))},[e,f,n,r]);let{watching:m}=l9(e,n,e=>{if(typeof e.size==`number`&&(s(e.size),!f&&e.size>10485760)){l(r(`files.docTooLargeForPreview`,{limit:d9(V7)}));return}l(null),a(e=>e+1)});return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsx)(u9,{filePath:e,cwd:t,extLabel:u===`docx`?`docx preview`:`pdf`,watching:m,sourceSessionId:n,ellipsis:!0,children:o!=null&&(0,E.jsx)(`span`,{children:d9(o)})}),(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,background:`var(--bg-panel)`},children:c?(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:24,color:`var(--status-error)`,fontSize:`var(--text-lg)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{children:c}),(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]}):(0,E.jsx)(`iframe`,{src:p,sandbox:f?void 0:`allow-same-origin`,title:r(`i18n.previewFile`,{file:hG(e)}),style:{width:`100%`,height:`100%`,border:`none`,background:f?`var(--bg)`:`#eef1f5`}},p)})]})}function _9({filePath:e,sourceSessionId:t,cwd:n}){let{t:r}=N(),[i,a]=(0,d.useState)(!1),[o,s]=(0,d.useState)(null),c=typeof n==`string`&&/^[a-zA-Z]:[\\/]/.test(n)||typeof n==`string`&&n.startsWith(`\\\\`),l=(0,d.useCallback)(async n=>{a(!0),s(null);try{let i=await fetch(s9(e,`open`,t,n?{chooseApp:1}:void 0),{method:`POST`}),a=await i.json().catch(()=>null);i.ok?s({ok:!0,text:r(`files.openLaunched`)}):s({ok:!1,text:a?.error??`HTTP ${i.status}`})}catch(e){s({ok:!1,text:String(e)})}finally{a(!1)}},[e,t,r]);return(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,gap:10,marginTop:16},children:[o&&(0,E.jsx)(`div`,{style:{color:o.ok?`var(--text-muted)`:`var(--status-error)`,fontSize:`var(--text-sm)`,maxWidth:460,textAlign:`center`,lineHeight:1.5},children:o.text}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,E.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>l(!1),className:`file-viewer-mode-button file-open-action-button`,children:r(`files.openInSystemApp`)}),c&&(0,E.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>l(!0),className:`file-viewer-mode-button file-open-action-button`,children:r(`files.chooseOtherApp`)})]})]})}function v9({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s}){return Y7(e)?(0,E.jsx)(m9,{filePath:e,cwd:t,sourceSessionId:n}):X7(e)?(0,E.jsx)(h9,{filePath:e,cwd:t,sourceSessionId:n}):Z7(e)?(0,E.jsx)(g9,{filePath:e,cwd:t,sourceSessionId:n}):(0,E.jsx)(Lee,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s})}function Iee({filePath:e,cwd:t,metadata:n,watching:r,isDeletedDiff:i,displayModes:a,effectiveDisplayMode:o,setDisplayMode:s,wrapLines:c,setWrapLines:l,editMode:u,dirty:d,handleSave:f,saveState:m,highlightReady:h,selectedLineRange:g,handleMentionSelectedLines:_,fileContent:v,sourceSessionId:y,t:b,saveError:x,enterEdit:S,cancelEdit:C}){return(0,E.jsxs)(`div`,{className:`file-viewer-toolbar`,style:{display:`flex`,alignItems:`center`,gap:8,padding:`5px 12px`,borderBottom:`1px solid var(--border)`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,background:`var(--bg)`,flexShrink:0},children:[(0,E.jsx)(qi,{label:e,children:(0,E.jsx)(`span`,{className:`file-viewer-path`,style:{fontFamily:`var(--font-mono)`},children:_G(e,t)})}),(0,E.jsx)(qi,{label:n,children:(0,E.jsx)(`span`,{className:`file-viewer-meta`,children:n})}),!i&&(0,E.jsx)(qi,{label:b(r?`i18n.liveSync`:`i18n.notWatching`),children:(0,E.jsx)(`span`,{"aria-label":b(r?`i18n.liveSync`:`i18n.notWatching`),className:`file-viewer-live-indicator`,style:{background:r?`var(--status-success)`:`var(--border)`,boxShadow:r?`0 0 4px var(--status-success)`:`none`}})}),(0,E.jsxs)(`div`,{className:`file-viewer-controls`,children:[a.length>1&&(0,E.jsx)(`div`,{className:`file-viewer-mode-switch`,"aria-label":b(`i18n.fileViewMode`),children:a.map(e=>{let t=o===e;return(0,E.jsx)(qi,{label:e===`diff`?b(`i18n.compareHead`):void 0,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>s(e),"aria-pressed":t,className:`file-viewer-mode-button`,style:{background:t?`var(--bg-selected)`:`transparent`,color:t?`var(--text)`:`var(--text-muted)`},children:e9[e]})},e)})}),(0,E.jsxs)(`div`,{className:`file-viewer-actions`,children:[o===`source`&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(qi,{label:b(`i18n.mentionSelectedLines`),children:(0,E.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:_,"aria-label":b(`i18n.mentionSelectedLines`),disabled:!g,className:`file-viewer-icon-button`,children:(0,E.jsx)(r9,{})})}),(0,E.jsx)(qi,{label:b(c?`i18n.disableWrap`:`i18n.enableWrap`),children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-label":b(c?`i18n.disableWrap`:`i18n.enableWrap`),"aria-pressed":c,className:`file-viewer-icon-button`,style:{background:c?`var(--bg-selected)`:`transparent`,color:c?`var(--text)`:`var(--text-muted)`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M4 7V4h16v3`}),(0,E.jsx)(`path`,{d:`M9 20h6`}),(0,E.jsx)(`path`,{d:`M12 4v16`})]})})})]}),o===`source`&&h&&!u&&(0,E.jsx)(`a`,{href:s9(e,`download`,y),download:hG(e),"aria-label":b(`i18n.downloadFile`),className:`file-viewer-icon-button`,style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,textDecoration:`none`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})}),!i&&o===`source`&&(0,E.jsx)(`div`,{className:`file-viewer-edit-controls`,style:{display:`flex`,alignItems:`center`,gap:8,marginLeft:8},children:u?(0,E.jsxs)(E.Fragment,{children:[d&&(0,E.jsx)(qi,{label:b(`i18n.unsavedChanges`),children:(0,E.jsx)(`span`,{"aria-label":b(`i18n.unsavedChanges`),style:{color:`var(--status-warning)`,fontWeight:700},children:`●`})}),(0,E.jsx)(qi,{label:b(`i18n.saveFileShortcut`),children:(0,E.jsx)(`button`,{type:`button`,onClick:f,disabled:!d||m===`saving`,"aria-label":b(`i18n.saveFile`),className:`file-viewer-icon-button`,style:{background:d?`var(--accent)`:`transparent`,color:d?`var(--bg)`:`var(--text-muted)`},children:m===`saving`?(0,E.jsx)(oi,{size:p.lg,className:`animate-spin`}):(0,E.jsx)(_i,{size:p.lg})})}),(0,E.jsx)(qi,{label:b(`i18n.cancelEdit`),children:(0,E.jsx)(`button`,{type:`button`,onClick:C,"aria-label":b(`i18n.cancelEdit`),className:`file-viewer-icon-button`,children:(0,E.jsx)(Mi,{size:p.lg})})}),m===`error`&&x&&(0,E.jsx)(`span`,{style:{color:`var(--status-error)`,fontSize:`var(--text-sm)`},children:b(`i18n.saveFailed`,{error:x})}),m===`saved`&&!d&&(0,E.jsx)(`span`,{style:{color:`var(--status-success)`,fontSize:`var(--text-sm)`},children:b(`i18n.saved`)})]}):(0,E.jsx)(qi,{label:b(`i18n.editFile`),children:(0,E.jsx)(`button`,{type:`button`,onClick:S,"aria-label":b(`i18n.editFile`),className:`file-viewer-icon-button`,children:(0,E.jsx)(ui,{size:p.lg})})})}),!i&&(0,E.jsx)(c9,{filePath:e,sourceSessionId:y})]})]})]})}function Lee({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:r,onMentionLines:i,onSaved:a,gitRefreshKey:o,initialDisplayMode:s}){let{isDark:c}=Tr(),{t:l}=N(),[u,f]=(0,d.useState)(null),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(!1),[v,y]=(0,d.useState)(!0),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(`source`),[D,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(!1),j=(0,d.useRef)(0),M=(0,d.useRef)(null),[P,ee]=(0,d.useState)(null),[F,I]=(0,d.useState)(!1),[te,ne]=(0,d.useState)(``),[re,ie]=(0,d.useState)(!1),[ae,L]=(0,d.useState)(`idle`),[R,oe]=(0,d.useState)(null),z=(0,d.useRef)(!1);z.current=F;let se=(0,d.useCallback)(e=>fetch(s9(e,`read`,n)).then(async e=>{let t=await e.json();return t.error?(x(t.error),C(e.status),null):(x(null),C(null),f(t),t)}).catch(e=>(x(String(e)),null)),[n]),ce=(0,d.useCallback)(async e=>{let n=++j.current;if(_(!0),!t){h(null),_(!1);return}try{let r=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${r.toString()}`),a=await i.json();if(n!==j.current)return;h(i.ok&&a.supported&&typeof a.patch==`string`?a:null)}catch{n===j.current&&h(null)}finally{n===j.current&&_(!1)}},[t]);(0,d.useEffect)(()=>{y(!0),x(null),C(null),f(null),h(null),T(s===`diff`?`diff`:`source`),A(!1),I(!1),ne(``),ie(!1),L(`idle`),oe(null),se(e).finally(()=>y(!1))},[e,se]);let{watching:le,closeWatch:ue}=l9(e,n,()=>{z.current||(se(e),ce(e))});(0,d.useEffect)(()=>{ce(e)},[ce,e,o]),(0,d.useEffect)(()=>{u?.language===`markdown`&&s!==`diff`&&T(`preview`)},[u?.language,s]);let de=m?.supported===!0&&typeof m.patch==`string`,fe=de&&m.status===`deleted`;(0,d.useEffect)(()=>{fe&&ue()},[fe,ue]);let pe=(0,d.useMemo)(()=>u?.language===`markdown`?iG(u.content):``,[u]);(0,d.useEffect)(()=>{let e=()=>{let e=M.current;ee(i&&w===`source`&&e?a9(e,window.getSelection()):null)};if(e(),!(!i||w!==`source`))return document.addEventListener(`selectionchange`,e),()=>document.removeEventListener(`selectionchange`,e)},[u?.content,w,i]);let me=(0,d.useCallback)(n=>{!i||!n||i(_G(e,t),n.startLine,n.endLine)},[t,e,i]),he=(0,d.useCallback)(()=>{me(P)},[me,P]);(0,d.useEffect)(()=>{if(!i||w!==`source`)return;let e=e=>{if(e.repeat||e.key.toLowerCase()!==`i`||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest(`input, textarea, [contenteditable='true']`))return;let n=M.current,r=n?a9(n,window.getSelection()):null;r&&(e.preventDefault(),me(r))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,me,i]);let ge=(0,d.useCallback)(()=>{ne(u?.content??``),ie(!1),L(`idle`),oe(null),I(!0)},[u?.content]),_e=(0,d.useCallback)(()=>{I(!1),ie(!1),L(`idle`),oe(null),se(e)},[e,se]),ve=(0,d.useCallback)(e=>{ne(e),ie(e!==(u?.content??``))},[u?.content]),ye=(0,d.useCallback)(async()=>{if(re){L(`saving`),oe(null);try{await Q7(e,te),f(e=>e&&{...e,content:te}),ie(!1),L(`saved`),a?.(e)}catch(e){L(`error`),oe(e instanceof Error?e.message:String(e))}}},[re,te,e,a]),be=u?.content??``;if((0,d.useEffect)(()=>{O(!1)},[be]),(0,d.useEffect)(()=>{if((fe?`diff`:w)!==`source`||D)return;let e=setTimeout(()=>O(!0),0);return()=>clearTimeout(e)},[fe,w,D]),v||w===`diff`&&g)return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,color:`var(--text-muted)`,fontSize:`var(--text-lg)`},children:[(0,E.jsx)(oi,{size:p.lg,className:`animate-spin`,"aria-hidden":`true`}),l(`i18n.loading`)]});if(b&&!fe)return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,padding:24,color:`var(--status-error)`,fontSize:`var(--text-lg)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{children:S===413?l(`files.fileTooLargeForPreview`,{limit:d9(B7)}):b}),S===413&&(0,E.jsx)(_9,{filePath:e,sourceSessionId:n,cwd:t})]});if(!u&&!fe)return null;let xe=u?.language??`text`,Se=xe===`html`,Ce=xe===`markdown`,we=Se||Ce,Te=gG(e),Ee=be.split(`
|
|
496
496
|
`),De=fe?`diff`:w,Oe=fe?[`diff`]:[`source`,...we?[`preview`]:[],`diff`],ke=fe?l(`files.deleted`):`${xe} · ${Ee.length} lines · ${d9(u.size)}`;return(0,E.jsxs)(`div`,{className:`file-viewer-shell`,style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[(0,E.jsx)(Iee,{filePath:e,cwd:t,metadata:ke,watching:le,isDeletedDiff:fe,displayModes:Oe,effectiveDisplayMode:De,setDisplayMode:T,wrapLines:k,setWrapLines:A,editMode:F,dirty:re,handleSave:ye,saveState:ae,saveError:R,enterEdit:ge,cancelEdit:_e,highlightReady:D,selectedLineRange:P,handleMentionSelectedLines:he,fileContent:be,sourceSessionId:n,t:l}),(0,E.jsxs)(`div`,{ref:M,className:`file-viewer-content`,style:{flex:1,overflow:`auto`,paddingRight:4,background:`var(--bg)`},children:[De===`source`&&(0,E.jsx)(`div`,{className:`file-viewer-source`,style:{display:`block`,height:`100%`,overflow:`auto`,background:`var(--bg)`},children:F?(0,E.jsx)(d.Suspense,{fallback:(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-muted)`},children:(0,E.jsx)(oi,{size:p.lg,className:`animate-spin`,"aria-hidden":`true`})}),children:(0,E.jsx)($7,{initialValue:te,language:xe,isDark:c,onChange:ve,onSave:ye},e)}):D?(0,E.jsx)(l8,{className:k?`file-source-view is-wrapped`:`file-source-view`,language:xe===`text`?`plaintext`:xe,style:c?N8:M8,showLineNumbers:!0,lineNumberStyle:{...n9},customStyle:{margin:0,padding:0,border:0,background:`var(--bg)`,...t9,width:k?`100%`:`max-content`,minWidth:`100%`,minHeight:`100%`,overflow:`visible`},codeTagProps:{style:{fontFamily:`var(--font-mono)`,overflowWrap:k?`anywhere`:`normal`}},renderer:e=>(0,E.jsx)(o9,{...e,wrapLines:k}),wrapLongLines:k,children:be}):(0,E.jsx)(`pre`,{className:k?`file-source-view is-wrapped`:`file-source-view`,style:{margin:0,padding:0,border:0,background:`var(--bg)`,...t9,fontFamily:`var(--font-mono)`,whiteSpace:k?`pre-wrap`:`pre`,overflowWrap:k?`anywhere`:`normal`,width:k?`100%`:`max-content`,minWidth:`100%`,minHeight:`100%`,overflow:`visible`},children:be})}),De===`diff`&&de?(0,E.jsx)(p9,{patch:m.patch}):De===`diff`?(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-muted)`,fontSize:`var(--text-lg)`},children:l(`i18n.noChanges`)}):Se&&De===`preview`?(0,E.jsx)(`iframe`,{srcDoc:be,sandbox:`allow-scripts`,style:{width:`100%`,height:`100%`,border:`none`,background:`var(--bg)`},title:l(`i18n.htmlPreview`)}):Ce&&De===`preview`?(0,E.jsx)(`div`,{className:`markdown-body markdown-file-preview`,style:{padding:`24px 32px`},children:(0,E.jsx)(Vk,{remarkPlugins:lG,rehypePlugins:dG,components:{code({className:e,children:t,...n}){let r=e?.replace(`language-`,``).toLowerCase()??``,i=String(t);return e?.includes(`language-`)||i.includes(`
|
|
497
|
-
`)?r===`mermaid`?(0,E.jsx)(R8,{code:i.replace(/\n$/,``),defaultPreview:!0}):(0,E.jsx)(H8,{code:i.replace(/\n$/,``),lang:r}):(0,E.jsx)(`code`,{className:e,...n,children:t})},pre({children:e}){return(0,E.jsx)(E.Fragment,{children:e})},a({href:e,children:t,...n}){return delete n.node,(0,E.jsx)(BG,{href:e,markdownDir:Te,onOpenFile:r,...n,children:t})},img({src:e,alt:r,...i}){delete i.node;let a=typeof e==`string`?RG(e,Te,t??Te):null,o=a?s9(a,`read`,n):e;return(0,E.jsx)(`img`,{src:o,alt:r??``,loading:`lazy`,...i})}},children:pe})}):null]})]})}function Ree({cwd:e,busy:t,error:n,onCancel:r,onConfirm:i}){let{t:a}=N();return(0,E.jsx)(jS,{open:!0,onOpenChange:e=>{!e&&!t&&r()},children:(0,E.jsxs)(FS,{className:`w-[440px] gap-0 overflow-hidden rounded-lg p-0`,style:{zIndex:1100,maxWidth:`100%`},showCloseButton:!1,onPointerDownOutside:e=>{t&&e.preventDefault()},onEscapeKeyDown:e=>{t&&e.preventDefault()},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,gap:12,padding:`18px 18px 14px`},children:[(0,E.jsxs)(`svg`,{width:p[`5xl`],height:p[`5xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--status-warning)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0,marginTop:1},children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`m9 12 2 2 4-4`})]}),(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(IS,{style:{fontSize:`var(--text-2xl)`,fontWeight:700,color:`var(--text)`,lineHeight:1.4},children:a(`trust.dialogTitle`)}),(0,E.jsx)(LS,{style:{marginTop:7,fontSize:`var(--text-base)`,lineHeight:1.6,color:`var(--text-muted)`},children:a(`trust.dialogBody`)}),(0,E.jsx)(`code`,{style:{display:`block`,marginTop:10,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:5,background:`var(--bg)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,overflowWrap:`anywhere`},children:e}),n&&(0,E.jsx)(`div`,{role:`alert`,style:{marginTop:10,color:`var(--status-error)`,fontSize:`var(--text-base)`,lineHeight:1.5},children:n})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,padding:`10px 18px`,borderTop:`1px solid var(--border)`},children:[(0,E.jsx)(AS,{type:`button`,variant:`outline`,onClick:r,disabled:t,className:`h-8 px-3 text-xs`,children:a(`trust.cancel`)}),(0,E.jsx)(AS,{type:`button`,onClick:i,disabled:t,className:`h-8 px-3 text-xs`,style:{cursor:t?`wait`:`pointer`},children:a(t?`trust.trusting`:`trust.trustProject`)})]})]})})}function zee({onCancel:e,onSelect:t,busy:n=!1,error:r}){let{t:i}=N(),[a,o]=(0,d.useState)(!0),[s,c]=(0,d.useState)(``),[l,u]=(0,d.useState)(null),[f,m]=(0,d.useState)(``),[h,g]=(0,d.useState)([]),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)(!0),T=(0,d.useRef)(null),D=(0,d.useCallback)(async e=>{w(!0),S(null);try{let t=await bG(e),n=t.path??e??`/`;c(n),u(t.parentPath??null),m(n),g(t.directories??[]),v(t.drives??null),b(``)}catch(e){S(e instanceof Error?e.message:String(e))}finally{w(!1)}},[]);(0,d.useEffect)(()=>{D()},[D]);let O=e=>{e.preventDefault();let t=f.trim();t&&D(t)},k=f.trim()!==s,A=!!s&&!k&&!n,j=!!l||wG(s),M=y.trim().toLowerCase(),P=e=>!M||e.toLowerCase().includes(M),ee=_===null?[]:_.filter(e=>P(e.name)||P(e.path)),F=h.filter(e=>P(e.name));return(0,E.jsx)(jS,{open:a,onOpenChange:t=>{!t&&!n&&(o(!1),e())},children:(0,E.jsxs)(FS,{className:`directory-picker-light flex w-[520px] max-w-[calc(100vw-16px)] flex-col gap-0 overflow-hidden p-0`,style:{height:`min(620px, calc(100dvh - 16px))`},showCloseButton:!1,onPointerDownOutside:e=>{n&&e.preventDefault()},onEscapeKeyDown:e=>{n&&e.preventDefault()},onOpenAutoFocus:e=>{e.preventDefault(),T.current?.focus()},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,flexShrink:0,padding:`12px 18px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(IS,{style:{fontWeight:700,fontSize:`var(--text-2xl)`,color:`var(--text)`},children:i(`directoryPicker.selectDirectory`)}),(0,E.jsx)(NS,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,disabled:n,title:i(`i18n.close`),"aria-label":i(`i18n.close`),style:{padding:`2px 6px`,border:0,background:`none`,color:`var(--text-muted)`,fontSize:`var(--text-5xl)`,lineHeight:1,cursor:n?`default`:`pointer`,opacity:n?.5:1},children:`×`})})]}),(0,E.jsxs)(`form`,{onSubmit:O,style:{display:`flex`,alignItems:`center`,gap:8,flexShrink:0,padding:`10px 14px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`button`,{className:`directory-picker-back`,type:`button`,onClick:()=>void D(l??void 0),disabled:C||!j,title:i(`directoryPicker.goToParent`),"aria-label":i(`directoryPicker.goToParent`),style:{width:36,height:36,padding:0,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`1px solid var(--border)`,borderRadius:6,background:`#ffffff`,color:`var(--text-muted)`,cursor:j?`pointer`:`default`,opacity:j?1:.45},children:(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m18 15-6-6-6 6`})})}),(0,E.jsx)(`label`,{htmlFor:`directory-path`,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:i(`directoryPicker.directoryPath`)}),(0,E.jsx)(yG,{className:`directory-picker-path h-9 flex-1 font-mono text-xs`,id:`directory-path`,type:`text`,ref:T,value:f,placeholder:`/path/to/project or ~/project`,autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>{m(e.target.value),S(null)}}),(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`submit`,disabled:C||!f.trim(),title:i(`directoryPicker.goToDirectory`),style:{minWidth:58,height:36,padding:`0 12px`,border:`1px solid var(--border)`,borderRadius:6,background:`#ffffff`,color:`var(--text-muted)`,cursor:C||!f.trim()?`default`:`pointer`,opacity:C||!f.trim()?.6:1},children:i(`directoryPicker.go`)})]}),(0,E.jsxs)(`div`,{className:`directory-picker-list`,style:{flex:1,minHeight:0,overflow:`auto`,padding:`8px 10px`},children:[C?(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(`directoryPicker.loadingDirectories`)}):_===null?F.length>0?F.map(e=>(0,E.jsxs)(`button`,{className:`directory-picker-entry`,type:`button`,onClick:()=>void D(e.path),title:e.path,style:{width:`100%`,minHeight:30,display:`flex`,alignItems:`center`,gap:7,padding:`5px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(SG,{}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(M?`directoryPicker.noMatches`:`directoryPicker.noSubdirectories`)}):ee.length>0?ee.map(e=>(0,E.jsxs)(`button`,{className:`directory-picker-entry`,type:`button`,onClick:()=>void D(e.path),title:e.path,style:{width:`100%`,minHeight:34,display:`flex`,alignItems:`center`,gap:7,padding:`6px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(CG,{}),(0,E.jsx)(`span`,{children:e.name})]},e.path)):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(M?`directoryPicker.noMatches`:`directoryPicker.noDrives`)}),(x||r)&&(0,E.jsx)(`div`,{style:{padding:`8px`,color:`var(--status-error)`,fontSize:`var(--text-sm)`},children:x??r})]}),(0,E.jsxs)(`div`,{className:`directory-picker-footer`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:10,flexShrink:0,padding:`10px 18px`,borderTop:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flex:1,minWidth:0},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`var(--text-dim)`,flexShrink:0},children:[(0,E.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,E.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),(0,E.jsx)(yG,{className:`directory-picker-search h-8 flex-1`,type:`text`,value:y,placeholder:i(`directoryPicker.search`),"aria-label":i(`directoryPicker.search`),autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>b(e.target.value)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexShrink:0},children:[(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`button`,onClick:e,disabled:n,style:{padding:`6px 14px`,border:`1px solid var(--border)`,borderRadius:6,background:`none`,color:`var(--text-muted)`,cursor:n?`default`:`pointer`,fontSize:`var(--text-lg)`},children:i(`i18n.cancel`)}),(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`button`,onClick:()=>t(s),disabled:!A,title:i(k?`directoryPicker.openBeforeSelecting`:`directoryPicker.selectCurrentDirectory`),style:{padding:`6px 16px`,border:0,borderRadius:6,background:`var(--accent)`,color:`var(--on-accent)`,fontSize:`var(--text-lg)`,fontWeight:600,opacity:A?1:.6,cursor:A?`pointer`:`default`},children:i(n?`i18n.checking`:`directoryPicker.selectThisFolder`)})]})]})]})})}function y9({visible:e=!0,gap:t=4,items:n}){return e?(0,E.jsx)(`div`,{style:{display:`flex`,gap:t,flexShrink:0},children:n.map(e=>(0,E.jsx)(qi,{label:e.title,children:(0,E.jsx)(`button`,{type:`button`,onClick:e.onClick,disabled:e.disabled,"data-testid":e.testId,"aria-label":e.title,"aria-pressed":e.ariaPressed,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:32,height:32,padding:0,background:e.background??`transparent`,border:`1px solid ${e.borderColor??`var(--border)`}`,borderRadius:7,color:e.color??`var(--text-muted)`,cursor:e.disabled?`default`:`pointer`,flexShrink:0,opacity:e.disabled?.6:1,transition:`background 0.12s, color 0.12s, border-color 0.12s`,"--hover-bg":e.danger?`color-mix(in srgb, var(--status-error) 8%, transparent)`:`var(--bg-selected)`,"--hover-color":e.danger?`var(--status-error)`:`var(--accent)`,"--hover-border":e.danger?`color-mix(in srgb, var(--status-error) 35%, transparent)`:`color-mix(in srgb, var(--accent) 35%, transparent)`},className:e.skipHover?void 0:`hover-shift`,children:e.icon})},e.key))}):null}var b9=2;function Bee({scrollStepPx:e=200,wrapperStyle:t,children:n,testId:r,hintTestId:i}){let a=(0,d.useRef)(null),[o,s]=(0,d.useState)({scrollHeight:0,clientHeight:0,scrollTop:0}),c=(0,d.useCallback)(()=>{if(document.hidden)return;let e=a.current;e&&s({scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,scrollTop:e.scrollTop})},[]);(0,d.useLayoutEffect)(()=>{c();let e=a.current;if(!e)return;let t=new ResizeObserver(c);return t.observe(e),()=>t.disconnect()},[c]);let{scrollHeight:l,clientHeight:u,scrollTop:f}=o,p=l-u>20,m=f<=b9,h=f+u>=l-b9,g=t=>{let n=a.current;if(!n)return;let r=Math.max(0,n.scrollHeight-n.clientHeight);n.scrollTo({top:Math.max(0,Math.min(r,n.scrollTop+t*e)),behavior:`smooth`})},_=e=>{let t=a.current;t&&t.scrollTo({top:e===`top`?0:Math.max(0,t.scrollHeight-t.clientHeight),behavior:`smooth`})};return(0,E.jsxs)(`div`,{style:{position:`relative`,...t},children:[(0,E.jsx)(`div`,{ref:a,"data-testid":r,onScroll:c,style:{position:`absolute`,inset:0,overflowY:`auto`,overflowX:`hidden`,padding:0},children:n}),p&&!m&&(0,E.jsx)(hr,{direction:`up`,visible:!0,testId:i?`${i}-scroll-up`:void 0,onHover:()=>g(-1),onClick:()=>_(`top`)}),p&&!h&&(0,E.jsx)(hr,{direction:`down`,visible:!0,testId:i?`${i}-scroll-down`:void 0,onHover:()=>g(1),onClick:()=>_(`bottom`)})]})}function Vee({...e}){return(0,E.jsx)($o,{"data-slot":`collapsible`,...e})}function Hee({...e}){return(0,E.jsx)(Jo,{"data-slot":`collapsible-trigger`,...e})}function Uee({...e}){return(0,E.jsx)(Xo,{"data-slot":`collapsible-content`,...e})}function Wee({title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i=!0,actions:a,expandedFlex:o=`1 1 0`,style:s,children:c}){return(0,E.jsxs)(Vee,{open:n,onOpenChange:r,style:{borderTop:`1px solid var(--border)`,display:`flex`,flexDirection:`column`,flex:n?o:`0 0 auto`,minHeight:0,overflow:`hidden`,...s},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,flexShrink:0,background:`var(--bg-panel)`},children:[(0,E.jsx)(qi,{label:t??e,children:(0,E.jsx)(Hee,{asChild:!0,children:(0,E.jsxs)(`button`,{type:`button`,disabled:!i,style:{display:`flex`,alignItems:`center`,gap:6,flex:`0 0 auto`,height:36,padding:`0 12px`,background:`none`,border:`none`,color:`var(--text-muted)`,cursor:i?`pointer`:`default`,fontSize:`var(--text-base)`,fontWeight:600,letterSpacing:`0.05em`,textTransform:`none`,textAlign:`left`},children:[i&&(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{transform:n?`rotate(90deg)`:`none`,transition:`transform 0.15s`,flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`3 2 7 5 3 8`})}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e})]})})}),a&&(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,marginLeft:`auto`,minWidth:0,gap:6,flexShrink:1,paddingRight:4},children:a})]}),(0,E.jsx)(Uee,{style:{display:`flex`,flexDirection:`column`,minHeight:0,flex:1},children:c})]})}function x9({title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i=!0,actions:a,headerExtra:o,expandedFlex:s=`1 1 0`,scrollStepPx:c=200,testId:l,hintTestId:u,rootTestId:d,scrollStyle:f,style:p,children:m}){return(0,E.jsx)(`div`,{"data-testid":d,style:{display:`flex`,flexDirection:`column`,border:`1px solid var(--border)`,borderRadius:0,background:`var(--bg-panel)`,overflow:`hidden`,...p},children:(0,E.jsxs)(Wee,{title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i,actions:a,expandedFlex:s,style:{borderTop:`none`},children:[o,(0,E.jsx)(Bee,{scrollStepPx:c,wrapperStyle:{flex:1,minHeight:0,...f},testId:l,hintTestId:u,children:m})]})})}function Gee(e){return e.error?e.path.split(/[\\/]/).pop()||e.id:e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12)}var S9=(e,t)=>e.replace(/\\/g,`/`)===t.replace(/\\/g,`/`),C9=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``).replace(/^[a-zA-Z]:/,e=>e.toLowerCase()),w9=`pi-web:unread-session-ids`;function Kee(){if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(w9);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function T9(e){if(!(typeof window>`u`))try{e.size===0?window.localStorage.removeItem(w9):window.localStorage.setItem(w9,JSON.stringify([...e]))}catch{}}function qee(){let[e,t]=(0,d.useState)(()=>Kee());return(0,d.useEffect)(()=>{T9(e)},[e]),{unreadSessionIds:e,setUnreadSessionIds:t}}function Jee(e){let{selectedCwd:t,selectedCwdProp:n,refreshKey:r,setSelectedCwd:i}=e,[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1),[l,u]=(0,d.useState)(!1),[f,p]=(0,d.useState)(``),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(!1),[v,y]=(0,d.useState)(null),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(``),w=(0,d.useRef)(null),T=(0,d.useRef)(null),E=(0,d.useRef)(null);(0,d.useEffect)(()=>{n&&n!==E.current&&(E.current=n,i(n))},[n,i]);let D=(0,d.useCallback)(()=>{c(!1),u(!1),p(``),h(null),y(null),C(``)},[]),[O,k]=(0,d.useState)(0);(0,d.useLayoutEffect)(()=>{if(!t){o(null),x(null);return}let e=!1;return x(t),fetch(`/api/worktrees?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(n=>{if(!e){if(x(null),n.error||!n.projectRoot){o(null);return}o({forCwd:t,projectRoot:n.projectRoot,isGit:n.isGit??!1,isTopLevel:n.isTopLevel??!1,worktrees:n.worktrees??[]})}}).catch(()=>{e||(x(null),o(null))}),()=>{e=!0}},[t,O,r]);let A=(0,d.useCallback)(async()=>{let e=f.trim();if(!(!e||g||!a)){_(!0),h(null);try{let t=await fetch(`/api/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:a.projectRoot,branch:e})}),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!n.path){h(n.error??`HTTP ${t.status}`);return}D(),o(t=>t&&{...t,forCwd:n.path,worktrees:[...t.worktrees,{path:n.path,branch:e,isMain:!1}]}),i(n.path),k(e=>e+1)}catch(e){h(e instanceof Error?e.message:String(e))}finally{_(!1)}}},[D,f,g,a,i]),j=(0,d.useCallback)(async(e,n)=>{if(!(!a||g)){_(!0),h(null);try{let r=await fetch(`/api/worktrees`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:a.projectRoot,path:e,force:n})}),o=await r.json().catch(()=>({}));if(!r.ok){if(o.dirty&&!n){y(e);return}h(o.error??`HTTP ${r.status}`);return}D(),t&&e&&S9(t,e)&&i(a.projectRoot),k(e=>e+1)}catch(e){h(e instanceof Error?e.message:String(e))}finally{_(!1)}}},[D,a,g,t,i]);return(0,d.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&D()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[D]),{worktreeState:a,worktreeLoadingCwd:b,wtDropdownOpen:s,setWtDropdownOpen:c,wtNewOpen:l,setWtNewOpen:u,wtNewBranch:f,setWtNewBranch:p,wtError:m,setWtError:h,wtBusy:g,wtConfirmRemove:v,setWtConfirmRemove:y,wtFilter:S,setWtFilter:C,wtDropdownRef:w,wtNewInputRef:T,closeWorktrees:D,handleCreateWorktree:A,handleRemoveWorktree:j}}function Yee({wt:e,selectedCwd:t,homeDir:n,setSelectedCwd:r}){let{t:i}=N(),{worktreeState:a,wtFilter:o,setWtFilter:s,wtDropdownOpen:c,setWtDropdownOpen:l,wtDropdownRef:u,closeWorktrees:d,handleRemoveWorktree:f,wtConfirmRemove:m,setWtConfirmRemove:h,wtBusy:g,wtNewOpen:_,setWtNewOpen:v,wtNewBranch:y,setWtNewBranch:b,wtNewInputRef:x,handleCreateWorktree:S,wtError:C,setWtError:w}=e;if(!a)return null;let T=a.worktrees.find(e=>S9(e.path,t))??a.worktrees.find(e=>e.isMain),D=a.worktrees.length>=8,O=D&&o.trim()?a.worktrees.filter(e=>(e.branch??D9(e.path,n)).toLowerCase().includes(o.trim().toLowerCase())):a.worktrees;return(0,E.jsxs)(`div`,{ref:u,"data-testid":`worktree-switcher`,style:{position:`relative`,marginTop:6},children:[(0,E.jsxs)(`button`,{"data-testid":`worktree-switcher-trigger`,onClick:()=>l(e=>!e),title:T?i(`sidebar.switchWorktreeTitle`,{path:T.path}):i(`sidebar.switchWorktree`),style:{width:`100%`,height:29,boxSizing:`border-box`,display:`flex`,alignItems:`center`,gap:6,padding:`0 10px`,background:`var(--bg-input)`,border:`1px solid var(--border)`,borderRadius:7,cursor:`pointer`,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--text-muted)`,textAlign:`left`},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0,color:T&&!T.isMain?`var(--accent)`:`var(--text-dim)`},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(O9,{text:T?T.branch??D9(T.path,n):`…`,style:{flex:1,fontFamily:`var(--font-mono)`,color:`var(--text)`}}),T?.isMain&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:i(`sidebar.main`)}),a.worktrees.length>1&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:a.worktrees.length}),(0,E.jsx)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`2 3.5 5 6.5 8 3.5`})})]}),(0,E.jsxs)($ee,{open:c,style:{position:`absolute`,top:`calc(100% + 4px)`,left:0,right:0,zIndex:100,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 6px 20px var(--shadow-color)`,overflow:`hidden`},children:[D&&(0,E.jsx)(`div`,{style:{padding:`6px 8px`,borderBottom:`1px solid var(--border)`},children:(0,E.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(s(``),d())},placeholder:i(`sidebar.filterWorktrees`),autoFocus:!0,style:{width:`100%`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,padding:`5px 8px`,border:`1px solid var(--border)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,boxSizing:`border-box`}})}),(0,E.jsxs)(`div`,{style:{maxHeight:`min(40vh, 300px)`,overflowY:`auto`},children:[O.map(e=>{let o=S9(e.path,t)||e.isMain&&!a.worktrees.some(e=>S9(e.path,t));return m===e.path?(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,padding:`7px 10px`,borderBottom:`1px solid var(--border)`,background:`color-mix(in srgb, var(--status-error) 6%, transparent)`},children:[(0,E.jsx)(`span`,{style:{flex:1,fontSize:`var(--text-sm)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:i(`sidebar.forceRemoveCheckout`)}),(0,E.jsx)(`button`,{"data-testid":`worktree-force-remove`,onClick:()=>void f(e.path,!0),disabled:g,style:{padding:`3px 9px`,background:`var(--status-error)`,border:`none`,borderRadius:5,color:`var(--on-error)`,fontSize:`var(--text-sm)`,fontWeight:600,cursor:`pointer`,flexShrink:0},children:i(`sidebar.force`)}),(0,E.jsx)(`button`,{onClick:()=>h(null),style:{padding:`3px 9px`,background:`var(--bg-hover)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`,flexShrink:0},children:i(`sidebar.cancel`)})]},e.path):(0,E.jsxs)(`div`,{className:`wt-row`,"data-testid":`worktree-row`,style:{display:`flex`,alignItems:`center`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsxs)(`button`,{"data-testid":`worktree-item`,onClick:()=>{r(e.path),d()},title:e.path,style:{flex:1,minWidth:0,display:`flex`,alignItems:`center`,gap:7,padding:`8px 10px`,background:`var(--bg)`,border:`none`,color:o?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`},children:[o?(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`var(--accent)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`1.5 5 4 7.5 8.5 2.5`})}):(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(O9,{text:e.branch??D9(e.path,n),style:{flex:1}}),e.isMain&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:i(`sidebar.main`)})]}),!e.isMain&&(0,E.jsx)(`button`,{"data-testid":`worktree-remove`,onClick:()=>void f(e.path,!1),disabled:g,title:i(`sidebar.removeWorktreeTitle`,{path:e.path}),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:34,height:28,padding:0,marginRight:4,background:`none`,border:`none`,color:`var(--text-dim)`,cursor:`pointer`,borderRadius:5,flexShrink:0,transition:`color 0.12s, background 0.12s`,"--hover-color":`var(--status-error)`,"--hover-bg":`color-mix(in srgb, var(--status-error) 8%, transparent)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`polyline`,{points:`3 6 5 6 21 6`}),(0,E.jsx)(`path`,{d:`M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6`}),(0,E.jsx)(`path`,{d:`M10 11v6M14 11v6`}),(0,E.jsx)(`path`,{d:`M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2`})]})})]},e.path)}),D&&O.length===0&&o.trim()&&(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:i(`sidebar.noMatchingWorktrees`)})]}),_?(0,E.jsxs)(`div`,{style:{padding:`6px 8px`},children:[(0,E.jsx)(`input`,{ref:x,"data-testid":`worktree-new-branch-input`,value:y,onChange:e=>{b(e.target.value),w(null)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),S()),e.key===`Escape`&&(v(!1),b(``),w(null))},placeholder:i(`sidebar.branchName`),style:{width:`100%`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,padding:`5px 8px`,border:`1px solid var(--accent)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,boxSizing:`border-box`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,marginTop:5},children:[(0,E.jsx)(`button`,{"data-testid":`worktree-create`,onClick:()=>void S(),disabled:g||!y.trim(),style:{flex:1,padding:`4px 0`,background:`var(--accent)`,border:`none`,borderRadius:5,color:`var(--on-accent)`,fontSize:`var(--text-sm)`,fontWeight:600,cursor:g||!y.trim()?`not-allowed`:`pointer`,opacity:g||!y.trim()?.65:1},children:i(g?`sidebar.creating`:`sidebar.create`)}),(0,E.jsx)(`button`,{onClick:()=>{v(!1),b(``),w(null)},style:{flex:1,padding:`4px 0`,background:`var(--bg-hover)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:i(`sidebar.cancel`)})]})]}):(0,E.jsxs)(`button`,{"data-testid":`worktree-new`,onClick:e=>{e.stopPropagation(),v(!0),w(null),setTimeout(()=>x.current?.focus(),0)},title:i(`sidebar.createWorktreeTitle`),style:{display:`flex`,alignItems:`center`,gap:7,width:`100%`,padding:`8px 10px`,background:`none`,border:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-sm)`},children:[(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.1`,strokeLinecap:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`5`,y1:`1`,x2:`5`,y2:`9`}),(0,E.jsx)(`line`,{x1:`1`,y1:`5`,x2:`9`,y2:`5`})]}),(0,E.jsx)(`span`,{children:i(`sidebar.newWorktree`)})]}),C&&(0,E.jsx)(`div`,{style:{padding:`5px 10px 8px`,color:`var(--status-error)`,fontSize:`var(--text-sm)`,lineHeight:1.35,overflowWrap:`anywhere`},children:C})]})]})}function E9(e,t){let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4),a=Math.floor(r/36e5),o=Math.floor(r/864e5);return i<1?t(`sidebar.justNow`):i<60?t(`sidebar.minutesAgo`,{count:i}):a<24?t(`sidebar.hoursAgo`,{count:a}):o<7?t(`sidebar.daysAgo`,{count:o}):n.toLocaleDateString()}function Xee(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=t.get(e);(!r||n.modified>r)&&t.set(e,n.modified)}return[...t.entries()].sort((e,t)=>t[1].localeCompare(e[1])).map(([e])=>e)}function D9(e,t){return t&&e.startsWith(t)?`~${e.slice(t.length)}`:e}function Zee(e){let t=e.split(/[\\/]+/).filter(Boolean);return t.length?t[t.length-1]:e}function O9({text:e,style:t}){return(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,display:`block`,minWidth:0,lineHeight:1.35,direction:`rtl`,textAlign:`left`,...t},children:(0,E.jsx)(`span`,{style:{unicodeBidi:`plaintext`},children:e})})}function k9({session:e}){return(0,E.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:4,color:`var(--danger)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:`${e.path}: ${e.error}`,children:[(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0},children:[(0,E.jsx)(`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`}),(0,E.jsx)(`path`,{d:`M12 9v4`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),e.error]})}var A9=140,Qee=2e3;function $ee({open:e,children:t,style:n}){let[r,i]=(0,d.useState)(e),[a,o]=(0,d.useState)(e);return(0,d.useEffect)(()=>{let t,n;return e?(i(!0),o(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>o(!0))})):(o(!1),n=setTimeout(()=>i(!1),A9)),()=>{t!==void 0&&window.cancelAnimationFrame(t),n&&clearTimeout(n)}},[e]),r?(0,E.jsx)(`div`,{style:{...n,opacity:+!!a,transform:a?`translateY(0) scale(1)`:`translateY(-8px) scale(0.96)`,transformOrigin:`top center`,transition:`opacity ${A9}ms ease, transform ${A9}ms ease`,pointerEvents:e?`auto`:`none`},children:t}):null}function ete(e){let t=new Map;for(let n of e)t.set(n.id,{session:n,children:[]});let n=new Map;for(let t of e)t.parentSessionId&&n.set(t.id,t.parentSessionId);function r(e){let r=n.get(e),i=new Set;for(;r;){if(i.has(r))return null;if(i.add(r),t.has(r))return r;r=n.get(r)}return null}let i=[];for(let e of t.values()){let n=r(e.session.id);n?t.get(n).children.push(e):i.push(e)}let a=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>a(e.children))};return a(i),i}function tte({selectedSessionId:e,selectedSession:t,onSelectSession:n,onNewSession:r,initialSessionId:i,skipInitialProjectSelection:a,onInitialRestoreDone:o,refreshKey:s,onSessionDeleted:c,onUnseenSession:l,selectedCwd:u,onCwdChange:f,savedWorkspaces:m,onSavedWorkspacesChange:h,onOpenFile:g}){let{t:_}=N(),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(!0),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(null),[D,O]=(0,d.useState)(``),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(``),[P,ee]=(0,d.useState)(null),[F,I]=(0,d.useState)(!1),te=Jee({selectedCwd:w,selectedCwdProp:u,refreshKey:s,setSelectedCwd:T}),{worktreeState:ne,worktreeLoadingCwd:re}=te,[ie,ae]=(0,d.useState)(!1),[L,R]=(0,d.useState)(``),oe=(0,d.useRef)(null);(0,d.useEffect)(()=>{ie&&oe.current?.focus()},[ie]);let[z,se]=(0,d.useState)(!1),[ce,le]=(0,d.useState)(()=>new Set),ue=(0,d.useCallback)(e=>{le(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),de=(0,d.useCallback)(e=>{le(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),un(e),l?.(e)},[l]),{unreadSessionIds:fe,setUnreadSessionIds:pe}=qee(),me=Xq(),{runningSessionIds:he,runningPhases:ge,runningPhaseSince:_e,runningBusySince:ye,setRunningSessionIds:be,runningPollAuthoritativeRef:xe}=Sn(),Se=(0,d.useRef)(new Set),Ce=(0,d.useRef)(null),we=(0,d.useRef)(0),Te=(0,d.useCallback)(async(e=!1,t=!1)=>{try{e&&x(!0);let n=t?await ve.refresh():await ve.load();y(n.sessions),xe.current||be(new Set(n.runningSessionIds??[]));let r=new Set(n.sessions.map(e=>e.id));pe(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),C(null),e||(se(!0),Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>se(!1),2e3))}catch(e){C(String(e))}finally{e&&x(!1)}},[pe,be,xe]),Ee=(0,d.useRef)(!1);(0,d.useEffect)(()=>{let e=!Ee.current;Ee.current=!0,Te(e,e)},[Te,s]),(0,d.useEffect)(()=>{T9(fe)},[fe]),(0,d.useEffect)(()=>{let t=[...Se.current].filter(t=>!he.has(t)&&t!==e),n=[...he];if((t.length>0||n.length>0)&&pe(e=>{let r=new Set(e);return n.forEach(e=>r.delete(e)),t.forEach(e=>r.add(e)),r}),t.length>0&&Te(!1),[...he].filter(e=>!v.some(t=>t.id===e)).length>0){let e=Date.now();e-we.current>=Qee&&(we.current=e,Te(!1,!0))}Se.current=he},[he,e,v,Te,pe]),(0,d.useEffect)(()=>{e&&(qq(e),pe(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}))},[e,pe]),(0,d.useEffect)(()=>{fetch(`/api/home`).then(e=>e.json()).then(e=>{e.home&&O(e.home)}).catch(e=>console.error(`[pi-web] load home dir:`,e))},[]);let De=(0,d.useRef)(!1),Oe=(0,d.useCallback)(e=>e?ne&&ne.forCwd&&S9(ne.forCwd,e)||ne?.worktrees.some(t=>S9(t.path,e))?ne.projectRoot:v.find(t=>t.cwd&&S9(t.cwd,e))?.projectRoot??e:null,[ne,v]),ke=(0,d.useRef)(null);(0,d.useEffect)(()=>{ke.current!==w&&(ke.current=w,f?.(w,Oe(w)))},[w,f,Oe]),(0,d.useEffect)(()=>{if(!(v.length===0||a)&&w===null){if(i&&!De.current){De.current=!0;let e=v.find(e=>e.id===i);if(e){T(e.cwd),ue(e.id),n(e,!0);return}o?.()}let e=Xee(v);e.length>0&&T(e[0])}},[v,w,i,a,n,o,ue]);let Ae=(0,d.useCallback)(async e=>{let t=(e??j).trim();if(!(!t||F)){I(!0),ee(null);try{let e=await fetch(`/api/cwd/validate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:t})}),n=await e.json().catch(()=>({}));if(!e.ok||n.error){ee(n.error??`HTTP ${e.status}`);return}let r=n.cwd??t;if(T(r),A(!1),M(``),h){let e=m??[];e.some(e=>C9(e)===C9(r))||h([...e,r])}}catch(e){ee(e instanceof Error?e.message:String(e))}finally{I(!1)}}},[j,F,m,h]),je=(0,d.useCallback)(async e=>{try{if((await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`HEAD`})).status===404){C(_(`sidebar.sessionDeleted`)),Te(!1,!0);return}}catch{}e.cwd&&T(e.cwd),ue(e.id),n(e)},[n,_,Te,ue]),Me=(0,d.useCallback)(e=>{let t=e??w;if(!t)return;let n=typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(n,t)},[w,r]),[Ne,Pe]=(0,d.useState)({}),[Fe,Ie]=(0,d.useState)(null),[Le,Re]=(0,d.useState)(null),[ze,Be]=(0,d.useState)(!1),Ve=Oe(w),He=v,Ue=!!(ne?.isGit&&ne.isTopLevel&&w&&Ve===ne.projectRoot),We=(w&&ne&&Ve===ne.projectRoot&&!Ue?ne.isGit?{label:_(`sidebar.openRepoRoot`),title:_(`sidebar.openRepoRootTitle`)}:{label:_(`sidebar.gitRepoRootOnly`),title:_(`sidebar.gitRepoRootOnlyTitle`)}:null)??(w&&re===w&&!Ue?{label:_(`sidebar.worktrees`),title:_(`sidebar.checkingWorktrees`)}:null),Ge=(0,d.useCallback)(async e=>{Re(null),Be(!0);try{await Promise.all(e.sessions.map(e=>fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`}).then(t=>{t.ok||console.error(`[sidebar] failed to delete ${e.id}:`,t.status)}).catch(t=>console.error(`[sidebar] failed to delete ${e.id}:`,t))));for(let t of e.sessions)c?.(t.id);let t=m??[];h&&t.some(t=>C9(t)===C9(e.root))&&h(t.filter(t=>C9(t)!==C9(e.root))),Te(!1,!0)}finally{Be(!1)}},[c,Te,m,h]),Ke=(0,d.useMemo)(()=>{let e=t&&!He.some(e=>e.id===t.id)?[{...t,projectRoot:t.projectRoot??Oe(t.cwd)??void 0},...He]:He,n=new Map,r=new Map;for(let t of e){let e=t.projectRoot??t.cwd??`unknown`,i=e===`unknown`?e:C9(e);n.has(i)||(n.set(i,[]),r.set(i,e)),n.get(i).push(t)}let i=[...n.entries()].map(([e,t])=>({root:r.get(e)??e,sessions:t})).sort((e,t)=>{let n=e=>Math.max(...e.map(e=>{let t=new Date(e.modified).getTime();return Number.isNaN(t)?0:t}));return n(t.sessions)-n(e.sessions)}),a=[];if(w){let e=Oe(w);e&&!n.has(C9(e))&&a.push({root:e,sessions:[]})}let o=new Set([...n.keys()]);for(let e of a)o.add(C9(e.root));let s=[];for(let e of m??[]){let t=C9(e);o.has(t)||(o.add(t),s.push({root:e,sessions:[]}))}return[...a,...i,...s]},[He,w,Oe,t,m]),qe=L.trim().toLowerCase(),Je=(0,d.useMemo)(()=>qe?Ke.map(e=>({...e,sessions:e.sessions.filter(e=>Gee(e).toLowerCase().includes(qe))})).filter(e=>e.sessions.length>0):Ke,[Ke,qe]);return(0,E.jsxs)(`div`,{"data-testid":`session-sidebar`,style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[k&&(0,E.jsx)(zee,{busy:F,error:P,onCancel:()=>{A(!1),ee(null)},onSelect:e=>void Ae(e)}),(0,E.jsxs)(x9,{title:_(`sidebar.workspace`),open:!0,onToggle:()=>{},collapsible:!1,testId:`workspace-scroll`,hintTestId:`workspace`,scrollStyle:{flex:`1 1 auto`,minHeight:80,background:`var(--bg)`},style:{flex:1,minHeight:0},actions:(0,E.jsx)(y9,{items:[{key:`search`,testId:`workspace-search-toggle`,onClick:()=>{ie&&R(``),ae(e=>!e)},title:_(`sidebar.searchSessions`),ariaPressed:ie,color:ie?`var(--accent)`:`var(--text-muted)`,background:ie?`var(--bg-selected)`:void 0,icon:(0,E.jsx)(vi,{size:p.lg})},{key:`new-workspace`,testId:`new-workspace`,onClick:()=>A(!0),title:_(`sidebar.newWorkspace`),color:`var(--text-muted)`,icon:(0,E.jsx)(Xr,{size:p.xl})},{key:`refresh`,testId:`session-refresh`,onClick:()=>Te(!1,!0),title:_(`sidebar.refresh`),skipHover:z,color:z?`var(--status-success)`:`var(--text-muted)`,background:z?`color-mix(in srgb, var(--status-success) 18%, transparent)`:void 0,icon:z?(0,E.jsx)(Rr,{size:p.xl,color:`var(--status-success)`,strokeWidth:2.5}):(0,E.jsx)(mi,{size:p.xl})}]}),headerExtra:(0,E.jsxs)(E.Fragment,{children:[ie&&(0,E.jsxs)(`div`,{"data-testid":`workspace-search`,style:{display:`flex`,alignItems:`center`,gap:4,width:`100%`,minWidth:0,padding:`4px 8px`,background:`var(--bg)`,borderBottom:`1px solid var(--border)`,boxSizing:`border-box`},children:[(0,E.jsx)(vi,{size:p.lg,color:`var(--text-muted)`,style:{flexShrink:0}}),(0,E.jsx)(`input`,{ref:oe,value:L,onChange:e=>R(e.target.value),placeholder:_(`sidebar.searchSessionsPlaceholder`),"aria-label":_(`sidebar.searchSessions`),style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`var(--text)`,fontSize:`var(--text-sm)`}}),L&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{R(``),oe.current?.focus()},"aria-label":_(`chat.clearSearch`),style:{border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0,padding:0},children:`✕`})]}),Ue&&(0,E.jsx)(Yee,{wt:te,selectedCwd:w,homeDir:D,setSelectedCwd:T}),We&&(0,E.jsxs)(`button`,{type:`button`,"aria-disabled":`true`,tabIndex:-1,title:We.title,style:{width:`100%`,height:29,boxSizing:`border-box`,marginTop:6,display:`flex`,alignItems:`center`,gap:6,padding:`0 10px`,border:`1px solid var(--border)`,borderRadius:7,background:`var(--bg-hover)`,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,lineHeight:1.35,whiteSpace:`nowrap`,textAlign:`left`,cursor:`default`,opacity:.82},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`},children:We.label})]})]}),children:[b&&(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`16px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`div`,{style:{width:14,height:14,border:`2px solid var(--border)`,borderTopColor:`var(--text-dim)`,borderRadius:`50%`,animation:`spin 0.8s linear infinite`,flexShrink:0}}),_(`sidebar.loading`)]}),S&&(0,E.jsx)(`div`,{style:{padding:`12px 14px`,color:`var(--status-error)`,fontSize:`var(--text-base)`},children:S}),!b&&!S&&qe&&Je.length===0&&(0,E.jsx)(`div`,{style:{padding:`16px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:_(`sidebar.searchSessionsNoResults`)}),Je.map(t=>{let n=t.sessions.some(t=>t.id===e)||t.root===Ve;return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(nte,{group:t,groupSelected:n,hoveredGroup:Fe,confirmDeleteGroup:Le,deletingGroup:ze,runningSessionIds:he,interactionBadges:me,collapsed:!!Ne[t.root],setHoveredGroup:Ie,setGroupCollapsed:Pe,setConfirmDeleteGroup:Re,handleDeleteGroup:Ge,handleNewSession:Me,copyText:Ri}),(qe||!Ne[t.root])&&(t.sessions.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`},children:_(`sidebar.noSessions`)}):ete(t.sessions).map(t=>(0,E.jsx)(j9,{node:t,selectedSessionId:e,runningSessionIds:he,runningPhases:ge,runningPhaseSince:_e,runningBusySince:ye,unreadSessionIds:fe,seenSessionIds:ce,interactionBadges:me,onSelectSession:je,onRenamed:()=>Te(!1,!0),onSessionDeleted:e=>{c?.(e),Te(!1,!0)},onUnseen:de,depth:0},t.session.id)))]},t.root)})]})]})}function nte({group:e,groupSelected:t,hoveredGroup:n,confirmDeleteGroup:r,deletingGroup:i,runningSessionIds:a,interactionBadges:o,collapsed:s,setHoveredGroup:c,setGroupCollapsed:l,setConfirmDeleteGroup:u,handleDeleteGroup:d,handleNewSession:f,copyText:m}){let{t:h}=N(),g=e.sessions.some(e=>a.has(e.id)),_=e.sessions.some(e=>o.has(e.id));return(0,E.jsx)(`div`,{"data-testid":`workspace-group-header`,onMouseEnter:()=>c(e.root),onMouseLeave:()=>c(null),style:{display:`flex`,alignItems:`center`,gap:4,height:40,padding:`0 2px`,boxSizing:`border-box`,fontSize:`var(--text-base)`,fontFamily:`var(--font-mono)`,color:`var(--text)`,fontWeight:600,textTransform:`none`,letterSpacing:.6,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,cursor:r===e.root?`default`:`pointer`,background:r===e.root?`color-mix(in srgb, var(--status-error) 6%, transparent)`:n===e.root?`var(--bg-hover)`:`var(--bg)`},onClick:r===e.root?void 0:()=>{l(t=>({...t,[e.root]:!t[e.root]}))},children:r===e.root?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:h(`sidebar.deleteWorkspace`,{count:e.sessions.length})}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,flexShrink:0},children:[(0,E.jsx)(`button`,{onClick:t=>{t.stopPropagation(),d(e)},disabled:i,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,height:22,padding:`0 9px`,background:`var(--status-error)`,border:`none`,borderRadius:5,color:`var(--on-error)`,cursor:i?`default`:`pointer`,opacity:i?.6:1,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:h(`sidebar.delete`)}),(0,E.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(null)},disabled:i,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,height:22,padding:`0 9px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:500,whiteSpace:`nowrap`},children:h(`sidebar.cancel`)})]})]}):(0,E.jsx)(E.Fragment,{children:(0,E.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:6,flex:1,minWidth:0,height:38,boxSizing:`border-box`,padding:`0 8px`,border:`none`,borderRadius:0,background:_&&s?`linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`:g&&s?`linear-gradient(90deg, transparent 13%, color-mix(in srgb, var(--accent) 18%, transparent) 25%, transparent 37%, transparent 63%, color-mix(in srgb, var(--shine-highlight) 50%, transparent) 75%, transparent 87%), linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`:`linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`,backgroundSize:g&&s&&!_?`200% 100%, auto`:void 0,animation:_&&s?`interaction-bg-blink 1s ease-in-out infinite`:g&&s?`pi-status-shine 1.5s linear infinite`:void 0,boxShadow:`0 2px 8px var(--shadow-color)`,margin:`0 -2px`},children:[(0,E.jsxs)(`span`,{style:{position:`relative`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:30,height:22,flexShrink:0},children:[(0,E.jsx)(`svg`,{width:`30`,height:`22`,viewBox:`0 0 24 24`,fill:t?`color-mix(in srgb, var(--accent) 18%, transparent)`:`var(--bg)`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:t?`var(--accent)`:`var(--text-muted)`,opacity:.95},children:(0,E.jsx)(`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`})}),(0,E.jsx)(`span`,{style:{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -38%)`,color:`var(--text-muted)`,fontSize:`var(--text-xs)`,fontWeight:400,lineHeight:1,textAlign:`center`,fontVariantNumeric:`tabular-nums`,userSelect:`none`},children:e.sessions.length})]}),(0,E.jsx)(qi,{label:e.root,wrapperStyle:{flex:1,minWidth:0,overflow:`hidden`},children:(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,maxWidth:`100%`,lineHeight:`20px`},children:Zee(e.root)})}),n===e.root&&(0,E.jsx)(y9,{items:[{key:`new-session`,onClick:t=>{t.stopPropagation(),f(e.root)},title:h(`sidebar.newSessionTitle`,{path:e.root}),icon:(0,E.jsx)(fi,{size:p.base})},{key:`copy-path`,onClick:t=>{t.stopPropagation(),m(e.root)},title:h(`sidebar.copyPath`),icon:(0,E.jsx)(Ur,{size:p.base})},{key:`delete-workspace`,onClick:t=>{t.stopPropagation(),u(e.root)},title:h(`sidebar.deleteWorkspaceTitle`),danger:!0,icon:(0,E.jsx)(Ei,{size:p.base})}]})]})})})}function j9({node:e,selectedSessionId:t,runningSessionIds:n,runningPhases:r,runningPhaseSince:i,runningBusySince:a,unreadSessionIds:o,seenSessionIds:s,interactionBadges:c,onSelectSession:l,onRenamed:u,onSessionDeleted:f,onUnseen:p,depth:m}){let[h,g]=(0,d.useState)(!1),_=e.children.length>0;return(0,E.jsxs)(`div`,{style:{paddingBottom:1,backgroundImage:`linear-gradient(90deg, transparent, var(--border), transparent)`,backgroundPosition:`0 100%`,backgroundSize:`100% 1px`,backgroundRepeat:`no-repeat`},children:[(0,E.jsxs)(`div`,{style:{position:`relative`},children:[m>0&&(0,E.jsx)(`div`,{style:{position:`absolute`,left:m*12+6,top:0,bottom:0,width:1,background:`var(--border)`,pointerEvents:`none`}}),(0,E.jsx)(ite,{session:e.session,isSelected:e.session.id===t,isRunning:n.has(e.session.id),phase:r[e.session.id],phaseSince:i[e.session.id],busySince:a[e.session.id],isUnread:o.has(e.session.id),isSeen:s.has(e.session.id),hasInteractionBadge:c.has(e.session.id),onClick:()=>l(e.session),onRenamed:u,onDeleted:e=>f?.(e),onUnseen:p,depth:m,hasChildren:_,collapsed:h,onToggleCollapse:()=>g(e=>!e)})]}),_&&!h&&(0,E.jsx)(`div`,{children:e.children.map(e=>(0,E.jsx)(j9,{node:e,selectedSessionId:t,runningSessionIds:n,runningPhases:r,runningPhaseSince:i,runningBusySince:a,unreadSessionIds:o,seenSessionIds:s,interactionBadges:c,onSelectSession:l,onRenamed:u,onSessionDeleted:f,onUnseen:p,depth:m+1},e.session.id))})]})}function rte(){let{t:e}=N();return(0,E.jsx)(`span`,{title:e(`sidebar.newActivity`),"aria-label":e(`sidebar.newSessionActivity`),style:{width:14,height:14,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,color:`var(--accent)`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`,style:{display:`block`},children:[(0,E.jsx)(`circle`,{cx:`7`,cy:`7`,r:`2.5`,fill:`currentColor`}),(0,E.jsx)(`circle`,{cx:`7`,cy:`7`,r:`3`,stroke:`currentColor`,strokeWidth:`1.4`,opacity:`0.32`,style:{transformOrigin:`center`,animation:`session-ring-pulse 1.6s ease-in-out infinite`}})]})})}function ite({session:e,isSelected:t,isRunning:n,phase:r,phaseSince:i,busySince:a,isUnread:o,isSeen:s=!0,hasInteractionBadge:c=!1,onClick:l,onRenamed:u,onDeleted:f,onUnseen:m,depth:h=0,hasChildren:g=!1,collapsed:_=!1,onToggleCollapse:v}){let{t:y}=N(),b=Cn(!!(n&&r),i),x=Cn(!!n,a),[S,C]=(0,d.useState)(!1),[w,T]=(0,d.useState)(!1),[D,O]=(0,d.useState)(``),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(!1),P=(0,d.useRef)(null),ee=e.error?e.path.split(/[\\/]/).pop()||e.id:e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),F=(0,d.useCallback)(t=>{t.stopPropagation(),O(e.name??``),T(!0),setTimeout(()=>P.current?.select(),0)},[e.name]),I=(0,d.useCallback)(async()=>{let t=D.trim();if(T(!1),t!==(e.name??``))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}),u?.()}catch{}},[D,e.id,e.name,u]),te=(0,d.useCallback)(async()=>{A(!1),M(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`}),f?.(e.id)}catch{M(!1)}},[e.id,f]),ne=(0,d.useCallback)(e=>{e.stopPropagation(),e.shiftKey?te():A(!0)},[te]),re=(0,d.useCallback)(e=>{e.stopPropagation(),te()},[te]),ie=(0,d.useCallback)(e=>{e.stopPropagation(),A(!1)},[]);return(0,E.jsx)(`div`,{"data-testid":`session-item`,"data-session-id":e.id,onClick:k||w?void 0:l,title:c?y(`sidebar.interactionBadge`):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>{C(!1)},style:{height:54,animation:c?`interaction-bg-blink 1s ease-in-out infinite`:void 0,display:`flex`,alignItems:`center`,paddingLeft:h>0?h*12+14:14,paddingRight:8,cursor:k||w?`default`:`pointer`,backgroundColor:k?`color-mix(in srgb, var(--status-error) 6%, transparent)`:S?`var(--bg-hover)`:`transparent`,transition:`background 0.1s`,opacity:j?.5:1,gap:6,overflow:`hidden`},className:t&&!k?`row-selected-gradient`:void 0,children:k?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:ee}),(0,E.jsxs)(`div`,{style:{marginTop:2,display:`flex`,alignItems:`center`,gap:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[e.error?(0,E.jsx)(k9,{session:e}):(0,E.jsx)(`span`,{title:e.modified,children:E9(e.modified,y)}),(0,E.jsx)(`span`,{children:y(`sidebar.messagesCount`,{count:e.messageCount})})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,flexShrink:0},children:[(0,E.jsxs)(`button`,{onClick:re,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,height:30,padding:`0 11px`,background:`var(--status-error)`,border:`none`,borderRadius:6,color:`var(--on-error)`,cursor:`pointer`,fontSize:`var(--text-base)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(Ei,{size:p.base}),y(`sidebar.delete`)]}),(0,E.jsx)(`button`,{onClick:ie,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,height:30,padding:`0 11px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,fontWeight:500,whiteSpace:`nowrap`},children:y(`sidebar.cancel`)})]})]}):w?(0,E.jsx)(`input`,{ref:P,"data-testid":`session-rename-input`,value:D,onChange:e=>O(e.target.value),onBlur:I,onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&T(!1)},autoFocus:!0,style:{flex:1,fontSize:`var(--text-base)`,padding:`5px 8px`,border:`1px solid var(--accent)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,height:30}}):(0,E.jsxs)(E.Fragment,{children:[h>0&&(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--text-dim)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:5,minWidth:0,fontSize:`var(--text-base)`,fontWeight:t?600:400,lineHeight:1.4,color:s?`var(--text)`:`var(--text-dim)`},title:ee,children:(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,minWidth:0},children:ee})}),(0,E.jsxs)(`div`,{style:{marginTop:2,display:`flex`,alignItems:`center`,gap:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[e.error?(0,E.jsx)(k9,{session:e}):n?(0,E.jsx)(QJ,{phase:r??{kind:`running_command`},elapsed:b,totalElapsed:x}):o?(0,E.jsx)(rte,{}):(0,E.jsx)(`span`,{title:e.modified,children:E9(e.modified,y)}),!e.error&&n?null:(0,E.jsx)(`span`,{children:y(`sidebar.messagesCount`,{count:e.messageCount})}),e.worktreeBranch&&(0,E.jsxs)(`span`,{title:`Worktree: ${e.cwd}`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--accent)`,minWidth:0,overflow:`hidden`},children:[(0,E.jsxs)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.worktreeBranch})]})]})]}),g&&(0,E.jsx)(qi,{label:_?`Expand forks`:`Collapse forks`,children:(0,E.jsx)(`button`,{onClick:e=>{e.stopPropagation(),v?.()},style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:20,height:20,padding:0,flexShrink:0,background:`none`,border:`none`,color:`var(--text-dim)`,cursor:`pointer`,transform:_?`rotate(-90deg)`:`none`,transition:`transform 0.15s`},children:(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`polyline`,{points:`2 3.5 5 6.5 8 3.5`})})})}),(0,E.jsx)(y9,{visible:S,items:[...s&&m?[{key:`unseen`,onClick:t=>{t.stopPropagation(),m(e.id)},title:y(`sidebar.disconnect`)||`断开`,icon:(0,E.jsx)(Oi,{size:p.base})}]:[],{key:`copy-path`,onClick:t=>{t.stopPropagation(),Ri(e.path)},title:y(`sidebar.copyPath`),icon:(0,E.jsx)(Ur,{size:p.base})},{key:`rename`,testId:`session-rename`,onClick:F,title:y(`sidebar.rename`),icon:(0,E.jsx)(ui,{size:p.xl})},{key:`delete`,testId:`session-delete`,onClick:ne,title:y(`sidebar.deleteWithShiftClick`),danger:!0,icon:(0,E.jsx)(Ei,{size:p.xl})}]})]})})}function ate(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(qe,Je,Je);if(t.length===0)return null;let n=t[t.length-1],r=t.length;return(0,E.jsx)(_l,{open:!0,onOpenChange:()=>{},children:(0,E.jsxs)(xl,{children:[(0,E.jsx)(Cl,{style:{position:`fixed`,inset:0,zIndex:1200,background:`rgba(0, 0, 0, 0.45)`}}),(0,E.jsxs)(Dl,{role:`alertdialog`,"aria-modal":`true`,onInteractOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:1200,maxWidth:480,width:`calc(100% - 48px)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:10,padding:`16px 20px`,boxShadow:`0 8px 32px rgba(0, 0, 0, 0.35)`},children:[(0,E.jsxs)(Ml,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10,fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`},children:[(0,E.jsx)(`span`,{style:{color:`var(--status-error)`},children:`⚠`}),(0,E.jsx)(`span`,{children:r>1?e(`errors.titleCount`,{count:r}):e(`errors.title`)})]}),(0,E.jsx)(Pl,{asChild:!0,children:(0,E.jsx)(`div`,{children:n.kind===`api`?(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:6},children:[(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 8px`,borderRadius:999,background:`color-mix(in srgb, var(--status-error) 14%, transparent)`,color:`var(--status-error)`,fontWeight:600,whiteSpace:`nowrap`},children:[`HTTP `,n.status||`ERR`]}),n.context&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`},children:n.context})]}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,wordBreak:`break-word`},children:n.message})]}):(0,E.jsxs)(`div`,{children:[n.context&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`,marginBottom:6},children:n.context}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,wordBreak:`break-word`},children:n.message})]})})}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,marginTop:16},children:[r>1&&(0,E.jsx)(`button`,{type:`button`,onClick:Xe,style:{border:`1px solid var(--border)`,background:`none`,color:`var(--text-muted)`,borderRadius:6,padding:`4px 12px`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:e(`errors.clearAll`)}),(0,E.jsx)(`button`,{type:`button`,onClick:Ye,style:{border:`none`,background:`var(--accent)`,color:`#fff`,borderRadius:6,padding:`4px 14px`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:e(`errors.close`)})]})]})]})})}var M9=[],ote=1,N9=new Set;function P9(){for(let e of N9)e()}function ste(e){return N9.add(e),()=>{N9.delete(e)}}function F9(){return M9}function cte(e){let t={id:ote++,label:e??``};M9=[...M9,t],P9();let n=!1;return()=>{n||(n=!0,M9=M9.filter(e=>e.id!==t.id),P9())}}var I9=new WeakMap;function lte(e){if(!e.isConnected)return()=>{};let t=I9.get(e);if(!t){let n=document.createElement(`div`);n.style.cssText=`position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb, var(--bg) 50%, transparent);z-index:5;`,n.innerHTML=`<div style="width:16px;height:16px;border:2px solid var(--border);border-top-color:var(--text-dim);border-radius:50%;animation:spin 0.8s linear infinite;"></div>`;let r=null;getComputedStyle(e).position===`static`&&(r=e.style.position,e.style.position=`relative`),e.appendChild(n),t={count:0,el:n,prevPosition:r},I9.set(e,t)}t.count++;let n=!1;return()=>{n||(n=!0,t.count--,t.count<=0&&(t.el.remove(),t.prevPosition!==null&&(t.prevPosition?e.style.position=t.prevPosition:e.style.removeProperty(`position`)),I9.delete(e)))}}async function ute(e){try{return await e.json()}catch{return null}}async function L9(e,t,n){let r=n?.loading??`fullscreen`,i=r===`fullscreen`?cte(n?.label):r instanceof HTMLElement?lte(r):null;try{let n;try{n=await fetch(e,t)}catch(e){throw new Be(e instanceof Error?e.message:`Network error`,0)}if(!n.ok){let e=await ute(n);throw new Be(e&&typeof e==`object`&&`error`in e&&typeof e.error==`string`?e.error:`HTTP ${n.status}`,n.status,e)}let r=await n.text();return r?JSON.parse(r):void 0}catch(e){throw e instanceof Be?e:new Be(e instanceof Error?e.message:String(e),0)}finally{i?.()}}var dte=3;function fte(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(ste,F9,F9);if(t.length===0)return null;let n=t.slice(0,dte),r=t.length-n.length;return(0,E.jsx)(`div`,{"aria-busy":`true`,style:{position:`fixed`,inset:0,zIndex:1150,background:`color-mix(in srgb, var(--bg) 40%, transparent)`,display:`flex`,alignItems:`center`,justifyContent:`center`,pointerEvents:`none`},children:(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10,minWidth:220,maxWidth:`60vw`,padding:`14px 18px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`var(--radius)`,boxShadow:`0 8px 32px rgba(0,0,0,0.25)`},children:[n.map(t=>(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:`var(--text-sm)`,color:`var(--text)`},children:[(0,E.jsx)(`div`,{style:{width:14,height:14,flexShrink:0,border:`2px solid var(--border)`,borderTopColor:`var(--accent)`,borderRadius:`50%`,animation:`spin 0.8s linear infinite`}}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:t.label||e(`loading.inProgress`)})]},t.id)),r>0&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:e(`loading.more`,{count:r})})]})})}var R9={},pte=6e4;function z9(e,t){return e===`Not found`?t(`files.notFound`):e===`Access denied`?t(`files.accessDenied`):e}async function B9(e,t){return((await L9(`/api/files/${mG(e)}?type=list`,void 0,t)).entries??[]).map(t=>({name:t.name,fullPath:vG(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function V9(e,t){return L9(`/api/git/status?${new URLSearchParams({cwd:e}).toString()}`,void 0,t)}var H9={modified:`files.modified`,added:`files.added`,deleted:`files.deleted`,renamed:`files.renamed`,untracked:`files.untracked`,conflict:`files.conflict`},U9={modified:`var(--status-warning)`,added:`var(--status-success)`,deleted:`var(--status-error)`,renamed:`var(--accent)`,untracked:`var(--status-success)`,conflict:`var(--status-error)`};function W9({status:e,t}){return(0,E.jsx)(`span`,{title:t(H9[e.status]),"aria-label":t(H9[e.status]),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,color:U9[e.status],fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,fontWeight:600},children:e.code})}function mte(e,t,n,r){return new Promise((i,a)=>{let o=new FormData;t.forEach(e=>o.append(`files`,e,e.name));let s=new XMLHttpRequest;s.open(`POST`,`/api/files/${mG(e)}?type=upload&conflict=${n}`),s.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&r(Math.round(e.loaded/e.total*100))},s.onerror=()=>a(Error(`Network error while uploading files`)),s.onabort=()=>a(Error(`Upload cancelled`)),s.onload=()=>{let e={};try{e=JSON.parse(s.responseText)}catch{s.responseText&&(e.error=s.responseText)}i({status:s.status,data:e})},s.send(o)})}function G9({size:e=11}){return(0,E.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,E.jsx)(`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`})]})}function K9({onClick:e,title:t}){return(0,E.jsx)(qi,{label:t,children:(0,E.jsx)(`button`,{type:`button`,onClick:e,"aria-label":t,style:{width:24,height:24,padding:0,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`none`,borderRadius:4,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,"--hover-color":`var(--text-muted)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`m6 6 12 12`}),(0,E.jsx)(`path`,{d:`m18 6-12 12`})]})})})}function q9({node:e,depth:t,cwd:n,onOpenFile:r,onAtMention:i,expandedPaths:a,onToggleExpanded:o,refreshToken:s,highlightedPaths:c,gitStatusByPath:l,changedDirectoryPaths:u,t:f}){let m=a.has(e.fullPath),h=c.has(e.fullPath),g=pG(e.fullPath),_=l.get(g),v=e.isDir&&(_!==void 0||u.has(g)),[y,b]=(0,d.useState)(e.children??[]),[x,S]=(0,d.useState)(e.loaded??!1),[C,w]=(0,d.useState)(!1),T=(0,d.useCallback)(async(t=!1)=>{if(!(x&&!t))try{let t=await B9(e.fullPath,{loading:`silent`});b(t),S(!0)}catch{}},[x,e.fullPath]);(0,d.useEffect)(()=>{m&&x&&T(!0)},[s]);let D=(0,d.useCallback)(()=>{if(e.isDir){let t=!m;o(e.fullPath,t),t&&!x&&T()}else r(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,x,m,T,r,o]);return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{onClick:D,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),style:{position:`relative`,display:`flex`,alignItems:`center`,gap:4,paddingLeft:8+t*14,paddingRight:8,height:24,cursor:`pointer`,background:C?`var(--bg-hover)`:`transparent`,borderRadius:4,userSelect:`none`},children:[e.isDir&&(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`var(--text-dim)`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0,transform:m?`rotate(90deg)`:`none`,transition:`transform 0.1s`},children:(0,E.jsx)(`polyline`,{points:`3 2 7 5 3 8`})}),!e.isDir&&(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`},children:e.isDir?(0,E.jsx)(In,{size:p.xl,open:m}):ur(e.name,14)}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},title:e.fullPath,children:e.name}),h&&(0,E.jsx)(`span`,{title:f(`files.newlyUploaded`),"aria-label":f(`files.newlyUploaded`),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,E.jsx)(`span`,{style:{width:6,height:6,borderRadius:`50%`,background:`var(--accent)`}})}),!C&&!e.isDir&&_&&(0,E.jsx)(W9,{status:_,t:f}),!C&&v&&(0,E.jsx)(`span`,{title:f(`files.containsChangedFiles`),"aria-label":f(`files.containsChangedFiles`),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,E.jsx)(`span`,{style:{width:6,height:6,borderRadius:`50%`,background:`var(--status-warning)`}})}),i&&C&&(0,E.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(_G(e.fullPath,n),e.isDir)},title:f(`files.insertPath`),style:{position:`absolute`,right:e.isDir?4:28,top:`50%`,transform:`translateY(-50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,padding:`0 8px`,height:20,background:`var(--bg-panel)`,border:`1px solid var(--border)`,borderRadius:4,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(G9,{}),f(`files.mention`)]}),C&&!e.isDir&&(0,E.jsx)(`a`,{href:`/api/files/${mG(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:f(`files.download`),style:{position:`absolute`,right:4,top:`50%`,transform:`translateY(-50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,padding:`0 5px`,height:20,background:`var(--bg-panel)`,border:`1px solid var(--border)`,borderRadius:4,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`,textDecoration:`none`},children:(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})})]}),e.isDir&&m&&(0,E.jsxs)(`div`,{children:[y.map(e=>(0,E.jsx)(q9,{node:e,depth:t+1,cwd:n,onOpenFile:r,onAtMention:i,expandedPaths:a,onToggleExpanded:o,refreshToken:s,highlightedPaths:c,gitStatusByPath:l,changedDirectoryPaths:u,t:f},e.fullPath)),y.length===0&&x&&(0,E.jsx)(`div`,{style:{paddingLeft:8+(t+1)*14,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,height:22,display:`flex`,alignItems:`center`},children:f(`files.empty`)})]})]})}function J9({status:e,cwd:t,onOpenFile:n,onStageToggle:r,unstage:i,t:a}){let[o,s]=(0,d.useState)(!1),c=hG(e.filePath),l=_G(e.filePath,t);return(0,E.jsxs)(`div`,{"data-testid":`git-change-row`,onClick:()=>n(e.filePath,c,{modeHint:`diff`}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),title:e.filePath,style:{display:`flex`,alignItems:`center`,gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:`pointer`,background:o?`var(--bg-hover)`:`transparent`,borderRadius:4,userSelect:`none`},children:[r!==void 0&&(0,E.jsx)(`button`,{type:`button`,"data-testid":`git-stage-toggle`,onClick:t=>{t.stopPropagation(),r(e)},"aria-label":a(i?`files.unstageFile`:`files.stageFile`),style:{width:16,height:16,padding:0,marginLeft:-4,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`none`,borderRadius:4,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,opacity:+!!o,"--hover-color":`var(--text-muted)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:(0,E.jsx)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,"aria-hidden":`true`,children:i?(0,E.jsx)(`path`,{d:`M6 12h12`}):(0,E.jsx)(`path`,{d:`M12 5v14M5 12h14`})})}),(0,E.jsx)(W9,{status:e,t:a}),(0,E.jsx)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`,opacity:.85},children:ur(c,13)}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:l}),e.lineStats&&(e.lineStats.additions>0||e.lineStats.deletions>0)&&(0,E.jsxs)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`,gap:5,fontFamily:`var(--font-mono)`,fontSize:`var(--text-xs)`,fontVariantNumeric:`tabular-nums`},children:[e.lineStats.additions>0&&(0,E.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.lineStats.additions]}),e.lineStats.deletions>0&&(0,E.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.lineStats.deletions]})]})]})}function hte({message:e,onMessageChange:t,commitBusy:n,canCommit:r,onCommit:i,pushBusy:a,canPush:o,onPush:s,pullBusy:c,canPull:l,onPull:u,aiBusy:f,canAiGenerate:m,onAiGenerate:h,autoGenerateOnEmpty:g,hasModelForAuto:_,aiModelHint:v,t:y}){let b=(0,d.useRef)(null),x=e.trim()===``,S=x&&g&&_&&m&&!f,C=n||!S&&x||!r;return(0,d.useLayoutEffect)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,120)}px`)},[e]),(0,E.jsx)(`div`,{style:{display:`flex`,padding:`4px 2px 6px`},children:(0,E.jsxs)(`div`,{style:{position:`relative`,display:`flex`,flexDirection:`column`,flex:1,minWidth:0,backgroundColor:`var(--bg)`,backgroundImage:n||f||a||c?`linear-gradient(90deg, transparent 13%, color-mix(in srgb, var(--accent) 18%, transparent) 25%, transparent 37%, transparent 63%, color-mix(in srgb, var(--shine-highlight) 50%, transparent) 75%, transparent 87%)`:void 0,backgroundSize:n||f||a||c?`200% 100%`:void 0,animation:n||f||a||c?`pi-status-shine 1.5s linear infinite`:void 0,borderRadius:6,border:`1px solid var(--border)`},children:[(0,E.jsx)(`textarea`,{ref:b,"data-testid":`git-commit-message`,value:e,disabled:n||f||a||c,placeholder:f?v?`${y(`git.ai.generating`)}(${v})`:y(`git.ai.generating`):y(`files.commitMessagePlaceholder`),onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),C||i())},rows:1,style:{flex:`0 1 auto`,minWidth:0,resize:`none`,boxSizing:`content-box`,overflowY:`auto`,maxHeight:120,fontSize:`var(--text-base)`,lineHeight:1.4,padding:`4px 6px`,color:n||f||a||c?`var(--text-dim)`:`var(--text)`,background:`transparent`,border:`none`,borderRadius:6,outline:`none`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:4,padding:`2px 6px 4px`},children:[(0,E.jsx)(qi,{label:(()=>{let e=y(f?`git.ai.generating`:`git.ai.generate`);return v?`${e}(${v})`:e})(),children:(0,E.jsx)(`button`,{onClick:h,disabled:f||!m||n||a||c,"aria-label":y(`git.ai.generate`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:f||!m||n||a||c?`var(--text-dim)`:`var(--accent)`,cursor:f||!m||n||a||c?`default`:`pointer`},children:f?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Si,{size:p.lg})})}),(0,E.jsx)(qi,{label:n?y(`files.committing`):C&&x&&!S?y(`files.commitMessageRequired`):S?`${y(`git.ai.generateAndCommit`)} (Ctrl+Enter)`:`${y(`files.commit`)} (Ctrl+Enter)`,children:(0,E.jsx)(`button`,{"data-testid":`git-commit`,onClick:i,disabled:C||c,"aria-label":y(`files.commit`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:C||c?`var(--text-dim)`:`var(--accent)`,cursor:C||c?`default`:`pointer`},children:n?(0,E.jsx)(oi,{size:p[`2xl`],style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Qr,{size:p[`2xl`]})})}),(0,E.jsx)(qi,{label:y(a?`files.pushing`:o?`files.push`:`files.pushUpToDate`),children:(0,E.jsx)(`button`,{"data-testid":`git-push`,onClick:s,disabled:a||n||c||!o,"aria-label":y(`files.push`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:a||n||c||!o?`var(--text-dim)`:`var(--accent)`,cursor:a||n||c||!o?`default`:`pointer`},children:a?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Hr,{size:p[`2xl`]})})}),(0,E.jsx)(qi,{label:y(c?`files.pulling`:l?`files.pull`:`files.pullUpToDate`),children:(0,E.jsx)(`button`,{"data-testid":`git-pull`,onClick:u,disabled:c||n||a||!l,"aria-label":y(`files.pull`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:c||n||a||!l?`var(--text-dim)`:`var(--accent)`,cursor:c||n||a||!l?`default`:`pointer`},children:c?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Vr,{size:p[`2xl`]})})})]})]})})}function Y9({prefix:e,count:t,additions:n,deletions:r,t:i}){return(0,E.jsxs)(`div`,{"aria-label":i(`files.changeStats`,{count:t,additions:n,deletions:r}),style:{display:`flex`,alignItems:`center`,gap:6,height:24,padding:`0 10px`,fontSize:`var(--text-base)`},children:[e&&(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`},children:e}),(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`},children:i(`files.changedCount`,{count:t})}),(0,E.jsxs)(`span`,{style:{color:U9.added,fontFamily:`var(--font-mono)`},children:[`+`,n]}),(0,E.jsxs)(`span`,{style:{color:U9.deleted,fontFamily:`var(--font-mono)`},children:[`-`,r]})]})}function X9({message:e,onDismiss:t}){let{t:n}=N();return(0,E.jsxs)(`div`,{role:`alert`,style:{display:`flex`,alignItems:`center`,gap:6,marginTop:4,padding:`6px 8px`,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--status-error)`,background:`var(--bg)`,border:`1px solid var(--status-error)`,borderRadius:6},children:[(0,E.jsx)(`span`,{style:{minWidth:0,flex:1,overflowWrap:`anywhere`,maxHeight:140,overflowY:`auto`,whiteSpace:`pre-wrap`},children:e}),(0,E.jsx)(K9,{onClick:t,title:n(`files.dismissError`)})]})}function gte({children:e}){return(0,E.jsx)(`div`,{style:{padding:`0 4px 2px`},children:e})}var _te=(0,d.forwardRef)(function({children:e},t){return(0,E.jsx)(`div`,{ref:t,style:{padding:`2px 4px`},children:e})}),vte=(0,d.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:n,searchQuery:r,onAtMention:i,onAtMentions:a,onUploadBusyChange:o,changesCollapsed:s,onChangesCountChange:c,sessionId:l,onOpenConfig:u},f){let{t:m}=N(),[h,g]=(0,d.useState)([]),[_,v]=(0,d.useState)(!0),[y,b]=(0,d.useState)(null),x=(0,d.useRef)(null),[S,C]=(0,d.useState)(new Set),[w,T]=(0,d.useState)(0),D=(r??``).trim().toLowerCase(),O=(0,d.useMemo)(()=>{if(!D)return h;function e(t){if(t.name.toLowerCase().includes(D))return t;if(t.isDir&&t.children){let n=t.children.map(e).filter(e=>e!==null);if(n.length>0)return{...t,children:n}}return null}return h.map(e).filter(e=>e!==null)},[h,D]),[k,A]=(0,d.useState)(new Set),[j,M]=(0,d.useState)([]),[P,ee]=(0,d.useState)({additions:0,deletions:0}),[F,I]=(0,d.useState)([]),[te,ne]=(0,d.useState)({additions:0,deletions:0}),re=(0,d.useMemo)(()=>D?F.filter(t=>_G(t.filePath,e).toLowerCase().includes(D)):F,[F,D,e]),ie=(0,d.useMemo)(()=>D?j.filter(t=>_G(t.filePath,e).toLowerCase().includes(D)):j,[j,D,e]),[ae,L]=(0,d.useState)({branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1}),[R,oe]=(0,d.useState)(null),[z,se]=(0,d.useState)(``),[ce,le]=(0,d.useState)(!1),[ue,de]=(0,d.useState)(null),[fe,pe]=(0,d.useState)(!1),[me,he]=(0,d.useState)(!1),[ge,ve]=(0,d.useState)(null),be=Li(),xe=(0,d.useRef)(0),[Se,Ce]=(0,d.useState)(!1),[we,Te]=(0,d.useState)(!1),Ee=(0,d.useSyncExternalStore)(ye.subscribe,()=>ye.get()?.preferences??R9,()=>R9),De=(0,d.useSyncExternalStore)(_e.subscribe,()=>_e.get()),Oe=Ee.commitMessageAutoGenerateOnEmpty!==!1,ke=Ee.commitStageAllConfirm!==!1,Ae=Ee.commitMessageUseCurrentModel===!0?!!(l||De?.defaultModel||(De?.modelList?.length??0)>0):!!(typeof Ee.commitMessageModel==`string`&&Ee.commitMessageModel),[je,Me]=(0,d.useState)(!1),[Ne,Pe]=(0,d.useState)(null),Fe=(0,d.useRef)(null),[Ie,Le]=(0,d.useState)(!1),[Re,ze]=(0,d.useState)(null),[Be,Ve]=(0,d.useState)(`idle`),[He,Ue]=(0,d.useState)(0),[We,Ge]=(0,d.useState)(null),[qe,Je]=(0,d.useState)(null),[Ye,Xe]=(0,d.useState)(null),Ze=(0,d.useRef)(null),Qe=(0,d.useRef)(null),$e=`${n??0}:${w}`,et=Be!==`idle`,tt=(0,d.useMemo)(()=>new Map(j.map(e=>[pG(e.filePath),e])),[j]),nt=(0,d.useMemo)(()=>{let t=new Set,n=pG(e).replace(/\/$/,``);for(let e of j){let r=gG(pG(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=gG(r);if(e===r)break;r=e}}return t},[e,j]),rt=(0,d.useCallback)((e,t)=>{C(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),it=(0,d.useCallback)(t=>{let n=t.uploaded??[],r=t.skipped??[],i=t.errors??[];Je({uploaded:n,skipped:r,errors:i}),n.length>0&&(A(new Set(n.map(t=>vG(e,t)))),T(e=>e+1))},[e]),at=(0,d.useCallback)(async(t,n)=>{Xe(null),Ge(null),Ue(0),Ve(`uploading`);try{let{status:r,data:i}=await mte(e,t,n,Ue);if(r===409&&i.conflicts?.length){Xe({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});return}if(r<200||r>=300)throw Error(i.error??`Upload failed (HTTP ${r})`);Ue(100),it(i)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{Ve(`idle`)}},[it,e]),ot=(0,d.useCallback)(async t=>{if(!(t.length===0||et)){Je(null),A(new Set),Xe(null),Ge(null),Ue(0),Ve(`checking`);try{let n=await L9(`/api/files/${mG(e)}?type=upload-check`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({fileNames:t.map(e=>e.name)})},{loading:`silent`});if(n.conflicts?.length){Xe({files:t,conflicts:n.conflicts,nonReplaceable:n.nonReplaceable??[]});return}await at(t,`error`)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{Ve(`idle`)}}},[e,at,et]),st=(0,d.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value=``,ot(t)},[ot]);(0,d.useImperativeHandle)(f,()=>({openUploadPicker(){et||Qe.current?.click()}}),[et]);let ct=(0,d.useCallback)(async()=>{Me(!0);try{let t=await L9(`/api/git/push`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e})},{loading:`silent`});console.info(`[git-push] ok:`,t.output||`(empty output)`),Pe({ok:!0,output:t.output??``})}catch(e){let t=e instanceof Error?e.message:String(e);console.info(`[git-push] failed:`,t),Pe({ok:!1,output:t})}finally{Me(!1),T(e=>e+1)}},[e]),lt=(0,d.useCallback)(async()=>{Le(!0);try{let t=await L9(`/api/git/pull`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e})},{loading:`silent`});console.info(`[git-pull] ok:`,t.output||`(empty output)`),ze({ok:!0,output:t.output??``})}catch(e){let t=e instanceof Error?e.message:String(e);console.info(`[git-pull] failed:`,t),ze({ok:!1,output:t})}finally{Le(!1),T(e=>e+1)}},[e]),ut=(()=>{let e=Ee.gitAutoFetchIntervalSec;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:0})();(0,d.useEffect)(()=>{if(ut<=0||!e)return;let t=()=>{document.hidden||L9(`/api/git/autofetch-status?cwd=${encodeURIComponent(e)}`,{},{loading:`silent`}).then(e=>{e.cached!==!1&&L(t=>({...t,ahead:e.ahead??t.ahead,behind:e.behind??t.behind}))}).catch(()=>{})};t();let n=setInterval(t,ut*1e3),r=()=>{document.hidden||t()};return document.addEventListener(`visibilitychange`,r),()=>{clearInterval(n),document.removeEventListener(`visibilitychange`,r)}},[e,ut]),(0,d.useEffect)(()=>{if(Fe.current&&clearTimeout(Fe.current),Ne)return Fe.current=setTimeout(()=>Pe(null),1e4),()=>{Fe.current&&clearTimeout(Fe.current)}},[Ne]);let dt=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(dt.current&&clearTimeout(dt.current),Re)return dt.current=setTimeout(()=>ze(null),1e4),()=>{dt.current&&clearTimeout(dt.current)}},[Re]),(0,d.useEffect)(()=>{o?.(et)},[o,et]),(0,d.useEffect)(()=>()=>o?.(!1),[o]),(0,d.useEffect)(()=>{let t=Ze.current!==e;Ze.current=e,t&&(C(new Set),A(new Set),Je(null),Xe(null),Ge(null)),b(null),v(t);let n=!1;return B9(e,{loading:`silent`}).then(e=>{n||g(e)}).catch(e=>{n||(b(e instanceof Error?e.message:String(e)),Ke(e,`file explorer`))}).finally(()=>{n||v(!1)}),()=>{n=!0}},[e,n,w]),(0,d.useEffect)(()=>{let t=!1;return V9(e,{loading:`silent`}).then(e=>{if(!t){let t=e.isGitRepository;M(t?e.files:[]),ee(t?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}),I(t?e.stagedFiles:[]),ne(t?{additions:e.stagedAdditions,deletions:e.stagedDeletions}:{additions:0,deletions:0}),L(t?{branch:e.branch??null,upstream:e.upstream??null,ahead:e.ahead??0,behind:e.behind??0,hasUpstream:e.hasUpstream??!1}:{branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1})}}).catch(()=>{t||(M([]),ee({additions:0,deletions:0}),I([]),ne({additions:0,deletions:0}),L({branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1}))}),()=>{t=!0}},[e,n,w]);let ft=(0,d.useCallback)(async(t,n)=>{oe(null);try{let r=await fetch(`/api/git/stage`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,filePath:t.filePath,action:n?`unstage`:`stage`})}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.error??`Git ${n?`unstage`:`stage`} failed (HTTP ${r.status})`);T(e=>e+1)}catch(e){oe(e instanceof Error?e.message:String(e))}},[e]);(0,d.useEffect)(()=>{c?.(j.length+F.length)},[j,F,c]);let pt=(0,d.useCallback)(async(t,n)=>{let r=n??z;le(!0),de(null);try{let n=await fetch(`/api/git/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,message:r,stageAll:t})}),i=await n.json().catch(()=>({}));if(!n.ok)throw Error(i.error??`Commit failed (HTTP ${n.status})`);se(``),de(null),pe(!1),T(e=>e+1)}catch(e){de(e instanceof Error?e.message:String(e))}finally{le(!1)}},[e,z]),mt=(0,d.useCallback)(async()=>{if(me||ce||je||we)return null;let t=++xe.current,n=ye.get()?.preferences??{};if(Object.keys(n).length===0)try{await ye.refresh(),n=ye.get()?.preferences??{}}catch{}let r=n.commitMessageUseCurrentModel===!0,i=typeof n.commitMessageModel==`string`?n.commitMessageModel:``,a=``,o=``;if(r){if(l)try{let e=await L9(`/api/agent/${encodeURIComponent(l)}`),t=e.state?.model??e.model??null;if(t){let e=t;a=e.provider??``,o=e.id??e.modelId??``}if(!a||!o)try{let e=await L9(`/api/sessions/${encodeURIComponent(l)}/state`);e.model&&(a=e.model.provider,o=e.model.id)}catch{}}catch{}if(!a||!o)try{let e=_e.get();if(!e?.defaultModel)try{await _e.refresh(),e=_e.get()}catch{}if(e?.defaultModel?.provider){let t=e.defaultModel;a=t.provider??``,o=t.modelId??t.id??``}if((!a||!o)&&e?.modelList?.[0]){let t=e.modelList[0];a=t.provider??``,o=t.modelId??t.id??``}}catch{}if(!a||!o)return ve(m(`git.ai.noSessionModel`)),null}else{if(!i)return Ce(!0),null;let e=i.indexOf(`/`);if(e===-1||(a=i.slice(0,e),o=i.slice(e+1),!a||!o))return ve(m(`git.ai.invalidModel`)),null}let s=n.commitMessageMaxTokens,c=typeof s==`number`&&Number.isFinite(s)?Math.min(4096,Math.max(64,Math.round(s))):512;he(!0),ve(null);try{let n=await be.start(t=>fetch(`/api/git/generate-commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,provider:a,modelId:o,maxTokens:c}),signal:t}),pte,{joinKey:`generate`}).promise;if(t!==xe.current)return null;let r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error??`Generate failed (HTTP ${n.status})`);if(!r.message)throw Error(`Empty response`);return se(r.message),r.message}catch(e){return t!==xe.current||e instanceof Fi&&e.message===`cancelled`||ve(e instanceof Error?e.message:String(e)),null}finally{t===xe.current&&he(!1)}},[me,ce,je,we,e,l,m,be]),ht=(0,d.useCallback)(async()=>{let t=await V9(e),n=t.isGitRepository;M(n?t.files:[]),ee(n?{additions:t.additions,deletions:t.deletions}:{additions:0,deletions:0}),I(n?t.stagedFiles:[]),ne(n?{additions:t.stagedAdditions,deletions:t.stagedDeletions}:{additions:0,deletions:0}),L(n?{branch:t.branch??null,upstream:t.upstream??null,ahead:t.ahead??0,behind:t.behind??0,hasUpstream:t.hasUpstream??!1}:{branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1});let r=z.trim()===``,i=n?t.stagedFiles??[]:[],a=n?t.files??[]:[],o=i.length+a.length>0;if(r&&Oe&&Ae&&o&&!me&&!ce&&!je&&!we){Te(!0);try{let e=await mt();if(!e)return;i.length>0?await pt(!1,e):ke?pe(!0):await pt(!0,e)}finally{Te(!1)}return}i.length>0?pt(!1):ke?pe(!0):pt(!0)},[e,z,Oe,Ae,ke,me,ce,je,we,mt,pt]),gt=et||Ye!==null||We!==null||qe!==null,_t=(0,d.useCallback)(()=>{!qe||qe.uploaded.length===0||a?.(qe.uploaded.map(t=>_G(vG(e,t),e)))},[e,a,qe]);return(0,E.jsxs)(`div`,{style:{minHeight:`100%`},children:[(0,E.jsx)(`input`,{ref:Qe,type:`file`,multiple:!0,hidden:!0,onChange:st}),gt&&(0,E.jsxs)(`div`,{style:{padding:`6px 8px`,borderBottom:`1px solid var(--border)`},children:[et&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":Be===`checking`?m(`files.checking`):m(`files.uploading`,{progress:He}),children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8,minHeight:14,color:`var(--text-muted)`},children:[Be===`checking`?(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,style:{animation:`spin 0.8s linear infinite`},"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M21 12a9 9 0 1 1-5.7-8.4`})}):(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 16V4`}),(0,E.jsx)(`path`,{d:`m7 9 5-5 5 5`}),(0,E.jsx)(`path`,{d:`M5 20h14`})]}),Be===`uploading`&&(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`},children:[He,`%`]})]}),Be===`uploading`&&(0,E.jsx)(`div`,{style:{height:3,marginTop:4,overflow:`hidden`,borderRadius:2,background:`var(--border)`},children:(0,E.jsx)(`div`,{style:{width:`${He}%`,height:`100%`,background:`var(--text-muted)`,transition:`width 120ms ease`}})})]}),Ye&&(0,E.jsxs)(`div`,{role:`alert`,style:{padding:7,border:`1px solid color-mix(in srgb, #f59e0b 55%, var(--border))`,borderRadius:4,background:`color-mix(in srgb, #f59e0b 9%, var(--bg-panel))`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,lineHeight:1.35,overflowWrap:`anywhere`},children:m(`files.conflictSummary`,{count:Ye.conflicts.length,countSuffix:Ye.conflicts.length===1?``:`s`,files:Ye.conflicts.join(`, `)})}),Ye.nonReplaceable.length>0&&(0,E.jsx)(`div`,{style:{marginTop:3,fontSize:`var(--text-xs)`,color:`#f59e0b`,lineHeight:1.35,overflowWrap:`anywhere`},children:m(`files.cannotReplace`,{files:Ye.nonReplaceable.join(`, `)})}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,marginTop:7},children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>void at(Ye.files,`overwrite`),style:{height:22,padding:`0 7px`,border:`1px solid var(--status-error)`,borderRadius:4,background:`transparent`,color:`var(--status-error)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.replace`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>void at(Ye.files,`skip`),style:{height:22,padding:`0 7px`,border:`1px solid var(--border)`,borderRadius:4,background:`var(--bg-panel)`,color:`var(--text)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.skipExisting`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>Xe(null),style:{height:22,padding:`0 7px`,border:`none`,borderRadius:4,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.cancel`)})]})]}),We&&(0,E.jsxs)(`div`,{role:`alert`,style:{display:`flex`,alignItems:`flex-start`,gap:6,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--status-error)`},children:[(0,E.jsx)(`span`,{style:{minWidth:0,flex:1,overflowWrap:`anywhere`},children:We}),(0,E.jsx)(K9,{onClick:()=>Ge(null),title:m(`files.dismissError`)})]}),qe&&(0,E.jsxs)(`div`,{"aria-live":`polite`,children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,minHeight:22,fontSize:`var(--text-sm)`},children:[(0,E.jsxs)(`div`,{style:{minWidth:0,flex:1,display:`flex`,alignItems:`center`,gap:8},children:[qe.uploaded.length>0&&(0,E.jsxs)(`span`,{title:`${qe.uploaded.length} uploaded`,"aria-label":`${qe.uploaded.length} uploaded`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--status-success)`},children:[(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m5 12 4 4L19 6`})}),(0,E.jsx)(`span`,{children:qe.uploaded.length})]}),qe.skipped.length>0&&(0,E.jsxs)(`span`,{title:`${qe.skipped.length} skipped`,"aria-label":`${qe.skipped.length} skipped`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--text-dim)`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,E.jsx)(`path`,{d:`M8 12h8`})]}),(0,E.jsx)(`span`,{children:qe.skipped.length})]}),qe.errors.length>0&&(0,E.jsxs)(`span`,{title:m(`files.uploadFailed`,{count:qe.errors.length}),"aria-label":m(`files.uploadFailed`,{count:qe.errors.length}),style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--status-error)`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 3 2.5 20h19L12 3Z`}),(0,E.jsx)(`path`,{d:`M12 9v4`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),(0,E.jsx)(`span`,{children:qe.errors.length})]})]}),qe.uploaded.length>0&&a&&(0,E.jsxs)(`button`,{type:`button`,onClick:_t,title:qe.uploaded.length===1?m(`files.addUploadedFile`):m(`files.addAllUploadedFiles`),"aria-label":qe.uploaded.length===1?m(`files.addUploadedFile`):m(`files.addAllUploadedFiles`),style:{height:22,padding:`0 7px`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,flexShrink:0,border:`1px solid var(--border)`,borderRadius:4,background:`var(--bg-panel)`,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(G9,{}),m(`files.mention`)]}),(0,E.jsx)(K9,{onClick:()=>Je(null),title:m(`files.dismissUploadResults`)})]}),qe.errors.map(e=>(0,E.jsxs)(`div`,{title:e.error,style:{display:`flex`,alignItems:`center`,gap:4,marginTop:3,minWidth:0,fontSize:`var(--text-xs)`,color:`var(--status-error)`},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,E.jsx)(`path`,{d:`M12 8v5`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),(0,E.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.name))]})]}),!s&&(0,E.jsxs)(gte,{children:[(0,E.jsx)(hte,{message:z,onMessageChange:se,commitBusy:ce||we,canCommit:F.length+j.length>0,onCommit:ht,pushBusy:je,canPush:ae.hasUpstream?ae.ahead>0:!!ae.branch&&ae.branch!==`HEAD`,onPush:ct,pullBusy:Ie,canPull:ae.hasUpstream&&ae.behind>0,onPull:lt,aiBusy:me,canAiGenerate:F.length+j.length>0,onAiGenerate:()=>{se(``),mt()},autoGenerateOnEmpty:Oe,hasModelForAuto:Ae,aiModelHint:(()=>{if(Ee.commitMessageUseCurrentModel===!0)return m(`git.ai.usingCurrentModel`);let e=typeof Ee.commitMessageModel==`string`?Ee.commitMessageModel:``;return e?m(`git.ai.usingModel`,{model:e}):``})(),t:m}),Ne&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,style:{marginTop:4,padding:`6px 8px`,borderRadius:6,border:`1px solid ${Ne.ok?`var(--status-success)`:`var(--status-error)`}`,background:`var(--bg)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,marginBottom:4},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:Ne.ok?`var(--status-success)`:`var(--status-error)`,flexShrink:0}}),(0,E.jsx)(`span`,{style:{color:`var(--text-muted)`,flex:1,minWidth:0},children:m(Ne.ok?`files.pushSuccess`:`files.pushFailed`)}),(0,E.jsx)(`button`,{onClick:()=>Pe(null),"aria-label":m(`files.dismissError`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,background:`none`,border:`none`,borderRadius:4,color:`var(--text-dim)`,cursor:`pointer`,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}),Ne.output&&(0,E.jsx)(`pre`,{style:{margin:0,maxHeight:140,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,color:Ne.ok?`var(--text-muted)`:`var(--status-error)`,fontFamily:`var(--font-mono)`},children:Ne.output})]}),Re&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,style:{marginTop:4,padding:`6px 8px`,borderRadius:6,border:`1px solid ${Re.ok?`var(--status-success)`:`var(--status-error)`}`,background:`var(--bg)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,marginBottom:4},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:Re.ok?`var(--status-success)`:`var(--status-error)`,flexShrink:0}}),(0,E.jsx)(`span`,{style:{color:`var(--text-muted)`,flex:1,minWidth:0},children:m(Re.ok?`files.pullSuccess`:`files.pullFailed`)}),(0,E.jsx)(`button`,{onClick:()=>ze(null),"aria-label":m(`files.dismissError`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,background:`none`,border:`none`,borderRadius:4,color:`var(--text-dim)`,cursor:`pointer`,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}),Re.output&&(0,E.jsx)(`pre`,{style:{margin:0,maxHeight:140,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,color:Re.ok?`var(--text-muted)`:`var(--status-error)`,fontFamily:`var(--font-mono)`},children:Re.output})]}),ue&&(0,E.jsx)(X9,{message:ue,onDismiss:()=>de(null)}),R&&(0,E.jsx)(X9,{message:z9(R,m),onDismiss:()=>oe(null)}),ge&&(0,E.jsx)(X9,{message:ge,onDismiss:()=>ve(null)}),(0,E.jsx)(Y9,{prefix:m(`files.stagedPrefix`),count:re.length,additions:te.additions,deletions:te.deletions,t:m}),re.length>0?re.map(n=>(0,E.jsx)(J9,{status:n,cwd:e,onOpenFile:t,onStageToggle:e=>void ft(e,!0),unstage:!0,t:m},`staged-${n.filePath}`)):(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,textAlign:`center`},children:m(`files.noStagedChanges`)}),(0,E.jsx)(`div`,{style:{height:6}}),(0,E.jsx)(Y9,{prefix:m(`files.unstagedPrefix`),count:ie.length,additions:P.additions,deletions:P.deletions,t:m}),ie.length>0?ie.map(n=>(0,E.jsx)(J9,{status:n,cwd:e,onOpenFile:t,onStageToggle:e=>void ft(e,!1),t:m},n.filePath)):(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,textAlign:`center`},children:m(`files.noUnstagedChanges`)})]}),s&&(0,E.jsxs)(_te,{ref:x,children:[y?(0,E.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:`var(--text-sm)`,color:`var(--status-error)`},children:z9(y,m)}):(D?O:h).map(n=>(0,E.jsx)(q9,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:S,onToggleExpanded:rt,refreshToken:$e,highlightedPaths:k,gitStatusByPath:tt,changedDirectoryPaths:nt,t:m},n.fullPath)),!_&&!y&&h.length===0&&(0,E.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:m(`files.noFiles`)})]}),(0,E.jsx)(YS,{open:Se,title:m(`git.ai.notConfiguredTitle`),description:m(`git.ai.notConfiguredDesc`),confirmText:m(`git.ai.goToConfig`),cancelText:m(`sidebar.cancel`),onCancel:()=>Ce(!1),onConfirm:()=>{Ce(!1),u?.(`git`)},icon:(0,E.jsx)(Si,{size:p[`5xl`],style:{color:`var(--accent)`}})}),(0,E.jsx)(YS,{open:fe,title:m(`files.commitTitle`),description:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{children:m(`files.confirmStageAllCommit`,{count:j.length})}),z.trim()!==``&&(0,E.jsx)(`div`,{style:{marginTop:8,padding:`6px 10px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,maxHeight:120,overflowY:`auto`,textAlign:`left`},children:z.trim()})]}),confirmText:m(`files.stageAllAndCommit`),cancelText:m(`sidebar.cancel`),onCancel:()=>pe(!1),onConfirm:()=>{pe(!1),pt(!0)},icon:(0,E.jsxs)(`svg`,{width:p[`5xl`],height:p[`5xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--status-warning)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0,marginTop:1},children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`m9 12 2 2 4-4`})]})})]})});function yte({cwd:e,onOpenFile:t,explorerRefreshKey:n,onExplorerRefresh:r,onAtMention:i,onAtMentions:a,sessionId:o,onOpenConfig:s}){let{t:c}=N(),[l,u]=(0,d.useState)(0),[f,m]=(0,d.useState)(!1),[h,g]=(0,d.useState)(0),[_,v]=(0,d.useState)(!0),[y,b]=(0,d.useState)(!1),x=(0,d.useRef)(null),S=(0,d.useRef)(null),[C,w]=(0,d.useState)(!1),[T,D]=(0,d.useState)(``),O=(0,d.useRef)(null);return(0,d.useEffect)(()=>{C&&O.current?.focus()},[C]),Wi(()=>{n!==void 0&&u(e=>e+1)},[n]),e?(0,E.jsx)(x9,{title:c(`files.explorer`),open:!0,onToggle:()=>{},collapsible:!1,testId:`explorer-scroll`,hintTestId:`explorer`,style:{flex:1,minHeight:0},scrollStyle:{background:`var(--bg)`},actions:(0,E.jsx)(y9,{items:[{key:`git`,testId:`explorer-changes-toggle`,onClick:()=>v(e=>!e),title:c(`sidebar.changedFiles`,{count:h}),ariaPressed:!_,color:h>0?`var(--accent)`:`var(--text-muted)`,background:_?void 0:`var(--bg-selected)`,borderColor:_?void 0:`var(--accent)`,icon:(0,E.jsx)(Zr,{size:p.lg})},{key:`search`,testId:`explorer-search-toggle`,onClick:()=>{C&&D(``),w(e=>!e)},title:c(`files.search`),ariaPressed:C,color:C?`var(--accent)`:`var(--text-muted)`,background:C?`var(--bg-selected)`:void 0,icon:(0,E.jsx)(vi,{size:p.lg})},{key:`upload`,onClick:()=>S.current?.openUploadPicker(),disabled:f,title:c(`sidebar.uploadFilesTitle`),color:`var(--text-muted)`,icon:(0,E.jsx)(fi,{size:p.base})},{key:`refresh`,onClick:()=>{r?r():u(e=>e+1),b(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>b(!1),2e3)},title:c(`sidebar.refreshExplorer`),skipHover:y,color:y?`var(--status-success)`:`var(--text-muted)`,background:y?`color-mix(in srgb, var(--status-success) 18%, transparent)`:void 0,icon:y?(0,E.jsx)(Rr,{size:p.lg,color:`var(--status-success)`,strokeWidth:2.5}):(0,E.jsx)(mi,{size:p.lg})}]}),headerExtra:C?(0,E.jsxs)(`div`,{"data-testid":`explorer-search`,style:{display:`flex`,alignItems:`center`,gap:4,width:`100%`,minWidth:0,padding:`4px 8px`,background:`var(--bg)`,borderBottom:`1px solid var(--border)`,boxSizing:`border-box`},children:[(0,E.jsx)(vi,{size:p.lg,color:`var(--text-muted)`,style:{flexShrink:0}}),(0,E.jsx)(`input`,{ref:O,"data-testid":`explorer-search-input`,value:T,onChange:e=>D(e.target.value),placeholder:c(`files.searchPlaceholder`),"aria-label":c(`files.search`),style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`var(--text)`,fontSize:`var(--text-sm)`}}),T&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{D(``),O.current?.focus()},"aria-label":c(`chat.clearSearch`),style:{border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}):void 0,children:(0,E.jsx)(vte,{ref:S,cwd:e,onOpenFile:t??(()=>{}),refreshKey:l,searchQuery:T,onAtMention:i,onAtMentions:a,onUploadBusyChange:m,changesCollapsed:_,onChangesCountChange:g,sessionId:o,onOpenConfig:s})}):null}function bte({geometries:e,messages:t,onAddMessage:n,onRemoveMessage:r,onUpdateMessage:i,widgets:a,closedKeys:o,onReopen:s}){let{t:c}=N(),[l,u]=(0,d.useState)(null),[f,p]=(0,d.useState)(null),m=(0,d.useRef)(null);(0,d.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=e=>a.find(t=>t.key===e)?.lines[0],g=(e,t,n)=>{s(e),p({key:e,x:t,y:n}),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>p(null),2500)},_=[...new Set([...Object.keys(e),...o.keys()])].map(t=>[t,e[t]]);return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,background:`var(--bg)`},children:[_.length===0?(0,E.jsx)(`div`,{style:{padding:`32px 16px`,textAlign:`center`,color:`var(--text-dim)`,fontSize:`var(--text-lg)`,lineHeight:1.6},children:c(`config.widgets.empty`)}):(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,overflowY:`auto`,padding:10,display:`flex`,flexDirection:`row`,flexWrap:`wrap`,alignContent:`flex-start`,gap:6},children:_.map(([e,a])=>{let s=t[e]??[],d=o.has(e),f=h(e);return(0,E.jsxs)(`div`,{"data-testid":`widget-config-item-${e}`,style:{flex:`1 1 200px`,boxSizing:`border-box`,padding:`8px 10px`,borderRadius:5,background:`var(--bg-panel)`,border:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:7,flexWrap:`wrap`},children:[(0,E.jsxs)(`div`,{style:{minWidth:0,flex:`1 1 120px`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,fontFamily:`var(--font-mono)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e}),a&&(0,E.jsxs)(`div`,{style:{marginTop:2,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,color:`var(--text-dim)`},children:[c(`config.widgets.x`),`: `,a.x,` `,c(`config.widgets.y`),`: `,a.y,` ·`,` `,c(`config.widgets.width`),`: `,a.width,` `,c(`config.widgets.height`),`:`,` `,a.height]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4,flexShrink:0},children:[d&&(0,E.jsxs)(`button`,{type:`button`,"data-testid":`widget-expand-${e}`,"aria-label":c(`widgets.reopen`),title:c(`widgets.reopen`),onClick:t=>g(e,t.clientX,t.clientY),style:{display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},className:`hover-shift`,children:[(0,E.jsx)(qr,{size:13,"aria-hidden":!0}),c(`widgets.reopen`)]}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`widget-bind-${e}`,onClick:()=>u(e),style:{display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:[(0,E.jsx)(ii,{size:13,"aria-hidden":!0}),c(`config.widgets.bind`)]})]})]}),f&&(0,E.jsx)(`div`,{style:{marginTop:4,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:f}),(0,E.jsx)(JK,{messages:s,onAdd:t=>n(e,t),onRemove:t=>r(e,t),onUpdate:(t,n)=>i(e,t,n),bindOpen:l===e,onBindOpenChange:e=>{e||u(null)},ns:`widgets`,bindTestIdPrefix:`widget-bind`,editTestIdPrefix:`widget-edit`,chipTestIdPrefix:`widget-bound-${e}`,bindHintArgs:{key:e}})]},e)})}),f&&(0,E.jsx)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`widget-expanded-toast`,style:{position:`fixed`,left:Math.min(f.x,window.innerWidth-180),top:f.y+12,transform:`translateX(-50%)`,zIndex:2e3,padding:`8px 12px`,borderRadius:7,border:`1px solid var(--status-success)`,background:`var(--bg)`,color:`var(--text)`,fontSize:`var(--text-base)`,boxShadow:`0 4px 16px var(--shadow-strong)`,whiteSpace:`nowrap`},children:c(`widgets.expandedToChat`,{key:f.key})})]})}var xte=e=>window.history.replaceState(null,``,e),Z9=36,Ste=176,Cte=224,Q9=86,$9=116;function wte(){let[e,t]=(0,d.useState)(!1);(0,d.useEffect)(()=>{t(!0)},[]);let[n]=(0,d.useState)(()=>Pq(new URLSearchParams(window.location.search))),{isDark:r,toggleTheme:i}=Tr(),{locale:a,setLocale:o,t:s,supportedLocales:c}=N(),l=ne();wq();let{settingsValue:u,defaultThinkingLevel:f,setDefaultThinkingLevel:m,compaction:h,retry:g,defaultProjectTrust:_,setDefaultProjectTrust:v,subagents:y,savedWorkspaces:b,handleSavedWorkspacesChange:x,widgetGeometries:S,setWidgetGeometry:C,widgetMessages:w,addWidgetMessage:T,removeWidgetMessage:D,updateWidgetMessage:O,fontScale:k,setFontScale:A}=Ut({isDark:r,toggleTheme:i}),[j,M]=(0,d.useState)(null),{selectedSession:ee,effectiveNewSessionCwd:F,showChat:I,projectTrustCwd:te,refreshKey:re,sessionKey:ie,explorerRefreshKey:R,setExplorerRefreshKey:oe,modelsRefreshKey:z,setModelsRefreshKey:se,activeCwd:ue,initialCwdStatus:de,initialCwdError:me,initialSessionRestored:he,projectTrust:ge,projectTrustDialogOpen:_e,setProjectTrustDialogOpen:ve,projectTrustBusy:ye,projectTrustError:be,setProjectTrustError:xe,extensionDialogActiveRef:Se,handleSelectSession:Te,handleNewSession:Ee,handleSessionCreated:De,handleAgentEnd:Oe,handleSessionRenamed:ke,handleSessionForked:Ae,handleSessionDeleted:je,handleSessionUnseen:Me,handleCwdChange:Ne,handleTrustProject:Pe,handleExplorerRefresh:Le,handleInitialRestoreDone:ze}=Qe({initialNavigation:n,onProjectSwitch:()=>{M(null),Be(e=>e.filter(e=>e.kind!==`file`)),Ve(null),xte(`/`)},onSessionSelected:e=>{l&&!e&<(!1)},onTopPanelReset:()=>M(null)}),{setSavedTabs:Be,setActiveSavedId:Ve,configTabOpen:He,configSection:Ue,setConfigSection:We,configTabActive:Ge,activeFileTab:Ke,fileTabs:qe,modelConfigFocus:Je,handleOpenFile:Ye,openConfigTab:Xe,handleOpenModelConfig:Ze,closeConfigTab:$e,handleCloseMainTab:tt}=bq({onSessionSelected:()=>{Pt(!1),l&<(!1)},onRefreshModels:()=>se(e=>e+1)}),{value:nt}=P(we),rt=(0,d.useMemo)(()=>nt?Fe(nt):0,[nt]),it=(0,d.useMemo)(()=>nt?Ie(nt,s(`common.plugins`)):[],[nt,s]),[at,ot]=(0,d.useState)(!1),st=(0,d.useCallback)(e=>{Ye(e,hG(e),{sourceSessionId:ee?.id??null})},[Ye,ee?.id]),[ct,lt]=(0,d.useState)(!0),[ut,dt]=(0,d.useState)(!1),ft=(0,d.useRef)(280),pt=(0,d.useRef)(280),mt=(0,d.useCallback)(()=>typeof window>`u`?480:ce({viewportWidth:window.innerWidth,rightPanelOpen:!1,rightPanelWidth:0}),[]),ht=fe({ariaLabel:s(`layout.resizeSidebar`),cssVariable:`--sidebar-width`,defaultWidth:280,getMaxWidth:mt,growthDirection:`right`,maxWidth:480,minWidth:180,storageKey:`pi-sidebar-width`,widthRef:ft}),gt=ht.reclampWidth,_t=fe({ariaLabel:s(`layout.resizeWidgetPanel`),cssVariable:`--widget-panel-width`,defaultWidth:280,getMaxWidth:()=>typeof window>`u`?560:le({viewportWidth:window.innerWidth,sidebarOpen:ct,sidebarWidth:ht.width}),growthDirection:`left`,maxWidth:560,minWidth:200,storageKey:`pi-widget-panel-width`,widthRef:pt});(0,d.useEffect)(()=>{l&<(!1)},[l,lt]),(0,d.useEffect)(()=>{dt(!0)},[]),(0,d.useEffect)(()=>{gt()},[gt]);let vt=(0,d.useRef)(void 0);(0,d.useEffect)(()=>{ue!==vt.current&&(vt.current=ue,Ce(ue),we.load().catch(e=>console.error(`[pi-web] load updates:`,e)))},[ue]);let yt=(0,d.useRef)(null),bt=(0,d.useRef)(null),xt=(0,d.useRef)(null),St=(0,d.useRef)(null),Ct=(0,d.useRef)(null),wt=pe(),Tt=(0,d.useCallback)(()=>{wt.schedule(()=>{M(null)},150)},[wt]),Et=wt.cancel,[Dt,Ot]=(0,d.useState)(null),kt=(0,d.useCallback)(e=>{l&<(!1),M(t=>t===e?null:e)},[l]),At=(0,d.useCallback)(()=>{l&&M(null),lt(e=>!e)},[l]);(0,d.useEffect)(()=>{if(!j)return;let e=()=>{if(document.hidden)return;let e=bt.current?.getBoundingClientRect();if(e){if(j===`language`&&!l&&St.current){let t=St.current.getBoundingClientRect(),n=xt.current?.getBoundingClientRect(),r=n?.top??t.top,i=n?.bottom??t.bottom,a=Math.min(Ste,n?.width??e.width),o=Math.min(t.left-1,Math.max(n?.left??e.left,(n?.right??e.right)-a)),s=i+4;Ot({top:s+Q9>window.innerHeight-4?r-Q9:s,left:o,width:a});return}if(j===`fontSize`&&!l&&Ct.current){let t=Ct.current.getBoundingClientRect(),n=xt.current?.getBoundingClientRect(),r=n?.top??t.top,i=n?.bottom??t.bottom,a=Math.min(Cte,n?.width??e.width),o=Math.min(t.left-1,Math.max(n?.left??e.left,(n?.right??e.right)-a)),s=i+4;Ot({top:s+$9>window.innerHeight-4?r-$9:s,left:o,width:a});return}Ot({top:e.bottom,left:e.left,width:e.width})}};e();let t=new ResizeObserver(e);return bt.current&&t.observe(bt.current),St.current&&t.observe(St.current),Ct.current&&t.observe(Ct.current),()=>t.disconnect()},[j,l]);let{widgetPanelOpen:jt,setWidgetPanelOpen:Mt,widgetsTabActive:Nt,setWidgetsTabActive:Pt,extensionWidgets:Ft,closedWidgets:It,handleCloseWidget:Lt,handleReopenWidget:zt,handleExtensionWidgetsChange:Bt,rightSidebarOpen:Vt,setRightSidebarOpen:Ht,closedWidgetCount:Wt}=xq({widgetGeometries:S,setWidgetGeometry:C}),Gt=l?jt:Vt,Kt=(0,d.useCallback)((e,t)=>{yt.current?.insertText(jq(e,t))},[]),qt=(0,d.useCallback)(e=>{let t=Nq(e);t&&yt.current?.insertText(t)},[]),Jt=(0,d.useCallback)((e,t,n)=>{yt.current?.insertText(Mq(e,t,n))},[]),Yt=n.sessionId;ae({onNewSession:e=>Ee(`kb-${Date.now()}`,e),activeCwd:ue});let Xt=he&&!I,Zt=[{id:dq,label:s(`tabs.chat`),closable:!1,icon:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`})})},{id:pq,label:s(`tabs.widgets`),badge:Wt,closable:!1,icon:(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`})]})},...He?[{id:fq,label:s(`config.title`),closable:!0,icon:(0,E.jsx)(bi,{width:p.lg,height:p.lg,"aria-hidden":`true`})}]:[],...qe],Qt=ue?hG(ue)||ue:null,$t=Qt?`Pi Web · ${Qt}`:`Pi Web`;(0,d.useEffect)(()=>{document.title=$t},[$t]),(0,d.useEffect)(()=>{let e=()=>{document.title=$t};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[$t]);let en=L(),tn=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{ref:xt,style:{padding:`2px 8px`,flexShrink:0,display:`flex`,justifyContent:`space-between`,gap:4},children:[{label:s(`config.title`),onClick:()=>{M(null),Xe()},disabled:!1,badge:rt,icon:(0,E.jsx)(bi,{width:p[`3xl`],height:p[`3xl`],"aria-hidden":`true`})},...en===`granted`||en==="default"||en===`denied`?[{label:s(en===`granted`?`notify.permission.grantedHint`:en===`denied`?`notify.permission.deniedHint`:`notify.permission.requestHint`),ariaLabel:s(en===`granted`?`notify.permission.granted`:en===`denied`?`notify.permission.denied`:`notify.permission.request`),onClick:en===`granted`?()=>{}:()=>Dn(),disabled:!1,testId:`notify-permission`,color:en===`granted`?`var(--status-success)`:en===`denied`?`var(--status-error)`:`var(--accent)`,icon:(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:en===`denied`?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`path`,{d:`M8.7 3A6 6 0 0 1 18 8a21.3 21.3 0 0 0 .6 5`}),(0,E.jsx)(`path`,{d:`M17 17H3s3-2 3-9a4.67 4.67 0 0 1 .3-1.7`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`}),(0,E.jsx)(`path`,{d:`m2 2 20 20`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`path`,{d:`M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`})]})})}]:[],{label:s(r?`theme.light`:`theme.dark`),onClick:()=>i(),disabled:!1,ariaPressed:r,icon:r?(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,E.jsx)(`line`,{x1:`12`,y1:`1`,x2:`12`,y2:`3`}),(0,E.jsx)(`line`,{x1:`12`,y1:`21`,x2:`12`,y2:`23`}),(0,E.jsx)(`line`,{x1:`4.22`,y1:`4.22`,x2:`5.64`,y2:`5.64`}),(0,E.jsx)(`line`,{x1:`18.36`,y1:`18.36`,x2:`19.78`,y2:`19.78`}),(0,E.jsx)(`line`,{x1:`1`,y1:`12`,x2:`3`,y2:`12`}),(0,E.jsx)(`line`,{x1:`21`,y1:`12`,x2:`23`,y2:`12`}),(0,E.jsx)(`line`,{x1:`4.22`,y1:`19.78`,x2:`5.64`,y2:`18.36`}),(0,E.jsx)(`line`,{x1:`18.36`,y1:`5.64`,x2:`19.78`,y2:`4.22`})]}):(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`path`,{d:`M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z`})})},{label:s(`common.language`),onClick:()=>{l&<(!1),Et(),M(`language`)},onMouseEnter:()=>{Et(),j!==`language`&&M(`language`)},onMouseLeave:Tt,disabled:!1,ref:St,ariaExpanded:j===`language`,noTooltip:!0,icon:(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,E.jsx)(`line`,{x1:`2`,y1:`12`,x2:`22`,y2:`12`}),(0,E.jsx)(`path`,{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`})]})},{label:s(`theme.fontSize`),onClick:()=>{l&<(!1),Et(),M(`fontSize`)},onMouseEnter:()=>{Et(),j!==`fontSize`&&M(`fontSize`)},onMouseLeave:Tt,disabled:!1,ref:Ct,ariaExpanded:j===`fontSize`,noTooltip:!0,icon:(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`polyline`,{points:`4 7 4 4 20 4 20 7`}),(0,E.jsx)(`line`,{x1:`9`,y1:`20`,x2:`15`,y2:`20`}),(0,E.jsx)(`line`,{x1:`12`,y1:`4`,x2:`12`,y2:`20`})]})}].map(({label:e,onClick:t,onMouseEnter:n,onMouseLeave:r,disabled:i,icon:a,ref:o,ariaPressed:s,ariaExpanded:c,noTooltip:l,badge:u,color:d,ariaLabel:f,testId:p})=>{let m=(0,E.jsxs)(`button`,{ref:o,onClick:t,disabled:i,"data-testid":p,"aria-label":f??e,"aria-pressed":s,"aria-haspopup":c===void 0?void 0:`menu`,"aria-expanded":c,style:{flex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,height:32,padding:0,background:`none`,border:`none`,borderRadius:9,...d?{color:d}:{color:`var(--text-muted)`},cursor:i?`default`:`pointer`,opacity:i?.35:1,transition:`background 0.12s, color 0.12s`,"--hover-color":`var(--text)`},onMouseEnter:n,onMouseLeave:r,className:`hover-shift`,children:[a,u!==void 0&&u>0?(0,E.jsx)(`span`,{"data-testid":`settings-update-badge`,style:{position:`absolute`,top:3,right:3,minWidth:15,height:15,padding:`0 4px`,borderRadius:8,background:`var(--status-error)`,color:`#fff`,fontSize:10,fontWeight:600,lineHeight:`15px`,textAlign:`center`},children:u}):null]});return l?(0,E.jsx)(`div`,{style:{flex:1,minWidth:0,display:`flex`},children:m},e):(0,E.jsx)(qi,{label:e,wrapperStyle:{flex:1,minWidth:0,display:`flex`},children:m},e)})}),rt>0&&!at&&(0,E.jsxs)(`div`,{role:`status`,"data-testid":`update-banner`,style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 12px`,borderBottom:`1px solid var(--border)`,background:`color-mix(in srgb, var(--status-warning) 10%, var(--bg-panel))`,fontSize:`var(--text-sm)`,color:`var(--text)`,flexShrink:0},children:[(0,E.jsx)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:s(`updates.banner`,{items:it.join(`, `)})}),(0,E.jsx)(`button`,{type:`button`,"data-testid":`update-banner-view`,onClick:()=>{Xe(),We(`updates`)},style:{padding:`3px 10px`,border:`1px solid var(--border)`,borderRadius:6,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0},children:s(`updates.view`)}),(0,E.jsx)(`button`,{type:`button`,"aria-label":s(`i18n.close`),onClick:()=>ot(!0),style:{padding:`2px 6px`,border:`none`,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0},children:`✕`})]}),(0,E.jsx)(tte,{selectedSessionId:ee?.id??null,selectedSession:ee,onSelectSession:Te,onNewSession:Ee,initialSessionId:Yt,skipInitialProjectSelection:n.requestedCwd!==null,onInitialRestoreDone:ze,refreshKey:re,onSessionDeleted:je,onUnseenSession:Me,selectedCwd:ee?.cwd??F,onCwdChange:Ne,savedWorkspaces:b,onSavedWorkspacesChange:x,onOpenFile:Ye})]});if(!e)return(0,E.jsx)(Fq,{});let nn=(0,E.jsx)(qi,{label:s(ct?`sidebar.hide`:`sidebar.show`),children:(0,E.jsx)(`button`,{onClick:At,"aria-label":s(ct?`sidebar.hide`:`sidebar.show`),"aria-pressed":ct,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:Z9,height:Z9,padding:0,background:`none`,border:`none`,borderRight:`1px solid var(--border)`,color:ct?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,flexShrink:0,transition:`color 0.12s`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p[`4xl`],height:p[`4xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:p[`4xl`],height:p[`4xl`],rx:`2`}),(0,E.jsx)(`line`,{x1:`9`,y1:`3`,x2:`9`,y2:`21`})]})})}),rn=I&&ge?.requiresTrust&&!ge.trusted?(0,E.jsx)(qi,{label:s(`trust.resourcesNotLoaded`),wrapperStyle:{height:`100%`},children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{xe(null),ve(!0)},"aria-label":s(`trust.resourcesNotLoaded`),style:{display:`flex`,alignItems:`center`,gap:6,height:`100%`,padding:l?`0 10px`:`0 12px`,background:`none`,border:`none`,borderLeft:`1px solid var(--border)`,color:`var(--status-warning)`,cursor:`pointer`,flexShrink:0,fontSize:`var(--text-sm)`,whiteSpace:`nowrap`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`M12 8v4`}),(0,E.jsx)(`path`,{d:`M12 16h.01`})]}),!l&&(0,E.jsx)(`span`,{children:s(`trust.resourcesNotLoaded`)})]})}):null,an=(0,E.jsx)(qi,{label:s(Gt?`sidebar.hide`:`sidebar.show`),children:(0,E.jsx)(`button`,{onClick:()=>{l?Mt(e=>!e):Ht(e=>!e)},"aria-controls":`widget-panel`,"aria-expanded":Gt,"aria-label":s(Gt?`sidebar.hide`:`sidebar.show`),"data-testid":`widget-panel-toggle`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:36,padding:0,background:`none`,border:`none`,borderLeft:`1px solid var(--border)`,color:jt?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,flexShrink:0,transition:`color 0.12s`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p[`4xl`],height:p[`4xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:p[`4xl`],height:p[`4xl`],rx:`2`}),(0,E.jsx)(`line`,{x1:`15`,y1:`3`,x2:`15`,y2:`21`})]})})});return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Re,{value:u,children:(0,E.jsx)(et,{value:{activeTopPanel:j,toggleTopPanel:kt,closeTopPanel:()=>M(null)},children:(0,E.jsx)(E.Fragment,{children:(0,E.jsxs)(Ki,{delayDuration:0,children:[(0,E.jsx)(`style`,{children:`
|
|
497
|
+
`)?r===`mermaid`?(0,E.jsx)(R8,{code:i.replace(/\n$/,``),defaultPreview:!0}):(0,E.jsx)(H8,{code:i.replace(/\n$/,``),lang:r}):(0,E.jsx)(`code`,{className:e,...n,children:t})},pre({children:e}){return(0,E.jsx)(E.Fragment,{children:e})},a({href:e,children:t,...n}){return delete n.node,(0,E.jsx)(BG,{href:e,markdownDir:Te,onOpenFile:r,...n,children:t})},img({src:e,alt:r,...i}){delete i.node;let a=typeof e==`string`?RG(e,Te,t??Te):null,o=a?s9(a,`read`,n):e;return(0,E.jsx)(`img`,{src:o,alt:r??``,loading:`lazy`,...i})}},children:pe})}):null]})]})}function Ree({cwd:e,busy:t,error:n,onCancel:r,onConfirm:i}){let{t:a}=N();return(0,E.jsx)(jS,{open:!0,onOpenChange:e=>{!e&&!t&&r()},children:(0,E.jsxs)(FS,{className:`w-[440px] gap-0 overflow-hidden rounded-lg p-0`,style:{zIndex:1100,maxWidth:`100%`},showCloseButton:!1,onPointerDownOutside:e=>{t&&e.preventDefault()},onEscapeKeyDown:e=>{t&&e.preventDefault()},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,gap:12,padding:`18px 18px 14px`},children:[(0,E.jsxs)(`svg`,{width:p[`5xl`],height:p[`5xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--status-warning)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0,marginTop:1},children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`m9 12 2 2 4-4`})]}),(0,E.jsxs)(`div`,{style:{minWidth:0},children:[(0,E.jsx)(IS,{style:{fontSize:`var(--text-2xl)`,fontWeight:700,color:`var(--text)`,lineHeight:1.4},children:a(`trust.dialogTitle`)}),(0,E.jsx)(LS,{style:{marginTop:7,fontSize:`var(--text-base)`,lineHeight:1.6,color:`var(--text-muted)`},children:a(`trust.dialogBody`)}),(0,E.jsx)(`code`,{style:{display:`block`,marginTop:10,padding:`8px 10px`,border:`1px solid var(--border)`,borderRadius:5,background:`var(--bg)`,color:`var(--text)`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,overflowWrap:`anywhere`},children:e}),n&&(0,E.jsx)(`div`,{role:`alert`,style:{marginTop:10,color:`var(--status-error)`,fontSize:`var(--text-base)`,lineHeight:1.5},children:n})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,padding:`10px 18px`,borderTop:`1px solid var(--border)`},children:[(0,E.jsx)(AS,{type:`button`,variant:`outline`,onClick:r,disabled:t,className:`h-8 px-3 text-xs`,children:a(`trust.cancel`)}),(0,E.jsx)(AS,{type:`button`,onClick:i,disabled:t,className:`h-8 px-3 text-xs`,style:{cursor:t?`wait`:`pointer`},children:a(t?`trust.trusting`:`trust.trustProject`)})]})]})})}function zee({onCancel:e,onSelect:t,busy:n=!1,error:r}){let{t:i}=N(),[a,o]=(0,d.useState)(!0),[s,c]=(0,d.useState)(``),[l,u]=(0,d.useState)(null),[f,m]=(0,d.useState)(``),[h,g]=(0,d.useState)([]),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)(!0),T=(0,d.useRef)(null),D=(0,d.useCallback)(async e=>{w(!0),S(null);try{let t=await bG(e),n=t.path??e??`/`;c(n),u(t.parentPath??null),m(n),g(t.directories??[]),v(t.drives??null),b(``)}catch(e){S(e instanceof Error?e.message:String(e))}finally{w(!1)}},[]);(0,d.useEffect)(()=>{D()},[D]);let O=e=>{e.preventDefault();let t=f.trim();t&&D(t)},k=f.trim()!==s,A=!!s&&!k&&!n,j=!!l||wG(s),M=y.trim().toLowerCase(),P=e=>!M||e.toLowerCase().includes(M),ee=_===null?[]:_.filter(e=>P(e.name)||P(e.path)),F=h.filter(e=>P(e.name));return(0,E.jsx)(jS,{open:a,onOpenChange:t=>{!t&&!n&&(o(!1),e())},children:(0,E.jsxs)(FS,{className:`directory-picker-light flex w-[520px] max-w-[calc(100vw-16px)] flex-col gap-0 overflow-hidden p-0`,style:{height:`min(620px, calc(100dvh - 16px))`},showCloseButton:!1,onPointerDownOutside:e=>{n&&e.preventDefault()},onEscapeKeyDown:e=>{n&&e.preventDefault()},onOpenAutoFocus:e=>{e.preventDefault(),T.current?.focus()},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,flexShrink:0,padding:`12px 18px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(IS,{style:{fontWeight:700,fontSize:`var(--text-2xl)`,color:`var(--text)`},children:i(`directoryPicker.selectDirectory`)}),(0,E.jsx)(NS,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,disabled:n,title:i(`i18n.close`),"aria-label":i(`i18n.close`),style:{padding:`2px 6px`,border:0,background:`none`,color:`var(--text-muted)`,fontSize:`var(--text-5xl)`,lineHeight:1,cursor:n?`default`:`pointer`,opacity:n?.5:1},children:`×`})})]}),(0,E.jsxs)(`form`,{onSubmit:O,style:{display:`flex`,alignItems:`center`,gap:8,flexShrink:0,padding:`10px 14px`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsx)(`button`,{className:`directory-picker-back`,type:`button`,onClick:()=>void D(l??void 0),disabled:C||!j,title:i(`directoryPicker.goToParent`),"aria-label":i(`directoryPicker.goToParent`),style:{width:36,height:36,padding:0,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`1px solid var(--border)`,borderRadius:6,background:`#ffffff`,color:`var(--text-muted)`,cursor:j?`pointer`:`default`,opacity:j?1:.45},children:(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m18 15-6-6-6 6`})})}),(0,E.jsx)(`label`,{htmlFor:`directory-path`,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:i(`directoryPicker.directoryPath`)}),(0,E.jsx)(yG,{className:`directory-picker-path h-9 flex-1 font-mono text-xs`,id:`directory-path`,type:`text`,ref:T,value:f,placeholder:`/path/to/project or ~/project`,autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>{m(e.target.value),S(null)}}),(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`submit`,disabled:C||!f.trim(),title:i(`directoryPicker.goToDirectory`),style:{minWidth:58,height:36,padding:`0 12px`,border:`1px solid var(--border)`,borderRadius:6,background:`#ffffff`,color:`var(--text-muted)`,cursor:C||!f.trim()?`default`:`pointer`,opacity:C||!f.trim()?.6:1},children:i(`directoryPicker.go`)})]}),(0,E.jsxs)(`div`,{className:`directory-picker-list`,style:{flex:1,minHeight:0,overflow:`auto`,padding:`8px 10px`},children:[C?(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(`directoryPicker.loadingDirectories`)}):_===null?F.length>0?F.map(e=>(0,E.jsxs)(`button`,{className:`directory-picker-entry`,type:`button`,onClick:()=>void D(e.path),title:e.path,style:{width:`100%`,minHeight:30,display:`flex`,alignItems:`center`,gap:7,padding:`5px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(SG,{}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(M?`directoryPicker.noMatches`:`directoryPicker.noSubdirectories`)}):ee.length>0?ee.map(e=>(0,E.jsxs)(`button`,{className:`directory-picker-entry`,type:`button`,onClick:()=>void D(e.path),title:e.path,style:{width:`100%`,minHeight:34,display:`flex`,alignItems:`center`,gap:7,padding:`6px 8px`,border:0,borderRadius:5,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`},children:[(0,E.jsx)(CG,{}),(0,E.jsx)(`span`,{children:e.name})]},e.path)):(0,E.jsx)(`div`,{style:{padding:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`},children:i(M?`directoryPicker.noMatches`:`directoryPicker.noDrives`)}),(x||r)&&(0,E.jsx)(`div`,{style:{padding:`8px`,color:`var(--status-error)`,fontSize:`var(--text-sm)`},children:x??r})]}),(0,E.jsxs)(`div`,{className:`directory-picker-footer`,style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:10,flexShrink:0,padding:`10px 18px`,borderTop:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flex:1,minWidth:0},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`var(--text-dim)`,flexShrink:0},children:[(0,E.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,E.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),(0,E.jsx)(yG,{className:`directory-picker-search h-8 flex-1`,type:`text`,value:y,placeholder:i(`directoryPicker.search`),"aria-label":i(`directoryPicker.search`),autoComplete:`off`,spellCheck:!1,style:xG,onChange:e=>b(e.target.value)})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,flexShrink:0},children:[(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`button`,onClick:e,disabled:n,style:{padding:`6px 14px`,border:`1px solid var(--border)`,borderRadius:6,background:`none`,color:`var(--text-muted)`,cursor:n?`default`:`pointer`,fontSize:`var(--text-lg)`},children:i(`i18n.cancel`)}),(0,E.jsx)(`button`,{className:`directory-picker-action`,type:`button`,onClick:()=>t(s),disabled:!A,title:i(k?`directoryPicker.openBeforeSelecting`:`directoryPicker.selectCurrentDirectory`),style:{padding:`6px 16px`,border:0,borderRadius:6,background:`var(--accent)`,color:`var(--on-accent)`,fontSize:`var(--text-lg)`,fontWeight:600,opacity:A?1:.6,cursor:A?`pointer`:`default`},children:i(n?`i18n.checking`:`directoryPicker.selectThisFolder`)})]})]})]})})}function y9({visible:e=!0,gap:t=4,items:n}){return e?(0,E.jsx)(`div`,{style:{display:`flex`,gap:t,flexShrink:0},children:n.map(e=>(0,E.jsx)(qi,{label:e.title,children:(0,E.jsx)(`button`,{type:`button`,onClick:e.onClick,disabled:e.disabled,"data-testid":e.testId,"aria-label":e.title,"aria-pressed":e.ariaPressed,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:32,height:32,padding:0,background:e.background??`transparent`,border:`1px solid ${e.borderColor??`var(--border)`}`,borderRadius:7,color:e.color??`var(--text-muted)`,cursor:e.disabled?`default`:`pointer`,flexShrink:0,opacity:e.disabled?.6:1,transition:`background 0.12s, color 0.12s, border-color 0.12s`,"--hover-bg":e.danger?`color-mix(in srgb, var(--status-error) 8%, transparent)`:`var(--bg-selected)`,"--hover-color":e.danger?`var(--status-error)`:`var(--accent)`,"--hover-border":e.danger?`color-mix(in srgb, var(--status-error) 35%, transparent)`:`color-mix(in srgb, var(--accent) 35%, transparent)`},className:e.skipHover?void 0:`hover-shift`,children:e.icon})},e.key))}):null}var b9=2;function Bee({scrollStepPx:e=200,wrapperStyle:t,children:n,testId:r,hintTestId:i}){let a=(0,d.useRef)(null),[o,s]=(0,d.useState)({scrollHeight:0,clientHeight:0,scrollTop:0}),c=(0,d.useCallback)(()=>{if(document.hidden)return;let e=a.current;e&&s({scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,scrollTop:e.scrollTop})},[]);(0,d.useLayoutEffect)(()=>{c();let e=a.current;if(!e)return;let t=new ResizeObserver(c);return t.observe(e),()=>t.disconnect()},[c]);let{scrollHeight:l,clientHeight:u,scrollTop:f}=o,p=l-u>20,m=f<=b9,h=f+u>=l-b9,g=t=>{let n=a.current;if(!n)return;let r=Math.max(0,n.scrollHeight-n.clientHeight);n.scrollTo({top:Math.max(0,Math.min(r,n.scrollTop+t*e)),behavior:`smooth`})},_=e=>{let t=a.current;t&&t.scrollTo({top:e===`top`?0:Math.max(0,t.scrollHeight-t.clientHeight),behavior:`smooth`})};return(0,E.jsxs)(`div`,{style:{position:`relative`,...t},children:[(0,E.jsx)(`div`,{ref:a,"data-testid":r,onScroll:c,style:{position:`absolute`,inset:0,overflowY:`auto`,overflowX:`hidden`,padding:0},children:n}),p&&!m&&(0,E.jsx)(hr,{direction:`up`,visible:!0,testId:i?`${i}-scroll-up`:void 0,onHover:()=>g(-1),onClick:()=>_(`top`)}),p&&!h&&(0,E.jsx)(hr,{direction:`down`,visible:!0,testId:i?`${i}-scroll-down`:void 0,onHover:()=>g(1),onClick:()=>_(`bottom`)})]})}function Vee({...e}){return(0,E.jsx)($o,{"data-slot":`collapsible`,...e})}function Hee({...e}){return(0,E.jsx)(Jo,{"data-slot":`collapsible-trigger`,...e})}function Uee({...e}){return(0,E.jsx)(Xo,{"data-slot":`collapsible-content`,...e})}function Wee({title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i=!0,actions:a,expandedFlex:o=`1 1 0`,style:s,children:c}){return(0,E.jsxs)(Vee,{open:n,onOpenChange:r,style:{borderTop:`1px solid var(--border)`,display:`flex`,flexDirection:`column`,flex:n?o:`0 0 auto`,minHeight:0,overflow:`hidden`,...s},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,flexShrink:0,background:`var(--bg-panel)`},children:[(0,E.jsx)(qi,{label:t??e,children:(0,E.jsx)(Hee,{asChild:!0,children:(0,E.jsxs)(`button`,{type:`button`,disabled:!i,style:{display:`flex`,alignItems:`center`,gap:6,flex:`0 0 auto`,height:36,padding:`0 12px`,background:`none`,border:`none`,color:`var(--text-muted)`,cursor:i?`pointer`:`default`,fontSize:`var(--text-base)`,fontWeight:600,letterSpacing:`0.05em`,textTransform:`none`,textAlign:`left`},children:[i&&(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{transform:n?`rotate(90deg)`:`none`,transition:`transform 0.15s`,flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`3 2 7 5 3 8`})}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e})]})})}),a&&(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,marginLeft:`auto`,minWidth:0,gap:6,flexShrink:1,paddingRight:4},children:a})]}),(0,E.jsx)(Uee,{style:{display:`flex`,flexDirection:`column`,minHeight:0,flex:1},children:c})]})}function x9({title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i=!0,actions:a,headerExtra:o,expandedFlex:s=`1 1 0`,scrollStepPx:c=200,testId:l,hintTestId:u,rootTestId:d,scrollStyle:f,style:p,children:m}){return(0,E.jsx)(`div`,{"data-testid":d,style:{display:`flex`,flexDirection:`column`,border:`1px solid var(--border)`,borderRadius:0,background:`var(--bg-panel)`,overflow:`hidden`,...p},children:(0,E.jsxs)(Wee,{title:e,titleTooltip:t,open:n,onToggle:r,collapsible:i,actions:a,expandedFlex:s,style:{borderTop:`none`},children:[o,(0,E.jsx)(Bee,{scrollStepPx:c,wrapperStyle:{flex:1,minHeight:0,...f},testId:l,hintTestId:u,children:m})]})})}function Gee(e){return e.error?e.path.split(/[\\/]/).pop()||e.id:e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12)}var S9=(e,t)=>e.replace(/\\/g,`/`)===t.replace(/\\/g,`/`),C9=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``).replace(/^[a-zA-Z]:/,e=>e.toLowerCase()),w9=`pi-web:unread-session-ids`;function Kee(){if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(w9);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function T9(e){if(!(typeof window>`u`))try{e.size===0?window.localStorage.removeItem(w9):window.localStorage.setItem(w9,JSON.stringify([...e]))}catch{}}function qee(){let[e,t]=(0,d.useState)(()=>Kee());return(0,d.useEffect)(()=>{T9(e)},[e]),{unreadSessionIds:e,setUnreadSessionIds:t}}function Jee(e){let{selectedCwd:t,selectedCwdProp:n,refreshKey:r,setSelectedCwd:i}=e,[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1),[l,u]=(0,d.useState)(!1),[f,p]=(0,d.useState)(``),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(!1),[v,y]=(0,d.useState)(null),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(``),w=(0,d.useRef)(null),T=(0,d.useRef)(null),E=(0,d.useRef)(null);(0,d.useEffect)(()=>{n&&n!==E.current&&(E.current=n,i(n))},[n,i]);let D=(0,d.useCallback)(()=>{c(!1),u(!1),p(``),h(null),y(null),C(``)},[]),[O,k]=(0,d.useState)(0);(0,d.useLayoutEffect)(()=>{if(!t){o(null),x(null);return}let e=!1;return x(t),fetch(`/api/worktrees?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(n=>{if(!e){if(x(null),n.error||!n.projectRoot){o(null);return}o({forCwd:t,projectRoot:n.projectRoot,isGit:n.isGit??!1,isTopLevel:n.isTopLevel??!1,worktrees:n.worktrees??[]})}}).catch(()=>{e||(x(null),o(null))}),()=>{e=!0}},[t,O,r]);let A=(0,d.useCallback)(async()=>{let e=f.trim();if(!(!e||g||!a)){_(!0),h(null);try{let t=await fetch(`/api/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:a.projectRoot,branch:e})}),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!n.path){h(n.error??`HTTP ${t.status}`);return}D(),o(t=>t&&{...t,forCwd:n.path,worktrees:[...t.worktrees,{path:n.path,branch:e,isMain:!1}]}),i(n.path),k(e=>e+1)}catch(e){h(e instanceof Error?e.message:String(e))}finally{_(!1)}}},[D,f,g,a,i]),j=(0,d.useCallback)(async(e,n)=>{if(!(!a||g)){_(!0),h(null);try{let r=await fetch(`/api/worktrees`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:a.projectRoot,path:e,force:n})}),o=await r.json().catch(()=>({}));if(!r.ok){if(o.dirty&&!n){y(e);return}h(o.error??`HTTP ${r.status}`);return}D(),t&&e&&S9(t,e)&&i(a.projectRoot),k(e=>e+1)}catch(e){h(e instanceof Error?e.message:String(e))}finally{_(!1)}}},[D,a,g,t,i]);return(0,d.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&D()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[D]),{worktreeState:a,worktreeLoadingCwd:b,wtDropdownOpen:s,setWtDropdownOpen:c,wtNewOpen:l,setWtNewOpen:u,wtNewBranch:f,setWtNewBranch:p,wtError:m,setWtError:h,wtBusy:g,wtConfirmRemove:v,setWtConfirmRemove:y,wtFilter:S,setWtFilter:C,wtDropdownRef:w,wtNewInputRef:T,closeWorktrees:D,handleCreateWorktree:A,handleRemoveWorktree:j}}function Yee({wt:e,selectedCwd:t,homeDir:n,setSelectedCwd:r}){let{t:i}=N(),{worktreeState:a,wtFilter:o,setWtFilter:s,wtDropdownOpen:c,setWtDropdownOpen:l,wtDropdownRef:u,closeWorktrees:d,handleRemoveWorktree:f,wtConfirmRemove:m,setWtConfirmRemove:h,wtBusy:g,wtNewOpen:_,setWtNewOpen:v,wtNewBranch:y,setWtNewBranch:b,wtNewInputRef:x,handleCreateWorktree:S,wtError:C,setWtError:w}=e;if(!a)return null;let T=a.worktrees.find(e=>S9(e.path,t))??a.worktrees.find(e=>e.isMain),D=a.worktrees.length>=8,O=D&&o.trim()?a.worktrees.filter(e=>(e.branch??D9(e.path,n)).toLowerCase().includes(o.trim().toLowerCase())):a.worktrees;return(0,E.jsxs)(`div`,{ref:u,"data-testid":`worktree-switcher`,style:{position:`relative`,marginTop:6},children:[(0,E.jsxs)(`button`,{"data-testid":`worktree-switcher-trigger`,onClick:()=>l(e=>!e),title:T?i(`sidebar.switchWorktreeTitle`,{path:T.path}):i(`sidebar.switchWorktree`),style:{width:`100%`,height:29,boxSizing:`border-box`,display:`flex`,alignItems:`center`,gap:6,padding:`0 10px`,background:`var(--bg-input)`,border:`1px solid var(--border)`,borderRadius:7,cursor:`pointer`,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--text-muted)`,textAlign:`left`},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0,color:T&&!T.isMain?`var(--accent)`:`var(--text-dim)`},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(O9,{text:T?T.branch??D9(T.path,n):`…`,style:{flex:1,fontFamily:`var(--font-mono)`,color:`var(--text)`}}),T?.isMain&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:i(`sidebar.main`)}),a.worktrees.length>1&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:a.worktrees.length}),(0,E.jsx)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`2 3.5 5 6.5 8 3.5`})})]}),(0,E.jsxs)($ee,{open:c,style:{position:`absolute`,top:`calc(100% + 4px)`,left:0,right:0,zIndex:100,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:8,boxShadow:`0 6px 20px var(--shadow-color)`,overflow:`hidden`},children:[D&&(0,E.jsx)(`div`,{style:{padding:`6px 8px`,borderBottom:`1px solid var(--border)`},children:(0,E.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(s(``),d())},placeholder:i(`sidebar.filterWorktrees`),autoFocus:!0,style:{width:`100%`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,padding:`5px 8px`,border:`1px solid var(--border)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,boxSizing:`border-box`}})}),(0,E.jsxs)(`div`,{style:{maxHeight:`min(40vh, 300px)`,overflowY:`auto`},children:[O.map(e=>{let o=S9(e.path,t)||e.isMain&&!a.worktrees.some(e=>S9(e.path,t));return m===e.path?(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,padding:`7px 10px`,borderBottom:`1px solid var(--border)`,background:`color-mix(in srgb, var(--status-error) 6%, transparent)`},children:[(0,E.jsx)(`span`,{style:{flex:1,fontSize:`var(--text-sm)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:i(`sidebar.forceRemoveCheckout`)}),(0,E.jsx)(`button`,{"data-testid":`worktree-force-remove`,onClick:()=>void f(e.path,!0),disabled:g,style:{padding:`3px 9px`,background:`var(--status-error)`,border:`none`,borderRadius:5,color:`var(--on-error)`,fontSize:`var(--text-sm)`,fontWeight:600,cursor:`pointer`,flexShrink:0},children:i(`sidebar.force`)}),(0,E.jsx)(`button`,{onClick:()=>h(null),style:{padding:`3px 9px`,background:`var(--bg-hover)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`,flexShrink:0},children:i(`sidebar.cancel`)})]},e.path):(0,E.jsxs)(`div`,{className:`wt-row`,"data-testid":`worktree-row`,style:{display:`flex`,alignItems:`center`,borderBottom:`1px solid var(--border)`},children:[(0,E.jsxs)(`button`,{"data-testid":`worktree-item`,onClick:()=>{r(e.path),d()},title:e.path,style:{flex:1,minWidth:0,display:`flex`,alignItems:`center`,gap:7,padding:`8px 10px`,background:`var(--bg)`,border:`none`,color:o?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`},children:[o?(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`var(--accent)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:(0,E.jsx)(`polyline`,{points:`1.5 5 4 7.5 8.5 2.5`})}):(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(O9,{text:e.branch??D9(e.path,n),style:{flex:1}}),e.isMain&&(0,E.jsx)(`span`,{style:{flexShrink:0,color:`var(--text-dim)`,fontSize:`var(--text-xs)`},children:i(`sidebar.main`)})]}),!e.isMain&&(0,E.jsx)(`button`,{"data-testid":`worktree-remove`,onClick:()=>void f(e.path,!1),disabled:g,title:i(`sidebar.removeWorktreeTitle`,{path:e.path}),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:34,height:28,padding:0,marginRight:4,background:`none`,border:`none`,color:`var(--text-dim)`,cursor:`pointer`,borderRadius:5,flexShrink:0,transition:`color 0.12s, background 0.12s`,"--hover-color":`var(--status-error)`,"--hover-bg":`color-mix(in srgb, var(--status-error) 8%, transparent)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p.base,height:p.base,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`polyline`,{points:`3 6 5 6 21 6`}),(0,E.jsx)(`path`,{d:`M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6`}),(0,E.jsx)(`path`,{d:`M10 11v6M14 11v6`}),(0,E.jsx)(`path`,{d:`M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2`})]})})]},e.path)}),D&&O.length===0&&o.trim()&&(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:i(`sidebar.noMatchingWorktrees`)})]}),_?(0,E.jsxs)(`div`,{style:{padding:`6px 8px`},children:[(0,E.jsx)(`input`,{ref:x,"data-testid":`worktree-new-branch-input`,value:y,onChange:e=>{b(e.target.value),w(null)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),S()),e.key===`Escape`&&(v(!1),b(``),w(null))},placeholder:i(`sidebar.branchName`),style:{width:`100%`,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,padding:`5px 8px`,border:`1px solid var(--accent)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,boxSizing:`border-box`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,marginTop:5},children:[(0,E.jsx)(`button`,{"data-testid":`worktree-create`,onClick:()=>void S(),disabled:g||!y.trim(),style:{flex:1,padding:`4px 0`,background:`var(--accent)`,border:`none`,borderRadius:5,color:`var(--on-accent)`,fontSize:`var(--text-sm)`,fontWeight:600,cursor:g||!y.trim()?`not-allowed`:`pointer`,opacity:g||!y.trim()?.65:1},children:i(g?`sidebar.creating`:`sidebar.create`)}),(0,E.jsx)(`button`,{onClick:()=>{v(!1),b(``),w(null)},style:{flex:1,padding:`4px 0`,background:`var(--bg-hover)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:i(`sidebar.cancel`)})]})]}):(0,E.jsxs)(`button`,{"data-testid":`worktree-new`,onClick:e=>{e.stopPropagation(),v(!0),w(null),setTimeout(()=>x.current?.focus(),0)},title:i(`sidebar.createWorktreeTitle`),style:{display:`flex`,alignItems:`center`,gap:7,width:`100%`,padding:`8px 10px`,background:`none`,border:`none`,color:`var(--text-muted)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-sm)`},children:[(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.1`,strokeLinecap:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`5`,y1:`1`,x2:`5`,y2:`9`}),(0,E.jsx)(`line`,{x1:`1`,y1:`5`,x2:`9`,y2:`5`})]}),(0,E.jsx)(`span`,{children:i(`sidebar.newWorktree`)})]}),C&&(0,E.jsx)(`div`,{style:{padding:`5px 10px 8px`,color:`var(--status-error)`,fontSize:`var(--text-sm)`,lineHeight:1.35,overflowWrap:`anywhere`},children:C})]})]})}function E9(e,t){let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4),a=Math.floor(r/36e5),o=Math.floor(r/864e5);return i<1?t(`sidebar.justNow`):i<60?t(`sidebar.minutesAgo`,{count:i}):a<24?t(`sidebar.hoursAgo`,{count:a}):o<7?t(`sidebar.daysAgo`,{count:o}):n.toLocaleDateString()}function Xee(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=t.get(e);(!r||n.modified>r)&&t.set(e,n.modified)}return[...t.entries()].sort((e,t)=>t[1].localeCompare(e[1])).map(([e])=>e)}function D9(e,t){return t&&e.startsWith(t)?`~${e.slice(t.length)}`:e}function Zee(e){let t=e.split(/[\\/]+/).filter(Boolean);return t.length?t[t.length-1]:e}function O9({text:e,style:t}){return(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,display:`block`,minWidth:0,lineHeight:1.35,direction:`rtl`,textAlign:`left`,...t},children:(0,E.jsx)(`span`,{style:{unicodeBidi:`plaintext`},children:e})})}function k9({session:e}){return(0,E.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:4,color:`var(--danger)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:`${e.path}: ${e.error}`,children:[(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0},children:[(0,E.jsx)(`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`}),(0,E.jsx)(`path`,{d:`M12 9v4`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),e.error]})}var A9=140,Qee=2e3;function $ee({open:e,children:t,style:n}){let[r,i]=(0,d.useState)(e),[a,o]=(0,d.useState)(e);return(0,d.useEffect)(()=>{let t,n;return e?(i(!0),o(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>o(!0))})):(o(!1),n=setTimeout(()=>i(!1),A9)),()=>{t!==void 0&&window.cancelAnimationFrame(t),n&&clearTimeout(n)}},[e]),r?(0,E.jsx)(`div`,{style:{...n,opacity:+!!a,transform:a?`translateY(0) scale(1)`:`translateY(-8px) scale(0.96)`,transformOrigin:`top center`,transition:`opacity ${A9}ms ease, transform ${A9}ms ease`,pointerEvents:e?`auto`:`none`},children:t}):null}function ete(e){let t=new Map;for(let n of e)t.set(n.id,{session:n,children:[]});let n=new Map;for(let t of e)t.parentSessionId&&n.set(t.id,t.parentSessionId);function r(e){let r=n.get(e),i=new Set;for(;r;){if(i.has(r))return null;if(i.add(r),t.has(r))return r;r=n.get(r)}return null}let i=[];for(let e of t.values()){let n=r(e.session.id);n?t.get(n).children.push(e):i.push(e)}let a=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>a(e.children))};return a(i),i}function tte({selectedSessionId:e,selectedSession:t,onSelectSession:n,onNewSession:r,initialSessionId:i,skipInitialProjectSelection:a,onInitialRestoreDone:o,refreshKey:s,onSessionDeleted:c,onUnseenSession:l,selectedCwd:u,onCwdChange:f,savedWorkspaces:m,onSavedWorkspacesChange:h,onOpenFile:g}){let{t:_}=N(),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(!0),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(null),[D,O]=(0,d.useState)(``),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(``),[P,ee]=(0,d.useState)(null),[F,I]=(0,d.useState)(!1),te=Jee({selectedCwd:w,selectedCwdProp:u,refreshKey:s,setSelectedCwd:T}),{worktreeState:ne,worktreeLoadingCwd:re}=te,[ie,ae]=(0,d.useState)(!1),[L,R]=(0,d.useState)(``),oe=(0,d.useRef)(null);(0,d.useEffect)(()=>{ie&&oe.current?.focus()},[ie]);let[z,se]=(0,d.useState)(!1),[ce,le]=(0,d.useState)(()=>new Set),ue=(0,d.useCallback)(e=>{le(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),de=(0,d.useCallback)(e=>{le(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}),un(e),l?.(e)},[l]),{unreadSessionIds:fe,setUnreadSessionIds:pe}=qee(),me=fJ(),{runningSessionIds:he,runningPhases:ge,runningPhaseSince:_e,runningBusySince:ye,setRunningSessionIds:be,runningPollAuthoritativeRef:xe}=Sn(),Se=(0,d.useRef)(new Set),Ce=(0,d.useRef)(null),we=(0,d.useRef)(0),Te=(0,d.useCallback)(async(e=!1,t=!1)=>{try{e&&x(!0);let n=t?await ve.refresh():await ve.load();y(n.sessions),xe.current||be(new Set(n.runningSessionIds??[]));let r=new Set(n.sessions.map(e=>e.id));pe(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),C(null),e||(se(!0),Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>se(!1),2e3))}catch(e){C(String(e))}finally{e&&x(!1)}},[pe,be,xe]),Ee=(0,d.useRef)(!1);(0,d.useEffect)(()=>{let e=!Ee.current;Ee.current=!0,Te(e,e)},[Te,s]),(0,d.useEffect)(()=>{T9(fe)},[fe]),(0,d.useEffect)(()=>{let t=[...Se.current].filter(t=>!he.has(t)&&t!==e),n=[...he];if((t.length>0||n.length>0)&&pe(e=>{let r=new Set(e);return n.forEach(e=>r.delete(e)),t.forEach(e=>r.add(e)),r}),t.length>0&&Te(!1),[...he].filter(e=>!v.some(t=>t.id===e)).length>0){let e=Date.now();e-we.current>=Qee&&(we.current=e,Te(!1,!0))}Se.current=he},[he,e,v,Te,pe]),(0,d.useEffect)(()=>{e&&(lJ(e),pe(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n}))},[e,pe]),(0,d.useEffect)(()=>{fetch(`/api/home`).then(e=>e.json()).then(e=>{e.home&&O(e.home)}).catch(e=>console.error(`[pi-web] load home dir:`,e))},[]);let De=(0,d.useRef)(!1),Oe=(0,d.useCallback)(e=>e?ne&&ne.forCwd&&S9(ne.forCwd,e)||ne?.worktrees.some(t=>S9(t.path,e))?ne.projectRoot:v.find(t=>t.cwd&&S9(t.cwd,e))?.projectRoot??e:null,[ne,v]),ke=(0,d.useRef)(null);(0,d.useEffect)(()=>{ke.current!==w&&(ke.current=w,f?.(w,Oe(w)))},[w,f,Oe]),(0,d.useEffect)(()=>{if(!(v.length===0||a)&&w===null){if(i&&!De.current){De.current=!0;let e=v.find(e=>e.id===i);if(e){T(e.cwd),ue(e.id),n(e,!0);return}o?.()}let e=Xee(v);e.length>0&&T(e[0])}},[v,w,i,a,n,o,ue]);let Ae=(0,d.useCallback)(async e=>{let t=(e??j).trim();if(!(!t||F)){I(!0),ee(null);try{let e=await fetch(`/api/cwd/validate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:t})}),n=await e.json().catch(()=>({}));if(!e.ok||n.error){ee(n.error??`HTTP ${e.status}`);return}let r=n.cwd??t;if(T(r),A(!1),M(``),h){let e=m??[];e.some(e=>C9(e)===C9(r))||h([...e,r])}}catch(e){ee(e instanceof Error?e.message:String(e))}finally{I(!1)}}},[j,F,m,h]),je=(0,d.useCallback)(async e=>{try{if((await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`HEAD`})).status===404){C(_(`sidebar.sessionDeleted`)),Te(!1,!0);return}}catch{}e.cwd&&T(e.cwd),ue(e.id),n(e)},[n,_,Te,ue]),Me=(0,d.useCallback)(e=>{let t=e??w;if(!t)return;let n=typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(n,t)},[w,r]),[Ne,Pe]=(0,d.useState)({}),[Fe,Ie]=(0,d.useState)(null),[Le,Re]=(0,d.useState)(null),[ze,Be]=(0,d.useState)(!1),Ve=Oe(w),He=v,Ue=!!(ne?.isGit&&ne.isTopLevel&&w&&Ve===ne.projectRoot),We=(w&&ne&&Ve===ne.projectRoot&&!Ue?ne.isGit?{label:_(`sidebar.openRepoRoot`),title:_(`sidebar.openRepoRootTitle`)}:{label:_(`sidebar.gitRepoRootOnly`),title:_(`sidebar.gitRepoRootOnlyTitle`)}:null)??(w&&re===w&&!Ue?{label:_(`sidebar.worktrees`),title:_(`sidebar.checkingWorktrees`)}:null),Ge=(0,d.useCallback)(async e=>{Re(null),Be(!0);try{await Promise.all(e.sessions.map(e=>fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`}).then(t=>{t.ok||console.error(`[sidebar] failed to delete ${e.id}:`,t.status)}).catch(t=>console.error(`[sidebar] failed to delete ${e.id}:`,t))));for(let t of e.sessions)c?.(t.id);let t=m??[];h&&t.some(t=>C9(t)===C9(e.root))&&h(t.filter(t=>C9(t)!==C9(e.root))),Te(!1,!0)}finally{Be(!1)}},[c,Te,m,h]),Ke=(0,d.useMemo)(()=>{let e=t&&!He.some(e=>e.id===t.id)?[{...t,projectRoot:t.projectRoot??Oe(t.cwd)??void 0},...He]:He,n=new Map,r=new Map;for(let t of e){let e=t.projectRoot??t.cwd??`unknown`,i=e===`unknown`?e:C9(e);n.has(i)||(n.set(i,[]),r.set(i,e)),n.get(i).push(t)}let i=[...n.entries()].map(([e,t])=>({root:r.get(e)??e,sessions:t})).sort((e,t)=>{let n=e=>Math.max(...e.map(e=>{let t=new Date(e.modified).getTime();return Number.isNaN(t)?0:t}));return n(t.sessions)-n(e.sessions)}),a=[];if(w){let e=Oe(w);e&&!n.has(C9(e))&&a.push({root:e,sessions:[]})}let o=new Set([...n.keys()]);for(let e of a)o.add(C9(e.root));let s=[];for(let e of m??[]){let t=C9(e);o.has(t)||(o.add(t),s.push({root:e,sessions:[]}))}return[...a,...i,...s]},[He,w,Oe,t,m]),qe=L.trim().toLowerCase(),Je=(0,d.useMemo)(()=>qe?Ke.map(e=>({...e,sessions:e.sessions.filter(e=>Gee(e).toLowerCase().includes(qe))})).filter(e=>e.sessions.length>0):Ke,[Ke,qe]);return(0,E.jsxs)(`div`,{"data-testid":`session-sidebar`,style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`hidden`},children:[k&&(0,E.jsx)(zee,{busy:F,error:P,onCancel:()=>{A(!1),ee(null)},onSelect:e=>void Ae(e)}),(0,E.jsxs)(x9,{title:_(`sidebar.workspace`),open:!0,onToggle:()=>{},collapsible:!1,testId:`workspace-scroll`,hintTestId:`workspace`,scrollStyle:{flex:`1 1 auto`,minHeight:80,background:`var(--bg)`},style:{flex:1,minHeight:0},actions:(0,E.jsx)(y9,{items:[{key:`search`,testId:`workspace-search-toggle`,onClick:()=>{ie&&R(``),ae(e=>!e)},title:_(`sidebar.searchSessions`),ariaPressed:ie,color:ie?`var(--accent)`:`var(--text-muted)`,background:ie?`var(--bg-selected)`:void 0,icon:(0,E.jsx)(vi,{size:p.lg})},{key:`new-workspace`,testId:`new-workspace`,onClick:()=>A(!0),title:_(`sidebar.newWorkspace`),color:`var(--text-muted)`,icon:(0,E.jsx)(Xr,{size:p.xl})},{key:`refresh`,testId:`session-refresh`,onClick:()=>Te(!1,!0),title:_(`sidebar.refresh`),skipHover:z,color:z?`var(--status-success)`:`var(--text-muted)`,background:z?`color-mix(in srgb, var(--status-success) 18%, transparent)`:void 0,icon:z?(0,E.jsx)(Rr,{size:p.xl,color:`var(--status-success)`,strokeWidth:2.5}):(0,E.jsx)(mi,{size:p.xl})}]}),headerExtra:(0,E.jsxs)(E.Fragment,{children:[ie&&(0,E.jsxs)(`div`,{"data-testid":`workspace-search`,style:{display:`flex`,alignItems:`center`,gap:4,width:`100%`,minWidth:0,padding:`4px 8px`,background:`var(--bg)`,borderBottom:`1px solid var(--border)`,boxSizing:`border-box`},children:[(0,E.jsx)(vi,{size:p.lg,color:`var(--text-muted)`,style:{flexShrink:0}}),(0,E.jsx)(`input`,{ref:oe,value:L,onChange:e=>R(e.target.value),placeholder:_(`sidebar.searchSessionsPlaceholder`),"aria-label":_(`sidebar.searchSessions`),style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`var(--text)`,fontSize:`var(--text-sm)`}}),L&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{R(``),oe.current?.focus()},"aria-label":_(`chat.clearSearch`),style:{border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0,padding:0},children:`✕`})]}),Ue&&(0,E.jsx)(Yee,{wt:te,selectedCwd:w,homeDir:D,setSelectedCwd:T}),We&&(0,E.jsxs)(`button`,{type:`button`,"aria-disabled":`true`,tabIndex:-1,title:We.title,style:{width:`100%`,height:29,boxSizing:`border-box`,marginTop:6,display:`flex`,alignItems:`center`,gap:6,padding:`0 10px`,border:`1px solid var(--border)`,borderRadius:7,background:`var(--bg-hover)`,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,lineHeight:1.35,whiteSpace:`nowrap`,textAlign:`left`,cursor:`default`,opacity:.82},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`},children:We.label})]})]}),children:[b&&(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`16px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`div`,{style:{width:14,height:14,border:`2px solid var(--border)`,borderTopColor:`var(--text-dim)`,borderRadius:`50%`,animation:`spin 0.8s linear infinite`,flexShrink:0}}),_(`sidebar.loading`)]}),S&&(0,E.jsx)(`div`,{style:{padding:`12px 14px`,color:`var(--status-error)`,fontSize:`var(--text-base)`},children:S}),!b&&!S&&qe&&Je.length===0&&(0,E.jsx)(`div`,{style:{padding:`16px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-base)`},children:_(`sidebar.searchSessionsNoResults`)}),Je.map(t=>{let n=t.sessions.some(t=>t.id===e)||t.root===Ve;return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(nte,{group:t,groupSelected:n,hoveredGroup:Fe,confirmDeleteGroup:Le,deletingGroup:ze,runningSessionIds:he,interactionBadges:me,collapsed:!!Ne[t.root],setHoveredGroup:Ie,setGroupCollapsed:Pe,setConfirmDeleteGroup:Re,handleDeleteGroup:Ge,handleNewSession:Me,copyText:Ri}),(qe||!Ne[t.root])&&(t.sessions.length===0?(0,E.jsx)(`div`,{style:{padding:`10px 14px`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`},children:_(`sidebar.noSessions`)}):ete(t.sessions).map(t=>(0,E.jsx)(j9,{node:t,selectedSessionId:e,runningSessionIds:he,runningPhases:ge,runningPhaseSince:_e,runningBusySince:ye,unreadSessionIds:fe,seenSessionIds:ce,interactionBadges:me,onSelectSession:je,onRenamed:()=>Te(!1,!0),onSessionDeleted:e=>{c?.(e),Te(!1,!0)},onUnseen:de,depth:0},t.session.id)))]},t.root)})]})]})}function nte({group:e,groupSelected:t,hoveredGroup:n,confirmDeleteGroup:r,deletingGroup:i,runningSessionIds:a,interactionBadges:o,collapsed:s,setHoveredGroup:c,setGroupCollapsed:l,setConfirmDeleteGroup:u,handleDeleteGroup:d,handleNewSession:f,copyText:m}){let{t:h}=N(),g=e.sessions.some(e=>a.has(e.id)),_=e.sessions.some(e=>o.has(e.id));return(0,E.jsx)(`div`,{"data-testid":`workspace-group-header`,onMouseEnter:()=>c(e.root),onMouseLeave:()=>c(null),style:{display:`flex`,alignItems:`center`,gap:4,height:40,padding:`0 2px`,boxSizing:`border-box`,fontSize:`var(--text-base)`,fontFamily:`var(--font-mono)`,color:`var(--text)`,fontWeight:600,textTransform:`none`,letterSpacing:.6,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,cursor:r===e.root?`default`:`pointer`,background:r===e.root?`color-mix(in srgb, var(--status-error) 6%, transparent)`:n===e.root?`var(--bg-hover)`:`var(--bg)`},onClick:r===e.root?void 0:()=>{l(t=>({...t,[e.root]:!t[e.root]}))},children:r===e.root?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:h(`sidebar.deleteWorkspace`,{count:e.sessions.length})}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,flexShrink:0},children:[(0,E.jsx)(`button`,{onClick:t=>{t.stopPropagation(),d(e)},disabled:i,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,height:22,padding:`0 9px`,background:`var(--status-error)`,border:`none`,borderRadius:5,color:`var(--on-error)`,cursor:i?`default`:`pointer`,opacity:i?.6:1,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:h(`sidebar.delete`)}),(0,E.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(null)},disabled:i,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,height:22,padding:`0 9px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:5,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:500,whiteSpace:`nowrap`},children:h(`sidebar.cancel`)})]})]}):(0,E.jsx)(E.Fragment,{children:(0,E.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:6,flex:1,minWidth:0,height:38,boxSizing:`border-box`,padding:`0 8px`,border:`none`,borderRadius:0,background:_&&s?`linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`:g&&s?`linear-gradient(90deg, transparent 13%, color-mix(in srgb, var(--accent) 18%, transparent) 25%, transparent 37%, transparent 63%, color-mix(in srgb, var(--shine-highlight) 50%, transparent) 75%, transparent 87%), linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`:`linear-gradient(180deg, transparent calc(100% - 25px), color-mix(in srgb, var(--border) 25%, transparent) 100%)`,backgroundSize:g&&s&&!_?`200% 100%, auto`:void 0,animation:_&&s?`interaction-bg-blink 1s ease-in-out infinite`:g&&s?`pi-status-shine 1.5s linear infinite`:void 0,boxShadow:`0 2px 8px var(--shadow-color)`,margin:`0 -2px`},children:[(0,E.jsxs)(`span`,{style:{position:`relative`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:30,height:22,flexShrink:0},children:[(0,E.jsx)(`svg`,{width:`30`,height:`22`,viewBox:`0 0 24 24`,fill:t?`color-mix(in srgb, var(--accent) 18%, transparent)`:`var(--bg)`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{color:t?`var(--accent)`:`var(--text-muted)`,opacity:.95},children:(0,E.jsx)(`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`})}),(0,E.jsx)(`span`,{style:{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -38%)`,color:`var(--text-muted)`,fontSize:`var(--text-xs)`,fontWeight:400,lineHeight:1,textAlign:`center`,fontVariantNumeric:`tabular-nums`,userSelect:`none`},children:e.sessions.length})]}),(0,E.jsx)(qi,{label:e.root,wrapperStyle:{flex:1,minWidth:0,overflow:`hidden`},children:(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,maxWidth:`100%`,lineHeight:`20px`},children:Zee(e.root)})}),n===e.root&&(0,E.jsx)(y9,{items:[{key:`new-session`,onClick:t=>{t.stopPropagation(),f(e.root)},title:h(`sidebar.newSessionTitle`,{path:e.root}),icon:(0,E.jsx)(fi,{size:p.base})},{key:`copy-path`,onClick:t=>{t.stopPropagation(),m(e.root)},title:h(`sidebar.copyPath`),icon:(0,E.jsx)(Ur,{size:p.base})},{key:`delete-workspace`,onClick:t=>{t.stopPropagation(),u(e.root)},title:h(`sidebar.deleteWorkspaceTitle`),danger:!0,icon:(0,E.jsx)(Ei,{size:p.base})}]})]})})})}function j9({node:e,selectedSessionId:t,runningSessionIds:n,runningPhases:r,runningPhaseSince:i,runningBusySince:a,unreadSessionIds:o,seenSessionIds:s,interactionBadges:c,onSelectSession:l,onRenamed:u,onSessionDeleted:f,onUnseen:p,depth:m}){let[h,g]=(0,d.useState)(!1),_=e.children.length>0;return(0,E.jsxs)(`div`,{style:{paddingBottom:1,backgroundImage:`linear-gradient(90deg, transparent, var(--border), transparent)`,backgroundPosition:`0 100%`,backgroundSize:`100% 1px`,backgroundRepeat:`no-repeat`},children:[(0,E.jsxs)(`div`,{style:{position:`relative`},children:[m>0&&(0,E.jsx)(`div`,{style:{position:`absolute`,left:m*12+6,top:0,bottom:0,width:1,background:`var(--border)`,pointerEvents:`none`}}),(0,E.jsx)(ite,{session:e.session,isSelected:e.session.id===t,isRunning:n.has(e.session.id),phase:r[e.session.id],phaseSince:i[e.session.id],busySince:a[e.session.id],isUnread:o.has(e.session.id),isSeen:s.has(e.session.id),hasInteractionBadge:c.has(e.session.id),onClick:()=>l(e.session),onRenamed:u,onDeleted:e=>f?.(e),onUnseen:p,depth:m,hasChildren:_,collapsed:h,onToggleCollapse:()=>g(e=>!e)})]}),_&&!h&&(0,E.jsx)(`div`,{children:e.children.map(e=>(0,E.jsx)(j9,{node:e,selectedSessionId:t,runningSessionIds:n,runningPhases:r,runningPhaseSince:i,runningBusySince:a,unreadSessionIds:o,seenSessionIds:s,interactionBadges:c,onSelectSession:l,onRenamed:u,onSessionDeleted:f,onUnseen:p,depth:m+1},e.session.id))})]})}function rte(){let{t:e}=N();return(0,E.jsx)(`span`,{title:e(`sidebar.newActivity`),"aria-label":e(`sidebar.newSessionActivity`),style:{width:14,height:14,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,color:`var(--accent)`},children:(0,E.jsxs)(`svg`,{width:p.xl,height:p.xl,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`,style:{display:`block`},children:[(0,E.jsx)(`circle`,{cx:`7`,cy:`7`,r:`2.5`,fill:`currentColor`}),(0,E.jsx)(`circle`,{cx:`7`,cy:`7`,r:`3`,stroke:`currentColor`,strokeWidth:`1.4`,opacity:`0.32`,style:{transformOrigin:`center`,animation:`session-ring-pulse 1.6s ease-in-out infinite`}})]})})}function ite({session:e,isSelected:t,isRunning:n,phase:r,phaseSince:i,busySince:a,isUnread:o,isSeen:s=!0,hasInteractionBadge:c=!1,onClick:l,onRenamed:u,onDeleted:f,onUnseen:m,depth:h=0,hasChildren:g=!1,collapsed:_=!1,onToggleCollapse:v}){let{t:y}=N(),b=Cn(!!(n&&r),i),x=Cn(!!n,a),[S,C]=(0,d.useState)(!1),[w,T]=(0,d.useState)(!1),[D,O]=(0,d.useState)(``),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(!1),P=(0,d.useRef)(null),ee=e.error?e.path.split(/[\\/]/).pop()||e.id:e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),F=(0,d.useCallback)(t=>{t.stopPropagation(),O(e.name??``),T(!0),setTimeout(()=>P.current?.select(),0)},[e.name]),I=(0,d.useCallback)(async()=>{let t=D.trim();if(T(!1),t!==(e.name??``))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})}),u?.()}catch{}},[D,e.id,e.name,u]),te=(0,d.useCallback)(async()=>{A(!1),M(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`}),f?.(e.id)}catch{M(!1)}},[e.id,f]),ne=(0,d.useCallback)(e=>{e.stopPropagation(),e.shiftKey?te():A(!0)},[te]),re=(0,d.useCallback)(e=>{e.stopPropagation(),te()},[te]),ie=(0,d.useCallback)(e=>{e.stopPropagation(),A(!1)},[]);return(0,E.jsx)(`div`,{"data-testid":`session-item`,"data-session-id":e.id,onClick:k||w?void 0:l,title:c?y(`sidebar.interactionBadge`):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>{C(!1)},style:{height:54,animation:c?`interaction-bg-blink 1s ease-in-out infinite`:void 0,display:`flex`,alignItems:`center`,paddingLeft:h>0?h*12+14:14,paddingRight:8,cursor:k||w?`default`:`pointer`,backgroundColor:k?`color-mix(in srgb, var(--status-error) 6%, transparent)`:S?`var(--bg-hover)`:`transparent`,transition:`background 0.1s`,opacity:j?.5:1,gap:6,overflow:`hidden`},className:t&&!k?`row-selected-gradient`:void 0,children:k?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:ee}),(0,E.jsxs)(`div`,{style:{marginTop:2,display:`flex`,alignItems:`center`,gap:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[e.error?(0,E.jsx)(k9,{session:e}):(0,E.jsx)(`span`,{title:e.modified,children:E9(e.modified,y)}),(0,E.jsx)(`span`,{children:y(`sidebar.messagesCount`,{count:e.messageCount})})]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,flexShrink:0},children:[(0,E.jsxs)(`button`,{onClick:re,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,height:30,padding:`0 11px`,background:`var(--status-error)`,border:`none`,borderRadius:6,color:`var(--on-error)`,cursor:`pointer`,fontSize:`var(--text-base)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(Ei,{size:p.base}),y(`sidebar.delete`)]}),(0,E.jsx)(`button`,{onClick:ie,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,height:30,padding:`0 11px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-base)`,fontWeight:500,whiteSpace:`nowrap`},children:y(`sidebar.cancel`)})]})]}):w?(0,E.jsx)(`input`,{ref:P,"data-testid":`session-rename-input`,value:D,onChange:e=>O(e.target.value),onBlur:I,onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&T(!1)},autoFocus:!0,style:{flex:1,fontSize:`var(--text-base)`,padding:`5px 8px`,border:`1px solid var(--accent)`,borderRadius:5,outline:`none`,background:`var(--bg)`,color:`var(--text)`,height:30}}):(0,E.jsxs)(E.Fragment,{children:[h>0&&(0,E.jsxs)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--text-dim)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,E.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:5,minWidth:0,fontSize:`var(--text-base)`,fontWeight:t?600:400,lineHeight:1.4,color:s?`var(--text)`:`var(--text-dim)`},title:ee,children:(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,minWidth:0},children:ee})}),(0,E.jsxs)(`div`,{style:{marginTop:2,display:`flex`,alignItems:`center`,gap:8,color:`var(--text-dim)`,fontSize:`var(--text-sm)`,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[e.error?(0,E.jsx)(k9,{session:e}):n?(0,E.jsx)(mY,{phase:r??{kind:`running_command`},elapsed:b,totalElapsed:x}):o?(0,E.jsx)(rte,{}):(0,E.jsx)(`span`,{title:e.modified,children:E9(e.modified,y)}),!e.error&&n?null:(0,E.jsx)(`span`,{children:y(`sidebar.messagesCount`,{count:e.messageCount})}),e.worktreeBranch&&(0,E.jsxs)(`span`,{title:`Worktree: ${e.cwd}`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--accent)`,minWidth:0,overflow:`hidden`},children:[(0,E.jsxs)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},children:[(0,E.jsx)(`line`,{x1:`6`,y1:`3`,x2:`6`,y2:`15`}),(0,E.jsx)(`circle`,{cx:`18`,cy:`6`,r:`3`}),(0,E.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,E.jsx)(`path`,{d:`M18 9a9 9 0 0 1-9 9`})]}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.worktreeBranch})]})]})]}),g&&(0,E.jsx)(qi,{label:_?`Expand forks`:`Collapse forks`,children:(0,E.jsx)(`button`,{onClick:e=>{e.stopPropagation(),v?.()},style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:20,height:20,padding:0,flexShrink:0,background:`none`,border:`none`,color:`var(--text-dim)`,cursor:`pointer`,transform:_?`rotate(-90deg)`:`none`,transition:`transform 0.15s`},children:(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`polyline`,{points:`2 3.5 5 6.5 8 3.5`})})})}),(0,E.jsx)(y9,{visible:S,items:[...s&&m?[{key:`unseen`,onClick:t=>{t.stopPropagation(),m(e.id)},title:y(`sidebar.disconnect`)||`断开`,icon:(0,E.jsx)(Oi,{size:p.base})}]:[],{key:`copy-path`,onClick:t=>{t.stopPropagation(),Ri(e.path)},title:y(`sidebar.copyPath`),icon:(0,E.jsx)(Ur,{size:p.base})},{key:`rename`,testId:`session-rename`,onClick:F,title:y(`sidebar.rename`),icon:(0,E.jsx)(ui,{size:p.xl})},{key:`delete`,testId:`session-delete`,onClick:ne,title:y(`sidebar.deleteWithShiftClick`),danger:!0,icon:(0,E.jsx)(Ei,{size:p.xl})}]})]})})}function ate(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(qe,Je,Je);if(t.length===0)return null;let n=t[t.length-1],r=t.length;return(0,E.jsx)(_l,{open:!0,onOpenChange:()=>{},children:(0,E.jsxs)(xl,{children:[(0,E.jsx)(Cl,{style:{position:`fixed`,inset:0,zIndex:1200,background:`rgba(0, 0, 0, 0.45)`}}),(0,E.jsxs)(Dl,{role:`alertdialog`,"aria-modal":`true`,onInteractOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:1200,maxWidth:480,width:`calc(100% - 48px)`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:10,padding:`16px 20px`,boxShadow:`0 8px 32px rgba(0, 0, 0, 0.35)`},children:[(0,E.jsxs)(Ml,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10,fontSize:`var(--text-base)`,fontWeight:600,color:`var(--text)`},children:[(0,E.jsx)(`span`,{style:{color:`var(--status-error)`},children:`⚠`}),(0,E.jsx)(`span`,{children:r>1?e(`errors.titleCount`,{count:r}):e(`errors.title`)})]}),(0,E.jsx)(Pl,{asChild:!0,children:(0,E.jsx)(`div`,{children:n.kind===`api`?(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:6},children:[(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`,padding:`1px 8px`,borderRadius:999,background:`color-mix(in srgb, var(--status-error) 14%, transparent)`,color:`var(--status-error)`,fontWeight:600,whiteSpace:`nowrap`},children:[`HTTP `,n.status||`ERR`]}),n.context&&(0,E.jsx)(`span`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`},children:n.context})]}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,wordBreak:`break-word`},children:n.message})]}):(0,E.jsxs)(`div`,{children:[n.context&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xs)`,color:`var(--text-dim)`,marginBottom:6},children:n.context}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,wordBreak:`break-word`},children:n.message})]})})}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:8,marginTop:16},children:[r>1&&(0,E.jsx)(`button`,{type:`button`,onClick:Xe,style:{border:`1px solid var(--border)`,background:`none`,color:`var(--text-muted)`,borderRadius:6,padding:`4px 12px`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:e(`errors.clearAll`)}),(0,E.jsx)(`button`,{type:`button`,onClick:Ye,style:{border:`none`,background:`var(--accent)`,color:`#fff`,borderRadius:6,padding:`4px 14px`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:e(`errors.close`)})]})]})]})})}var M9=[],ote=1,N9=new Set;function P9(){for(let e of N9)e()}function ste(e){return N9.add(e),()=>{N9.delete(e)}}function F9(){return M9}function cte(e){let t={id:ote++,label:e??``};M9=[...M9,t],P9();let n=!1;return()=>{n||(n=!0,M9=M9.filter(e=>e.id!==t.id),P9())}}var I9=new WeakMap;function lte(e){if(!e.isConnected)return()=>{};let t=I9.get(e);if(!t){let n=document.createElement(`div`);n.style.cssText=`position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb, var(--bg) 50%, transparent);z-index:5;`,n.innerHTML=`<div style="width:16px;height:16px;border:2px solid var(--border);border-top-color:var(--text-dim);border-radius:50%;animation:spin 0.8s linear infinite;"></div>`;let r=null;getComputedStyle(e).position===`static`&&(r=e.style.position,e.style.position=`relative`),e.appendChild(n),t={count:0,el:n,prevPosition:r},I9.set(e,t)}t.count++;let n=!1;return()=>{n||(n=!0,t.count--,t.count<=0&&(t.el.remove(),t.prevPosition!==null&&(t.prevPosition?e.style.position=t.prevPosition:e.style.removeProperty(`position`)),I9.delete(e)))}}async function ute(e){try{return await e.json()}catch{return null}}async function L9(e,t,n){let r=n?.loading??`fullscreen`,i=r===`fullscreen`?cte(n?.label):r instanceof HTMLElement?lte(r):null;try{let n;try{n=await fetch(e,t)}catch(e){throw new Be(e instanceof Error?e.message:`Network error`,0)}if(!n.ok){let e=await ute(n);throw new Be(e&&typeof e==`object`&&`error`in e&&typeof e.error==`string`?e.error:`HTTP ${n.status}`,n.status,e)}let r=await n.text();return r?JSON.parse(r):void 0}catch(e){throw e instanceof Be?e:new Be(e instanceof Error?e.message:String(e),0)}finally{i?.()}}var dte=3;function fte(){let{t:e}=N(),t=(0,d.useSyncExternalStore)(ste,F9,F9);if(t.length===0)return null;let n=t.slice(0,dte),r=t.length-n.length;return(0,E.jsx)(`div`,{"aria-busy":`true`,style:{position:`fixed`,inset:0,zIndex:1150,background:`color-mix(in srgb, var(--bg) 40%, transparent)`,display:`flex`,alignItems:`center`,justifyContent:`center`,pointerEvents:`none`},children:(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10,minWidth:220,maxWidth:`60vw`,padding:`14px 18px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`var(--radius)`,boxShadow:`0 8px 32px rgba(0,0,0,0.25)`},children:[n.map(t=>(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,fontSize:`var(--text-sm)`,color:`var(--text)`},children:[(0,E.jsx)(`div`,{style:{width:14,height:14,flexShrink:0,border:`2px solid var(--border)`,borderTopColor:`var(--accent)`,borderRadius:`50%`,animation:`spin 0.8s linear infinite`}}),(0,E.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:t.label||e(`loading.inProgress`)})]},t.id)),r>0&&(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:e(`loading.more`,{count:r})})]})})}var R9={},pte=6e4;function z9(e,t){return e===`Not found`?t(`files.notFound`):e===`Access denied`?t(`files.accessDenied`):e}async function B9(e,t){return((await L9(`/api/files/${mG(e)}?type=list`,void 0,t)).entries??[]).map(t=>({name:t.name,fullPath:vG(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function V9(e,t){return L9(`/api/git/status?${new URLSearchParams({cwd:e}).toString()}`,void 0,t)}var H9={modified:`files.modified`,added:`files.added`,deleted:`files.deleted`,renamed:`files.renamed`,untracked:`files.untracked`,conflict:`files.conflict`},U9={modified:`var(--status-warning)`,added:`var(--status-success)`,deleted:`var(--status-error)`,renamed:`var(--accent)`,untracked:`var(--status-success)`,conflict:`var(--status-error)`};function W9({status:e,t}){return(0,E.jsx)(`span`,{title:t(H9[e.status]),"aria-label":t(H9[e.status]),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`,color:U9[e.status],fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,fontWeight:600},children:e.code})}function mte(e,t,n,r){return new Promise((i,a)=>{let o=new FormData;t.forEach(e=>o.append(`files`,e,e.name));let s=new XMLHttpRequest;s.open(`POST`,`/api/files/${mG(e)}?type=upload&conflict=${n}`),s.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&r(Math.round(e.loaded/e.total*100))},s.onerror=()=>a(Error(`Network error while uploading files`)),s.onabort=()=>a(Error(`Upload cancelled`)),s.onload=()=>{let e={};try{e=JSON.parse(s.responseText)}catch{s.responseText&&(e.error=s.responseText)}i({status:s.status,data:e})},s.send(o)})}function G9({size:e=11}){return(0,E.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,E.jsx)(`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`})]})}function K9({onClick:e,title:t}){return(0,E.jsx)(qi,{label:t,children:(0,E.jsx)(`button`,{type:`button`,onClick:e,"aria-label":t,style:{width:24,height:24,padding:0,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`none`,borderRadius:4,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,"--hover-color":`var(--text-muted)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`m6 6 12 12`}),(0,E.jsx)(`path`,{d:`m18 6-12 12`})]})})})}function q9({node:e,depth:t,cwd:n,onOpenFile:r,onAtMention:i,expandedPaths:a,onToggleExpanded:o,refreshToken:s,highlightedPaths:c,gitStatusByPath:l,changedDirectoryPaths:u,t:f}){let m=a.has(e.fullPath),h=c.has(e.fullPath),g=pG(e.fullPath),_=l.get(g),v=e.isDir&&(_!==void 0||u.has(g)),[y,b]=(0,d.useState)(e.children??[]),[x,S]=(0,d.useState)(e.loaded??!1),[C,w]=(0,d.useState)(!1),T=(0,d.useCallback)(async(t=!1)=>{if(!(x&&!t))try{let t=await B9(e.fullPath,{loading:`silent`});b(t),S(!0)}catch{}},[x,e.fullPath]);(0,d.useEffect)(()=>{m&&x&&T(!0)},[s]);let D=(0,d.useCallback)(()=>{if(e.isDir){let t=!m;o(e.fullPath,t),t&&!x&&T()}else r(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,x,m,T,r,o]);return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{onClick:D,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),style:{position:`relative`,display:`flex`,alignItems:`center`,gap:4,paddingLeft:8+t*14,paddingRight:8,height:24,cursor:`pointer`,background:C?`var(--bg-hover)`:`transparent`,borderRadius:4,userSelect:`none`},children:[e.isDir&&(0,E.jsx)(`svg`,{width:p.xs,height:p.xs,viewBox:`0 0 10 10`,fill:`none`,stroke:`var(--text-dim)`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0,transform:m?`rotate(90deg)`:`none`,transition:`transform 0.1s`},children:(0,E.jsx)(`polyline`,{points:`3 2 7 5 3 8`})}),!e.isDir&&(0,E.jsx)(`span`,{style:{width:10,flexShrink:0}}),(0,E.jsx)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`},children:e.isDir?(0,E.jsx)(In,{size:p.xl,open:m}):ur(e.name,14)}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},title:e.fullPath,children:e.name}),h&&(0,E.jsx)(`span`,{title:f(`files.newlyUploaded`),"aria-label":f(`files.newlyUploaded`),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,E.jsx)(`span`,{style:{width:6,height:6,borderRadius:`50%`,background:`var(--accent)`}})}),!C&&!e.isDir&&_&&(0,E.jsx)(W9,{status:_,t:f}),!C&&v&&(0,E.jsx)(`span`,{title:f(`files.containsChangedFiles`),"aria-label":f(`files.containsChangedFiles`),style:{width:14,height:14,flexShrink:0,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,E.jsx)(`span`,{style:{width:6,height:6,borderRadius:`50%`,background:`var(--status-warning)`}})}),i&&C&&(0,E.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(_G(e.fullPath,n),e.isDir)},title:f(`files.insertPath`),style:{position:`absolute`,right:e.isDir?4:28,top:`50%`,transform:`translateY(-50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,padding:`0 8px`,height:20,background:`var(--bg-panel)`,border:`1px solid var(--border)`,borderRadius:4,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(G9,{}),f(`files.mention`)]}),C&&!e.isDir&&(0,E.jsx)(`a`,{href:`/api/files/${mG(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:f(`files.download`),style:{position:`absolute`,right:4,top:`50%`,transform:`translateY(-50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,padding:`0 5px`,height:20,background:`var(--bg-panel)`,border:`1px solid var(--border)`,borderRadius:4,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`,textDecoration:`none`},children:(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,E.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,E.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]})})]}),e.isDir&&m&&(0,E.jsxs)(`div`,{children:[y.map(e=>(0,E.jsx)(q9,{node:e,depth:t+1,cwd:n,onOpenFile:r,onAtMention:i,expandedPaths:a,onToggleExpanded:o,refreshToken:s,highlightedPaths:c,gitStatusByPath:l,changedDirectoryPaths:u,t:f},e.fullPath)),y.length===0&&x&&(0,E.jsx)(`div`,{style:{paddingLeft:8+(t+1)*14,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,height:22,display:`flex`,alignItems:`center`},children:f(`files.empty`)})]})]})}function J9({status:e,cwd:t,onOpenFile:n,onStageToggle:r,unstage:i,t:a}){let[o,s]=(0,d.useState)(!1),c=hG(e.filePath),l=_G(e.filePath,t);return(0,E.jsxs)(`div`,{"data-testid":`git-change-row`,onClick:()=>n(e.filePath,c,{modeHint:`diff`}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),title:e.filePath,style:{display:`flex`,alignItems:`center`,gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:`pointer`,background:o?`var(--bg-hover)`:`transparent`,borderRadius:4,userSelect:`none`},children:[r!==void 0&&(0,E.jsx)(`button`,{type:`button`,"data-testid":`git-stage-toggle`,onClick:t=>{t.stopPropagation(),r(e)},"aria-label":a(i?`files.unstageFile`:`files.stageFile`),style:{width:16,height:16,padding:0,marginLeft:-4,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,border:`none`,borderRadius:4,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,opacity:+!!o,"--hover-color":`var(--text-muted)`,"--hover-bg":`var(--bg-hover)`},className:`hover-shift`,children:(0,E.jsx)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,"aria-hidden":`true`,children:i?(0,E.jsx)(`path`,{d:`M6 12h12`}):(0,E.jsx)(`path`,{d:`M12 5v14M5 12h14`})})}),(0,E.jsx)(W9,{status:e,t:a}),(0,E.jsx)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`,opacity:.85},children:ur(c,13)}),(0,E.jsx)(`span`,{style:{fontSize:`var(--text-base)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:l}),e.lineStats&&(e.lineStats.additions>0||e.lineStats.deletions>0)&&(0,E.jsxs)(`span`,{style:{flexShrink:0,display:`flex`,alignItems:`center`,gap:5,fontFamily:`var(--font-mono)`,fontSize:`var(--text-xs)`,fontVariantNumeric:`tabular-nums`},children:[e.lineStats.additions>0&&(0,E.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.lineStats.additions]}),e.lineStats.deletions>0&&(0,E.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.lineStats.deletions]})]})]})}function hte({message:e,onMessageChange:t,commitBusy:n,canCommit:r,onCommit:i,pushBusy:a,canPush:o,onPush:s,pullBusy:c,canPull:l,onPull:u,aiBusy:f,canAiGenerate:m,onAiGenerate:h,autoGenerateOnEmpty:g,hasModelForAuto:_,aiModelHint:v,t:y}){let b=(0,d.useRef)(null),x=e.trim()===``,S=x&&g&&_&&m&&!f,C=n||!S&&x||!r;return(0,d.useLayoutEffect)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,120)}px`)},[e]),(0,E.jsx)(`div`,{style:{display:`flex`,padding:`4px 2px 6px`},children:(0,E.jsxs)(`div`,{style:{position:`relative`,display:`flex`,flexDirection:`column`,flex:1,minWidth:0,backgroundColor:`var(--bg)`,backgroundImage:n||f||a||c?`linear-gradient(90deg, transparent 13%, color-mix(in srgb, var(--accent) 18%, transparent) 25%, transparent 37%, transparent 63%, color-mix(in srgb, var(--shine-highlight) 50%, transparent) 75%, transparent 87%)`:void 0,backgroundSize:n||f||a||c?`200% 100%`:void 0,animation:n||f||a||c?`pi-status-shine 1.5s linear infinite`:void 0,borderRadius:6,border:`1px solid var(--border)`},children:[(0,E.jsx)(`textarea`,{ref:b,"data-testid":`git-commit-message`,value:e,disabled:n||f||a||c,placeholder:f?v?`${y(`git.ai.generating`)}(${v})`:y(`git.ai.generating`):y(`files.commitMessagePlaceholder`),onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),C||i())},rows:1,style:{flex:`0 1 auto`,minWidth:0,resize:`none`,boxSizing:`content-box`,overflowY:`auto`,maxHeight:120,fontSize:`var(--text-base)`,lineHeight:1.4,padding:`4px 6px`,color:n||f||a||c?`var(--text-dim)`:`var(--text)`,background:`transparent`,border:`none`,borderRadius:6,outline:`none`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:4,padding:`2px 6px 4px`},children:[(0,E.jsx)(qi,{label:(()=>{let e=y(f?`git.ai.generating`:`git.ai.generate`);return v?`${e}(${v})`:e})(),children:(0,E.jsx)(`button`,{onClick:h,disabled:f||!m||n||a||c,"aria-label":y(`git.ai.generate`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:f||!m||n||a||c?`var(--text-dim)`:`var(--accent)`,cursor:f||!m||n||a||c?`default`:`pointer`},children:f?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Si,{size:p.lg})})}),(0,E.jsx)(qi,{label:n?y(`files.committing`):C&&x&&!S?y(`files.commitMessageRequired`):S?`${y(`git.ai.generateAndCommit`)} (Ctrl+Enter)`:`${y(`files.commit`)} (Ctrl+Enter)`,children:(0,E.jsx)(`button`,{"data-testid":`git-commit`,onClick:i,disabled:C||c,"aria-label":y(`files.commit`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:C||c?`var(--text-dim)`:`var(--accent)`,cursor:C||c?`default`:`pointer`},children:n?(0,E.jsx)(oi,{size:p[`2xl`],style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Qr,{size:p[`2xl`]})})}),(0,E.jsx)(qi,{label:y(a?`files.pushing`:o?`files.push`:`files.pushUpToDate`),children:(0,E.jsx)(`button`,{"data-testid":`git-push`,onClick:s,disabled:a||n||c||!o,"aria-label":y(`files.push`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:a||n||c||!o?`var(--text-dim)`:`var(--accent)`,cursor:a||n||c||!o?`default`:`pointer`},children:a?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Hr,{size:p[`2xl`]})})}),(0,E.jsx)(qi,{label:y(c?`files.pulling`:l?`files.pull`:`files.pullUpToDate`),children:(0,E.jsx)(`button`,{"data-testid":`git-pull`,onClick:u,disabled:c||n||a||!l,"aria-label":y(`files.pull`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:30,padding:0,flexShrink:0,background:`none`,border:`1px solid transparent`,borderRadius:6,color:c||n||a||!l?`var(--text-dim)`:`var(--accent)`,cursor:c||n||a||!l?`default`:`pointer`},children:c?(0,E.jsx)(oi,{size:p.lg,style:{animation:`spin 0.8s linear infinite`}}):(0,E.jsx)(Vr,{size:p[`2xl`]})})})]})]})})}function Y9({prefix:e,count:t,additions:n,deletions:r,t:i}){return(0,E.jsxs)(`div`,{"aria-label":i(`files.changeStats`,{count:t,additions:n,deletions:r}),style:{display:`flex`,alignItems:`center`,gap:6,height:24,padding:`0 10px`,fontSize:`var(--text-base)`},children:[e&&(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`},children:e}),(0,E.jsx)(`span`,{style:{color:`var(--text-dim)`},children:i(`files.changedCount`,{count:t})}),(0,E.jsxs)(`span`,{style:{color:U9.added,fontFamily:`var(--font-mono)`},children:[`+`,n]}),(0,E.jsxs)(`span`,{style:{color:U9.deleted,fontFamily:`var(--font-mono)`},children:[`-`,r]})]})}function X9({message:e,onDismiss:t}){let{t:n}=N();return(0,E.jsxs)(`div`,{role:`alert`,style:{display:`flex`,alignItems:`center`,gap:6,marginTop:4,padding:`6px 8px`,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--status-error)`,background:`var(--bg)`,border:`1px solid var(--status-error)`,borderRadius:6},children:[(0,E.jsx)(`span`,{style:{minWidth:0,flex:1,overflowWrap:`anywhere`,maxHeight:140,overflowY:`auto`,whiteSpace:`pre-wrap`},children:e}),(0,E.jsx)(K9,{onClick:t,title:n(`files.dismissError`)})]})}function gte({children:e}){return(0,E.jsx)(`div`,{style:{padding:`0 4px 2px`},children:e})}var _te=(0,d.forwardRef)(function({children:e},t){return(0,E.jsx)(`div`,{ref:t,style:{padding:`2px 4px`},children:e})}),vte=(0,d.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:n,searchQuery:r,onAtMention:i,onAtMentions:a,onUploadBusyChange:o,changesCollapsed:s,onChangesCountChange:c,sessionId:l,onOpenConfig:u},f){let{t:m}=N(),[h,g]=(0,d.useState)([]),[_,v]=(0,d.useState)(!0),[y,b]=(0,d.useState)(null),x=(0,d.useRef)(null),[S,C]=(0,d.useState)(new Set),[w,T]=(0,d.useState)(0),D=(r??``).trim().toLowerCase(),O=(0,d.useMemo)(()=>{if(!D)return h;function e(t){if(t.name.toLowerCase().includes(D))return t;if(t.isDir&&t.children){let n=t.children.map(e).filter(e=>e!==null);if(n.length>0)return{...t,children:n}}return null}return h.map(e).filter(e=>e!==null)},[h,D]),[k,A]=(0,d.useState)(new Set),[j,M]=(0,d.useState)([]),[P,ee]=(0,d.useState)({additions:0,deletions:0}),[F,I]=(0,d.useState)([]),[te,ne]=(0,d.useState)({additions:0,deletions:0}),re=(0,d.useMemo)(()=>D?F.filter(t=>_G(t.filePath,e).toLowerCase().includes(D)):F,[F,D,e]),ie=(0,d.useMemo)(()=>D?j.filter(t=>_G(t.filePath,e).toLowerCase().includes(D)):j,[j,D,e]),[ae,L]=(0,d.useState)({branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1}),[R,oe]=(0,d.useState)(null),[z,se]=(0,d.useState)(``),[ce,le]=(0,d.useState)(!1),[ue,de]=(0,d.useState)(null),[fe,pe]=(0,d.useState)(!1),[me,he]=(0,d.useState)(!1),[ge,ve]=(0,d.useState)(null),be=Li(),xe=(0,d.useRef)(0),[Se,Ce]=(0,d.useState)(!1),[we,Te]=(0,d.useState)(!1),Ee=(0,d.useSyncExternalStore)(ye.subscribe,()=>ye.get()?.preferences??R9,()=>R9),De=(0,d.useSyncExternalStore)(_e.subscribe,()=>_e.get()),Oe=Ee.commitMessageAutoGenerateOnEmpty!==!1,ke=Ee.commitStageAllConfirm!==!1,Ae=Ee.commitMessageUseCurrentModel===!0?!!(l||De?.defaultModel||(De?.modelList?.length??0)>0):!!(typeof Ee.commitMessageModel==`string`&&Ee.commitMessageModel),[je,Me]=(0,d.useState)(!1),[Ne,Pe]=(0,d.useState)(null),Fe=(0,d.useRef)(null),[Ie,Le]=(0,d.useState)(!1),[Re,ze]=(0,d.useState)(null),[Be,Ve]=(0,d.useState)(`idle`),[He,Ue]=(0,d.useState)(0),[We,Ge]=(0,d.useState)(null),[qe,Je]=(0,d.useState)(null),[Ye,Xe]=(0,d.useState)(null),Ze=(0,d.useRef)(null),Qe=(0,d.useRef)(null),$e=`${n??0}:${w}`,et=Be!==`idle`,tt=(0,d.useMemo)(()=>new Map(j.map(e=>[pG(e.filePath),e])),[j]),nt=(0,d.useMemo)(()=>{let t=new Set,n=pG(e).replace(/\/$/,``);for(let e of j){let r=gG(pG(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=gG(r);if(e===r)break;r=e}}return t},[e,j]),rt=(0,d.useCallback)((e,t)=>{C(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),it=(0,d.useCallback)(t=>{let n=t.uploaded??[],r=t.skipped??[],i=t.errors??[];Je({uploaded:n,skipped:r,errors:i}),n.length>0&&(A(new Set(n.map(t=>vG(e,t)))),T(e=>e+1))},[e]),at=(0,d.useCallback)(async(t,n)=>{Xe(null),Ge(null),Ue(0),Ve(`uploading`);try{let{status:r,data:i}=await mte(e,t,n,Ue);if(r===409&&i.conflicts?.length){Xe({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});return}if(r<200||r>=300)throw Error(i.error??`Upload failed (HTTP ${r})`);Ue(100),it(i)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{Ve(`idle`)}},[it,e]),ot=(0,d.useCallback)(async t=>{if(!(t.length===0||et)){Je(null),A(new Set),Xe(null),Ge(null),Ue(0),Ve(`checking`);try{let n=await L9(`/api/files/${mG(e)}?type=upload-check`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({fileNames:t.map(e=>e.name)})},{loading:`silent`});if(n.conflicts?.length){Xe({files:t,conflicts:n.conflicts,nonReplaceable:n.nonReplaceable??[]});return}await at(t,`error`)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{Ve(`idle`)}}},[e,at,et]),st=(0,d.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value=``,ot(t)},[ot]);(0,d.useImperativeHandle)(f,()=>({openUploadPicker(){et||Qe.current?.click()}}),[et]);let ct=(0,d.useCallback)(async()=>{Me(!0);try{let t=await L9(`/api/git/push`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e})},{loading:`silent`});console.info(`[git-push] ok:`,t.output||`(empty output)`),Pe({ok:!0,output:t.output??``})}catch(e){let t=e instanceof Error?e.message:String(e);console.info(`[git-push] failed:`,t),Pe({ok:!1,output:t})}finally{Me(!1),T(e=>e+1)}},[e]),lt=(0,d.useCallback)(async()=>{Le(!0);try{let t=await L9(`/api/git/pull`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e})},{loading:`silent`});console.info(`[git-pull] ok:`,t.output||`(empty output)`),ze({ok:!0,output:t.output??``})}catch(e){let t=e instanceof Error?e.message:String(e);console.info(`[git-pull] failed:`,t),ze({ok:!1,output:t})}finally{Le(!1),T(e=>e+1)}},[e]),ut=(()=>{let e=Ee.gitAutoFetchIntervalSec;return typeof e==`number`&&Number.isFinite(e)&&e>0?e:0})();(0,d.useEffect)(()=>{if(ut<=0||!e)return;let t=()=>{document.hidden||L9(`/api/git/autofetch-status?cwd=${encodeURIComponent(e)}`,{},{loading:`silent`}).then(e=>{e.cached!==!1&&L(t=>({...t,ahead:e.ahead??t.ahead,behind:e.behind??t.behind}))}).catch(()=>{})};t();let n=setInterval(t,ut*1e3),r=()=>{document.hidden||t()};return document.addEventListener(`visibilitychange`,r),()=>{clearInterval(n),document.removeEventListener(`visibilitychange`,r)}},[e,ut]),(0,d.useEffect)(()=>{if(Fe.current&&clearTimeout(Fe.current),Ne)return Fe.current=setTimeout(()=>Pe(null),1e4),()=>{Fe.current&&clearTimeout(Fe.current)}},[Ne]);let dt=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(dt.current&&clearTimeout(dt.current),Re)return dt.current=setTimeout(()=>ze(null),1e4),()=>{dt.current&&clearTimeout(dt.current)}},[Re]),(0,d.useEffect)(()=>{o?.(et)},[o,et]),(0,d.useEffect)(()=>()=>o?.(!1),[o]),(0,d.useEffect)(()=>{let t=Ze.current!==e;Ze.current=e,t&&(C(new Set),A(new Set),Je(null),Xe(null),Ge(null)),b(null),v(t);let n=!1;return B9(e,{loading:`silent`}).then(e=>{n||g(e)}).catch(e=>{n||(b(e instanceof Error?e.message:String(e)),Ke(e,`file explorer`))}).finally(()=>{n||v(!1)}),()=>{n=!0}},[e,n,w]),(0,d.useEffect)(()=>{let t=!1;return V9(e,{loading:`silent`}).then(e=>{if(!t){let t=e.isGitRepository;M(t?e.files:[]),ee(t?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}),I(t?e.stagedFiles:[]),ne(t?{additions:e.stagedAdditions,deletions:e.stagedDeletions}:{additions:0,deletions:0}),L(t?{branch:e.branch??null,upstream:e.upstream??null,ahead:e.ahead??0,behind:e.behind??0,hasUpstream:e.hasUpstream??!1}:{branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1})}}).catch(()=>{t||(M([]),ee({additions:0,deletions:0}),I([]),ne({additions:0,deletions:0}),L({branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1}))}),()=>{t=!0}},[e,n,w]);let ft=(0,d.useCallback)(async(t,n)=>{oe(null);try{let r=await fetch(`/api/git/stage`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,filePath:t.filePath,action:n?`unstage`:`stage`})}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.error??`Git ${n?`unstage`:`stage`} failed (HTTP ${r.status})`);T(e=>e+1)}catch(e){oe(e instanceof Error?e.message:String(e))}},[e]);(0,d.useEffect)(()=>{c?.(j.length+F.length)},[j,F,c]);let pt=(0,d.useCallback)(async(t,n)=>{let r=n??z;le(!0),de(null);try{let n=await fetch(`/api/git/commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,message:r,stageAll:t})}),i=await n.json().catch(()=>({}));if(!n.ok)throw Error(i.error??`Commit failed (HTTP ${n.status})`);se(``),de(null),pe(!1),T(e=>e+1)}catch(e){de(e instanceof Error?e.message:String(e))}finally{le(!1)}},[e,z]),mt=(0,d.useCallback)(async()=>{if(me||ce||je||we)return null;let t=++xe.current,n=ye.get()?.preferences??{};if(Object.keys(n).length===0)try{await ye.refresh(),n=ye.get()?.preferences??{}}catch{}let r=n.commitMessageUseCurrentModel===!0,i=typeof n.commitMessageModel==`string`?n.commitMessageModel:``,a=``,o=``;if(r){if(l)try{let e=await L9(`/api/agent/${encodeURIComponent(l)}`),t=e.state?.model??e.model??null;if(t){let e=t;a=e.provider??``,o=e.id??e.modelId??``}if(!a||!o)try{let e=await L9(`/api/sessions/${encodeURIComponent(l)}/state`);e.model&&(a=e.model.provider,o=e.model.id)}catch{}}catch{}if(!a||!o)try{let e=_e.get();if(!e?.defaultModel)try{await _e.refresh(),e=_e.get()}catch{}if(e?.defaultModel?.provider){let t=e.defaultModel;a=t.provider??``,o=t.modelId??t.id??``}if((!a||!o)&&e?.modelList?.[0]){let t=e.modelList[0];a=t.provider??``,o=t.modelId??t.id??``}}catch{}if(!a||!o)return ve(m(`git.ai.noSessionModel`)),null}else{if(!i)return Ce(!0),null;let e=i.indexOf(`/`);if(e===-1||(a=i.slice(0,e),o=i.slice(e+1),!a||!o))return ve(m(`git.ai.invalidModel`)),null}let s=n.commitMessageMaxTokens,c=typeof s==`number`&&Number.isFinite(s)?Math.min(4096,Math.max(64,Math.round(s))):512;he(!0),ve(null);try{let n=await be.start(t=>fetch(`/api/git/generate-commit`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cwd:e,provider:a,modelId:o,maxTokens:c}),signal:t}),pte,{joinKey:`generate`}).promise;if(t!==xe.current)return null;let r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error??`Generate failed (HTTP ${n.status})`);if(!r.message)throw Error(`Empty response`);return se(r.message),r.message}catch(e){return t!==xe.current||e instanceof Fi&&e.message===`cancelled`||ve(e instanceof Error?e.message:String(e)),null}finally{t===xe.current&&he(!1)}},[me,ce,je,we,e,l,m,be]),ht=(0,d.useCallback)(async()=>{let t=await V9(e),n=t.isGitRepository;M(n?t.files:[]),ee(n?{additions:t.additions,deletions:t.deletions}:{additions:0,deletions:0}),I(n?t.stagedFiles:[]),ne(n?{additions:t.stagedAdditions,deletions:t.stagedDeletions}:{additions:0,deletions:0}),L(n?{branch:t.branch??null,upstream:t.upstream??null,ahead:t.ahead??0,behind:t.behind??0,hasUpstream:t.hasUpstream??!1}:{branch:null,upstream:null,ahead:0,behind:0,hasUpstream:!1});let r=z.trim()===``,i=n?t.stagedFiles??[]:[],a=n?t.files??[]:[],o=i.length+a.length>0;if(r&&Oe&&Ae&&o&&!me&&!ce&&!je&&!we){Te(!0);try{let e=await mt();if(!e)return;i.length>0?await pt(!1,e):ke?pe(!0):await pt(!0,e)}finally{Te(!1)}return}i.length>0?pt(!1):ke?pe(!0):pt(!0)},[e,z,Oe,Ae,ke,me,ce,je,we,mt,pt]),gt=et||Ye!==null||We!==null||qe!==null,_t=(0,d.useCallback)(()=>{!qe||qe.uploaded.length===0||a?.(qe.uploaded.map(t=>_G(vG(e,t),e)))},[e,a,qe]);return(0,E.jsxs)(`div`,{style:{minHeight:`100%`},children:[(0,E.jsx)(`input`,{ref:Qe,type:`file`,multiple:!0,hidden:!0,onChange:st}),gt&&(0,E.jsxs)(`div`,{style:{padding:`6px 8px`,borderBottom:`1px solid var(--border)`},children:[et&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-label":Be===`checking`?m(`files.checking`):m(`files.uploading`,{progress:He}),children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:8,minHeight:14,color:`var(--text-muted)`},children:[Be===`checking`?(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,style:{animation:`spin 0.8s linear infinite`},"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M21 12a9 9 0 1 1-5.7-8.4`})}):(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 16V4`}),(0,E.jsx)(`path`,{d:`m7 9 5-5 5 5`}),(0,E.jsx)(`path`,{d:`M5 20h14`})]}),Be===`uploading`&&(0,E.jsxs)(`span`,{style:{fontSize:`var(--text-xs)`},children:[He,`%`]})]}),Be===`uploading`&&(0,E.jsx)(`div`,{style:{height:3,marginTop:4,overflow:`hidden`,borderRadius:2,background:`var(--border)`},children:(0,E.jsx)(`div`,{style:{width:`${He}%`,height:`100%`,background:`var(--text-muted)`,transition:`width 120ms ease`}})})]}),Ye&&(0,E.jsxs)(`div`,{role:`alert`,style:{padding:7,border:`1px solid color-mix(in srgb, #f59e0b 55%, var(--border))`,borderRadius:4,background:`color-mix(in srgb, #f59e0b 9%, var(--bg-panel))`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-sm)`,color:`var(--text)`,lineHeight:1.35,overflowWrap:`anywhere`},children:m(`files.conflictSummary`,{count:Ye.conflicts.length,countSuffix:Ye.conflicts.length===1?``:`s`,files:Ye.conflicts.join(`, `)})}),Ye.nonReplaceable.length>0&&(0,E.jsx)(`div`,{style:{marginTop:3,fontSize:`var(--text-xs)`,color:`#f59e0b`,lineHeight:1.35,overflowWrap:`anywhere`},children:m(`files.cannotReplace`,{files:Ye.nonReplaceable.join(`, `)})}),(0,E.jsxs)(`div`,{style:{display:`flex`,gap:5,marginTop:7},children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>void at(Ye.files,`overwrite`),style:{height:22,padding:`0 7px`,border:`1px solid var(--status-error)`,borderRadius:4,background:`transparent`,color:`var(--status-error)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.replace`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>void at(Ye.files,`skip`),style:{height:22,padding:`0 7px`,border:`1px solid var(--border)`,borderRadius:4,background:`var(--bg-panel)`,color:`var(--text)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.skipExisting`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>Xe(null),style:{height:22,padding:`0 7px`,border:`none`,borderRadius:4,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-xs)`},children:m(`files.cancel`)})]})]}),We&&(0,E.jsxs)(`div`,{role:`alert`,style:{display:`flex`,alignItems:`flex-start`,gap:6,fontSize:`var(--text-sm)`,lineHeight:1.35,color:`var(--status-error)`},children:[(0,E.jsx)(`span`,{style:{minWidth:0,flex:1,overflowWrap:`anywhere`},children:We}),(0,E.jsx)(K9,{onClick:()=>Ge(null),title:m(`files.dismissError`)})]}),qe&&(0,E.jsxs)(`div`,{"aria-live":`polite`,children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,minHeight:22,fontSize:`var(--text-sm)`},children:[(0,E.jsxs)(`div`,{style:{minWidth:0,flex:1,display:`flex`,alignItems:`center`,gap:8},children:[qe.uploaded.length>0&&(0,E.jsxs)(`span`,{title:`${qe.uploaded.length} uploaded`,"aria-label":`${qe.uploaded.length} uploaded`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--status-success)`},children:[(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m5 12 4 4L19 6`})}),(0,E.jsx)(`span`,{children:qe.uploaded.length})]}),qe.skipped.length>0&&(0,E.jsxs)(`span`,{title:`${qe.skipped.length} skipped`,"aria-label":`${qe.skipped.length} skipped`,style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--text-dim)`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,E.jsx)(`path`,{d:`M8 12h8`})]}),(0,E.jsx)(`span`,{children:qe.skipped.length})]}),qe.errors.length>0&&(0,E.jsxs)(`span`,{title:m(`files.uploadFailed`,{count:qe.errors.length}),"aria-label":m(`files.uploadFailed`,{count:qe.errors.length}),style:{display:`flex`,alignItems:`center`,gap:3,color:`var(--status-error)`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 3 2.5 20h19L12 3Z`}),(0,E.jsx)(`path`,{d:`M12 9v4`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),(0,E.jsx)(`span`,{children:qe.errors.length})]})]}),qe.uploaded.length>0&&a&&(0,E.jsxs)(`button`,{type:`button`,onClick:_t,title:qe.uploaded.length===1?m(`files.addUploadedFile`):m(`files.addAllUploadedFiles`),"aria-label":qe.uploaded.length===1?m(`files.addUploadedFile`):m(`files.addAllUploadedFiles`),style:{height:22,padding:`0 7px`,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:4,flexShrink:0,border:`1px solid var(--border)`,borderRadius:4,background:`var(--bg-panel)`,color:`var(--accent)`,cursor:`pointer`,fontSize:`var(--text-sm)`,fontWeight:600,whiteSpace:`nowrap`},children:[(0,E.jsx)(G9,{}),m(`files.mention`)]}),(0,E.jsx)(K9,{onClick:()=>Je(null),title:m(`files.dismissUploadResults`)})]}),qe.errors.map(e=>(0,E.jsxs)(`div`,{title:e.error,style:{display:`flex`,alignItems:`center`,gap:4,marginTop:3,minWidth:0,fontSize:`var(--text-xs)`,color:`var(--status-error)`},children:[(0,E.jsxs)(`svg`,{width:p.sm,height:p.sm,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{flexShrink:0},"aria-hidden":`true`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,E.jsx)(`path`,{d:`M12 8v5`}),(0,E.jsx)(`path`,{d:`M12 17h.01`})]}),(0,E.jsx)(`span`,{style:{minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.name))]})]}),!s&&(0,E.jsxs)(gte,{children:[(0,E.jsx)(hte,{message:z,onMessageChange:se,commitBusy:ce||we,canCommit:F.length+j.length>0,onCommit:ht,pushBusy:je,canPush:ae.hasUpstream?ae.ahead>0:!!ae.branch&&ae.branch!==`HEAD`,onPush:ct,pullBusy:Ie,canPull:ae.hasUpstream&&ae.behind>0,onPull:lt,aiBusy:me,canAiGenerate:F.length+j.length>0,onAiGenerate:()=>{se(``),mt()},autoGenerateOnEmpty:Oe,hasModelForAuto:Ae,aiModelHint:(()=>{if(Ee.commitMessageUseCurrentModel===!0)return m(`git.ai.usingCurrentModel`);let e=typeof Ee.commitMessageModel==`string`?Ee.commitMessageModel:``;return e?m(`git.ai.usingModel`,{model:e}):``})(),t:m}),Ne&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,style:{marginTop:4,padding:`6px 8px`,borderRadius:6,border:`1px solid ${Ne.ok?`var(--status-success)`:`var(--status-error)`}`,background:`var(--bg)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,marginBottom:4},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:Ne.ok?`var(--status-success)`:`var(--status-error)`,flexShrink:0}}),(0,E.jsx)(`span`,{style:{color:`var(--text-muted)`,flex:1,minWidth:0},children:m(Ne.ok?`files.pushSuccess`:`files.pushFailed`)}),(0,E.jsx)(`button`,{onClick:()=>Pe(null),"aria-label":m(`files.dismissError`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,background:`none`,border:`none`,borderRadius:4,color:`var(--text-dim)`,cursor:`pointer`,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}),Ne.output&&(0,E.jsx)(`pre`,{style:{margin:0,maxHeight:140,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,color:Ne.ok?`var(--text-muted)`:`var(--status-error)`,fontFamily:`var(--font-mono)`},children:Ne.output})]}),Re&&(0,E.jsxs)(`div`,{role:`status`,"aria-live":`polite`,style:{marginTop:4,padding:`6px 8px`,borderRadius:6,border:`1px solid ${Re.ok?`var(--status-success)`:`var(--status-error)`}`,background:`var(--bg)`,fontSize:`var(--text-sm)`,lineHeight:1.5},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,marginBottom:4},children:[(0,E.jsx)(`span`,{style:{width:7,height:7,borderRadius:`50%`,background:Re.ok?`var(--status-success)`:`var(--status-error)`,flexShrink:0}}),(0,E.jsx)(`span`,{style:{color:`var(--text-muted)`,flex:1,minWidth:0},children:m(Re.ok?`files.pullSuccess`:`files.pullFailed`)}),(0,E.jsx)(`button`,{onClick:()=>ze(null),"aria-label":m(`files.dismissError`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,background:`none`,border:`none`,borderRadius:4,color:`var(--text-dim)`,cursor:`pointer`,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}),Re.output&&(0,E.jsx)(`pre`,{style:{margin:0,maxHeight:140,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-all`,color:Re.ok?`var(--text-muted)`:`var(--status-error)`,fontFamily:`var(--font-mono)`},children:Re.output})]}),ue&&(0,E.jsx)(X9,{message:ue,onDismiss:()=>de(null)}),R&&(0,E.jsx)(X9,{message:z9(R,m),onDismiss:()=>oe(null)}),ge&&(0,E.jsx)(X9,{message:ge,onDismiss:()=>ve(null)}),(0,E.jsx)(Y9,{prefix:m(`files.stagedPrefix`),count:re.length,additions:te.additions,deletions:te.deletions,t:m}),re.length>0?re.map(n=>(0,E.jsx)(J9,{status:n,cwd:e,onOpenFile:t,onStageToggle:e=>void ft(e,!0),unstage:!0,t:m},`staged-${n.filePath}`)):(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,textAlign:`center`},children:m(`files.noStagedChanges`)}),(0,E.jsx)(`div`,{style:{height:6}}),(0,E.jsx)(Y9,{prefix:m(`files.unstagedPrefix`),count:ie.length,additions:P.additions,deletions:P.deletions,t:m}),ie.length>0?ie.map(n=>(0,E.jsx)(J9,{status:n,cwd:e,onOpenFile:t,onStageToggle:e=>void ft(e,!1),t:m},n.filePath)):(0,E.jsx)(`div`,{style:{padding:`8px 10px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`,textAlign:`center`},children:m(`files.noUnstagedChanges`)})]}),s&&(0,E.jsxs)(_te,{ref:x,children:[y?(0,E.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:`var(--text-sm)`,color:`var(--status-error)`},children:z9(y,m)}):(D?O:h).map(n=>(0,E.jsx)(q9,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:S,onToggleExpanded:rt,refreshToken:$e,highlightedPaths:k,gitStatusByPath:tt,changedDirectoryPaths:nt,t:m},n.fullPath)),!_&&!y&&h.length===0&&(0,E.jsx)(`div`,{style:{padding:`8px 12px`,fontSize:`var(--text-sm)`,color:`var(--text-dim)`},children:m(`files.noFiles`)})]}),(0,E.jsx)(YS,{open:Se,title:m(`git.ai.notConfiguredTitle`),description:m(`git.ai.notConfiguredDesc`),confirmText:m(`git.ai.goToConfig`),cancelText:m(`sidebar.cancel`),onCancel:()=>Ce(!1),onConfirm:()=>{Ce(!1),u?.(`git`)},icon:(0,E.jsx)(Si,{size:p[`5xl`],style:{color:`var(--accent)`}})}),(0,E.jsx)(YS,{open:fe,title:m(`files.commitTitle`),description:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{children:m(`files.confirmStageAllCommit`,{count:j.length})}),z.trim()!==``&&(0,E.jsx)(`div`,{style:{marginTop:8,padding:`6px 10px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:6,fontFamily:`var(--font-mono)`,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,maxHeight:120,overflowY:`auto`,textAlign:`left`},children:z.trim()})]}),confirmText:m(`files.stageAllAndCommit`),cancelText:m(`sidebar.cancel`),onCancel:()=>pe(!1),onConfirm:()=>{pe(!1),pt(!0)},icon:(0,E.jsxs)(`svg`,{width:p[`5xl`],height:p[`5xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`var(--status-warning)`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{flexShrink:0,marginTop:1},children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`m9 12 2 2 4-4`})]})})]})});function yte({cwd:e,onOpenFile:t,explorerRefreshKey:n,onExplorerRefresh:r,onAtMention:i,onAtMentions:a,sessionId:o,onOpenConfig:s}){let{t:c}=N(),[l,u]=(0,d.useState)(0),[f,m]=(0,d.useState)(!1),[h,g]=(0,d.useState)(0),[_,v]=(0,d.useState)(!0),[y,b]=(0,d.useState)(!1),x=(0,d.useRef)(null),S=(0,d.useRef)(null),[C,w]=(0,d.useState)(!1),[T,D]=(0,d.useState)(``),O=(0,d.useRef)(null);return(0,d.useEffect)(()=>{C&&O.current?.focus()},[C]),Wi(()=>{n!==void 0&&u(e=>e+1)},[n]),e?(0,E.jsx)(x9,{title:c(`files.explorer`),open:!0,onToggle:()=>{},collapsible:!1,testId:`explorer-scroll`,hintTestId:`explorer`,style:{flex:1,minHeight:0},scrollStyle:{background:`var(--bg)`},actions:(0,E.jsx)(y9,{items:[{key:`git`,testId:`explorer-changes-toggle`,onClick:()=>v(e=>!e),title:c(`sidebar.changedFiles`,{count:h}),ariaPressed:!_,color:h>0?`var(--accent)`:`var(--text-muted)`,background:_?void 0:`var(--bg-selected)`,borderColor:_?void 0:`var(--accent)`,icon:(0,E.jsx)(Zr,{size:p.lg})},{key:`search`,testId:`explorer-search-toggle`,onClick:()=>{C&&D(``),w(e=>!e)},title:c(`files.search`),ariaPressed:C,color:C?`var(--accent)`:`var(--text-muted)`,background:C?`var(--bg-selected)`:void 0,icon:(0,E.jsx)(vi,{size:p.lg})},{key:`upload`,onClick:()=>S.current?.openUploadPicker(),disabled:f,title:c(`sidebar.uploadFilesTitle`),color:`var(--text-muted)`,icon:(0,E.jsx)(fi,{size:p.base})},{key:`refresh`,onClick:()=>{r?r():u(e=>e+1),b(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>b(!1),2e3)},title:c(`sidebar.refreshExplorer`),skipHover:y,color:y?`var(--status-success)`:`var(--text-muted)`,background:y?`color-mix(in srgb, var(--status-success) 18%, transparent)`:void 0,icon:y?(0,E.jsx)(Rr,{size:p.lg,color:`var(--status-success)`,strokeWidth:2.5}):(0,E.jsx)(mi,{size:p.lg})}]}),headerExtra:C?(0,E.jsxs)(`div`,{"data-testid":`explorer-search`,style:{display:`flex`,alignItems:`center`,gap:4,width:`100%`,minWidth:0,padding:`4px 8px`,background:`var(--bg)`,borderBottom:`1px solid var(--border)`,boxSizing:`border-box`},children:[(0,E.jsx)(vi,{size:p.lg,color:`var(--text-muted)`,style:{flexShrink:0}}),(0,E.jsx)(`input`,{ref:O,"data-testid":`explorer-search-input`,value:T,onChange:e=>D(e.target.value),placeholder:c(`files.searchPlaceholder`),"aria-label":c(`files.search`),style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`var(--text)`,fontSize:`var(--text-sm)`}}),T&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{D(``),O.current?.focus()},"aria-label":c(`chat.clearSearch`),style:{border:`none`,background:`transparent`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,display:`flex`,alignItems:`center`,justifyContent:`center`,width:16,height:16,padding:0,flexShrink:0},children:(0,E.jsx)(Mi,{size:p.base})})]}):void 0,children:(0,E.jsx)(vte,{ref:S,cwd:e,onOpenFile:t??(()=>{}),refreshKey:l,searchQuery:T,onAtMention:i,onAtMentions:a,onUploadBusyChange:m,changesCollapsed:_,onChangesCountChange:g,sessionId:o,onOpenConfig:s})}):null}function bte({geometries:e,messages:t,onAddMessage:n,onRemoveMessage:r,onUpdateMessage:i,widgets:a,closedKeys:o,onReopen:s}){let{t:c}=N(),[l,u]=(0,d.useState)(null),[f,p]=(0,d.useState)(null),m=(0,d.useRef)(null);(0,d.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=e=>a.find(t=>t.key===e)?.lines[0],g=(e,t,n)=>{s(e),p({key:e,x:t,y:n}),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>p(null),2500)},_=[...new Set([...Object.keys(e),...o.keys()])].map(t=>[t,e[t]]);return(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,background:`var(--bg)`},children:[_.length===0?(0,E.jsx)(`div`,{style:{padding:`32px 16px`,textAlign:`center`,color:`var(--text-dim)`,fontSize:`var(--text-lg)`,lineHeight:1.6},children:c(`config.widgets.empty`)}):(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,overflowY:`auto`,padding:10,display:`flex`,flexDirection:`row`,flexWrap:`wrap`,alignContent:`flex-start`,gap:6},children:_.map(([e,a])=>{let s=t[e]??[],d=o.has(e),f=h(e);return(0,E.jsxs)(`div`,{"data-testid":`widget-config-item-${e}`,style:{flex:`1 1 200px`,boxSizing:`border-box`,padding:`8px 10px`,borderRadius:5,background:`var(--bg-panel)`,border:`1px solid var(--border)`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:7,flexWrap:`wrap`},children:[(0,E.jsxs)(`div`,{style:{minWidth:0,flex:`1 1 120px`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,fontWeight:600,fontFamily:`var(--font-mono)`,color:`var(--text)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e}),a&&(0,E.jsxs)(`div`,{style:{marginTop:2,fontSize:`var(--text-sm)`,fontFamily:`var(--font-mono)`,color:`var(--text-dim)`},children:[c(`config.widgets.x`),`: `,a.x,` `,c(`config.widgets.y`),`: `,a.y,` ·`,` `,c(`config.widgets.width`),`: `,a.width,` `,c(`config.widgets.height`),`:`,` `,a.height]})]}),(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4,flexShrink:0},children:[d&&(0,E.jsxs)(`button`,{type:`button`,"data-testid":`widget-expand-${e}`,"aria-label":c(`widgets.reopen`),title:c(`widgets.reopen`),onClick:t=>g(e,t.clientX,t.clientY),style:{display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},className:`hover-shift`,children:[(0,E.jsx)(qr,{size:13,"aria-hidden":!0}),c(`widgets.reopen`)]}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`widget-bind-${e}`,onClick:()=>u(e),style:{display:`flex`,alignItems:`center`,gap:4,padding:`4px 8px`,borderRadius:5,border:`1px solid var(--border)`,background:`var(--bg)`,color:`var(--text-muted)`,fontSize:`var(--text-sm)`,cursor:`pointer`},children:[(0,E.jsx)(ii,{size:13,"aria-hidden":!0}),c(`config.widgets.bind`)]})]})]}),f&&(0,E.jsx)(`div`,{style:{marginTop:4,fontSize:`var(--text-sm)`,color:`var(--text-muted)`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:f}),(0,E.jsx)(JK,{messages:s,onAdd:t=>n(e,t),onRemove:t=>r(e,t),onUpdate:(t,n)=>i(e,t,n),bindOpen:l===e,onBindOpenChange:e=>{e||u(null)},ns:`widgets`,bindTestIdPrefix:`widget-bind`,editTestIdPrefix:`widget-edit`,chipTestIdPrefix:`widget-bound-${e}`,bindHintArgs:{key:e}})]},e)})}),f&&(0,E.jsx)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`widget-expanded-toast`,style:{position:`fixed`,left:Math.min(f.x,window.innerWidth-180),top:f.y+12,transform:`translateX(-50%)`,zIndex:2e3,padding:`8px 12px`,borderRadius:7,border:`1px solid var(--status-success)`,background:`var(--bg)`,color:`var(--text)`,fontSize:`var(--text-base)`,boxShadow:`0 4px 16px var(--shadow-strong)`,whiteSpace:`nowrap`},children:c(`widgets.expandedToChat`,{key:f.key})})]})}var xte=e=>window.history.replaceState(null,``,e),Z9=36,Ste=176,Cte=224,Q9=86,$9=116;function wte(){let[e,t]=(0,d.useState)(!1);(0,d.useEffect)(()=>{t(!0)},[]);let[n]=(0,d.useState)(()=>Pq(new URLSearchParams(window.location.search))),{isDark:r,toggleTheme:i}=Tr(),{locale:a,setLocale:o,t:s,supportedLocales:c}=N(),l=ne();wq();let{settingsValue:u,defaultThinkingLevel:f,setDefaultThinkingLevel:m,compaction:h,retry:g,defaultProjectTrust:_,setDefaultProjectTrust:v,subagents:y,savedWorkspaces:b,handleSavedWorkspacesChange:x,widgetGeometries:S,setWidgetGeometry:C,widgetMessages:w,addWidgetMessage:T,removeWidgetMessage:D,updateWidgetMessage:O,fontScale:k,setFontScale:A}=Ut({isDark:r,toggleTheme:i}),[j,M]=(0,d.useState)(null),{selectedSession:ee,effectiveNewSessionCwd:F,showChat:I,projectTrustCwd:te,refreshKey:re,sessionKey:ie,explorerRefreshKey:R,setExplorerRefreshKey:oe,modelsRefreshKey:z,setModelsRefreshKey:se,activeCwd:ue,initialCwdStatus:de,initialCwdError:me,initialSessionRestored:he,projectTrust:ge,projectTrustDialogOpen:_e,setProjectTrustDialogOpen:ve,projectTrustBusy:ye,projectTrustError:be,setProjectTrustError:xe,extensionDialogActiveRef:Se,handleSelectSession:Te,handleNewSession:Ee,handleSessionCreated:De,handleAgentEnd:Oe,handleSessionRenamed:ke,handleSessionForked:Ae,handleSessionDeleted:je,handleSessionUnseen:Me,handleCwdChange:Ne,handleTrustProject:Pe,handleExplorerRefresh:Le,handleInitialRestoreDone:ze}=Qe({initialNavigation:n,onProjectSwitch:()=>{M(null),Be(e=>e.filter(e=>e.kind!==`file`)),Ve(null),xte(`/`)},onSessionSelected:e=>{l&&!e&<(!1)},onTopPanelReset:()=>M(null)}),{setSavedTabs:Be,setActiveSavedId:Ve,configTabOpen:He,configSection:Ue,setConfigSection:We,configTabActive:Ge,activeFileTab:Ke,fileTabs:qe,modelConfigFocus:Je,handleOpenFile:Ye,openConfigTab:Xe,handleOpenModelConfig:Ze,closeConfigTab:$e,handleCloseMainTab:tt}=bq({onSessionSelected:()=>{Pt(!1),l&<(!1)},onRefreshModels:()=>se(e=>e+1)}),{value:nt}=P(we),rt=(0,d.useMemo)(()=>nt?Fe(nt):0,[nt]),it=(0,d.useMemo)(()=>nt?Ie(nt,s(`common.plugins`)):[],[nt,s]),[at,ot]=(0,d.useState)(!1),st=(0,d.useCallback)(e=>{Ye(e,hG(e),{sourceSessionId:ee?.id??null})},[Ye,ee?.id]),[ct,lt]=(0,d.useState)(!0),[ut,dt]=(0,d.useState)(!1),ft=(0,d.useRef)(280),pt=(0,d.useRef)(280),mt=(0,d.useCallback)(()=>typeof window>`u`?480:ce({viewportWidth:window.innerWidth,rightPanelOpen:!1,rightPanelWidth:0}),[]),ht=fe({ariaLabel:s(`layout.resizeSidebar`),cssVariable:`--sidebar-width`,defaultWidth:280,getMaxWidth:mt,growthDirection:`right`,maxWidth:480,minWidth:180,storageKey:`pi-sidebar-width`,widthRef:ft}),gt=ht.reclampWidth,_t=fe({ariaLabel:s(`layout.resizeWidgetPanel`),cssVariable:`--widget-panel-width`,defaultWidth:280,getMaxWidth:()=>typeof window>`u`?560:le({viewportWidth:window.innerWidth,sidebarOpen:ct,sidebarWidth:ht.width}),growthDirection:`left`,maxWidth:560,minWidth:200,storageKey:`pi-widget-panel-width`,widthRef:pt});(0,d.useEffect)(()=>{l&<(!1)},[l,lt]),(0,d.useEffect)(()=>{dt(!0)},[]),(0,d.useEffect)(()=>{gt()},[gt]);let vt=(0,d.useRef)(void 0);(0,d.useEffect)(()=>{ue!==vt.current&&(vt.current=ue,Ce(ue),we.load().catch(e=>console.error(`[pi-web] load updates:`,e)))},[ue]);let yt=(0,d.useRef)(null),bt=(0,d.useRef)(null),xt=(0,d.useRef)(null),St=(0,d.useRef)(null),Ct=(0,d.useRef)(null),wt=pe(),Tt=(0,d.useCallback)(()=>{wt.schedule(()=>{M(null)},150)},[wt]),Et=wt.cancel,[Dt,Ot]=(0,d.useState)(null),kt=(0,d.useCallback)(e=>{l&<(!1),M(t=>t===e?null:e)},[l]),At=(0,d.useCallback)(()=>{l&&M(null),lt(e=>!e)},[l]);(0,d.useEffect)(()=>{if(!j)return;let e=()=>{if(document.hidden)return;let e=bt.current?.getBoundingClientRect();if(e){if(j===`language`&&!l&&St.current){let t=St.current.getBoundingClientRect(),n=xt.current?.getBoundingClientRect(),r=n?.top??t.top,i=n?.bottom??t.bottom,a=Math.min(Ste,n?.width??e.width),o=Math.min(t.left-1,Math.max(n?.left??e.left,(n?.right??e.right)-a)),s=i+4;Ot({top:s+Q9>window.innerHeight-4?r-Q9:s,left:o,width:a});return}if(j===`fontSize`&&!l&&Ct.current){let t=Ct.current.getBoundingClientRect(),n=xt.current?.getBoundingClientRect(),r=n?.top??t.top,i=n?.bottom??t.bottom,a=Math.min(Cte,n?.width??e.width),o=Math.min(t.left-1,Math.max(n?.left??e.left,(n?.right??e.right)-a)),s=i+4;Ot({top:s+$9>window.innerHeight-4?r-$9:s,left:o,width:a});return}Ot({top:e.bottom,left:e.left,width:e.width})}};e();let t=new ResizeObserver(e);return bt.current&&t.observe(bt.current),St.current&&t.observe(St.current),Ct.current&&t.observe(Ct.current),()=>t.disconnect()},[j,l]);let{widgetPanelOpen:jt,setWidgetPanelOpen:Mt,widgetsTabActive:Nt,setWidgetsTabActive:Pt,extensionWidgets:Ft,closedWidgets:It,handleCloseWidget:Lt,handleReopenWidget:zt,handleExtensionWidgetsChange:Bt,rightSidebarOpen:Vt,setRightSidebarOpen:Ht,closedWidgetCount:Wt}=xq({widgetGeometries:S,setWidgetGeometry:C}),Gt=l?jt:Vt,Kt=(0,d.useCallback)((e,t)=>{yt.current?.insertText(jq(e,t))},[]),qt=(0,d.useCallback)(e=>{let t=Nq(e);t&&yt.current?.insertText(t)},[]),Jt=(0,d.useCallback)((e,t,n)=>{yt.current?.insertText(Mq(e,t,n))},[]),Yt=n.sessionId;ae({onNewSession:e=>Ee(`kb-${Date.now()}`,e),activeCwd:ue});let Xt=he&&!I,Zt=[{id:dq,label:s(`tabs.chat`),closable:!1,icon:(0,E.jsx)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`})})},{id:pq,label:s(`tabs.widgets`),badge:Wt,closable:!1,icon:(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`}),(0,E.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`})]})},...He?[{id:fq,label:s(`config.title`),closable:!0,icon:(0,E.jsx)(bi,{width:p.lg,height:p.lg,"aria-hidden":`true`})}]:[],...qe],Qt=ue?hG(ue)||ue:null,$t=Qt?`Pi Web · ${Qt}`:`Pi Web`;(0,d.useEffect)(()=>{document.title=$t},[$t]),(0,d.useEffect)(()=>{let e=()=>{document.title=$t};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[$t]);let en=L(),tn=(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{ref:xt,style:{padding:`2px 8px`,flexShrink:0,display:`flex`,justifyContent:`space-between`,gap:4},children:[{label:s(`config.title`),onClick:()=>{M(null),Xe()},disabled:!1,badge:rt,icon:(0,E.jsx)(bi,{width:p[`3xl`],height:p[`3xl`],"aria-hidden":`true`})},...en===`granted`||en==="default"||en===`denied`?[{label:s(en===`granted`?`notify.permission.grantedHint`:en===`denied`?`notify.permission.deniedHint`:`notify.permission.requestHint`),ariaLabel:s(en===`granted`?`notify.permission.granted`:en===`denied`?`notify.permission.denied`:`notify.permission.request`),onClick:en===`granted`?()=>{}:()=>Dn(),disabled:!1,testId:`notify-permission`,color:en===`granted`?`var(--status-success)`:en===`denied`?`var(--status-error)`:`var(--accent)`,icon:(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:en===`denied`?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`path`,{d:`M8.7 3A6 6 0 0 1 18 8a21.3 21.3 0 0 0 .6 5`}),(0,E.jsx)(`path`,{d:`M17 17H3s3-2 3-9a4.67 4.67 0 0 1 .3-1.7`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`}),(0,E.jsx)(`path`,{d:`m2 2 20 20`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`path`,{d:`M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9`}),(0,E.jsx)(`path`,{d:`M10.3 21a1.94 1.94 0 0 0 3.4 0`})]})})}]:[],{label:s(r?`theme.light`:`theme.dark`),onClick:()=>i(),disabled:!1,ariaPressed:r,icon:r?(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,E.jsx)(`line`,{x1:`12`,y1:`1`,x2:`12`,y2:`3`}),(0,E.jsx)(`line`,{x1:`12`,y1:`21`,x2:`12`,y2:`23`}),(0,E.jsx)(`line`,{x1:`4.22`,y1:`4.22`,x2:`5.64`,y2:`5.64`}),(0,E.jsx)(`line`,{x1:`18.36`,y1:`18.36`,x2:`19.78`,y2:`19.78`}),(0,E.jsx)(`line`,{x1:`1`,y1:`12`,x2:`3`,y2:`12`}),(0,E.jsx)(`line`,{x1:`21`,y1:`12`,x2:`23`,y2:`12`}),(0,E.jsx)(`line`,{x1:`4.22`,y1:`19.78`,x2:`5.64`,y2:`18.36`}),(0,E.jsx)(`line`,{x1:`18.36`,y1:`5.64`,x2:`19.78`,y2:`4.22`})]}):(0,E.jsx)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,E.jsx)(`path`,{d:`M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z`})})},{label:s(`common.language`),onClick:()=>{l&<(!1),Et(),M(`language`)},onMouseEnter:()=>{Et(),j!==`language`&&M(`language`)},onMouseLeave:Tt,disabled:!1,ref:St,ariaExpanded:j===`language`,noTooltip:!0,icon:(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,E.jsx)(`line`,{x1:`2`,y1:`12`,x2:`22`,y2:`12`}),(0,E.jsx)(`path`,{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`})]})},{label:s(`theme.fontSize`),onClick:()=>{l&<(!1),Et(),M(`fontSize`)},onMouseEnter:()=>{Et(),j!==`fontSize`&&M(`fontSize`)},onMouseLeave:Tt,disabled:!1,ref:Ct,ariaExpanded:j===`fontSize`,noTooltip:!0,icon:(0,E.jsxs)(`svg`,{width:p[`3xl`],height:p[`3xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`polyline`,{points:`4 7 4 4 20 4 20 7`}),(0,E.jsx)(`line`,{x1:`9`,y1:`20`,x2:`15`,y2:`20`}),(0,E.jsx)(`line`,{x1:`12`,y1:`4`,x2:`12`,y2:`20`})]})}].map(({label:e,onClick:t,onMouseEnter:n,onMouseLeave:r,disabled:i,icon:a,ref:o,ariaPressed:s,ariaExpanded:c,noTooltip:l,badge:u,color:d,ariaLabel:f,testId:p})=>{let m=(0,E.jsxs)(`button`,{ref:o,onClick:t,disabled:i,"data-testid":p,"aria-label":f??e,"aria-pressed":s,"aria-haspopup":c===void 0?void 0:`menu`,"aria-expanded":c,style:{flex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,height:32,padding:0,background:`none`,border:`none`,borderRadius:9,...d?{color:d}:{color:`var(--text-muted)`},cursor:i?`default`:`pointer`,opacity:i?.35:1,transition:`background 0.12s, color 0.12s`,"--hover-color":`var(--text)`},onMouseEnter:n,onMouseLeave:r,className:`hover-shift`,children:[a,u!==void 0&&u>0?(0,E.jsx)(`span`,{"data-testid":`settings-update-badge`,style:{position:`absolute`,top:3,right:3,minWidth:15,height:15,padding:`0 4px`,borderRadius:8,background:`var(--status-error)`,color:`#fff`,fontSize:10,fontWeight:600,lineHeight:`15px`,textAlign:`center`},children:u}):null]});return l?(0,E.jsx)(`div`,{style:{flex:1,minWidth:0,display:`flex`},children:m},e):(0,E.jsx)(qi,{label:e,wrapperStyle:{flex:1,minWidth:0,display:`flex`},children:m},e)})}),rt>0&&!at&&(0,E.jsxs)(`div`,{role:`status`,"data-testid":`update-banner`,style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 12px`,borderBottom:`1px solid var(--border)`,background:`color-mix(in srgb, var(--status-warning) 10%, var(--bg-panel))`,fontSize:`var(--text-sm)`,color:`var(--text)`,flexShrink:0},children:[(0,E.jsx)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:s(`updates.banner`,{items:it.join(`, `)})}),(0,E.jsx)(`button`,{type:`button`,"data-testid":`update-banner-view`,onClick:()=>{Xe(),We(`updates`)},style:{padding:`3px 10px`,border:`1px solid var(--border)`,borderRadius:6,background:`none`,color:`var(--text-muted)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0},children:s(`updates.view`)}),(0,E.jsx)(`button`,{type:`button`,"aria-label":s(`i18n.close`),onClick:()=>ot(!0),style:{padding:`2px 6px`,border:`none`,background:`none`,color:`var(--text-dim)`,cursor:`pointer`,fontSize:`var(--text-sm)`,flexShrink:0},children:`✕`})]}),(0,E.jsx)(tte,{selectedSessionId:ee?.id??null,selectedSession:ee,onSelectSession:Te,onNewSession:Ee,initialSessionId:Yt,skipInitialProjectSelection:n.requestedCwd!==null,onInitialRestoreDone:ze,refreshKey:re,onSessionDeleted:je,onUnseenSession:Me,selectedCwd:ee?.cwd??F,onCwdChange:Ne,savedWorkspaces:b,onSavedWorkspacesChange:x,onOpenFile:Ye})]});if(!e)return(0,E.jsx)(Fq,{});let nn=(0,E.jsx)(qi,{label:s(ct?`sidebar.hide`:`sidebar.show`),children:(0,E.jsx)(`button`,{onClick:At,"aria-label":s(ct?`sidebar.hide`:`sidebar.show`),"aria-pressed":ct,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:Z9,height:Z9,padding:0,background:`none`,border:`none`,borderRight:`1px solid var(--border)`,color:ct?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,flexShrink:0,transition:`color 0.12s`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p[`4xl`],height:p[`4xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:p[`4xl`],height:p[`4xl`],rx:`2`}),(0,E.jsx)(`line`,{x1:`9`,y1:`3`,x2:`9`,y2:`21`})]})})}),rn=I&&ge?.requiresTrust&&!ge.trusted?(0,E.jsx)(qi,{label:s(`trust.resourcesNotLoaded`),wrapperStyle:{height:`100%`},children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>{xe(null),ve(!0)},"aria-label":s(`trust.resourcesNotLoaded`),style:{display:`flex`,alignItems:`center`,gap:6,height:`100%`,padding:l?`0 10px`:`0 12px`,background:`none`,border:`none`,borderLeft:`1px solid var(--border)`,color:`var(--status-warning)`,cursor:`pointer`,flexShrink:0,fontSize:`var(--text-sm)`,whiteSpace:`nowrap`},children:[(0,E.jsxs)(`svg`,{width:p.lg,height:p.lg,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,E.jsx)(`path`,{d:`M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z`}),(0,E.jsx)(`path`,{d:`M12 8v4`}),(0,E.jsx)(`path`,{d:`M12 16h.01`})]}),!l&&(0,E.jsx)(`span`,{children:s(`trust.resourcesNotLoaded`)})]})}):null,an=(0,E.jsx)(qi,{label:s(Gt?`sidebar.hide`:`sidebar.show`),children:(0,E.jsx)(`button`,{onClick:()=>{l?Mt(e=>!e):Ht(e=>!e)},"aria-controls":`widget-panel`,"aria-expanded":Gt,"aria-label":s(Gt?`sidebar.hide`:`sidebar.show`),"data-testid":`widget-panel-toggle`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,width:36,height:36,padding:0,background:`none`,border:`none`,borderLeft:`1px solid var(--border)`,color:jt?`var(--text)`:`var(--text-muted)`,cursor:`pointer`,flexShrink:0,transition:`color 0.12s`,"--hover-color":`var(--text)`},className:`hover-shift`,children:(0,E.jsxs)(`svg`,{width:p[`4xl`],height:p[`4xl`],viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`rect`,{x:`3`,y:`3`,width:p[`4xl`],height:p[`4xl`],rx:`2`}),(0,E.jsx)(`line`,{x1:`15`,y1:`3`,x2:`15`,y2:`21`})]})})});return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(Re,{value:u,children:(0,E.jsx)(et,{value:{activeTopPanel:j,toggleTopPanel:kt,closeTopPanel:()=>M(null)},children:(0,E.jsx)(E.Fragment,{children:(0,E.jsxs)(Ki,{delayDuration:0,children:[(0,E.jsx)(`style`,{children:`
|
|
498
498
|
@media (max-width: 640px) {
|
|
499
499
|
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
500
500
|
opacity: 0 !important;
|
|
@@ -505,4 +505,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
505
505
|
box-shadow: none;
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
|
-
`}),(0,E.jsx)(Pn,{}),(0,E.jsxs)(`div`,{style:{display:`flex`,width:`100%`,height:`var(--app-viewport-height, 100dvh)`,paddingLeft:`env(safe-area-inset-left)`,paddingRight:`env(safe-area-inset-right)`,overflow:`hidden`,background:`var(--bg)`},children:[(0,E.jsx)(`div`,{className:`sidebar-overlay-backdrop${ut?``:` sidebar-mobile-pending`}`,onClick:()=>lt(!1),style:{position:`fixed`,inset:0,zIndex:199,background:`var(--overlay)`,opacity:+!!ct,pointerEvents:ct?`auto`:`none`,transition:`opacity 0.25s ease`}}),(0,E.jsx)(`div`,{ref:ht.panelRef,id:`session-sidebar`,className:`sidebar-container${ct?` sidebar-open`:` sidebar-closed`}${ut?``:` sidebar-mobile-pending`}${ht.isResizing?` sidebar-resizing`:``}`,"data-testid":`sidebar`,style:{"--sidebar-width":`${ht.width}px`,background:`var(--bg-panel)`,borderRight:`1px solid var(--border)`,display:`flex`,flexDirection:`column`,flexShrink:0,paddingTop:`env(safe-area-inset-top)`,paddingBottom:`env(safe-area-inset-bottom)`,zIndex:200},children:tn}),ct&&(0,E.jsx)(qi,{label:`${s(`layout.resizeSidebar`)}: ${s(`layout.resizeHint`)}`,wrapperStyle:{display:`flex`,flex:`0 0 0`,width:0},children:(0,E.jsx)(`div`,{...ht.separatorProps,"aria-controls":`session-sidebar`,className:`panel-resize-handle sidebar-resize-handle${ht.isResizing?` is-resizing`:``}`,"data-resize-handle":`sidebar`})}),(0,E.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`hidden`,minWidth:0},children:[j&&Dt&&(0,E.jsxs)(`div`,{onMouseEnter:Et,onMouseLeave:Tt,style:{position:`fixed`,top:Dt.top,left:Dt.left,width:Dt.width,maxHeight:`calc(100dvh - ${Dt.top}px)`,overflowY:`auto`,zIndex:1500},children:[j===`language`&&(0,E.jsx)(`div`,{role:`menu`,"aria-label":s(`common.language`),style:{background:`var(--bg-panel)`,border:`1px solid var(--border)`,overflow:`hidden`,padding:4},children:c.map(e=>(0,E.jsx)(`button`,{type:`button`,onClick:()=>{o(e.id),M(null)},role:`menuitemradio`,"aria-checked":a===e.id,style:{display:`flex`,alignItems:`center`,width:`100%`,height:34,padding:`0 10px`,border:`none`,borderRadius:4,background:a===e.id?`var(--bg-selected)`:`transparent`,color:`var(--text)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-base)`,transition:`background 0.1s`},className:a===e.id?void 0:`hover-shift`,children:(0,E.jsx)(`span`,{children:e.label})},e.id))}),j===`fontSize`&&(0,E.jsxs)(`div`,{role:`menu`,"aria-label":s(`theme.fontSize`),style:{background:`var(--bg-panel)`,border:`1px solid var(--border)`,padding:`10px 12px 12px`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,fontSize:`var(--text-base)`,color:`var(--text-muted)`,marginBottom:8},children:[(0,E.jsx)(`span`,{children:s(`theme.fontSize`)}),(0,E.jsxs)(`span`,{style:{fontFamily:`var(--font-mono)`,color:`var(--text)`,fontWeight:600},children:[Math.round(k*100),`%`]})]}),(0,E.jsx)(`input`,{type:`range`,min:.85,max:1.3,step:.05,value:k,onChange:e=>A(Number(e.target.value)),"aria-label":s(`theme.fontSize`),style:{width:`100%`,accentColor:`var(--accent)`,cursor:`pointer`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,fontSize:`var(--text-xs)`,color:`var(--text-dim)`,marginTop:4},children:[(0,E.jsx)(`span`,{children:`85%`}),(0,E.jsx)(`span`,{children:`130%`})]})]})]}),(0,E.jsxs)(br,{tabs:Zt,activeTabId:Ge?fq:Nt?pq:Ke?mq(Ke.filePath):dq,leftExtra:nn,rightExtra:an,onSelectTab:e=>{if(e===`widgets`){Pt(!0),Ve(null);return}Pt(!1),Ve(e===`chat`?null:e)},onCloseTab:tt,tabBarRef:bt,overlay:(0,E.jsxs)(E.Fragment,{children:[de===`validating`&&(0,E.jsxs)(`div`,{role:`status`,style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:8,padding:24,color:`var(--text-muted)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,color:`var(--text)`},children:s(`workspace.opening`)}),(0,E.jsx)(`div`,{style:{maxWidth:`min(720px, 100%)`,overflowWrap:`anywhere`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`},children:n.requestedCwd})]}),de===`error`&&(0,E.jsxs)(`div`,{role:`alert`,style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:8,padding:24,color:`var(--text-muted)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,color:`var(--status-error)`},children:s(`workspace.unable`)}),(0,E.jsx)(`div`,{style:{maxWidth:`min(720px, 100%)`,overflowWrap:`anywhere`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`},children:n.requestedCwd}),(0,E.jsx)(`div`,{style:{maxWidth:720,fontSize:`var(--text-base)`},children:me})]}),Xt&&(ue?(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-muted)`,fontSize:`var(--text-2xl)`},children:s(`workspace.selectSession`)}):(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,userSelect:`none`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,fontStyle:`italic`,color:`var(--accent)`},children:`Pi Web`}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:s(`workspace.selectWorkspace`)})]}))]}),children:[(0,E.jsx)(vr,{id:fq,testId:`config-tab-pane`,children:(0,E.jsx)(lq,{section:Ue,onSectionChange:We,cwd:te,sessionId:ee?.id??null,onClose:$e,onOpenFile:Ye,sidebarWidth:ht.width,onSidebarWidthChange:ht.setWidth,widgetPanelWidth:_t.width,onWidgetPanelWidthChange:_t.setWidth,modelConfigFocus:Je,defaultThinkingLevel:f,onDefaultThinkingLevelChange:m,compaction:h,onCompactionChange:e=>Rt({firstPaint:{compaction:e}}),retry:g,onRetryChange:e=>Rt({firstPaint:{retry:e}}),defaultProjectTrust:_,onDefaultProjectTrustChange:v,subagents:y,onSubagentsChange:e=>Rt({firstPaint:{subagents:{defaultModel:e.defaultModel||void 0,defaultThinking:e.defaultThinking||void 0}}})})}),(0,E.jsx)(vr,{id:Ke?mq(Ke.filePath):`file:`,testId:`file-tab-pane`,children:Ke&&(0,E.jsx)(v9,{filePath:Ke.filePath,cwd:ue??void 0,sourceSessionId:Ke.sourceSessionId,gitRefreshKey:R,initialDisplayMode:Ke.initialDisplayMode,onMentionLines:Jt,onSaved:()=>oe(e=>e+1),onOpenFile:e=>Ye(e,hG(e),{sourceSessionId:Ke.sourceSessionId})})}),(0,E.jsx)(vr,{id:dq,keepAlive:!0,testId:`chat-tab-pane`,scroll:`hidden`,activeWhen:I,children:(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,display:`flex`,flexDirection:`column`,overflow:`hidden`},children:(0,E.jsx)(N7,{session:ee,newSessionCwd:F,onAgentEnd:Oe,onSessionCreated:De,onSessionForked:Ae,modelsRefreshKey:z,onOpenModelConfig:Ze,chatInputRef:yt,onOpenFile:st,onSessionRenamed:ke,windowTitleBase:Qt,toolbarExtra:rn,closedWidgetKeys:It,onCloseWidget:Lt,onExtensionWidgetsChange:Bt,onExtensionDialogChange:e=>{Se.current=e}},ie)})}),(0,E.jsx)(vr,{id:pq,keepAlive:!0,testId:`widgets-tab-pane`,zIndex:1,activeWhen:I,children:(0,E.jsx)(bte,{geometries:S,messages:w,onAddMessage:T,onRemoveMessage:D,onUpdateMessage:O,widgets:Ft,closedKeys:It,onReopen:zt})})]})]}),Gt&&(0,E.jsx)(qi,{label:`${s(`layout.resizeWidgetPanel`)}: ${s(`layout.resizeHint`)}`,wrapperStyle:{display:`flex`,flex:`0 0 0`,width:0},children:(0,E.jsx)(`div`,{..._t.separatorProps,"aria-controls":`widget-panel`,className:`panel-resize-handle widget-panel-resize-handle${_t.isResizing?` is-resizing`:``}`,"data-resize-handle":`widget-panel`})}),!l&&!Vt?null:(0,E.jsx)(`div`,{ref:_t.panelRef,"aria-controls":`widget-panel`,style:l?{position:`fixed`,inset:0,zIndex:250,display:`flex`,flexDirection:`column`}:{"--widget-panel-width":`${_t.width}px`,width:`var(--widget-panel-width)`,display:`flex`,flexDirection:`column`,minWidth:0,overflow:`hidden`,borderLeft:`1px solid var(--border)`,background:`var(--bg)`},children:(0,E.jsx)(yte,{cwd:ee?.cwd??F,onOpenFile:Ye,explorerRefreshKey:R,onExplorerRefresh:Le,onAtMention:Kt,onAtMentions:qt,sessionId:ee?.id??null,onOpenConfig:e=>Xe(e)})})]}),_e&&te&&(0,E.jsx)(Ree,{cwd:te,busy:ye,error:be,onCancel:()=>{ye||ve(!1)},onConfirm:()=>void Pe()})]})})})}),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(ate,{}),(0,E.jsx)(fte,{})]})]})}var Tte=class extends d.Component{constructor(...e){super(...e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){Ke(e,`render error`)}render(){return this.state.hasError?(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,height:`100vh`,color:`var(--text)`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`span`,{children:`⚠️`}),(0,E.jsx)(`span`,{children:`Something went wrong while rendering.`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>{this.setState({hasError:!1})},style:{border:`1px solid var(--border)`,background:`none`,color:`var(--text)`,borderRadius:6,padding:`4px 14px`,cursor:`pointer`},children:`Try again`})]}):this.props.children}};function Ete(){return(0,d.useEffect)(()=>{if(!(`serviceWorker`in navigator))return;let e=()=>{navigator.serviceWorker.register(`/sw.js?v=0.15.6`,{scope:`/`,updateViaCache:`none`}).catch(e=>{console.error(`Failed to register the Pi Web service worker:`,e)})};if(document.readyState===`complete`){e();return}return window.addEventListener(`load`,e,{once:!0}),()=>window.removeEventListener(`load`,e)},[]),null}var Dte=`piE2eFixtureDir`;function Ote(){return typeof window>`u`?null:new URL(window.location.href).searchParams.get(`piE2eFixtureDir`)}function kte(){if(typeof document>`u`)return;let e=Ote();e&&(document.cookie=`${Dte}=${encodeURIComponent(e)}; path=/; SameSite=Lax`)}async function Ate(){kte(),Rq(!0),Vq();let e=zq(`boot`),t=null;try{let n=await ye.load();e(`preferences catalog loaded`,`locale=${n.firstPaint?.locale}`);let r=n.firstPaint?.locale;(r===`en`||r===`zh-CN`)&&(t=r,document.documentElement.lang=r===`zh-CN`?`zh-CN`:`en`);let i=n.theme;if(i===`dark`?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`),i)try{localStorage.setItem(`pi-theme`,i)}catch{}}catch{}e(`root render`),window.addEventListener(`unhandledrejection`,e=>{Ke(e.reason,`unhandled promise rejection`)}),window.addEventListener(`error`,e=>{let t=(e.error instanceof Error?e.error.message:``)||e.message||``;t.includes(`ResizeObserver loop`)||t.startsWith(`Script error`)||Ke(e.error??e.message,`uncaught error`)}),(0,f.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(d.StrictMode,{children:(0,E.jsx)(Tte,{children:(0,E.jsxs)(M,{initialLocale:t,children:[(0,E.jsx)(wte,{}),(0,E.jsx)(Ete,{})]})})}))}Ate();export{l0 as a,t2 as i,R3 as n,T as o,H3 as r,i as s,A2 as t};
|
|
508
|
+
`}),(0,E.jsx)(Pn,{}),(0,E.jsxs)(`div`,{style:{display:`flex`,width:`100%`,height:`var(--app-viewport-height, 100dvh)`,paddingLeft:`env(safe-area-inset-left)`,paddingRight:`env(safe-area-inset-right)`,overflow:`hidden`,background:`var(--bg)`},children:[(0,E.jsx)(`div`,{className:`sidebar-overlay-backdrop${ut?``:` sidebar-mobile-pending`}`,onClick:()=>lt(!1),style:{position:`fixed`,inset:0,zIndex:199,background:`var(--overlay)`,opacity:+!!ct,pointerEvents:ct?`auto`:`none`,transition:`opacity 0.25s ease`}}),(0,E.jsx)(`div`,{ref:ht.panelRef,id:`session-sidebar`,className:`sidebar-container${ct?` sidebar-open`:` sidebar-closed`}${ut?``:` sidebar-mobile-pending`}${ht.isResizing?` sidebar-resizing`:``}`,"data-testid":`sidebar`,style:{"--sidebar-width":`${ht.width}px`,background:`var(--bg-panel)`,borderRight:`1px solid var(--border)`,display:`flex`,flexDirection:`column`,flexShrink:0,paddingTop:`env(safe-area-inset-top)`,paddingBottom:`env(safe-area-inset-bottom)`,zIndex:200},children:tn}),ct&&(0,E.jsx)(qi,{label:`${s(`layout.resizeSidebar`)}: ${s(`layout.resizeHint`)}`,wrapperStyle:{display:`flex`,flex:`0 0 0`,width:0},children:(0,E.jsx)(`div`,{...ht.separatorProps,"aria-controls":`session-sidebar`,className:`panel-resize-handle sidebar-resize-handle${ht.isResizing?` is-resizing`:``}`,"data-resize-handle":`sidebar`})}),(0,E.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`hidden`,minWidth:0},children:[j&&Dt&&(0,E.jsxs)(`div`,{onMouseEnter:Et,onMouseLeave:Tt,style:{position:`fixed`,top:Dt.top,left:Dt.left,width:Dt.width,maxHeight:`calc(100dvh - ${Dt.top}px)`,overflowY:`auto`,zIndex:1500},children:[j===`language`&&(0,E.jsx)(`div`,{role:`menu`,"aria-label":s(`common.language`),style:{background:`var(--bg-panel)`,border:`1px solid var(--border)`,overflow:`hidden`,padding:4},children:c.map(e=>(0,E.jsx)(`button`,{type:`button`,onClick:()=>{o(e.id),M(null)},role:`menuitemradio`,"aria-checked":a===e.id,style:{display:`flex`,alignItems:`center`,width:`100%`,height:34,padding:`0 10px`,border:`none`,borderRadius:4,background:a===e.id?`var(--bg-selected)`:`transparent`,color:`var(--text)`,cursor:`pointer`,textAlign:`left`,fontSize:`var(--text-base)`,transition:`background 0.1s`},className:a===e.id?void 0:`hover-shift`,children:(0,E.jsx)(`span`,{children:e.label})},e.id))}),j===`fontSize`&&(0,E.jsxs)(`div`,{role:`menu`,"aria-label":s(`theme.fontSize`),style:{background:`var(--bg-panel)`,border:`1px solid var(--border)`,padding:`10px 12px 12px`},children:[(0,E.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,fontSize:`var(--text-base)`,color:`var(--text-muted)`,marginBottom:8},children:[(0,E.jsx)(`span`,{children:s(`theme.fontSize`)}),(0,E.jsxs)(`span`,{style:{fontFamily:`var(--font-mono)`,color:`var(--text)`,fontWeight:600},children:[Math.round(k*100),`%`]})]}),(0,E.jsx)(`input`,{type:`range`,min:.85,max:1.3,step:.05,value:k,onChange:e=>A(Number(e.target.value)),"aria-label":s(`theme.fontSize`),style:{width:`100%`,accentColor:`var(--accent)`,cursor:`pointer`}}),(0,E.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,fontSize:`var(--text-xs)`,color:`var(--text-dim)`,marginTop:4},children:[(0,E.jsx)(`span`,{children:`85%`}),(0,E.jsx)(`span`,{children:`130%`})]})]})]}),(0,E.jsxs)(br,{tabs:Zt,activeTabId:Ge?fq:Nt?pq:Ke?mq(Ke.filePath):dq,leftExtra:nn,rightExtra:an,onSelectTab:e=>{if(e===`widgets`){Pt(!0),Ve(null);return}Pt(!1),Ve(e===`chat`?null:e)},onCloseTab:tt,tabBarRef:bt,overlay:(0,E.jsxs)(E.Fragment,{children:[de===`validating`&&(0,E.jsxs)(`div`,{role:`status`,style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:8,padding:24,color:`var(--text-muted)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,color:`var(--text)`},children:s(`workspace.opening`)}),(0,E.jsx)(`div`,{style:{maxWidth:`min(720px, 100%)`,overflowWrap:`anywhere`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`},children:n.requestedCwd})]}),de===`error`&&(0,E.jsxs)(`div`,{role:`alert`,style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:8,padding:24,color:`var(--text-muted)`,textAlign:`center`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-xl)`,color:`var(--status-error)`},children:s(`workspace.unable`)}),(0,E.jsx)(`div`,{style:{maxWidth:`min(720px, 100%)`,overflowWrap:`anywhere`,fontFamily:`var(--font-mono)`,fontSize:`var(--text-base)`},children:n.requestedCwd}),(0,E.jsx)(`div`,{style:{maxWidth:720,fontSize:`var(--text-base)`},children:me})]}),Xt&&(ue?(0,E.jsx)(`div`,{style:{height:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`var(--text-muted)`,fontSize:`var(--text-2xl)`},children:s(`workspace.selectSession`)}):(0,E.jsxs)(`div`,{style:{height:`100%`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,userSelect:`none`},children:[(0,E.jsx)(`div`,{style:{fontSize:`var(--text-6xl)`,fontWeight:700,fontStyle:`italic`,color:`var(--accent)`},children:`Pi Web`}),(0,E.jsx)(`div`,{style:{fontSize:`var(--text-base)`,color:`var(--text-muted)`},children:s(`workspace.selectWorkspace`)})]}))]}),children:[(0,E.jsx)(vr,{id:fq,testId:`config-tab-pane`,children:(0,E.jsx)(lq,{section:Ue,onSectionChange:We,cwd:te,sessionId:ee?.id??null,onClose:$e,onOpenFile:Ye,sidebarWidth:ht.width,onSidebarWidthChange:ht.setWidth,widgetPanelWidth:_t.width,onWidgetPanelWidthChange:_t.setWidth,modelConfigFocus:Je,defaultThinkingLevel:f,onDefaultThinkingLevelChange:m,compaction:h,onCompactionChange:e=>Rt({firstPaint:{compaction:e}}),retry:g,onRetryChange:e=>Rt({firstPaint:{retry:e}}),defaultProjectTrust:_,onDefaultProjectTrustChange:v,subagents:y,onSubagentsChange:e=>Rt({firstPaint:{subagents:{defaultModel:e.defaultModel||void 0,defaultThinking:e.defaultThinking||void 0}}})})}),(0,E.jsx)(vr,{id:Ke?mq(Ke.filePath):`file:`,testId:`file-tab-pane`,children:Ke&&(0,E.jsx)(v9,{filePath:Ke.filePath,cwd:ue??void 0,sourceSessionId:Ke.sourceSessionId,gitRefreshKey:R,initialDisplayMode:Ke.initialDisplayMode,onMentionLines:Jt,onSaved:()=>oe(e=>e+1),onOpenFile:e=>Ye(e,hG(e),{sourceSessionId:Ke.sourceSessionId})})}),(0,E.jsx)(vr,{id:dq,keepAlive:!0,testId:`chat-tab-pane`,scroll:`hidden`,activeWhen:I,children:(0,E.jsx)(`div`,{style:{flex:1,minHeight:0,display:`flex`,flexDirection:`column`,overflow:`hidden`},children:(0,E.jsx)(N7,{session:ee,newSessionCwd:F,onAgentEnd:Oe,onSessionCreated:De,onSessionForked:Ae,modelsRefreshKey:z,onOpenModelConfig:Ze,chatInputRef:yt,onOpenFile:st,onSessionRenamed:ke,windowTitleBase:Qt,toolbarExtra:rn,closedWidgetKeys:It,onCloseWidget:Lt,onExtensionWidgetsChange:Bt,onExtensionDialogChange:e=>{Se.current=e}},ie)})}),(0,E.jsx)(vr,{id:pq,keepAlive:!0,testId:`widgets-tab-pane`,zIndex:1,activeWhen:I,children:(0,E.jsx)(bte,{geometries:S,messages:w,onAddMessage:T,onRemoveMessage:D,onUpdateMessage:O,widgets:Ft,closedKeys:It,onReopen:zt})})]})]}),Gt&&(0,E.jsx)(qi,{label:`${s(`layout.resizeWidgetPanel`)}: ${s(`layout.resizeHint`)}`,wrapperStyle:{display:`flex`,flex:`0 0 0`,width:0},children:(0,E.jsx)(`div`,{..._t.separatorProps,"aria-controls":`widget-panel`,className:`panel-resize-handle widget-panel-resize-handle${_t.isResizing?` is-resizing`:``}`,"data-resize-handle":`widget-panel`})}),!l&&!Vt?null:(0,E.jsx)(`div`,{ref:_t.panelRef,"aria-controls":`widget-panel`,style:l?{position:`fixed`,inset:0,zIndex:250,display:`flex`,flexDirection:`column`}:{"--widget-panel-width":`${_t.width}px`,width:`var(--widget-panel-width)`,display:`flex`,flexDirection:`column`,minWidth:0,overflow:`hidden`,borderLeft:`1px solid var(--border)`,background:`var(--bg)`},children:(0,E.jsx)(yte,{cwd:ee?.cwd??F,onOpenFile:Ye,explorerRefreshKey:R,onExplorerRefresh:Le,onAtMention:Kt,onAtMentions:qt,sessionId:ee?.id??null,onOpenConfig:e=>Xe(e)})})]}),_e&&te&&(0,E.jsx)(Ree,{cwd:te,busy:ye,error:be,onCancel:()=>{ye||ve(!1)},onConfirm:()=>void Pe()})]})})})}),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(ate,{}),(0,E.jsx)(fte,{})]})]})}var Tte=class extends d.Component{constructor(...e){super(...e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){Ke(e,`render error`)}render(){return this.state.hasError?(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:12,height:`100vh`,color:`var(--text)`,fontSize:`var(--text-base)`},children:[(0,E.jsx)(`span`,{children:`⚠️`}),(0,E.jsx)(`span`,{children:`Something went wrong while rendering.`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>{this.setState({hasError:!1})},style:{border:`1px solid var(--border)`,background:`none`,color:`var(--text)`,borderRadius:6,padding:`4px 14px`,cursor:`pointer`},children:`Try again`})]}):this.props.children}};function Ete(){return(0,d.useEffect)(()=>{if(!(`serviceWorker`in navigator))return;let e=()=>{navigator.serviceWorker.register(`/sw.js?v=0.15.7`,{scope:`/`,updateViaCache:`none`}).catch(e=>{console.error(`Failed to register the Pi Web service worker:`,e)})};if(document.readyState===`complete`){e();return}return window.addEventListener(`load`,e,{once:!0}),()=>window.removeEventListener(`load`,e)},[]),null}var Dte=`piE2eFixtureDir`;function Ote(){return typeof window>`u`?null:new URL(window.location.href).searchParams.get(`piE2eFixtureDir`)}function kte(){if(typeof document>`u`)return;let e=Ote();e&&(document.cookie=`${Dte}=${encodeURIComponent(e)}; path=/; SameSite=Lax`)}async function Ate(){kte(),Rq(!0),Vq();let e=zq(`boot`),t=null;try{let n=await ye.load();e(`preferences catalog loaded`,`locale=${n.firstPaint?.locale}`);let r=n.firstPaint?.locale;(r===`en`||r===`zh-CN`)&&(t=r,document.documentElement.lang=r===`zh-CN`?`zh-CN`:`en`);let i=n.theme;if(i===`dark`?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`),i)try{localStorage.setItem(`pi-theme`,i)}catch{}}catch{}e(`root render`),window.addEventListener(`unhandledrejection`,e=>{Ke(e.reason,`unhandled promise rejection`)}),window.addEventListener(`error`,e=>{let t=(e.error instanceof Error?e.error.message:``)||e.message||``;t.includes(`ResizeObserver loop`)||t.startsWith(`Script error`)||Ke(e.error??e.message,`uncaught error`)}),(0,f.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(d.StrictMode,{children:(0,E.jsx)(Tte,{children:(0,E.jsxs)(M,{initialLocale:t,children:[(0,E.jsx)(wte,{}),(0,E.jsx)(Ete,{})]})})}))}Ate();export{l0 as a,t2 as i,R3 as n,T as o,H3 as r,i as s,A2 as t};
|