@evandu/super-pi 0.1.176 → 0.1.178

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/bin/super-pi.js +152 -6
  2. package/dist/client/.super-pi-client-sources.json +3 -3
  3. package/dist/client/assets/{CodeMirrorEditor-DwtVhvhP.js → CodeMirrorEditor-BenB0qCl.js} +2 -2
  4. package/dist/client/assets/{dist-B5HaTMDn.js → dist-9SgjXHKI.js} +1 -1
  5. package/dist/client/assets/{dist-DUlq1w0J.js → dist-B7qg204Z.js} +1 -1
  6. package/dist/client/assets/{dist-aLwW7rgW.js → dist-BBqymG_O.js} +1 -1
  7. package/dist/client/assets/{dist-BfwhoJ2c.js → dist-BEhZCgAe.js} +1 -1
  8. package/dist/client/assets/{dist-CnQpZpXf.js → dist-BTbcZiCW.js} +1 -1
  9. package/dist/client/assets/{dist-CaVt9IMZ.js → dist-BWYKkV9J.js} +1 -1
  10. package/dist/client/assets/{dist-Oz3xTF4n.js → dist-BfRyxOfA.js} +1 -1
  11. package/dist/client/assets/{dist-bRSb7mNW.js → dist-BgVPFmiW.js} +1 -1
  12. package/dist/client/assets/{dist-rsaX54pd.js → dist-Bm5z1I13.js} +1 -1
  13. package/dist/client/assets/{dist-DKu5ZQPe.js → dist-BondndXn.js} +1 -1
  14. package/dist/client/assets/{dist-DjKLhP2P.js → dist-BphpuegD.js} +1 -1
  15. package/dist/client/assets/{dist-G3kXm5bB.js → dist-Bqa4C7ia.js} +1 -1
  16. package/dist/client/assets/{dist-BvjjidDY.js → dist-C-XFV2Lh.js} +1 -1
  17. package/dist/client/assets/{dist-ddEYIZIm.js → dist-CAqvv7Ol.js} +1 -1
  18. package/dist/client/assets/{dist-Bs2J7cm7.js → dist-CP2zo9EH.js} +1 -1
  19. package/dist/client/assets/{dist-C_3vxg18.js → dist-D1W6DFkl.js} +1 -1
  20. package/dist/client/assets/{dist-EJoljryk.js → dist-D754rN4L.js} +1 -1
  21. package/dist/client/assets/{dist-Ce50Y3kx.js → dist-DRcKCYFV.js} +1 -1
  22. package/dist/client/assets/{dist-CxcCl9nU.js → dist-DsYkcVVD.js} +1 -1
  23. package/dist/client/assets/{dist-gOkylN4I.js → dist-Dy29IXwY.js} +1 -1
  24. package/dist/client/assets/{dist-LjIserDZ.js → dist-DynAZB38.js} +1 -1
  25. package/dist/client/assets/{dist-CHLXZD6Z.js → dist-fJbqoI_z.js} +1 -1
  26. package/dist/client/assets/{index-ZnFnQvel.js → index-D5fhfow-.js} +4 -4
  27. package/dist/client/index.html +1 -1
  28. package/dist/server/application/run-service.js +5 -0
  29. package/dist/server/command-handler.js +17 -2
  30. package/dist/server/http-server.js +18 -2
  31. package/dist/server/index.js +18 -5
  32. package/dist/server/update.d.ts +14 -0
  33. package/dist/server/update.js +32 -2
  34. package/package.json +5 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-ddEYIZIm.js","assets/dist-C_3vxg18.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-CAqvv7Ol.js","assets/dist-D1W6DFkl.js"])))=>i.map(i=>d[i]);
2
2
  var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(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 u=o((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.for(`react.view_transition`),m=Symbol.iterator;function h(e){return typeof e!=`object`||!e?null:(e=m&&e[m]||e[`@@iterator`],typeof e==`function`?e:null)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,v={};function y(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}y.prototype.isReactComponent={},y.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`)},y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function b(){}b.prototype=y.prototype;function x(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}var S=x.prototype=new b;S.constructor=x,_(S,y.prototype),S.isPureReactComponent=!0;var C=Array.isArray;function w(){}var T={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function D(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function O(e,t){return D(e.type,t,e.props)}function k(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function A(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var j=/\/+/g;function M(e,t){return typeof e==`object`&&e&&e.key!=null?A(``+e.key):t.toString(36)}function N(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(w,w):(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 P(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,P(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+M(e,0):a,C(o)?(i=``,c!=null&&(i=c.replace(j,`$&/`)+`/`),P(o,r,i,``,function(e){return e})):o!=null&&(k(o)&&(o=O(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(j,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(C(e))for(var u=0;u<e.length;u++)a=e[u],s=l+M(a,u),c+=P(a,r,i,s,o);else if(u=h(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+M(a,u++),c+=P(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return P(N(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 F(e,t,n){if(e==null)return e;var r=[],i=0;return P(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ee(e){if(e._status===-1){var t=e._result,n=t();n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t,n.status===void 0&&(n.status=`fulfilled`,n.value=t))},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t,n.status===void 0&&(n.status=`rejected`,n.reason=t))}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var te=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)};function ne(e){var t=T.T,n={};n.types=t===null?null:t.types,T.T=n;try{var r=e(),i=T.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(w,te)}catch(e){te(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),T.T=t}}function re(e){var t=T.T;if(t!==null){var n=t.types;n===null?t.types=[e]:n.indexOf(e)===-1&&n.push(e)}else ne(re.bind(null,e))}var I={map:F,forEach:function(e,t,n){F(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return F(e,function(){t++}),t},toArray:function(e){return F(e,function(e){return e})||[]},only:function(e){if(!k(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=I,e.Component=y,e.Fragment=r,e.Profiler=a,e.PureComponent=x,e.StrictMode=i,e.Suspense=l,e.ViewTransition=p,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=T,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return T.H.useMemoCache(e)}},e.addTransitionType=re,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=_({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!E.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 D(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)E.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 D(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=k,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=ne,e.unstable_useCacheRefresh=function(){return T.H.useCacheRefresh()},e.use=function(e){return T.H.use(e)},e.useActionState=function(e,t,n){return T.H.useActionState(e,t,n)},e.useCallback=function(e,t){return T.H.useCallback(e,t)},e.useContext=function(e){return T.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return T.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return T.H.useEffect(e,t)},e.useEffectEvent=function(e){return T.H.useEffectEvent(e)},e.useId=function(){return T.H.useId()},e.useImperativeHandle=function(e,t,n){return T.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return T.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return T.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return T.H.useMemo(e,t)},e.useOptimistic=function(e,t){return T.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return T.H.useReducer(e,t,n)},e.useRef=function(e){return T.H.useRef(e)},e.useState=function(e){return T.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return T.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return T.H.useTransition()},e.version=`19.3.1`})),d=o(((e,t)=>{t.exports=u()})),f=o((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}}}})),p=o(((e,t)=>{t.exports=f()})),m=o((e=>{var t=d();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 i={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},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(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=i,e.browser=function(e){return{$$typeof:o,_reason:e}},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 c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.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,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,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=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.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=u(n,t.crossOrigin);i.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=u(t.as,t.crossOrigin);i.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,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.1`})),h=o(((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=m()})),g=o((e=>{var t=p(),n=d(),r=h();function i(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 a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(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 c(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 l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}function m(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&m(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function g(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function _(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function v(e){var t=[null,null],n=g(e);return n===null||y(t,e,n.child,{foundSelf:!1}),t}function y(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&y(e,t,n.child,r))return!0;n=n.sibling}return!1}function b(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var x=null,S=null;function C(e,t,n){return e===n||e===t&&(x=e,!0)}function w(e,t,n){return e===n?(S=e,!1):e===t&&(S!==null&&(x=e),!0)}function T(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function E(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var D=Object.assign,O=Symbol.for(`react.element`),k=Symbol.for(`react.transitional.element`),A=Symbol.for(`react.portal`),j=Symbol.for(`react.fragment`),M=Symbol.for(`react.strict_mode`),N=Symbol.for(`react.profiler`),P=Symbol.for(`react.consumer`),F=Symbol.for(`react.context`),ee=Symbol.for(`react.forward_ref`),te=Symbol.for(`react.suspense`),ne=Symbol.for(`react.suspense_list`),re=Symbol.for(`react.memo`),I=Symbol.for(`react.lazy`),ie=Symbol.for(`react.activity`),ae=Symbol.for(`react.legacy_hidden`),oe=Symbol.for(`react.memo_cache_sentinel`),se=Symbol.for(`react.view_transition`),ce=Symbol.for(`react.recoverable`),le=Symbol.iterator;function ue(e){return typeof e!=`object`||!e?null:(e=le&&e[le]||e[`@@iterator`],typeof e==`function`?e:null)}var de=Symbol.for(`react.client.reference`);function fe(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===de?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case j:return`Fragment`;case N:return`Profiler`;case M:return`StrictMode`;case te:return`Suspense`;case ne:return`SuspenseList`;case ie:return`Activity`;case se:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case A:return`Portal`;case F:return e.displayName||`Context`;case P:return(e._context.displayName||`Context`)+`.Consumer`;case ee:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case re:return t=e.displayName||null,t===null?fe(e.type)||`Memo`:t;case I:t=e._payload,e=e._init;try{return fe(e(t))}catch{}}return null}var pe=Array.isArray,L=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,me=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,he={pending:!1,data:null,method:null,action:null},ge=[],_e=-1;function ve(e){return{current:e}}function ye(e){0>_e||(e.current=ge[_e],ge[_e]=null,_e--)}function be(e,t){_e++,ge[_e]=e.current,e.current=t}var xe=ve(null),Se=ve(null),Ce=ve(null),we=ve(null);function Te(e,t){switch(be(Ce,t),be(Se,e),be(xe,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?hp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=hp(t),e=gp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ye(xe),be(xe,e)}function Ee(){ye(xe),ye(Se),ye(Ce)}function De(e){var t=e.memoizedState;t!==null&&(fh._currentValue=t.memoizedState,be(we,e)),t=xe.current;var n=gp(t,e.type);t!==n&&(be(Se,e),be(xe,n))}function Oe(e){Se.current===e&&(ye(xe),ye(Se)),we.current===e&&(ye(we),fh._currentValue=he)}var ke,Ae;function je(e){if(ke===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ke=t&&t[1]||``,Ae=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+ke+e+Ae}var Me=!1;function Ne(e,t){if(!e||Me)return``;Me=!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}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}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(`
@@ -45,8 +45,8 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
45
45
  `)))}return{node:{type:`list`,ordered:n,start:n?Number(r[2]):1,items:a},next:o}}function dm(e){let t=e.trim();t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&!t.endsWith(`\\|`)&&(t=t.slice(0,-1));let n=[],r=``;for(let e=0;e<t.length;e+=1)t[e]===`\\`&&t[e+1]===`|`?(r+=`|`,e+=1):t[e]===`|`?(n.push(r.trim()),r=``):r+=t[e];return n.push(r.trim()),n}function fm(e){let t=e.startsWith(`:`),n=e.endsWith(`:`);return t&&n?`center`:n?`right`:t?`left`:null}function pm(e,t){let n=e.slice(0,t);for(;n.length<t;)n.push(``);return n}var mm={alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,varepsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,vartheta:`ϑ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,pi:`π`,varpi:`ϖ`,rho:`ρ`,varrho:`ϱ`,sigma:`σ`,varsigma:`ς`,tau:`τ`,upsilon:`υ`,phi:`φ`,varphi:`ϕ`,chi:`χ`,psi:`ψ`,omega:`ω`,Gamma:`Γ`,Delta:`Δ`,Theta:`Θ`,Lambda:`Λ`,Xi:`Ξ`,Pi:`Π`,Sigma:`Σ`,Upsilon:`Υ`,Phi:`Φ`,Psi:`Ψ`,Omega:`Ω`},hm={times:`×`,div:`÷`,pm:`±`,mp:`∓`,cdot:`·`,ast:`∗`,star:`⋆`,circ:`∘`,bullet:`∙`,leq:`≤`,le:`≤`,geq:`≥`,ge:`≥`,neq:`≠`,ne:`≠`,approx:`≈`,sim:`∼`,simeq:`≃`,equiv:`≡`,propto:`∝`,ll:`≪`,gg:`≫`,in:`∈`,notin:`∉`,ni:`∋`,subset:`⊂`,subseteq:`⊆`,supset:`⊃`,supseteq:`⊇`,cup:`∪`,cap:`∩`,setminus:`∖`,emptyset:`∅`,varnothing:`∅`,aleph:`ℵ`,hbar:`ℏ`,ell:`ℓ`,Re:`ℜ`,Im:`ℑ`,sum:`∑`,prod:`∏`,coprod:`∐`,int:`∫`,iint:`∬`,iiint:`∭`,oint:`∮`,bigcup:`⋃`,bigcap:`⋂`,to:`→`,rightarrow:`→`,leftarrow:`←`,gets:`←`,leftrightarrow:`↔`,Rightarrow:`⇒`,Leftarrow:`⇐`,Leftrightarrow:`⇔`,mapsto:`↦`,longrightarrow:`⟶`,longleftarrow:`⟵`,uparrow:`↑`,downarrow:`↓`,ldots:`…`,cdots:`⋯`,vdots:`⋮`,ddots:`⋱`,dots:`…`,therefore:`∴`,because:`∵`,angle:`∠`,triangle:`△`,perp:`⊥`,parallel:`∥`,degree:`°`,prime:`′`,lbrace:`{`,rbrace:`}`,lbrack:`[`,rbrack:`]`,langle:`⟨`,rangle:`⟩`,lfloor:`⌊`,rfloor:`⌋`,lceil:`⌈`,rceil:`⌉`,vert:`|`,Vert:`‖`,backslash:`\\`,oplus:`⊕`,ominus:`⊖`,otimes:`⊗`,oslash:`⊘`,odot:`⊙`,dagger:`†`,ddagger:`‡`,quad:` `,qquad:` `,thinspace:` `,enspace:` `,negthinspace:``},gm=new Set(`arcsin.arccos.arctan.sinh.cosh.tanh.cot.sec.csc.sin.cos.tan.log.ln.lg.exp.lim.limsup.liminf.max.min.det.dim.ker.deg.gcd.hom.arg.Pr.sup.inf`.split(`.`)),_m={C:`ℂ`,H:`ℍ`,N:`ℕ`,P:`ℙ`,Q:`ℚ`,R:`ℝ`,Z:`ℤ`},vm={B:`ℬ`,E:`ℰ`,F:`ℱ`,H:`ℋ`,I:`ℐ`,L:`ℒ`,M:`ℳ`,R:`ℛ`,e:`ℯ`,g:`ℊ`,o:`ℴ`},ym={mathbb:e=>_m[e]??e.toUpperCase(),mathcal:e=>vm[e]??e.toUpperCase(),mathscr:e=>vm[e]??e.toUpperCase()},bm=new Set([`left`,`right`,`big`,`Big`,`bigg`,`Bigg`,`bigl`,`bigr`,`Bigl`,`Bigr`,`biggl`,`biggr`,`Biggl`,`Biggr`,`middle`,`displaystyle`,`textstyle`,`scriptstyle`,`limits`,`nolimits`,`nonumber`,`notag`,`label`]),xm={hat:`^`,widehat:`^`,bar:`‾`,overline:`‾`,tilde:`~`,widetilde:`~`,vec:`→`,dot:`·`,ddot:`··`,check:`ˇ`,breve:`˘`,acute:`´`,grave:"`"},Sm=new Set([`(`,`)`,`[`,`]`,`|`,`/`,`<`,`>`]),Cm=new Set([`pmatrix`,`bmatrix`,`Bmatrix`,`vmatrix`,`Vmatrix`,`matrix`,`array`,`cases`,`aligned`,`align`,`alignat`,`split`,`gather`,`gathered`,`equation`,`smallmatrix`,`dcases`,`subarray`]);function wm(e){let t=[],n=``,r=()=>{n&&=(t.push(...Om(n)),``)},i=e=>{r(),t.push(e)};for(let a=0;a<e.length;){let o=e[a];if(o===`\\`){let t=a,r=/^\\([a-zA-Z]+|.)/.exec(e.slice(a));if(!r){n+=o,a+=1;continue}let s=r[1];if(a+=r[0].length,s===`\\`){i({type:`math-row-break`});continue}if(s===`{`||s===`}`){n+=s;continue}if(s===`,`||s===`;`||s===`:`||s===`!`||s===`&`)continue;if(s===`%`){for(;a<e.length&&e[a]!==`
46
46
  `;)a+=1;continue}if(bm.has(s))continue;if(s===`begin`){let n=zp(e,a),r=n.content,o=`\\end{${r}}`,s=e.indexOf(o,n.next),c=s===-1?e.length:s+o.length;i({type:`math-unsupported`,value:e.slice(t,c),reason:`\\begin{${r}} 不支持`}),a=c;continue}if(s===`frac`||s===`dfrac`||s===`tfrac`||s===`cfrac`){let t=Em(e,a),n=Em(e,t.next);a=n.next,i({type:`math-fraction`,numerator:wm(t.content),denominator:wm(n.content)});continue}if(s===`sqrt`){let t,n=a;if(e[n]===`[`){let r=Tm(e,n);t=wm(r.content),n=r.next}let r=Em(e,n);a=r.next,i({type:`math-root`,...t?{index:t}:{},radicand:wm(r.content)});continue}if(s===`text`||s===`mathrm`||s===`textrm`||s===`mathbf`||s===`mathit`||s===`mathsf`||s===`mathtt`||s===`operatorname`||s===`textbf`){let t=zp(e,a);a=t.next,i({type:`math-text`,value:t.content});continue}if(s in ym){let t=Em(e,a);a=t.next;let n=ym[s];i({type:`math-text`,value:[...t.content].map(n).join(``)});continue}if(s in xm){let t=Em(e,a);a=t.next,i({type:`math-text`,value:`${km(wm(t.content))}${xm[s]}`});continue}if(s in mm){i({type:`math-identifier`,value:mm[s]});continue}if(s in hm){let e=hm[s];/^\d/.test(e)?i({type:`math-number`,value:e}):/^[A-Za-z]/.test(e)?i({type:`math-text`,value:e}):i({type:`math-operator`,value:e});continue}if(gm.has(s)){i({type:`math-function`,value:s});continue}if(Cm.has(s))continue;i({type:`math-unsupported`,value:`\\${s}`,reason:`\\${s} 不支持`})}else if(o===`{`){let n=zp(e,a);t.push(...wm(n.content)),a=n.next}else if(o===`}`||o===`&`||o===`$`)a+=1;else if(o===`^`||o===`_`){r();let n=Em(e,a+1);a=n.next,Dm(t,o===`^`?`sup`:`sub`,wm(n.content))}else Sm.has(o)?(i({type:`math-text`,value:o}),a+=1):(n+=o,a+=1)}return r(),t}function Tm(e,t){let n=e.indexOf(`]`,t+1);return n===-1?{content:``,next:e.length}:{content:e.slice(t+1,n),next:n+1}}function Em(e,t){let n=e[t];if(n===void 0)return{content:``,next:t};if(n===`{`)return zp(e,t);let r=/^\\[a-zA-Z]+/.exec(e.slice(t));return r?{content:r[0],next:t+r[0].length}:{content:n,next:t+1}}function Dm(e,t,n){let r=e.pop();if(r){if(r.type===`math-script`)t===`sub`&&!r.sub?e.push({...r,sub:n}):t===`sup`&&!r.sup?e.push({...r,sup:n}):e.push(r);else if(r.type===`math-identifier`||r.type===`math-text`){let i=[...r.value],a=i.pop()??``;i.length&&e.push({type:r.type,value:i.join(``)}),e.push({type:`math-script`,base:[{type:`math-identifier`,value:a}],...t===`sub`?{sub:n}:{sup:n}})}else e.push({type:`math-script`,base:[r],...t===`sub`?{sub:n}:{sup:n}})}}function Om(e){let t=[],n=0;for(;n<e.length;){let r=e.slice(n),i=/^\d+(?:\.\d+)?/.exec(r);if(i){t.push({type:`math-number`,value:i[0]}),n+=i[0].length;continue}let a=/^[A-Za-z]+/.exec(r);if(a){t.push(gm.has(a[0])?{type:`math-function`,value:a[0]}:{type:`math-identifier`,value:a[0]}),n+=a[0].length;continue}let o=/^[,;:!.'’|()\-+=<>/*]+/.exec(r);o?(t.push({type:`math-operator`,value:o[0]}),n+=o[0].length):(t.push({type:`math-text`,value:r[0]}),n+=1)}return t.reduce((e,t)=>{let n=e[e.length-1];return n?.type===`math-operator`&&t.type===`math-operator`?n.value+=t.value:e.push({...t}),e},[])}function km(e){return e.map(e=>{switch(e.type){case`math-text`:case`math-number`:case`math-identifier`:case`math-operator`:case`math-function`:return e.value;case`math-script`:return`${km(e.base)}${e.sub?`_{${km(e.sub)}}`:``}${e.sup?`^{${km(e.sup)}}`:``}`;case`math-fraction`:return`\\frac{${km(e.numerator)}}{${km(e.denominator)}}`;case`math-root`:return`\\sqrt{${km(e.radicand)}}`;case`math-row-break`:return`\\\\`;case`math-unsupported`:return e.value;default:return``}}).join(``)}function Am({source:e}){let t=(0,V.useMemo)(()=>cm(e),[e]);return(0,H.jsx)(`div`,{className:`md`,"data-md":`1`,children:t.map((e,t)=>Nm(e,t))})}function jm({source:e}){let t=(0,V.useMemo)(()=>Xp(e),[e]);return(0,H.jsx)(`span`,{className:`md md-inline`,children:t.map((e,t)=>Fm(e,t))})}function Mm(e){return jp(e).map((e,t)=>e.kind===`plain`?(0,H.jsx)(`span`,{children:e.text},t):(0,H.jsx)(`span`,{className:`code-token-${e.kind}`,children:e.text},t))}function Nm(e,t){switch(e.type){case`paragraph`:return(0,H.jsx)(`p`,{className:`md-p`,children:e.children.map((e,t)=>Fm(e,t))},t);case`heading`:{let n=`h${Math.min(6,Math.max(1,e.level))}`;return(0,H.jsx)(n,{className:`md-h md-h${e.level}`,children:e.children.map((e,t)=>Fm(e,t))},t)}case`code-block`:return(0,H.jsx)(`pre`,{className:`md-pre`,"data-md-lang":e.lang||void 0,children:(0,H.jsx)(`code`,{className:`md-code`,children:Mm(e.value)})},t);case`list`:{let n=e.items.map((e,t)=>(0,H.jsx)(`li`,{className:`md-li`,children:e.map((e,t)=>Nm(e,t))},t));return e.ordered?(0,H.jsx)(`ol`,{className:`md-ol`,start:e.start>1?e.start:void 0,children:n},t):(0,H.jsx)(`ul`,{className:`md-ul`,children:n},t)}case`blockquote`:return(0,H.jsx)(`blockquote`,{className:`md-quote`,children:e.children.map((e,t)=>Nm(e,t))},t);case`rule`:return(0,H.jsx)(`hr`,{className:`md-rule`},t);case`table`:return(0,H.jsx)(`div`,{className:`md-table-wrap`,children:(0,H.jsxs)(`table`,{className:`md-table`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{children:e.head.map((t,n)=>(0,H.jsx)(`th`,{style:Pm(e.align[n]),children:t.map((e,t)=>Fm(e,t))},n))})}),(0,H.jsx)(`tbody`,{children:e.rows.map((t,n)=>(0,H.jsx)(`tr`,{children:t.map((t,n)=>(0,H.jsx)(`td`,{style:Pm(e.align[n]),children:t.map((e,t)=>Fm(e,t))},n))},n))})]})},t);case`math-block`:return(0,H.jsx)(Im,{source:e.source},t);default:return null}}var Pm=e=>e?{textAlign:e}:void 0;function Fm(e,t){switch(e.type){case`text`:return(0,H.jsx)(V.Fragment,{children:e.value},t);case`code`:return(0,H.jsx)(`code`,{className:`md-code-inline`,children:e.value},t);case`strong`:return(0,H.jsx)(`strong`,{className:`md-strong`,children:e.children.map((e,t)=>Fm(e,t))},t);case`em`:return(0,H.jsx)(`em`,{className:`md-em`,children:e.children.map((e,t)=>Fm(e,t))},t);case`del`:return(0,H.jsx)(`del`,{className:`md-del`,children:e.children.map((e,t)=>Fm(e,t))},t);case`break`:return(0,H.jsx)(`br`,{className:`md-break`},t);case`math`:return(0,H.jsx)(Lm,{source:e.source},t);case`link`:{let n=Fp(e.href);return n?(0,H.jsx)(`a`,{className:`md-link`,href:n,title:e.title,target:`_blank`,rel:`noopener noreferrer nofollow`,children:e.children.map((e,t)=>Fm(e,t))},t):(0,H.jsx)(V.Fragment,{children:e.children.map((e,t)=>Fm(e,t))},t)}default:return null}}function Im({source:e}){let t=(0,V.useMemo)(()=>wm(e),[e]);return(0,H.jsx)(`div`,{className:`md-math md-math-block`,"data-md-math":`block`,"data-md-math-source":e,children:t.map((e,t)=>Rm(e,t))})}function Lm({source:e}){let t=(0,V.useMemo)(()=>wm(e),[e]);return(0,H.jsx)(`span`,{className:`md-math md-math-inline`,"data-md-math":`inline`,"data-md-math-source":e,children:t.map((e,t)=>Rm(e,t))})}function Rm(e,t){switch(e.type){case`math-text`:return(0,H.jsx)(`span`,{className:`md-m-text`,children:e.value},t);case`math-number`:return(0,H.jsx)(`span`,{className:`md-m-number`,children:e.value},t);case`math-identifier`:return(0,H.jsx)(`i`,{className:`md-m-var`,children:e.value},t);case`math-operator`:return(0,H.jsx)(`span`,{className:`md-m-op`,children:e.value},t);case`math-function`:return(0,H.jsx)(`span`,{className:`md-m-fn`,children:e.value},t);case`math-row-break`:return(0,H.jsx)(`br`,{className:`md-m-rowbreak`},t);case`math-unsupported`:return(0,H.jsx)(`span`,{className:`md-m-unsupported`,"data-md-math-unsupported":`1`,title:e.reason,children:e.value},t);case`math-script`:return(0,H.jsxs)(`span`,{className:`md-m-script`,children:[(0,H.jsx)(`span`,{className:`md-m-base`,children:e.base.map((e,t)=>Rm(e,t))}),e.sup&&(0,H.jsx)(`sup`,{className:`md-m-sup`,children:e.sup.map((e,t)=>Rm(e,t))}),e.sub&&(0,H.jsx)(`sub`,{className:`md-m-sub`,children:e.sub.map((e,t)=>Rm(e,t))})]},t);case`math-fraction`:return(0,H.jsxs)(`span`,{className:`md-m-frac`,children:[(0,H.jsx)(`span`,{className:`md-m-num`,children:e.numerator.map((e,t)=>Rm(e,t))}),(0,H.jsx)(`span`,{className:`md-m-den`,children:e.denominator.map((e,t)=>Rm(e,t))})]},t);case`math-root`:return(0,H.jsxs)(`span`,{className:`md-m-root`,children:[(0,H.jsx)(`span`,{className:`md-m-radical`,children:`√`}),e.index&&(0,H.jsx)(`sup`,{className:`md-m-index`,children:e.index.map((e,t)=>Rm(e,t))}),(0,H.jsx)(`span`,{className:`md-m-body`,children:e.radicand.map((e,t)=>Rm(e,t))})]},t);default:return null}}var zm=[[`help`,`Show help`],[`model`,`Choose model`],[`settings`,`Open settings`],[`clear`,`Clear session`],[`compact`,`Compact context`],[`reload`,`Reload agents`],[`new`,`New session`],[`fork`,`Fork session`],[`resume`,`Resume session`],[`stop`,`Stop run`],[`skill`,`Workspace skill`]].map(([e,t])=>({id:e,label:t,description:t,scope:`builtin`})),Bm=e=>e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase();function Vm(e,t){let n=Bm(t.trim());return e.examples?.find(t=>Bm(t).includes(n)&&t!==e.id)??e.id}function Hm(e,t){let n=Bm(t.trim());return n?e.filter(e=>Bm(e.id).includes(n)||Bm(e.label).includes(n)||Bm(e.description).includes(n)||e.examples?.some(e=>Bm(e).includes(n))):e}function Um({query:e,anchorRect:t,command:n,workspaceId:r,promptCatalog:i,onSelect:a,onClose:o}){let[s,c]=(0,V.useState)(0),[l,u]=(0,V.useState)(zm),d=(0,V.useRef)(null),f=(0,V.useRef)([]);(0,V.useEffect)(()=>{r&&n({type:`prompt.catalog.fetch`,workspaceId:r})},[r,n]),(0,V.useEffect)(()=>{let e=!1,t=r?`/api/skills?workspaceId=${encodeURIComponent(r)}`:`/api/skills`;return fetch(t).then(e=>e.ok?e.json():void 0).then(t=>{if(e||!Array.isArray(t?.skills))return;let n=t.skills.map(e=>{let t=e.id?.startsWith(`skill:`)?e.id:`skill:${e.name}`,n=e.description?.trim()||(e.scope===`workspace`?`工作区技能`:`技能`);return{id:t,label:n,description:n,examples:[t]}});u([...zm.filter(e=>e.id!==`skill`),...n])}).catch(()=>{}),()=>{e=!0}},[r]);let p=[{id:`start`,label:`start — 打开浏览器`,description:`在浏览器中打开 Super Pi 控制台`,action:()=>n({type:`super_pi.start`})},{id:`restart`,label:`restart — 重启 Super Pi 服务`,description:`停掉并重新启动服务,加载磁盘上的新代码`,action:()=>n({type:`super_pi.restart`})},{id:`update`,label:`update — 更新 Super Pi`,description:`运行 npm install -g @evandu/super-pi 然后重启`,action:()=>n({type:`super_pi.update`})}],m=(i&&i.workspaceId===r?i.prompts:[]).map(e=>({id:e.name,label:e.description,description:e.description,argumentHint:e.argumentHint,scope:e.scope,shadowed:[...p,...l].some(t=>t.id===e.name)})),h=Hm([...p,...l,...m],e),g=h.length===0?-1:Math.min(Math.max(s,0),h.length-1),_=e=>c(t=>h.length?Math.min(Math.max(t+e,0),h.length-1):0);(0,V.useEffect)(()=>{let e=e=>{d.current?.contains(e.target)||o()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[o]),(0,V.useEffect)(()=>{c(0)},[e]),(0,V.useLayoutEffect)(()=>{g>=0&&f.current[g]?.scrollIntoView({block:`nearest`})},[g]);let v={position:`fixed`,left:Math.max(8,Math.min(t.left,window.innerWidth-360)),bottom:Math.max(8,window.innerHeight-t.top+6),zIndex:200},y=e=>{if(e.key===`Escape`)e.preventDefault(),o();else if(e.key===`ArrowDown`)e.preventDefault(),_(1);else if(e.key===`ArrowUp`)e.preventDefault(),_(-1);else if(e.key===`Home`)e.preventDefault(),c(0);else if(e.key===`End`)e.preventDefault(),c(h.length-1);else if(e.key===`Enter`){e.preventDefault();let t=h[g];if(!t)return;t.action?(t.action(),o()):a(t)}};return(0,V.useEffect)(()=>(window.addEventListener(`keydown`,y),()=>window.removeEventListener(`keydown`,y))),(0,H.jsx)(`div`,{ref:d,className:`slash-menu`,style:v,role:`listbox`,"aria-label":`斜杠命令`,children:h.length===0?(0,H.jsxs)(`div`,{className:`slash-menu-empty`,children:[`没有匹配「`,e,`」的命令`]}):h.map((e,t)=>(0,H.jsxs)(`button`,{ref:e=>{f.current[t]=e},type:`button`,role:`option`,"aria-selected":t===g,className:`slash-menu-item${t===g?` selected`:``}`,"data-slash-command":e.id,onClick:()=>{e.action?(e.action(),o()):a(e)},onMouseEnter:()=>c(t),children:[(0,H.jsxs)(`span`,{className:`slash-menu-item-id`,children:[`/`,e.id,e.argumentHint?` `+e.argumentHint:``]}),(0,H.jsx)(`span`,{className:`slash-menu-item-sep`,"aria-hidden":`true`,children:` — `}),(0,H.jsx)(`span`,{className:`slash-menu-item-label`,children:e.label}),(0,H.jsx)(`span`,{className:`slash-menu-item-scope`,"data-slash-command-scope":e.scope??`builtin`,children:e.shadowed?`Built-in command wins`:e.scope===`project`?`Project prompt`:e.scope===`user`?`User prompt`:`Pi built-in`}),e.examples?.length?(0,H.jsx)(`span`,{className:`slash-menu-item-examples`,children:e.examples.slice(0,2).join(` · `)}):null]},e.id))})}var Wm=class extends V.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[SuperPi ErrorBoundary captured error]:`,e,t)}reset=()=>{this.setState({error:null})};render(){let{error:e}=this.state;return e?this.props.fallback?this.props.fallback(e,this.reset):(0,H.jsxs)(`div`,{className:`error-boundary-card`,"data-error-boundary":`1`,children:[(0,H.jsxs)(`div`,{className:`error-boundary-head`,children:[(0,H.jsx)(`span`,{className:`error-boundary-icon`,"aria-hidden":`true`,children:`⚠️`}),(0,H.jsx)(`strong`,{children:`视图渲染遇到异常`})]}),(0,H.jsx)(`p`,{className:`error-boundary-msg`,children:e.message||`未知组件错误`}),(0,H.jsx)(`button`,{type:`button`,className:`error-boundary-retry`,onClick:this.reset,children:`重试`})]}):this.props.children}};function Gm(){}Gm.prototype={diff:function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=n.callback;typeof n==`function`&&(r=n,n={}),this.options=n;var i=this;function a(e){return r?(setTimeout(function(){r(void 0,e)},0),!0):e}e=this.castInput(e),t=this.castInput(t),e=this.removeEmpty(this.tokenize(e)),t=this.removeEmpty(this.tokenize(t));var o=t.length,s=e.length,c=1,l=o+s;n.maxEditLength&&(l=Math.min(l,n.maxEditLength));var u=n.timeout??1/0,d=Date.now()+u,f=[{oldPos:-1,lastComponent:void 0}],p=this.extractCommon(f[0],t,e,0);if(f[0].oldPos+1>=s&&p+1>=o)return a([{value:this.join(t),count:t.length}]);var m=-1/0,h=1/0;function g(){for(var n=Math.max(m,-c);n<=Math.min(h,c);n+=2){var r=void 0,l=f[n-1],u=f[n+1];l&&(f[n-1]=void 0);var d=!1;if(u){var g=u.oldPos-n;d=u&&0<=g&&g<o}var _=l&&l.oldPos+1<s;if(!d&&!_)f[n]=void 0;else{if(r=!_||d&&l.oldPos+1<u.oldPos?i.addToPath(u,!0,void 0,0):i.addToPath(l,void 0,!0,1),p=i.extractCommon(r,t,e,n),r.oldPos+1>=s&&p+1>=o)return a(Km(i,r.lastComponent,t,e,i.useLongestToken));f[n]=r,r.oldPos+1>=s&&(h=Math.min(h,n-1)),p+1>=o&&(m=Math.max(m,n+1))}}c++}if(r)(function e(){setTimeout(function(){if(c>l||Date.now()>d)return r();g()||e()},0)})();else for(;c<=l&&Date.now()<=d;){var _=g();if(_)return _}},addToPath:function(e,t,n,r){var i=e.lastComponent;return i&&i.added===t&&i.removed===n?{oldPos:e.oldPos+r,lastComponent:{count:i.count+1,added:t,removed:n,previousComponent:i.previousComponent}}:{oldPos:e.oldPos+r,lastComponent:{count:1,added:t,removed:n,previousComponent:i}}},extractCommon:function(e,t,n,r){for(var i=t.length,a=n.length,o=e.oldPos,s=o-r,c=0;s+1<i&&o+1<a&&this.equals(t[s+1],n[o+1]);)s++,o++,c++;return c&&(e.lastComponent={count:c,previousComponent:e.lastComponent}),e.oldPos=o,s},equals:function(e,t){return this.options.comparator?this.options.comparator(e,t):e===t||this.options.ignoreCase&&e.toLowerCase()===t.toLowerCase()},removeEmpty:function(e){for(var t=[],n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t},castInput:function(e){return e},tokenize:function(e){return e.split(``)},join:function(e){return e.join(``)}};function Km(e,t,n,r,i){for(var a=[],o;t;)a.push(t),o=t.previousComponent,delete t.previousComponent,t=o;a.reverse();for(var s=0,c=a.length,l=0,u=0;s<c;s++){var d=a[s];if(!d.removed){if(!d.added&&i){var f=n.slice(l,l+d.count);f=f.map(function(e,t){var n=r[u+t];return n.length>e.length?n:e}),d.value=e.join(f)}else d.value=e.join(n.slice(l,l+d.count));l+=d.count,d.added||(u+=d.count)}else if(d.value=e.join(r.slice(u,u+d.count)),u+=d.count,s&&a[s-1].added){var p=a[s-1];a[s-1]=a[s],a[s]=p}}var m=a[c-1];return c>1&&typeof m.value==`string`&&(m.added||m.removed)&&e.equals(``,m.value)&&(a[c-2].value+=m.value,a.pop()),a}new Gm;var qm=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,Jm=/\S/,Ym=new Gm;Ym.equals=function(e,t){return this.options.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e===t||this.options.ignoreWhitespace&&!Jm.test(e)&&!Jm.test(t)},Ym.tokenize=function(e){for(var t=e.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),n=0;n<t.length-1;n++)!t[n+1]&&t[n+2]&&qm.test(t[n])&&qm.test(t[n+2])&&(t[n]+=t[n+2],t.splice(n+1,2),n--);return t};var Xm=new Gm;Xm.tokenize=function(e){this.options.stripTrailingCr&&(e=e.replace(/\r\n/g,`
47
47
  `));var t=[],n=e.split(/(\n|\r\n)/);n[n.length-1]||n.pop();for(var r=0;r<n.length;r++){var i=n[r];r%2&&!this.options.newlineIsToken?t[t.length-1]+=i:(this.options.ignoreWhitespace&&(i=i.trim()),t.push(i))}return t};function Zm(e,t,n){return Xm.diff(e,t,n)}var Qm=new Gm;Qm.tokenize=function(e){return e.split(/(\S.+?[.!?])(?=\s+|$)/)};var $m=new Gm;$m.tokenize=function(e){return e.split(/([{}:;,]|\s+)/)};function eh(e){"@babel/helpers - typeof";return eh=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},eh(e)}var th=Object.prototype.toString,nh=new Gm;nh.useLongestToken=!0,nh.tokenize=Xm.tokenize,nh.castInput=function(e){var t=this.options,n=t.undefinedReplacement,r=t.stringifyReplacer,i=r===void 0?function(e,t){return t===void 0?n:t}:r;return typeof e==`string`?e:JSON.stringify(rh(e,null,null,i),i,` `)},nh.equals=function(e,t){return Gm.prototype.equals.call(nh,e.replace(/,([\r\n])/g,`$1`),t.replace(/,([\r\n])/g,`$1`))};function rh(e,t,n,r,i){t||=[],n||=[],r&&(e=r(i,e));for(var a=0;a<t.length;a+=1)if(t[a]===e)return n[a];var o;if(th.call(e)===`[object Array]`){for(t.push(e),o=Array(e.length),n.push(o),a=0;a<e.length;a+=1)o[a]=rh(e[a],t,n,r,i);return t.pop(),n.pop(),o}if(e&&e.toJSON&&(e=e.toJSON()),eh(e)===`object`&&e!==null){t.push(e),o={},n.push(o);var s=[],c;for(c in e)e.hasOwnProperty(c)&&s.push(c);for(s.sort(),a=0;a<s.length;a+=1)c=s[a],o[c]=rh(e[c],t,n,r,c);t.pop(),n.pop()}else o=e;return o}var ih=new Gm;ih.tokenize=function(e){return e.slice()},ih.join=ih.removeEmpty=function(e){return e};function ah(e,t){let n=Zm(e??``,t??``),r=[],i=0,a=0,o=1,s=1;for(let e of n){let t=e.value.split(`
48
- `),n=t.length>0&&t[t.length-1]===``;n&&t.pop();for(let c=0;c<t.length;c+=1){let l=t[c],u=c===t.length-1&&!n;e.added?(r.push({kind:`added`,text:l,newLine:s,noNewline:u}),s+=1,i+=1):e.removed?(r.push({kind:`removed`,text:l,oldLine:o,noNewline:u}),o+=1,a+=1):(r.push({kind:`same`,text:l,oldLine:o,newLine:s,noNewline:u}),o+=1,s+=1)}}return{lines:r,added:i,removed:a,identical:i===0&&a===0}}function oh(e,t=3){let n=new Set;e.lines.forEach((r,i)=>{if(r.kind!==`same`)for(let r=-t;r<=t;r+=1){let t=i+r;t>=0&&t<e.lines.length&&n.add(t)}});let r=[],i=0,a=!1;return e.lines.forEach((e,t)=>{n.has(t)?(a&&=(r.push({kind:`fold`,text:`⋯ 省略未改动的行`}),!1),r.push(e)):a||(a=!0,i+=1)}),a&&r.push({kind:`fold`,text:`⋯ 省略未改动的行`}),{lines:r,folded:i}}function sh(e){return Array.isArray?Array.isArray(e):_h(e)===`[object Array]`}function ch(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function lh(e){return e==null?``:ch(e)}function uh(e){return typeof e==`string`}function dh(e){return typeof e==`number`}function fh(e){return e===!0||e===!1||mh(e)&&_h(e)==`[object Boolean]`}function ph(e){return typeof e==`object`}function mh(e){return ph(e)&&e!==null}function hh(e){return e!=null}function gh(e){return!e.trim().length}function _h(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var vh=`Incorrect 'index' type`,yh=`Invalid doc index: must be a non-negative integer within the bounds of the docs array`,bh=e=>`Invalid value for key ${e}`,xh=e=>`Pattern length exceeds max of ${e}.`,Sh=e=>`Missing ${e} property in key`,Ch=e=>`Property 'weight' in key '${e}' must be a positive integer`,wh=`Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.`,Th=Object.prototype.hasOwnProperty,Eh=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Dh(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Dh(e){let t=null,n=null,r=null,i=1,a=null;if(uh(e)||sh(e))r=e,t=Oh(e),n=kh(e);else{if(!Th.call(e,`name`))throw Error(Sh(`name`));let o=e.name;if(r=o,Th.call(e,`weight`)&&e.weight!==void 0&&(i=e.weight,i<=0))throw Error(Ch(kh(o)));t=Oh(o),n=kh(o),a=e.getFn??null}return{path:t,id:n,weight:i,src:r,getFn:a}}function Oh(e){return sh(e)?e:e.split(`.`)}function kh(e){return sh(e)?e.join(`.`):e}function Ah(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(hh(e)){if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!hh(s))return;if(a===t.length-1&&(uh(s)||dh(s)||fh(s)||typeof s==`bigint`))n.push(o===void 0?lh(s):{v:lh(s),i:o});else if(sh(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}}};return i(e,uh(t)?t.split(`.`):t,0),r?n:n[0]}var jh={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Mh={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Nh={location:0,threshold:.6,distance:100},Ph={useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:`any`,getFn:Ah,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},Y=Object.freeze({...Mh,...jh,...Nh,...Ph});function Fh(e){return e>=9&&e<=13||e===32||e===160}function Ih(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=0,a=!1;for(let e=0;e<t.length;e++)Fh(t.charCodeAt(e))?a=!1:a||=(i++,!0);if(i===0&&(i=1),n.has(i))return n.get(i);let o=Math.round(r/i**(.5*e))/r;return n.set(i,o),o},clear(){n.clear()}}}var Lh=class{constructor({getFn:e=Y.getFn,fieldNormWeight:t=Y.fieldNormWeight}={}){this.norm=Ih(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;let e=this.docs.length;this.records=Array(e);let t=0;if(uh(this.docs[0]))for(let n=0;n<e;n++){let e=this._createStringRecord(this.docs[n],n);e&&(this.records[t++]=e)}else for(let n=0;n<e;n++)this.records[t++]=this._createObjectRecord(this.docs[n],n);this.records.length=t,this.norm.clear()}add(e,t){if(!Number.isInteger(t)||t<0)throw Error(yh);if(uh(e)){let n=this._createStringRecord(e,t);return n&&this.records.push(n),n}let n=this._createObjectRecord(e,t);return this.records.push(n),n}removeAt(e){if(!Number.isInteger(e)||e<0)throw Error(yh);for(let t=0,n=this.records.length;t<n;t+=1)if(this.records[t].i===e){this.records.splice(t,1);break}for(let t=0,n=this.records.length;t<n;t+=1)this.records[t].i>e&&--this.records[t].i}removeAll(e){let t=new Set;for(let n of e)Number.isInteger(n)&&n>=0&&t.add(n);if(t.size===0)return;this.records=this.records.filter(e=>!t.has(e.i));let n=Array.from(t).sort((e,t)=>e-t);for(let e of this.records){let t=0,r=n.length;for(;t<r;){let i=t+r>>>1;n[i]<e.i?t=i+1:r=i}e.i-=t}}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_createStringRecord(e,t){return!hh(e)||gh(e)?null:{v:e,i:t,n:this.norm.get(e)}}_createObjectRecord(e,t){let n={i:t,$:{}};for(let t=0,r=this.keys.length;t<r;t++){let r=this.keys[t],i=r.getFn?r.getFn(e):this.getFn(e,r.path);if(hh(i)){if(sh(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(hh(n)){if(uh(n)){if(!gh(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(hh(n.v)){let t=uh(n.v)?n.v:lh(n.v);if(!gh(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[t]=e}else if(uh(i)&&!gh(i)){let e={v:i,n:this.norm.get(i)};n.$[t]=e}}}return n}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function Rh(e,t,{getFn:n=Y.getFn,fieldNormWeight:r=Y.fieldNormWeight}={}){let i=new Lh({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Dh)),i.setSources(t),i.create(),i}function zh(e,{getFn:t=Y.getFn,fieldNormWeight:n=Y.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Lh({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Bh(e=[],t=Y.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}function Vh(e,t,n,{location:r=Y.location,distance:i=Y.distance,threshold:a=Y.threshold,findAllMatches:o=Y.findAllMatches,minMatchCharLength:s=Y.minMatchCharLength,includeMatches:c=Y.includeMatches,ignoreLocation:l=Y.ignoreLocation}={}){if(t.length>32)throw Error(xh(32));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=0,S=u+d,C=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=S;for(;r<i;)h(t,f+i)<=p?r=i:S=i,i=Math.floor((S-r)/2+r);S=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&C&&(b=h(t,i),b<=p)){if(p=b,m=i,x=t,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}if(g&&m>=0){let t=Math.min(d-1,m+u-1+x);for(let r=m;r<=t;r+=1)n[e[r]]&&(_[r]=1)}let w={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Bh(_,s);e.length?c&&(w.indices=e):w.isMatch=!1}return w}function Hh(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Uh(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Wh={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},Gh=RegExp(`[`+Object.keys(Wh).join(``)+`]`,`g`),Kh=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(Gh,e=>Wh[e]):e=>e,qh=class{constructor(e,{location:t=Y.location,threshold:n=Y.threshold,distance:r=Y.distance,includeMatches:i=Y.includeMatches,findAllMatches:a=Y.findAllMatches,minMatchCharLength:o=Y.minMatchCharLength,isCaseSensitive:s=Y.isCaseSensitive,ignoreDiacritics:c=Y.ignoreDiacritics,ignoreLocation:l=Y.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?Kh(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Hh(e),startIndex:t})},d=this.pattern.length;if(d>32){let e=0,t=d%32,n=d-t;for(;e<n;)u(this.pattern.substr(e,32),e),e+=32;if(t){let e=d-32;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?Kh(e):e,this.pattern===e){if(e.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Vh(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Uh(u)),p}},Jh=new Set([`fuzzy`,`include`]);function Yh(e){return e.startsWith(`inverse`)}var Xh=[{type:`exact`,multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:e=>({type:`exact`,search(t){let n=t===e;return{isMatch:n,score:+!n,indices:[0,e.length-1]}}})},{type:`include`,multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:e=>({type:`include`,search(t){let n=0,r,i=[],a=e.length;for(;(r=t.indexOf(e,n))>-1;)n=r+a,i.push([r,n-1]);let o=!!i.length;return{isMatch:o,score:+!o,indices:i}}})},{type:`prefix-exact`,multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:e=>({type:`prefix-exact`,search(t){let n=t.startsWith(e);return{isMatch:n,score:+!n,indices:[0,e.length-1]}}})},{type:`inverse-prefix-exact`,multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:e=>({type:`inverse-prefix-exact`,search(t){let n=!t.startsWith(e);return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`inverse-suffix-exact`,multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:e=>({type:`inverse-suffix-exact`,search(t){let n=!t.endsWith(e);return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`suffix-exact`,multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:e=>({type:`suffix-exact`,search(t){let n=t.endsWith(e);return{isMatch:n,score:+!n,indices:[t.length-e.length,t.length-1]}}})},{type:`inverse-exact`,multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:e=>({type:`inverse-exact`,search(t){let n=t.indexOf(e)===-1;return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`fuzzy`,multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(e,t={})=>{let n=new qh(e,{location:t.location??Y.location,threshold:t.threshold??Y.threshold,distance:t.distance??Y.distance,includeMatches:t.includeMatches??Y.includeMatches,findAllMatches:t.findAllMatches??Y.findAllMatches,minMatchCharLength:t.minMatchCharLength??Y.minMatchCharLength,isCaseSensitive:t.isCaseSensitive??Y.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics??Y.ignoreDiacritics,ignoreLocation:t.ignoreLocation??Y.ignoreLocation});return{type:`fuzzy`,search(e){return n.searchIn(e)}}}}],Zh=Xh.length,Qh=`\0`,$h=`|`;function eg(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function tg(e,t){let n=e.match(t);return n?n[1]:null}function ng(e,t={}){return e.replace(/\\\|/g,Qh).split($h).map(e=>{let n=eg(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<Zh;){let e=Xh[o],n=tg(i,e.multiRegex);n&&(r.push(e.create(n,t)),a=!0)}if(!a)for(o=-1;++o<Zh;){let e=Xh[o],n=tg(i,e.singleRegex);if(n){r.push(e.create(n,t));break}}}return r})}var rg=class{constructor(e,{isCaseSensitive:t=Y.isCaseSensitive,ignoreDiacritics:n=Y.ignoreDiacritics,includeMatches:r=Y.includeMatches,minMatchCharLength:i=Y.minMatchCharLength,ignoreLocation:a=Y.ignoreLocation,findAllMatches:o=Y.findAllMatches,location:s=Y.location,threshold:c=Y.threshold,distance:l=Y.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?Kh(e):e,this.pattern=e,this.query=ng(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?Kh(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l)a+=1,s+=d,Yh(r.type)&&(c=!0),n&&(Jh.has(r.type)?o.push(...u):o.push(u));else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Uh(o)),e}}return{isMatch:!1,score:1}}},ig=[];function ag(...e){ig.push(...e)}function og(e,t){for(let n=0,r=ig.length;n<r;n+=1){let r=ig[n];if(r.condition(e,t))return new r(e,t)}return new qh(e,t)}var sg={AND:`$and`,OR:`$or`},cg={PATH:`$path`,PATTERN:`$val`},lg=e=>!!(e[sg.AND]||e[sg.OR]),ug=e=>!!e[cg.PATH],dg=e=>!sh(e)&&ph(e)&&!lg(e),fg=e=>({[sg.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function pg(e,t,{auto:n=!0}={}){let r=e=>{if(uh(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=og(e,t)),r}let i=Object.keys(e),a=ug(e);if(!a&&i.length>1&&!lg(e))return r(fg(e));if(dg(e)){let r=a?e[cg.PATH]:i[0],o=a?e[cg.PATTERN]:e[r];if(!uh(o))throw Error(bh(r));let s={keyId:kh(r),pattern:o};return n&&(s.searcher=og(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];sh(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return lg(e)||(e=fg(e)),r(e)}function mg(e,{ignoreFieldNorm:t=Y.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function hg(e,{ignoreFieldNorm:t=Y.ignoreFieldNorm}){e.forEach(e=>{e.score=mg(e.matches,{ignoreFieldNorm:t})})}var gg=class{constructor(e,t){this.limit=e,this.heap=[],this.comparator=t}get size(){return this.heap.length}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):this.comparator(e,this.heap[0])<0&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(this.comparator(t[e],t[n])<=0)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&this.comparator(t[i],t[r])>0&&(r=i),a<n&&this.comparator(t[a],t[r])>0&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function _g(e){let t=[];return e.matches.forEach(e=>{if(!hh(e.indices)||!e.indices.length)return;let n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.id),e.idx>-1&&(n.refIndex=e.idx),t.push(n)}),t}function vg(e,t,{includeMatches:n=Y.includeMatches,includeScore:r=Y.includeScore}={}){return e.map(e=>{let{idx:i}=e,a={item:t[i],refIndex:i};return n&&(a.matches=_g(e)),r&&(a.score=e.score),a})}var yg=/[\p{L}\p{M}\p{N}_]+/gu,bg=new WeakSet;function xg(e){bg.has(e)||(bg.add(e),console.warn(`[Fuse] tokenize regex ${e} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Sg(e){if(typeof e==`function`){let t=!1;return n=>{let r=e(n);if(!t&&(t=!0,!Array.isArray(r)||r.some(e=>typeof e!=`string`)))throw Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(r)?`array containing non-strings`:typeof r}.`);return r}}return e instanceof RegExp?(e.global||xg(e),t=>t.match(e)||[]):e=>e.match(yg)||[]}function Cg({isCaseSensitive:e=!1,ignoreDiacritics:t=!1,tokenize:n}={}){let r=Sg(n);return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Kh(n)),r(n)}}}var wg=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=Cg({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,tokenize:t.tokenize});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new qh(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}this.combineAll=t.tokenMatch===`all`,this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0,a=0,o=this.combineAll&&!this.useMask?new Set:null;for(let s=0;s<this.termSearchers.length;s++){let c=this.termSearchers[s].searchIn(e),l=this.idfWeights[s];r+=l,c.isMatch&&(i++,n+=l*(1-c.score),c.indices&&t.push(...c.indices),this.combineAll&&(this.useMask?a|=1<<s:o.add(s)))}if(i===0)return{isMatch:!1,score:1};let s=r>0?1-n/r:0,c={isMatch:!0,score:Math.max(.001,s)};return this.options.includeMatches&&t.length&&(c.indices=Uh(t)),this.combineAll&&(this.useMask?c.matchedMask=a:c.matchedTerms=o,c.termCount=this.numTerms),c}};function Tg(e,t,n,r){let i=r.tokenize(t);if(!i.length)return;e.fieldCount++,e.docFieldCount.set(n,(e.docFieldCount.get(n)||0)+1);let a=new Set(i),o=e.docTermFieldHits.get(n);o||(o=new Map,e.docTermFieldHits.set(n,o));for(let t of a)o.set(t,(o.get(t)||0)+1),e.df.set(t,(e.df.get(t)||0)+1)}function Eg(e,t,n,r){let{i,v:a,$:o}=t;if(a!==void 0)Tg(e,a,i,r);else if(o)for(let t=0;t<n;t++){let n=o[t];if(n){if(Array.isArray(n))for(let t of n)Tg(e,t.v,i,r);else Tg(e,n.v,i,r)}}}function Dg(e,t,n){let r={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(let i of e)Eg(r,i,t,n);return r}function Og(e,t,n,r){Eg(e,t,n,r)}function kg(e,t){let n=e.docFieldCount.get(t);if(n===void 0)return;e.fieldCount-=n,e.docFieldCount.delete(t);let r=e.docTermFieldHits.get(t);if(r){for(let[t,n]of r){let r=(e.df.get(t)||0)-n;r<=0?e.df.delete(t):e.df.set(t,r)}e.docTermFieldHits.delete(t)}}function Ag(e,t){if(t.length===0)return;let n=Array.from(new Set(t)).sort((e,t)=>e-t);for(let t of n)kg(e,t);let r=e=>{let t=0,r=n.length;for(;t<r;){let i=t+r>>>1;n[i]<e?t=i+1:r=i}return e-t},i=n[0],a=new Map;for(let[t,n]of e.docFieldCount)a.set(t>i?r(t):t,n);e.docFieldCount=a;let o=new Map;for(let[t,n]of e.docTermFieldHits)o.set(t>i?r(t):t,n);e.docTermFieldHits=o}var jg=class{constructor(e,t,n){this.options={...Y,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Eh(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=og(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Lh))throw Error(vh);if(this._myIndex=t||Rh(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=Cg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Dg(this._myIndex.records,this._myIndex.keys.length,e)}this._invalidateSearcherCache()}add(e){if(!hh(e))return;this._docs.push(e);let t=this._myIndex.add(e,this._docs.length-1);if(this._invertedIndex&&t){let e=Cg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Og(this._invertedIndex,t,this._myIndex.keys.length,e)}this._invalidateSearcherCache()}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){this._invertedIndex&&Ag(this._invertedIndex,n);let e=new Set(n);this._docs=this._docs.filter((t,n)=>!e.has(n)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return t}removeAt(e){if(!Number.isInteger(e)||e<0||e>=this._docs.length)throw Error(yh);this._invertedIndex&&Ag(this._invertedIndex,[e]);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),this._invalidateSearcherCache(),t}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(e=>this._keyStore.get(e.id)||e)}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(uh(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return dh(n)&&n>-1&&(e=e.slice(0,n)),e}let c=a&&dh(n)&&n>0&&uh(e),l=o,u=(e,t)=>l(e,t)||e.idx-t.idx,d;if(c){let t=new gg(n,u);uh(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),d=t.extractSorted()}else d=uh(e)?uh(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),hg(d,{ignoreFieldNorm:s}),a&&d.sort(uh(e)?u:l),dh(n)&&n>-1&&(d=d.slice(0,n));return vg(d,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),i=this.options.useTokenSearch&&this.options.tokenMatch===`all`,{records:a}=this._myIndex,o=t?null:[];return a.forEach(({v:e,i:a,n:s})=>{if(!hh(e))return;let c=r.searchIn(e);if(c.isMatch){let r={score:c.score,value:e,norm:s,indices:c.indices};i&&(r.matchedMask=c.matchedMask,r.matchedTerms=c.matchedTerms,r.termCount=c.termCount);let l=[r];if(!i||this._coversAllTokens(l)){let r={item:e,idx:a,matches:l};t?(r.score=mg(r.matches,{ignoreFieldNorm:n}),t.insert(r)):o.push(r)}}}),o}_searchLogical(e){let t=pg(e,this.options),n=this._normalizedKeys(),r=(e,t,i)=>{if(!(`children`in e)){let{keyId:r,searcher:a}=e,o;return r===null?(o=[],n.forEach((e,n)=>{o.push(...this._findMatches({key:e,value:t[n],searcher:a}))})):o=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(t,r),searcher:a}),o&&o.length?[{idx:i,item:t,matches:o}]:[]}let{children:a,operator:o}=e,s=[];for(let e=0,n=a.length;e<n;e+=1){let n=a[e],c=r(n,t,i);if(c.length)s.push(...c);else if(o===sg.AND)return[]}return s},i=this._myIndex.records,a=new Map,o=[];return i.forEach(({$:e,i:n})=>{if(hh(e)){let i=r(t,e,n);i.length&&(a.has(n)||(a.set(n,{idx:n,item:e,matches:[]}),o.push(a.get(n))),i.forEach(({matches:e})=>{a.get(n).matches.push(...e)}))}}),o}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),i=this.options.useTokenSearch&&this.options.tokenMatch===`all`,{records:a}=this._myIndex,o=this._normalizedKeys(),s=t?null:[];return a.forEach(({$:e,i:a})=>{if(!hh(e))return;let c=[],l=!1,u=!1;if(o.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(c.push(...i),i[0].hasInverse&&(u=!0)):l=!0}),!(u&&l)&&c.length&&(!i||this._coversAllTokens(c))){let r={idx:a,item:e,matches:c};t?(r.score=mg(r.matches,{ignoreFieldNorm:n}),t.insert(r)):s.push(r)}}),s}_findMatches({key:e,value:t,searcher:n}){if(!hh(t))return[];let r=[];if(sh(t))t.forEach(({v:t,i,n:a})=>{if(!hh(t))return;let o=n.searchIn(t);if(o.isMatch){let n={score:o.score,key:e,value:t,idx:i,norm:a,indices:o.indices,hasInverse:o.hasInverse};o.termCount!==void 0&&(n.matchedMask=o.matchedMask,n.matchedTerms=o.matchedTerms,n.termCount=o.termCount),r.push(n)}});else{let{v:i,n:a}=t,o=n.searchIn(i);if(o.isMatch){let t={score:o.score,key:e,value:i,norm:a,indices:o.indices,hasInverse:o.hasInverse};o.termCount!==void 0&&(t.matchedMask=o.matchedMask,t.matchedTerms=o.matchedTerms,t.termCount=o.termCount),r.push(t)}}return r}_coversAllTokens(e){let t=e.length?e[0].termCount:void 0;if(t===void 0)return!0;if(t<=31){let n=0;for(let t=0;t<e.length;t++)n|=e[t].matchedMask||0;return n===2**t-1}let n=new Set;for(let t=0;t<e.length;t++){let r=e[t].matchedTerms;if(r)for(let e of r)n.add(e)}return n.size===t}};jg.version=`7.5.0`,jg.createIndex=Rh,jg.parseIndex=zh,jg.config=Y,jg.match=function(e,t,n){if(n&&n.useTokenSearch)throw Error(wh);return og(e,{...Y,...n}).searchIn(t)},jg.parseQuery=pg,ag(rg),ag(wg),jg.use=function(...e){e.forEach(e=>ag(e))};var Mg=jg,Ng=`modulepreload`,Pg=function(e){return`/`+e},Fg={},Ig=function(e){return e.pathname.endsWith(`.css`)},Lg=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Rg=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,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?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Pg(t,n);let r=s(t),i=Ig(r);return Lg(Fg,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Ng,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}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)})},zg=class extends Error{status;body;constructor(e,t){super(t.error||`HTTP ${e}`),this.name=`BlameApiError`,this.status=e,this.body=t}},Bg=class extends Error{constructor(){super(`Blame 请求已取消`),this.name=`BlameCancelledError`}},Vg=(e,t,n=``)=>`/api/git?workspaceId=${encodeURIComponent(e)}&op=blame&path=${encodeURIComponent(t)}${n?`&cwd=${encodeURIComponent(n)}`:``}`;async function Hg(e,t,n={}){if(n.signal?.aborted)throw new Bg;let r=n.timeoutMs??15e3,i=new AbortController,a=!1,o=setTimeout(()=>{a=!0,i.abort()},r),s=()=>i.abort();n.signal?.addEventListener(`abort`,s,{once:!0});try{let r=await fetch(Vg(e,t,n.cwd),{signal:i.signal}),a;try{a=await r.json()}catch{a=void 0}if(!r.ok){let e=a??{};throw new zg(r.status,{error:e.error||`HTTP ${r.status}`,...e.code?{code:e.code}:{}})}return a}catch(e){throw n.signal?.aborted?new Bg:a?new zg(408,{error:`请求超时:${Math.round(r/1e3)} 秒内服务端没有响应`,code:`timeout`}):e}finally{clearTimeout(o),n.signal?.removeEventListener(`abort`,s)}}var Ug=`\0`,Wg=(e,t,n)=>[e,t,n??``].join(Ug),Gg=24,Kg=new Map;function qg(e){let t=Kg.get(e);if(t)return Kg.delete(e),Kg.set(e,t),t}function Jg(e,t){for(Kg.delete(e),Kg.set(e,t);Kg.size>Gg;){let e=Kg.keys().next();if(e.done)break;Kg.delete(e.value)}}var Yg={untracked:`这个文件尚未被 Git 跟踪`,binary:`二进制文件不支持 Blame`,too_large:`文件过大,未显示 Blame`,no_head:`仓库还没有提交`,not_in_revision:`这个版本里没有这个文件`},Xg=`此工作区不是 Git 仓库`;function Zg(e){return e&&Yg[e]?{code:e,text:Yg[e]}:{code:`unsupported`,text:`这个文件暂时不能显示 Blame`}}function Qg(e){return e instanceof zg&&e.body.code===`not_a_repo`?{state:`unsupported`,note:{code:`not_a_repo`,text:Xg}}:{state:`error`,note:{code:`error`,text:`读取 Blame 失败:${e instanceof Error&&e.message?e.message:`未知错误`}`}}}var $g=`${Ug}uncommitted`;function e_(e){let t=new Map,n=0;for(let r of e.lines)t.has(r.line)||t.set(r.line,r),r.line>n&&(n=r.line);let r=[],i=null,a=0;for(let e=1;e<=n;e+=1){let n=t.get(e);if(!n){r.push({line:e,kind:`missing`,data:null}),i=null,a=e;continue}let o=n.isUncommitted?$g:n.commit??`${Ug}none`,s=o===i&&e===a+1?`continuation`:n.isUncommitted?`uncommitted`:`commit`;r.push({line:e,kind:s,data:n}),i=o,a=e}if(e.truncated)for(let t=n+1;t<=e.totalLines;t+=1)r.push({line:t,kind:`truncated`,data:null});return r}function t_(e){let t=0;for(let n of e.lines)n.line>t&&(t=n.line);return t}function n_(e){switch(e.kind){case`commit`:{let t=e.data,n=t?.shortCommit??t?.commit?.slice(0,8)??`?`,r=t?.author?.trim();return r?`${n} · ${r}`:n}case`continuation`:return`│`;case`uncommitted`:return`● 未提交`;case`missing`:return`?`;case`truncated`:return`…`;default:return``}}function r_(e){if(e.kind===`uncommitted`||e.data?.isUncommitted)return[`未提交`,`这行尚不属于任何 Git 提交`];if(e.kind===`missing`)return[`没有 Blame 信息`,`这一行没有对应的提交记录`];if(e.kind===`truncated`)return[`Blame 数据已截断`,`文件太长,只显示了前面一部分的提交信息`];let t=e.data;if(!t)return[`没有 Blame 信息`];let n=t.shortCommit??t.commit?.slice(0,8)??`未知提交`,r=t.author?.trim()||`未知作者`;return[n,t.authorEmail?`${r} <${t.authorEmail}>`:r,i_(t.date),t.summary?.trim()||`(没有提交摘要)`]}function i_(e){if(!e)return`不详`;let t=new Date(e);if(!Number.isFinite(t.getTime()))return e;let n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function a_(e){if(e.length===0)return 0;let t=1;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(t+=1);return e.charCodeAt(e.length-1)===10&&--t,t}function o_(e,t,n=!1){return!t||!t.supported?!1:n||a_(e)!==t.totalLines}var s_=new WeakMap;function c_(e){let t=s_.get(e);if(t)return t;let n={response:e,models:e_(e),covered:t_(e)};return s_.set(e,n),n}function l_(e,t){if(!e||t<1)return null;let n=e.models[t-1];return n&&n.line===t?n:null}var u_=`a1b2c3d · Author`;async function d_(){let[e,t]=await Promise.all([Rg(()=>import(`./dist-C_3vxg18.js`).then(e=>e.x),[]),Rg(()=>import(`./dist-ddEYIZIm.js`).then(e=>e.s),__vite__mapDeps([0,1]))]),n=e.StateEffect.define(),r=e.StateField.define({create:()=>null,update:(e,t)=>{for(let e of t.effects)if(e.is(n))return e.value;return e}}),i=e.StateEffect.define(),a=e.StateField.define({create:()=>null,update:(e,t)=>{for(let e of t.effects)if(e.is(i))return e.value;return e}}),o=t.GutterMarker;class s extends o{model;constructor(e){super(),this.model=e}eq(e){let t=e.model;return t?t.line===this.model.line&&t.kind===this.model.kind&&t.data?.commit===this.model.data?.commit&&t.data?.summary===this.model.data?.summary&&t.data?.author===this.model.data?.author:!1}toDOM(){let e=document.createElement(`span`);e.className=`cm-blame-marker cm-blame-${this.model.kind}`,e.setAttribute(`data-file-blame-line`,String(this.model.line)),e.setAttribute(`data-file-blame-kind`,this.model.kind),this.model.data?.commit&&e.setAttribute(`data-file-blame-commit`,this.model.data.commit);let t=r_(this.model);return e.setAttribute(`title`,t.join(`
49
- `)),e.setAttribute(`aria-label`,t.join(` · `)),e.textContent=n_(this.model),e}}class c extends o{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-blame-marker cm-blame-spacer`,e.textContent=u_,e}}let l=t.gutter({class:`cm-blame-gutter`,initialSpacer:()=>new c,lineMarker:(e,t)=>{let n=e.state.field(r);if(!n)return null;let i=e.state.doc.lineAt(t.from).number,a=l_(n,i);return new s(a??{line:i,kind:`missing`,data:null})},lineMarkerChange:e=>e.startState.field(r)!==e.state.field(r)}),u=t.ViewPlugin.fromClass(class{line=null;editorView;constructor(e){this.editorView=e,this.editorView.dom.addEventListener(`mousemove`,this.onMove),this.editorView.dom.addEventListener(`mouseleave`,this.onLeave)}destroy(){this.editorView.dom.removeEventListener(`mousemove`,this.onMove),this.editorView.dom.removeEventListener(`mouseleave`,this.onLeave)}update(e){e.startState.field(r)!==e.state.field(r)&&this.line!==null&&(this.line=null,this.editorView.dispatch({effects:i.of(null)}))}onMove=e=>{let t=this.lineAt(e);if(t===this.line)return;if(this.line=t,t===null){this.editorView.dispatch({effects:i.of(null)});return}let n=l_(this.editorView.state.field(r),t);if(!n){this.editorView.dispatch({effects:i.of(null)});return}let a=this.editorView.state.doc,o=a.line(Math.min(t,a.lines));this.editorView.dispatch({effects:i.of({pos:o.from,above:!0,create:()=>({dom:f_(n)})})})};onLeave=()=>{this.line=null,this.editorView.dispatch({effects:i.of(null)})};lineAt(e){let t=e.target,n=t?.closest?.(`[data-file-blame-line]`);if(n){let e=Number(n.getAttribute(`data-file-blame-line`));return Number.isInteger(e)&&e>0?e:null}if(t?.closest?.(`.cm-blame-gutter`))return null;let r=this.editorView.posAtCoords({x:e.clientX,y:e.clientY});return r==null?null:this.editorView.state.doc.lineAt(r).number}});return{field:r,setBlame:n,base:[r,a,t.showTooltip.from(a),u],gutter:l}}function f_(e){let t=document.createElement(`div`);t.className=`cm-blame-tooltip`,t.setAttribute(`data-file-blame-tooltip`,`1`),t.setAttribute(`data-file-blame-kind`,e.kind),e.data?.commit&&t.setAttribute(`data-file-blame-commit`,e.data.commit);for(let n of r_(e)){let e=document.createElement(`div`);e.className=`cm-blame-tooltip-row`,e.textContent=n,t.appendChild(e)}return t}var p_=4e3,m_=(0,V.lazy)(()=>Rg(()=>import(`./CodeMirrorEditor-DwtVhvhP.js`).then(e=>({default:e.CodeMirrorEditor})),[])),h_=class extends Error{status;body;constructor(e,t){super(t.error||`HTTP ${e}`),this.status=e,this.body=t,this.name=`ApiError`}},g_=15e3,__=e=>new h_(408,{error:`请求超时:${g_/1e3} 秒内服务端没有响应`,code:`timeout`,details:{path:e}});async function v_(e,t){let n=new AbortController,r=setTimeout(()=>n.abort(),g_);try{let r=await fetch(e,{...t,signal:n.signal}),i;try{i=await r.json()}catch{i=void 0}if(!r.ok)throw new h_(r.status,i??{error:`HTTP ${r.status}`});return i}catch(t){throw n.signal.aborted?__(e):t}finally{clearTimeout(r)}}var y_=e=>e instanceof h_?e:new h_(0,{error:e instanceof Error?e.message:`读取失败`}),b_=e=>encodeURIComponent(e),x_=e=>e?`&cwd=${b_(e)}`:``,S_=(e,t,n)=>`/api/files?workspaceId=${b_(e)}&path=${b_(t)}${x_(n)}`,C_=(e,t,n)=>`/api/file?workspaceId=${b_(e)}&path=${b_(t)}${x_(n)}`,w_=(e,t,n)=>`/api/file?workspaceId=${b_(e)}&path=${b_(t)}&meta=1${x_(n)}`,T_=(e,t,n)=>`/api/files?workspaceId=${b_(e)}&q=${b_(t)}${x_(n)}`,E_=e=>e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`,D_=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?``:new Date(e).toLocaleTimeString(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})};function O_({workspaceId:e,entryPath:t,name:n,listings:r,expanded:i,toggle:a,loadDirectory:o,openPaths:s,changedDirs:c,changedPaths:l,onOpen:u,depth:d}){let f=r[t],p=i.has(t);return(0,V.useEffect)(()=>{p&&f===void 0&&o(t)},[p,t,f,o]),(0,H.jsxs)(`li`,{className:`file-node`,"data-file-dir":t,"data-file-dir-changed":c.has(t)?`1`:`0`,children:[(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-dir`,"data-file-dir-toggle":t,"aria-expanded":p,style:{paddingLeft:`${8+d*13}px`},title:c.has(t)?`${t} 里有 agent 改过的文件`:t,onClick:()=>a(t),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`,children:p?`▾`:`▸`}),(0,H.jsx)(cp,{category:`folder`}),(0,H.jsx)(`span`,{className:`file-name`,children:n}),c.has(t)&&(0,H.jsx)(`span`,{className:`file-badge file-badge-changed`,"data-file-dir-changed-badge":t,title:`里面有 agent 改过的文件`,children:`✎`})]}),p&&(0,H.jsx)(`ul`,{className:`file-children`,children:f===void 0?(0,H.jsx)(`li`,{className:`file-row-loading`,"data-file-loading":t,children:`读取中…`}):`error`in f?(0,H.jsx)(`li`,{className:`file-row-error`,"data-file-error":t,title:np(f.error.message),children:tp(f.error.message,`这个目录读取失败。`)}):f.entries.length===0?(0,H.jsx)(`li`,{className:`file-row-empty`,"data-file-empty":t,children:`空目录`}):(0,H.jsxs)(H.Fragment,{children:[f.truncated&&(0,H.jsx)(`li`,{className:`file-row-empty`,"data-file-truncated":t,children:`条目过多,只显示前一部分`}),f.entries.map(t=>t.kind===`directory`?(0,H.jsx)(O_,{workspaceId:e,entryPath:t.path,name:t.name,listings:r,expanded:i,toggle:a,loadDirectory:o,openPaths:s,changedDirs:c,changedPaths:l,onOpen:u,depth:d+1},t.path):(0,H.jsx)(k_,{entry:t,depth:d+1,openPaths:s,changedPaths:l,onOpen:u},t.path))]})})]})}function k_({entry:e,depth:t,openPaths:n,changedPaths:r,onOpen:i}){if(e.kind===`symlink`)return(0,H.jsx)(`li`,{className:`file-node`,"data-file-entry":e.path,"data-file-outside":e.path,children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,disabled:!0,title:`${e.path} 是一个指向 workspace 之外的符号链接,不能打开`,style:{paddingLeft:`${8+t*13}px`},children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`file-name`,children:e.name}),(0,H.jsx)(`span`,{className:`file-badge`,"data-file-outside-badge":`1`,children:`外部链接`})]})});let a=n.has(e.path),o=r.has(e.path);return(0,H.jsx)(`li`,{className:`file-node`,"data-file-entry":e.path,"data-file-row-open":a?`1`:`0`,"data-file-row-changed":o?`1`:`0`,children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,"data-file-open":e.path,disabled:!e.text,title:e.text?o?`${e.path}(agent 改过这个文件,点击查看改动)`:a?`${e.path}(已经打开,点击切换到它)`:e.path:`${e.name} 是二进制文件,无法以文本打开`,style:{paddingLeft:`${8+t*13}px`},onClick:()=>i(e),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(cp,{path:e.path}),(0,H.jsx)(`span`,{className:`file-name`,children:e.name}),a&&(0,H.jsx)(`span`,{className:`file-open-mark`,"data-file-open-mark":e.path,title:`已经打开`,"aria-label":`已经打开`,children:`●`}),o&&(0,H.jsx)(`span`,{className:`file-badge file-badge-changed`,"data-file-changed":e.path,title:`agent 改过这个文件`,children:`✎ 已改`}),e.document&&(0,H.jsx)(`span`,{className:`file-badge`,"data-file-document":`1`,"aria-label":`文档文件`,children:`文档`}),!e.text&&!e.document&&(0,H.jsx)(`span`,{className:`file-badge`,"data-file-binary":`1`,"aria-label":`不支持的文件类型`,children:`不支持`})]})})}function A_({file:e,state:t,message:n,external:r,jumpToLine:i,onChange:a,onSave:o,onReload:s,onOverwrite:c,workspaceId:l,cwd:u=``}){let[d,f]=(0,V.useState)(!0),p=(0,V.useRef)(null),[m,h]=(0,V.useState)({}),[g,_]=(0,V.useState)(null),v=(0,V.useRef)(0),y=m[e.path]===!0&&!!l,b=l?u?`${l}:${u}`:l:``;(0,V.useEffect)(()=>{let t=++v.current;if(!y||!l){_(null);return}let n=new AbortController,i=Wg(b,e.path,e.etag),a=r?void 0:qg(i);if(a)_({state:a.supported?`ready`:`unsupported`,response:a,path:e.path,workspaceId:b,note:a.supported?null:Zg(a.reason)});else return _({state:`loading`,response:null,path:e.path,workspaceId:b,note:null}),Hg(l,e.path,{signal:n.signal,cwd:u}).then(n=>{t===v.current&&(r||Jg(i,n),_({state:n.supported?`ready`:`unsupported`,response:n,path:e.path,workspaceId:b,note:n.supported?null:Zg(n.reason)}))}).catch(n=>{if(t!==v.current||n instanceof Bg)return;let r=Qg(n);_({state:r.state,response:null,path:e.path,workspaceId:b,note:r.note})}),()=>{n.abort()}},[y,l,u,b,e.path,e.etag,r]);let x=g&&g.path===e.path&&g.workspaceId===b?g:null,S=y?x?.state??`loading`:`off`,C=S===`ready`&&o_(e.content,x?.response??null,e.dirty||r),w=[];x?.note&&w.push(x.note),S===`ready`&&x?.response?.truncated&&w.push({code:`truncated`,text:`Blame 数据已截断,只显示了前面一部分(共 ${x.response.totalLines} 行)`}),C&&w.push({code:`stale`,text:`内容已改动,Blame 对应的是磁盘上的版本`});let T=S===`loading`?`⌛ Blame`:S===`ready`?`✓ Blame`:S===`off`?`Blame`:`! Blame`;(0,V.useEffect)(()=>{i&&f(!1)},[e.path,i]),(0,V.useEffect)(()=>{let e=p.current;if(!i||!e)return;let t=Math.min(i.line,e.value.split(`
48
+ `),n=t.length>0&&t[t.length-1]===``;n&&t.pop();for(let c=0;c<t.length;c+=1){let l=t[c],u=c===t.length-1&&!n;e.added?(r.push({kind:`added`,text:l,newLine:s,noNewline:u}),s+=1,i+=1):e.removed?(r.push({kind:`removed`,text:l,oldLine:o,noNewline:u}),o+=1,a+=1):(r.push({kind:`same`,text:l,oldLine:o,newLine:s,noNewline:u}),o+=1,s+=1)}}return{lines:r,added:i,removed:a,identical:i===0&&a===0}}function oh(e,t=3){let n=new Set;e.lines.forEach((r,i)=>{if(r.kind!==`same`)for(let r=-t;r<=t;r+=1){let t=i+r;t>=0&&t<e.lines.length&&n.add(t)}});let r=[],i=0,a=!1;return e.lines.forEach((e,t)=>{n.has(t)?(a&&=(r.push({kind:`fold`,text:`⋯ 省略未改动的行`}),!1),r.push(e)):a||(a=!0,i+=1)}),a&&r.push({kind:`fold`,text:`⋯ 省略未改动的行`}),{lines:r,folded:i}}function sh(e){return Array.isArray?Array.isArray(e):_h(e)===`[object Array]`}function ch(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function lh(e){return e==null?``:ch(e)}function uh(e){return typeof e==`string`}function dh(e){return typeof e==`number`}function fh(e){return e===!0||e===!1||mh(e)&&_h(e)==`[object Boolean]`}function ph(e){return typeof e==`object`}function mh(e){return ph(e)&&e!==null}function hh(e){return e!=null}function gh(e){return!e.trim().length}function _h(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var vh=`Incorrect 'index' type`,yh=`Invalid doc index: must be a non-negative integer within the bounds of the docs array`,bh=e=>`Invalid value for key ${e}`,xh=e=>`Pattern length exceeds max of ${e}.`,Sh=e=>`Missing ${e} property in key`,Ch=e=>`Property 'weight' in key '${e}' must be a positive integer`,wh=`Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.`,Th=Object.prototype.hasOwnProperty,Eh=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Dh(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Dh(e){let t=null,n=null,r=null,i=1,a=null;if(uh(e)||sh(e))r=e,t=Oh(e),n=kh(e);else{if(!Th.call(e,`name`))throw Error(Sh(`name`));let o=e.name;if(r=o,Th.call(e,`weight`)&&e.weight!==void 0&&(i=e.weight,i<=0))throw Error(Ch(kh(o)));t=Oh(o),n=kh(o),a=e.getFn??null}return{path:t,id:n,weight:i,src:r,getFn:a}}function Oh(e){return sh(e)?e:e.split(`.`)}function kh(e){return sh(e)?e.join(`.`):e}function Ah(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(hh(e)){if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!hh(s))return;if(a===t.length-1&&(uh(s)||dh(s)||fh(s)||typeof s==`bigint`))n.push(o===void 0?lh(s):{v:lh(s),i:o});else if(sh(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}}};return i(e,uh(t)?t.split(`.`):t,0),r?n:n[0]}var jh={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Mh={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Nh={location:0,threshold:.6,distance:100},Ph={useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:`any`,getFn:Ah,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},Y=Object.freeze({...Mh,...jh,...Nh,...Ph});function Fh(e){return e>=9&&e<=13||e===32||e===160}function Ih(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=0,a=!1;for(let e=0;e<t.length;e++)Fh(t.charCodeAt(e))?a=!1:a||=(i++,!0);if(i===0&&(i=1),n.has(i))return n.get(i);let o=Math.round(r/i**(.5*e))/r;return n.set(i,o),o},clear(){n.clear()}}}var Lh=class{constructor({getFn:e=Y.getFn,fieldNormWeight:t=Y.fieldNormWeight}={}){this.norm=Ih(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;let e=this.docs.length;this.records=Array(e);let t=0;if(uh(this.docs[0]))for(let n=0;n<e;n++){let e=this._createStringRecord(this.docs[n],n);e&&(this.records[t++]=e)}else for(let n=0;n<e;n++)this.records[t++]=this._createObjectRecord(this.docs[n],n);this.records.length=t,this.norm.clear()}add(e,t){if(!Number.isInteger(t)||t<0)throw Error(yh);if(uh(e)){let n=this._createStringRecord(e,t);return n&&this.records.push(n),n}let n=this._createObjectRecord(e,t);return this.records.push(n),n}removeAt(e){if(!Number.isInteger(e)||e<0)throw Error(yh);for(let t=0,n=this.records.length;t<n;t+=1)if(this.records[t].i===e){this.records.splice(t,1);break}for(let t=0,n=this.records.length;t<n;t+=1)this.records[t].i>e&&--this.records[t].i}removeAll(e){let t=new Set;for(let n of e)Number.isInteger(n)&&n>=0&&t.add(n);if(t.size===0)return;this.records=this.records.filter(e=>!t.has(e.i));let n=Array.from(t).sort((e,t)=>e-t);for(let e of this.records){let t=0,r=n.length;for(;t<r;){let i=t+r>>>1;n[i]<e.i?t=i+1:r=i}e.i-=t}}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_createStringRecord(e,t){return!hh(e)||gh(e)?null:{v:e,i:t,n:this.norm.get(e)}}_createObjectRecord(e,t){let n={i:t,$:{}};for(let t=0,r=this.keys.length;t<r;t++){let r=this.keys[t],i=r.getFn?r.getFn(e):this.getFn(e,r.path);if(hh(i)){if(sh(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(hh(n)){if(uh(n)){if(!gh(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(hh(n.v)){let t=uh(n.v)?n.v:lh(n.v);if(!gh(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[t]=e}else if(uh(i)&&!gh(i)){let e={v:i,n:this.norm.get(i)};n.$[t]=e}}}return n}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function Rh(e,t,{getFn:n=Y.getFn,fieldNormWeight:r=Y.fieldNormWeight}={}){let i=new Lh({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Dh)),i.setSources(t),i.create(),i}function zh(e,{getFn:t=Y.getFn,fieldNormWeight:n=Y.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Lh({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Bh(e=[],t=Y.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}function Vh(e,t,n,{location:r=Y.location,distance:i=Y.distance,threshold:a=Y.threshold,findAllMatches:o=Y.findAllMatches,minMatchCharLength:s=Y.minMatchCharLength,includeMatches:c=Y.includeMatches,ignoreLocation:l=Y.ignoreLocation}={}){if(t.length>32)throw Error(xh(32));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=0,S=u+d,C=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=S;for(;r<i;)h(t,f+i)<=p?r=i:S=i,i=Math.floor((S-r)/2+r);S=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&C&&(b=h(t,i),b<=p)){if(p=b,m=i,x=t,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}if(g&&m>=0){let t=Math.min(d-1,m+u-1+x);for(let r=m;r<=t;r+=1)n[e[r]]&&(_[r]=1)}let w={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Bh(_,s);e.length?c&&(w.indices=e):w.isMatch=!1}return w}function Hh(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Uh(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Wh={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},Gh=RegExp(`[`+Object.keys(Wh).join(``)+`]`,`g`),Kh=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(Gh,e=>Wh[e]):e=>e,qh=class{constructor(e,{location:t=Y.location,threshold:n=Y.threshold,distance:r=Y.distance,includeMatches:i=Y.includeMatches,findAllMatches:a=Y.findAllMatches,minMatchCharLength:o=Y.minMatchCharLength,isCaseSensitive:s=Y.isCaseSensitive,ignoreDiacritics:c=Y.ignoreDiacritics,ignoreLocation:l=Y.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?Kh(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Hh(e),startIndex:t})},d=this.pattern.length;if(d>32){let e=0,t=d%32,n=d-t;for(;e<n;)u(this.pattern.substr(e,32),e),e+=32;if(t){let e=d-32;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?Kh(e):e,this.pattern===e){if(e.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Vh(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Uh(u)),p}},Jh=new Set([`fuzzy`,`include`]);function Yh(e){return e.startsWith(`inverse`)}var Xh=[{type:`exact`,multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:e=>({type:`exact`,search(t){let n=t===e;return{isMatch:n,score:+!n,indices:[0,e.length-1]}}})},{type:`include`,multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:e=>({type:`include`,search(t){let n=0,r,i=[],a=e.length;for(;(r=t.indexOf(e,n))>-1;)n=r+a,i.push([r,n-1]);let o=!!i.length;return{isMatch:o,score:+!o,indices:i}}})},{type:`prefix-exact`,multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:e=>({type:`prefix-exact`,search(t){let n=t.startsWith(e);return{isMatch:n,score:+!n,indices:[0,e.length-1]}}})},{type:`inverse-prefix-exact`,multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:e=>({type:`inverse-prefix-exact`,search(t){let n=!t.startsWith(e);return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`inverse-suffix-exact`,multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:e=>({type:`inverse-suffix-exact`,search(t){let n=!t.endsWith(e);return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`suffix-exact`,multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:e=>({type:`suffix-exact`,search(t){let n=t.endsWith(e);return{isMatch:n,score:+!n,indices:[t.length-e.length,t.length-1]}}})},{type:`inverse-exact`,multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:e=>({type:`inverse-exact`,search(t){let n=t.indexOf(e)===-1;return{isMatch:n,score:+!n,indices:[0,t.length-1]}}})},{type:`fuzzy`,multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(e,t={})=>{let n=new qh(e,{location:t.location??Y.location,threshold:t.threshold??Y.threshold,distance:t.distance??Y.distance,includeMatches:t.includeMatches??Y.includeMatches,findAllMatches:t.findAllMatches??Y.findAllMatches,minMatchCharLength:t.minMatchCharLength??Y.minMatchCharLength,isCaseSensitive:t.isCaseSensitive??Y.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics??Y.ignoreDiacritics,ignoreLocation:t.ignoreLocation??Y.ignoreLocation});return{type:`fuzzy`,search(e){return n.searchIn(e)}}}}],Zh=Xh.length,Qh=`\0`,$h=`|`;function eg(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function tg(e,t){let n=e.match(t);return n?n[1]:null}function ng(e,t={}){return e.replace(/\\\|/g,Qh).split($h).map(e=>{let n=eg(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<Zh;){let e=Xh[o],n=tg(i,e.multiRegex);n&&(r.push(e.create(n,t)),a=!0)}if(!a)for(o=-1;++o<Zh;){let e=Xh[o],n=tg(i,e.singleRegex);if(n){r.push(e.create(n,t));break}}}return r})}var rg=class{constructor(e,{isCaseSensitive:t=Y.isCaseSensitive,ignoreDiacritics:n=Y.ignoreDiacritics,includeMatches:r=Y.includeMatches,minMatchCharLength:i=Y.minMatchCharLength,ignoreLocation:a=Y.ignoreLocation,findAllMatches:o=Y.findAllMatches,location:s=Y.location,threshold:c=Y.threshold,distance:l=Y.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?Kh(e):e,this.pattern=e,this.query=ng(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?Kh(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l)a+=1,s+=d,Yh(r.type)&&(c=!0),n&&(Jh.has(r.type)?o.push(...u):o.push(u));else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Uh(o)),e}}return{isMatch:!1,score:1}}},ig=[];function ag(...e){ig.push(...e)}function og(e,t){for(let n=0,r=ig.length;n<r;n+=1){let r=ig[n];if(r.condition(e,t))return new r(e,t)}return new qh(e,t)}var sg={AND:`$and`,OR:`$or`},cg={PATH:`$path`,PATTERN:`$val`},lg=e=>!!(e[sg.AND]||e[sg.OR]),ug=e=>!!e[cg.PATH],dg=e=>!sh(e)&&ph(e)&&!lg(e),fg=e=>({[sg.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function pg(e,t,{auto:n=!0}={}){let r=e=>{if(uh(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=og(e,t)),r}let i=Object.keys(e),a=ug(e);if(!a&&i.length>1&&!lg(e))return r(fg(e));if(dg(e)){let r=a?e[cg.PATH]:i[0],o=a?e[cg.PATTERN]:e[r];if(!uh(o))throw Error(bh(r));let s={keyId:kh(r),pattern:o};return n&&(s.searcher=og(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];sh(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return lg(e)||(e=fg(e)),r(e)}function mg(e,{ignoreFieldNorm:t=Y.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function hg(e,{ignoreFieldNorm:t=Y.ignoreFieldNorm}){e.forEach(e=>{e.score=mg(e.matches,{ignoreFieldNorm:t})})}var gg=class{constructor(e,t){this.limit=e,this.heap=[],this.comparator=t}get size(){return this.heap.length}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):this.comparator(e,this.heap[0])<0&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(this.comparator(t[e],t[n])<=0)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&this.comparator(t[i],t[r])>0&&(r=i),a<n&&this.comparator(t[a],t[r])>0&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function _g(e){let t=[];return e.matches.forEach(e=>{if(!hh(e.indices)||!e.indices.length)return;let n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.id),e.idx>-1&&(n.refIndex=e.idx),t.push(n)}),t}function vg(e,t,{includeMatches:n=Y.includeMatches,includeScore:r=Y.includeScore}={}){return e.map(e=>{let{idx:i}=e,a={item:t[i],refIndex:i};return n&&(a.matches=_g(e)),r&&(a.score=e.score),a})}var yg=/[\p{L}\p{M}\p{N}_]+/gu,bg=new WeakSet;function xg(e){bg.has(e)||(bg.add(e),console.warn(`[Fuse] tokenize regex ${e} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Sg(e){if(typeof e==`function`){let t=!1;return n=>{let r=e(n);if(!t&&(t=!0,!Array.isArray(r)||r.some(e=>typeof e!=`string`)))throw Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(r)?`array containing non-strings`:typeof r}.`);return r}}return e instanceof RegExp?(e.global||xg(e),t=>t.match(e)||[]):e=>e.match(yg)||[]}function Cg({isCaseSensitive:e=!1,ignoreDiacritics:t=!1,tokenize:n}={}){let r=Sg(n);return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Kh(n)),r(n)}}}var wg=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=Cg({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,tokenize:t.tokenize});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new qh(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}this.combineAll=t.tokenMatch===`all`,this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0,a=0,o=this.combineAll&&!this.useMask?new Set:null;for(let s=0;s<this.termSearchers.length;s++){let c=this.termSearchers[s].searchIn(e),l=this.idfWeights[s];r+=l,c.isMatch&&(i++,n+=l*(1-c.score),c.indices&&t.push(...c.indices),this.combineAll&&(this.useMask?a|=1<<s:o.add(s)))}if(i===0)return{isMatch:!1,score:1};let s=r>0?1-n/r:0,c={isMatch:!0,score:Math.max(.001,s)};return this.options.includeMatches&&t.length&&(c.indices=Uh(t)),this.combineAll&&(this.useMask?c.matchedMask=a:c.matchedTerms=o,c.termCount=this.numTerms),c}};function Tg(e,t,n,r){let i=r.tokenize(t);if(!i.length)return;e.fieldCount++,e.docFieldCount.set(n,(e.docFieldCount.get(n)||0)+1);let a=new Set(i),o=e.docTermFieldHits.get(n);o||(o=new Map,e.docTermFieldHits.set(n,o));for(let t of a)o.set(t,(o.get(t)||0)+1),e.df.set(t,(e.df.get(t)||0)+1)}function Eg(e,t,n,r){let{i,v:a,$:o}=t;if(a!==void 0)Tg(e,a,i,r);else if(o)for(let t=0;t<n;t++){let n=o[t];if(n){if(Array.isArray(n))for(let t of n)Tg(e,t.v,i,r);else Tg(e,n.v,i,r)}}}function Dg(e,t,n){let r={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(let i of e)Eg(r,i,t,n);return r}function Og(e,t,n,r){Eg(e,t,n,r)}function kg(e,t){let n=e.docFieldCount.get(t);if(n===void 0)return;e.fieldCount-=n,e.docFieldCount.delete(t);let r=e.docTermFieldHits.get(t);if(r){for(let[t,n]of r){let r=(e.df.get(t)||0)-n;r<=0?e.df.delete(t):e.df.set(t,r)}e.docTermFieldHits.delete(t)}}function Ag(e,t){if(t.length===0)return;let n=Array.from(new Set(t)).sort((e,t)=>e-t);for(let t of n)kg(e,t);let r=e=>{let t=0,r=n.length;for(;t<r;){let i=t+r>>>1;n[i]<e?t=i+1:r=i}return e-t},i=n[0],a=new Map;for(let[t,n]of e.docFieldCount)a.set(t>i?r(t):t,n);e.docFieldCount=a;let o=new Map;for(let[t,n]of e.docTermFieldHits)o.set(t>i?r(t):t,n);e.docTermFieldHits=o}var jg=class{constructor(e,t,n){this.options={...Y,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Eh(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=og(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Lh))throw Error(vh);if(this._myIndex=t||Rh(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=Cg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Dg(this._myIndex.records,this._myIndex.keys.length,e)}this._invalidateSearcherCache()}add(e){if(!hh(e))return;this._docs.push(e);let t=this._myIndex.add(e,this._docs.length-1);if(this._invertedIndex&&t){let e=Cg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Og(this._invertedIndex,t,this._myIndex.keys.length,e)}this._invalidateSearcherCache()}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){this._invertedIndex&&Ag(this._invertedIndex,n);let e=new Set(n);this._docs=this._docs.filter((t,n)=>!e.has(n)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return t}removeAt(e){if(!Number.isInteger(e)||e<0||e>=this._docs.length)throw Error(yh);this._invertedIndex&&Ag(this._invertedIndex,[e]);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),this._invalidateSearcherCache(),t}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(e=>this._keyStore.get(e.id)||e)}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(uh(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return dh(n)&&n>-1&&(e=e.slice(0,n)),e}let c=a&&dh(n)&&n>0&&uh(e),l=o,u=(e,t)=>l(e,t)||e.idx-t.idx,d;if(c){let t=new gg(n,u);uh(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),d=t.extractSorted()}else d=uh(e)?uh(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),hg(d,{ignoreFieldNorm:s}),a&&d.sort(uh(e)?u:l),dh(n)&&n>-1&&(d=d.slice(0,n));return vg(d,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),i=this.options.useTokenSearch&&this.options.tokenMatch===`all`,{records:a}=this._myIndex,o=t?null:[];return a.forEach(({v:e,i:a,n:s})=>{if(!hh(e))return;let c=r.searchIn(e);if(c.isMatch){let r={score:c.score,value:e,norm:s,indices:c.indices};i&&(r.matchedMask=c.matchedMask,r.matchedTerms=c.matchedTerms,r.termCount=c.termCount);let l=[r];if(!i||this._coversAllTokens(l)){let r={item:e,idx:a,matches:l};t?(r.score=mg(r.matches,{ignoreFieldNorm:n}),t.insert(r)):o.push(r)}}}),o}_searchLogical(e){let t=pg(e,this.options),n=this._normalizedKeys(),r=(e,t,i)=>{if(!(`children`in e)){let{keyId:r,searcher:a}=e,o;return r===null?(o=[],n.forEach((e,n)=>{o.push(...this._findMatches({key:e,value:t[n],searcher:a}))})):o=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(t,r),searcher:a}),o&&o.length?[{idx:i,item:t,matches:o}]:[]}let{children:a,operator:o}=e,s=[];for(let e=0,n=a.length;e<n;e+=1){let n=a[e],c=r(n,t,i);if(c.length)s.push(...c);else if(o===sg.AND)return[]}return s},i=this._myIndex.records,a=new Map,o=[];return i.forEach(({$:e,i:n})=>{if(hh(e)){let i=r(t,e,n);i.length&&(a.has(n)||(a.set(n,{idx:n,item:e,matches:[]}),o.push(a.get(n))),i.forEach(({matches:e})=>{a.get(n).matches.push(...e)}))}}),o}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),i=this.options.useTokenSearch&&this.options.tokenMatch===`all`,{records:a}=this._myIndex,o=this._normalizedKeys(),s=t?null:[];return a.forEach(({$:e,i:a})=>{if(!hh(e))return;let c=[],l=!1,u=!1;if(o.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(c.push(...i),i[0].hasInverse&&(u=!0)):l=!0}),!(u&&l)&&c.length&&(!i||this._coversAllTokens(c))){let r={idx:a,item:e,matches:c};t?(r.score=mg(r.matches,{ignoreFieldNorm:n}),t.insert(r)):s.push(r)}}),s}_findMatches({key:e,value:t,searcher:n}){if(!hh(t))return[];let r=[];if(sh(t))t.forEach(({v:t,i,n:a})=>{if(!hh(t))return;let o=n.searchIn(t);if(o.isMatch){let n={score:o.score,key:e,value:t,idx:i,norm:a,indices:o.indices,hasInverse:o.hasInverse};o.termCount!==void 0&&(n.matchedMask=o.matchedMask,n.matchedTerms=o.matchedTerms,n.termCount=o.termCount),r.push(n)}});else{let{v:i,n:a}=t,o=n.searchIn(i);if(o.isMatch){let t={score:o.score,key:e,value:i,norm:a,indices:o.indices,hasInverse:o.hasInverse};o.termCount!==void 0&&(t.matchedMask=o.matchedMask,t.matchedTerms=o.matchedTerms,t.termCount=o.termCount),r.push(t)}}return r}_coversAllTokens(e){let t=e.length?e[0].termCount:void 0;if(t===void 0)return!0;if(t<=31){let n=0;for(let t=0;t<e.length;t++)n|=e[t].matchedMask||0;return n===2**t-1}let n=new Set;for(let t=0;t<e.length;t++){let r=e[t].matchedTerms;if(r)for(let e of r)n.add(e)}return n.size===t}};jg.version=`7.5.0`,jg.createIndex=Rh,jg.parseIndex=zh,jg.config=Y,jg.match=function(e,t,n){if(n&&n.useTokenSearch)throw Error(wh);return og(e,{...Y,...n}).searchIn(t)},jg.parseQuery=pg,ag(rg),ag(wg),jg.use=function(...e){e.forEach(e=>ag(e))};var Mg=jg,Ng=`modulepreload`,Pg=function(e){return`/`+e},Fg={},Ig=function(e){return e.pathname.endsWith(`.css`)},Lg=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Rg=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,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?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Pg(t,n);let r=s(t),i=Ig(r);return Lg(Fg,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Ng,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}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)})},zg=class extends Error{status;body;constructor(e,t){super(t.error||`HTTP ${e}`),this.name=`BlameApiError`,this.status=e,this.body=t}},Bg=class extends Error{constructor(){super(`Blame 请求已取消`),this.name=`BlameCancelledError`}},Vg=(e,t,n=``)=>`/api/git?workspaceId=${encodeURIComponent(e)}&op=blame&path=${encodeURIComponent(t)}${n?`&cwd=${encodeURIComponent(n)}`:``}`;async function Hg(e,t,n={}){if(n.signal?.aborted)throw new Bg;let r=n.timeoutMs??15e3,i=new AbortController,a=!1,o=setTimeout(()=>{a=!0,i.abort()},r),s=()=>i.abort();n.signal?.addEventListener(`abort`,s,{once:!0});try{let r=await fetch(Vg(e,t,n.cwd),{signal:i.signal}),a;try{a=await r.json()}catch{a=void 0}if(!r.ok){let e=a??{};throw new zg(r.status,{error:e.error||`HTTP ${r.status}`,...e.code?{code:e.code}:{}})}return a}catch(e){throw n.signal?.aborted?new Bg:a?new zg(408,{error:`请求超时:${Math.round(r/1e3)} 秒内服务端没有响应`,code:`timeout`}):e}finally{clearTimeout(o),n.signal?.removeEventListener(`abort`,s)}}var Ug=`\0`,Wg=(e,t,n)=>[e,t,n??``].join(Ug),Gg=24,Kg=new Map;function qg(e){let t=Kg.get(e);if(t)return Kg.delete(e),Kg.set(e,t),t}function Jg(e,t){for(Kg.delete(e),Kg.set(e,t);Kg.size>Gg;){let e=Kg.keys().next();if(e.done)break;Kg.delete(e.value)}}var Yg={untracked:`这个文件尚未被 Git 跟踪`,binary:`二进制文件不支持 Blame`,too_large:`文件过大,未显示 Blame`,no_head:`仓库还没有提交`,not_in_revision:`这个版本里没有这个文件`},Xg=`此工作区不是 Git 仓库`;function Zg(e){return e&&Yg[e]?{code:e,text:Yg[e]}:{code:`unsupported`,text:`这个文件暂时不能显示 Blame`}}function Qg(e){return e instanceof zg&&e.body.code===`not_a_repo`?{state:`unsupported`,note:{code:`not_a_repo`,text:Xg}}:{state:`error`,note:{code:`error`,text:`读取 Blame 失败:${e instanceof Error&&e.message?e.message:`未知错误`}`}}}var $g=`${Ug}uncommitted`;function e_(e){let t=new Map,n=0;for(let r of e.lines)t.has(r.line)||t.set(r.line,r),r.line>n&&(n=r.line);let r=[],i=null,a=0;for(let e=1;e<=n;e+=1){let n=t.get(e);if(!n){r.push({line:e,kind:`missing`,data:null}),i=null,a=e;continue}let o=n.isUncommitted?$g:n.commit??`${Ug}none`,s=o===i&&e===a+1?`continuation`:n.isUncommitted?`uncommitted`:`commit`;r.push({line:e,kind:s,data:n}),i=o,a=e}if(e.truncated)for(let t=n+1;t<=e.totalLines;t+=1)r.push({line:t,kind:`truncated`,data:null});return r}function t_(e){let t=0;for(let n of e.lines)n.line>t&&(t=n.line);return t}function n_(e){switch(e.kind){case`commit`:{let t=e.data,n=t?.shortCommit??t?.commit?.slice(0,8)??`?`,r=t?.author?.trim();return r?`${n} · ${r}`:n}case`continuation`:return`│`;case`uncommitted`:return`● 未提交`;case`missing`:return`?`;case`truncated`:return`…`;default:return``}}function r_(e){if(e.kind===`uncommitted`||e.data?.isUncommitted)return[`未提交`,`这行尚不属于任何 Git 提交`];if(e.kind===`missing`)return[`没有 Blame 信息`,`这一行没有对应的提交记录`];if(e.kind===`truncated`)return[`Blame 数据已截断`,`文件太长,只显示了前面一部分的提交信息`];let t=e.data;if(!t)return[`没有 Blame 信息`];let n=t.shortCommit??t.commit?.slice(0,8)??`未知提交`,r=t.author?.trim()||`未知作者`;return[n,t.authorEmail?`${r} <${t.authorEmail}>`:r,i_(t.date),t.summary?.trim()||`(没有提交摘要)`]}function i_(e){if(!e)return`不详`;let t=new Date(e);if(!Number.isFinite(t.getTime()))return e;let n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function a_(e){if(e.length===0)return 0;let t=1;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(t+=1);return e.charCodeAt(e.length-1)===10&&--t,t}function o_(e,t,n=!1){return!t||!t.supported?!1:n||a_(e)!==t.totalLines}var s_=new WeakMap;function c_(e){let t=s_.get(e);if(t)return t;let n={response:e,models:e_(e),covered:t_(e)};return s_.set(e,n),n}function l_(e,t){if(!e||t<1)return null;let n=e.models[t-1];return n&&n.line===t?n:null}var u_=`a1b2c3d · Author`;async function d_(){let[e,t]=await Promise.all([Rg(()=>import(`./dist-D1W6DFkl.js`).then(e=>e.x),[]),Rg(()=>import(`./dist-CAqvv7Ol.js`).then(e=>e.s),__vite__mapDeps([0,1]))]),n=e.StateEffect.define(),r=e.StateField.define({create:()=>null,update:(e,t)=>{for(let e of t.effects)if(e.is(n))return e.value;return e}}),i=e.StateEffect.define(),a=e.StateField.define({create:()=>null,update:(e,t)=>{for(let e of t.effects)if(e.is(i))return e.value;return e}}),o=t.GutterMarker;class s extends o{model;constructor(e){super(),this.model=e}eq(e){let t=e.model;return t?t.line===this.model.line&&t.kind===this.model.kind&&t.data?.commit===this.model.data?.commit&&t.data?.summary===this.model.data?.summary&&t.data?.author===this.model.data?.author:!1}toDOM(){let e=document.createElement(`span`);e.className=`cm-blame-marker cm-blame-${this.model.kind}`,e.setAttribute(`data-file-blame-line`,String(this.model.line)),e.setAttribute(`data-file-blame-kind`,this.model.kind),this.model.data?.commit&&e.setAttribute(`data-file-blame-commit`,this.model.data.commit);let t=r_(this.model);return e.setAttribute(`title`,t.join(`
49
+ `)),e.setAttribute(`aria-label`,t.join(` · `)),e.textContent=n_(this.model),e}}class c extends o{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-blame-marker cm-blame-spacer`,e.textContent=u_,e}}let l=t.gutter({class:`cm-blame-gutter`,initialSpacer:()=>new c,lineMarker:(e,t)=>{let n=e.state.field(r);if(!n)return null;let i=e.state.doc.lineAt(t.from).number,a=l_(n,i);return new s(a??{line:i,kind:`missing`,data:null})},lineMarkerChange:e=>e.startState.field(r)!==e.state.field(r)}),u=t.ViewPlugin.fromClass(class{line=null;editorView;constructor(e){this.editorView=e,this.editorView.dom.addEventListener(`mousemove`,this.onMove),this.editorView.dom.addEventListener(`mouseleave`,this.onLeave)}destroy(){this.editorView.dom.removeEventListener(`mousemove`,this.onMove),this.editorView.dom.removeEventListener(`mouseleave`,this.onLeave)}update(e){e.startState.field(r)!==e.state.field(r)&&this.line!==null&&(this.line=null,this.editorView.dispatch({effects:i.of(null)}))}onMove=e=>{let t=this.lineAt(e);if(t===this.line)return;if(this.line=t,t===null){this.editorView.dispatch({effects:i.of(null)});return}let n=l_(this.editorView.state.field(r),t);if(!n){this.editorView.dispatch({effects:i.of(null)});return}let a=this.editorView.state.doc,o=a.line(Math.min(t,a.lines));this.editorView.dispatch({effects:i.of({pos:o.from,above:!0,create:()=>({dom:f_(n)})})})};onLeave=()=>{this.line=null,this.editorView.dispatch({effects:i.of(null)})};lineAt(e){let t=e.target,n=t?.closest?.(`[data-file-blame-line]`);if(n){let e=Number(n.getAttribute(`data-file-blame-line`));return Number.isInteger(e)&&e>0?e:null}if(t?.closest?.(`.cm-blame-gutter`))return null;let r=this.editorView.posAtCoords({x:e.clientX,y:e.clientY});return r==null?null:this.editorView.state.doc.lineAt(r).number}});return{field:r,setBlame:n,base:[r,a,t.showTooltip.from(a),u],gutter:l}}function f_(e){let t=document.createElement(`div`);t.className=`cm-blame-tooltip`,t.setAttribute(`data-file-blame-tooltip`,`1`),t.setAttribute(`data-file-blame-kind`,e.kind),e.data?.commit&&t.setAttribute(`data-file-blame-commit`,e.data.commit);for(let n of r_(e)){let e=document.createElement(`div`);e.className=`cm-blame-tooltip-row`,e.textContent=n,t.appendChild(e)}return t}var p_=4e3,m_=(0,V.lazy)(()=>Rg(()=>import(`./CodeMirrorEditor-BenB0qCl.js`).then(e=>({default:e.CodeMirrorEditor})),[])),h_=class extends Error{status;body;constructor(e,t){super(t.error||`HTTP ${e}`),this.status=e,this.body=t,this.name=`ApiError`}},g_=15e3,__=e=>new h_(408,{error:`请求超时:${g_/1e3} 秒内服务端没有响应`,code:`timeout`,details:{path:e}});async function v_(e,t){let n=new AbortController,r=setTimeout(()=>n.abort(),g_);try{let r=await fetch(e,{...t,signal:n.signal}),i;try{i=await r.json()}catch{i=void 0}if(!r.ok)throw new h_(r.status,i??{error:`HTTP ${r.status}`});return i}catch(t){throw n.signal.aborted?__(e):t}finally{clearTimeout(r)}}var y_=e=>e instanceof h_?e:new h_(0,{error:e instanceof Error?e.message:`读取失败`}),b_=e=>encodeURIComponent(e),x_=e=>e?`&cwd=${b_(e)}`:``,S_=(e,t,n)=>`/api/files?workspaceId=${b_(e)}&path=${b_(t)}${x_(n)}`,C_=(e,t,n)=>`/api/file?workspaceId=${b_(e)}&path=${b_(t)}${x_(n)}`,w_=(e,t,n)=>`/api/file?workspaceId=${b_(e)}&path=${b_(t)}&meta=1${x_(n)}`,T_=(e,t,n)=>`/api/files?workspaceId=${b_(e)}&q=${b_(t)}${x_(n)}`,E_=e=>e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`,D_=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?``:new Date(e).toLocaleTimeString(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})};function O_({workspaceId:e,entryPath:t,name:n,listings:r,expanded:i,toggle:a,loadDirectory:o,openPaths:s,changedDirs:c,changedPaths:l,onOpen:u,depth:d}){let f=r[t],p=i.has(t);return(0,V.useEffect)(()=>{p&&f===void 0&&o(t)},[p,t,f,o]),(0,H.jsxs)(`li`,{className:`file-node`,"data-file-dir":t,"data-file-dir-changed":c.has(t)?`1`:`0`,children:[(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-dir`,"data-file-dir-toggle":t,"aria-expanded":p,style:{paddingLeft:`${8+d*13}px`},title:c.has(t)?`${t} 里有 agent 改过的文件`:t,onClick:()=>a(t),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`,children:p?`▾`:`▸`}),(0,H.jsx)(cp,{category:`folder`}),(0,H.jsx)(`span`,{className:`file-name`,children:n}),c.has(t)&&(0,H.jsx)(`span`,{className:`file-badge file-badge-changed`,"data-file-dir-changed-badge":t,title:`里面有 agent 改过的文件`,children:`✎`})]}),p&&(0,H.jsx)(`ul`,{className:`file-children`,children:f===void 0?(0,H.jsx)(`li`,{className:`file-row-loading`,"data-file-loading":t,children:`读取中…`}):`error`in f?(0,H.jsx)(`li`,{className:`file-row-error`,"data-file-error":t,title:np(f.error.message),children:tp(f.error.message,`这个目录读取失败。`)}):f.entries.length===0?(0,H.jsx)(`li`,{className:`file-row-empty`,"data-file-empty":t,children:`空目录`}):(0,H.jsxs)(H.Fragment,{children:[f.truncated&&(0,H.jsx)(`li`,{className:`file-row-empty`,"data-file-truncated":t,children:`条目过多,只显示前一部分`}),f.entries.map(t=>t.kind===`directory`?(0,H.jsx)(O_,{workspaceId:e,entryPath:t.path,name:t.name,listings:r,expanded:i,toggle:a,loadDirectory:o,openPaths:s,changedDirs:c,changedPaths:l,onOpen:u,depth:d+1},t.path):(0,H.jsx)(k_,{entry:t,depth:d+1,openPaths:s,changedPaths:l,onOpen:u},t.path))]})})]})}function k_({entry:e,depth:t,openPaths:n,changedPaths:r,onOpen:i}){if(e.kind===`symlink`)return(0,H.jsx)(`li`,{className:`file-node`,"data-file-entry":e.path,"data-file-outside":e.path,children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,disabled:!0,title:`${e.path} 是一个指向 workspace 之外的符号链接,不能打开`,style:{paddingLeft:`${8+t*13}px`},children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`file-name`,children:e.name}),(0,H.jsx)(`span`,{className:`file-badge`,"data-file-outside-badge":`1`,children:`外部链接`})]})});let a=n.has(e.path),o=r.has(e.path);return(0,H.jsx)(`li`,{className:`file-node`,"data-file-entry":e.path,"data-file-row-open":a?`1`:`0`,"data-file-row-changed":o?`1`:`0`,children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,"data-file-open":e.path,disabled:!e.text,title:e.text?o?`${e.path}(agent 改过这个文件,点击查看改动)`:a?`${e.path}(已经打开,点击切换到它)`:e.path:`${e.name} 是二进制文件,无法以文本打开`,style:{paddingLeft:`${8+t*13}px`},onClick:()=>i(e),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(cp,{path:e.path}),(0,H.jsx)(`span`,{className:`file-name`,children:e.name}),a&&(0,H.jsx)(`span`,{className:`file-open-mark`,"data-file-open-mark":e.path,title:`已经打开`,"aria-label":`已经打开`,children:`●`}),o&&(0,H.jsx)(`span`,{className:`file-badge file-badge-changed`,"data-file-changed":e.path,title:`agent 改过这个文件`,children:`✎ 已改`}),e.document&&(0,H.jsx)(`span`,{className:`file-badge`,"data-file-document":`1`,"aria-label":`文档文件`,children:`文档`}),!e.text&&!e.document&&(0,H.jsx)(`span`,{className:`file-badge`,"data-file-binary":`1`,"aria-label":`不支持的文件类型`,children:`不支持`})]})})}function A_({file:e,state:t,message:n,external:r,jumpToLine:i,onChange:a,onSave:o,onReload:s,onOverwrite:c,workspaceId:l,cwd:u=``}){let[d,f]=(0,V.useState)(!0),p=(0,V.useRef)(null),[m,h]=(0,V.useState)({}),[g,_]=(0,V.useState)(null),v=(0,V.useRef)(0),y=m[e.path]===!0&&!!l,b=l?u?`${l}:${u}`:l:``;(0,V.useEffect)(()=>{let t=++v.current;if(!y||!l){_(null);return}let n=new AbortController,i=Wg(b,e.path,e.etag),a=r?void 0:qg(i);if(a)_({state:a.supported?`ready`:`unsupported`,response:a,path:e.path,workspaceId:b,note:a.supported?null:Zg(a.reason)});else return _({state:`loading`,response:null,path:e.path,workspaceId:b,note:null}),Hg(l,e.path,{signal:n.signal,cwd:u}).then(n=>{t===v.current&&(r||Jg(i,n),_({state:n.supported?`ready`:`unsupported`,response:n,path:e.path,workspaceId:b,note:n.supported?null:Zg(n.reason)}))}).catch(n=>{if(t!==v.current||n instanceof Bg)return;let r=Qg(n);_({state:r.state,response:null,path:e.path,workspaceId:b,note:r.note})}),()=>{n.abort()}},[y,l,u,b,e.path,e.etag,r]);let x=g&&g.path===e.path&&g.workspaceId===b?g:null,S=y?x?.state??`loading`:`off`,C=S===`ready`&&o_(e.content,x?.response??null,e.dirty||r),w=[];x?.note&&w.push(x.note),S===`ready`&&x?.response?.truncated&&w.push({code:`truncated`,text:`Blame 数据已截断,只显示了前面一部分(共 ${x.response.totalLines} 行)`}),C&&w.push({code:`stale`,text:`内容已改动,Blame 对应的是磁盘上的版本`});let T=S===`loading`?`⌛ Blame`:S===`ready`?`✓ Blame`:S===`off`?`Blame`:`! Blame`;(0,V.useEffect)(()=>{i&&f(!1)},[e.path,i]),(0,V.useEffect)(()=>{let e=p.current;if(!i||!e)return;let t=Math.min(i.line,e.value.split(`
50
50
  `).length),n=e.value.split(`
51
51
  `),r=n.slice(0,t-1).reduce((e,t)=>e+t.length+1,0);e.focus(),e.setSelectionRange(r,r+n[t-1].length);let a=parseFloat(getComputedStyle(e).lineHeight);e.scrollTop=Math.max(0,(t-1)*a-e.clientHeight/2),e.scrollLeft=0;let o=e.previousElementSibling;o instanceof HTMLElement&&(o.scrollTop=e.scrollTop,o.scrollLeft=0)},[e.path,i,d]);let E=/\.md$/i.test(e.path);return(0,H.jsxs)(`div`,{className:`file-editor`,"data-file-editor":e.path,"data-save-state":t,children:[(0,H.jsxs)(`div`,{className:`file-editor-head`,children:[(0,H.jsx)(`span`,{className:`file-editor-path`,title:e.path,children:e.path}),(0,H.jsxs)(`span`,{className:`file-editor-flags`,children:[E&&(0,H.jsx)(`button`,{type:`button`,className:`file-preview-toggle`,onClick:()=>f(e=>!e),children:d?`原文`:`预览`}),(0,H.jsx)(`button`,{type:`button`,className:`file-blame-toggle`,"data-file-blame-toggle":e.path,"data-file-blame-state":S,"aria-pressed":y,"aria-label":y?`关闭 Git Blame`:`显示 Git Blame`,onClick:()=>h(t=>({...t,[e.path]:t[e.path]!==!0})),children:T}),e.dirty&&(0,H.jsx)(`span`,{className:`file-dirty`,"data-file-dirty":`1`,children:`未保存`}),(0,H.jsx)(`button`,{type:`button`,className:`file-save`,"data-file-save":e.path,onClick:o,disabled:t===`saving`,children:t===`saving`?`保存中…`:`保存`})]})]}),w.length>0&&(0,H.jsx)(`p`,{className:`file-blame-note`,"data-file-blame-reason":w.map(e=>e.code).join(` `),role:`status`,children:w.map(e=>e.text).join(`;`)}),r&&t!==`conflict`&&(0,H.jsxs)(`div`,{className:`file-conflict`,"data-file-external":e.path,role:`alert`,children:[(0,H.jsx)(`p`,{children:`这个文件在磁盘上已经被改过了,你的修改还没有覆盖它。`}),(0,H.jsxs)(`div`,{className:`file-conflict-actions`,children:[(0,H.jsx)(`button`,{type:`button`,"data-file-reload":e.path,onClick:s,children:`丢掉我的修改,读磁盘版本`}),(0,H.jsx)(`button`,{type:`button`,"data-file-overwrite":e.path,onClick:c,children:`仍然覆盖磁盘`})]})]}),t===`conflict`&&(0,H.jsxs)(`div`,{className:`file-conflict`,"data-file-conflict":e.path,role:`alert`,children:[(0,H.jsx)(`p`,{children:`保存被拒绝:这个文件在磁盘上已经被改过了,覆盖会丢掉对方的改动。`}),(0,H.jsxs)(`div`,{className:`file-conflict-actions`,children:[(0,H.jsx)(`button`,{type:`button`,"data-file-reload":e.path,onClick:s,children:`丢掉我的修改,读磁盘版本`}),(0,H.jsx)(`button`,{type:`button`,"data-file-overwrite":e.path,onClick:c,children:`仍然覆盖磁盘`})]})]}),n&&t!==`conflict`&&!r&&(0,H.jsx)(`p`,{className:`file-editor-message file-message-${t}`,"data-file-message":t,role:`status`,children:n}),E&&d?(0,H.jsx)(`div`,{className:`file-markdown-preview`,"data-file-preview":`markdown`,children:(0,H.jsx)(Am,{source:e.content})}):(0,H.jsx)(Wm,{fallback:(t,n)=>(0,H.jsxs)(`div`,{className:`file-editor-fallback`,"data-file-editor-fallback":`1`,children:[(0,H.jsxs)(`div`,{className:`file-editor-fallback-bar`,children:[(0,H.jsxs)(`span`,{children:[`⚠️ 高级编辑器加载异常(`,t.message||`未知错误`,`),已自动降级为安全模式`]}),(0,H.jsx)(`button`,{type:`button`,onClick:n,children:`重新加载`})]}),(0,H.jsx)(`textarea`,{className:`file-textarea`,value:e.content,onChange:e=>a(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),o())}})]}),children:(0,H.jsx)(V.Suspense,{fallback:(0,H.jsx)(`div`,{className:`file-cm-wrap`,"data-file-text":e.path,"data-file-content":e.content,"data-file-selection":`0,0`,"data-file-editor-ready":`0`,children:(0,H.jsx)(`span`,{className:`file-cm-status`,"data-file-editor-loading":`1`,children:`⌛ 正在加载编辑器…`})}),children:(0,H.jsx)(m_,{path:e.path,value:e.content,onChange:a,jumpToLine:i,onSave:o,workspaceId:l,blame:y&&x&&!C?{state:x.state,response:x.response,path:x.path,workspaceId:l??``}:void 0})})})]})}function j_({line:e}){if(e.kind===`fold`)return(0,H.jsx)(`div`,{className:`file-diff-line file-diff-fold`,"data-diff-kind":`fold`,children:e.text});let t=e.kind===`added`?`+`:e.kind===`removed`?`-`:` `;return(0,H.jsxs)(`div`,{className:`file-diff-line file-diff-${e.kind}`,"data-diff-kind":e.kind,"data-diff-no-newline":e.noNewline?`1`:void 0,children:[(0,H.jsx)(`span`,{className:`file-diff-mark`,"aria-hidden":`true`,children:t}),(0,H.jsx)(`span`,{className:`file-diff-number`,"aria-hidden":`true`,children:e.oldLine??``}),(0,H.jsx)(`span`,{className:`file-diff-number`,"aria-hidden":`true`,children:e.newLine??``}),(0,H.jsx)(`span`,{className:`file-diff-text`,children:e.text}),e.noNewline&&(0,H.jsx)(`span`,{className:`file-diff-no-newline`,title:`这个版本的末尾没有换行`,children:`(末尾无换行)`})]})}function M_({diff:e,loading:t,error:n,bufferContent:r,mode:i,onMode:a}){if(t)return(0,H.jsx)(`div`,{className:`file-diff`,"data-file-diff-state":`loading`,children:(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-diff-loading":`1`,children:`正在读取差异…`})});if(n)return(0,H.jsx)(`div`,{className:`file-diff`,"data-file-diff-state":`error`,children:(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-diff-error":`1`,title:np(n),children:tp(n,`这个文件的差异读取失败。`)})});if(!e)return(0,H.jsx)(`div`,{className:`file-diff`,"data-file-diff-state":`empty`,children:(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-diff-empty":`1`,children:`没有选中的差异。`})});let o=typeof r==`string`,s=i===`buffer`&&o,c=s?e.after:e.before,l=s?r:e.after,u=s?`我未保存的修改`:e.label,d=s?`buffer`:e.baseline,f=o&&e.baseline!==`none`?(0,H.jsxs)(`span`,{className:`file-diff-switch`,"data-file-diff-switch":`1`,children:[(0,H.jsx)(`button`,{type:`button`,className:`file-diff-switch-btn${s?``:` file-diff-switch-active`}`,"data-file-diff-base":`server`,"aria-pressed":!s,onClick:()=>a(`server`),children:`agent 的改动`}),(0,H.jsx)(`button`,{type:`button`,className:`file-diff-switch-btn${s?` file-diff-switch-active`:``}`,"data-file-diff-base":`buffer`,"aria-pressed":s,onClick:()=>a(`buffer`),children:`我的修改`})]}):null;if(d===`none`)return(0,H.jsxs)(`div`,{className:`file-diff`,"data-file-diff-state":`none`,"data-file-diff-baseline":d,children:[(0,H.jsxs)(`div`,{className:`file-editor-head`,children:[(0,H.jsx)(`span`,{className:`file-editor-path`,title:e.path,children:e.path}),(0,H.jsx)(`span`,{className:`file-editor-flags`,children:f})]}),(0,H.jsx)(`p`,{className:`file-diff-nobaseline`,"data-file-diff-nobaseline":`1`,children:u})]});let p=ah(c,l),m=oh(p);return(0,H.jsxs)(`div`,{className:`file-diff`,"data-file-diff-state":`ready`,"data-file-diff-baseline":d,"data-file-diff-added":p.added,"data-file-diff-removed":p.removed,children:[(0,H.jsxs)(`div`,{className:`file-editor-head`,children:[(0,H.jsx)(`span`,{className:`file-editor-path`,title:e.path,children:e.path}),(0,H.jsxs)(`span`,{className:`file-editor-flags`,children:[f,(0,H.jsx)(`span`,{className:`file-diff-baseline`,"data-file-diff-label":`1`,children:u}),(0,H.jsxs)(`span`,{className:`file-diff-count`,"data-file-diff-count":`1`,children:[`+`,p.added,` / -`,p.removed]})]})]}),e.beforeUnknown&&!s&&(0,H.jsx)(`p`,{className:`file-diff-warning`,"data-file-diff-before-unknown":`1`,role:`status`,children:`读不到改动前的版本(文件太大或无法读取),这里只显示现在的内容。`}),e.before===null&&!e.beforeUnknown&&!s&&(0,H.jsx)(`p`,{className:`file-diff-warning`,"data-file-diff-is-new":`1`,role:`status`,children:`这个文件是新建的,下面是它的全部内容。`}),p.identical?(0,H.jsx)(`p`,{className:`file-diff-nobaseline`,"data-file-diff-identical":`1`,children:`两个版本没有区别。`}):(0,H.jsx)(`div`,{className:`file-diff-body`,"data-file-diff-body":`1`,children:m.lines.map((e,t)=>(0,H.jsx)(j_,{line:e},t))})]})}function N_({error:e}){let t=e.body.code,n=typeof e.body.details?.path==`string`?e.body.details.path:``,r=t===`workspace_missing`?`missing`:t===`timeout`?`timeout`:`failed`;return(0,H.jsxs)(`div`,{className:`rail-empty file-problem`,"data-file-root-error":`1`,"data-file-error-kind":r,role:`alert`,children:[r===`missing`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`file-problem-title`,"data-file-error-title":`1`,children:`工作区路径不存在,无法读取文件。`}),(0,H.jsx)(`p`,{className:`file-problem-hint`,children:`请确认这个路径是写错了,还是目录被移动或删除了:`}),(0,H.jsx)(`code`,{className:`file-problem-path`,"data-file-error-path":`1`,children:n||tp(e.message,`路径未知`)})]}),r===`timeout`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`file-problem-title`,"data-file-error-title":`1`,children:`读取超时,服务端没有回应。`}),(0,H.jsxs)(`p`,{className:`file-problem-hint`,children:[`已经等了 `,g_/1e3,` 秒。如果这个工作区在网络盘上,请检查它是否已连接,然后点上面的 ↻ 重试。`]})]}),r===`failed`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`file-problem-title`,"data-file-error-title":`1`,children:`读取失败。`}),(0,H.jsx)(`p`,{className:`file-problem-hint`,title:np(e.message),children:tp(e.message,`读取失败,请稍后重试。`)})]})]})}function P_(e,t=``){let n=t.trim().replaceAll(`\\`,`/`).replace(/^\/+|\/+$/g,``),r=e?n?`${e}:${n}`:e:void 0,i=(0,V.useRef)(r);i.current=r;let[a,o]=(0,V.useState)([]),[s,c]=(0,V.useState)(),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)({}),[p,m]=(0,V.useState)({}),[h,g]=(0,V.useState)({}),[_,v]=(0,V.useState)(()=>new Set),[y,b]=(0,V.useState)(``),[x,S]=(0,V.useState)(null),[C,w]=(0,V.useState)(null),[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)([]),[k,A]=(0,V.useState)(!1),[j,M]=(0,V.useState)([]),N=(0,V.useRef)(void 0),P=(0,V.useRef)(-1),F=(0,V.useRef)(!1),ee=(0,V.useCallback)(e=>{N.current?N.current.buffered.push(e):!F.current||e.version<=P.current||(P.current=e.version,O(t=>{let n=new Map(t.map(e=>[e.path,e]));for(let t of e.changed)n.set(t.path,t);for(let t of e.removed)n.delete(t);return[...n.values()]}),A(e.complete),M(e.skipped))},[]),te=(0,V.useCallback)(()=>{let e=N.current;N.current=void 0,e?.controller.abort()},[]);(0,V.useEffect)(()=>(te(),F.current=!1,P.current=-1,O([]),A(!1),M([]),te),[r,te]);let ne=(0,V.useCallback)((t=!1)=>{if(!e||!r||N.current?.scopeKey===r||!t&&F.current)return;let i={workspaceId:e,scopeKey:r,controller:new AbortController,buffered:[]};N.current=i,fetch(`/api/files/index?workspaceId=${encodeURIComponent(e)}${x_(n)}`,{signal:i.controller.signal}).then(e=>{if(!e.ok)throw Error(`文件索引请求失败(${e.status})`);return e.json()}).then(e=>{if(N.current!==i)return;let t=new Map((e.changed??[]).map(e=>[e.path,e]));for(let n of e.removed??[])t.delete(n);let n=e.version??-1,r=e.complete===!0,a=e.skipped??[];for(let e of i.buffered.sort((e,t)=>e.version-t.version))if(!(e.version<=n)){for(let n of e.changed)t.set(n.path,n);for(let n of e.removed)t.delete(n);n=e.version,r=e.complete,a=e.skipped}N.current=void 0,F.current=!0,P.current=n,O([...t.values()]),A(r),M(a)}).catch(()=>{N.current===i&&(N.current=void 0)})},[e,n,r]),[re,I]=(0,V.useState)({});(0,V.useEffect)(()=>{if(o([]),c(void 0),u(``),f({}),m({}),g({}),v(new Set),S(null),w(null),b(``),E(!1),!e)return;let t=!0;return v_(S_(e,``,n)).then(e=>{t&&g({"":e})}).catch(e=>{t&&g({"":{error:y_(e)}})}),()=>{t=!1}},[e,n,r]);let ie=(0,V.useRef)(void 0),[ae,oe]=(0,V.useState)(void 0);(0,V.useEffect)(()=>{if(!e||!r||ie.current===r)return;ie.current=r;let t=I_()[r];t&&(t.expanded.length&&v(new Set(t.expanded)),typeof t.listHeight==`number`&&S(t.listHeight),t.open.length&&(async()=>{for(let e of t.open)if(await ue({path:e,name:e.split(`/`).pop()??e,text:!0}),i.current!==r)return;t.active&&i.current===r&&(c(t.active),oe(t.active))})())},[e,n,r]),(0,V.useEffect)(()=>{if(!e||!r)return;let t=setTimeout(()=>{let e=I_();e[r]={open:a.map(e=>e.path),expanded:[..._],...s?{active:s}:{},...x===null?{}:{listHeight:x}},L_(e)},400);return()=>{clearTimeout(t)}},[e,r,a,_,s,x]);let se=(0,V.useCallback)(t=>{e&&v_(S_(e,t,n)).then(e=>{i.current===r&&g(n=>({...n,[t]:e}))}).catch(e=>{i.current===r&&g(n=>({...n,[t]:{error:y_(e)}}))})},[e,n,r]),ce=(0,V.useCallback)(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=(0,V.useCallback)(()=>{e&&(g({}),v(new Set),v_(S_(e,``,n)).then(e=>{i.current===r&&g({"":e})}).catch(e=>{i.current===r&&g({"":{error:y_(e)}})}))},[e,n,r]);(0,V.useEffect)(()=>{let t=y.trim();if(!e||!t){w(null),E(!1);return}let r=!0;E(!0);let i=setTimeout(()=>{v_(T_(e,t,n)).then(e=>{r&&(w(e),E(!1))}).catch(e=>{r&&(w({mode:`search`,query:t,hits:[],total:0,indexed:!1}),E(!1),u(`搜索失败:${e instanceof Error?e.message:`未知错误`}`))})},80);return()=>{r=!1,clearTimeout(i)}},[y,e,n]);let ue=(0,V.useCallback)(async t=>{if(e){if(t.text===!1)u(`「${t.name}」不支持以文本打开(二进制文件)。`);else if(a.some(e=>e.path===t.path))c(t.path);else{u(``);try{let a=await v_(C_(e,t.path,n));if(i.current!==r)return;o(e=>e.some(e=>e.path===t.path)?e:[...e,{path:a.path,name:t.name,content:a.content,etag:a.meta.etag,dirty:!1}]),c(a.path),m(e=>({...e,[a.path]:!1}))}catch(e){i.current===r&&u(`打不开「${t.name}」:${e instanceof Error?e.message:`未知错误`}`)}}}},[e,n,r,a]),de=(0,V.useCallback)(e=>{o(t=>{let n=t.find(t=>t.path===e);if(n?.dirty&&!window.confirm(`「${n.name}」有未保存的修改,关掉就丢了。仍然关闭?`))return t;let r=t.findIndex(t=>t.path===e),i=t.filter(t=>t.path!==e);return e===s&&c(i.length===0?void 0:i[Math.min(r,i.length-1)]?.path),i})},[s]),fe=(0,V.useCallback)((e,t)=>{o(n=>n.map(n=>n.path===e?{...n,content:t,dirty:!0}:n))},[]),pe=(0,V.useRef)(a);pe.current=a,(0,V.useEffect)(()=>{if(!e||a.length===0)return;let t=!0,r=setInterval(()=>{for(let r of pe.current.map(e=>e.path))v_(w_(e,r,n)).then(e=>{if(!t)return;let n=pe.current.find(e=>e.path===r);n&&e.etag!==n.etag&&m(e=>({...e,[r]:!0}))}).catch(()=>{})},p_);return()=>{t=!1,clearInterval(r)}},[e,n,a.length]);let L=(0,V.useCallback)(async(t,s)=>{if(!e)return;let c=a.find(e=>e.path===t);if(!c)return;f(e=>({...e,[t]:{state:`saving`,message:``}}));let l=c.etag;if(s)try{l=(await v_(w_(e,t,n))).etag}catch(e){i.current===r&&f(n=>({...n,[t]:{state:`error`,message:`无法读取磁盘上的最新版本:${e instanceof Error?e.message:`未知错误`}`}}));return}let u=c.content;try{let a=await v_(C_(e,t,n),{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t,content:u,baseEtag:l})});if(i.current!==r)return;let s=pe.current.find(e=>e.path===t),c=s!==void 0&&s.content!==u;o(e=>e.map(e=>e.path===t?{...e,etag:a.meta.etag,dirty:e.content!==u}:e)),m(e=>({...e,[t]:!1})),f(e=>({...e,[t]:{state:`saved`,message:c?`已保存,但你又改了;最新修改仍未保存`:`已保存 ${D_(a.meta.modifiedAt)}`}}))}catch(e){if(i.current!==r)return;let n=e instanceof h_&&e.body.code===`stale`;f(r=>({...r,[t]:{state:n?`conflict`:`error`,message:e instanceof Error?e.message:`保存失败`}})),n&&m(e=>({...e,[t]:!0}))}},[e,n,r,a]),me=(0,V.useCallback)(async t=>{if(!e)return;let a=pe.current.find(e=>e.path===t)?.content;try{let s=await v_(C_(e,t,n));if(i.current!==r)return;let c=pe.current.find(e=>e.path===t),l=c!==void 0&&c.content!==a;o(e=>e.map(e=>e.path===t?{...e,content:l?e.content:s.content,etag:s.meta.etag,dirty:l}:e)),m(e=>({...e,[t]:!1})),f(e=>({...e,[t]:{state:`saved`,message:l?`已读取磁盘版本;你后来输入的修改仍未保存`:`已重新载入磁盘版本`}}))}catch(e){i.current===r&&f(n=>({...n,[t]:{state:`error`,message:e instanceof Error?e.message:`重新载入失败`}}))}},[e,n,r]),he=a.find(e=>e.path===s),ge=(0,V.useMemo)(()=>a.map(e=>({id:e.path,label:e.name,title:e.path,closable:!0,badge:e.dirty?(0,H.jsx)(`span`,{className:`file-tab-badge`,"data-file-tab-dirty":e.path,"aria-label":`未保存`,children:`●`}):void 0})),[a]),_e=(0,V.useMemo)(()=>new Set(a.map(e=>e.path)),[a]),ve=(0,V.useCallback)((e,t,n)=>{I(r=>({...r,[e]:{changes:t,dropped:n}}))},[]),ye=e?re[e]:void 0,be=(0,V.useMemo)(()=>{let e=ye?.changes??[];if(!n)return e;let t=`${n}/`;return e.flatMap(e=>e.path.startsWith(t)?[{...e,path:e.path.slice(t.length)}]:[])},[ye,n]),xe=ye?.dropped??0;return{open:a,activePath:s,active:he,tabItems:ge,openPaths:_e,notice:l,setNotice:u,saves:d,external:p,openFile:ue,setActivePath:c,closeFile:de,updateBuffer:fe,save:L,reload:me,listings:h,expanded:_,toggleDirectory:ce,loadDirectory:se,refreshTree:le,listHeight:x,setListHeight:S,query:y,setQuery:b,hits:C,searching:T,changed:be,changedPaths:(0,V.useMemo)(()=>new Set(be.map(e=>e.path)),[be]),changedDirs:(0,V.useMemo)(()=>{let e=new Set;for(let t of be){let n=t.path.split(`/`);for(let t=1;t<n.length;t++)e.add(n.slice(0,t).join(`/`))}return e},[be]),changedDropped:xe,setChangedFor:ve,index:D,indexComplete:k,indexSkipped:j,requestIndex:ne,cancelIndexRequest:te,setIndex:ee,restoredActive:ae}}var F_=`super-pi.file-workbench.v1`;function I_(){try{if(typeof window>`u`)return{};let e=JSON.parse(window.localStorage.getItem(`super-pi.file-workbench.v1`)??`null`);if(!e||typeof e!=`object`)return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`)continue;let e=r,i=Array.isArray(e.open)?e.open.filter(e=>typeof e==`string`):[],a=Array.isArray(e.expanded)?e.expanded.filter(e=>typeof e==`string`):[],o=typeof e.listHeight==`number`&&Number.isFinite(e.listHeight)&&e.listHeight>0?Math.round(e.listHeight):void 0;t[n]={open:i,expanded:a,...typeof e.active==`string`?{active:e.active}:{},...o?{listHeight:o}:{}}}return t}catch{return{}}}function L_(e){try{typeof window<`u`&&window.localStorage.setItem(F_,JSON.stringify(e))}catch{}}function R_({height:e,onHeight:t,panelRef:n,min:r=120}){let[i,a]=(0,V.useState)(!1),o=()=>{let e=n.current?.querySelector(`.files-tree`)??null;return{list:e,height:e?.getBoundingClientRect().height??0}},s=e=>{e.preventDefault(),e.currentTarget.focus();let n=e.clientY,{height:i}=o();a(!0);let s=document.body,c=s.style.cursor,l=s.style.userSelect;s.style.cursor=`row-resize`,s.style.userSelect=`none`;let u=e=>{let a=Math.round(i+(e.clientY-n));t(Math.max(r,a))},d=()=>{s.style.cursor=c,s.style.userSelect=l,a(!1),window.removeEventListener(`mousemove`,u),window.removeEventListener(`mouseup`,d)};window.addEventListener(`mousemove`,u),window.addEventListener(`mouseup`,d)},c=e=>e.shiftKey?96:24;return(0,H.jsx)(`div`,{className:`files-splitter${i?` files-splitter-dragging`:``}`,"data-file-splitter":`1`,"data-file-splitter-dragging":i?`true`:`false`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`调整文件列表高度`,"aria-valuenow":e??void 0,"aria-valuemin":r,tabIndex:0,onMouseDown:s,onKeyDown:e=>{let i=c(e);if(e.key===`ArrowDown`){e.preventDefault();let{height:n}=o();t(Math.max(r,Math.round(n)+i))}else if(e.key===`ArrowUp`){e.preventDefault();let{height:n}=o(),a=Math.round(n)-i;t(a<=r?null:a)}else if(e.key===`Home`)e.preventDefault(),t(null);else if(e.key===`End`){e.preventDefault();let i=n.current?.querySelector(`.files-tree`)?.parentElement?.clientHeight??0;t(Math.max(r,i))}}})}function z_({workspaceId:e,files:t,onOpenFile:n,onOpenChanged:r}){let{open:i,openPaths:a,notice:o,setNotice:s,openFile:c,listings:l,expanded:u,toggleDirectory:d,loadDirectory:f,refreshTree:p,listHeight:m,setListHeight:h,query:g,setQuery:_,hits:v,searching:y,changed:b,changedPaths:x,changedDirs:S,changedDropped:C}=t,w=(0,V.useCallback)(e=>{n?n(e):c(e)},[n,c]),T=l[``],E=g.trim(),D=(0,V.useRef)(null),O=(0,V.useCallback)(e=>{let t=D.current;if(!t)return;let n=e.target?.closest(`.file-row`);if(!n)return;let r=[...t.querySelectorAll(`.file-row`)],i=r.indexOf(n);if(i<0)return;let a=e=>{let t=Math.max(0,Math.min(r.length-1,e));r[t]?.focus()};if(e.key===`ArrowDown`)e.preventDefault(),a(i+1);else if(e.key===`ArrowUp`)e.preventDefault(),a(i-1);else if(e.key===`Home`)e.preventDefault(),a(0);else if(e.key===`End`)e.preventDefault(),a(r.length-1);else if(e.key===`ArrowRight`){let t=n.getAttribute(`data-file-dir-toggle`);t&&n.getAttribute(`aria-expanded`)===`false`&&(e.preventDefault(),d(t))}else if(e.key===`ArrowLeft`){let r=n.getAttribute(`data-file-dir-toggle`);if(r&&n.getAttribute(`aria-expanded`)===`true`){e.preventDefault(),d(r);return}let i=n.getAttribute(`data-file-open`)??n.getAttribute(`data-file-hit`);if(i){e.preventDefault();let n=i.lastIndexOf(`/`),r=n<0?``:i.slice(0,n);(r?t.querySelector(`[data-file-dir-toggle="${CSS.escape(r)}"]`):null)?.focus()}}},[d]),[k,A]=(0,V.useState)(200);(0,V.useEffect)(()=>{A(200)},[E,e]);let j=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(E===``)return;let e=j.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&A(e=>e>=(v?.hits.length??0)?e:e+200)},{rootMargin:`200px`});return t.observe(e),()=>t.disconnect()},[E,v]);let M=(0,V.useMemo)(()=>{if(E){if(y||!v)return(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-searching":`1`,children:`搜索中…`});if(v.hits.length===0)return(0,H.jsxs)(`p`,{className:`rail-empty`,"data-file-search-empty":`1`,children:[`没有匹配「`,E,`」的文件。`]});let e=v.hits.slice(0,k),t=[],n=new Map;for(let r of e){let e=n.get(r.directory);if(e)e.push(r);else{let e=[r];n.set(r.directory,e),t.push({directory:r.directory,hits:e})}}return(0,H.jsxs)(H.Fragment,{children:[t.map(e=>(0,H.jsxs)(`section`,{className:`file-group`,"data-file-search-group":e.directory,children:[(0,H.jsxs)(`h3`,{className:`file-group-head`,"data-file-search-group-head":e.directory,children:[(0,H.jsx)(`span`,{className:`file-group-name`,children:e.directory||`/`}),(0,H.jsx)(`span`,{className:`file-group-count`,children:e.hits.length})]}),(0,H.jsx)(`ul`,{className:`file-list`,children:e.hits.map(e=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,"data-file-hit":e.path,"data-file-hit-open":a.has(e.path)?`1`:`0`,onClick:()=>w({path:e.path,name:e.name,text:!0}),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(cp,{path:e.path}),(0,H.jsx)(`span`,{className:`file-name`,children:e.name}),a.has(e.path)&&(0,H.jsx)(`span`,{className:`file-open-mark`,"data-file-open-mark":e.path,title:`已经打开`,"aria-label":`已经打开`,children:`●`})]})},e.path))})]},e.directory||`/`)),e.length<v.hits.length&&(0,H.jsx)(`div`,{ref:j,className:`file-sentinel`,"data-file-search-more":`1`,children:`正在载入更多…`})]})}return e?T===void 0?(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-root-loading":`1`,children:`读取工作区…`}):`error`in T?(0,H.jsx)(N_,{error:T.error}):(0,H.jsxs)(H.Fragment,{children:[T.truncated&&(0,H.jsx)(`p`,{className:`file-search-note`,"data-file-truncated-root":`1`,children:`条目过多,只显示前一部分。`}),T.entries.length===0?(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-root-empty":`1`,children:`这个工作区是空的,没有文件也没有子目录。`}):(0,H.jsx)(`ul`,{className:`file-list`,children:T.entries.map(t=>t.kind===`directory`?(0,H.jsx)(O_,{workspaceId:e,entryPath:t.path,name:t.name,listings:l,expanded:u,toggle:d,loadDirectory:f,openPaths:a,changedDirs:S,changedPaths:x,onOpen:e=>w(e),depth:0},t.path):(0,H.jsx)(k_,{entry:t,depth:0,openPaths:a,changedPaths:x,onOpen:e=>w(e)},t.path))})]}):(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-no-workspace":`1`,children:`先在左侧选一个工作区,这里会显示它的文件。`})},[E,y,v,k,e,T,l,u,d,f,w,a,S,x]);return(0,H.jsxs)(`div`,{className:`files-panel`,"data-files-panel":`1`,"data-files-open-count":i.length,"data-files-changed-count":b.length,ref:D,onKeyDown:O,children:[(0,H.jsxs)(`div`,{className:`files-search`,children:[(0,H.jsx)(`span`,{className:`files-search-icon`,"aria-hidden":`true`,children:(0,H.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`13`,height:`13`,fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,children:[(0,H.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.6`}),(0,H.jsx)(`path`,{d:`M10.4 10.4 14 14`})]})}),(0,H.jsx)(`input`,{type:`search`,className:`files-search-input`,"data-file-search-input":`1`,value:g,placeholder:`按文件名搜索…`,"aria-label":`按文件名搜索`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),_(``))},onChange:e=>_(e.target.value)}),(0,H.jsx)(`button`,{type:`button`,className:`files-refresh`,"data-file-refresh":`1`,title:`重新读取目录`,"aria-label":`重新读取目录`,disabled:!e,onClick:()=>p(),children:`↻`})]}),E&&v&&!y&&(0,H.jsxs)(`p`,{className:`files-count`,"data-file-search-count":`1`,role:`status`,children:[(0,H.jsx)(`b`,{children:v.total.toLocaleString(`zh-CN`)}),` 个结果`,v.indexed===!1&&(0,H.jsx)(`span`,{className:`files-count-note`,"data-file-search-indexing":`1`,children:`正在建立索引…`})]}),b.length>0&&(0,H.jsxs)(`div`,{className:`files-changed`,"data-file-changed-list":`1`,children:[(0,H.jsxs)(`p`,{className:`files-changed-head`,"data-file-changed-head":`1`,children:[`agent 改了 `,b.length,` 个文件`]}),C>0&&(0,H.jsxs)(`p`,{className:`file-search-note`,"data-file-changed-dropped":`1`,children:[`还有 `,C,` 个改动没有记录(超过保留上限)。`]}),(0,H.jsx)(`ul`,{className:`file-list`,children:b.map(e=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`file-row file-row-file`,"data-file-changed-open":e.path,title:`${e.path}(点击查看改动)`,onClick:()=>r?.(e.path),children:[(0,H.jsx)(`span`,{className:`file-caret`,"aria-hidden":`true`}),(0,H.jsx)(cp,{path:e.path}),(0,H.jsx)(`span`,{className:`file-name`,children:e.path.split(`/`).pop()}),(0,H.jsx)(`span`,{className:`file-badge-path`,children:e.path.split(`/`).slice(0,-1).join(`/`)||`/`}),(0,H.jsx)(`span`,{className:`file-badge file-badge-changed`,"data-file-changed-kind":e.path,children:e.baseline===null&&!e.baselineUnknown?`新建`:`已改`})]})},e.path))})]}),o&&(0,H.jsx)(`p`,{className:`rail-empty`,"data-file-notice":`1`,children:o}),(0,H.jsxs)(`div`,{className:`files-tree`,"data-file-tree":E?`search`:`browse`,style:m===null?void 0:{height:`${m}px`,flex:`0 0 auto`},children:[(0,H.jsx)(`div`,{className:`files-tree-body`,children:M}),i.length===0&&(0,H.jsx)(`p`,{className:`rail-empty file-hint`,"data-file-none-open":`1`,children:`点一个文本文件,它会在上面的标签栏开一个标签,正文显示在中间主画面。`}),i.length>0&&(0,H.jsxs)(`p`,{className:`files-hint file-hint`,"data-file-open-hint":`1`,children:[`已打开 `,i.length,` 个文件,正文显示在中间主画面;点上面的标签切换,点这里的行切换。`]})]}),(0,H.jsx)(R_,{height:m,onHeight:h,panelRef:D}),(0,H.jsxs)(`p`,{className:`files-footnote`,"data-files-footnote":`1`,children:[`只支持纯文本(md / 代码),二进制文件不会打开。写入只允许覆盖已存在的文件,不新建,不删除。`,i.length>0&&` 当前打开 ${i.length} 个文件,占 ${E_(i.reduce((e,t)=>e+t.content.length,0))}。`]})]})}function B_({workspaceId:e,cwd:t=``,onOpen:n,onClose:r}){let[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(0),m=(0,V.useRef)(null),h=(0,V.useRef)(null);(0,V.useEffect)(()=>{m.current?.focus()},[]),(0,V.useEffect)(()=>{h.current?.scrollIntoView({block:`nearest`})},[f]),(0,V.useEffect)(()=>{let n=i.trim();if(s(null),l(``),p(0),!e||!n){d(!1);return}let r=!0;d(!0);let a=setTimeout(()=>{v_(`/api/files/search?workspaceId=${b_(e)}&q=${b_(n)}${x_(t)}`).then(e=>{r&&(s(e),d(!1))}).catch(e=>{r&&(l(tp(e,`搜索没有完成`)),d(!1))})},220);return()=>{r=!1,clearTimeout(a)}},[i,e,t]);let g=e=>{e&&(n(e),r())},_=o?.truncated||o?.complete===!1,v={index:`索引未完整`,size:`文件超过 512KB`,depth:`目录超过 12 层`,time:`搜索超过 10 秒`,results:`达到 500 条上限`,output:`SDK 输出达到上限`,line:`长行已截断`,unreadable:`部分文件无法读取`};return(0,H.jsx)(`div`,{className:`quick-open-backdrop`,"data-content-search":`1`,role:`presentation`,onMouseDown:r,children:(0,H.jsxs)(`div`,{className:`quick-open content-search`,role:`dialog`,"aria-modal":`true`,"aria-label":`内容搜索`,onMouseDown:e=>e.stopPropagation(),children:[(0,H.jsx)(`input`,{ref:m,className:`quick-open-input`,"data-content-search-input":`1`,value:i,maxLength:256,placeholder:`内容搜索(区分大小写,按字面匹配)`,"aria-label":`内容搜索`,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),r()):e.key===`ArrowDown`?(e.preventDefault(),p(e=>Math.min(e+1,Math.max(0,(o?.hits.length??0)-1)))):e.key===`ArrowUp`?(e.preventDefault(),p(e=>Math.max(0,e-1))):e.key===`Enter`&&(e.preventDefault(),g(o?.hits[f]))}}),(0,H.jsxs)(`p`,{className:`quick-open-status`,role:`status`,"data-content-search-status":c?`error`:u?`searching`:_?`partial`:`complete`,children:[c?`✕ 搜索失败:`+c:u?`… 搜索中`:e?_?`⚠ 结果不完整`:o?`✓ 搜索完成`:`○ 输入要搜索的内容`:`○ 请先选择工作区`,o?` · ${o.hits.length} 条命中`:``,` · Esc 关闭`]}),_&&(0,H.jsxs)(`p`,{className:`quick-open-status`,"data-content-search-partial":`1`,children:[`⚠ 结果不完整:`,o?.reasons.map(e=>v[e]??e).join(`;`)]}),o&&o.skipped.length>0&&(0,H.jsxs)(`details`,{className:`quick-open-status`,"data-content-search-skipped":`1`,children:[(0,H.jsxs)(`summary`,{children:[`↷ 已跳过 `,o.skipped.length,` 个文件或目录`]}),(0,H.jsx)(`p`,{className:`content-search-skipped-paths`,children:o.skipped.join(`
52
52
  `)})]}),o&&!u&&o.hits.length===0&&(0,H.jsx)(`p`,{className:`quick-open-status`,"data-content-search-empty":`1`,children:`○ 没有匹配的行`}),(0,H.jsx)(`ul`,{className:`quick-open-results content-search-results`,role:`listbox`,children:o?.hits.map((e,t)=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{ref:t===f?h:void 0,type:`button`,"data-content-search-result":`${e.path}:${e.line}`,className:`quick-open-result content-search-result${f===t?` quick-open-result-active`:``}`,"aria-selected":f===t,onMouseEnter:()=>p(t),onClick:()=>g(e),children:[(0,H.jsxs)(`span`,{children:[e.path,`:`,e.line]}),(0,H.jsx)(`small`,{title:e.text,children:e.text})]})},`${e.path}:${e.line}`))})]})})}function V_({entries:e,complete:t,skipped:n,onOpen:r,onClose:i}){let[a,o]=(0,V.useState)(``),[s,c]=(0,V.useState)(0),l=(0,V.useRef)(null),u=(0,V.useMemo)(()=>e.filter(e=>e.kind===`file`&&e.text!==!1),[e]),d=(0,V.useMemo)(()=>a.trim()?new Mg(u,{keys:[`path`],threshold:.38,ignoreLocation:!0}).search(a).slice(0,20).map(e=>e.item):u.slice(0,20),[u,a]);(0,V.useEffect)(()=>{l.current?.focus(),c(0)},[a]);let f=(0,V.useCallback)(e=>{e&&(r({path:e.path,name:e.path.split(`/`).pop()??e.path,text:e.text}),i())},[r,i]);return(0,H.jsx)(`div`,{className:`quick-open-backdrop`,"data-quick-open":`1`,role:`presentation`,onMouseDown:i,children:(0,H.jsxs)(`div`,{className:`quick-open`,role:`dialog`,"aria-modal":`true`,"aria-label":`快速打开`,onMouseDown:e=>e.stopPropagation(),children:[(0,H.jsx)(`input`,{ref:l,className:`quick-open-input`,"data-quick-open-input":`1`,value:a,placeholder:`快速打开:输入文件名或路径`,"aria-label":`快速打开文件路径`,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),i()):e.key===`ArrowDown`?(e.preventDefault(),c(e=>Math.min(e+1,Math.max(0,d.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),c(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),f(d[s]))}}),(0,H.jsxs)(`p`,{className:`quick-open-status`,"data-quick-open-status":t?`complete`:`partial`,children:[t?`✓ 索引完整`:`⚠ 索引不完整`,` · `,u.length,` 个文件 · Esc 关闭`]}),n.length>0&&(0,H.jsxs)(`p`,{className:`quick-open-status`,"data-quick-open-skipped":`1`,title:n.join(`, `),children:[`↷ 已跳过:`,n.join(`, `)]}),(0,H.jsx)(`ul`,{className:`quick-open-results`,role:`listbox`,children:d.map((e,t)=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,"data-quick-open-result":e.path,className:t===s?`quick-open-result quick-open-result-active`:`quick-open-result`,"aria-selected":t===s,onMouseEnter:()=>c(t),onClick:()=>f(e),children:[(0,H.jsx)(`span`,{children:e.path.split(`/`).pop()}),(0,H.jsx)(`small`,{children:e.path})]})},e.path))})]})})}function H_(e,t,n=88,r=200){let i=Math.max(0,Math.floor(e));if(!Number.isFinite(t)||t<=0)return{perRow:Math.max(1,i),width:n};if(i===0)return{perRow:1,width:n};if(i===1)return{perRow:1,width:Math.min(r,t)};let a=t/i;if(a>=n)return{perRow:i,width:Math.min(a,r)};for(let e=2;e<=i;e+=1){let a=Math.ceil(i/e),o=t/a;if(o>=n)return{perRow:a,width:Math.min(o,r)}}return{perRow:1,width:n}}function U_(e,t){let n=Math.max(1,Math.floor(t)),r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function W_(e,t,n=88,r=200){let[i,a]=(0,V.useState)(()=>H_(e,0,n,r)),[o,s]=(0,V.useState)(null),c=(0,V.useCallback)(()=>{let i=H_(e,t,n,r);s({count:e,containerWidth:t}),a(e=>e.perRow===i.perRow&&e.width===i.width?e:i)},[e,t,n,r]),l=(0,V.useRef)(t);(0,V.useLayoutEffect)(()=>{t<=0||l.current!==t&&(l.current=t,c())},[t,c]);let u=(0,V.useRef)(null);return(0,V.useLayoutEffect)(()=>{let t=u.current;u.current=e,t!==null&&e>t&&c()},[e,c]),{layout:i,frozen:o!==null&&o.count!==e,recompute:c}}function G_({tabs:e,activeId:t,onSelect:n,onClose:r,onActivate:i,ariaLabel:a,minWidth:o=88,maxWidth:s=200,prefix:c=`workspace-tab`,idPrefix:l=c,className:u}){let d=(0,V.useRef)(null),[f,p]=(0,V.useState)(0),{layout:m,frozen:h,recompute:g}=W_(e.length,f,o,s);(0,V.useLayoutEffect)(()=>{let e=d.current;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.clientWidth;t>0&&p(t)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let _=U_(e,m.perRow),v=(e,t)=>t===void 0?{}:{[`data-${c}-${e}`]:t},y=e.filter(e=>e.kind===`file`).length,b=e.filter(e=>e.kind===`session`||!e.kind).length,x=t=>({[`data-${t}-strip`]:`1`,...h?{[`data-${t}-frozen`]:`1`}:{},[`data-${t}-count`]:t===`file-tab`?y:t===`session-tab`?b:e.length,[`data-${t}-min`]:o,[`data-${t}-max`]:s,[`data-${t}-per-row`]:m.perRow,[`data-${t}-width`]:Math.round(m.width*100)/100}),S=e=>{let t=e.relatedTarget;(!t||t.isConnected)&&g()},C=e=>{let t=e.relatedTarget;(!t||t.isConnected)&&g()};(0,V.useEffect)(()=>{if(!h)return;let e=d.current;if(!e)return;let t=t=>{let n=e.getBoundingClientRect();t.clientX>=n.left&&t.clientX<=n.right&&t.clientY>=n.top&&t.clientY<=n.bottom||g()};return document.addEventListener(`mousemove`,t,!0),()=>document.removeEventListener(`mousemove`,t,!0)},[h,g]);let w=[`${c}-strip`,`workspace-tab-strip`,`session-tab-strip`,`file-tab-strip`,u].filter(Boolean).join(` `);return(0,H.jsx)(`div`,{ref:d,className:w,role:`tablist`,"aria-label":a??`工作区标签页`,...v(`strip`,`1`),...x(`workspace-tab`),...x(`session-tab`),...x(`file-tab`),style:{"--tab-w":`${m.width}px`},onMouseEnter:S,onMouseLeave:C,children:_.map((a,o)=>(0,H.jsx)(`div`,{className:`${c}-row workspace-tab-row session-tab-row file-tab-row`,role:`presentation`,...v(`row`,o),children:a.map(a=>{let o=a.id===t||a.rawId!==void 0&&a.rawId===t,s=a.title??a.label,u=a.kind,d=a.rawId??a.id,f=e.findIndex(e=>e.id===a.id),p=[c,o?`${c}-active`:``,`workspace-tab`,o?`workspace-tab-active`:``,u?`${u}-tab`:``,u&&o?`${u}-tab-active`:``,a.preview?`${c}-preview`:``,a.preview?`workspace-tab-preview`:``,a.preview&&u?`${u}-tab-preview`:``].filter(Boolean).join(` `);return(0,H.jsxs)(`div`,{role:`tab`,id:`${l}-${a.id}`,"aria-selected":o,"aria-controls":`${l}-panel-${a.id}`,tabIndex:o?0:-1,className:p,...v(`id`,d),...v(`index`,f),...o?v(`active`,`1`):{},...v(`closable`,a.closable===!1?`0`:`1`),...u?{"data-tab-kind":u}:{},...a.preview?{"data-tab-preview":`1`}:{},...u===`session`||!u?{"data-session-tab-id":d,"data-session-tab-index":f,...o?{"data-session-tab-active":`1`}:{},"data-session-tab-closable":a.closable===!1?`0`:`1`,...a.preview?{"data-session-tab-preview":`1`}:{}}:{},...u===`file`?{"data-file-tab-id":d,"data-file-tab-index":f,...o?{"data-file-tab-active":`1`}:{},"data-file-tab-closable":a.closable===!1?`0`:`1`}:{},...u===`diff`?{"data-diff-tab-id":d,"data-diff-tab-index":f,...o?{"data-diff-tab-active":`1`}:{},"data-diff-tab-closable":a.closable===!1?`0`:`1`}:{},title:s,style:{width:m.width,boxSizing:`border-box`},onClick:()=>n?.(a.id),onDoubleClick:()=>{(u===`session`||u===void 0)&&i?.(a.id)},onAuxClick:e=>{e.button===1&&(e.preventDefault(),e.stopPropagation(),a.closable!==!1&&r&&r(a.id))},onMouseDown:e=>{e.button===1&&e.preventDefault()},onKeyDown:t=>{if(t.key!==`ArrowLeft`&&t.key!==`ArrowRight`)return;t.preventDefault();let r=t.key===`ArrowRight`?1:-1,i=e[(e.findIndex(e=>e.id===a.id)+r+e.length)%e.length];i&&n?.(i.id)},children:[a.icon&&(0,H.jsx)(`span`,{className:`${c}-icon workspace-tab-icon`,children:a.icon}),a.badge,(0,H.jsx)(`span`,{className:`${c}-label workspace-tab-label ${u?`${u}-tab-label`:``}`,...v(`label`,d),...u===`session`||!u?{"data-session-tab-label":d}:{},...u===`file`?{"data-file-tab-label":d}:{},...u===`diff`?{"data-diff-tab-label":d}:{},children:a.label}),a.closable!==!1&&r&&(0,H.jsx)(`button`,{type:`button`,className:`${c}-close workspace-tab-close ${u?`${u}-tab-close`:``}`,...v(`close`,d),...u===`session`||!u?{"data-session-tab-close":d}:{},...u===`file`?{"data-file-tab-close":d}:{},...u===`diff`?{"data-diff-tab-close":d}:{},onClick:e=>{e.stopPropagation(),r(a.id)},onDoubleClick:e=>{e.stopPropagation()},title:`关闭 ${s}`,"aria-label":`关闭 ${s}`,children:`×`})]},a.id)})},`row_${o}`))})}var K_={pending:`未开始`,running:`运行中`,completed:`已完成`,failed:`失败`,skipped:`已跳过`,stopped:`已停止`},q_={running:`运行中`,completed:`全部完成`,failed:`中途失败`,stopped:`已停止`},J_={pending:`○`,running:`◐`,completed:`✓`,failed:`✕`,skipped:`→`,stopped:`■`},Y_={stop:`失败即停`,skip:`失败跳过`,"retry:1":`失败重试 1 次`,"retry:2":`失败重试 2 次`,"retry:3":`失败重试 3 次`};function X_(e){let t=Math.max(0,Math.round(e/1e3)),n=t%60,r=Math.floor(t/60)%60,i=Math.floor(t/3600),a=e=>String(e).padStart(2,`0`);return i>0?`${i}h ${a(r)}:${a(n)}`:`${r}:${a(n)}`}function Z_(e){let t=e.status===`running`,[n,r]=(0,V.useState)(0);(0,V.useEffect)(()=>{if(!t)return;r(Date.now());let e=window.setInterval(()=>r(Date.now()),200);return()=>window.clearInterval(e)},[t,e.startedAt]);let i=Date.parse(e.startedAt);if(Number.isFinite(i)){if(!t){let t=Date.parse(e.finishedAt??``);return Number.isFinite(t)?t-i:void 0}return n>0?n-i:void 0}}function Q_({step:e,names:t}){let n=e.attempts.length,r=e.attempts[n-1],i=t.get(e.agentId)||e.agentId,a=e.label?.trim()||i;return(0,H.jsxs)(`li`,{className:`workflow-step workflow-step-${e.status}`,"data-workflow-step":e.index+1,"data-workflow-step-status":e.status,"data-workflow-step-agent":e.agentId,"data-workflow-step-attempts":n,children:[(0,H.jsx)(`span`,{className:`workflow-step-mark`,"aria-hidden":`true`,children:J_[e.status]}),(0,H.jsxs)(`span`,{className:`workflow-step-n`,"data-workflow-step-n":e.index+1,children:[`第 `,e.index+1,` 步`]}),(0,H.jsx)(`strong`,{className:`workflow-step-name`,"data-workflow-step-name":e.index+1,children:a}),(0,H.jsx)(`span`,{className:`workflow-step-agent`,"data-workflow-step-agent-name":e.index+1,children:i}),n>1&&(0,H.jsxs)(`span`,{className:`workflow-step-tries`,"data-workflow-step-retried":e.index+1,children:[`尝试 `,n,` 次`]}),(0,H.jsx)(`span`,{className:`workflow-step-status`,"data-workflow-step-status-text":e.index+1,children:K_[e.status]}),e.status===`failed`&&r?.error&&(0,H.jsx)(`span`,{className:`workflow-step-why`,"data-workflow-step-error":e.index+1,title:np(r.error),children:tp(r.error,`这一步没有完成。`)})]})}function $_({nodes:e,steps:t,names:n}){return(0,H.jsx)(`ol`,{className:`workflow-steps`,children:e.map((e,r)=>{if(e.kind===`step`){let r=t[e.stepIndex];return r?(0,H.jsx)(Q_,{step:r,names:n},`step-${e.stepIndex}`):null}return e.kind===`loop`?(0,H.jsxs)(`li`,{className:`workflow-node workflow-loop`,"data-workflow-loop":!0,"data-workflow-loop-rounds":e.rounds.length,"data-workflow-loop-max":e.max,"data-workflow-until":e.until,children:[(0,H.jsxs)(`div`,{className:`workflow-node-head`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`↻`}),(0,H.jsx)(`strong`,{children:`循环`}),(0,H.jsxs)(`span`,{children:[`直到「`,e.until,`」`]}),(0,H.jsxs)(`span`,{"data-workflow-loop-progress":!0,children:[`已跑 `,e.rounds.length,`/`,e.max,` 轮`]})]}),e.rounds.map(e=>(0,H.jsxs)(`section`,{className:`workflow-round`,"data-workflow-round":e.n,"data-workflow-round-met":e.untilMet?`true`:`false`,children:[(0,H.jsxs)(`div`,{className:`workflow-round-head`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:e.untilMet?`✓`:`○`}),`第 `,e.n,` 轮 · `,e.untilMet?`条件满足`:`条件未满足`]}),(0,H.jsx)($_,{nodes:e.nodes,steps:t,names:n})]},e.n))]},`loop-${r}`):(0,H.jsxs)(`li`,{className:`workflow-node workflow-foreach`,"data-workflow-foreach":!0,"data-workflow-foreach-count":e.items.length,children:[(0,H.jsxs)(`div`,{className:`workflow-node-head`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`≡`}),(0,H.jsx)(`strong`,{children:`逐项执行`}),(0,H.jsxs)(`span`,{children:[e.items.length,` 个由 primary 给出的项目`]})]}),e.iterations.map((e,r)=>(0,H.jsxs)(`section`,{className:`workflow-item`,"data-workflow-item":r+1,"data-workflow-item-value":e.item,children:[(0,H.jsxs)(`div`,{className:`workflow-item-head`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),`第 `,r+1,` 项 · `,e.item]}),(0,H.jsx)($_,{nodes:e.nodes,steps:t,names:n})]},`${r}-${e.item}`))]},`foreach-${r}`)})})}function ev({workflow:e,names:t,onStop:n,stopping:r}){let i=e.status===`running`,a=Z_(e),o=e.steps.filter(e=>e.status===`completed`||e.status===`skipped`).length;return(0,H.jsxs)(`article`,{className:`workflow-card workflow-${e.status}`,"data-workflow-card":e.id,"data-workflow-status":e.status,"data-workflow-steps":e.steps.length,"data-workflow-current":e.currentIndex+1,children:[(0,H.jsxs)(`div`,{className:`workflow-head`,children:[(0,H.jsx)(`span`,{className:`workflow-badge`,children:`编排`}),(0,H.jsx)(`strong`,{className:`workflow-summary`,"data-workflow-summary":e.id,children:e.summary}),(0,H.jsxs)(`span`,{className:`workflow-progress`,"data-workflow-progress":e.id,children:[o,`/`,e.steps.length]}),(0,H.jsx)(`span`,{className:`workflow-status`,"data-workflow-status-text":e.id,children:q_[e.status]??`未知状态`}),(0,H.jsx)(`span`,{className:`workflow-policy`,"data-workflow-policy":e.onFailure,children:Y_[e.onFailure]??e.onFailure}),a!==void 0&&(0,H.jsxs)(`span`,{className:`workflow-clock`,"data-workflow-elapsed":e.id,children:[i?`已运行 `:`用时 `,X_(a)]}),i&&(0,H.jsx)(`button`,{type:`button`,className:`workflow-stop`,"data-workflow-stop":e.id,disabled:r,onClick:n,children:`停止`})]}),e.nodes?(0,H.jsx)($_,{nodes:e.nodes,steps:e.steps,names:t}):(0,H.jsx)(`ol`,{className:`workflow-steps`,"data-workflow-step-count":e.steps.length,children:e.steps.map(e=>(0,H.jsx)(Q_,{step:e,names:t},e.index))})]})}var tv=[{id:`agents`,label:`智能体与创建`,icon:`🤖`,title:`Agent 智能体系统与创建指南`,description:`了解 Super Pi 的角色设定机制,以及如何一步步创建你自己的自定义 Agent。`},{id:`workspace`,label:`工作区与会话`,icon:`🗂️`,title:`工作区与多会话管理`,description:`高效管理本地代码仓库、独立会话标签页与多模态图文输入。`},{id:`subagents`,label:`子任务与编排`,icon:`⚡`,title:`子智能体委托与顺序编排使用指南`,description:`让主 Agent 安排分工、交接结果,并查看进度、处理失败与停止任务。`},{id:`model-policy`,label:`模型使用规则`,icon:`🔒`,title:`模型过滤规则(按工作区限制可用模型)`,description:`用正则规则限定哪些工作区只能用哪些模型,防止敏感代码被发到不该用的模型上。`},{id:`memory`,label:`主动记忆`,icon:`🧠`,title:`主动记忆与技能经验`,description:`让 Super Pi 在得到明确证据后保存长期事实、用户偏好和可复用工作方法。`},{id:`knowledge`,label:`知识库`,icon:`📚`,title:`工作区知识库`,description:`导入规范与设计文档,让 Agent 检索原文作答,而不是凭记忆编造。`},{id:`feishu`,label:`飞书`,icon:`📄`,title:`飞书云文档的读写`,description:`让 Agent 读一篇飞书文档、写回结论。接入方式、连接步骤与常见问题。`},{id:`tools`,label:`侧边栏工具`,icon:`🧩`,title:`全局工具:开发、导出与导入`,description:`让 Agent 写一个工具,用一个文件分享给别人,导入前先看清它会做什么。`},{id:`cli`,label:`指令与快捷键`,icon:`⌨️`,title:`Pi 终端命令与键盘快捷操作`,description:`利用 Pi 终端斜杠指令控制服务生命周期,掌握常用快捷键提升效率。`},{id:`themes`,label:`外观与主题`,icon:`🎨`,title:`界面主题与个性化显示`,description:`内置 4 款专业高对比度主题,针对不同环境提供舒适体验。`}];function nv({onClose:e}){let[t,n]=(0,V.useState)(`agents`);(0,V.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!t.defaultPrevented&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let r=tv.find(e=>e.id===t)??tv[0];return(0,H.jsx)(`div`,{className:`overlay`,onClick:e,children:(0,H.jsxs)(`div`,{className:`picker settings-window help-window`,"data-help-window":`1`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,"aria-labelledby":`help-window-title`,children:[(0,H.jsxs)(`div`,{className:`settings-window-head help-window-head`,children:[(0,H.jsxs)(`div`,{className:`help-head-title`,children:[(0,H.jsx)(`h2`,{id:`help-window-title`,children:`使用指南与帮助`}),(0,H.jsx)(`span`,{className:`help-badge`,children:`v0.1.x`})]}),(0,H.jsx)(`button`,{type:`button`,className:`help-close-button`,"aria-label":`关闭指南`,onClick:e,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`settings-window-body help-window-body`,children:[(0,H.jsxs)(`nav`,{className:`settings-nav help-nav`,role:`tablist`,"aria-orientation":`vertical`,"aria-label":`使用指南分类`,children:[(0,H.jsx)(`div`,{className:`settings-nav-label`,children:`目录`}),tv.map(e=>(0,H.jsxs)(`button`,{type:`button`,id:`help-tab-${e.id}`,className:`settings-category help-category`,role:`tab`,"aria-selected":e.id===r.id,"aria-controls":`help-panel`,tabIndex:e.id===r.id?0:-1,onClick:()=>n(e.id),children:[(0,H.jsx)(`span`,{className:`help-tab-icon`,"aria-hidden":`true`,children:e.icon}),(0,H.jsx)(`span`,{children:e.label})]},e.id))]}),(0,H.jsxs)(`div`,{id:`help-panel`,className:`settings-panel help-panel`,role:`tabpanel`,"aria-labelledby":`help-tab-${r.id}`,children:[(0,H.jsxs)(`div`,{className:`help-panel-header`,children:[(0,H.jsx)(`h3`,{className:`help-panel-title`,children:r.title}),(0,H.jsx)(`p`,{className:`help-panel-desc`,children:r.description})]}),(0,H.jsxs)(`div`,{className:`help-panel-content`,children:[r.id===`agents`&&(0,H.jsx)(av,{}),r.id===`workspace`&&(0,H.jsx)(ov,{}),r.id===`subagents`&&(0,H.jsx)(cv,{}),r.id===`model-policy`&&(0,H.jsx)(sv,{}),r.id===`memory`&&(0,H.jsx)(rv,{}),r.id===`knowledge`&&(0,H.jsx)(iv,{}),r.id===`feishu`&&(0,H.jsx)(lv,{}),r.id===`tools`&&(0,H.jsx)(uv,{}),r.id===`cli`&&(0,H.jsx)(dv,{}),r.id===`themes`&&(0,H.jsx)(fv,{})]}),(0,H.jsx)(`div`,{className:`picker-actions help-actions`,children:(0,H.jsx)(`button`,{type:`button`,className:`picker-cancel`,onClick:e,children:`关闭`})})]})]})]})})}function rv(){return(0,H.jsxs)(`div`,{className:`help-section-group`,children:[(0,H.jsxs)(`div`,{className:`help-card highlight`,children:[(0,H.jsx)(`h4`,{children:`🧠 它会记住什么?`}),(0,H.jsx)(`p`,{children:`用户档案保存跨工作区的长期偏好;工作区事实保存环境与项目约定;技能保存已经验证过的步骤、命令和坑。临时结果、秘密和未验证的失败不会保存。`})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`主动保存与后台复盘`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsxs)(`li`,{children:[`主 Agent 可以使用 `,(0,H.jsx)(`code`,{children:`memory`}),` 和 `,(0,H.jsx)(`code`,{children:`skill_manage`}),` 工具主动保存;说“记住了”本身不会写入。`]}),(0,H.jsx)(`li`,{children:`每隔若干回合,系统会在独立会话中复盘最近证据。复盘不能读写工作区文件、执行命令或派发任务。`}),(0,H.jsx)(`li`,{children:`读取记忆和历史只返回带来源的参考数据,不能把记忆中的文字当作新的指令。`})]})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`权限与审批`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsx)(`li`,{children:`子 Agent 可以读取相关记忆,但没有写入权限。`}),(0,H.jsx)(`li`,{children:`后台复盘新增记忆可以直接保存;修改或删除旧条目会进入设置中的待审批列表。`}),(0,H.jsx)(`li`,{children:`在“设置 → 主动记忆”可以开关功能、调整复盘间隔、编辑条目和批准提案。`})]})]})]})}function iv(){return(0,H.jsxs)(`div`,{className:`help-section-group`,children:[(0,H.jsxs)(`div`,{className:`help-card highlight`,children:[(0,H.jsx)(`h4`,{children:`📚 它解决什么问题?`}),(0,H.jsx)(`p`,{children:`Agent 默认靠训练时的记忆回答项目里的问题。知识库让你把规范、设计稿、会议纪要导入工作区,Agent 在回答前检索这些文档的原文片段,而不是凭印象编造。它与“主动记忆”不同:记忆是 Agent 自己沉淀的事实和技能,知识库的内容来自工作区里真实存在的文档。`})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`怎么用`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsxs)(`li`,{children:[`在“设置 → 知识库”里点“浏览工作区文件…”,在弹出的浏览器里挑一个 Markdown 或文本文件,挑完即导入。也可以直接粘贴正文、手动填写相对路径,或者直接对 Agent 说“把某某文件加入知识库”——它会用 `,(0,H.jsx)(`code`,{children:`knowledge_import`}),` 导入,走的是同一条服务端校验。`]}),(0,H.jsx)(`li`,{children:`同一个文件内容改了再导入就是更新,不会留下旧版本;同样的内容换个标题再导入也不会变成两篇。`}),(0,H.jsx)(`li`,{children:`面板里的“试检索”会用和 Agent 相同的检索器回答,方便你在交给 Agent 之前先确认它找得到。`}),(0,H.jsxs)(`li`,{children:[`从下一条消息开始生效。Agent 使用 `,(0,H.jsx)(`code`,{children:`knowledge_search`}),` 检索,只拿得到片段和来源,拿不到整篇文档。`]})]})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`语义检索是内置的`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsxs)(`li`,{children:[`关键词检索始终可用。语义检索让“撤销购买”也能找到写着“取消订单”的段落,它靠一个`,(0,H.jsx)(`strong`,{children:`随安装包一起分发`}),`的中文模型在本机运行,不需要额外下载、不需要联网、也不会把文档发到任何服务。`]}),(0,H.jsxs)(`li`,{children:[`第一次检索时加载模型(约一秒),之后一直可用。设 `,(0,H.jsx)(`code`,{children:`SUPER_PI_KNOWLEDGE_EMBEDDINGS=0`}),` 可以彻底关闭语义检索,只保留关键词检索。`]})]})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`它不知道的事`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsx)(`li`,{children:`知识库只会检索它有的东西。文档里没写的,它检索出来也不会有——所以导入什么,直接决定它能回答什么。`}),(0,H.jsx)(`li`,{children:`语义检索总会返回“最接近的那一段”,即使这一段其实并不回答问题。检索结果带一个分数,低分意味着这可能只是最像的一条,Agent 会被要求先核对再使用。`}),(0,H.jsxs)(`li`,{children:[`Agent 可以按你的要求把工作区文件导入知识库(`,(0,H.jsx)(`code`,{children:`knowledge_import`}),`,只接受文本类文件),但`,(0,H.jsx)(`strong`,{children:`不能删除`}),`——删除文档只有你能在“设置 → 知识库”里做。`]})]})]})]})}function av(){return(0,H.jsxs)(`div`,{className:`help-section-group`,children:[(0,H.jsxs)(`div`,{className:`help-card highlight`,children:[(0,H.jsx)(`h4`,{children:`💡 Agent 是什么?`}),(0,H.jsxs)(`p`,{children:[`在 Super Pi 中,`,(0,H.jsx)(`strong`,{children:`Agent(智能体)`}),` 是一套独立的「角色提示词设定与能力配置」。 通过切换 Agent,模型将扮演专精工程师、系统架构师、代码审查员或规划专家等不同角色,遵循指定的原则来协助你完成任务。`]})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`📁 Agent 文件存放在哪里?`}),(0,H.jsxs)(`ul`,{className:`help-list`,children:[(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:`内置 Agent 目录:`}),`项目根目录下的 `,(0,H.jsx)(`code`,{children:`agents/`}),` 文件夹,例如 `,(0,H.jsx)(`code`,{children:`agents/coder.md`}),`、`,(0,H.jsx)(`code`,{children:`agents/planner.md`}),`、`,(0,H.jsx)(`code`,{children:`agents/reviewer.md`}),` 等。`]}),(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:`用户自定义持久化目录:`}),`用户主目录下的 `,(0,H.jsx)(`code`,{children:`~/.super-pi/agents/`}),`,放入此目录的文件在所有项目和更新中均持久有效。`]})]})]}),(0,H.jsxs)(`div`,{className:`help-card`,children:[(0,H.jsx)(`h4`,{children:`🚀 如何创建一个全新的自定义 Agent?`}),(0,H.jsxs)(`div`,{className:`help-steps`,children:[(0,H.jsxs)(`div`,{className:`help-step`,children:[(0,H.jsx)(`span`,{className:`step-num`,children:`1`}),(0,H.jsxs)(`div`,{className:`step-body`,children:[(0,H.jsx)(`strong`,{children:`创建 Markdown 文件`}),(0,H.jsxs)(`p`,{children:[`在 `,(0,H.jsx)(`code`,{children:`agents/`}),` 或 `,(0,H.jsx)(`code`,{children:`~/.super-pi/agents/`}),` 目录下新建文件,例如 `,(0,H.jsx)(`code`,{children:`architect.md`}),`。`]})]})]}),(0,H.jsxs)(`div`,{className:`help-step`,children:[(0,H.jsx)(`span`,{className:`step-num`,children:`2`}),(0,H.jsxs)(`div`,{className:`step-body`,children:[(0,H.jsx)(`strong`,{children:`编写元数据与系统提示词`}),(0,H.jsx)(`p`,{children:`文件开头使用 YAML Frontmatter 声明名称和描述,正文编写设定提示词:`}),(0,H.jsx)(`pre`,{className:`help-code-block`,children:(0,H.jsx)(`code`,{children:`---
@@ -96,7 +96,7 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
96
96
 
97
97
  工具不属于当前 workspace;通过内置 tool_register 一次性提交完整文件(index.html、JS/CSS,必要时 .py),Super Pi 会保存为全局工具并自动出现在每个 workspace 的工具 Tab。
98
98
 
99
- 如需本地计算,声明 script: { path, timeoutMs, parameters }。脚本必须是 Python,参数以 JSON 从 stdin 传入,stdout 必须只输出一个 JSON 对象。在 index.html 中加载 <script src="./super-pi-tool.js"><\/script>,然后调用 SuperPiTool.run(params)、SuperPiTool.get(runId)、SuperPiTool.wait(runId) 或 SuperPiTool.cancel(runId)。这些都是已绑定本工具身份的相对接口;不要调用 /api/exec,不要猜测 toolId,也不要传 shell 命令、任意文件路径或未声明参数。页面必须实际执行一次示例任务并显示运行状态、日志和结构化结果。第三方包写进 environment.requires(必须钉死成 pkg==version),首次运行时会装进这个工具自己的虚拟环境。需要模型能力(摘要、改写、抽取、分类)时调用 SuperPiTool.llm({ prompt, system }),不要自己写模型客户端或保管密钥,并在注册时声明 permissions: { llm: true }——否则服务端会拒绝,导入页面也会提示用户。最后返回注册 id、访问地址、文件清单和验证结果。`);d(e),window.setTimeout(()=>d(!1),1800)};(0,V.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let I=(0,V.useMemo)(()=>[...t.map(e=>({id:e.id,name:e.name,glyph:e.glyph})),...n.map(e=>({id:e.id,name:e.name,glyph:`🧩`}))],[t,n]);(0,V.useEffect)(()=>{if(!M)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),N(void 0);return}if(vk(e.key)||Dk(e.target))return;e.preventDefault(),e.stopPropagation();let t=M;if(N(void 0),e.key===`Delete`||e.key===`Backspace`){qk.clearShortcut(t),F(void 0);return}let n=yk(e);if(!n){F(`没有认出这个按键,换一个试试。`);return}let i=Tk(n);if(!i.ok){F(i.reason);return}let a=jk(r,n,t);if(a){let e=I.find(e=>e.id===a)?.name;F(e?`这个组合键已经被「${e}」占用了,换一个键。`:`这个组合键已经被另一个工具占用了,换一个键。`)}else qk.setShortcut(t,n),F(void 0)};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[M,r,I]);let ie=e=>{ne(Bk(e,window.innerWidth,window.innerHeight))},ae=e=>{zk(e)},oe=()=>{ne(void 0),zk(void 0)},se=(0,V.useRef)(!1),ce=n.map(e=>e.slug).filter(e=>typeof e==`string`),le=e=>{p(void 0),h(void 0),k(void 0),D({tool:e,name:rA({slug:e.slug??`tool`})})},ue=async(e,t)=>{p(void 0),h(void 0),k(void 0);let n=iA(t);if(!n.ok)k(n.reason);else try{let t=await fetch(`/api/tools/export?id=${encodeURIComponent(e.id)}`),r=await t.json();if(!t.ok||!r.bundle)throw Error(r.error??`HTTP ${t.status}`);let i=new Blob([JSON.stringify(r.bundle,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n.name,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),h(r.skipped?.length?`已导出「${e.name}」,但有 ${r.skipped.length} 个文件没有包含:${r.skipped.join(`、`)}。`:`已导出「${e.name}」。`)}catch(e){p(`导出失败:${tp(e)}`)}finally{D(void 0)}},de=async e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;p(void 0),h(void 0),x(void 0);let n=eA(await t.text(),t.name);n.ok?(_({filename:t.name,bundle:n.bundle,unnamedFormat:n.unnamedFormat}),y(ce.includes(n.bundle.slug)?nA(n.bundle.slug,ce):n.bundle.slug),C(n.bundle.files[0]?.path)):p(n.reason)},fe=()=>{_(void 0),y(``),x(void 0),C(void 0)},pe=async()=>{if(!g)return;x(void 0);let e=tA(v);if(!e.ok)x(e.reason);else if(ce.includes(e.slug))x(`本机已经有 slug「${e.slug}」的工具,换一个名字再导入。`);else{T(!0);try{let t=await fetch(`/api/tools`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(lA(g.bundle,e.slug))}),n=await t.json();if(!t.ok||!n.id)throw Error(n.error??`HTTP ${t.status}`);await Jk(),h(`已导入「${g.bundle.name}」,它现在出现在工具栏里,所有工作区都能用。`),fe()}catch(e){p(`导入失败:${tp(e)}`)}finally{T(!1)}}};(0,V.useEffect)(()=>{E&&j.current?.scrollIntoView({block:`center`})},[E]);let L=()=>{let e=Cv(i);e.ok?t.length>=32?l(`工具最多 32 个,先删掉一个再加。`):(qk.setTools([...t,{id:Dv(`link`,t.map(e=>e.id)),kind:`link`,name:o.trim()||Gj(e.url),glyph:`↗`,url:e.url}]),a(``),s(``),l(void 0)):l(e.reason)},me=te?{width:`${te.width}px`,height:`${te.height}px`,maxWidth:`calc(100vw - 32px)`,maxHeight:`calc(100vh - 32px)`}:void 0;return(0,sa.createPortal)((0,H.jsxs)(`div`,{className:`tool-overlay`,"data-tool-settings-overlay":`1`,onPointerDown:()=>{se.current=!1},onClick:t=>{se.current?se.current=!1:t.target===t.currentTarget&&e()},children:[(0,H.jsxs)(`div`,{className:`tool-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`tool-settings-title`,"data-tool-settings":`1`,ref:ee,style:me,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsx)(`h2`,{className:`tool-dialog-title`,id:`tool-settings-title`,children:`⚙ 工具设置`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,"data-tool-settings-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭工具设置`,onClick:e,children:`✕`})]}),(0,H.jsx)(`div`,{className:`tool-dialog-body`,children:g?(0,H.jsx)(Wj,{pending:g,slugDraft:v,slugError:b,preview:S,busy:w,onSlugChange:e=>{y(e),x(void 0)},onPreviewChange:C,onCancel:fe,onConfirm:()=>void pe()}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`tool-prompt-card`,children:[(0,H.jsx)(`strong`,{children:`给 Agent 开发新工具`}),(0,H.jsx)(`p`,{className:`tool-hint`,children:`工具会挂载到 Super Pi 的统一 HTTP 服务,不需要再启动独立服务器。`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-link-copy-prompt`,"data-tool-development-prompt":`1`,onClick:()=>void re(),children:u?`已复制`:`复制工具开发 Prompt`})]}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`从预置列表添加`})}),(0,H.jsx)(`div`,{className:`tool-presets`,"data-tool-presets":_v.length,children:_v.map(e=>{let n=t.some(t=>t.kind===e.kind);return(0,H.jsxs)(`div`,{className:`tool-preset`,"data-tool-preset":e.kind,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:e.glyph}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{children:e.blurb})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-add-preset":e.kind,disabled:n,title:n?`${e.name}已经在工具栏里了`:`添加${e.name}`,"aria-label":n?`${e.name}已添加`:`添加${e.name}`,onClick:()=>qk.setTools(Ov(t,e.kind)),children:n?`已添加`:`添加`})]},e.kind)})}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`添加网址工具`})}),(0,H.jsx)(`p`,{className:`tool-hint`,children:`填一个网址,它会变成一个图标;点开后在弹窗里用按钮在新标签页打开。网址只接受 http / https / mailto。`}),(0,H.jsx)(`input`,{className:`tool-input`,"data-tool-url-input":`1`,value:i,maxLength:2048,placeholder:`https://example.com/工具`,"aria-label":`工具网址`,onChange:e=>{a(e.target.value),l(void 0)}}),(0,H.jsx)(`input`,{className:`tool-input`,"data-tool-url-name":`1`,value:o,maxLength:40,placeholder:`名称(可留空,默认用域名)`,"aria-label":`工具名称(可选)`,onChange:e=>s(e.target.value)}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-url-add":`1`,disabled:!i.trim(),onClick:L,children:`添加网址工具`}),c&&(0,H.jsx)(`p`,{className:`tool-error`,"data-tool-error":`1`,role:`alert`,children:c}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-scope-note":`1`,children:[`能自定义到哪:从上面挑预置工具,或自己填一个网址。`,(0,H.jsx)(`b`,{children:`没有开放「写一段脚本来执行」这一档`}),`——它在浏览器里等同于任意代码执行,会拿着本应用的权限跑。计算器是手写的算术解析器,不含 eval,也认不出变量名。`]}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`快捷键`})}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-shortcut-hint":`1`,children:[`给每个工具绑一个组合键,按下就直接打开它,不用先找到右侧栏。`,(0,H.jsx)(`b`,{children:`弹窗打开时快捷键不生效`}),`——模态弹窗期间键盘归它自己,关掉之后再按。`]}),(0,H.jsx)(`div`,{className:`tool-shortcuts`,"data-tool-shortcut-count":I.length,children:I.map(e=>(0,H.jsxs)(`div`,{className:`tool-shortcut-row`,"data-tool-shortcut-row":e.id,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:e.glyph}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{children:r[e.id]?`按 ${xk(r[e.id])} 打开`:`还没有快捷键`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-shortcut-set`,"data-tool-shortcut-set":e.id,"data-tool-shortcut-capturing":M===e.id?`1`:void 0,"aria-pressed":M===e.id,title:M===e.id?`按下想用的组合键(Esc 取消,Delete 清除)`:`点一下,然后按下想用的组合键`,onClick:()=>{F(void 0),N(M===e.id?void 0:e.id)},children:M===e.id?`按下组合键…`:r[e.id]?xk(r[e.id]):`未设置`}),r[e.id]&&(0,H.jsx)(`button`,{type:`button`,className:`tool-shortcut-clear`,"data-tool-shortcut-clear":e.id,title:`清除${e.name}的快捷键`,"aria-label":`清除${e.name}的快捷键`,onClick:()=>{qk.clearShortcut(e.id),F(void 0),N(void 0)},children:`清除`})]},e.id))}),P&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-shortcut-error":`1`,children:P}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsxs)(`h2`,{className:`rail-section-title`,children:[`已安装的全局工具(`,n.length,`)`]})}),n.length===0?(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-mounted-empty":`1`,children:`还没有通过 tool_register 注册的工具。上面复制那段 Prompt,让 Agent 写一个。`}):(0,H.jsx)(`div`,{className:`tool-presets`,"data-tool-mounted-list":n.length,children:n.map(e=>{let t=sA(e.environmentState);return(0,H.jsxs)(`div`,{className:`tool-share-row`,"data-tool-share-row":e.id,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:`🧩`}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{"data-tool-env":e.environmentState?.state??`unknown`,children:t?`${t.warn?`⚠ `:``}${t.text}${e.environmentState?.detail?` · ${e.environmentState.detail}`:``}`:`环境未知`}),e.permissions?.llm&&(0,H.jsx)(`small`,{"data-tool-model":`1`,children:`⚠ 会调用模型`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-export":e.id,title:`导出${e.name},得到一个可以发给别人导入的文件`,"aria-label":`导出${e.name}`,onClick:()=>le(e),children:`导出`})]},e.id)})}),E&&(0,H.jsxs)(`div`,{className:`tool-share-review`,ref:j,"data-tool-export-name":`1`,children:[(0,H.jsxs)(`h3`,{className:`tool-share-title`,children:[`导出「`,E.tool.name,`」`]}),(0,H.jsxs)(`label`,{className:`tool-hint`,children:[`文件名(发给别人的就是这个文件)`,(0,H.jsx)(`input`,{className:`tool-input`,value:E.name,"aria-label":`导出文件名`,"data-tool-export-input":`1`,onChange:e=>D({...E,name:e.target.value})})]}),O&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-export-name-error":`1`,children:O}),(0,H.jsxs)(`div`,{className:`tool-share-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-export-cancel":`1`,onClick:()=>{D(void 0),k(void 0)},children:`取消`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-export-confirm":`1`,onClick:()=>void ue(E.tool,E.name),children:`导出`})]})]}),m&&(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-share-notice":`1`,children:m}),f&&(0,H.jsx)(`p`,{className:`tool-error`,"data-tool-share-error":`1`,role:`alert`,children:f}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`从文件导入`})}),(0,H.jsxs)(`p`,{className:`tool-hint`,children:[`收到别人分享的工具文件(`,(0,H.jsx)(`code`,{children:Xk}),`)?导入后它出现在工具栏里,所有工作区都能用。`,(0,H.jsx)(`b`,{children:`导入前会先给你看这个包里有什么。`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-import-pick":`1`,onClick:()=>A.current?.click(),children:`选择文件…`}),(0,H.jsx)(`input`,{ref:A,type:`file`,accept:`.json,application/json`,style:{display:`none`},"data-tool-import-input":`1`,onChange:e=>void de(e)})]})})]}),(0,H.jsx)(Hj,{targetRef:ee,onResize:ie,onCommit:ae,onDragEnd:()=>{se.current=!0},onReset:oe})]}),document.body)}var Vj=18;function Hj({targetRef:e,onResize:t,onCommit:n,onDragEnd:r,onReset:i}){let[a,o]=(0,V.useState)(),s=(0,V.useRef)(void 0);return(0,V.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{let e=t.getBoundingClientRect();o({left:e.right-Vj,top:e.bottom-Vj})};n();let r=new ResizeObserver(n);return r.observe(t),window.addEventListener(`resize`,n),window.addEventListener(`scroll`,n,!0),()=>{r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`scroll`,n,!0)}},[e]),(0,H.jsx)(`div`,{className:`tool-dialog-grip`,"data-tool-settings-grip":`1`,role:`separator`,"aria-orientation":`vertical`,tabIndex:0,"aria-label":`调整工具设置弹窗大小:拖动或用方向键,Enter 恢复默认尺寸`,style:a?{left:`${a.left}px`,top:`${a.top}px`}:void 0,onPointerDown:i=>{i.preventDefault(),i.stopPropagation();let a=e.current;if(!a)return;let o=a.getBoundingClientRect(),c=o.left+o.width/2,l=o.top+o.height/2;s.current=void 0;let u=e=>{let n=Bk({width:2*(e.clientX-c),height:2*(e.clientY-l)},window.innerWidth,window.innerHeight);s.current=n,t(n)},d=()=>{window.removeEventListener(`pointermove`,u),window.removeEventListener(`pointerup`,d),window.removeEventListener(`pointercancel`,d),s.current&&(n(s.current),r())};window.addEventListener(`pointermove`,u),window.addEventListener(`pointerup`,d),window.addEventListener(`pointercancel`,d)},onDoubleClick:()=>i(),onKeyDown:r=>{if(r.key===`Enter`||r.key===` `){r.preventDefault(),i();return}let a=r.shiftKey?8:24,o=e.current?.getBoundingClientRect(),c=o?.width??Nk.width,l=o?.height??Nk.height;if(r.key===`ArrowRight`)c+=a;else if(r.key===`ArrowLeft`)c-=a;else if(r.key===`ArrowDown`)l+=a;else if(r.key===`ArrowUp`)l-=a;else return;r.preventDefault();let u=Bk({width:c,height:l},window.innerWidth,window.innerHeight);s.current=u,t(u),n(u)},onClick:e=>e.stopPropagation()})}function Uj(){let{tools:e,mountedTools:t,openToolId:n,settingsOpen:r,shortcuts:i}=Kk(),a=e.find(e=>e.id===n),o=t.find(e=>e.id===n);return(0,V.useEffect)(()=>{let n=n=>{if(!r&&!document.querySelector(`[aria-modal="true"]`)&&!(n.isComposing||n.defaultPrevented)){for(let[r,a]of Object.entries(i))if(Ok(a,n)&&(e.some(e=>e.id===r)||t.some(e=>e.id===r))){n.preventDefault(),qk.openTool(r);return}}};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[i,e,t,r]),(0,V.useEffect)(()=>{Jk();let e=()=>{Jk()};return window.addEventListener(`super-pi-tools-updated`,e),()=>window.removeEventListener(`super-pi-tools-updated`,e)},[]),(0,V.useEffect)(()=>{qk.persistTools()},[]),(0,H.jsxs)(H.Fragment,{children:[r&&(0,H.jsx)(Bj,{onClose:()=>qk.closeSettings()}),a&&(0,H.jsx)(Kj,{tool:a,onClose:()=>qk.closeTool()}),o&&(0,H.jsx)($j,{tool:o,onClose:()=>qk.closeTool()})]})}function Wj({pending:e,slugDraft:t,slugError:n,preview:r,busy:i,onSlugChange:a,onPreviewChange:o,onCancel:s,onConfirm:c}){let l=e.bundle,u=l.files.reduce((e,t)=>e+new TextEncoder().encode(t.content).length,0),d=oA(l),f=aA(l),p=l.files.find(e=>e.path===r)??l.files[0];return(0,H.jsxs)(`div`,{className:`tool-share-review`,"data-tool-import-review":`1`,children:[(0,H.jsx)(`h3`,{className:`tool-share-title`,"data-tool-import-name":`1`,children:l.name}),l.description&&(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-import-desc":`1`,children:l.description}),e.unnamedFormat&&(0,H.jsx)(`p`,{className:`tool-import-note`,"data-tool-import-unbranded":`1`,children:`这个文件没有 Super Pi 的工具标记,已按内容形状读取——粘出来的 tool_register 参数也认。`}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-import-files":`1`,children:[l.files.length,` 个文件 · 共 `,cA(u)]}),(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-import-paths":`1`,children:l.files.map(e=>e.path).join(` · `)}),l.script&&(0,H.jsxs)(`p`,{className:`tool-import-warn`,"data-tool-import-script":l.script.path,children:[(0,H.jsxs)(`b`,{children:[`⚠ 含 Python 脚本 `,l.script.path]}),(0,H.jsx)(`br`,{}),`导入后运行这个工具时,这段代码会在本机上执行,权限和你自己的 Python 一样(能读你的文件、能联网)。 可以先展开下面的文件列表把它读完。`]}),(0,H.jsxs)(`p`,{className:d.tone===`warn`?`tool-import-warn`:`tool-import-note`,"data-tool-import-env":d.tone,children:[(0,H.jsxs)(`b`,{children:[d.tone===`warn`?`⚠ `:`✓ `,d.text]}),l.environment?.fingerprint?.python&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`br`,{}),`导出方环境:Python `,l.environment.fingerprint.python,` · `,l.environment.fingerprint.platform||`未知平台`,`。版本对不上时会标出来,但不会拦住你运行。`]})]}),f&&(0,H.jsxs)(`p`,{className:`tool-import-warn`,"data-tool-import-model":`1`,children:[(0,H.jsx)(`b`,{children:`⚠ 这个工具可以调用模型`}),(0,H.jsx)(`br`,{}),f.text,`。模型由 Super Pi 通过 Pi 调用(凭据和模型选择都在 Super Pi 这边),工具只拿到文字。`]}),(0,H.jsxs)(`details`,{className:`tool-import-files`,"data-tool-import-filebox":l.files.length,children:[(0,H.jsxs)(`summary`,{children:[`查看文件(`,l.files.length,`)`]}),(0,H.jsx)(`div`,{className:`tool-share-tabs`,children:l.files.map(e=>(0,H.jsx)(`button`,{type:`button`,className:`tool-share-tab`,"aria-pressed":e.path===p?.path,"data-tool-import-file":e.path,onClick:()=>o(e.path),children:e.path},e.path))}),(0,H.jsx)(`pre`,{className:`tool-import-code`,"data-tool-import-code":p?.path,children:p?.content??``})]}),(0,H.jsxs)(`label`,{className:`tool-hint`,"data-tool-import-slug":`1`,children:[`导入后的 slug(工具的短名字,也是它在磁盘上的目录名)`,(0,H.jsx)(`input`,{className:`tool-input`,value:t,"aria-label":`导入后的 slug`,onChange:e=>a(e.target.value)})]}),n&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-import-slug-error":`1`,children:n}),(0,H.jsxs)(`div`,{className:`tool-share-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-import-cancel":`1`,onClick:s,children:`取消`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-import-confirm":`1`,disabled:i,onClick:c,children:i?`导入中…`:`导入`})]})]})}function Gj(e){let t=e.replace(/^[./]+/,``).slice(0,30).trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(e))return t||e.slice(0,30);try{return new URL(e,typeof window>`u`?`http://localhost`:window.location.href).hostname||t||e.slice(0,30)}catch{return e.slice(0,30)}}function Kj({tool:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`tool-overlay`,"data-tool-overlay":e.id,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`tool-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`tool-dialog-title`,"data-tool-dialog":e.id,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsxs)(`h2`,{className:`tool-dialog-title`,id:`tool-dialog-title`,children:[(0,H.jsx)(`span`,{className:`tool-dialog-glyph`,"aria-hidden":`true`,children:e.glyph}),e.name]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,"data-tool-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭${e.name}`,onClick:t,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`tool-dialog-body`,children:[e.kind===`calculator`&&(0,H.jsx)(Jj,{}),e.kind===`timestamp`&&(0,H.jsx)(Yj,{}),e.kind===`link`&&(0,H.jsx)(Xj,{tool:e})]})]})}),document.body)}function qj({image:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`lightbox-overlay`,"data-lightbox-overlay":`1`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`lightbox-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`lightbox-title`,"data-lightbox-dialog":`1`,children:[(0,H.jsxs)(`div`,{className:`lightbox-head`,children:[(0,H.jsx)(`h2`,{className:`lightbox-title`,id:`lightbox-title`,children:e.name||`图片大图`}),(0,H.jsx)(`button`,{type:`button`,className:`lightbox-close`,"data-lightbox-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭大图`,onClick:t,children:`✕`})]}),(0,H.jsx)(`div`,{className:`lightbox-body`,children:(0,H.jsx)(`img`,{src:e.url,alt:e.name||`图片大图`,className:`lightbox-image`})})]})}),document.body)}function Jj(){let[e,t]=(0,V.useState)(`12 * (3 + 4)`),n=Hv(e),r=e=>{t(t=>t+e)};return(0,H.jsxs)(`div`,{className:`tool-calc`,"data-tool-calc":`1`,children:[(0,H.jsx)(`input`,{className:`tool-input tool-calc-input`,"data-calc-input":`1`,value:e,maxLength:200,"aria-label":`算式`,spellCheck:!1,autoComplete:`off`,placeholder:`例如 (12 + 8) / 4`,onChange:e=>{t(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&e.preventDefault()}}),(0,H.jsx)(`div`,{className:`tool-calc-keys`,"data-calc-keys":`1`,children:[[`7`,`7`],[`8`,`8`],[`9`,`9`],[`÷`,`/`],[`(`,`(`],[`)`,`)`],[`4`,`4`],[`5`,`5`],[`6`,`6`],[`×`,`*`],[`^`,`^`],[`%`,`%`],[`1`,`1`],[`2`,`2`],[`3`,`3`],[`-`,`-`],[`←`,`back`],[`C`,`clear`],[`0`,`0`],[`.`,`.`],[`+`,`+`]].map(([e,n])=>(0,H.jsx)(`button`,{type:`button`,className:`tool-calc-key`,"data-calc-key":n,"aria-label":e===`C`?`清空`:e===`←`?`退格`:`输入 ${e}`,onClick:()=>{n===`clear`?t(``):n===`back`?t(e=>e.slice(0,-1)):r(n)},children:e},e))}),n.ok?(0,H.jsx)(`p`,{className:`tool-calc-result`,"data-calc-result":`1`,"data-calc-value":String(n.value),children:Uv(n.value)}):(0,H.jsx)(`p`,{className:`tool-calc-error`,"data-calc-error":`1`,role:`alert`,children:n.reason})]})}function Yj(){let[e,t]=(0,V.useState)(``),n=Wv(e),r=n.ok?Kv(n.ms):null;return(0,H.jsxs)(`div`,{className:`tool-stamp`,"data-tool-stamp":`1`,children:[(0,H.jsx)(`input`,{className:`tool-input`,"data-stamp-input":`1`,value:e,maxLength:64,spellCheck:!1,"aria-label":`时间戳或日期`,placeholder:`1757000000 或 2026-10-08T09:00:00`,onChange:e=>t(e.target.value)}),r?(0,H.jsxs)(`dl`,{className:`tool-stamp-out`,"data-stamp-result":`1`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`本地时间`}),(0,H.jsx)(`dd`,{"data-stamp-local":`1`,children:r.local})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`ISO(UTC)`}),(0,H.jsx)(`dd`,{"data-stamp-iso":`1`,children:r.iso})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`秒`}),(0,H.jsx)(`dd`,{"data-stamp-seconds":`1`,children:r.seconds})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`毫秒`}),(0,H.jsx)(`dd`,{"data-stamp-ms":`1`,children:r.milliseconds})]})]}):(0,H.jsx)(`p`,{className:`tool-stamp-error`,"data-stamp-error":`1`,role:`alert`,children:n.ok?`这个日期无法显示。`:n.reason})]})}function Xj({tool:e}){let[t,n]=(0,V.useState)(!1),r=async()=>{let e=await PA(`请为 Super Pi 开发一个全局右侧栏工具并自动挂载。不要启动独立 HTTP 服务器。通过内置 tool_register 提交完整的 HTML/JS/CSS 文件;工具将被 Super Pi 保存并在所有 workspace 可用。如需计算,注册一个 Python 脚本(不接受 shell 命令),参数经 JSON stdin 传入,stdout 只输出 JSON 结果。在页面里加载 ./super-pi-tool.js,使用 SuperPiTool.run(params)、wait(runId)、get(runId) 和 cancel(runId) 执行、等待、查看和取消任务。它们会自动绑定当前工具;不要调用 /api/exec,也不要猜测 toolId。`);n(e),window.setTimeout(()=>n(!1),1800)};return(0,H.jsxs)(`div`,{className:`tool-link`,"data-tool-link":e.id,children:[(0,H.jsx)(`p`,{className:`tool-hint`,children:`这是旧版外部网页链接;新工具由 Super Pi 统一托管,并可选绑定受控 Python 脚本。`}),(0,H.jsx)(`code`,{className:`tool-link-url`,"data-tool-link-url":e.id,children:e.url}),(0,H.jsxs)(`div`,{className:`tool-link-actions`,children:[(0,H.jsx)(`a`,{className:`tool-link-open`,"data-tool-link-open":e.id,href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:e.url,children:`在新标签页打开 ↗`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-link-copy-prompt`,"data-tool-copy-prompt":e.id,onClick:()=>void r(),children:t?`已复制`:`复制开发 Prompt`})]}),/^https?:\/\//i.test(e.url??``)&&(0,H.jsx)(`iframe`,{className:`tool-link-frame`,"data-tool-frame":e.id,src:e.url,title:e.name,sandbox:`allow-forms allow-modals allow-pointer-lock allow-popups allow-same-origin allow-scripts`,referrerPolicy:`no-referrer`})]})}var Zj=`(max-width: 1100px)`,Qj=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n));function $j({tool:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`tool-overlay`,"data-mounted-tool-overlay":e.id,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`tool-dialog`,"data-mounted-tool-dialog":e.id,role:`dialog`,"aria-modal":`true`,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsxs)(`h2`,{className:`tool-dialog-title`,children:[`🧩 `,e.name]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,onClick:t,children:`✕`})]}),(0,H.jsx)(`div`,{className:`tool-dialog-body`,children:(0,H.jsx)(`iframe`,{className:`tool-link-frame`,src:`/tools/${encodeURIComponent(e.id)}/`,title:e.name,sandbox:`allow-forms allow-modals allow-popups allow-scripts`,referrerPolicy:`no-referrer`})})]})}),document.body)}function eM(e,t,n){let r=Math.max(0,Math.round(n)-480),i=Qj(520,180,Math.max(180,r-240)),a=Qj(Math.round(e),180,i),o=Qj(640,240,Math.max(240,r-a));return{sidebar:a,rail:Qj(Math.round(t),240,o),sidebarMin:180,sidebarMax:i,railMin:240,railMax:o,sumCap:r}}var tM=`super-pi.rail-widths.v1`,nM=`super-pi.reader-state.v1`,rM=`super-pi.folded-groups.v1`;function iM(){try{if(typeof window>`u`)return{};let e=JSON.parse(window.localStorage.getItem(`super-pi.folded-groups.v1`)??`null`);if(!e||typeof e!=`object`)return{};let t=e=>{let t={};if(e&&typeof e==`object`)for(let[n,r]of Object.entries(e))typeof r==`boolean`&&(t[n]=r);return t};return{workspaces:t(e.workspaces),archived:t(e.archived)}}catch{return{}}}function aM(e){try{typeof window<`u`&&window.localStorage.setItem(rM,JSON.stringify(e))}catch{}}var oM=e=>{let t=document.querySelector(`[data-workspace-group="${CSS.escape(e)}"]`);return t?[...t.querySelectorAll(`.conversation-row[data-session-root]`)].map(e=>({id:e.dataset.sessionRoot??``,middle:(()=>{let t=e.getBoundingClientRect();return t.top+t.height/2})()})).filter(e=>e.id!==``):[]},sM=6,cM=400,lM=32,uM=48,dM=e=>{e.dataset.programmaticScroll=`true`,window.setTimeout(()=>{delete e.dataset.programmaticScroll},0)};function fM(e,t,n=!1,r=!1){let i=e.scrollHeight-e.clientHeight-e.scrollTop,a=n?!1:r?!0:t.followTail?i<=uM:i<=lM,o,s;if(!a){let t=e.getBoundingClientRect().top,n=[...e.querySelectorAll(`[data-transcript-key]`)].find(e=>e.getBoundingClientRect().bottom>t);o=n?.dataset.transcriptKey,s=n?n.getBoundingClientRect().top-t:void 0}return{followTail:a,scrollTop:e.scrollTop,...o?{anchorKey:o,anchorOffset:s}:{}}}function pM(){try{if(typeof window>`u`)return{conversations:{}};let e=JSON.parse(window.localStorage.getItem(`super-pi.reader-state.v1`)??`null`);if(!e||typeof e!=`object`)return{conversations:{}};let t={};if(e.conversations&&typeof e.conversations==`object`)for(let[n,r]of Object.entries(e.conversations)){let e=r;typeof e.followTail==`boolean`&&(t[n]={followTail:e.followTail,scrollTop:Number.isFinite(e.scrollTop)?Math.max(0,Number(e.scrollTop)):0,...typeof e.anchorKey==`string`?{anchorKey:e.anchorKey}:{},...Number.isFinite(e.anchorOffset)?{anchorOffset:Number(e.anchorOffset)}:{}})}let n={};if(e.readAt&&typeof e.readAt==`object`)for(let[t,r]of Object.entries(e.readAt))typeof r==`string`&&(n[t]=r);return{activeId:typeof e.activeId==`string`?e.activeId:void 0,workspaceId:typeof e.workspaceId==`string`?e.workspaceId:void 0,conversations:t,readAt:n}}catch{return{conversations:{}}}}function mM(e){try{typeof window<`u`&&window.localStorage.setItem(nM,JSON.stringify(e))}catch{}}var hM=`super-pi.session-tabs.v1`;function gM(e,t){if(!t||e.has(t))return e;let n=new Set(e);return n.add(t),n}function _M(e,t,n){let r=e.touched.has(t),i=e.touched;if(r){let r=new Set(e.touched);r.delete(t),n&&r.add(n),i=r}return{ids:e.ids.flatMap(e=>e===t?n?[n]:[]:[e]),previewId:e.previewId===t?n&&!r?n:void 0:e.previewId,emptied:e.emptied,touched:i}}function vM(){try{if(typeof window>`u`)return{ids:[]};let e=JSON.parse(window.sessionStorage.getItem(`super-pi.session-tabs.v1`)??`null`);if(!e||typeof e!=`object`)return{ids:[]};let t=e,n=Array.isArray(t.ids)?[...new Set(t.ids.filter(e=>typeof e==`string`))]:[],r=typeof t.previewId==`string`&&n.includes(t.previewId)?t.previewId:void 0,i=Array.isArray(t.touched)?[...new Set(t.touched.filter(e=>typeof e==`string`))]:[];return{ids:n,activeId:typeof t.activeId==`string`&&n.includes(t.activeId)?t.activeId:void 0,previewId:r,touched:i}}catch{return{ids:[]}}}function yM(e,t,n,r){try{if(typeof window>`u`)return;window.sessionStorage.setItem(hM,JSON.stringify({ids:e,...t&&e.includes(t)?{activeId:t}:{},...n&&e.includes(n)?{previewId:n}:{},...r&&r.length>0?{touched:r}:{}}))}catch{}}function bM(){try{if(typeof window>`u`)return{};let e=window.localStorage.getItem(tM);if(e===null)return{};let t=JSON.parse(e),n=e=>typeof e==`number`&&Number.isFinite(e)&&e>0?Math.round(e):void 0;return{sidebar:n(t.sidebar),rail:n(t.rail)}}catch{return{}}}function xM(e){try{if(typeof window>`u`)return;window.localStorage.setItem(tM,JSON.stringify(e))}catch{}}function SM({side:e,width:t,min:n,max:r,label:i,onWidth:a}){let[o,s]=(0,V.useState)(!1),c=e=>e.shiftKey?64:16;return(0,H.jsx)(`div`,{className:`rail-resizer rail-resizer-${e}${o?` rail-resizer-dragging`:``}`,"data-rail-resizer":e,"data-rail-resizer-dragging":o?`true`:`false`,"data-rail-resizer-width":t,role:`separator`,"aria-orientation":`vertical`,"aria-label":i,"aria-valuenow":t,"aria-valuemin":n,"aria-valuemax":r,tabIndex:0,onMouseDown:i=>{i.preventDefault(),i.currentTarget.focus();let o=i.clientX,c=t;s(!0);let l=document.body,u=l.style.cursor,d=l.style.userSelect;l.style.cursor=`col-resize`,l.style.userSelect=`none`;let f=t=>{let i=e===`left`?t.clientX-o:o-t.clientX;a(Qj(c+i,n,r))},p=()=>{l.style.cursor=u,l.style.userSelect=d,s(!1),window.removeEventListener(`mousemove`,f),window.removeEventListener(`mouseup`,p)};window.addEventListener(`mousemove`,f),window.addEventListener(`mouseup`,p)},onKeyDown:i=>{let o=c(i);i.key===`ArrowLeft`?(i.preventDefault(),a(Qj(e===`left`?t-o:t+o,n,r))):i.key===`ArrowRight`?(i.preventDefault(),a(Qj(e===`left`?t+o:t-o,n,r))):i.key===`Home`?(i.preventDefault(),a(n)):i.key===`End`&&(i.preventDefault(),a(r))}})}var CM=`super-pi.composer-height.v1`,wM=148,TM=.55,EM=()=>Math.max(wM,Math.round((typeof window>`u`?800:window.innerHeight)*TM)),DM=e=>{let t=Number.isFinite(e)?e:wM;return Math.round(Math.min(EM(),Math.max(wM,t)))},OM=()=>{try{let e=window.localStorage.getItem(CM);return e===null?wM:DM(Number(e))}catch{return wM}};function kM({height:e,onHeight:t}){let[n,r]=(0,V.useState)(!1),i=e=>e.shiftKey?64:16,a=EM();return(0,H.jsx)(`div`,{className:`composer-resize${n?` composer-resize-dragging`:``}`,"data-composer-resize":`1`,"data-composer-resize-dragging":n?`true`:`false`,"data-composer-height":e,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`调整消息编辑区高度`,"aria-valuenow":e,"aria-valuemin":wM,"aria-valuemax":a,tabIndex:0,onMouseDown:n=>{n.preventDefault(),n.currentTarget.focus();let i=n.clientY,a=e;r(!0);let o=document.documentElement,s=document.body.style.userSelect;document.body.style.cursor=`ns-resize`,document.body.style.userSelect=`none`;let c=e=>{let t=DM(a+(i-e.clientY));o.style.setProperty(`--composer-height`,`${t}px`)},l=()=>{document.body.style.cursor=``,document.body.style.userSelect=s;let n=Number.parseFloat(o.style.getPropertyValue(`--composer-height`));r(!1),window.removeEventListener(`mousemove`,c),window.removeEventListener(`mouseup`,l),t(Number.isFinite(n)?n:e)};window.addEventListener(`mousemove`,c),window.addEventListener(`mouseup`,l)},onKeyDown:n=>{let r=i(n);n.key===`ArrowUp`?(n.preventDefault(),t(DM(e+r))):n.key===`ArrowDown`?(n.preventDefault(),t(DM(e-r))):n.key===`Home`?(n.preventDefault(),t(wM)):n.key===`End`?(n.preventDefault(),t(a)):n.key===`PageUp`?(n.preventDefault(),t(DM(e+96))):n.key===`PageDown`&&(n.preventDefault(),t(DM(e-96)))}})}function AM(e,t,n){if(!e.length)return;let r=n?e.find(e=>e.workspaceId===n):void 0;if(r)return r;if(!(n&&t.some(e=>e.id===n)))return e[0]}function jM(){let[e,t]=(0,V.useState)(fA),n=(0,V.useCallback)(e=>{t(t=>{let n=typeof e==`function`?e(t):e;return pe(n,t)})},[]),[r,i]=(0,V.useState)([]),a=(0,V.useRef)([]),o=(0,V.useRef)(null);o.current||=pM();let s=(0,V.useRef)(null);s.current||=vM();let c=s.current,l=r.reduce((e,t)=>t.apply(e),e),[u,d]=(0,V.useState)(s.current.activeId??o.current.activeId),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(),[g,_]=(0,V.useState)(()=>iM().workspaces??{}),[v,y]=(0,V.useState)(o.current.workspaceId),[b,x]=(0,V.useState)(()=>({ids:c.ids,previewId:c.previewId,touched:new Set(c.touched??[]),emptied:!1})),S=b.ids,C=b.previewId,w=b.emptied===!0,[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(!1),[k,A]=(0,V.useState)(),j=(0,V.useRef)(null),M=(0,V.useRef)(void 0),N=(0,V.useRef)(o.current.conversations),P=(0,V.useRef)(S);P.current=S;let F=(0,V.useRef)(o.current.readAt??{}),[ee,te]=(0,V.useState)(0),ne=(0,V.useRef)(null),re=(0,V.useRef)(null),I=(0,V.useRef)(void 0),ie=(0,V.useRef)(!1),ae=(0,V.useRef)(!0),[oe,se]=(0,V.useState)({followTail:!0,scrollTop:0}),ce=(0,V.useRef)(!1),le=(0,V.useRef)(new Map),ue=(0,V.useRef)(void 0),de=(0,V.useRef)([]),fe=(0,V.useRef)(void 0),pe=(0,V.useCallback)((e,t)=>{let n=new Map(t.conversations.map(e=>[e.id,e]));return{...e,conversations:e.conversations.map(e=>{let t=n.get(e.id);if(e.messagesLoaded===!1||!t||t.messagesLoaded===!1||t.status!==`running`)return e;let r=new Map(t.messages.map(e=>[e.id,e]));return{...e,messages:e.messages.map(e=>{let t=r.get(e.id);return!t||!(t.content.length>e.content.length||(t.thinking?.length??0)>(e.thinking?.length??0))?e:{...e,content:t.content,thinking:t.thinking,thinkingActive:t.thinkingActive,thinkingBlocks:xA(t.thinkingBlocks,e.thinkingBlocks)}})}})}},[]),L=(0,V.useCallback)(()=>{if(fe.current!==void 0&&(cancelAnimationFrame(fe.current),fe.current=void 0),!de.current.length)return;let e=de.current;de.current=[];let t=new Map;for(let n of e){let e=`${n.conversationId}\u0000${n.messageId}`,r=t.get(e)??[];r.push(n),t.set(e,r)}n(e=>({...e,conversations:e.conversations.map(e=>{let n=e.messages.map(n=>{let r=t.get(`${e.id}\u0000${n.id}`);if(!r)return n;let i={...n};for(let e of r){if(e.type===`message.delta`){i.content+=e.delta;continue}if(i.thinkingActive=e.active,!e.delta)continue;let t=e.at??i.content.length,n=bA(i.thinkingBlocks??[],e,t);i={...i,thinking:(i.thinking??``)+e.delta,thinkingBlocks:n}}return i});return n.every((t,n)=>t===e.messages[n])?e:{...e,messages:n}})}))},[]),me=(0,V.useCallback)(e=>{let t=de.current,n=t.at(-1);n&&n.type===e.type&&n.conversationId===e.conversationId&&n.messageId===e.messageId&&(e.type!==`message.thinking`||n.type===`message.thinking`&&n.at===e.at&&n.active===e.active&&n.blockIndex===e.blockIndex)?t[t.length-1]={...e,delta:n.delta+e.delta}:t.push(e),fe.current===void 0&&(fe.current=requestAnimationFrame(L))},[L]),he=(0,V.useCallback)(e=>{ue.current=e},[]),[ge,_e]=(0,V.useState)(()=>iM().archived??{});(0,V.useEffect)(()=>{aM({workspaces:g,archived:ge})},[g,ge]);let[ve,ye]=(0,V.useState)(()=>ck());(0,V.useEffect)(()=>{lk(ve)},[ve]);let[be,xe]=(0,V.useState)(),Se=(0,V.useRef)(0),Ce=(0,V.useRef)(``),we=(e,t,n,r)=>{let i=(e.target instanceof Element?e.target:void 0)?.closest(`button`);if(i&&!i.classList.contains(`conversation`)||e.button!==0)return;let a=e.clientY,o=e.pointerType===`touch`,s=!1,c,l=[],u,d=!1,f=e=>{let t=l.filter(e=>e.id!==n);if(t.length===0){u=void 0,d=!1;return}let r=0;for(;r<t.length&&t[r].middle<e;)r+=1;r<t.length?(u=t[r].id,d=!1):(u=t[t.length-1].id,d=!0)},p=()=>xe(e=>e&&e.dropRootId===u&&e.dropAfter===d?e:{workspaceId:t,conversationId:n,dropRootId:u,dropAfter:d}),m=()=>{s||(s=!0,l=oM(t),f(a),document.body.style.userSelect=`none`,p())},h=e=>{if(!s){if(o){c!==void 0&&window.clearTimeout(c),c=void 0;return}if(Math.abs(e.clientY-a)<sM)return;m()}f(e.clientY),p()},g=e=>{if(window.removeEventListener(`pointermove`,h),window.removeEventListener(`pointerup`,_),window.removeEventListener(`pointercancel`,v),document.removeEventListener(`touchmove`,y),c!==void 0&&window.clearTimeout(c),document.body.style.userSelect=``,s&&e){let e=r.filter(e=>e!==n),i=u===void 0?e.length:d?e.indexOf(u)+1:e.indexOf(u);ye(e=>({...e,[t]:ok(r,n,i)})),Se.current=Date.now(),Ce.current=n}xe(void 0)},_=()=>g(!0),v=()=>g(!1),y=e=>{s&&e.preventDefault()};window.addEventListener(`pointermove`,h),window.addEventListener(`pointerup`,_),window.addEventListener(`pointercancel`,v),o&&(document.addEventListener(`touchmove`,y,{passive:!1}),c=window.setTimeout(m,cM))},[Te,Ee]=(0,V.useState)(()=>{if(typeof window>`u`)return``;try{return window.localStorage.getItem(`super-pi.user-nickname`)??``}catch{return``}}),De=e=>{let t=e.slice(0,24);Ee(t);try{window.localStorage.setItem(`super-pi.user-nickname`,t)}catch{}},Oe=Te.trim()||`你`,[ke,Ae]=(0,V.useState)(),[je,Me]=(0,V.useState)([]),[Ne,Pe]=(0,V.useState)([]),[Fe,Ie]=(0,V.useState)(new Map),[Le,Re]=(0,V.useState)(new Map),[ze,Be]=(0,V.useState)(),[Ve,He]=(0,V.useState)(),[Ue,We]=(0,V.useState)(),[Ge,Ke]=(0,V.useState)([]),[qe,Je]=(0,V.useState)([]),[Ye,Xe]=(0,V.useState)(),[Ze,Qe]=(0,V.useState)(),[$e,et]=(0,V.useState)(),[tt,nt]=(0,V.useState)(`idle`),[rt,it]=(0,V.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1100px)`).matches),[at,ot]=(0,V.useState)(`chat`),[st,ct]=(0,V.useState)(!1),[lt,ut]=(0,V.useState)(()=>typeof window>`u`?1440:window.innerWidth);(0,V.useEffect)(()=>{let e=()=>ut(window.innerWidth);return window.addEventListener(`resize`,e),e(),()=>window.removeEventListener(`resize`,e)},[]);let[dt,ft]=(0,V.useState)(bM),pt=eM(dt.sidebar??270,dt.rail??320,lt);(0,V.useEffect)(()=>{xM({sidebar:dt.sidebar??270,rail:dt.rail??320})},[dt.sidebar,dt.rail]);let mt=e=>ft(t=>({...t,sidebar:e})),ht=e=>ft(t=>({...t,rail:e})),[gt,_t]=(0,V.useState)(null);(0,V.useEffect)(()=>{_t(OM())},[]),(0,V.useEffect)(()=>{gt!==null&&document.documentElement.style.setProperty(`--composer-height`,`${gt}px`)},[gt]);let vt=e=>{let t=DM(e);_t(t);try{window.localStorage.setItem(CM,String(t))}catch{}};(0,V.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Zj),t=e=>{e.matches&&it(!0)};return e.addEventListener(`change`,t),e.matches&&it(!0),()=>e.removeEventListener(`change`,t)},[]);let yt=lt<=1100;(0,V.useEffect)(()=>{if(!yt||rt)return;let e=e=>{e.key===`Escape`&&(e.defaultPrevented||document.querySelector(`.tool-overlay, .lightbox-overlay, .quick-open-backdrop, .ctx-menu, .overlay, .picker-menu, .content-search-overlay`)||(e.preventDefault(),it(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[yt,rt]);let[bt,xt]=(0,V.useState)({}),[St,Ct]=(0,V.useState)({}),[wt,Tt]=(0,V.useState)({}),[Et,Dt]=(0,V.useState)(),[Ot,kt]=(0,V.useState)(()=>new Set),[At,jt]=(0,V.useState)(),[Mt,Nt]=(0,V.useState)(),Pt=(0,V.useRef)(new Map),[Ft,It]=(0,V.useState)({}),Lt=(0,V.useRef)(new Set),[Rt,zt]=(0,V.useState)([]),[Bt,Vt]=(0,V.useState)([]),[Ht,Ut]=(0,V.useState)(),[Wt,Gt]=(0,V.useState)(!1),Kt=(0,V.useRef)(null),qt=(0,V.useRef)(!1),Jt=(0,V.useRef)(0),Yt=(0,V.useRef)([]),Xt=(0,V.useRef)(void 0),Zt=(0,V.useRef)(!1),Qt=(0,V.useRef)(new Set),$t=(0,V.useRef)(new Set),en=(0,V.useRef)(new Map),tn=(0,V.useRef)(new Map),[nn,rn]=(0,V.useState)(()=>Date.now());(0,V.useEffect)(()=>{let e=window.setInterval(()=>rn(Date.now()),3e4);return()=>window.clearInterval(e)},[]);let an=(0,V.useMemo)(()=>l.conversations.filter(e=>!e.archivedAt),[l.conversations]),on=(0,V.useMemo)(()=>e.conversations.filter(e=>!e.archivedAt),[e.conversations]),sn=(0,V.useMemo)(()=>new Set(l.collapsedConversationIds??[]),[l.collapsedConversationIds]),R=(0,V.useMemo)(()=>{let e=an.find(e=>e.id===u);if(e)return e;if(!w)return AM(an,l.workspaces,v)},[w,u,an,v,l.workspaces]),cn=(0,V.useMemo)(()=>dA(R?.parentConversationId,R?.parentConversationId?l.conversations.find(e=>e.id===R.parentConversationId):void 0),[R,l.conversations]),ln=!!(R&&l.unlockedChildConversationIds?.includes(R.id)),un=cn&&!ln,dn=ne.current;if(dn){let e=dn.dataset.messageScrollContainer;e&&R?.id&&e!==R?.id&&dn.querySelector(`[data-transcript-key]`)&&(N.current[e]=fM(dn,N.current[e]??{followTail:!0,scrollTop:0}))}ae.current=R?.messagesLoaded!==!1,(0,V.useEffect)(()=>{if(!T||w||u&&on.some(e=>e.id===u)||u&&a.current.some(e=>e.temporaryId===u))return;let e=AM(an,l.workspaces,v);d(e?.id)},[w,u,on,an,T,v,l.workspaces]),(0,V.useEffect)(()=>{h(void 0)},[u,v]);let fn=(0,V.useMemo)(()=>l.workspaces.find(e=>e.id===v)??l.workspaces[0],[l.workspaces,v]),[pn,mn]=(0,V.useState)(``);(0,V.useEffect)(()=>{mn(``)},[fn?.id]);let hn=(0,V.useRef)(v);hn.current=v,(0,V.useEffect)(()=>{R&&y(R.workspaceId)},[R?.id]),(0,V.useEffect)(()=>{Xt.current=u},[u]),(0,V.useEffect)(()=>{I.current=R?.id},[R?.id]),(0,V.useEffect)(()=>{let e=R?.id;if(!e)return;let t=l.conversations.find(t=>t.id===e);if(!t)return;let n=F.current[e];F.current[e]=t.updatedAt,n!==t.updatedAt&&te(e=>e+1),mM({activeId:Xt.current,workspaceId:R?.workspaceId??v,conversations:N.current,readAt:F.current})},[R?.id,l.conversations]),(0,V.useEffect)(()=>{f&&u&&mM({activeId:u,workspaceId:R?.workspaceId??v,conversations:N.current,readAt:F.current})},[u,R?.workspaceId,f,v]),(0,V.useEffect)(()=>{let e=ne.current;if(!e||!R?.id||R.messagesLoaded===!1)return;let t=R.id;ce.current=!1;let n=N.current[t]??{followTail:!0,scrollTop:0};N.current[t]=n,se(n);let r=requestAnimationFrame(()=>{if(ne.current!==e)ie.current=!1;else{if(n.followTail)dM(e),e.scrollTop=e.scrollHeight;else{let t=n.anchorKey?e.querySelector(`[data-transcript-key="${CSS.escape(n.anchorKey)}"]`):null;e.scrollTop=t?Math.max(0,e.scrollTop+t.getBoundingClientRect().top-(n.anchorOffset??0)-e.getBoundingClientRect().top):n.scrollTop}ie.current=!1}});return()=>cancelAnimationFrame(r)},[R?.id,R?.messagesLoaded]),(0,V.useLayoutEffect)(()=>{ie.current=!0},[R?.id,R?.messagesLoaded]);let gn=(0,V.useCallback)((e,t=!1,n=!1)=>{let r=I.current;if(!r||ie.current||!ae.current)return;let i=fM(e,N.current[r]??{followTail:!0,scrollTop:0},t,n);ce.current=!i.followTail,N.current[r]=i,se(i),mM({activeId:r,workspaceId:hn.current,conversations:N.current,readAt:F.current})},[]),_n=Ft[R?.id??``]??{text:``,images:[],attachments:[],uploading:0},vn=_n.text,yn=_n.images,bn=_n.attachments,xn=_n.uploading,Sn=(e,t)=>It(n=>({...n,[e]:t(n[e]??{text:``,images:[],attachments:[],uploading:0})})),Cn=e=>Sn(R?.id??``,t=>({...t,text:e})),wn=e=>Sn(R?.id??``,t=>({...t,attachments:t.attachments.some(t=>t.kind===e.kind&&t.id===e.id)?t.attachments:[...t.attachments,e]})),Tn=(e,t)=>Sn(R?.id??``,n=>({...n,attachments:n.attachments.filter(n=>n.kind!==e||n.id!==t)})),[En,Dn]=(0,V.useState)({visible:!1,query:``,rect:null}),On=e=>Sn(R?.id??``,t=>({...t,images:typeof e==`function`?e(t.images):e})),kn=S.length>0?S:w?[]:R?[R.id]:[],An=(0,V.useMemo)(()=>kn.map(e=>an.find(t=>t.id===e)).filter(e=>e!==void 0),[kn,an]),jn=An.length>0;(0,V.useEffect)(()=>{if(!T)return;let e=new Set(an.map(e=>e.id));x(t=>{let n=t.ids.filter(t=>e.has(t)),r=t.previewId&&e.has(t.previewId)?t.previewId:void 0;return n.length===t.ids.length&&r===t.previewId?t:{...t,ids:n,previewId:r}})},[T,an]),(0,V.useEffect)(()=>{yM(S,u,C,[...b.touched])},[u,S,C,b.touched]);let Mn=(0,V.useCallback)(e=>{e&&x(t=>{if(t.touched.has(e))return t;let n=t.previewId===e?void 0:t.previewId;return{...t,previewId:n,touched:gM(t.touched,e)}})},[]),Nn=(0,V.useCallback)(e=>{d(e);let t=an.find(t=>t.id===e)?.workspaceId;t&&y(t),nr(`session`),x(t=>{let n=t.emptied===!0,r=n?{...t,emptied:!1}:t;if(r.ids.includes(e))return r;let i=!n&&r.ids.length===0&&R?.id&&R.id!==e?[R.id]:[],a=[...r.ids,...i];if(r.touched.has(e))return{...r,ids:[...a,e]};let o=r.previewId?a.indexOf(r.previewId):-1,s=o>=0?a.map((t,n)=>n===o?e:t):[...a,e];return{...r,ids:s,previewId:e}})},[R,an]),Pn=(0,V.useCallback)(e=>{e&&(Mn(e),Nn(e))},[Mn,Nn]),Fn=R?.workspaceId??v,In=R?.cwd??``,z=P_(Fn,In),Ln=(0,V.useRef)(z.setChangedFor),Rn=(0,V.useRef)(z.setIndex),zn=(0,V.useRef)(Fn);zn.current=Fn;let Bn=(0,V.useRef)(In);Bn.current=In,(0,V.useEffect)(()=>{Ln.current=z.setChangedFor},[z.setChangedFor]),(0,V.useEffect)(()=>{Rn.current=z.setIndex},[z.setIndex]);let[Vn,Hn]=(0,V.useState)(vj[0].id),[Un,Wn]=(0,V.useState)({}),Gn=(R?.id?Un[R.id]:void 0)??Vn,Kn=(0,V.useCallback)(e=>{Hn(e),R?.id&&Wn(t=>({...t,[R.id]:e}))},[R?.id]),[qn,Jn]=(0,V.useState)(!1),Yn=(0,V.useRef)(void 0),Xn=(0,V.useRef)(``);(0,V.useEffect)(()=>{Jn(!1),M.current?.readyState===WebSocket.OPEN&&M.current.send(JSON.stringify({type:`files.index.subscribe`}))},[Fn,In]);let[Zn,Qn]=(0,V.useState)(!1),[$n,er]=(0,V.useState)(),[tr,nr]=(0,V.useState)(`session`),[rr,ir]=(0,V.useState)(),[ar,or]=(0,V.useState)([]);(0,V.useEffect)(()=>{tr===`file`&&!z.active&&nr(`session`)},[tr,z.active]),(0,V.useEffect)(()=>{tr===`diff`&&!rr&&nr(`session`)},[tr,rr]);let sr=(0,V.useRef)(`${Fn??``}:${In}`);(0,V.useEffect)(()=>{let e=`${Fn??``}:${In}`;sr.current!==e&&(sr.current=e,or([]),ir(void 0),nr(`session`))},[Fn,In]),(0,V.useEffect)(()=>{z.restoredActive&&nr(`file`)},[z.restoredActive]);let cr=(0,V.useCallback)(e=>{or(t=>t.includes(e)?t:[...t,e]),ir(e),nr(`diff`),Hn(`files`)},[]),[lr,ur]=(0,V.useState)({diff:null,loading:!1,error:``}),[dr,fr]=(0,V.useState)(`server`);(0,V.useEffect)(()=>{if(tr!==`diff`||!rr||!Fn)return;let e=!0;return ur({diff:null,loading:!0,error:``}),fetch(`/api/files/diff?workspaceId=${encodeURIComponent(Fn)}&path=${encodeURIComponent(rr)}${In?`&cwd=${encodeURIComponent(In)}`:``}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{e&&ur({diff:t,loading:!1,error:``})}).catch(t=>{e&&ur({diff:null,loading:!1,error:t instanceof Error?t.message:`读取差异失败`})}),()=>{e=!1}},[tr,rr,Fn,In]);let pr=(0,V.useMemo)(()=>{if(!rr)return;let e=z.open.find(e=>e.path===rr);return e&&e.dirty?e.content:void 0},[rr,z.open]),mr=(0,V.useCallback)(e=>{z.setActivePath(e),nr(`file`),Hn(`files`)},[z.setActivePath]),hr=(0,V.useCallback)(async(e,t)=>{er(t?{workspaceId:v,path:e.path,line:t,request:Date.now()}:void 0),await z.openFile(e),nr(`file`)},[z.openFile,v]);(0,V.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.shiftKey&&e.key.toLowerCase()===`f`?(e.preventDefault(),Qn(!0)):(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`p`&&(e.preventDefault(),Yn.current=Fn,Xn.current=In,Jn(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Fn,In]);let gr=(0,V.useMemo)(()=>An.map(e=>({id:`session:${e.id}`,rawId:e.id,kind:`session`,label:e.title,title:e.title,closable:!0,preview:C===e.id,badge:(0,H.jsx)(Dj,{state:Ej(e,Tj(e,je),F.current[e.id])})})),[An,je,l.conversations,ee,C]),_r=(0,V.useMemo)(()=>z.open.map(e=>({id:`file:${e.path}`,rawId:e.path,kind:`file`,label:e.name,title:e.path,closable:!0,badge:e.dirty?(0,H.jsx)(`span`,{className:`file-tab-badge`,"data-file-tab-dirty":e.path,"aria-label":`未保存`,children:`●`}):void 0})),[z.open]),vr=(0,V.useMemo)(()=>ar.map(e=>({id:`diff:${e}`,rawId:e,kind:`diff`,label:e.split(/[\\/]/).pop()||e,title:`${e}(改动)`,closable:!0,icon:(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`±`})})),[ar]),yr=(0,V.useMemo)(()=>[...gr,..._r,...vr],[gr,_r,vr]),br=tr===`file`&&z.activePath?`file:${z.activePath}`:tr===`diff`&&rr?`diff:${rr}`:R?.id?`session:${R.id}`:void 0,xr=(0,V.useCallback)(e=>{if(e.startsWith(`file:`)){let t=e.slice(5);mr(t)}else if(e.startsWith(`diff:`)){let t=e.slice(5);ir(t),nr(`diff`)}else if(e.startsWith(`session:`)){let t=e.slice(8);Nn(t)}},[mr,Nn]),Sr=(0,V.useCallback)(e=>{e.startsWith(`session:`)&&Pn(e.slice(8))},[Pn]),Cr=(0,V.useCallback)(e=>{let t=kn.indexOf(e);if(t<0)return;let n=kn.filter(t=>t!==e);if(x(t=>({...t,ids:t.ids.filter(t=>t!==e),previewId:t.previewId===e?void 0:t.previewId,emptied:n.length===0||t.emptied})),R?.id!==e)return;let r=n[Math.min(t,n.length-1)];if(r)d(r);else if(z.open.length>0){let e=z.activePath&&z.open.some(e=>e.path===z.activePath)?z.activePath:z.open[0].path;z.setActivePath(e),nr(`file`)}else ar.length>0?(ir(ar[0]),nr(`diff`)):d(void 0)},[kn,R,z,ar]),wr=(0,V.useCallback)(e=>{if(e.startsWith(`file:`)){let t=e.slice(5);z.closeFile(t),z.activePath===t&&z.open.length<=1&&nr(`session`)}else if(e.startsWith(`diff:`)){let t=e.slice(5);or(e=>e.filter(e=>e!==t)),rr===t&&(ir(void 0),nr(`session`))}else if(e.startsWith(`session:`)){let t=e.slice(8);Cr(t)}},[z,Cr,rr]),Tr=z.active,Er=R?.id;(0,V.useEffect)(()=>{Er&&!Er.startsWith(`pending:`)&&jr({type:`conversation.select`,conversationId:Er})},[Er]);let B=(e,t=`info`)=>{if(!e)return;let n=++Jt.current;Pe(r=>[...r,{key:n,text:e,kind:t}]),Yt.current.push(window.setTimeout(()=>Pe(e=>e.filter(e=>e.key!==n)),7e3))};(0,V.useEffect)(()=>{let e=R?.id,t=R?.agentNotice;e&&t&&!Qt.current.has(e)&&(Qt.current.add(e),B(t,`info`))},[R?.id,R?.agentNotice]);let Dr=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n<0)return[t,...e];let r=[...e];return r[n]=t,r},Or=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n<0)return[t,...e];let r=[...e];return r[n]=t,r},kr=(e,t)=>{if(t.blocking)Me(n=>[...n.filter(n=>n.conversationId!==e||n.request.requestId!==t.requestId),{conversationId:e,request:t}]);else if(t.method===`notify`)B(t.message||t.title,t.notifyType??`info`);else if(t.method===`setStatus`){let e=t.statusKey??``;Ie(n=>{let r=new Map(n);return t.statusText===void 0?r.delete(e):r.set(e,t.statusText),r})}else if(t.method===`setWidget`){let e=t.widgetKey??``;Re(n=>{let r=new Map(n);return t.widgetLines===void 0?r.delete(e):r.set(e,{lines:t.widgetLines,placement:t.widgetPlacement??`aboveEditor`}),r})}else t.method===`setTitle`?Be(t.title):t.method===`set_editor_text`&&e===Xt.current&&Cn(t.text??``)},Ar=(e,t,n)=>{Me(n=>n.filter(n=>n.conversationId!==e||n.request.requestId!==t));let r=JA[n];r&&B(r,`warning`)};(0,V.useEffect)(()=>{let e=!1,t=0,r,s=()=>{if(e)return;let c=location.protocol===`https:`?`wss`:`ws`,l=new WebSocket(`${c}://${location.host}/ws?state=focused${Xt.current?`&conversationId=${encodeURIComponent(Xt.current)}`:``}`);M.current=l,l.onopen=()=>{if(!e){t=0,p(!0),l.send(JSON.stringify({type:`stream.configure`,coalesce:!0})),l.send(JSON.stringify({type:`catalog.fetch`,conversationId:Xt.current})),hn.current&&l.send(JSON.stringify({type:`prompt.catalog.fetch`,workspaceId:hn.current})),l.send(JSON.stringify({type:`catalog.fetchAll`})),l.send(JSON.stringify({type:`agent.catalog.fetch`})),l.send(JSON.stringify({type:`subagent.catalog.fetch`}));for(let e of a.current)e.retry&&e.command&&l.send(JSON.stringify({...e.command,operationRequestId:e.id}))}},l.onclose=n=>{if(e)return;Zt.current=!1;let o=rk(a.current);for(let e of o.failed)e.onFailure?.();if(a.current=o.retry,i(o.retry),p(!1),t===0){let e=n.reason?.trim()?`${n.reason.trim()}(code ${n.code})`:`code ${n.code}`;console.error(`[Super Pi Error] websocket closed:`,n.code,n.reason),B(`与 Super Pi 服务的连接断开,正在重连。(${e})`,`error`)}r=window.setTimeout(s,Math.min(NA,MA*2**t++))},l.onmessage=({data:t})=>{if(e)return;let r=JSON.parse(t);if(r.type!==`message.delta`&&r.type!==`message.thinking`&&L(),r.type===`exec.output`){let e=le.current.get(r.sessionId)??``;le.current.set(r.sessionId,(e+r.data).slice(-512e3)),le.current.size>64&&le.current.delete(le.current.keys().next().value),window.dispatchEvent(new CustomEvent(`super-pi-exec-output`,{detail:r}))}else if(r.type===`run.stopping`)kt(e=>{let t=new Set(e);return t.add(r.conversationId),t});else if(r.type===`exec.exit`)(r.stdout||r.stderr)&&le.current.set(r.sessionId,`${r.stdout}${r.stderr}`);else if(r.type.startsWith(`terminal.`))ue.current?.(r);else if(r.type===`conversation.autoRename.result`){let e=Pt.current.get(r.conversationId);e&&(Pt.current.delete(r.conversationId),r.ok?e.resolve(r.title):e.reject(Error(r.error)))}else if(r.type===`message.thinking`)me(r);else if(r.type===`state`){L(),Zt.current=!1;let e=Xt.current,t=!!(e&&$t.current.has(e)),s=!(!e||r.state.conversations.some(t=>t.id===e)),c=t&&s&&e&&en.current.has(e)?{...r.state,conversations:[en.current.get(e),...r.state.conversations]}:r.state;e&&!s&&($t.current.delete(e),en.current.delete(e)),a.current=a.current.filter(e=>!e.accepted?.(c)),i(a.current),kt(e=>{let t=new Set(e);for(let e of[...t]){let n=c.conversations.find(t=>t.id===e);(!n||n.status!==`running`&&n.status!==`waiting`)&&t.delete(e)}return t}),n(c),E(!0),p(!0),y(e=>{if(e&&(c.workspaces.some(t=>t.id===e)||a.current.some(t=>t.temporaryId===e)))return e;let t=o.current?.workspaceId;return t&&c.workspaces.some(e=>e.id===t)?t:c.workspaces[0]?.id})}else if(r.type===`message.delta`)me(r);else if(r.type===`message.revert.result`)oa(void 0),Dt(void 0),r.ok||(console.error(`[Super Pi Error] revert failed:`,r.message),h(r.message));else if(r.type===`operation.result`){let e=a.current.find(e=>e.id===r.requestId);if(a.current=a.current.filter(e=>e.id!==r.requestId),i(a.current),e?.temporaryId){let t=e.temporaryId;if(r.ok&&r.entityId){let e=r.entityId,i=tn.current.get(t);if(i&&en.current.set(e,{...i,id:e}),$t.current.add(e),i){let t={...i,id:e};n(n=>n.conversations.some(t=>t.id===e)?n:{...n,conversations:[t,...n.conversations]})}It(n=>{let r=n[t];if(!r)return n;let i=n[e],a={...n};return a[e]=i?{...i,text:r.text||i.text,images:r.images.length?r.images:i.images,attachments:r.attachments.length?r.attachments:i.attachments,uploading:r.uploading+i.uploading}:r,delete a[t],a}),tn.current.delete(t)}d(n=>n===t?r.ok?r.entityId:e.previousActiveId:n),x(e=>_M(e,t,r.ok&&r.entityId?r.entityId:void 0)),y(e=>e===t?r.ok?r.entityId:void 0:e)}if(!r.ok){console.error(`[Super Pi Error] operation failed:`,r.message),e?.onFailure?.(r.message);let t=r.message??`操作失败`;h(t),e?.onFailure||B(tp(t),`error`)}}else r.type===`tools.updated`?window.dispatchEvent(new Event(`super-pi-tools-updated`)):r.type===`files.changed`?Ln.current(r.workspaceId,r.changes,r.dropped):r.type===`files.index`?r.workspaceId===zn.current&&(r.cwd??``)===Bn.current&&Rn.current(r):r.type===`error`?(console.error(`[Super Pi Error]`,r.message),h(r.message),B(tp(r.message),`error`),Zt.current&&=!1):r.type===`extension.ui`?kr(r.conversationId,r.request):r.type===`extension.ui.closed`?Ar(r.conversationId,r.requestId,r.reason):r.type===`model.catalog`?(!r.conversationId||r.conversationId===Xt.current)&&He(r.catalog):r.type===`model.catalog.all`?We(r.catalog):r.type===`providers.list`?(Ke(r.providers),Je(r.apis)):r.type===`agent.catalog`?Xe(r.catalog):r.type===`prompt.catalog`?Ae(r.catalog):r.type===`subagent.catalog`?Qe(r.catalog):r.type===`server.version`?(et(r.version),r.version.needsRestart&&B(`检测到 Super Pi 代码已更新(v${r.version.runningVersion} → v${r.version.diskVersion}),请执行 /super_pi restart 重启服务生效`,`warning`)):r.type===`subagent.event`?n(e=>({...e,subagentRuns:Dr(e.subagentRuns??[],r.run)})):r.type===`workflow.event`?n(e=>({...e,workflows:Or(e.workflows??[],r.workflow)})):r.type===`message.tools`?n(e=>({...e,conversations:e.conversations.map(e=>e.id===r.conversationId?{...e,messages:e.messages.map(e=>e.id===r.messageId?{...e,toolCalls:r.toolCalls}:e)}:e)})):r.type===`conversation.fork.result`&&(pa(e=>e===r.conversationId?void 0:e),B(r.ok?`已从「${r.title}」分叉出新会话,放在侧边栏最上面;没有切换过去。${r.messagesCopied?`复制了 ${r.messagesCopied} 条消息。`:`原会话还没有消息,只复制了会话本身。`}`:`分叉失败:${tp(r.message)}`,r.ok?`info`:`error`))}};return s(),()=>{e=!0,L(),window.clearTimeout(r);for(let e of Yt.current)window.clearTimeout(e);M.current?.close()}},[me,L]);let jr=(0,V.useCallback)(e=>M.current?.readyState===WebSocket.OPEN&&(M.current.send(JSON.stringify(e)),!0),[]);(0,V.useEffect)(()=>{if(!f)return;let e=R?.id;e?.startsWith(`pending:`)||jr({type:`state.subscribe`,...e?{conversationId:e}:{}})},[R?.id,f,jr]),(0,V.useEffect)(()=>{if(f&&qn&&Fn&&Yn.current===Fn&&Xn.current===In)return jr({type:`files.index.subscribe`,workspaceId:Fn,...In?{cwd:In}:{}}),z.requestIndex(!0),()=>{jr({type:`files.index.subscribe`}),z.cancelIndexRequest()}},[f,qn,Fn,In,jr,z.requestIndex,z.cancelIndexRequest]);let Mr=(e,t,n,r,o,s,c)=>{let l=M.current?.readyState===WebSocket.OPEN,u=nk(e);if(a.current.some(e=>e.key===t)||!l&&!u)return!1;let d=Ev(),f={id:d,key:t,apply:n,temporaryId:r,previousActiveId:Xt.current,onFailure:o,accepted:s,...c?{expiresAt:Date.now()+c}:{},...u?{retry:!0,command:e}:{}};return a.current=[...a.current,f],i(a.current),l&&M.current.send(JSON.stringify({...e,operationRequestId:d})),!0},Nr=(0,V.useRef)(new Set),Pr=(e,t)=>{jr({type:`conversation.childLock`,conversationId:e,unlocked:t})?(gA(e,t),Nr.current.add(e)):B(t?`连接断开,这个子会话没有解锁,请重试`:`连接断开,这个子会话没有上锁,请重试`,`error`)};(0,V.useEffect)(()=>{if(!T||!f)return;let e=hA();if(e.size)for(let t of l.conversations){if(!e.has(t.id))continue;let n=t.parentConversationId?l.conversations.find(e=>e.id===t.parentConversationId):void 0;dA(t.parentConversationId,n)&&(l.unlockedChildConversationIds?.includes(t.id)||Nr.current.has(t.id)||(Nr.current.add(t.id),jr({type:`conversation.childLock`,conversationId:t.id,unlocked:!0})))}},[jr,f,T,l.conversations,l.unlockedChildConversationIds]);let Fr=e=>{if(!e)return;let t=`message_${Ev()}`;Mr({type:`message.send`,conversationId:e,content:RA,clientId:t},`continue-truncated:${e}`,e=>e,void 0,void 0,void 0)};(0,V.useEffect)(()=>{let e=r.flatMap(e=>e.expiresAt?[e.expiresAt]:[]);if(!e.length)return;let t=window.setTimeout(()=>{let e=a.current.filter(e=>e.expiresAt&&e.expiresAt<=Date.now());if(e.length){a.current=a.current.filter(t=>!e.includes(t)),i(a.current);for(let t of e)t.onFailure?.(`打断请求超时,尚未确认是否开始回答;请检查会话状态后重试`)}},Math.max(0,Math.min(...e)-Date.now()));return()=>window.clearTimeout(t)},[r]);let Ir=(e,t)=>n=>({...n,conversations:n.conversations.map(n=>n.id===e?{...n,...t}:n)}),Lr=(e,t)=>n=>({...n,workspaces:n.workspaces.map(n=>n.id===e?{...n,...t}:n)}),Rr=R?.id.startsWith(`pending:`)===!0,zr=!!(R&&Sj(R)&&(Ot.has(R.id)||r.some(e=>e.key===`stop:${R.id}`))),Br=R?.messagesLoaded===!1||r.some(e=>e.key.startsWith(`send:${R?.id}:`)||e.key===`configuration:${R?.id}`||e.temporaryId===R?.id||e.key===`archive:${R?.id}`),Vr=(e,t,n,r,i)=>{e&&M.current?.send(JSON.stringify({type:`question.answer`,conversationId:e,messageId:t,callIndex:n,answers:r,cancelled:i}))},Hr=(e,t,n)=>(Mn(e),Mr({type:`extension.ui.answer`,conversationId:e,requestId:t,...n},`answer:${e}:${t}`,e=>e)),Ur=R?.model??Ve?.defaultModel,Wr=R?.thinkingLevel??Ve?.defaultThinkingLevel,Gr=Ve?.source===`pi`,Kr=!!Ve?.models.find(e=>e.provider===Ur?.provider&&e.modelId===Ur?.modelId)?.imageInput,qr=(e,t)=>!e||!t?e:{...e,models:e.models.filter(e=>(l.modelFilterRules??[]).every(n=>{try{return!new RegExp(n.workspacePattern,`i`).test(t.name)||new RegExp(n.modelPattern,`i`).test(e.label)||new RegExp(n.modelPattern,`i`).test(`${e.provider}/${e.modelId}`)}catch{return!0}}))},Jr=!!R?.messages?.some(e=>e.images&&e.images.length>0),Yr=qr(Ve,l.workspaces.find(e=>e.id===R?.workspaceId))?.models??[],Xr=(Jr?Yr.filter(e=>e.imageInput):Yr).map(e=>({key:`${e.provider}/${e.modelId}`,label:e.label,detail:e.detail,badge:HA(e),selected:Ur?.provider===e.provider&&Ur.modelId===e.modelId})),Zr=(Ve?.levels??[]).map(e=>({key:e,label:e,selected:e===Wr})),Qr=e=>{if(!R)return;let[t,n]=e.split(`/`);t&&n&&(Mn(R.id),Mr({type:`conversation.model`,conversationId:R.id,provider:t,modelId:n},`configuration:${R.id}`,Ir(R.id,{model:Ve?.models.find(e=>e.provider===t&&e.modelId===n)??{provider:t,modelId:n,label:n}})))},$r=e=>{R&&(Mn(R.id),Mr({type:`conversation.thinking`,conversationId:R.id,level:e},`configuration:${R.id}`,Ir(R.id,{thinkingLevel:e})))},ei=Ye?.agents.find(e=>e.id===R?.agentId),ti=[{key:gj,label:`跟随 Pi 默认`,detail:`不使用任何 agent 角色`,selected:!R?.agentId},...(Ye?.agents??[]).map(e=>({key:e.id,label:e.name,detail:e.toolSummary,color:e.color,selected:R?.agentId===e.id}))],ni=ei?.model,ri=!!(ni&&R?.model&&R.model.provider===ni.provider&&R.model.modelId===ni.modelId);ei?.thinkingLevel&&(R?.thinkingLevel,ei.thinkingLevel);let ii=e=>{if(R){let t=Ye?.agents.find(t=>t.id===e);Mr({type:`conversation.agent`,conversationId:R.id,agentId:e===gj?null:e},`configuration:${R.id}`,Ir(R.id,{agentId:t?.id,...t?.model?{model:{...t.model,label:t.model.modelId}}:{},...t?.thinkingLevel?{thinkingLevel:t.thinkingLevel}:{}}))}},ai=je.filter(e=>e.conversationId===R?.id),oi=(0,V.useMemo)(()=>(l.subagentRuns??[]).filter(e=>e.conversationId===R?.id),[l.subagentRuns,R?.id]),si=(0,V.useMemo)(()=>(l.workflows??[]).filter(e=>e.conversationId===R?.id),[l.workflows,R?.id]),ci=(0,V.useMemo)(()=>new Map(si.map(e=>[e.id,e])),[si]),li=(0,V.useMemo)(()=>new Map((Ze?.agents??[]).map(e=>[e.id,e.name])),[Ze]),ui=(0,V.useMemo)(()=>new Map((R?.messages??[]).map(e=>[e.id,e])),[R?.messages]),di=(0,V.useMemo)(()=>new Map(oi.map(e=>[e.id,e])),[oi]),fi=(0,V.useMemo)(()=>{let e=new Map;for(let t of oi)t.originMessageId!==void 0&&t.originCallRow!==void 0&&e.set(`${t.originMessageId}:${t.originCallRow}`,t);return e},[oi]),pi=(0,V.useMemo)(()=>{if(!R||!jn)return[];let e=Et?.conversationId===R.id?(()=>{let e=R.messages.find(e=>e.id===Et.messageId);if(e)return{index:R.messages.indexOf(e),at:Date.parse(e.createdAt)||0,...Et.kind===`withdraw`?{inclusive:!0}:{inclusive:!1}}})():void 0,t=[];return R.messages.forEach((n,r)=>{e&&(r>e.index||e.inclusive&&r===e.index)||n.delivery||t.push({at:Date.parse(n.createdAt)||0,seq:r,key:`m:${n.id}`})}),oi.forEach((n,r)=>{n.originMessageId&&n.originCallRow!==void 0&&R?.messages.some(e=>e.id===n.originMessageId&&e.toolCalls?.[n.originCallRow])||e&&(Date.parse(n.startedAt)||0)>e.at||t.push({at:Date.parse(n.startedAt)||0,seq:t.length+r,key:`r:${n.id}`})}),si.forEach((n,r)=>{e&&(Date.parse(n.startedAt)||0)>e.at||t.push({at:Date.parse(n.startedAt)||0,seq:t.length+r,key:`w:${n.id}`})}),t.sort((e,t)=>e.at-t.at||e.seq-t.seq).map(e=>e.key)},[R,oi,si,Et]),mi=(0,V.useMemo)(()=>{for(let e=pi.length-1;e>=0;--e){let t=pi[e];if(t.startsWith(`m:`)&&ui.get(t.slice(2))?.role===`user`)return t.slice(2)}},[pi,ui]);(0,V.useEffect)(()=>{let e=ne.current;if(!e||!R?.id)return;let t=()=>{!ce.current&&N.current[R.id]?.followTail&&(dM(e),e.scrollTop=e.scrollHeight)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);n.observe(e);for(let t of e.children)n.observe(t);return()=>n.disconnect()},[R?.id,R?.messages,oi,si,jn,pi]);let hi=e=>xt(t=>({...t,[e]:!t[e]})),gi=(e,t)=>Ct(n=>({...n,[`${e}:${t}`]:!n[`${e}:${t}`]})),_i=(e,t)=>Tt(n=>({...n,[`${e}:${t}`]:n[`${e}:${t}`]!==!1})),[vi,yi]=(0,V.useState)({}),bi=e=>yi(t=>({...t,[e]:t[e]!==!0})),xi=e=>{Mr({type:`subagent.stop`,runId:e},`stop:${e}`,e=>e)||B(`连接断开,无法停止子智能体,请重试`,`error`)},Si=e=>{Mr({type:`workflow.stop`,workflowId:e},`stop:${e}`,e=>e)||B(`连接断开,无法停止编排,请重试`,`error`)},Ci=e=>[...Le].filter(([,t])=>t.placement===e).map(([e,t])=>{let n=t.lines;return(0,H.jsxs)(`div`,{className:`extui-widget`,"data-widget-key":e,"data-widget-lines":n.length,children:[n.slice(0,YA).map((e,t)=>(0,H.jsx)(`div`,{children:e},`${t}:${e}`)),n.length>YA&&(0,H.jsx)(`div`,{children:`… (widget truncated)`})]},e)}),wi=(e,t)=>{let n=`pending:${Ev()}`,r={id:n,name:e,path:t,updatedAt:new Date().toISOString()};Mr({type:`workspace.create`,name:e,path:t},`create-workspace`,e=>({...e,workspaces:[...e.workspaces,r]}),n)&&(y(n),d(void 0),O(!1))},[Ti,Ei]=(0,V.useState)(),Di=(e,t)=>Ei(n=>n?.kind===e&&n.id===t?n:{kind:e,id:t}),Oi=()=>Ei(void 0),ki=(e,t)=>Ti?.kind===e&&Ti.id===t,Ai=(e,t,n)=>!t.startsWith(`pending:`)&&(e===`conversation`&&Mn(t),Mr(e===`workspace`?{type:`workspace.rename`,workspaceId:t,name:n}:{type:`conversation.rename`,conversationId:t,name:n},`rename:${t}`,e===`workspace`?Lr(t,{name:n}):Ir(t,{title:n}))?(Zt.current=!0,Oi(),!0):(B(`连接断开,改名未保存,请重试`,`error`),!1)),ji=async e=>{if(e.startsWith(`pending:`)){B(`这个会话还在创建中,稍后再试`,`warning`);return}if(Pt.current.has(e))return;B(`正在根据对话内容生成标题…`,`info`);let t=new Promise((t,n)=>{Pt.current.set(e,{resolve:t,reject:n}),window.setTimeout(()=>{Pt.current.delete(e)&&n(Error(`模型在 30 秒内没有返回标题`))},32e3)});if(!jr({type:`conversation.autoRename`,conversationId:e}))Pt.current.delete(e),B(`连接断开,无法生成标题`,`error`);else try{let n=await t;Ai(`conversation`,e,n),B(`已重命名为「${n}」`,`info`)}catch(e){B(`重命名失败:${tp(e)}`,`error`)}},Mi=e=>{if(e.id.startsWith(`pending:`))return;let t=l.conversations.filter(t=>t.workspaceId===e.id).length;window.confirm(`从列表移除工作区「${e.name}」?${t?`其中的 ${t} 条会话会保留,`:``}重新添加同一个目录即可恢复,不会删除任何会话。`)&&Mr({type:`workspace.delete`,workspaceId:e.id},`delete:${e.id}`,t=>({...t,workspaces:t.workspaces.filter(t=>t.id!==e.id),conversations:t.conversations.filter(t=>t.workspaceId!==e.id)}))},[Ni,Pi]=(0,V.useState)(),Fi=Ni?l.workspaces.find(e=>e.id===Ni):void 0,{theme:Ii,setTheme:Li}=ny(),[Ri,zi]=(0,V.useState)(!1),[Bi,Vi]=(0,V.useState)(!1),Hi=(e,t,n,r)=>{e.startsWith(`pending:`)||(Mr({type:`workspace.settings`,workspaceId:e,model:n?{provider:n.provider,modelId:n.modelId}:null,thinkingLevel:r??null,agentId:t??null},`defaults:${e}`,Lr(e,{defaultModel:n,defaultThinkingLevel:r,defaultAgentId:t}))?Pi(void 0):B(`连接断开,设置未保存,请重试`,`error`))},Ui=(e,t=``)=>{if(e.startsWith(`pending:`))return;if(a.current.some(t=>t.key===`defaults:${e}`)){B(`工作区设置正在保存,请稍后再新建会话`,`warning`);return}let n=`pending:${Ev()}`,r={id:n,workspaceId:e,title:`新会话`,status:`idle`,updatedAt:new Date().toISOString(),messages:[],...t?{cwd:t}:{}};tn.current.set(n,r),Mr({type:`conversation.create`,workspaceId:e,...t?{cwd:t}:{}},`create-session:${e}:${n}`,e=>({...e,conversations:[r,...e.conversations]}),n)?(y(e),d(n),nr(`session`),x(e=>({...e,ids:[...e.ids.filter(e=>e!==n),n],touched:gM(e.touched,n)}))):(tn.current.delete(n),B(`连接断开,会话未创建,请重试`,`error`))},Wi=e=>{if(e.startsWith(`pending:`))return;let t=l.conversations.find(t=>t.id===e);if(!t||t.archivedAt||t.parentConversationId&&l.conversations.some(e=>e.id===t.parentConversationId))return;let n=AA(l.conversations,e),r=n.filter(e=>!e.archivedAt),i=r.length-1,a=n.length-r.length;if(i>0&&!window.confirm(`归档整棵会话树「${t.title}」?本次将归档 ${r.length} 个会话(1 个根会话和 ${i} 个活跃子孙)${a?`,跳过 ${a} 个已归档子孙`:``};恢复根会话时,整棵树会一起恢复。`))return;let o=new Date().toISOString(),s=new Set(r.map(e=>e.id));Mr({type:`conversation.archive`,conversationId:e},`archive:${e}`,e=>({...e,conversations:e.conversations.map(e=>s.has(e.id)&&!e.archivedAt?{...e,archivedAt:o}:e)}))},Gi=(e,t)=>Mr({type:`conversation.collapse`,conversationId:e,collapsed:t},`collapse:${e}`,n=>{let r=new Set(n.collapsedConversationIds??[]);t?r.add(e):r.delete(e);let i={...n};return r.size===0?delete i.collapsedConversationIds:i.collapsedConversationIds=[...r],i}),Ki=e=>{let t=l.conversations.find(t=>t.id===e);if(!t?.archivedAt||(t.parentConversationId?l.conversations.find(e=>e.id===t.parentConversationId):void 0)?.archivedAt)return;let n=new Set(AA(l.conversations,e).filter(e=>e.archivedAt).map(e=>e.id));Mr({type:`conversation.unarchive`,conversationId:e},`unarchive:${e}`,e=>({...e,conversations:e.conversations.map(e=>{if(!n.has(e.id)||!e.archivedAt)return e;let t={...e};return delete t.archivedAt,t})}))},qi=async e=>{if(!R){B(`请先选择或创建会话`,`error`);return}if(!Kr){B(`当前模型不支持图片输入`,`error`);return}let t=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],n=e.filter(e=>t.includes(e.type)?e.size>5242880?(B(`图片「${e.name}」超过 5MB 上限`,`error`),!1):!0:(B(`不支持的文件格式「${e.name}」,仅支持 PNG/JPEG/GIF/WebP`,`error`),!1));if(n.length===0)return;let r=R.id;Sn(r,e=>({...e,uploading:e.uploading+n.length}));let i=n.map(e=>({id:Ev(),conversationId:r,name:e.name,url:URL.createObjectURL(e)}));Vt(e=>[...e,...i]);for(let[e,t]of n.entries()){let n=i[e];try{let e=await new Promise((e,n)=>{let r=new FileReader;r.onload=()=>{let t=r.result,n=t.indexOf(`,`);e(n>=0?t.slice(n+1):t)},r.onerror=n,r.readAsDataURL(t)}),i=await fetch(`/api/upload`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({conversationId:r,name:t.name,mimeType:t.type,data:e})});if(!(i.headers.get(`content-type`)??``).includes(`application/json`)){B(`服务器未返回 JSON 响应,请刷新或重启服务`,`error`);continue}if(i.ok){let e=await i.json();if(Lt.current.has(n.id))continue;Vt(e=>e.filter(e=>e.id!==n.id)),URL.revokeObjectURL(n.url),Sn(r,t=>({...t,images:[...t.images,{id:e.id,name:e.name,mimeType:e.mimeType,bytes:e.bytes}]}))}else{let e=await i.json().catch(()=>({error:`上传失败`}));B(tp(e.error,`上传失败(HTTP ${i.status})`),`error`)}}catch(e){B(`上传失败:${tp(e,`网络或服务暂时不可用`)}`,`error`)}finally{Vt(e=>e.map(e=>e.id===n.id?{...e,failed:!0}:e)),Sn(r,e=>({...e,uploading:Math.max(0,e.uploading-1)}))}}},Ji=e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r.type.startsWith(`image/`)){let e=r.getAsFile();e&&n.push(e)}}if(n.length>0){if(!Kr){B(`当前模型不支持图片输入`,`error`);return}e.preventDefault(),qi(n)}},Yi=e=>{e.dataTransfer?.types?.includes(`Files`)&&(e.preventDefault(),Gt(!0))},Xi=e=>{e.currentTarget.contains(e.relatedTarget)||Gt(!1)},Zi=e=>{Gt(!1);let t=Array.from(e.dataTransfer?.files??[]).filter(e=>e.type.startsWith(`image/`));if(t.length>0){if(e.preventDefault(),!Kr){B(`当前模型不支持图片输入`,`error`);return}qi(t)}},Qi=e=>{if(e.preventDefault(),!R)return;if(un){B(uA,`warning`);return}if(Br){B(Rr?`会话正在创建,请稍候再发送`:R.messagesLoaded===!1?`正在加载会话,请稍候再发送`:`正在保存配置,请稍候再发送`,`info`);return}if(!vn.trim()&&yn.length===0)return;if(yn.length>0&&!Kr){B(`当前模型不支持图片输入,请移除图片或切换至支持图文的模型`,`error`);return}if(xn>0){B(`图片正在上传中,请稍候…`,`info`);return}let t=`message_${Ev()}`,n=R.id,r=vn,i=yn,a=bn;Mn(n),Mr({type:`message.send`,conversationId:n,content:vn,clientId:t,...yn.length>0?{images:yn}:{},...bn.length>0?{attachments:bn}:{}},`send:${n}:${t}`,e=>{let a=e.conversations.find(e=>e.id===n);if(!a||a.messages.some(e=>e.id===t))return e;let o=a.status===`running`||a.status===`waiting`,s=new Date().toISOString();return{...e,conversations:e.conversations.map(e=>e.id===n?{...e,...o?{}:{status:`waiting`,updatedAt:s},messages:[...e.messages,{id:t,role:`user`,content:r,...i.length>0?{images:i}:{},...bn.length>0?{attachments:bn}:{},...o?{delivery:`waiting`}:{},createdAt:s}]}:e)}},t,e=>{zt(o=>[...o,{id:t,conversationId:n,content:r,images:i,attachments:a,reason:e}]),Sn(n,e=>e.text||e.images.length||e.attachments.length?e:{...e,text:r,images:i,attachments:a})},e=>!!e.conversations.find(e=>e.id===n)?.messages.some(e=>e.id===t))?Sn(R.id,e=>({...e,text:``,images:[]})):B(`这条消息已经在发送队列中,请稍候`,`info`)},$i=(0,V.useMemo)(()=>(R?.messages??[]).filter(e=>(e.role===`user`||e.role===`tool`)&&e.delivery),[R?.messages]),ea=e=>{Mr({type:`message.cancel`,conversationId:R?.id??``,messageId:e},`queue:${e}`,t=>({...t,conversations:t.conversations.map(t=>t.id===R?.id?{...t,messages:t.messages.filter(t=>t.id!==e)}:t)}))||B(`连接断开,撤回没有生效,请重试`,`error`)},ta=e=>{Mr({type:`message.steer`,conversationId:R?.id??``,messageId:e},`queue:${e}`,t=>({...t,conversations:t.conversations.map(t=>t.id===R?.id?{...t,messages:_A(t.messages,e,0)}:t)}),void 0,void 0,t=>t.conversations.find(e=>e.id===R?.id)?.messages.find(t=>t.id===e)?.delivery===`sending`)||B(`连接断开,插到最前没有生效,请重试`,`error`)},na=e=>{let t=R?.id;t&&(M.current?.readyState===WebSocket.OPEN?Mr({type:`message.interrupt`,conversationId:t,messageId:e},`interrupt:${t}:${e}`,e=>e,void 0,e=>B(e??`打断失败,请重试`,`error`),n=>{let r=n.conversations.find(e=>e.id===t)?.messages.find(t=>t.id===e);return!(!r||r.delivery)},3e4)||B(`正在打断,请稍候`,`info`):B(`连接断开,打断没有生效,请重试`,`error`))},ra=e=>{Mr({type:`message.sendQueued`,conversationId:R?.id??``,messageId:e},`send-queued:${e}`,e=>e,void 0,void 0,t=>!t.conversations.find(e=>e.id===R?.id)?.messages.find(t=>t.id===e)?.delivery)||B(`连接断开,发送没有生效,请重试`,`error`)},ia=(e,t)=>{Mr({type:`message.edit`,conversationId:R?.id??``,messageId:e,content:t},`edit:${e}`,n=>({...n,conversations:n.conversations.map(n=>n.id===R?.id?{...n,messages:n.messages.map(n=>n.id===e?{...n,content:t}:n)}:n)}))||B(`连接断开,修改没有生效,请重试`,`error`)},[aa,oa]=(0,V.useState)(),sa=(e,t=!1)=>{if(!R||R.messagesLoaded===!1||aa)return;let n=R.messages.find(t=>t.id===e);n&&(n&&It(e=>{let t=e[R.id]??{text:``,images:[],attachments:[],uploading:0};return t.text.trim()||t.images.length||t.attachments.length?e:{...e,[R.id]:{...t,text:n.content,images:n.images??[]}}}),Dt({conversationId:R.id,messageId:e,kind:t?`withdraw`:`revert`})),jr({type:`message.revert`,conversationId:R.id,messageId:e,withdraw:t})?oa(e):(Dt(void 0),B(`连接断开,回退未执行,请重试`,`error`))},[ca,la]=(0,V.useState)(),ua=(0,V.useRef)(void 0),da=async(e,t)=>{ua.current&&clearTimeout(ua.current);let n=await PA(t);la({id:e,kind:n?`copied`:`error`}),n||B(`复制失败:浏览器拒绝了剪贴板写入,可以手动选中这条消息的文字复制`,`error`),ua.current=setTimeout(()=>la(void 0),2e3)};(0,V.useEffect)(()=>()=>{ua.current&&clearTimeout(ua.current)},[]);let[fa,pa]=(0,V.useState)(),ma=e=>{fa||e.startsWith(`pending:`)||(Mn(e),jr({type:`conversation.fork`,conversationId:e})?pa(e):B(`连接断开,分叉没有执行,请重试`,`error`))},ha=new Map;for(let e of l.scheduledTasks??[])e.conversationId&&!ha.has(e.conversationId)&&ha.set(e.conversationId,e);return(0,H.jsxs)(`main`,{className:`shell${rt?` shell-rail-collapsed`:``} mobile-panel-${at}${st?` mobile-drawer-open`:``}`,"data-rail-collapsed":rt,"data-selected-workspace":v??``,style:{"--sidebar-width":`${pt.sidebar}px`,"--rail-col":rt?void 0:`${pt.rail}px`},children:[(0,H.jsxs)(`aside`,{children:[(0,H.jsxs)(`div`,{className:`brand`,children:[(0,H.jsx)(`span`,{children:`π`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`strong`,{children:`SUPER PI`}),(0,H.jsx)(`small`,{children:`agent workspace`})]})]}),(0,H.jsx)(`div`,{className:`sidebar-actions`,children:(0,H.jsx)(`button`,{className:`workspace-new`,onClick:()=>O(!0),children:`+ 工作区`})}),(0,H.jsx)(`div`,{className:`label label-desktop`,children:`工作区`}),(0,H.jsx)(`div`,{className:`label label-phone`,children:`会话`}),(0,H.jsx)(`nav`,{children:l.workspaces.map(e=>{let t=l.conversations.filter(t=>t.workspaceId===e.id),n=t.filter(e=>!e.archivedAt),r=uk(n,sn,{manualRoots:ve[e.id]}),i=r.filter(e=>e.depth===0).map(e=>e.conversation.id),a=t.filter(e=>e.archivedAt),o=uk(a,new Set),s=g[e.id]??!1,c=ge[e.id]??!0;return(0,H.jsxs)(`section`,{className:`workspace-group`,"data-workspace-group":e.id,children:[(0,H.jsx)(`div`,{className:`workspace-header`,children:ki(`workspace`,e.id)?(0,H.jsx)(mj,{initial:e.name,label:`重命名工作区 ${e.name}`,onCommit:t=>Ai(`workspace`,e.id,t),onClose:Oi}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{className:`workspace-toggle`,"aria-expanded":!s,title:e.path,onContextMenu:t=>{t.preventDefault();let n=t.currentTarget.getBoundingClientRect();jt({workspace:e,x:t.clientX||n.left+24,y:t.clientY||n.top+n.height})},onClick:()=>{let t=an.find(t=>t.workspaceId===e.id)?.id;y(e.id),d(t),_(t=>({...t,[e.id]:!s}))},children:[(0,H.jsx)(`span`,{className:`chevron chevron-folder`,"aria-hidden":`true`,children:s?`📁`:`📂`}),(0,H.jsxs)(`span`,{children:[(0,H.jsx)(`strong`,{onDoubleClick:()=>Di(`workspace`,e.id),children:e.name}),(0,H.jsx)(`small`,{children:e.path})]})]}),(0,H.jsx)(`button`,{className:`workspace-add`,title:`在此工作区新建会话`,onClick:t=>{j.current=t.currentTarget,A({workspaceId:e.id})},children:`+`}),(0,H.jsx)(`button`,{className:`workspace-settings`,title:`工作区设置(默认智能体 / 模型 / 思考强度)`,"aria-label":`工作区设置 ${e.name}`,onClick:()=>Pi(e.id),children:`⚙`}),(0,H.jsx)(`button`,{className:`workspace-delete`,title:`从列表移除工作区(会话保留,重新添加同一目录即可恢复)`,onClick:()=>Mi(e),children:`×`})]})}),!s&&(r.length?r.map(({conversation:t,depth:r,childCount:a,isLastSibling:o})=>(0,H.jsxs)(`div`,{className:`conversation-row`,style:{"--tree-depth":r},"data-session-root":r===0?t.id:void 0,"data-session-dragging":be?.conversationId===t.id?`true`:void 0,"data-session-drop":be?.dropRootId===t.id?be.dropAfter?`after`:`before`:void 0,onPointerDown:r===0?n=>we(n,e.id,t.id,i):void 0,children:[a>0?(0,H.jsxs)(`button`,{type:`button`,className:`conversation-tree-toggle`,"data-tree-toggle":t.id,"aria-expanded":!sn.has(t.id),title:sn.has(t.id)?`展开 ${a} 个子会话`:`折叠 ${a} 个子会话`,"aria-label":sn.has(t.id)?`展开会话 ${t.title} 的 ${a} 个子会话`:`折叠会话 ${t.title} 的 ${a} 个子会话`,onClick:()=>Gi(t.id,!sn.has(t.id)),children:[(0,H.jsx)(`span`,{className:`chevron`,"aria-hidden":`true`,children:sn.has(t.id)?`▸`:`▾`}),(0,H.jsx)(`small`,{children:a})]}):(0,H.jsx)(`span`,{className:`conversation-tree-spacer`,"aria-hidden":`true`}),ki(`conversation`,t.id)?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(mj,{initial:t.title,label:`重命名会话 ${t.title}`,onCommit:e=>Ai(`conversation`,t.id,e),onClose:Oi}),(0,H.jsx)(`small`,{className:`conversation-time`,children:kA(t.updatedAt,nn)})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{className:`conversation ${R?.id===t.id?`selected`:``}`,"data-conversation":t.id,"data-tree-child":r>0?`true`:void 0,"data-tree-last":r>0&&o?`true`:void 0,title:r>0?`${t.title}(由「${n.find(e=>e.id===t.parentConversationId)?.title??`已不存在的会话`}」创建)`:t.title,"aria-label":`打开会话 ${t.title}${kj(t,ha.get(t.id))}`,onContextMenu:e=>{e.preventDefault();let n=e.currentTarget.getBoundingClientRect();Nt({conversation:t,x:e.clientX||n.left+24,y:e.clientY||n.top+n.height})},onClick:()=>{t.id===Ce.current&&Date.now()-Se.current<300||(Nn(t.id),y(e.id),ct(!1))},onDoubleClick:()=>{Pn(t.id)},children:[(0,H.jsx)(`i`,{className:`conversation-mark`,children:(0,H.jsx)(Dj,{state:Ej(t,Tj(t,je),F.current[t.id])})}),(0,H.jsx)(`span`,{"data-conversation-title":t.id,onDoubleClick:e=>{e.stopPropagation(),Di(`conversation`,t.id)},style:{flex:`0 1 auto`},children:t.title}),(0,H.jsx)(`span`,{className:`conversation-title-gap`,"aria-hidden":`true`,style:{marginLeft:`-8px`}}),Oj(t,ha.get(t.id)),(0,H.jsx)(`small`,{children:kA(t.updatedAt,nn)})]}),(0,H.jsx)(`button`,{type:`button`,className:`conversation-fork`,"data-fork-conversation":t.id,"data-fork-state":fa===t.id?`pending`:`idle`,disabled:!!fa,title:`从此会话分叉出一个新会话`,"aria-label":`从会话 ${t.title} 分叉出一个新会话`,onClick:()=>ma(t.id),children:`⑂`}),!(t.parentConversationId&&l.conversations.some(e=>e.id===t.parentConversationId))&&(0,H.jsx)(`button`,{className:`conversation-archive`,"data-archive-conversation":t.id,title:`归档整棵会话树`,"aria-label":`归档会话 ${t.title}`,onClick:()=>Wi(t.id),children:`×`})]})]},t.id)):(0,H.jsx)(`div`,{className:`conversation-empty`,children:`暂无会话`})),!s&&a.length>0&&(0,H.jsxs)(`div`,{className:`archived-group`,"data-archived-count":a.length,children:[(0,H.jsxs)(`button`,{className:`archived-toggle`,title:c?`展开已归档会话`:`收起已归档会话`,"aria-expanded":!c,onClick:()=>_e(t=>({...t,[e.id]:!c})),children:[(0,H.jsx)(`span`,{className:`chevron`,"aria-hidden":`true`,children:c?`▸`:`▾`}),(0,H.jsxs)(`span`,{className:`archived-label`,children:[`已归档 (`,a.length,`)`]})]}),!c&&o.map(({conversation:e,depth:t,isLastSibling:n})=>{let r=AA(a,e.id).length-1,i=!!(e.parentConversationId&&l.conversations.some(t=>t.id===e.parentConversationId&&t.archivedAt));return(0,H.jsxs)(`div`,{className:`conversation-archived`,"data-archived-conversation":e.id,"data-archived-at":e.archivedAt,"data-tree-child":t>0?`true`:void 0,"data-tree-last":t>0&&n?`true`:void 0,style:{"--tree-depth":t},children:[(0,H.jsx)(`i`,{className:`conversation-mark`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{"data-archived-title":e.id,children:e.title}),Oj(e,ha.get(e.id)),(0,H.jsx)(`small`,{children:jA(e.archivedAt)}),!i&&(0,H.jsx)(`button`,{className:`conversation-restore`,"data-restore-conversation":e.id,title:r?`恢复这个会话和它的 ${r} 个子孙会话`:`恢复为正常会话`,"aria-label":r?`恢复会话 ${e.title} 及其 ${r} 个子孙会话`:`恢复会话 ${e.title}`,onClick:()=>Ki(e.id),children:`↑`})]},e.id)})]})]},e.id)})}),(0,H.jsxs)(`footer`,{children:[(0,H.jsxs)(`div`,{className:`footer-status`,children:[(0,H.jsx)(`i`,{className:f?`online`:`offline`}),f?`已连接`:`正在连接`,(0,H.jsx)(`span`,{children:`本地持久化`})]}),(0,H.jsxs)(`div`,{className:`footer-version`,"data-super-pi-version":$e?.runningVersion??``,children:[`Super Pi v`,$e?.runningVersion??`…`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,"data-theme-open":`1`,"aria-haspopup":`dialog`,"aria-expanded":Ri,onClick:()=>{zi(!0),jr({type:`catalog.fetchAll`}),jr({type:`providers.fetch`})},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`⚙`}),`设置`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,"data-help-open":`1`,"aria-haspopup":`dialog`,"aria-expanded":Bi,onClick:()=>Vi(!0),children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`📖`}),`使用指南`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,title:`检查 Super Pi 更新`,onClick:async()=>{nt(`updating`);try{let e=await fetch(`/api/update-check`);if(!e.ok)throw Error(`check failed`);let t=await e.json();if(t.needsRestart)B(`当前代码已更新,正在重启服务…`,`info`);else if(t.updateAvailable){if(!window.confirm(`发现新版本 v${t.latestVersion??``},是否立即更新并重启 Super Pi?`))B(`已取消更新`,`info`);else{if(!(await fetch(`/api/update`,{method:`POST`})).ok)throw Error(`update failed`);B(`正在更新到 v${t.latestVersion} 并重启…`,`info`)}}else B(`当前已是最新版本`,`info`)}catch{B(`检查更新失败,请检查网络或服务日志`,`error`)}finally{nt(`idle`)}},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:tt===`updating`?`⟳`:`↻`}),tt===`updating`?`正在检查更新…`:`检查更新`]}),$e?.needsRestart&&(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger restart-needed-trigger`,title:`代码已更新:当前运行 v${$e.runningVersion},磁盘版本 v${$e.diskVersion}。点击复制重启命令 /super_pi restart`,onClick:async()=>{nt(`updating`);try{if(!(await fetch(`/api/update`,{method:`POST`})).ok)throw Error(`update failed`);B(`正在更新 Super Pi,服务即将重启…`,`info`)}catch{nt(`idle`),B(`更新启动失败,请检查服务日志`,`error`)}},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:tt===`updating`?`⟳`:`⚠️`}),tt===`updating`?`正在更新并重启…`:`更新并重启服务`]})]})]}),(0,H.jsx)(SM,{side:`left`,width:pt.sidebar,min:pt.sidebarMin,max:pt.sidebarMax,label:`调整左侧栏宽度`,onWidth:mt}),(0,H.jsxs)(`section`,{className:`chat`,"data-main-view":tr,"data-main-view-kind":tr,children:[yr.length>0&&(0,H.jsx)(`div`,{className:`chat-tab-strip`,"data-chat-tab-strip":`1`,"data-session-count":An.length,"data-file-count":z.open.length,children:(0,H.jsx)(G_,{tabs:yr,prefix:`workspace-tab`,ariaLabel:`工作区标签页`,activeId:br,onSelect:xr,onClose:wr,onActivate:Sr,minWidth:120,maxWidth:320})}),(0,H.jsxs)(`header`,{children:[(0,H.jsx)(`button`,{type:`button`,className:`mobile-drawer-toggle`,"data-mobile-drawer-toggle":`1`,"aria-label":`打开会话列表`,title:`会话列表`,"aria-expanded":st,onClick:()=>ct(!0),children:`☰`}),(0,H.jsxs)(`div`,{className:`chat-head`,children:[(0,H.jsx)(`h1`,{children:R?.title??`准备开始`}),Fe.size>0?[...Fe].map(([e,t])=>(0,H.jsx)(`p`,{"data-role":`run-status`,"data-status-key":e,children:`扩展状态:${e?`${e} · `:``}${t}`},e)):(0,H.jsx)(`p`,{"data-role":`run-status`,children:R?.status===`running`?`Agent 正在工作`:R?.status===`awaiting_background`?`后台任务运行中`:`Pi runtime · Web 控制台`})]}),(0,H.jsxs)(`span`,{className:`chat-view chat-view-${tr}`,"data-main-view-indicator":tr,"data-main-view-kind":tr,title:tr===`file`?`中间主画面正在显示文件 ${z.active?.path??``}`:tr===`diff`?`中间主画面正在显示 ${rr??``} 的改动`:`中间主画面正在显示这个会话的消息流`,children:[(0,H.jsx)(`span`,{className:`chat-view-label`,children:`主区显示`}),(0,H.jsx)(`span`,{className:`chat-view-kind`,children:tr===`file`?`文件`:tr===`diff`?`改动`:`会话`}),tr===`file`&&z.active&&(0,H.jsx)(`span`,{className:`chat-view-name`,"data-main-view-name":z.active.name,children:z.active.name}),tr===`diff`&&rr&&(0,H.jsx)(`span`,{className:`chat-view-name`,"data-main-view-name":rr,children:rr})]}),(0,H.jsx)(`div`,{className:`badge`,"data-conversation-status":R?.status??`idle`,children:xj[R?.status??`idle`]})]}),m&&(0,H.jsxs)(`div`,{className:`error`,role:`alert`,"data-global-error":!0,children:[(0,H.jsx)(`span`,{title:np(m),children:tp(m)}),(0,H.jsx)(`button`,{type:`button`,"aria-label":`关闭错误提示`,title:`关闭错误提示`,onClick:()=>h(void 0),children:`×`})]}),R?.error&&(0,H.jsx)(`div`,{className:`error`,"data-role":`conversation-error`,title:np(R.error),children:tp(R.error)}),R?.warning&&(0,H.jsxs)(`div`,{className:`warning`,role:`status`,"data-role":`conversation-warning`,title:np(R.warning),children:[(0,H.jsx)(`span`,{children:R.warning}),(0,H.jsx)(`button`,{type:`button`,"data-role":`conversation-warning-continue`,title:`让模型接着把被截断的部分写完`,onClick:()=>Fr(R?.id??``),children:`继续写完`})]}),R?.modelNotice&&(0,H.jsx)(`div`,{className:`model-notice`,"data-role":`conversation-model-notice`,children:R.modelNotice}),R?.agentNotice&&(0,H.jsx)(`div`,{className:`model-notice`,"data-role":`conversation-agent-notice`,children:R.agentNotice}),ze&&(0,H.jsxs)(`div`,{className:`extui-title-note`,children:[`扩展建议标题:`,ze]}),Ne.length>0&&(0,H.jsx)(`div`,{className:`toasts`,role:`status`,"aria-live":`polite`,"data-toast-count":Ne.length,children:Ne.map(e=>(0,H.jsx)(`div`,{className:`toast toast-${e.kind}`,"data-toast-kind":e.kind,children:e.text},e.key))}),tr===`file`?(0,H.jsx)(`div`,{className:`chat-file-view`,"data-main-file-view":Tr?.path,"data-file-view-kind":`editor`,children:Tr?(0,H.jsx)(A_,{file:Tr,state:z.saves[Tr.path]?.state??`idle`,message:z.saves[Tr.path]?.message??``,external:z.external[Tr.path]===!0,jumpToLine:$n&&$n.workspaceId===v&&$n.path===Tr.path?$n:void 0,onChange:e=>z.updateBuffer(Tr.path,e),onSave:()=>void z.save(Tr.path,!1),onReload:()=>void z.reload(Tr.path),onOverwrite:()=>void z.save(Tr.path,!0),workspaceId:v,cwd:In}):(0,H.jsx)(`p`,{className:`rail-empty`,"data-main-file-empty":`1`,children:`没有选中的文件。`})}):tr===`diff`?(0,H.jsx)(`div`,{className:`chat-file-view`,"data-main-diff-view":rr??``,"data-file-view-kind":`diff`,children:(0,H.jsx)(M_,{diff:lr.diff,loading:lr.loading,error:lr.error,bufferContent:pr,mode:dr,onMode:fr})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`messages`,ref:ne,"data-message-scroll-container":R?.id??``,onWheel:e=>{e.deltaY<0&&N.current[R?.id??``]?.followTail&&(ce.current=!0,gn(e.currentTarget,!0))},onScroll:e=>{let t=e.currentTarget;t.dataset.programmaticScroll===`true`?delete t.dataset.programmaticScroll:gn(t)},children:[(!R||!jn)&&(0,H.jsxs)(`div`,{className:`empty`,children:[(0,H.jsx)(`div`,{className:`orb`,children:`π`}),(0,H.jsx)(`h2`,{children:`开始一个新会话`}),l.workspaces.length===0?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{children:`先创建一个工作区,再开始会话。`}),(0,H.jsx)(`button`,{onClick:()=>O(!0),children:`+ 新建工作区`})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{children:l.workspaces.length===1&&fn?`在「${fn.name}」中创建会话,即可向 Super Pi 发送任务。`:`选择工作区即可开始会话,向 Super Pi 发送任务。`}),l.workspaces.length>1&&(0,H.jsxs)(`div`,{className:`empty-workspace-select`,children:[(0,H.jsx)(`label`,{htmlFor:`empty-workspace-choice`,children:`工作区:`}),(0,H.jsxs)(`select`,{id:`empty-workspace-choice`,"aria-label":`选择工作区`,value:fn?.id,onChange:e=>{e.target.value===`__new__`?O(!0):y(e.target.value)},children:[l.workspaces.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name},e.id)),(0,H.jsx)(`option`,{value:`__new__`,children:`+ 新建工作区…`})]})]}),fn&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(GA,{workspaceId:fn.id,value:pn,onChange:mn}),(0,H.jsx)(`button`,{onClick:()=>Ui(fn.id,pn),children:`新建会话`})]}),(0,H.jsx)(`span`,{className:`empty-secondary-action`,role:`button`,tabIndex:0,onClick:()=>O(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),O(!0))},children:`+ 新建工作区`})]})]}),R?.messagesLoaded===!1&&(0,H.jsx)(`p`,{role:`status`,"data-conversation-loading":`1`,children:`正在加载会话…`}),pi.map(e=>{if(e.startsWith(`m:`)){let t=ui.get(e.slice(2));if(!t)return null;let n=t.id===mi,i=t.role===`user`&&R?.status!==`running`&&R?.status!==`waiting`&&aa!==t.id,a=i&&n&&!t.id.startsWith(`pending:`),o=i&&!n&&!!t.piEntryId,s=t.content?(0,H.jsx)(Am,{source:t.content}):(0,H.jsx)(`span`,{className:`typing`,children:`正在思考`}),c=t.toolCalls??[];if(t.role===`user`){let n=ca?.id===t.id?ca.kind:void 0,r=t.content||(t.images?.length?`[图片]`:``);return(0,H.jsxs)(`article`,{className:`message user`,"data-transcript-key":e,children:[(0,H.jsxs)(`div`,{className:`message-body`,children:[(0,H.jsxs)(`div`,{className:`bubble`,children:[(0,H.jsxs)(`div`,{className:`meta`,children:[Oe,(0,H.jsx)(`time`,{children:SA(t.createdAt)})]}),t.images&&t.images.length>0&&(0,H.jsx)(`div`,{className:`message-images`,"data-message-images":`1`,children:t.images.map(e=>(0,H.jsx)(`button`,{type:`button`,className:`message-image-btn`,"data-message-image-id":e.id,onClick:()=>Ut({url:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,name:e.name,bytes:e.bytes}),title:e.name?`查看大图:${e.name}`:`查看大图`,children:(0,H.jsx)(`img`,{src:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,alt:e.name||`图片`,className:`message-image-thumb`,loading:`lazy`})},e.id))}),(0,H.jsx)(`div`,{className:`content`,children:s})]}),t.attachments&&t.attachments.length>0&&(0,H.jsx)(`div`,{className:`message-attachments`,"data-message-attachments":`1`,children:t.attachments.map(e=>{let n=`att:${t.id}:${e.kind}:${e.id}`,r=St[n]??!1;return(0,H.jsxs)(`div`,{className:`message-attachment`,"data-message-attachment":e.kind,children:[(0,H.jsxs)(`button`,{type:`button`,className:`message-attachment-head`,"data-message-attachment-toggle":e.id,"aria-expanded":r,onClick:()=>Ct(e=>({...e,[n]:!r})),children:[(0,H.jsx)(`span`,{className:`message-attachment-glyph`,"aria-hidden":`true`,children:`▤`}),(0,H.jsx)(`span`,{className:`message-attachment-label`,children:`技能`}),(0,H.jsx)(`span`,{className:`message-attachment-name`,title:e.name,children:e.name}),(0,H.jsx)(`span`,{className:`message-attachment-chevron`,"aria-hidden":`true`,children:r?`▾`:`▸`})]}),r&&(0,H.jsx)(`pre`,{className:`message-attachment-body`,"data-message-attachment-body":e.id,children:e.content})]},n)})}),(0,H.jsxs)(`div`,{className:`message-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`message-copy`,"data-copy-message":t.id,"data-copy-state":n,"aria-label":`复制这条消息:${r}`,onClick:()=>da(t.id,r),children:n===`copied`?`已复制`:n===`error`?`复制失败`:`复制`}),a&&(0,H.jsx)(`button`,{type:`button`,className:`message-revert`,"data-withdraw-message":t.id,title:`撤回并编辑:删除这条消息并将文字恢复到输入框继续编辑`,onClick:()=>sa(t.id,!0),children:`撤回`}),o&&(0,H.jsx)(`button`,{type:`button`,className:`message-revert`,"data-revert-message":t.id,title:`回退到这里:删除后续全部内容(Pi 的记录和这里的历史一起清掉,不会新建会话,也不动任何代码文件)`,onClick:()=>sa(t.id),children:`回退`})]})]}),(0,H.jsx)(`div`,{className:`avatar`,title:Oe,children:Oe})]},e)}if(t.role===`tool`){let n=/<task id="[^"]+" state="[^"]+"/.test(t.content),r=(()=>{let e=/<summary>([\s\S]*?)<\/summary>/.exec(t.content);return e?e[1].trim():n?`后台回传`:(t.content.split(`
99
+ 如需本地计算,声明 script: { path, timeoutMs, parameters }。脚本必须是 Python,参数以 JSON 从 stdin 传入,stdout 必须只输出一个 JSON 对象。在 index.html 中加载 <script src="./super-pi-tool.js"><\/script>,然后调用 SuperPiTool.run(params)、SuperPiTool.get(runId)、SuperPiTool.wait(runId) 或 SuperPiTool.cancel(runId)。这些都是已绑定本工具身份的相对接口;不要调用 /api/exec,不要猜测 toolId,也不要传 shell 命令、任意文件路径或未声明参数。页面必须实际执行一次示例任务并显示运行状态、日志和结构化结果。第三方包写进 environment.requires(必须钉死成 pkg==version),首次运行时会装进这个工具自己的虚拟环境。需要模型能力(摘要、改写、抽取、分类)时调用 SuperPiTool.llm({ prompt, system }),不要自己写模型客户端或保管密钥,并在注册时声明 permissions: { llm: true }——否则服务端会拒绝,导入页面也会提示用户。最后返回注册 id、访问地址、文件清单和验证结果。`);d(e),window.setTimeout(()=>d(!1),1800)};(0,V.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let I=(0,V.useMemo)(()=>[...t.map(e=>({id:e.id,name:e.name,glyph:e.glyph})),...n.map(e=>({id:e.id,name:e.name,glyph:`🧩`}))],[t,n]);(0,V.useEffect)(()=>{if(!M)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),N(void 0);return}if(vk(e.key)||Dk(e.target))return;e.preventDefault(),e.stopPropagation();let t=M;if(N(void 0),e.key===`Delete`||e.key===`Backspace`){qk.clearShortcut(t),F(void 0);return}let n=yk(e);if(!n){F(`没有认出这个按键,换一个试试。`);return}let i=Tk(n);if(!i.ok){F(i.reason);return}let a=jk(r,n,t);if(a){let e=I.find(e=>e.id===a)?.name;F(e?`这个组合键已经被「${e}」占用了,换一个键。`:`这个组合键已经被另一个工具占用了,换一个键。`)}else qk.setShortcut(t,n),F(void 0)};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[M,r,I]);let ie=e=>{ne(Bk(e,window.innerWidth,window.innerHeight))},ae=e=>{zk(e)},oe=()=>{ne(void 0),zk(void 0)},se=(0,V.useRef)(!1),ce=n.map(e=>e.slug).filter(e=>typeof e==`string`),le=e=>{p(void 0),h(void 0),k(void 0),D({tool:e,name:rA({slug:e.slug??`tool`})})},ue=async(e,t)=>{p(void 0),h(void 0),k(void 0);let n=iA(t);if(!n.ok)k(n.reason);else try{let t=await fetch(`/api/tools/export?id=${encodeURIComponent(e.id)}`),r=await t.json();if(!t.ok||!r.bundle)throw Error(r.error??`HTTP ${t.status}`);let i=new Blob([JSON.stringify(r.bundle,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n.name,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),h(r.skipped?.length?`已导出「${e.name}」,但有 ${r.skipped.length} 个文件没有包含:${r.skipped.join(`、`)}。`:`已导出「${e.name}」。`)}catch(e){p(`导出失败:${tp(e)}`)}finally{D(void 0)}},de=async e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;p(void 0),h(void 0),x(void 0);let n=eA(await t.text(),t.name);n.ok?(_({filename:t.name,bundle:n.bundle,unnamedFormat:n.unnamedFormat}),y(ce.includes(n.bundle.slug)?nA(n.bundle.slug,ce):n.bundle.slug),C(n.bundle.files[0]?.path)):p(n.reason)},fe=()=>{_(void 0),y(``),x(void 0),C(void 0)},pe=async()=>{if(!g)return;x(void 0);let e=tA(v);if(!e.ok)x(e.reason);else if(ce.includes(e.slug))x(`本机已经有 slug「${e.slug}」的工具,换一个名字再导入。`);else{T(!0);try{let t=await fetch(`/api/tools`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(lA(g.bundle,e.slug))}),n=await t.json();if(!t.ok||!n.id)throw Error(n.error??`HTTP ${t.status}`);await Jk(),h(`已导入「${g.bundle.name}」,它现在出现在工具栏里,所有工作区都能用。`),fe()}catch(e){p(`导入失败:${tp(e)}`)}finally{T(!1)}}};(0,V.useEffect)(()=>{E&&j.current?.scrollIntoView({block:`center`})},[E]);let L=()=>{let e=Cv(i);e.ok?t.length>=32?l(`工具最多 32 个,先删掉一个再加。`):(qk.setTools([...t,{id:Dv(`link`,t.map(e=>e.id)),kind:`link`,name:o.trim()||Gj(e.url),glyph:`↗`,url:e.url}]),a(``),s(``),l(void 0)):l(e.reason)},me=te?{width:`${te.width}px`,height:`${te.height}px`,maxWidth:`calc(100vw - 32px)`,maxHeight:`calc(100vh - 32px)`}:void 0;return(0,sa.createPortal)((0,H.jsxs)(`div`,{className:`tool-overlay`,"data-tool-settings-overlay":`1`,onPointerDown:()=>{se.current=!1},onClick:t=>{se.current?se.current=!1:t.target===t.currentTarget&&e()},children:[(0,H.jsxs)(`div`,{className:`tool-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`tool-settings-title`,"data-tool-settings":`1`,ref:ee,style:me,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsx)(`h2`,{className:`tool-dialog-title`,id:`tool-settings-title`,children:`⚙ 工具设置`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,"data-tool-settings-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭工具设置`,onClick:e,children:`✕`})]}),(0,H.jsx)(`div`,{className:`tool-dialog-body`,children:g?(0,H.jsx)(Wj,{pending:g,slugDraft:v,slugError:b,preview:S,busy:w,onSlugChange:e=>{y(e),x(void 0)},onPreviewChange:C,onCancel:fe,onConfirm:()=>void pe()}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`tool-prompt-card`,children:[(0,H.jsx)(`strong`,{children:`给 Agent 开发新工具`}),(0,H.jsx)(`p`,{className:`tool-hint`,children:`工具会挂载到 Super Pi 的统一 HTTP 服务,不需要再启动独立服务器。`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-link-copy-prompt`,"data-tool-development-prompt":`1`,onClick:()=>void re(),children:u?`已复制`:`复制工具开发 Prompt`})]}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`从预置列表添加`})}),(0,H.jsx)(`div`,{className:`tool-presets`,"data-tool-presets":_v.length,children:_v.map(e=>{let n=t.some(t=>t.kind===e.kind);return(0,H.jsxs)(`div`,{className:`tool-preset`,"data-tool-preset":e.kind,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:e.glyph}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{children:e.blurb})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-add-preset":e.kind,disabled:n,title:n?`${e.name}已经在工具栏里了`:`添加${e.name}`,"aria-label":n?`${e.name}已添加`:`添加${e.name}`,onClick:()=>qk.setTools(Ov(t,e.kind)),children:n?`已添加`:`添加`})]},e.kind)})}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`添加网址工具`})}),(0,H.jsx)(`p`,{className:`tool-hint`,children:`填一个网址,它会变成一个图标;点开后在弹窗里用按钮在新标签页打开。网址只接受 http / https / mailto。`}),(0,H.jsx)(`input`,{className:`tool-input`,"data-tool-url-input":`1`,value:i,maxLength:2048,placeholder:`https://example.com/工具`,"aria-label":`工具网址`,onChange:e=>{a(e.target.value),l(void 0)}}),(0,H.jsx)(`input`,{className:`tool-input`,"data-tool-url-name":`1`,value:o,maxLength:40,placeholder:`名称(可留空,默认用域名)`,"aria-label":`工具名称(可选)`,onChange:e=>s(e.target.value)}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-url-add":`1`,disabled:!i.trim(),onClick:L,children:`添加网址工具`}),c&&(0,H.jsx)(`p`,{className:`tool-error`,"data-tool-error":`1`,role:`alert`,children:c}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-scope-note":`1`,children:[`能自定义到哪:从上面挑预置工具,或自己填一个网址。`,(0,H.jsx)(`b`,{children:`没有开放「写一段脚本来执行」这一档`}),`——它在浏览器里等同于任意代码执行,会拿着本应用的权限跑。计算器是手写的算术解析器,不含 eval,也认不出变量名。`]}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`快捷键`})}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-shortcut-hint":`1`,children:[`给每个工具绑一个组合键,按下就直接打开它,不用先找到右侧栏。`,(0,H.jsx)(`b`,{children:`弹窗打开时快捷键不生效`}),`——模态弹窗期间键盘归它自己,关掉之后再按。`]}),(0,H.jsx)(`div`,{className:`tool-shortcuts`,"data-tool-shortcut-count":I.length,children:I.map(e=>(0,H.jsxs)(`div`,{className:`tool-shortcut-row`,"data-tool-shortcut-row":e.id,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:e.glyph}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{children:r[e.id]?`按 ${xk(r[e.id])} 打开`:`还没有快捷键`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-shortcut-set`,"data-tool-shortcut-set":e.id,"data-tool-shortcut-capturing":M===e.id?`1`:void 0,"aria-pressed":M===e.id,title:M===e.id?`按下想用的组合键(Esc 取消,Delete 清除)`:`点一下,然后按下想用的组合键`,onClick:()=>{F(void 0),N(M===e.id?void 0:e.id)},children:M===e.id?`按下组合键…`:r[e.id]?xk(r[e.id]):`未设置`}),r[e.id]&&(0,H.jsx)(`button`,{type:`button`,className:`tool-shortcut-clear`,"data-tool-shortcut-clear":e.id,title:`清除${e.name}的快捷键`,"aria-label":`清除${e.name}的快捷键`,onClick:()=>{qk.clearShortcut(e.id),F(void 0),N(void 0)},children:`清除`})]},e.id))}),P&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-shortcut-error":`1`,children:P}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsxs)(`h2`,{className:`rail-section-title`,children:[`已安装的全局工具(`,n.length,`)`]})}),n.length===0?(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-mounted-empty":`1`,children:`还没有通过 tool_register 注册的工具。上面复制那段 Prompt,让 Agent 写一个。`}):(0,H.jsx)(`div`,{className:`tool-presets`,"data-tool-mounted-list":n.length,children:n.map(e=>{let t=sA(e.environmentState);return(0,H.jsxs)(`div`,{className:`tool-share-row`,"data-tool-share-row":e.id,children:[(0,H.jsx)(`span`,{className:`tool-preset-glyph`,"aria-hidden":`true`,children:`🧩`}),(0,H.jsxs)(`span`,{className:`tool-preset-text`,children:[(0,H.jsx)(`strong`,{children:e.name}),(0,H.jsx)(`small`,{"data-tool-env":e.environmentState?.state??`unknown`,children:t?`${t.warn?`⚠ `:``}${t.text}${e.environmentState?.detail?` · ${e.environmentState.detail}`:``}`:`环境未知`}),e.permissions?.llm&&(0,H.jsx)(`small`,{"data-tool-model":`1`,children:`⚠ 会调用模型`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-export":e.id,title:`导出${e.name},得到一个可以发给别人导入的文件`,"aria-label":`导出${e.name}`,onClick:()=>le(e),children:`导出`})]},e.id)})}),E&&(0,H.jsxs)(`div`,{className:`tool-share-review`,ref:j,"data-tool-export-name":`1`,children:[(0,H.jsxs)(`h3`,{className:`tool-share-title`,children:[`导出「`,E.tool.name,`」`]}),(0,H.jsxs)(`label`,{className:`tool-hint`,children:[`文件名(发给别人的就是这个文件)`,(0,H.jsx)(`input`,{className:`tool-input`,value:E.name,"aria-label":`导出文件名`,"data-tool-export-input":`1`,onChange:e=>D({...E,name:e.target.value})})]}),O&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-export-name-error":`1`,children:O}),(0,H.jsxs)(`div`,{className:`tool-share-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-export-cancel":`1`,onClick:()=>{D(void 0),k(void 0)},children:`取消`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-export-confirm":`1`,onClick:()=>void ue(E.tool,E.name),children:`导出`})]})]}),m&&(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-share-notice":`1`,children:m}),f&&(0,H.jsx)(`p`,{className:`tool-error`,"data-tool-share-error":`1`,role:`alert`,children:f}),(0,H.jsx)(`div`,{className:`rail-section-head`,children:(0,H.jsx)(`h2`,{className:`rail-section-title`,children:`从文件导入`})}),(0,H.jsxs)(`p`,{className:`tool-hint`,children:[`收到别人分享的工具文件(`,(0,H.jsx)(`code`,{children:Xk}),`)?导入后它出现在工具栏里,所有工作区都能用。`,(0,H.jsx)(`b`,{children:`导入前会先给你看这个包里有什么。`})]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-import-pick":`1`,onClick:()=>A.current?.click(),children:`选择文件…`}),(0,H.jsx)(`input`,{ref:A,type:`file`,accept:`.json,application/json`,style:{display:`none`},"data-tool-import-input":`1`,onChange:e=>void de(e)})]})})]}),(0,H.jsx)(Hj,{targetRef:ee,onResize:ie,onCommit:ae,onDragEnd:()=>{se.current=!0},onReset:oe})]}),document.body)}var Vj=18;function Hj({targetRef:e,onResize:t,onCommit:n,onDragEnd:r,onReset:i}){let[a,o]=(0,V.useState)(),s=(0,V.useRef)(void 0);return(0,V.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{let e=t.getBoundingClientRect();o({left:e.right-Vj,top:e.bottom-Vj})};n();let r=new ResizeObserver(n);return r.observe(t),window.addEventListener(`resize`,n),window.addEventListener(`scroll`,n,!0),()=>{r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`scroll`,n,!0)}},[e]),(0,H.jsx)(`div`,{className:`tool-dialog-grip`,"data-tool-settings-grip":`1`,role:`separator`,"aria-orientation":`vertical`,tabIndex:0,"aria-label":`调整工具设置弹窗大小:拖动或用方向键,Enter 恢复默认尺寸`,style:a?{left:`${a.left}px`,top:`${a.top}px`}:void 0,onPointerDown:i=>{i.preventDefault(),i.stopPropagation();let a=e.current;if(!a)return;let o=a.getBoundingClientRect(),c=o.left+o.width/2,l=o.top+o.height/2;s.current=void 0;let u=e=>{let n=Bk({width:2*(e.clientX-c),height:2*(e.clientY-l)},window.innerWidth,window.innerHeight);s.current=n,t(n)},d=()=>{window.removeEventListener(`pointermove`,u),window.removeEventListener(`pointerup`,d),window.removeEventListener(`pointercancel`,d),s.current&&(n(s.current),r())};window.addEventListener(`pointermove`,u),window.addEventListener(`pointerup`,d),window.addEventListener(`pointercancel`,d)},onDoubleClick:()=>i(),onKeyDown:r=>{if(r.key===`Enter`||r.key===` `){r.preventDefault(),i();return}let a=r.shiftKey?8:24,o=e.current?.getBoundingClientRect(),c=o?.width??Nk.width,l=o?.height??Nk.height;if(r.key===`ArrowRight`)c+=a;else if(r.key===`ArrowLeft`)c-=a;else if(r.key===`ArrowDown`)l+=a;else if(r.key===`ArrowUp`)l-=a;else return;r.preventDefault();let u=Bk({width:c,height:l},window.innerWidth,window.innerHeight);s.current=u,t(u),n(u)},onClick:e=>e.stopPropagation()})}function Uj(){let{tools:e,mountedTools:t,openToolId:n,settingsOpen:r,shortcuts:i}=Kk(),a=e.find(e=>e.id===n),o=t.find(e=>e.id===n);return(0,V.useEffect)(()=>{let n=n=>{if(!r&&!document.querySelector(`[aria-modal="true"]`)&&!(n.isComposing||n.defaultPrevented)){for(let[r,a]of Object.entries(i))if(Ok(a,n)&&(e.some(e=>e.id===r)||t.some(e=>e.id===r))){n.preventDefault(),qk.openTool(r);return}}};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[i,e,t,r]),(0,V.useEffect)(()=>{Jk();let e=()=>{Jk()};return window.addEventListener(`super-pi-tools-updated`,e),()=>window.removeEventListener(`super-pi-tools-updated`,e)},[]),(0,V.useEffect)(()=>{qk.persistTools()},[]),(0,H.jsxs)(H.Fragment,{children:[r&&(0,H.jsx)(Bj,{onClose:()=>qk.closeSettings()}),a&&(0,H.jsx)(Kj,{tool:a,onClose:()=>qk.closeTool()}),o&&(0,H.jsx)($j,{tool:o,onClose:()=>qk.closeTool()})]})}function Wj({pending:e,slugDraft:t,slugError:n,preview:r,busy:i,onSlugChange:a,onPreviewChange:o,onCancel:s,onConfirm:c}){let l=e.bundle,u=l.files.reduce((e,t)=>e+new TextEncoder().encode(t.content).length,0),d=oA(l),f=aA(l),p=l.files.find(e=>e.path===r)??l.files[0];return(0,H.jsxs)(`div`,{className:`tool-share-review`,"data-tool-import-review":`1`,children:[(0,H.jsx)(`h3`,{className:`tool-share-title`,"data-tool-import-name":`1`,children:l.name}),l.description&&(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-import-desc":`1`,children:l.description}),e.unnamedFormat&&(0,H.jsx)(`p`,{className:`tool-import-note`,"data-tool-import-unbranded":`1`,children:`这个文件没有 Super Pi 的工具标记,已按内容形状读取——粘出来的 tool_register 参数也认。`}),(0,H.jsxs)(`p`,{className:`tool-hint`,"data-tool-import-files":`1`,children:[l.files.length,` 个文件 · 共 `,cA(u)]}),(0,H.jsx)(`p`,{className:`tool-hint`,"data-tool-import-paths":`1`,children:l.files.map(e=>e.path).join(` · `)}),l.script&&(0,H.jsxs)(`p`,{className:`tool-import-warn`,"data-tool-import-script":l.script.path,children:[(0,H.jsxs)(`b`,{children:[`⚠ 含 Python 脚本 `,l.script.path]}),(0,H.jsx)(`br`,{}),`导入后运行这个工具时,这段代码会在本机上执行,权限和你自己的 Python 一样(能读你的文件、能联网)。 可以先展开下面的文件列表把它读完。`]}),(0,H.jsxs)(`p`,{className:d.tone===`warn`?`tool-import-warn`:`tool-import-note`,"data-tool-import-env":d.tone,children:[(0,H.jsxs)(`b`,{children:[d.tone===`warn`?`⚠ `:`✓ `,d.text]}),l.environment?.fingerprint?.python&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`br`,{}),`导出方环境:Python `,l.environment.fingerprint.python,` · `,l.environment.fingerprint.platform||`未知平台`,`。版本对不上时会标出来,但不会拦住你运行。`]})]}),f&&(0,H.jsxs)(`p`,{className:`tool-import-warn`,"data-tool-import-model":`1`,children:[(0,H.jsx)(`b`,{children:`⚠ 这个工具可以调用模型`}),(0,H.jsx)(`br`,{}),f.text,`。模型由 Super Pi 通过 Pi 调用(凭据和模型选择都在 Super Pi 这边),工具只拿到文字。`]}),(0,H.jsxs)(`details`,{className:`tool-import-files`,"data-tool-import-filebox":l.files.length,children:[(0,H.jsxs)(`summary`,{children:[`查看文件(`,l.files.length,`)`]}),(0,H.jsx)(`div`,{className:`tool-share-tabs`,children:l.files.map(e=>(0,H.jsx)(`button`,{type:`button`,className:`tool-share-tab`,"aria-pressed":e.path===p?.path,"data-tool-import-file":e.path,onClick:()=>o(e.path),children:e.path},e.path))}),(0,H.jsx)(`pre`,{className:`tool-import-code`,"data-tool-import-code":p?.path,children:p?.content??``})]}),(0,H.jsxs)(`label`,{className:`tool-hint`,"data-tool-import-slug":`1`,children:[`导入后的 slug(工具的短名字,也是它在磁盘上的目录名)`,(0,H.jsx)(`input`,{className:`tool-input`,value:t,"aria-label":`导入后的 slug`,onChange:e=>a(e.target.value)})]}),n&&(0,H.jsx)(`p`,{className:`tool-error`,role:`alert`,"data-tool-import-slug-error":`1`,children:n}),(0,H.jsxs)(`div`,{className:`tool-share-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`tool-preset-add`,"data-tool-import-cancel":`1`,onClick:s,children:`取消`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-url-add`,"data-tool-import-confirm":`1`,disabled:i,onClick:c,children:i?`导入中…`:`导入`})]})]})}function Gj(e){let t=e.replace(/^[./]+/,``).slice(0,30).trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(e))return t||e.slice(0,30);try{return new URL(e,typeof window>`u`?`http://localhost`:window.location.href).hostname||t||e.slice(0,30)}catch{return e.slice(0,30)}}function Kj({tool:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`tool-overlay`,"data-tool-overlay":e.id,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`tool-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`tool-dialog-title`,"data-tool-dialog":e.id,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsxs)(`h2`,{className:`tool-dialog-title`,id:`tool-dialog-title`,children:[(0,H.jsx)(`span`,{className:`tool-dialog-glyph`,"aria-hidden":`true`,children:e.glyph}),e.name]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,"data-tool-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭${e.name}`,onClick:t,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`tool-dialog-body`,children:[e.kind===`calculator`&&(0,H.jsx)(Jj,{}),e.kind===`timestamp`&&(0,H.jsx)(Yj,{}),e.kind===`link`&&(0,H.jsx)(Xj,{tool:e})]})]})}),document.body)}function qj({image:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`lightbox-overlay`,"data-lightbox-overlay":`1`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`lightbox-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`lightbox-title`,"data-lightbox-dialog":`1`,children:[(0,H.jsxs)(`div`,{className:`lightbox-head`,children:[(0,H.jsx)(`h2`,{className:`lightbox-title`,id:`lightbox-title`,children:e.name||`图片大图`}),(0,H.jsx)(`button`,{type:`button`,className:`lightbox-close`,"data-lightbox-close":`1`,title:`关闭(Esc)`,"aria-label":`关闭大图`,onClick:t,children:`✕`})]}),(0,H.jsx)(`div`,{className:`lightbox-body`,children:(0,H.jsx)(`img`,{src:e.url,alt:e.name||`图片大图`,className:`lightbox-image`})})]})}),document.body)}function Jj(){let[e,t]=(0,V.useState)(`12 * (3 + 4)`),n=Hv(e),r=e=>{t(t=>t+e)};return(0,H.jsxs)(`div`,{className:`tool-calc`,"data-tool-calc":`1`,children:[(0,H.jsx)(`input`,{className:`tool-input tool-calc-input`,"data-calc-input":`1`,value:e,maxLength:200,"aria-label":`算式`,spellCheck:!1,autoComplete:`off`,placeholder:`例如 (12 + 8) / 4`,onChange:e=>{t(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&e.preventDefault()}}),(0,H.jsx)(`div`,{className:`tool-calc-keys`,"data-calc-keys":`1`,children:[[`7`,`7`],[`8`,`8`],[`9`,`9`],[`÷`,`/`],[`(`,`(`],[`)`,`)`],[`4`,`4`],[`5`,`5`],[`6`,`6`],[`×`,`*`],[`^`,`^`],[`%`,`%`],[`1`,`1`],[`2`,`2`],[`3`,`3`],[`-`,`-`],[`←`,`back`],[`C`,`clear`],[`0`,`0`],[`.`,`.`],[`+`,`+`]].map(([e,n])=>(0,H.jsx)(`button`,{type:`button`,className:`tool-calc-key`,"data-calc-key":n,"aria-label":e===`C`?`清空`:e===`←`?`退格`:`输入 ${e}`,onClick:()=>{n===`clear`?t(``):n===`back`?t(e=>e.slice(0,-1)):r(n)},children:e},e))}),n.ok?(0,H.jsx)(`p`,{className:`tool-calc-result`,"data-calc-result":`1`,"data-calc-value":String(n.value),children:Uv(n.value)}):(0,H.jsx)(`p`,{className:`tool-calc-error`,"data-calc-error":`1`,role:`alert`,children:n.reason})]})}function Yj(){let[e,t]=(0,V.useState)(``),n=Wv(e),r=n.ok?Kv(n.ms):null;return(0,H.jsxs)(`div`,{className:`tool-stamp`,"data-tool-stamp":`1`,children:[(0,H.jsx)(`input`,{className:`tool-input`,"data-stamp-input":`1`,value:e,maxLength:64,spellCheck:!1,"aria-label":`时间戳或日期`,placeholder:`1757000000 或 2026-10-08T09:00:00`,onChange:e=>t(e.target.value)}),r?(0,H.jsxs)(`dl`,{className:`tool-stamp-out`,"data-stamp-result":`1`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`本地时间`}),(0,H.jsx)(`dd`,{"data-stamp-local":`1`,children:r.local})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`ISO(UTC)`}),(0,H.jsx)(`dd`,{"data-stamp-iso":`1`,children:r.iso})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`秒`}),(0,H.jsx)(`dd`,{"data-stamp-seconds":`1`,children:r.seconds})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`dt`,{children:`毫秒`}),(0,H.jsx)(`dd`,{"data-stamp-ms":`1`,children:r.milliseconds})]})]}):(0,H.jsx)(`p`,{className:`tool-stamp-error`,"data-stamp-error":`1`,role:`alert`,children:n.ok?`这个日期无法显示。`:n.reason})]})}function Xj({tool:e}){let[t,n]=(0,V.useState)(!1),r=async()=>{let e=await PA(`请为 Super Pi 开发一个全局右侧栏工具并自动挂载。不要启动独立 HTTP 服务器。通过内置 tool_register 提交完整的 HTML/JS/CSS 文件;工具将被 Super Pi 保存并在所有 workspace 可用。如需计算,注册一个 Python 脚本(不接受 shell 命令),参数经 JSON stdin 传入,stdout 只输出 JSON 结果。在页面里加载 ./super-pi-tool.js,使用 SuperPiTool.run(params)、wait(runId)、get(runId) 和 cancel(runId) 执行、等待、查看和取消任务。它们会自动绑定当前工具;不要调用 /api/exec,也不要猜测 toolId。`);n(e),window.setTimeout(()=>n(!1),1800)};return(0,H.jsxs)(`div`,{className:`tool-link`,"data-tool-link":e.id,children:[(0,H.jsx)(`p`,{className:`tool-hint`,children:`这是旧版外部网页链接;新工具由 Super Pi 统一托管,并可选绑定受控 Python 脚本。`}),(0,H.jsx)(`code`,{className:`tool-link-url`,"data-tool-link-url":e.id,children:e.url}),(0,H.jsxs)(`div`,{className:`tool-link-actions`,children:[(0,H.jsx)(`a`,{className:`tool-link-open`,"data-tool-link-open":e.id,href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:e.url,children:`在新标签页打开 ↗`}),(0,H.jsx)(`button`,{type:`button`,className:`tool-link-copy-prompt`,"data-tool-copy-prompt":e.id,onClick:()=>void r(),children:t?`已复制`:`复制开发 Prompt`})]}),/^https?:\/\//i.test(e.url??``)&&(0,H.jsx)(`iframe`,{className:`tool-link-frame`,"data-tool-frame":e.id,src:e.url,title:e.name,sandbox:`allow-forms allow-modals allow-pointer-lock allow-popups allow-same-origin allow-scripts`,referrerPolicy:`no-referrer`})]})}var Zj=`(max-width: 1100px)`,Qj=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n));function $j({tool:e,onClose:t}){return(0,V.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,sa.createPortal)((0,H.jsx)(`div`,{className:`tool-overlay`,"data-mounted-tool-overlay":e.id,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{className:`tool-dialog`,"data-mounted-tool-dialog":e.id,role:`dialog`,"aria-modal":`true`,children:[(0,H.jsxs)(`div`,{className:`tool-dialog-head`,children:[(0,H.jsxs)(`h2`,{className:`tool-dialog-title`,children:[`🧩 `,e.name]}),(0,H.jsx)(`button`,{type:`button`,className:`tool-dialog-close`,onClick:t,children:`✕`})]}),(0,H.jsx)(`div`,{className:`tool-dialog-body`,children:(0,H.jsx)(`iframe`,{className:`tool-link-frame`,src:`/tools/${encodeURIComponent(e.id)}/`,title:e.name,sandbox:`allow-forms allow-modals allow-popups allow-scripts`,referrerPolicy:`no-referrer`})})]})}),document.body)}function eM(e,t,n){let r=Math.max(0,Math.round(n)-480),i=Qj(520,180,Math.max(180,r-240)),a=Qj(Math.round(e),180,i),o=Qj(640,240,Math.max(240,r-a));return{sidebar:a,rail:Qj(Math.round(t),240,o),sidebarMin:180,sidebarMax:i,railMin:240,railMax:o,sumCap:r}}var tM=`super-pi.rail-widths.v1`,nM=`super-pi.reader-state.v1`,rM=`super-pi.folded-groups.v1`;function iM(){try{if(typeof window>`u`)return{};let e=JSON.parse(window.localStorage.getItem(`super-pi.folded-groups.v1`)??`null`);if(!e||typeof e!=`object`)return{};let t=e=>{let t={};if(e&&typeof e==`object`)for(let[n,r]of Object.entries(e))typeof r==`boolean`&&(t[n]=r);return t};return{workspaces:t(e.workspaces),archived:t(e.archived)}}catch{return{}}}function aM(e){try{typeof window<`u`&&window.localStorage.setItem(rM,JSON.stringify(e))}catch{}}var oM=e=>{let t=document.querySelector(`[data-workspace-group="${CSS.escape(e)}"]`);return t?[...t.querySelectorAll(`.conversation-row[data-session-root]`)].map(e=>({id:e.dataset.sessionRoot??``,middle:(()=>{let t=e.getBoundingClientRect();return t.top+t.height/2})()})).filter(e=>e.id!==``):[]},sM=6,cM=400,lM=32,uM=48,dM=e=>{e.dataset.programmaticScroll=`true`,window.setTimeout(()=>{delete e.dataset.programmaticScroll},0)};function fM(e,t,n=!1,r=!1){let i=e.scrollHeight-e.clientHeight-e.scrollTop,a=n?!1:r?!0:t.followTail?i<=uM:i<=lM,o,s;if(!a){let t=e.getBoundingClientRect().top,n=[...e.querySelectorAll(`[data-transcript-key]`)].find(e=>e.getBoundingClientRect().bottom>t);o=n?.dataset.transcriptKey,s=n?n.getBoundingClientRect().top-t:void 0}return{followTail:a,scrollTop:e.scrollTop,...o?{anchorKey:o,anchorOffset:s}:{}}}function pM(){try{if(typeof window>`u`)return{conversations:{}};let e=JSON.parse(window.localStorage.getItem(`super-pi.reader-state.v1`)??`null`);if(!e||typeof e!=`object`)return{conversations:{}};let t={};if(e.conversations&&typeof e.conversations==`object`)for(let[n,r]of Object.entries(e.conversations)){let e=r;typeof e.followTail==`boolean`&&(t[n]={followTail:e.followTail,scrollTop:Number.isFinite(e.scrollTop)?Math.max(0,Number(e.scrollTop)):0,...typeof e.anchorKey==`string`?{anchorKey:e.anchorKey}:{},...Number.isFinite(e.anchorOffset)?{anchorOffset:Number(e.anchorOffset)}:{}})}let n={};if(e.readAt&&typeof e.readAt==`object`)for(let[t,r]of Object.entries(e.readAt))typeof r==`string`&&(n[t]=r);return{activeId:typeof e.activeId==`string`?e.activeId:void 0,workspaceId:typeof e.workspaceId==`string`?e.workspaceId:void 0,conversations:t,readAt:n}}catch{return{conversations:{}}}}function mM(e){try{typeof window<`u`&&window.localStorage.setItem(nM,JSON.stringify(e))}catch{}}var hM=`super-pi.session-tabs.v1`;function gM(e,t){if(!t||e.has(t))return e;let n=new Set(e);return n.add(t),n}function _M(e,t,n){let r=e.touched.has(t),i=e.touched;if(r){let r=new Set(e.touched);r.delete(t),n&&r.add(n),i=r}return{ids:e.ids.flatMap(e=>e===t?n?[n]:[]:[e]),previewId:e.previewId===t?n&&!r?n:void 0:e.previewId,emptied:e.emptied,touched:i}}function vM(){try{if(typeof window>`u`)return{ids:[]};let e=JSON.parse(window.sessionStorage.getItem(`super-pi.session-tabs.v1`)??`null`);if(!e||typeof e!=`object`)return{ids:[]};let t=e,n=Array.isArray(t.ids)?[...new Set(t.ids.filter(e=>typeof e==`string`))]:[],r=typeof t.previewId==`string`&&n.includes(t.previewId)?t.previewId:void 0,i=Array.isArray(t.touched)?[...new Set(t.touched.filter(e=>typeof e==`string`))]:[];return{ids:n,activeId:typeof t.activeId==`string`&&n.includes(t.activeId)?t.activeId:void 0,previewId:r,touched:i}}catch{return{ids:[]}}}function yM(e,t,n,r){try{if(typeof window>`u`)return;window.sessionStorage.setItem(hM,JSON.stringify({ids:e,...t&&e.includes(t)?{activeId:t}:{},...n&&e.includes(n)?{previewId:n}:{},...r&&r.length>0?{touched:r}:{}}))}catch{}}function bM(){try{if(typeof window>`u`)return{};let e=window.localStorage.getItem(tM);if(e===null)return{};let t=JSON.parse(e),n=e=>typeof e==`number`&&Number.isFinite(e)&&e>0?Math.round(e):void 0;return{sidebar:n(t.sidebar),rail:n(t.rail)}}catch{return{}}}function xM(e){try{if(typeof window>`u`)return;window.localStorage.setItem(tM,JSON.stringify(e))}catch{}}function SM({side:e,width:t,min:n,max:r,label:i,onWidth:a}){let[o,s]=(0,V.useState)(!1),c=e=>e.shiftKey?64:16;return(0,H.jsx)(`div`,{className:`rail-resizer rail-resizer-${e}${o?` rail-resizer-dragging`:``}`,"data-rail-resizer":e,"data-rail-resizer-dragging":o?`true`:`false`,"data-rail-resizer-width":t,role:`separator`,"aria-orientation":`vertical`,"aria-label":i,"aria-valuenow":t,"aria-valuemin":n,"aria-valuemax":r,tabIndex:0,onMouseDown:i=>{i.preventDefault(),i.currentTarget.focus();let o=i.clientX,c=t;s(!0);let l=document.body,u=l.style.cursor,d=l.style.userSelect;l.style.cursor=`col-resize`,l.style.userSelect=`none`;let f=t=>{let i=e===`left`?t.clientX-o:o-t.clientX;a(Qj(c+i,n,r))},p=()=>{l.style.cursor=u,l.style.userSelect=d,s(!1),window.removeEventListener(`mousemove`,f),window.removeEventListener(`mouseup`,p)};window.addEventListener(`mousemove`,f),window.addEventListener(`mouseup`,p)},onKeyDown:i=>{let o=c(i);i.key===`ArrowLeft`?(i.preventDefault(),a(Qj(e===`left`?t-o:t+o,n,r))):i.key===`ArrowRight`?(i.preventDefault(),a(Qj(e===`left`?t+o:t-o,n,r))):i.key===`Home`?(i.preventDefault(),a(n)):i.key===`End`&&(i.preventDefault(),a(r))}})}var CM=`super-pi.composer-height.v1`,wM=148,TM=.55,EM=()=>Math.max(wM,Math.round((typeof window>`u`?800:window.innerHeight)*TM)),DM=e=>{let t=Number.isFinite(e)?e:wM;return Math.round(Math.min(EM(),Math.max(wM,t)))},OM=()=>{try{let e=window.localStorage.getItem(CM);return e===null?wM:DM(Number(e))}catch{return wM}};function kM({height:e,onHeight:t}){let[n,r]=(0,V.useState)(!1),i=e=>e.shiftKey?64:16,a=EM();return(0,H.jsx)(`div`,{className:`composer-resize${n?` composer-resize-dragging`:``}`,"data-composer-resize":`1`,"data-composer-resize-dragging":n?`true`:`false`,"data-composer-height":e,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`调整消息编辑区高度`,"aria-valuenow":e,"aria-valuemin":wM,"aria-valuemax":a,tabIndex:0,onMouseDown:n=>{n.preventDefault(),n.currentTarget.focus();let i=n.clientY,a=e;r(!0);let o=document.documentElement,s=document.body.style.userSelect;document.body.style.cursor=`ns-resize`,document.body.style.userSelect=`none`;let c=e=>{let t=DM(a+(i-e.clientY));o.style.setProperty(`--composer-height`,`${t}px`)},l=()=>{document.body.style.cursor=``,document.body.style.userSelect=s;let n=Number.parseFloat(o.style.getPropertyValue(`--composer-height`));r(!1),window.removeEventListener(`mousemove`,c),window.removeEventListener(`mouseup`,l),t(Number.isFinite(n)?n:e)};window.addEventListener(`mousemove`,c),window.addEventListener(`mouseup`,l)},onKeyDown:n=>{let r=i(n);n.key===`ArrowUp`?(n.preventDefault(),t(DM(e+r))):n.key===`ArrowDown`?(n.preventDefault(),t(DM(e-r))):n.key===`Home`?(n.preventDefault(),t(wM)):n.key===`End`?(n.preventDefault(),t(a)):n.key===`PageUp`?(n.preventDefault(),t(DM(e+96))):n.key===`PageDown`&&(n.preventDefault(),t(DM(e-96)))}})}function AM(e,t,n){if(!e.length)return;let r=n?e.find(e=>e.workspaceId===n):void 0;if(r)return r;if(!(n&&t.some(e=>e.id===n)))return e[0]}function jM(){let[e,t]=(0,V.useState)(fA),n=(0,V.useCallback)(e=>{t(t=>{let n=typeof e==`function`?e(t):e;return pe(n,t)})},[]),[r,i]=(0,V.useState)([]),a=(0,V.useRef)([]),o=(0,V.useRef)(null);o.current||=pM();let s=(0,V.useRef)(null);s.current||=vM();let c=s.current,l=r.reduce((e,t)=>t.apply(e),e),[u,d]=(0,V.useState)(s.current.activeId??o.current.activeId),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(),[g,_]=(0,V.useState)(()=>iM().workspaces??{}),[v,y]=(0,V.useState)(o.current.workspaceId),[b,x]=(0,V.useState)(()=>({ids:c.ids,previewId:c.previewId,touched:new Set(c.touched??[]),emptied:!1})),S=b.ids,C=b.previewId,w=b.emptied===!0,[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(!1),[k,A]=(0,V.useState)(),j=(0,V.useRef)(null),M=(0,V.useRef)(void 0),N=(0,V.useRef)(o.current.conversations),P=(0,V.useRef)(S);P.current=S;let F=(0,V.useRef)(o.current.readAt??{}),[ee,te]=(0,V.useState)(0),ne=(0,V.useRef)(null),re=(0,V.useRef)(null),I=(0,V.useRef)(void 0),ie=(0,V.useRef)(!1),ae=(0,V.useRef)(!0),[oe,se]=(0,V.useState)({followTail:!0,scrollTop:0}),ce=(0,V.useRef)(!1),le=(0,V.useRef)(new Map),ue=(0,V.useRef)(void 0),de=(0,V.useRef)([]),fe=(0,V.useRef)(void 0),pe=(0,V.useCallback)((e,t)=>{let n=new Map(t.conversations.map(e=>[e.id,e]));return{...e,conversations:e.conversations.map(e=>{let t=n.get(e.id);if(e.messagesLoaded===!1||!t||t.messagesLoaded===!1||t.status!==`running`)return e;let r=new Map(t.messages.map(e=>[e.id,e]));return{...e,messages:e.messages.map(e=>{let t=r.get(e.id);return!t||!(t.content.length>e.content.length||(t.thinking?.length??0)>(e.thinking?.length??0))?e:{...e,content:t.content,thinking:t.thinking,thinkingActive:t.thinkingActive,thinkingBlocks:xA(t.thinkingBlocks,e.thinkingBlocks)}})}})}},[]),L=(0,V.useCallback)(()=>{if(fe.current!==void 0&&(cancelAnimationFrame(fe.current),fe.current=void 0),!de.current.length)return;let e=de.current;de.current=[];let t=new Map;for(let n of e){let e=`${n.conversationId}\u0000${n.messageId}`,r=t.get(e)??[];r.push(n),t.set(e,r)}n(e=>({...e,conversations:e.conversations.map(e=>{let n=e.messages.map(n=>{let r=t.get(`${e.id}\u0000${n.id}`);if(!r)return n;let i={...n};for(let e of r){if(e.type===`message.delta`){i.content+=e.delta;continue}if(i.thinkingActive=e.active,!e.delta)continue;let t=e.at??i.content.length,n=bA(i.thinkingBlocks??[],e,t);i={...i,thinking:(i.thinking??``)+e.delta,thinkingBlocks:n}}return i});return n.every((t,n)=>t===e.messages[n])?e:{...e,messages:n}})}))},[]),me=(0,V.useCallback)(e=>{let t=de.current,n=t.at(-1);n&&n.type===e.type&&n.conversationId===e.conversationId&&n.messageId===e.messageId&&(e.type!==`message.thinking`||n.type===`message.thinking`&&n.at===e.at&&n.active===e.active&&n.blockIndex===e.blockIndex)?t[t.length-1]={...e,delta:n.delta+e.delta}:t.push(e),fe.current===void 0&&(fe.current=requestAnimationFrame(L))},[L]),he=(0,V.useCallback)(e=>{ue.current=e},[]),[ge,_e]=(0,V.useState)(()=>iM().archived??{});(0,V.useEffect)(()=>{aM({workspaces:g,archived:ge})},[g,ge]);let[ve,ye]=(0,V.useState)(()=>ck());(0,V.useEffect)(()=>{lk(ve)},[ve]);let[be,xe]=(0,V.useState)(),Se=(0,V.useRef)(0),Ce=(0,V.useRef)(``),we=(e,t,n,r)=>{let i=(e.target instanceof Element?e.target:void 0)?.closest(`button`);if(i&&!i.classList.contains(`conversation`)||e.button!==0)return;let a=e.clientY,o=e.pointerType===`touch`,s=!1,c,l=[],u,d=!1,f=e=>{let t=l.filter(e=>e.id!==n);if(t.length===0){u=void 0,d=!1;return}let r=0;for(;r<t.length&&t[r].middle<e;)r+=1;r<t.length?(u=t[r].id,d=!1):(u=t[t.length-1].id,d=!0)},p=()=>xe(e=>e&&e.dropRootId===u&&e.dropAfter===d?e:{workspaceId:t,conversationId:n,dropRootId:u,dropAfter:d}),m=()=>{s||(s=!0,l=oM(t),f(a),document.body.style.userSelect=`none`,p())},h=e=>{if(!s){if(o){c!==void 0&&window.clearTimeout(c),c=void 0;return}if(Math.abs(e.clientY-a)<sM)return;m()}f(e.clientY),p()},g=e=>{if(window.removeEventListener(`pointermove`,h),window.removeEventListener(`pointerup`,_),window.removeEventListener(`pointercancel`,v),document.removeEventListener(`touchmove`,y),c!==void 0&&window.clearTimeout(c),document.body.style.userSelect=``,s&&e){let e=r.filter(e=>e!==n),i=u===void 0?e.length:d?e.indexOf(u)+1:e.indexOf(u);ye(e=>({...e,[t]:ok(r,n,i)})),Se.current=Date.now(),Ce.current=n}xe(void 0)},_=()=>g(!0),v=()=>g(!1),y=e=>{s&&e.preventDefault()};window.addEventListener(`pointermove`,h),window.addEventListener(`pointerup`,_),window.addEventListener(`pointercancel`,v),o&&(document.addEventListener(`touchmove`,y,{passive:!1}),c=window.setTimeout(m,cM))},[Te,Ee]=(0,V.useState)(()=>{if(typeof window>`u`)return``;try{return window.localStorage.getItem(`super-pi.user-nickname`)??``}catch{return``}}),De=e=>{let t=e.slice(0,24);Ee(t);try{window.localStorage.setItem(`super-pi.user-nickname`,t)}catch{}},Oe=Te.trim()||`你`,[ke,Ae]=(0,V.useState)(),[je,Me]=(0,V.useState)([]),[Ne,Pe]=(0,V.useState)([]),[Fe,Ie]=(0,V.useState)(new Map),[Le,Re]=(0,V.useState)(new Map),[ze,Be]=(0,V.useState)(),[Ve,He]=(0,V.useState)(),[Ue,We]=(0,V.useState)(),[Ge,Ke]=(0,V.useState)([]),[qe,Je]=(0,V.useState)([]),[Ye,Xe]=(0,V.useState)(),[Ze,Qe]=(0,V.useState)(),[$e,et]=(0,V.useState)(),[tt,nt]=(0,V.useState)(`idle`),[rt,it]=(0,V.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1100px)`).matches),[at,ot]=(0,V.useState)(`chat`),[st,ct]=(0,V.useState)(!1),[lt,ut]=(0,V.useState)(()=>typeof window>`u`?1440:window.innerWidth);(0,V.useEffect)(()=>{let e=()=>ut(window.innerWidth);return window.addEventListener(`resize`,e),e(),()=>window.removeEventListener(`resize`,e)},[]);let[dt,ft]=(0,V.useState)(bM),pt=eM(dt.sidebar??270,dt.rail??320,lt);(0,V.useEffect)(()=>{xM({sidebar:dt.sidebar??270,rail:dt.rail??320})},[dt.sidebar,dt.rail]);let mt=e=>ft(t=>({...t,sidebar:e})),ht=e=>ft(t=>({...t,rail:e})),[gt,_t]=(0,V.useState)(null);(0,V.useEffect)(()=>{_t(OM())},[]),(0,V.useEffect)(()=>{gt!==null&&document.documentElement.style.setProperty(`--composer-height`,`${gt}px`)},[gt]);let vt=e=>{let t=DM(e);_t(t);try{window.localStorage.setItem(CM,String(t))}catch{}};(0,V.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Zj),t=e=>{e.matches&&it(!0)};return e.addEventListener(`change`,t),e.matches&&it(!0),()=>e.removeEventListener(`change`,t)},[]);let yt=lt<=1100;(0,V.useEffect)(()=>{if(!yt||rt)return;let e=e=>{e.key===`Escape`&&(e.defaultPrevented||document.querySelector(`.tool-overlay, .lightbox-overlay, .quick-open-backdrop, .ctx-menu, .overlay, .picker-menu, .content-search-overlay`)||(e.preventDefault(),it(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[yt,rt]);let[bt,xt]=(0,V.useState)({}),[St,Ct]=(0,V.useState)({}),[wt,Tt]=(0,V.useState)({}),[Et,Dt]=(0,V.useState)(),[Ot,kt]=(0,V.useState)(()=>new Set),[At,jt]=(0,V.useState)(),[Mt,Nt]=(0,V.useState)(),Pt=(0,V.useRef)(new Map),[Ft,It]=(0,V.useState)({}),Lt=(0,V.useRef)(new Set),[Rt,zt]=(0,V.useState)([]),[Bt,Vt]=(0,V.useState)([]),[Ht,Ut]=(0,V.useState)(),[Wt,Gt]=(0,V.useState)(!1),Kt=(0,V.useRef)(null),qt=(0,V.useRef)(!1),Jt=(0,V.useRef)(0),Yt=(0,V.useRef)([]),Xt=(0,V.useRef)(void 0),Zt=(0,V.useRef)(!1),Qt=(0,V.useRef)(new Set),$t=(0,V.useRef)(new Set),en=(0,V.useRef)(new Map),tn=(0,V.useRef)(new Map),[nn,rn]=(0,V.useState)(()=>Date.now());(0,V.useEffect)(()=>{let e=window.setInterval(()=>rn(Date.now()),3e4);return()=>window.clearInterval(e)},[]);let an=(0,V.useMemo)(()=>l.conversations.filter(e=>!e.archivedAt),[l.conversations]),on=(0,V.useMemo)(()=>e.conversations.filter(e=>!e.archivedAt),[e.conversations]),sn=(0,V.useMemo)(()=>new Set(l.collapsedConversationIds??[]),[l.collapsedConversationIds]),R=(0,V.useMemo)(()=>{let e=an.find(e=>e.id===u);if(e)return e;if(!w)return AM(an,l.workspaces,v)},[w,u,an,v,l.workspaces]),cn=(0,V.useMemo)(()=>dA(R?.parentConversationId,R?.parentConversationId?l.conversations.find(e=>e.id===R.parentConversationId):void 0),[R,l.conversations]),ln=!!(R&&l.unlockedChildConversationIds?.includes(R.id)),un=cn&&!ln,dn=ne.current;if(dn){let e=dn.dataset.messageScrollContainer;e&&R?.id&&e!==R?.id&&dn.querySelector(`[data-transcript-key]`)&&(N.current[e]=fM(dn,N.current[e]??{followTail:!0,scrollTop:0}))}ae.current=R?.messagesLoaded!==!1,(0,V.useEffect)(()=>{if(!T||w||u&&on.some(e=>e.id===u)||u&&a.current.some(e=>e.temporaryId===u))return;let e=AM(an,l.workspaces,v);d(e?.id)},[w,u,on,an,T,v,l.workspaces]),(0,V.useEffect)(()=>{h(void 0)},[u,v]);let fn=(0,V.useMemo)(()=>l.workspaces.find(e=>e.id===v)??l.workspaces[0],[l.workspaces,v]),[pn,mn]=(0,V.useState)(``);(0,V.useEffect)(()=>{mn(``)},[fn?.id]);let hn=(0,V.useRef)(v);hn.current=v,(0,V.useEffect)(()=>{R&&y(R.workspaceId)},[R?.id]),(0,V.useEffect)(()=>{Xt.current=u},[u]),(0,V.useEffect)(()=>{I.current=R?.id},[R?.id]),(0,V.useEffect)(()=>{let e=R?.id;if(!e)return;let t=l.conversations.find(t=>t.id===e);if(!t)return;let n=F.current[e];F.current[e]=t.updatedAt,n!==t.updatedAt&&te(e=>e+1),mM({activeId:Xt.current,workspaceId:R?.workspaceId??v,conversations:N.current,readAt:F.current})},[R?.id,l.conversations]),(0,V.useEffect)(()=>{f&&u&&mM({activeId:u,workspaceId:R?.workspaceId??v,conversations:N.current,readAt:F.current})},[u,R?.workspaceId,f,v]),(0,V.useEffect)(()=>{let e=ne.current;if(!e||!R?.id||R.messagesLoaded===!1)return;let t=R.id;ce.current=!1;let n=N.current[t]??{followTail:!0,scrollTop:0};N.current[t]=n,se(n);let r=requestAnimationFrame(()=>{if(ne.current!==e)ie.current=!1;else{if(n.followTail)dM(e),e.scrollTop=e.scrollHeight;else{let t=n.anchorKey?e.querySelector(`[data-transcript-key="${CSS.escape(n.anchorKey)}"]`):null;e.scrollTop=t?Math.max(0,e.scrollTop+t.getBoundingClientRect().top-(n.anchorOffset??0)-e.getBoundingClientRect().top):n.scrollTop}ie.current=!1}});return()=>cancelAnimationFrame(r)},[R?.id,R?.messagesLoaded]),(0,V.useLayoutEffect)(()=>{ie.current=!0},[R?.id,R?.messagesLoaded]);let gn=(0,V.useCallback)((e,t=!1,n=!1)=>{let r=I.current;if(!r||ie.current||!ae.current)return;let i=fM(e,N.current[r]??{followTail:!0,scrollTop:0},t,n);ce.current=!i.followTail,N.current[r]=i,se(i),mM({activeId:r,workspaceId:hn.current,conversations:N.current,readAt:F.current})},[]),_n=Ft[R?.id??``]??{text:``,images:[],attachments:[],uploading:0},vn=_n.text,yn=_n.images,bn=_n.attachments,xn=_n.uploading,Sn=(e,t)=>It(n=>({...n,[e]:t(n[e]??{text:``,images:[],attachments:[],uploading:0})})),Cn=e=>Sn(R?.id??``,t=>({...t,text:e})),wn=e=>Sn(R?.id??``,t=>({...t,attachments:t.attachments.some(t=>t.kind===e.kind&&t.id===e.id)?t.attachments:[...t.attachments,e]})),Tn=(e,t)=>Sn(R?.id??``,n=>({...n,attachments:n.attachments.filter(n=>n.kind!==e||n.id!==t)})),[En,Dn]=(0,V.useState)({visible:!1,query:``,rect:null}),On=e=>Sn(R?.id??``,t=>({...t,images:typeof e==`function`?e(t.images):e})),kn=S.length>0?S:w?[]:R?[R.id]:[],An=(0,V.useMemo)(()=>kn.map(e=>an.find(t=>t.id===e)).filter(e=>e!==void 0),[kn,an]),jn=An.length>0;(0,V.useEffect)(()=>{if(!T)return;let e=new Set(an.map(e=>e.id));x(t=>{let n=t.ids.filter(t=>e.has(t)),r=t.previewId&&e.has(t.previewId)?t.previewId:void 0;return n.length===t.ids.length&&r===t.previewId?t:{...t,ids:n,previewId:r}})},[T,an]),(0,V.useEffect)(()=>{yM(S,u,C,[...b.touched])},[u,S,C,b.touched]);let Mn=(0,V.useCallback)(e=>{e&&x(t=>{if(t.touched.has(e))return t;let n=t.previewId===e?void 0:t.previewId;return{...t,previewId:n,touched:gM(t.touched,e)}})},[]),Nn=(0,V.useCallback)(e=>{d(e);let t=an.find(t=>t.id===e)?.workspaceId;t&&y(t),nr(`session`),x(t=>{let n=t.emptied===!0,r=n?{...t,emptied:!1}:t;if(r.ids.includes(e))return r;let i=!n&&r.ids.length===0&&R?.id&&R.id!==e?[R.id]:[],a=[...r.ids,...i];if(r.touched.has(e))return{...r,ids:[...a,e]};let o=r.previewId?a.indexOf(r.previewId):-1,s=o>=0?a.map((t,n)=>n===o?e:t):[...a,e];return{...r,ids:s,previewId:e}})},[R,an]),Pn=(0,V.useCallback)(e=>{e&&(Mn(e),Nn(e))},[Mn,Nn]),Fn=R?.workspaceId??v,In=R?.cwd??``,z=P_(Fn,In),Ln=(0,V.useRef)(z.setChangedFor),Rn=(0,V.useRef)(z.setIndex),zn=(0,V.useRef)(Fn);zn.current=Fn;let Bn=(0,V.useRef)(In);Bn.current=In,(0,V.useEffect)(()=>{Ln.current=z.setChangedFor},[z.setChangedFor]),(0,V.useEffect)(()=>{Rn.current=z.setIndex},[z.setIndex]);let[Vn,Hn]=(0,V.useState)(vj[0].id),[Un,Wn]=(0,V.useState)({}),Gn=(R?.id?Un[R.id]:void 0)??Vn,Kn=(0,V.useCallback)(e=>{Hn(e),R?.id&&Wn(t=>({...t,[R.id]:e}))},[R?.id]),[qn,Jn]=(0,V.useState)(!1),Yn=(0,V.useRef)(void 0),Xn=(0,V.useRef)(``);(0,V.useEffect)(()=>{Jn(!1),M.current?.readyState===WebSocket.OPEN&&M.current.send(JSON.stringify({type:`files.index.subscribe`}))},[Fn,In]);let[Zn,Qn]=(0,V.useState)(!1),[$n,er]=(0,V.useState)(),[tr,nr]=(0,V.useState)(`session`),[rr,ir]=(0,V.useState)(),[ar,or]=(0,V.useState)([]);(0,V.useEffect)(()=>{tr===`file`&&!z.active&&nr(`session`)},[tr,z.active]),(0,V.useEffect)(()=>{tr===`diff`&&!rr&&nr(`session`)},[tr,rr]);let sr=(0,V.useRef)(`${Fn??``}:${In}`);(0,V.useEffect)(()=>{let e=`${Fn??``}:${In}`;sr.current!==e&&(sr.current=e,or([]),ir(void 0),nr(`session`))},[Fn,In]),(0,V.useEffect)(()=>{z.restoredActive&&nr(`file`)},[z.restoredActive]);let cr=(0,V.useCallback)(e=>{or(t=>t.includes(e)?t:[...t,e]),ir(e),nr(`diff`),Hn(`files`)},[]),[lr,ur]=(0,V.useState)({diff:null,loading:!1,error:``}),[dr,fr]=(0,V.useState)(`server`);(0,V.useEffect)(()=>{if(tr!==`diff`||!rr||!Fn)return;let e=!0;return ur({diff:null,loading:!0,error:``}),fetch(`/api/files/diff?workspaceId=${encodeURIComponent(Fn)}&path=${encodeURIComponent(rr)}${In?`&cwd=${encodeURIComponent(In)}`:``}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(t=>{e&&ur({diff:t,loading:!1,error:``})}).catch(t=>{e&&ur({diff:null,loading:!1,error:t instanceof Error?t.message:`读取差异失败`})}),()=>{e=!1}},[tr,rr,Fn,In]);let pr=(0,V.useMemo)(()=>{if(!rr)return;let e=z.open.find(e=>e.path===rr);return e&&e.dirty?e.content:void 0},[rr,z.open]),mr=(0,V.useCallback)(e=>{z.setActivePath(e),nr(`file`),Hn(`files`)},[z.setActivePath]),hr=(0,V.useCallback)(async(e,t)=>{er(t?{workspaceId:v,path:e.path,line:t,request:Date.now()}:void 0),await z.openFile(e),nr(`file`)},[z.openFile,v]);(0,V.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.shiftKey&&e.key.toLowerCase()===`f`?(e.preventDefault(),Qn(!0)):(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`p`&&(e.preventDefault(),Yn.current=Fn,Xn.current=In,Jn(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Fn,In]);let gr=(0,V.useMemo)(()=>An.map(e=>({id:`session:${e.id}`,rawId:e.id,kind:`session`,label:e.title,title:e.title,closable:!0,preview:C===e.id,badge:(0,H.jsx)(Dj,{state:Ej(e,Tj(e,je),F.current[e.id])})})),[An,je,l.conversations,ee,C]),_r=(0,V.useMemo)(()=>z.open.map(e=>({id:`file:${e.path}`,rawId:e.path,kind:`file`,label:e.name,title:e.path,closable:!0,badge:e.dirty?(0,H.jsx)(`span`,{className:`file-tab-badge`,"data-file-tab-dirty":e.path,"aria-label":`未保存`,children:`●`}):void 0})),[z.open]),vr=(0,V.useMemo)(()=>ar.map(e=>({id:`diff:${e}`,rawId:e,kind:`diff`,label:e.split(/[\\/]/).pop()||e,title:`${e}(改动)`,closable:!0,icon:(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`±`})})),[ar]),yr=(0,V.useMemo)(()=>[...gr,..._r,...vr],[gr,_r,vr]),br=tr===`file`&&z.activePath?`file:${z.activePath}`:tr===`diff`&&rr?`diff:${rr}`:R?.id?`session:${R.id}`:void 0,xr=(0,V.useCallback)(e=>{if(e.startsWith(`file:`)){let t=e.slice(5);mr(t)}else if(e.startsWith(`diff:`)){let t=e.slice(5);ir(t),nr(`diff`)}else if(e.startsWith(`session:`)){let t=e.slice(8);Nn(t)}},[mr,Nn]),Sr=(0,V.useCallback)(e=>{e.startsWith(`session:`)&&Pn(e.slice(8))},[Pn]),Cr=(0,V.useCallback)(e=>{let t=kn.indexOf(e);if(t<0)return;let n=kn.filter(t=>t!==e);if(x(t=>({...t,ids:t.ids.filter(t=>t!==e),previewId:t.previewId===e?void 0:t.previewId,emptied:n.length===0||t.emptied})),R?.id!==e)return;let r=n[Math.min(t,n.length-1)];if(r)d(r);else if(z.open.length>0){let e=z.activePath&&z.open.some(e=>e.path===z.activePath)?z.activePath:z.open[0].path;z.setActivePath(e),nr(`file`)}else ar.length>0?(ir(ar[0]),nr(`diff`)):d(void 0)},[kn,R,z,ar]),wr=(0,V.useCallback)(e=>{if(e.startsWith(`file:`)){let t=e.slice(5);z.closeFile(t),z.activePath===t&&z.open.length<=1&&nr(`session`)}else if(e.startsWith(`diff:`)){let t=e.slice(5);or(e=>e.filter(e=>e!==t)),rr===t&&(ir(void 0),nr(`session`))}else if(e.startsWith(`session:`)){let t=e.slice(8);Cr(t)}},[z,Cr,rr]),Tr=z.active,Er=R?.id;(0,V.useEffect)(()=>{Er&&!Er.startsWith(`pending:`)&&jr({type:`conversation.select`,conversationId:Er})},[Er]);let B=(e,t=`info`)=>{if(!e)return;let n=++Jt.current;Pe(r=>[...r,{key:n,text:e,kind:t}]),Yt.current.push(window.setTimeout(()=>Pe(e=>e.filter(e=>e.key!==n)),7e3))};(0,V.useEffect)(()=>{let e=R?.id,t=R?.agentNotice;e&&t&&!Qt.current.has(e)&&(Qt.current.add(e),B(t,`info`))},[R?.id,R?.agentNotice]);let Dr=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n<0)return[t,...e];let r=[...e];return r[n]=t,r},Or=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);if(n<0)return[t,...e];let r=[...e];return r[n]=t,r},kr=(e,t)=>{if(t.blocking)Me(n=>[...n.filter(n=>n.conversationId!==e||n.request.requestId!==t.requestId),{conversationId:e,request:t}]);else if(t.method===`notify`)B(t.message||t.title,t.notifyType??`info`);else if(t.method===`setStatus`){let e=t.statusKey??``;Ie(n=>{let r=new Map(n);return t.statusText===void 0?r.delete(e):r.set(e,t.statusText),r})}else if(t.method===`setWidget`){let e=t.widgetKey??``;Re(n=>{let r=new Map(n);return t.widgetLines===void 0?r.delete(e):r.set(e,{lines:t.widgetLines,placement:t.widgetPlacement??`aboveEditor`}),r})}else t.method===`setTitle`?Be(t.title):t.method===`set_editor_text`&&e===Xt.current&&Cn(t.text??``)},Ar=(e,t,n)=>{Me(n=>n.filter(n=>n.conversationId!==e||n.request.requestId!==t));let r=JA[n];r&&B(r,`warning`)};(0,V.useEffect)(()=>{let e=!1,t=0,r,s=()=>{if(e)return;let c=location.protocol===`https:`?`wss`:`ws`,l=new WebSocket(`${c}://${location.host}/ws?state=focused${Xt.current?`&conversationId=${encodeURIComponent(Xt.current)}`:``}`);M.current=l,l.onopen=()=>{if(!e){t=0,p(!0),l.send(JSON.stringify({type:`stream.configure`,coalesce:!0})),l.send(JSON.stringify({type:`catalog.fetch`,conversationId:Xt.current})),hn.current&&l.send(JSON.stringify({type:`prompt.catalog.fetch`,workspaceId:hn.current})),l.send(JSON.stringify({type:`catalog.fetchAll`})),l.send(JSON.stringify({type:`agent.catalog.fetch`})),l.send(JSON.stringify({type:`subagent.catalog.fetch`}));for(let e of a.current)e.retry&&e.command&&l.send(JSON.stringify({...e.command,operationRequestId:e.id}))}},l.onclose=n=>{if(e)return;Zt.current=!1;let o=rk(a.current);for(let e of o.failed)e.onFailure?.();if(a.current=o.retry,i(o.retry),p(!1),t===0){let e=n.reason?.trim()?`${n.reason.trim()}(code ${n.code})`:`code ${n.code}`;console.error(`[Super Pi Error] websocket closed:`,n.code,n.reason),B(`与 Super Pi 服务的连接断开,正在重连。(${e})`,`error`)}r=window.setTimeout(s,Math.min(NA,MA*2**t++))},l.onmessage=({data:t})=>{if(e)return;let r=JSON.parse(t);if(r.type!==`message.delta`&&r.type!==`message.thinking`&&L(),r.type===`exec.output`){let e=le.current.get(r.sessionId)??``;le.current.set(r.sessionId,(e+r.data).slice(-512e3)),le.current.size>64&&le.current.delete(le.current.keys().next().value),window.dispatchEvent(new CustomEvent(`super-pi-exec-output`,{detail:r}))}else if(r.type===`run.stopping`)kt(e=>{let t=new Set(e);return t.add(r.conversationId),t});else if(r.type===`exec.exit`)(r.stdout||r.stderr)&&le.current.set(r.sessionId,`${r.stdout}${r.stderr}`);else if(r.type.startsWith(`terminal.`))ue.current?.(r);else if(r.type===`conversation.autoRename.result`){let e=Pt.current.get(r.conversationId);e&&(Pt.current.delete(r.conversationId),r.ok?e.resolve(r.title):e.reject(Error(r.error)))}else if(r.type===`message.thinking`)me(r);else if(r.type===`state`){L(),Zt.current=!1;let e=Xt.current,t=!!(e&&$t.current.has(e)),s=!(!e||r.state.conversations.some(t=>t.id===e)),c=t&&s&&e&&en.current.has(e)?{...r.state,conversations:[en.current.get(e),...r.state.conversations]}:r.state;e&&!s&&($t.current.delete(e),en.current.delete(e)),a.current=a.current.filter(e=>!e.accepted?.(c)),i(a.current),kt(e=>{let t=new Set(e);for(let e of[...t]){let n=c.conversations.find(t=>t.id===e);(!n||n.status!==`running`&&n.status!==`waiting`)&&t.delete(e)}return t}),n(c),E(!0),p(!0),y(e=>{if(e&&(c.workspaces.some(t=>t.id===e)||a.current.some(t=>t.temporaryId===e)))return e;let t=o.current?.workspaceId;return t&&c.workspaces.some(e=>e.id===t)?t:c.workspaces[0]?.id})}else if(r.type===`message.delta`)me(r);else if(r.type===`message.revert.result`)oa(void 0),Dt(void 0),r.ok||(console.error(`[Super Pi Error] revert failed:`,r.message),h(r.message));else if(r.type===`operation.result`){let e=a.current.find(e=>e.id===r.requestId);if(a.current=a.current.filter(e=>e.id!==r.requestId),i(a.current),e?.temporaryId){let t=e.temporaryId;if(r.ok&&r.entityId){let e=r.entityId,i=tn.current.get(t);if(i&&en.current.set(e,{...i,id:e}),$t.current.add(e),i){let t={...i,id:e};n(n=>n.conversations.some(t=>t.id===e)?n:{...n,conversations:[t,...n.conversations]})}It(n=>{let r=n[t];if(!r)return n;let i=n[e],a={...n};return a[e]=i?{...i,text:r.text||i.text,images:r.images.length?r.images:i.images,attachments:r.attachments.length?r.attachments:i.attachments,uploading:r.uploading+i.uploading}:r,delete a[t],a}),tn.current.delete(t)}d(n=>n===t?r.ok?r.entityId:e.previousActiveId:n),x(e=>_M(e,t,r.ok&&r.entityId?r.entityId:void 0)),y(e=>e===t?r.ok?r.entityId:void 0:e)}if(!r.ok){console.error(`[Super Pi Error] operation failed:`,r.message),e?.onFailure?.(r.message);let t=r.message??`操作失败`;h(t),e?.onFailure||B(tp(t),`error`)}}else r.type===`tools.updated`?window.dispatchEvent(new Event(`super-pi-tools-updated`)):r.type===`files.changed`?Ln.current(r.workspaceId,r.changes,r.dropped):r.type===`files.index`?r.workspaceId===zn.current&&(r.cwd??``)===Bn.current&&Rn.current(r):r.type===`error`?(console.error(`[Super Pi Error]`,r.message),h(r.message),B(tp(r.message),`error`),Zt.current&&=!1):r.type===`extension.ui`?kr(r.conversationId,r.request):r.type===`extension.ui.closed`?Ar(r.conversationId,r.requestId,r.reason):r.type===`model.catalog`?(!r.conversationId||r.conversationId===Xt.current)&&He(r.catalog):r.type===`model.catalog.all`?We(r.catalog):r.type===`providers.list`?(Ke(r.providers),Je(r.apis)):r.type===`agent.catalog`?Xe(r.catalog):r.type===`prompt.catalog`?Ae(r.catalog):r.type===`subagent.catalog`?Qe(r.catalog):r.type===`server.version`?(et(r.version),r.version.needsRestart&&B(`检测到 Super Pi 代码已更新(v${r.version.runningVersion} → v${r.version.diskVersion}),请执行 /super_pi restart 重启服务生效`,`warning`)):r.type===`subagent.event`?n(e=>({...e,subagentRuns:Dr(e.subagentRuns??[],r.run)})):r.type===`workflow.event`?n(e=>({...e,workflows:Or(e.workflows??[],r.workflow)})):r.type===`message.tools`?n(e=>({...e,conversations:e.conversations.map(e=>e.id===r.conversationId?{...e,messages:e.messages.map(e=>e.id===r.messageId?{...e,toolCalls:r.toolCalls}:e)}:e)})):r.type===`conversation.fork.result`&&(pa(e=>e===r.conversationId?void 0:e),B(r.ok?`已从「${r.title}」分叉出新会话,放在侧边栏最上面;没有切换过去。${r.messagesCopied?`复制了 ${r.messagesCopied} 条消息。`:`原会话还没有消息,只复制了会话本身。`}`:`分叉失败:${tp(r.message)}`,r.ok?`info`:`error`))}};return s(),()=>{e=!0,L(),window.clearTimeout(r);for(let e of Yt.current)window.clearTimeout(e);M.current?.close()}},[me,L]);let jr=(0,V.useCallback)(e=>M.current?.readyState===WebSocket.OPEN&&(M.current.send(JSON.stringify(e)),!0),[]);(0,V.useEffect)(()=>{if(!f)return;let e=R?.id;e?.startsWith(`pending:`)||jr({type:`state.subscribe`,...e?{conversationId:e}:{}})},[R?.id,f,jr]),(0,V.useEffect)(()=>{if(f&&qn&&Fn&&Yn.current===Fn&&Xn.current===In)return jr({type:`files.index.subscribe`,workspaceId:Fn,...In?{cwd:In}:{}}),z.requestIndex(!0),()=>{jr({type:`files.index.subscribe`}),z.cancelIndexRequest()}},[f,qn,Fn,In,jr,z.requestIndex,z.cancelIndexRequest]);let Mr=(e,t,n,r,o,s,c)=>{let l=M.current?.readyState===WebSocket.OPEN,u=nk(e);if(a.current.some(e=>e.key===t)||!l&&!u)return!1;let d=Ev(),f={id:d,key:t,apply:n,temporaryId:r,previousActiveId:Xt.current,onFailure:o,accepted:s,...c?{expiresAt:Date.now()+c}:{},...u?{retry:!0,command:e}:{}};return a.current=[...a.current,f],i(a.current),l&&M.current.send(JSON.stringify({...e,operationRequestId:d})),!0},Nr=(0,V.useRef)(new Set),Pr=(e,t)=>{jr({type:`conversation.childLock`,conversationId:e,unlocked:t})?(gA(e,t),Nr.current.add(e)):B(t?`连接断开,这个子会话没有解锁,请重试`:`连接断开,这个子会话没有上锁,请重试`,`error`)};(0,V.useEffect)(()=>{if(!T||!f)return;let e=hA();if(e.size)for(let t of l.conversations){if(!e.has(t.id))continue;let n=t.parentConversationId?l.conversations.find(e=>e.id===t.parentConversationId):void 0;dA(t.parentConversationId,n)&&(l.unlockedChildConversationIds?.includes(t.id)||Nr.current.has(t.id)||(Nr.current.add(t.id),jr({type:`conversation.childLock`,conversationId:t.id,unlocked:!0})))}},[jr,f,T,l.conversations,l.unlockedChildConversationIds]);let Fr=e=>{if(!e)return;let t=`message_${Ev()}`;Mr({type:`message.send`,conversationId:e,content:RA,clientId:t},`continue-truncated:${e}`,e=>e,void 0,void 0,void 0)};(0,V.useEffect)(()=>{let e=r.flatMap(e=>e.expiresAt?[e.expiresAt]:[]);if(!e.length)return;let t=window.setTimeout(()=>{let e=a.current.filter(e=>e.expiresAt&&e.expiresAt<=Date.now());if(e.length){a.current=a.current.filter(t=>!e.includes(t)),i(a.current);for(let t of e)t.onFailure?.(`打断请求超时,尚未确认是否开始回答;请检查会话状态后重试`)}},Math.max(0,Math.min(...e)-Date.now()));return()=>window.clearTimeout(t)},[r]);let Ir=(e,t)=>n=>({...n,conversations:n.conversations.map(n=>n.id===e?{...n,...t}:n)}),Lr=(e,t)=>n=>({...n,workspaces:n.workspaces.map(n=>n.id===e?{...n,...t}:n)}),Rr=R?.id.startsWith(`pending:`)===!0,zr=!!(R&&Sj(R)&&(Ot.has(R.id)||r.some(e=>e.key===`stop:${R.id}`))),Br=R?.messagesLoaded===!1||r.some(e=>e.key.startsWith(`send:${R?.id}:`)||e.key===`configuration:${R?.id}`||e.temporaryId===R?.id||e.key===`archive:${R?.id}`),Vr=(e,t,n,r,i)=>{e&&M.current?.send(JSON.stringify({type:`question.answer`,conversationId:e,messageId:t,callIndex:n,answers:r,cancelled:i}))},Hr=(e,t,n)=>(Mn(e),Mr({type:`extension.ui.answer`,conversationId:e,requestId:t,...n},`answer:${e}:${t}`,e=>e)),Ur=R?.model??Ve?.defaultModel,Wr=R?.thinkingLevel??Ve?.defaultThinkingLevel,Gr=Ve?.source===`pi`,Kr=!!Ve?.models.find(e=>e.provider===Ur?.provider&&e.modelId===Ur?.modelId)?.imageInput,qr=(e,t)=>!e||!t?e:{...e,models:e.models.filter(e=>(l.modelFilterRules??[]).every(n=>{try{return!new RegExp(n.workspacePattern,`i`).test(t.name)||new RegExp(n.modelPattern,`i`).test(e.label)||new RegExp(n.modelPattern,`i`).test(`${e.provider}/${e.modelId}`)}catch{return!0}}))},Jr=!!R?.messages?.some(e=>e.images&&e.images.length>0),Yr=qr(Ve,l.workspaces.find(e=>e.id===R?.workspaceId))?.models??[],Xr=(Jr?Yr.filter(e=>e.imageInput):Yr).map(e=>({key:`${e.provider}/${e.modelId}`,label:e.label,detail:e.detail,badge:HA(e),selected:Ur?.provider===e.provider&&Ur.modelId===e.modelId})),Zr=(Ve?.levels??[]).map(e=>({key:e,label:e,selected:e===Wr})),Qr=e=>{if(!R)return;let[t,n]=e.split(`/`);t&&n&&(Mn(R.id),Mr({type:`conversation.model`,conversationId:R.id,provider:t,modelId:n},`configuration:${R.id}`,Ir(R.id,{model:Ve?.models.find(e=>e.provider===t&&e.modelId===n)??{provider:t,modelId:n,label:n}})))},$r=e=>{R&&(Mn(R.id),Mr({type:`conversation.thinking`,conversationId:R.id,level:e},`configuration:${R.id}`,Ir(R.id,{thinkingLevel:e})))},ei=Ye?.agents.find(e=>e.id===R?.agentId),ti=[{key:gj,label:`跟随 Pi 默认`,detail:`不使用任何 agent 角色`,selected:!R?.agentId},...(Ye?.agents??[]).map(e=>({key:e.id,label:e.name,detail:e.toolSummary,color:e.color,selected:R?.agentId===e.id}))],ni=ei?.model,ri=!!(ni&&R?.model&&R.model.provider===ni.provider&&R.model.modelId===ni.modelId);ei?.thinkingLevel&&(R?.thinkingLevel,ei.thinkingLevel);let ii=e=>{if(R){let t=Ye?.agents.find(t=>t.id===e);Mr({type:`conversation.agent`,conversationId:R.id,agentId:e===gj?null:e},`configuration:${R.id}`,Ir(R.id,{agentId:t?.id,...t?.model?{model:{...t.model,label:t.model.modelId}}:{},...t?.thinkingLevel?{thinkingLevel:t.thinkingLevel}:{}}))}},ai=je.filter(e=>e.conversationId===R?.id),oi=(0,V.useMemo)(()=>(l.subagentRuns??[]).filter(e=>e.conversationId===R?.id),[l.subagentRuns,R?.id]),si=(0,V.useMemo)(()=>(l.workflows??[]).filter(e=>e.conversationId===R?.id),[l.workflows,R?.id]),ci=(0,V.useMemo)(()=>new Map(si.map(e=>[e.id,e])),[si]),li=(0,V.useMemo)(()=>new Map((Ze?.agents??[]).map(e=>[e.id,e.name])),[Ze]),ui=(0,V.useMemo)(()=>new Map((R?.messages??[]).map(e=>[e.id,e])),[R?.messages]),di=(0,V.useMemo)(()=>new Map(oi.map(e=>[e.id,e])),[oi]),fi=(0,V.useMemo)(()=>{let e=new Map;for(let t of oi)t.originMessageId!==void 0&&t.originCallRow!==void 0&&e.set(`${t.originMessageId}:${t.originCallRow}`,t);return e},[oi]),pi=(0,V.useMemo)(()=>{if(!R||!jn)return[];let e=Et?.conversationId===R.id?(()=>{let e=R.messages.find(e=>e.id===Et.messageId);if(e)return{index:R.messages.indexOf(e),at:Date.parse(e.createdAt)||0,...Et.kind===`withdraw`?{inclusive:!0}:{inclusive:!1}}})():void 0,t=[];return R.messages.forEach((n,r)=>{e&&(r>e.index||e.inclusive&&r===e.index)||n.delivery||t.push({at:Date.parse(n.createdAt)||0,seq:r,key:`m:${n.id}`})}),oi.forEach((n,r)=>{n.originMessageId&&n.originCallRow!==void 0&&R?.messages.some(e=>e.id===n.originMessageId&&e.toolCalls?.[n.originCallRow])||e&&(Date.parse(n.startedAt)||0)>e.at||t.push({at:Date.parse(n.startedAt)||0,seq:t.length+r,key:`r:${n.id}`})}),si.forEach((n,r)=>{e&&(Date.parse(n.startedAt)||0)>e.at||t.push({at:Date.parse(n.startedAt)||0,seq:t.length+r,key:`w:${n.id}`})}),t.sort((e,t)=>e.at-t.at||e.seq-t.seq).map(e=>e.key)},[R,oi,si,Et]),mi=(0,V.useMemo)(()=>{for(let e=pi.length-1;e>=0;--e){let t=pi[e];if(t.startsWith(`m:`)&&ui.get(t.slice(2))?.role===`user`)return t.slice(2)}},[pi,ui]);(0,V.useEffect)(()=>{let e=ne.current;if(!e||!R?.id)return;let t=()=>{!ce.current&&N.current[R.id]?.followTail&&(dM(e),e.scrollTop=e.scrollHeight)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);n.observe(e);for(let t of e.children)n.observe(t);return()=>n.disconnect()},[R?.id,R?.messages,oi,si,jn,pi]);let hi=e=>xt(t=>({...t,[e]:!t[e]})),gi=(e,t)=>Ct(n=>({...n,[`${e}:${t}`]:!n[`${e}:${t}`]})),_i=(e,t)=>Tt(n=>({...n,[`${e}:${t}`]:n[`${e}:${t}`]!==!1})),[vi,yi]=(0,V.useState)({}),bi=e=>yi(t=>({...t,[e]:t[e]!==!0})),xi=e=>{Mr({type:`subagent.stop`,runId:e},`stop:${e}`,e=>e)||B(`连接断开,无法停止子智能体,请重试`,`error`)},Si=e=>{Mr({type:`workflow.stop`,workflowId:e},`stop:${e}`,e=>e)||B(`连接断开,无法停止编排,请重试`,`error`)},Ci=e=>[...Le].filter(([,t])=>t.placement===e).map(([e,t])=>{let n=t.lines;return(0,H.jsxs)(`div`,{className:`extui-widget`,"data-widget-key":e,"data-widget-lines":n.length,children:[n.slice(0,YA).map((e,t)=>(0,H.jsx)(`div`,{children:e},`${t}:${e}`)),n.length>YA&&(0,H.jsx)(`div`,{children:`… (widget truncated)`})]},e)}),wi=(e,t)=>{let n=`pending:${Ev()}`,r={id:n,name:e,path:t,updatedAt:new Date().toISOString()};Mr({type:`workspace.create`,name:e,path:t},`create-workspace`,e=>({...e,workspaces:[...e.workspaces,r]}),n)&&(y(n),d(void 0),O(!1))},[Ti,Ei]=(0,V.useState)(),Di=(e,t)=>Ei(n=>n?.kind===e&&n.id===t?n:{kind:e,id:t}),Oi=()=>Ei(void 0),ki=(e,t)=>Ti?.kind===e&&Ti.id===t,Ai=(e,t,n)=>!t.startsWith(`pending:`)&&(e===`conversation`&&Mn(t),Mr(e===`workspace`?{type:`workspace.rename`,workspaceId:t,name:n}:{type:`conversation.rename`,conversationId:t,name:n},`rename:${t}`,e===`workspace`?Lr(t,{name:n}):Ir(t,{title:n}))?(Zt.current=!0,Oi(),!0):(B(`连接断开,改名未保存,请重试`,`error`),!1)),ji=async e=>{if(e.startsWith(`pending:`)){B(`这个会话还在创建中,稍后再试`,`warning`);return}if(Pt.current.has(e))return;B(`正在根据对话内容生成标题…`,`info`);let t=new Promise((t,n)=>{Pt.current.set(e,{resolve:t,reject:n}),window.setTimeout(()=>{Pt.current.delete(e)&&n(Error(`模型在 30 秒内没有返回标题`))},32e3)});if(!jr({type:`conversation.autoRename`,conversationId:e}))Pt.current.delete(e),B(`连接断开,无法生成标题`,`error`);else try{let n=await t;Ai(`conversation`,e,n),B(`已重命名为「${n}」`,`info`)}catch(e){B(`重命名失败:${tp(e)}`,`error`)}},Mi=e=>{if(e.id.startsWith(`pending:`))return;let t=l.conversations.filter(t=>t.workspaceId===e.id).length;window.confirm(`从列表移除工作区「${e.name}」?${t?`其中的 ${t} 条会话会保留,`:``}重新添加同一个目录即可恢复,不会删除任何会话。`)&&Mr({type:`workspace.delete`,workspaceId:e.id},`delete:${e.id}`,t=>({...t,workspaces:t.workspaces.filter(t=>t.id!==e.id),conversations:t.conversations.filter(t=>t.workspaceId!==e.id)}))},[Ni,Pi]=(0,V.useState)(),Fi=Ni?l.workspaces.find(e=>e.id===Ni):void 0,{theme:Ii,setTheme:Li}=ny(),[Ri,zi]=(0,V.useState)(!1),[Bi,Vi]=(0,V.useState)(!1),Hi=(e,t,n,r)=>{e.startsWith(`pending:`)||(Mr({type:`workspace.settings`,workspaceId:e,model:n?{provider:n.provider,modelId:n.modelId}:null,thinkingLevel:r??null,agentId:t??null},`defaults:${e}`,Lr(e,{defaultModel:n,defaultThinkingLevel:r,defaultAgentId:t}))?Pi(void 0):B(`连接断开,设置未保存,请重试`,`error`))},Ui=(e,t=``)=>{if(e.startsWith(`pending:`))return;if(a.current.some(t=>t.key===`defaults:${e}`)){B(`工作区设置正在保存,请稍后再新建会话`,`warning`);return}let n=`pending:${Ev()}`,r={id:n,workspaceId:e,title:`新会话`,status:`idle`,updatedAt:new Date().toISOString(),messages:[],...t?{cwd:t}:{}};tn.current.set(n,r),Mr({type:`conversation.create`,workspaceId:e,...t?{cwd:t}:{}},`create-session:${e}:${n}`,e=>({...e,conversations:[r,...e.conversations]}),n)?(y(e),d(n),nr(`session`),x(e=>({...e,ids:[...e.ids.filter(e=>e!==n),n],touched:gM(e.touched,n)}))):(tn.current.delete(n),B(`连接断开,会话未创建,请重试`,`error`))},Wi=e=>{if(e.startsWith(`pending:`))return;let t=l.conversations.find(t=>t.id===e);if(!t||t.archivedAt||t.parentConversationId&&l.conversations.some(e=>e.id===t.parentConversationId))return;let n=AA(l.conversations,e),r=n.filter(e=>!e.archivedAt),i=r.length-1,a=n.length-r.length;if(i>0&&!window.confirm(`归档整棵会话树「${t.title}」?本次将归档 ${r.length} 个会话(1 个根会话和 ${i} 个活跃子孙)${a?`,跳过 ${a} 个已归档子孙`:``};恢复根会话时,整棵树会一起恢复。`))return;let o=new Date().toISOString(),s=new Set(r.map(e=>e.id));Mr({type:`conversation.archive`,conversationId:e},`archive:${e}`,e=>({...e,conversations:e.conversations.map(e=>s.has(e.id)&&!e.archivedAt?{...e,archivedAt:o}:e)}))},Gi=(e,t)=>Mr({type:`conversation.collapse`,conversationId:e,collapsed:t},`collapse:${e}`,n=>{let r=new Set(n.collapsedConversationIds??[]);t?r.add(e):r.delete(e);let i={...n};return r.size===0?delete i.collapsedConversationIds:i.collapsedConversationIds=[...r],i}),Ki=e=>{let t=l.conversations.find(t=>t.id===e);if(!t?.archivedAt||(t.parentConversationId?l.conversations.find(e=>e.id===t.parentConversationId):void 0)?.archivedAt)return;let n=new Set(AA(l.conversations,e).filter(e=>e.archivedAt).map(e=>e.id));Mr({type:`conversation.unarchive`,conversationId:e},`unarchive:${e}`,e=>({...e,conversations:e.conversations.map(e=>{if(!n.has(e.id)||!e.archivedAt)return e;let t={...e};return delete t.archivedAt,t})}))},qi=async e=>{if(!R){B(`请先选择或创建会话`,`error`);return}if(!Kr){B(`当前模型不支持图片输入`,`error`);return}let t=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],n=e.filter(e=>t.includes(e.type)?e.size>5242880?(B(`图片「${e.name}」超过 5MB 上限`,`error`),!1):!0:(B(`不支持的文件格式「${e.name}」,仅支持 PNG/JPEG/GIF/WebP`,`error`),!1));if(n.length===0)return;let r=R.id;Sn(r,e=>({...e,uploading:e.uploading+n.length}));let i=n.map(e=>({id:Ev(),conversationId:r,name:e.name,url:URL.createObjectURL(e)}));Vt(e=>[...e,...i]);for(let[e,t]of n.entries()){let n=i[e];try{let e=await new Promise((e,n)=>{let r=new FileReader;r.onload=()=>{let t=r.result,n=t.indexOf(`,`);e(n>=0?t.slice(n+1):t)},r.onerror=n,r.readAsDataURL(t)}),i=await fetch(`/api/upload`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({conversationId:r,name:t.name,mimeType:t.type,data:e})});if(!(i.headers.get(`content-type`)??``).includes(`application/json`)){B(`服务器未返回 JSON 响应,请刷新或重启服务`,`error`);continue}if(i.ok){let e=await i.json();if(Lt.current.has(n.id))continue;Vt(e=>e.filter(e=>e.id!==n.id)),URL.revokeObjectURL(n.url),Sn(r,t=>({...t,images:[...t.images,{id:e.id,name:e.name,mimeType:e.mimeType,bytes:e.bytes}]}))}else{let e=await i.json().catch(()=>({error:`上传失败`}));B(tp(e.error,`上传失败(HTTP ${i.status})`),`error`)}}catch(e){B(`上传失败:${tp(e,`网络或服务暂时不可用`)}`,`error`)}finally{Vt(e=>e.map(e=>e.id===n.id?{...e,failed:!0}:e)),Sn(r,e=>({...e,uploading:Math.max(0,e.uploading-1)}))}}},Ji=e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r.type.startsWith(`image/`)){let e=r.getAsFile();e&&n.push(e)}}if(n.length>0){if(!Kr){B(`当前模型不支持图片输入`,`error`);return}e.preventDefault(),qi(n)}},Yi=e=>{e.dataTransfer?.types?.includes(`Files`)&&(e.preventDefault(),Gt(!0))},Xi=e=>{e.currentTarget.contains(e.relatedTarget)||Gt(!1)},Zi=e=>{Gt(!1);let t=Array.from(e.dataTransfer?.files??[]).filter(e=>e.type.startsWith(`image/`));if(t.length>0){if(e.preventDefault(),!Kr){B(`当前模型不支持图片输入`,`error`);return}qi(t)}},Qi=e=>{if(e.preventDefault(),!R)return;if(un){B(uA,`warning`);return}if(Br){B(Rr?`会话正在创建,请稍候再发送`:R.messagesLoaded===!1?`正在加载会话,请稍候再发送`:`正在保存配置,请稍候再发送`,`info`);return}if(!vn.trim()&&yn.length===0)return;if(yn.length>0&&!Kr){B(`当前模型不支持图片输入,请移除图片或切换至支持图文的模型`,`error`);return}if(xn>0){B(`图片正在上传中,请稍候…`,`info`);return}let t=`message_${Ev()}`,n=R.id,r=vn,i=yn,a=bn;Mn(n),Mr({type:`message.send`,conversationId:n,content:vn,clientId:t,...yn.length>0?{images:yn}:{},...bn.length>0?{attachments:bn}:{}},`send:${n}:${t}`,e=>{let a=e.conversations.find(e=>e.id===n);if(!a||a.messages.some(e=>e.id===t))return e;let o=a.status===`running`||a.status===`waiting`,s=new Date().toISOString();return{...e,conversations:e.conversations.map(e=>e.id===n?{...e,...o?{}:{status:`waiting`,updatedAt:s},messages:[...e.messages,{id:t,role:`user`,content:r,...i.length>0?{images:i}:{},...bn.length>0?{attachments:bn}:{},...o?{delivery:`waiting`}:{},createdAt:s}]}:e)}},t,e=>{zt(o=>[...o,{id:t,conversationId:n,content:r,images:i,attachments:a,reason:e}]),Sn(n,e=>e.text||e.images.length||e.attachments.length?e:{...e,text:r,images:i,attachments:a})},e=>!!e.conversations.find(e=>e.id===n)?.messages.some(e=>e.id===t))?Sn(R.id,e=>({...e,text:``,images:[]})):B(`这条消息已经在发送队列中,请稍候`,`info`)},$i=(0,V.useMemo)(()=>(R?.messages??[]).filter(e=>(e.role===`user`||e.role===`tool`)&&e.delivery),[R?.messages]),ea=e=>{Mr({type:`message.cancel`,conversationId:R?.id??``,messageId:e},`queue:${e}`,t=>({...t,conversations:t.conversations.map(t=>t.id===R?.id?{...t,messages:t.messages.filter(t=>t.id!==e)}:t)}))||B(`连接断开,撤回没有生效,请重试`,`error`)},ta=e=>{Mr({type:`message.steer`,conversationId:R?.id??``,messageId:e},`queue:${e}`,t=>({...t,conversations:t.conversations.map(t=>t.id===R?.id?{...t,messages:_A(t.messages,e,0)}:t)}),void 0,void 0,t=>t.conversations.find(e=>e.id===R?.id)?.messages.find(t=>t.id===e)?.delivery===`sending`)||B(`连接断开,插到最前没有生效,请重试`,`error`)},na=e=>{let t=R?.id;t&&(M.current?.readyState===WebSocket.OPEN?Mr({type:`message.interrupt`,conversationId:t,messageId:e},`interrupt:${t}:${e}`,e=>e,void 0,e=>B(e??`打断失败,请重试`,`error`),n=>{let r=n.conversations.find(e=>e.id===t)?.messages.find(t=>t.id===e);return!(!r||r.delivery)},3e4)||B(`正在打断,请稍候`,`info`):B(`连接断开,打断没有生效,请重试`,`error`))},ra=e=>{Mr({type:`message.sendQueued`,conversationId:R?.id??``,messageId:e},`send-queued:${e}`,e=>e,void 0,void 0,t=>!t.conversations.find(e=>e.id===R?.id)?.messages.find(t=>t.id===e)?.delivery)||B(`连接断开,发送没有生效,请重试`,`error`)},ia=(e,t)=>{Mr({type:`message.edit`,conversationId:R?.id??``,messageId:e,content:t},`edit:${e}`,n=>({...n,conversations:n.conversations.map(n=>n.id===R?.id?{...n,messages:n.messages.map(n=>n.id===e?{...n,content:t}:n)}:n)}))||B(`连接断开,修改没有生效,请重试`,`error`)},[aa,oa]=(0,V.useState)(),sa=(e,t=!1)=>{if(!R||R.messagesLoaded===!1||aa)return;let n=R.messages.find(t=>t.id===e);n&&(n&&It(e=>{let t=e[R.id]??{text:``,images:[],attachments:[],uploading:0};return t.text.trim()||t.images.length||t.attachments.length?e:{...e,[R.id]:{...t,text:n.content,images:n.images??[]}}}),Dt({conversationId:R.id,messageId:e,kind:t?`withdraw`:`revert`})),jr({type:`message.revert`,conversationId:R.id,messageId:e,withdraw:t})?oa(e):(Dt(void 0),B(`连接断开,回退未执行,请重试`,`error`))},[ca,la]=(0,V.useState)(),ua=(0,V.useRef)(void 0),da=async(e,t)=>{ua.current&&clearTimeout(ua.current);let n=await PA(t);la({id:e,kind:n?`copied`:`error`}),n||B(`复制失败:浏览器拒绝了剪贴板写入,可以手动选中这条消息的文字复制`,`error`),ua.current=setTimeout(()=>la(void 0),2e3)};(0,V.useEffect)(()=>()=>{ua.current&&clearTimeout(ua.current)},[]);let[fa,pa]=(0,V.useState)(),ma=e=>{fa||e.startsWith(`pending:`)||(Mn(e),jr({type:`conversation.fork`,conversationId:e})?pa(e):B(`连接断开,分叉没有执行,请重试`,`error`))},ha=new Map;for(let e of l.scheduledTasks??[])e.conversationId&&!ha.has(e.conversationId)&&ha.set(e.conversationId,e);return(0,H.jsxs)(`main`,{className:`shell${rt?` shell-rail-collapsed`:``} mobile-panel-${at}${st?` mobile-drawer-open`:``}`,"data-rail-collapsed":rt,"data-selected-workspace":v??``,style:{"--sidebar-width":`${pt.sidebar}px`,"--rail-col":rt?void 0:`${pt.rail}px`},children:[(0,H.jsxs)(`aside`,{children:[(0,H.jsxs)(`div`,{className:`brand`,children:[(0,H.jsx)(`span`,{children:`π`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`strong`,{children:`SUPER PI`}),(0,H.jsx)(`small`,{children:`agent workspace`})]})]}),(0,H.jsx)(`div`,{className:`sidebar-actions`,children:(0,H.jsx)(`button`,{className:`workspace-new`,onClick:()=>O(!0),children:`+ 工作区`})}),(0,H.jsx)(`div`,{className:`label label-desktop`,children:`工作区`}),(0,H.jsx)(`div`,{className:`label label-phone`,children:`会话`}),(0,H.jsx)(`nav`,{children:l.workspaces.map(e=>{let t=l.conversations.filter(t=>t.workspaceId===e.id),n=t.filter(e=>!e.archivedAt),r=uk(n,sn,{manualRoots:ve[e.id]}),i=r.filter(e=>e.depth===0).map(e=>e.conversation.id),a=t.filter(e=>e.archivedAt),o=uk(a,new Set),s=g[e.id]??!1,c=ge[e.id]??!0;return(0,H.jsxs)(`section`,{className:`workspace-group`,"data-workspace-group":e.id,children:[(0,H.jsx)(`div`,{className:`workspace-header`,children:ki(`workspace`,e.id)?(0,H.jsx)(mj,{initial:e.name,label:`重命名工作区 ${e.name}`,onCommit:t=>Ai(`workspace`,e.id,t),onClose:Oi}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{className:`workspace-toggle`,"aria-expanded":!s,title:e.path,onContextMenu:t=>{t.preventDefault();let n=t.currentTarget.getBoundingClientRect();jt({workspace:e,x:t.clientX||n.left+24,y:t.clientY||n.top+n.height})},onClick:()=>{let t=an.find(t=>t.workspaceId===e.id)?.id;y(e.id),d(t),_(t=>({...t,[e.id]:!s}))},children:[(0,H.jsx)(`span`,{className:`chevron chevron-folder`,"aria-hidden":`true`,children:s?`📁`:`📂`}),(0,H.jsxs)(`span`,{children:[(0,H.jsx)(`strong`,{onDoubleClick:()=>Di(`workspace`,e.id),children:e.name}),(0,H.jsx)(`small`,{children:e.path})]})]}),(0,H.jsx)(`button`,{className:`workspace-add`,title:`在此工作区新建会话`,onClick:t=>{j.current=t.currentTarget,A({workspaceId:e.id})},children:`+`}),(0,H.jsx)(`button`,{className:`workspace-settings`,title:`工作区设置(默认智能体 / 模型 / 思考强度)`,"aria-label":`工作区设置 ${e.name}`,onClick:()=>Pi(e.id),children:`⚙`}),(0,H.jsx)(`button`,{className:`workspace-delete`,title:`从列表移除工作区(会话保留,重新添加同一目录即可恢复)`,onClick:()=>Mi(e),children:`×`})]})}),!s&&(r.length?r.map(({conversation:t,depth:r,childCount:a,isLastSibling:o})=>(0,H.jsxs)(`div`,{className:`conversation-row`,style:{"--tree-depth":r},"data-session-root":r===0?t.id:void 0,"data-session-dragging":be?.conversationId===t.id?`true`:void 0,"data-session-drop":be?.dropRootId===t.id?be.dropAfter?`after`:`before`:void 0,onPointerDown:r===0?n=>we(n,e.id,t.id,i):void 0,children:[a>0?(0,H.jsxs)(`button`,{type:`button`,className:`conversation-tree-toggle`,"data-tree-toggle":t.id,"aria-expanded":!sn.has(t.id),title:sn.has(t.id)?`展开 ${a} 个子会话`:`折叠 ${a} 个子会话`,"aria-label":sn.has(t.id)?`展开会话 ${t.title} 的 ${a} 个子会话`:`折叠会话 ${t.title} 的 ${a} 个子会话`,onClick:()=>Gi(t.id,!sn.has(t.id)),children:[(0,H.jsx)(`span`,{className:`chevron`,"aria-hidden":`true`,children:sn.has(t.id)?`▸`:`▾`}),(0,H.jsx)(`small`,{children:a})]}):(0,H.jsx)(`span`,{className:`conversation-tree-spacer`,"aria-hidden":`true`}),ki(`conversation`,t.id)?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(mj,{initial:t.title,label:`重命名会话 ${t.title}`,onCommit:e=>Ai(`conversation`,t.id,e),onClose:Oi}),(0,H.jsx)(`small`,{className:`conversation-time`,children:kA(t.updatedAt,nn)})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{className:`conversation ${R?.id===t.id?`selected`:``}`,"data-conversation":t.id,"data-tree-child":r>0?`true`:void 0,"data-tree-last":r>0&&o?`true`:void 0,title:r>0?`${t.title}(由「${n.find(e=>e.id===t.parentConversationId)?.title??`已不存在的会话`}」创建)`:t.title,"aria-label":`打开会话 ${t.title}${kj(t,ha.get(t.id))}`,onContextMenu:e=>{e.preventDefault();let n=e.currentTarget.getBoundingClientRect();Nt({conversation:t,x:e.clientX||n.left+24,y:e.clientY||n.top+n.height})},onClick:()=>{t.id===Ce.current&&Date.now()-Se.current<300||(Nn(t.id),y(e.id),ct(!1))},onDoubleClick:()=>{Pn(t.id)},children:[(0,H.jsx)(`i`,{className:`conversation-mark`,children:(0,H.jsx)(Dj,{state:Ej(t,Tj(t,je),F.current[t.id])})}),(0,H.jsx)(`span`,{"data-conversation-title":t.id,onDoubleClick:e=>{e.stopPropagation(),Di(`conversation`,t.id)},style:{flex:`0 1 auto`},children:t.title}),(0,H.jsx)(`span`,{className:`conversation-title-gap`,"aria-hidden":`true`,style:{marginLeft:`-8px`}}),Oj(t,ha.get(t.id)),(0,H.jsx)(`small`,{children:kA(t.updatedAt,nn)})]}),(0,H.jsx)(`button`,{type:`button`,className:`conversation-fork`,"data-fork-conversation":t.id,"data-fork-state":fa===t.id?`pending`:`idle`,disabled:!!fa,title:`从此会话分叉出一个新会话`,"aria-label":`从会话 ${t.title} 分叉出一个新会话`,onClick:()=>ma(t.id),children:`⑂`}),!(t.parentConversationId&&l.conversations.some(e=>e.id===t.parentConversationId))&&(0,H.jsx)(`button`,{className:`conversation-archive`,"data-archive-conversation":t.id,title:`归档整棵会话树`,"aria-label":`归档会话 ${t.title}`,onClick:()=>Wi(t.id),children:`×`})]})]},t.id)):(0,H.jsx)(`div`,{className:`conversation-empty`,children:`暂无会话`})),!s&&a.length>0&&(0,H.jsxs)(`div`,{className:`archived-group`,"data-archived-count":a.length,children:[(0,H.jsxs)(`button`,{className:`archived-toggle`,title:c?`展开已归档会话`:`收起已归档会话`,"aria-expanded":!c,onClick:()=>_e(t=>({...t,[e.id]:!c})),children:[(0,H.jsx)(`span`,{className:`chevron`,"aria-hidden":`true`,children:c?`▸`:`▾`}),(0,H.jsxs)(`span`,{className:`archived-label`,children:[`已归档 (`,a.length,`)`]})]}),!c&&o.map(({conversation:e,depth:t,isLastSibling:n})=>{let r=AA(a,e.id).length-1,i=!!(e.parentConversationId&&l.conversations.some(t=>t.id===e.parentConversationId&&t.archivedAt));return(0,H.jsxs)(`div`,{className:`conversation-archived`,"data-archived-conversation":e.id,"data-archived-at":e.archivedAt,"data-tree-child":t>0?`true`:void 0,"data-tree-last":t>0&&n?`true`:void 0,style:{"--tree-depth":t},children:[(0,H.jsx)(`i`,{className:`conversation-mark`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{"data-archived-title":e.id,children:e.title}),Oj(e,ha.get(e.id)),(0,H.jsx)(`small`,{children:jA(e.archivedAt)}),!i&&(0,H.jsx)(`button`,{className:`conversation-restore`,"data-restore-conversation":e.id,title:r?`恢复这个会话和它的 ${r} 个子孙会话`:`恢复为正常会话`,"aria-label":r?`恢复会话 ${e.title} 及其 ${r} 个子孙会话`:`恢复会话 ${e.title}`,onClick:()=>Ki(e.id),children:`↑`})]},e.id)})]})]},e.id)})}),(0,H.jsxs)(`footer`,{children:[(0,H.jsxs)(`div`,{className:`footer-status`,children:[(0,H.jsx)(`i`,{className:f?`online`:`offline`}),f?`已连接`:`正在连接`,(0,H.jsx)(`span`,{children:`本地持久化`})]}),(0,H.jsxs)(`div`,{className:`footer-version`,"data-super-pi-version":$e?.runningVersion??``,children:[`Super Pi v`,$e?.runningVersion??`…`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,"data-theme-open":`1`,"aria-haspopup":`dialog`,"aria-expanded":Ri,onClick:()=>{zi(!0),jr({type:`catalog.fetchAll`}),jr({type:`providers.fetch`})},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`⚙`}),`设置`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,"data-help-open":`1`,"aria-haspopup":`dialog`,"aria-expanded":Bi,onClick:()=>Vi(!0),children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`📖`}),`使用指南`]}),(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger`,title:`检查 Super Pi 更新`,disabled:tt!==`idle`,onClick:async()=>{nt(`updating`);try{let e=await fetch(`/api/update-check`);if(!e.ok)throw Error(`check failed`);let t=await e.json();if(t.needsRestart)B(`当前代码已更新,正在重启服务…`,`info`);else if(t.updateAvailable){if(!window.confirm(`发现新版本 v${t.latestVersion??``},是否立即更新并重启 Super Pi?`))B(`已取消更新`,`info`);else{if(!(await fetch(`/api/update`,{method:`POST`})).ok)throw Error(`update failed`);B(`正在更新到 v${t.latestVersion} 并重启…`,`info`)}}else B(`当前已是最新版本`,`info`)}catch{B(`检查更新失败,请检查网络或服务日志`,`error`)}finally{nt(`idle`)}},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:tt===`updating`?`⟳`:`↻`}),tt===`updating`?`正在检查更新…`:`检查更新`]}),$e?.needsRestart&&(0,H.jsxs)(`button`,{type:`button`,className:`theme-settings-trigger restart-needed-trigger`,disabled:tt!==`idle`,title:`代码已更新:当前运行 v${$e.runningVersion},磁盘版本 v${$e.diskVersion}。点击复制重启命令 /super_pi restart`,onClick:async()=>{nt(`updating`);try{if(!(await fetch(`/api/update`,{method:`POST`})).ok)throw Error(`update failed`);B(`正在更新 Super Pi,服务即将重启…`,`info`)}catch{nt(`idle`),B(`更新启动失败,请检查服务日志`,`error`)}},children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:tt===`updating`?`⟳`:`⚠️`}),tt===`updating`?`正在更新并重启…`:`更新并重启服务`]})]})]}),(0,H.jsx)(SM,{side:`left`,width:pt.sidebar,min:pt.sidebarMin,max:pt.sidebarMax,label:`调整左侧栏宽度`,onWidth:mt}),(0,H.jsxs)(`section`,{className:`chat`,"data-main-view":tr,"data-main-view-kind":tr,children:[yr.length>0&&(0,H.jsx)(`div`,{className:`chat-tab-strip`,"data-chat-tab-strip":`1`,"data-session-count":An.length,"data-file-count":z.open.length,children:(0,H.jsx)(G_,{tabs:yr,prefix:`workspace-tab`,ariaLabel:`工作区标签页`,activeId:br,onSelect:xr,onClose:wr,onActivate:Sr,minWidth:120,maxWidth:320})}),(0,H.jsxs)(`header`,{children:[(0,H.jsx)(`button`,{type:`button`,className:`mobile-drawer-toggle`,"data-mobile-drawer-toggle":`1`,"aria-label":`打开会话列表`,title:`会话列表`,"aria-expanded":st,onClick:()=>ct(!0),children:`☰`}),(0,H.jsxs)(`div`,{className:`chat-head`,children:[(0,H.jsx)(`h1`,{children:R?.title??`准备开始`}),Fe.size>0?[...Fe].map(([e,t])=>(0,H.jsx)(`p`,{"data-role":`run-status`,"data-status-key":e,children:`扩展状态:${e?`${e} · `:``}${t}`},e)):(0,H.jsx)(`p`,{"data-role":`run-status`,children:R?.status===`running`?`Agent 正在工作`:R?.status===`awaiting_background`?`后台任务运行中`:`Pi runtime · Web 控制台`})]}),(0,H.jsxs)(`span`,{className:`chat-view chat-view-${tr}`,"data-main-view-indicator":tr,"data-main-view-kind":tr,title:tr===`file`?`中间主画面正在显示文件 ${z.active?.path??``}`:tr===`diff`?`中间主画面正在显示 ${rr??``} 的改动`:`中间主画面正在显示这个会话的消息流`,children:[(0,H.jsx)(`span`,{className:`chat-view-label`,children:`主区显示`}),(0,H.jsx)(`span`,{className:`chat-view-kind`,children:tr===`file`?`文件`:tr===`diff`?`改动`:`会话`}),tr===`file`&&z.active&&(0,H.jsx)(`span`,{className:`chat-view-name`,"data-main-view-name":z.active.name,children:z.active.name}),tr===`diff`&&rr&&(0,H.jsx)(`span`,{className:`chat-view-name`,"data-main-view-name":rr,children:rr})]}),(0,H.jsx)(`div`,{className:`badge`,"data-conversation-status":R?.status??`idle`,children:xj[R?.status??`idle`]})]}),m&&(0,H.jsxs)(`div`,{className:`error`,role:`alert`,"data-global-error":!0,children:[(0,H.jsx)(`span`,{title:np(m),children:tp(m)}),(0,H.jsx)(`button`,{type:`button`,"aria-label":`关闭错误提示`,title:`关闭错误提示`,onClick:()=>h(void 0),children:`×`})]}),R?.error&&(0,H.jsx)(`div`,{className:`error`,"data-role":`conversation-error`,title:np(R.error),children:tp(R.error)}),R?.warning&&(0,H.jsxs)(`div`,{className:`warning`,role:`status`,"data-role":`conversation-warning`,title:np(R.warning),children:[(0,H.jsx)(`span`,{children:R.warning}),(0,H.jsx)(`button`,{type:`button`,"data-role":`conversation-warning-continue`,title:`让模型接着把被截断的部分写完`,onClick:()=>Fr(R?.id??``),children:`继续写完`})]}),R?.modelNotice&&(0,H.jsx)(`div`,{className:`model-notice`,"data-role":`conversation-model-notice`,children:R.modelNotice}),R?.agentNotice&&(0,H.jsx)(`div`,{className:`model-notice`,"data-role":`conversation-agent-notice`,children:R.agentNotice}),ze&&(0,H.jsxs)(`div`,{className:`extui-title-note`,children:[`扩展建议标题:`,ze]}),Ne.length>0&&(0,H.jsx)(`div`,{className:`toasts`,role:`status`,"aria-live":`polite`,"data-toast-count":Ne.length,children:Ne.map(e=>(0,H.jsx)(`div`,{className:`toast toast-${e.kind}`,"data-toast-kind":e.kind,children:e.text},e.key))}),tr===`file`?(0,H.jsx)(`div`,{className:`chat-file-view`,"data-main-file-view":Tr?.path,"data-file-view-kind":`editor`,children:Tr?(0,H.jsx)(A_,{file:Tr,state:z.saves[Tr.path]?.state??`idle`,message:z.saves[Tr.path]?.message??``,external:z.external[Tr.path]===!0,jumpToLine:$n&&$n.workspaceId===v&&$n.path===Tr.path?$n:void 0,onChange:e=>z.updateBuffer(Tr.path,e),onSave:()=>void z.save(Tr.path,!1),onReload:()=>void z.reload(Tr.path),onOverwrite:()=>void z.save(Tr.path,!0),workspaceId:v,cwd:In}):(0,H.jsx)(`p`,{className:`rail-empty`,"data-main-file-empty":`1`,children:`没有选中的文件。`})}):tr===`diff`?(0,H.jsx)(`div`,{className:`chat-file-view`,"data-main-diff-view":rr??``,"data-file-view-kind":`diff`,children:(0,H.jsx)(M_,{diff:lr.diff,loading:lr.loading,error:lr.error,bufferContent:pr,mode:dr,onMode:fr})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`messages`,ref:ne,"data-message-scroll-container":R?.id??``,onWheel:e=>{e.deltaY<0&&N.current[R?.id??``]?.followTail&&(ce.current=!0,gn(e.currentTarget,!0))},onScroll:e=>{let t=e.currentTarget;t.dataset.programmaticScroll===`true`?delete t.dataset.programmaticScroll:gn(t)},children:[(!R||!jn)&&(0,H.jsxs)(`div`,{className:`empty`,children:[(0,H.jsx)(`div`,{className:`orb`,children:`π`}),(0,H.jsx)(`h2`,{children:`开始一个新会话`}),l.workspaces.length===0?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{children:`先创建一个工作区,再开始会话。`}),(0,H.jsx)(`button`,{onClick:()=>O(!0),children:`+ 新建工作区`})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{children:l.workspaces.length===1&&fn?`在「${fn.name}」中创建会话,即可向 Super Pi 发送任务。`:`选择工作区即可开始会话,向 Super Pi 发送任务。`}),l.workspaces.length>1&&(0,H.jsxs)(`div`,{className:`empty-workspace-select`,children:[(0,H.jsx)(`label`,{htmlFor:`empty-workspace-choice`,children:`工作区:`}),(0,H.jsxs)(`select`,{id:`empty-workspace-choice`,"aria-label":`选择工作区`,value:fn?.id,onChange:e=>{e.target.value===`__new__`?O(!0):y(e.target.value)},children:[l.workspaces.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name},e.id)),(0,H.jsx)(`option`,{value:`__new__`,children:`+ 新建工作区…`})]})]}),fn&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(GA,{workspaceId:fn.id,value:pn,onChange:mn}),(0,H.jsx)(`button`,{onClick:()=>Ui(fn.id,pn),children:`新建会话`})]}),(0,H.jsx)(`span`,{className:`empty-secondary-action`,role:`button`,tabIndex:0,onClick:()=>O(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),O(!0))},children:`+ 新建工作区`})]})]}),R?.messagesLoaded===!1&&(0,H.jsx)(`p`,{role:`status`,"data-conversation-loading":`1`,children:`正在加载会话…`}),pi.map(e=>{if(e.startsWith(`m:`)){let t=ui.get(e.slice(2));if(!t)return null;let n=t.id===mi,i=t.role===`user`&&R?.status!==`running`&&R?.status!==`waiting`&&aa!==t.id,a=i&&n&&!t.id.startsWith(`pending:`),o=i&&!n&&!!t.piEntryId,s=t.content?(0,H.jsx)(Am,{source:t.content}):(0,H.jsx)(`span`,{className:`typing`,children:`正在思考`}),c=t.toolCalls??[];if(t.role===`user`){let n=ca?.id===t.id?ca.kind:void 0,r=t.content||(t.images?.length?`[图片]`:``);return(0,H.jsxs)(`article`,{className:`message user`,"data-transcript-key":e,children:[(0,H.jsxs)(`div`,{className:`message-body`,children:[(0,H.jsxs)(`div`,{className:`bubble`,children:[(0,H.jsxs)(`div`,{className:`meta`,children:[Oe,(0,H.jsx)(`time`,{children:SA(t.createdAt)})]}),t.images&&t.images.length>0&&(0,H.jsx)(`div`,{className:`message-images`,"data-message-images":`1`,children:t.images.map(e=>(0,H.jsx)(`button`,{type:`button`,className:`message-image-btn`,"data-message-image-id":e.id,onClick:()=>Ut({url:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,name:e.name,bytes:e.bytes}),title:e.name?`查看大图:${e.name}`:`查看大图`,children:(0,H.jsx)(`img`,{src:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,alt:e.name||`图片`,className:`message-image-thumb`,loading:`lazy`})},e.id))}),(0,H.jsx)(`div`,{className:`content`,children:s})]}),t.attachments&&t.attachments.length>0&&(0,H.jsx)(`div`,{className:`message-attachments`,"data-message-attachments":`1`,children:t.attachments.map(e=>{let n=`att:${t.id}:${e.kind}:${e.id}`,r=St[n]??!1;return(0,H.jsxs)(`div`,{className:`message-attachment`,"data-message-attachment":e.kind,children:[(0,H.jsxs)(`button`,{type:`button`,className:`message-attachment-head`,"data-message-attachment-toggle":e.id,"aria-expanded":r,onClick:()=>Ct(e=>({...e,[n]:!r})),children:[(0,H.jsx)(`span`,{className:`message-attachment-glyph`,"aria-hidden":`true`,children:`▤`}),(0,H.jsx)(`span`,{className:`message-attachment-label`,children:`技能`}),(0,H.jsx)(`span`,{className:`message-attachment-name`,title:e.name,children:e.name}),(0,H.jsx)(`span`,{className:`message-attachment-chevron`,"aria-hidden":`true`,children:r?`▾`:`▸`})]}),r&&(0,H.jsx)(`pre`,{className:`message-attachment-body`,"data-message-attachment-body":e.id,children:e.content})]},n)})}),(0,H.jsxs)(`div`,{className:`message-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`message-copy`,"data-copy-message":t.id,"data-copy-state":n,"aria-label":`复制这条消息:${r}`,onClick:()=>da(t.id,r),children:n===`copied`?`已复制`:n===`error`?`复制失败`:`复制`}),a&&(0,H.jsx)(`button`,{type:`button`,className:`message-revert`,"data-withdraw-message":t.id,title:`撤回并编辑:删除这条消息并将文字恢复到输入框继续编辑`,onClick:()=>sa(t.id,!0),children:`撤回`}),o&&(0,H.jsx)(`button`,{type:`button`,className:`message-revert`,"data-revert-message":t.id,title:`回退到这里:删除后续全部内容(Pi 的记录和这里的历史一起清掉,不会新建会话,也不动任何代码文件)`,onClick:()=>sa(t.id),children:`回退`})]})]}),(0,H.jsx)(`div`,{className:`avatar`,title:Oe,children:Oe})]},e)}if(t.role===`tool`){let n=/<task id="[^"]+" state="[^"]+"/.test(t.content),r=(()=>{let e=/<summary>([\s\S]*?)<\/summary>/.exec(t.content);return e?e[1].trim():n?`后台回传`:(t.content.split(`
100
100
  `).find(e=>e.trim().length>0)??``).trim().slice(0,60)||`任务指令`})(),i=(()=>{let e=/<task id="[^"]+" state="([^"]+)"/.exec(t.content);return e?e[1]:`completed`})(),a=(()=>{let e=/<task_(?:result|error)>\n?([\s\S]*?)\n?<\/(?:task_result|task_error)>/.exec(t.content);return e?e[1]:t.content})(),o=(()=>{let e=/<result_file>([\s\S]*?)<\/result_file>/.exec(t.content);return e&&e[1].trim()?e[1].trim():void 0})(),s=(()=>{let e=/<task id="([^"]+)"/.exec(t.content);return e?e[1]:void 0})(),c=!!(s&&an.some(e=>e.id===s)),l=`tool:${t.id}`,u=St[l]??!1,d=n?`后台回传`:`智能体下发`;return(0,H.jsx)(`article`,{className:`message tool${n?``:` tool-order`}`,"data-transcript-key":e,"data-tool-state":i,"data-tool-kind":n?`delivery`:`order`,children:(0,H.jsxs)(`div`,{className:`message-body`,children:[(0,H.jsxs)(`div`,{className:`bg-result-head`,"data-bg-result-head":t.id,children:[(0,H.jsxs)(`button`,{type:`button`,className:`bg-result-toggle`,"data-bg-result-toggle":t.id,"aria-expanded":u,title:u?`折叠${d}`:`展开${d}`,onClick:()=>Ct(e=>({...e,[l]:!u})),children:[(0,H.jsx)(`span`,{className:`bg-result-glyph`,"aria-hidden":`true`,children:i===`error`?`✕`:n?`↩`:`↓`}),(0,H.jsx)(`span`,{className:`bg-result-label`,children:d}),(0,H.jsx)(`span`,{className:`bg-result-summary`,title:r,children:r}),!u&&(0,H.jsx)(`span`,{className:`bg-result-preview`,"data-bg-result-preview":t.id,title:`展开查看完整输出`,children:a.split(`
101
101
  `).slice(-1)[0]}),(0,H.jsx)(`span`,{className:`bg-result-chevron`,"aria-hidden":`true`,children:u?`▾`:`▸`})]}),(o||c&&s)&&(0,H.jsxs)(`div`,{className:`bg-result-actions`,"data-bg-result-actions":t.id,children:[o&&(0,H.jsxs)(`button`,{type:`button`,className:`bg-result-action`,"data-result-file-link":o,title:`在主区域打开产物文件:${o}`,onClick:e=>{e.stopPropagation();let t=o.split(/[/\\]/).pop()||o;hr({path:o,name:t,text:!0}).catch(e=>{console.warn(`打开产物文件失败:`,e)})},children:[(0,H.jsx)(`span`,{className:`bg-result-action-glyph`,"aria-hidden":`true`,children:`📄`}),(0,H.jsx)(`span`,{children:`查看产物文件`})]}),c&&s&&(0,H.jsxs)(`button`,{type:`button`,className:`bg-result-action`,"data-result-session-link":s,title:`跳转到子会话:${s}`,onClick:e=>{e.stopPropagation(),Nn(s)},children:[(0,H.jsx)(`span`,{className:`bg-result-action-glyph`,"aria-hidden":`true`,children:`↗`}),(0,H.jsx)(`span`,{children:`跳转到子会话`})]})]})]}),u&&(0,H.jsx)(`div`,{className:`bg-result-body`,"data-bg-result-body":t.id,children:(0,H.jsx)(`pre`,{className:`bg-result-pre`,"data-bg-result-pre":t.id,children:a})})]})},e)}let l=t.thinking?.trim()?t.thinking:``,u=t.thinkingBlocks?.length?t.thinkingBlocks:l?[{at:0,text:l}]:[],d=(e,n)=>{let r=typeof e.at==`number`&&Number.isFinite(e.at)?e.at:n;return Math.max(0,Math.min(r,t.content.length))},f=e=>e.thinkingBlock===void 0?typeof e.thinkingAt!=`number`||!(e.thinkingAt<l.length||t.thinkingActive)?-1:u.findIndex((t,n)=>(e.at??0)>=t.at&&(u[n+1]===void 0||(e.at??0)<u[n+1].at)):e.thinkingBlock??-1,p=e=>c.map((e,t)=>({call:e,index:t})).filter(({call:t})=>f(t)===e),m=[],h=[...u.map((e,t)=>({at:e.at,order:u.slice(0,t).reduce((e,t)=>e+t.text.length,0)*2+1,segment:{blockIndex:t}})),...c.map((e,t)=>({at:d(e,t),order:(e.thinkingAt??0)*2,segment:{call:e,index:t}})).filter(({segment:e})=>`call`in e&&f(e.call)<0)].sort((e,t)=>e.at-t.at||e.order-t.order),g=0;for(let e of h){let n=Math.max(g,Math.min(e.at,t.content.length));n>g&&m.push({text:t.content.slice(g,n)}),m.push(e.segment),g=n}g<t.content.length&&m.push({text:t.content.slice(g)});let _=e=>{let t=fi.get(e);if(t)return(0,H.jsx)(`div`,{className:`call-anchored-run`,"data-call-anchored-run":t.id,"data-call-anchored-site":e,children:(0,H.jsx)(oj,{run:t,name:li.get(t.agentId)??``,expanded:!!bt[t.id],onToggle:()=>hi(t.id),onStop:()=>xi(t.id),stopping:r.some(e=>e.key===`stop:${t.id}`)})})},v=e=>e.call.question?(0,H.jsx)(`div`,{className:`call-blocks`,"data-call-block-index":e.index,children:(0,H.jsx)(dj,{question:e.call.question,index:e.index,expanded:`${t.id}:${e.index}`in wt?!!wt[`${t.id}:${e.index}`]:!0,onToggle:()=>_i(t.id,e.index),onAnswer:(n,r)=>Vr(R?.id??``,t.id,e.index,n,r)})},`c${e.index}`):(0,H.jsx)(`div`,{className:`call-blocks`,"data-call-block-index":e.index,children:(0,H.jsx)(rj,{call:e.call,index:e.index,expanded:`${t.id}:${e.index}`in St&&!!St[`${t.id}:${e.index}`],onToggle:()=>gi(t.id,e.index),backgroundOutput:e.call.backgroundTask&&(0,H.jsx)(nj,{task:e.call.backgroundTask,initialOutput:le.current.get(e.call.backgroundTask.id)??``,expanded:`${t.id}:${e.index}`in St&&!!St[`${t.id}:${e.index}`]}),runCard:_(`${t.id}:${e.index}`)})},`c${e.index}`),y=e=>{let n=u[e],r=u.slice(0,e).reduce((e,t)=>e+t.text.length,0),i=0,a=[];for(let{call:t,index:o}of p(e).sort((e,t)=>(e.call.thinkingAt??r)-(t.call.thinkingAt??r)||e.index-t.index)){let e=Math.max(i,Math.min(n.text.length,(t.thinkingAt??r)-r));e>i&&a.push((0,H.jsx)(`div`,{className:`content thinking-text`,children:(0,H.jsx)(Am,{source:n.text.slice(i,e)})},`t${o}`)),a.push(v({call:t,index:o})),i=e}i<n.text.length&&a.push((0,H.jsx)(`div`,{className:`content thinking-text`,children:(0,H.jsx)(Am,{source:n.text.slice(i)})},`tail`));let o=p(e).filter(e=>e.call.status===void 0),s=o.find(e=>e.call.question?.status===`pending`);return(0,H.jsx)(aj,{liveCall:s?`question`:o.at(-1)?.call.label,liveAwaitingReader:!!s,liveExtra:o.length>1?o.length-1:void 0,messageId:`${t.id}:${e}`,nestedCount:p(e).length,preview:n.text.split(`
102
102
  `).map(e=>e.trim()).find(Boolean)??``,expanded:vi[`${t.id}:${e}`]===!0,onToggle:()=>bi(`${t.id}:${e}`),children:a},`${t.id}:thinking:${e}`)};return(0,H.jsxs)(`article`,{className:`message assistant`,"data-transcript-key":e,children:[(0,H.jsx)(`div`,{className:`avatar`,children:`π`}),(0,H.jsxs)(`div`,{className:`message-body`,children:[(0,H.jsxs)(`div`,{className:`meta`,children:[t.agentIdentity?.name??`Super Pi`,(0,H.jsx)(`time`,{children:SA(t.createdAt)})]}),m.length===0&&(R?.status===`running`||R?.status===`waiting`)?(0,H.jsx)(`div`,{className:`content`,children:(0,H.jsx)(`span`,{className:`typing`,children:`正在思考`})}):m.map((e,t)=>`blockIndex`in e?y(e.blockIndex):`text`in e?e.text?(0,H.jsx)(`div`,{className:`content`,children:(0,H.jsx)(Am,{source:e.text})},`t${t}`):null:v(e))]})]},e)}if(e.startsWith(`w:`)){let t=ci.get(e.slice(2));return t?(0,H.jsxs)(`div`,{"data-transcript-key":e,children:[r.some(e=>e.key===`stop:${t.id}`)&&(0,H.jsx)(`span`,{children:`停止中…`}),(0,H.jsx)(ev,{workflow:t,names:li,stopping:r.some(e=>e.key===`stop:${t.id}`),onStop:()=>Si(t.id)},e)]},e):null}let t=di.get(e.slice(2));return t?(0,H.jsxs)(`div`,{"data-transcript-key":e,children:[r.some(e=>e.key===`stop:${t.id}`)&&(0,H.jsx)(`span`,{children:`停止中…`}),(0,H.jsx)(oj,{run:t,stopping:r.some(e=>e.key===`stop:${t.id}`),name:li.get(t.agentId)??``,expanded:!!bt[t.id],onToggle:()=>hi(t.id),onStop:()=>xi(t.id)},e)]},e):null})]}),(0,H.jsx)(sj,{messages:$i,pendingInterrupts:r.filter(e=>e.key.startsWith(`interrupt:${R?.id}:`)).map(e=>e.key.slice(`interrupt:${R?.id}:`.length)),running:R?.status===`running`,onSteer:ta,onInterrupt:na,onSend:ra,onCancel:ea,onEdit:ia}),(0,H.jsxs)(`div`,{className:`stream-tail`,"data-stream-tail":`1`,"data-follow-tail":oe.followTail?`true`:`false`,children:[gt!==null&&(0,H.jsx)(kM,{height:gt,onHeight:vt}),(0,H.jsx)(`span`,{className:`stream-tail-status`,"data-run-status":R?.status??`idle`,"data-stream-state":f?zr?`stopping`:R&&Tj(R,je)?`question`:R?.status===`waiting`?`waiting`:R?.status===`running`?`streaming`:R?.status===`awaiting_background`||$i.length?`waiting`:R?.status===`failed`?`failed`:`ready`:`waiting`,children:f?Rr?`正在创建会话…`:zr?`正在停止…`:R&&Tj(R,je)?`等你回答 · Agent 在等你的回复`:R?.messagesLoaded===!1?`正在加载会话…`:R?.status===`waiting`?`等待 LLM 返回`:R?.status===`running`?`Streaming · 正在生成`:R?.status===`awaiting_background`?`等待后台任务 · 任务在后台运行中`:$i.length?`Waiting · 消息排队中`:R?.status===`failed`?`运行失败`:R?.status===`stopped`?`已停止`:`就绪`:`连接中 / 等待连接`}),!oe.followTail&&(0,H.jsx)(`button`,{type:`button`,className:`stream-tail-jump`,"data-jump-to-bottom":`1`,onClick:()=>{let e=ne.current;e&&(dM(e),e.scrollTop=e.scrollHeight,gn(e,!1,!0))},children:`↓ 跳到底部`}),(0,H.jsx)(`span`,{className:`stream-tail-mode`,"data-follow-tail":oe.followTail?`true`:`false`,children:oe.followTail?`贴底`:`自由浏览`})]}),(ai.length>0||[...Le.values()].some(e=>e.placement===`aboveEditor`))&&(0,H.jsxs)(`div`,{className:`extui`,"data-extui-count":ai.length,children:[ai.map(e=>(0,H.jsx)(pj,{request:e.request,pending:r.some(t=>t.key===`answer:${e.conversationId}:${e.request.requestId}`),onAnswer:t=>Hr(e.conversationId,e.request.requestId,t)},e.request.requestId)),Ci(`aboveEditor`)]}),(0,H.jsxs)(`form`,{onSubmit:Qi,onPaste:Ji,onDragOver:Yi,onDragLeave:Xi,onDrop:Zi,className:Wt?`composer-dropzone-active`:void 0,children:[(0,H.jsxs)(`div`,{className:`composer-input`,"data-composer-input":`1`,children:[(0,H.jsx)(`textarea`,{ref:re,value:vn,onCompositionStart:()=>{qt.current=!0},onCompositionEnd:()=>{qt.current=!1},onChange:e=>{Cn(e.target.value),e.target.value.trim()&&Mn(R?.id??``);let t=e.target.value,n=e.target.selectionStart??t.length,r=t.slice(0,n),i=r.lastIndexOf(`/`),a=r.slice(i+1),o=i>0?r[i-1]:``;i>=0&&(i===0||/\s/.test(o))&&/^[\w:-]*$/u.test(a)?Dn({visible:!0,query:a,rect:e.currentTarget.getBoundingClientRect()}):Dn({visible:!1,query:``,rect:null})},placeholder:R?Kr?`描述你要完成的任务(支持粘贴/拖放图片)…`:`描述你要完成的任务…`:`先创建会话`,disabled:!R,readOnly:un,"aria-describedby":un?`child-session-lock-reason`:void 0,onKeyDown:e=>{if(!(qt.current||pA(e))){if(En.visible){if(e.key===`Escape`){e.preventDefault(),Dn({visible:!1,query:``,rect:null});return}if([`ArrowDown`,`ArrowUp`,`Enter`].includes(e.key)){e.preventDefault();return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}}),un&&(0,H.jsxs)(`div`,{className:`composer-lock`,"data-child-session-lock":`1`,role:`note`,"aria-labelledby":`child-session-lock-title`,children:[(0,H.jsx)(`span`,{className:`composer-lock-glyph`,"data-child-session-lock-glyph":`1`,"aria-hidden":`true`,children:(0,H.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`30`,height:`30`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,focusable:`false`,children:[(0,H.jsx)(`rect`,{x:`4`,y:`10`,width:`16`,height:`11`,rx:`2.5`}),(0,H.jsx)(`path`,{d:`M8 10V7a4 4 0 0 1 8 0v3`}),(0,H.jsx)(`path`,{d:`M12 14.5v2.5`})]})}),(0,H.jsxs)(`span`,{className:`composer-lock-text`,children:[(0,H.jsx)(`span`,{className:`composer-lock-title`,"data-child-session-lock-title":`1`,id:`child-session-lock-title`,children:`子会话输入框已上锁`}),(0,H.jsx)(`span`,{className:`composer-lock-reason`,"data-child-session-lock-reason":`1`,id:`child-session-lock-reason`,children:`汇报线只允许逐级上升,子会话默认不能直接对话;确有特殊情况可解锁。`})]}),(0,H.jsx)(`button`,{type:`button`,className:`composer-lock-action`,"data-child-session-unlock":`1`,onClick:()=>Pr(R?.id??``,!0),children:`临时解锁`})]})]}),En.visible&&En.rect&&(0,H.jsx)(Um,{query:En.query,anchorRect:En.rect,workspaceId:R?.workspaceId,promptCatalog:ke,command:jr,onSelect:e=>{if(e.id.startsWith(`skill:`)){let t=e.id.slice(6),n=document.querySelector(`[data-selected-workspace]`)?.dataset.selectedWorkspace??R?.workspaceId,r=new URLSearchParams({name:t,...n?{workspaceId:n}:{}});fetch(`/api/skills/read?${r.toString()}`).then(async n=>{if(!n.ok){B(`读取技能失败`,`error`);return}let r=await n.json();typeof r.content==`string`&&wn({kind:`skill`,id:r.id??e.id,name:r.name??t,content:r.content})}).catch(()=>B(`读取技能失败`,`error`))}let t=re.current?.selectionStart??vn.length,n=vn.slice(0,t),r=n.lastIndexOf(`/`),i=Vm(e,En.query),a=`${n.slice(0,r)}/${i} ${vn.slice(t)}`;Cn(a),Dn({visible:!1,query:``,rect:null})},onClose:()=>Dn({visible:!1,query:``,rect:null})}),Rt.filter(e=>e.conversationId===R?.id).map(e=>(0,H.jsxs)(`div`,{className:`composer-notice`,"data-failed-send":e.id,role:`alert`,children:[(0,H.jsx)(`span`,{className:`composer-notice-mark`,"aria-hidden":`true`,children:`!`}),(0,H.jsxs)(`div`,{className:`composer-notice-body`,children:[(0,H.jsx)(`p`,{className:`composer-notice-title`,"data-failed-send-reason":`1`,title:np(e.reason),children:e.reason?.trim()?tp(e.reason):`服务端没有接受这条消息。`}),(0,H.jsx)(`p`,{className:`composer-notice-text`,title:e.content,children:e.content})]}),(0,H.jsxs)(`div`,{className:`composer-notice-actions`,children:[(0,H.jsx)(`button`,{type:`button`,className:`composer-notice-action`,"data-failed-send-restore":`1`,disabled:!!(vn||yn.length||bn.length),title:vn||yn.length||bn.length?`输入框里已经有内容,先把这条留在下面`:`放回输入框,改完再发`,onClick:()=>{Sn(e.conversationId,t=>({...t,text:e.content,images:e.images,attachments:e.attachments})),zt(t=>t.filter(t=>t.id!==e.id))},children:`放回输入框`}),(0,H.jsx)(`button`,{type:`button`,className:`composer-notice-dismiss`,"data-failed-send-dismiss":`1`,onClick:()=>zt(t=>t.filter(t=>t.id!==e.id)),children:`丢弃`})]})]},e.id)),Bt.filter(e=>e.conversationId===R?.id).map(e=>(0,H.jsxs)(`div`,{className:`composer-upload-preview${e.failed?` composer-upload-preview-failed`:``}`,"data-upload-preview":e.id,children:[(0,H.jsx)(`img`,{src:e.url,alt:e.name,width:44,height:44,className:`composer-upload-thumb`}),(0,H.jsx)(`span`,{className:`composer-upload-state`,"data-upload-preview-state":e.failed?`failed`:`uploading`,children:e.failed?`上传失败`:`上传中…`}),(0,H.jsx)(`button`,{type:`button`,className:`composer-upload-remove`,"aria-label":`移除 ${e.name}`,title:`移除这张图片`,onClick:()=>{Lt.current.add(e.id),URL.revokeObjectURL(e.url),Vt(t=>t.filter(t=>t.id!==e.id))},children:`移除`})]},e.id)),(yn.length>0||xn>0)&&(0,H.jsxs)(`div`,{className:`composer-attachments`,"data-composer-attachments":`1`,children:[yn.map((e,t)=>(0,H.jsxs)(`div`,{className:`composer-attachment-item`,"data-composer-attachment-id":e.id,children:[(0,H.jsx)(`img`,{src:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,alt:e.name||`已附图片`,className:`composer-attachment-thumb`,onClick:()=>Ut({url:`/api/upload/${encodeURIComponent(R?.id??``)}/${encodeURIComponent(e.id)}`,name:e.name,bytes:e.bytes}),title:`点击查看大图`}),(0,H.jsx)(`span`,{className:`composer-attachment-name`,title:e.name,children:e.name||`图片`}),(0,H.jsx)(`button`,{type:`button`,className:`composer-attachment-remove`,"data-composer-attachment-remove":e.id,onClick:()=>On(e=>e.filter((e,n)=>n!==t)),"aria-label":`移除 ${e.name||`图片`}`,title:`移除图片`,children:`✕`})]},e.id)),xn>0&&(0,H.jsx)(`div`,{className:`composer-attachment-item composer-attachment-uploading`,children:(0,H.jsxs)(`span`,{children:[`图片上传中 (`,xn,`)…`]})}),bn.map(e=>(0,H.jsxs)(`div`,{className:`composer-attachment-item composer-attachment-skill`,"data-composer-skill-id":e.id,children:[(0,H.jsx)(`span`,{className:`composer-attachment-glyph`,"aria-hidden":`true`,children:`▤`}),(0,H.jsx)(`span`,{className:`composer-attachment-name`,title:e.name,children:e.name}),(0,H.jsx)(`button`,{type:`button`,className:`composer-attachment-remove`,"data-composer-skill-remove":e.id,onClick:()=>Tn(e.kind,e.id),"aria-label":`移除 ${e.name}`,title:`移除技能`,children:`✕`})]},`${e.kind}:${e.id}`))]}),(0,H.jsxs)(`div`,{className:`composer`,children:[(0,H.jsxs)(`div`,{className:`session-picker`,"data-session-picker":`1`,children:[(0,H.jsx)(hj,{kind:`agent`,label:ei?.name??`跟随 Pi 默认`,value:R?.agentId??gj,options:ti,disabled:!Ye||Ye.source===`unavailable`||Br,note:ZA(Ye),onChoose:ii}),(0,H.jsx)(hj,{kind:`model`,label:Ur?.label??(Ve?`Pi 默认`:`读取中…`),value:Ur?`${Ur.provider}/${Ur.modelId}`:void 0,detail:ri?`来自 ${ei?.name}`:Ur&&Ve?.source===`pi`&&!R?.model?`Pi 默认模型`:Ur?`${Ur.provider}/${Ur.modelId}`:void 0,options:Xr,disabled:!Gr||Br,note:XA(`模型`,Ve,Jr),onChoose:Qr}),(0,H.jsx)(hj,{kind:`thinking`,label:Wr??(Ve?`Pi 默认`:`读取中…`),value:Wr,options:Zr,disabled:!Gr||Br,note:XA(`思考等级`,Ve),onChoose:$r})]}),(0,H.jsxs)(`div`,{className:`composer-hints`,children:[(0,H.jsxs)(`button`,{type:`button`,className:`composer-attach-btn`,"data-composer-attach":`1`,onClick:()=>Kt.current?.click(),disabled:!R||!Kr||xn>0,title:R?Kr?`添加图片(支持剪贴板粘贴与拖拽)`:`当前模型不支持图片输入`:`请先创建或选择会话`,"aria-label":`添加图片`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,children:`+`}),` 图片`]}),(0,H.jsx)(`input`,{ref:Kt,type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,multiple:!0,style:{display:`none`},onChange:e=>{e.target.files?.length&&(qi(Array.from(e.target.files)),e.target.value=``)}}),Jr&&(0,H.jsx)(`span`,{"data-image-session-hint":`1`,title:`此会话历史已包含图片,仅显示支持图文的模型`,children:`图文会话`}),(0,H.jsx)(`span`,{children:`Enter 发送 · Shift + Enter 换行`})]}),(0,H.jsxs)(`div`,{className:`composer-actions`,children:[cn&&!un&&(0,H.jsx)(`button`,{type:`button`,className:`composer-relock`,"data-child-session-relock":`1`,title:`重新给这个子会话上锁`,onClick:()=>Pr(R?.id??``,!1),children:`重新上锁`}),R&&(Sj(R)||R.status===`awaiting_background`)&&(0,H.jsx)(`button`,{type:`button`,className:`stop`,"data-stop-run":R.id,disabled:r.some(e=>e.key===`stop:${R.id}`)||Ot.has(R.id),onClick:()=>Mr({type:`run.stop`,conversationId:R.id},`stop:${R.id}`,e=>e),children:r.some(e=>e.key===`stop:${R.id}`)||Ot.has(R.id)?`停止中…`:`停止`}),(0,H.jsx)(`button`,{className:`send ${Sj(R)?`send-queued`:``}`,"data-send-mode":Sj(R)?`queued`:`direct`,disabled:!vn.trim()&&yn.length===0||!R||xn>0||!!aa||Br||un,title:R?un?uA:Rr?`正在创建会话,请稍候再发送`:R.messagesLoaded===!1?`正在加载会话,请稍候再发送`:aa?`正在撤回:Pi 的历史还没截断完成,撤回结束后即可发送`:!vn.trim()&&yn.length===0?`请输入消息或添加图片后发送`:xn>0?`图片上传中…`:Sj(R)?`这一轮结束后发送(发送后可在上面的排队区取消或插队)`:void 0:`请先创建或选择会话`,children:aa?`撤回中…`:Sj(R)?`排队发送 ↑`:`发送 ↑`})]})]})]}),Ci(`belowEditor`)]})]}),(0,H.jsx)(SM,{side:`right`,width:rt?30:pt.rail,min:pt.railMin,max:pt.railMax,label:`调整右侧栏宽度`,onWidth:ht}),qn&&(0,H.jsx)(V_,{entries:z.index,complete:z.indexComplete,skipped:z.indexSkipped,onOpen:e=>{hr(e)},onClose:()=>Jn(!1)}),Zn&&(0,H.jsx)(B_,{workspaceId:v,cwd:In,onOpen:e=>{hr({path:e.path,name:e.name,text:!0},e.line)},onClose:()=>Qn(!1)},`${v}:${In}`),(0,H.jsx)(Uj,{}),st&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,className:`mobile-drawer-backdrop`,"data-mobile-drawer-backdrop":`1`,"aria-label":`关闭会话列表`,onClick:()=>ct(!1)}),(0,H.jsx)(`button`,{type:`button`,className:`mobile-drawer-close`,"data-mobile-drawer-close":`1`,"aria-label":`关闭会话列表`,title:`关闭`,onClick:()=>ct(!1),children:`×`})]}),(0,H.jsxs)(`nav`,{className:`mobile-nav`,"aria-label":`移动端主导航`,children:[(0,H.jsxs)(`button`,{type:`button`,"data-mobile-nav":`workspaces`,className:at===`workspaces`?`active`:``,onClick:()=>ot(`workspaces`),children:[`☰`,(0,H.jsx)(`span`,{children:`工作区`})]}),(0,H.jsxs)(`button`,{type:`button`,"data-mobile-nav":`chat`,className:at===`chat`?`active`:``,onClick:()=>ot(`chat`),children:[`◉`,(0,H.jsx)(`span`,{children:`对话`})]}),(0,H.jsxs)(`button`,{type:`button`,"data-mobile-nav":`rail`,className:at===`rail`?`active`:``,onClick:()=>{ot(`rail`),it(!1)},children:[`▣`,(0,H.jsx)(`span`,{children:`工具`})]})]}),` `,At&&(0,H.jsx)(FA,{workspace:At.workspace,x:At.x,y:At.y,notify:B,onClose:()=>jt(void 0)}),Mt&&(0,H.jsx)(IA,{conversation:Mt.conversation,x:Mt.x,y:Mt.y,notify:B,onRename:()=>void ji(Mt.conversation.id),onClose:()=>Nt(void 0),sendCommand:jr,orchestrated:Mt.conversation.origin===`orchestrator`,childCount:an.filter(e=>e.parentConversationId===Mt.conversation.id).length}),D&&(0,H.jsx)(qA,{onClose:()=>O(!1),onCreate:wi}),k&&(()=>{let e=l.workspaces.find(e=>e.id===k.workspaceId);return e?(0,H.jsx)(KA,{workspace:e,onClose:()=>{A(void 0),j.current?.focus()},onCreate:e=>{Ui(k.workspaceId,e),A(void 0),j.current?.focus()}}):null})(),Ri&&(0,H.jsx)(hy,{workspaceId:v,theme:Ii,onChooseTheme:e=>Li(e),onClose:()=>zi(!1),agentCatalog:Ye,subagentCatalog:Ze,modelFilterRules:l.modelFilterRules??[],pendingSettings:r.some(e=>e.key===`model-rules`||e.key===`agent-directories`||e.key===`default-model`),onSetModelRules:e=>Mr({type:`model.rules.set`,rules:e},`model-rules`,t=>({...t,modelFilterRules:e})),defaultModel:l.defaultModel,modelCatalog:Ue,onSetDefaultModel:e=>Mr({type:`settings.defaultModel`,model:e?{provider:e.provider,modelId:e.modelId}:null},`default-model`,t=>{let n={...t};return e?n.defaultModel=e:delete n.defaultModel,n}),providers:Ge,providerApis:qe,onSetProvider:e=>{jr({type:`providers.set`,provider:e})},onRemoveProvider:e=>{jr({type:`providers.remove`,providerId:e})},onRepairProviders:()=>{jr({type:`providers.repair`}),B(`正在清理 Pi 不接受的空字段并重新读取模型清单`,`info`)},onToggleProvider:(e,t)=>{jr(t?{type:`providers.enable`,providerId:e}:{type:`providers.disable`,providerId:e}),B(t?`已启用供应商「${e}」,它的模型重新出现在选择器里`:`已停用供应商「${e}」:配置已从 Pi 的文件里拿掉并保存在这里,模型不再出现在选择器里`,`info`)},onRemoveProviderModel:(e,t)=>{jr({type:`providers.removeModel`,providerId:e,modelId:t})},customAgentDirs:l.customAgentDirs??[],onSetCustomAgentDirs:e=>Mr({type:`agents.setCustomDirs`,dirs:e},`agent-directories`,t=>({...t,customAgentDirs:e})),onRescanAgents:()=>jr({type:`agents.rescan`}),userNickname:Te,onSetUserNickname:De,terminalShell:l.terminalShell,onSetTerminalShell:e=>{jr({type:`terminal.shell.set`,command:e})}}),Bi&&(0,H.jsx)(nv,{onClose:()=>Vi(!1)}),Fi&&(0,H.jsx)(_j,{workspace:Fi,catalog:qr(Ve,Fi),agents:Ye,onClose:()=>Pi(void 0),onRename:()=>{let e=Fi.id;Pi(void 0),Di(`workspace`,e)},onSave:(e,t,n)=>Hi(Fi.id,e,t,n)}),Ht&&(0,H.jsx)(qj,{image:Ht,onClose:()=>Ut(void 0)}),yt&&!rt&&(0,H.jsx)(`div`,{className:`rail-backdrop`,role:`presentation`,"aria-hidden":`true`,onClick:()=>it(!0)}),(0,H.jsx)(Rj,{onOpenSession:Nn,todos:l.todosByConversation?.[R?.id??``]??[],tasks:Fj(R,l.backgroundTasks??[]),messages:R?.messages??[],execOutputs:le.current,scheduledTasks:(l.scheduledTasks??[]).filter(e=>e.workspaceId===v),scheduledCatalog:qr(Ve,l.workspaces.find(e=>e.id===v)),scheduledAgents:Ye,notify:B,serverTimeZone:l.serverTimeZone,collapsed:rt,onToggle:()=>it(e=>!e),workspaceId:Fn,workspaceLabel:l.workspaces.find(e=>e.id===Fn)?.path,conversationId:R?.id,cwd:In,connected:f,files:z,onOpenFile:e=>void hr(e),onOpenChanged:cr,activeTab:Gn,onSelectTab:Kn,sendCommand:jr,registerTerminalSink:he,terminalShell:l.terminalShell})]})}ty(ey()),(0,ca.createRoot)(document.getElementById(`root`)).render((0,H.jsx)(V.StrictMode,{children:(0,H.jsx)(jM,{})}));export{d as a,y as i,d_ as n,s as o,Rg as r,l as s,c_ as t};